-
Notifications
You must be signed in to change notification settings - Fork 516
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
[NativeAOT] Add support for [Preserve] attributes #18666
[NativeAOT] Add support for [Preserve] attributes #18666
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d2e181a
to
69ec2d3
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ationAwareSubStep This improves error reporting.
…cDependency attributes. Add support for mapping Preserve attributes to DynamicDependency attributes, and use for NativeAOT. This fixes a problem where NativeAOT would trim away all our tests in our test suites.
69ec2d3
to
c6576d3
Compare
✅ API diff for current PR / commitLegacy Xamarin (No breaking changes)
NET (empty diffs)
✅ API diff vs stableLegacy Xamarin (No breaking changes).NET (No breaking changes)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
💻 [CI Build] Windows Integration Tests passed 💻✅ All Windows Integration Tests passed. Pipeline on Agent |
💻 [PR Build] Tests on macOS M1 - Mac Ventura (13.0) passed 💻✅ All tests on macOS M1 - Mac Ventura (13.0) passed. Pipeline on Agent |
💻 [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻✅ All tests on macOS M1 - Mac Big Sur (11.5) passed. Pipeline on Agent |
📚 [PR Build] Artifacts 📚Packages generatedView packagesPipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build] Test results 🚀Test results✅ All tests passed on VSTS: simulator tests. 🎉 All 232 tests passed 🎉 Tests counts✅ bcl: All 69 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
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.
green > gred
Make 'Full' the default link mode for all platforms for NativeAOT because: * It will achieve the best app size. * NativeAOT is not a drop-in replacement that's guaranteed to work - there are already known features NativeAOT don't support (and may never support), so this may be an opportunity for app developers (and component vendors) to make their products trimmer safe. * NativeAOT will be in preview in .NET 8, so we can change our mind later if it turns out to cause too many problems. * In some cases NativeAOT might require trimming, because we may optimize/rewrite assemblies to be NativeAOT-compatible to support existing libraries. This requires #18666 to be merged first, so that ests aren't linked away.
This is a follow-up to #18666 The idea is to transform `[Preserve(Conditional = true)]` into `[DynamicDependency(signature, type)]` on the static constructor of the given type: ```c# class MyClass { [Preserve (Conditional = true)] public void MyMethod () { } // transformed into ... [DynamicDependency ("MyMethod", typeof (MyClass))] static MyClass() { /* either the existing cctor or a new empty cctor */ } public void MyMethod () { } } ```
This is a follow-up to #18666 This PR resolves the following warnings that I've seen in build logs when running MySingleView with NativeAOT: ``` ILLink : warning IL2034: <Module>..cctor(): The 'DynamicDependencyAttribute' could not be analyzed. [/..../xamarin/xamarin-macios/tests/dotnet/MySingleView/MySingleView.csproj] ILLink : warning IL2034: <Module>..cctor(): The 'DynamicDependencyAttribute' could not be analyzed. [/..../xamarin/xamarin-macios/tests/dotnet/MySingleView/MySingleView.csproj] ... ``` The generated module cctor code looks like this: ```c# internal class <Module> { [DynamicDependency("InvokeConformsToProtocol(ObjCRuntime.NativeHandle)", typeof(NSObject))] [DynamicDependency("Foundation.NSObject", null)] [DynamicDependency("ConformsToProtocol(ObjCRuntime.NativeHandle)", typeof(NSObject))] [DynamicDependency("Foundation.NSObject", null)] // ... static <Module>() { // ... } } ``` The `[DynamicDependency("T", null)]` attributes are invalid. We could change them to `[DynamicDependency(DynamicallyAccessedMemberTypes.None, typeof(T))]` but I think that attribute is redundant because the type itself is always already preserved through the attribute that precedes it with a selector of one of its methods/fields.
Add partial support for the
[Preserve]
attribute for NativeAOT. This is done by injecting an equivalent[DynamicDependency]
attribute. The partial support comes from the fact that there's no way to map a conditional preserve attribute ([Preserve (Conditional = true)]
) to a[DynamicDependency]
attribute, so we report a warning instead.For non-conditional
[Preserve]
attributes, we'll now add a[DynamicDependency]
attribute to the assembly's module constructor for the type/member in question, effectively rooting it.This makes it possible to fully link all our test suites when NativeAOT (otherwise NativeAOT would just link out all the tests, leaving the test suites empty - and unfortunately green, so this was a rather accidental discovery).