-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[interp] Implement tailcalls #118901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[interp] Implement tailcalls #118901
Conversation
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
d4f78ae
to
097ccd9
Compare
There was a problem hiding this 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 |
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
Rebased and verified that tailcall.cmd still passes in InterpModes 1 and 2 (in addition to |
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.)