Skip to content

[ILLink] Linker relies on recursive interfaceImpls to be applied by Roslyn #98536

@jtschuster

Description

@jtschuster

Roslyn will apply InterfaceImpl's of the interfaces declared on the type, and all the interfaces that those interfaces implement, recursively. We rely on this fact in a few places in the linker when searching for DIMs, and determining which interfaces can be trimmed. However, this isn't required by IL, and if Roslyn doesn't do this, we get the wrong behavior.

In the following examples, if each type only has InterfaceImpls for the declared interfaces, the app will still run fine, but the linker would break it.

interface IFoo
{
	void Method();
}

interface IBar : IFoo
{
	void IFoo.Method() { }
}

interface IBaz: IBar /*, not IFoo */
{
	void Method() { }
}
    
class MyFoo : IBaz /* not IBar, not IFoo */
{ }

static void CallMethod(IFoo foo)
{
  foo.Method();
}

static void Main()
{
  CallMethod(new MyFoo());
}
interface IBase
{
  static abstract void Method();
}

interface I2 : IBase 
{ 
 static void IBase.Method() { }
}

interface I3 : I2 /* Not IBase */ { }

interface I4 : I3 /* not I2, not IBase */ { }

static void CallMethod<T>() where T : IBase
{
  T.Method();
}

static void Main()
{
  CallMethod<I4>();
}

See #98436 (comment) for additional context and discussion.

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzersin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions