diff options
Diffstat (limited to 'src/ILCompiler.Compiler/src/Compiler/MetadataManager.cs')
-rw-r--r-- | src/ILCompiler.Compiler/src/Compiler/MetadataManager.cs | 142 |
1 files changed, 18 insertions, 124 deletions
diff --git a/src/ILCompiler.Compiler/src/Compiler/MetadataManager.cs b/src/ILCompiler.Compiler/src/Compiler/MetadataManager.cs index 2c2c6123b..31526a097 100644 --- a/src/ILCompiler.Compiler/src/Compiler/MetadataManager.cs +++ b/src/ILCompiler.Compiler/src/Compiler/MetadataManager.cs @@ -42,6 +42,8 @@ namespace ILCompiler protected readonly CompilerTypeSystemContext _typeSystemContext; protected readonly MetadataBlockingPolicy _blockingPolicy; + protected readonly ManifestResourceBlockingPolicy _resourceBlockingPolicy; + protected readonly DynamicInvokeThunkGenerationPolicy _dynamicInvokeThunkGenerationPolicy; private List<NonGCStaticsNode> _cctorContextsGenerated = new List<NonGCStaticsNode>(); private HashSet<TypeDesc> _typesWithEETypesGenerated = new HashSet<TypeDesc>(); @@ -50,16 +52,18 @@ namespace ILCompiler private HashSet<GenericDictionaryNode> _genericDictionariesGenerated = new HashSet<GenericDictionaryNode>(); private HashSet<IMethodBodyNode> _methodBodiesGenerated = new HashSet<IMethodBodyNode>(); private List<TypeGVMEntriesNode> _typeGVMEntries = new List<TypeGVMEntriesNode>(); - private HashSet<DefaultConstructorFromLazyNode> _defaultConstructorsNeeded = new HashSet<DefaultConstructorFromLazyNode>(); internal NativeLayoutInfoNode NativeLayoutInfo { get; private set; } internal DynamicInvokeTemplateDataNode DynamicInvokeTemplateData { get; private set; } public virtual bool SupportsReflection => true; - public MetadataManager(CompilerTypeSystemContext typeSystemContext, MetadataBlockingPolicy blockingPolicy) + public MetadataManager(CompilerTypeSystemContext typeSystemContext, MetadataBlockingPolicy blockingPolicy, + ManifestResourceBlockingPolicy resourceBlockingPolicy, DynamicInvokeThunkGenerationPolicy dynamicInvokeThunkGenerationPolicy) { _typeSystemContext = typeSystemContext; _blockingPolicy = blockingPolicy; + _resourceBlockingPolicy = resourceBlockingPolicy; + _dynamicInvokeThunkGenerationPolicy = dynamicInvokeThunkGenerationPolicy; } public void AttachToDependencyGraph(DependencyAnalyzerBase<NodeFactory> graph) @@ -205,12 +209,6 @@ namespace ILCompiler { _genericDictionariesGenerated.Add(dictionaryNode); } - - var ctorFromLazyGenericsNode = obj as DefaultConstructorFromLazyNode; - if (ctorFromLazyGenericsNode != null) - { - _defaultConstructorsNeeded.Add(ctorFromLazyGenericsNode); - } } /// <summary> @@ -218,60 +216,10 @@ namespace ILCompiler /// </summary> public virtual bool IsReflectionInvokable(MethodDesc method) { - return IsMethodSignatureSupportedInReflectionInvoke(method) + return Internal.IL.Stubs.DynamicInvokeMethodThunk.SupportsSignature(method.Signature) && IsMethodSupportedInReflectionInvoke(method); } - protected bool IsMethodSignatureSupportedInReflectionInvoke(MethodDesc method) - { - var signature = method.Signature; - - // ---------------------------------------------------------------- - // TODO: support for methods returning pointer types - https://github.com/dotnet/corert/issues/2113 - // ---------------------------------------------------------------- - - if (signature.ReturnType.IsPointer) - return false; - - for (int i = 0; i < signature.Length; i++) - if (signature[i].IsByRef && ((ByRefType)signature[i]).ParameterType.IsPointer) - return false; - - // ---------------------------------------------------------------- - // TODO: function pointer types are odd: https://github.com/dotnet/corert/issues/1929 - // ---------------------------------------------------------------- - - if (signature.ReturnType.IsFunctionPointer) - return false; - - for (int i = 0; i < signature.Length; i++) - if (signature[i].IsFunctionPointer) - return false; - - // ---------------------------------------------------------------- - // Methods with ByRef returns can't be reflection invoked - // ---------------------------------------------------------------- - - if (signature.ReturnType.IsByRef) - return false; - - // ---------------------------------------------------------------- - // Methods that return ByRef-like types or take them by reference can't be reflection invoked - // ---------------------------------------------------------------- - - if (signature.ReturnType.IsByRefLike) - return false; - - for (int i = 0; i < signature.Length; i++) - { - ByRefType paramType = signature[i] as ByRefType; - if (paramType != null && paramType.ParameterType.IsByRefLike) - return false; - } - - return true; - } - protected bool IsMethodSupportedInReflectionInvoke(MethodDesc method) { TypeDesc owningType = method.OwningType; @@ -430,7 +378,11 @@ namespace ILCompiler /// <summary> /// Given that a method is invokable, does there exist a reflection invoke stub? /// </summary> - public abstract bool HasReflectionInvokeStubForInvokableMethod(MethodDesc method); + public bool HasReflectionInvokeStubForInvokableMethod(MethodDesc method) + { + Debug.Assert(IsReflectionInvokable(method)); + return _dynamicInvokeThunkGenerationPolicy.HasStaticInvokeThunk(method); + } /// <summary> /// Given that a method is invokable, if it is inserted into the reflection invoke table @@ -470,65 +422,7 @@ namespace ILCompiler // Instantiate the generic thunk over the parameters and the return type of the target method // - ParameterMetadata[] paramMetadata = null; - TypeDesc[] instantiation = new TypeDesc[sig.ReturnType.IsVoid ? sig.Length : sig.Length + 1]; - Debug.Assert(thunk.Instantiation.Length == instantiation.Length); - for (int i = 0; i < sig.Length; i++) - { - TypeDesc parameterType = sig[i]; - if (parameterType.IsByRef) - { - // strip ByRefType off the parameter (the method already has ByRef in the signature) - parameterType = ((ByRefType)parameterType).ParameterType; - - Debug.Assert(!parameterType.IsPointer); // TODO: support for methods returning pointer types - https://github.com/dotnet/corert/issues/2113 - } - else if (parameterType.IsPointer || parameterType.IsFunctionPointer) - { - // For pointer typed parameters, instantiate the method over IntPtr - parameterType = context.GetWellKnownType(WellKnownType.IntPtr); - } - else if (parameterType.IsEnum) - { - // If the invoke method takes an enum as an input parameter and there is no default value for - // that paramter, we don't need to specialize on the exact enum type (we only need to specialize - // on the underlying integral type of the enum.) - if (paramMetadata == null) - paramMetadata = method.GetParameterMetadata(); - - bool hasDefaultValue = false; - foreach (var p in paramMetadata) - { - // Parameter metadata indexes are 1-based (0 is reserved for return "parameter") - if (p.Index == (i + 1) && p.HasDefault) - { - hasDefaultValue = true; - break; - } - } - - if (!hasDefaultValue) - parameterType = parameterType.UnderlyingType; - } - - instantiation[i] = parameterType; - } - - if (!sig.ReturnType.IsVoid) - { - TypeDesc returnType = sig.ReturnType; - Debug.Assert(!returnType.IsByRef); - - // If the invoke method return an object reference, we don't need to specialize on the - // exact type of the object reference, as the behavior is not different. - if ((returnType.IsDefType && !returnType.IsValueType) || returnType.IsArray) - { - returnType = context.GetWellKnownType(WellKnownType.Object); - } - - instantiation[sig.Length] = returnType; - } - + TypeDesc[] instantiation = Internal.IL.Stubs.DynamicInvokeMethodThunk.GetThunkInstantiationForMethod(method); Debug.Assert(thunk.Instantiation.Length == instantiation.Length); // Check if at least one of the instantiation arguments is a universal canonical type, and if so, we @@ -683,11 +577,6 @@ namespace ILCompiler return _methodBodiesGenerated; } - internal IEnumerable<DefaultConstructorFromLazyNode> GetDefaultConstructorsNeeded() - { - return _defaultConstructorsNeeded; - } - internal bool TypeGeneratesEEType(TypeDesc type) { return _typesWithEETypesGenerated.Contains(type); @@ -777,6 +666,11 @@ namespace ILCompiler return _blockingPolicy.IsBlocked(typicalMethodDefinition); } + public bool IsManifestResourceBlocked(ModuleDesc module, string resourceName) + { + return _resourceBlockingPolicy.IsManifestResourceBlocked(module, resourceName); + } + public bool CanGenerateMetadata(MetadataType type) { return (GetMetadataCategory(type) & MetadataCategory.Description) != 0; |