1
Fork 0

-Zprint-type-sizes: print the types of awaitees and unnamed coroutine locals.

This should assist comprehending the size of coroutines.
In particular, whenever a future is suspended while awaiting another
future, the latter is given the special name `__awaitee`, and now the
type of the awaited future will be printed, allowing identifying
caller/callee — er, I mean, poller/pollee — relationships.

It would be possible to include the type name in more cases, but I
thought that that might be overly verbose (`print-type-sizes` is already
a lot of text) and ordinary named fields or variables are easier for
readers to discover the types of.
This commit is contained in:
Kevin Reid 2024-03-22 16:45:32 -07:00
parent 85e449a323
commit 44d185b0d0
5 changed files with 34 additions and 16 deletions

View file

@ -44,6 +44,10 @@ pub struct FieldInfo {
pub offset: u64,
pub size: u64,
pub align: u64,
/// Name of the type of this field.
/// Present only if the creator thought that this would be important for identifying the field,
/// typically because the field name is uninformative.
pub type_name: Option<Symbol>,
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
@ -192,7 +196,7 @@ impl CodeStats {
fields.sort_by_key(|f| (f.offset, f.size));
for field in fields {
let FieldInfo { kind, ref name, offset, size, align } = field;
let FieldInfo { kind, ref name, offset, size, align, type_name } = field;
if offset > min_offset {
let pad = offset - min_offset;
@ -201,21 +205,27 @@ impl CodeStats {
if offset < min_offset {
// If this happens it's probably a union.
println!(
print!(
"print-type-size {indent}{kind} `.{name}`: {size} bytes, \
offset: {offset} bytes, \
alignment: {align} bytes"
);
} else if info.packed || offset == min_offset {
println!("print-type-size {indent}{kind} `.{name}`: {size} bytes");
print!("print-type-size {indent}{kind} `.{name}`: {size} bytes");
} else {
// Include field alignment in output only if it caused padding injection
println!(
print!(
"print-type-size {indent}{kind} `.{name}`: {size} bytes, \
alignment: {align} bytes"
);
}
if let Some(type_name) = type_name {
println!(", type: {type_name}");
} else {
println!();
}
min_offset = offset + size;
}
}