summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_session/src/code_stats.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_session/src/code_stats.rs')
-rw-r--r--compiler/rustc_session/src/code_stats.rs32
1 files changed, 27 insertions, 5 deletions
diff --git a/compiler/rustc_session/src/code_stats.rs b/compiler/rustc_session/src/code_stats.rs
index 1085bce44..551782504 100644
--- a/compiler/rustc_session/src/code_stats.rs
+++ b/compiler/rustc_session/src/code_stats.rs
@@ -20,7 +20,25 @@ pub enum SizeKind {
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
+pub enum FieldKind {
+ AdtField,
+ Upvar,
+ GeneratorLocal,
+}
+
+impl std::fmt::Display for FieldKind {
+ fn fmt(&self, w: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ FieldKind::AdtField => write!(w, "field"),
+ FieldKind::Upvar => write!(w, "upvar"),
+ FieldKind::GeneratorLocal => write!(w, "local"),
+ }
+ }
+}
+
+#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct FieldInfo {
+ pub kind: FieldKind,
pub name: Symbol,
pub offset: u64,
pub size: u64,
@@ -66,7 +84,11 @@ impl CodeStats {
// Sort variants so the largest ones are shown first. A stable sort is
// used here so that source code order is preserved for all variants
// that have the same size.
- variants.sort_by(|info1, info2| info2.size.cmp(&info1.size));
+ // Except for Generators, whose variants are already sorted according to
+ // their yield points in `variant_info_for_generator`.
+ if kind != DataTypeKind::Generator {
+ variants.sort_by(|info1, info2| info2.size.cmp(&info1.size));
+ }
let info = TypeSizeInfo {
kind,
type_description: type_desc.to_string(),
@@ -145,7 +167,7 @@ impl CodeStats {
fields.sort_by_key(|f| (f.offset, f.size));
for field in fields {
- let FieldInfo { ref name, offset, size, align } = field;
+ let FieldInfo { kind, ref name, offset, size, align } = field;
if offset > min_offset {
let pad = offset - min_offset;
@@ -155,16 +177,16 @@ impl CodeStats {
if offset < min_offset {
// If this happens it's probably a union.
println!(
- "print-type-size {indent}field `.{name}`: {size} bytes, \
+ "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}field `.{name}`: {size} bytes");
+ println!("print-type-size {indent}{kind} `.{name}`: {size} bytes");
} else {
// Include field alignment in output only if it caused padding injection
println!(
- "print-type-size {indent}field `.{name}`: {size} bytes, \
+ "print-type-size {indent}{kind} `.{name}`: {size} bytes, \
alignment: {align} bytes"
);
}