From f70486b30074f396edbb14c41c480b77e58487b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Fri, 5 May 2023 15:20:59 +0900 Subject: [PATCH 1/6] Get rid of reflection blocked types Fixes #72570. Still need to delete workarounds that make things public in corelib but maybe this diff is large enough already? We were gradually getting less and less from reflection blocking: * We stopped blocking things outside corelib (.NET Native blocked all of BCL; we don't). * We trim reflection metadata and that allows us to have method bodies without metadata. With this, we should be able to get type definition-level reflection metadata for any MethodTable there is in the system. This is a ~30 kB size regression for BasicMinimalApis. It is pretty much a wash for Hello World, because all the BCL cruft to handle reflection blocked types costs as much as the benefit of blocking. --- eng/testing/tests.singlefile.targets | 3 - .../__BlockAllReflectionAttribute.cs | 16 -- .../__BlockReflectionAttribute.cs | 16 -- .../src/CompatibilitySuppressions.xml | 4 - .../DeveloperExperience.cs | 1 - .../Reflection/Augments/ReflectionAugments.cs | 2 - .../Reflection/Core/AssemblyBinder.cs | 2 - .../Core/Execution/ExecutionDomain.cs | 67 +---- .../Core/Execution/ExecutionEnvironment.cs | 7 +- .../Core/Execution/FieldAccessor.cs | 1 - .../Core/Execution/MethodInvoker.cs | 1 - .../Core/Execution/ReflectionCoreExecution.cs | 1 - .../Core/NonPortable/RuntimeTypeUnifier.cs | 8 +- .../Reflection/Core/ReflectionDomainSetup.cs | 1 - .../ReflectionExecutionDomainCallbacks.cs | 6 +- .../Runtime/Augments/RuntimeAugments.cs | 13 - .../Augments/StackTraceMetadataCallbacks.cs | 1 - .../Runtime/Augments/TypeLoaderCallbacks.cs | 1 - .../CompilerServices/FunctionPointerOps.cs | 1 - .../GenericMethodDescriptor.cs | 1 - .../CompilerServices/OpenMethodResolver.cs | 1 - .../src/System.Private.CoreLib.csproj | 6 - .../System/Diagnostics/DebugAnnotations.cs | 1 - .../DebuggerGuidedStepThroughAttribute.cs | 1 - .../Reflection/AssemblyRuntimeNameHelpers.cs | 1 - .../src/System/Reflection/BinderBundle.cs | 1 - .../System/Reflection/DynamicInvokeInfo.cs | 1 - .../src/System/Reflection/EnumInfo.cs | 2 - .../BlockedRuntimeTypeNameGenerator.cs | 39 --- .../MetadataReaderExtensions.NativeFormat.cs | 1 - .../General/MetadataReaderExtensions.cs | 1 - .../Reflection/Runtime/General/QHandles.cs | 6 - .../Runtime/General/QSignatureTypeHandle.cs | 1 - .../General/TypeResolver.NativeFormat.cs | 4 - .../Reflection/Runtime/General/TypeUnifier.cs | 41 --- .../TypeInfos/RuntimeBlockedTypeInfo.cs | 251 ------------------ .../RuntimeConstructedGenericTypeInfo.cs | 3 - .../RuntimeTypeInfo.CoreGetDeclared.cs | 8 - .../ReflectionBlockedAttribute.cs | 11 - .../InteropServices/InteropExtensions.cs | 1 - .../src/System/Runtime/RuntimeImports.cs | 1 - .../src/System/Runtime/TypeLoaderExports.cs | 2 - .../src/System/RuntimeExceptionHelpers.cs | 1 - .../src/System/Threading/Condition.cs | 1 - .../src/System/Threading/Lock.cs | 1 - .../src/System/Threading/LockHolder.cs | 1 - ...nExecutionDomainCallbacksImplementation.cs | 4 +- ...EnvironmentImplementation.MappingTables.cs | 97 +------ ...cutionEnvironmentImplementation.Runtime.cs | 15 +- .../DiagnosticMappingTables.cs | 121 --------- .../MissingMetadataExceptionCreator.cs | 8 - .../Execution/ReflectionExecution.cs | 3 +- ...nExecutionDomainCallbacksImplementation.cs | 14 +- ...System.Private.Reflection.Execution.csproj | 20 +- .../System.Private.StackTraceMetadata.csproj | 3 - .../TypeLoader/LowLevelStringConverter.cs | 7 - .../TypeLoader/MetadataReaderHelpers.cs | 167 ------------ .../TypeLoaderEnvironment.Metadata.cs | 191 ------------- ...derEnvironment.MetadataSignatureParsing.cs | 8 - .../TypeSystem/RuntimeNoMetadataType.cs | 8 - .../src/System.Private.TypeLoader.csproj | 4 - .../SortableDependencyNode.cs | 2 - .../NativeFormat/Generator/CsWriter.cs | 1 - .../NativeFormatReaderCommonGen.cs | 6 - .../NativeFormat/NativeFormatReaderGen.cs | 180 ------------- .../NativeFormat/NativeMetadataReader.cs | 7 - .../Common/Internal/Runtime/MetadataBlob.cs | 4 +- .../BlockedInternalsBlockingPolicy.cs | 233 ---------------- .../BlockReflectionTypeMapNode.cs | 87 ------ .../DependencyAnalysis/CanonicalEETypeNode.cs | 11 - .../ConstructedEETypeNode.cs | 11 - .../DefaultConstructorMapNode.cs | 92 ------- .../Compiler/GeneratingMetadataManager.cs | 4 - .../Compiler/MetadataManager.cs | 6 - .../ILCompiler.Compiler.csproj | 3 - .../aot/ILCompiler/ILCompilerRootCommand.cs | 3 - src/coreclr/tools/aot/ILCompiler/Program.cs | 3 +- 77 files changed, 37 insertions(+), 1827 deletions(-) delete mode 100644 src/coreclr/nativeaot/Common/src/System/Runtime/CompilerServices/__BlockAllReflectionAttribute.cs delete mode 100644 src/coreclr/nativeaot/Common/src/System/Runtime/CompilerServices/__BlockReflectionAttribute.cs delete mode 100644 src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/BlockedRuntimeTypeNameGenerator.cs delete mode 100644 src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeBlockedTypeInfo.cs delete mode 100644 src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/ReflectionBlockedAttribute.cs delete mode 100644 src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/PayForPlayExperience/DiagnosticMappingTables.cs delete mode 100644 src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/MetadataReaderHelpers.cs delete mode 100644 src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/BlockedInternalsBlockingPolicy.cs delete mode 100644 src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/BlockReflectionTypeMapNode.cs delete mode 100644 src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DefaultConstructorMapNode.cs diff --git a/eng/testing/tests.singlefile.targets b/eng/testing/tests.singlefile.targets index 5fb0e1bd643ea..85af1cae8127d 100644 --- a/eng/testing/tests.singlefile.targets +++ b/eng/testing/tests.singlefile.targets @@ -73,9 +73,6 @@ - - - diff --git a/src/coreclr/nativeaot/Common/src/System/Runtime/CompilerServices/__BlockAllReflectionAttribute.cs b/src/coreclr/nativeaot/Common/src/System/Runtime/CompilerServices/__BlockAllReflectionAttribute.cs deleted file mode 100644 index 7e560e3f5a21c..0000000000000 --- a/src/coreclr/nativeaot/Common/src/System/Runtime/CompilerServices/__BlockAllReflectionAttribute.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/* - Providing a definition for __BlockAllReflectionAttribute in an assembly is a signal to the .NET Native toolchain - to remove the metadata for all APIs. This both reduces size and disables all reflection on those - APIs in libraries that include this. -*/ - -using System; - -namespace System.Runtime.CompilerServices -{ - [AttributeUsage(AttributeTargets.All)] - internal class __BlockAllReflectionAttribute : Attribute { } -} diff --git a/src/coreclr/nativeaot/Common/src/System/Runtime/CompilerServices/__BlockReflectionAttribute.cs b/src/coreclr/nativeaot/Common/src/System/Runtime/CompilerServices/__BlockReflectionAttribute.cs deleted file mode 100644 index aba2c806f7171..0000000000000 --- a/src/coreclr/nativeaot/Common/src/System/Runtime/CompilerServices/__BlockReflectionAttribute.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/* - Providing a definition for __BlockReflectionAttribute in an assembly is a signal to the .NET Native toolchain - to remove the metadata for all non-public APIs. This both reduces size and disables private reflection on those - APIs in libraries that include this. -*/ - -using System; - -namespace System.Runtime.CompilerServices -{ - [AttributeUsage(AttributeTargets.All)] - internal class __BlockReflectionAttribute : Attribute { } -} diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml index 8d13e91b02fee..86675997e2cba 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml @@ -888,10 +888,6 @@ CP0001 T:System.Runtime.CompilerServices.ForceLazyDictionaryAttribute - - CP0001 - T:System.Runtime.CompilerServices.ReflectionBlockedAttribute - CP0001 T:System.Runtime.CompilerServices.StaticClassConstructionContext diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/DeveloperExperience/DeveloperExperience.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/DeveloperExperience/DeveloperExperience.cs index 8461301d8c88c..6acb98800a7da 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/DeveloperExperience/DeveloperExperience.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/DeveloperExperience/DeveloperExperience.cs @@ -16,7 +16,6 @@ namespace Internal.DeveloperExperience { - [System.Runtime.CompilerServices.ReflectionBlocked] public class DeveloperExperience { /// diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Augments/ReflectionAugments.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Augments/ReflectionAugments.cs index d9d82cac96077..41238fe70e30a 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Augments/ReflectionAugments.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Augments/ReflectionAugments.cs @@ -27,7 +27,6 @@ namespace Internal.Reflection.Augments { - [System.Runtime.CompilerServices.ReflectionBlocked] public static class ReflectionAugments { // @@ -117,7 +116,6 @@ internal static ReflectionCoreCallbacks ReflectionCoreCallbacks // This class is implemented by Internal.Reflection.Core.dll and provides the actual implementation // of Type.GetTypeInfo() and Assembly.Load(). // - [System.Runtime.CompilerServices.ReflectionBlocked] public abstract class ReflectionCoreCallbacks { public abstract Assembly Load(AssemblyName refName, bool throwOnFileNotFound); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/AssemblyBinder.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/AssemblyBinder.cs index 30383e213c941..9646731da80c2 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/AssemblyBinder.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/AssemblyBinder.cs @@ -13,7 +13,6 @@ namespace Internal.Reflection.Core { // Auto StructLayout used to suppress warning that order of fields is not guaranteed in partial structs [StructLayout(LayoutKind.Auto)] - [ReflectionBlocked] [CLSCompliant(false)] public partial struct AssemblyBindResult { @@ -28,7 +27,6 @@ public partial struct AssemblyBindResult // // If the binder cannot locate an assembly, it must return null and set "exception" to an exception object. // - [ReflectionBlocked] [CLSCompliant(false)] public abstract class AssemblyBinder { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ExecutionDomain.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ExecutionDomain.cs index 125c19249a7f5..93a129d253b81 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ExecutionDomain.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ExecutionDomain.cs @@ -25,7 +25,6 @@ namespace Internal.Reflection.Core.Execution // // This singleton class acts as an entrypoint from System.Private.Reflection.Execution to System.Private.Reflection.Core. // - [ReflectionBlocked] [CLSCompliant(false)] public sealed class ExecutionDomain { @@ -97,32 +96,23 @@ public MethodBase GetMethod(RuntimeTypeHandle declaringTypeHandle, QMethodDefini // This group of methods jointly service the Type.GetTypeFromHandle() path. The caller // is responsible for analyzing the RuntimeTypeHandle to figure out which flavor to call. //======================================================================================= - public Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle, bool isGenericTypeDefinition) + public Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle) { - QTypeDefinition qTypeDefinition; - - if (ExecutionEnvironment.TryGetMetadataForNamedType(typeHandle, out qTypeDefinition)) - { + QTypeDefinition qTypeDefinition = ExecutionEnvironment.GetMetadataForNamedType(typeHandle); #if ECMA_METADATA_SUPPORT - if (qTypeDefinition.IsNativeFormatMetadataBased) -#endif - { - return qTypeDefinition.NativeFormatHandle.GetNamedType(qTypeDefinition.NativeFormatReader, typeHandle); - } -#if ECMA_METADATA_SUPPORT - else - { - return System.Reflection.Runtime.TypeInfos.EcmaFormat.EcmaFormatRuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(qTypeDefinition.EcmaFormatReader, - qTypeDefinition.EcmaFormatHandle, - typeHandle); - } + if (qTypeDefinition.IsNativeFormatMetadataBased) #endif + { + return qTypeDefinition.NativeFormatHandle.GetNamedType(qTypeDefinition.NativeFormatReader, typeHandle); } +#if ECMA_METADATA_SUPPORT else { - Debug.Assert(ExecutionEnvironment.IsReflectionBlocked(typeHandle) || RuntimeAugments.MightBeUnconstructedType(typeHandle)); - return RuntimeBlockedTypeInfo.GetRuntimeBlockedTypeInfo(typeHandle, isGenericTypeDefinition); + return System.Reflection.Runtime.TypeInfos.EcmaFormat.EcmaFormatRuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(qTypeDefinition.EcmaFormatReader, + qTypeDefinition.EcmaFormatHandle, + typeHandle); } +#endif } public Type GetArrayTypeForHandle(RuntimeTypeHandle typeHandle) @@ -184,21 +174,6 @@ public Type GetConstructedGenericTypeForHandle(RuntimeTypeHandle typeHandle) RuntimeTypeHandle[] genericTypeArgumentHandles; genericTypeDefinitionHandle = RuntimeAugments.GetGenericInstantiation(typeHandle, out genericTypeArgumentHandles); - // Reflection blocked constructed generic types simply pretend to not be generic - // This is reasonable, as the behavior of reflection blocked types is supposed - // to be that they expose the minimal information about a type that is necessary - // for users of Object.GetType to move from that type to a type that isn't - // reflection blocked. By not revealing that reflection blocked types are generic - // we are making it appear as if implementation detail types exposed to user code - // are all non-generic, which is theoretically possible, and by doing so - // we avoid (in all known circumstances) the very complicated case of representing - // the interfaces, base types, and generic parameter types of reflection blocked - // generic type definitions. - if (ExecutionEnvironment.IsReflectionBlocked(genericTypeDefinitionHandle)) - { - return RuntimeBlockedTypeInfo.GetRuntimeBlockedTypeInfo(typeHandle, isGenericTypeDefinition: false); - } - RuntimeTypeInfo genericTypeDefinition = genericTypeDefinitionHandle.GetTypeForRuntimeTypeHandle(); int count = genericTypeArgumentHandles.Length; RuntimeTypeInfo[] genericTypeArguments = new RuntimeTypeInfo[count]; @@ -246,28 +221,6 @@ public RuntimeTypeHandle GetTypeHandleIfAvailable(Type type) return runtimeType.InternalTypeHandleIfAvailable; } - public bool SupportsReflection(Type type) - { - if (type is not RuntimeType) - return false; - - if (ExecutionEnvironment.IsReflectionBlocked(type.TypeHandle)) - { - // The type is an internal framework type and is blocked from reflection - return false; - } - - RuntimeTypeInfo runtimeType = type.CastToRuntimeTypeInfo(); - if (runtimeType.InternalFullNameOfAssembly == Internal.Runtime.Augments.RuntimeAugments.HiddenScopeAssemblyName) - { - // The type is an internal framework type but is reflectable for internal class library use - // where we make the type appear in a hidden assembly - return false; - } - - return true; - } - public static bool IsPrimitiveType(Type type) => type == typeof(bool) || type == typeof(char) || type == typeof(sbyte) || type == typeof(byte) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ExecutionEnvironment.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ExecutionEnvironment.cs index 9936ab41ca0a9..4074537712b5a 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ExecutionEnvironment.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ExecutionEnvironment.cs @@ -21,7 +21,6 @@ namespace Internal.Reflection.Core.Execution // This class abstracts the underlying Redhawk (or whatever execution engine) runtime and exposes the services // that I.R.Core.Execution needs. // - [ReflectionBlocked] [CLSCompliant(false)] public abstract class ExecutionEnvironment { @@ -47,18 +46,14 @@ public abstract class ExecutionEnvironment public abstract IEnumerable TryGetImplementedInterfaces(RuntimeTypeHandle typeHandle); public abstract void VerifyInterfaceIsImplemented(RuntimeTypeHandle typeHandle, RuntimeTypeHandle ifaceHandle); public abstract void GetInterfaceMap(Type instanceType, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Type interfaceType, out MethodInfo[] interfaceMethods, out MethodInfo[] targetMethods); - public abstract bool IsReflectionBlocked(RuntimeTypeHandle typeHandle); public abstract string GetLastResortString(RuntimeTypeHandle typeHandle); //============================================================================================== // Reflection Mapping Tables //============================================================================================== - public abstract bool TryGetMetadataForNamedType(RuntimeTypeHandle runtimeTypeHandle, out QTypeDefinition qTypeDefinition); + public abstract QTypeDefinition GetMetadataForNamedType(RuntimeTypeHandle runtimeTypeHandle); public abstract bool TryGetNamedTypeForMetadata(QTypeDefinition qTypeDefinition, out RuntimeTypeHandle runtimeTypeHandle); - public abstract bool TryGetTypeReferenceForNamedType(RuntimeTypeHandle runtimeTypeHandle, out MetadataReader metadataReader, out TypeReferenceHandle typeRefHandle); - public abstract bool TryGetNamedTypeForTypeReference(MetadataReader metadataReader, TypeReferenceHandle typeRefHandle, out RuntimeTypeHandle runtimeTypeHandle); - public abstract bool TryGetArrayTypeForElementType(RuntimeTypeHandle elementTypeHandle, out RuntimeTypeHandle arrayTypeHandle); public abstract bool TryGetArrayTypeElementType(RuntimeTypeHandle arrayTypeHandle, out RuntimeTypeHandle elementTypeHandle); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/FieldAccessor.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/FieldAccessor.cs index 43bfb3cf82e50..af157f4ee504e 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/FieldAccessor.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/FieldAccessor.cs @@ -12,7 +12,6 @@ namespace Internal.Reflection.Core.Execution // // This class abstracts the underlying Redhawk (or whatever execution engine) runtime that sets and gets fields. // - [ReflectionBlocked] [CLSCompliant(false)] public abstract class FieldAccessor { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/MethodInvoker.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/MethodInvoker.cs index fe85e9268532b..60637267cec20 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/MethodInvoker.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/MethodInvoker.cs @@ -16,7 +16,6 @@ namespace Internal.Reflection.Core.Execution // This class polymorphically implements the MethodBase.Invoke() api and its close cousins. MethodInvokers are designed to be built once and cached // for maximum Invoke() throughput. // - [ReflectionBlocked] public abstract class MethodInvoker { protected MethodInvoker() { } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ReflectionCoreExecution.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ReflectionCoreExecution.cs index 292c03692adf9..27ba66be97c59 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ReflectionCoreExecution.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ReflectionCoreExecution.cs @@ -13,7 +13,6 @@ namespace Internal.Reflection.Core.Execution { - [ReflectionBlocked] [CLSCompliant(false)] public static class ReflectionCoreExecution { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/NonPortable/RuntimeTypeUnifier.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/NonPortable/RuntimeTypeUnifier.cs index 1825d62398bf1..2f46272cd3b75 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/NonPortable/RuntimeTypeUnifier.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/NonPortable/RuntimeTypeUnifier.cs @@ -82,17 +82,13 @@ public static Type GetRuntimeTypeBypassCache(EETypePtr eeType) if (eeType.IsDefType) { - if (eeType.IsGenericTypeDefinition) - { - return callbacks.GetNamedTypeForHandle(runtimeTypeHandle, isGenericTypeDefinition: true); - } - else if (eeType.IsGeneric) + if (eeType.IsGeneric) { return callbacks.GetConstructedGenericTypeForHandle(runtimeTypeHandle); } else { - return callbacks.GetNamedTypeForHandle(runtimeTypeHandle, isGenericTypeDefinition: false); + return callbacks.GetNamedTypeForHandle(runtimeTypeHandle); } } else if (eeType.IsArray) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/ReflectionDomainSetup.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/ReflectionDomainSetup.cs index dfb955cf69139..774d2264068a0 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/ReflectionDomainSetup.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/ReflectionDomainSetup.cs @@ -8,7 +8,6 @@ namespace Internal.Reflection.Core { - [ReflectionBlocked] [CLSCompliant(false)] public abstract class ReflectionDomainSetup { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/ReflectionExecutionDomainCallbacks.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/ReflectionExecutionDomainCallbacks.cs index 91a12fec2e3e6..8cd36ec6d55ba 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/ReflectionExecutionDomainCallbacks.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/ReflectionExecutionDomainCallbacks.cs @@ -22,18 +22,15 @@ namespace Internal.Runtime.Augments { [CLSCompliant(false)] - [System.Runtime.CompilerServices.ReflectionBlocked] public abstract class ReflectionExecutionDomainCallbacks { public abstract IntPtr TryGetStaticClassConstructionContext(RuntimeTypeHandle runtimeTypeHandle); - public abstract bool IsReflectionBlocked(RuntimeTypeHandle typeHandle); - //======================================================================================= // This group of methods jointly service the Type.GetTypeFromHandle() path. The caller // is responsible for analyzing the RuntimeTypeHandle to figure out which flavor to call. //======================================================================================= - public abstract Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle, bool isGenericTypeDefinition); + public abstract Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle); public abstract Type GetArrayTypeForHandle(RuntimeTypeHandle typeHandle); public abstract Type GetMdArrayTypeForHandle(RuntimeTypeHandle typeHandle, int rank); public abstract Type GetPointerTypeForHandle(RuntimeTypeHandle typeHandle); @@ -49,7 +46,6 @@ public abstract class ReflectionExecutionDomainCallbacks public abstract Assembly GetAssemblyForHandle(RuntimeTypeHandle typeHandle); public abstract RuntimeTypeHandle GetTypeHandleIfAvailable(Type type); - public abstract bool SupportsReflection(Type type); public abstract MethodInfo GetDelegateMethod(Delegate del); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs index 74c75705619d7..6624ab722ee14 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs @@ -34,7 +34,6 @@ namespace Internal.Runtime.Augments using BinderBundle = System.Reflection.BinderBundle; using Pointer = System.Reflection.Pointer; - [ReflectionBlocked] public static class RuntimeAugments { /// @@ -445,15 +444,6 @@ public static RuntimeTypeHandle ProjectionTypeForArrays } } - // - // Returns the name of a virtual assembly we dump types private class library-Reflectable ty[es for internal class library use. - // The assembly binder visible to apps will never reveal this assembly. - // - // Note that this is not versionable as it is exposed as a const (and needs to be a const so we can used as a custom attribute argument - which - // is the other reason this string is not versionable.) - // - public const string HiddenScopeAssemblyName = "HiddenScope, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; - // // This implements the "IsAssignableFrom()" api for runtime-created types. By policy, we let the underlying runtime decide assignability. // @@ -504,9 +494,6 @@ public static IEnumerable TryGetImplementedInterfaces(Runtime { EETypePtr ifcEEType = eeType.Interfaces[i]; RuntimeTypeHandle ifcrth = new RuntimeTypeHandle(ifcEEType); - if (Callbacks.IsReflectionBlocked(ifcrth)) - continue; - implementedInterfaces.Add(ifcrth); } return implementedInterfaces.ToArray(); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/StackTraceMetadataCallbacks.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/StackTraceMetadataCallbacks.cs index 6a48e27a579b8..86fa2082186d7 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/StackTraceMetadataCallbacks.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/StackTraceMetadataCallbacks.cs @@ -14,7 +14,6 @@ namespace Internal.Runtime.Augments /// Internal.Runtime.Augments.RuntimeAugments.InitializeStackTraceMetadataSupport(StackTraceMetadataCallbacks callbacks); /// /// - [System.Runtime.CompilerServices.ReflectionBlocked] [CLSCompliant(false)] public abstract class StackTraceMetadataCallbacks { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/TypeLoaderCallbacks.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/TypeLoaderCallbacks.cs index 9a20e76b7d38b..99210e9db22c9 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/TypeLoaderCallbacks.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/TypeLoaderCallbacks.cs @@ -12,7 +12,6 @@ namespace Internal.Runtime.Augments { [CLSCompliant(false)] - [System.Runtime.CompilerServices.ReflectionBlocked] public abstract class TypeLoaderCallbacks { public abstract TypeManagerHandle GetModuleForMetadataReader(MetadataReader reader); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/FunctionPointerOps.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/FunctionPointerOps.cs index 30c62e9b436cb..eba8555712a88 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/FunctionPointerOps.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/FunctionPointerOps.cs @@ -8,7 +8,6 @@ namespace Internal.Runtime.CompilerServices { - [System.Runtime.CompilerServices.ReflectionBlocked] public static class FunctionPointerOps { #if TARGET_WASM diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/GenericMethodDescriptor.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/GenericMethodDescriptor.cs index f23d9aa8165f2..1c37c09b89307 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/GenericMethodDescriptor.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/GenericMethodDescriptor.cs @@ -5,7 +5,6 @@ namespace Internal.Runtime.CompilerServices { - [System.Runtime.CompilerServices.ReflectionBlocked] public struct GenericMethodDescriptor { public readonly IntPtr MethodFunctionPointer; diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/OpenMethodResolver.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/OpenMethodResolver.cs index b9a5b1353499f..ba71680b302e6 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/OpenMethodResolver.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/OpenMethodResolver.cs @@ -19,7 +19,6 @@ namespace Internal.Runtime.CompilerServices // so that repeated allocation of the same resolver will not leak. // 3) Use the ResolveMethod function to do the virtual lookup. This function takes advantage of // a lockless cache so the resolution is very fast for repeated lookups. - [ReflectionBlocked] public struct OpenMethodResolver : IEquatable { // Lazy initialized to point to the type loader method when the first `GVMResolve` resolver is created diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj index e400551f9a50b..4c728e839788d 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -192,7 +192,6 @@ - @@ -358,9 +357,6 @@ Internal\LowLevelLinq\LowLevelEnumerable.ToArray.cs - - System\Runtime\CompilerServices\__BlockReflectionAttribute.cs - System\Runtime\CompilerServices\DeveloperExperienceState.cs @@ -427,7 +423,6 @@ - @@ -503,7 +498,6 @@ - diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/DebugAnnotations.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/DebugAnnotations.cs index cdb6dd7e6c642..a9a11a7935d4b 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/DebugAnnotations.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/DebugAnnotations.cs @@ -6,7 +6,6 @@ namespace System.Diagnostics /// /// Annotations used by debugger /// - [System.Runtime.CompilerServices.ReflectionBlocked] public static class DebugAnnotations { /// diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/DebuggerGuidedStepThroughAttribute.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/DebuggerGuidedStepThroughAttribute.cs index 41eaf9cbd26d9..43b88ba4a687e 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/DebuggerGuidedStepThroughAttribute.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/DebuggerGuidedStepThroughAttribute.cs @@ -3,7 +3,6 @@ namespace System.Diagnostics { - [System.Runtime.CompilerServices.ReflectionBlocked] [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor, Inherited = false)] public sealed class DebuggerGuidedStepThroughAttribute : Attribute { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/AssemblyRuntimeNameHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/AssemblyRuntimeNameHelpers.cs index fc4ed2816e580..1a7023789dc1b 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/AssemblyRuntimeNameHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/AssemblyRuntimeNameHelpers.cs @@ -9,7 +9,6 @@ namespace System.Reflection { - [System.Runtime.CompilerServices.ReflectionBlocked] public static class AssemblyRuntimeNameHelpers { // diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/BinderBundle.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/BinderBundle.cs index 29ddf87589dae..e8c02b28e00b1 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/BinderBundle.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/BinderBundle.cs @@ -11,7 +11,6 @@ namespace System.Reflection // to manage.) // // This is not an api type but needs to be public as both Reflection.Core and System.Private.Corelib accesses it. - [System.Runtime.CompilerServices.ReflectionBlocked] public sealed class BinderBundle { public BinderBundle(Binder binder, CultureInfo culture) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/DynamicInvokeInfo.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/DynamicInvokeInfo.cs index 08543a3d83bfc..b1f7b76607a28 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/DynamicInvokeInfo.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/DynamicInvokeInfo.cs @@ -9,7 +9,6 @@ namespace System.Reflection { // caches information required for efficient argument validation and type coercion for reflection Invoke. - [ReflectionBlocked] public class DynamicInvokeInfo { // Public state diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/EnumInfo.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/EnumInfo.cs index b173b12ea3b20..59d2c53ae951f 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/EnumInfo.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/EnumInfo.cs @@ -13,7 +13,6 @@ namespace System.Reflection { - [ReflectionBlocked] public abstract class EnumInfo { private protected EnumInfo(Type underlyingType, string[] names, bool isFlags) @@ -28,7 +27,6 @@ private protected EnumInfo(Type underlyingType, string[] names, bool isFlags) internal bool HasFlagsAttribute { get; } } - [ReflectionBlocked] public sealed class EnumInfo : EnumInfo where TStorage : struct, INumber { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/BlockedRuntimeTypeNameGenerator.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/BlockedRuntimeTypeNameGenerator.cs deleted file mode 100644 index fd2ffc7870546..0000000000000 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/BlockedRuntimeTypeNameGenerator.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Diagnostics; -using System.Collections.Concurrent; - -namespace System.Reflection.Runtime.General -{ - // - // This class dispenses randomized strings (that serve as both the fake name and fake assembly container) for - // reflection-blocked types. - // - // The names are randomized to prevent apps from hard-wiring dependencies on them or attempting to serialize them - // across app execution. - // - internal static class BlockedRuntimeTypeNameGenerator - { - public static string GetNameForBlockedRuntimeType(RuntimeTypeHandle typeHandle) - { - string name = s_blockedNameTable.GetOrAdd(new RuntimeTypeHandleKey(typeHandle)); - return name; - } - - private sealed class BlockedRuntimeTypeNameTable : ConcurrentUnifier - { - protected sealed override string Factory(RuntimeTypeHandleKey key) - { - uint count = s_counter++; - return $"$BlockedFromReflection_{count}_{Guid.NewGuid().ToString().Substring(0, 8)}"; - } - - private static uint s_counter; - } - - private static readonly BlockedRuntimeTypeNameTable s_blockedNameTable = new BlockedRuntimeTypeNameTable(); - } -} diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs index 8d9e6cde0dbed..1ddce5f75544d 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs @@ -25,7 +25,6 @@ namespace System.Reflection.Runtime.General // // Collect various metadata reading tasks for better chunking... // - [ReflectionBlocked] [CLSCompliant(false)] public static class NativeFormatMetadataReaderExtensions { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/MetadataReaderExtensions.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/MetadataReaderExtensions.cs index 35d240d925b3e..cf1ccdbacf6db 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/MetadataReaderExtensions.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/MetadataReaderExtensions.cs @@ -14,7 +14,6 @@ namespace System.Reflection.Runtime.General { - [ReflectionBlocked] [CLSCompliant(false)] public static partial class MetadataReaderExtensions { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/QHandles.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/QHandles.cs index f8c7e014c857e..ab7a2ce9e83d8 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/QHandles.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/QHandles.cs @@ -15,7 +15,6 @@ namespace Internal.Reflection.Core { - [ReflectionBlocked] [CLSCompliant(false)] public struct QScopeDefinition : IEquatable { @@ -63,7 +62,6 @@ public override int GetHashCode() namespace System.Reflection.Runtime.General { - [ReflectionBlocked] [CLSCompliant(false)] public struct QHandle : IEquatable { @@ -101,7 +99,6 @@ public override int GetHashCode() private readonly Handle _handle; } - [ReflectionBlocked] [CLSCompliant(false)] public partial struct QMethodDefinition { @@ -127,7 +124,6 @@ public static QMethodDefinition FromObjectAndInt(object reader, int token) private readonly int _handle; } - [ReflectionBlocked] [CLSCompliant(false)] public partial struct QTypeDefinition { @@ -143,7 +139,6 @@ public partial struct QTypeDefinition } - [ReflectionBlocked] [CLSCompliant(false)] public partial struct QTypeDefRefOrSpec { @@ -158,7 +153,6 @@ public partial struct QTypeDefRefOrSpec private readonly int _handle; } - [ReflectionBlocked] [CLSCompliant(false)] public struct QGenericParameter : IEquatable { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/QSignatureTypeHandle.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/QSignatureTypeHandle.cs index c7892602a1487..c9d3430c2cffb 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/QSignatureTypeHandle.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/QSignatureTypeHandle.cs @@ -13,7 +13,6 @@ namespace System.Reflection.Runtime.General { - [ReflectionBlocked] [CLSCompliant(false)] public partial struct QSignatureTypeHandle { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeResolver.NativeFormat.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeResolver.NativeFormat.cs index 923f081a05679..67c369d67fd02 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeResolver.NativeFormat.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeResolver.NativeFormat.cs @@ -173,10 +173,6 @@ internal static RuntimeTypeInfo ResolveTypeDefinition(this TypeDefinitionHandle Justification = "Resolves type references within metadata. We ensure metadata is consistent.")] private static RuntimeTypeInfo? TryResolveTypeReference(this TypeReferenceHandle typeReferenceHandle, MetadataReader reader, ref Exception? exception) { - RuntimeTypeHandle resolvedRuntimeTypeHandle; - if (ReflectionCoreExecution.ExecutionEnvironment.TryGetNamedTypeForTypeReference(reader, typeReferenceHandle, out resolvedRuntimeTypeHandle)) - return resolvedRuntimeTypeHandle.GetTypeForRuntimeTypeHandle(); - TypeReference typeReference = typeReferenceHandle.GetTypeReference(reader); string name = typeReference.TypeName.GetString(reader); Handle parent = typeReference.ParentNamespaceOrType; diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs index 583360f98f24a..1d42c8599d964 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs @@ -156,44 +156,6 @@ public static RuntimeTypeInfo GetConstructedGenericType(this RuntimeTypeInfo gen namespace System.Reflection.Runtime.TypeInfos { - //----------------------------------------------------------------------------------------------------------- - // TypeInfos that represent type definitions (i.e. Foo or Foo<>) or constructed generic types (Foo) - // that can never be reflection-enabled due to the framework Reflection block. - //----------------------------------------------------------------------------------------------------------- - internal sealed partial class RuntimeBlockedTypeInfo - { - internal static RuntimeBlockedTypeInfo GetRuntimeBlockedTypeInfo(RuntimeTypeHandle typeHandle, bool isGenericTypeDefinition) - { - RuntimeBlockedTypeInfo type; - if (isGenericTypeDefinition) - type = GenericBlockedTypeTable.Table.GetOrAdd(new RuntimeTypeHandleKey(typeHandle)); - else - type = BlockedTypeTable.Table.GetOrAdd(new RuntimeTypeHandleKey(typeHandle)); - type.EstablishDebugName(); - return type; - } - - private sealed class BlockedTypeTable : ConcurrentUnifierW - { - protected sealed override RuntimeBlockedTypeInfo Factory(RuntimeTypeHandleKey key) - { - return new RuntimeBlockedTypeInfo(key.TypeHandle, isGenericTypeDefinition: false); - } - - public static readonly BlockedTypeTable Table = new BlockedTypeTable(); - } - - private sealed class GenericBlockedTypeTable : ConcurrentUnifierW - { - protected sealed override RuntimeBlockedTypeInfo Factory(RuntimeTypeHandleKey key) - { - return new RuntimeBlockedTypeInfo(key.TypeHandle, isGenericTypeDefinition: true); - } - - public static readonly GenericBlockedTypeTable Table = new GenericBlockedTypeTable(); - } - } - //----------------------------------------------------------------------------------------------------------- // TypeInfos for Sz and multi-dim Array types. //----------------------------------------------------------------------------------------------------------- @@ -478,9 +440,6 @@ private static RuntimeTypeHandle GetRuntimeTypeHandleIfAny(RuntimeTypeInfo gener if (genericTypeDefinitionHandle.IsNull()) return default(RuntimeTypeHandle); - if (ReflectionCoreExecution.ExecutionEnvironment.IsReflectionBlocked(genericTypeDefinitionHandle)) - return default(RuntimeTypeHandle); - int count = genericTypeArguments.Length; RuntimeTypeHandle[] genericTypeArgumentHandles = new RuntimeTypeHandle[count]; for (int i = 0; i < count; i++) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeBlockedTypeInfo.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeBlockedTypeInfo.cs deleted file mode 100644 index c086c1109e3db..0000000000000 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeBlockedTypeInfo.cs +++ /dev/null @@ -1,251 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Reflection; -using System.Diagnostics; -using System.Collections.Generic; -using System.Reflection.Runtime.General; -using System.Reflection.Runtime.TypeInfos; -using System.Reflection.Runtime.Assemblies; -using System.Reflection.Runtime.CustomAttributes; - -using Internal.LowLevelLinq; -using Internal.Reflection.Core.Execution; - -using CharSet = System.Runtime.InteropServices.CharSet; -using LayoutKind = System.Runtime.InteropServices.LayoutKind; -using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute; - -namespace System.Reflection.Runtime.TypeInfos -{ - // - // TypeInfos that represent type definitions (i.e. Foo or Foo<>) or constructed generic types (Foo) - // that can never be reflection-enabled due to the framework Reflection block. - // - // These types differ from NoMetadata TypeInfos in that properties that inquire about members, - // custom attributes or interfaces return an empty list rather than throwing a missing metadata exception. - // - // Since these represent "internal framework types", the app cannot prove we are lying. - // - internal sealed partial class RuntimeBlockedTypeInfo : RuntimeTypeDefinitionTypeInfo - { - private RuntimeBlockedTypeInfo(RuntimeTypeHandle typeHandle, bool isGenericTypeDefinition) - { - _typeHandle = typeHandle; - _isGenericTypeDefinition = isGenericTypeDefinition; - } - - public sealed override Assembly Assembly - { - get - { - return typeof(object).Assembly; - } - } - - public sealed override bool ContainsGenericParameters - { - get - { - return _isGenericTypeDefinition; - } - } - - public sealed override IEnumerable CustomAttributes - { - get - { - return Array.Empty(); - } - } - - public sealed override bool IsByRefLike - { - get - { - return Internal.Runtime.Augments.RuntimeAugments.IsByRefLike(_typeHandle); - } - } - - public sealed override string FullName - { - get - { - return GeneratedName; - } - } - - public sealed override Guid GUID - { - get - { - throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(this); - } - } - -#if DEBUG - public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other) => base.HasSameMetadataDefinitionAs(other); -#endif - - public sealed override bool IsGenericTypeDefinition - { - get - { - return _isGenericTypeDefinition; - } - } - - public sealed override string Namespace - { - get - { - return null; // Reflection-blocked framework types report themselves as existing in the "root" namespace. - } - } - - public sealed override StructLayoutAttribute StructLayoutAttribute - { - get - { - return new StructLayoutAttribute(LayoutKind.Auto) - { - CharSet = CharSet.Ansi, - Pack = 8, - Size = 0, - }; - } - } - - public sealed override string ToString() - { - return _typeHandle.LastResortString(); - } - - public sealed override int MetadataToken - { - get - { - throw new InvalidOperationException(SR.NoMetadataTokenAvailable); - } - } - - protected sealed override TypeAttributes GetAttributeFlagsImpl() - { - return TypeAttributes.Class | TypeAttributes.NotPublic; - } - - protected sealed override int InternalGetHashCode() - { - return _typeHandle.GetHashCode(); - } - - // - // Returns the anchoring typedef that declares the members that this type wants returned by the Declared*** properties. - // The Declared*** properties will project the anchoring typedef's members by overriding their DeclaringType property with "this" - // and substituting the value of this.TypeContext into any generic parameters. - // - // Default implementation returns null which causes the Declared*** properties to return no members. - // - // Note that this does not apply to DeclaredNestedTypes. Nested types and their containers have completely separate generic instantiation environments - // (despite what C# might lead you to think.) Constructed generic types return the exact same same nested types that its generic type definition does - // - i.e. their DeclaringTypes refer back to the generic type definition, not the constructed generic type.) - // - // Note also that we cannot use this anchoring concept for base types because of generic parameters. Generic parameters return - // baseclass and interfaces based on its constraints. - // - internal sealed override RuntimeNamedTypeInfo AnchoringTypeDefinitionForDeclaredMembers - { - get - { - return null; // this causes the type to report having no members. - } - } - - internal sealed override RuntimeTypeInfo[] RuntimeGenericTypeParameters - { - get - { - throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(this); - } - } - - internal sealed override Type InternalDeclaringType - { - get - { - return null; - } - } - - public sealed override string Name - { - get - { - return GeneratedName; - } - } - - internal sealed override string InternalFullNameOfAssembly - { - get - { - return GeneratedName; - } - } - - internal sealed override RuntimeTypeHandle InternalTypeHandleIfAvailable - { - get - { - return _typeHandle; - } - } - - // - // Returns the base type as a typeDef, Ref, or Spec. Default behavior is to QTypeDefRefOrSpec.Null, which causes BaseType to return null. - // - internal sealed override QTypeDefRefOrSpec TypeRefDefOrSpecForBaseType - { - get - { - throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(this); - } - } - - // - // Returns the *directly implemented* interfaces as typedefs, specs or refs. ImplementedInterfaces will take care of the transitive closure and - // insertion of the TypeContext. - // - internal sealed override QTypeDefRefOrSpec[] TypeRefDefOrSpecsForDirectlyImplementedInterfaces - { - get - { - throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(this); - } - } - - // - // Returns the generic parameter substitutions to use when enumerating declared members, base class and implemented interfaces. - // - internal sealed override TypeContext TypeContext - { - get - { - throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(this); - } - } - - private string GeneratedName - { - get - { - return _lazyGeneratedName ??= BlockedRuntimeTypeNameGenerator.GetNameForBlockedRuntimeType(_typeHandle); - } - } - - private readonly RuntimeTypeHandle _typeHandle; - private readonly bool _isGenericTypeDefinition; - private volatile string _lazyGeneratedName; - } -} diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeConstructedGenericTypeInfo.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeConstructedGenericTypeInfo.cs index aece6012b1dc7..ca54f0e244538 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeConstructedGenericTypeInfo.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeConstructedGenericTypeInfo.cs @@ -224,9 +224,6 @@ internal sealed override Type InternalDeclaringType { get { - RuntimeTypeHandle typeHandle = InternalTypeHandleIfAvailable; - if ((!typeHandle.IsNull()) && ReflectionCoreExecution.ExecutionEnvironment.IsReflectionBlocked(typeHandle)) - return null; return GenericTypeDefinitionTypeInfo.InternalDeclaringType; } } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.CoreGetDeclared.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.CoreGetDeclared.cs index 9ef282eae5bcd..3dcbe559c0e2b 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.CoreGetDeclared.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.CoreGetDeclared.cs @@ -139,12 +139,4 @@ internal sealed override IEnumerable CoreGetDeclaredNestedTypes(NameFilter return GenericTypeDefinitionTypeInfo.CoreGetDeclaredNestedTypes(optionalNameFilter); } } - - internal sealed partial class RuntimeBlockedTypeInfo - { - internal sealed override IEnumerable CoreGetDeclaredNestedTypes(NameFilter optionalNameFilter) - { - return Array.Empty(); - } - } } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/ReflectionBlockedAttribute.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/ReflectionBlockedAttribute.cs deleted file mode 100644 index 3b6c28e21f540..0000000000000 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/ReflectionBlockedAttribute.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace System.Runtime.CompilerServices -{ - // When applied to a type this custom attribute cause the type to be treated as reflection blocked. - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] - public class ReflectionBlockedAttribute : Attribute - { - } -} diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/InteropExtensions.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/InteropExtensions.cs index e263397237a6a..cd397aca57f99 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/InteropExtensions.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/InteropExtensions.cs @@ -19,7 +19,6 @@ namespace System.Runtime.InteropServices /// in order to be accessible from System.Private.Interop.dll. /// [CLSCompliant(false)] - [ReflectionBlocked] public static class InteropExtensions { internal static bool MightBeBlittable(this EETypePtr eeType) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs index f3b4cca51b052..8ed0fef3f6480 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -21,7 +21,6 @@ namespace System.Runtime // E.g., the class and methods are marked internal assuming that only the base class library needs them // but if a class library wants to factor differently (such as putting the GCHandle methods in an // optional library, those methods can be moved to a different file/namespace/dll - [ReflectionBlocked] public static partial class RuntimeImports { private const string RuntimeLibrary = "*"; diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/TypeLoaderExports.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/TypeLoaderExports.cs index 6d71f0d880d0a..0c15531e2081e 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/TypeLoaderExports.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/TypeLoaderExports.cs @@ -10,7 +10,6 @@ namespace System.Runtime { - [ReflectionBlocked] public static class TypeLoaderExports { public static unsafe void ActivatorCreateInstanceAny(ref object ptrToData, IntPtr pEETypePtr) @@ -318,7 +317,6 @@ private static Entry[] ResizeCacheForNewEntryAsNecessary() } } - [ReflectionBlocked] public delegate IntPtr RuntimeObjectFactory(IntPtr context, IntPtr signature, object contextObject, ref IntPtr auxResult); internal static unsafe class RawCalliHelper diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs index 97ced6c5e361c..717cf44678847 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs @@ -24,7 +24,6 @@ internal static void Initialize() } } - [ReflectionBlocked] public class RuntimeExceptionHelpers { //------------------------------------------------------------------------------------------------------------ diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Condition.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Condition.cs index 5ec71cffc0e68..a567debf03708 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Condition.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Condition.cs @@ -8,7 +8,6 @@ namespace System.Threading { - [System.Runtime.CompilerServices.ReflectionBlocked] public sealed class Condition { internal class Waiter diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Lock.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Lock.cs index 706189829b85f..f38fc0f7c4405 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Lock.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Lock.cs @@ -8,7 +8,6 @@ namespace System.Threading { - [ReflectionBlocked] public sealed class Lock : IDisposable { // diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/LockHolder.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/LockHolder.cs index 1c459d6ebd1af..784a5d0fe3555 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/LockHolder.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/LockHolder.cs @@ -5,7 +5,6 @@ namespace System.Threading { - [ReflectionBlocked] public struct LockHolder : IDisposable { private Lock _lock; diff --git a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/ReflectionExecutionDomainCallbacksImplementation.cs b/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/ReflectionExecutionDomainCallbacksImplementation.cs index b859c6c0987fe..5aa1c6a27f6d6 100644 --- a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/ReflectionExecutionDomainCallbacksImplementation.cs +++ b/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/ReflectionExecutionDomainCallbacksImplementation.cs @@ -20,12 +20,10 @@ internal class ReflectionExecutionDomainCallbacksImplementation : ReflectionExec public override Exception GetExceptionForHR(int hr) => throw new NotImplementedException(); public override Type GetMdArrayTypeForHandle(RuntimeTypeHandle typeHandle, int rank) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle); public override MethodBase GetMethodBaseFromStartAddressIfAvailable(IntPtr methodStartAddress) => null; - public override Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle, bool isGenericTypeDefinition) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle); + public override Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle); public override Type GetPointerTypeForHandle(RuntimeTypeHandle typeHandle) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle); public override Type GetFunctionPointerTypeForHandle(RuntimeTypeHandle typeHandle) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle); public override RuntimeTypeHandle GetTypeHandleIfAvailable(Type type) => type.TypeHandle; - public override bool IsReflectionBlocked(RuntimeTypeHandle typeHandle) => false; - public override bool SupportsReflection(Type type) => false; public override IntPtr TryGetStaticClassConstructionContext(RuntimeTypeHandle runtimeTypeHandle) => throw new NotSupportedException(SR.Reflection_Disabled); } } diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs index 47b08a12daabd..6cf6f57de8c96 100644 --- a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs +++ b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs @@ -100,52 +100,15 @@ private static unsafe bool TryGetNativeReaderForBlob(NativeFormatModuleInfo modu /// runtimeTypeHandle is a typedef (not a constructed type such as an array or generic instance.) /// /// Runtime handle of the type in question - /// TypeDef handle for the type - public sealed override unsafe bool TryGetMetadataForNamedType(RuntimeTypeHandle runtimeTypeHandle, out QTypeDefinition qTypeDefinition) + public sealed override QTypeDefinition GetMetadataForNamedType(RuntimeTypeHandle runtimeTypeHandle) { Debug.Assert(!RuntimeAugments.IsGenericType(runtimeTypeHandle)); - return TypeLoaderEnvironment.Instance.TryGetMetadataForNamedType(runtimeTypeHandle, out qTypeDefinition); - } - - // - // Return true for a TypeDef if the policy has decided this type is blocked from reflection. - // - // Preconditions: - // runtimeTypeHandle is a typedef or a generic type instance (not a constructed type such as an array) - // - public sealed override unsafe bool IsReflectionBlocked(RuntimeTypeHandle runtimeTypeHandle) - { - // For generic types, use the generic type definition - runtimeTypeHandle = GetTypeDefinition(runtimeTypeHandle); - var moduleHandle = RuntimeAugments.GetModuleFromTypeHandle(runtimeTypeHandle); - - //make sure the module is actually NativeFormatModuleInfo, if the module - //doesnt have reflection enabled it wont be a NativeFormatModuleInfo - if (!(ModuleList.Instance.TryGetModuleInfoByHandle(moduleHandle, out ModuleInfo untypedModuleInfo) && (untypedModuleInfo is NativeFormatModuleInfo module))) - { - return true; - } - - NativeReader blockedReflectionReader = GetNativeReaderForBlob(module, ReflectionMapBlob.BlockReflectionTypeMap); - NativeParser blockedReflectionParser = new NativeParser(blockedReflectionReader, 0); - NativeHashtable blockedReflectionHashtable = new NativeHashtable(blockedReflectionParser); - ExternalReferencesTable externalReferences = default(ExternalReferencesTable); - externalReferences.InitializeCommonFixupsTable(module); - - int hashcode = runtimeTypeHandle.GetHashCode(); - var lookup = blockedReflectionHashtable.Lookup(hashcode); - NativeParser entryParser; - while (!(entryParser = lookup.GetNext()).IsNull) + if (!TypeLoaderEnvironment.Instance.TryGetMetadataForNamedType(runtimeTypeHandle, out QTypeDefinition qTypeDefinition)) { - RuntimeTypeHandle entryType = externalReferences.GetRuntimeTypeHandleFromIndex(entryParser.GetUnsigned()); - if (!entryType.Equals(runtimeTypeHandle)) - continue; - - // Entry found, must be blocked - return true; + // This should be unreachable unless there's a compiler bug + throw new InvalidOperationException(); } - // Entry not found, must not be blocked - return false; + return qTypeDefinition; } /// @@ -166,46 +129,6 @@ public sealed override unsafe bool TryGetNamedTypeForMetadata(QTypeDefinition qT return TypeLoaderEnvironment.Instance.TryGetNamedTypeForMetadata(qTypeDefinition, out runtimeTypeHandle); } - /// - /// Return the metadata handle for a TypeRef if this type was referenced indirectly by other type that pay-for-play has denoted as browsable - /// (for example, as part of a method signature.) - /// - /// This is only used in "debug" builds to provide better missing metadata diagnostics. - /// - /// Preconditions: - /// runtimeTypeHandle is a typedef (not a constructed type such as an array or generic instance.) - /// - /// MethodTable of the type in question - /// Metadata reader for the type - /// Located TypeRef handle - public sealed override unsafe bool TryGetTypeReferenceForNamedType(RuntimeTypeHandle runtimeTypeHandle, out MetadataReader metadataReader, out TypeReferenceHandle typeRefHandle) - { - return TypeLoaderEnvironment.TryGetTypeReferenceForNamedType(runtimeTypeHandle, out metadataReader, out typeRefHandle); - } - - /// - /// Return the RuntimeTypeHandle for the named type referenced by another type that pay-for-play denotes as browsable (for example, - /// in a member signature.) Typically, the type itself is *not* browsable (or it would have appeared in the TypeDef table.) - /// - /// This is used to ensure that we can produce a Type object if requested and that it match up with the analogous - /// Type obtained via typeof(). - /// - /// - /// Preconditions: - /// metadataReader + typeRefHandle - a valid metadata reader + typeReferenceHandle where "metadataReader" is one - /// of the metadata readers returned by ExecutionEnvironment.MetadataReaders. - /// - /// Note: Although this method has a "bool" return value like the other mapping table accessors, the pay-for-play design - /// guarantees that any type that has a metadata TypeReference to it also has a RuntimeTypeHandle underneath. - /// - /// Metadata reader for module containing the type reference - /// TypeRef handle to look up - /// Resolved MethodTable for the type reference - public sealed override unsafe bool TryGetNamedTypeForTypeReference(MetadataReader metadataReader, TypeReferenceHandle typeRefHandle, out RuntimeTypeHandle runtimeTypeHandle) - { - return TypeLoaderEnvironment.TryGetNamedTypeForTypeReference(metadataReader, typeRefHandle, out runtimeTypeHandle); - } - // // Given a RuntimeTypeHandle for any type E, return a RuntimeTypeHandle for type E[], if the pay for play policy denotes E[] as browsable. This is used to // implement Array.CreateInstance(). @@ -928,11 +851,7 @@ private unsafe bool TryGetMethodForOriginalLdFtnResult_InvokeMap_Inner(NativeFor if ((entryFlags & InvokeTableFlags.HasMetadataHandle) != 0) { RuntimeTypeHandle declaringTypeHandleDefinition = GetTypeDefinition(declaringTypeHandle); - QTypeDefinition qTypeDefinition; - if (!TryGetMetadataForNamedType(declaringTypeHandleDefinition, out qTypeDefinition)) - { - RuntimeExceptionHelpers.FailFast("Unable to resolve named type to having a metadata reader"); - } + QTypeDefinition qTypeDefinition = GetMetadataForNamedType(declaringTypeHandleDefinition); MethodHandle nativeFormatMethodHandle = (((int)HandleType.Method << 24) | (int)entryMethodHandleOrNameAndSigRaw).AsMethodHandle(); @@ -1097,11 +1016,9 @@ public sealed override unsafe bool TryGetFieldFromHandle(RuntimeFieldHandle runt if (!TypeLoaderEnvironment.Instance.TryGetRuntimeFieldHandleComponents(runtimeFieldHandle, out declaringTypeHandle, out fieldName)) return false; - QTypeDefinition qTypeDefinition; RuntimeTypeHandle metadataLookupTypeHandle = GetTypeDefinition(declaringTypeHandle); - if (!TryGetMetadataForNamedType(metadataLookupTypeHandle, out qTypeDefinition)) - return false; + QTypeDefinition qTypeDefinition = GetMetadataForNamedType(metadataLookupTypeHandle); // TODO! Handle ecma style types MetadataReader reader = qTypeDefinition.NativeFormatReader; diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.Runtime.cs b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.Runtime.cs index c47e5f72a1504..d4412719e0d4f 100644 --- a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.Runtime.cs +++ b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.Runtime.cs @@ -138,20 +138,7 @@ public sealed override void GetEnumInfo(RuntimeTypeHandle typeHandle, out string typeDefHandle = RuntimeAugments.GetGenericDefinition(typeHandle); } - // If the type is reflection blocked, we pretend there are no enum values defined - if (ReflectionExecution.ExecutionEnvironment.IsReflectionBlocked(typeDefHandle)) - { - names = Array.Empty(); - values = Array.Empty(); - isFlags = false; - return; - } - - QTypeDefinition qTypeDefinition; - if (!ReflectionExecution.ExecutionEnvironment.TryGetMetadataForNamedType(typeDefHandle, out qTypeDefinition)) - { - throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(Type.GetTypeFromHandle(typeDefHandle)); - } + QTypeDefinition qTypeDefinition = ReflectionExecution.ExecutionEnvironment.GetMetadataForNamedType(typeDefHandle); if (qTypeDefinition.IsNativeFormatMetadataBased) { diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/PayForPlayExperience/DiagnosticMappingTables.cs b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/PayForPlayExperience/DiagnosticMappingTables.cs deleted file mode 100644 index d49f576080a42..0000000000000 --- a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/PayForPlayExperience/DiagnosticMappingTables.cs +++ /dev/null @@ -1,121 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using global::System; -using global::System.Text; -using global::System.Collections.Generic; - -using global::Internal.Metadata.NativeFormat; - -using global::Internal.Runtime.Augments; - -using System.Reflection.Runtime.General; - -namespace Internal.Reflection.Execution.PayForPlayExperience -{ - internal static partial class DiagnosticMappingTables - { - // Get the diagnostic name string for a type. - // Returns true if the function is successful. - // runtimeTypeHandle represents the type to get a name for - // diagnosticName is the name that is returned - public static bool TryGetDiagnosticStringForNamedType(RuntimeTypeHandle runtimeTypeHandle, out string diagnosticName) - { - diagnosticName = null; - ExecutionEnvironmentImplementation executionEnvironment = ReflectionExecution.ExecutionEnvironment; - - MetadataReader reader; - TypeReferenceHandle typeReferenceHandle; - if (executionEnvironment.TryGetTypeReferenceForNamedType(runtimeTypeHandle, out reader, out typeReferenceHandle)) - { - diagnosticName = GetTypeFullNameFromTypeRef(typeReferenceHandle, reader); - return true; - } - - QTypeDefinition qTypeDefinition; - if (executionEnvironment.TryGetMetadataForNamedType(runtimeTypeHandle, out qTypeDefinition)) - { - TryGetFullNameFromTypeDefEcma(qTypeDefinition, ref diagnosticName); - if (diagnosticName != null) - return true; - - if (qTypeDefinition.IsNativeFormatMetadataBased) - { - TypeDefinitionHandle typeDefinitionHandle = qTypeDefinition.NativeFormatHandle; - diagnosticName = GetTypeFullNameFromTypeDef(typeDefinitionHandle, qTypeDefinition.NativeFormatReader); - return true; - } - } - return false; - } - - static partial void TryGetFullNameFromTypeDefEcma(QTypeDefinition qTypeDefinition, ref string result); - - private static string GetTypeFullNameFromTypeRef(TypeReferenceHandle typeReferenceHandle, MetadataReader reader) - { - TypeReference typeReference = typeReferenceHandle.GetTypeReference(reader); - string s = typeReference.TypeName.GetString(reader); - Handle parentHandle = typeReference.ParentNamespaceOrType; - HandleType parentHandleType = parentHandle.HandleType; - if (parentHandleType == HandleType.TypeReference) - { - string containingTypeName = GetTypeFullNameFromTypeRef(parentHandle.ToTypeReferenceHandle(reader), reader); - s = containingTypeName + "+" + s; - } - else if (parentHandleType == HandleType.NamespaceReference) - { - NamespaceReferenceHandle namespaceReferenceHandle = parentHandle.ToNamespaceReferenceHandle(reader); - for (;;) - { - NamespaceReference namespaceReference = namespaceReferenceHandle.GetNamespaceReference(reader); - string namespacePart = namespaceReference.Name.GetStringOrNull(reader); - if (namespacePart == null) - break; // Reached the root namespace. - s = namespacePart + "." + s; - if (namespaceReference.ParentScopeOrNamespace.HandleType != HandleType.NamespaceReference) - break; // Should have reached the root namespace first but this helper is for ToString() - better to - // return partial information than crash. - namespaceReferenceHandle = namespaceReference.ParentScopeOrNamespace.ToNamespaceReferenceHandle(reader); - } - } - else - { - // If we got here, the metadata is illegal but this helper is for ToString() - better to - // return something partial than throw. - } - return s; - } - - private static string GetTypeFullNameFromTypeDef(TypeDefinitionHandle typeDefinitionHandle, MetadataReader reader) - { - string s; - - TypeDefinition typeDefinition = typeDefinitionHandle.GetTypeDefinition(reader); - s = typeDefinition.Name.GetString(reader); - - TypeDefinitionHandle enclosingTypeDefHandle = typeDefinition.EnclosingType; - if (!enclosingTypeDefHandle.IsNull(reader)) - { - string containingTypeName = GetTypeFullNameFromTypeDef(enclosingTypeDefHandle, reader); - s = containingTypeName + "+" + s; - } - else - { - NamespaceDefinitionHandle namespaceHandle = typeDefinition.NamespaceDefinition; - for (;;) - { - NamespaceDefinition namespaceDefinition = namespaceHandle.GetNamespaceDefinition(reader); - string namespacePart = namespaceDefinition.Name.GetStringOrNull(reader); - if (namespacePart == null) - break; // Reached the root namespace. - s = namespacePart + "." + s; - if (namespaceDefinition.ParentScopeOrNamespace.HandleType != HandleType.NamespaceDefinition) - break; // Should have reached the root namespace first but this helper is for ToString() - better to - // return partial information than crash. - namespaceHandle = namespaceDefinition.ParentScopeOrNamespace.ToNamespaceDefinitionHandle(reader); - } - } - return s; - } - } -} diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/PayForPlayExperience/MissingMetadataExceptionCreator.cs b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/PayForPlayExperience/MissingMetadataExceptionCreator.cs index 54c485cd4b339..1234383b6d943 100644 --- a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/PayForPlayExperience/MissingMetadataExceptionCreator.cs +++ b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/PayForPlayExperience/MissingMetadataExceptionCreator.cs @@ -149,14 +149,6 @@ internal static string ToDisplayStringIfAvailable(this Type type) { return type.Name; } - else if (hasRuntimeTypeHandle) - { - string s; - if (!DiagnosticMappingTables.TryGetDiagnosticStringForNamedType(runtimeTypeHandle, out s)) - return null; - - return s; - } else { return type.FullName; diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ReflectionExecution.cs b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ReflectionExecution.cs index cc3b1d8d59549..2d48cf5faebb7 100644 --- a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ReflectionExecution.cs +++ b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ReflectionExecution.cs @@ -77,8 +77,7 @@ public static bool TryGetMethodMetadataFromStartAddress(IntPtr methodStartAddres if (!qMethodDefinition.IsNativeFormatMetadataBased) return false; - if (!ExecutionEnvironment.TryGetMetadataForNamedType(declaringTypeHandle, out QTypeDefinition qTypeDefinition)) - return false; + QTypeDefinition qTypeDefinition = ExecutionEnvironment.GetMetadataForNamedType(declaringTypeHandle); Debug.Assert(qTypeDefinition.IsNativeFormatMetadataBased); Debug.Assert(qTypeDefinition.NativeFormatReader == qMethodDefinition.NativeFormatReader); diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ReflectionExecutionDomainCallbacksImplementation.cs b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ReflectionExecutionDomainCallbacksImplementation.cs index f3f7ee9962784..537ee115ef43c 100644 --- a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ReflectionExecutionDomainCallbacksImplementation.cs +++ b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ReflectionExecutionDomainCallbacksImplementation.cs @@ -31,18 +31,13 @@ public ReflectionExecutionDomainCallbacksImplementation(ExecutionDomain executio _executionEnvironment = executionEnvironment; } - public sealed override bool IsReflectionBlocked(RuntimeTypeHandle typeHandle) - { - return _executionEnvironment.IsReflectionBlocked(typeHandle); - } - //======================================================================================= // This group of methods jointly service the Type.GetTypeFromHandle() path. The caller // is responsible for analyzing the RuntimeTypeHandle to figure out which flavor to call. //======================================================================================= - public sealed override Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle, bool isGenericTypeDefinition) + public sealed override Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle) { - return _executionDomain.GetNamedTypeForHandle(typeHandle, isGenericTypeDefinition); + return _executionDomain.GetNamedTypeForHandle(typeHandle); } public sealed override Type GetArrayTypeForHandle(RuntimeTypeHandle typeHandle) @@ -119,11 +114,6 @@ public sealed override RuntimeTypeHandle GetTypeHandleIfAvailable(Type type) return _executionDomain.GetTypeHandleIfAvailable(type); } - public sealed override bool SupportsReflection(Type type) - { - return _executionDomain.SupportsReflection(type); - } - public sealed override MethodInfo GetDelegateMethod(Delegate del) { return DelegateMethodInfoRetriever.GetDelegateMethodInfo(del); diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/System.Private.Reflection.Execution.csproj b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/System.Private.Reflection.Execution.csproj index 81302d18af9de..76d3934794fd2 100644 --- a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/System.Private.Reflection.Execution.csproj +++ b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/System.Private.Reflection.Execution.csproj @@ -47,39 +47,35 @@ - - + Internal\Runtime\MetadataBlob.cs - + System\NotImplemented.cs - + System\Collections\Generic\LowLevelList.cs - + System\Collections\Generic\LowLevelDictionary.cs - + Internal\LowLevelLinq\LowLevelEnumerable.cs - + Internal\LowLevelLinq\LowLevelEnumerable.ToArray.cs - + System\Collections\HashHelpers.cs - + System\Collections\Generic\Empty.cs - - System\Runtime\CompilerServices\__BlockAllReflectionAttribute.cs - diff --git a/src/coreclr/nativeaot/System.Private.StackTraceMetadata/src/System.Private.StackTraceMetadata.csproj b/src/coreclr/nativeaot/System.Private.StackTraceMetadata/src/System.Private.StackTraceMetadata.csproj index 87b0de7f2205f..f88e4914774a5 100644 --- a/src/coreclr/nativeaot/System.Private.StackTraceMetadata/src/System.Private.StackTraceMetadata.csproj +++ b/src/coreclr/nativeaot/System.Private.StackTraceMetadata/src/System.Private.StackTraceMetadata.csproj @@ -21,8 +21,5 @@ Internal\Runtime\MetadataBlob.cs - - System\Runtime\CompilerServices\__BlockAllReflectionAttribute.cs - diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/LowLevelStringConverter.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/LowLevelStringConverter.cs index ce7111657e862..af2e73493e13d 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/LowLevelStringConverter.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/LowLevelStringConverter.cs @@ -116,7 +116,6 @@ public static string LowLevelToString(this IntPtr arg) public static string LowLevelToString(this RuntimeTypeHandle rtth) { - TypeReferenceHandle typeRefHandle; QTypeDefinition qTypeDefinition; MetadataReader reader; @@ -128,12 +127,6 @@ public static string LowLevelToString(this RuntimeTypeHandle rtth) return typeDefHandle.GetFullName(reader); } - // Try to get the name from diagnostic metadata - if (TypeLoaderEnvironment.TryGetTypeReferenceForNamedType(rtth, out reader, out typeRefHandle)) - { - return typeRefHandle.GetFullName(reader); - } - // Fallback implementation when no metadata available return LowLevelToStringRawEETypeAddress(rtth); } diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/MetadataReaderHelpers.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/MetadataReaderHelpers.cs deleted file mode 100644 index 2d8cea0fa5613..0000000000000 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/MetadataReaderHelpers.cs +++ /dev/null @@ -1,167 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - - -using global::System; -using global::System.Reflection; -using global::Internal.Metadata.NativeFormat; - -using Debug = System.Diagnostics.Debug; -using AssemblyFlags = Internal.Metadata.NativeFormat.AssemblyFlags; - -namespace Internal.Runtime.TypeLoader -{ - public static class MetadataReaderHelpers - { - public static bool CompareTypeReferenceAcrossModules(TypeReferenceHandle tr1, MetadataReader mr1, TypeReferenceHandle tr2, MetadataReader mr2) - { - TypeReference trData1 = mr1.GetTypeReference(tr1); - TypeReference trData2 = mr2.GetTypeReference(tr2); - if (!trData1.TypeName.StringEquals(trData2.TypeName.GetConstantStringValue(mr2).Value, mr1)) - return false; - - if (trData1.ParentNamespaceOrType.HandleType != trData2.ParentNamespaceOrType.HandleType) - return false; - - if (trData1.ParentNamespaceOrType.HandleType == HandleType.TypeReference) - return CompareTypeReferenceAcrossModules(trData1.ParentNamespaceOrType.ToTypeReferenceHandle(mr1), mr1, trData2.ParentNamespaceOrType.ToTypeReferenceHandle(mr2), mr2); - - return CompareNamespaceReferenceAcrossModules(trData1.ParentNamespaceOrType.ToNamespaceReferenceHandle(mr1), mr1, trData2.ParentNamespaceOrType.ToNamespaceReferenceHandle(mr2), mr2); - } - - public static bool CompareNamespaceReferenceAcrossModules(NamespaceReferenceHandle nr1, MetadataReader mr1, NamespaceReferenceHandle nr2, MetadataReader mr2) - { - NamespaceReference nrData1 = mr1.GetNamespaceReference(nr1); - NamespaceReference nrData2 = mr2.GetNamespaceReference(nr2); - - if (nrData1.Name.IsNull(mr1) != nrData2.Name.IsNull(mr2)) - return false; - - if (!nrData1.Name.IsNull(mr1)) - { - if (!nrData1.Name.StringEquals(nrData2.Name.GetConstantStringValue(mr2).Value, mr1)) - return false; - } - - if (nrData1.ParentScopeOrNamespace.HandleType != nrData1.ParentScopeOrNamespace.HandleType) - return false; - - if (nrData1.ParentScopeOrNamespace.HandleType == HandleType.NamespaceReference) - return CompareNamespaceReferenceAcrossModules(nrData1.ParentScopeOrNamespace.ToNamespaceReferenceHandle(mr1), mr1, nrData2.ParentScopeOrNamespace.ToNamespaceReferenceHandle(mr2), mr2); - - return CompareScopeReferenceAcrossModules(nrData1.ParentScopeOrNamespace.ToScopeReferenceHandle(mr1), mr1, nrData2.ParentScopeOrNamespace.ToScopeReferenceHandle(mr2), mr2); - } - - public static bool CompareScopeReferenceAcrossModules(ScopeReferenceHandle sr1, MetadataReader mr1, ScopeReferenceHandle sr2, MetadataReader mr2) - { - ScopeReference srData1 = mr1.GetScopeReference(sr1); - ScopeReference srData2 = mr2.GetScopeReference(sr2); - if (!srData1.Name.StringEquals(srData2.Name.GetConstantStringValue(mr2).Value, mr1)) - return false; - - if (!srData1.Culture.StringEquals(srData2.Culture.GetConstantStringValue(mr2).Value, mr1)) - return false; - - if (srData1.MajorVersion != srData2.MajorVersion) - return false; - - if (srData1.MinorVersion != srData2.MinorVersion) - return false; - - if (srData1.RevisionNumber != srData2.RevisionNumber) - return false; - - if (srData1.BuildNumber != srData2.BuildNumber) - return false; - - return true; - } - - public static bool CompareTypeReferenceToDefinition(TypeReferenceHandle tr1, MetadataReader mr1, TypeDefinitionHandle td2, MetadataReader mr2) - { - // TODO! The correct implementation here is probably to call into the assembly binder, but that's not available due to layering. - // For now, just implement comparison, which will be equivalent in all cases until we support loading multiple copies of the same assembly - - TypeReference trData1 = mr1.GetTypeReference(tr1); - TypeDefinition tdData2 = mr2.GetTypeDefinition(td2); - - if (!trData1.TypeName.StringEquals(tdData2.Name.GetConstantStringValue(mr2).Value, mr1)) - return false; - - switch (trData1.ParentNamespaceOrType.HandleType) - { - case HandleType.TypeReference: - if (tdData2.EnclosingType.IsNull(mr2)) - return false; - - return CompareTypeReferenceToDefinition(trData1.ParentNamespaceOrType.ToTypeReferenceHandle(mr1), mr1, tdData2.EnclosingType, mr2); - - case HandleType.NamespaceReference: - return CompareNamespaceReferenceToDefinition(trData1.ParentNamespaceOrType.ToNamespaceReferenceHandle(mr1), mr1, tdData2.NamespaceDefinition, mr2); - - default: - Debug.Assert(false); - throw new BadImageFormatException(); - } - } - - public static bool CompareNamespaceReferenceToDefinition(NamespaceReferenceHandle nr1, MetadataReader mr1, NamespaceDefinitionHandle nd2, MetadataReader mr2) - { - NamespaceReference nrData1 = mr1.GetNamespaceReference(nr1); - NamespaceDefinition ndData2 = mr2.GetNamespaceDefinition(nd2); - - if (nrData1.Name.IsNull(mr1) != ndData2.Name.IsNull(mr2)) - return false; - - if (!nrData1.Name.IsNull(mr1)) - { - if (!nrData1.Name.StringEquals(ndData2.Name.GetConstantStringValue(mr2).Value, mr1)) - return false; - } - - switch (nrData1.ParentScopeOrNamespace.HandleType) - { - case HandleType.NamespaceReference: - if (ndData2.ParentScopeOrNamespace.HandleType != HandleType.NamespaceDefinition) - return false; - return CompareNamespaceReferenceToDefinition(nrData1.ParentScopeOrNamespace.ToNamespaceReferenceHandle(mr1), mr1, ndData2.ParentScopeOrNamespace.ToNamespaceDefinitionHandle(mr2), mr2); - - case HandleType.ScopeReference: - if (ndData2.ParentScopeOrNamespace.HandleType != HandleType.ScopeDefinition) - return false; - - return CompareScopeReferenceToDefinition(nrData1.ParentScopeOrNamespace.ToScopeReferenceHandle(mr1), mr1, ndData2.ParentScopeOrNamespace.ToScopeDefinitionHandle(mr2), mr2); - - default: - Debug.Assert(false); - throw new BadImageFormatException(); - } - } - - public static bool CompareScopeReferenceToDefinition(ScopeReferenceHandle sr1, MetadataReader mr1, ScopeDefinitionHandle sd2, MetadataReader mr2) - { - ScopeReference srData1 = mr1.GetScopeReference(sr1); - ScopeDefinition sdData2 = mr2.GetScopeDefinition(sd2); - if (!srData1.Name.StringEquals(sdData2.Name.GetConstantStringValue(mr2).Value, mr1)) - return false; - - if (!srData1.Culture.StringEquals(sdData2.Culture.GetConstantStringValue(mr2).Value, mr1)) - return false; - - if (srData1.MajorVersion != sdData2.MajorVersion) - return false; - - if (srData1.MinorVersion != sdData2.MinorVersion) - return false; - - if (srData1.RevisionNumber != sdData2.RevisionNumber) - return false; - - if (srData1.BuildNumber != sdData2.BuildNumber) - return false; - - return true; - } - - } -} diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.Metadata.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.Metadata.cs index fba781424ea97..3c214d4c51d1e 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.Metadata.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.Metadata.cs @@ -191,177 +191,6 @@ public unsafe bool TryGetNamedTypeForMetadata(QTypeDefinition qTypeDefinition, o return false; } - /// - /// Return the metadata handle for a TypeRef if this type was referenced indirectly by other type that pay-for-play has denoted as browsable - /// (for example, as part of a method signature.) - /// - /// This is only used in "debug" builds to provide better diagnostics when metadata is missing. - /// - /// Preconditions: - /// runtimeTypeHandle is a typedef (not a constructed type such as an array or generic instance.) - /// - /// MethodTable of the type in question - /// Metadata reader for the type - /// Located TypeRef handle - public static unsafe bool TryGetTypeReferenceForNamedType(RuntimeTypeHandle runtimeTypeHandle, out MetadataReader metadataReader, out TypeReferenceHandle typeRefHandle) - { - int hashCode = runtimeTypeHandle.GetHashCode(); - - // Iterate over all modules, starting with the module that defines the MethodTable - foreach (NativeFormatModuleInfo module in ModuleList.EnumerateModules(RuntimeAugments.GetModuleFromTypeHandle(runtimeTypeHandle))) - { - NativeReader typeMapReader; - if (TryGetNativeReaderForBlob(module, ReflectionMapBlob.TypeMap, out typeMapReader)) - { - NativeParser typeMapParser = new NativeParser(typeMapReader, 0); - NativeHashtable typeHashtable = new NativeHashtable(typeMapParser); - - ExternalReferencesTable externalReferences = default(ExternalReferencesTable); - externalReferences.InitializeCommonFixupsTable(module); - - var lookup = typeHashtable.Lookup(hashCode); - NativeParser entryParser; - while (!(entryParser = lookup.GetNext()).IsNull) - { - RuntimeTypeHandle foundType = externalReferences.GetRuntimeTypeHandleFromIndex(entryParser.GetUnsigned()); - if (foundType.Equals(runtimeTypeHandle)) - { - Handle entryMetadataHandle = entryParser.GetUnsigned().AsHandle(); - if (entryMetadataHandle.HandleType == HandleType.TypeReference) - { - metadataReader = module.MetadataReader; - typeRefHandle = entryMetadataHandle.ToTypeReferenceHandle(metadataReader); - return true; - } - } - } - } - } - - metadataReader = null; - typeRefHandle = default(TypeReferenceHandle); - - return false; - } - - /// - /// Return the RuntimeTypeHandle for the named type referenced by another type that pay-for-play denotes as browsable (for example, - /// in a member signature.) This will only find the typehandle if it is not defined in the current module, and is primarily used - /// to find non-browsable types. - /// - /// This is used to ensure that we can produce a Type object if requested and that it match up with the analogous - /// Type obtained via typeof(). - /// - /// - /// Preconditions: - /// metadataReader + typeRefHandle - a valid metadata reader + typeReferenceHandle where "metadataReader" is one - /// of the metadata readers returned by ExecutionEnvironment.MetadataReaders. - /// - /// Note: Although this method has a "bool" return value like the other mapping table accessors, the pay-for-play design - /// guarantees that any type that has a metadata TypeReference to it also has a RuntimeTypeHandle underneath. - /// - /// Metadata reader for module containing the type reference - /// TypeRef handle to look up - /// Resolved MethodTable for the type reference - /// Search all modules - public static unsafe bool TryGetNamedTypeForTypeReference(MetadataReader metadataReader, TypeReferenceHandle typeRefHandle, out RuntimeTypeHandle runtimeTypeHandle, bool searchAllModules = false) - { - int hashCode = typeRefHandle.ComputeHashCode(metadataReader); - NativeFormatModuleInfo typeRefModule = ModuleList.Instance.GetModuleInfoForMetadataReader(metadataReader); - return TryGetNamedTypeForTypeReference_Inner(metadataReader, typeRefModule, typeRefHandle, hashCode, typeRefModule, out runtimeTypeHandle); - } - - /// - /// Return the RuntimeTypeHandle for the named type referenced by another type that pay-for-play denotes as browsable (for example, - /// in a member signature.) This lookup will attempt to resolve to an MethodTable in any module to cover situations where the type - /// does not have a TypeDefinition (non-browsable type) as well as cases where it does. - /// - /// Preconditions: - /// metadataReader + typeRefHandle - a valid metadata reader + typeReferenceHandle where "metadataReader" is one - /// of the metadata readers returned by ExecutionEnvironment.MetadataReaders. - /// - /// Note: Although this method has a "bool" return value like the other mapping table accessors, the pay-for-play design - /// guarantees that any type that has a metadata TypeReference to it also has a RuntimeTypeHandle underneath. - /// - /// Metadata reader for module containing the type reference - /// TypeRef handle to look up - /// Resolved MethodTable for the type reference - public static unsafe bool TryResolveNamedTypeForTypeReference(MetadataReader metadataReader, TypeReferenceHandle typeRefHandle, out RuntimeTypeHandle runtimeTypeHandle) - { - int hashCode = typeRefHandle.ComputeHashCode(metadataReader); - NativeFormatModuleInfo typeRefModule = ModuleList.Instance.GetModuleInfoForMetadataReader(metadataReader); - runtimeTypeHandle = default(RuntimeTypeHandle); - - foreach (NativeFormatModuleInfo module in ModuleList.EnumerateModules(typeRefModule.Handle)) - { - if (TryGetNamedTypeForTypeReference_Inner(metadataReader, typeRefModule, typeRefHandle, hashCode, module, out runtimeTypeHandle)) - return true; - } - - return false; - } - - private static unsafe bool TryGetNamedTypeForTypeReference_Inner(MetadataReader metadataReader, - NativeFormatModuleInfo typeRefModule, - TypeReferenceHandle typeRefHandle, - int hashCode, - NativeFormatModuleInfo module, - out RuntimeTypeHandle runtimeTypeHandle) - { - Debug.Assert(typeRefModule == ModuleList.Instance.GetModuleInfoForMetadataReader(metadataReader)); - - NativeReader typeMapReader; - if (TryGetNativeReaderForBlob(module, ReflectionMapBlob.TypeMap, out typeMapReader)) - { - NativeParser typeMapParser = new NativeParser(typeMapReader, 0); - NativeHashtable typeHashtable = new NativeHashtable(typeMapParser); - - ExternalReferencesTable externalReferences = default(ExternalReferencesTable); - externalReferences.InitializeCommonFixupsTable(module); - - var lookup = typeHashtable.Lookup(hashCode); - NativeParser entryParser; - while (!(entryParser = lookup.GetNext()).IsNull) - { - var foundTypeIndex = entryParser.GetUnsigned(); - var handle = entryParser.GetUnsigned().AsHandle(); - - if (module == typeRefModule) - { - if (handle.Equals(typeRefHandle)) - { - runtimeTypeHandle = externalReferences.GetRuntimeTypeHandleFromIndex(foundTypeIndex); - return true; - } - } - else if (handle.HandleType == HandleType.TypeReference) - { - MetadataReader mrFoundHandle = module.MetadataReader; - // We found a type reference handle in another module.. see if it matches - if (MetadataReaderHelpers.CompareTypeReferenceAcrossModules(typeRefHandle, metadataReader, handle.ToTypeReferenceHandle(mrFoundHandle), mrFoundHandle)) - { - runtimeTypeHandle = externalReferences.GetRuntimeTypeHandleFromIndex(foundTypeIndex); - return true; - } - } - else if (handle.HandleType == HandleType.TypeDefinition) - { - // We found a type definition handle in another module. See if it matches - MetadataReader mrFoundHandle = module.MetadataReader; - // We found a type definition handle in another module.. see if it matches - if (MetadataReaderHelpers.CompareTypeReferenceToDefinition(typeRefHandle, metadataReader, handle.ToTypeDefinitionHandle(mrFoundHandle), mrFoundHandle)) - { - runtimeTypeHandle = externalReferences.GetRuntimeTypeHandleFromIndex(foundTypeIndex); - return true; - } - } - } - } - - runtimeTypeHandle = default(RuntimeTypeHandle); - return false; - } - /// /// Given a RuntimeTypeHandle for any non-dynamic type E, return a RuntimeTypeHandle for type E[] /// if the pay for play policy denotes E[] as browsable. This is used to implement Array.CreateInstance(). @@ -661,26 +490,6 @@ internal static unsafe IntPtr TryGetDefaultConstructorForType_Inner(NativeFormat } } - // If not found in the invoke map, try the default constructor map - NativeReader defaultCtorMapReader; - if (TryGetNativeReaderForBlob(mappingTableModule, ReflectionMapBlob.DefaultConstructorMap, out defaultCtorMapReader)) - { - NativeParser defaultCtorMapParser = new NativeParser(defaultCtorMapReader, 0); - NativeHashtable defaultCtorHashtable = new NativeHashtable(defaultCtorMapParser); - - ExternalReferencesTable externalReferencesForDefaultCtorMap = default(ExternalReferencesTable); - externalReferencesForDefaultCtorMap.InitializeCommonFixupsTable(mappingTableModule); - var lookup = defaultCtorHashtable.Lookup(canonHelper.LookupHashCode); - NativeParser defaultCtorParser; - while (!(defaultCtorParser = lookup.GetNext()).IsNull) - { - RuntimeTypeHandle entryType = externalReferencesForDefaultCtorMap.GetRuntimeTypeHandleFromIndex(defaultCtorParser.GetUnsigned()); - if (!canonHelper.IsCanonicallyEquivalent(entryType)) - continue; - - return externalReferencesForDefaultCtorMap.GetFunctionPointerFromIndex(defaultCtorParser.GetUnsigned()); - } - } return IntPtr.Zero; } diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.MetadataSignatureParsing.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.MetadataSignatureParsing.cs index 181804eb2e253..2727d49a917a8 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.MetadataSignatureParsing.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.MetadataSignatureParsing.cs @@ -360,14 +360,6 @@ private bool CompareTypeSigWithType(ref NativeParser parser, TypeManagerHandle m } break; - case HandleType.TypeReference: - if (!TypeLoaderEnvironment.TryResolveNamedTypeForTypeReference( - _metadataReader, typeHandle.ToTypeReferenceHandle(_metadataReader), out type2)) - { - return false; - } - break; - default: return false; } diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeNoMetadataType.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeNoMetadataType.cs index 38ac2815af055..bcbc5c6a10c38 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeNoMetadataType.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeNoMetadataType.cs @@ -296,9 +296,7 @@ private void GetTypeNameHelper(out string name, out string nsName, out string as Debug.Assert(!genericDefinitionHandle.IsNull()); #if DEBUG - TypeReferenceHandle typeRefHandle; QTypeDefinition qTypeDefinition; - MetadataReader reader; string enclosingDummy; @@ -309,12 +307,6 @@ private void GetTypeNameHelper(out string name, out string nsName, out string as typeDefHandle.GetFullName(qTypeDefinition.NativeFormatReader, out name, out enclosingDummy, out nsName); assemblyName = typeDefHandle.GetContainingModuleName(qTypeDefinition.NativeFormatReader); } - // Try to get the name from diagnostic metadata - else if (TypeLoaderEnvironment.TryGetTypeReferenceForNamedType(genericDefinitionHandle, out reader, out typeRefHandle)) - { - typeRefHandle.GetFullName(reader, out name, out enclosingDummy, out nsName); - assemblyName = typeRefHandle.GetContainingModuleName(reader); - } else #endif { diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj b/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj index 8463098f2f013..61799cfc159b1 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj @@ -231,7 +231,6 @@ - @@ -272,9 +271,6 @@ - - System\Runtime\CompilerServices\__BlockAllReflectionAttribute.cs - diff --git a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/SortableDependencyNode.cs b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/SortableDependencyNode.cs index 9ff3e3135d973..7fcc1a9c3b447 100644 --- a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/SortableDependencyNode.cs +++ b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/SortableDependencyNode.cs @@ -89,11 +89,9 @@ protected enum ObjectNodeOrder InterfaceGenericVirtualMethodTableNode, GenericMethodsTemplateMap, GenericTypesTemplateMap, - BlockReflectionTypeMapNode, StaticsInfoHashtableNode, ReflectionVirtualInvokeMapNode, ArrayOfEmbeddedPointersNode, - DefaultConstructorMapNode, ExternalReferencesTableNode, StackTraceEmbeddedMetadataNode, StackTraceMethodMappingNode, diff --git a/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/Generator/CsWriter.cs b/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/Generator/CsWriter.cs index e279a86b8500c..aa8bc5da629c9 100644 --- a/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/Generator/CsWriter.cs +++ b/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/Generator/CsWriter.cs @@ -95,7 +95,6 @@ public void WriteTypeAttributesForCoreLib() _writer.WriteLine("#if SYSTEM_PRIVATE_CORELIB"); WriteScopeAttribute("[CLSCompliant(false)]"); - WriteScopeAttribute("[ReflectionBlocked]"); _writer.WriteLine("#endif"); } } diff --git a/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/NativeFormatReaderCommonGen.cs b/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/NativeFormatReaderCommonGen.cs index 03ec0e9ae1d77..a9c8b12eaa1af 100644 --- a/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/NativeFormatReaderCommonGen.cs +++ b/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/NativeFormatReaderCommonGen.cs @@ -17,7 +17,6 @@ namespace Internal.Metadata.NativeFormat [Flags] #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public enum AssemblyFlags : uint { @@ -36,7 +35,6 @@ public enum AssemblyFlags : uint #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public enum AssemblyHashAlgorithm : uint { @@ -47,7 +45,6 @@ public enum AssemblyHashAlgorithm : uint #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public enum GenericParameterKind : byte { @@ -60,7 +57,6 @@ public enum GenericParameterKind : byte #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public enum NamedArgumentMemberKind : byte { @@ -73,7 +69,6 @@ public enum NamedArgumentMemberKind : byte #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public enum SignatureCallingConvention : byte { @@ -91,7 +86,6 @@ public enum SignatureCallingConvention : byte #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public enum HandleType : byte { diff --git a/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/NativeFormatReaderGen.cs b/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/NativeFormatReaderGen.cs index d21f809903d5c..6620dc373d184 100644 --- a/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/NativeFormatReaderGen.cs +++ b/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/NativeFormatReaderGen.cs @@ -23,7 +23,6 @@ namespace Internal.Metadata.NativeFormat { #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ArraySignature { @@ -82,7 +81,6 @@ public Int32Collection LowerBounds #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ArraySignatureHandle { @@ -168,7 +166,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ByReferenceSignature { @@ -197,7 +194,6 @@ public Handle Type #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ByReferenceSignatureHandle { @@ -283,7 +279,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantBooleanArray { @@ -311,7 +306,6 @@ public BooleanCollection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantBooleanArrayHandle { @@ -397,7 +391,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantBooleanValue { @@ -425,7 +418,6 @@ public bool Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantBooleanValueHandle { @@ -511,7 +503,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantBoxedEnumValue { @@ -551,7 +542,6 @@ public Handle Type #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantBoxedEnumValueHandle { @@ -637,7 +627,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantByteArray { @@ -665,7 +654,6 @@ public ByteCollection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantByteArrayHandle { @@ -751,7 +739,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantByteValue { @@ -779,7 +766,6 @@ public byte Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantByteValueHandle { @@ -865,7 +851,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantCharArray { @@ -893,7 +878,6 @@ public CharCollection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantCharArrayHandle { @@ -979,7 +963,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantCharValue { @@ -1007,7 +990,6 @@ public char Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantCharValueHandle { @@ -1093,7 +1075,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantDoubleArray { @@ -1121,7 +1102,6 @@ public DoubleCollection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantDoubleArrayHandle { @@ -1207,7 +1187,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantDoubleValue { @@ -1235,7 +1214,6 @@ public double Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantDoubleValueHandle { @@ -1321,7 +1299,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantEnumArray { @@ -1359,7 +1336,6 @@ public Handle Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantEnumArrayHandle { @@ -1445,7 +1421,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantHandleArray { @@ -1473,7 +1448,6 @@ public HandleCollection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantHandleArrayHandle { @@ -1559,7 +1533,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantInt16Array { @@ -1587,7 +1560,6 @@ public Int16Collection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantInt16ArrayHandle { @@ -1673,7 +1645,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantInt16Value { @@ -1701,7 +1672,6 @@ public short Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantInt16ValueHandle { @@ -1787,7 +1757,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantInt32Array { @@ -1815,7 +1784,6 @@ public Int32Collection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantInt32ArrayHandle { @@ -1901,7 +1869,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantInt32Value { @@ -1929,7 +1896,6 @@ public int Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantInt32ValueHandle { @@ -2015,7 +1981,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantInt64Array { @@ -2043,7 +2008,6 @@ public Int64Collection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantInt64ArrayHandle { @@ -2129,7 +2093,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantInt64Value { @@ -2157,7 +2120,6 @@ public long Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantInt64ValueHandle { @@ -2243,7 +2205,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantReferenceValue { @@ -2261,7 +2222,6 @@ public ConstantReferenceValueHandle Handle #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantReferenceValueHandle { @@ -2347,7 +2307,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantSByteArray { @@ -2375,7 +2334,6 @@ public SByteCollection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantSByteArrayHandle { @@ -2461,7 +2419,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantSByteValue { @@ -2489,7 +2446,6 @@ public sbyte Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantSByteValueHandle { @@ -2575,7 +2531,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantSingleArray { @@ -2603,7 +2558,6 @@ public SingleCollection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantSingleArrayHandle { @@ -2689,7 +2643,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantSingleValue { @@ -2717,7 +2670,6 @@ public float Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantSingleValueHandle { @@ -2803,7 +2755,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantStringArray { @@ -2832,7 +2783,6 @@ public HandleCollection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantStringArrayHandle { @@ -2918,7 +2868,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantStringValue { @@ -2946,7 +2895,6 @@ public string Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantStringValueHandle { @@ -3032,7 +2980,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantUInt16Array { @@ -3060,7 +3007,6 @@ public UInt16Collection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantUInt16ArrayHandle { @@ -3146,7 +3092,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantUInt16Value { @@ -3174,7 +3119,6 @@ public ushort Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantUInt16ValueHandle { @@ -3260,7 +3204,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantUInt32Array { @@ -3288,7 +3231,6 @@ public UInt32Collection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantUInt32ArrayHandle { @@ -3374,7 +3316,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantUInt32Value { @@ -3402,7 +3343,6 @@ public uint Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantUInt32ValueHandle { @@ -3488,7 +3428,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantUInt64Array { @@ -3516,7 +3455,6 @@ public UInt64Collection Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantUInt64ArrayHandle { @@ -3602,7 +3540,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantUInt64Value { @@ -3630,7 +3567,6 @@ public ulong Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ConstantUInt64ValueHandle { @@ -3716,7 +3652,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct CustomAttribute { @@ -3766,7 +3701,6 @@ public NamedArgumentHandleCollection NamedArguments #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct CustomAttributeHandle { @@ -3852,7 +3786,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct Event { @@ -3921,7 +3854,6 @@ public CustomAttributeHandleCollection CustomAttributes #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct EventHandle { @@ -4007,7 +3939,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct Field { @@ -4086,7 +4017,6 @@ public CustomAttributeHandleCollection CustomAttributes #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct FieldHandle { @@ -4172,7 +4102,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct FieldSignature { @@ -4201,7 +4130,6 @@ public Handle Type #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct FieldSignatureHandle { @@ -4287,7 +4215,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct FunctionPointerSignature { @@ -4315,7 +4242,6 @@ public MethodSignatureHandle Signature #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct FunctionPointerSignatureHandle { @@ -4401,7 +4327,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct GenericParameter { @@ -4480,7 +4405,6 @@ public CustomAttributeHandleCollection CustomAttributes #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct GenericParameterHandle { @@ -4566,7 +4490,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct MemberReference { @@ -4616,7 +4539,6 @@ public Handle Signature #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct MemberReferenceHandle { @@ -4702,7 +4624,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct Method { @@ -4790,7 +4711,6 @@ public CustomAttributeHandleCollection CustomAttributes #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct MethodHandle { @@ -4876,7 +4796,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct MethodInstantiation { @@ -4916,7 +4835,6 @@ public HandleCollection GenericTypeArguments #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct MethodInstantiationHandle { @@ -5002,7 +4920,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct MethodSemantics { @@ -5040,7 +4957,6 @@ public MethodHandle Method #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct MethodSemanticsHandle { @@ -5126,7 +5042,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct MethodSignature { @@ -5197,7 +5112,6 @@ public HandleCollection VarArgParameters #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct MethodSignatureHandle { @@ -5283,7 +5197,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct MethodTypeVariableSignature { @@ -5311,7 +5224,6 @@ public int Number #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct MethodTypeVariableSignatureHandle { @@ -5397,7 +5309,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ModifiedType { @@ -5447,7 +5358,6 @@ public Handle Type #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ModifiedTypeHandle { @@ -5533,7 +5443,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct NamedArgument { @@ -5593,7 +5502,6 @@ public Handle Value #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct NamedArgumentHandle { @@ -5679,7 +5587,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct NamespaceDefinition { @@ -5748,7 +5655,6 @@ public NamespaceDefinitionHandleCollection NamespaceDefinitions #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct NamespaceDefinitionHandle { @@ -5834,7 +5740,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct NamespaceReference { @@ -5873,7 +5778,6 @@ public ConstantStringValueHandle Name #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct NamespaceReferenceHandle { @@ -5959,7 +5863,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct Parameter { @@ -6028,7 +5931,6 @@ public CustomAttributeHandleCollection CustomAttributes #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ParameterHandle { @@ -6114,7 +6016,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct PointerSignature { @@ -6143,7 +6044,6 @@ public Handle Type #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct PointerSignatureHandle { @@ -6229,7 +6129,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct Property { @@ -6308,7 +6207,6 @@ public CustomAttributeHandleCollection CustomAttributes #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct PropertyHandle { @@ -6394,7 +6292,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct PropertySignature { @@ -6444,7 +6341,6 @@ public HandleCollection Parameters #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct PropertySignatureHandle { @@ -6530,7 +6426,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct QualifiedField { @@ -6568,7 +6463,6 @@ public TypeDefinitionHandle EnclosingType #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct QualifiedFieldHandle { @@ -6654,7 +6548,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct QualifiedMethod { @@ -6692,7 +6585,6 @@ public TypeDefinitionHandle EnclosingType #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct QualifiedMethodHandle { @@ -6778,7 +6670,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct SZArraySignature { @@ -6807,7 +6698,6 @@ public Handle ElementType #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct SZArraySignatureHandle { @@ -6893,7 +6783,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ScopeDefinition { @@ -7071,7 +6960,6 @@ public CustomAttributeHandleCollection ModuleCustomAttributes #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ScopeDefinitionHandle { @@ -7157,7 +7045,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ScopeReference { @@ -7255,7 +7142,6 @@ public ConstantStringValueHandle Culture #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ScopeReferenceHandle { @@ -7341,7 +7227,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeDefinition { @@ -7511,7 +7396,6 @@ public CustomAttributeHandleCollection CustomAttributes #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeDefinitionHandle { @@ -7597,7 +7481,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeForwarder { @@ -7645,7 +7528,6 @@ public TypeForwarderHandleCollection NestedTypes #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeForwarderHandle { @@ -7731,7 +7613,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeInstantiationSignature { @@ -7771,7 +7652,6 @@ public HandleCollection GenericTypeArguments #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeInstantiationSignatureHandle { @@ -7857,7 +7737,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeReference { @@ -7896,7 +7775,6 @@ public ConstantStringValueHandle TypeName #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeReferenceHandle { @@ -7982,7 +7860,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeSpecification { @@ -8011,7 +7888,6 @@ public Handle Signature #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeSpecificationHandle { @@ -8097,7 +7973,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeVariableSignature { @@ -8125,7 +8000,6 @@ public int Number #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeVariableSignatureHandle { @@ -8211,7 +8085,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct NamedArgumentHandleCollection { @@ -8241,7 +8114,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -8282,7 +8154,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct MethodSemanticsHandleCollection { @@ -8312,7 +8183,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -8353,7 +8223,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct CustomAttributeHandleCollection { @@ -8383,7 +8252,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -8424,7 +8292,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ParameterHandleCollection { @@ -8454,7 +8321,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -8495,7 +8361,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct GenericParameterHandleCollection { @@ -8525,7 +8390,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -8566,7 +8430,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeDefinitionHandleCollection { @@ -8596,7 +8459,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -8637,7 +8499,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct TypeForwarderHandleCollection { @@ -8667,7 +8528,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -8708,7 +8568,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct NamespaceDefinitionHandleCollection { @@ -8738,7 +8597,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -8779,7 +8637,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct MethodHandleCollection { @@ -8809,7 +8666,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -8850,7 +8706,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct FieldHandleCollection { @@ -8880,7 +8735,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -8921,7 +8775,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct PropertyHandleCollection { @@ -8951,7 +8804,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -8992,7 +8844,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct EventHandleCollection { @@ -9022,7 +8873,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9063,7 +8913,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ScopeDefinitionHandleCollection { @@ -9093,7 +8942,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9134,7 +8982,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct BooleanCollection { @@ -9164,7 +9011,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9205,7 +9051,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct CharCollection { @@ -9235,7 +9080,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9276,7 +9120,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct ByteCollection { @@ -9306,7 +9149,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9347,7 +9189,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct SByteCollection { @@ -9377,7 +9218,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9418,7 +9258,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct Int16Collection { @@ -9448,7 +9287,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9489,7 +9327,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct UInt16Collection { @@ -9519,7 +9356,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9560,7 +9396,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct Int32Collection { @@ -9590,7 +9425,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9631,7 +9465,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct UInt32Collection { @@ -9661,7 +9494,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9702,7 +9534,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct Int64Collection { @@ -9732,7 +9563,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9773,7 +9603,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct UInt64Collection { @@ -9803,7 +9632,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9844,7 +9672,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct SingleCollection { @@ -9874,7 +9701,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9915,7 +9741,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct DoubleCollection { @@ -9945,7 +9770,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -9986,7 +9810,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct Handle { @@ -10308,7 +10131,6 @@ public TypeVariableSignatureHandle ToTypeVariableSignatureHandle(MetadataReader #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial struct HandleCollection { @@ -10338,7 +10160,6 @@ public Enumerator GetEnumerator() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public struct Enumerator { @@ -10379,7 +10200,6 @@ public void Dispose() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public partial class MetadataReader { diff --git a/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/NativeMetadataReader.cs b/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/NativeMetadataReader.cs index 673867d0f9946..40b68f760b939 100644 --- a/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/NativeMetadataReader.cs +++ b/src/coreclr/tools/Common/Internal/Metadata/NativeFormat/NativeMetadataReader.cs @@ -18,9 +18,6 @@ namespace Internal.Metadata.NativeFormat { // This Enum matches CorMethodSemanticsAttr defined in CorHdr.h [Flags] -#if SYSTEM_PRIVATE_CORELIB - [ReflectionBlocked] -#endif public enum MethodSemanticsAttributes { Setter = 0x0001, @@ -33,9 +30,6 @@ public enum MethodSemanticsAttributes // This Enum matches CorPInvokeMap defined in CorHdr.h [Flags] -#if SYSTEM_PRIVATE_CORELIB - [ReflectionBlocked] -#endif public enum PInvokeAttributes { NoMangle = 0x0001, @@ -158,7 +152,6 @@ public override string ToString() #if SYSTEM_PRIVATE_CORELIB [CLSCompliant(false)] - [ReflectionBlocked] #endif public static class NativeFormatReaderExtensions { diff --git a/src/coreclr/tools/Common/Internal/Runtime/MetadataBlob.cs b/src/coreclr/tools/Common/Internal/Runtime/MetadataBlob.cs index f1d1ea20790a4..e1a4d90162c2d 100644 --- a/src/coreclr/tools/Common/Internal/Runtime/MetadataBlob.cs +++ b/src/coreclr/tools/Common/Internal/Runtime/MetadataBlob.cs @@ -9,7 +9,7 @@ internal enum ReflectionMapBlob ArrayMap = 2, PointerTypeMap = 3, FunctionPointerTypeMap = 4, - BlockReflectionTypeMap = 5, + // unused = 5, InvokeMap = 6, VirtualInvokeMap = 7, CommonFixupsTable = 8, @@ -18,7 +18,7 @@ internal enum ReflectionMapBlob ByRefTypeMap = 11, // unused = 12, EmbeddedMetadata = 13, - DefaultConstructorMap = 14, + // Unused = 14, UnboxingAndInstantiatingStubMap = 15, StructMarshallingStubMap = 16, DelegateMarshallingStubMap = 17, diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/BlockedInternalsBlockingPolicy.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/BlockedInternalsBlockingPolicy.cs deleted file mode 100644 index 32145754e9988..0000000000000 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/BlockedInternalsBlockingPolicy.cs +++ /dev/null @@ -1,233 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Internal.TypeSystem; -using Internal.TypeSystem.Ecma; - -using Debug = System.Diagnostics.Debug; -using TypeAttributes = System.Reflection.TypeAttributes; -using MethodAttributes = System.Reflection.MethodAttributes; -using FieldAttributes = System.Reflection.FieldAttributes; - -namespace ILCompiler -{ - /// - /// Represents a metadata policy that blocks implementations details. - /// - public sealed class BlockedInternalsBlockingPolicy : MetadataBlockingPolicy - { - private enum ModuleBlockingMode - { - None, - BlockedInternals, - FullyBlocked, - } - - private sealed class ModuleBlockingState - { - public ModuleDesc Module { get; } - public ModuleBlockingMode BlockingMode { get; } - public ModuleBlockingState(ModuleDesc module, ModuleBlockingMode mode) - { - Module = module; - BlockingMode = mode; - } - } - - private sealed class BlockedModulesHashtable : LockFreeReaderHashtable - { - protected override int GetKeyHashCode(ModuleDesc key) => key.GetHashCode(); - protected override int GetValueHashCode(ModuleBlockingState value) => value.Module.GetHashCode(); - protected override bool CompareKeyToValue(ModuleDesc key, ModuleBlockingState value) => ReferenceEquals(key, value.Module); - protected override bool CompareValueToValue(ModuleBlockingState value1, ModuleBlockingState value2) => ReferenceEquals(value1.Module, value2.Module); - protected override ModuleBlockingState CreateValueFromKey(ModuleDesc module) - { - ModuleBlockingMode blockingMode = ModuleBlockingMode.None; - - if (module.GetType("System.Runtime.CompilerServices", "__BlockAllReflectionAttribute", throwIfNotFound: false) != null) - { - blockingMode = ModuleBlockingMode.FullyBlocked; - } - else if (module.GetType("System.Runtime.CompilerServices", "__BlockReflectionAttribute", throwIfNotFound: false) != null) - { - blockingMode = ModuleBlockingMode.BlockedInternals; - } - - return new ModuleBlockingState(module, blockingMode); - } - } - private BlockedModulesHashtable _blockedModules = new BlockedModulesHashtable(); - - private sealed class BlockingState - { - public EcmaType Type { get; } - public bool IsBlocked { get; } - public BlockingState(EcmaType type, bool isBlocked) - { - Type = type; - IsBlocked = isBlocked; - } - } - - private sealed class BlockedTypeHashtable : LockFreeReaderHashtable - { - private readonly BlockedModulesHashtable _blockedModules; - - public BlockedTypeHashtable(BlockedModulesHashtable blockedModules) - { - _blockedModules = blockedModules; - } - - protected override int GetKeyHashCode(EcmaType key) => key.GetHashCode(); - protected override int GetValueHashCode(BlockingState value) => value.Type.GetHashCode(); - protected override bool CompareKeyToValue(EcmaType key, BlockingState value) => ReferenceEquals(key, value.Type); - protected override bool CompareValueToValue(BlockingState value1, BlockingState value2) => ReferenceEquals(value1.Type, value2.Type); - protected override BlockingState CreateValueFromKey(EcmaType type) - { - ModuleBlockingMode moduleBlockingMode = _blockedModules.GetOrCreateValue(type.EcmaModule).BlockingMode; - bool isBlocked = ComputeIsBlocked(type, moduleBlockingMode); - return new BlockingState(type, isBlocked); - } - - private bool ComputeIsBlocked(EcmaType type, ModuleBlockingMode blockingMode) - { - // If the type is explicitly blocked, it's always blocked. - if (type.HasCustomAttribute("System.Runtime.CompilerServices", "ReflectionBlockedAttribute")) - return true; - - // If no blocking is applied to the module, the type is not blocked - if (blockingMode == ModuleBlockingMode.None) - return false; - - // type always gets metadata - if (type.IsModuleType) - return false; - - // The various SR types used in Resource Manager always get metadata - if ((type.Name == "Strings" || type.Name == "SR") && - type.Namespace.Contains(type.Module.Assembly.GetName().Name)) - return false; - - // Event sources are not blocked - if (type.HasCustomAttribute("System.Diagnostics.Tracing", "EventSourceAttribute")) - return false; - - // We block everything else if the module is blocked - if (blockingMode == ModuleBlockingMode.FullyBlocked) - return true; - - DefType containingType = type.ContainingType; - var typeDefinition = type.MetadataReader.GetTypeDefinition(type.Handle); - - if (containingType == null) - { - if ((typeDefinition.Attributes & TypeAttributes.Public) == 0) - { - return true; - } - } - else - { - if ((typeDefinition.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic) - { - return ComputeIsBlocked((EcmaType)containingType, blockingMode); - } - else - { - return true; - } - } - - return false; - } - } - private BlockedTypeHashtable _blockedTypes; - - private MetadataType ArrayOfTType { get; } - - public BlockedInternalsBlockingPolicy(TypeSystemContext context) - { - _blockedTypes = new BlockedTypeHashtable(_blockedModules); - - ArrayOfTType = context.SystemModule.GetType("System", "Array`1", throwIfNotFound: false); - } - - public override bool IsBlocked(MetadataType type) - { - Debug.Assert(type.IsTypeDefinition); - - var ecmaType = type as EcmaType; - if (ecmaType == null) - return true; - - return _blockedTypes.GetOrCreateValue(ecmaType).IsBlocked; - } - - public override bool IsBlocked(MethodDesc method) - { - Debug.Assert(method.IsTypicalMethodDefinition); - - var ecmaMethod = method as EcmaMethod; - if (ecmaMethod == null) - return true; - - ModuleBlockingMode moduleBlockingMode = _blockedModules.GetOrCreateValue(ecmaMethod.Module).BlockingMode; - if (moduleBlockingMode == ModuleBlockingMode.None) - return false; - else if (moduleBlockingMode == ModuleBlockingMode.FullyBlocked) - return true; - - // We are blocking internal implementation details - Debug.Assert(moduleBlockingMode == ModuleBlockingMode.BlockedInternals); - - var owningType = (EcmaType)ecmaMethod.OwningType; - if (_blockedTypes.GetOrCreateValue(owningType).IsBlocked) - return true; - - MethodAttributes accessibility = ecmaMethod.Attributes & MethodAttributes.Public; - if (accessibility != MethodAttributes.Family - && accessibility != MethodAttributes.FamORAssem - && accessibility != MethodAttributes.Public) - { - return true; - } - - // Methods on Array`1 are implementation details that implement the generic interfaces on - // arrays. They should not generate metadata or be reflection invokable. - // We could get rid of this special casing two ways: - // * Make these method stop being regular EcmaMethods with Array as their owning type, or - // * Make these methods implement the interfaces explicitly (they would become private and naturally blocked) - if (ecmaMethod.OwningType == ArrayOfTType) - return true; - - return false; - } - - public override bool IsBlocked(FieldDesc field) - { - Debug.Assert(field.IsTypicalFieldDefinition); - - var ecmaField = field as EcmaField; - if (ecmaField == null) - return true; - - ModuleBlockingMode moduleBlockingMode = _blockedModules.GetOrCreateValue(ecmaField.Module).BlockingMode; - if (moduleBlockingMode == ModuleBlockingMode.None) - return false; - else if (moduleBlockingMode == ModuleBlockingMode.FullyBlocked) - return true; - - // We are blocking internal implementation details - Debug.Assert(moduleBlockingMode == ModuleBlockingMode.BlockedInternals); - - var owningType = (EcmaType)ecmaField.OwningType; - if (_blockedTypes.GetOrCreateValue(owningType).IsBlocked) - return true; - - FieldAttributes accessibility = ecmaField.Attributes & FieldAttributes.FieldAccessMask; - return accessibility != FieldAttributes.Family - && accessibility != FieldAttributes.FamORAssem - && accessibility != FieldAttributes.Public; - } - } -} diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/BlockReflectionTypeMapNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/BlockReflectionTypeMapNode.cs deleted file mode 100644 index 707ad23464722..0000000000000 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/BlockReflectionTypeMapNode.cs +++ /dev/null @@ -1,87 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; - -using Internal.TypeSystem; -using Internal.NativeFormat; -using Internal.Text; - -namespace ILCompiler.DependencyAnalysis -{ - /// - /// Represents a hashtable of all type blocked from reflection. - /// - public sealed class BlockReflectionTypeMapNode : ObjectNode, ISymbolDefinitionNode - { - private ObjectAndOffsetSymbolNode _endSymbol; - private ExternalReferencesTableNode _externalReferences; - - public BlockReflectionTypeMapNode(ExternalReferencesTableNode externalReferences) - { - _endSymbol = new ObjectAndOffsetSymbolNode(this, 0, "__block_reflection_type_map_End", true); - _externalReferences = externalReferences; - } - - public ISymbolDefinitionNode EndSymbol => _endSymbol; - - public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb) - { - sb.Append(nameMangler.CompilationUnitPrefix).Append("__block_reflection_type_map"); - } - public int Offset => 0; - public override bool IsShareable => false; - - public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory); - - public override bool StaticDependenciesAreComputed => true; - - protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler); - - public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) - { - // This node does not trigger generation of other nodes. - if (relocsOnly) - return new ObjectData(Array.Empty(), Array.Empty(), 1, new ISymbolDefinitionNode[] { this }); - - var writer = new NativeWriter(); - var reflectionBlockTypeMapHashTable = new VertexHashtable(); - - Section hashTableSection = writer.NewSection(); - hashTableSection.Place(reflectionBlockTypeMapHashTable); - - foreach (var type in factory.MetadataManager.GetTypesWithEETypes()) - { - if (!type.IsTypeDefinition) - continue; - - var mdType = type as MetadataType; - if (mdType == null) - continue; - - if (!factory.MetadataManager.IsReflectionBlocked(mdType)) - continue; - - if (!factory.CompilationModuleGroup.ContainsType(mdType)) - continue; - - // Go with a necessary type symbol. It will be upgraded to a constructed one if a constructed was emitted. - IEETypeNode typeSymbol = factory.NecessaryTypeSymbol(type); - - Vertex vertex = writer.GetUnsignedConstant(_externalReferences.GetIndex(typeSymbol)); - - int hashCode = typeSymbol.Type.GetHashCode(); - reflectionBlockTypeMapHashTable.Append((uint)hashCode, hashTableSection.Place(vertex)); - } - - byte[] hashTableBytes = writer.Save(); - - _endSymbol.SetSymbolOffset(hashTableBytes.Length); - - return new ObjectData(hashTableBytes, Array.Empty(), 1, new ISymbolDefinitionNode[] { this, _endSymbol }); - } - - protected internal override int Phase => (int)ObjectNodePhase.Ordered; - public override int ClassCode => (int)ObjectNodeOrder.BlockReflectionTypeMapNode; - } -} diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CanonicalEETypeNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CanonicalEETypeNode.cs index 500192714f719..c614452f17c92 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CanonicalEETypeNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CanonicalEETypeNode.cs @@ -58,17 +58,6 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact AddDependenciesForUniversalGVMSupport(factory, _type, ref dependencyList); } - // Keep track of the default constructor map dependency for this type if it has a default constructor - // We only do this for reflection blocked types because dataflow analysis is responsible for - // generating default constructors for Activator.CreateInstance in other cases. - MethodDesc defaultCtor = closestDefType.GetDefaultConstructor(); - if (defaultCtor != null && factory.MetadataManager.IsReflectionBlocked(defaultCtor)) - { - dependencyList.Add(new DependencyListEntry( - factory.CanonicalEntrypoint(defaultCtor), - "DefaultConstructorNode")); - } - return dependencyList; } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ConstructedEETypeNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ConstructedEETypeNode.cs index 1e9e3144d2be0..2d20dabfe94f7 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ConstructedEETypeNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ConstructedEETypeNode.cs @@ -80,17 +80,6 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact factory.InteropStubManager.AddInterestingInteropConstructedTypeDependencies(ref dependencyList, factory, _type); - // Keep track of the default constructor map dependency for this type if it has a default constructor - // We only do this for reflection blocked types because dataflow analysis is responsible for - // generating default constructors for Activator.CreateInstance in other cases. - MethodDesc defaultCtor = closestDefType.GetDefaultConstructor(); - if (defaultCtor != null && factory.MetadataManager.IsReflectionBlocked(defaultCtor)) - { - dependencyList.Add(new DependencyListEntry( - factory.CanonicalEntrypoint(defaultCtor), - "DefaultConstructorNode")); - } - return dependencyList; } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DefaultConstructorMapNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DefaultConstructorMapNode.cs deleted file mode 100644 index ff6647649d719..0000000000000 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DefaultConstructorMapNode.cs +++ /dev/null @@ -1,92 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; - -using Internal.Text; -using Internal.TypeSystem; -using Internal.NativeFormat; - -namespace ILCompiler.DependencyAnalysis -{ - /// - /// DefaultConstructorMap blob, containing information on default constructor entrypoints of all types used - /// by lazy generic instantiations. - /// - internal sealed class DefaultConstructorMapNode : ObjectNode, ISymbolDefinitionNode - { - private ObjectAndOffsetSymbolNode _endSymbol; - private ExternalReferencesTableNode _externalReferences; - - public DefaultConstructorMapNode(ExternalReferencesTableNode externalReferences) - { - _endSymbol = new ObjectAndOffsetSymbolNode(this, 0, "__DefaultConstructor_Map_End", true); - _externalReferences = externalReferences; - } - - public ISymbolNode EndSymbol => _endSymbol; - - public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb) - { - sb.Append(nameMangler.CompilationUnitPrefix).Append("__DefaultConstructor_Map"); - } - - public int Offset => 0; - public override bool IsShareable => false; - public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory); - public override bool ShouldSkipEmittingObjectNode(NodeFactory factory) => false; - public override bool StaticDependenciesAreComputed => true; - - protected internal override int Phase => (int)ObjectNodePhase.Ordered; - public override int ClassCode => (int)ObjectNodeOrder.DefaultConstructorMapNode; - - protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler); - - public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) - { - // This node does not trigger generation of other nodes. - if (relocsOnly) - return new ObjectData(Array.Empty(), Array.Empty(), 1, new ISymbolDefinitionNode[] { this }); - - var writer = new NativeWriter(); - var defaultConstructorHashtable = new VertexHashtable(); - - Section defaultConstructorHashtableSection = writer.NewSection(); - defaultConstructorHashtableSection.Place(defaultConstructorHashtable); - - foreach (var type in factory.MetadataManager.GetTypesWithConstructedEETypes()) - { - MethodDesc defaultCtor = type.GetDefaultConstructor(); - if (defaultCtor == null) - continue; - - // We only place default constructors of reflection-blocked types in this table. - // At runtime, the type loader will search both this table and the invoke map - // for default constructor info. If the ctor is reflectable, we would have - // expected dataflow analysis to ensure there's a reflectable method for it. - // If we don't find a reflectable method for the ctor of a non-blocked type - // there would have to be a dataflow analysis warning. - if (!factory.MetadataManager.IsReflectionBlocked(defaultCtor)) - continue; - - defaultCtor = defaultCtor.GetCanonMethodTarget(CanonicalFormKind.Specific); - - ISymbolNode typeNode = factory.NecessaryTypeSymbol(type); - ISymbolNode defaultCtorNode = factory.MethodEntrypoint(defaultCtor, false); - - Vertex vertex = writer.GetTuple( - writer.GetUnsignedConstant(_externalReferences.GetIndex(typeNode)), - writer.GetUnsignedConstant(_externalReferences.GetIndex(defaultCtorNode))); - - int hashCode = type.GetHashCode(); - defaultConstructorHashtable.Append((uint)hashCode, defaultConstructorHashtableSection.Place(vertex)); - } - - byte[] hashTableBytes = writer.Save(); - - _endSymbol.SetSymbolOffset(hashTableBytes.Length); - - return new ObjectData(hashTableBytes, Array.Empty(), 1, new ISymbolDefinitionNode[] { this, _endSymbol }); - } - } -} diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/GeneratingMetadataManager.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/GeneratingMetadataManager.cs index 14f1bdfdcee8d..3d30bcd072e1b 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/GeneratingMetadataManager.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/GeneratingMetadataManager.cs @@ -54,10 +54,6 @@ protected void ComputeMetadata( var transformed = MetadataTransform.Run(policy, GetCompilationModulesWithMetadata()); MetadataTransform transform = transformed.Transform; - // TODO: DeveloperExperienceMode: Use transformed.Transform.HandleType() to generate - // TypeReference records for _typeDefinitionsGenerated that don't have metadata. - // (To be used in MissingMetadataException messages) - // Generate metadata blob var writer = new MetadataWriter(); writer.ScopeDefinitions.AddRange(transformed.Scopes); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs index ed5591bd3c84b..10d7ae4edf033 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs @@ -182,18 +182,12 @@ public virtual void AddToReadyToRunHeader(ReadyToRunHeaderNode header, NodeFacto var genericTypesTemplatesMapNode = new GenericTypesTemplateMap(commonFixupsTableNode); header.Add(BlobIdToReadyToRunSection(ReflectionMapBlob.TypeTemplateMap), genericTypesTemplatesMapNode, genericTypesTemplatesMapNode, genericTypesTemplatesMapNode.EndSymbol); - var blockReflectionTypeMapNode = new BlockReflectionTypeMapNode(commonFixupsTableNode); - header.Add(BlobIdToReadyToRunSection(ReflectionMapBlob.BlockReflectionTypeMap), blockReflectionTypeMapNode, blockReflectionTypeMapNode, blockReflectionTypeMapNode.EndSymbol); - var staticsInfoHashtableNode = new StaticsInfoHashtableNode(nativeReferencesTableNode, nativeStaticsTableNode); header.Add(BlobIdToReadyToRunSection(ReflectionMapBlob.StaticsInfoHashtable), staticsInfoHashtableNode, staticsInfoHashtableNode, staticsInfoHashtableNode.EndSymbol); var virtualInvokeMapNode = new ReflectionVirtualInvokeMapNode(commonFixupsTableNode); header.Add(BlobIdToReadyToRunSection(ReflectionMapBlob.VirtualInvokeMap), virtualInvokeMapNode, virtualInvokeMapNode, virtualInvokeMapNode.EndSymbol); - var defaultConstructorMapNode = new DefaultConstructorMapNode(commonFixupsTableNode); - header.Add(BlobIdToReadyToRunSection(ReflectionMapBlob.DefaultConstructorMap), defaultConstructorMapNode, defaultConstructorMapNode, defaultConstructorMapNode.EndSymbol); - var stackTraceMethodMappingNode = new StackTraceMethodMappingNode(); header.Add(BlobIdToReadyToRunSection(ReflectionMapBlob.BlobIdStackTraceMethodRvaToTokenMapping), stackTraceMethodMappingNode, stackTraceMethodMappingNode, stackTraceMethodMappingNode.EndSymbol); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj b/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj index fc41ba97ec0f0..c03d8e5171d4a 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj @@ -332,7 +332,6 @@ - @@ -398,7 +397,6 @@ - @@ -474,7 +472,6 @@ - diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs index e90dfd7256ef4..a417d22aa7c87 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs +++ b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs @@ -68,8 +68,6 @@ internal sealed class ILCompilerRootCommand : RootCommand new(new[] { "--mstat" }, "Generate an mstat file"); public Option MetadataLogFileName { get; } = new(new[] { "--metadatalog" }, "Generate a metadata log file"); - public Option NoMetadataBlocking { get; } = - new(new[] { "--nometadatablocking" }, "Ignore metadata blocking for internal implementation details"); public Option CompleteTypesMetadata { get; } = new(new[] { "--completetypemetadata" }, "Generate complete metadata for types"); public Option ReflectionData { get; } = @@ -195,7 +193,6 @@ public ILCompilerRootCommand(string[] args) : base(".NET Native IL Compiler") AddOption(MapFileName); AddOption(MstatFileName); AddOption(MetadataLogFileName); - AddOption(NoMetadataBlocking); AddOption(CompleteTypesMetadata); AddOption(ReflectionData); AddOption(ScanReflection); diff --git a/src/coreclr/tools/aot/ILCompiler/Program.cs b/src/coreclr/tools/aot/ILCompiler/Program.cs index 56689af570bf0..1d04d3a414dbe 100644 --- a/src/coreclr/tools/aot/ILCompiler/Program.cs +++ b/src/coreclr/tools/aot/ILCompiler/Program.cs @@ -348,8 +348,7 @@ public int Run() UsageBasedMetadataGenerationOptions metadataGenerationOptions = default; if (supportsReflection) { - mdBlockingPolicy = Get(_command.NoMetadataBlocking) ? - new NoMetadataBlockingPolicy() : new BlockedInternalsBlockingPolicy(typeSystemContext); + mdBlockingPolicy = new NoMetadataBlockingPolicy(); resBlockingPolicy = new ManifestResourceBlockingPolicy(logger, featureSwitches); From 6f8c84fe10c8ef420d57aba523ebc3e3529e2c1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Fri, 5 May 2023 17:42:18 +0900 Subject: [PATCH 2/6] Fix release builds --- .../RuntimeHelpers.NativeAot.cs | 10 + .../ConstructedEETypeNode.cs | 6 - .../Compiler/DependencyAnalysis/EETypeNode.cs | 14 +- .../Compiler/UsageBasedMetadataManager.cs | 11 +- .../tools/aot/ILCompiler/repro/Program.cs | 415 +++++++++++++++++- .../TrimmingBehaviors/DeadCodeElimination.cs | 20 +- 6 files changed, 446 insertions(+), 30 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs index bcbc4008351d0..551a067c8625c 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using Internal.Reflection.Augments; +using Internal.Reflection.Core.Execution; using Internal.Runtime; using Internal.Runtime.Augments; using System.Diagnostics.CodeAnalysis; @@ -347,6 +348,15 @@ public static unsafe object GetUninitializedObject( throw new NotSupportedException(SR.NotSupported_ByRefLike); } + Debug.Assert(MethodTable.Of()->NumVtableSlots > 0); + if (mt->NumVtableSlots == 0) + { + // This is a type without a vtable or GCDesc. We must not allow creating an instance of it + throw ReflectionCoreExecution.ExecutionDomain.CreateMissingMetadataException(type); + } + // Paranoid check: not-meant-for-GC-heap types should be reliably identifiable by empty vtable. + Debug.Assert(!mt->ContainsGCPointers || RuntimeImports.RhGetGCDescSize(new EETypePtr(mt)) != 0); + if (mt->IsNullable) { mt = mt->NullableType; diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ConstructedEETypeNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ConstructedEETypeNode.cs index 2d20dabfe94f7..28f193274c8bb 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ConstructedEETypeNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ConstructedEETypeNode.cs @@ -31,9 +31,6 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact // relocs to nodes we emit. dependencyList.Add(factory.NecessaryTypeSymbol(_type), "NecessaryType for constructed type"); - if(_type is MetadataType mdType) - ModuleUseBasedDependencyAlgorithm.AddDependenciesDueToModuleUse(ref dependencyList, factory, mdType.Module); - DefType closestDefType = _type.GetClosestDefType(); if (MightHaveInterfaceDispatchMap(factory)) @@ -75,9 +72,6 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact } } - // Ask the metadata manager if we have any dependencies due to the presence of the EEType. - factory.MetadataManager.GetDependenciesDueToEETypePresence(ref dependencyList, factory, _type); - factory.InteropStubManager.AddInterestingInteropConstructedTypeDependencies(ref dependencyList, factory, _type); return dependencyList; diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs index 01cde356ab263..df78c3032f5c2 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs @@ -622,16 +622,12 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact } } - if (!ConstructedEETypeNode.CreationAllowed(_type)) - { - // If necessary MethodTable is the highest load level for this type, ask the metadata manager - // if we have any dependencies due to presence of the EEType. - factory.MetadataManager.GetDependenciesDueToEETypePresence(ref dependencies, factory, _type); + // Ask the metadata manager + // if we have any dependencies due to presence of the EEType. + factory.MetadataManager.GetDependenciesDueToEETypePresence(ref dependencies, factory, _type); - // If necessary MethodTable is the highest load level, consider this a module use - if(_type is MetadataType mdType) - ModuleUseBasedDependencyAlgorithm.AddDependenciesDueToModuleUse(ref dependencies, factory, mdType.Module); - } + if (_type is MetadataType mdType) + ModuleUseBasedDependencyAlgorithm.AddDependenciesDueToModuleUse(ref dependencies, factory, mdType.Module); if (_type.IsFunctionPointer) FunctionPointerMapNode.GetHashtableDependencies(ref dependencies, factory, (FunctionPointerType)_type); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs index 883d077a9bcc4..47eee39d4b4be 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs @@ -629,20 +629,11 @@ public override IEnumerable GetCompilationModulesWithMetadata() private IEnumerable GetTypesWithRuntimeMapping() { // All constructed types that are not blocked get runtime mapping - foreach (var constructedType in GetTypesWithConstructedEETypes()) + foreach (var constructedType in GetTypesWithEETypes()) { if (!IsReflectionBlocked(constructedType)) yield return constructedType; } - - // All necessary types for which this is the highest load level that are not blocked - // get runtime mapping. - foreach (var necessaryType in GetTypesWithEETypes()) - { - if (!ConstructedEETypeNode.CreationAllowed(necessaryType) && - !IsReflectionBlocked(necessaryType)) - yield return necessaryType; - } } public override void GetDependenciesDueToAccess(ref DependencyList dependencies, NodeFactory factory, MethodIL methodIL, FieldDesc writtenField) diff --git a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs index 9e71394c3732a..79f391e03572a 100644 --- a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs +++ b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs @@ -1,12 +1,421 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#undef DEBUG + using System; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +DeadCodeElimination.Run(); -class Program + +class DeadCodeElimination { - static void Main() + public static int Run() + { + SanityTest.Run(); + TestInstanceMethodOptimization.Run(); + TestAbstractTypeNeverDerivedVirtualsOptimization.Run(); + TestAbstractNeverDerivedWithDevirtualizedCall.Run(); + TestAbstractDerivedByUnrelatedTypeWithDevirtualizedCall.Run(); + TestUnusedDefaultInterfaceMethod.Run(); + TestArrayElementTypeOperations.Run(); + TestStaticVirtualMethodOptimizations.Run(); + TestTypeEquals.Run(); + TestBranchesInGenericCodeRemoval.Run(); + + return 100; + } + + class SanityTest + { + class PresentType { } + + class NotPresentType { } + + public static void Run() + { + typeof(PresentType).ToString(); + + if (GetTypeSecretly(typeof(SanityTest), nameof(PresentType)) == null) + throw new Exception(); + + ThrowIfPresent(typeof(SanityTest), nameof(NotPresentType)); + } + } + + class TestInstanceMethodOptimization + { + class UnreferencedType { } + + class NeverAllocatedType + { + public Type DoSomething() => typeof(UnreferencedType); + } + +#if !DEBUG + static object s_instance = new object[10]; +#endif + + public static void Run() + { + Console.WriteLine("Testing instance methods on unallocated types"); + +#if DEBUG + NeverAllocatedType instance = null; + if (instance != null) + instance.DoSomething(); +#else + // In release builds additionally test that the "is" check didn't introduce the constructed type + if (s_instance is NeverAllocatedType never) + never.DoSomething(); +#endif + + ThrowIfPresent(typeof(TestInstanceMethodOptimization), nameof(UnreferencedType)); + } + } + + class TestAbstractTypeNeverDerivedVirtualsOptimization + { + class UnreferencedType1 + { + } + + class TheBase + { + public virtual object Something() => new object(); + } + + abstract class AbstractDerived : TheBase + { + // We expect "Something" to be generated as a throwing helper. + [MethodImpl(MethodImplOptions.NoInlining)] + public sealed override object Something() => new UnreferencedType1(); + // We expect "callvirt Something" to get devirtualized here. + [MethodImpl(MethodImplOptions.NoInlining)] + public object TrySomething() => Something(); + } + + abstract class AbstractDerivedAgain : AbstractDerived + { + } + + static TheBase s_b = new TheBase(); + static AbstractDerived s_d = null; + + public static void Run() + { + Console.WriteLine("Testing virtual methods on never derived abstract types"); + + // Make sure Something is seen virtually used. + s_b.Something(); + + // Force a constructed MethodTable for AbstractDerived and AbstractDerivedAgain into closure + typeof(AbstractDerivedAgain).ToString(); + + if (s_d != null) + { + s_d.TrySomething(); + } + + ThrowIfPresent(typeof(TestAbstractTypeNeverDerivedVirtualsOptimization), nameof(UnreferencedType1)); + } + } + + class TestAbstractNeverDerivedWithDevirtualizedCall + { + static void DoIt(Derived d) => d?.DoSomething(); + + abstract class Base + { + [MethodImpl(MethodImplOptions.NoInlining)] + public virtual void DoSomething() => new UnreferencedType1().ToString(); + } + + sealed class Derived : Base { } + + class UnreferencedType1 { } + + public static void Run() + { + Console.WriteLine("Testing abstract classes that might have methods reachable through devirtualization"); + + // Force a vtable for Base + typeof(Base).ToString(); + + // Do a devirtualizable virtual call to something that was never allocated + // and uses a virtual method implementation from Base. + DoIt(null); + + ThrowIfPresent(typeof(TestAbstractNeverDerivedWithDevirtualizedCall), nameof(UnreferencedType1)); + } + } + + class TestAbstractDerivedByUnrelatedTypeWithDevirtualizedCall + { + static void DoIt(Derived1 d) => d?.DoSomething(); + + abstract class Base + { + [MethodImpl(MethodImplOptions.NoInlining)] + public virtual void DoSomething() => new UnreferencedType1().ToString(); + } + + sealed class Derived1 : Base { } + + sealed class Derived2 : Base + { + public override void DoSomething() { } + } + + class UnreferencedType1 { } + + public static void Run() + { + Console.WriteLine("Testing more abstract classes that might have methods reachable through devirtualization"); + + // Force a vtable for Base + typeof(Base).ToString(); + + // Do a devirtualizable virtual call to something that was never allocated + // and uses a virtual method implementation from Base. + DoIt(null); + + new Derived2().DoSomething(); + + ThrowIfPresent(typeof(TestAbstractDerivedByUnrelatedTypeWithDevirtualizedCall), nameof(UnreferencedType1)); + } + } + + class TestUnusedDefaultInterfaceMethod + { + interface IFoo + { + void DoSomething(); + } + + interface IBar : IFoo + { + void IFoo.DoSomething() + { + Activator.CreateInstance(typeof(NeverReferenced)); + } + } + + class NeverReferenced { } + + class SomeInstance : IBar + { + void IFoo.DoSomething() { } + } + + static IFoo s_instance = new SomeInstance(); + + public static void Run() + { + s_instance.DoSomething(); + + ThrowIfPresent(typeof(TestUnusedDefaultInterfaceMethod), nameof(NeverReferenced)); + } + } + + class TestArrayElementTypeOperations + { + public static void Run() + { + Console.WriteLine("Testing array element type optimizations"); + + // We consider valuetype elements of arrays constructed... + { + Array arr = new NeverAllocated1[1]; + ThrowIfNotPresent(typeof(TestArrayElementTypeOperations), nameof(Marker1)); + + // The reason they're considered constructed is runtime magic here + // Make sure that works too. + object o = arr.GetValue(0); + if (!o.ToString().Contains(nameof(Marker1))) + throw new Exception(); + } + + // ...but not nullable... + { + Array arr = new Nullable[1]; + arr.GetValue(0); + ThrowIfPresent(typeof(TestArrayElementTypeOperations), nameof(Marker2)); + } + + + // ...or reference type element types + { + Array arr = new NeverAllocated3[1]; + arr.GetValue(0); + ThrowIfPresent(typeof(TestArrayElementTypeOperations), nameof(Marker3)); + } + } + + class Marker1 { } + struct NeverAllocated1 + { + public override string ToString() => typeof(Marker1).ToString(); + } + + class Marker2 { } + struct NeverAllocated2 + { + public override string ToString() => typeof(Marker2).ToString(); + } + + class Marker3 { } + class NeverAllocated3 + { + public override string ToString() => typeof(Marker3).ToString(); + } + } + + class TestStaticVirtualMethodOptimizations + { + interface IFoo + { + static abstract Type Frob(); + } + + struct StructWithReachableStaticVirtual : IFoo + { + public static Type Frob() => typeof(Marker1); + } + + class ClassWithUnreachableStaticVirtual : IFoo + { + public static Type Frob() => typeof(Marker2); + } + + class Marker1 { } + class Marker2 { } + + static Type Call() where T : IFoo => T.Frob(); + + public static void Run() + { + Console.WriteLine("Testing unused static virtual method optimization"); + + // No shared generic code - we should not see IFoo.Frob as "virtually used" + Call(); + + // Implements IFoo.Frob, but there's no consumption place, so won't be generated. + new ClassWithUnreachableStaticVirtual().ToString(); + + ThrowIfNotPresent(typeof(TestStaticVirtualMethodOptimizations), nameof(Marker1)); + ThrowIfPresent(typeof(TestStaticVirtualMethodOptimizations), nameof(Marker2)); + } + } + + class TestTypeEquals + { + sealed class Never { } + + static Type s_type = null; + + public static void Run() + { + // This was asserting the BCL because Never would not have reflection metadata + // despite the typeof + Console.WriteLine(s_type == typeof(Never)); + +#if !DEBUG + ThrowIfPresentWithUsableMethodTable(typeof(TestTypeEquals), nameof(Never)); +#endif + } + } + + class TestBranchesInGenericCodeRemoval + { + class ClassWithUnusedVirtual + { + public virtual string MyUnusedVirtualMethod() => typeof(UnusedFromVirtual).ToString(); + public virtual string MyUsedVirtualMethod() => typeof(UsedFromVirtual).ToString(); + } + + class UnusedFromVirtual { } + class UsedFromVirtual { } + + struct Unused { public byte Val; } + struct Used { public byte Val; } + + [MethodImpl(MethodImplOptions.NoInlining)] + static T Cast(byte o, ClassWithUnusedVirtual inst) + { + if (typeof(T) == typeof(Unused)) + { + // Expect this not to be scanned. The virtual slot should not be created. + inst.MyUnusedVirtualMethod(); + + Unused result = new Unused { Val = o }; + return (T)(object)result; + } + else if (typeof(T) == typeof(Used)) + { + // This will introduce a virtual slot. + inst.MyUsedVirtualMethod(); + + Used result = new Used { Val = o }; + return (T)(object)result; + } + return default; + } + + public static void Run() + { + Console.WriteLine("Testing dead branches guarded by typeof in generic code removal"); + + Cast(12, new ClassWithUnusedVirtual()); + + // We only expect to be able to get rid of it when optimizing +#if !DEBUG + ThrowIfPresentWithUsableMethodTable(typeof(TestBranchesInGenericCodeRemoval), nameof(Unused)); +#endif + ThrowIfNotPresent(typeof(TestBranchesInGenericCodeRemoval), nameof(Used)); + + ThrowIfPresent(typeof(TestBranchesInGenericCodeRemoval), nameof(UnusedFromVirtual)); + ThrowIfNotPresent(typeof(TestBranchesInGenericCodeRemoval), nameof(UsedFromVirtual)); + } + } + + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern", + Justification = "That's the point")] + private static Type GetTypeSecretly(Type testType, string typeName) => testType.GetNestedType(typeName, BindingFlags.NonPublic | BindingFlags.Public); + + private static void ThrowIfPresent(Type testType, string typeName) + { + if (GetTypeSecretly(testType, typeName) != null) + { + throw new Exception(typeName); + } + } + + private static void ThrowIfPresentWithUsableMethodTable(Type testType, string typeName) + { + Type t = GetTypeSecretly(testType, typeName); + if (t == null) + return; + + try + { + RuntimeHelpers.GetUninitializedObject(t); + + // Should have thrown NotSupported above. + throw new Exception(); + } + catch (NotSupportedException) { } + } + + private static void ThrowIfNotPresent(Type testType, string typeName) { - Console.WriteLine("Hello world"); + if (GetTypeSecretly(testType, typeName) == null) + { + throw new Exception(typeName); + } } } diff --git a/src/tests/nativeaot/SmokeTests/TrimmingBehaviors/DeadCodeElimination.cs b/src/tests/nativeaot/SmokeTests/TrimmingBehaviors/DeadCodeElimination.cs index e04e1c80ed2f3..152c851455666 100644 --- a/src/tests/nativeaot/SmokeTests/TrimmingBehaviors/DeadCodeElimination.cs +++ b/src/tests/nativeaot/SmokeTests/TrimmingBehaviors/DeadCodeElimination.cs @@ -320,7 +320,7 @@ public static void Run() Console.WriteLine(s_type == typeof(Never)); #if !DEBUG - ThrowIfPresent(typeof(TestTypeEquals), nameof(Never)); + ThrowIfPresentWithUsableMethodTable(typeof(TestTypeEquals), nameof(Never)); #endif } } @@ -369,7 +369,7 @@ public static void Run() // We only expect to be able to get rid of it when optimizing #if !DEBUG - ThrowIfPresent(typeof(TestBranchesInGenericCodeRemoval), nameof(Unused)); + ThrowIfPresentWithUsableMethodTable(typeof(TestBranchesInGenericCodeRemoval), nameof(Unused)); #endif ThrowIfNotPresent(typeof(TestBranchesInGenericCodeRemoval), nameof(Used)); @@ -390,6 +390,22 @@ private static void ThrowIfPresent(Type testType, string typeName) } } + private static void ThrowIfPresentWithUsableMethodTable(Type testType, string typeName) + { + Type t = GetTypeSecretly(testType, typeName); + if (t == null) + return; + + try + { + RuntimeHelpers.GetUninitializedObject(t); + + // Should have thrown NotSupported above. + throw new Exception(); + } + catch (NotSupportedException) { } + } + private static void ThrowIfNotPresent(Type testType, string typeName) { if (GetTypeSecretly(testType, typeName) == null) From 1b4915f8c24c575451d9a99006686cc9250c9d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Mon, 8 May 2023 10:51:05 +0900 Subject: [PATCH 3/6] Fix Unix size issue? --- .../src/System/Text/Latin1Encoding.cs | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs index 04d0e4f93e09a..811cabe1a06f1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs @@ -553,16 +553,13 @@ public override unsafe string GetString(byte[] bytes) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.bytes); } - return string.Create(bytes.Length, (encoding: this, bytes), static (chars, args) => + string result = string.FastAllocateString(bytes.Length); + fixed (byte* pBytes = bytes) + fixed (char* pChars = result) { - Debug.Assert(chars.Length == args.bytes.Length); - - fixed (byte* pBytes = args.bytes) - fixed (char* pChars = chars) - { - args.encoding.GetCharsCommon(pBytes, args.bytes.Length, pChars, chars.Length); - } - }); + GetCharsCommon(pBytes, bytes.Length, pChars, result.Length); + } + return result; } public override unsafe string GetString(byte[] bytes, int index, int count) @@ -586,14 +583,13 @@ public override unsafe string GetString(byte[] bytes, int index, int count) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer); } - return string.Create(count, (encoding: this, bytes, index), static (chars, args) => + string result = string.FastAllocateString(bytes.Length); + fixed (byte* pBytes = bytes) + fixed (char* pChars = result) { - fixed (byte* pBytes = args.bytes) - fixed (char* pChars = chars) - { - args.encoding.GetCharsCommon(pBytes + args.index, chars.Length, pChars, chars.Length); - } - }); + GetCharsCommon(pBytes + index, bytes.Length - index, pChars, result.Length); + } + return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] From a7a7251d9d86770266fbb42751318e2099c7bc0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Mon, 8 May 2023 11:23:22 +0900 Subject: [PATCH 4/6] Don't touch repro project --- .../tools/aot/ILCompiler/repro/Program.cs | 415 +----------------- 1 file changed, 3 insertions(+), 412 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs index 79f391e03572a..9e71394c3732a 100644 --- a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs +++ b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs @@ -1,421 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#undef DEBUG - using System; -using System.Diagnostics.CodeAnalysis; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -DeadCodeElimination.Run(); - -class DeadCodeElimination +class Program { - public static int Run() - { - SanityTest.Run(); - TestInstanceMethodOptimization.Run(); - TestAbstractTypeNeverDerivedVirtualsOptimization.Run(); - TestAbstractNeverDerivedWithDevirtualizedCall.Run(); - TestAbstractDerivedByUnrelatedTypeWithDevirtualizedCall.Run(); - TestUnusedDefaultInterfaceMethod.Run(); - TestArrayElementTypeOperations.Run(); - TestStaticVirtualMethodOptimizations.Run(); - TestTypeEquals.Run(); - TestBranchesInGenericCodeRemoval.Run(); - - return 100; - } - - class SanityTest - { - class PresentType { } - - class NotPresentType { } - - public static void Run() - { - typeof(PresentType).ToString(); - - if (GetTypeSecretly(typeof(SanityTest), nameof(PresentType)) == null) - throw new Exception(); - - ThrowIfPresent(typeof(SanityTest), nameof(NotPresentType)); - } - } - - class TestInstanceMethodOptimization - { - class UnreferencedType { } - - class NeverAllocatedType - { - public Type DoSomething() => typeof(UnreferencedType); - } - -#if !DEBUG - static object s_instance = new object[10]; -#endif - - public static void Run() - { - Console.WriteLine("Testing instance methods on unallocated types"); - -#if DEBUG - NeverAllocatedType instance = null; - if (instance != null) - instance.DoSomething(); -#else - // In release builds additionally test that the "is" check didn't introduce the constructed type - if (s_instance is NeverAllocatedType never) - never.DoSomething(); -#endif - - ThrowIfPresent(typeof(TestInstanceMethodOptimization), nameof(UnreferencedType)); - } - } - - class TestAbstractTypeNeverDerivedVirtualsOptimization - { - class UnreferencedType1 - { - } - - class TheBase - { - public virtual object Something() => new object(); - } - - abstract class AbstractDerived : TheBase - { - // We expect "Something" to be generated as a throwing helper. - [MethodImpl(MethodImplOptions.NoInlining)] - public sealed override object Something() => new UnreferencedType1(); - // We expect "callvirt Something" to get devirtualized here. - [MethodImpl(MethodImplOptions.NoInlining)] - public object TrySomething() => Something(); - } - - abstract class AbstractDerivedAgain : AbstractDerived - { - } - - static TheBase s_b = new TheBase(); - static AbstractDerived s_d = null; - - public static void Run() - { - Console.WriteLine("Testing virtual methods on never derived abstract types"); - - // Make sure Something is seen virtually used. - s_b.Something(); - - // Force a constructed MethodTable for AbstractDerived and AbstractDerivedAgain into closure - typeof(AbstractDerivedAgain).ToString(); - - if (s_d != null) - { - s_d.TrySomething(); - } - - ThrowIfPresent(typeof(TestAbstractTypeNeverDerivedVirtualsOptimization), nameof(UnreferencedType1)); - } - } - - class TestAbstractNeverDerivedWithDevirtualizedCall - { - static void DoIt(Derived d) => d?.DoSomething(); - - abstract class Base - { - [MethodImpl(MethodImplOptions.NoInlining)] - public virtual void DoSomething() => new UnreferencedType1().ToString(); - } - - sealed class Derived : Base { } - - class UnreferencedType1 { } - - public static void Run() - { - Console.WriteLine("Testing abstract classes that might have methods reachable through devirtualization"); - - // Force a vtable for Base - typeof(Base).ToString(); - - // Do a devirtualizable virtual call to something that was never allocated - // and uses a virtual method implementation from Base. - DoIt(null); - - ThrowIfPresent(typeof(TestAbstractNeverDerivedWithDevirtualizedCall), nameof(UnreferencedType1)); - } - } - - class TestAbstractDerivedByUnrelatedTypeWithDevirtualizedCall - { - static void DoIt(Derived1 d) => d?.DoSomething(); - - abstract class Base - { - [MethodImpl(MethodImplOptions.NoInlining)] - public virtual void DoSomething() => new UnreferencedType1().ToString(); - } - - sealed class Derived1 : Base { } - - sealed class Derived2 : Base - { - public override void DoSomething() { } - } - - class UnreferencedType1 { } - - public static void Run() - { - Console.WriteLine("Testing more abstract classes that might have methods reachable through devirtualization"); - - // Force a vtable for Base - typeof(Base).ToString(); - - // Do a devirtualizable virtual call to something that was never allocated - // and uses a virtual method implementation from Base. - DoIt(null); - - new Derived2().DoSomething(); - - ThrowIfPresent(typeof(TestAbstractDerivedByUnrelatedTypeWithDevirtualizedCall), nameof(UnreferencedType1)); - } - } - - class TestUnusedDefaultInterfaceMethod - { - interface IFoo - { - void DoSomething(); - } - - interface IBar : IFoo - { - void IFoo.DoSomething() - { - Activator.CreateInstance(typeof(NeverReferenced)); - } - } - - class NeverReferenced { } - - class SomeInstance : IBar - { - void IFoo.DoSomething() { } - } - - static IFoo s_instance = new SomeInstance(); - - public static void Run() - { - s_instance.DoSomething(); - - ThrowIfPresent(typeof(TestUnusedDefaultInterfaceMethod), nameof(NeverReferenced)); - } - } - - class TestArrayElementTypeOperations - { - public static void Run() - { - Console.WriteLine("Testing array element type optimizations"); - - // We consider valuetype elements of arrays constructed... - { - Array arr = new NeverAllocated1[1]; - ThrowIfNotPresent(typeof(TestArrayElementTypeOperations), nameof(Marker1)); - - // The reason they're considered constructed is runtime magic here - // Make sure that works too. - object o = arr.GetValue(0); - if (!o.ToString().Contains(nameof(Marker1))) - throw new Exception(); - } - - // ...but not nullable... - { - Array arr = new Nullable[1]; - arr.GetValue(0); - ThrowIfPresent(typeof(TestArrayElementTypeOperations), nameof(Marker2)); - } - - - // ...or reference type element types - { - Array arr = new NeverAllocated3[1]; - arr.GetValue(0); - ThrowIfPresent(typeof(TestArrayElementTypeOperations), nameof(Marker3)); - } - } - - class Marker1 { } - struct NeverAllocated1 - { - public override string ToString() => typeof(Marker1).ToString(); - } - - class Marker2 { } - struct NeverAllocated2 - { - public override string ToString() => typeof(Marker2).ToString(); - } - - class Marker3 { } - class NeverAllocated3 - { - public override string ToString() => typeof(Marker3).ToString(); - } - } - - class TestStaticVirtualMethodOptimizations - { - interface IFoo - { - static abstract Type Frob(); - } - - struct StructWithReachableStaticVirtual : IFoo - { - public static Type Frob() => typeof(Marker1); - } - - class ClassWithUnreachableStaticVirtual : IFoo - { - public static Type Frob() => typeof(Marker2); - } - - class Marker1 { } - class Marker2 { } - - static Type Call() where T : IFoo => T.Frob(); - - public static void Run() - { - Console.WriteLine("Testing unused static virtual method optimization"); - - // No shared generic code - we should not see IFoo.Frob as "virtually used" - Call(); - - // Implements IFoo.Frob, but there's no consumption place, so won't be generated. - new ClassWithUnreachableStaticVirtual().ToString(); - - ThrowIfNotPresent(typeof(TestStaticVirtualMethodOptimizations), nameof(Marker1)); - ThrowIfPresent(typeof(TestStaticVirtualMethodOptimizations), nameof(Marker2)); - } - } - - class TestTypeEquals - { - sealed class Never { } - - static Type s_type = null; - - public static void Run() - { - // This was asserting the BCL because Never would not have reflection metadata - // despite the typeof - Console.WriteLine(s_type == typeof(Never)); - -#if !DEBUG - ThrowIfPresentWithUsableMethodTable(typeof(TestTypeEquals), nameof(Never)); -#endif - } - } - - class TestBranchesInGenericCodeRemoval - { - class ClassWithUnusedVirtual - { - public virtual string MyUnusedVirtualMethod() => typeof(UnusedFromVirtual).ToString(); - public virtual string MyUsedVirtualMethod() => typeof(UsedFromVirtual).ToString(); - } - - class UnusedFromVirtual { } - class UsedFromVirtual { } - - struct Unused { public byte Val; } - struct Used { public byte Val; } - - [MethodImpl(MethodImplOptions.NoInlining)] - static T Cast(byte o, ClassWithUnusedVirtual inst) - { - if (typeof(T) == typeof(Unused)) - { - // Expect this not to be scanned. The virtual slot should not be created. - inst.MyUnusedVirtualMethod(); - - Unused result = new Unused { Val = o }; - return (T)(object)result; - } - else if (typeof(T) == typeof(Used)) - { - // This will introduce a virtual slot. - inst.MyUsedVirtualMethod(); - - Used result = new Used { Val = o }; - return (T)(object)result; - } - return default; - } - - public static void Run() - { - Console.WriteLine("Testing dead branches guarded by typeof in generic code removal"); - - Cast(12, new ClassWithUnusedVirtual()); - - // We only expect to be able to get rid of it when optimizing -#if !DEBUG - ThrowIfPresentWithUsableMethodTable(typeof(TestBranchesInGenericCodeRemoval), nameof(Unused)); -#endif - ThrowIfNotPresent(typeof(TestBranchesInGenericCodeRemoval), nameof(Used)); - - ThrowIfPresent(typeof(TestBranchesInGenericCodeRemoval), nameof(UnusedFromVirtual)); - ThrowIfNotPresent(typeof(TestBranchesInGenericCodeRemoval), nameof(UsedFromVirtual)); - } - } - - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern", - Justification = "That's the point")] - private static Type GetTypeSecretly(Type testType, string typeName) => testType.GetNestedType(typeName, BindingFlags.NonPublic | BindingFlags.Public); - - private static void ThrowIfPresent(Type testType, string typeName) - { - if (GetTypeSecretly(testType, typeName) != null) - { - throw new Exception(typeName); - } - } - - private static void ThrowIfPresentWithUsableMethodTable(Type testType, string typeName) - { - Type t = GetTypeSecretly(testType, typeName); - if (t == null) - return; - - try - { - RuntimeHelpers.GetUninitializedObject(t); - - // Should have thrown NotSupported above. - throw new Exception(); - } - catch (NotSupportedException) { } - } - - private static void ThrowIfNotPresent(Type testType, string typeName) + static void Main() { - if (GetTypeSecretly(testType, typeName) == null) - { - throw new Exception(typeName); - } + Console.WriteLine("Hello world"); } } From 8c2c5ee423c4e76837f93c54a9abf40e154dd303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Mon, 8 May 2023 12:10:14 +0900 Subject: [PATCH 5/6] Update src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs Co-authored-by: Jan Kotas --- .../System.Private.CoreLib/src/System/Text/Latin1Encoding.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs index 811cabe1a06f1..f495057c760cd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs @@ -583,7 +583,7 @@ public override unsafe string GetString(byte[] bytes, int index, int count) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer); } - string result = string.FastAllocateString(bytes.Length); + string result = string.FastAllocateString(count); fixed (byte* pBytes = bytes) fixed (char* pChars = result) { From 5cfb2569e42e9dc40fa18e7822f78fd3cb476454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Mon, 8 May 2023 12:28:54 +0900 Subject: [PATCH 6/6] Update src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs Co-authored-by: Jan Kotas --- .../System.Private.CoreLib/src/System/Text/Latin1Encoding.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs index f495057c760cd..7dd5ee233bcd9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs @@ -587,7 +587,7 @@ public override unsafe string GetString(byte[] bytes, int index, int count) fixed (byte* pBytes = bytes) fixed (char* pChars = result) { - GetCharsCommon(pBytes + index, bytes.Length - index, pChars, result.Length); + GetCharsCommon(pBytes + index, count, pChars, count); } return result; }