Skip to content

Commit

Permalink
Cache the InterfaceImplementation for the concrete type that requires…
Browse files Browse the repository at this point in the history
… the DIM to be kept in DefaultInterfaceImplementations cache (dotnet#98782)

Previously, we would cache the InterfaceImpl that pointed to the interface that provided the DIM. It should be the original type that created the need for the DIM.
  • Loading branch information
jtschuster committed Feb 23, 2024
1 parent 9512aab commit d676724
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ void ProcessVirtualMethod (MethodDefinition method)
foreach (var dimInfo in defaultImplementations) {
ProcessDefaultImplementation (dimInfo.ImplementingType, dimInfo.InterfaceImpl, dimInfo.DefaultInterfaceMethod);

var ov = new OverrideInformation (method, dimInfo.DefaultInterfaceMethod, Context);
var ov = new OverrideInformation (method, dimInfo.DefaultInterfaceMethod, Context, dimInfo.InterfaceImpl);
if (IsInterfaceImplementationMethodNeededByTypeDueToInterface (ov, dimInfo.ImplementingType))
MarkMethod (ov.Override, new DependencyInfo (DependencyKind.Override, ov.Base), ScopeStack.CurrentScope.Origin);
}
Expand Down
10 changes: 5 additions & 5 deletions src/tools/illink/src/linker/Linker/TypeMapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void MapInterfaceMethodsInTypeHierarchy (TypeDefinition type)
}

// Look for a default implementation last.
FindAndAddDefaultInterfaceImplementations (type, type, resolvedInterfaceMethod);
FindAndAddDefaultInterfaceImplementations (type, type, resolvedInterfaceMethod, interfaceImpl.OriginalImpl);
}
}
}
Expand Down Expand Up @@ -290,7 +290,7 @@ void AnnotateMethods (MethodDefinition @base, MethodDefinition @override, Interf
/// <param name="implOfInterface">
/// The InterfaceImplementation on <paramref name="type"/> that points to the DeclaringType of <paramref name="interfaceMethod"/>.
/// </param>
void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplementsInterface, TypeDefinition typeThatMayHaveDIM, MethodDefinition interfaceMethodToBeImplemented)
void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplementsInterface, TypeDefinition typeThatMayHaveDIM, MethodDefinition interfaceMethodToBeImplemented, InterfaceImplementation implOfInterface)
{
// Go over all interfaces, trying to find a method that is an explicit MethodImpl of the
// interface method in question.
Expand All @@ -305,7 +305,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplement
foreach (var potentialImplMethod in potentialImplInterface.Methods) {
if (potentialImplMethod == interfaceMethodToBeImplemented &&
!potentialImplMethod.IsAbstract) {
AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (interfaceImpl, potentialImplMethod));
AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (implOfInterface, potentialImplMethod));
foundImpl = true;
break;
}
Expand All @@ -316,7 +316,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplement
// This method is an override of something. Let's see if it's the method we are looking for.
foreach (var @override in potentialImplMethod.Overrides) {
if (context.TryResolve (@override) == interfaceMethodToBeImplemented) {
AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (interfaceImpl, potentialImplMethod));
AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (implOfInterface, potentialImplMethod));
foundImpl = true;
break;
}
Expand All @@ -330,7 +330,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplement
// We haven't found a MethodImpl on the current interface, but one of the interfaces
// this interface requires could still provide it.
if (!foundImpl) {
FindAndAddDefaultInterfaceImplementations (typeThatImplementsInterface, potentialImplInterface, interfaceMethodToBeImplemented);
FindAndAddDefaultInterfaceImplementations (typeThatImplementsInterface, potentialImplInterface, interfaceMethodToBeImplemented, implOfInterface);
}
}
}
Expand Down

0 comments on commit d676724

Please sign in to comment.