Skip to content

[5.2] Add workaround for stack overflow in tree visitation when having a reduced stack size #208

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

akyrtzi
Copy link
Contributor

@akyrtzi akyrtzi commented Mar 25, 2020

Cherry-pick of #205

To determine the correct specific visitation function for a syntax node,
we need to switch through a huge switch statement that covers all syntax
types. In debug builds, the cases of this switch statement do not share
stack space (rdar://55929175). Because of this, the switch statement
requires allocates about 15KB of stack space. In scenarios with reduced
stack size (in particular dispatch queues), this often results in a
stack overflow during syntax tree visitation.

To circumvent this problem, this commit moves adds a flag that moves the
retrieval of the specific visitation function to its own function. This
way, the stack frame that determines the correct visitiation 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.

The workaround currently has a 50% performance decrease in release
builds, so it is only used in debug builds.

@akyrtzi
Copy link
Contributor Author

akyrtzi commented Mar 25, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 5e278e4

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 5e278e4

…duced stack size

To determine the correct specific visitation function for a syntax node,
we need to switch through a huge switch statement that covers all syntax
types. In debug builds, the cases of this switch statement do not share
stack space (rdar://55929175). Because of this, the switch statement
requires allocates about 15KB of stack space. In scenarios with reduced
stack size (in particular dispatch queues), this often results in a
stack overflow during syntax tree visitation.

To circumvent this problem, this commit moves adds a flag that moves the
retrieval of the specific visitation function to its own function. This
way, the stack frame that determines the correct visitiation 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.

The workaround currently has a 50% performance decrease in release
builds, so it is only used in debug builds.
@akyrtzi akyrtzi force-pushed the 5.2-stack-overflow-on-debug branch from 5e278e4 to f622dcc Compare March 25, 2020 21:47
@akyrtzi
Copy link
Contributor Author

akyrtzi commented Mar 25, 2020

@swift-ci Please test

@swiftlang swiftlang deleted a comment from swift-ci Mar 25, 2020
@swiftlang swiftlang deleted a comment from swift-ci Mar 25, 2020
@akyrtzi akyrtzi merged commit 0688b9c into swiftlang:swift-5.2-branch Mar 26, 2020
@akyrtzi akyrtzi deleted the 5.2-stack-overflow-on-debug branch March 26, 2020 00:12
adevress pushed a commit to adevress/swift-syntax that referenced this pull request Jan 14, 2024
Rewrite and fix `OneVariableDeclarationPerLine`.
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