Skip to content

Allow to inline MethodGroup/Lamda directly passed as an argument #10049

@dmitriyse

Description

@dmitriyse

This is an example where inlining logically possible, but currently not supported by JIT:

using System;
using System.Runtime.CompilerServices;

public class C {

    public void InlineTest() {
 		// This method should not call anything
        // Everything can be inlined
        DoWithGuardTwice(PrintHello);
        
        //DoWithGuardTwice(()=>{Console.WriteLine("bye");});
    }
    
    public void PrintHello()
    {
        Console.WriteLine("Hello");
    }
    
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void DoWithGuardTwice(/*Probably with some hint here*/ Action a)
    {
        lock(this)
        {
            a();
            a();
        }
    }    
}

https://sharplab.io/#v2:C4LghgzgtgPgAgBgARwIwG4CwAoRLUB0ASgK4B2wAllAKYEDCA9lAA6UA2NATgMrcBulAMY0IWbDjgBmFACYk9JAG8cOJOpQy4AFiQBJMu0pkaAFVHAAFAEplagJD2A9E6SmAFpQhJawd4wATJAh/EnYgskZgJCEwdnYkMDIATz9jAHM1DWyXJABRfm5UzzJ0mKSkACMaJGMjEwCs7PUAEUYAdUo/AHESMC4A0wB3YRpLAAUuY2AACRp4xmtxZo0m5pc2zp6+geHRyxsAXgA+JTQATksAIkrkmiulgF8ltce1tekUXUnpuYWbNYqbArdQXa5/diMB7LDRvYGreHqADaAFkaH5AnpWOxLGiMQEsSx2AB5FhURhkCAEACC6XSXFEEEohQM9Qy1gAuh8tLpNl13L1+oMRiJLE4AFSTRiVMCVdjJJAjPzBZg1ErRdzcGji1xoeRgayAtbZSFCADWljSEENiOaQJBzTANhhDvUTpetuycK92RwcKAA===

This is a complex type of inlining. As an alternative this type of inlining was proposed to be implemented at the C# compiler level: dotnet/csharplang#1413

category:cq
theme:inlining
skill-level:expert
cost:medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIoptimization

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions