-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Annotate required APIs with DynamicallyAccessedMemberTypes.Interfaces #52461
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
Conversation
After the basic annotation of Type.GetInterface and Type.GetInterfaces this propagates this annotation to all places which require it. It also resolves warnings in all the places where this shows up.
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
|
Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer Issue DetailsAfter the basic annotation of Type.GetInterface and Type.GetInterfaces this propagates this annotation to all places which require it. It also resolves warnings in all the places where this shows up. For the most part this is just blindly propagating the annotations. Most of the suppressions rely on the fact that is
|
| return list.ToArray(); | ||
| } | ||
|
|
||
| [UnconditionalSuppressMessage ("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", |
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've submitted #52535 to see whether we can just delete the problematic code instead.
I think this would only do something if we allowed instance fields on interfaces, but that smells a lot like multiple-inheritance problems, so I don't think we're ever going to allow that.
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 a lot for testing this.
src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeGenerator.cs
Show resolved
Hide resolved
| "The trimmer will keep the interface and thus all of its implementations in that case. " + | ||
| "The call to GetInterfaces may return less results in trimmed apps, but it will " + | ||
| "include the interfaces this method looks for if they should be there.")] | ||
| static Type[] GetInterfacesOnType (Type t) |
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.
| static Type[] GetInterfacesOnType (Type t) | |
| static Type[] GetInterfacesOnType(Type t) |
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've been officially tainted by the linker repo coding style 😄
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.
| [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] | ||
| public sealed override Type[] FindInterfaces(TypeFilter filter, object? filterCriteria) => throw new NotSupportedException(SR.NotSupported_SignatureType); | ||
|
|
||
| public sealed override InterfaceMapping GetInterfaceMap(Type interfaceType) => throw new NotSupportedException(SR.NotSupported_SignatureType); |
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.
What about GetInterfaceMap? Does this need any annotations?
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 don't think we need to. The GetInterfaceMap returns the per-method details for the specified interface type - so the interface type is guaranteed to exist. Maybe we need to annotate it with PublicMethods? @MichalStrehovsky would you know?
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.
Maybe we need to annotate it with PublicMethods
Does PublicMethods include explicitly implemented methods?
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.
Or do you mean PublicMethods on the interface type?
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.
Might have to be all the methods on the interface: #46912 (comment)
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.
Yeah - we will need to make it all methods... although I will have to play with it - if it has different semantics than GetMethod regarding inheritance... oh well.
src/libraries/System.Reflection.TypeExtensions/ref/System.Reflection.TypeExtensions.cs
Show resolved
Hide resolved
What about Looks like it was just missed in the Refers to: src/libraries/System.Runtime/ref/System.Runtime.cs:9079 in 702bed0. [](commit_id = 702bed0, deletion_comment = False) |
eerhardt
left a comment
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 had just one more comment on TypeInfo.ImplementedInterfaces ref file. Other than that, looks good.
The Interfaces annotation is transitive (by definition), so once it applies to a Type it also applies to all the interfaces implemented by that type.
|
With the last change I annotated the return value of |
eerhardt
left a comment
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.
![]()

After the basic annotation of Type.GetInterface and Type.GetInterfaces this propagates this annotation to all places which require it. It also resolves warnings in all the places where this shows up.
For the most part this is just blindly propagating the annotations.
Most of the suppressions rely on the fact that is
IFoois referenced (and thus theTypeinstance of it exists at runtime), trimmer guarantees that it will keep it on all types which implement that interface. And also on additional fact that ifIFoo<>is preserved, then all instantiations of it are also preserved. This is true for linker, but not necessarily true for AOT - that is we can do better if we don't have to make that assumption. For now I rely on that assumption.