Repository navigation
Merge null and undefined checks with source maps on too - #9503
Conversation
Why:
With source maps on, the two reads of `e` in
`e === null || e === undefined` carry different source locations.
`Js_dump` compared them with `=`, which includes the locations, so it
printed both checks instead of `e == null`, and the JavaScript depended
on whether source maps were on. It now compares them with
`Js_analyzer.eq_expression`, which ignores locations. Fixes #9502.
JS modified (null and undefined checks with source maps):
Example:
let r = opaque({v: Nullable.null})
eq(__LOC__, r.v === Nullable.null || r.v === Nullable.undefined, true)
Before (js): tests/compiler_tests/src/null_check_merge_test.res, with source maps
Test_utils.eq("…", r.v === null || r.v === undefined, true);
After (js): with source maps, the same as without them
Test_utils.eq("…", r.v == null, true);
Review: Can `eq_expression` stop a merge that `=` allowed?
It answers false for some shapes, such as floats or `Length`. Building
tests/compiler_tests without source maps gives the committed output, so
no merge there is lost.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gKGdW5oiHFukU4zkSu
Signed-off-by: Christoph Knittel <ck@cca.io>
Changelog🐛 Bug fix
Semantic Diff1 commit · Full page Merge null and undefined checks with source maps on too0af7037 · cknitt + Claude · Dec 01, 2026, 21:15 UTC
JS modified (null and undefined checks with source maps) let r = opaque({v: Nullable.null})
eq(__LOC__, r.v === Nullable.null || r.v === Nullable.undefined, true)
-Test_utils.eq("…", r.v === null || r.v === undefined, true);
+Test_utils.eq("…", r.v == null, true);Review
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9503 +/- ##
=======================================
Coverage 82.49% 82.50%
=======================================
Files 467 467
Lines 66125 66126 +1
=======================================
+ Hits 54553 54554 +1
Misses 11572 11572
🚀 New features to boost your workflow:
|
✅ Compiler benchmarksAllocated wordsIn total: 655,168,978 → 655,169,032 (±0.00%). Generated projects: 627,292,805 → 627,293,008 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 9,128,430,130 → 9,128,427,490 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 27,368,788 → 27,368,738 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request 0af7037 compared with base 69e11bf in this run. |
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9503 |
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
cristianoc
left a comment
There was a problem hiding this comment.
Worth doing a quick adversarial review too: by simple code inspection it should be possible to determine that source maps do not affect the generated code.
Fixes #9502.
With source maps on, the two reads of
eine === null || e === undefinedcarry different source locations.Js_dumpcompared them with=, which includes the locations, so it printed both checks instead ofe == null. The generated JavaScript then depended on whether source maps were on.The operands are now compared with
Js_analyzer.eq_expression, which ignores locations. It is more conservative than=for some shapes (floats,Length, …), but building tests/compiler_tests without source maps still gives the committed output, so no existing merge is lost. With and without source maps the output of tests/compiler_tests is now the same.Test: the source map project gets a null check in
Helper.res, checks that the default build merges it, and checks that the hidden-mode build (no source map comment) prints the same JS as the default build. That second check fails without the fix.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gKGdW5oiHFukU4zkSu