Skip to content

Generic math does not work in WASM AOT #60447

@kg

Description

@kg

Description

Any code using Generic Math will produce runtime errors in an AOT'd wasm application. It works in the interpreter.

Reproduction Steps

    private static T LerpGeneric<T> (T a, T b, T t) 
        where T : IAdditionOperators<T, T, T>, 
            ISubtractionOperators<T, T, T>, 
            IMultiplyOperators<T, T, T>
    {
        var size = b - a;
        var offset = size * t;
        return a + offset;
    }
    
    [BenchmarkCategory(Categories.Runtime)]
    [Benchmark]
    public double Lerp_Generic ()
    {
        double result = 0;
        for (int i = 0; i < IterationCount; i++) {
            double accumulator = 0;
            for (int j = 0; j < ArrayLength; j++) {
                double t = j / dArrayLength;
                accumulator += LerpGeneric(A[j], B[LengthMinusOne - j], t);
            }
            result += accumulator;
        }
        return result;
    }

Expected behavior

Working generic math (even if it falls back to the interpreter)

Actual behavior

console.error: RuntimeError: null function or function signature mismatch
console.error: RuntimeError: null function or function signature mismatch
    at MicroBenchmarks_GenericMathTest_Lerp_Generic (wasm://wasm/2627c6ae:wasm-function[290160]:0x4b57467)
    at b8f19783_ecdd_483a_a5be_f2cfb1051f26_wrapper_delegate_invoke__Module_invoke_double (wasm://wasm/2627c6ae:wasm-function[138969]:0x20df192)
    at b8f19783_ecdd_483a_a5be_f2cfb1051f26_BenchmarkDotNet_Autogenerated_Runnable_3_WorkloadActionNoUnroll_long (wasm://wasm/2627c6ae:wasm-function[139003]:0x20e20d5)
    at b8f19783_ecdd_483a_a5be_f2cfb1051f26_wrapper_delegate_invoke_System_Action_1_long_invoke_void_T_long (wasm://wasm/2627c6ae:wasm-function[138974]:0x20dfe10)
    at BenchmarkDotNet_BenchmarkDotNet_Engines_Engine_RunIteration_BenchmarkDotNet_Engines_IterationData (wasm://wasm/2627c6ae:wasm-function[314273]:0x5258a20)
    at BenchmarkDotNet_BenchmarkDotNet_Engines_EngineFactory_Jit_BenchmarkDotNet_Engines_Engine_int_int_int (wasm://wasm/2627c6ae:wasm-function[14040]:0x4edbcb)
    at BenchmarkDotNet_BenchmarkDotNet_Engines_EngineFactory_CreateReadyToRun_BenchmarkDotNet_Engines_EngineParameters (wasm://wasm/2627c6ae:wasm-function[314292]:0x5259ef8)
    at BenchmarkDotNet_Diagnostics_Windows_aot_wrapper_gsharedvt_out_sig_obj_this_obj (wasm://wasm/2627c6ae:wasm-function[922]:0x18c201)
    at jit_call_cb (wasm://wasm/2627c6ae:wasm-function[36553]:0xbe0d89)
    at invoke_vi (dotnet.js:1:234708)
    ```

### Regression?

_No response_

### Known Workarounds

_No response_

### Configuration

latest ```main```

### Other information

_No response_

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions