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

[release/9.0-staging] Fix IDynamicInterfaceCastable with shared generic code #109918

Open
wants to merge 3 commits into
base: release/9.0-staging
Choose a base branch
from

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Nov 18, 2024

Backport of #108235 to release/9.0-staging

/cc @MichalStrehovsky

Customer Impact

  • Customer reported
  • Found internally

Regression

  • Yes
  • No

Second one is a regression.

Testing

Added targeted regression test for both.

The first one was a known missing feature that we didn't think is reachable with CsWinRT. It is.

Testing missed the second on because it's an interaction between multiple systems.

Risk

This has been checked into .NET 10 for 2 months already. The risk should be low. We also extended testing for this in main branch.

IMPORTANT: If this backport is for a servicing release, please verify that:

  • The PR target branch is release/X.0-staging, not release/X.0.

  • If the change touches code that ships in a NuGet package, you have added the necessary package authoring and gotten it explicitly reviewed.

Fixes #72909.

Internal team ran into this. Turns out CsWinRT also needs this, but they're were working around instead pushing on a fix.

The big problem with this one is that we have an interface call to a default interface method that requires generic context. This means we need some kind of instantiating thunk (since callsite didn't provide generic context because it didn't know it). The normal default interface case uses an instantiating thunk that simply indexes into the interface list of `this`. We know the index of the interface (we don't know the concrete type because `T`s could be involved), but we can easily compute it at runtime from `this`.

The problem with `IDynamicInterfaceCastable` is that `this` is useless (the class doesn't know anything about the interface). So we need to get the generic context from somewhere else. In this PR, I'm using the thunkpool as "somewhere else". When we finish interface lookup and find out `IDynamicInterfaceCastable` provided a shared method, we create a thunkpool thunk that stashes away the context. We then call the "default interface method instantiating thunk" and instead of indexing into interface list of `this`, we index into interface list of whatever was stashed away. So there are two thunks before we reach the point of executing the method body.
Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

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

Thanks. Shouldn't this also include the regression test from #109917?

@MichalStrehovsky
Copy link
Member

Thanks. Shouldn't this also include the regression test from #109917?

We can have a tell mode change after? I don't know what are the rules around backports, I thought it's pull request granularity. I did validate locally that this cherry pick fixes that case.

@jkotas
Copy link
Member

jkotas commented Nov 18, 2024

It is perfectly fine to cherry pick multiple main PRs into a backport PR.

@MichalStrehovsky
Copy link
Member

It is perfectly fine to cherry pick multiple main PRs into a backport PR.

Sounds good, added it.

Copy link
Member

@jeffschwMSFT jeffschwMSFT left a comment

Choose a reason for hiding this comment

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

lgtm. please get a code review. we will take for consideration in 9.0.x

@jeffschwMSFT jeffschwMSFT added the Servicing-consider Issue for next servicing release review label Nov 19, 2024
@jeffschwMSFT jeffschwMSFT added this to the 9.0.x milestone Nov 19, 2024
@jeffschwMSFT jeffschwMSFT added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Nov 26, 2024
@jeffschwMSFT jeffschwMSFT modified the milestones: 9.0.x, 9.0.1 Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants