Skip to content

Merge null and undefined checks with source maps on too - #9503

Merged
cknitt merged 1 commit into
masterfrom
null-merge-source-map
Dec 2, 2026
Merged

cknitt merged 1 commit into
masterfrom
null-merge-source-map

Conversation

@cknitt

@cknitt cknitt commented Dec 1, 2026

Copy link
Copy Markdown
Member

Fixes #9502.

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. 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

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>
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Print e == null for a null and undefined check with source maps on too, so source maps no longer change the generated JavaScript.

Semantic Diff

1 commit · Full page

Merge null and undefined checks with source maps on too

0af7037 · cknitt + Claude · Dec 01, 2026, 21:15 UTC

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)

let r = opaque({v: Nullable.null})
eq(__LOC__, r.v === Nullable.null || r.v === Nullable.undefined, true)

js · Before: tests/compiler_tests/src/null_check_merge_test.res, with source maps · After: with source maps, the same as without them

-Test_utils.eq("…", r.v === null || r.v === undefined, true);
+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.

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.50%. Comparing base (69e11bf) to head (0af7037).
⚠️ Report is 5 commits behind head on master.

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           
Files with missing lines Coverage Δ
compiler/backend/js_dump.ml 92.60% <100.00%> (+<0.01%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In 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.

Instructions

In total: 9,128,430,130 → 9,128,427,490 (±0.00%).

None of the 33 benchmarks changed by 0.1% or more.

Output size

In 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.

@pkg-pr-new

pkg-pr-new Bot commented Dec 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9503

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9503

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9503

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9503

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9503

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9503

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9503

commit: 0af7037

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

@cknitt

cknitt commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T07:20:18.815234Z 0af7037 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cknitt
cknitt marked this pull request as ready for review December 2, 2026 07:19
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 0af703747b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@cknitt
cknitt requested a review from cristianoc December 2, 2026 07:25
@cknitt
cknitt enabled auto-merge (squash) December 2, 2026 07:26

@cristianoc cristianoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cknitt
cknitt merged commit 653cfc0 into master Dec 2, 2026
23 checks passed
@cknitt
cknitt deleted the null-merge-source-map branch December 2, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Source maps change how null and undefined checks are printed

2 participants