Skip to content

Conversation

@lambdageek
Copy link
Member

Don't unbox a valuetype this if the generic method is a DIM

Fixes #58394

@ghost ghost added the area-VM-meta-mono label Sep 1, 2021
@ghost
Copy link

ghost commented Sep 1, 2021

Tagging subscribers to this area:
See info in area-owners.md if you want to be subscribed.

Issue Details

Don't unbox a valuetype this if the generic method is a DIM

Fixes #58394

Author: lambdageek
Assignees: -
Labels:

area-VM-meta-mono

Milestone: -

Don't unbox a valuetype `this` if the generic method is a DIM

Fixes dotnet#58394
@lambdageek lambdageek force-pushed the fix-gh-58394 branch 3 times, most recently from 600cabb to f46f4e6 Compare September 2, 2021 02:34
} else if (orig_vtable_slot) {
if (m_class_is_valuetype (m->klass))
if (m_class_is_valuetype (m->klass)) {
g_assert (!mini_method_is_default_method (m));
Copy link
Member

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?

Copy link
Member Author

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 uses this in 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.

Copy link
Member

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?

Copy link
Member Author

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?

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.

Copy link
Member

Choose a reason for hiding this comment

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

make sense!

@SamMonoRT
Copy link
Member

SamMonoRT commented Sep 2, 2021

We need to backport to release\6.0 once all validation is complete

@lambdageek
Copy link
Member Author

/backport to release/6.0

@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2021

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1195616255

@lambdageek
Copy link
Member Author

/azp run sync-runtime-to-mono

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lambdageek lambdageek merged commit ba1f318 into dotnet:main Sep 3, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Oct 3, 2021
@lambdageek lambdageek deleted the fix-gh-58394 branch March 19, 2022 16:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[mono] Crash when calling an interface method on a struct through a generic default interface method

4 participants