-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Lift the same-signature restriction for extern "tail"
#157983
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
Merged
rust-bors
merged 1 commit into
rust-lang:main
from
folkertdev:tailcc-lift-same-signature-restriction
Jun 25, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
tests/ui/explicit-tail-calls/no-unsized-arguments.aarch64.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| error[E0277]: the size for values of type `[u8]` cannot be known at compilation time | ||
| --> $DIR/no-unsized-arguments.rs:40:42 | ||
| | | ||
| LL | extern "tail" fn unsized_argument(x: [u8]) -> u8 { | ||
| | ^^^^ doesn't have a size known at compile-time | ||
| | | ||
| = help: the trait `Sized` is not implemented for `[u8]` | ||
| help: function arguments must have a statically known size, borrowed slices always have a known size | ||
| | | ||
| LL | extern "tail" fn unsized_argument(x: &[u8]) -> u8 { | ||
| | + | ||
|
|
||
| error: unsized arguments cannot be used in a tail call | ||
| --> $DIR/no-unsized-arguments.rs:33:5 | ||
| | | ||
| LL | become unsized_argument(b); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: unsized argument of type `[u8]` | ||
|
|
||
| error: unsized arguments cannot be used in a tail call | ||
| --> $DIR/no-unsized-arguments.rs:48:5 | ||
| | | ||
| LL | become unsized_argument(*b); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: unsized argument of type `[u8]` | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0277`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| //@ add-minicore | ||
| //@ ignore-backends: gcc | ||
| //@ min-llvm-version: 22 | ||
| // | ||
| //@ revisions: x86 x86_64 aarch64 | ||
| // | ||
| //@ [x86] compile-flags: --target=i686-unknown-linux-gnu | ||
| //@ [x86] needs-llvm-components: x86 | ||
| //@ [x86_64] compile-flags: --target=x86_64-unknown-linux-gnu | ||
| //@ [x86_64] needs-llvm-components: x86 | ||
| //@ [aarch64] compile-flags: --target=aarch64-unknown-linux-gnu | ||
| //@ [aarch64] needs-llvm-components: aarch64 | ||
| #![feature(explicit_tail_calls, rust_tail_cc, unsized_fn_params, no_core)] | ||
| #![allow(incomplete_features, internal_features)] | ||
| #![no_core] | ||
| #![crate_type = "lib"] | ||
|
|
||
| extern crate minicore; | ||
| use minicore::*; | ||
|
|
||
| extern "C" { | ||
| fn extract(_: [u8]) -> u8; | ||
| } | ||
|
|
||
| fn vanilla(b: [u8]) -> u8 { | ||
| fn unsized_argument(x: [u8]) -> u8 { | ||
| unsafe { extract(x) } | ||
| } | ||
|
|
||
| // Non-tail call. | ||
| let _ = unsized_argument(b); | ||
|
|
||
| become unsized_argument(b); | ||
| //~^ ERROR unsized arguments cannot be used in a tail call | ||
| } | ||
|
|
||
| extern "tail" fn tailcc(b: &[u8]) -> u8 { | ||
| // `extern "tail"` is special because we also can't unsized parameters in standard definitions | ||
| // and calls. | ||
| extern "tail" fn unsized_argument(x: [u8]) -> u8 { | ||
| //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time | ||
| unsafe { extract(x) } | ||
| } | ||
|
|
||
| // Vanilla call. | ||
| let _ = unsized_argument(*b); | ||
|
|
||
| become unsized_argument(*b); | ||
| //~^ ERROR unsized arguments cannot be used in a tail call | ||
| } |
31 changes: 31 additions & 0 deletions
31
tests/ui/explicit-tail-calls/no-unsized-arguments.x86.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| error[E0277]: the size for values of type `[u8]` cannot be known at compilation time | ||
| --> $DIR/no-unsized-arguments.rs:40:42 | ||
| | | ||
| LL | extern "tail" fn unsized_argument(x: [u8]) -> u8 { | ||
| | ^^^^ doesn't have a size known at compile-time | ||
| | | ||
| = help: the trait `Sized` is not implemented for `[u8]` | ||
| help: function arguments must have a statically known size, borrowed slices always have a known size | ||
| | | ||
| LL | extern "tail" fn unsized_argument(x: &[u8]) -> u8 { | ||
| | + | ||
|
|
||
| error: unsized arguments cannot be used in a tail call | ||
| --> $DIR/no-unsized-arguments.rs:33:5 | ||
| | | ||
| LL | become unsized_argument(b); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: unsized argument of type `[u8]` | ||
|
|
||
| error: unsized arguments cannot be used in a tail call | ||
| --> $DIR/no-unsized-arguments.rs:48:5 | ||
| | | ||
| LL | become unsized_argument(*b); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: unsized argument of type `[u8]` | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0277`. |
31 changes: 31 additions & 0 deletions
31
tests/ui/explicit-tail-calls/no-unsized-arguments.x86_64.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| error[E0277]: the size for values of type `[u8]` cannot be known at compilation time | ||
| --> $DIR/no-unsized-arguments.rs:40:42 | ||
| | | ||
| LL | extern "tail" fn unsized_argument(x: [u8]) -> u8 { | ||
| | ^^^^ doesn't have a size known at compile-time | ||
| | | ||
| = help: the trait `Sized` is not implemented for `[u8]` | ||
| help: function arguments must have a statically known size, borrowed slices always have a known size | ||
| | | ||
| LL | extern "tail" fn unsized_argument(x: &[u8]) -> u8 { | ||
| | + | ||
|
|
||
| error: unsized arguments cannot be used in a tail call | ||
| --> $DIR/no-unsized-arguments.rs:33:5 | ||
| | | ||
| LL | become unsized_argument(b); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: unsized argument of type `[u8]` | ||
|
|
||
| error: unsized arguments cannot be used in a tail call | ||
| --> $DIR/no-unsized-arguments.rs:48:5 | ||
| | | ||
| LL | become unsized_argument(*b); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: unsized argument of type `[u8]` | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0277`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/ui/explicit-tail-calls/tailcc-no-signature-restriction.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //@ run-pass | ||
| //@ ignore-backends: gcc | ||
| //@ min-llvm-version: 22 | ||
| //@ revisions: x86_64 aarch64 | ||
| // | ||
| // FIXME: enable x86 on LLVM 23. | ||
| //@ [x86_64] only-x86_64 | ||
| //@ [aarch64] only-aarch64 | ||
| #![feature(explicit_tail_calls, rust_tail_cc)] | ||
|
|
||
| #[inline(never)] | ||
| pub extern "tail" fn add() -> u64 { | ||
| #[inline(never)] | ||
| extern "tail" fn add(a: u64, b: u64) -> u64 { | ||
| a.wrapping_add(b) | ||
| } | ||
|
|
||
| become add(1, 2); | ||
| } | ||
|
|
||
| #[inline(never)] | ||
| pub extern "tail" fn pass_struct(a: u64, d: u64) -> u64 { | ||
| #[derive(Clone, Copy)] | ||
| pub struct Large { | ||
| pub a: u64, | ||
| pub b: u64, | ||
| pub c: u64, | ||
| pub d: u64, | ||
| } | ||
|
|
||
| #[inline(never)] | ||
| extern "tail" fn add(large: Large) -> u64 { | ||
| let _ = large.b; | ||
| let _ = large.c; | ||
| large.a.wrapping_add(large.d) | ||
| } | ||
|
|
||
| let large = Large { a, b: 0xBBBB_BBBB_BBBB_BBBB, c: 0xCCCC_CCCC_CCCC_CCCC, d }; | ||
| become add(large); | ||
| } | ||
|
|
||
| fn main() { | ||
| assert_eq!(add(), 3); | ||
|
|
||
| // FIXME: LLVM 22 has a bug which makes this miscompile. | ||
| if false { | ||
| assert_eq!(pass_struct(5, 6), 5 + 6); | ||
| } | ||
|
Comment on lines
+45
to
+48
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anything that doesn't fit into register actually runs into this bug, which is fixed in LLVM 23. |
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.