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

[ILLink analyzer] Add analyzer support for feature checks #94944

Merged
merged 11 commits into from
Feb 29, 2024

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Nov 18, 2023

Adds support for annotating static boolean properties with [FeatureCheckAttribute(typeof(RequiresDynamicCodeAttribute))], causing the property to be treated as a guard for analyzer warnings about the corresponding Requires attribute.

Adds two new warnings for:

  • Invalid use of FeatureCheckAttribute applied to a non-static or non-bool property
  • Implementation of the property doesn't obviously satisfy the "guard property" (it should return false whenever the guarded feature is disabled).

See #94625 for notes on the design.
See #96859 for the API proposal.

@ghost ghost added the linkable-framework Issues associated with delivering a linker friendly framework label Nov 18, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Nov 18, 2023
@ghost ghost assigned sbomer Nov 18, 2023
@ghost
Copy link

ghost commented Nov 18, 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

Adds support for annotating static boolean properties with [FeatureGuardAttribute(typeof(RequiresDynamicCodeAttribute))], causing the property to be treated as a guard for analyzer warnings about the corresponding Requires attribute.

Adds two new warnings for:

  • Invalid use of FeatureGuardAttribute applied to a non-static or non-bool property
  • Implementation of the property doesn't obviously satisfy the "guard property" (it should return false whenever the guarded feature is disabled).

See #94625 for notes on the design.

Author: sbomer
Assignees: -
Labels:

linkable-framework

Milestone: -

@sbomer sbomer changed the title [ILLink analyzer] Add analyzer support for feature guards [ILLink analyzer] Add analyzer support for feature checks Feb 27, 2024
@sbomer sbomer requested a review from agocke February 27, 2024 18:14
Copy link
Member

@jtschuster jtschuster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

sbomer and others added 3 commits February 28, 2024 15:29
…cksValue.cs

Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
- Add more detail to feature check validation message
- Use existing attribute helper to get AttributeData by attribute name
- Replace unnecessary ImmutableArray Builder
- Invert some if conditions to return early
- Rename TrimAnalysisReturnValuePattern -> FeatureCheckReturnValuePattern
@sbomer sbomer merged commit 756141c into dotnet:main Feb 29, 2024
76 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 31, 2024
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