Skip to content

Conversation

@AlekseyTs
Copy link
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
Contributor Author

@dotnet/roslyn-compiler Please review

@RikkiGibson
Copy link
Member

RikkiGibson commented Oct 27, 2025

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

@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

Copy link
Member

@333fred 333fred left a comment

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);
Copy link
Member

@333fred 333fred Oct 28, 2025

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);
Copy link
Member

@333fred 333fred Oct 28, 2025

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
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
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
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))
Copy link
Member

@333fred 333fred Oct 28, 2025

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
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.

Copy link
Member

@RikkiGibson RikkiGibson left a comment

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
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

3 participants