Skip to content

Bump the magic numbers at release time instead of in pull requests - #9000

Merged
cknitt merged 4 commits into
masterfrom
magic-numbers-at-release
Oct 23, 2026
Merged

cknitt merged 4 commits into
masterfrom
magic-numbers-at-release

Conversation

@cknitt

@cknitt cknitt commented Oct 23, 2026

Copy link
Copy Markdown
Member

Closes #8947.

Pull requests no longer bump the .cmi, .cmt and .ast magic numbers in compiler/ext/config.ml, so parallel PRs stop conflicting on them.

  • Release-time bump. yarn changelog:release bumps each counter when compiler/ml, compiler/ext or compiler/flow_parser changed since the previous release tag (git describe, excluding the tag of the version being released). These are the ml library and the libraries it depends on, so they cover every serialized type and the types they reference. A counter that already differs from the tag is left alone, so running the release step again for the same version doesn't bump twice. The bump runs after all validation and before anything is written.
  • CI guard. The changelog check fails a PR without the changelog:release label that bumps a counter. Switching to another prefix is allowed.
  • Own prefixes. .cmi/.cmt move from Caml1999I040/Caml1999T048 to ResCmi040/ResCmt048. OCaml's numbers count up toward the same values (OCaml 5.5 writes Caml1999I037), so OCaml tools would eventually accept our files. Both numbers stay the same length, since .cmt reading compares one header with both.
  • Errors. A .cmi with a Caml1999I… header is reported as built by an older version. The message now says ReScript instead of OCaml.
  • Docs. The release step in CONTRIBUTING.md, changes/README.md and compiler/AGENTS.md now describe the new process.

There is one deliberate difference from the issue text: all four numbers use the same source directories. A per-format file list (e.g. parsetree.ml only) would miss dependencies such as External_ffi_types and String_literal. Bumping too often is harmless.

For the first release after this PR, the dry run against v13.0.0-alpha.6 bumps nothing: the new prefixes and the .ast bumps made since that tag already make every number differ from it.

Existing open PRs that bump a number will conflict with this one once more. After rebasing, they should drop the bump, or the new check fails.

New tests

  • scripts/magicNumbers.test.js: counter increments, bump rules (already-bumped numbers, previous release with other prefixes or without config.ml), and a temporary git repo with release tags covering unrelated changes, uncommitted changes, reruns once the version's tag exists, and the next release. Also the PR guard.
  • scripts/changelog.test.js: run("release") writes the bumped config.ml.
  • tests/build_tests/cmi_magic_number: new .cmi files start with ResCmi…. Legacy, older, newer and unrelated headers each get the right error.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QFCgV9acRwi6ohFaj9atR8

@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.29%. Comparing base (f26ccd0) to head (090f711).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9000      +/-   ##
==========================================
+ Coverage   81.27%   81.29%   +0.01%     
==========================================
  Files         456      456              
  Lines       63834    63836       +2     
==========================================
+ Hits        51882    51893      +11     
+ Misses      11952    11943       -9     
Files with missing lines Coverage Δ
compiler/ext/config.ml 100.00% <ø> (ø)
compiler/ml/cmi_format.ml 95.74% <100.00%> (+20.18%) ⬆️
🚀 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.

@cknitt

cknitt commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T16:31:17.882673Z 090f711 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 93dae5cdae

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

