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 EventSourceGeneration). #71662

Merged
merged 8 commits into from
Jul 12, 2022

Conversation

CyrusNajmabadi
Copy link
Member

Followup to #70911 and #71652

@ghost
Copy link

ghost commented Jul 5, 2022

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

Issue Details

Followup to #70911 and #71652

Author: CyrusNajmabadi
Assignees: -
Labels:

area-System.Runtime.InteropServices

Milestone: -

{
continue;
}
if (attribute.AttributeClass.Name != "EventSourceAttribute" &&
Copy link
Member

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 ||?

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed!

@CyrusNajmabadi
Copy link
Member Author

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.

@stephentoub
Copy link
Member

This is a follow-up pr to the library import pr.

Ok. Out of curiosity why does this depend on the LibraryImport one?

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review July 12, 2022 16:06
{
const string EventSourceAutoGenerateAttribute = "System.Diagnostics.Tracing.EventSourceAutoGenerateAttribute";
Copy link
Member Author

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

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;
}
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 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;
}
}
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 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.

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

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

@CyrusNajmabadi CyrusNajmabadi Jul 12, 2022

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

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Aug 12, 2022
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.

2 participants