Repository navigation
Annotate required APIs with DynamicallyAccessedMemberTypes.Interfaces - #52461
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.
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.
Thanks a lot for testing this.
| "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.
| static Type[] GetInterfacesOnType (Type t) | |
| static Type[] GetInterfacesOnType(Type t) |
There was a problem hiding this comment.
I've been officially tainted by the linker repo coding style 😄
| [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.
What about GetInterfaceMap? Does this need any annotations?
There was a problem hiding this comment.
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.
Maybe we need to annotate it with PublicMethods
Does PublicMethods include explicitly implemented methods?
There was a problem hiding this comment.
Or do you mean PublicMethods on the interface type?
There was a problem hiding this comment.
Might have to be all the methods on the interface: #46912 (comment)
There was a problem hiding this comment.
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.
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.
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 |

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.