diff options
author | Andy Gocke <angocke@microsoft.com> | 2022-03-23 20:23:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-23 20:23:23 +0300 |
commit | eab62f9046510f4dce671103470e0be9bc68b04b (patch) | |
tree | 6afdb1f346b234522432668f246cfab627a283c2 | |
parent | e9cfb5413a6a7a7b5bfc3b9a73671be2b18642cf (diff) |
Remove special logic for TypeConverterAttribute (#2659) (#2695)
(cherry picked from commit b10e1bc3da22862b4ddedc2b50639dee9d8dacfd)
Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
-rw-r--r-- | src/linker/Linker.Steps/MarkStep.cs | 50 | ||||
-rw-r--r-- | test/Mono.Linker.Tests.Cases/ComponentModel/TypeDescriptionProviderAttributeOnType.cs | 64 |
2 files changed, 48 insertions, 66 deletions
diff --git a/src/linker/Linker.Steps/MarkStep.cs b/src/linker/Linker.Steps/MarkStep.cs index 1d1b95555..621ca734c 100644 --- a/src/linker/Linker.Steps/MarkStep.cs +++ b/src/linker/Linker.Steps/MarkStep.cs @@ -819,7 +819,6 @@ namespace Mono.Linker.Steps continue; MarkCustomAttribute (ca, reason); - MarkSpecialCustomAttributeDependencies (ca, provider); } } @@ -1570,7 +1569,6 @@ namespace Mono.Linker.Steps markOccurred = true; using (ScopeStack.PushScope (scope)) { MarkCustomAttribute (customAttribute, reason); - MarkSpecialCustomAttributeDependencies (customAttribute, provider); } } @@ -2070,30 +2068,10 @@ namespace Mono.Linker.Steps if (MarkMethodsIf (type.Methods, MethodDefinitionExtensions.IsPublicInstancePropertyMethod, new DependencyInfo (DependencyKind.ReferencedBySpecialAttribute, type))) Tracer.AddDirectDependency (attribute, new DependencyInfo (DependencyKind.CustomAttribute, type), marked: false); break; - case "TypeDescriptionProviderAttribute" when attrType.Namespace == "System.ComponentModel": - MarkTypeConverterLikeDependency (attribute, l => l.IsDefaultConstructor (), type); - break; } } } - // - // Used for known framework attributes which can be applied to any element - // - bool MarkSpecialCustomAttributeDependencies (CustomAttribute ca, ICustomAttributeProvider provider) - { - var dt = ca.Constructor.DeclaringType; - if (dt.Name == "TypeConverterAttribute" && dt.Namespace == "System.ComponentModel") { - MarkTypeConverterLikeDependency (ca, l => - l.IsDefaultConstructor () || - l.Parameters.Count == 1 && l.Parameters[0].ParameterType.IsTypeOf ("System", "Type"), - provider); - return true; - } - - return false; - } - void MarkMethodSpecialCustomAttributes (MethodDefinition method) { if (!method.HasCustomAttributes) @@ -2116,34 +2094,6 @@ namespace Mono.Linker.Steps } } - protected virtual void MarkTypeConverterLikeDependency (CustomAttribute attribute, Func<MethodDefinition, bool> predicate, ICustomAttributeProvider provider) - { - var args = attribute.ConstructorArguments; - if (args.Count < 1) - return; - - TypeDefinition? typeDefinition = null; - switch (attribute.ConstructorArguments[0].Value) { - case string s: - if (!Context.TypeNameResolver.TryResolveTypeName (s, ScopeStack.CurrentScope.Origin.Provider, out TypeReference? typeRef, out AssemblyDefinition? assemblyDefinition)) - break; - typeDefinition = Context.TryResolve (typeRef); - if (typeDefinition != null) - MarkingHelpers.MarkMatchingExportedType (typeDefinition, assemblyDefinition, new DependencyInfo (DependencyKind.CustomAttribute, provider)); - - break; - case TypeReference type: - typeDefinition = Context.Resolve (type); - break; - } - - if (typeDefinition == null) - return; - - Tracer.AddDirectDependency (attribute, new DependencyInfo (DependencyKind.CustomAttribute, provider), marked: false); - MarkMethodsIf (typeDefinition.Methods, predicate, new DependencyInfo (DependencyKind.ReferencedBySpecialAttribute, attribute)); - } - static readonly Regex DebuggerDisplayAttributeValueRegex = new Regex ("{[^{}]+}", RegexOptions.Compiled); void MarkTypeWithDebuggerDisplayAttribute (TypeDefinition type, CustomAttribute attribute) diff --git a/test/Mono.Linker.Tests.Cases/ComponentModel/TypeDescriptionProviderAttributeOnType.cs b/test/Mono.Linker.Tests.Cases/ComponentModel/TypeDescriptionProviderAttributeOnType.cs index 07de3e5f8..ca6099f9c 100644 --- a/test/Mono.Linker.Tests.Cases/ComponentModel/TypeDescriptionProviderAttributeOnType.cs +++ b/test/Mono.Linker.Tests.Cases/ComponentModel/TypeDescriptionProviderAttributeOnType.cs @@ -1,37 +1,69 @@ +using System; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Cases.Expectations.Metadata; + namespace Mono.Linker.Tests.Cases.ComponentModel { - [TypeDescriptionProvider (typeof (CustomTDP))] - - [Kept] - [KeptAttributeAttribute (typeof (TypeDescriptionProviderAttribute))] - class CustomTypeDescriptionProvider_1 + [Reference ("System.dll")] + [ExpectedNoWarnings] + public class TypeDescriptionProviderAttributeOnType { - [Kept] - public CustomTypeDescriptionProvider_1 () + public static void Main () { + var r1 = new CustomTypeDescriptionProvider_1 (); + IInterface v = InterfaceTypeConverter.CreateVisual (typeof (System.String)); } + [TypeDescriptionProvider (typeof (CustomTDP))] [Kept] - [KeptBaseType (typeof (TypeDescriptionProvider))] - class CustomTDP : TypeDescriptionProvider + [KeptAttributeAttribute (typeof (TypeDescriptionProviderAttribute))] + class CustomTypeDescriptionProvider_1 { [Kept] - public CustomTDP () + public CustomTypeDescriptionProvider_1 () { } + + [Kept] + [KeptBaseType (typeof (TypeDescriptionProvider))] + class CustomTDP : TypeDescriptionProvider + { + [Kept] + public CustomTDP () + { + } + } } - } - [Reference ("System.dll")] - public class TypeDescriptionProviderAttributeOnType - { - public static void Main () + [Kept] + [KeptAttributeAttribute (typeof (TypeConverterAttribute))] + [TypeConverter (typeof (InterfaceTypeConverter))] + public interface IInterface + { } + + [Kept] + [KeptBaseType (typeof (TypeConverter))] + public class InterfaceTypeConverter : TypeConverter { - var r1 = new CustomTypeDescriptionProvider_1 (); + [Kept] + public static IInterface CreateVisual ( + [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] + Type visualType) + { + try { + return (IInterface) Activator.CreateInstance (visualType); + } catch { + } + + return null; + } + + [Kept] + public InterfaceTypeConverter () { } } } } |