Skip to content

Commit a1f65d6

Browse files
MichalStrehovskytmds
authored andcommitted
Make it possible for arrays to have default-implemented methods (dotnet#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).
1 parent 36b64dd commit a1f65d6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ public sealed override IEnumerable<CombinedDependencyListEntry> GetConditionalSt
531531
if (!isStaticInterfaceMethod && defaultIntfMethod.IsCanonicalMethod(CanonicalFormKind.Any))
532532
{
533533
// Canonical instance default methods need to go through a thunk that adds the right generic context
534-
defaultIntfMethod = factory.TypeSystemContext.GetDefaultInterfaceMethodImplementationThunk(defaultIntfMethod, _type.ConvertToCanonForm(CanonicalFormKind.Specific), providingInterfaceDefinitionType);
534+
defaultIntfMethod = factory.TypeSystemContext.GetDefaultInterfaceMethodImplementationThunk(defaultIntfMethod, defType.ConvertToCanonForm(CanonicalFormKind.Specific), providingInterfaceDefinitionType);
535535
}
536536
result.Add(new CombinedDependencyListEntry(factory.MethodEntrypoint(defaultIntfMethod), factory.VirtualMethodUse(interfaceMethod), "Interface method"));
537537

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/SealedVTableNode.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,11 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly)
216216

217217
if (BuildSealedVTableSlots(factory, relocsOnly))
218218
{
219+
DefType defType = _type.GetClosestDefType();
220+
219221
for (int i = 0; i < _sealedVTableEntries.Count; i++)
220222
{
221-
IMethodNode relocTarget = _sealedVTableEntries[i].GetTarget(factory, _type);
223+
IMethodNode relocTarget = _sealedVTableEntries[i].GetTarget(factory, defType);
222224

223225
if (factory.Target.SupportsRelativePointers)
224226
objData.EmitReloc(relocTarget, RelocType.IMAGE_REL_BASED_RELPTR32);

0 commit comments

Comments
 (0)