1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-08 11:37:04 +09:00
Satori/docs/tools/illink/methods-kept-by-interface.md
Tlakaelel Axayakatl Ceja 18e20d84fd
Update ILLink wording (#82050)
Update linker wording to disambiguate the term from native linker, switched to illink
Deleted illink steps-explained document since is no longer accurate
This change did not change attribute justification messages
Add changes to use same wording between shared files
2023-02-23 10:44:50 -08:00

5.6 KiB

Interface Implementation Methods Marking

(Does this method need to be kept due to the interface method it overrides)

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):

  • Base method is abstract or has a default implementation (abstract vs virtual in C#)
  • Method is Instance or Static
  • Implementing type is relevant to variant casting or not
    • Relevant to variant casting means the type token appears, the type is passed as a type argument or array type, or is reflected over.
  • Base method is marked as used or not
  • Base method is from preserved scope or not
  • Implementing type is marked as instantiated or not
  • Interface Implementation is marked or not

Note that in library mode, interface methods that can be accessed by COM or native code are marked by the ILLink.

If the interface implementation is not marked, do not mark the implementation method

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):

  • Base method is abstract or has a default implementation
  • Method is Instance or Static
  • Implementing type is relevant to variant casting or not
  • Base method is marked as used or not
  • Base method from preserved scope or not
  • Implementing type is marked as instantiated or not
  • Interface Implementation is marked

If the interface method is not marked and the interface doesn't come from a preserved scope, do not mark the implementation method

Unmarked interface methods from link assemblies will be removed so the implementing method does not need to be kept.

Cases left:

  • Base method is abstract or has a default implementation
  • Method is Instance or Static
  • Implementing type is relevant to variant casting or not
  • Base method is marked as used or not
  • Base method from preserved scope or not
  • Base method is either marked as used or from preserved scope (combine above)
  • Implementing type is marked as instantiated or not
  • Interface Implementation is marked

If the interface method is abstract, mark the implementation method

The method is needed for valid IL.

Cases left:

  • Base method has a default implementation
  • Method is Instance or Static
  • Implementing type is relevant to variant casting or not
  • Base method is marked as used or from preserved scope
  • Implementing type is marked as instantiated or not
  • Interface Implementation is marked

If the method is an instance method then mark the implementation method if the type is instantiated (or instantiable in library mode) and do not mark the implementation otherwise.

An application can call the instance interface method if and only if the type is instantiated.

Cases left:

  • Base method has a default implementation
  • Method is Static
  • Implementing type is relevant to variant casting or not
  • Base method is marked as used or from preserved scope
  • Implementing type is marked as instantiated or not
  • Interface Implementation is marked

The use of static methods is not related to whether or not a type is instantiated or not.

Cases left:

  • Base method has a default implementation
  • Method is Static
  • Implementing type is relevant to variant casting or not
  • Base method is marked as used or from preserved scope
  • Interface Implementation is marked

If the implementing type is relevant to variant casting, mark the implementation method.

A static method may only be called through a constrained call if the type is relevant to variant casting.

Cases left:

  • Base method has a default implementation
  • Method is Static
  • Implementing type is not relevant to variant casting
  • Base method is marked as used or from preserved scope
  • Interface Implementation is marked

If the interface method is in a preserved scope, mark the implementation method.

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.

Otherwise, do not mark the implementing 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