Count the exception a try handler binds as bound
Why
Lam_closure did not add the variable a try … catch handler binds to the bound variables, so inside the handler it counted as free, and every function containing a handler looked as if it captured a variable. Such functions were never closed, so an @inline function with a try … catch was never stored for other modules and always called. Inlined copies get fresh names for that variable, since Lam_bounded_vars renames it like any other binder.
modifiedJS a module using an @inline function with try … catch
// Inline_export.res@inlinelet catchMessage = f => try f() catch { | JsExn(e) => JsExn.message(e) | _ => None } // inline_export_test.reslet fromCatch = Inline_export.catchMessage(() => JsError.throwWithMessage("boom"))
js
Before
After
let fromCatch = Inline_export.catchMessage(() => Stdlib_JsError.throwWithMessage("boom")); 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;}
Review
- Does inlining within a module change? Not in the repository's tests: the runtime, Belt and every test output other than this one are the same.