Repository navigation
[12.x] Give each inlined copy of a function or functor body its own static exits - #9459
Open
illusionalsagacity wants to merge 1 commit into
Conversation
…xits (rescript-lang#9414) Lam_bounded_vars.rewrite refreshes the bound variables of a function body before it is copied (an `@inline` function at each call site, a functor body at each application) but kept the ids of the static catches inside it. The copies and the definition then shared an exit id, and Lam_pass_exits.subst_helper, which records inlinable handlers by exit id, substituted one copy's handler into the raises of another. Each catch in the rewritten body now gets a fresh exit id (negative ids, which mark exception cases, stay negative) and the raises it scopes are redirected; raises to exits caught outside the body are left alone. On 12.x the copies come out right and the definition is the one that takes a copy's handler: with master's test, `pick` itself returned "t" for every match of its or-pattern, and the functor `Make` did the same. Master's runtime tests therefore pass on 12.x without the fix, so a test calls the definitions without inlining them, through `id` and through a functor unpacked from a first-class module; it fails without the fix. 12.x has Lam.t where master has Lambda.t, takes the exit counters from Lambda instead of Lambda_exits, and has Map_int's map-first argument order. It has no tests/ounit_tests/ounit_lam_bounded_vars_tests.ml, so it is added with only this PR's tests. (cherry picked from commit 64cdd3c) Signed-off-by: Rob <illusionalsagacity@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #9414 to 12.x.
Problem
Lam_bounded_vars.rewriterefreshes the bound variables of a function body before it is copied (an@inlinefunction at each call site, a functor body at each application), but kept the ids of the static catches inside it. The copies and the definition then shared an exit id, andLam_pass_exits.subst_helper, which records inlinable handlers by exit id, substituted one copy's handler into the raises of another, so the wrong arm of aswitchwith or-patterns or an| exceptioncase ran.On master the second copy took the first one's handler. On 12.x the copies come out right, and the definition is the one that takes the handler the constant copy was simplified to, so
pick(0, 5, false)called without inlining returns"t".Before:
After:
A functor applied twice had the same problem: the
Makefunction of master's test computed"t"forflag = false.Fix
As on master, each catch in the rewritten body gets a fresh exit id (negative ids, which mark exception cases, stay negative) and the raises it scopes are redirected; raises to exits caught outside the body keep their ids.
Differences from master:
Lam.twhere master hasLambda.t, takes the exit counters fromLambdarather thanLambda_exits, and hasMap_int's map-first argument order.tests/ounit_tests/ounit_lam_bounded_vars_tests.ml, so it is added with only this PR's unit tests. The unmerged Rename the assigned variable when inlining an assignment #9424 backport adds the same file, so whichever lands second needs a small merge of that file and ofounit_tests_main.ml.pick,nestedandboundthroughid, andMakethrough a functor unpacked from a first-class module, so they aren't inlined.Tests
tests/ounit_tests/ounit_lam_bounded_vars_tests.ml: master's four unit tests (a fresh exit per copy, outer exits kept, a catch scoping over its body only, negative ids staying negative). All four fail without the fix.tests/tests/src/inline_static_exit_test.res: master's tests plus "definitions of inlined functions and functors", which fails without the fix. The generated JS of the definitions now matches master's.tests/tests/src/inline_static_exit_cross_module_{lib,test}.res: master's cross-module tests, unchanged; they pass on 12.x with and without the fix.Investigated by Claude.