Skip to content

Conversation

@bclement-ocp
Copy link
Contributor

There are some situations (particularly with extensions stored on a
variable x that add new equations for that same variable x) that
causes the current (and the previous) meet algorithm to go into an
infinite loop. The rest of the code is carefully written to avoid these
situations, but this is hampering recent work in the typing env (#4112
and #3538 are carefully working around this).

The proper long term fix for the issue is not clear. It might be similar
to what is done in #4112, where extensions are associated with
identifiers to avoid adding extensions recursively, if we want to allow
recursive extensions. Or it might be some clever mechanism to extract
recursive equations from extensions and lift them to the point of the
disjunction.

In the short term, this patch uses the meet_env from #4269 and #4278
in order to keep track of variables we are currently adding an equation
for, and simply dropping a second occurence of the same variable: if
this happens, we are likely entering an infinite loop of trying to add
the same equation recursively, so we simply drop the inner equation.

This should not happen currently, however it is going to start happening
when we start tracking the Is_int and Get_tag values of blocks for
the match-in-match heuristics.

Note: this PR includes (and is rebased on top of) #4278 ; only the latest commit is new in this PR.

@bclement-ocp bclement-ocp requested a review from lthls July 28, 2025 16:46
@bclement-ocp bclement-ocp added flambda2 Prerequisite for, or part of, flambda2 match-in-match prerequisites, or part of, match-in-match labels Jul 28, 2025
@bclement-ocp bclement-ocp force-pushed the prevent_recursive_meet branch from 3df3b33 to 289b3dd Compare July 30, 2025 13:07
There are some situations (particularly with extensions stored on a
variable `x` that add new equations for that same variable `x`) that
causes the current (and the previous) meet algorithm to go into an
infinite loop.  The rest of the code is carefully written to avoid these
situations, but this is hampering recent work in the typing env (oxcaml#4112
and oxcaml#3538 are carefully working around this).

The proper long term fix for the issue is not clear. It might be similar
to what is done in oxcaml#4112, where extensions are associated with
identifiers to avoid adding extensions recursively, if we want to allow
recursive extensions. Or it might be some clever mechanism to extract
recursive equations from extensions and lift them to the point of the
disjunction.

In the short term, this patch uses the `meet_env` from oxcaml#4269 and oxcaml#4278
in order to keep track of variables we are currently adding an equation
for, and simply dropping a second occurence of the same variable: if
this happens, we are likely entering an infinite loop of trying to add
the same equation recursively, so we simply drop the inner equation.

This should not happen currently, however it is going to start happening
when we start tracking the `Is_int` and `Get_tag` values of blocks for
the match-in-match heuristics.
@mshinwell mshinwell merged commit 834b76d into oxcaml:main Sep 17, 2025
23 checks passed
@bclement-ocp bclement-ocp deleted the prevent_recursive_meet branch October 2, 2025 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flambda2 Prerequisite for, or part of, flambda2 match-in-match prerequisites, or part of, match-in-match

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants