Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Always use CORINFO_HELP_READYTORUN_DELEGATE_CTOR optimization #2102

@MichalStrehovsky

Description

@MichalStrehovsky

Repro program (needs to be compiled with --usesharedgenerics):

using System;

internal class Program
{
    private static int Main()
    {
        TestDelegateFatFunctionPointers.Run();
        return 100;
    }


    /// <summary>
    /// Tests that we can use a delegate that points to a generic method.
    /// </summary>
    class TestDelegateFatFunctionPointers
    {
        T Generic<T>(object o) where T : class
        {
            Func<object, T> f = OtherGeneric<T>;
            return f(o);
        }

        T OtherGeneric<T>(object o) where T : class
        {
            return o as T;
        }

        public static void Run()
        {
            string hw = "Hello World";
            string roundtrip = new TestDelegateFatFunctionPointers().Generic<string>(hw);
            if (roundtrip != hw)
                throw new Exception();
        }
    }
}

fgOptimizeDelegateConstructor will abort the optimization because if (oper == GT_FTN_ADDR) is not met.

This will result in generating a normal call to the delegate's .ctor method. CoreRT doesn't have enough smarts in it to be able to tell from the function pointer how the delegate object should be laid out. The construction needs to always go through the helper. I think we're aborting because the actual address is coming from a dictionary lookup.

We're expecting the token passed to getReadyToRunDelegateCtorHelper will be the token that was ldftn'd.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions