-
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 EventSourceGeneration). #71662
Conversation
…roslyn (for LibraryImportGenerator).
…roslyn (for EventSourcewGenerator).
Tagging subscribers to this area: @dotnet/interop-contrib |
{ | ||
continue; | ||
} | ||
if (attribute.AttributeClass.Name != "EventSourceAttribute" && |
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.
Is &&
correct here? It shouldn't be ||
?
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.
indeed!
...ibraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Parser.cs
Outdated
Show resolved
Hide resolved
This is a follow-up pr to the library import pr. @joperezr tells me that this isn't shipping yet, so it was low pri to fix. |
Ok. Out of curiosity why does this depend on the LibraryImport one? |
{ | ||
const string EventSourceAutoGenerateAttribute = "System.Diagnostics.Tracing.EventSourceAutoGenerateAttribute"; |
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.
we don't need to check for EventSourceAutoGenerateAttribute. we wouldn't have gotten here unless we had that attribute on the class we're examining.
if (attributeFullName.Equals(EventSourceAutoGenerateAttribute, StringComparison.Ordinal)) | ||
{ | ||
autoGenerate = true; | ||
continue; |
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.
we required having EventSourceAutoGenerateAttribute before. otherwise, autogenerate would not be true, and we'd bail out below.
if (!attributeFullName.Equals(EventSourceAttribute, StringComparison.Ordinal)) | ||
{ | ||
continue; | ||
} |
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 below would only execute if we had EventSourceAttribute, so that's what we maintain below.
// since this generator doesn't know how to generate a nested type... | ||
return null; | ||
} | ||
} |
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 this check up. there was no point doing it in a loop since it would always be the same result. and if it always caused us to continue, we'd never set eventSourceClass
. so we'd terminate the loop and would return null
. so this is effectively the same.
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 logic is wrong in that it can't handle: namespace n1 { namespace n2 { class Whatever { } } }
. However, that bug existed before. I didn't change it.
A better check would likely be to do if (classDef.Parent is TypeDeclarationSyntax)
{ | ||
foreach (AttributeSyntax ca in cal.Attributes) | ||
if (attribute.AttributeClass?.Name != "EventSourceAttribute" || |
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.
in general, try to do the basic name check first. it's much faster and allocation-light versus ToDisplayString
|
||
if (!autoGenerate) | ||
string nspace = ns.Name.ToString(); |
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 is not correct. if you have namespace N1/*comment*/. N2
, then the ToString will include hte extraneous comments and whitespace. However, this was the logic from before, so i'm keeping it.
// We don't need to include the later generator factories for collection elements | ||
// as the later generator factories only apply to parameters. | ||
generatorFactory = new AttributedMarshallingModelGeneratorFactory( | ||
generatorFactory, | ||
elementFactory, | ||
new AttributedMarshallingModelOptions(runtimeMarshallingDisabled, Scenario.ManagedToUnmanagedIn, Scenario.ManagedToUnmanagedRef, Scenario.ManagedToUnmanagedOut)); | ||
new AttributedMarshallingModelOptions(runtimeMarshallingDisabled, MarshalMode.ManagedToUnmanagedIn, MarshalMode.ManagedToUnmanagedRef, MarshalMode.ManagedToUnmanagedOut)); |
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'm still not clear on why these changes are necessary in this PR. Is this PR renaming Scenario to MarshalMode or something?
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.
These were bad merges as i was undoing the changes. The files are now untouched. Note: this will be squashed when PR is merged, so there won't be random cruft like this in your repo history. However, i don't like squashing as the PR is in progress as that can make it harder to see what's going on. If you want though i can pre-squash.
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.
If you want though i can pre-squash.
Nope.
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.
Thanks!
Followup to #70911 and #71652