-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Use manual recursion for binary patterns #75212
Conversation
Much like binary operators, we can have deeply-nested binary patterns. An example of this is our own IsBuildOnlyDiagnostic, which has ~2500 binary patterns in a single arm, and growing every release. To avoid stack depth issues, I took the same approach we do for binary operators; rewrite recursion to use a manual stack for these cases. Fixes dotnet#73439.
@dotnet/roslyn-compiler for review. I cannot stress strongly enough, review with whitespace off. Otherwise all the extractions to local functions will be much harder to review. |
Also note: A much simpler workaround would just be to break up IsBuildOnlyDiagnostic into a few different pattern arms. I didn't take that approach because that would just leave a maintenance task on us every so often to fix up the compilation when some builds randomly start failing; this seems much less painful long term, and I don't think the original code is unreasonable. |
Converting this back to draft while I find a few more places that binary operators are handled that we probably need to handle patterns as well. |
…t code worst-case.
Alright. There are a couple of locations in the optimizer and emit where we do specially handle binary operators, but we these nodes don't survive the local rewriter, and there are existing assertions that we don't have any patterns at that point. This is ready for review. |
@333fred It looks like there are legitimate test failures |
@AlekseyTs I believe they should be fixed now. |
@333fred It looks like EndToEnd tests are crashing, likely related to the added test |
src/Compilers/Core/Portable/Operations/ControlFlowGraphBuilder.cs
Outdated
Show resolved
Hide resolved
|
||
var rightPatternStack = ArrayBuilder<PatternSyntax>.GetInstance(); | ||
|
||
while (currentPattern is BinaryPatternSyntax binaryPattern) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that results in less-clear code, like we have in VisitBinaryExpression
above. I'd prefer to keep this as is.
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker_Patterns.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs
Outdated
Show resolved
Hide resolved
Done with review pass (commit 5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 10)
@dotnet/roslyn-compiler for a second review |
@@ -184,22 +184,23 @@ public static Location GetTooLongOrComplexExpressionErrorLocation(BoundNode node | |||
{ | |||
SyntaxNode syntax = node.Syntax; | |||
|
|||
if (!(syntax is ExpressionSyntax)) | |||
if (syntax is not (ExpressionSyntax or PatternSyntax)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really feel like the type of thing that needs to be extracted to a local function; it honestly feels like that would impede readability, not help. I'd prefer to leave this as is.
…terns * upstream/main: (267 commits) Support long chains of `else if` statements (dotnet#74317) Update dependencies from https://github.com/dotnet/source-build-externals build 20240930.2 Fix the path to the proposal (dotnet#75302) Fix TSA tooling (dotnet#75307) Clarify the bug template to request a code snippet (dotnet#75306) Bump razor for serialization changes (dotnet#75282) Disallow declaration of indexers in absence of proper DefaultMemberAttribute. (dotnet#75099) stoub use ref Simpler Simplify Switch to a threadlocal storage to prevent locks add comment don't mess with user caret in smart rename Update LanguageServer references Localized file check-in by OneLocBuild Task: Build definition ID 327: Build ID 2548898 Use common helper method Localized file check-in by OneLocBuild Task: Build definition ID 327: Build ID 2548278 Field-backed properties: additional tests (dotnet#75283) Revert "Updates content exclusion for on-the-fly-docs (dotnet#75172)" (dotnet#75279) (dotnet#75284) ...
Much like binary operators, we can have deeply-nested binary patterns. An example of this is our own IsBuildOnlyDiagnostic, which has ~2500 binary patterns in a single arm, and growing every release. To avoid stack depth issues, I took the same approach we do for binary operators; rewrite recursion to use a manual stack for these cases. Fixes #73439.