Skip to content
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

Merged
merged 7 commits into from
Apr 25, 2024
Merged

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Apr 22, 2024

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

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 22, 2024
@@ -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");
Copy link
Member Author

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.

Copy link
Member

@jtschuster jtschuster left a comment

Choose a reason for hiding this comment

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

Thank you!

@sbomer
Copy link
Member Author

sbomer commented Apr 24, 2024

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.

@sbomer sbomer requested a review from jtschuster April 24, 2024 20:33
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.
@sbomer
Copy link
Member Author

sbomer commented Apr 24, 2024

@MichalStrehovsky I'd appreciate your eyes on the latest commit b898b27.

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

LGTM otherwise, thanks!

IntrinsicId intrinsicId,
out MultiValue? methodReturnValue)
{
MultiValue? maybeMethodReturnValue = methodReturnValue = null;
Copy link
Member

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?)

Copy link
Member Author

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
@sbomer sbomer merged commit 4fc6d4c into dotnet:main Apr 25, 2024
109 of 113 checks passed
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
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.
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
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.
@github-actions github-actions bot locked and limited conversation to collaborators May 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants