Skip to content

Commit 9da5359

Browse files
authored
[ILLink] Add correct ImplementingType to DIM cache in TypeMapInfo (#98513)
Adds the correc
1 parent 71344ce commit 9da5359

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/tools/illink/src/linker/Linker/TypeMapInfo.cs

+19-12
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void MapInterfaceMethodsInTypeHierarchy (TypeDefinition type)
181181
}
182182

183183
// Look for a default implementation last.
184-
FindAndAddDefaultInterfaceImplementations (type, resolvedInterfaceMethod);
184+
FindAndAddDefaultInterfaceImplementations (type, type, resolvedInterfaceMethod);
185185
}
186186
}
187187
}
@@ -279,26 +279,33 @@ void AnnotateMethods (MethodDefinition @base, MethodDefinition @override, Interf
279279
return context.TryResolve (type)?.BaseType;
280280
}
281281

282-
// Returns a list of default implementations of the given interface method on this type.
283-
// Note that this returns a list to potentially cover the diamond case (more than one
284-
// most specific implementation of the given interface methods). ILLink needs to preserve
285-
// all the implementations so that the proper exception can be thrown at runtime.
286-
void FindAndAddDefaultInterfaceImplementations (TypeDefinition type, MethodDefinition interfaceMethod)
282+
/// <summary>
283+
/// Returns a list of default implementations of the given interface method on this type.
284+
/// Note that this returns a list to potentially cover the diamond case (more than one
285+
/// most specific implementation of the given interface methods). ILLink needs to preserve
286+
/// all the implementations so that the proper exception can be thrown at runtime.
287+
/// </summary>
288+
/// <param name="type">The type that implements (directly or via a base interface) the declaring interface of <paramref name="interfaceMethod"/></param>
289+
/// <param name="interfaceMethod">The method to find a default implementation for</param>
290+
/// <param name="implOfInterface">
291+
/// The InterfaceImplementation on <paramref name="type"/> that points to the DeclaringType of <paramref name="interfaceMethod"/>.
292+
/// </param>
293+
void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplementsInterface, TypeDefinition typeThatMayHaveDIM, MethodDefinition interfaceMethodToBeImplemented)
287294
{
288295
// Go over all interfaces, trying to find a method that is an explicit MethodImpl of the
289296
// interface method in question.
290297

291-
foreach (var interfaceImpl in type.Interfaces) {
298+
foreach (var interfaceImpl in typeThatMayHaveDIM.Interfaces) {
292299
var potentialImplInterface = context.TryResolve (interfaceImpl.InterfaceType);
293300
if (potentialImplInterface == null)
294301
continue;
295302

296303
bool foundImpl = false;
297304

298305
foreach (var potentialImplMethod in potentialImplInterface.Methods) {
299-
if (potentialImplMethod == interfaceMethod &&
306+
if (potentialImplMethod == interfaceMethodToBeImplemented &&
300307
!potentialImplMethod.IsAbstract) {
301-
AddDefaultInterfaceImplementation (interfaceMethod, type, (interfaceImpl, potentialImplMethod));
308+
AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (interfaceImpl, potentialImplMethod));
302309
foundImpl = true;
303310
break;
304311
}
@@ -308,8 +315,8 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition type, MethodDefin
308315

309316
// This method is an override of something. Let's see if it's the method we are looking for.
310317
foreach (var @override in potentialImplMethod.Overrides) {
311-
if (context.TryResolve (@override) == interfaceMethod) {
312-
AddDefaultInterfaceImplementation (interfaceMethod, type, (interfaceImpl, @potentialImplMethod));
318+
if (context.TryResolve (@override) == interfaceMethodToBeImplemented) {
319+
AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (interfaceImpl, potentialImplMethod));
313320
foundImpl = true;
314321
break;
315322
}
@@ -323,7 +330,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition type, MethodDefin
323330
// We haven't found a MethodImpl on the current interface, but one of the interfaces
324331
// this interface requires could still provide it.
325332
if (!foundImpl) {
326-
FindAndAddDefaultInterfaceImplementations (potentialImplInterface, interfaceMethod);
333+
FindAndAddDefaultInterfaceImplementations (typeThatImplementsInterface, potentialImplInterface, interfaceMethodToBeImplemented);
327334
}
328335
}
329336
}

0 commit comments

Comments
 (0)