diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-06-13 12:07:12 +0000 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-06-13 12:07:12 +0000 |
| commit | 8e6a193946eea931c44caecfdd3c3353d036335b (patch) | |
| tree | 8fcafc2404d0aa1f300ae024e8aedfebf4af0de8 | |
| parent | 5008a08acf6d3e8e01e6b1768850579da6058aea (diff) | |
| download | rust-8e6a193946eea931c44caecfdd3c3353d036335b.tar.gz rust-8e6a193946eea931c44caecfdd3c3353d036335b.zip | |
Tweak names and docs for vtable stats
| -rw-r--r-- | compiler/rustc_interface/src/passes.rs | 22 | ||||
| -rw-r--r-- | compiler/rustc_session/src/code_stats.rs | 50 |
2 files changed, 43 insertions, 29 deletions
diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index d61f2d0668a..be2af94961f 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -880,9 +880,9 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> { let mut first_dsa = true; // Number of vtable entries, if we didn't have upcasting - let mut unupcasted_cost = 0; + let mut entries_ignoring_upcasting = 0; // Number of vtable entries needed solely for upcasting - let mut upcast_cost = 0; + let mut entries_for_upcasting = 0; let trait_ref = ty::Binder::dummy(ty::TraitRef::identity(tcx, tr)); @@ -911,9 +911,9 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> { // If this is the first dsa, it would be included either way, // otherwise it's needed for upcasting if std::mem::take(&mut first_dsa) { - unupcasted_cost += 3; + entries_ignoring_upcasting += 3; } else { - upcast_cost += 3; + entries_for_upcasting += 3; } } @@ -926,10 +926,10 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> { // We can't really do that as, for example, all not trivial bounds on generic // parameters are impossible (since we don't know the parameters...), // see the comment above. - unupcasted_cost += own_existential_entries.len(); + entries_ignoring_upcasting += own_existential_entries.len(); if emit_vptr { - upcast_cost += 1; + entries_for_upcasting += 1; } } } @@ -942,10 +942,12 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> { &name, VTableSizeInfo { trait_name: name.clone(), - size_words_without_upcasting: unupcasted_cost, - size_words_with_upcasting: unupcasted_cost + upcast_cost, - difference_words: upcast_cost, - difference_percent: upcast_cost as f64 / unupcasted_cost as f64 * 100., + entries: entries_ignoring_upcasting + entries_for_upcasting, + entries_ignoring_upcasting, + entries_for_upcasting, + upcasting_cost_percent: entries_for_upcasting as f64 + / entries_ignoring_upcasting as f64 + * 100., }, ) } diff --git a/compiler/rustc_session/src/code_stats.rs b/compiler/rustc_session/src/code_stats.rs index f76263de13f..51cac328c3a 100644 --- a/compiler/rustc_session/src/code_stats.rs +++ b/compiler/rustc_session/src/code_stats.rs @@ -68,10 +68,21 @@ pub struct TypeSizeInfo { pub struct VTableSizeInfo { pub trait_name: String, - pub size_words_without_upcasting: usize, - pub size_words_with_upcasting: usize, - pub difference_words: usize, - pub difference_percent: f64, + + /// Number of entries in a vtable with the current algorithm + /// (i.e. with upcasting). + pub entries: usize, + + /// Number of entries in a vtable, as-if we did not have trait upcasting. + pub entries_ignoring_upcasting: usize, + + /// Number of entries in a vtable needed solely for upcasting + /// (i.e. `entries - entries_ignoring_upcasting`). + pub entries_for_upcasting: usize, + + /// Cost of having upcasting in % relative to the number of entries without + /// upcasting (i.e. `entries_for_upcasting / entries_ignoring_upcasting * 100%`). + pub upcasting_cost_percent: f64, } #[derive(Default)] @@ -216,25 +227,26 @@ impl CodeStats { } pub fn print_vtable_sizes(&self, crate_name: &str) { - let mut rr = std::mem::take(&mut *self.vtable_sizes.lock()).into_iter().collect::<Vec<_>>(); - - rr.sort_by(|(_, stats_a), (_, stats_b)| { - stats_b.difference_percent.total_cmp(&stats_a.difference_percent) + let mut infos = std::mem::take(&mut *self.vtable_sizes.lock()) + .into_iter() + .map(|(_did, stats)| stats) + .collect::<Vec<_>>(); + + // Sort by the cost % in reverse order (from biggest to smallest) + infos.sort_by(|a, b| { + a.upcasting_cost_percent.total_cmp(&b.upcasting_cost_percent).reverse() }); - for ( - _, - VTableSizeInfo { - trait_name, - size_words_without_upcasting, - size_words_with_upcasting, - difference_words, - difference_percent, - }, - ) in rr + for VTableSizeInfo { + trait_name, + entries, + entries_ignoring_upcasting, + entries_for_upcasting, + upcasting_cost_percent, + } in infos { println!( - r#"print-vtable-sizes {{ "crate_name": "{crate_name}", "trait_name": "{trait_name}", "size_unupcastable_words": "{size_words_without_upcasting}", "size_upcastable_words": "{size_words_with_upcasting}", diff: "{difference_words}", diff_p: "{difference_percent}" }}"# + r#"print-vtable-sizes {{ "crate_name": "{crate_name}", "trait_name": "{trait_name}", "entries": "{entries}", "entries_ignoring_upcasting": "{entries_ignoring_upcasting}", "entries_for_upcasting": "{entries_for_upcasting}", "upcasting_cost_percent": "{upcasting_cost_percent}" }}"# ); } } |
