Skip to content

20260514 tricky cse assign - #482

Merged
prozacchiwawa merged 5 commits into
mainfrom
20260514-tricky-cse-assign
May 28, 2026
Merged

prozacchiwawa merged 5 commits into
mainfrom
20260514-tricky-cse-assign

Conversation

@prozacchiwawa

@prozacchiwawa prozacchiwawa commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Because this would have kept programs from compiling, this does not need to be feature gated.


Note

Medium Risk
Changes compiler optimization semantics for assign/CSE interaction; incorrect ceiling logic could skip valid CSE or still miscompile, though new tests lock in the reported breakage case.

Overview
Fixes common subexpression elimination (CSE) incorrectly hoisting shared code above assign / let bindings when one occurrence lives in a binding that depends on other names in that form (e.g. B uses A while (+ A 1) is also duplicated in the assign body).

detect_common_cse_root now takes an optional ceiling path and returns Option: it refuses a root above a containing assign body that still provides names the subexpression needs, or when the only common root would sit above that ceiling. cse_optimize_bodyform computes that ceiling via new match_bindings (names in the duplicated expr ∩ names bound by enclosing lets) and skips the CSE rewrite when no safe root exists.

Adds regression coverage: unit test for ceiling rejection, cse-complex-2.clsp, and test_cse_breakage_example_lift_outside_bindings (compile + run expects 1).

Reviewed by Cursor Bugbot for commit 5cfd027. Bugbot is set up for automated code reviews on this repo. Configure here.

@prozacchiwawa
prozacchiwawa marked this pull request as ready for review May 18, 2026 16:04
Comment thread src/compiler/optimize/cse.rs
Co-authored-by: arty <prozacchiwawa@users.noreply.github.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3accfbc. Configure here.

Comment thread src/compiler/optimize/cse.rs Outdated
aqk
aqk previously approved these changes May 26, 2026
@prozacchiwawa
prozacchiwawa merged commit 84cb418 into main May 28, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants