Repository navigation
SA1141: Use IOperation for expression analysis - #4292
Merged
Merged
Conversation
Use operation-provided types and target methods instead of repeated semantic-model queries. Preserve diagnostic locations, expression-tree exclusions, declaration analysis, and the legacy compiler fallback. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The broader callbacks introduce a measured standalone performance regression without demonstrating a CPU improvement.
1 open finding
What changed in this PR
Refactors SA1141 expression analysis to use Roslyn operations while retaining syntax fallback for older compilers.
Changes:
- Adds operation-based tuple analysis and expression-tree exclusions.
- Adds C# 7 regression coverage for nested types and queries.
| File | Description |
|---|---|
SA1141UseTupleSyntax.cs |
Implements operation-based analysis. |
SA1141CSharp7UnitTests.cs |
Covers tuple expressions and exclusions. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4292 +/- ##
==========================================
- Coverage 97.63% 97.61% -0.03%
==========================================
Files 1292 1292
Lines 139777 139961 +184
Branches 4603 4625 +22
==========================================
+ Hits 136467 136618 +151
- Misses 2119 2149 +30
- Partials 1191 1194 +3 🚀 New features to boost your workflow:
|
Avoid broad operation dispatch and operation-tree setup on unrelated code. Retrieve operations only for Create invocations and type syntax containing ValueTuple, preserving operation-based semantic checks. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This was referenced Nov 11, 2026
Bump StyleCop.Analyzers from 1.2.0-beta.556 to 1.3.180
microsoftgraph/aspnetcore-webhooks-sample#436
Open
Closed
Open
This was referenced Nov 29, 2026
Open
Open
Open
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

SA1141's repeated
GetSymbolInfocalls were reported to cause heavy CPU usage. This uses Roslyn operations for expression semantics while preserving narrow syntax registrations and filtering before requesting an operation.Fixes #3609
Approach
Createname checks pass. For object creation, defaults, and casts, retrieve an operation only when the relevant type syntax contains a genericValueTuplename, including nested tuple/generic types.No intentional diagnostic or code-fix behavior changes. The added tests characterize existing behavior rather than reproduce a diagnostic failure on master; this issue concerns analysis cost.
Validation
The revised Debug build completed with zero warnings. SA1141 tests passed in all ten C# 6 through C# 15 test projects on net10.0. The initial implementation also passed the C# 7 project's net472 tests. Added coverage exercises nested types, unrelated operations, expression-tree casts, nested lambdas, and queryable versus enumerable queries.
Performance
Review identified that the initial broad operation registrations added standalone operation-driver overhead on unrelated code. Those registrations have been removed. Unrelated expressions now exit through syntax filtering without requesting an operation.
A local standalone benchmark generated 2,000 methods per scenario, pre-bound each fresh compilation with
GetDiagnostics, then timedGetAnalyzerDiagnosticsAsyncwith only SA1141 enabled and concurrency disabled. Each process ran three warmups and five measured iterations, using the C# 15 project's Roslyn assemblies. Three paired process runs compared the original implementation at47643d314with the revised implementation:Unrelated methods contain
Math.Max(1, 2),new List<int>(),default(List<int>), and(List<int>)input. Tuple-heavy methods containValueTuple.Create(1, 2),new ValueTuple<int, int>(1, 2),default(List<ValueTuple<int, int>>), and(ValueTuple<int, int>)input; the harness asserts 8,000 diagnostics in that scenario and zero in the unrelated scenario.The previous roughly 10 MB unrelated-code allocation penalty is eliminated; tuple-heavy allocations decrease about 20%. Timing varies between runs, so these measurements do not establish a CPU speedup or a large-solution performance claim.