Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate trimming of static interface methods when the interface is not used #2733

Open
vitek-karas opened this issue Apr 8, 2022 · 1 comment

Comments

@vitek-karas
Copy link
Member

Currently linker will keep the interface if there's a method which implements one of the static interface methods on it and that implementation method is kept. This is unlike non-static interface methods where the same situation still allows the linker to remove the interface.

Sample:

void Main()
{
    TestClass.Method (); // Use the implementation method only
}

[Kept] // ??? Why
interface IStaticIFace
{
    [Kept] // ??? Why
    static abstract Method();
}

[Kept] // This is correct
class TestClass : IStaticIFace
{
    [Kept] // This is correct
    public static abstract Method() {};
}
@vitek-karas
Copy link
Member Author

I debugged this a little. The main difference is that non-static methods implement the interface method implicitly - there's no override in the IL metadata. Static interface method implementation do have an explicit override in the metadata. Currently linker if method has overrides marks those overrides (and interfaces they belong to) without any additional logic.

This needs a bit of investigation:

  • Is it OK to not keep the interface/method in this case? Will Cecil do the right thing with metadata if linker removed them?
  • How to implement such behavior - linker would explicitly ignore override in the IL metadata - this might need careful handling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants