refactor(codegen): hoist AllocationStatement allocas to function entry#1656
Open
refactor(codegen): hoist AllocationStatement allocas to function entry#1656
Conversation
…loop-desugaring
This reverts commit 2bd0bee.
This changes `AllocationStatement` AST semantics globally in codegen: stack storage is now created in the function entry block instead of at the current insertion point. Initialization still happens at the original statement location, so only the allocation is hoisted while reset/store semantics remain local to the lowered statement. This is a broader codegen refactor, but it also fixes the regression from the new loop desugaring. FOR and REPEAT lowering introduces synthetic AllocationStatement temporaries such as ran_once_N and is_incrementing_N. In nested lowered loops those allocas previously ended up inside outer loop bodies, and at -Onone each iteration reserved fresh stack space. Nested FOR loops with large iteration counts could therefore exhaust the stack and crash with SIGSEGV. By hoisting AllocationStatement storage to the entry block, nested lowered loops now allocate those temporaries once per function invocation while still reinitializing them at the original control-flow location. Add codegen and lit regression coverage for the nested loop reproducer and update affected snapshots.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR changes the behavior of
AllocationStatementhoisting them at the function entry block rather than in-place where they were defined. For examplewill roughly (in codegen) translate to
The example also provides the motivation for that behavioral change, i.e. not doing so will eventually "overflow" the stack reaching the maximum stack-memory limit (which on my machine was something like ~8MB)