Skip to content

Commit 4b859c3

Browse files
authored
Rollup merge of #107695 - Swatinem:futcallx3, r=compiler-errors
Add test for Future inflating arg size to 3x This adds one more test that should track improvements to generator layout, like #62958 and #62575. In particular, this test highlights suboptimal layout, as the storage for the argument future is not being reused across its usage as `upvar`, `local` and `awaitee` (being polled to completion). This is on top of #107692 (as those would conflict with each other) It is a minimal repro for code mentioned in moka-rs/moka#212 (comment) (CC `@tatsuya6502)`
2 parents 306dbaf + 7a7b2e3 commit 4b859c3

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// compile-flags: -Z print-type-sizes --crate-type lib
2+
// edition:2021
3+
// build-pass
4+
// ignore-pass
5+
6+
async fn wait() {}
7+
8+
async fn big_fut(arg: [u8; 1024]) {}
9+
10+
async fn calls_fut(fut: impl std::future::Future<Output = ()>) {
11+
loop {
12+
wait().await;
13+
if true {
14+
return fut.await;
15+
} else {
16+
wait().await;
17+
}
18+
}
19+
}
20+
21+
pub async fn test() {
22+
let fut = big_fut([0u8; 1024]);
23+
calls_fut(fut).await;
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
print-type-size type: `[async fn body@$DIR/async-awaiting-fut.rs:21:21: 24:2]`: 3078 bytes, alignment: 1 bytes
2+
print-type-size discriminant: 1 bytes
3+
print-type-size variant `Unresumed`: 0 bytes
4+
print-type-size variant `Suspend0`: 3077 bytes
5+
print-type-size local `.__awaitee`: 3077 bytes, offset: 0 bytes, alignment: 1 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/async-awaiting-fut.rs:10:64: 19:2]`: 3077 bytes, alignment: 1 bytes
9+
print-type-size discriminant: 1 bytes
10+
print-type-size variant `Unresumed`: 2051 bytes
11+
print-type-size padding: 1026 bytes
12+
print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes
13+
print-type-size variant `Suspend0`: 2052 bytes
14+
print-type-size local `.fut`: 1025 bytes, offset: 0 bytes, alignment: 1 bytes
15+
print-type-size local `..generator_field4`: 1 bytes
16+
print-type-size padding: 1 bytes
17+
print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes
18+
print-type-size local `.__awaitee`: 1 bytes
19+
print-type-size variant `Suspend1`: 3076 bytes
20+
print-type-size padding: 1024 bytes
21+
print-type-size local `..generator_field4`: 1 bytes, alignment: 1 bytes
22+
print-type-size padding: 1 bytes
23+
print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes
24+
print-type-size local `.__awaitee`: 1025 bytes
25+
print-type-size variant `Suspend2`: 2052 bytes
26+
print-type-size local `.fut`: 1025 bytes, offset: 0 bytes, alignment: 1 bytes
27+
print-type-size local `..generator_field4`: 1 bytes
28+
print-type-size padding: 1 bytes
29+
print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes
30+
print-type-size local `.__awaitee`: 1 bytes
31+
print-type-size variant `Returned`: 2051 bytes
32+
print-type-size padding: 1026 bytes
33+
print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes
34+
print-type-size variant `Panicked`: 2051 bytes
35+
print-type-size padding: 1026 bytes
36+
print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes
37+
print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/async-awaiting-fut.rs:10:64: 19:2]>`: 3077 bytes, alignment: 1 bytes
38+
print-type-size field `.value`: 3077 bytes
39+
print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/async-awaiting-fut.rs:10:64: 19:2]>`: 3077 bytes, alignment: 1 bytes
40+
print-type-size variant `MaybeUninit`: 3077 bytes
41+
print-type-size field `.uninit`: 0 bytes
42+
print-type-size field `.value`: 3077 bytes
43+
print-type-size type: `[async fn body@$DIR/async-awaiting-fut.rs:8:35: 8:37]`: 1025 bytes, alignment: 1 bytes
44+
print-type-size discriminant: 1 bytes
45+
print-type-size variant `Unresumed`: 1024 bytes
46+
print-type-size upvar `.arg`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
47+
print-type-size variant `Returned`: 1024 bytes
48+
print-type-size upvar `.arg`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
49+
print-type-size variant `Panicked`: 1024 bytes
50+
print-type-size upvar `.arg`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
51+
print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/async-awaiting-fut.rs:8:35: 8:37]>`: 1025 bytes, alignment: 1 bytes
52+
print-type-size field `.value`: 1025 bytes
53+
print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/async-awaiting-fut.rs:8:35: 8:37]>`: 1025 bytes, alignment: 1 bytes
54+
print-type-size variant `MaybeUninit`: 1025 bytes
55+
print-type-size field `.uninit`: 0 bytes
56+
print-type-size field `.value`: 1025 bytes
57+
print-type-size type: `[async fn body@$DIR/async-awaiting-fut.rs:6:17: 6:19]`: 1 bytes, alignment: 1 bytes
58+
print-type-size discriminant: 1 bytes
59+
print-type-size variant `Unresumed`: 0 bytes
60+
print-type-size variant `Returned`: 0 bytes
61+
print-type-size variant `Panicked`: 0 bytes
62+
print-type-size type: `std::mem::ManuallyDrop<bool>`: 1 bytes, alignment: 1 bytes
63+
print-type-size field `.value`: 1 bytes
64+
print-type-size type: `std::mem::MaybeUninit<bool>`: 1 bytes, alignment: 1 bytes
65+
print-type-size variant `MaybeUninit`: 1 bytes
66+
print-type-size field `.uninit`: 0 bytes
67+
print-type-size field `.value`: 1 bytes
68+
print-type-size type: `std::task::Poll<()>`: 1 bytes, alignment: 1 bytes
69+
print-type-size discriminant: 1 bytes
70+
print-type-size variant `Ready`: 0 bytes
71+
print-type-size field `.0`: 0 bytes
72+
print-type-size variant `Pending`: 0 bytes

0 commit comments

Comments
 (0)