Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

[feature/damAnalyzer] Remove "reflection access pattern" logic from linker - #2447

Merged
vitek-karas merged 4 commits into
dotnet:feature/damAnalyzerfrom
vitek-karas:RemoveReflectionAccessPattern
Dec 15, 2021
Merged

vitek-karas merged 4 commits into
dotnet:feature/damAnalyzerfrom
vitek-karas:RemoveReflectionAccessPattern

Conversation

@vitek-karas

Copy link
Copy Markdown
Member

Removes the IReflectionPatternRecorder and all related classes. This interface has been introduced at the very beginning of the data flow work in the linker. Back then the purpose of it was to separate the marking logic from diagnostic reporting logic. We thought we would be able to report nice virtual callstacks of warnings and so on. These ideas were superseded by the current design of forcing explicit annotations on method boundaries and thus avoiding the need to report warnings correlated across multiple methods.

As such the only consumer of this interface is a "logger" which directly outputs any unrecognized patterns as warnings. The product makes no use of the "Recognized pattern" event at all.

The only remaining logic is the ability to suppress diagnostic generation within the data flow logic (typically due to RequiresUnreferencedCode attribute on the method). For now I kept this by adding an AnalysisContext helper struct to pass around the message origin and diagnostics settings and logging warnings through it. We will likely need an abstraction for diagnostics to be able to share code with the analyzer anyway, so this is probably a step in the right direction.

This is almost entirely a mechanical change, in general simplifying the code.

@vitek-karas vitek-karas self-assigned this Dec 15, 2021
@vitek-karas

Copy link
Copy Markdown
Member Author

I strongly suggest hiding whitespace different to review the ReflectionMethodBodyScanner.cs changes. This change removes a try/finally around the entire body, effectively changing whitespaces on every line. Combined with actual code changes on those same lines, this makes the diff with whitespaces unusable (the entire method is basically marked as changed).

Hide whitespace diffs for the diff to make sense:
image

@@ -1824,7 +1751,7 @@ bool IsComInterop (IMarshalInfoProvider marshalInfoProvider, TypeReference param
return false;
}

bool AnalyzeGenericInstantiationTypeArray (in MultiValue arrayParam, ref ReflectionPatternContext reflectionContext, MethodReference calledMethod, IList<GenericParameter> genericParameters)
bool AnalyzeGenericInstantiationTypeArray (in AnalysisContext context, in MultiValue arrayParam, MethodReference calledMethod, IList<GenericParameter> genericParameters)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe we should keep naming it analysisContext to not confuse it with the linker context

@tlakollo tlakollo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% familiar with the calls in which we create a new AnalysisContext and I remember there was a discussion on why they needed an immutable reference for the analysis context which I didn't fully understand but in general, the changes look fine.

@vitek-karas

Copy link
Copy Markdown
Member Author

Before this change the context struct was actually mutable, since we used state in it to track the completeness of all the checks. That's why it was passed around as ref all the time (stack allocated, but not copied). The new struct is readonly and thus immutable and so we avoid the ref everywhere. Other than that it should not be really different.

@vitek-karas
vitek-karas merged commit 077e33b into dotnet:feature/damAnalyzer Dec 15, 2021
@vitek-karas
vitek-karas deleted the RemoveReflectionAccessPattern branch December 15, 2021 22:58
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
…inker (dotnet/linker#2447)

Removes the `IReflectionPatternRecorder` and all related classes. This interface has been introduced at the very beginning of the data flow work in the linker. Back then the purpose of it was to separate the marking logic from diagnostic reporting logic. We thought we would be able to report nice virtual callstacks of warnings and so on. These ideas were superseded by the current design of forcing explicit annotations on method boundaries and thus avoiding the need to report warnings correlated across multiple methods.

As such the only consumer of this interface is a "logger" which directly outputs any unrecognized patterns as warnings. The product makes no use of the "Recognized pattern" event at all.

The only remaining logic is the ability to suppress diagnostic generation within the data flow logic (typically due to `RequiresUnreferencedCode` attribute on the method). For now I kept this by adding an `AnalysisContext` helper struct to pass around the message origin and diagnostics settings and logging warnings through it. We will likely need an abstraction for diagnostics to be able to share code with the analyzer anyway, so this is probably a step in the right direction.

This is almost entirely a mechanical change, in general simplifying the code.

Commit migrated from dotnet/linker@077e33b
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants