-
Notifications
You must be signed in to change notification settings - Fork 122
Initial changes to make vtable generation trimming safe for AOT #1352
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
Sergio0694
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.
Just leaving some initial thoughts 🙂
I assume the analyzer you mentioned would be to warn users if their types are not partial, because the generator wouldn't be able to add the necessary attributes to it?
|
For authored WinRT components, will it be an issue that the new attributes takes an array of types? Array of types aren't allowed as attribute parameters in WinRT components as far as I know, and I remember we specifically hit this issue in the Microsoft Store as well. Unless that restriction was just due to .NET Native specifically and not something about WinRT components per se? 🤔 |
Right, I believe the type would need to be marked partial for the source generator to add the attribute. There is always the option for the developer themselves to put the attribute if they want and I plan on updating the source generator to detect that and not put it itself. |
Based on this from the docs |
|
This should possibly fix #1270, will need to validate. |
Co-authored-by: Sergio Pedri <sergio0694@live.com>
|
Merging these changes for now to unblock my other PRs, but I will probably have an upcoming PR that will slightly change the design here to the below. This will allow to eliminate some of the remaining reflection to get the vftbl ptr and also be a design that we can eventually easily move to static interfaces from C# 11 when we can. |
This PR adds a new attribute
WinRTExposedTypewhich can be put on C# implemented types that are passed across the ABI. This attribute takes an array of WinRT interface types which are entries on the CCW vtable for that type. Previously we were usingDynamicallyAccessedMemberTypes.Interfacesalong with reflection, but given this attribute was placed on a function several levels down and one of which is of typeobjectrather than the concrete type, it didn't work as intended when all assemblies were trimmed. With this new attribute, we are also able to skip some of the WinRT type checks along with covariance type generation at runtime along with not needing to keep all the interfaces on the type that aren't WinRT interfaces if they aren't needed.This attribute can be added by libraries and apps on their C# types that they use with CsWinRT projected APIs if desired. But this PR also adds a source generator which will analyze the sources and determine if there are any WinRT interfaces implemented by the class and if so adds the attribute to the class if it is declared partial. CsWinRT also puts that attribute on
unsealed classesso that any internal interfaces implemented by such projected classes in override / protected scenarios are also on the vtable if they are extended by another C# class.Upcoming todo:
System.EventHandler<int>may need to be handled differently.partialif the class isn't already marked as such.