Skip to content

Leave source locations out of bodies stored in .cmj files - #9470

Draft
cknitt wants to merge 1 commit into
masterfrom
strip-cmj-locations
Draft

cknitt wants to merge 1 commit into
masterfrom
strip-cmj-locations

Conversation

@cknitt

@cknitt cknitt commented Nov 28, 2026

Copy link
Copy Markdown
Member

Function bodies stored in a .cmj for other modules to inline no longer keep source locations. This is PR 1 of the plan in #8733 (problem 2.10).

Before, a stored body kept the locations of its applications, primitives and functions, and -no-keep-locs doesn't cover them. With -bs-cross-module-opt, which the runtime and Belt are built with, that meant:

  • a line shift changed the .cmj;
  • the runtime's published .cmj files contained the absolute paths of the machine that built them.

The next PR in the plan rebuilds dependents when a .cmj changes. Without this one, it would rebuild the direct dependents of a module with a .resi on every line shift. Nothing reads these locations once a body is inlined in another module.

The new Lambda_traverse.drop_locations sets every location to Location.none, building through Lambda's constructors like the rest of that module. Generated JavaScript doesn't change, for the runtime, Belt or the test suite.

New tests: two cases in ounit_lambda_traverse_tests.ml. One checks that a term with locations under nodes without them comes back with none. The other checks that a term without locations is handed back as it is.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D

Why:
    A function body stored in a .cmj for other modules to inline kept the
    locations of its applications, primitives and functions, and
    -no-keep-locs does not cover them. So with -bs-cross-module-opt a line
    shift changed the .cmj, and the runtime's published .cmj files held the
    absolute paths of the machine that built them. Rebuilding dependents when
    a .cmj changes (#8733, PR 2) would then rebuild them on every line shift.
    Nothing reads these locations once the body is inlined elsewhere.

Cmj modified (stored body):
Example:
    // A.res, compiled with -bs-cross-module-opt, then again with a blank
    // line added at the top
    @inline let g = x => x + 1
    let h = x => x * 2
    let flag = true
Before (text):
    A.cmj: 200 bytes, names /…/A.res
    after the line shift: A.cmj changes
After (text):
    A.cmj: 170 bytes, names no file
    after the line shift: A.cmj is byte for byte the same

Review: Does inlining change? No. A dependent's JS is the same, and so is
the runtime's and Belt's.

Review: Why build through Lambda's constructors? The rest of
Lambda_traverse does, so a stored body is normalized like any other term.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D
Signed-off-by: Christoph Knittel <ck@cca.io>
@github-actions

Copy link
Copy Markdown

Changelog

🏠 Internal

  • Leave source locations out of the function bodies stored in .cmj files for inlining, so a .cmj no longer changes when only line numbers do and no longer contains build paths.

Semantic Diff

1 commit · Full page

Leave source locations out of bodies stored in .cmj files

7b26dcc · cknitt + Claude · Nov 28, 2026, 20:48 UTC

Why

A function body stored in a .cmj for other modules to inline kept the locations of its applications, primitives and functions, and -no-keep-locs does not cover them. So with -bs-cross-module-opt a line shift changed the .cmj, and the runtime's published .cmj files held the absolute paths of the machine that built them. Rebuilding dependents when a .cmj changes (#8733, PR 2) would then rebuild them on every line shift. Nothing reads these locations once the body is inlined elsewhere.

Cmj modified (stored body)

// A.res, compiled with -bs-cross-module-opt, then again with a blank
// line added at the top
@inline let g = x => x + 1
let h = x => x * 2
let flag = true

text

-A.cmj: 200 bytes, names /…/A.res
-after the line shift: A.cmj changes
+A.cmj: 170 bytes, names no file
+after the line shift: A.cmj is byte for byte the same

Review

  • Does inlining change? No. A dependent's JS is the same, and so is the runtime's and Belt's.
  • Why build through Lambda's constructors? The rest of Lambda_traverse does, so a stored body is normalized like any other term.

@codecov

codecov Bot commented Nov 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.35%. Comparing base (e51ee46) to head (7b26dcc).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9470   +/-   ##
=======================================
  Coverage   82.34%   82.35%           
=======================================
  Files         462      462           
  Lines       65817    65843   +26     
=======================================
+ Hits        54198    54222   +24     
- Misses      11619    11621    +2     
Files with missing lines Coverage Δ
compiler/backend/lam_stats_export.ml 93.47% <100.00%> (+0.14%) ⬆️
compiler/typing/lambda_traverse.ml 94.35% <100.00%> (+0.26%) ⬆️
tests/ounit_tests/ounit_lambda_traverse_tests.ml 100.00% <100.00%> (ø)

... and 1 file 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

Copy link
Copy Markdown

🎉 Compiler benchmarks

Allocated words

In total: 656,997,638 → 656,987,142 (±0.00%).

Generated projects: 629,285,350 → 629,285,160 (±0.00%).

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

Instructions

In total: 9,223,996,068 → 9,224,178,313 (±0.00%).

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

Output size

In total: 26,710,059 → 26,696,844 (-0.05%).

🎉 Improvement: 2 outputs are more than 1% smaller.

Benchmark Base Head Change
output/belt/*.cmj 42,889 33,211 -22.57%
output/runtime/*.cmj 19,973 17,059 -14.59%
output/tests/*.cmj 95,299 94,424 -0.92%

Pull request 7b26dcc compared with base e51ee46 in this run.

@pkg-pr-new

pkg-pr-new Bot commented Nov 28, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 7b26dcc

@github-actions

Copy link
Copy Markdown

This branch has not been deployed

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

1 participant