forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#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 rust-lang#62958 and rust-lang#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 rust-lang#107692 (as those would conflict with each other) It is a minimal repro for code mentioned in moka-rs/moka#212 (comment) (CC `@tatsuya6502)`
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// compile-flags: -Z print-type-sizes --crate-type lib | ||
// edition:2021 | ||
// build-pass | ||
// ignore-pass | ||
|
||
async fn wait() {} | ||
|
||
async fn big_fut(arg: [u8; 1024]) {} | ||
|
||
async fn calls_fut(fut: impl std::future::Future<Output = ()>) { | ||
loop { | ||
wait().await; | ||
if true { | ||
return fut.await; | ||
} else { | ||
wait().await; | ||
} | ||
} | ||
} | ||
|
||
pub async fn test() { | ||
let fut = big_fut([0u8; 1024]); | ||
calls_fut(fut).await; | ||
} |
72 changes: 72 additions & 0 deletions
72
tests/ui/async-await/future-sizes/async-awaiting-fut.stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
print-type-size type: `[async fn body@$DIR/async-awaiting-fut.rs:21:21: 24:2]`: 3078 bytes, alignment: 1 bytes | ||
print-type-size discriminant: 1 bytes | ||
print-type-size variant `Unresumed`: 0 bytes | ||
print-type-size variant `Suspend0`: 3077 bytes | ||
print-type-size local `.__awaitee`: 3077 bytes, offset: 0 bytes, alignment: 1 bytes | ||
print-type-size variant `Returned`: 0 bytes | ||
print-type-size variant `Panicked`: 0 bytes | ||
print-type-size type: `[async fn body@$DIR/async-awaiting-fut.rs:10:64: 19:2]`: 3077 bytes, alignment: 1 bytes | ||
print-type-size discriminant: 1 bytes | ||
print-type-size variant `Unresumed`: 2051 bytes | ||
print-type-size padding: 1026 bytes | ||
print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes | ||
print-type-size variant `Suspend0`: 2052 bytes | ||
print-type-size local `.fut`: 1025 bytes, offset: 0 bytes, alignment: 1 bytes | ||
print-type-size local `..generator_field4`: 1 bytes | ||
print-type-size padding: 1 bytes | ||
print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes | ||
print-type-size local `.__awaitee`: 1 bytes | ||
print-type-size variant `Suspend1`: 3076 bytes | ||
print-type-size padding: 1024 bytes | ||
print-type-size local `..generator_field4`: 1 bytes, alignment: 1 bytes | ||
print-type-size padding: 1 bytes | ||
print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes | ||
print-type-size local `.__awaitee`: 1025 bytes | ||
print-type-size variant `Suspend2`: 2052 bytes | ||
print-type-size local `.fut`: 1025 bytes, offset: 0 bytes, alignment: 1 bytes | ||
print-type-size local `..generator_field4`: 1 bytes | ||
print-type-size padding: 1 bytes | ||
print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes | ||
print-type-size local `.__awaitee`: 1 bytes | ||
print-type-size variant `Returned`: 2051 bytes | ||
print-type-size padding: 1026 bytes | ||
print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes | ||
print-type-size variant `Panicked`: 2051 bytes | ||
print-type-size padding: 1026 bytes | ||
print-type-size upvar `.fut`: 1025 bytes, alignment: 1 bytes | ||
print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/async-awaiting-fut.rs:10:64: 19:2]>`: 3077 bytes, alignment: 1 bytes | ||
print-type-size field `.value`: 3077 bytes | ||
print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/async-awaiting-fut.rs:10:64: 19:2]>`: 3077 bytes, alignment: 1 bytes | ||
print-type-size variant `MaybeUninit`: 3077 bytes | ||
print-type-size field `.uninit`: 0 bytes | ||
print-type-size field `.value`: 3077 bytes | ||
print-type-size type: `[async fn body@$DIR/async-awaiting-fut.rs:8:35: 8:37]`: 1025 bytes, alignment: 1 bytes | ||
print-type-size discriminant: 1 bytes | ||
print-type-size variant `Unresumed`: 1024 bytes | ||
print-type-size upvar `.arg`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes | ||
print-type-size variant `Returned`: 1024 bytes | ||
print-type-size upvar `.arg`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes | ||
print-type-size variant `Panicked`: 1024 bytes | ||
print-type-size upvar `.arg`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes | ||
print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/async-awaiting-fut.rs:8:35: 8:37]>`: 1025 bytes, alignment: 1 bytes | ||
print-type-size field `.value`: 1025 bytes | ||
print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/async-awaiting-fut.rs:8:35: 8:37]>`: 1025 bytes, alignment: 1 bytes | ||
print-type-size variant `MaybeUninit`: 1025 bytes | ||
print-type-size field `.uninit`: 0 bytes | ||
print-type-size field `.value`: 1025 bytes | ||
print-type-size type: `[async fn body@$DIR/async-awaiting-fut.rs:6:17: 6:19]`: 1 bytes, alignment: 1 bytes | ||
print-type-size discriminant: 1 bytes | ||
print-type-size variant `Unresumed`: 0 bytes | ||
print-type-size variant `Returned`: 0 bytes | ||
print-type-size variant `Panicked`: 0 bytes | ||
print-type-size type: `std::mem::ManuallyDrop<bool>`: 1 bytes, alignment: 1 bytes | ||
print-type-size field `.value`: 1 bytes | ||
print-type-size type: `std::mem::MaybeUninit<bool>`: 1 bytes, alignment: 1 bytes | ||
print-type-size variant `MaybeUninit`: 1 bytes | ||
print-type-size field `.uninit`: 0 bytes | ||
print-type-size field `.value`: 1 bytes | ||
print-type-size type: `std::task::Poll<()>`: 1 bytes, alignment: 1 bytes | ||
print-type-size discriminant: 1 bytes | ||
print-type-size variant `Ready`: 0 bytes | ||
print-type-size field `.0`: 0 bytes | ||
print-type-size variant `Pending`: 0 bytes |