Skip to content

Support v12 CMT files in analysis#8477

Draft
aspeddro wants to merge 1 commit into
rescript-lang:masterfrom
aspeddro:fix/cmt-v12-compat
Draft

Support v12 CMT files in analysis#8477
aspeddro wants to merge 1 commit into
rescript-lang:masterfrom
aspeddro:fix/cmt-v12-compat

Conversation

@aspeddro

@aspeddro aspeddro commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

This fixes an analysis/LSP crash when a v13 analysis binary reads v12 .cmt/.cmti files.

The change keeps the current compiler writing a new CMT magic number, while allowing the CMT reader to accept explicitly supported older CMT magic numbers. It also moves the new for...of typedtree and parsetree constructors to the end of their variants so v12 marshalled constructor tags remain stable.

Root Cause

Editor analysis reads compiled .cmt files directly. Those files are OCaml Marshal payloads containing typedtree data, so variant constructors are decoded by their runtime constructor tag/index, not by constructor name.

The for...of implementation added new constructors in the middle of existing variants:

  • Texp_for_of
  • Texp_for_await_of
  • Pexp_for_of
  • Pexp_for_await_of

That shifted the numeric tags for existing constructors after Texp_for / Pexp_for. When v13 analysis accepted or tried to read v12 CMT files, an old constructor such as Texp_send could be decoded as Texp_for_of. The payload layout is different, so Tast_iterator could then read invalid values and segfault instead of raising a catchable OCaml exception.

Why This Fix Works

Appending the new constructors preserves the tags and payload layout for every constructor that already existed in v12. That means v13 can safely read v12 CMTs for old syntax, while v13-generated artifacts can still use the new for...of constructors.

The CMT reader now uses Config.is_supported_cmt_magic_number instead of requiring exact equality with the current writer magic. This gives analysis an explicit compatibility window instead of either rejecting all older artifacts or unsafely accepting incompatible formats.

Close #8475

Keep new for...of typedtree and parsetree constructors at the end of their variants so existing marshalled constructor tags remain stable for v12 artifacts.

Allow CMT readers to accept explicitly supported older magic numbers while still writing a new magic for current artifacts.

Signed-off-by: Pedro Castro <aspeddro@gmail.com>
@aspeddro

aspeddro commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

TODO:

  • Update CHANGELOG

@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.42%. Comparing base (516e650) to head (15a9fec).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8477   +/-   ##
=======================================
  Coverage   74.42%   74.42%           
=======================================
  Files         451      452    +1     
  Lines       61459    61460    +1     
=======================================
+ Hits        45743    45744    +1     
  Misses      15716    15716           
Files with missing lines Coverage Δ
compiler/ext/config.ml 100.00% <100.00%> (ø)
compiler/ml/typedtree.ml 92.85% <ø> (ø)
🚀 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.

@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8477

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 15a9fec

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.

analysis segmentation fault for references after #7887

1 participant