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

Move shared dataflow value creation helpers out of HandleCallAction - #2757

Merged
sbomer merged 7 commits into
dotnet:mainfrom
sbomer:annotationContext
Apr 25, 2022
Merged

sbomer merged 7 commits into
dotnet:mainfrom
sbomer:annotationContext

Conversation

@sbomer

@sbomer sbomer commented Apr 22, 2022

Copy link
Copy Markdown
Member

This builds on the work @jtschuster did in c2fff33 to share code for the annotation checks.

I noticed that ReflectionMethodBodyScanner and HandleCallAction started accumulating these helpers for creating dataflow values from methods and I thought it would make sense for that to be handled as a separate concern, so I moved them out to a separate class and adjusted some of the callsites in ReflectionMethodBodyScanner to use the shared version.

This was motivated in part by some of the factoring I am doing as a follow-up to 137b7b9, but isn't directly related. (While working on the follow-up, I came across a point where I needed to create a dataflow value in shared code from outside HandleCallAction, and there wasn't a very clean way to do this).

@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.

In general looks good to me

@jtschuster jtschuster left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it make more sense to put all of this into FlowAnnotations and make that a partial class? It looks like there are already a few duplicate methods in FlowAnnotations.cs on the linker side. LGTM otherwise.

sbomer added 2 commits April 25, 2022 13:15
- Move MethodRequiresDataFlowAnalysis to AnnotationContext
@sbomer

sbomer commented Apr 25, 2022

Copy link
Copy Markdown
Member Author

I was debating whether to use FlowAnnotations for this - if you had the same thought it's probably worth it. I took the suggestion, Thanks!

@sbomer
sbomer merged commit 4418cce into dotnet:main Apr 25, 2022

@vitek-karas vitek-karas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the late review - just one perf related comment.

_owningSymbol = owningSymbol;
_operation = operation;
_diagnosticContext = diagnosticContext;
_annotations = new FlowAnnotations ();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is relatively expensive - FlowAnnotations is a class, so this is a heap allocation - but it doesn't store anything. Also linker doesn't have this problem since it's using a "singleton" instance effectively. We should do the same in the analyzer (note that HandleCallAction is created very frequently - it should be allocation free if at all possible).

Same goes for the ReflectionAccessAnalyzer below - either make it a struct or share the instance between calls to this constructor.

agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
…otnet/linker#2757)

This builds on the work @jtschuster did in c2fff33 to share code for
the annotation checks.

I noticed that ReflectionMethodBodyScanner and HandleCallAction
started accumulating these helpers for creating dataflow values from
methods and I thought it would make sense for that to be handled as a
separate concern, so I moved them out to a separate class and adjusted
some of the callsites in ReflectionMethodBodyScanner to use the shared
version.

This was motivated in part by some of the factoring I am doing as a
follow-up to 137b7b9, but isn't directly related. (While working on
the follow-up, I came across a point where I needed to create a
dataflow value in shared code from outside HandleCallAction, and there
wasn't a very clean way to do this).



Commit migrated from dotnet/linker@4418cce
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.

4 participants