Skip to content

Commit 8299cf6

Browse files
Remove print_vtable_sizes
1 parent 57356a2 commit 8299cf6

File tree

5 files changed

+1
-225
lines changed

5 files changed

+1
-225
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use rustc_parse::{
2626
};
2727
use rustc_passes::{abi_test, input_stats, layout_test};
2828
use rustc_resolve::Resolver;
29-
use rustc_session::code_stats::VTableSizeInfo;
3029
use rustc_session::config::{CrateType, Input, OutFileName, OutputFilenames, OutputType};
3130
use rustc_session::cstore::Untracked;
3231
use rustc_session::output::{collect_crate_types, filename_for_input, find_crate_name};
@@ -985,90 +984,6 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
985984
// we will fail to emit overlap diagnostics. Thus we invoke it here unconditionally.
986985
let _ = tcx.all_diagnostic_items(());
987986
});
988-
989-
if sess.opts.unstable_opts.print_vtable_sizes {
990-
let traits = tcx.traits(LOCAL_CRATE);
991-
992-
for &tr in traits {
993-
if !tcx.is_dyn_compatible(tr) {
994-
continue;
995-
}
996-
997-
let name = ty::print::with_no_trimmed_paths!(tcx.def_path_str(tr));
998-
999-
let mut first_dsa = true;
1000-
1001-
// Number of vtable entries, if we didn't have upcasting
1002-
let mut entries_ignoring_upcasting = 0;
1003-
// Number of vtable entries needed solely for upcasting
1004-
let mut entries_for_upcasting = 0;
1005-
1006-
let trait_ref = ty::Binder::dummy(ty::TraitRef::identity(tcx, tr));
1007-
1008-
// A slightly edited version of the code in
1009-
// `rustc_trait_selection::traits::vtable::vtable_entries`, that works without self
1010-
// type and just counts number of entries.
1011-
//
1012-
// Note that this is technically wrong, for traits which have associated types in
1013-
// supertraits:
1014-
//
1015-
// trait A: AsRef<Self::T> + AsRef<()> { type T; }
1016-
//
1017-
// Without self type we can't normalize `Self::T`, so we can't know if `AsRef<Self::T>`
1018-
// and `AsRef<()>` are the same trait, thus we assume that those are different, and
1019-
// potentially over-estimate how many vtable entries there are.
1020-
//
1021-
// Similarly this is wrong for traits that have methods with possibly-impossible bounds.
1022-
// For example:
1023-
//
1024-
// trait B<T> { fn f(&self) where T: Copy; }
1025-
//
1026-
// Here `dyn B<u8>` will have 4 entries, while `dyn B<String>` will only have 3.
1027-
// However, since we don't know `T`, we can't know if `T: Copy` holds or not,
1028-
// thus we lean on the bigger side and say it has 4 entries.
1029-
traits::vtable::prepare_vtable_segments(tcx, trait_ref, |segment| {
1030-
match segment {
1031-
traits::vtable::VtblSegment::MetadataDSA => {
1032-
// If this is the first dsa, it would be included either way,
1033-
// otherwise it's needed for upcasting
1034-
if std::mem::take(&mut first_dsa) {
1035-
entries_ignoring_upcasting += 3;
1036-
} else {
1037-
entries_for_upcasting += 3;
1038-
}
1039-
}
1040-
1041-
traits::vtable::VtblSegment::TraitOwnEntries { trait_ref, emit_vptr } => {
1042-
// Lookup the shape of vtable for the trait.
1043-
let own_existential_entries =
1044-
tcx.own_existential_vtable_entries(trait_ref.def_id());
1045-
1046-
// The original code here ignores the method if its predicates are
1047-
// impossible. We can't really do that as, for example, all not trivial
1048-
// bounds on generic parameters are impossible (since we don't know the
1049-
// parameters...), see the comment above.
1050-
entries_ignoring_upcasting += own_existential_entries.len();
1051-
1052-
if emit_vptr {
1053-
entries_for_upcasting += 1;
1054-
}
1055-
}
1056-
}
1057-
1058-
std::ops::ControlFlow::Continue::<std::convert::Infallible>(())
1059-
});
1060-
1061-
sess.code_stats.record_vtable_size(tr, &name, VTableSizeInfo {
1062-
trait_name: name.clone(),
1063-
entries: entries_ignoring_upcasting + entries_for_upcasting,
1064-
entries_ignoring_upcasting,
1065-
entries_for_upcasting,
1066-
upcasting_cost_percent: entries_for_upcasting as f64
1067-
/ entries_ignoring_upcasting as f64
1068-
* 100.,
1069-
})
1070-
}
1071-
}
1072987
}
1073988

1074989
/// Check for the `#[rustc_error]` annotation, which forces an error in codegen. This is used
@@ -1149,12 +1064,6 @@ pub(crate) fn start_codegen<'tcx>(
11491064
tcx.sess.code_stats.print_type_sizes();
11501065
}
11511066

