Skip to content

Commit e0b4595

Browse files
committed
explicit tail call tests with indexing, indirect operands in LLVM
1 parent a448837 commit e0b4595

File tree

5 files changed

+109
-2
lines changed

5 files changed

+109
-2
lines changed

tests/ui/explicit-tail-calls/drop-order.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// FIXME(explicit_tail_calls): enable this test once rustc_codegen_ssa supports tail calls
2-
//@ ignore-test: tail calls are not implemented in rustc_codegen_ssa yet, so this causes 🧊
31
//@ run-pass
42
#![expect(incomplete_features)]
53
#![feature(explicit_tail_calls)]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Indexing taken from
2+
// https://github.com/phi-go/rfcs/blob/guaranteed-tco/text%2F0000-explicit-tail-calls.md#tail-call-elimination
3+
// should probably come back to after some decision on verbiage
4+
#![expect(incomplete_features)]
5+
#![feature(explicit_tail_calls)]
6+
7+
fn f0(_: usize) {}
8+
fn f1(_: usize) {}
9+
fn f2(_: usize) {}
10+
11+
fn indexer(idx: usize) {
12+
let v: [&dyn Fn(usize); 3] = [&f0, &f1, &f2];
13+
become v[idx](idx) //~ error: mismatched function ABIs
14+
//~^ error: mismatched signatures
15+
}
16+
17+
fn main() {
18+
for idx in 0..3 {
19+
indexer(idx);
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: mismatched function ABIs
2+
--> $DIR/indexer.rs:13:5
3+
|
4+
LL | become v[idx](idx)
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `become` requires caller and callee to have the same ABI
8+
= note: caller ABI is `"Rust"`, while callee ABI is `"rust-call"`
9+
10+
error: mismatched signatures
11+
--> $DIR/indexer.rs:13:5
12+
|
13+
LL | become v[idx](idx)
14+
| ^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: `become` requires caller and callee to have matching signatures
17+
= note: caller signature: `fn(usize)`
18+
= note: callee signature: `extern "rust-call" fn(&dyn Fn(usize), (usize,))`
19+
20+
error: aborting due to 2 previous errors
21+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//@build-fail
2+
//@ normalize-stderr: "note: .*\n\n" -> ""
3+
//@ normalize-stderr: "thread 'rustc' panicked.*\n" -> ""
4+
//@ normalize-stderr: "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: "
5+
//@ rustc-env:RUST_BACKTRACE=0
6+
//@known-bug: #144293
7+
//@ failure-status: 101
8+
// Same as recursion-etc but eggs LLVM emission into giving indirect arguments.
9+
#![expect(incomplete_features)]
10+
#![feature(explicit_tail_calls)]
11+
12+
use std::hint::black_box;
13+
14+
struct U64Wrapper {
15+
pub x: u64,
16+
pub arbitrary: String,
17+
}
18+
19+
fn count(curr: U64Wrapper, top: U64Wrapper) -> U64Wrapper {
20+
if black_box(curr.x) >= top.x {
21+
curr
22+
} else {
23+
become count(
24+
U64Wrapper {
25+
x: curr.x + 1,
26+
arbitrary: curr.arbitrary,
27+
},
28+
top,
29+
)
30+
}
31+
}
32+
33+
fn main() {
34+
println!(
35+
"{}",
36+
count(
37+
U64Wrapper {
38+
x: 0,
39+
arbitrary: "hello!".into()
40+
},
41+
black_box(U64Wrapper {
42+
x: 1000000,
43+
arbitrary: "goodbye!".into()
44+
})
45+
)
46+
.x
47+
);
48+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error: internal compiler error: $COMPILER_DIR_REAL/rustc_codegen_ssa/src/mir/block.rs:LL:CC: arguments using PassMode::Indirect are currently not supported for tail calls
2+
--> $DIR/recursion-etc-u64wrapper.rs:23:16
3+
|
4+
LL | become count(
5+
| ________________^
6+
LL | | U64Wrapper {
7+
LL | | x: curr.x + 1,
8+
LL | | arbitrary: curr.arbitrary,
9+
LL | | },
10+
LL | | top,
11+
LL | | )
12+
| |_________^
13+
14+
15+
Box<dyn Any>
16+
query stack during panic:
17+
end of query stack
18+
error: aborting due to 1 previous error
19+

0 commit comments

Comments
 (0)