From c5767b45fe3691daa39bc32b5544b63a65727bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 9 May 2023 16:19:09 +0900 Subject: [PATCH 1/2] Stop special casing reflected-on internals Concept of reflection blocked internals was deleted in #85810. This is no longer needed. --- .../src/CompatibilitySuppressions.xml | 8 ------- .../Tracing/TraceLogging/PropertyValue.cs | 22 +++---------------- .../System/Resources/RuntimeResourceSet.cs | 7 +----- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml index 86675997e2cba..0883ff244559c 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml @@ -804,10 +804,6 @@ CP0001 T:System.Diagnostics.DebuggerGuidedStepThroughAttribute - - CP0001 - T:System.Diagnostics.Tracing.PropertyValue - CP0001 T:System.MDArray @@ -872,10 +868,6 @@ CP0001 T:System.Reflection.RuntimeAssemblyName - - CP0001 - T:System.Resources.RuntimeResourceSet - CP0001 T:System.Runtime.CompilerServices.EagerStaticClassConstructionAttribute diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs index 5b5f9c77b1ff5..cd6237c3fcc75 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs @@ -13,13 +13,7 @@ namespace System.Diagnostics.Tracing /// /// To get the value of a property quickly, use a delegate produced by . /// -#if NATIVEAOT - [CLSCompliant(false)] - public // On NativeAOT, this must be public to prevent it from getting reflection blocked. -#else - internal -#endif - readonly unsafe struct PropertyValue + internal readonly unsafe struct PropertyValue { /// /// Union of well-known value types, to avoid boxing those types. @@ -202,12 +196,7 @@ private static Func GetReferenceTypePropertyGetter return helper.GetPropertyGetter(property); } -#if NATIVEAOT - public // On NativeAOT, this must be public to prevent it from getting reflection blocked. -#else - private -#endif - abstract class TypeHelper + private abstract class TypeHelper { public abstract Func GetPropertyGetter(PropertyInfo property); @@ -219,12 +208,7 @@ protected static Delegate GetGetMethod(PropertyInfo property, Type propertyType) } } -#if NATIVEAOT - public // On NativeAOT, this must be public to prevent it from getting reflection blocked. -#else - private -#endif - sealed class ReferenceTypeHelper : TypeHelper where TContainer : class + private sealed class ReferenceTypeHelper : TypeHelper where TContainer : class { private static Func GetGetMethod(PropertyInfo property) where TProperty : struct => property.GetMethod!.CreateDelegate>(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Resources/RuntimeResourceSet.cs b/src/libraries/System.Private.CoreLib/src/System/Resources/RuntimeResourceSet.cs index d5af57f74188d..314c90e122ebb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Resources/RuntimeResourceSet.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Resources/RuntimeResourceSet.cs @@ -154,12 +154,7 @@ namespace System.Resources // into smaller chunks, each of size sqrt(n), would be substantially better for // resource files containing thousands of resources. // -#if NATIVEAOT - public // On NativeAOT, this must be public to prevent it from getting reflection blocked. -#else - internal -#endif - sealed class RuntimeResourceSet : ResourceSet, IEnumerable + internal sealed class RuntimeResourceSet : ResourceSet, IEnumerable { // Cache for resources. Key is the resource name, which can be cached // for arbitrarily long times, since the object is usually a string From 2582decb392d8f0fbe098c2b7df4bfb30a8b971c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 9 May 2023 17:44:54 +0900 Subject: [PATCH 2/2] Can no longer access ResourceSet outside corelib --- src/libraries/System.Private.CoreLib/src/System/SR.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/SR.cs b/src/libraries/System.Private.CoreLib/src/System/SR.cs index 88b2b27f65438..148e91074e1bd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SR.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SR.cs @@ -15,7 +15,9 @@ internal static partial class SR private static readonly object _lock = new object(); private static List? _currentlyLoading; private static int _infinitelyRecursingCount; +#if SYSTEM_PRIVATE_CORELIB private static bool _resourceManagerInited; +#endif private static string InternalGetResourceString(string key) { @@ -72,6 +74,7 @@ private static string InternalGetResourceString(string key) _currentlyLoading ??= new List(); +#if SYSTEM_PRIVATE_CORELIB // Call class constructors preemptively, so that we cannot get into an infinite // loop constructing a TypeInitializationException. If this were omitted, // we could get the Infinite recursion assert above by failing type initialization @@ -84,6 +87,7 @@ private static string InternalGetResourceString(string key) RuntimeHelpers.RunClassConstructor(typeof(BinaryReader).TypeHandle); _resourceManagerInited = true; } +#endif _currentlyLoading.Add(key); // Push