Skip to content

Commit 1f4a88a

Browse files
committed
explicit tail call tests with indirect operands in LLVM, small test for indexing into a function table as described by RFC 3407
1 parent a448837 commit 1f4a88a

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@run-pass
2+
// Indexing taken from
3+
// https://github.com/phi-go/rfcs/blob/guaranteed-tco/text%2F0000-explicit-tail-calls.md#tail-call-elimination
4+
// no other test has utilized the "function table"
5+
// described in the RFC aside from this one at this point.
6+
#![expect(incomplete_features)]
7+
#![feature(explicit_tail_calls)]
8+
9+
fn f0(_: usize) {}
10+
fn f1(_: usize) {}
11+
fn f2(_: usize) {}
12+
13+
fn indexer(idx: usize) {
14+
let v: [fn(usize); 3] = [f0, f1, f2];
15+
become v[idx](idx)
16+
}
17+
18+
fn main() {
19+
for idx in 0..3 {
20+
indexer(idx);
21+
}
22+
}
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)