-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Polyfill the incremental generator ForAttributeWithMetadataName from roslyn (for LoggingGenerator). #71651
Conversation
…roslyn (for LoggingGenerator).
@@ -34,33 +34,6 @@ public Parser(Compilation compilation, Action<Diagnostic> reportDiagnostic, Canc | |||
internal static bool IsSyntaxTargetForGeneration(SyntaxNode node) => | |||
node is MethodDeclarationSyntax m && m.AttributeLists.Count > 0; | |||
|
|||
internal static ClassDeclarationSyntax? GetSemanticTargetForGeneration(GeneratorSyntaxContext context) |
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.
moved to 3.11 file as it's only used for that scenario now.
Tagging subscribers to this area: @dotnet/area-extensions-logging Issue DetailsFollowup to #70911
|
INamedTypeSymbol attributeContainingTypeSymbol = attributeSymbol.ContainingType; | ||
string fullName = attributeContainingTypeSymbol.ToDisplayString(); | ||
|
||
if (fullName == Parser.LoggerMessageAttribute) |
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.
note: the only check we do is that hte attribute's fully qualified name is LoggerMessageAttribute (e.g. we don't actually check type-equility or anything like that). as such, we don't have to do any additional semantic work ourselves as this is exactly what roslyn is ensuring.
context, | ||
Parser.LoggerMessageAttribute, | ||
(node, _) => node is MethodDeclarationSyntax, | ||
(context, _) => context.TargetNode.Parent as ClassDeclarationSyntax) |
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 original code did no actual semantic checks beyond just checking that there was an attribute with a particular fully qualified name on it. this is unlike the regex generator which does additional semantic checks.
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 believe that was intentional. https://github.com/dotnet/runtime/pull/51064/files#r614207808
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.
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.
note: this wasn't a complaint. Just pointing out the difference between these two generators. It's not necessarily right/wrong, just something to potentially look into depending on what semantics you want.
return _span[_pos]; | ||
} | ||
} | ||
} |
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.
note: i'm copying what the regex generator does. it's unclear to me why Pop
is not just in the linked ValueListBuilder file that is referenced.
public T Pop() | ||
{ | ||
_pos--; | ||
return _span[_pos]; |
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.
@stephentoub any concern that this doesn't clear the value that was popped? i assume it's ok since this is all short lived on the stack anyways?
@joperezr Who should look at this PR? Thanks! |
@maryamariyan - can you take a look? |
@joperezr @ericstj , @maryamariyan is OOF. Is there someone else who can look at this? Thanks! |
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.
LGTM
I added a couple more folks. The owners for this area are @eerhardt @tarekgh and @maryamariyan. |
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.
LGTM. Thanks @CyrusNajmabadi!
<Compile Include="$(CoreLibSharedDir)System\Collections\Generic\ValueListBuilder.cs" Link="Production\ValueListBuilder.cs" /> | ||
<Compile Include="$(CoreLibSharedDir)System\Collections\Generic\ValueListBuilder.Pop.cs" Link="Production\ValueListBuilder.Pop.cs" /> |
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.
(nit) what does the Production
folder mean here?
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.
No idea. this was copied from teh regex generator which uses those folder names :) @stephentoub ?
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.
A random-ish name that shows up in the IDE indicating that the source is also used by the production libraries and not just part of the source generator.
Followup to #70911