Skip to content

Lift the same-signature restriction for extern "tail"#157983

Open
folkertdev wants to merge 1 commit into
rust-lang:mainfrom
folkertdev:tailcc-lift-same-signature-restriction
Open

Lift the same-signature restriction for extern "tail"#157983
folkertdev wants to merge 1 commit into
rust-lang:mainfrom
folkertdev:tailcc-lift-same-signature-restriction

Conversation

@folkertdev

Copy link
Copy Markdown
Contributor

tracking issue: #157427

The extern "tail" calling convention uses callee cleanup (i.e. the callee restores the stack, not the caller). Hence, the same-signature restriction that is normally required to codegen tail calls does not apply.

We need the ABI to deviate from extern "Rust" to make sure indirect arguments are passed by stack offset, not via a pointer into the caller's stack frame (the value would potentially be overwritten). For standard tail calls we work around this problem by storing the value in the caller's caller, but for extern "tail" that doesn't work reliably because the signatures can be different.

I'm not sure about unsized arguments. That feature seems really broken, so I'm not sure how much work we should put into trying to do something reasonable there. Fundamentally I don't think we can support unsized arguments in extern "tail" calls.

Also we can't really promote using this yet due to tailcc being a bit broken on LLVM 22 on x86_64.

r? WaffleLapkin
cc @bjorn3

@folkertdev folkertdev added the F-rust_tail_cc `#![feature(rust_tail_cc)]` label Jun 16, 2026
@rustbot rustbot added F-explicit_tail_calls `#![feature(explicit_tail_calls)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 16, 2026
@rustbot

rustbot commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

WaffleLapkin is not on the review rotation at the moment.
They may take a while to respond.

@bjorn3

bjorn3 commented Jun 16, 2026

Copy link
Copy Markdown
Member

I don't think it is possible supporting unsized arguments with tail calls except for the narrow case where every tail call passes the unsized argument it received from its own caller, in which case Indirect { on_stack: false } would work even with extern "tail". I don't think it is worth supporting this narrow of a rule, so I think disallowing unsized arguments on extern "tail" entirely is the right call.

@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the tailcc-lift-same-signature-restriction branch from 9ff5f86 to 0a30594 Compare June 16, 2026 19:41
@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_mir_build/src/check_tail_calls.rs
Comment thread compiler/rustc_hir_typeck/src/check.rs
@folkertdev folkertdev force-pushed the tailcc-lift-same-signature-restriction branch 2 times, most recently from ce0a4ed to 73d1dea Compare June 16, 2026 20:59
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the tailcc-lift-same-signature-restriction branch from 73d1dea to 2a61ca9 Compare June 17, 2026 09:04
@rust-log-analyzer

This comment has been minimized.

@folkertdev folkertdev force-pushed the tailcc-lift-same-signature-restriction branch from 2a61ca9 to 0aa786a Compare June 17, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-explicit_tail_calls `#![feature(explicit_tail_calls)]` F-rust_tail_cc `#![feature(rust_tail_cc)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants