Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Avoid deep recursion for nested bound patterns - #80920

#80920
Merged
AlekseyTs merged 2 commits into
dotnet:maindotnet/roslyn:mainfrom
AlekseyTs:Issue80840AlekseyTs/roslyn:Issue80840Copy head branch name to clipboard
Oct 29, 2025
Merged

Avoid deep recursion for nested bound patterns#80920
AlekseyTs merged 2 commits into
dotnet:maindotnet/roslyn:mainfrom
AlekseyTs:Issue80840AlekseyTs/roslyn:Issue80840Copy head branch name to clipboard

Conversation

@AlekseyTs

Copy link
Copy Markdown
Contributor

Closes #80840.

@AlekseyTs
AlekseyTs requested a review from a team as a code owner October 27, 2025 21:28
@AlekseyTs AlekseyTs changed the title Avoid deep recursion for deeply nested bound patterns Avoid deep recursion for nested bound patterns Oct 27, 2025
@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler Please review

@RikkiGibson

RikkiGibson commented Oct 27, 2025

Copy link
Copy Markdown
Member

I will try to repro the stack overflow again with this PR and will review it soon. Thanks #Resolved

@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler Please review

@333fred 333fred left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Done review pass. Only a couple of minor questions.

return false;
}

Debug.Assert(t2 is SequenceTests);

@333fred 333fred Oct 28, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: it's not obvious at first read that equalsEasyOut will validate that RemainingTests are equal in length. Think we can strengthen this assert and make it easier to understand by asserting that the remaining tests lengths are equal here. #Resolved


if (!sequence.RemainingTests.Any(t => t is SequenceTests))
{
return sequence.RemainingTests.SequenceEqual(other.RemainingTests);

@333fred 333fred Oct 28, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there any chance that there will be nested sequences in an individual remaining test? And if so, is that something we want to handle? If the answer to either question is no, consider leaving a comment to explain. #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am not sure what is there to explain. This operation is equivalent to what the "non-easy" comparison would do.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the recursion was sequence->nonsequence->sequence..., then we'd still have deep recursion here. That's what I'm concerned about.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This PR doesn't attempt to avoid that form of recursion, even if one is possible.


static int? getHashCodeEasyOut(SequenceTests sequence)
{
if (sequence.RemainingTests.Any(t => t is SequenceTests))

@333fred 333fred Oct 28, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same question about nested sequences. #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same answer. I am not making any assumptions about nested sequences.

Comment thread src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs
Comment thread src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs Outdated
Comment thread src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs Outdated

@RikkiGibson RikkiGibson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM modulo the pending comments. It looks like the stack overflow from #80840 does not repro with this change.

@AlekseyTs
AlekseyTs enabled auto-merge (squash) October 28, 2025 22:55
@AlekseyTs
AlekseyTs merged commit d17c054 into dotnet:main Oct 29, 2025
23 of 24 checks passed
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Oct 29, 2025
@davidwengier davidwengier modified the milestones: Next, 18.3 Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stack overflow in ErrorFacts.IsBuildOnlyDiagnostic

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.