This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Repository navigation
Remove AnalysisContext and ScopeStack from method body scanner - #2747
Merged
Merged
Conversation
tlakollo
reviewed
Apr 19, 2022
Don't copy origin into local
tlakollo
reviewed
Apr 19, 2022
tlakollo
reviewed
Apr 19, 2022
Use 'in' for new MessageOrigin parameters
tlakollo
reviewed
Apr 19, 2022
vitek-karas
pushed a commit
that referenced
this pull request
Apr 26, 2022
) Follow-up to #2747. This is a factoring change only and doesn't introduce functional changes. This does two things to move the method body scanner to be more similar to the trim analysis visitor: - Uses `DiagnosticContext` to record diagnostics. Right now, this still happens inline as we run the scanner, but the idea will be to move this out to a driver that runs the analysis, and then records diagnostics from the recorded patterns (like how it is done in the analyzer) - Moves reflection-marking helpers out of `ReflectionMethodBodyScanner` to a separate class. This prevents us from having to pass around the scanner to other helpers, and makes it more obvious which parts of the code to scanning only vs other things. The new `ReflectionMarker` is conceptually similar to `ReflectionAccessAnalyzer` in the Roslyn analyzer and could be a candidate for future code sharing.
agocke
pushed a commit
to dotnet/runtime
that referenced
this pull request
Nov 16, 2022
…t/linker#2747) * Motivation: For compiler-generated code dataflow, we may need to analyze a compiler-generated method multiple times as part of the closure of methods reached from user code. This is necessary because as we analyze this closure of methods we might find new captured state that flows into a previously analyzed method in the same closure. To avoid spurious warnings, we need a deduplication mechanism similar to what we do in the analyzer. The eventual goal is for the linker to have something similar to the analyzer's TrimAnalysisPatternStore that deduplicates warnings produced from multiple scans of the same method body. We also might need the ability to run the method body scanner without producing any warnings, when analyzing compiler-generated methods reachable by reflection. (The linker will warn about reflection over compiler-generated code, and won't produce the full set of diagnostics for these methods, but still needs to scan them to ensure dependencies are kept). The first step is to remove some levels of indirection around the message origins, to make it easier to cache messages by origin in the future. * This change: This is an initial factoring of ReflectionMethodBodyScanner that just gets rid of AnalysisContext and ScopeStack usages in that class. No functional changes are intended. Some of the ScopeStack logic is a bit subtle: the shared global ScopeStack meant that it was difficult to tell which scope might be used when reporting a warning - it was path-dependent. I pushed all of the ScopeStack.CurrentScope.Origin calls up into callsites outside of ReflectionMethodBodyScanner, so that the scanner logic could avoid concerning itself with pushing and popping scopes. Instead, it passes message origins along explicitly when required. Commit migrated from dotnet/linker@137b7b9
agocke
pushed a commit
to dotnet/runtime
that referenced
this pull request
Nov 16, 2022
…tnet/linker#2761) Follow-up to dotnet/linker#2747. This is a factoring change only and doesn't introduce functional changes. This does two things to move the method body scanner to be more similar to the trim analysis visitor: - Uses `DiagnosticContext` to record diagnostics. Right now, this still happens inline as we run the scanner, but the idea will be to move this out to a driver that runs the analysis, and then records diagnostics from the recorded patterns (like how it is done in the analyzer) - Moves reflection-marking helpers out of `ReflectionMethodBodyScanner` to a separate class. This prevents us from having to pass around the scanner to other helpers, and makes it more obvious which parts of the code to scanning only vs other things. The new `ReflectionMarker` is conceptually similar to `ReflectionAccessAnalyzer` in the Roslyn analyzer and could be a candidate for future code sharing. Commit migrated from dotnet/linker@f26189b
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Motivation:
For compiler-generated code dataflow, we may need to analyze a compiler-generated method multiple times as part of the closure of methods reached from user code. This is necessary because as we analyze this closure of methods we might find new captured state that flows into a previously analyzed method in the same closure.
To avoid spurious warnings, we need a deduplication mechanism similar to what we do in the analyzer. The eventual goal is for the linker to have something similar to the analyzer's
TrimAnalysisPatternStorethat deduplicates warnings produced from multiple scans of the same method body.We also might need the ability to run the method body scanner without producing any warnings, when analyzing compiler-generated methods reachable by reflection. (The linker will warn about reflection over compiler-generated code, and won't produce the full set of diagnostics for these methods, but still needs to scan them to ensure dependencies are kept).
The first step is to remove some levels of indirection around the message origins, to make it easier to cache messages by origin in the future.
This change:
This is an initial factoring of ReflectionMethodBodyScanner that just gets rid of AnalysisContext and ScopeStack usages in that class. No functional changes are intended.
Some of the ScopeStack logic is a bit subtle: the shared global ScopeStack meant that it was difficult to tell which scope might be used when reporting a warning - it was path-dependent. I pushed all of the
ScopeStack.CurrentScope.Origincalls up into callsites outside of ReflectionMethodBodyScanner, so that the scanner logic could avoid concerning itself with pushing and popping scopes. Instead, it passes message origins along explicitly when required.