[NativeAOT] Improve the transformation of [Preserve(AllMembers = true)]#19516
[NativeAOT] Improve the transformation of [Preserve(AllMembers = true)]#19516simonrozsival merged 5 commits intodotnet:mainfrom
Conversation
|
| ( { IsEnum: true }, _) => DynamicallyAccessedMemberTypes.PublicFields, | ||
| (_, false) => DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors, | ||
| (_, true) => allMemberTypes, | ||
| }; |
There was a problem hiding this comment.
nit: I find the pattern matching switch kinda hard to read compared to splitting it up a bit:
var members = allMembers
? allMemberTypes
: DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors;
// only preserve fields for enums
if (type.IsEnum)
members = DynamicallyAccessedMemberTypes.PublicFields
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.
|
The |
💻 [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] Artifacts 📚Packages generatedView packagesPipeline on Agent |
✅ 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 |
❌ [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌Failed tests are:
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 |
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build] Test results 🚀Test results✅ All tests passed on VSTS: simulator tests. 🎉 All 235 tests passed 🎉 Tests counts✅ bcl: All 69 tests passed. [attempt 2] Html Report (VSDrops) Download Pipeline on Agent |
Closes #19505
We transform
[Preserve(AllMembers = true)]into[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(T))]. There is difference between which members are preserved in these two cases. TheDynamicallyAccessedMemberTypes.Allpreserves many more, especially nested types and their members. This manifested with theIL3050AOT analysis warning we got from ILC when building any app:NSObject_Disposerhas[Preserve(AllMembers = true)]NSObject_Disposeris a subclass of NSObjectNSObjecthas nested enumsFlagsandXamarinGCHandleFlagsEnumhas a public static methodGetValues(Type)GetValuesmethod is annotated withRequiresDynamicCodeand ILC produces a warning because even though it isn't used anywhere in the codebase, it could be used via reflectionI changed two things when transforming Preserve:
PublicMethodssince that would preserve public methods in the base class which includes theGetValues(Type)method.All.All ^ PublicNestedTypes ^ NonPublicNestedTypessince that would automatically include any new flag added to the enum in the future.