Comment thread scripts/magicNumbers.js Outdated
cknitt and others added 3 commits October 23, 2026 16:17
Why:
    Every pull request that changed a serialized type bumped the .cmi, .cmt
    or .ast magic number, so parallel pull requests kept conflicting on the
    same lines of config.ml. `yarn changelog:release` now bumps each counter
    when compiler/ml, compiler/ext or compiler/flow_parser changed since the
    previous release tag, and the changelog check rejects pull requests that
    bump one. The .cmi and .cmt numbers switch to ResCmi/ResCmt prefixes:
    with OCaml's Caml1999 prefix, they run into the numbers of OCaml
    releases (OCaml 5.5 writes Caml1999I037), and OCaml tools would take our
    files for theirs (#8947).

Diagnostic modified (.cmi from an earlier compiler):
Before (diagnostic):
    A.cmi
    is not a compiled interface for this version of OCaml.
    It seems to be for an older version of OCaml.
After (diagnostic):
    A.cmi
    is not a compiled interface for this version of ReScript.
    It seems to be for an older version of ReScript.

Review: Why not derive the magic numbers from a digest of the types? Tools that read .cmi files need a stable number per release that only changes when the format may have changed; a digest changes on every release and has no order.
Review: What about two dev builds that share a counter? Both build systems clean a package when the bsc hash changes, so only mixing files from different builds by hand reads a mismatched layout.
Breaking: Tools that check for Caml1999I/Caml1999T magic numbers have to look for ResCmi/ResCmt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QFCgV9acRwi6ohFaj9atR8
Signed-off-by: Christoph Knittel <ck@cca.io>
yarn typecheck rejected their implicitly typed parameters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QFCgV9acRwi6ohFaj9atR8
Signed-off-by: Christoph Knittel <ck@cca.io>
Codex review: git describe took the nearest tag, so a maintenance branch merged into master made its newer tag of an older line, with other magic numbers, the previous release, and no number was bumped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QFCgV9acRwi6ohFaj9atR8
Signed-off-by: Christoph Knittel <ck@cca.io>
@rescript-lang rescript-lang deleted a comment from github-actions Bot Oct 23, 2026
@rescript-lang rescript-lang deleted a comment from github-actions Bot Oct 23, 2026
@cknitt
cknitt force-pushed the magic-numbers-at-release branch from 93dae5c to 857f88e Compare October 23, 2026 16:19
@cknitt

cknitt commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

@codex review

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Semantic Diff

4 commits · 090f711 · Oct 23, 2026, 16:25 UTC · Full page

Bump the magic numbers at release time instead of in pull requests

1c5a168 · Christoph Knittel + Claude · Oct 23, 2026, 15:51 UTC

Why

Every pull request that changed a serialized type bumped the .cmi, .cmt or .ast magic number, so parallel pull requests kept conflicting on the same lines of config.ml. yarn changelog:release now bumps each counter when compiler/ml, compiler/ext or compiler/flow_parser changed since the previous release tag, and the changelog check rejects pull requests that bump one. The .cmi and .cmt numbers switch to ResCmi/ResCmt prefixes: with OCaml's Caml1999 prefix, they run into the numbers of OCaml releases (OCaml 5.5 writes Caml1999I037), and OCaml tools would take our files for theirs (#8947).

Diagnostic modified (.cmi from an earlier compiler)

diagnostic

 A.cmi
-is not a compiled interface for this version of OCaml.
-It seems to be for an older version of OCaml.
+is not a compiled interface for this version of ReScript.
+It seems to be for an older version of ReScript.

⚠️ Breaking: Tools that check for Caml1999I/Caml1999T magic numbers have to look for ResCmi/ResCmt.

Review

  • Why not derive the magic numbers from a digest of the types? Tools that read .cmi files need a stable number per release that only changes when the format may have changed; a digest changes on every release and has no order.
  • What about two dev builds that share a counter? Both build systems clean a package when the bsc hash changes, so only mixing files from different builds by hand reads a mismatched layout.
Type the helpers of the cmi_magic_number build test

36bdb7b · Christoph Knittel + Claude · Oct 23, 2026, 16:11 UTC

yarn typecheck rejected their implicitly typed parameters.

Compare the magic numbers with the highest release below the version

857f88e · Christoph Knittel + Claude · Oct 23, 2026, 16:19 UTC

Codex review: git describe took the nearest tag, so a maintenance branch merged into master made its newer tag of an older line, with other magic numbers, the previous release, and no number was bumped.

✨ Install dependencies in the changelog workflow

090f711 · Christoph Knittel + Claude · Oct 23, 2026, 16:24 UTC · new

Codex review: the changelog scripts now import semver, which a clean checkout lacks.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 857f88e62a

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

Comment thread .github/workflows/changelog.yml
Codex review: the changelog scripts now import semver, which a clean checkout lacks.

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

cknitt commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 090f711538

ℹ️ 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 October 23, 2026 16:32
@cknitt
cknitt marked this pull request as ready for review October 23, 2026 16:33
@cknitt
cknitt enabled auto-merge (squash) October 23, 2026 16:38
@pkg-pr-new

pkg-pr-new Bot commented Oct 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 090f711

@github-actions

Copy link
Copy Markdown

@cknitt
cknitt merged commit 6540936 into master Oct 23, 2026
26 checks passed
@cknitt
cknitt deleted the magic-numbers-at-release branch October 23, 2026 17:23
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.

Bump the .cmi / .cmt / .ast magic numbers at release time instead of in every PR

2 participants