Skip to content

Conversation

kg
Copy link
Member

@kg kg commented Aug 19, 2025

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.)

Copy link
Contributor

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

@kg kg force-pushed the interp-tailcall-1 branch 2 times, most recently from d4f78ae to 097ccd9 Compare August 20, 2025 19:41
@kg kg marked this pull request as ready for review August 20, 2025 19:42
@Copilot Copilot AI review requested due to automatic review settings August 20, 2025 19:42
@kg kg requested a review from janvorli as a code owner August 20, 2025 19:42
Copy link
Contributor

@Copilot Copilot AI left a comment

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.

File Description
src/coreclr/vm/interpexec.cpp Implements tail call execution logic and adds isTailcall flag handling
src/coreclr/interpreter/intops.def Defines new tail call opcodes
src/coreclr/interpreter/interpretershared.h Adds argsSize field to InterpMethod for tail call argument copying
src/coreclr/interpreter/compiler.cpp Updates compiler to emit tail call opcodes and pass argsSize to InterpMethod constructor

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 kg force-pushed the interp-tailcall-1 branch from 097ccd9 to 977d1bf Compare August 21, 2025 18:24
@kg
Copy link
Member Author

kg commented Aug 21, 2025

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:main Aug 22, 2025
96 of 98 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants