diff options
author | Michal Strehovský <michals@microsoft.com> | 2017-12-28 23:03:17 +0300 |
---|---|---|
committer | Michal Strehovský <michals@microsoft.com> | 2017-12-28 23:03:17 +0300 |
commit | 3063f7a1b61efb3a2a4b34892e90f830d0849ef4 (patch) | |
tree | e69735b0a108020b7a592dd98959574057cadc58 | |
parent | 843f6ab3477eeb36f221d502e5ceaa780ac6c503 (diff) |
Consider methods on `Array<T>` blocked
These show up in random places. We should treat them as reflection blocked.
-rw-r--r-- | src/ILCompiler.Compiler/src/Compiler/BlockedInternalsBlockingPolicy.cs | 23 | ||||
-rw-r--r-- | src/ILCompiler.Compiler/src/Compiler/UsageBasedMetadataManager.cs | 6 |
2 files changed, 23 insertions, 6 deletions
diff --git a/src/ILCompiler.Compiler/src/Compiler/BlockedInternalsBlockingPolicy.cs b/src/ILCompiler.Compiler/src/Compiler/BlockedInternalsBlockingPolicy.cs index da6759197..9a19e31ae 100644 --- a/src/ILCompiler.Compiler/src/Compiler/BlockedInternalsBlockingPolicy.cs +++ b/src/ILCompiler.Compiler/src/Compiler/BlockedInternalsBlockingPolicy.cs @@ -115,6 +115,21 @@ namespace ILCompiler } private BlockedTypeHashtable _blockedTypes; + private MetadataType _arrayOfTType; + private MetadataType InitializeArrayOfTType(TypeSystemEntity contextEntity) + { + _arrayOfTType = contextEntity.Context.SystemModule.GetType("System", "Array`1"); + return _arrayOfTType; + } + private MetadataType GetArrayOfTType(TypeSystemEntity contextEntity) + { + if (_arrayOfTType != null) + { + return _arrayOfTType; + } + return InitializeArrayOfTType(contextEntity); + } + public BlockedInternalsBlockingPolicy() { _blockedTypes = new BlockedTypeHashtable(_blockedModules); @@ -146,6 +161,14 @@ namespace ILCompiler { if ((ecmaMethod.Attributes & MethodAttributes.Public) != MethodAttributes.Public) return true; + + // Methods on Array`1<T> 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<T> as their owning type, or + // * Make these methods implement the interfaces explicitly (they would become private and naturally blocked) + if (ecmaMethod.OwningType == GetArrayOfTType(ecmaMethod)) + return true; } return false; diff --git a/src/ILCompiler.Compiler/src/Compiler/UsageBasedMetadataManager.cs b/src/ILCompiler.Compiler/src/Compiler/UsageBasedMetadataManager.cs index 6100d991f..d7287c03e 100644 --- a/src/ILCompiler.Compiler/src/Compiler/UsageBasedMetadataManager.cs +++ b/src/ILCompiler.Compiler/src/Compiler/UsageBasedMetadataManager.cs @@ -130,18 +130,12 @@ namespace ILCompiler protected override void GetMetadataDependenciesDueToReflectability(ref DependencyList dependencies, NodeFactory factory, MethodDesc method) { - if (method.GetTypicalMethodDefinition().OwningType == factory.ArrayOfTClass) - return; - dependencies = dependencies ?? new DependencyList(); dependencies.Add(factory.MethodMetadata(method.GetTypicalMethodDefinition()), "Reflectable method"); } protected override void GetMetadataDependenciesDueToReflectability(ref DependencyList dependencies, NodeFactory factory, TypeDesc type) { - if (type.GetTypeDefinition() == factory.ArrayOfTClass) - return; - TypeMetadataNode.GetMetadataDependencies(ref dependencies, factory, type, "Reflectable type"); // If we don't have precise field usage information, apply policy that all fields that |