Skip to content

Type @inline constants in the type checker, keep their attributes and allow annotations - #9467

Merged
cknitt merged 5 commits into
masterfrom
inline-const-typer
Nov 29, 2026
Merged

cknitt merged 5 commits into
masterfrom
inline-const-typer

Conversation

@cknitt

@cknitt cknitt commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

The type checker now handles @inline constants itself. Before, the frontend rewrote @inline let x = 1 and @inline(1) let x: int into external x: int = "#rescript-inline", and the type checker decoded that again.

The rewrite dropped all other attributes. So @deprecated on an @inline constant never warned, and its doc comment was lost. Both are now kept. The reserved "#rescript-inline" primitive name is gone too.

This is the @inline item of #8624 and proposal 2 of #8733, done the way #8728 handled FFI attributes: the attribute stays as written, and the parsetree doesn't change.

Annotated constants such as @inline let x: int = 3 are now inlined too. Before, they were ordinary values with warning 53. The annotation is checked as for an ordinary let: an alias is kept, _ and type variables take the literal's type, and anything else is an error: "This @inline constant has type int, but it is annotated with type float." Like other @inline constants, they're no longer exported to JavaScript or by genType. Otherwise no JavaScript output changes.

As for a plain let, the .cmi keeps only an @inline constant's @deprecated attributes; the .cmt, which editors read, keeps all of them.

Benchmarks: Stdlib_Ordering.res allocates about 1.25% more. Its three @inline constants have long doc comments, which are now kept instead of thrown away. Everything else is flat or allocates less.

New tests:

  • Cross_deprecated_inline_const (multi-file error test): a deprecated @inline constant from a module and from an interface warns at its use in another module, not inside its own module.
  • inline_const_annotated.res and inline_const_annotated_use.res (JS output tests): annotated constants are inlined, including through an alias, char, _ and 'a. A module using it from outside still sees its plain int values as int.
  • inline_const_annotation_mismatch.res (error test): an annotation that isn't the literal's type.
  • inline_const_annotation_deprecated_type.res (error test): a deprecated type in an annotation warns once, and not under the binding's @warning("-3").
  • inline_const_not_a_constant.res (error test): @inline let x: 'a. int = … and @inline let _ = … stay ordinary values with the usual warnings.
  • InlineConstants.res (ast-mapping fixture): @inline constants round-trip through the v0 AST.

The external_reserved_inline_primitive error test is removed along with the error.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D

Why:
    The frontend rewrote `@inline let x = 1` and `@inline(1) let x: int`
    into `external x: int = "#rescript-inline"`, whose only attribute was
    the `@inline` payload, and the type checker decoded that again. The
    rewrite dropped every other attribute, so a deprecated `@inline`
    constant warned nowhere and its doc comment was lost. The type checker
    now reads `@inline` itself, as it does FFI attributes since #8728, and
    the reserved primitive name is gone. This is the `@inline` item of
    #8624 and proposal 2 of #8733.

AST modified (expanded tree):
Example:
    /** The old limit. */
    @deprecated("Use newLimit instead") @inline
    let limit = 10
Before (expanded):
    structure_item
      Pstr_primitive
      value_description "limit"
        attribute  "inline"
          [
            structure_item
              Pstr_eval
              expression
                Pexp_constant PConst_int (10,None)
          ]
        core_type
          Ptyp_constr "int"
          []
        "#rescript-inline"
After (expanded): the binding as written
    structure_item
      Pstr_value Nonrec
      [
        <def>
            attribute  "res.doc"
              …
            attribute  "deprecated"
              …
            attribute  "inline"
              []
          pattern
            Ppat_var "limit"
          expression
            Pexp_constant PConst_int (10,None)
      ]

Typedtree modified (inline constant):
Before (typed):
    structure_item
      Tstr_primitive
      value_description limit/1001
        core_type
          Ttyp_constr "int/1"
          []
        <inline const>
