Skip to content
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

Port stackoverflow fix from Roslyn to SourceGenerator PolyFill #76955

Merged
merged 1 commit into from
Oct 20, 2022

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Oct 12, 2022

Fixes #76953 for 8.0 and onwards
Ports dotnet/roslyn#64322 back to the runtime polyfill.

Corresponding 6.0 servicing fix is here: #76946
Corresponding 7.0 servicing fix is here: #76954

Customer Impact

Customers using 7.0.0 sdk can run into stack-overflows in the Source-Generator helper code code, in both VS and compiler, when compiling code with certain problematic code-constructs. This happens for tehse customers even if they are not using Source-Generators themselves as the overflow occurs in the code that is trying to determine if the generator should run.

This commonly happens when working with, or trying to compile, generated code produced by tools like T4 or Antlr (which commonly generate deeply recursive trees).

Examples of code that causes this are:

string data = "..." + "..." + "..." + /* thousands more concatenations */ + "..." + "..." + "...";

In a case like this, the concatenation code is not a balanced tree but instead, effectively, a linear tree like so:

image

The existing code works by recursing the user's parse tree, which ends up blowing the stack in cases like these.

As this is a stack overflow, it is fairly catastrophic for the user. Absent them changing this code outside of VS, which may not be possible for tool-generated code, the only workaround is to disable these generators (like System.Text.Json). Disabling the generator may be suitable for customers that are not using that generator, but will completely break users who are using it and who do have these code constructs.

Testing

Risk

Low. This is a simple port of a change made in roslyn to switch from implicit recursion, to using an explicit stack. This is a refactoring that roslyn is familiar with as stack-overflows are not uncommon for us as users do have these sorts of files, and recursive solutions have often had to be refactored in a similar fashion.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@CyrusNajmabadi
Copy link
Member Author

@joperezr Can we take this? Or will the 7.0 fix naturally flow into main?

@joperezr
Copy link
Member

Yes, we can take it. 7.0 doesn't flow to main in dotnet/runtime, so we actually have to take it, I just missed the email for this PR. Will manually validate in a bit and merge once it is ready

@CyrusNajmabadi
Copy link
Member Author

Great, thanks!

@CyrusNajmabadi
Copy link
Member Author

@joperezr Just pinging to make sure this is not lost :)

@joperezr
Copy link
Member

Failures in OSX are unrelated, so I'll go ahead and merge. Thanks @CyrusNajmabadi!

@joperezr joperezr merged commit 6e6032c into dotnet:main Oct 20, 2022
@CyrusNajmabadi
Copy link
Member Author

Thanks!

@CyrusNajmabadi CyrusNajmabadi deleted the generatorStackOverflowMain branch October 20, 2022 19:06
@ghost ghost locked as resolved and limited conversation to collaborators Nov 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StackOverflowException on web project code analysis
2 participants