Skip to content

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Sep 6, 2025

Fixes #118713 (analyzer only for now)
Fixes #119290

This removes the warning for DAM annotation mismatch in the base types of a type declaration. This doesn't cause holes because we produce warnings on the construction of the derived type. Removing the warning enables the use of static methods on such a type.

While implementing this I ran into an ILLink bug around branch removal. We weren't fixing up IL offsets during branch removal, but we were using the offsets as a dictionary key when tracking known stacks during method body scanning. This includes a change to fix up IL offsets during the IL rewrite when we remove unreachable blocks.

Depends on #119291

@github-actions github-actions bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Sep 6, 2025
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Sep 6, 2025
Copy link
Contributor

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

Moving this warning is more complicated than that for base types
because we would either need to warn on conversion to interfaces,
or warn on every constructor (for kept interface implementations).
@sbomer sbomer changed the title Remove analyzer DAM warning on types Remove base DAM mismatch warning on types Sep 8, 2025
- Move new constraint processing to generic dataflow
- Take new constraint into account for requires dataflow check
MethodBodyScanner tracks known stacks by IL offset,
so these need to be correct when analyzing IL. We can't just
wait for cecil to update offsets for us when writing to disk.
@sbomer sbomer requested a review from a team September 15, 2025 20:08
@sbomer sbomer marked this pull request as ready for review September 15, 2025 20:08
@sbomer sbomer requested a review from marek-safar as a code owner September 15, 2025 20:08
@Copilot Copilot AI review requested due to automatic review settings September 15, 2025 20:08
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 pull request fixes issues related to Dynamically Accessed Members (DAM) annotation mismatch warnings on base types of type declarations. The changes remove these warnings for base type mismatches since warnings are already produced at construction of derived types. This enables the use of static methods on such types. Additionally, it includes a fix for an ILLink bug around branch removal that affects IL offset tracking during method body scanning.

Key changes include:

  • Removal of DAM mismatch warnings for base types in type declarations
  • Fix for IL offset handling during unreachable block optimization
  • Updates to test expectations reflecting the warning removal
  • Refactoring of analyzer context to better handle trim analyzer instances

Reviewed Changes

Copilot reviewed 27 out of 28 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs Comments out debug logging for test message matching
src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs Removes expected warnings for base type DAM mismatches
src/tools/illink/test/Mono.Linker.Tests.Cases/Generics/GenericConstraints.cs Adds test case for new constraint on methods
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterWarningLocation.cs Updates warning expectations and adds constructor calls
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlowMarking.cs Updates test expectations and changes class to interface
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs Removes base type DAM mismatch warnings from tests
src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/GenericsTests.cs Adds test method for generic constraints
src/tools/illink/src/linker/Linker.Steps/UnreachableBlocksOptimizer.cs Fixes IL offset tracking during instruction replacement
src/tools/illink/src/linker/Linker.Steps/MarkStep.cs Removes base type generic argument data flow processing
src/tools/illink/src/linker/Linker.Dataflow/GenericArgumentDataFlow.cs Adds new constraint handling and updates parameter processing
src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs Adds methods to check for generic parameter new constraints
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs Updates analyzer context usage
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisReflectionAccessPattern.cs Updates trim analyzer reference
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisMethodCallPattern.cs Updates trim analyzer reference
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisGenericInstantiationPattern.cs Updates analyzer iteration
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisAssignmentPattern.cs Updates trim analyzer reference
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/RequireDynamicallyAccessedMembersAction.cs Updates constructor to use specific analyzer
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/HandleCallAction.cs Updates constructor parameter
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/GenericArgumentDataFlow.cs Refactors to use specific analyzer instances
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/FeatureCheckReturnValuePattern.cs Updates trim analyzer reference
src/tools/illink/src/ILLink.RoslynAnalyzer/RequiresUnreferencedCodeAnalyzer.cs Adds generic instantiation processing
src/tools/illink/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs Adds generic instantiation processing base functionality
src/tools/illink/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs Removes base type processing
src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlowAnalyzerContext.cs Changes from boolean flag to specific analyzer instance
src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/ResultChecker.cs Comments out debug logging for test message matching
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DataflowAnalyzedTypeDefinitionNode.cs Removes base type generic argument data flow processing
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/GenericArgumentDataFlow.cs Adds comments about new constraint handling

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.

It feels a bit awkward to be passing around the instances of the analyzers, but I don't have a better solution.

- Use interface for generic dataflow
- Remove outdated comment
- Clarify expected warning reason
- Add Kept attributes for clarity
@sbomer sbomer enabled auto-merge (squash) September 16, 2025 21:19
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.

ILLink: extra warning for generic parameter with new constraint and annotation Remove DAM warning for base types/interfaces
2 participants