After (typed):
    structure_item
      Tstr_primitive
      value_description limit/1001
        attribute "deprecated"
          …
        attribute "res.doc"
          …
        core_type
          Ttyp_constr "int/1"
          []
        <inline const>

Diagnostic added (deprecated inline constant):
Example:
    // User.res
    let a = Legacy.limit
Before (diagnostic): none
After (diagnostic):
    Warning number 3
    User.res:1:9-20

    deprecated: Legacy.limit
    Use newLimit instead

Diagnostic removed (reserved primitive):
Example:
    external answer: int = "#rescript-inline"
Before (diagnostic):
    "#rescript-inline" is reserved for @inline constants
After (diagnostic): none; it is an unknown primitive like any other `#` name

Review: Does the generated JavaScript change? No. The typed tree is the
same `Tstr_primitive` with `Kind_inline_const`, and every `tests/tests`
output is unchanged.

Review: Why does `Ast_checks` call `inline_const_of_binding`? The general
literal check runs before type checking and would add warning 107 to the
out-of-range `@inline` int error. Calling it first reports only the
error, as the frontend rewrite did.

Review: Is an annotated binding such as `@inline let x: int = 3` inlined
now? No, it stays an ordinary exported value with warning 53. Inlining it
would remove its JavaScript export, so that is left for a separate
decision.

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

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Keep @deprecated and doc comments on @inline constants, so uses from other modules warn and editors show the doc.
  • Inline @inline constants with a type annotation, such as @inline let x: int = 3, instead of ignoring the attribute with warning 53. Like other @inline constants, they are no longer exported to JavaScript or by genType.

Semantic Diff

5 commits · Full page

Type @inline constants in the type checker and keep their attributes

0a953dc · cknitt + Claude · Nov 28, 2026, 19:46 UTC

Why

The frontend rewrote @inline let x = 1 and @inline(1) let x: int into external x: int = "#rescript-inline", whose only attribute was the @inline payload, and the type checker decoded that again. The rewrite dropped every other attribute, so a deprecated @inline constant warned nowhere and its doc comment was lost. The type checker now reads @inline itself, as it does FFI attributes since #8728, and the reserved primitive name is gone. This is the @inline item of #8624 and proposal 2 of #8733.

AST modified (expanded tree)

/** The old limit. */
@deprecated("Use newLimit instead") @inline
let limit = 10

expanded · After: the binding as written

 structure_item
-  Pstr_primitive
-  value_description "limit"
-    attribute  "inline"
-        structure_item
-          Pstr_eval
-          expression
-            Pexp_constant PConst_int (10,None)
-    core_type
-      Ptyp_constr "int"
-      []
-    "#rescript-inline"
+  Pstr_value Nonrec
+    <def>
+        attribute  "res.doc"
+          …
+        attribute  "deprecated"
+          …
+        attribute  "inline"
+          []
+      pattern
+        Ppat_var "limit"
+      expression
+        Pexp_constant PConst_int (10,None)

Typedtree modified (inline constant)

typed

 structure_item
   Tstr_primitive
   value_description limit/1001
+    attribute "deprecated"
+      …
+    attribute "res.doc"
+      …
     core_type
       Ttyp_constr "int/1"
       []
     <inline const>

Diagnostic added (deprecated inline constant)

// User.res
let a = Legacy.limit

diagnostic

-none
+Warning number 3
+User.res:1:9-20
+
+deprecated: Legacy.limit
+Use newLimit instead

Diagnostic removed (reserved primitive)

external answer: int = "#rescript-inline"

diagnostic

-"#rescript-inline" is reserved for @inline constants
+none; it is an unknown primitive like any other `#` name

Review

  • Does the generated JavaScript change? No. The typed tree is the same Tstr_primitive with Kind_inline_const, and every tests/tests output is unchanged.
  • Why does Ast_checks call inline_const_of_binding? The general literal check runs before type checking and would add warning 107 to the out-of-range @inline int error. Calling it first reports only the error, as the frontend rewrite did.
  • Is an annotated binding such as @inline let x: int = 3 inlined now? No, it stays an ordinary exported value with warning 53. Inlining it would remove its JavaScript export, so that is left for a separate decision.
