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

Emit delegate object array thunks - #2911

Merged
MichalStrehovsky merged 1 commit into
dotnet:masterfrom
MichalStrehovsky:expressionInterpreterSupport
Mar 8, 2017
Merged

MichalStrehovsky merged 1 commit into
dotnet:masterfrom
MichalStrehovsky:expressionInterpreterSupport

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

This is a special kind of thunks used to invoke delegates created by the
LINQ expression interpreter.

This is mostly a port from the Project N IL2IL toolchain, but I added the empty
array optimization because it's silly to allocate empty arrays.

This is a special kind of thunks used to invoke delegates created by the
LINQ expression interpreter.
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

Tested with the code below, but I can't check that in because our FX packaging story is still incomplete. (Can't reference System.Linq.Expressions.)

using System;
using System.Linq.Expressions;

internal class Program
{
    private static void SayHello()
    {
        Console.WriteLine("Hello");
    }

    private static void SayHelloName(string name)
    {
        Console.WriteLine("Hello " + name);
    }

    private static string GetHello()
    {
        return "Hello";
    }

    private static string GetHelloName(string name)
    {
        return "Hello " + name;
    }

    private static void Main(string[] args)
    {
        new Program();
        {
            Action a = SayHello;
            Action b = a.Invoke;
            Expression<Action> h = () => SayHello();
            h.Compile()();
        }

        {
            Action<string> a = SayHelloName;
            Action<string> b = a.Invoke;
            Expression<Action<string>> h = (string name) => SayHelloName(name);
            h.Compile()("Michal");
        }

        {
            Func<string> a = GetHello;
            Func<string> b = a.Invoke;
            Expression<Func<string>> h = () => GetHello();
            Console.WriteLine(h.Compile()());
        }

        {
            Func<string, string> a = GetHelloName;
            Func<string, string> b = a.Invoke;
            Expression<Func<string, string>> h = (string name) => GetHelloName(name);
            Console.WriteLine(h.Compile()("Michal"));
        }
    }
}

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

@davidwrighton PTAL

@davidwrighton davidwrighton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The empty array optimization should be a nice moderate improvement.

@MichalStrehovsky
MichalStrehovsky merged commit 351923c into dotnet:master Mar 8, 2017
@MichalStrehovsky
MichalStrehovsky deleted the expressionInterpreterSupport branch March 8, 2017 20:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants