Skip to content

Commit 2d6eccd

Browse files
committed
Auto merge of rust-lang#77755 - bugadani:perf-calc-dtor, r=ecstatic-morse
Monomorphize `calculate_dtor` instead of using function pointers Change `calculate_dtor` to avoid dynamic dispatching. This change allows the empty functions to be optimized away. Based on the discussion in rust-lang#77754 (comment), the performance impact of this change was measured. Perf run results: https://perf.rust-lang.org/compare.html?start=7bc5839e99411aad9061a632b62075d1346cbb3b&end=ffec759ae9bbc4d6d2235ff40ade6723a85bc7cc
2 parents e8529c7 + 0d27b76 commit 2d6eccd

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
9494
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
9595
adt_destructor => {
9696
let _ = cdata;
97-
tcx.calculate_dtor(def_id, &mut |_,_| Ok(()))
97+
tcx.calculate_dtor(def_id, |_,_| Ok(()))
9898
}
9999
variances_of => { tcx.arena.alloc_from_iter(cdata.get_item_variances(def_id.index)) }
100100
associated_item_def_ids => {

compiler/rustc_middle/src/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'tcx> TyCtxt<'tcx> {
341341
pub fn calculate_dtor(
342342
self,
343343
adt_did: DefId,
344-
validate: &mut dyn FnMut(Self, DefId) -> Result<(), ErrorReported>,
344+
validate: impl Fn(Self, DefId) -> Result<(), ErrorReported>,
345345
) -> Option<ty::Destructor> {
346346
let drop_trait = self.lang_items().drop_trait()?;
347347
self.ensure().coherent_trait(drop_trait);

compiler/rustc_mir/src/transform/check_const_item_mutation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'a, 'tcx> ConstMutationChecker<'a, 'tcx> {
5353
//
5454
// #[const_mutation_allowed]
5555
// pub const LOG: Log = Log { msg: "" };
56-
match self.tcx.calculate_dtor(def_id, &mut |_, _| Ok(())) {
56+
match self.tcx.calculate_dtor(def_id, |_, _| Ok(())) {
5757
Some(_) => None,
5858
None => Some(def_id),
5959
}

compiler/rustc_typeck/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub fn provide(providers: &mut Providers) {
264264
}
265265

266266
fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::Destructor> {
267-
tcx.calculate_dtor(def_id, &mut dropck::check_drop_impl)
267+
tcx.calculate_dtor(def_id, dropck::check_drop_impl)
268268
}
269269

270270
/// If this `DefId` is a "primary tables entry", returns

0 commit comments

Comments
 (0)