Skip to content

[wasm][coreclr] Avoid using calli thunks for delegates #121222

@radekdoulik

Description

@radekdoulik

Try to not use calli thunks for code like this:

class Program
{
    static void Main(string[] args)
    {
        CountDelegate countDelegate = new CountDelegate(getCount);
        Console.WriteLine($"count: {countDelegate()}");
        Console.WriteLine($"count: {countDelegate()}");
    }

    static double getCount()
    {
        return counter++;
    }

    static double counter = 0;

    delegate double CountDelegate();
}

We hit an assert, but then the output follows and is as expected, so I think we don't need to use the thunk here and possibly just try to get it during interpreter compilation?

ASSERT FAILED
	Expression: false && "GetCookieForCalliSig: unknown thunk signature"
	Location:   line 632 in /Users/rodo/git/runtime-main/src/coreclr/vm/wasm/helpers.cpp
	Function:   GetCookieForCalliSig
	Process:    42
Frame (InlinedCallFrame): 0x4fdf7c
    Skipping 0x4fdf7c
Frame (InterpreterFrame): 0x4feca0
   0) dynamicClass::IL_STUB_PInvoke, IR_0038
   1) System.Delegate::DelegateConstruct, IR_0043
   2) Program::Main, IR_000e
count: 0
count: 1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions