-
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
Make it possible for arrays to have default-implemented methods #96672
Make it possible for arrays to have default-implemented methods #96672
Conversation
Within the managed type system, the array types are special. When asking question about virtual/interface methods implemented by arrays, one needs to switch from the array type (that doesn't have any virtual methods as far as the type system in concerned) to the `Array<T>` type from corelib (that has the methods). The `GetClosestDefType` API is the API that does this transformation. We were not consistent enough in using it and it didn't work for default methods. In dotnet#95830, arrays are going to get a default interface method (the implementation of `IList<T>.System.Collections.Generic.IReadOnlyList<T>.get_Item` which is `virtual final` but still a new slot).
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsWithin the managed type system, the array types are special. When asking question about virtual/interface methods implemented by arrays, one needs to switch from the array type (that doesn't have any virtual methods as far as the type system in concerned) to the The In #95830, arrays are going to get a default interface method (the implementation of @dotnet/ilc-contrib
|
Noticed this while working on dotnet#96672. There are two ways how virtual method can be referred to: as a direct reference to the method body (i.e. non-virtually), or as a reference to a particular slot number (virtually). When we mark a virtual method as visible by reflection, it typically means “virtually visible to reflection” (one can invoke the method with a random derived `this` so the invoke happens through the slot). But we still try to optimize this into a direct reference if possible so that we don’t waste an extra slot. This is possible for final methods, or methods on sealed classes for example. The marking in dependency graph didn’t take into account this optimization – it was creating an unnecessary virtual slot for reflection-visible final methods that then went unused. With this half of the diff in dotnet#96672 is technically not necessary (we no longer end up with the new virtual method in the vtable), but that fix is still a correct fix.
Noticed this while working on #96672. There are two ways how virtual method can be referred to: as a direct reference to the method body (i.e. non-virtually), or as a reference to a particular slot number (virtually). When we mark a virtual method as visible by reflection, it typically means “virtually visible to reflection” (one can invoke the method with a random derived `this` so the invoke happens through the slot). But we still try to optimize this into a direct reference if possible so that we don’t waste an extra slot. This is possible for final methods, or methods on sealed classes for example. The marking in dependency graph didn’t take into account this optimization – it was creating an unnecessary virtual slot for reflection-visible final methods that then went unused. With this half of the diff in #96672 is technically not necessary (we no longer end up with the new virtual method in the vtable), but that fix is still a correct fix.
…et#96672) Within the managed type system, the array types are special. When asking question about virtual/interface methods implemented by arrays, one needs to switch from the array type (that doesn't have any virtual methods as far as the type system in concerned) to the `Array<T>` type from corelib (that has the methods). The `GetClosestDefType` API is the API that does this transformation. We were not consistent enough in using it and it didn't work for default methods. In dotnet#95830, arrays are going to get a default interface method (the implementation of `IList<T>.System.Collections.Generic.IReadOnlyList<T>.get_Item` which is `virtual final` but still a new slot).
Noticed this while working on dotnet#96672. There are two ways how virtual method can be referred to: as a direct reference to the method body (i.e. non-virtually), or as a reference to a particular slot number (virtually). When we mark a virtual method as visible by reflection, it typically means “virtually visible to reflection” (one can invoke the method with a random derived `this` so the invoke happens through the slot). But we still try to optimize this into a direct reference if possible so that we don’t waste an extra slot. This is possible for final methods, or methods on sealed classes for example. The marking in dependency graph didn’t take into account this optimization – it was creating an unnecessary virtual slot for reflection-visible final methods that then went unused. With this half of the diff in dotnet#96672 is technically not necessary (we no longer end up with the new virtual method in the vtable), but that fix is still a correct fix.
Within the managed type system, the array types are special. When asking question about virtual/interface methods implemented by arrays, one needs to switch from the array type (that doesn't have any virtual methods as far as the type system in concerned) to the
Array<T>
type from corelib (that has the methods).The
GetClosestDefType
API is the API that does this transformation. We were not consistent enough in using it and it didn't work for default methods.In #95830, arrays are going to get a default interface method (the implementation of
IList<T>.System.Collections.Generic.IReadOnlyList<T>.get_Item
which isvirtual final
but still a new slot).@dotnet/ilc-contrib