Skip to content

[clr-interp] Implement tail-calling for delegates and support for delegates in wasm - #120205

Merged
davidwrighton merged 5 commits into
dotnet:mainfrom
davidwrighton:tail_call_delegates
Sep 30, 2025
Merged

[clr-interp] Implement tail-calling for delegates and support for delegates in wasm#120205
davidwrighton merged 5 commits into
dotnet:mainfrom
davidwrighton:tail_call_delegates

Conversation

@davidwrighton

@davidwrightondavidwrighton commented Sep 29, 2025

Copy link
Copy Markdown
Member
  • Disable shuffle thunk creation for portable entrypoints and enable ILDelegateShuffle thunks instead
  • Also implement the shuffle thunk in the interpreter directly so that most cases don't need to even use those in WASM or cases where we have pregenerated code
  • Add a new opcode for tail-calling a delegate method

…egates in wasm
- Disable shuffle thunk creation for portable entrypoints and enable ILDelegateShuffle thunks instead
- Also implement the shuffle thunk in the interpreter directly so that most cases don't need to even use those in WASM or cases where we have pregenerated code
- Add a new opcode for tail-calling a delegate method
CopilotAI review requested due to automatic review settings September 29, 2025 18:20
@davidwrightondavidwrighton changed the title [clr-interp] Implement tail-calling for delegates and support for del…[clr-interp] Implement tail-calling for delegates and support for delegates in wasmSep 29, 2025
@github-actionsgithub-actionsBot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Sep 29, 2025

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements tail-calling for delegates in the CLR interpreter and enables delegate support in WebAssembly by modifying how delegate shuffle thunks are handled.

  • Adds a new INTOP_CALLDELEGATE_TAIL opcode for tail-calling delegate methods
  • Disables shuffle thunk creation for portable entrypoints and enables IL delegate shuffle thunks instead
  • Implements shuffle thunk logic directly in the interpreter to avoid needing shuffle thunks for most WASM cases

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

FileDescription
src/coreclr/vm/interpexec.cppImplements tail-call delegate handling and direct shuffle thunk execution in interpreter
src/coreclr/vm/comdelegate.cppDisables portable shuffle array generation and enables IL delegate shuffle thunks for portable entrypoints
src/coreclr/interpreter/inc/intops.defAdds new INTOP_CALLDELEGATE_TAIL opcode definition
src/coreclr/interpreter/compiler.cppEmits INTOP_CALLDELEGATE_TAIL opcode for tail-call delegate invocations

Comment threadsrc/coreclr/vm/interpexec.cpp Outdated
kg
kg approved these changes Sep 29, 2025

@kgkg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks right other than Copilot's comment pointing out the potential null dereference for static delegates

Comment threadsrc/coreclr/vm/comdelegate.cpp Outdated
Comment threadsrc/coreclr/vm/interpexec.cpp
@davidwrighton
davidwrighton marked this pull request as draft September 29, 2025 21:28
@davidwrighton
davidwrighton marked this pull request as ready for review September 29, 2025 21:55

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment threadsrc/coreclr/vm/interpexec.cpp
Comment threadsrc/coreclr/vm/interpexec.cpp

@janvorlijanvorli 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.

LGTM, thank you!

@davidwrighton
davidwrighton enabled auto-merge (squash) September 29, 2025 22:50
@davidwrighton
davidwrighton merged commit 691e950 into dotnet:mainSep 30, 2025
98 checks passed
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Oct 30, 2025
@pavelsavarapavelsavara added the arch-wasm WebAssembly architecture label Jun 16, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasmWebAssembly architectureneeds-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@davidwrighton@kg@jkotas@janvorli@pavelsavara