Inline annotated @inline constants

ffb8d09 · cknitt + Claude · Nov 28, 2026, 19:55 UTC

Why

@inline let x: int = 3 was an ordinary value with warning 53, because only a binding without a type annotation was turned into a constant. The author asked for inlining, and the annotation says no more than the literal does. The annotation must be the literal's type, possibly through an alias, since the constant is inlined with the literal's representation.

JS modified (annotated constant)

// A.res
type id = int
@inline let typed: int = 3
@inline let aliased: id = 4

// U.res
let u = (A.typed, A.aliased)

js · A.mjs

-let typed = 3;
-
-let aliased = 4;
-
-export {
-  typed,
-  aliased,
-}
+/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

js · U.mjs

-import * as A from "./A.mjs";
-
 let u = [
-  A.typed,
-  A.aliased
+  3,
+  4
 ];

Diagnostic removed (annotated constant)

diagnostic

-Warning number 53
-A.res:2:1-26
-
-the @inline attribute cannot appear in this context
+none

Diagnostic added (annotation mismatch)

@inline let ratio: float = 3

diagnostic · Before: the ordinary let mismatch

-This has type: int
-But it's expected to have type: float
+This @inline constant has type int, but it is annotated with type float.

Review

  • Can an annotation hide the literal's type, as in type t and @inline let x: t = 3? No. The annotation must equal the literal's type after expanding aliases, so an abstract type, a type variable or option<int> is an error. An interface can still give an @inline constant an abstract type.
  • Is @inline let x: type a. int = 3 inlined? No. A type a. annotation keeps the binding an ordinary let.
Do less work for each @inline constant

35d909b · cknitt + Claude · Nov 28, 2026, 20:31 UTC

The allocation benchmark flagged Stdlib_Ordering.res (+1.43% allocated words): its three @inline constants keep their doc comments now, and each one was also built twice and type-compared. The early range check now only reads the literal, the type comparison runs only for an annotated binding, and attributes are copied only when there is a @deprecated. The file now allocates 0.79% more than on master, which is the doc comments.

Let the literal fill in type variables in an @inline annotation

ed5b1e8 · cknitt + Claude · Nov 29, 2026, 06:51 UTC

Why

An annotated @inline constant was compared with the literal's type for equality, so @inline let x: _ = 3 and @inline let x: 'a = 3 were rejected, although an ordinary let accepts them and they compiled before this pull request. The annotation is now unified with the literal's type, as for a let. A Codex review found this.

Diagnostic removed (annotation with a type variable)

@inline let x: _ = 3
let y = x

diagnostic

-This @inline constant has type int, but it is annotated with type 'a.
+none; `x` is the inline constant 3 of type int

js · After

let y = 3;

Review

  • Which type does the constant get? The annotation when it has no type variables, so an alias such as id is kept, and otherwise the literal's type. float, an abstract type or option<'a> are still errors.
✨ Check an @inline annotation once, against a fresh literal type

d46c901 · cknitt + Claude · Nov 29, 2026, 07:08 UTC · new

Why

A review by Claude (Fable model) found that the annotation check could corrupt the compilation unit. It unified the annotation with Predef's shared int node, so after @inline let x: id = 4 every later int in the file, and in its .cmi, became id, and @inline let x: char = 97 overflowed the stack, since char is defined as that node. It also translated the annotation twice, the first time outside the binding's @warning scope, which doubled or unsilenced warnings. And 'a. int annotations and @inline let _ = … were treated like constants.

Typing modified (annotated @inline constant)

text · Before: Typemod, then Typedecl.transl_value_decl · After: Typedecl.transl_value_decl, inside the binding's warning scope

-translate the annotation, unify it with Predef's shared type_int ()
-translate the annotation again, as a type scheme
+translate the annotation once, unify it with a fresh int, string, float, bool or bigint
+on failure, undo the unification, then report it

