Skip to content

[interp] Implement tailcalls - #118901

Merged
kg merged 2 commits into
dotnet:mainfrom
kg:interp-tailcall-1
Aug 22, 2025
Merged

[interp] Implement tailcalls#118901
kg merged 2 commits into
dotnet:mainfrom
kg:interp-tailcall-1

Conversation

@kg

@kgkg commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

This PR currently implements tailcalls for CALL and CALLVIRT. The opcode for tail position calli is also generated but not implemented since it wasn't immediately obvious how to implement it (it doesn't look like the mono interpreter has an opcode for it.)

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Comment threadsrc/coreclr/vm/interpexec.cpp Outdated
Comment threadsrc/coreclr/vm/interpexec.cpp
@kg
kgforce-pushed the interp-tailcall-1 branch 2 times, most recently from d4f78ae to 097ccd9CompareAugust 20, 2025 19:41
@kg
kg marked this pull request as ready for review August 20, 2025 19:42
CopilotAI review requested due to automatic review settings August 20, 2025 19:42
@kg
kg requested a review from janvorli as a code ownerAugust 20, 2025 19:42

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 tailcall support for the CoreCLR interpreter, enabling proper tail call optimization for CALL and CALLVIRT operations. The implementation reuses the current stack frame for tail calls instead of creating a new one, which is essential for proper tail call semantics.

Key changes:

  • Adds new tail call opcodes (INTOP_CALL_TAIL, INTOP_CALLVIRT_TAIL, INTOP_CALLI_TAIL)
  • Implements tail call logic that reuses the current stack frame by copying arguments and reinitializing the frame
  • Updates the InterpMethod structure to track argument size needed for tail call argument copying

Reviewed Changes

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

FileDescription
src/coreclr/vm/interpexec.cppImplements tail call execution logic and adds isTailcall flag handling
src/coreclr/interpreter/intops.defDefines new tail call opcodes
src/coreclr/interpreter/interpretershared.hAdds argsSize field to InterpMethod for tail call argument copying
src/coreclr/interpreter/compiler.cppUpdates compiler to emit tail call opcodes and pass argsSize to InterpMethod constructor

Comment threadsrc/coreclr/vm/interpexec.cpp
Comment threadsrc/coreclr/vm/interpexec.cpp
kg added 2 commits August 21, 2025 11:17
Don't assert on tail calli, just do a non-tail call for now so the application will at least run (but potentially run out of stack)
Cleanup fixme comments
@kg
kgforce-pushed the interp-tailcall-1 branch from 097ccd9 to 977d1bfCompareAugust 21, 2025 18:24
@kg

kg commented Aug 21, 2025

Copy link
Copy Markdown
ContributorAuthor

Rebased and verified that tailcall.cmd still passes in InterpModes 1 and 2 (in addition to DOTNET_Interpreter=tailcall!*)

@kg
kg merged commit 0f21477 into dotnet:mainAug 22, 2025
96 of 98 checks passed
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Sep 22, 2025
Sign up for freeto 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.

5 participants

@kg@BrzVlad@jkotas@davidwrighton