Skip to content

Try to resolve exact targets for constrained static interface calls #135168

Description

@NinoFloris

These calls use the same concrete struct and interface instantiation. On .NET 11 ARM64, the instance call resolves and inlines, while the static-abstract call uses generic-dictionary dispatch.

using System;
using System.Runtime.CompilerServices;

var value = (new object(), 42);
Console.WriteLine(Outer.CallInstance(default(FuncImpl), value));
Console.WriteLine(Outer.CallStatic<FuncImpl, (object, int)>(value));

interface IFunc<T>
{
    int Invoke(T value);
    static abstract int InvokeStatic(T value);
}

readonly struct FuncImpl : IFunc<(object, int)>
{
    public int Invoke((object, int) value) => value.Item2;
    public static int InvokeStatic((object, int) value) => value.Item2;
}

static class Outer
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static int CallInstance<TFunc, T>(TFunc func, T value)
        where TFunc : struct, IFunc<T>
        => func.Invoke(value);

    [MethodImpl(MethodImplOptions.NoInlining)]
    public static int CallStatic<TFunc, T>(T value)
        where TFunc : struct, IFunc<T>
        => TFunc.InvokeStatic(value);
}

Both wrappers canonicalize T to ValueTuple<__Canon, int>. However, FuncImpl implements only one compatible IFunc, so the target is unambiguous.

Activity

  1. added
    tenet-performance
    on Oct 3, 2026
  2. added
    untriaged
    on Oct 3, 2026
  3. added
    area-CodeGen-coreclr
    on Oct 3, 2026
  4. dotnet-policy-service commented on Oct 3, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  5. added and removed
    area-CodeGen-coreclr
    on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-TypeSystem-coreclrtenet-performanceuntriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions