-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ILLink] Add interface implementing type to OverrideInformation (#98274)
Adds the type that implements the interface to the OverrideInformation class to be able to properly handle cases where the base provides the interface method or the type relies on a default interface method. Adds the InterfaceImplementor class that is basically a tuple of (TypeDefinition typeWithInterface, InterfaceImplementation ImplementedInterface) to do this. Also cleans some unnecessary code in OverrideInformation and ensures that OverrideInformation will have an InterfaceImplementor if the base method is an interface method.
- Loading branch information
1 parent
d112020
commit 1afd4bc
Showing
10 changed files
with
222 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/tools/illink/src/linker/Linker/InterfaceImplementor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using Mono.Cecil; | ||
|
||
namespace Mono.Linker | ||
{ | ||
public class InterfaceImplementor | ||
{ | ||
/// <summary> | ||
/// The type that implements <see cref="InterfaceImplementor.InterfaceType"/>. | ||
/// </summary> | ||
public TypeDefinition Implementor { get; } | ||
/// <summary> | ||
/// The .interfaceimpl on <see cref="InterfaceImplementor.Implementor"/>that points to <see cref="InterfaceImplementor.InterfaceType"/> | ||
/// </summary> | ||
public InterfaceImplementation InterfaceImplementation { get; } | ||
/// <summary> | ||
/// The type of the interface that is implemented by <see cref="InterfaceImplementor.Implementor"/> | ||
/// </summary> | ||
public TypeDefinition InterfaceType { get; } | ||
|
||
public InterfaceImplementor (TypeDefinition implementor, InterfaceImplementation interfaceImplementation, TypeDefinition interfaceType, IMetadataResolver resolver) | ||
{ | ||
Implementor = implementor; | ||
InterfaceImplementation = interfaceImplementation; | ||
InterfaceType = interfaceType; | ||
Debug.Assert(resolver.Resolve (interfaceImplementation.InterfaceType) == interfaceType); | ||
} | ||
|
||
public static InterfaceImplementor Create(TypeDefinition implementor, TypeDefinition interfaceType, IMetadataResolver resolver) | ||
{ | ||
foreach(InterfaceImplementation iface in implementor.Interfaces) { | ||
if (resolver.Resolve(iface.InterfaceType) == interfaceType) { | ||
return new InterfaceImplementor(implementor, iface, interfaceType, resolver); | ||
} | ||
} | ||
|
||
Queue<TypeDefinition> ifacesToCheck = new (); | ||
ifacesToCheck.Enqueue(implementor); | ||
while (ifacesToCheck.Count > 0) { | ||
var currentIface = ifacesToCheck.Dequeue (); | ||
|
||
foreach(InterfaceImplementation ifaceImpl in currentIface.Interfaces) { | ||
var iface = resolver.Resolve (ifaceImpl.InterfaceType); | ||
if (iface == interfaceType) { | ||
return new InterfaceImplementor(implementor, ifaceImpl, interfaceType, resolver); | ||
} | ||
ifacesToCheck.Enqueue (iface); | ||
} | ||
} | ||
throw new InvalidOperationException ($"Type '{implementor.FullName}' does not implement interface '{interfaceType.FullName}' directly or through any interfaces"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.