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_assign_cross_module_lib.res@inlinelet orDefault = (f, default) => try f() catch { | _ => default } // inline_assign_cross_module_test.reslet caught = () => ( Inline_assign_cross_module_lib.orDefault(() => 1, 0), Inline_assign_cross_module_lib.orDefault(() => JsError.throwWithMessage("boom"), 2),)
js
Before
After the second copy's binder is renamed
return [ Inline_assign_cross_module_lib.orDefault(() => 1, 0), Inline_assign_cross_module_lib.orDefault(() => Stdlib_JsError.throwWithMessage("boom"), 2)]; function caught() { let tmp; try { tmp = 1; } catch (exn) { tmp = 0; } let tmp$1; try { throw new Error("boom"); } catch (exn$1) { tmp$1 = 2; } return [ tmp, tmp$1 ];}
Review
- Does inlining within a module change? Not in the repository's tests: the runtime, Belt and every other test output are the same.