From ee84ffdd685e0b8ebe1e61e44d47ac7e69d0d146 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Strehovsk=C3=BD?= Date: Thu, 8 Jun 2023 18:14:36 +0900 Subject: [PATCH] Ifdef out DynamicDependencies that are not necessary (#87209) These create unnecessary reflection targets. Trimming done by NativeAOT will do the right thing and it is redundant on CoreCLR. --- .../System.Private.CoreLib/src/System/AppContext.cs | 4 ++++ .../System.Private.CoreLib/src/System/String.cs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/AppContext.cs b/src/libraries/System.Private.CoreLib/src/System/AppContext.cs index 9023a33..23e968c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/AppContext.cs +++ b/src/libraries/System.Private.CoreLib/src/System/AppContext.cs @@ -71,10 +71,14 @@ namespace System } #pragma warning disable CS0067 // events raised by the VM +#if MONO [field: DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(UnhandledExceptionEventArgs))] +#endif internal static event UnhandledExceptionEventHandler? UnhandledException; +#if MONO [field: DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(FirstChanceExceptionEventArgs))] +#endif internal static event EventHandler? FirstChanceException; #pragma warning restore CS0067 diff --git a/src/libraries/System.Private.CoreLib/src/System/String.cs b/src/libraries/System.Private.CoreLib/src/System/String.cs index f3429dd..d20d5d2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.cs @@ -69,7 +69,9 @@ namespace System */ [MethodImpl(MethodImplOptions.InternalCall)] +#if MONO [DynamicDependency("Ctor(System.Char[])")] +#endif public extern String(char[]? value); private static string Ctor(char[]? value) @@ -88,7 +90,9 @@ namespace System } [MethodImpl(MethodImplOptions.InternalCall)] +#if MONO [DynamicDependency("Ctor(System.Char[],System.Int32,System.Int32)")] +#endif public extern String(char[] value, int startIndex, int length); private static string Ctor(char[] value, int startIndex, int length) @@ -113,7 +117,9 @@ namespace System [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] +#if MONO [DynamicDependency("Ctor(System.Char*)")] +#endif public extern unsafe String(char* value); private static unsafe string Ctor(char* ptr) @@ -137,7 +143,9 @@ namespace System [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] +#if MONO [DynamicDependency("Ctor(System.Char*,System.Int32,System.Int32)")] +#endif public extern unsafe String(char* value, int startIndex, int length); private static unsafe string Ctor(char* ptr, int startIndex, int length) @@ -169,7 +177,9 @@ namespace System [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] +#if MONO [DynamicDependency("Ctor(System.SByte*)")] +#endif public extern unsafe String(sbyte* value); private static unsafe string Ctor(sbyte* value) @@ -185,7 +195,9 @@ namespace System [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] +#if MONO [DynamicDependency("Ctor(System.SByte*,System.Int32,System.Int32)")] +#endif public extern unsafe String(sbyte* value, int startIndex, int length); private static unsafe string Ctor(sbyte* value, int startIndex, int length) @@ -239,7 +251,9 @@ namespace System [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] +#if MONO [DynamicDependency("Ctor(System.SByte*,System.Int32,System.Int32,System.Text.Encoding)")] +#endif public extern unsafe String(sbyte* value, int startIndex, int length, Encoding enc); private static unsafe string Ctor(sbyte* value, int startIndex, int length, Encoding? enc) @@ -268,7 +282,9 @@ namespace System } [MethodImpl(MethodImplOptions.InternalCall)] +#if MONO [DynamicDependency("Ctor(System.Char,System.Int32)")] +#endif public extern String(char c, int count); private static string Ctor(char c, int count) @@ -288,7 +304,9 @@ namespace System } [MethodImpl(MethodImplOptions.InternalCall)] +#if MONO [DynamicDependency("Ctor(System.ReadOnlySpan{System.Char})")] +#endif public extern String(ReadOnlySpan value); private static unsafe string Ctor(ReadOnlySpan value) -- 2.7.4