-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
base: release/9.0-staging
Are you sure you want to change the base?
[release/9.0-staging] Fix IDynamicInterfaceCastable with shared generic code #109918
Conversation
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.
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.
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. |
It is perfectly fine to cherry pick multiple main PRs into a backport PR. |
Sounds good, added 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.
lgtm. please get a code review. we will take for consideration in 9.0.x
Backport of #108235 to release/9.0-staging
/cc @MichalStrehovsky
Customer Impact
Regression
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
, notrelease/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.