Skip to content

Support v12 CMT files in analysis#8477

Merged
fhammerschmidt merged 1 commit into
rescript-lang:masterfrom
aspeddro:fix/cmt-v12-compat
Jun 17, 2026
Merged

Support v12 CMT files in analysis#8477
fhammerschmidt merged 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.

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

Close #8475

@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 (afe469c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8477   +/-   ##
=======================================
  Coverage   74.42%   74.42%           
=======================================
  Files         451      451           
  Lines       61459    61459           
=======================================
  Hits        45743    45743           
  Misses      15716    15716           
Files with missing lines Coverage Δ
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: afe469c

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.
@aspeddro aspeddro force-pushed the fix/cmt-v12-compat branch from 15a9fec to afe469c Compare June 17, 2026 13:20
@aspeddro aspeddro marked this pull request as ready for review June 17, 2026 13:21
@aspeddro

Copy link
Copy Markdown
Contributor Author

Ready for review!!

@aspeddro

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: afe469c6c9

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

@fhammerschmidt fhammerschmidt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great catch!

@fhammerschmidt fhammerschmidt enabled auto-merge (squash) June 17, 2026 13:43
@fhammerschmidt fhammerschmidt merged commit 7004d36 into rescript-lang:master Jun 17, 2026
30 checks passed
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

2 participants