-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[mini] Don't add unbox tramopline on generic DIM calls #58521
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
47 changes: 47 additions & 0 deletions
47
src/tests/Loader/classloader/DefaultInterfaceMethods/regressions/github58394.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| namespace GenericDimValuetypeBug | ||
| { | ||
| class Program | ||
| { | ||
| static int Main() | ||
| { | ||
| if (RunOne() != 17) | ||
| return 1; | ||
| if (RunTwo() != 23) | ||
| return 2; | ||
| return 100; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static int RunOne() | ||
| { | ||
| return (new Foo() { x = 17 } as IFoo).NoCrash(); | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static int RunTwo() | ||
| { | ||
| return (new Foo() { x = 23 } as IFoo).Crash<int>(); | ||
| } | ||
| } | ||
|
|
||
| interface IFoo | ||
| { | ||
| int Crash<T>() => Bla(); | ||
|
|
||
| int NoCrash() => Bla(); | ||
|
|
||
| int Bla(); | ||
| } | ||
|
|
||
| struct Foo: IFoo | ||
| { | ||
| public int x; | ||
| public int Bla() => x; | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/tests/Loader/classloader/DefaultInterfaceMethods/regressions/github58394.csproj
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
| <OutputType>Exe</OutputType> | ||
| <CLRTestKind>BuildAndRun</CLRTestKind> | ||
| <CLRTestPriority>0</CLRTestPriority> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| </ItemGroup> | ||
| </Project> |
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 don't you add the same condition as above?
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.
Good question.
I couldn't tell if we could ever end up in this branch with a valuetype klass and a default interface method.
I thought it would be better to add an assertion (because if it does ever happen the failure will be right at this spot) instead of skipping the
need_unbox_tramp. If we erroneous add or don't add an unbox trampoline, we will get a crash later when we actually call the underlying managed method and it usesthisin some way. That will be a crash in some unrelated managed code and it won't be obvious how to trace it back to this trampoline. With the assert if anyone comes up with a way to violate it the assumptions it will break in the place where we need to fix it.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.
That's right. The assertion would definitely make debugging easier. But my confusion is that in the future, when someone hit this assertion, I feel the solution would be to skip adding unbox trampoline. Or you think more work would be needed on top of that?
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 don't know. I can't tell from the code how we end up in this branch with a DIM. I'd need to see an example and I couldn't make one.
And also I can't tell if in that case the right thing would be to add an unbox, or to not add one. To be honest I was hoping one of our existing tests would break on the assert, and then I'd know that things were fine as is.
But nothing broke. So I still don't know whether that case can happen. And what we should do if it does happen.
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.
make sense!