Skip to content

Commit 37a430e

Browse files
Remove print_vtable_sizes
1 parent 08d7e9d commit 37a430e

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

1078993
/// Check for the `#[rustc_error]` annotation, which forces an error in codegen. This is used
@@ -1153,12 +1068,6 @@ pub(crate) fn start_codegen<'tcx>(
11531068
tcx.sess.code_stats.print_type_sizes();
11541069
}
11551070

1156-
if tcx.sess.opts.unstable_opts.print_vtable_sizes {
1157-
let crate_name = tcx.crate_name(LOCAL_CRATE);
1158-
1159-
tcx.sess.code_stats.print_vtable_sizes(crate_name);
1160-
}
1161-
11621071
codegen
11631072
}
11641073

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
@@ -2033,8 +2033,6 @@ options! {
20332033
Note that this overwrites the effect `-Clink-dead-code` has on collection!"),
20342034
print_type_sizes: bool = (false, parse_bool, [UNTRACKED],
20352035
"print layout information for each type encountered (default: no)"),
2036-
print_vtable_sizes: bool = (false, parse_bool, [UNTRACKED],
2037-
"print size comparison between old and new vtable layouts (default: no)"),
20382036
proc_macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
20392037
"show backtraces for panics during proc-macro execution (default: no)"),
20402038
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)