Repository navigation
Rename a for loop's start expression once when inlining - #9396
Conversation
Changelog🏠 Internal
Semantic Diff2 commits · Full page Rename a for loop's start expression once when inliningec4cc89 · cknitt + Claude · Nov 22, 2026, 20:52 UTC Lam_bounded_vars renames the variables bound inside a function body before it is inlined. Its for-loop case rewrote the start expression twice ( Test the renaming of a for loop's start expression when inlining4c7a4c3 · cknitt + Claude · Nov 23, 2026, 08:37 UTC The previous commit had no lasting test, as Codex pointed out. A unit test now rewrites a for loop whose start expression binds a variable and checks that the binder, its use and the renaming map agree, with one map entry per binder; with the old double rename the map records a name the result doesn't use. An end-to-end test applies two function literals right away, which inlines them through Lam_bounded_vars, with a let and a callback in the loop's start expression, and checks their results. Functions with loops are otherwise too big to inline, so this is the path that reaches the for-loop case. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9396 +/- ##
=======================================
Coverage 82.21% 82.21%
=======================================
Files 460 461 +1
Lines 65552 65573 +21
=======================================
+ Hits 53892 53914 +22
+ Misses 11660 11659 -1
🚀 New features to boost your workflow:
|
✅ Compiler benchmarksAllocated wordsIn total: 636,986,837 → 636,986,804 (±0.00%). Generated projects: 629,044,295 → 629,044,801 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 9,221,398,536 → 9,221,420,665 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 25,976,823 → 25,976,816 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request 4c7a4c3 compared with base 449d6e7 in this run. |
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b8ed82e324
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
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 |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
Lam_bounded_vars renames the variables bound inside a function body before it is inlined. Its for-loop case rewrote the start expression twice (`let l1 = aux l1 in ... Lambda.for_ ident (aux l1) ...`), a slip that has been there since at least 2019. The second pass only renamed the fresh binders again, consistently, so the result was the same program; JS output and diagnostics are byte-identical on 77 benchmark files, and allocation drops by 56 words in total. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH Signed-off-by: Christoph Knittel <ck@cca.io>
The previous commit had no lasting test, as Codex pointed out. A unit test now rewrites a for loop whose start expression binds a variable and checks that the binder, its use and the renaming map agree, with one map entry per binder; with the old double rename the map records a name the result doesn't use. An end-to-end test applies two function literals right away, which inlines them through Lam_bounded_vars, with a let and a callback in the loop's start expression, and checks their results. Functions with loops are otherwise too big to inline, so this is the path that reaches the for-loop case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH Signed-off-by: Christoph Knittel <ck@cca.io>
a07c272 to
4c7a4c3
Compare
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9396 |
Lam_bounded_varsrenames the variables bound inside a function body before the function is inlined. Itsforloop case rewrote the loop's start expression twice:This has been there since at least 2019. The second pass only renamed the already fresh binders again, consistently, so the result was the same program. Now the start expression is rewritten once.
JS output and diagnostics are byte-identical on 77 benchmark files.
New tests:
tests/ounit_tests/ounit_lam_bounded_vars_tests.mlrewrites a for loop whose start expression binds a variable, and checks that the binder, its use and the renaming map agree. It fails with the old double rename.tests/tests/src/inline_for_start_test.resapplies two function literals right away, which inlines them throughLam_bounded_vars, with aletand a callback in the loop's start expression. Functions with loops are otherwise too big to inline, so this is the path that reaches the for-loop case.🤖 Generated with Claude Code
https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH