Filter identifier name simplification according to aliases and predefined types#41079
Filter identifier name simplification according to aliases and predefined types#41079sharwell merged 2 commits intodotnet:masterfrom
Conversation
src/Features/CSharp/Portable/Diagnostics/Analyzers/TypeSyntaxSimplifierWalker.cs
Outdated
Show resolved
Hide resolved
src/Features/CSharp/Portable/Diagnostics/Analyzers/TypeSyntaxSimplifierWalker.cs
Show resolved
Hide resolved
src/Features/CSharp/Portable/Diagnostics/Analyzers/TypeSyntaxSimplifierWalker.cs
Show resolved
Hide resolved
| _cancellationToken = cancellationToken; | ||
|
|
||
| var root = semanticModel.SyntaxTree.GetRoot(cancellationToken); | ||
| _aliasedNames = GetAliasedNames(root as CompilationUnitSyntax); |
There was a problem hiding this comment.
this should be a normal cast.
There was a problem hiding this comment.
This doesn't seem problematic, and there are known cases where syntax trees do not have CompilationUnitSyntax as the root.
There was a problem hiding this comment.
and there are known cases where syntax trees do not have CompilationUnitSyntax as the root.
Those would all be bugs in the case of analyzers though. No one should ever register a semantic-model analyzer and not get a CompilationUnit. That would be a big invariance bug.
There was a problem hiding this comment.
The rewrite of GetAliasedNames specifically targets scenarios where the entry point is not a semantic model analyzer. Semantic model analyzers always start at the root so the normal recursive descent walker can be used for this.
There was a problem hiding this comment.
i'm not certain what you mean. When is the entrypoint not a semantic-model analyzer?
There was a problem hiding this comment.
In the current code, it's not. But we're considering a hybrid code block + syntax node analyzer if we can't get the performance up through SemanticModel sharing in the compiler or driver.
src/Features/CSharp/Portable/Diagnostics/Analyzers/TypeSyntaxSimplifierWalker.cs
Show resolved
Hide resolved
| // The only possible simplifications to an unqualified identifier are replacement with an alias or | ||
| // replacement with a predefined type. | ||
| canTrySimplify = CanReplaceIdentifierWithAlias(node.Identifier.ValueText!) | ||
| || CanReplaceIdentifierWithPredefinedType(node.Identifier.ValueText!); |
There was a problem hiding this comment.
extract out node.Identifier.ValueText to a local.
There was a problem hiding this comment.
extract all of this to a local function canTrySimplify()
src/Features/VisualBasic/Portable/Diagnostics/Analyzers/TypeSyntaxSimplifierWalker.vb
Show resolved
Hide resolved
Yikes. Can we file issue for that as well? Is this just callbacks in AnalyzerRunner? Or in the analyzer infrastructure itself? |
This issue doesn't exist in the main AnalyzerRunner implementation. It's the test code I added to get the number of TrySimplify attempts were made for each type of syntax. |
Extracted from #40746 and generalized to work with Visual Basic.
Baseline numbers (49a468c + #41072):
Updated numbers (49a468c + this pull request):
📝 The increase in diagnostics is due to a bug in Simplify Type Names for the Visual Basic code
NameOf([Object]). The apparent increase in analyzer execution time is noise caused by contested locks used for measuring the callbacks. The allocation numbers and end-to-end time improvements were consistent.📝 In combination with #41072, 99.75% of calls to
TrySimplifywere eliminated as unnecessary forIdentifierNameSyntax.