Skip to content

Commit cc8f990

Browse files
committed
Add tests to assert current behavior of large future sizes
Based on a couple of sources: - https://swatinem.de/blog/future-size/ - rust-lang#62958
1 parent 11d96b5 commit cc8f990

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// edition: 2021
2+
// run-pass
3+
4+
async fn test(_arg: [u8; 8192]) {}
5+
6+
async fn use_future(fut: impl std::future::Future<Output = ()>) {
7+
fut.await
8+
}
9+
10+
fn main() {
11+
let n = std::mem::size_of_val(&use_future(use_future(use_future(use_future(use_future(
12+
use_future(use_future(use_future(use_future(use_future(test(
13+
[0; 8192]
14+
))))))
15+
))))));
16+
println!("size is: {n}");
17+
// Not putting an exact number in case it slightly changes over different commits
18+
assert!(n > 8000000);
19+
}

tests/ui/future-sizes/large-arg.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile-flags: -Z print-type-sizes --crate-type=lib
2+
// edition: 2021
3+
// build-pass
4+
5+
pub async fn test() {
6+
let _ = a([0u8; 1024]).await;
7+
}
8+
9+
pub async fn a<T>(t: T) -> T {
10+
b(t).await
11+
}
12+
async fn b<T>(t: T) -> T {
13+
c(t).await
14+
}
15+
async fn c<T>(t: T) -> T {
16+
t
17+
}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
print-type-size type: `[async fn body@$DIR/large-arg.rs:5:21: 7:2]`: 3076 bytes, alignment: 1 bytes
2+
print-type-size discriminant: 1 bytes
3+
print-type-size variant `Suspend0`: 3075 bytes
4+
print-type-size field `.__awaitee`: 3075 bytes, offset: 0 bytes, alignment: 1 bytes
5+
print-type-size variant `Unresumed`: 0 bytes
6+
print-type-size variant `Returned`: 0 bytes
7+
print-type-size variant `Panicked`: 0 bytes
8+
print-type-size type: `[async fn body@$DIR/large-arg.rs:9:30: 11:2]`: 3075 bytes, alignment: 1 bytes
9+
print-type-size discriminant: 1 bytes
10+
print-type-size variant `Suspend0`: 3074 bytes
11+
print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
12+
print-type-size field `.__awaitee`: 2050 bytes
13+
print-type-size variant `Unresumed`: 1024 bytes
14+
print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
15+
print-type-size variant `Returned`: 1024 bytes
16+
print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
17+
print-type-size variant `Panicked`: 1024 bytes
18+
print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
19+
print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/large-arg.rs:9:30: 11:2]>`: 3075 bytes, alignment: 1 bytes
20+
print-type-size field `.value`: 3075 bytes
21+
print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/large-arg.rs:9:30: 11:2]>`: 3075 bytes, alignment: 1 bytes
22+
print-type-size variant `MaybeUninit`: 3075 bytes
23+
print-type-size field `.uninit`: 0 bytes
24+
print-type-size field `.value`: 3075 bytes
25+
print-type-size type: `[async fn body@$DIR/large-arg.rs:12:26: 14:2]`: 2050 bytes, alignment: 1 bytes
26+
print-type-size discriminant: 1 bytes
27+
print-type-size variant `Suspend0`: 2049 bytes
28+
print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
29+
print-type-size field `.__awaitee`: 1025 bytes
30+
print-type-size variant `Unresumed`: 1024 bytes
31+
print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
32+
print-type-size variant `Returned`: 1024 bytes
33+
print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
34+
print-type-size variant `Panicked`: 1024 bytes
35+
print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
36+
print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/large-arg.rs:12:26: 14:2]>`: 2050 bytes, alignment: 1 bytes
37+
print-type-size field `.value`: 2050 bytes
38+
print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/large-arg.rs:12:26: 14:2]>`: 2050 bytes, alignment: 1 bytes
39+
print-type-size variant `MaybeUninit`: 2050 bytes
40+
print-type-size field `.uninit`: 0 bytes
41+
print-type-size field `.value`: 2050 bytes
42+
print-type-size type: `[async fn body@$DIR/large-arg.rs:15:26: 17:2]`: 1025 bytes, alignment: 1 bytes
43+
print-type-size discriminant: 1 bytes
44+
print-type-size variant `Unresumed`: 1024 bytes
45+
print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
46+
print-type-size variant `Returned`: 1024 bytes
47+
print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
48+
print-type-size variant `Panicked`: 1024 bytes
49+
print-type-size field `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
50+
print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/large-arg.rs:15:26: 17:2]>`: 1025 bytes, alignment: 1 bytes
51+
print-type-size field `.value`: 1025 bytes
52+
print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/large-arg.rs:15:26: 17:2]>`: 1025 bytes, alignment: 1 bytes
53+
print-type-size variant `MaybeUninit`: 1025 bytes
54+
print-type-size field `.uninit`: 0 bytes
55+
print-type-size field `.value`: 1025 bytes
56+
print-type-size type: `std::task::Poll<[u8; 1024]>`: 1025 bytes, alignment: 1 bytes
57+
print-type-size discriminant: 1 bytes
58+
print-type-size variant `Ready`: 1024 bytes
59+
print-type-size field `.0`: 1024 bytes
60+
print-type-size variant `Pending`: 0 bytes

0 commit comments

Comments
 (0)