Closed
Description
Description
Testcase
using System;
using System.Runtime.InteropServices;
public class Test
{
public static int Main () {
var del = (Func<string, string>)Delegate.CreateDelegate (typeof (Func<string, string>), null, typeof (object).GetMethod ("ToString"));
Console.WriteLine (del ("FOO"));
}
}
Description
At the moment, this is creating a wrapper which depends on both the delegate type and the bounded method to make a virtual call to delegate's bounded method which can not be generated at AOT time since the AOT compiler can not determine that a particular combination of delegate type and bound method will be needed at runtime.
Approach
Instead of making a virtual call, we should make a calli
instruction using a pointer to the bounded method.
In this way, AOT compiler could generate a wrapper depending just on the delegate type.
Tasks
- Enable
calli
instruction for JIT instead ofcallvirt
- Make WRAPPER_SUBTYPE_DELEGATE_INVOKE_VIRTUAL to be associated only with the delegate type in order to generate it at AOT time