-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't ignore the case when dataflow doesn't know what's going on #101031
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the value unknown in my repro?
I would expect that the dataflow should be able to trace through
new Action(Test<string>).Method
without problems.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Known limitation of the dataflow analysis (#93720 is the tracking issue).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought #93720 was about not tracking variable types for
GetType
- how does that explain this issue? If we don't trace throughnew Action(Test<string>)
, I would have expected it to show up as an unknown value, not empty.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought unknown/empty are interchangeable but now I understand the difference. We eventually want to know the type allocated through the
new Action
so thatGetType
(or in this caseDelegate.get_Method
) know the type it's operating on.In this case, we end up with empty instead of unknown because constructors take this path (they "return void"):
runtime/src/tools/illink/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs
Lines 1168 to 1170 in 3d0da2c
And we can no longer bash it to unknown here because the HandleCallAction returned true (i.e.
handledFunction
):runtime/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/MethodBodyScanner.cs
Lines 1302 to 1319 in 3d0da2c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, that looks like something we should fix (not that it'll help with the issue this PR is addressing). Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fix tracking of
new Action(Test<string>)
, I think we'd need to introduce a new dataflow value forAction
that tracks theldftn
result, and handle that case in theget_Method
intrinsic. It seems like just knowing that the input has typeAction
doesn't solve the problem, so I'm not sure #93720 is the right tracking issue. I think that one is more specific toGetType
handling.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to know what method the Action points to, just the concrete type the Delegate.get_Method method is called on (System.Action in this case).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm missing something - why don't we need to know the method it points to? Is it because we keep metadata for all delegate targets if there's any call to get_Method? I was assuming we'd ideally only keep metadata for those delegate targets that had a get_Method call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler keeps track of delegate type + method. If we know delegate type, we know all the methods it can be used with.
We don't track this at method granularity because doing
new Action(Foo).Method
is very rare. People only do this if they want to work around lack ofmethodof
in C#. What happens 95% of time is that we construct a delegate somewhere and a different part of the program will callDelegate.get_Method
on it. That's why we only care about delegate type.Dataflow losing track of the type in the trivial
new Action(Foo).Method
pattern is throwing a wrench in this because if someone uses this to work aroundmethodof
, we only seeDelegate.get_Method
was called on some unknown thing and we need to disable the optimization globally because this could be any delegate.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thank you!