Skip to content

Use two-step dispatch to SyntaxVisitor.vistImpl #2121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Aug 30, 2023

SyntaxRewriter has had a problem with stack allocation space for a while because cases in a switch statement don’t share stack space in debug builds (rdar://55929175). We started seeing this issue with SyntaxVisitor as well now. Use the same approach to fix the problem:

To circumvent this problem, make calling the specific visitation function a two-step process: First determine the function to call in this function and return a reference to it, then call it. This way, the stack frame that determines the correct visitation function will be popped of the stack before the function is being called, making the switch's stack space transient instead of having it linger in the call stack.

And to make the entire approach look sane, allow 4 arguments on the same line for SyntaxVisitor instead of the 3 that we allow in all other files.

@ahoppen ahoppen requested a review from bnbarham August 30, 2023 23:02
@ahoppen
Copy link
Member Author

ahoppen commented Aug 30, 2023

@swift-ci Please test

Comment on lines 141 to 142
/// stack space (rdar://55929175). Because of this, the switch statement
/// requires allocates about 15KB of stack space. In scenarios with reduced
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// stack space (rdar://55929175). Because of this, the switch statement
/// requires allocates about 15KB of stack space. In scenarios with reduced
/// stack space (rdar://55929175). Because of this, the switch statement
/// requires about 15KB of stack space. In scenarios with reduced

`SyntaxRewriter` has had a problem with stack allocation space for a while because cases in a switch statement don’t share stack space in debug builds (rdar://55929175). We started seeing this issue with `SyntaxVisitor` as well now. Use the same approach to fix the problem:

To circumvent this problem, make calling the specific visitation function a two-step process: First determine the function to call in this function and return a reference to it, then call it. This way, the stack frame that determines the correct visitation function will be popped of the stack before the function is being called, making the switch's stack space transient instead of having it linger in the call stack.

And to make the entire approach look sane, allow 4 arguments on the same line for SyntaxVisitor instead of the 3 that we allow in all other files.
@ahoppen ahoppen force-pushed the ahoppen/syntax-visitor-visitation-function branch from 3d6578a to cfe2a11 Compare August 30, 2023 23:47
@ahoppen
Copy link
Member Author

ahoppen commented Aug 30, 2023

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge August 30, 2023 23:47
@kimdv
Copy link
Contributor

kimdv commented Aug 31, 2023

@swift-ci please test Windows

@ahoppen ahoppen merged commit 12e2eb8 into swiftlang:main Aug 31, 2023
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