Repository navigation
Conversation
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>
Changelog🐛 Bug fix
Semantic Diff3 commits · Full page Type
|
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>
|
| Benchmark | Base | Head | Change |
|---|---|---|---|
packages/@rescript/runtime/Stdlib_Ordering.res |
152,472 | 154,381 | +1.25% |
packages/@rescript/belt/src/Belt_List.resi |
758,750 | 750,202 | -1.13% |
packages/@rescript/belt/src/Belt_Array.resi |
650,342 | 644,889 | -0.84% |
packages/@rescript/runtime/Stdlib_List.resi |
409,869 | 406,574 | -0.80% |
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/belt/src/Belt_MutableSet.resi |
397,552 | 394,818 | -0.69% |
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% |
packages/@rescript/belt/src/Belt_Set.resi |
437,444 | 434,578 | -0.66% |
87 more changes
| Benchmark | Base | Head | Change |
|---|---|---|---|
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/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/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/runtime/Stdlib_Int.resi |
206,109 | 205,061 | -0.51% |
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/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_Option.resi |
236,513 | 235,448 | -0.45% |
packages/@rescript/runtime/Stdlib_Iterator.resi |
159,252 | 158,542 | -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/runtime/Stdlib_Result.resi |
296,383 | 295,188 | -0.40% |
packages/@rescript/runtime/Stdlib_Array.resi |
728,609 | 725,721 | -0.40% |
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/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_Null.resi |
204,437 | 203,682 | -0.37% |
packages/@rescript/runtime/Stdlib_Dict.resi |
240,857 | 239,992 | -0.36% |
packages/@rescript/runtime/Stdlib_Nullable.resi |
199,678 | 198,975 | -0.35% |
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_Bool.res |
146,106 | 146,551 | +0.30% |
packages/@rescript/runtime/Stdlib_Float.resi |
194,298 | 193,748 | -0.28% |
packages/@rescript/runtime/Stdlib_String.resi |
497,483 | 496,101 | -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% |
stress/InlineChain.res |
3,542,096 | 3,550,825 | +0.25% |
packages/@rescript/runtime/Stdlib_Set.resi |
228,959 | 228,397 | -0.25% |
packages/@rescript/runtime/Stdlib_Map.resi |
217,114 | 216,618 | -0.23% |
packages/@rescript/runtime/Stdlib_Date.resi |
614,254 | 612,869 | -0.23% |
packages/@rescript/runtime/Stdlib_Global.resi |
155,554 | 155,204 | -0.23% |
packages/@rescript/runtime/Stdlib_DataView.resi |
268,050 | 267,476 | -0.21% |
packages/@rescript/runtime/Stdlib_RegExp.resi |
187,806 | 187,423 | -0.20% |
packages/@rescript/runtime/Stdlib_Intl_Collator.res |
178,701 | 179,061 | +0.20% |
parse/RedBlackTreeNoComments.res |
355,142 | 355,838 | +0.20% |
parse/RedBlackTree.res |
362,855 | 363,551 | +0.19% |
packages/@rescript/runtime/Stdlib_Float.res |
219,035 | 219,441 | +0.19% |
packages/@rescript/runtime/Stdlib_Nullable.res |
330,045 | 330,610 | +0.17% |
packages/@rescript/runtime/Stdlib_Null.res |
332,547 | 333,111 | +0.17% |
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_Map.res |
982,236 | 983,773 | +0.16% |
packages/@rescript/runtime/Stdlib_Promise.resi |
356,023 | 355,474 | -0.15% |
packages/@rescript/runtime/Stdlib_Option.res |
754,552 | 755,693 | +0.15% |
packages/@rescript/belt/src/Belt_Option.res |
389,411 | 389,992 | +0.15% |
packages/@rescript/belt/src/Belt_HashSet.resi |
222,784 | 222,452 | -0.15% |
packages/@rescript/belt/src/Belt_Set.res |
858,896 | 860,085 | +0.14% |
packages/@rescript/runtime/Stdlib_Temporal_Instant.res |
307,681 | 308,083 | +0.13% |
parse/Napkinscript.res |
10,716,176 | 10,730,032 | +0.13% |
packages/@rescript/runtime/Stdlib_Temporal_PlainTime.res |
320,339 | 320,745 | +0.13% |
packages/@rescript/runtime/Stdlib_ArrayBuffer.resi |
110,995 | 110,858 | -0.12% |
build/leaf-edit |
13,109,870 | 13,125,303 | +0.12% |
packages/@rescript/runtime/Stdlib_String.res |
504,095 | 504,683 | +0.12% |
packages/@rescript/belt/src/Belt_MapInt.res |
1,182,642 | 1,184,005 | +0.12% |
packages/@rescript/belt/src/Belt_MapString.res |
1,183,178 | 1,184,541 | +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/Stdlib_Array.res |
1,282,476 | 1,283,929 | +0.11% |
packages/@rescript/runtime/Stdlib_Temporal_Duration.res |
373,682 | 374,097 | +0.11% |
packages/@rescript/runtime/Stdlib_Int.res |
455,660 | 456,151 | +0.11% |
packages/@rescript/runtime/Stdlib_Temporal_PlainYearMonth.res |
382,367 | 382,777 | +0.11% |
packages/@rescript/runtime/Stdlib_JsError.res |
230,071 | 230,317 | +0.11% |
packages/@rescript/belt/src/Belt_Result.res |
410,003 | 410,438 | +0.11% |
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res |
403,989 | 404,409 | +0.10% |
build/Namespace/clean |
84,258,458 | 84,345,909 | +0.10% |
packages/@rescript/belt/src/Belt_MutableMapInt.res |
1,155,801 | 1,156,961 | +0.10% |
packages/@rescript/belt/src/Belt_MutableMapString.res |
1,156,078 | 1,157,238 | +0.10% |
packages/@rescript/belt/src/Belt_Array.res |
2,157,890 | 2,160,051 | +0.10% |
Instructions
In total: 9,223,996,004 → 9,223,847,707 (±0.00%).
| Benchmark | Base | Head | Change |
|---|---|---|---|
packages/@rescript/runtime/Stdlib_Math.resi |
21,317,371 | 21,244,952 | -0.34% |
packages/@rescript/belt/src/Belt_List.resi |
38,989,796 | 38,866,564 | -0.32% |
packages/@rescript/runtime/Stdlib_Date.resi |
34,303,244 | 34,197,380 | -0.31% |
packages/@rescript/runtime/Stdlib_Array.resi |
40,127,150 | 40,005,207 | -0.30% |
packages/@rescript/belt/src/Belt_Array.resi |
33,729,441 | 33,646,408 | -0.25% |
packages/@rescript/runtime/Stdlib_List.resi |
24,544,131 | 24,484,906 | -0.24% |
packages/@rescript/runtime/Stdlib_String.resi |
29,470,827 | 29,400,526 | -0.24% |
Output size
In total: 26,710,059 → 26,716,354 (+0.02%).
| Benchmark | Base | Head | Change |
|---|---|---|---|
output/runtime/*.cmt |
3,035,969 | 3,041,009 | +0.17% |
Pull request 35d909b compared with base e51ee46 in this run.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9467 +/- ##
==========================================
+ Coverage 82.34% 82.35% +0.01%
==========================================
Files 462 462
Lines 65817 65825 +8
==========================================
+ Hits 54198 54213 +15
+ Misses 11619 11612 -7
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
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>
The type checker now handles
@inlineconstants itself. Before, the frontend rewrote@inline let x = 1and@inline(1) let x: intintoexternal x: int = "#rescript-inline", and the type checker decoded that again.The rewrite dropped all other attributes. So
@deprecatedon an@inlineconstant never warned, and its doc comment was lost. Both are now kept. The reserved"#rescript-inline"primitive name is gone too.This is the
@inlineitem 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 = 3are now inlined too. Before, they were ordinary values with warning 53. The annotation must be the literal's type, possibly through an alias. Otherwise it's an error: "This @inline constant has type int, but it is annotated with type float." Like other@inlineconstants, they're no longer exported to JavaScript. Otherwise no JavaScript output changes.New tests:
Cross_deprecated_inline_const(multi-file error test): a deprecated@inlineconstant from a module and from an interface warns at its use in another module, not inside its own module.inline_const_annotated.res(JS output test): annotated constants, one through a type alias, are inlined.inline_const_annotation_mismatch.res(error test): an annotation that isn't the literal's type.InlineConstants.res(ast-mapping fixture):@inlineconstants round-trip through the v0 AST.The
external_reserved_inline_primitiveerror test is removed along with the error.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D