diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs index defd270ef7a2c3..391d5328a4be96 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs @@ -305,6 +305,14 @@ public void AddModuleTokenForType(TypeDesc type, ModuleToken token) public int GetModuleIndex(IEcmaModule module) { + int moduleIndex = _moduleIndexLookup(module); + if (moduleIndex != 0 && !(module is Internal.TypeSystem.Ecma.MutableModule)) + { + if (!_compilationModuleGroup.VersionsWithModule((ModuleDesc)module)) + { + throw new InternalCompilerErrorException("Attempt to use token from a module not within the version bubble"); + } + } return _moduleIndexLookup(module); } @@ -316,7 +324,7 @@ public int GetModuleIndex(IEcmaModule module) /// private class DummyTypeInfo { - public static DummyTypeInfo Instance = new DummyTypeInfo(); + public static DummyTypeInfo Instance = new DummyTypeInfo(); } private class TokenResolverProvider : ISignatureTypeProvider diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/SignatureBuilder.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/SignatureBuilder.cs index fe5595531ad810..1fb549a6f1afa0 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/SignatureBuilder.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/SignatureBuilder.cs @@ -602,6 +602,11 @@ public SignatureContext EmitFixup(NodeFactory factory, ReadyToRunFixupKind fixup else { EmitByte((byte)(fixupKind | ReadyToRunFixupKind.ModuleOverride)); + if (!(targetModule is Internal.TypeSystem.Ecma.MutableModule) && !factory.CompilationModuleGroup.VersionsWithModule((ModuleDesc)targetModule)) + { + throw new InternalCompilerErrorException("Attempt to use token from a module not within the version bubble"); + } + EmitUInt((uint)factory.ManifestMetadataTable.ModuleToIndex(targetModule)); return new SignatureContext(targetModule, outerContext.Resolver); } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/RuntimeDeterminedTypeHelper.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/RuntimeDeterminedTypeHelper.cs index f2f56713670d9a..2f298d26f34867 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/RuntimeDeterminedTypeHelper.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/RuntimeDeterminedTypeHelper.cs @@ -132,6 +132,7 @@ public static bool Equals(MethodWithToken methodWithToken1, MethodWithToken meth return Equals(methodWithToken1.Method, methodWithToken2.Method) && Equals(methodWithToken1.OwningType, methodWithToken2.OwningType) && Equals(methodWithToken1.ConstrainedType, methodWithToken2.ConstrainedType) + && Equals(methodWithToken1.Token.Module, methodWithToken2.Token.Module) && methodWithToken1.Unboxing == methodWithToken2.Unboxing; } @@ -152,7 +153,8 @@ public static bool Equals(FieldWithToken field1, FieldWithToken field2) { return field1 == null && field2 == null; } - return RuntimeDeterminedTypeHelper.Equals(field1.Field, field2.Field); + return RuntimeDeterminedTypeHelper.Equals(field1.Field, field2.Field) && + Equals(field1.Token.Module, field2.Token.Module); } public static int GetHashCode(Instantiation instantiation)