[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 }})

simonrozsival

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:

  1. NSObject_Disposer has [Preserve(AllMembers = true)]
  2. NSObject_Disposer is a subclass of NSObject
  3. NSObject has nested enums Flags and XamarinGCHandleFlags
  4. the base class Enum has a public static method GetValues(Type)
  5. the GetValues method is annotated with RequiresDynamicCode 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:

@simonrozsival

@github-actions GitHub Actions

⚠️ 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).

akoeplinger

( { 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

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@simonrozsival

@simonrozsival

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@simonrozsival

rolfbjarne

@simonrozsival

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.

@vs-mobiletools-engineering-service2

@vs-mobiletools-engineering-service2

💻 [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]

@vs-mobiletools-engineering-service2

@vs-mobiletools-engineering-service2

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)

✅ API diff vs stable

Legacy Xamarin (No breaking changes)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 5c57994acd076191f1cc0c5811aa33bba19644b7 [PR build]

@vs-mobiletools-engineering-service2

❌ [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌

Failed tests are:

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2

💻 [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]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2