Skip to content

Support ReScript 12 and 13 in dependency and value usage analysis - #10

Merged
mununki merged 4 commits into
mainfrom
rescript-compiler-compat
Oct 21, 2026
Merged

mununki merged 4 commits into
mainfrom
rescript-compiler-compat

Conversation

@mununki

@mununki mununki commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Resolves #6

Summary

  • Fix the segfault in value usage analysis (-vb) on ReScript 12 builds. .cmt typed trees are read with the layout of the compiler that wrote them, through one backend per release (Compiler_v11, Compiler_v12, Compiler_v13) selected in lib/compilers.ml by the CMT magic number, the cmt_infos layout and, where several releases write the same CMT format, the compiler version in lib/bs/compiler-info.json
  • Fix dependency analysis for projects with "namespace": true: app-Ns.cmt is now matched with app.ast, so imports are filtered again. Unused imports and ReScript 12 runtime modules (Stdlib_*, Primitive_*) no longer show up as dependencies, the generated namespace module is no longer a node, and -vb works in namespaced projects
  • Read .ast headers by their byte length instead of treating it as a module count
  • Read the ReScript 12 dependencies / dev-dependencies fields of rescript.json when resolving external modules
  • Support the ReScript 13.0 alphas. ReScript 12 and 13.0.0-alpha.1 to alpha.5 all write the same CMT format, but alpha.4 changed the typed tree in place, so the version decides: alpha.1 to alpha.3 and alpha.5 use the ReScript 12 decoder (extended with the constructors alpha.5 appends), alpha.6 has its own decoder, and alpha.4 gets the dependency graph with -6 from -vb
  • Stop with an error on .cmt files from unknown compilers instead of silently producing an empty graph, and skip constructors added by later releases instead of misreading them

Supported ReScript versions

ReScript Dependency graph Value usage (-vb)
11.0.0 - 11.1.4 Yes Yes
12.0.0 - 12.3.1 Yes Yes
13.0.0-alpha.1 - alpha.3, alpha.5, alpha.6 Yes Yes
13.0.0-alpha.4 Yes No (-6)

Other versions of a supported CMT format (for example a later 13.0 prerelease) get the dependency graph, and -6 from -vb until their typed tree has been checked.

Tests

  • Add ReScript 12 and 13 fixture workspaces (test/rescript12, test/rescript13), each with a standard and a namespaced project built from the same sources as test/rescript
  • Add test_value_usage (same -vb counts on ReScript 11, 12 and 13, plus a ReScript 13 module using for...of, continue, template literals and object literals) and test_compilers (compiler identification by format and version, decoder guards; runs under dune runtest)
  • Checked by hand on builds made with 11.0.0, 11.0.1, 13.0.0-alpha.3, alpha.4 and alpha.5, which have no fixtures
  • Fixture workspace packages are built one at a time, since parallel builds corrupt their shared compiled @rescript/react

- Decode typed trees with the layout of the compiler that wrote each .cmt
  file (ReScript 11 vs 12, told apart by the cmt_infos size), fixing the
  segfault in -vb on ReScript 12 builds
- Resolve the .ast file of namespaced modules (app-Ns.cmt -> app.ast) so
  imports are filtered again, drop the generated namespace module from the
  graph, and normalize namespaced value paths for -vb
- Read .ast headers by their byte length instead of as a module count
- Read the ReScript 12 dependencies/dev-dependencies fields of rescript.json
- Filter ReScript 12 runtime modules (Stdlib_*, Primitive_*)
- Align the vendored ReScript 11 typedtree with the compiler layout
- Add ReScript 12 fixture projects (standard and namespaced) with graph and
  value usage regression tests
- Identify the compiler of each .cmt file from its magic number and
  cmt_infos layout (lib/compilers.ml), and decode typed trees with one
  backend per release (Compiler_v11, Compiler_v12)
- Keep typed trees opaque in the vendored Cmt_format and accept every CMT
  format version when reading; rename the ReScript 11 typedtree to
  Typedtree_v11
- Support ReScript 13 (13.0.0-alpha.6) for the dependency graph; value
  usage analysis reports -6 for compilers it cannot decode yet
- Stop with an error on .cmt files from unknown compilers instead of
  silently producing an empty graph
- Skip constructors added by later releases in the decoders instead of
  matching on unknown tags
- Add ReScript 13 fixture projects, self-contained compiler identification
  tests, and build fixture workspace packages one at a time so they do not
  corrupt their shared compiled dependencies
- Document the supported ReScript versions and how to add a release
- Pick the typed tree decoder from the compiler version in
  lib/bs/compiler-info.json where several releases write the same CMT
  format: ReScript 12 and 13.0.0-alpha.1 to alpha.5 all write
  Caml1999T022 with 14 fields, but alpha.4 inserted constructors in the
  middle of expression_desc and crashed -vb on for...of loops
- Read 13.0.0-alpha.1 to alpha.3 and alpha.5 with the ReScript 12 decoder,
  extended with the constructors alpha.5 appends (for...of, break,
  continue), and report -6 for alpha.4 and versions not checked yet
- Add a decoder for the 13.0.0-alpha.6 typed tree (Typedtree_v13,
  Compiler_v13)
- Add a module using ReScript 13 syntax to the ReScript 13 fixtures and
  test value usage there, plus version identification tests
@mununki
mununki merged commit 16ea5c8 into main Oct 21, 2026
1 check passed
@mununki
mununki deleted the rescript-compiler-compat branch October 21, 2026 14:35
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.

Namespace breaks the analysis of dependencies

1 participant