Skip to content

Add ExcludeStatics support to trimming tools #117904

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Jul 21, 2025

See API proposal in #117524.

@sbomer sbomer requested review from a team and Copilot July 21, 2025 23:15
@github-actions github-actions bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Jul 21, 2025
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Jul 21, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for the ExcludeStatics property to the RequiresUnreferencedCode and RequiresDynamicCode attributes in trimming tools. This feature allows developers to apply requires attributes to classes while excluding static members from the warnings, providing more granular control over trim analysis.

Key changes:

  • Added ExcludeStatics property to attribute definitions and parsing logic
  • Updated trimmer analysis logic to skip static members when ExcludeStatics = true
  • Added comprehensive test cases to validate the new functionality

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/tools/illink/src/ILLink.Shared/RequiresUnreferencedCodeAttribute.cs Added new attribute definition with ExcludeStatics property
src/tools/illink/src/ILLink.Shared/RequiresDynamicCodeAttribute.cs Added new attribute definition with ExcludeStatics property
src/tools/illink/src/linker/Linker/LinkerAttributesInformation.cs Updated attribute parsing to handle ExcludeStatics property
src/tools/illink/src/linker/Linker/Annotations.cs Modified analysis logic to respect ExcludeStatics setting
src/tools/illink/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs Updated analyzer to handle ExcludeStatics in Roslyn context
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/DiagnosticUtilities.cs Updated NativeAOT compiler analysis logic
src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresExcludeStatics.cs Comprehensive test cases for ExcludeStatics functionality
Various test infrastructure files Updated to include new attribute files and test support
Comments suppressed due to low confidence (1)

src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs:86

  • The call to AttributedMethod() is added without any context or expectations. If this is meant to test specific behavior, it should have corresponding ExpectedWarning or UnexpectedWarning attributes.
                AttributedMethod();

Copy link
Contributor

Tagging subscribers to this area: @dotnet/illink
See info in area-owners.md if you want to be subscribed.

- Fix kept items validation for polyfilled attributes
- Clean up tests
- Fix to ignore NativeAOT injected members
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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