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

Make it possible for arrays to have default-implemented methods #96672

Merged
merged 1 commit into from
Jan 9, 2024

Conversation

MichalStrehovsky
Copy link
Member

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 is virtual final but still a new slot).

@dotnet/ilc-contrib

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).
@ghost
Copy link

ghost commented Jan 9, 2024

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

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 is virtual final but still a new slot).

@dotnet/ilc-contrib

Author: MichalStrehovsky
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

TylerBrinkley added a commit to TylerBrinkley/runtime that referenced this pull request Jan 9, 2024
@MichalStrehovsky MichalStrehovsky merged commit 3710d53 into dotnet:main Jan 9, 2024
110 checks passed
@MichalStrehovsky MichalStrehovsky deleted the defaultsonarrays branch January 9, 2024 19:56
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this pull request Jan 10, 2024
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.
MichalStrehovsky added a commit that referenced this pull request Jan 10, 2024
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.
tmds pushed a commit to tmds/runtime that referenced this pull request Jan 23, 2024
…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).
tmds pushed a commit to tmds/runtime that referenced this pull request Jan 23, 2024
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.
@github-actions github-actions bot locked and limited conversation to collaborators Feb 9, 2024
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.

None yet

2 participants