Repository navigation
Count the exception a try handler binds as bound - #9485
Conversation
Changelog💅 Polish
Semantic Diff1 commit · Full page Count the exception a try handler binds as bound87fe94d · cknitt + Claude · Nov 29, 2026, 09:03 UTC
JS modified (a module using an // inline_assign_cross_module_lib.res
@inline
let orDefault = (f, default) =>
try f() catch {
| _ => default
}
// inline_assign_cross_module_test.res
let caught = () => (
Inline_assign_cross_module_lib.orDefault(() => 1, 0),
Inline_assign_cross_module_lib.orDefault(() => JsError.throwWithMessage("boom"), 2),
)
-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
|
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
✅ Compiler benchmarksAllocated wordsIn total: 672,761,691 → 672,762,274 (±0.00%). Generated projects: 630,418,670 → 630,418,804 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 9,225,746,058 → 9,225,758,584 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 27,303,751 → 27,303,679 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request 87fe94d compared with base ed1ff33 in this run. |
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
44b3341 to
17aa2b0
Compare
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.
JS modified (a module using an @inline function with try … catch):
Example:
// inline_assign_cross_module_lib.res
@inline
let orDefault = (f, default) =>
try f() catch {
| _ => default
}
// inline_assign_cross_module_test.res
let caught = () => (
Inline_assign_cross_module_lib.orDefault(() => 1, 0),
Inline_assign_cross_module_lib.orDefault(() => JsError.throwWithMessage("boom"), 2),
)
Before (js):
return [
Inline_assign_cross_module_lib.orDefault(() => 1, 0),
Inline_assign_cross_module_lib.orDefault(() => Stdlib_JsError.throwWithMessage("boom"), 2)
];
After (js): the second copy's binder is renamed
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.
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>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## inline-fallback-unloadable-module #9485 +/- ##
=====================================================================
- Coverage 82.45% 82.45% -0.01%
=====================================================================
Files 465 465
Lines 65984 65987 +3
=====================================================================
+ Hits 54406 54408 +2
- Misses 11578 11579 +1
🚀 New features to boost your workflow:
|
17aa2b0 to
87fe94d
Compare
Lam_closuredidn't count the variable atry … catchhandler binds as bound, so inside the handler it looked captured from outside. Every function containing a handler then counted as not closed. So an@inlinefunction with atry … catchwas never stored for other modules, and was always called.Inlined copies get fresh names for that variable, since
Lam_bounded_varsrenames it like any other binder.New test:
orDefaultintests/tests/src/inline_assign_cross_module_lib.res, an@inlinefunction with a handler, inlined twice in one function ofinline_assign_cross_module_test.res. Both copies are inlined, and the second binder is renamed (exn$1). Other outputs, including the runtime's and Belt's, are the same.This replaces #9481, which GitHub closed as merged when the stack was reordered: its commit became part of the branch it was based on. Part of stack #9486, after #9478.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D