-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Add trim analyzer support for C# 14 extensions #119017
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
base: main
Are you sure you want to change the base?
Conversation
Tagging subscribers to this area: @dotnet/illink |
There was a problem hiding this 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 trim analyzer support for C# 14 extensions by implementing comprehensive handling of the new extension syntax introduced in C# 14. The key changes enable proper data flow analysis and warning generation for extension members while addressing compiler-generated artifacts.
- Adds test coverage for both traditional extension methods and new C# 14 extension members
- Updates the trim analysis infrastructure to handle extension parameters on types
- Implements workarounds for compiler-generated types that inherit attributes from extension members
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs |
Adds workaround to skip attribute validation for compiler-generated extension member types |
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ExtensionsDataFlow.cs |
New test case for traditional extension method data flow analysis |
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ExtensionMembersDataFlow.cs |
New test case for C# 14 extension members data flow analysis |
src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/DataFlowTests.cs |
Adds test methods for the new extension data flow test cases |
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs |
Updates parameter handling to support extension parameters on types |
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/ParameterProxy.cs |
Enhances parameter proxy to handle extension parameters with proper indexing |
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/MethodParameterValue.cs |
Removes obsolete constructors for method parameter values |
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs |
Updates parameter annotation retrieval for extension methods |
src/tools/illink/src/ILLink.RoslynAnalyzer/IMethodSymbolExtensions.cs |
Adds extension parameter detection and parameter counting logic |
src/tools/illink/src/ILLink.RoslynAnalyzer/ILLink.RoslynAnalyzer.csproj |
Reorders NoWarn directives and removes conditional compilation warning suppression |
src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/LocalDataFlowVisitor.cs |
Updates method and property call handling for extension parameters |
src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/ResultChecker.cs |
Duplicates the compiler-generated type workaround for NativeAOT testing |
eng/Versions.props |
Updates Microsoft.CodeAnalysis version from 4.8.0 to 4.14.0 |
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/ParameterProxy.cs
Show resolved
Hide resolved
src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/LocalDataFlowVisitor.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ExtensionMembersDataFlow.cs
Outdated
Show resolved
Hide resolved
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ExtensionMembersDataFlow.cs
Outdated
Show resolved
Hide resolved
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ExtensionMembersDataFlow.cs
Show resolved
Hide resolved
Including extension operators, and plain operators.
Fixes #115949
This adds Roslyn analyzer support for C# 14 extensions. A few notes on the behavior:
New tests uncovered an analyzer issue with operators in the (extension or not): #119110. This change includes test coverage for non-extension operators.