diff options
author | Michal Strehovský <MichalStrehovsky@users.noreply.github.com> | 2017-05-23 07:07:08 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2017-05-23 07:07:08 +0300 |
commit | 9a1e20d87876237005a46ecf9ca0ce69524f3b6e (patch) | |
tree | 9c3dcea7d5a27a2c1b5e37fb32f758afd480cf63 /src | |
parent | a806c3f2aadeda028dc3c1ba8cd41534235b0064 (diff) |
Restore ability to compile against Test.CoreLib (#3674)
Building against the lightweight version of S.P.CoreLib has bitrotted
over the past year. The classlib is handy for codegen and architecture
bringups and we might want to use it when getting rid of ready to run
helpers.
Diffstat (limited to 'src')
9 files changed, 51 insertions, 9 deletions
diff --git a/src/Common/src/TypeSystem/IL/HelperExtensions.cs b/src/Common/src/TypeSystem/IL/HelperExtensions.cs index e49be4df4..694430c8c 100644 --- a/src/Common/src/TypeSystem/IL/HelperExtensions.cs +++ b/src/Common/src/TypeSystem/IL/HelperExtensions.cs @@ -80,10 +80,10 @@ namespace Internal.IL /// Retrieves a namespace type in <paramref name= "module" /> that is well known to the compiler. /// Throws an exception if the type doesn't exist. /// </summary> - public static MetadataType GetKnownType(this ModuleDesc module, string @namespace, string name) + public static MetadataType GetKnownType(this ModuleDesc module, string @namespace, string name, bool throwIfNotFound = true) { MetadataType type = module.GetType(@namespace, name, false); - if (type == null) + if (type == null && throwIfNotFound) { throw new InvalidOperationException( String.Format("Expected type '{0}' not found in module '{1}'", diff --git a/src/Common/src/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs b/src/Common/src/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs index ecfff05a2..68c89d880 100644 --- a/src/Common/src/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs +++ b/src/Common/src/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs @@ -32,6 +32,11 @@ namespace Internal.IL.Stubs _targetSignature = signature; } + public static bool SupportsThunks(TypeSystemContext context) + { + return context.SystemModule.GetType("System", "InvokeUtils", false) != null; + } + public override TypeSystemContext Context { get diff --git a/src/Common/src/TypeSystem/Interop/InteropTypes.cs b/src/Common/src/TypeSystem/Interop/InteropTypes.cs index bbace938c..14f0d01a8 100644 --- a/src/Common/src/TypeSystem/Interop/InteropTypes.cs +++ b/src/Common/src/TypeSystem/Interop/InteropTypes.cs @@ -4,6 +4,8 @@ using Internal.IL; +using Debug = System.Diagnostics.Debug; + namespace Internal.TypeSystem.Interop { public static class InteropTypes @@ -50,9 +52,9 @@ namespace Internal.TypeSystem.Interop return context.SystemModule.GetKnownType("System.Runtime.InteropServices", "NativeFunctionPointerWrapper"); } - public static MetadataType GetStringBuilder(TypeSystemContext context) + public static MetadataType GetStringBuilder(TypeSystemContext context, bool throwIfNotFound = true) { - return context.SystemModule.GetKnownType("System.Text", "StringBuilder"); + return context.SystemModule.GetKnownType("System.Text", "StringBuilder", throwIfNotFound); } public static MetadataType GetSystemArray(TypeSystemContext context) @@ -107,7 +109,8 @@ namespace Internal.TypeSystem.Interop public static bool IsStringBuilder(TypeSystemContext context, TypeDesc type) { - return type == GetStringBuilder(context); + Debug.Assert(type != null); + return type == GetStringBuilder(context, throwIfNotFound: false); } public static bool IsSystemDecimal(TypeSystemContext context, TypeDesc type) diff --git a/src/ILCompiler.Compiler/src/Compiler/CompilerGeneratedMetadataManager.cs b/src/ILCompiler.Compiler/src/Compiler/CompilerGeneratedMetadataManager.cs index 9026446e2..495b837f7 100644 --- a/src/ILCompiler.Compiler/src/Compiler/CompilerGeneratedMetadataManager.cs +++ b/src/ILCompiler.Compiler/src/Compiler/CompilerGeneratedMetadataManager.cs @@ -26,12 +26,17 @@ namespace ILCompiler public sealed class CompilerGeneratedMetadataManager : MetadataManager { private readonly string _metadataLogFile; - private Dictionary<DynamicInvokeMethodSignature, MethodDesc> _dynamicInvokeThunks = new Dictionary<DynamicInvokeMethodSignature, MethodDesc>(); + private Dictionary<DynamicInvokeMethodSignature, MethodDesc> _dynamicInvokeThunks; public CompilerGeneratedMetadataManager(CompilationModuleGroup group, CompilerTypeSystemContext typeSystemContext, string logFile) : base(group, typeSystemContext, new BlockedInternalsBlockingPolicy()) { _metadataLogFile = logFile; + + if (DynamicInvokeMethodThunk.SupportsThunks(typeSystemContext)) + { + _dynamicInvokeThunks = new Dictionary<DynamicInvokeMethodSignature, MethodDesc>(); + } } public override bool WillUseMetadataTokenToReferenceMethod(MethodDesc method) @@ -183,6 +188,9 @@ namespace ILCompiler { Debug.Assert(IsReflectionInvokable(method)); + if (_dynamicInvokeThunks == null) + return false; + // Place an upper limit on how many parameters a method can have to still get a static stub. // From the past experience, methods taking 8000+ parameters get a stub that can hit various limitations // in the codegen. On Project N, we were limited to 256 parameters because of MDIL limitations. diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/CodeBasedDependencyAlgorithm.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/CodeBasedDependencyAlgorithm.cs index 67540126d..48fcdea9e 100644 --- a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/CodeBasedDependencyAlgorithm.cs +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/CodeBasedDependencyAlgorithm.cs @@ -29,7 +29,7 @@ namespace ILCompiler.DependencyAnalysis dependencies = new DependencyList(); if (factory.MetadataManager.HasReflectionInvokeStubForInvokableMethod(method) - && (factory.Target.Abi != TargetAbi.ProjectN) || !method.IsCanonicalMethod(CanonicalFormKind.Any)) + && ((factory.Target.Abi != TargetAbi.ProjectN) || !method.IsCanonicalMethod(CanonicalFormKind.Any))) { MethodDesc canonInvokeStub = factory.MetadataManager.GetCanonicalReflectionInvokeStub(method); if (canonInvokeStub.IsSharedByGenericInstantiations) diff --git a/src/JitInterface/src/CorInfoImpl.cs b/src/JitInterface/src/CorInfoImpl.cs index e5296ddce..f20ab5a89 100644 --- a/src/JitInterface/src/CorInfoImpl.cs +++ b/src/JitInterface/src/CorInfoImpl.cs @@ -1675,7 +1675,8 @@ namespace Internal.JitInterface TypeDesc fieldType = fieldDesc.FieldType; CorInfoType type = asCorInfoType(fieldType, out structType); - Debug.Assert(_compilation.TypeSystemContext.GetWellKnownType(WellKnownType.ByReferenceOfT).GetKnownField("_value").FieldType.Category == TypeFlags.IntPtr); + Debug.Assert(!fieldDesc.OwningType.IsByReferenceOfT || + fieldDesc.OwningType.GetKnownField("_value").FieldType.Category == TypeFlags.IntPtr); if (type == CorInfoType.CORINFO_TYPE_NATIVEINT && fieldDesc.OwningType.IsByReferenceOfT) { Debug.Assert(structType == null); diff --git a/src/Runtime.Base/src/System/Array.cs b/src/Runtime.Base/src/System/Array.cs index 1a8547377..d25231f64 100644 --- a/src/Runtime.Base/src/System/Array.cs +++ b/src/Runtime.Base/src/System/Array.cs @@ -11,7 +11,7 @@ namespace System // The Array type is one of the primitives understood by the compilers and runtime // Data Contract: Single field of type int - public class Array + public partial class Array { // CS0649: Field '{blah}' is never assigned to, and will always have its default value #pragma warning disable 649 diff --git a/src/Test.CoreLib/src/System/Array.cs b/src/Test.CoreLib/src/System/Array.cs new file mode 100644 index 000000000..2c06a91d8 --- /dev/null +++ b/src/Test.CoreLib/src/System/Array.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Runtime; + +using EEType = Internal.Runtime.EEType; + +namespace System +{ + partial class Array + { + // This is the classlib-provided "get array eetype" function that will be invoked whenever the runtime + // needs to know the base type of an array. + [RuntimeExport("GetSystemArrayEEType")] + private static unsafe EEType* GetSystemArrayEEType() + { + return EETypePtr.EETypePtrOf<Array>().ToPointer(); + } + } +} diff --git a/src/Test.CoreLib/src/Test.CoreLib.csproj b/src/Test.CoreLib/src/Test.CoreLib.csproj index 6d56898e1..7322f6afe 100644 --- a/src/Test.CoreLib/src/Test.CoreLib.csproj +++ b/src/Test.CoreLib/src/Test.CoreLib.csproj @@ -142,6 +142,9 @@ <Compile Include="..\..\Runtime.Base\src\System\Diagnostics\Debug.cs"> <Link>System\Diagnostics\Debug.cs</Link> </Compile> + <Compile Include="..\..\Runtime.Base\src\System\Diagnostics\Eval.cs"> + <Link>System\Diagnostics\Eval.cs</Link> + </Compile> <Compile Include="..\..\Runtime.Base\src\System\Exception.cs"> <Link>System\Exception.cs</Link> </Compile> @@ -245,6 +248,7 @@ <Compile Include="System\Runtime\CompilerServices\StaticClassConstructionContext.cs" /> <Compile Include="System\Runtime\RuntimeImports.cs" /> <Compile Include="System\Threading\Interlocked.cs" /> + <Compile Include="System\Array.cs" /> <Compile Include="System\RuntimeExceptionHelpers.cs" /> <Compile Include="System\Object.cs" /> <Compile Include="..\..\Common\src\Internal\Runtime\TypeManagerHandle.cs"> |