Skip to content

Commit 916fb6a

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 7cd9505 commit 916fb6a

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//@ known-bug: #144293
2+
// Same as recursion-etc but eggs LLVM emission into giving indirect arguments.
3+
#![expect(incomplete_features)]
4+
#![feature(explicit_tail_calls)]
5+
6+
use std::hint::black_box;
7+
8+
struct U64Wrapper {
9+
pub x: u64,
10+
pub arbitrary: String,
11+
}
12+
13+
fn count(curr: U64Wrapper, top: U64Wrapper) -> U64Wrapper {
14+
if black_box(curr.x) >= top.x {
15+
curr
16+
} else {
17+
become count(
18+
U64Wrapper {
19+
x: curr.x + 1,
20+
arbitrary: curr.arbitrary,
21+
},
22+
top,
23+
)
24+
}
25+
}
26+
27+
fn main() {
28+
println!(
29+
"{}",
30+
count(
31+
U64Wrapper {
32+
x: 0,
33+
arbitrary: "hello!".into()
34+
},
35+
black_box(U64Wrapper {
36+
x: 1000000,
37+
arbitrary: "goodbye!".into()
38+
})
39+
)
40+
.x
41+
);
42+
}

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+
}

0 commit comments

Comments
 (0)