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

[release/7.0] Port stackoverflow fix from Roslyn to SourceGenerator PolyFill #76954

Merged

Conversation

CyrusNajmabadi
Copy link
Member

Fixes #76953 in the 7.0 branch.
Ports dotnet/roslyn#64322 back to the runtime polyfill.

Corresponding 6.0 fix is here: #76946

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.

@ghost ghost assigned CyrusNajmabadi Oct 12, 2022
@CyrusNajmabadi CyrusNajmabadi added the Servicing-consider Issue for next servicing release review label Oct 12, 2022
@CyrusNajmabadi CyrusNajmabadi changed the title Port stackoverflow fix from Roslyn to SourceGenerator PolyFill [release/7.0] Port stackoverflow fix from Roslyn to SourceGenerator PolyFill Oct 12, 2022
@joperezr joperezr added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Oct 13, 2022
@joperezr
Copy link
Member

Approved via email.

@carlossanlop carlossanlop added this to the 7.0.0 milestone Oct 13, 2022
@carlossanlop
Copy link
Member

Talked to @joperezr, I'm waiting for his sign-off after he does some manual testing. Once we get that, I can merge.

Copy link
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

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

Ok, thanks for waiting, manual validation succeeded so this is good to go.

@carlossanlop
Copy link
Member

:shipit:

@carlossanlop carlossanlop merged commit cd2d837 into dotnet:release/7.0 Oct 13, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the generatorStackOverflow70 branch October 13, 2022 19:18
@ghost ghost locked as resolved and limited conversation to collaborators Nov 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants