[release/11.0] Revert deconstruction analysis in trim analyzer - #134484
Open
jtschuster wants to merge 3 commits into
Open
jtschuster wants to merge 3 commits into
jtschuster wants to merge 3 commits into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/illink |
jtschuster
force-pushed
the
RevertDeconstructionAnalysis
branch
from
September 23, 2026 05:20
ea6366a to
5206ea7
Compare
This was referenced Sep 23, 2026
jtschuster
marked this pull request as ready for review
September 23, 2026 16:38
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
One or more issues must be addressed before approval.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2
Open (3)
What changed in this PR
Reverts full deconstruction dataflow analysis while retaining conservative local clearing to avoid bogus trim warnings.
Changes:
- Restores conservative conversion handling.
- Removes complex deconstruction tracking and adds basic local invalidation.
- Updates shared test expectations.
| File | Description |
|---|---|
| src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ExtensionMembersDataFlow.cs | Updated as part of this pull request. |
| src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/DeconstructUserDefinedConversion.cs | Updated as part of this pull request. |
| src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/DeconstructFieldTarget.cs | Updated as part of this pull request. |
| src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ConstructedTypesDataFlow.cs | Updated as part of this pull request. |
| src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs | Updated as part of this pull request. |
| src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/LocalStateLattice.cs | Updated as part of this pull request. |
| src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/LocalStateAndContextLattice.cs | Updated as part of this pull request. |
| src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/LocalDataFlowVisitor.cs | Updated as part of this pull request. |
|
|
||
| // Local dataflow states are mutable and should never be used as dictionary keys. | ||
| public override int GetHashCode() => throw new NotImplementedException(); | ||
| public override int GetHashCode() => HashUtils.Combine(LocalState, Context); |
| Dictionary.Equals(other.Dictionary) && | ||
| CapturedReferences.Equals(other.CapturedReferences) && | ||
| CapturedTargetValues.Equals(other.CapturedTargetValues); | ||
| public bool Equals(LocalState<TValue> other) => Dictionary.Equals(other.Dictionary); |
Comment on lines
+752
to
+754
| case IDeclarationExpressionOperation declaration: | ||
| SetDeconstructedLocalsToTop(declaration.Expression, state); | ||
| break; |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Flow-captured locals are not cleared, and captured-reference changes are omitted from fixpoint equality.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 2
Open (7)
Include CapturedReferences in local state equality Avoid throwing from LocalStateAndContext.GetHashCode Flow-captured targets are not cleared · New Preserve unwrapping of conversion and parenthesized targets Use singular form after “a” · New Test does not exercise flow-capture clearing · New Comment references removed analyzer methods · New
Comment on lines
+744
to
+759
| private void SetDeconstructedLocalsToTop(IOperation target, LocalDataFlowState<TValue, TContext, TValueLattice, TContextLattice> state) | ||
| { | ||
| switch (target) | ||
| { | ||
| case ITupleOperation tuple: | ||
| foreach (IOperation element in tuple.Elements) | ||
| SetDeconstructedLocalsToTop(element, state); | ||
| break; | ||
| case IDeclarationExpressionOperation declaration: | ||
| SetDeconstructedLocalsToTop(declaration.Expression, state); | ||
| break; | ||
| case ILocalReferenceOperation local: | ||
| SetLocal(local.Local, TopValue, state); | ||
| break; | ||
| } | ||
| } |
| // (IIncrementOrDecrementOperation) and coalescing assignment (ICoalesceAssignmentOperation) | ||
| // are not handled here and fall back to the base visitor, which visits the write target | ||
| // directly. Enabling the following assert requires handling those first. | ||
| // This can also happen for a deconstruction assignments, where the write is not to a byref. |
| static (Type type, object instance) GetInput(Type type, int unused) => (type, null); | ||
|
|
||
| [ExpectedWarning("IL2077")] | ||
| [ExpectedWarning("IL2077", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/123767")] |
Comment on lines
+269
to
+270
| [ExpectedWarning("IL2026", nameof(GetIndexerHolder), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/123767")] | ||
| [ExpectedWarning("IL2026", nameof(GetIndex), Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/123767")] |
This branch has not been deployed
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.



#131624 implemented support for deconstruction and dataflow for TupleOperations (e.g.
(a, b) = (b, a)). However, in some cases it made assumptions that Roslyn would lower a TupleOperation to a ValueTuple creation andItemNfield reference. This led to unexpected warnings like the one found in #133911.#134377 offers one possible fix, but doesn't seem bulletproof and may introduce more regressions. A more "proper" fix would be an even larger change. The least risky "fix" is to revert the original PR and avoid creating bogus warnings at the cost of missing some valid warnings until publish time. However, a full revert reintroduces some bogus warnings (though they were present in .NET 10). Instead, we add very basic support to clear the dataflow information for locals that we see are assigned to in deconstruction assignments. In other words, the following snippet does not produce a bogus warning.
This PR is broken into three commits:
Customer Impact
Regression
Testing
Tests from the original PR were re-introduced with the assertions changed to reflect the behavior prior to the PR's product changes. Existing regression tests validate other scenarios are unaffected.
Risk
Low to medium. The diff is large, but it reverts behavior to .NET 10. There's a small possibility of regressions, but the likelihood and severity of regressions are less risky than the known regression in #133911.