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

@folkertdev folkertdev commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

View all comments

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
arg.cast_to_with_attrs(Reg { kind: RegKind::Integer, size }, attr.into());
}

if self.conv == CanonAbi::RustTail && arg.layout.is_sized() {

@WaffleLapkin WaffleLapkin Jun 22, 2026

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.

extern "tail" requires that args are sized, so I think arg.layout.is_sized() should be an assert instead

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

right, fixed

Comment thread compiler/rustc_target/src/callconv/mod.rs
@folkertdev folkertdev force-pushed the tailcc-lift-same-signature-restriction branch from 0aa786a to f6c3707 Compare June 22, 2026 13:24
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

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

r=me with green CI

View changes since this review

@folkertdev folkertdev force-pushed the tailcc-lift-same-signature-restriction branch from f6c3707 to d8d4b89 Compare June 22, 2026 15:01
@rustbot

rustbot commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors r=WaffleLapkin

@rust-bors

rust-bors Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit d8d4b89 has been approved by WaffleLapkin

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 5. This pull request will be tested once the tree is reopened.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 22, 2026
…ure-restriction, r=WaffleLapkin

Lift the same-signature restriction for `extern "tail"`

tracking issue: rust-lang#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
rust-bors Bot pushed a commit that referenced this pull request Jun 23, 2026
Rollup of 6 pull requests

Successful merges:

 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158222 (format: ignore println newline in foreign format hints)
 - #158274 (triagebot: Stop pinging myself)
rust-bors Bot pushed a commit that referenced this pull request Jun 23, 2026
Rollup of 6 pull requests

Successful merges:

 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158222 (format: ignore println newline in foreign format hints)
 - #158274 (triagebot: Stop pinging myself)
rust-bors Bot pushed a commit that referenced this pull request Jun 23, 2026
Rollup of 6 pull requests

Successful merges:

 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158222 (format: ignore println newline in foreign format hints)
 - #158274 (triagebot: Stop pinging myself)
@jhpratt

jhpratt commented Jun 23, 2026

Copy link
Copy Markdown
Member

@bors r-

#158277 (comment)

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 23, 2026
@rust-bors

rust-bors Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#158277), which was unapproved.

View changes since this unapproval

@folkertdev folkertdev force-pushed the tailcc-lift-same-signature-restriction branch from 637142b to e638ebe Compare June 23, 2026 08:39
@folkertdev

Copy link
Copy Markdown
Contributor Author

Turns out x86 fails on LLVM 22 even in the simple case. It should be fixed by LLVM 23, I'll validate that locally (but the outcome should not be blocking here).

@bors try jobs=i686-gnu-nopt-1,x86_64-gnu-nopt

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 23, 2026
…tion, r=<try>

Lift the same-signature restriction for `extern "tail"`


try-job: i686-gnu-nopt-1
try-job: x86_64-gnu-nopt
@rust-bors

rust-bors Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 79c979d (79c979da0163c369152caeca08bb9256b5f79533)
Base parent: 4429659 (4429659e4745016bd3f26a4a421843edc7fbc422)

@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors r=WaffleLapkin

@rust-bors

rust-bors Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit e638ebe has been approved by WaffleLapkin

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 23, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 23, 2026
…ure-restriction, r=WaffleLapkin

Lift the same-signature restriction for `extern "tail"`

tracking issue: rust-lang#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
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 23, 2026
…ure-restriction, r=WaffleLapkin

Lift the same-signature restriction for `extern "tail"`

tracking issue: rust-lang#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
rust-bors Bot pushed a commit that referenced this pull request Jun 23, 2026
…uwer

Rollup of 23 pull requests

Successful merges:

 - #158315 (`rust-analyzer` subtree update)
 - #155739 (Add temporary scope to assert_eq and assert_ne)
 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157527 (Move derive tests into their dedicated folder)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #158020 (Update mingw-w64 C toolchain)
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158257 ( fix escaping placeholder check in next solver normalization folder)
 - #158263 (Only load the feature list once in the entire resolver)
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)
 - #158300 (Improve unknown crate_type diagnostic suggestions)
 - #158304 (mailmap: update mu001999)

Failed merges:

 - #158256 (Avoid parser panics bubbling out to proc macros)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 24, 2026
…ure-restriction, r=WaffleLapkin

Lift the same-signature restriction for `extern "tail"`

tracking issue: rust-lang#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
rust-bors Bot pushed a commit that referenced this pull request Jun 24, 2026
Rollup of 27 pull requests

Successful merges:

 - #158315 (`rust-analyzer` subtree update)
 - #155739 (Add temporary scope to assert_eq and assert_ne)
 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158053 (Optimize network address parser)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157527 (Move derive tests into their dedicated folder)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #158020 (Update mingw-w64 C toolchain)
 - #158039 (c-variadic: test that we use equality up to free lifetimes)
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158257 ( fix escaping placeholder check in next solver normalization folder)
 - #158263 (Only load the feature list once in the entire resolver)
 - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use)
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)
 - #158300 (Improve unknown crate_type diagnostic suggestions)
 - #158304 (mailmap: update mu001999)
 - #158309 (Update `rustc-literal-escaper` version to `0.0.8`)

Failed merges:

 - #158256 (Avoid parser panics bubbling out to proc macros)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 24, 2026
…ure-restriction, r=WaffleLapkin

Lift the same-signature restriction for `extern "tail"`

tracking issue: rust-lang#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
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 24, 2026
…ure-restriction, r=WaffleLapkin

Lift the same-signature restriction for `extern "tail"`

tracking issue: rust-lang#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
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

7 participants