From 9f3bc63dc4f7c4af0a13c623f7aa767cbd691266 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 29 Nov 2026 07:54:23 +0000 Subject: [PATCH] Inline @inline functions in other modules without a flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Why: `@inline` on a function inlined its calls only in its own module. Other modules inlined it only with -bs-cross-module-opt, which also inlined every small closed function, annotated or not. `@inline` now means the same in every module: an exported `@inline` function or functor stores its body in the .cmj, and other modules inline it, flag or not. The Option helpers that #8689 marked are `@inline`. This is PR 5 of the plan in #8733 (proposal 3) and replaces the compiler part of #8689, without the `@inline(crossModule)` payload. JS modified (another module, without -bs-cross-module-opt): Example: // A.res @inline let g = x => x + 1 let h = x => x * 2 // B.res let a = A.g(3) let b = A.h(4) Before (js): B let a = A.g(3); let b = A.h(4); After (js): B let b = A.h(4); let a = 4; JS modified (an Option helper): Example: // tests/belt_tests/src/bs_stack_test.res while current->Option.isSome { … } Before (js): while (Stdlib_Option.isSome(current)) { After (js): while (current !== undefined) { 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, closed ↦ with -bs-cross-module-opt other closed function under size 5, closed functor ↦ with -bs-cross-module-opt After (mapping): Lam_stats_export.values_of_export, Js_cmj_format.get_result true, false, null, undefined ↦ always @inline function or functor, closed, not async, no directive ↦ always other closed function under size 5, closed functor ↦ with -bs-cross-module-opt Review: What keeps a body from being stored? It must be closed, since it is copied without its environment, not async and without a directive, and it must not call a relative-path external (#9475). A caller that can't load a module the body names calls the function instead (#9478). Review: Which functions does this cover? Those defined at the top level of a module. A function in a nested module (`module M = { @inline let f = … }`) and an `@inline let rec` are still inlined only in their own module. Review: Does the caller rebuild when the body changes? Yes, through the changed .cmj (#9473); tests/build_tests/projects/inline_function_rebuild edits a body on the same line, which leaves the .cmi as it is. Review: Can a JS global be captured by the import of a module whose uses were all inlined? Not any more. Such a module is still imported when it has side effects, so `Js_pass_external_shadow` now counts the modules imported for their side effects as bindings in scope (`Lam_compile_env.side_effect_modules`, which `populate_required_modules` uses too). Before, it saw only the modules the generated code still named and printed the global bare, which then read the import (inline_shadowed_import_test.res). Found by marking every function in tests/tests `@inline`. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D Signed-off-by: Christoph Knittel --- ...inline-functions-across-modules.feature.md | 1 + compiler/backend/js_cmj_format.ml | 3 + compiler/backend/js_pass_external_shadow.ml | 14 +- compiler/backend/js_pass_external_shadow.mli | 2 +- compiler/backend/lam_compile_env.ml | 15 +- compiler/backend/lam_compile_env.mli | 6 + compiler/backend/lam_compile_main.ml | 3 + compiler/backend/lam_stats_export.ml | 43 ++--- packages/@rescript/runtime/Stdlib_Option.res | 9 + tests/belt_tests/src/bs_stack_test.mjs | 9 +- .../inline_function_rebuild/.gitignore | 2 + .../projects/inline_function_rebuild/input.js | 33 ++++ .../inline_function_rebuild/rescript.json | 7 + .../inline_function_rebuild/src/A.res | 2 + .../inline_function_rebuild/src/B.res | 1 + .../ounit_external_shadow_tests.ml | 33 +++- tests/tests/src/flat_make_export_test.mjs | 4 +- tests/tests/src/inline_export.mjs | 32 ++++ tests/tests/src/inline_export.res | 13 ++ tests/tests/src/inline_export_test.mjs | 175 ++++++++++++++++++ tests/tests/src/inline_export_test.res | 79 ++++++++ .../tests/src/inline_shadowed_import_lib.mjs | 14 ++ .../tests/src/inline_shadowed_import_lib.res | 6 + .../tests/src/inline_shadowed_import_test.mjs | 22 +++ .../tests/src/inline_shadowed_import_test.res | 17 ++ tests/tests/src/int_overflow_test.mjs | 12 +- tests/tests/src/stdlib/Stdlib_ObjectTests.mjs | 22 ++- tests/tests/src/stdlib/Stdlib_TempTests.mjs | 17 +- .../tests/src/stdlib/Stdlib_TemporalTests.mjs | 7 +- tests/tests/src/stdlib/Stdlib_TestTests.mjs | 6 +- .../src/stdlib/intl/Stdlib_IntlTests.mjs | 4 +- 31 files changed, 550 insertions(+), 63 deletions(-) create mode 100644 changes/inline-functions-across-modules.feature.md create mode 100644 tests/build_tests/projects/inline_function_rebuild/.gitignore create mode 100644 tests/build_tests/projects/inline_function_rebuild/input.js create mode 100644 tests/build_tests/projects/inline_function_rebuild/rescript.json create mode 100644 tests/build_tests/projects/inline_function_rebuild/src/A.res create mode 100644 tests/build_tests/projects/inline_function_rebuild/src/B.res create mode 100644 tests/tests/src/inline_export.mjs create mode 100644 tests/tests/src/inline_export.res create mode 100644 tests/tests/src/inline_export_test.mjs create mode 100644 tests/tests/src/inline_export_test.res create mode 100644 tests/tests/src/inline_shadowed_import_lib.mjs create mode 100644 tests/tests/src/inline_shadowed_import_lib.res create mode 100644 tests/tests/src/inline_shadowed_import_test.mjs create mode 100644 tests/tests/src/inline_shadowed_import_test.res diff --git a/changes/inline-functions-across-modules.feature.md b/changes/inline-functions-across-modules.feature.md new file mode 100644 index 00000000000..eafac94ff7c --- /dev/null +++ b/changes/inline-functions-across-modules.feature.md @@ -0,0 +1 @@ +- Inline `@inline` functions in the modules that use them too, not only in their own module, and mark `Option.map`, `flatMap`, `getOr`, `mapOr`, `orElse`, `filter`, `forEach`, `isSome` and `isNone` as `@inline`, so calls to them compile to the code they run. This applies to functions defined at the top level of a module. diff --git a/compiler/backend/js_cmj_format.ml b/compiler/backend/js_cmj_format.ml index 92a727b689d..27309c3722e 100644 --- a/compiler/backend/js_cmj_format.ml +++ b/compiler/backend/js_cmj_format.ml @@ -110,6 +110,9 @@ let get_result mid_val = (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} diff --git a/compiler/backend/js_pass_external_shadow.ml b/compiler/backend/js_pass_external_shadow.ml index 8727597b928..63c6835b8a4 100644 --- a/compiler/backend/js_pass_external_shadow.ml +++ b/compiler/backend/js_pass_external_shadow.ml @@ -87,9 +87,17 @@ let imported_modules (js : J.program) = self.program self js; !names -let program (js : J.program) : J.program = - (* printed names of the bindings in scope at the current point *) - let in_scope = ref (imported_modules js) in +let program ~(imports : J.module_id list) (js : J.program) : J.program = + (* printed names of the bindings in scope at the current point. [imports] + are the modules imported for their side effects, which the program may + name nowhere, as when every use of them was inlined. *) + let in_scope = + ref + (List.fold_left + (fun names (m : J.module_id) -> + if m.dynamic_import then names else add_binding m.id names) + (imported_modules js) imports) + in let with_bindings add f = let outer = !in_scope in in_scope := add outer; diff --git a/compiler/backend/js_pass_external_shadow.mli b/compiler/backend/js_pass_external_shadow.mli index 5e23936c53d..5eea30612d3 100644 --- a/compiler/backend/js_pass_external_shadow.mli +++ b/compiler/backend/js_pass_external_shadow.mli @@ -23,4 +23,4 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) (* Rewrite to using globalThis when shadowing would break @val/@scope globals. *) -val program : J.program -> J.program +val program : imports:J.module_id list -> J.program -> J.program diff --git a/compiler/backend/lam_compile_env.ml b/compiler/backend/lam_compile_env.ml index 667afcefb5e..624d5a19456 100644 --- a/compiler/backend/lam_compile_env.ml +++ b/compiler/backend/lam_compile_env.ml @@ -180,11 +180,16 @@ let is_pure_module (oid : Lam_module_ident.t) = | Some (Ml {cmj_table}) -> cmj_table.pure | Some (External _) -> false) -let populate_required_modules extras - (hard_dependencies : unit Lam_module_ident.Hash_set.t) = +let side_effect_modules extras = + let modules = ref [] in Lam_module_ident.Hash.iter - (fun id _ -> if not (is_pure_module id) then add hard_dependencies id) + (fun id _ -> if not (is_pure_module id) then modules := id :: !modules) (cached_tbl ()); Lam_module_ident.Hash_set.iter - (fun id () -> if not (is_pure_module id) then add hard_dependencies id) - extras + (fun id () -> if not (is_pure_module id) then modules := id :: !modules) + extras; + !modules + +let populate_required_modules extras + (hard_dependencies : unit Lam_module_ident.Hash_set.t) = + List.iter (add hard_dependencies) (side_effect_modules extras) diff --git a/compiler/backend/lam_compile_env.mli b/compiler/backend/lam_compile_env.mli index 9d84ea9b7f4..eabf2bb97a9 100644 --- a/compiler/backend/lam_compile_env.mli +++ b/compiler/backend/lam_compile_env.mli @@ -86,3 +86,9 @@ val get_package_info_from_cmj : *) val populate_required_modules : unit Lam_module_ident.Hash_set.t -> unit Lam_module_ident.Hash_set.t -> unit + +(* The modules [populate_required_modules extras] adds: the ones with side + effects, which are imported even when the generated code names none of + their values, as when all uses were inlined. *) +val side_effect_modules : + unit Lam_module_ident.Hash_set.t -> Lam_module_ident.t list diff --git a/compiler/backend/lam_compile_main.ml b/compiler/backend/lam_compile_main.ml index 244696bf577..32fa834b174 100644 --- a/compiler/backend/lam_compile_main.ml +++ b/compiler/backend/lam_compile_main.ml @@ -432,6 +432,9 @@ let compile ?on_optimized_lambda (output_prefix : string) (* After the passes that add bindings, so that a JS global read in one of them, as in [let t_0 = t_0], is not captured by the binding *) |> Js_pass_external_shadow.program + ~imports: + (if !((Js_config.current ()).all_module_aliases) then [] + else Lam_compile_env.side_effect_modules may_required_modules) |> j "external_shadow" |> (fun js -> ignore @@ Js_pass_scope.program js; diff --git a/compiler/backend/lam_stats_export.ml b/compiler/backend/lam_stats_export.ml index 73e3dd853d9..298d73d4de1 100644 --- a/compiler/backend/lam_stats_export.ml +++ b/compiler/backend/lam_stats_export.ml @@ -72,34 +72,32 @@ let values_of_export (meta : Lam_stats.t) (export_map : Lambda.t Map_ident.t) : | Const_js_false )) | None -> optlam - | Some lambda -> - if not !((Js_config.current ()).cross_module_inline) then None - else if calls_relative_external lambda then None - else if - Lam_analysis.safe_to_inline lambda - (* when inlning a non function, we have to be very careful, - only truly immutable values can be inlined - *) - then + | Some lambda -> ( + if calls_relative_external lambda then None + else match lambda with - | Lfunction {attr = {inline = Always_inline}} - (* FIXME: is_closed lambda is too restrictive - It precludes ues cases - - inline forEach but not forEachU - *) - | Lfunction {attr = {is_a_functor = true}} -> - if Lam_closure.is_closed lambda (* TODO: seriealize more*) then - optlam + | Lfunction ({attr = {inline = Always_inline}} as fn) -> + (* An [@inline] function or functor: other modules inline its + body too, with or without -bs-cross-module-opt, when they + can. It must be closed, since the body is copied without + its environment. *) + if + Lambda.lfunction_can_be_inlined fn + && Lam_closure.is_closed lambda + then optlam else 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 - (* TODO: - 1. global need re-assocate when do the beta reduction - 2. [lambda_exports] is not precise - *) let free_variables = Lam_closure.free_variables Set_ident.empty Map_ident.empty lambda @@ -110,8 +108,7 @@ let values_of_export (meta : Lam_stats.t) (export_map : Lambda.t Map_ident.t) : then ( Ir_log.dwarn ~__POS__ "%s recorded for inlining @." x.name; optlam) - else None - else None + else None) in match (arity, persistent_closed_lambda) with | Single Arity_na, (None | Some (Lconst Const_module_alias)) -> acc diff --git a/packages/@rescript/runtime/Stdlib_Option.res b/packages/@rescript/runtime/Stdlib_Option.res index 660f5a60a30..da70b16c05f 100644 --- a/packages/@rescript/runtime/Stdlib_Option.res +++ b/packages/@rescript/runtime/Stdlib_Option.res @@ -5,12 +5,14 @@ */ type t<'a> = option<'a> = None | Some('a) +@inline let filter = (opt, p) => switch opt { | Some(x) as option if p(x) => option | _ => None } +@inline let forEach = (opt, f) => switch opt { | Some(x) => f(x) @@ -31,42 +33,49 @@ let getOrThrow = (x, ~message=?) => external getUnsafe: option<'a> => 'a = "%identity" +@inline let mapOr = (opt, default, f) => switch opt { | Some(x) => f(x) | None => default } +@inline let map = (opt, f) => switch opt { | Some(x) => Some(f(x)) | None => None } +@inline let flatMap = (opt, f) => switch opt { | Some(x) => f(x) | None => None } +@inline let getOr = (opt, default) => switch opt { | Some(x) => x | None => default } +@inline let orElse = (opt, other) => switch opt { | Some(_) as some => some | None => other } +@inline let isSome = x => switch x { | Some(_) => true | None => false } +@inline let isNone = x => x == None let equal = (a, b, eq) => diff --git a/tests/belt_tests/src/bs_stack_test.mjs b/tests/belt_tests/src/bs_stack_test.mjs index 0729f2a230d..e6c8f4b34d1 100644 --- a/tests/belt_tests/src/bs_stack_test.mjs +++ b/tests/belt_tests/src/bs_stack_test.mjs @@ -2,7 +2,6 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as Belt_MutableQueue from "@rescript/belt/src/Belt_MutableQueue.mjs"; import * as Belt_MutableStack from "@rescript/belt/src/Belt_MutableStack.mjs"; @@ -10,7 +9,7 @@ function inOrder(v) { let current = v; let s = Belt_MutableStack.make(); let q = Belt_MutableQueue.make(); - while (Stdlib_Option.isSome(current)) { + while (current !== undefined) { let v$1 = current; Belt_MutableStack.push(s, v$1); current = v$1.left; @@ -20,7 +19,7 @@ function inOrder(v) { let v$2 = current; Belt_MutableQueue.add(q, v$2.value); current = v$2.right; - while (Stdlib_Option.isSome(current)) { + while (current !== undefined) { let v$3 = current; Belt_MutableStack.push(s, v$3); current = v$3.left; @@ -33,7 +32,7 @@ function inOrder3(v) { let current = v; let s = Belt_MutableStack.make(); let q = Belt_MutableQueue.make(); - while (Stdlib_Option.isSome(current)) { + while (current !== undefined) { let v$1 = current; Belt_MutableStack.push(s, v$1); current = v$1.left; @@ -41,7 +40,7 @@ function inOrder3(v) { Belt_MutableStack.dynamicPopIter(s, popped => { Belt_MutableQueue.add(q, popped.value); let current = popped.right; - while (Stdlib_Option.isSome(current)) { + while (current !== undefined) { let v = current; Belt_MutableStack.push(s, v); current = v.left; diff --git a/tests/build_tests/projects/inline_function_rebuild/.gitignore b/tests/build_tests/projects/inline_function_rebuild/.gitignore new file mode 100644 index 00000000000..b39db7b2777 --- /dev/null +++ b/tests/build_tests/projects/inline_function_rebuild/.gitignore @@ -0,0 +1,2 @@ +lib +src/**/*.mjs diff --git a/tests/build_tests/projects/inline_function_rebuild/input.js b/tests/build_tests/projects/inline_function_rebuild/input.js new file mode 100644 index 00000000000..67ff12d8561 --- /dev/null +++ b/tests/build_tests/projects/inline_function_rebuild/input.js @@ -0,0 +1,33 @@ +// @ts-check + +// Without -bs-cross-module-opt, 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"; +import * as fs from "node:fs/promises"; +import * as path from "node:path"; +import { setup } from "#dev/process"; + +const { execBuildOrThrow, execClean } = setup(import.meta.dirname); +const source = path.join(import.meta.dirname, "src", "A.res"); +const output = path.join(import.meta.dirname, "src", "B.mjs"); +const original = await fs.readFile(source, "utf8"); + +await execClean(); +try { + await execBuildOrThrow(); + assert.match(await fs.readFile(output, "utf8"), /let result = 2;/); + + // Same line, same type: only A's .cmj changes. + await fs.writeFile(source, original.replace("x + 1", "x + 2")); + await execBuildOrThrow(); + assert.match(await fs.readFile(output, "utf8"), /let result = 3;/); + + // Without @inline, B calls the function. + await fs.writeFile(source, original.replace("@inline\n", "")); + await execBuildOrThrow(); + assert.match(await fs.readFile(output, "utf8"), /A\.bump\(1\)/); +} finally { + await fs.writeFile(source, original); + await execClean(); +} diff --git a/tests/build_tests/projects/inline_function_rebuild/rescript.json b/tests/build_tests/projects/inline_function_rebuild/rescript.json new file mode 100644 index 00000000000..5cfe3021912 --- /dev/null +++ b/tests/build_tests/projects/inline_function_rebuild/rescript.json @@ -0,0 +1,7 @@ +{ + "name": "inline_function_rebuild", + "sources": { "dir": "src" }, + "package-specs": { "module": "esmodule", "in-source": true }, + "suffix": ".mjs", + "warnings": { "error": true } +} diff --git a/tests/build_tests/projects/inline_function_rebuild/src/A.res b/tests/build_tests/projects/inline_function_rebuild/src/A.res new file mode 100644 index 00000000000..472ec816edb --- /dev/null +++ b/tests/build_tests/projects/inline_function_rebuild/src/A.res @@ -0,0 +1,2 @@ +@inline +let bump = x => x + 1 diff --git a/tests/build_tests/projects/inline_function_rebuild/src/B.res b/tests/build_tests/projects/inline_function_rebuild/src/B.res new file mode 100644 index 00000000000..ffe66e169ff --- /dev/null +++ b/tests/build_tests/projects/inline_function_rebuild/src/B.res @@ -0,0 +1 @@ +let result = A.bump(1) diff --git a/tests/ounit_tests/ounit_external_shadow_tests.ml b/tests/ounit_tests/ounit_external_shadow_tests.ml index 80522046d92..8323d5f9439 100644 --- a/tests/ounit_tests/ounit_external_shadow_tests.ml +++ b/tests/ounit_tests/ounit_external_shadow_tests.ml @@ -30,7 +30,31 @@ let switch_on_global () = export_set = Set_ident.empty; } in - Js_pass_external_shadow.program program + Js_pass_external_shadow.program ~imports:[] program + +(* [f()] in a module that imports a module printed as [g], with + [dynamic_import] as given, which no expression names. *) +let read_global_with_import ~dynamic_import = + let program : J.program = + { + block = + [ + statement + (Exp + (E.call ~info:Js_call_info.na_full_call (E.js_global "f") + [E.js_global "g"])); + ]; + exports = []; + export_set = Set_ident.empty; + } + in + let import = + Lam_module_ident.of_ml ~dynamic_import (Ident.create_persistent "g") + in + match Js_pass_external_shadow.program ~imports:[import] program with + | {block = [{statement_desc = Exp {expression_desc = Call (_, [arg], _)}}]} -> + arg + | _ -> OUnit.assert_failure "unexpected program shape" let is_global_read (e : J.expression) = match e.expression_desc with @@ -60,4 +84,11 @@ let suites = (List.exists is_global_this_read args) | _ -> OUnit.assert_failure "unexpected case body") | _ -> OUnit.assert_failure "unexpected program shape" ); + ( "a module imported only for its side effects is a binding in scope" + >:: fun _ -> + OUnit.assert_bool "the read goes through globalThis" + (is_global_this_read + (read_global_with_import ~dynamic_import:false)); + OUnit.assert_bool "a dynamic import declares no binding" + (is_global_read (read_global_with_import ~dynamic_import:true)) ); ] diff --git a/tests/tests/src/flat_make_export_test.mjs b/tests/tests/src/flat_make_export_test.mjs index 8b3f96f0d7c..d780da41cc8 100644 --- a/tests/tests/src/flat_make_export_test.mjs +++ b/tests/tests/src/flat_make_export_test.mjs @@ -2,7 +2,7 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as Flat_make_export_use from "./flat_make_export_use.mjs"; Mocha.describe("Flat_make_export_test", () => { @@ -22,7 +22,7 @@ Mocha.describe("Flat_make_export_test", () => { Test_utils.eq("File \"flat_make_export_test.res\", line 23, characters 7-14", Flat_make_export_use.nested, "nested"); Test_utils.eq("File \"flat_make_export_test.res\", line 24, characters 7-14", Flat_make_export_use.recursive, "recursive"); Test_utils.eq("File \"flat_make_export_test.res\", line 25, characters 7-14", Flat_make_export_use.coerced, "coerced"); - Test_utils.eq("File \"flat_make_export_test.res\", line 26, characters 7-14", Stdlib_Option.map(Flat_make_export_use.rebound, f => f()), "rebound"); + Test_utils.eq("File \"flat_make_export_test.res\", line 26, characters 7-14", Flat_make_export_use.rebound !== undefined ? Primitive_option.some(Primitive_option.valFromOption(Flat_make_export_use.rebound)()) : undefined, "rebound"); Test_utils.eq("File \"flat_make_export_test.res\", line 27, characters 7-14", Flat_make_export_use.applied, "applied"); Test_utils.eq("File \"flat_make_export_test.res\", line 28, characters 7-14", Flat_make_export_use.included, "one"); Test_utils.eq("File \"flat_make_export_test.res\", line 29, characters 7-14", Flat_make_export_use.aliased, "one"); diff --git a/tests/tests/src/inline_export.mjs b/tests/tests/src/inline_export.mjs new file mode 100644 index 00000000000..46139cc55f7 --- /dev/null +++ b/tests/tests/src/inline_export.mjs @@ -0,0 +1,32 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; + +function apply(value, f) { + return f(value); +} + +function ordinary(value, f) { + return f(value); +} + +function catchMessage(f) { + try { + return f(); + } catch (raw_e) { + let e = Primitive_exceptions.internalToException(raw_e); + if (e.RE_EXN_ID === "JsExn") { + return Stdlib_JsExn.message(e._1); + } else { + return; + } + } +} + +export { + apply, + ordinary, + catchMessage, +} +/* Stdlib_JsExn Not a pure module */ diff --git a/tests/tests/src/inline_export.res b/tests/tests/src/inline_export.res new file mode 100644 index 00000000000..9dc34ee5de0 --- /dev/null +++ b/tests/tests/src/inline_export.res @@ -0,0 +1,13 @@ +// Used from inline_export_test.res: other modules inline @inline functions, +// without -bs-cross-module-opt. +@inline +let apply = (value, f) => f(value) + +let ordinary = (value, f) => f(value) + +@inline +let catchMessage = f => + try f() catch { + | JsExn(e) => JsExn.message(e) + | _ => None + } diff --git a/tests/tests/src/inline_export_test.mjs b/tests/tests/src/inline_export_test.mjs new file mode 100644 index 00000000000..76504a74a77 --- /dev/null +++ b/tests/tests/src/inline_export_test.mjs @@ -0,0 +1,175 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Mocha from "mocha"; +import * as Test_utils from "./test_utils.mjs"; +import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.mjs"; +import * as Inline_export from "./inline_export.mjs"; +import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; + +let mapped = 3; + +let flatMapped = 4; + +let nested = Primitive_option.some(undefined); + +let mappedNested = Primitive_option.some(Primitive_option.valFromOption(nested)); + +function mapValue(opt) { + if (opt !== undefined) { + return Primitive_option.some((x => x + 1 | 0)(Primitive_option.valFromOption(opt))); + } +} + +function flatMapValue(opt) { + if (opt !== undefined) { + let x = Primitive_option.valFromOption(opt); + return x + 2 | 0; + } +} + +function forEachValue(opt, f) { + if (opt !== undefined) { + return f(Primitive_option.valFromOption(opt)); + } +} + +function filterValue(opt, p) { + if (opt !== undefined && p(Primitive_option.valFromOption(opt))) { + return opt; + } +} + +function mapOrValue(opt, $$default, f) { + if (opt !== undefined) { + return f(Primitive_option.valFromOption(opt)); + } else { + return $$default; + } +} + +function getOrValue(opt, $$default) { + if (opt !== undefined) { + return Primitive_option.valFromOption(opt); + } else { + return $$default; + } +} + +function orElseValue(opt, other) { + if (opt !== undefined) { + return opt; + } else { + return other; + } +} + +function isSomeValue(opt) { + return opt !== undefined; +} + +function isNoneValue(opt) { + return opt === undefined; +} + +let visited = []; + +visited.push(4); + +let fromOrdinary = Inline_export.ordinary(3, x => x + 1 | 0); + +let fromCatch; + +try { + fromCatch = Stdlib_JsError.throwWithMessage("boom"); +} catch (raw_e) { + let e = Primitive_exceptions.internalToException(raw_e); + fromCatch = e.RE_EXN_ID === "JsExn" ? Stdlib_JsExn.message(e._1) : undefined; +} + +Mocha.describe("@inline across modules", () => { + Mocha.test("Option helpers", () => { + Test_utils.eq("File \"inline_export_test.res\", line 30, characters 7-14", mapped, 3); + Test_utils.eq("File \"inline_export_test.res\", line 31, characters 7-14", flatMapped, 4); + Test_utils.eq("File \"inline_export_test.res\", line 32, characters 7-14", mappedNested, Primitive_option.some(undefined)); + Test_utils.eq("File \"inline_export_test.res\", line 33, characters 7-14", mapValue(2), 3); + Test_utils.eq("File \"inline_export_test.res\", line 34, characters 7-14", mapValue(undefined), undefined); + Test_utils.eq("File \"inline_export_test.res\", line 35, characters 7-14", flatMapValue(2), 4); + Test_utils.eq("File \"inline_export_test.res\", line 36, characters 7-14", flatMapValue(undefined), undefined); + visited.push(5); + Test_utils.eq("File \"inline_export_test.res\", line 38, characters 7-14", visited, [ + 4, + 5 + ]); + }); + Mocha.test("only marked exports are inlined", () => { + Test_utils.eq("File \"inline_export_test.res\", line 41, characters 7-14", 4, 4); + Test_utils.eq("File \"inline_export_test.res\", line 42, characters 7-14", fromOrdinary, 4); + Test_utils.eq("File \"inline_export_test.res\", line 43, characters 7-14", fromCatch, "boom"); + }); + Mocha.test("additional Option helpers", () => { + Test_utils.eq("File \"inline_export_test.res\", line 46, characters 7-14", 4, 4); + Test_utils.eq("File \"inline_export_test.res\", line 47, characters 7-14", undefined, undefined); + Test_utils.eq("File \"inline_export_test.res\", line 48, characters 7-14", undefined, undefined); + Test_utils.eq("File \"inline_export_test.res\", line 49, characters 7-14", 3, 3); + Test_utils.eq("File \"inline_export_test.res\", line 50, characters 7-14", 0, 0); + Test_utils.eq("File \"inline_export_test.res\", line 51, characters 7-14", 2, 2); + Test_utils.eq("File \"inline_export_test.res\", line 52, characters 7-14", 0, 0); + Test_utils.eq("File \"inline_export_test.res\", line 53, characters 7-14", 2, 2); + Test_utils.eq("File \"inline_export_test.res\", line 54, characters 7-14", 3, 3); + Test_utils.eq("File \"inline_export_test.res\", line 55, characters 7-14", true, true); + Test_utils.eq("File \"inline_export_test.res\", line 56, characters 7-14", false, false); + Test_utils.eq("File \"inline_export_test.res\", line 57, characters 7-14", false, false); + Test_utils.eq("File \"inline_export_test.res\", line 58, characters 7-14", true, true); + }); + Mocha.test("eager fallback arguments", () => { + let effects = []; + let getDefault = () => { + effects.push("getOr"); + return 0; + }; + let mapDefault = () => { + effects.push("mapOr"); + return 0; + }; + let other = () => { + effects.push("orElse"); + return 0; + }; + getDefault(); + Test_utils.eq("File \"inline_export_test.res\", line 74, characters 7-14", 2, 2); + mapDefault(); + Test_utils.eq("File \"inline_export_test.res\", line 75, characters 7-14", 2, 2); + other(); + Test_utils.eq("File \"inline_export_test.res\", line 76, characters 7-14", 2, 2); + Test_utils.eq("File \"inline_export_test.res\", line 77, characters 7-14", effects, [ + "getOr", + "mapOr", + "orElse" + ]); + }); +}); + +let fromExport = 4; + +export { + mapped, + flatMapped, + nested, + mappedNested, + mapValue, + flatMapValue, + forEachValue, + filterValue, + mapOrValue, + getOrValue, + orElseValue, + isSomeValue, + isNoneValue, + visited, + fromExport, + fromOrdinary, + fromCatch, +} +/* Not a pure module */ diff --git a/tests/tests/src/inline_export_test.res b/tests/tests/src/inline_export_test.res new file mode 100644 index 00000000000..05112ac1e35 --- /dev/null +++ b/tests/tests/src/inline_export_test.res @@ -0,0 +1,79 @@ +// @inline functions from other modules: Option helpers from the runtime and +// Inline_export, compiled without -bs-cross-module-opt. +open Mocha +open Test_utils + +let mapped = Some(2)->Option.map(x => x + 1) +let flatMapped = Some(2)->Option.flatMap(x => Some(x + 2)) +let nested: option> = Some(None) +let mappedNested = nested->Option.map(x => x) +let mapValue = opt => opt->Option.map(x => x + 1) +let flatMapValue = opt => opt->Option.flatMap(x => Some(x + 2)) +let forEachValue = (opt, f) => opt->Option.forEach(f) +let filterValue = (opt, p) => opt->Option.filter(p) +let mapOrValue = (opt, default, f) => opt->Option.mapOr(default, f) +let getOrValue = (opt, default) => opt->Option.getOr(default) +let orElseValue = (opt, other) => opt->Option.orElse(other) +let isSomeValue = opt => opt->Option.isSome +let isNoneValue = opt => opt->Option.isNone + +let visited: array = [] +Some(4)->Option.forEach(x => visited->Array.push(x)) +None->Option.forEach(_ => visited->Array.push(0)) + +let fromExport = Inline_export.apply(3, x => x + 1) +let fromOrdinary = Inline_export.ordinary(3, x => x + 1) +let fromCatch = Inline_export.catchMessage(() => JsError.throwWithMessage("boom")) + +describe("@inline across modules", () => { + test("Option helpers", () => { + eq(__LOC__, mapped, Some(3)) + eq(__LOC__, flatMapped, Some(4)) + eq(__LOC__, mappedNested, Some(None)) + eq(__LOC__, mapValue(Some(2)), Some(3)) + eq(__LOC__, mapValue(None), None) + eq(__LOC__, flatMapValue(Some(2)), Some(4)) + eq(__LOC__, flatMapValue(None), None) + forEachValue(Some(5), x => visited->Array.push(x)) + eq(__LOC__, visited, [4, 5]) + }) + test("only marked exports are inlined", () => { + eq(__LOC__, fromExport, 4) + eq(__LOC__, fromOrdinary, 4) + eq(__LOC__, fromCatch, Some("boom")) + }) + test("additional Option helpers", () => { + eq(__LOC__, filterValue(Some(4), x => x > 3), Some(4)) + eq(__LOC__, filterValue(Some(2), x => x > 3), None) + eq(__LOC__, filterValue(None, _ => true), None) + eq(__LOC__, mapOrValue(Some(2), 0, x => x + 1), 3) + eq(__LOC__, mapOrValue(None, 0, x => x + 1), 0) + eq(__LOC__, getOrValue(Some(2), 0), 2) + eq(__LOC__, getOrValue(None, 0), 0) + eq(__LOC__, orElseValue(Some(2), Some(3)), Some(2)) + eq(__LOC__, orElseValue(None, Some(3)), Some(3)) + eq(__LOC__, isSomeValue(Some(2)), true) + eq(__LOC__, isSomeValue(None), false) + eq(__LOC__, isNoneValue(Some(2)), false) + eq(__LOC__, isNoneValue(None), true) + }) + test("eager fallback arguments", () => { + let effects = [] + let getDefault = () => { + effects->Array.push("getOr") + 0 + } + let mapDefault = () => { + effects->Array.push("mapOr") + 0 + } + let other = () => { + effects->Array.push("orElse") + Some(0) + } + eq(__LOC__, Some(2)->Option.getOr(getDefault()), 2) + eq(__LOC__, Some(2)->Option.mapOr(mapDefault(), x => x), 2) + eq(__LOC__, Some(2)->Option.orElse(other()), Some(2)) + eq(__LOC__, effects, ["getOr", "mapOr", "orElse"]) + }) +}) diff --git a/tests/tests/src/inline_shadowed_import_lib.mjs b/tests/tests/src/inline_shadowed_import_lib.mjs new file mode 100644 index 00000000000..7d30cbacc6e --- /dev/null +++ b/tests/tests/src/inline_shadowed_import_lib.mjs @@ -0,0 +1,14 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +globalThis.inlineShadowedImportLoaded = true +; + +function double(x) { + return (x << 1); +} + +export { + double, +} +/* Not a pure module */ diff --git a/tests/tests/src/inline_shadowed_import_lib.res b/tests/tests/src/inline_shadowed_import_lib.res new file mode 100644 index 00000000000..1ac31a4a6ce --- /dev/null +++ b/tests/tests/src/inline_shadowed_import_lib.res @@ -0,0 +1,6 @@ +// Loading this module has a side effect, so a module that uses it imports it +// even when every use is inlined. +%%raw(`globalThis.inlineShadowedImportLoaded = true`) + +@inline +let double = x => x * 2 diff --git a/tests/tests/src/inline_shadowed_import_test.mjs b/tests/tests/src/inline_shadowed_import_test.mjs new file mode 100644 index 00000000000..f2a6d8700e4 --- /dev/null +++ b/tests/tests/src/inline_shadowed_import_test.mjs @@ -0,0 +1,22 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Mocha from "mocha"; +import * as Test_utils from "./test_utils.mjs"; +import * as Inline_shadowed_import_lib from "./inline_shadowed_import_lib.mjs"; + +globalThis.Inline_shadowed_import_lib = 70 +; + +Mocha.describe("Inline_shadowed_import_test", () => { + Mocha.test("a global named like an import whose uses are all inlined", () => { + Test_utils.eq("File \"inline_shadowed_import_test.res\", line 14, characters 7-14", 4, 4); + Test_utils.eq("File \"inline_shadowed_import_test.res\", line 15, characters 7-14", globalThis.Inline_shadowed_import_lib, 70); + }); +}); + +let doubled = 4; + +export { + doubled, +} +/* Not a pure module */ diff --git a/tests/tests/src/inline_shadowed_import_test.res b/tests/tests/src/inline_shadowed_import_test.res new file mode 100644 index 00000000000..82e0ec8b118 --- /dev/null +++ b/tests/tests/src/inline_shadowed_import_test.res @@ -0,0 +1,17 @@ +// A JS global with the name of a module that is imported, though every use of +// it is inlined, is still read as the global, not as the import. +open Mocha +open Test_utils + +%%raw(`globalThis.Inline_shadowed_import_lib = 70`) + +@val external libGlobal: int = "Inline_shadowed_import_lib" + +let doubled = Inline_shadowed_import_lib.double(2) + +describe(__MODULE__, () => { + test("a global named like an import whose uses are all inlined", () => { + eq(__LOC__, doubled, 4) + eq(__LOC__, libGlobal, 70) + }) +}) diff --git a/tests/tests/src/int_overflow_test.mjs b/tests/tests/src/int_overflow_test.mjs index 82554707887..667e82d1ef9 100644 --- a/tests/tests/src/int_overflow_test.mjs +++ b/tests/tests/src/int_overflow_test.mjs @@ -3,7 +3,7 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; import * as Stdlib_Float from "@rescript/runtime/lib/es6/Stdlib_Float.mjs"; -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; function hash_variant(s) { let accu = 0; @@ -49,8 +49,14 @@ Mocha.describe("Int_overflow_test", () => { Mocha.test("hash_variant_test2", () => Test_utils.eq("File \"int_overflow_test.res\", line 61, characters 38-45", hash_variant2("xxyyzxzzyy"), -449896130)); Mocha.test("int_literal_flow", () => Test_utils.eq("File \"int_overflow_test.res\", line 62, characters 36-43", -1, -1)); Mocha.test("int_literal_flow2", () => Test_utils.eq("File \"int_overflow_test.res\", line 63, characters 37-44", -1, -1)); - Mocha.test("float_conversion_test1", () => Test_utils.eq("File \"int_overflow_test.res\", line 65, characters 7-14", Stdlib_Option.map(Stdlib_Float.fromString("3"), prim => prim | 0), 3)); - Mocha.test("float_conversion_test2", () => Test_utils.eq("File \"int_overflow_test.res\", line 68, characters 7-14", Stdlib_Option.map(Stdlib_Float.fromString("3.2"), prim => prim | 0), 3)); + Mocha.test("float_conversion_test1", () => { + let opt = Stdlib_Float.fromString("3"); + Test_utils.eq("File \"int_overflow_test.res\", line 65, characters 7-14", opt !== undefined ? Primitive_option.some(Primitive_option.valFromOption(opt) | 0) : undefined, 3); + }); + Mocha.test("float_conversion_test2", () => { + let opt = Stdlib_Float.fromString("3.2"); + Test_utils.eq("File \"int_overflow_test.res\", line 68, characters 7-14", opt !== undefined ? Primitive_option.some(Primitive_option.valFromOption(opt) | 0) : undefined, 3); + }); }); let max_int = 2147483647; diff --git a/tests/tests/src/stdlib/Stdlib_ObjectTests.mjs b/tests/tests/src/stdlib/Stdlib_ObjectTests.mjs index eee989fd219..82a12bde359 100644 --- a/tests/tests/src/stdlib/Stdlib_ObjectTests.mjs +++ b/tests/tests/src/stdlib/Stdlib_ObjectTests.mjs @@ -2,8 +2,8 @@ import * as Test from "./Test.mjs"; import * as Stdlib_BigInt from "@rescript/runtime/lib/es6/Stdlib_BigInt.mjs"; -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; let eq = Primitive_object.equal; @@ -445,7 +445,7 @@ runGetTest({ source: () => ({ a: 1 }), - get: i => Stdlib_Option.isSome(i["toString"]), + get: i => i["toString"] !== undefined, expected: true }); @@ -476,10 +476,20 @@ runGetTest({ 3 ] }), - get: i => Stdlib_Option.getOr(Stdlib_Option.map(i["a"], i => i.concat([ - 4, - 5 - ])), []), + get: i => { + let opt = i["a"]; + let f = i => i.concat([ + 4, + 5 + ]); + let opt$1 = opt !== undefined ? Primitive_option.some(f(Primitive_option.valFromOption(opt))) : undefined; + let $$default = []; + if (opt$1 !== undefined) { + return Primitive_option.valFromOption(opt$1); + } else { + return $$default; + } + }, expected: [ 1, 2, diff --git a/tests/tests/src/stdlib/Stdlib_TempTests.mjs b/tests/tests/src/stdlib/Stdlib_TempTests.mjs index af63b4cbd79..8a18db36c38 100644 --- a/tests/tests/src/stdlib/Stdlib_TempTests.mjs +++ b/tests/tests/src/stdlib/Stdlib_TempTests.mjs @@ -5,7 +5,6 @@ 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_Float from "@rescript/runtime/lib/es6/Stdlib_Float.mjs"; import * as Stdlib_BigInt from "@rescript/runtime/lib/es6/Stdlib_BigInt.mjs"; -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as Primitive_bigint from "@rescript/runtime/lib/es6/Primitive_bigint.mjs"; import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as Stdlib_IntlTests from "./intl/Stdlib_IntlTests.mjs"; @@ -137,7 +136,11 @@ console.info("BigInt"); console.info("---"); -console.log(Primitive_bigint.div(BigInt(1), Stdlib_Option.getOr(Stdlib_BigInt.fromFloat(12.0), 0n))); +let tmp$1 = BigInt(1); + +let opt = Stdlib_BigInt.fromFloat(12.0); + +console.log(Primitive_bigint.div(tmp$1, opt !== undefined ? Primitive_option.valFromOption(opt) : 0n)); console.info(""); @@ -202,13 +205,11 @@ console.log(regex.test(string)); let result = regex.exec(string); -let result$1 = result == null ? undefined : Primitive_option.some(result); - -console.log(Stdlib_Option.map(result$1, prim => prim.input)); +console.log(!(result == null) ? Primitive_option.some(result.input) : undefined); -console.log(Stdlib_Option.map(result$1, prim => prim.index)); +console.log(!(result == null) ? Primitive_option.some(result.index) : undefined); -console.log(Stdlib_Option.map(result$1, prim => prim.slice(1))); +console.log(!(result == null) ? Primitive_option.some(result.slice(1)) : undefined); console.info(""); @@ -321,6 +322,8 @@ let formatter = Stdlib_IntlTests.formatter; let segments = Stdlib_IntlTests.segments; +let result$1 = result == null ? undefined : Primitive_option.some(result); + export { _collator, collator, diff --git a/tests/tests/src/stdlib/Stdlib_TemporalTests.mjs b/tests/tests/src/stdlib/Stdlib_TemporalTests.mjs index 18c76469a96..5af66905034 100644 --- a/tests/tests/src/stdlib/Stdlib_TemporalTests.mjs +++ b/tests/tests/src/stdlib/Stdlib_TemporalTests.mjs @@ -2,7 +2,6 @@ import * as Test from "./Test.mjs"; import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.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_object from "@rescript/runtime/lib/es6/Primitive_object.mjs"; import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; @@ -328,7 +327,9 @@ Test.run([ 57 ], "getTimeZoneTransition without a transition" -], Stdlib_Option.isNone(Primitive_option.fromNullable(utc.getTimeZoneTransition("previous"))), eq, true); +], Primitive_option.fromNullable(utc.getTimeZoneTransition("previous")) === undefined, eq, true); + +let opt = utc.withTimeZone("America/New_York").getTimeZoneTransition("next"); Test.run([ [ @@ -338,7 +339,7 @@ Test.run([ 54 ], "getTimeZoneTransition with a transition" -], Stdlib_Option.map(Primitive_option.fromNullable(utc.withTimeZone("America/New_York").getTimeZoneTransition("next")), transition => transition.toString()), eq, "2024-03-10T03:00:00-04:00[America/New_York]"); +], !(opt == null) ? Primitive_option.some(opt.toString()) : undefined, eq, "2024-03-10T03:00:00-04:00[America/New_York]"); Test.run([ [ diff --git a/tests/tests/src/stdlib/Stdlib_TestTests.mjs b/tests/tests/src/stdlib/Stdlib_TestTests.mjs index bca6b692aad..67b37cff720 100644 --- a/tests/tests/src/stdlib/Stdlib_TestTests.mjs +++ b/tests/tests/src/stdlib/Stdlib_TestTests.mjs @@ -2,8 +2,8 @@ import * as Test from "./Test.mjs"; import * as Stdlib_BigInt from "@rescript/runtime/lib/es6/Stdlib_BigInt.mjs"; -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; let eq = Primitive_object.equal; @@ -11,7 +11,9 @@ let nan = NaN; let infinity = Number.POSITIVE_INFINITY; -let bign = Stdlib_Option.getOr(Stdlib_BigInt.fromFloat(Number.MAX_VALUE), 0n); +let opt = Stdlib_BigInt.fromFloat(Number.MAX_VALUE); + +let bign = opt !== undefined ? Primitive_option.valFromOption(opt) : 0n; let bign$1 = bign + bign; diff --git a/tests/tests/src/stdlib/intl/Stdlib_IntlTests.mjs b/tests/tests/src/stdlib/intl/Stdlib_IntlTests.mjs index 85e250c1b5e..7945fa8b097 100644 --- a/tests/tests/src/stdlib/intl/Stdlib_IntlTests.mjs +++ b/tests/tests/src/stdlib/intl/Stdlib_IntlTests.mjs @@ -1,7 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.mjs"; -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; import * as Stdlib_Intl_LocaleTest from "./Stdlib_Intl_LocaleTest.mjs"; @@ -58,7 +57,8 @@ try { let e$2 = Primitive_exceptions.internalToException(raw_e$2); if (e$2.RE_EXN_ID === "JsExn") { let e$3 = e$2._1; - let message = Stdlib_Option.map(Stdlib_JsExn.message(e$3), prim => prim.toLowerCase()); + let opt = Stdlib_JsExn.message(e$3); + let message = opt !== undefined ? Primitive_option.some(Primitive_option.valFromOption(opt).toLowerCase()) : undefined; if (message === "invalid key : someinvalidkey") { console.log("Caught expected error"); } else {