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

Fix invalid suppression in System.Attribute #70710

Closed

Conversation

MichalStrehovsky
Copy link
Member

The suppression on System.Attribute is wrong. Ran into this in #70201 where EditorBrowsableAttributeTests.EqualsTest is failing because we didn't generate any reflection metadata for the field. This proves beyond any doubt that even I can't write a correct trim warning suppression.

There's a difference between "a field is kept" and "a field is accessible from reflection without issues". The issue is more pronounced in Native AOT (where the field can be completely erased from reflection). The implementation of Attribute.Equals didn't see any fields on the attribute type because the static analysis didn't deem any of them necessary.

Fields (or methods) that are provably not visible from reflection without warnings are free to be optimized in any way by trimming (e.g. how we strip method parameter names in illink).

This fixes the suppression and replaces it with a more correct DAM on type.

Cc @dotnet/ilc-contrib

The suppression on System.Attribute is wrong. Ran into this in dotnet#70201 where `EditorBrowsableAttributeTests.EqualsTest` is failing because we didn't generate any reflection metadata for the field.

There's a difference between "a field is kept" and "a field is accessible from reflection without issues". The issue is more pronounced in Native AOT (where the field can be completely erased from reflection). The implementation of Attribute.Equals didn't see any fields on the attribute type because the static analysis didn't deem any of them necessary.

This fixes the suppression and replaces it with a more correct DAM on type.
@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@MichalStrehovsky MichalStrehovsky added the linkable-framework Issues associated with delivering a linker friendly framework label Jun 14, 2022
@ghost
Copy link

ghost commented Jun 14, 2022

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

Issue Details

The suppression on System.Attribute is wrong. Ran into this in #70201 where EditorBrowsableAttributeTests.EqualsTest is failing because we didn't generate any reflection metadata for the field. This proves beyond any doubt that even I can't write a correct trim warning suppression.

There's a difference between "a field is kept" and "a field is accessible from reflection without issues". The issue is more pronounced in Native AOT (where the field can be completely erased from reflection). The implementation of Attribute.Equals didn't see any fields on the attribute type because the static analysis didn't deem any of them necessary.

Fields (or methods) that are provably not visible from reflection without warnings are free to be optimized in any way by trimming (e.g. how we strip method parameter names in illink).

This fixes the suppression and replaces it with a more correct DAM on type.

Cc @dotnet/ilc-contrib

Author: MichalStrehovsky
Assignees: MichalStrehovsky
Labels:

new-api-needs-documentation, linkable-framework

Milestone: -

@MichalStrehovsky
Copy link
Member Author

ILLink(0,0): error IL2114: (NETCORE_ENGINEERING_TELEMETRY=Build) System.Runtime.InteropServices.ComEventInterfaceAttribute.<EventProvider>k__BackingField: 'DynamicallyAccessedMembersAttribute' on 'System.Runtime.InteropServices.ComEventInterfaceAttribute' or one of its base types references 'System.Runtime.InteropServices.ComEventInterfaceAttribute.<EventProvider>k__BackingField' which has 'DynamicallyAccessedMembersAttribute' requirements.

Oh, right, okay. I didn't want to open that can of worms.

I think I'm just going to special case System.Attribute descendants in the compiler to compensate for the invalid suppression here.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 14, 2022
@MichalStrehovsky MichalStrehovsky deleted the attributeAnnotation branch September 6, 2022 06:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
linkable-framework Issues associated with delivering a linker friendly framework new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant