diff --git a/src/coreclr/tools/Common/Compiler/TypeExtensions.cs b/src/coreclr/tools/Common/Compiler/TypeExtensions.cs index 8042359e8784ad..df3282e24ce80c 100644 --- a/src/coreclr/tools/Common/Compiler/TypeExtensions.cs +++ b/src/coreclr/tools/Common/Compiler/TypeExtensions.cs @@ -28,22 +28,7 @@ public static bool IsSealed(this TypeDesc type) /// public static DefType GetClosestDefType(this TypeDesc type) { - if (type.IsArray) - { - if (!type.IsArrayTypeWithoutGenericInterfaces()) - { - MetadataType arrayShadowType = type.Context.SystemModule.GetType("System", "Array`1", throwIfNotFound: false); - if (arrayShadowType != null) - { - return arrayShadowType.MakeInstantiatedType(((ArrayType)type).ElementType); - } - } - - return type.Context.GetWellKnownType(WellKnownType.Array); - } - - Debug.Assert(type is DefType); - return (DefType)type; + return ((CompilerTypeSystemContext)type.Context).GetClosestDefType(type); } /// diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.Aot.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.Aot.cs index 24c076777fe2a6..33305d2011c876 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.Aot.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.Aot.cs @@ -27,6 +27,7 @@ public SharedGenericsConfiguration GenericsConfig private TypeDesc[] _arrayOfTInterfaces; private ArrayOfTRuntimeInterfacesAlgorithm _arrayOfTRuntimeInterfacesAlgorithm; + private MetadataType _arrayOfTType; public CompilerTypeSystemContext(TargetDetails details, SharedGenericsMode genericsMode, DelegateFeature delegateFeatures) : base(details) @@ -169,6 +170,23 @@ protected override DelegateInfo CreateDelegateInfo(TypeDesc delegateType) return new DelegateInfo(delegateType, _delegateFeatures); } + internal DefType GetClosestDefType(TypeDesc type) + { + if (type.IsArray) + { + if (!type.IsArrayTypeWithoutGenericInterfaces()) + { + MetadataType arrayShadowType = _arrayOfTType ?? (_arrayOfTType = SystemModule.GetType("System", "Array`1")); + return arrayShadowType.MakeInstantiatedType(((ArrayType)type).ElementType); + } + + return GetWellKnownType(WellKnownType.Array); + } + + Debug.Assert(type is DefType); + return (DefType)type; + } + private readonly LazyGenericsSupport.GenericCycleDetector _genericCycleDetector = new LazyGenericsSupport.GenericCycleDetector(); public void DetectGenericCycles(TypeSystemEntity owner, TypeSystemEntity referent) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilerContext.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilerContext.cs index 44bddc17c8b639..fdb6fab3e91de8 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilerContext.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilerContext.cs @@ -17,6 +17,17 @@ public CompilerTypeSystemContext(TargetDetails details, SharedGenericsMode gener { _genericsMode = genericsMode; } + + internal DefType GetClosestDefType(TypeDesc type) + { + if (type.IsArray) + { + return GetWellKnownType(WellKnownType.Array); + } + + Debug.Assert(type is DefType); + return (DefType)type; + } } public partial class ReadyToRunCompilerContext : CompilerTypeSystemContext