1152-
if tcx.sess.opts.unstable_opts.print_vtable_sizes {
1153-
let crate_name = tcx.crate_name(LOCAL_CRATE);
1154-
1155-
tcx.sess.code_stats.print_vtable_sizes(crate_name);
1156-
}
1157-
11581067
codegen
11591068
}
11601069

compiler/rustc_session/src/code_stats.rs

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::cmp;
22

33
use rustc_abi::{Align, Size};
4-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
4+
use rustc_data_structures::fx::FxHashSet;
55
use rustc_data_structures::sync::Lock;
66
use rustc_span::Symbol;
7-
use rustc_span::def_id::DefId;
87

98
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
109
pub struct VariantInfo {
@@ -71,29 +70,9 @@ pub struct TypeSizeInfo {
7170
pub variants: Vec<VariantInfo>,
7271
}
7372

74-
pub struct VTableSizeInfo {
75-
pub trait_name: String,
76-
77-
/// Number of entries in a vtable with the current algorithm
78-
/// (i.e. with upcasting).
79-
pub entries: usize,
80-
81-
/// Number of entries in a vtable, as-if we did not have trait upcasting.
82-
pub entries_ignoring_upcasting: usize,
83-
84-
/// Number of entries in a vtable needed solely for upcasting
85-
/// (i.e. `entries - entries_ignoring_upcasting`).
86-
pub entries_for_upcasting: usize,
87-
88-
/// Cost of having upcasting in % relative to the number of entries without
89-
/// upcasting (i.e. `entries_for_upcasting / entries_ignoring_upcasting * 100%`).
90-
pub upcasting_cost_percent: f64,
91-
}
92-
9373
#[derive(Default)]
9474
pub struct CodeStats {
9575
type_sizes: Lock<FxHashSet<TypeSizeInfo>>,
96-
vtable_sizes: Lock<FxHashMap<DefId, VTableSizeInfo>>,
9776
}
9877

9978
impl CodeStats {
@@ -127,14 +106,6 @@ impl CodeStats {
127106
self.type_sizes.borrow_mut().insert(info);
128107
}
129108

130-
pub fn record_vtable_size(&self, trait_did: DefId, trait_name: &str, info: VTableSizeInfo) {
131-
let prev = self.vtable_sizes.lock().insert(trait_did, info);
132-
assert!(
133-
prev.is_none(),
134-
"size of vtable for `{trait_name}` ({trait_did:?}) is already recorded"
135-
);
136-
}
137-
138109
pub fn print_type_sizes(&self) {
139110
let type_sizes = self.type_sizes.borrow();
140111
// We will soon sort, so the initial order does not matter.
@@ -238,33 +209,4 @@ impl CodeStats {
238209
}
239210
}
240211
}
241-
242-
pub fn print_vtable_sizes(&self, crate_name: Symbol) {
243-
// We will soon sort, so the initial order does not matter.
244-
#[allow(rustc::potential_query_instability)]
245-
let mut infos =
246-
std::mem::take(&mut *self.vtable_sizes.lock()).into_values().collect::<Vec<_>>();
247-
248-
// Primary sort: cost % in reverse order (from largest to smallest)
249-
// Secondary sort: trait_name
250-
infos.sort_by(|a, b| {
251-
a.upcasting_cost_percent
252-
.total_cmp(&b.upcasting_cost_percent)
253-
.reverse()
254-
.then_with(|| a.trait_name.cmp(&b.trait_name))
255-
});
256-
257-
for VTableSizeInfo {
258-
trait_name,
259-
entries,
260-
entries_ignoring_upcasting,
261-
entries_for_upcasting,
262-
upcasting_cost_percent,
263-
} in infos
264-
{
265-
println!(
266-
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}" }}"#
267-
);
268-
}
269-
}
270212
}

compiler/rustc_session/src/options.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,8 +2016,6 @@ options! {
20162016
Note that this overwrites the effect `-Clink-dead-code` has on collection!"),
20172017
print_type_sizes: bool = (false, parse_bool, [UNTRACKED],
20182018
"print layout information for each type encountered (default: no)"),
2019-
print_vtable_sizes: bool = (false, parse_bool, [UNTRACKED],
2020-
"print size comparison between old and new vtable layouts (default: no)"),
20212019
proc_macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
20222020
"show backtraces for panics during proc-macro execution (default: no)"),
20232021
proc_macro_execution_strategy: ProcMacroExecutionStrategy = (ProcMacroExecutionStrategy::SameThread,

tests/ui/traits/object/print_vtable_sizes.rs

Lines changed: 0 additions & 62 deletions
This file was deleted.

tests/ui/traits/object/print_vtable_sizes.stdout

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)