diff options
author | Jackson Schuster <36744439+jtschuster@users.noreply.github.com> | 2022-04-21 01:37:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-21 01:37:45 +0300 |
commit | a073a68561a7f45a2dba0976083ee3e9873bf423 (patch) | |
tree | fe8df5ca5a750ae83b00f0a87cc6a0759fce2435 /test/Mono.Linker.Tests.Cases | |
parent | e768b2e47c4d5f371bb30974463126d3b1751b5b (diff) |
Trim static interfaces (#2741)
Don't mark static interface methods when called on a concrete type, and removed the MethodImpl / Override if the interface method is kept.
Co-authored-by: vitek-karas <vitek.karas@microsoft.com>
Co-authored-by: vitek-karas <10670590+vitek-karas@users.noreply.github.com>
Diffstat (limited to 'test/Mono.Linker.Tests.Cases')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/InterfaceVariants.cs | 94 | ||||
-rw-r--r-- | test/Mono.Linker.Tests.Cases/Libraries/RootLibrary.cs | 3 |
2 files changed, 75 insertions, 22 deletions
diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/InterfaceVariants.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/InterfaceVariants.cs index f9d54d009..9b766b42a 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/InterfaceVariants.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/InterfaceVariants.cs @@ -17,24 +17,77 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces public static void Main () { Type t = typeof (UninstantiatedPublicClassWithInterface); - t = typeof (UninstantiatedPublicClassWithImplicitlyImplementedInterface); + t = typeof (UninstantiatedClassWithImplicitlyImplementedInterface); t = typeof (UninstantiatedPublicClassWithPrivateInterface); + t = typeof (ImplementsUsedStaticInterface.InterfaceMethodUnused); + t = typeof (ImplementsUnusedStaticInterface.InterfaceMethodUnused); - UninstantiatedPublicClassWithInterface.InternalStaticInterfaceMethodUsed (); - InstantiatedClassWithInterfaces.InternalStaticInterfaceMethodUsed (); - + ImplementsUnusedStaticInterface.InterfaceMethodUsedThroughImplementation.InternalStaticInterfaceMethodUsedThroughImplementation (); + GenericMethodThatCallsInternalStaticInterfaceMethod + <ImplementsUsedStaticInterface.InterfaceMethodUsedThroughInterface> (); // Use all public interfaces - they're marked as public only to denote them as "used" typeof (IPublicInterface).RequiresPublicMethods (); typeof (IPublicStaticInterface).RequiresPublicMethods (); + var ___ = new InstantiatedClassWithInterfaces (); + } + + [Kept] + internal static void GenericMethodThatCallsInternalStaticInterfaceMethod<T> () where T : IStaticInterfaceUsed + { + T.StaticMethodUsedThroughInterface (); + } + + [Kept] + class ImplementsUsedStaticInterface + { + + [Kept] + [KeptInterface (typeof (IStaticInterfaceUsed))] + internal class InterfaceMethodUsedThroughInterface : IStaticInterfaceUsed + { + [Kept] + [KeptOverride (typeof (IStaticInterfaceUsed))] + public static void StaticMethodUsedThroughInterface () + { + } + public static void UnusedMethod () { } + } + + [Kept] + [KeptInterface (typeof (IStaticInterfaceUsed))] + internal class InterfaceMethodUnused : IStaticInterfaceUsed + { + [Kept] + [KeptOverride (typeof (IStaticInterfaceUsed))] + public static void StaticMethodUsedThroughInterface () + { + } + public static void UnusedMethod () { } + } + } + + [Kept] + internal class ImplementsUnusedStaticInterface + { + [Kept] + internal class InterfaceMethodUsedThroughImplementation : IStaticInterfaceUnused + { + [Kept] + [RemovedOverride (typeof (IStaticInterfaceUnused))] + public static void InternalStaticInterfaceMethodUsedThroughImplementation () { } + } - var a = new InstantiatedClassWithInterfaces (); + [Kept] + internal class InterfaceMethodUnused : IStaticInterfaceUnused + { + public static void InternalStaticInterfaceMethodUsedThroughImplementation () { } + } } [Kept] [KeptInterface (typeof (IEnumerator))] [KeptInterface (typeof (IPublicInterface))] [KeptInterface (typeof (IPublicStaticInterface))] - [KeptInterface (typeof (IInternalStaticInterfaceWithUsedMethod))] // https://github.com/dotnet/linker/issues/2733 [KeptInterface (typeof (ICopyLibraryInterface))] [KeptInterface (typeof (ICopyLibraryStaticInterface))] public class UninstantiatedPublicClassWithInterface : @@ -42,7 +95,6 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces IPublicStaticInterface, IInternalInterface, IInternalStaticInterface, - IInternalStaticInterfaceWithUsedMethod, IEnumerator, ICopyLibraryInterface, ICopyLibraryStaticInterface @@ -69,8 +121,6 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces static void IInternalStaticInterface.ExplicitImplementationInternalStaticInterfaceMethod () { } - [Kept] - public static void InternalStaticInterfaceMethodUsed () { } [Kept] [ExpectBodyModified] @@ -101,9 +151,9 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces [Kept] [KeptInterface (typeof (IFormattable))] - public class UninstantiatedPublicClassWithImplicitlyImplementedInterface : IInternalInterface, IFormattable + public class UninstantiatedClassWithImplicitlyImplementedInterface : IInternalInterface, IFormattable { - internal UninstantiatedPublicClassWithImplicitlyImplementedInterface () { } + internal UninstantiatedClassWithImplicitlyImplementedInterface () { } public void InternalInterfaceMethod () { } @@ -122,7 +172,6 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces [KeptInterface (typeof (IEnumerator))] [KeptInterface (typeof (IPublicInterface))] [KeptInterface (typeof (IPublicStaticInterface))] - [KeptInterface (typeof (IInternalStaticInterfaceWithUsedMethod))] // https://github.com/dotnet/linker/issues/2733 [KeptInterface (typeof (ICopyLibraryInterface))] [KeptInterface (typeof (ICopyLibraryStaticInterface))] public class InstantiatedClassWithInterfaces : @@ -130,7 +179,6 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces IPublicStaticInterface, IInternalInterface, IInternalStaticInterface, - IInternalStaticInterfaceWithUsedMethod, IEnumerator, ICopyLibraryInterface, ICopyLibraryStaticInterface @@ -159,9 +207,6 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces static void IInternalStaticInterface.ExplicitImplementationInternalStaticInterfaceMethod () { } [Kept] - public static void InternalStaticInterfaceMethodUsed () { } - - [Kept] bool IEnumerator.MoveNext () { throw new PlatformNotSupportedException (); } [Kept] @@ -225,13 +270,20 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces static abstract void ExplicitImplementationInternalStaticInterfaceMethod (); } - // The interface methods themselves are not used, but the implentation of these methods is - // https://github.com/dotnet/linker/issues/2733 + // The interface methods themselves are not used, but the implementation of these methods is + internal interface IStaticInterfaceUnused + { + static abstract void InternalStaticInterfaceMethodUsedThroughImplementation (); + } + + // The interface methods themselves are used through the interface [Kept] - internal interface IInternalStaticInterfaceWithUsedMethod + internal interface IStaticInterfaceUsed { - [Kept] // https://github.com/dotnet/linker/issues/2733 - static abstract void InternalStaticInterfaceMethodUsed (); + [Kept] + static abstract void StaticMethodUsedThroughInterface (); + + static abstract void UnusedMethod (); } private interface IPrivateInterface diff --git a/test/Mono.Linker.Tests.Cases/Libraries/RootLibrary.cs b/test/Mono.Linker.Tests.Cases/Libraries/RootLibrary.cs index 1534573ea..eebdbf67c 100644 --- a/test/Mono.Linker.Tests.Cases/Libraries/RootLibrary.cs +++ b/test/Mono.Linker.Tests.Cases/Libraries/RootLibrary.cs @@ -217,6 +217,7 @@ namespace Mono.Linker.Tests.Cases.Libraries void IInternalInterface.ExplicitImplementationInternalInterfaceMethod () { } [Kept] + [RemovedOverride (typeof (IInternalStaticInterface))] public static void InternalStaticInterfaceMethod () { } static void IInternalStaticInterface.ExplicitImplementationInternalStaticInterfaceMethod () { } @@ -300,6 +301,7 @@ namespace Mono.Linker.Tests.Cases.Libraries void IInternalInterface.ExplicitImplementationInternalInterfaceMethod () { } [Kept] + [RemovedOverride (typeof (IInternalStaticInterface))] public static void InternalStaticInterfaceMethod () { } static void IInternalStaticInterface.ExplicitImplementationInternalStaticInterfaceMethod () { } @@ -366,7 +368,6 @@ namespace Mono.Linker.Tests.Cases.Libraries [Kept] internal interface IInternalStaticInterface { - [Kept] // https://github.com/dotnet/linker/issues/2733 static abstract void InternalStaticInterfaceMethod (); static abstract void ExplicitImplementationInternalStaticInterfaceMethod (); |