From 8b1bd18638889ceba91943d844f795ef354083db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 7 Jun 2023 18:06:12 +0900 Subject: [PATCH 1/2] Ifdef out DynamicDependencies that are not necessary These create unnecessary reflection targets. Trimming done by NativeAOT will do the right thing. --- .../src/System/AppContext.cs | 4 ++++ .../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 9023a33944b2f9..d2a01579bdaf83 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 @@ public static void SetData(string name, object? data) } #pragma warning disable CS0067 // events raised by the VM +#if !NATIVEAOT [field: DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(UnhandledExceptionEventArgs))] +#endif internal static event UnhandledExceptionEventHandler? UnhandledException; +#if !NATIVEAOT [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 f3429dd18aa0d6..93185334692a08 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 @@ public sealed partial class String */ [MethodImpl(MethodImplOptions.InternalCall)] +#if !NATIVEAOT [DynamicDependency("Ctor(System.Char[])")] +#endif public extern String(char[]? value); private static string Ctor(char[]? value) @@ -88,7 +90,9 @@ private static string Ctor(char[]? value) } [MethodImpl(MethodImplOptions.InternalCall)] +#if !NATIVEAOT [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 @@ private static string Ctor(char[] value, int startIndex, int length) [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] +#if !NATIVEAOT [DynamicDependency("Ctor(System.Char*)")] +#endif public extern unsafe String(char* value); private static unsafe string Ctor(char* ptr) @@ -137,7 +143,9 @@ private static unsafe string Ctor(char* ptr) [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] +#if !NATIVEAOT [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 @@ private static unsafe string Ctor(char* ptr, int startIndex, int length) [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] +#if !NATIVEAOT [DynamicDependency("Ctor(System.SByte*)")] +#endif public extern unsafe String(sbyte* value); private static unsafe string Ctor(sbyte* value) @@ -185,7 +195,9 @@ private static unsafe string Ctor(sbyte* value) [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] +#if !NATIVEAOT [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 @@ private static unsafe string CreateStringForSByteConstructor(byte* pb, int numBy [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] +#if !NATIVEAOT [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 @@ private static unsafe string Ctor(sbyte* value, int startIndex, int length, Enco } [MethodImpl(MethodImplOptions.InternalCall)] +#if !NATIVEAOT [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 @@ private static string Ctor(char c, int count) } [MethodImpl(MethodImplOptions.InternalCall)] +#if !NATIVEAOT [DynamicDependency("Ctor(System.ReadOnlySpan{System.Char})")] +#endif public extern String(ReadOnlySpan value); private static unsafe string Ctor(ReadOnlySpan value) From 82de73495cdf8ef998819279d8b812d40910e0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Thu, 8 Jun 2023 05:36:15 +0900 Subject: [PATCH 2/2] FB --- .../src/System/AppContext.cs | 4 ++-- .../src/System/String.cs | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/AppContext.cs b/src/libraries/System.Private.CoreLib/src/System/AppContext.cs index d2a01579bdaf83..23e968c7d1729e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/AppContext.cs +++ b/src/libraries/System.Private.CoreLib/src/System/AppContext.cs @@ -71,12 +71,12 @@ public static void SetData(string name, object? data) } #pragma warning disable CS0067 // events raised by the VM -#if !NATIVEAOT +#if MONO [field: DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(UnhandledExceptionEventArgs))] #endif internal static event UnhandledExceptionEventHandler? UnhandledException; -#if !NATIVEAOT +#if MONO [field: DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(FirstChanceExceptionEventArgs))] #endif internal static event EventHandler? FirstChanceException; diff --git a/src/libraries/System.Private.CoreLib/src/System/String.cs b/src/libraries/System.Private.CoreLib/src/System/String.cs index 93185334692a08..d20d5d23649014 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.cs @@ -69,7 +69,7 @@ public sealed partial class String */ [MethodImpl(MethodImplOptions.InternalCall)] -#if !NATIVEAOT +#if MONO [DynamicDependency("Ctor(System.Char[])")] #endif public extern String(char[]? value); @@ -90,7 +90,7 @@ private static string Ctor(char[]? value) } [MethodImpl(MethodImplOptions.InternalCall)] -#if !NATIVEAOT +#if MONO [DynamicDependency("Ctor(System.Char[],System.Int32,System.Int32)")] #endif public extern String(char[] value, int startIndex, int length); @@ -117,7 +117,7 @@ private static string Ctor(char[] value, int startIndex, int length) [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] -#if !NATIVEAOT +#if MONO [DynamicDependency("Ctor(System.Char*)")] #endif public extern unsafe String(char* value); @@ -143,7 +143,7 @@ private static unsafe string Ctor(char* ptr) [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] -#if !NATIVEAOT +#if MONO [DynamicDependency("Ctor(System.Char*,System.Int32,System.Int32)")] #endif public extern unsafe String(char* value, int startIndex, int length); @@ -177,7 +177,7 @@ private static unsafe string Ctor(char* ptr, int startIndex, int length) [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] -#if !NATIVEAOT +#if MONO [DynamicDependency("Ctor(System.SByte*)")] #endif public extern unsafe String(sbyte* value); @@ -195,7 +195,7 @@ private static unsafe string Ctor(sbyte* value) [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] -#if !NATIVEAOT +#if MONO [DynamicDependency("Ctor(System.SByte*,System.Int32,System.Int32)")] #endif public extern unsafe String(sbyte* value, int startIndex, int length); @@ -251,7 +251,7 @@ private static unsafe string CreateStringForSByteConstructor(byte* pb, int numBy [CLSCompliant(false)] [MethodImpl(MethodImplOptions.InternalCall)] -#if !NATIVEAOT +#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); @@ -282,7 +282,7 @@ private static unsafe string Ctor(sbyte* value, int startIndex, int length, Enco } [MethodImpl(MethodImplOptions.InternalCall)] -#if !NATIVEAOT +#if MONO [DynamicDependency("Ctor(System.Char,System.Int32)")] #endif public extern String(char c, int count); @@ -304,7 +304,7 @@ private static string Ctor(char c, int count) } [MethodImpl(MethodImplOptions.InternalCall)] -#if !NATIVEAOT +#if MONO [DynamicDependency("Ctor(System.ReadOnlySpan{System.Char})")] #endif public extern String(ReadOnlySpan value);