Repository navigation
Stop merging a long run of assignments into one deep expression - #1490
Conversation
With -localOptimizations, SimpleRewrites merges `x = e1; x = x + e2` into `x = e1 + e2`, and one walk merges a whole run, so a generated run of `sum += gN` became one expression as deep as the run. The flatten after it overflowed the Java stack from about a thousand statements, and with alternating operators the Lua output nested a parenthesis per level, which luac rejects beyond 200. A merge now stops once the left operands hold 64 operators.
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f5f1f7a9ec
ℹ️ 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".
The bound counted only operators down the left operands, so a first value nested deep on its right operands could still be merged past what luac loads.
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
With -localOptimizations, SimpleRewrites merges
x = e1; x = x ⊕ e2intox = e1 ⊕ e2, and one walk merges a whole run of such statements. A generated run ofsum += g0...sum += g3299therefore became a single expression 3300 levels deep. The flatten at the end of the same pass then overflowed the Java stack (Flatten.flattenExprs -> ImOperatorCall.flatten -> Flatten.flatten). On the default 1 MB stack this happens from about 850 statements with SimpleRewrites cold, and between 1200 and 1500 statements in a full compile.The same growth also breaks Lua output well before the stack. When the operators alternate (
h *= a,h += b), each level is a parenthesis in the Lua output, and luac rejects 150 pairs with "too many C levels (limit is 200)".The deep expression exists only because this pass builds it from flat statements, so I fixed it there: the merge now stops once the left operands already hold 64 operators (SimpleRewrites.MAX_MERGED_OPERATORS). I chose this over making the walkers independent of the Java stack because the Lua case is a limit in the emitted script, not in the compiler, and because the IM walkers (generated copy, visitors, attributes, flatten, translators, printers) all recurse. A long run still merges into one assignment per 64 statements. Output is unchanged unless an expression already has 64 operators down its left operands.
Tests (OptimizerTests):
OptimizerTests, LuaBackendAuditTests and DeterministicChecks pass. Compiling the repros twice gives byte-identical Jass and Lua, and pjass parses all five Jass variants. This is an IM-only change with no host assumptions; I checked it on Windows only.
Measured on the 3.0.0 client (Lua,
-inline -localOptimizations, 150 pairs ofh *= aandh += bin one function): built by master before this change, the script nests 300 parentheses and the map never started; the client stayed at the main menu and exited without running it. Built with this change, the deepest line nests 64, the map loads andmix(1, 1)returns 151. The same function in a Jass build loads and returns 151 as well.