-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Fix StackOverflowException in RoutePatternAnalyzer #48105
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It looks like the analysis is only interested in tokens, so this could be replaced with:
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.
The code I added follows what the Regex analyzer does. I investigated why the regex analyzer doesn't use
DecendantTokens
. I think it could have, but the recently addedFilteredSpans
check wouldn't work with the helper method:https://github.com/dotnet/roslyn/blob/4dcbb0bdb9f7630fec6ce81b311525ef974fd4b0/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/LanguageServices/AbstractRegexDiagnosticAnalyzer.cs#L63-L64
It looks like
FilteredSpans
has only just been made public. aspnetcore probably won't update to bits with it until after .NET 8. I'd like to leave the method as is so using FilteredSpans in the future is possible.Btw, what are filtered spans? I'm guessing it's an optimization, but I'd be interested if you could point me at more detail.
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.
Adding @mavasani for the question on filtered spans.
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.
FilterSpan is the new API added on analysis context types when computing diagnostics for lightbulb. This allows expensive analyzers to optimize their performance based on the span within the tree for which diagnostics are being computed. If the analyzer ignores this span, the analyzer driver will filter the reported diagnostics outside this span, there should be no functional impact of ignoring this filter span.
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 analyzer is expensive. Do you recommend eventually using filter span like other analyzers are doing?
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.
Definitely - all SemanticModelAnalysisContext callbacks should respect the filter span. I plan to write a meta-analyzer in Microsoft.CodeAnalysis.Analyzers package to recommend the same. These analyzers are known to be the biggest beneficiaries of this API on lightbulb path.
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 do not understand why
DescendantTokens
is in compatible withFilteredSpans
. It can be implemented by passing down the predicate correct? Having every analyzer / generator out there build their own stack for navigating the tree to scan tokens is not the right solution.@333fred
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 see there is a
DescendantTokens
overload that takes a span: https://github.com/dotnet/roslyn/blob/252def9efa028af3f0562929b4b0e8a74dcd3124/src/Compilers/Core/Portable/Syntax/SyntaxNode.cs#L1049It looks like the overload checks span overlaps.
I think the below would work (assuming FilterSpan was available):
DescendantTokens
allocates an enumerator, but this method was allocating a collection before anyway. I'll switch the PR to use it and we can addFilterSpan
when it's available.