Adjust records behavior around IOperations and analyzer actions.#46308
Adjust records behavior around IOperations and analyzer actions.#46308AlekseyTs merged 3 commits intodotnet:masterfrom
Conversation
|
@mavasani, @cston, @jcouv, @RikkiGibson, @333fred Please review. |
2 similar comments
|
@mavasani, @cston, @jcouv, @RikkiGibson, @333fred Please review. |
|
@mavasani, @cston, @jcouv, @RikkiGibson, @333fred Please review. |
| { | ||
| context.RegisterSymbolStartAction(Handle1, SymbolKind.Method); | ||
| context.RegisterSymbolStartAction(Handle1, SymbolKind.Property); | ||
| context.RegisterSymbolStartAction(Handle1, SymbolKind.Parameter); |
There was a problem hiding this comment.
Can we add a context.RegisterSymbolStartAction(..., SymbolKind.NamedType) with a nested RegisterSymbolEndAction and then verify that all the FireCountX are 0 at the start of the former callback and 1 at the start of latter callback? This should verify correct ordering of callbacks. #Resolved
|
|
||
| public override void Initialize(AnalysisContext context) | ||
| { | ||
| context.RegisterSymbolAction(Handle, SymbolKind.Method); |
There was a problem hiding this comment.
Should we also add context.RegisterSymbolAction(Handle, SymbolKind.NamedType); to verify callbacks for the record type itself? #Resolved
There was a problem hiding this comment.
Should we also add context.RegisterSymbolAction(Handle, SymbolKind.NamedType); to verify callbacks for the record type itself?
I can certainly add one, I don't think there is anything interesting about the type itself, the PR is was mostly focused on record members.
In reply to: 461193457 [](ancestors = 461193457)
| Debug.Assert(operationBlock.Parent.IsImplicit); | ||
| Debug.Assert(operationBlock.Parent.Parent is IConstructorBodyOperation ctorBody && | ||
| ctorBody.Initializer == operationBlock.Parent); | ||
|
|
There was a problem hiding this comment.
Should we add the below assert?
| Debug.Assert(!operationBlock.Parent.Parent.IsImplicit); | |
| ``` #Resolved |
| } | ||
| }"; | ||
| comp = CreateCompilation(sourceB, references: new[] { refA }, parseOptions: TestOptions.RegularPreview, options: TestOptions.ReleaseExe); | ||
| comp.VerifyDiagnostics(); |
There was a problem hiding this comment.
Was there a reason to remove this call? #Resolved
There was a problem hiding this comment.
Was there a reason to remove this call?
It was determined redundant in one of the previous PRs due to .VerifyDiagnostics() below.
In reply to: 461201750 [](ancestors = 461201750)
| declaredNode, declaredSymbol, executableCodeBlocks, (codeBlocks) => codeBlocks.SelectMany( | ||
| cb => | ||
| { | ||
| var filter = semanticModel.GetSyntaxNodesToAnalyzeFilter(cb, declaredSymbol); |
There was a problem hiding this comment.
Is the below existing invocation to this method redundant now?
roslyn/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs
Lines 2695 to 2697 in 507c81a
#Resolved
There was a problem hiding this comment.
Is the below existing invocation to this method redundant now?
roslyn/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs
Lines 2695 to 2697 in 507c81a
No, that place iterates through nodes itself
In reply to: 461205407 [](ancestors = 461205407)
mavasani
left a comment
There was a problem hiding this comment.
Overall LGTM. Only relevant open question is if we can remove the existing invocation to GetSyntaxNodesToAnalyzeFilter in the analyzer driver as we are now invoking it directly within the core analyzer executor.
Responded on that thread. In reply to: 456180326 [](ancestors = 456180326) |
|
@cston, @RikkiGibson, @333fred Please review, need a second sign-off. |
|
@cston, @RikkiGibson, @333fred Please review, need a second sign-off. |
| model = (accessor.Body != null || accessor.ExpressionBody != null) ? GetOrAddModel(node) : null; | ||
| break; | ||
|
|
||
| case RecordDeclarationSyntax { ParameterList: { }, PrimaryConstructorBaseType: { } } recordDeclaration when TryGetSynthesizedRecordConstructor(recordDeclaration) is SynthesizedRecordConstructor ctor: |
There was a problem hiding this comment.
ctor [](start = 210, length = 4)
Consider omitting the variable name so it's clear we're not expecting to use the value. #Pending
There was a problem hiding this comment.
Consider omitting the variable name so it's clear we're not expecting to use the value.
Sometimes it is useful during debugging
In reply to: 461794242 [](ancestors = 461794242)
| return node == baseType.ArgumentList; | ||
| } | ||
|
|
||
| return true; |
There was a problem hiding this comment.
return true [](start = 39, length = 11)
Is this correct given the comment above ("Accept only nodes ...")? #Resolved
There was a problem hiding this comment.
Is this correct given the comment above ("Accept only nodes ...")?
I think yes, this filter is called in the process of descending down the tree. If it returns false for parent node, it is never called for a child node.
In reply to: 461820251 [](ancestors = 461820251)
| var recordDeclarations = tree.GetRoot().DescendantNodes().OfType<RecordDeclarationSyntax>().Skip(1).ToArray(); | ||
|
|
||
| Assert.Equal("C", recordDeclarations[0].Identifier.ValueText); | ||
| Assert.Null(model.GetOperation(recordDeclarations[0])); |
There was a problem hiding this comment.
model.GetOperation(recordDeclarations[0]) [](start = 24, length = 41)
Why does GetOperation() return null? #Resolved
There was a problem hiding this comment.
Why does GetOperation() return null?
There is no user code for this primary constructor, no code blocks to fire analyzers on, we never create a member semantic model for a primary constructor like that, etc. Technically, we could produce an "empty" IConstructorBodyOperation node, but then we would have to do something with analyzers to make sure an action for this node would fire. Unfortunately, analyzer driver is able to do that only when there is a "real" node for an initializer or a body (see GetOperationsToAnalyze in AnalyzerDriver.cs), we have neither of them here. I decided to not deal with this complexity right now, when we don't really have a real scenario to enable.
In reply to: 461876729 [](ancestors = 461876729)
333fred
left a comment
There was a problem hiding this comment.
Sorry for the late review. This LGTM
No description provided.