Diagnostic modified (a dependent of a module with an alias constant)

// D2.res
module M = {
  type id = int
  @inline let al: id = 4
}
let one = 1
// U.res
let a = D2.one + 1

diagnostic

-This has type: id
-But it's expected to have type: int
+none

Diagnostic modified (char annotation)

@inline let x: char = 97

diagnostic

-Fatal error: exception Stack overflow
+none; `x` is the inline constant 97 of type char

Representation modified (an @inline constant's attributes)

mapping

-.cmi ↦ every attribute but @inline, doc comments included
+.cmi ↦ only @deprecated, as for a plain let
+.cmt ↦ every attribute but @inline, in source order, for editors

Review

  • Which bindings count as constants? Ast_checks and the type checker now share one test, Ast_external_mk.inline_binding: a single non-recursive let of a name, with no annotation or one that is not type a. or 'a.. @inline let _ = … and @inline let y: 'a. int = 3 are ordinary values with warning 53, as on master.

Why:
    `@inline let x: int = 3` was an ordinary value with warning 53, because
    only a binding without a type annotation was turned into a constant.
    The author asked for inlining, and the annotation says no more than the
    literal does. The annotation must be the literal's type, possibly
    through an alias, since the constant is inlined with the literal's
    representation.

JS modified (annotated constant):
Example:
    // A.res
    type id = int
    @inline let typed: int = 3
    @inline let aliased: id = 4

    // U.res
    let u = (A.typed, A.aliased)
Before (js): A.mjs
    let typed = 3;

    let aliased = 4;

    export {
      typed,
      aliased,
    }
After (js): A.mjs
    /* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */
Before (js): U.mjs
    import * as A from "./A.mjs";

    let u = [
      A.typed,
      A.aliased
    ];
After (js): U.mjs
    let u = [
      3,
      4
    ];

Diagnostic removed (annotated constant):
Before (diagnostic):
    Warning number 53
    A.res:2:1-26

    the @inline attribute cannot appear in this context
After (diagnostic): none

Diagnostic added (annotation mismatch):
Example:
    @inline let ratio: float = 3
Before (diagnostic): the ordinary `let` mismatch
    This has type: int
    But it's expected to have type: float
After (diagnostic):
    This @inline constant has type int, but it is annotated with type float.

Review: Can an annotation hide the literal's type, as in `type t` and
`@inline let x: t = 3`? No. The annotation must equal the literal's type
after expanding aliases, so an abstract type, a type variable or
`option<int>` is an error. An interface can still give an `@inline`
constant an abstract type.

Review: Is `@inline let x: type a. int = 3` inlined? No. A `type a.`
annotation keeps the binding an ordinary `let`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt cknitt changed the title Type @inline constants in the type checker and keep their attributes Type @inline constants in the type checker, keep their attributes and allow annotations Nov 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

🎉 Compiler benchmarks

Allocated words

In total: 658,600,291 → 658,911,438 (+0.05%).

Generated projects: 629,278,417 → 629,861,705 (+0.09%).

🎉 Improvement: 1 benchmark allocates more than 1% less.

Benchmark Base Head Change
packages/@rescript/belt/src/Belt_List.resi 758,750 750,202 -1.13%
packages/@rescript/runtime/Stdlib_List.resi 409,869 406,215 -0.89%
packages/@rescript/belt/src/Belt_Array.resi 650,342 644,889 -0.84%
packages/@rescript/belt/src/Belt_Option.resi 243,380 241,438 -0.80%
packages/@rescript/runtime/Stdlib_BigInt.resi 186,575 185,253 -0.71%
packages/@rescript/runtime/Stdlib_Ordering.res 152,472 153,550 +0.71%
packages/@rescript/belt/src/Belt_MutableSet.resi 397,552 394,818 -0.69%
packages/@rescript/runtime/Stdlib_Int.resi 206,109 204,702 -0.68%
packages/@rescript/belt/src/Belt_MutableQueue.resi 207,332 205,928 -0.68%
packages/@rescript/belt/src/Belt_SetDict.resi 402,686 400,030 -0.66%
84 more changes
Benchmark Base Head Change
packages/@rescript/belt/src/Belt_Set.resi 437,444 434,578 -0.66%
packages/@rescript/runtime/Stdlib_JSON.resi 237,033 235,516 -0.64%
packages/@rescript/belt/src/Belt_Map.resi 579,477 575,837 -0.63%
packages/@rescript/runtime/Stdlib_Option.resi 236,513 235,089 -0.60%
packages/@rescript/belt/src/Belt_SetString.resi 259,928 258,460 -0.56%
packages/@rescript/belt/src/Belt_SetInt.resi 260,055 258,587 -0.56%
packages/@rescript/belt/src/Belt_HashMap.resi 296,914 295,242 -0.56%
packages/@rescript/runtime/Stdlib_JsError.resi 184,974 183,965 -0.55%
packages/@rescript/runtime/Stdlib_Null.resi 204,437 203,323 -0.54%
packages/@rescript/runtime/Stdlib_Nullable.resi 199,678 198,616 -0.53%
packages/@rescript/runtime/Stdlib_Result.resi 296,383 294,829 -0.52%
packages/@rescript/belt/src/Belt_MapString.resi 391,314 389,270 -0.52%
packages/@rescript/belt/src/Belt_MapInt.resi 391,357 389,313 -0.52%
packages/@rescript/belt/src/Belt_MutableMapString.resi 314,999 313,453 -0.49%
packages/@rescript/belt/src/Belt_MutableMapInt.resi 315,117 313,571 -0.49%
packages/@rescript/runtime/Stdlib_Float.resi 194,298 193,389 -0.47%
packages/@rescript/belt/src/Belt_MutableSetString.resi 265,002 263,786 -0.46%
packages/@rescript/belt/src/Belt_MutableSetInt.resi 265,119 263,903 -0.46%
packages/@rescript/runtime/Stdlib_Iterator.resi 159,252 158,542 -0.45%
packages/@rescript/runtime/Stdlib_Array.resi 728,609 725,362 -0.45%
packages/@rescript/runtime/Stdlib_AsyncIterator.resi 177,824 177,044 -0.44%
packages/@rescript/belt/src/Belt_Result.resi 240,174 239,124 -0.44%
packages/@rescript/runtime/Stdlib_JsExn.resi 122,781 122,267 -0.42%
packages/@rescript/belt/src/Belt_Range.resi 176,663 175,963 -0.40%
packages/@rescript/belt/src/Belt_SortArray.resi 253,948 252,960 -0.39%
packages/@rescript/runtime/Stdlib_Bool.resi 116,824 116,370 -0.39%
packages/@rescript/belt/src/Belt_MapDict.resi 513,304 511,326 -0.39%
packages/@rescript/belt/src/Belt_Int.resi 149,777 149,208 -0.38%
packages/@rescript/belt/src/Belt_Float.resi 151,257 150,688 -0.38%
packages/@rescript/belt/src/Belt_MutableMap.resi 395,450 393,966 -0.38%
packages/@rescript/runtime/Stdlib_Math.resi 328,330 327,113 -0.37%
packages/@rescript/runtime/Stdlib_Dict.resi 240,857 239,992 -0.36%
packages/@rescript/runtime/Stdlib_String.resi 497,483 495,742 -0.35%
stress/InlineChain.res 3,542,096 3,553,835 +0.33%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.resi 159,931 159,411 -0.33%
packages/@rescript/runtime/Stdlib_Generator.resi 160,553 160,033 -0.32%
packages/@rescript/runtime/Stdlib_IterableIterator.resi 149,412 148,943 -0.31%
packages/@rescript/runtime/Stdlib_AsyncGenerator.resi 165,931 165,411 -0.31%
packages/@rescript/runtime/Stdlib_Date.resi 614,254 612,510 -0.28%
packages/@rescript/belt/src/Belt_MutableStack.resi 169,287 168,839 -0.26%
packages/@rescript/runtime/Stdlib_Symbol.resi 160,147 159,725 -0.26%
packages/@rescript/runtime/Stdlib_IteratorObject.resi 234,382 233,774 -0.26%
packages/@rescript/runtime/Stdlib_Lazy.resi 112,440 112,150 -0.26%
packages/@rescript/runtime/Stdlib_Console.resi 411,616 410,571 -0.25%
packages/@rescript/belt/src/Belt_SortArrayString.resi 169,583 169,155 -0.25%
packages/@rescript/belt/src/Belt_SortArrayInt.resi 169,701 169,273 -0.25%
packages/@rescript/runtime/Stdlib_Set.resi 228,959 228,397 -0.25%
parse/RedBlackTreeNoComments.res 355,142 355,958 +0.23%
packages/@rescript/runtime/Stdlib_Map.resi 217,114 216,618 -0.23%
packages/@rescript/runtime/Stdlib_Global.resi 155,554 155,204 -0.23%
parse/RedBlackTree.res 362,855 363,671 +0.22%
packages/@rescript/runtime/Stdlib_DataView.resi 268,050 267,476 -0.21%
packages/@rescript/belt/src/Belt_Map.res 982,236 984,301 +0.21%
packages/@rescript/runtime/Stdlib_RegExp.resi 187,806 187,423 -0.20%
packages/@rescript/belt/src/Belt_Option.res 389,411 390,192 +0.20%
packages/@rescript/belt/src/Belt_Set.res 858,896 860,583 +0.20%
packages/@rescript/runtime/Stdlib_Type.resi 135,952 135,722 -0.17%
packages/@rescript/belt/src/Belt_HashMapString.resi 213,720 213,368 -0.16%
packages/@rescript/belt/src/Belt_HashMapInt.resi 213,834 213,482 -0.16%
packages/@rescript/belt/src/Belt_MapInt.res 1,182,642 1,184,475 +0.15%
packages/@rescript/belt/src/Belt_MapString.res 1,183,178 1,185,011 +0.15%
packages/@rescript/runtime/Stdlib_Promise.resi 356,023 355,474 -0.15%
parse/Napkinscript.res 10,716,176 10,732,577 +0.15%
packages/@rescript/belt/src/Belt_HashSet.resi 222,784 222,452 -0.15%
packages/@rescript/belt/src/Belt_Result.res 410,003 410,588 +0.14%
packages/@rescript/runtime/Stdlib_JsError.res 229,983 230,309 +0.14%
packages/@rescript/belt/src/Belt_Array.res 2,157,430 2,160,351 +0.14%
packages/@rescript/belt/src/Belt_MutableMapString.res 1,156,078 1,157,642 +0.14%
packages/@rescript/belt/src/Belt_MutableMapInt.res 1,155,801 1,157,361 +0.13%
packages/@rescript/runtime/Stdlib_JsExn.res 173,212 173,438 +0.13%
build/Namespace/clean 84,256,729 84,363,986 +0.13%
packages/@rescript/belt/src/Belt_MutableMap.res 1,303,512 1,305,150 +0.13%
packages/@rescript/runtime/Stdlib_ArrayBuffer.resi 110,995 110,858 -0.12%
packages/@rescript/belt/src/Belt_MutableStack.res 388,048 388,516 +0.12%
packages/@rescript/belt/src/Belt_HashSetString.resi 175,559 175,359 -0.11%
packages/@rescript/belt/src/Belt_HashSetInt.resi 175,672 175,472 -0.11%
packages/@rescript/runtime/Primitive_int.res 171,986 172,181 +0.11%
packages/@rescript/runtime/Primitive_bigint.res 177,458 177,655 +0.11%
build/clean 250,301,662 250,577,999 +0.11%
packages/@rescript/belt/src/Belt_MapDict.res 1,632,534 1,634,328 +0.11%
packages/@rescript/belt/src/Belt_Range.res 288,683 288,995 +0.11%
packages/@rescript/runtime/Stdlib_Lazy.res 221,376 221,615 +0.11%
build/WideDeps/clean 371,173,403 371,559,945 +0.10%
packages/@rescript/belt/src/Belt_MutableQueue.res 792,295 793,114 +0.10%

Instructions

In total: 9,227,223,941 → 9,224,795,389 (-0.03%).

Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Math.resi 21,451,808 21,288,822 -0.76%
packages/@rescript/runtime/Stdlib_List.resi 24,677,755 24,522,892 -0.63%
packages/@rescript/runtime/Stdlib_Date.resi 34,440,248 34,225,709 -0.62%
packages/@rescript/runtime/Stdlib_String.resi 29,603,894 29,430,225 -0.59%
packages/@rescript/runtime/Stdlib_Array.resi 40,263,893 40,036,714 -0.56%
packages/@rescript/belt/src/Belt_List.resi 39,123,629 38,910,142 -0.55%
packages/@rescript/belt/src/Belt_Array.resi 33,863,617 33,687,817 -0.52%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res 24,242,703 24,130,340 -0.46%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 25,684,692 25,580,249 -0.41%
parse/RedBlackTree.res 14,994,453 14,942,497 -0.35%
6 more changes
Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 31,358,488 31,262,022 -0.31%
packages/@rescript/runtime/Stdlib_TypedArray.res 41,482,912 41,372,542 -0.27%
parse/RedBlackTreeNoComments.res 14,567,822 14,533,476 -0.24%
format/RedBlackTreeNoComments.res 24,151,297 24,101,734 -0.21%
format/RedBlackTree.res 24,496,305 24,446,742 -0.20%
packages/@rescript/runtime/JsxDOMStyle.res 95,263,652 95,156,147 -0.11%

Output size

In total: 26,829,064 → 26,830,802 (+0.01%).

None of the 13 benchmarks changed by 0.1% or more.

Pull request d46c901 compared with base 87db367 in this run.

@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.38554% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.37%. Comparing base (e51ee46) to head (d46c901).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
compiler/typing/ast_external_mk.ml 92.85% 2 Missing ⚠️
compiler/typing/typedecl.ml 96.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9467      +/-   ##
==========================================
+ Coverage   82.34%   82.37%   +0.02%     
==========================================
  Files         462      462              
  Lines       65817    65781      -36     
==========================================
- Hits        54198    54186      -12     
+ Misses      11619    11595      -24     
Files with missing lines Coverage Δ
compiler/frontend/bs_builtin_ppx.ml 90.07% <ø> (-0.42%) ⬇️
compiler/typing/ast_checks.ml 81.60% <100.00%> (+1.36%) ⬆️
compiler/typing/ast_external.ml 100.00% <100.00%> (ø)
compiler/typing/typemod.ml 77.34% <100.00%> (+0.24%) ⬆️
compiler/typing/typedecl.ml 83.88% <96.00%> (+0.18%) ⬆️
compiler/typing/ast_external_mk.ml 93.87% <92.85%> (-2.13%) ⬇️

... and 8 files with indirect coverage changes

🚀 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 Nov 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: d46c901

The allocation benchmark flagged Stdlib_Ordering.res (+1.43% allocated
words): its three @inline constants keep their doc comments now, and each
one was also built twice and type-compared. The early range check now only
reads the literal, the type comparison runs only for an annotated binding,
and attributes are copied only when there is a @deprecated. The file now
allocates 0.79% more than on master, which is the doc comments.

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

cknitt commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T07:11:16.446022Z d46c901 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: 35d909ba6e

ℹ️ 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 compiler/typing/typemod.ml Resolved
Why:
    An annotated @inline constant was compared with the literal's type for
    equality, so `@inline let x: _ = 3` and `@inline let x: 'a = 3` were
    rejected, although an ordinary `let` accepts them and they compiled
    before this pull request. The annotation is now unified with the
    literal's type, as for a `let`. A Codex review found this.

Diagnostic removed (annotation with a type variable):
Example:
    @inline let x: _ = 3
    let y = x
Before (diagnostic):
    This @inline constant has type int, but it is annotated with type 'a.
After (diagnostic): none; `x` is the inline constant 3 of type int
After (js):
    let y = 3;

Review: Which type does the constant get? The annotation when it has no
type variables, so an alias such as `id` is kept, and otherwise the
literal's type. `float`, an abstract type or `option<'a>` are still
errors.

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

cknitt commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: ed5b1e84cb

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

Why:
    A review by Claude (Fable model) found that the annotation check could
    corrupt the compilation unit. It unified the annotation with Predef's
    shared `int` node, so after `@inline let x: id = 4` every later `int`
    in the file, and in its .cmi, became `id`, and `@inline let x: char =
    97` overflowed the stack, since `char` is defined as that node. It also
    translated the annotation twice, the first time outside the binding's
    @warning scope, which doubled or unsilenced warnings. And `'a. int`
    annotations and `@inline let _ = …` were treated like constants.

Typing modified (annotated @inline constant):
Before (text): Typemod, then Typedecl.transl_value_decl
    translate the annotation, unify it with Predef's shared type_int ()
    translate the annotation again, as a type scheme
After (text): Typedecl.transl_value_decl, inside the binding's warning scope
    translate the annotation once, unify it with a fresh int, string, float, bool or bigint
    on failure, undo the unification, then report it

Diagnostic modified (a dependent of a module with an alias constant):
Example:
    // D2.res
    module M = {
      type id = int
      @inline let al: id = 4
    }
    let one = 1
    // U.res
    let a = D2.one + 1
Before (diagnostic):
    This has type: id
    But it's expected to have type: int
After (diagnostic): none

Diagnostic modified (char annotation):
Example:
    @inline let x: char = 97
Before (diagnostic):
    Fatal error: exception Stack overflow
After (diagnostic): none; `x` is the inline constant 97 of type char

Representation modified (an @inline constant's attributes):
Before (mapping):
    .cmi ↦ every attribute but @inline, doc comments included
After (mapping):
    .cmi ↦ only @deprecated, as for a plain let
    .cmt ↦ every attribute but @inline, in source order, for editors

Review: Which bindings count as constants? Ast_checks and the type checker
now share one test, `Ast_external_mk.inline_binding`: a single
non-recursive `let` of a name, with no annotation or one that is not
`type a.` or `'a.`. `@inline let _ = …` and `@inline let y: 'a. int = 3`
are ordinary values with warning 53, as on master.

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

cknitt commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: d46c90172a

ℹ️ 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 November 29, 2026 07:12
@cknitt
cknitt marked this pull request as ready for review November 29, 2026 07:12

@cristianoc cristianoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are they still inlined across files?

@cknitt

cknitt commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Yes. An @inline constant is still a primitive with its constant in the .cmi (Val_prim with Kind_inline_const), so other files inline it as before, with or without -bs-cross-module-opt. What changed is only how the type checker gets there: it reads @inline itself instead of decoding a fake external.

The last commit drops attributes from the .cmi: it keeps only @deprecated, like a plain let. That doesn't touch the constant, which is part of the value's kind, not an attribute.

From the tests:

  • tests/tests/src/inline_const_test.mjs uses Inline_const's constants from another file, including through its .resi. It still has let f = "hello" and let f3 = "中文", and the PR doesn't change it.
  • The new inline_const_annotated_use.mjs uses annotated constants from another file. They're inlined as 8 and 97.

@github-actions

Copy link
Copy Markdown

@cknitt
cknitt merged commit db22926 into master Nov 29, 2026
23 checks passed
@cknitt
cknitt deleted the inline-const-typer branch November 29, 2026 07:33
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.

2 participants