-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Share return value handling in trim analysis #101398
Conversation
@@ -682,8 +682,7 @@ public class Derived : Base | |||
} | |||
|
|||
[Kept] | |||
// https://github.com/dotnet/linker/issues/2755 | |||
[ExpectedWarning ("IL2075", "GetMethod", ProducedBy = Tool.Trimmer | Tool.NativeAot)] | |||
[ExpectedWarning ("IL2075", "GetMethod")] | |||
public static void Test () | |||
{ | |||
new Derived ().GetType ().GetMethod ("Method"); |
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 analyzer handling of object.GetType was not setting a return value, so moving to the shared logic fixes this discrepancy.
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.
Thank you!
src/tools/illink/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs
Outdated
Show resolved
Hide resolved
And add missing cases to the switch statement for the analyzer.
I missed a few cases for the intrinsics that don't have special analyzer handling. I added those cases, and also made a fix to avoid crashing Release builds of the analyzer in case we add more cases without analyzer handling in the future. |
The PInvoke logic and the CheckAndReportRequires logic should not be needed for this intrinsic, and the old shared HandleCallAction would go to the default case that sets the return value to Top and returns false. Now this instead returns true and lets the shared return value logic kick in.
@MichalStrehovsky I'd appreciate your eyes on the latest commit b898b27. |
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.
LGTM otherwise, thanks!
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/MethodBodyScanner.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs
Outdated
Show resolved
Hide resolved
IntrinsicId intrinsicId, | ||
out MultiValue? methodReturnValue) | ||
{ | ||
MultiValue? maybeMethodReturnValue = methodReturnValue = null; |
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.
What's the difference between maybeMethodReturnValue and methodReturnValue (do we need both?)
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.
Some code paths assign to the out param methodReturnValue and return immediately, but the paths that use AddReturnValue
needed a separate local because local functions can't assign to out parameters of the containing function.
- Return instead of out param in HandleCall - FIx formatting
This shares more of the HandleCall logic across ILLink/ILC/ILLink.RoslynAnalyzer. The return value handling has been moved from each tool's implementation (ReflectionMethodBodyScanner/TrimAnalysisVisitor) into the shared HandleCallAction, and the extra handling in MethodBodyScanner has been removed. * Fix Array_CreateInstance case The PInvoke logic and the CheckAndReportRequires logic should not be needed for this intrinsic, and the old shared HandleCallAction would go to the default case that sets the return value to Top and returns false. Now this instead returns true and lets the shared return value logic kick in.
This shares more of the HandleCall logic across ILLink/ILC/ILLink.RoslynAnalyzer. The return value handling has been moved from each tool's implementation (ReflectionMethodBodyScanner/TrimAnalysisVisitor) into the shared HandleCallAction, and the extra handling in MethodBodyScanner has been removed. * Fix Array_CreateInstance case The PInvoke logic and the CheckAndReportRequires logic should not be needed for this intrinsic, and the old shared HandleCallAction would go to the default case that sets the return value to Top and returns false. Now this instead returns true and lets the shared return value logic kick in.
This shares more of the HandleCall logic across ILLink/ILC/ILLink.RoslynAnalyzer. The return value handling has been moved from each tool's implementation (ReflectionMethodBodyScanner/TrimAnalysisVisitor) into the shared HandleCallAction, and the extra handling in MethodBodyScanner has been removed.
Addresses the suggestions from #101212 (comment) and #101212 (comment).