Skip to content
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

Avoid looking for dynamically accessed members when none are requested. #90154

Closed

Conversation

rolfbjarne
Copy link
Member

@rolfbjarne rolfbjarne commented Aug 8, 2023

The purpose of this logic is to warn when no members can be found for a
DynamicDependency attribute.

However, it even warns when DynamicallyAccessedMemberTypes.None is specified
in the attribute, which seems a bit overeager, so change the logic to not warn
when DynamicallyAccessedMemberTypes.None is specified (nor try to mark any
members, because we're not supposed to mark any members).

The purpose of this logic is to warn when no members can be found for a
DynamicDependency attribute.

However, it even warns when DynamicallyAccessedMemberTypes.None is specified
in the attribute, which seems a bit overeager, so change the logic to not warn
when DynamicallyAccessedMemberTypes.None is specified.
@rolfbjarne rolfbjarne requested a review from marek-safar as a code owner August 8, 2023 14:40
@ghost ghost added the linkable-framework Issues associated with delivering a linker friendly framework label Aug 8, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Aug 8, 2023
@ghost ghost assigned rolfbjarne Aug 8, 2023
@ghost
Copy link

ghost commented Aug 8, 2023

Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr, @marek-safar
See info in area-owners.md if you want to be subscribed.

Issue Details

The purpose of this logic is to warn when no members can be found for a
DynamicDependency attribute.

However, it even warns when DynamicallyAccessedMemberTypes.None is specified
in the attribute, which seems a bit overeager, so change the logic to not warn
when DynamicallyAccessedMemberTypes.None is specified.

Author: rolfbjarne
Assignees: -
Labels:

linkable-framework

Milestone: -

@vitek-karas
Copy link
Member

Please add a test which validates the desired behavior.

Curious: What's the scenario to have a DynamicDependency and specify None on members?

@rolfbjarne
Copy link
Member Author

rolfbjarne commented Aug 17, 2023

Curious: What's the scenario to have a DynamicDependency and specify None on members?

I'm adding support to NativeAOT for [Preserve] attributes by mapping them to [DynamicDependency] attributes, and the closest I've found to [Preserve (AllMembers = true)] on a type is [DynamicDependency (DynamicallyAccessedMemberTypes.None)].

@rolfbjarne
Copy link
Member Author

Closing, we found an alternative solution that doesn't show any warnings.

@rolfbjarne rolfbjarne closed this Sep 1, 2023
rolfbjarne pushed a commit to dotnet/macios that referenced this pull request Sep 1, 2023
`None` seems to be equivalent to not having the attribute at all. The type will be stripped by ILLink and ILC. The `PublicConstructors | NonPublicConstructors` seems to be a better option to keep the type while making it possible to trim as much of its members as possible.

This change resolves two warnings:
```
ILLink : warning IL2037: <Module>..cctor(): No members were resolved for 'None' on type 'Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.FrameView'.
ILC : warning IL2037: <Module>..cctor(): No members were resolved for '0' on type 'Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.FrameView'. 
```
(Note: these warnings will still be present for _static_ classes which don't have a static constructor)

@rolfbjarne I believe we don't need dotnet/runtime#90154 anymore


---------

Co-authored-by: Simon Rozsival <[email protected]>
@ghost ghost locked as resolved and limited conversation to collaborators Oct 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants