Semantic Diff

#9526 Export @inline constants from their module

1 commit

e4894716e7c8ca97458b45c65db2ffddcf15ecd1..pr-9526

0895c161f · cknitt + Claude · Dec 04, 2026, 13:04 UTC

Export @inline constants from their module

Why

An @inline constant was only a primitive, so its module had no field for it: the JS output did not export it, genType silently dropped @genType @inline let x = 42, and hiding one behind a plain let x: int in an interface rebuilt the constant in a coercion. Now the constant is also an ordinary field of its module (proposal 5 of #8733). Uses in ReScript still get the literal, read from the .cmi as before. Types.is_module_field decides which values are fields, and every place that counts field positions or skips primitives uses it.

modifiedJS a module with @inline constants

@inline let less = -1 module Nested = {  @inline let label = "nested"} let pair = (less, Nested.label)
js
Before
After
let Nested = {}; let Nested = { label: "nested"}; let less = -1; let pair = [let pair = [ -1, -1, "nested" "nested"];]; export {export { less, Nested, Nested, pair, pair,}}

modifiedJS a constant in a recursive module

module rec A: {  @inline(9) let k: int  let f: unit => int} = {  @inline let k = 9  let f = () => B.g()}and B: {  let g: unit => int} = {  let g = () => A.k + 1}
js
After
let A = Primitive_module.init([  "x.res",  1,  4], {  TAG: "Module",  _0: [    [      {        TAG: "Value",        _0: 9      },      "k"    ],    [      "Function",      "f"    ]  ]});…

modifiedDiagnostic a constant takes its JavaScript name

@inline let \"a-b" = 1let a$b = 2
diagnostic
After
This value has the same JavaScript name a$bas the value at x.res:1:1-22.Rename one of them.

modifiedReanalyze an unused @inline constant

@inline let unusedConst = 2
reanalyze Warning Dead Value
After
x.res:1:1-27
unusedConst is never used

Review

  • Does an interface still decide what other modules inline? Yes. @inline(c) let x: t in a .resi still needs an @inline implementation with the same constant, and a plain let x = c still does not match it. A plain let x: t hides the constant: other modules read the field, which is now the implementation's own binding instead of a coercion that rebuilt it.
  • Why do Int.Constants and Ordering change in the runtime? Their constants are @inline, so Stdlib_Int.Constants.minValue and maxValue and Stdlib_Ordering.less, equal and greater are now exported. The unreleased changelog entries that said constants have no export are updated, and the breaking entry for Int.Constants is dropped: with the export back, nothing about it breaks.
  • Why does a module alias in a recursive module now get the tag Value instead of value? Constants and aliases share one shape tag, and Value is the name of the runtime constructor. The runtime only tests for Module, so both spellings behave the same.