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

Split up ReflectionMethodBodyScanner - #2796

Merged
sbomer merged 2 commits into
dotnet:mainfrom
sbomer:splitScanner
May 19, 2022
Merged

sbomer merged 2 commits into
dotnet:mainfrom
sbomer:splitScanner

Conversation

@sbomer

@sbomer sbomer commented May 13, 2022

Copy link
Copy Markdown
Member

This separates the pieces which require the dataflow analysis from those that don't.
Also includes a few other small cleanup changes (no functional changes).
Please let me know if you have better ideas for a name than FlowInsensitiveReflectionScanner.

This addresses the feedback in #2782 (comment)

This separates the pieces which require the dataflow analysis from those that don't.
Also includes a few other small cleanup changes (no functional changes).
@sbomer
sbomer marked this pull request as ready for review May 13, 2022 22:39
@sbomer
sbomer requested a review from marek-safar as a code owner May 13, 2022 22:39

@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, I agree that FlowInsensitiveReflectionScanner is a weird name but so far I haven't come up with something different. Will reply if something comes to mind

Comment thread src/linker/Linker/Annotations.cs Resolved

MethodDefinition? owningMethod;
while (context.CompilerGeneratedState.TryGetOwningMethodForCompilerGeneratedMember (member, out owningMethod)) {
Debug.Assert (owningMethod != member);

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.

What is this assertion protecting against?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's just an incomplete way of declaring the expectation that TryGetOwningMethod... walks up to the owning member so that this isn't an infinite loop.


namespace Mono.Linker.Dataflow
{
public class FlowInsensitiveReflectionScanner

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.

Very odd name. If the type does not need DataFlow why is it in the namespace?

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.

I actually don't mind this being in the DataFlow - it is data flow, just not inside a method body.
Maybe we should split this further:

  • AttributeDataFlow - handle all of the attribute stuff - we could even move some of the code from MarkStep to here possibly (NativeAOT has lot more of the code in these methods as well).
  • GenericArgumentDataFlow - just the generic stuff - it's going to be small, but so what.
  • And maybe we should then rename the ReflectionMethodBodyScanner to MethodBodyDataFlow - or something like that. But I'm not sure about this - both names have downsides as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes I was having trouble finding a good name for this. The difference is that attribute/generic parameter logic doesn't have locals or any state that needs to be tracked so it's arguably not really a dataflow analysis. But it computes the same kinds of results as the dataflow analysis in the method body scanner.

I think @vitek-karas's suggestion to split it further addresses this. I split it up into separate types for attribute/generic logic. I left ReflectionMethodBodyScanner because it's a pretty established name at this point, but happy to change it if you prefer.


namespace Mono.Linker.Dataflow
{
public class FlowInsensitiveReflectionScanner

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.

I actually don't mind this being in the DataFlow - it is data flow, just not inside a method body.
Maybe we should split this further:

  • AttributeDataFlow - handle all of the attribute stuff - we could even move some of the code from MarkStep to here possibly (NativeAOT has lot more of the code in these methods as well).
  • GenericArgumentDataFlow - just the generic stuff - it's going to be small, but so what.
  • And maybe we should then rename the ReflectionMethodBodyScanner to MethodBodyDataFlow - or something like that. But I'm not sure about this - both names have downsides as well.

- Use switch expression
- Split into attribute/generic dataflow types
- Use readonly structs
- Avoid ValueNode naming
- Simplify some existing code
readonly MarkStep _markStep;
readonly MessageOrigin _origin;

public AttributeDataFlow (LinkContext context, MarkStep markStep, in MessageOrigin origin)

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.

We only ever use one instance method once before the struct goes out of scope. I know since it's a struct on the stack, it shouldn't allocate so it isn't less performant than static methods, but is there a reason we follow this pattern instead of making the methods static?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Mainly I followed it to stay consistent with how ReflectionMethodBodyScanner is invoked. In general I think this pattern can be an ok way to separate per-invocation arguments (like the attribute field/argument) from the ones that could be shared across invocations (like context/markstep) even though we don't actually reuse the AttributeDataFlow instance here.

@sbomer
sbomer merged commit 8e738bb into dotnet:main May 19, 2022
@sbomer
sbomer deleted the splitScanner branch May 21, 2022 04:51
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
* Split up ReflectionMethodBodyScanner

This separates the pieces which require the dataflow analysis from those that don't.
Also includes a few other small cleanup changes (no functional changes).

* PR feedback

- Use switch expression
- Split into attribute/generic dataflow types
- Use readonly structs
- Avoid ValueNode naming
- Simplify some existing code

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

5 participants