Skip to content
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

Merged
merged 6 commits into from
Jul 7, 2022

Conversation

CyrusNajmabadi
Copy link
Member

Followup to #70911

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

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.

@ghost
Copy link

ghost commented Jul 5, 2022

Tagging subscribers to this area: @dotnet/area-extensions-logging
See info in area-owners.md if you want to be subscribed.

Issue Details

Followup to #70911

Author: CyrusNajmabadi
Assignees: CyrusNajmabadi
Labels:

area-Extensions-Logging

Milestone: -

INamedTypeSymbol attributeContainingTypeSymbol = attributeSymbol.ContainingType;
string fullName = attributeContainingTypeSymbol.ToDisplayString();

if (fullName == Parser.LoggerMessageAttribute)
Copy link
Member Author

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

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @chsienki and @jaredpar can advise about it?

Copy link
Member Author

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];
}
}
}
Copy link
Member Author

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

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?

@CyrusNajmabadi
Copy link
Member Author

@joperezr Who should look at this PR? Thanks!

@eerhardt
Copy link
Member

eerhardt commented Jul 6, 2022

@maryamariyan - can you take a look?

@CyrusNajmabadi
Copy link
Member Author

@joperezr @ericstj , @maryamariyan is OOF. Is there someone else who can look at this? Thanks!

@ericstj ericstj requested a review from tarekgh July 7, 2022 17:25
Copy link
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ericstj
Copy link
Member

ericstj commented Jul 7, 2022

I added a couple more folks. The owners for this area are @eerhardt @tarekgh and @maryamariyan.

@CyrusNajmabadi
Copy link
Member Author

Thanks! @eerhardt did you want to look as well? Or is @tarekgh 's sign off complete? Thanks!

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @CyrusNajmabadi!

Comment on lines +21 to +22
<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" />
Copy link
Member

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?

Copy link
Member Author

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 ?

Copy link
Member

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.

@CyrusNajmabadi CyrusNajmabadi merged commit 9610320 into dotnet:main Jul 7, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the loggingGenerator branch July 7, 2022 19:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants