docs/tools/illink/methods-kept-by-interface.md
The following behavior is expected for interface methods. This logic could be used to begin marking and sweeping the .Override of a method since if the method isn't a dependency due to the interface/base type, we should be able to remove the methodImpl. Right now, the methodImpl is always kept if both the interface method and overriding method is kept, but that isn't always necessary.
Whether or not a method implementing an interface method is required due to the interface is affected by the following cases / possibilities (the method could still be kept for other reasons):
abstract vs virtual in C#)Note that in library mode, interface methods that can be accessed by COM or native code are marked by the ILLink.
A type that doesn't implement the interface isn't required to have methods that implement the interface. However, a base type may have a public method that implements an interface on a derived type. If the interface implementation on the derived type is marked, then the method may be needed and we should go onto the next step.
Cases left (bold means we know it is only one of the possible options now):
Unmarked interface methods from link assemblies will be removed so the implementing method does not need to be kept.
Cases left:
The method is needed for valid IL.
Cases left:
An application can call the instance interface method if and only if the type is instantiated.
Cases left:
The use of static methods is not related to whether or not a type is instantiated or not.
Cases left:
A static method may only be called through a constrained call if the type is relevant to variant casting.
Cases left:
We assume the implementing type could be relevant to variant casting in the preserved scope assembly and could be called, so we will keep the method.
Summary:
if Interface Implementation is not marked then do not mark the implementation method.
else if Base method is marked as not used AND Interface is not from preserved scope do not mark the implementation method
else if Base method does not have a default implementation then mark the implementation method
else if Implementation method is an instance method AND Implementing type is instantiated then mark the implementation method
else if Implementation method is an instance method AND Implementing type is not instantiated then do not mark the implementation method
else if Method is Static AND Implementing type is relevant to variant casting then mark the implementation method
else if Method is Static AND Interface method is from a preserved scope then mark the implementation method
else do not mark the implementation method