[NativeAOT] Improve the transformation of [Preserve(AllMembers = true)] by simonrozsival · Pull Request #19516 · dotnet/macios (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation23 Commits5 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
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. The DynamicallyAccessedMemberTypes.All
preserves many more, especially nested types and their members. This manifested with the IL3050
AOT analysis warning we got from ILC when building any app:
NSObject_Disposer
has[Preserve(AllMembers = true)]
NSObject_Disposer
is a subclass of NSObjectNSObject
has nested enumsFlags
andXamarinGCHandleFlags
- the base class
Enum
has a public static methodGetValues(Type)
- the
GetValues
method is annotated withRequiresDynamicCode
and ILC produces a warning because even though it isn't used anywhere in the codebase, it could be used via reflection
I changed two things when transforming Preserve:
- For enums, we only need to preserve public fields. We especially want to avoid
PublicMethods
since that would preserve public methods in the base class which includes theGetValues(Type)
method. - For other types, I list explicitly the member types that should be preserved instead of using
All
.- The code is verbose, but in the end, I chose the explicit list instead of
All ^ PublicNestedTypes ^ NonPublicNestedTypes
since that would automatically include any new flag added to the enum in the future.
- The code is verbose, but in the end, I chose the explicit list instead of
⚠️ Your code has been reformatted. ⚠️
If this is not desired, add the actions-disable-autoformat
label, and revert the reformatting commit.
If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).
( { IsEnum: true }, _) => DynamicallyAccessedMemberTypes.PublicFields, |
---|
(_, false) => DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors, |
(_, true) => allMemberTypes, |
}; |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
The CMBlockBufferCustomBlockSource
test needed updating. This is most likely because due to the change, NativeAOT doesn't generate the same metadata for the struct as it did before, and we can't resolve the type just using its name. The struct is still there, we just need to access it slightly differently. I think it is an OK tradeoff.
💻 [PR Build] Tests on macOS M1 - Mac Ventura (13.0) passed 💻
✅ All tests on macOS M1 - Mac Ventura (13.0) passed.
Pipeline on Agent
Hash: [PR build]
✅ API diff for current PR / commit
Legacy Xamarin (No breaking changes)
iOS(no change detected)tvOS(no change detected)watchOS(no change detected)macOS(no change detected) NET (empty diffs)iOS: (empty diff detected)tvOS: (empty diff detected)MacCatalyst: (empty diff detected)macOS: (empty diff detected)
✅ API diff vs stable
Legacy Xamarin (No breaking changes)
- iOS: vsdrops gist (No breaking changes)
- tvOS: vsdrops gist (No breaking changes)
- watchOS: vsdrops gist (No breaking changes)
- macOS: vsdrops gist (No breaking changes) .NET (No breaking changes)
- iOS: vsdrops gist (No breaking changes)
- tvOS: vsdrops gist (No breaking changes)
- MacCatalyst: vsdrops gist (No breaking changes)
- macOS: vsdrops gist (No breaking changes)
- Microsoft.iOS vs Microsoft.MacCatalyst: vsdrops gist Legacy Xamarin (stable) vs .NET
- iOS: vsdrops gist
- tvOS: vsdrops gist
- macOS: vsdrops gist
ℹ️ Generator diff
Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)
Pipeline on Agent
Hash: 5c57994acd076191f1cc0c5811aa33bba19644b7 [PR build]
❌ [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌
Failed tests are:
- dontlink
- introspection
- linksdk
- linkall
- xammac_tests
- monotouch-test
Pipeline on Agent
Hash: [PR build]
💻 [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
Hash: [PR build]