dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.25k stars 4.73k forks source link

[wasm] AOT to interpreter transitions don't work for certain generic methods #80994

Open vargaz opened 1 year ago

vargaz commented 1 year ago

Description

Testcase:

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

internal sealed class Outer<TSet> where TSet : IComparable<TSet>
{
    internal struct Inner {
        public int i1, i2, i3, i4, i5, i6, i7, i8;
    }

    [MethodImplAttribute (MethodImplOptions.NoInlining)]
    public void foo2 () {
        foo (new Inner () {i1 = 1, i2 = 2, i3 = 3, i4 = 4, i5 = 5, i6 = 6, i7 = 7, i8 = 8 }, out object o);
    }

    [MethodImplAttribute (MethodImplOptions.NoInlining)]
    public void foo<T> (T t, out object o) {
        o = null;
        try {
        } finally {
            try {
            } catch {
            }
        }
    }
}

public class Test
{
    public static void Main () {
        new Outer<string> ().foo2 ();
    }
}

To reproduce: Compile with AOT.

Actual result:

RuntimeError: null function or function signature mismatch
    at Wasm_Console_V8_Sample_Outer_1_TSet_REF_foo2 (wasm://wasm/0128741a:wasm-function[6047]:0x12d248)
    at Wasm_Console_V8_Sample_Test_Main (wasm://wasm/0128741a:wasm-function[6049]:0x12d2d8)

Reproduction Steps

.

Expected behavior

.

Actual behavior

.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

ghost commented 1 year ago

Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.

Issue Details
### Description Testcase: ``` // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; using System.Runtime.CompilerServices; using System.Threading.Tasks; internal sealed class Outer where TSet : IComparable { internal struct Inner { public int i1, i2, i3, i4, i5, i6, i7, i8; } [MethodImplAttribute (MethodImplOptions.NoInlining)] public void foo2 () { foo (new Inner () {i1 = 1, i2 = 2, i3 = 3, i4 = 4, i5 = 5, i6 = 6, i7 = 7, i8 = 8 }, out object o); } [MethodImplAttribute (MethodImplOptions.NoInlining)] public void foo (T t, out object o) { o = null; try { } finally { try { } catch { } } } } public class Test { public static void Main () { new Outer ().foo2 (); } } ``` To reproduce: Compile with AOT. Actual result: ``` RuntimeError: null function or function signature mismatch at Wasm_Console_V8_Sample_Outer_1_TSet_REF_foo2 (wasm://wasm/0128741a:wasm-function[6047]:0x12d248) at Wasm_Console_V8_Sample_Test_Main (wasm://wasm/0128741a:wasm-function[6049]:0x12d2d8) ``` ### Reproduction Steps . ### Expected behavior . ### Actual behavior . ### Regression? _No response_ ### Known Workarounds _No response_ ### Configuration _No response_ ### Other information _No response_
Author: vargaz
Assignees: -
Labels: `arch-wasm`, `untriaged`, `area-Codegen-AOT-mono`
Milestone: -
vargaz commented 1 year ago

What happens here is that foo2 cannot be AOT so the runtime needs to generate a gsharedvt_in_sig wrapper to call it using the interpreter, the generated wrapper has the following signature:

void object:gsharedvt_in_sig (Outer`1/Inner<object>,intptr&,intptr)

This fails to AOT because Outer has generic constraints, so Outer is not a valid generic instantion. Because the wrapper is not AOTed, it cannot be found at runtime, leading to the error.

pavelsavara commented 4 months ago

cc @kotlarmilos