Skip to content

Commit

Permalink
Make it possible for arrays to have default-implemented methods (#96672)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
MichalStrehovsky authored Jan 9, 2024
1 parent 4e97ec2 commit 3710d53
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ public sealed override IEnumerable<CombinedDependencyListEntry> GetConditionalSt
if (!isStaticInterfaceMethod && defaultIntfMethod.IsCanonicalMethod(CanonicalFormKind.Any))
{
// Canonical instance default methods need to go through a thunk that adds the right generic context
defaultIntfMethod = factory.TypeSystemContext.GetDefaultInterfaceMethodImplementationThunk(defaultIntfMethod, _type.ConvertToCanonForm(CanonicalFormKind.Specific), providingInterfaceDefinitionType);
defaultIntfMethod = factory.TypeSystemContext.GetDefaultInterfaceMethodImplementationThunk(defaultIntfMethod, defType.ConvertToCanonForm(CanonicalFormKind.Specific), providingInterfaceDefinitionType);
}
result.Add(new CombinedDependencyListEntry(factory.MethodEntrypoint(defaultIntfMethod), factory.VirtualMethodUse(interfaceMethod), "Interface method"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly)

if (BuildSealedVTableSlots(factory, relocsOnly))
{
DefType defType = _type.GetClosestDefType();

for (int i = 0; i < _sealedVTableEntries.Count; i++)
{
IMethodNode relocTarget = _sealedVTableEntries[i].GetTarget(factory, _type);
IMethodNode relocTarget = _sealedVTableEntries[i].GetTarget(factory, defType);

if (factory.Target.SupportsRelativePointers)
objData.EmitReloc(relocTarget, RelocType.IMAGE_REL_BASED_RELPTR32);
Expand Down

0 comments on commit 3710d53

Please sign in to comment.