From 7cc0465bab14000d311094f2cf2dda0f2d794cc7 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 29 Nov 2026 09:11:06 +0000 Subject: [PATCH] Remove -bs-cross-module-opt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Why: Since `@inline` functions are inlined in every module, the flag only added an internal heuristic: with it, every closed function under size 5 and every closed functor was inlined into other modules, annotated or not. Only the runtime and Belt set it, plus a few tests. It was always internal, so it is removed with its `-bs-no-cross-module-opt` partner: bsc now reports both as unknown options. This is PR 7 of the plan in #8733 (proposal 4). Representation modified (which bodies a .cmj stores): Before (mapping): Lam_stats_export.values_of_export, Js_cmj_format.get_result true, false, null, undefined ↦ always @inline function or functor ↦ always other closed function under size 5, closed functor ↦ with -bs-cross-module-opt After (mapping): Lam_stats_export.values_of_export true, false, null, undefined ↦ always @inline function or functor ↦ always anything else ↦ never JS modified (the runtime, built without the flag): Example: // Stdlib_Uint8Array.res include Stdlib_TypedArray.Impl({ … }) Before (js): Stdlib_Uint8Array.mjs without the flag, before @inline on Impl import * as Stdlib_TypedArray from "./Stdlib_TypedArray.mjs"; Stdlib_TypedArray.Impl({}); … /* Not a pure module */ After (js): Stdlib_Uint8Array.mjs, as with the flag let Constants = {}; … /* No side effect */ Review: What did the runtime lose without the flag? Three things, now `@inline`: `Primitive_option.isNested`, `Stdlib_JsError.panic` and the `Stdlib_TypedArray.Impl` functor. With them, the runtime's and Belt's JavaScript is the same as with the flag. Of the tests, only DocTest changes: `JsError.panic` is inlined there now. Review: Do the cross-module inlining tests still inline? Yes. Their libraries used the flag; `minus3`, `callNext` and the `Make` functor are now `@inline`, and their outputs differ only in source locations. Review: What else goes with the flag? `Lam_analysis.safe_to_inline`, which only the heuristic used, two runtime comments saying the runtime needs the flag, and the flag in the wording of the unreleased changelog entry for #9424. Breaking: bsc rejects -bs-cross-module-opt and -bs-no-cross-module-opt as unknown options; drop them from `compiler-flags`. Small functions and functors are no longer inlined into other modules automatically; mark the ones that should be with `@inline`. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D Signed-off-by: Christoph Knittel --- changes/inline-assign-rename.fix.md | 2 +- changes/remove-cross-module-opt.breaking.md | 1 + compiler/backend/js_cmj_format.ml | 20 +++----------- compiler/backend/lam_analysis.ml | 12 --------- compiler/backend/lam_analysis.mli | 2 -- compiler/backend/lam_stats_export.ml | 27 +++---------------- compiler/driver/rescript_compiler_driver.ml | 6 ----- compiler/typing/js_config.ml | 2 -- compiler/typing/js_config.mli | 1 - packages/@rescript/belt/rescript.json | 1 - packages/@rescript/runtime/Primitive_hash.res | 2 -- .../@rescript/runtime/Primitive_object.res | 2 -- .../@rescript/runtime/Primitive_option.res | 1 + packages/@rescript/runtime/Stdlib_JsError.res | 1 + .../@rescript/runtime/Stdlib_TypedArray.res | 1 + .../runtime/lib/es6/Primitive_hash.mjs | 2 +- .../runtime/lib/js/Primitive_hash.cjs | 2 +- packages/@rescript/runtime/rescript.json | 1 - tests/belt_tests/src/belt_mapint_test.mjs | 4 +-- tests/belt_tests/src/belt_mapint_test.res | 2 -- tests/belt_tests/src/rec_module_opt.res | 9 ------- .../cross_module_relative_external/input.js | 2 +- .../rescript.json | 1 - .../app/rescript.json | 3 +-- .../cross_module_unloadable_module/input.js | 2 +- .../node_modules/p/rescript.json | 3 +-- .../node_modules/q/rescript.json | 3 +-- .../projects/inline_function_rebuild/input.js | 2 +- tests/docstring_tests/DocTest.res.js | 4 +-- .../src/inline_arg_order_cross_module_lib.res | 4 +-- .../inline_arg_order_cross_module_test.mjs | 6 ++--- .../inline_arg_order_cross_module_test.res | 2 -- .../src/inline_assign_cross_module_lib.res | 2 -- .../src/inline_assign_cross_module_test.mjs | 19 ++++++------- .../src/inline_assign_cross_module_test.res | 2 -- tests/tests/src/inline_export.res | 3 +-- tests/tests/src/inline_export_test.res | 2 +- .../inline_static_exit_cross_module_lib.res | 3 +-- .../inline_static_exit_cross_module_test.mjs | 14 +++++----- .../inline_static_exit_cross_module_test.res | 2 -- 40 files changed, 48 insertions(+), 132 deletions(-) create mode 100644 changes/remove-cross-module-opt.breaking.md diff --git a/changes/inline-assign-rename.fix.md b/changes/inline-assign-rename.fix.md index 60214d886e8..cc07fbde9e3 100644 --- a/changes/inline-assign-rename.fix.md +++ b/changes/inline-assign-rename.fix.md @@ -1 +1 @@ -- Fix inlining another module's function that assigns a local variable, as in `let r = ref(x); r := r.contents + 1`, with `-bs-cross-module-opt`: the compiler crashed, the generated code assigned an undeclared variable, a value read from the variable before an assignment was read after it instead, or a condition on the variable was decided by the value it started with. +- Fix inlining another module's function that assigns a local variable, as in `let r = ref(x); r := r.contents + 1`: the compiler crashed, the generated code assigned an undeclared variable, a value read from the variable before an assignment was read after it instead, or a condition on the variable was decided by the value it started with. diff --git a/changes/remove-cross-module-opt.breaking.md b/changes/remove-cross-module-opt.breaking.md new file mode 100644 index 00000000000..351ac73136d --- /dev/null +++ b/changes/remove-cross-module-opt.breaking.md @@ -0,0 +1 @@ +- Remove the internal `-bs-cross-module-opt` and `-bs-no-cross-module-opt` flags: other modules inline exactly the functions marked `@inline`. With the first flag, small functions and functors used to be inlined into other modules automatically; mark the ones that should be with `@inline`, and drop the flags from `compiler-flags`. diff --git a/compiler/backend/js_cmj_format.ml b/compiler/backend/js_cmj_format.ml index 27309c3722e..8b16c1a8588 100644 --- a/compiler/backend/js_cmj_format.ml +++ b/compiler/backend/js_cmj_format.ml @@ -103,37 +103,23 @@ let key_comp a b = Ext_string.compare a b.name let not_found key = {name = key; arity = single_na; persistent_closed_lambda = None} -let get_result mid_val = - match mid_val.persistent_closed_lambda with - | Some - (Lconst - (Const_js_null | Const_js_undefined _ | Const_js_true | Const_js_false)) - | None -> - mid_val - (* Stored because the function is [@inline]: inlined with or without - -bs-cross-module-opt. *) - | Some (Lfunction {attr = {inline = Always_inline; _}; _}) -> mid_val - | Some _ -> - if !((Js_config.current ()).cross_module_inline) then mid_val - else {mid_val with persistent_closed_lambda = None} - let rec binary_search_aux arr lo hi (key : string) = let mid = (lo + hi) / 2 in let mid_val = Array.unsafe_get arr mid in let c = key_comp key mid_val in - if c = 0 then get_result mid_val + if c = 0 then mid_val else if c < 0 then (* a[lo] =< key < a[mid] <= a[hi] *) if hi = mid then let lo_val = Array.unsafe_get arr lo in - if lo_val.name = key then get_result lo_val else not_found key + if lo_val.name = key then lo_val else not_found key else binary_search_aux arr lo mid key else if (* a[lo] =< a[mid] < key <= a[hi] *) lo = mid then let hi_val = Array.unsafe_get arr hi in - if hi_val.name = key then get_result hi_val else not_found key + if hi_val.name = key then hi_val else not_found key else binary_search_aux arr mid hi key let binary_search (sorted : keyed_cmj_values) (key : string) : keyed_cmj_value = diff --git a/compiler/backend/lam_analysis.ml b/compiler/backend/lam_analysis.ml index 0812ed0fea6..92145b27639 100644 --- a/compiler/backend/lam_analysis.ml +++ b/compiler/backend/lam_analysis.ml @@ -242,15 +242,3 @@ let ok_to_inline_fun_when_app (m : Lambda.lfunction) (args : Lambda.t list) = s < small_inline_size || destruct_pattern body params args || (args_all_const args && s < 10 && no_side_effects body)) - -(* TODO: We can relax this a bit later, - but decide whether to inline it later in the call site -*) -let safe_to_inline (lam : Lambda.t) = - match lam with - | Lfunction _ -> true - | Lconst - ( Const_polyvar _ | Const_constructor _ | Const_js_true | Const_js_false - | Const_js_undefined _ ) -> - true - | _ -> false diff --git a/compiler/backend/lam_analysis.mli b/compiler/backend/lam_analysis.mli index 4807870f1f3..da3b2c12248 100644 --- a/compiler/backend/lam_analysis.mli +++ b/compiler/backend/lam_analysis.mli @@ -57,5 +57,3 @@ val ok_to_inline_fun_when_app : Lambda.lfunction -> Lambda.t list -> bool val small_inline_size : int val exit_inline_size : int - -val safe_to_inline : Lambda.t -> bool diff --git a/compiler/backend/lam_stats_export.ml b/compiler/backend/lam_stats_export.ml index 968a6fe02b5..54ab69c6867 100644 --- a/compiler/backend/lam_stats_export.ml +++ b/compiler/backend/lam_stats_export.ml @@ -81,7 +81,8 @@ let values_of_export (meta : Lam_stats.t) (export_map : Lambda.t Map_ident.t) : } -> ( (* An [@inline] function or functor: other modules inline its body too, when they can. It must be closed, since the body is - copied without its environment. *) + copied without its environment. Other values keep only the + constants above. *) let not_stored = if async then Some "it is async" else if Option.is_some directive then Some "it has a directive" @@ -113,29 +114,7 @@ let values_of_export (meta : Lam_stats.t) (export_map : Lambda.t Map_ident.t) : (Warnings.Inline_not_stored ((if is_a_functor then "functor" else "function"), reason))); None) - | _ when calls_relative_external lambda -> None - | _ when not !((Js_config.current ()).cross_module_inline) -> None - | _ when not (Lam_analysis.safe_to_inline lambda) -> - (* when inlining a non function, we have to be very careful, - only truly immutable values can be inlined *) - None - | Lfunction {attr = {is_a_functor = true}} -> - if Lam_closure.is_closed lambda then optlam else None - | _ -> - let lam_size = - Lam_analysis.size_upto ~limit:Lam_analysis.small_inline_size - lambda - in - let free_variables = - Lam_closure.free_variables Set_ident.empty Map_ident.empty lambda - in - if - lam_size < Lam_analysis.small_inline_size - && Map_ident.is_empty free_variables - then ( - Ir_log.dwarn ~__POS__ "%s recorded for inlining @." x.name; - optlam) - else None) + | _ -> None) in match (arity, persistent_closed_lambda) with | Single Arity_na, (None | Some (Lconst Const_module_alias)) -> acc diff --git a/compiler/driver/rescript_compiler_driver.ml b/compiler/driver/rescript_compiler_driver.ml index 8a1175121ae..92ff58e8dd7 100644 --- a/compiler/driver/rescript_compiler_driver.ml +++ b/compiler/driver/rescript_compiler_driver.ml @@ -418,12 +418,6 @@ let command_line_flags () : (string * Bsc_args.spec * string) array = ( "-bs-no-builtin-ppx", set (Js_config.current ()).no_builtin_ppx, "*internal* Disable built-in ppx" ); - ( "-bs-cross-module-opt", - set (Js_config.current ()).cross_module_inline, - "*internal* Enable cross module inlining(experimental), default(false)" ); - ( "-bs-no-cross-module-opt", - clear (Js_config.current ()).cross_module_inline, - "*internal* Disable cross module inlining(experimental)" ); ( "-debug-ir", set (Js_config.current ()).debug_ir, "*internal* Dump compiler IR and enable Lambda invariant checks" ); diff --git a/compiler/typing/js_config.ml b/compiler/typing/js_config.ml index 616ea4d9034..935271e3713 100644 --- a/compiler/typing/js_config.ml +++ b/compiler/typing/js_config.ml @@ -31,7 +31,6 @@ let tool_name = "ReScript" type t = { no_version_header: bool ref; directives: string list ref; - cross_module_inline: bool ref; debug_ir: bool ref; check_lam: bool ref; no_builtin_ppx: bool ref; @@ -60,7 +59,6 @@ let create () = { no_version_header = ref false; directives = ref []; - cross_module_inline = ref false; debug_ir = ref false; check_lam = ref false; no_builtin_ppx = ref false; diff --git a/compiler/typing/js_config.mli b/compiler/typing/js_config.mli index 1185045a9f9..4c6767b8531 100644 --- a/compiler/typing/js_config.mli +++ b/compiler/typing/js_config.mli @@ -30,7 +30,6 @@ type t = { no_version_header: bool ref; (** Suppress the version header. *) directives: string list ref; (** Directives printed verbatim just after the version header. *) - cross_module_inline: bool ref; (** Cross-module inlining option. *) debug_ir: bool ref; (** Dump intermediate representations and related diagnostics. *) check_lam: bool ref; diff --git a/packages/@rescript/belt/rescript.json b/packages/@rescript/belt/rescript.json index 5fb8388b9a7..17151a6499e 100644 --- a/packages/@rescript/belt/rescript.json +++ b/packages/@rescript/belt/rescript.json @@ -22,7 +22,6 @@ "-no-alias-deps", "-bs-no-version-header", "-bs-no-check-div-by-zero", - "-bs-cross-module-opt", "-w -3+50", "-warn-error A" ] diff --git a/packages/@rescript/runtime/Primitive_hash.res b/packages/@rescript/runtime/Primitive_hash.res index e44a3a73b17..fc893396b86 100644 --- a/packages/@rescript/runtime/Primitive_hash.res +++ b/packages/@rescript/runtime/Primitive_hash.res @@ -9,8 +9,6 @@ module Int = Stdlib_Int module Obj = Primitive_object_extern module String = Primitive_string_extern -// Note: this only works as intended as long as the runtime is compiled -// with -bs-cross-module-opt. let typeof = Primitive_js_extern.typeof @send external charCodeAt: (string, int) => int = "charCodeAt" diff --git a/packages/@rescript/runtime/Primitive_object.res b/packages/@rescript/runtime/Primitive_object.res index e254bb60ac8..16dbf359ac3 100644 --- a/packages/@rescript/runtime/Primitive_object.res +++ b/packages/@rescript/runtime/Primitive_object.res @@ -8,8 +8,6 @@ module Array = Primitive_array_extern type t = Primitive_object_extern.t -// Note: this only works as intended as long as the runtime is compiled -// with -bs-cross-module-opt. let repr = Primitive_object_extern.repr let magic = Primitive_object_extern.magic let tag = Primitive_object_extern.tag diff --git a/packages/@rescript/runtime/Primitive_option.res b/packages/@rescript/runtime/Primitive_option.res index d348909a6d7..5261944b389 100644 --- a/packages/@rescript/runtime/Primitive_option.res +++ b/packages/@rescript/runtime/Primitive_option.res @@ -9,6 +9,7 @@ module Obj = Primitive_object_extern type nested = {@as("BS_PRIVATE_NESTED_SOME_NONE") depth: int} /* INPUT: [x] should not be nullable */ +@inline let isNested = (x: Obj.t): bool => { Obj.repr((Obj.magic(x): nested).depth) !== Obj.repr(Primitive_js_extern.undefined) } diff --git a/packages/@rescript/runtime/Stdlib_JsError.res b/packages/@rescript/runtime/Stdlib_JsError.res index d80274e282f..15bf6190e46 100644 --- a/packages/@rescript/runtime/Stdlib_JsError.res +++ b/packages/@rescript/runtime/Stdlib_JsError.res @@ -45,6 +45,7 @@ module URIError = { let throwWithMessage = s => make(s)->throw } +@inline let panic = msg => make(`Panic! ${msg}`)->throw external toJsExn: t => Stdlib_JsExn.t = "%identity" diff --git a/packages/@rescript/runtime/Stdlib_TypedArray.res b/packages/@rescript/runtime/Stdlib_TypedArray.res index fd562a61ee1..c39f8733451 100644 --- a/packages/@rescript/runtime/Stdlib_TypedArray.res +++ b/packages/@rescript/runtime/Stdlib_TypedArray.res @@ -483,6 +483,7 @@ typed array module includes them, so `Int8Array.get(view, 0)` works on an `Int8Array.t`. A typed array reaches the functions above with a coercion, such as `(view :> TypedArray.t)`. */ +@inline module Impl = ( T: { type t diff --git a/packages/@rescript/runtime/lib/es6/Primitive_hash.mjs b/packages/@rescript/runtime/lib/es6/Primitive_hash.mjs index f5bb46354f2..a6628915c74 100644 --- a/packages/@rescript/runtime/lib/es6/Primitive_hash.mjs +++ b/packages/@rescript/runtime/lib/es6/Primitive_hash.mjs @@ -36,7 +36,7 @@ function unsafe_pop(q) { RE_EXN_ID: "Assert_failure", _1: [ "Primitive_hash.res", - 59, + 57, 12 ], Error: new Error() diff --git a/packages/@rescript/runtime/lib/js/Primitive_hash.cjs b/packages/@rescript/runtime/lib/js/Primitive_hash.cjs index 0d16c8972f8..b2d265abb48 100644 --- a/packages/@rescript/runtime/lib/js/Primitive_hash.cjs +++ b/packages/@rescript/runtime/lib/js/Primitive_hash.cjs @@ -36,7 +36,7 @@ function unsafe_pop(q) { RE_EXN_ID: "Assert_failure", _1: [ "Primitive_hash.res", - 59, + 57, 12 ], Error: new Error() diff --git a/packages/@rescript/runtime/rescript.json b/packages/@rescript/runtime/rescript.json index 61a19dbf0fe..0d263d7eb82 100644 --- a/packages/@rescript/runtime/rescript.json +++ b/packages/@rescript/runtime/rescript.json @@ -29,7 +29,6 @@ "-no-alias-deps", "-bs-no-version-header", "-bs-no-check-div-by-zero", - "-bs-cross-module-opt", "-w -3+50", "-warn-error A" ] diff --git a/tests/belt_tests/src/belt_mapint_test.mjs b/tests/belt_tests/src/belt_mapint_test.mjs index 80562534bda..ea906abfdef 100644 --- a/tests/belt_tests/src/belt_mapint_test.mjs +++ b/tests/belt_tests/src/belt_mapint_test.mjs @@ -11,12 +11,12 @@ Mocha.describe("Belt_mapint_test", () => { m = Belt_MapInt.set(m, i, i); } for (let i$1 = 0; i$1 <= 999999; ++i$1) { - Test_utils.ok("File \"belt_mapint_test.res\", line 17, characters 9-16", Belt_MapInt.get(m, i$1) !== undefined); + Test_utils.ok("File \"belt_mapint_test.res\", line 15, characters 9-16", Belt_MapInt.get(m, i$1) !== undefined); } for (let i$2 = 0; i$2 <= 999999; ++i$2) { m = Belt_MapInt.remove(m, i$2); } - Test_utils.ok("File \"belt_mapint_test.res\", line 23, characters 7-14", Belt_MapInt.isEmpty(m)); + Test_utils.ok("File \"belt_mapint_test.res\", line 21, characters 7-14", Belt_MapInt.isEmpty(m)); }); }); diff --git a/tests/belt_tests/src/belt_mapint_test.res b/tests/belt_tests/src/belt_mapint_test.res index c341b8d2ae7..9dd28a23811 100644 --- a/tests/belt_tests/src/belt_mapint_test.res +++ b/tests/belt_tests/src/belt_mapint_test.res @@ -1,5 +1,3 @@ -@@config({flags: ["-bs-no-cross-module-opt"]}) - open Mocha open Test_utils diff --git a/tests/belt_tests/src/rec_module_opt.res b/tests/belt_tests/src/rec_module_opt.res index 6a02d2ae333..c38bfd78909 100644 --- a/tests/belt_tests/src/rec_module_opt.res +++ b/tests/belt_tests/src/rec_module_opt.res @@ -1,12 +1,3 @@ -@@config({ - flags: [ - /* "-drawlambda"; */ - /* "-dlambda"; */ - /* "-dtypedtree"; */ - "-bs-no-cross-module-opt", - ], -}) - module rec A: { type t = Leaf(string) | Node(AComparable.t) let cmp: (t, t) => int diff --git a/tests/build_tests/projects/cross_module_relative_external/input.js b/tests/build_tests/projects/cross_module_relative_external/input.js index 727bfefb73c..a6ae6849dd3 100644 --- a/tests/build_tests/projects/cross_module_relative_external/input.js +++ b/tests/build_tests/projects/cross_module_relative_external/input.js @@ -1,6 +1,6 @@ // @ts-check -// With -bs-cross-module-opt, a body that calls an external with a path +// An @inline body that calls an external with a path // relative to its own file must not be inlined into a module in another // directory, where that path would point elsewhere. diff --git a/tests/build_tests/projects/cross_module_relative_external/rescript.json b/tests/build_tests/projects/cross_module_relative_external/rescript.json index db37e2a201c..fd604c30a92 100644 --- a/tests/build_tests/projects/cross_module_relative_external/rescript.json +++ b/tests/build_tests/projects/cross_module_relative_external/rescript.json @@ -9,6 +9,5 @@ "in-source": true }, "suffix": ".mjs", - "compiler-flags": ["-bs-cross-module-opt"], "warnings": { "error": "A-113" } } diff --git a/tests/build_tests/projects/cross_module_unloadable_module/app/rescript.json b/tests/build_tests/projects/cross_module_unloadable_module/app/rescript.json index 0559a407d9e..d77baff3830 100644 --- a/tests/build_tests/projects/cross_module_unloadable_module/app/rescript.json +++ b/tests/build_tests/projects/cross_module_unloadable_module/app/rescript.json @@ -3,6 +3,5 @@ "sources": { "dir": "src" }, "dependencies": ["p"], "package-specs": { "module": "esmodule", "in-source": true }, - "suffix": ".mjs", - "compiler-flags": ["-bs-cross-module-opt"] + "suffix": ".mjs" } diff --git a/tests/build_tests/projects/cross_module_unloadable_module/input.js b/tests/build_tests/projects/cross_module_unloadable_module/input.js index 293de671033..8719c4855e4 100644 --- a/tests/build_tests/projects/cross_module_unloadable_module/input.js +++ b/tests/build_tests/projects/cross_module_unloadable_module/input.js @@ -1,6 +1,6 @@ // @ts-check -// With -bs-cross-module-opt, a stored body that names a module of a package +// A stored @inline body that names a module of a package // the caller does not depend on cannot be inlined there: that module is not // on the caller's load path. The caller calls the value instead. diff --git a/tests/build_tests/projects/cross_module_unloadable_module/node_modules/p/rescript.json b/tests/build_tests/projects/cross_module_unloadable_module/node_modules/p/rescript.json index 01b930e8785..f38bc843320 100644 --- a/tests/build_tests/projects/cross_module_unloadable_module/node_modules/p/rescript.json +++ b/tests/build_tests/projects/cross_module_unloadable_module/node_modules/p/rescript.json @@ -3,6 +3,5 @@ "sources": { "dir": "src" }, "dependencies": ["q"], "package-specs": { "module": "esmodule", "in-source": true }, - "suffix": ".mjs", - "compiler-flags": ["-bs-cross-module-opt"] + "suffix": ".mjs" } diff --git a/tests/build_tests/projects/cross_module_unloadable_module/node_modules/q/rescript.json b/tests/build_tests/projects/cross_module_unloadable_module/node_modules/q/rescript.json index 198c78354f4..5212023a8c0 100644 --- a/tests/build_tests/projects/cross_module_unloadable_module/node_modules/q/rescript.json +++ b/tests/build_tests/projects/cross_module_unloadable_module/node_modules/q/rescript.json @@ -2,6 +2,5 @@ "name": "q", "sources": { "dir": "src" }, "package-specs": { "module": "esmodule", "in-source": true }, - "suffix": ".mjs", - "compiler-flags": ["-bs-cross-module-opt"] + "suffix": ".mjs" } diff --git a/tests/build_tests/projects/inline_function_rebuild/input.js b/tests/build_tests/projects/inline_function_rebuild/input.js index 67ff12d8561..052e303c08b 100644 --- a/tests/build_tests/projects/inline_function_rebuild/input.js +++ b/tests/build_tests/projects/inline_function_rebuild/input.js @@ -1,6 +1,6 @@ // @ts-check -// Without -bs-cross-module-opt, B inlines A's @inline function, and is +// B inlines A's @inline function, and is // compiled again when that body changes although A's interface does not. import * as assert from "node:assert"; diff --git a/tests/docstring_tests/DocTest.res.js b/tests/docstring_tests/DocTest.res.js index 931c39afa44..da9384982dd 100644 --- a/tests/docstring_tests/DocTest.res.js +++ b/tests/docstring_tests/DocTest.res.js @@ -10,7 +10,6 @@ import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.mjs"; import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.mjs"; import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; -import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.mjs"; import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.mjs"; import * as Promises from "node:fs/promises"; import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; @@ -59,7 +58,8 @@ async function extractDocFromFile(file) { let e = Primitive_exceptions.internalToException(raw_e); if (e.RE_EXN_ID === "JsExn") { console.error(e._1); - return Stdlib_JsError.panic(`Failed to extract code blocks from ${file}`); + let msg = `Failed to extract code blocks from ${file}`; + throw new Error(`Panic! ${msg}`); } throw e; } diff --git a/tests/tests/src/inline_arg_order_cross_module_lib.res b/tests/tests/src/inline_arg_order_cross_module_lib.res index fe71f1da3c6..1cb8878863f 100644 --- a/tests/tests/src/inline_arg_order_cross_module_lib.res +++ b/tests/tests/src/inline_arg_order_cross_module_lib.res @@ -1,6 +1,6 @@ -@@config({flags: ["-bs-cross-module-opt"]}) - // Inlined by inline_arg_order_cross_module_test.res +@inline let minus3 = (_x: int, a: int, b: int) => b - a +@inline let callNext = (next: unit => int => int, x: int) => next()(x) diff --git a/tests/tests/src/inline_arg_order_cross_module_test.mjs b/tests/tests/src/inline_arg_order_cross_module_test.mjs index 5435def96e9..36db81d9812 100644 --- a/tests/tests/src/inline_arg_order_cross_module_test.mjs +++ b/tests/tests/src/inline_arg_order_cross_module_test.mjs @@ -35,9 +35,9 @@ function readThenCall() { } Mocha.describe("Inline_arg_order_cross_module_test", () => { - Mocha.test("a read of a local ref before an argument that assigns it", () => Test_utils.eq("File \"inline_arg_order_cross_module_test.res\", line 38, characters 7-14", 1, readThenBump(0))); - Mocha.test("a read of a local ref after an argument that assigns it", () => Test_utils.eq("File \"inline_arg_order_cross_module_test.res\", line 42, characters 7-14", 9, bumpThenRead(0))); - Mocha.test("a read of a local ref before a callee that assigns it", () => Test_utils.eq("File \"inline_arg_order_cross_module_test.res\", line 46, characters 7-14", 0, readThenCall())); + Mocha.test("a read of a local ref before an argument that assigns it", () => Test_utils.eq("File \"inline_arg_order_cross_module_test.res\", line 36, characters 7-14", 1, readThenBump(0))); + Mocha.test("a read of a local ref after an argument that assigns it", () => Test_utils.eq("File \"inline_arg_order_cross_module_test.res\", line 40, characters 7-14", 9, bumpThenRead(0))); + Mocha.test("a read of a local ref before a callee that assigns it", () => Test_utils.eq("File \"inline_arg_order_cross_module_test.res\", line 44, characters 7-14", 0, readThenCall())); }); export { diff --git a/tests/tests/src/inline_arg_order_cross_module_test.res b/tests/tests/src/inline_arg_order_cross_module_test.res index ae05c45a0db..b3fbe034b98 100644 --- a/tests/tests/src/inline_arg_order_cross_module_test.res +++ b/tests/tests/src/inline_arg_order_cross_module_test.res @@ -1,5 +1,3 @@ -@@config({flags: ["-bs-cross-module-opt"]}) - // A call to another module's function that takes a parameter of the caller is // inlined while compiling to JavaScript, after a local ref has become a // variable. An argument that reads the variable used to be substituted into diff --git a/tests/tests/src/inline_assign_cross_module_lib.res b/tests/tests/src/inline_assign_cross_module_lib.res index 1264c2671cf..89c86bb55ee 100644 --- a/tests/tests/src/inline_assign_cross_module_lib.res +++ b/tests/tests/src/inline_assign_cross_module_lib.res @@ -1,5 +1,3 @@ -@@config({flags: ["-bs-cross-module-opt"]}) - // Inlined by inline_assign_cross_module_test.res @inline let bumpTwice = (x: int) => { diff --git a/tests/tests/src/inline_assign_cross_module_test.mjs b/tests/tests/src/inline_assign_cross_module_test.mjs index a2ef08121db..30328532045 100644 --- a/tests/tests/src/inline_assign_cross_module_test.mjs +++ b/tests/tests/src/inline_assign_cross_module_test.mjs @@ -2,6 +2,7 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; +import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.mjs"; function id(x) { return x; @@ -85,7 +86,7 @@ function caught() { } let tmp$1; try { - throw new Error("boom"); + tmp$1 = Stdlib_JsError.throwWithMessage("boom"); } catch (exn$1) { tmp$1 = 2; } @@ -96,8 +97,8 @@ function caught() { } Mocha.describe("Inline_assign_cross_module_test", () => { - Mocha.test("a variable the inlined function assigns, twice in a function", () => Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 39, characters 7-14", 14, addBumped(id(3), id(4)))); - Mocha.test("a variable the inlined function assigns, with a constant argument", () => Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 43, characters 7-14", [ + Mocha.test("a variable the inlined function assigns, twice in a function", () => Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 37, characters 7-14", 14, addBumped(id(3), id(4)))); + Mocha.test("a variable the inlined function assigns, with a constant argument", () => Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 41, characters 7-14", [ 12, 4 ], bumpConstants())); @@ -105,28 +106,28 @@ Mocha.describe("Inline_assign_cross_module_test", () => { let r = 5; let p = r; r = 10; - Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 47, characters 7-14", 15, p + r | 0); + Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 45, characters 7-14", 15, p + r | 0); }); Mocha.test("a copy of an assigned variable, made before the assignment", () => { let r = 1; let s = r; r = s + 1 | 0; - Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 51, characters 7-14", 3, s + r | 0); + Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 49, characters 7-14", 3, s + r | 0); }); - Mocha.test("a read of an assigned variable, passed to a bound closure before the assignment", () => Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 55, characters 7-14", 15, readBeforeAssignBound())); + Mocha.test("a read of an assigned variable, passed to a bound closure before the assignment", () => Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 53, characters 7-14", 15, readBeforeAssignBound())); Mocha.test("a condition on an assigned variable bound to a constant", () => { let r = true; r = !r; - Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 59, characters 7-14", 2, r ? 1 : 2); + Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 57, characters 7-14", 2, r ? 1 : 2); }); Mocha.test("a switch on an assigned variable bound to a constant", () => { let r = "a"; r = "b"; let match = r; let tmp = match === "a" ? 1 : 2; - Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 63, characters 7-14", 2, tmp); + Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 61, characters 7-14", 2, tmp); }); - Mocha.test("a function with a try handler, inlined twice in a function", () => Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 67, characters 7-14", [ + Mocha.test("a function with a try handler, inlined twice in a function", () => Test_utils.eq("File \"inline_assign_cross_module_test.res\", line 65, characters 7-14", [ 1, 2 ], caught())); diff --git a/tests/tests/src/inline_assign_cross_module_test.res b/tests/tests/src/inline_assign_cross_module_test.res index 02be8aa57ff..bad171c8dbf 100644 --- a/tests/tests/src/inline_assign_cross_module_test.res +++ b/tests/tests/src/inline_assign_cross_module_test.res @@ -1,5 +1,3 @@ -@@config({flags: ["-bs-cross-module-opt"]}) - // Inlining another module's function renames its local variables. An // assignment to one used to keep the old name, a variable this module doesn't // declare. diff --git a/tests/tests/src/inline_export.res b/tests/tests/src/inline_export.res index 9dc34ee5de0..962852209fe 100644 --- a/tests/tests/src/inline_export.res +++ b/tests/tests/src/inline_export.res @@ -1,5 +1,4 @@ -// Used from inline_export_test.res: other modules inline @inline functions, -// without -bs-cross-module-opt. +// Used from inline_export_test.res: other modules inline @inline functions. @inline let apply = (value, f) => f(value) diff --git a/tests/tests/src/inline_export_test.res b/tests/tests/src/inline_export_test.res index 05112ac1e35..5818403f07d 100644 --- a/tests/tests/src/inline_export_test.res +++ b/tests/tests/src/inline_export_test.res @@ -1,5 +1,5 @@ // @inline functions from other modules: Option helpers from the runtime and -// Inline_export, compiled without -bs-cross-module-opt. +// Inline_export. open Mocha open Test_utils diff --git a/tests/tests/src/inline_static_exit_cross_module_lib.res b/tests/tests/src/inline_static_exit_cross_module_lib.res index 0f4f8ba44a2..c3d99a2d864 100644 --- a/tests/tests/src/inline_static_exit_cross_module_lib.res +++ b/tests/tests/src/inline_static_exit_cross_module_lib.res @@ -1,5 +1,3 @@ -@@config({flags: ["-bs-cross-module-opt"]}) - // Inlined by inline_static_exit_cross_module_test.res. Only closed functions // are inlined in other modules, so the handlers call no function of this one. @inline @@ -20,6 +18,7 @@ module type S = { let flag: bool } +@inline module Make = (X: S) => { let r = switch (X.v, X.w) { | (0, _) | (_, 0) => diff --git a/tests/tests/src/inline_static_exit_cross_module_test.mjs b/tests/tests/src/inline_static_exit_cross_module_test.mjs index 4af6995c8e9..dd5f85a84d6 100644 --- a/tests/tests/src/inline_static_exit_cross_module_test.mjs +++ b/tests/tests/src/inline_static_exit_cross_module_test.mjs @@ -105,17 +105,17 @@ let Second = { Mocha.describe("Inline_static_exit_cross_module_test", () => { Mocha.test("two inlined copies", () => { - Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 34, characters 7-14", constant, "t"); - Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 35, characters 7-14", computed, "a05"); - Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 36, characters 7-14", computedOther, "other"); + Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 32, characters 7-14", constant, "t"); + Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 33, characters 7-14", computed, "a05"); + Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 34, characters 7-14", computedOther, "other"); }); Mocha.test("two inlined copies in a function", () => { - Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 40, characters 7-14", both(0, 5, false), "t a05"); - Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 41, characters 7-14", both(1, 5, false), "other other"); + Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 38, characters 7-14", both(0, 5, false), "t a05"); + Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 39, characters 7-14", both(1, 5, false), "other other"); }); Mocha.test("functor applied twice", () => { - Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 45, characters 7-14", r, "t"); - Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 46, characters 7-14", r$1, "a05"); + Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 43, characters 7-14", r, "t"); + Test_utils.eq("File \"inline_static_exit_cross_module_test.res\", line 44, characters 7-14", r$1, "a05"); }); }); diff --git a/tests/tests/src/inline_static_exit_cross_module_test.res b/tests/tests/src/inline_static_exit_cross_module_test.res index 7fa5e0327a3..f91355d5fda 100644 --- a/tests/tests/src/inline_static_exit_cross_module_test.res +++ b/tests/tests/src/inline_static_exit_cross_module_test.res @@ -1,5 +1,3 @@ -@@config({flags: ["-bs-cross-module-opt"]}) - // Two copies of another module's function, or of its functor's body, each have // their own static exits, so each runs its own handler. open Mocha