From afe469c6c999babfb7d806b2a9d429da58c11461 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Wed, 17 Jun 2026 10:20:24 -0300 Subject: [PATCH] Support v12 CMT files in analysis 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. --- CHANGELOG.md | 1 + compiler/ml/parsetree.ml | 8 ++++---- compiler/ml/typedtree.ml | 7 +++++-- compiler/ml/typedtree.mli | 7 +++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 070c866edc8..d7782095395 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ - Fix formatting of trailing comments before `=` in let bindings. https://github.com/rescript-lang/rescript/pull/8444 - Fix analysis namespace parsing after the Yojson migration. https://github.com/rescript-lang/rescript/pull/8454 - Fix namespaced reference lookup in editor analysis. https://github.com/rescript-lang/rescript/pull/8455 +- Fix analysis segmentation fault for references after https://github.com/rescript-lang/rescript/pull/7887. https://github.com/rescript-lang/rescript/pull/8477 #### :memo: Documentation diff --git a/compiler/ml/parsetree.ml b/compiler/ml/parsetree.ml index 29207d0150b..86bf4e7ba97 100644 --- a/compiler/ml/parsetree.ml +++ b/compiler/ml/parsetree.ml @@ -290,10 +290,6 @@ and expression_desc = (* for i = E1 to E2 do E3 done (flag = Upto) for i = E1 downto E2 do E3 done (flag = Downto) *) - | Pexp_for_of of pattern * expression * expression - (* for pattern of array_expr do body_expr *) - | Pexp_for_await_of of pattern * expression * expression - (* for await pattern of iterable_expr do body_expr *) | Pexp_constraint of expression * core_type (* (E : T) *) | Pexp_coerce of expression * unit * core_type (* (E :> T) (None, T) @@ -322,6 +318,10 @@ and expression_desc = (* . *) | Pexp_await of expression | Pexp_jsx_element of jsx_element + | Pexp_for_of of pattern * expression * expression + (* for pattern of array_expr do body_expr *) + | Pexp_for_await_of of pattern * expression * expression +(* for await pattern of iterable_expr do body_expr *) (* an element of a record pattern or expression *) and 'a record_element = {lid: Longident.t loc; x: 'a; opt: bool (* optional *)} diff --git a/compiler/ml/typedtree.ml b/compiler/ml/typedtree.ml index f772a0eb64b..8149b9f4b18 100644 --- a/compiler/ml/typedtree.ml +++ b/compiler/ml/typedtree.ml @@ -119,14 +119,17 @@ and expression_desc = * expression * direction_flag * expression - | Texp_for_of of Ident.t * Parsetree.pattern * expression * expression - | Texp_for_await_of of Ident.t * Parsetree.pattern * expression * expression | Texp_send of expression * meth * expression option | Texp_letmodule of Ident.t * string loc * module_expr * expression | Texp_letexception of extension_constructor * expression | Texp_assert of expression | Texp_pack of module_expr | Texp_extension_constructor of Longident.t loc * Path.t + (* Keep new expression constructors at the end. CMT files are marshalled by + runtime constructor tag, so inserting constructors before existing ones + breaks analysis when it reads CMTs produced by older compiler versions. *) + | Texp_for_of of Ident.t * Parsetree.pattern * expression * expression + | Texp_for_await_of of Ident.t * Parsetree.pattern * expression * expression and meth = Tmeth_name of string diff --git a/compiler/ml/typedtree.mli b/compiler/ml/typedtree.mli index 538405a7691..049fafd8a8d 100644 --- a/compiler/ml/typedtree.mli +++ b/compiler/ml/typedtree.mli @@ -220,14 +220,17 @@ and expression_desc = * expression * direction_flag * expression - | Texp_for_of of Ident.t * Parsetree.pattern * expression * expression - | Texp_for_await_of of Ident.t * Parsetree.pattern * expression * expression | Texp_send of expression * meth * expression option | Texp_letmodule of Ident.t * string loc * module_expr * expression | Texp_letexception of extension_constructor * expression | Texp_assert of expression | Texp_pack of module_expr | Texp_extension_constructor of Longident.t loc * Path.t + (* Keep new expression constructors at the end. CMT files are marshalled by + runtime constructor tag, so inserting constructors before existing ones + breaks analysis when it reads CMTs produced by older compiler versions. *) + | Texp_for_of of Ident.t * Parsetree.pattern * expression * expression + | Texp_for_await_of of Ident.t * Parsetree.pattern * expression * expression and meth = Tmeth_name of string