Repository navigation
[12.x] Compare tag_info when merging constant blocks - #9386
Open
illusionalsagacity wants to merge 1 commit into
Open
illusionalsagacity wants to merge 1 commit into
illusionalsagacity wants to merge 1 commit into
Conversation
A block's tag is its constructor's position in its type, so after a coercion two blocks with the same tag and fields can have different constructor names or record field names, and compile to different JavaScript. Lam_constant.eq_approx, used to merge switch arms, and Js_analyzer.eq_expression, used to merge if/else branches, compared only the tag and fields, so such arms were merged and returned the wrong value. Compare tag_info too. Signed-off-by: Rob <illusionalsagacity@users.noreply.github.com>
illusionalsagacity
force-pushed
the
fix-block-arm-merge
branch
from
November 22, 2026 13:25
2350b87 to
6983d0f
Compare
5 tasks done
illusionalsagacity
marked this pull request as ready for review
November 22, 2026 13:28
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
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.
Fixes #9385.
Before, the
ifis dropped, sof(false)returnsFirst(1):After:
A block's tag is its constructor's position.
Second(1)is created as asmall, whereSecondis constructor 0, so after the coercion it has the same tag and field asFirst(1).Js_analyzer.eq_expression(mergingif/elsebranches) andLam_constant.eq_approx(merging switch arms) ignoredtag_info, which holds the constructor and record field names, so they treated the two as equal. Both now compare it. Master already keeps these apart.Slight deoptimization
tag_infois compared whole, so it also compares parts that don't change the printed block, such as the source type's constructor count and the locations of attributes like doc comments. A few branches that print the same are no longer merged:Before, this compiled to a single
return {TAG: "First", _0: 1}; now both branches are kept. Master gives the same output as this PR. Comparing only the printed parts would mean comparing attributes without their locations, so this keeps the simpler, conservative comparison.Tests
tests/tests/src/block_arm_merge_test.rescoversifbranches and switch arms returning coerced constructors and records. All 3 tests fail without the change, and no other module intests/testschanges output.