Derive the .cmi / .cmt / .ast magic numbers instead of bumping them in every PR
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 35/100
- Type d'issue
- Fonctionnalité
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- ocaml
- Domaine
- compilers
Piste de recherche
Start with compiler/ext/config.ml and inspect how the .cmi, .cmt, and .ast magic numbers are defined, then trace the serialized interfaces and release tooling described in the proposal. The work spans digest generation, release recording and counter updates, and possibly dev build suffixes and prefix changes. Done means release counters change only when serialized layouts change, outside tools can distinguish compatible releases, and the changelog notes the prefix change.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Problem
compiler/ext/config.ml holds hand-numbered magic numbers for .cmi (Caml1999I036), .cmt (Caml1999T043) and marshaled .ast files (ResImpl01315 / ResIntf01315). Every PR that changes a serialized type bumps them, so parallel PRs constantly conflict on the same lines. That's the same problem we had with CHANGELOG.md before fragments. There have been about 20 bumps since August.
The per-PR precision buys nothing:
- Rebuilds after a compiler change are driven by
bsc_hash, which both build systems store, not by the magic numbers. - Outside tools only ever see released versions, so intermediate bumps between two releases are invisible to them.
- A bump forgotten in a PR fails silently: mixing files across a layout change crashes in
Marshalinstead of giving a clean error.
The Caml1999 prefix is a separate problem. OCaml 5.5 uses Caml1999I037 / Caml1999T037, so our I036 is most likely a real OCaml release's .cmi number, and the next bump would collide with OCaml 5.5. An OCaml tool would then accept a ReScript .cmi and misread it, instead of rejecting it.
What outside tools need
Tools that read .cmi/.cmt files may rely on the magic number. They need:
- A stable number for each release.
- A change between releases only when the format may have changed, so they can tell that two releases share a format.
- Ordering, for "built by a newer compiler" checks (
cmi_format.mlalready uses it for its older/newer error).
Proposal
Bump the counters at release time, not in PRs:
- A dune rule computes a digest of the interfaces whose values are serialized. For
.cmithat istypes,path,ident,parsetree, …; for.cmtaddtypedtree; for.astit isparsetree. Prefer whole directories or dune's cmi digests over a hand-picked file list, which would go stale like manual bumps do. - A checked-in file records the counter and digest from the last release. PRs never touch it.
- The release script, or a CI check on release PRs, compares the current digest with the recorded one. If they differ, it bumps the counter and records the new digest. Comment-only edits cause harmless extra bumps.
- Optional: dev builds append the digest (e.g.
…037+3fa9c1d2), so mixing two dev builds that share a counter but differ in layout gives a clean error instead of a crash. Releases ship the bare counter. - Switch to our own prefixes (e.g.
ResCmi…/ResCmt…, like the.astnumbers already did), so OCaml tools reject our files. Note this in the changelog because outside tools will see it.
Not in scope: .cmj has no magic number yet, only a digest of its own content (js_cmj_format.ml has a TODO). It could get a counter under the same scheme. The frozen Parsetree0 PPX numbers (Caml1999M022 / N022) must never change and stay as they are.
Alternatives considered
- The compiler version as the magic number. Stable per release and never touched by PRs. However, it changes on every release even when the format didn't, it has no meaningful ordering across prereleases, and dev builds sharing a version can't detect a layout mismatch.
- A pure content digest. Exact and never conflicts, but outside tools can't see that two releases share a format, and there's no ordering.
- Langage dominant
- OCaml
- Étoiles
- 7.5k
- Forks
- 483
- Merge moyen
- 21 h 8 min
- PR mergées (30 j)
- 183
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de rescript-lang/rescript
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
rescript-lang/rescript#8996 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 1-2 jours Accessibilité débutants 70/100
rescript-lang/rescript#8997 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 1-2 jours Accessibilité débutants 55/100
rescript-lang/rescript#8995 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
rescript-lang/rescript#8994 ·
Les mainteneurs répondent en général sous 1 jour
-
Issues from differential semantic drift analysis (a7721303 to b123b7c3)Peut-être pris @cknitt l’a pris aujourd’hui. Ouverte
rescript-lang/rescript#8980 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de rescript-lang/rescript
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
bug P2
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
Les mainteneurs répondent en général sous 1 jour
-
duplicate
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
numba/numba#10939 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Quantinuum/tket#2255 ·
Les mainteneurs répondent en général sous 1 jour