diff --git a/src/coreclr/tools/Common/TypeSystem/IL/NativeAotILProvider.cs b/src/coreclr/tools/Common/TypeSystem/IL/NativeAotILProvider.cs index 5bbde912ee987b..fcd5925c258985 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/NativeAotILProvider.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/NativeAotILProvider.cs @@ -369,7 +369,9 @@ public override MethodIL GetMethodIL(MethodDesc method) if (wrappedIL == null) return null; - return new AsyncMethodIL(asyncVariantImpl, wrappedIL); + return wrappedIL is EcmaMethodIL ecmaIL + ? new EcmaAsyncMethodIL(asyncVariantImpl, ecmaIL) + : new AsyncMethodIL(asyncVariantImpl, wrappedIL); } else { @@ -378,7 +380,7 @@ public override MethodIL GetMethodIL(MethodDesc method) } } - private sealed class AsyncMethodIL : MethodIL + private class AsyncMethodIL : MethodIL { private readonly AsyncMethodVariant _variant; private readonly MethodIL _wrappedIL; @@ -398,5 +400,16 @@ public AsyncMethodIL(AsyncMethodVariant variant, MethodIL wrappedIL) public override bool IsInitLocals => _wrappedIL.IsInitLocals; public override int MaxStack => _wrappedIL.MaxStack; } + + private sealed class EcmaAsyncMethodIL : AsyncMethodIL, IEcmaMethodIL + { + public EcmaAsyncMethodIL(AsyncMethodVariant variant, EcmaMethodIL wrappedIL) + : base(variant, wrappedIL) + { + Module = wrappedIL.Module; + } + + public IEcmaModule Module { get; } + } } } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs index 4c15e385bb0a9e..e1b1d9db36d8d8 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs @@ -629,10 +629,10 @@ public MethodIL GetMethodILWithInlinedSubstitutions(MethodIL method) debugInfo = new SubstitutedDebugInformation(debugInfo, sequencePoints.ToArray()); } - // We only optimize EcmaMethods because there we can find out the highest string token RID + // We only optimize IL backed by an ECMA module because we can find the highest string token RID // in use. ArrayBuilder newStrings = default; - if (hasGetResourceStringCall && method.GetMethodILDefinition() is EcmaMethodIL ecmaMethodIL) + if (hasGetResourceStringCall && method.GetMethodILDefinition() is IEcmaMethodIL ecmaMethodIL) { // We're going to inject new string tokens. Start where the last token of the module left off. // We don't need this token to be globally unique because all token resolution happens in the context @@ -1182,7 +1182,7 @@ public override object GetObject(int token, NotFoundBehavior notFoundBehavior) { // If this is a string token, it could be one of the new string tokens we injected. if ((token >>> 24) == TokenTypeString - && _wrappedMethodIL.GetMethodILDefinition() is EcmaMethodIL ecmaMethodIL) + && _wrappedMethodIL.GetMethodILDefinition() is IEcmaMethodIL ecmaMethodIL) { int rid = token & 0xFFFFFF; int maxRealTokenRid = ecmaMethodIL.Module.MetadataReader.GetHeapSize(HeapIndex.UserString);