-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Revert "Emit less metadata for not-reflection-visible types (#91660)" #91988
Conversation
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsThis is a revert of #91660 (first commit, no need to review that, really) and a regression test (second commit). This fixes an issue discovered in the SDK repo: dotnet/sdk#35293 (comment) The compiler assumes MethodTables used in casts and interface dispatch are not reflection visible. As we found the hard way in the above PR, this is not true when The compiler had this wrong assumption for a while (the regression test I'm adding would fail on .NET 7). The only reason why we haven't already seen this in .NET 7 was that crossgen2 PDB writing was written with a manual ComWrapper in .NET 7, vs in .NET 8 it uses the generator that does a bunch of reflection on the type handle for whatever reason. We'll probably also want to upgrade the places within the compiler that hand out NecessaryEEType for dispatch/cast to interfaces to hand out ConstructedEEType instead but I don't want to do that as part of a .NET 8 fix. This has been broken in 7.0 too and it is also observable (NecessaryEETypes don't have a populated interface list), but nothing known fails on this right now. So thanks to IDynamicInterfaceCastable, the problem #91660 was trying to solve is totally unfixable and WinForms apps will always bring half of WPF with them. Cc @dotnet/ilc-contrib
|
/backport to release/8.0 |
Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6169862067 |
We have |
The interface that the COM source generator reflects on is not the implementation interface. In theory we don't even have a guarantee there is a |
I think it would be perfectly fine to skip calling IDynamicInterfaceCastable callbacks for interfaces that cannot be possibly implemented by IDynamicInterfaceCastable. In other words, if the system can prove that the interface cannot be possibly implemented by an object by some means, it is fine to skip IDynamicInterfaceCastable callbacks. |
It's a lot of work to make an observable optimization around this that could break appcompat. I don't think the savings we get from this are huge in general. We get a lot of savings when we can optimize constructed methodtable to unconstructed ones for classes (because classes have vtables). Interfaces are less interesting. We'll have to tell WinForms team to divorce their package from WPF if they want good size so that the problematic attribute on |
Didn't see https://github.com/dotnet/runtime/actions/runs/6169862067. All good. |
This is a revert of #91660 (first commit, no need to review that, really) and a regression test (second commit).
This fixes an issue discovered in the SDK repo: dotnet/sdk#35293 (comment)
The compiler assumes MethodTables used in casts and interface dispatch are not reflection visible. As we found the hard way in the above PR, this is not true when
IDynamicInterfaceCastable
is present. WithIDynamicInterfaceCastable
, any (interface) type handle used in cast or interface dispatch could be reflection visible in user code.The compiler had this wrong assumption for a while (the regression test I'm adding would fail on .NET 7). The only reason why we haven't already seen this in .NET 7 was that crossgen2 PDB writing was written with a manual ComWrapper in .NET 7, vs in .NET 8 it uses the generator that does a bunch of reflection on the type handle for whatever reason.
We'll probably also want to upgrade the places within the compiler that hand out NecessaryEEType for dispatch/cast to interfaces to hand out ConstructedEEType instead but I don't want to do that as part of a .NET 8 fix. This has been broken in 7.0 too and it is also observable (NecessaryEETypes don't have a populated interface list), but nothing known fails on this right now.
So thanks to IDynamicInterfaceCastable, the problem #91660 was trying to solve is totally unfixable and WinForms apps will always bring half of WPF with them.
Cc @dotnet/ilc-contrib