Skip to content

[WIP] Implement an intrinsic for delegate lambdas#125901

Draft
MichalPetryka wants to merge 2 commits intodotnet:mainfrom
MichalPetryka:lambda-prototype
Draft

[WIP] Implement an intrinsic for delegate lambdas#125901
MichalPetryka wants to merge 2 commits intodotnet:mainfrom
MichalPetryka:lambda-prototype

Conversation

@MichalPetryka
Copy link
Contributor

Implements a basic intrinsic for creating delegate singletons, to be used by Roslyn for lambdas and method group conversions.

Creates delegates closed over null instances to save on memory, this makes it reject instance methods on generic types since those need an instance.

Uses a field for caching non frozen delegates since otherwise we'd have a noticeable perf regression on every access for cases that can't be expanded in the JIT (shared generics, unloadable assemblies). This also significantly simplifies the implementation.

TODO:

  • Decide on final name and signature
  • Decide if instance methods on generic types need to be supported
  • Implement Mono support
  • Cleanup NAOT compilation handling
  • Implement support in NAOT .cctor interpreter (optional)

cc @jkotas @MichalStrehovsky @EgorBo

Depends on #99200 (without it this is a GC hole)
Depends on #125875 (fix included here too)

Closes #85014

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 22, 2026
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Introduce an intrinsic for more efficient lambda generation

1 participant