1
Fork 0

Auto merge of #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 https://github.com/rust-lang/rust/pull/77754#discussion_r502498970, the performance impact of this change was measured.

Perf run results: https://perf.rust-lang.org/compare.html?start=7bc5839e99411aad9061a632b62075d1346cbb3b&end=ffec759ae9bbc4d6d2235ff40ade6723a85bc7cc
This commit is contained in:
bors 2020-10-13 10:19:30 +00:00
commit 2d6eccdb67
4 changed files with 4 additions and 4 deletions

View file

@ -94,7 +94,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
adt_def => { cdata.get_adt_def(def_id.index, tcx) } adt_def => { cdata.get_adt_def(def_id.index, tcx) }
adt_destructor => { adt_destructor => {
let _ = cdata; let _ = cdata;
tcx.calculate_dtor(def_id, &mut |_,_| Ok(())) tcx.calculate_dtor(def_id, |_,_| Ok(()))
} }
variances_of => { tcx.arena.alloc_from_iter(cdata.get_item_variances(def_id.index)) } variances_of => { tcx.arena.alloc_from_iter(cdata.get_item_variances(def_id.index)) }
associated_item_def_ids => { associated_item_def_ids => {

View file

@ -341,7 +341,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn calculate_dtor( pub fn calculate_dtor(
self, self,
adt_did: DefId, adt_did: DefId,
validate: &mut dyn FnMut(Self, DefId) -> Result<(), ErrorReported>, validate: impl Fn(Self, DefId) -> Result<(), ErrorReported>,
) -> Option<ty::Destructor> { ) -> Option<ty::Destructor> {
let drop_trait = self.lang_items().drop_trait()?; let drop_trait = self.lang_items().drop_trait()?;
self.ensure().coherent_trait(drop_trait); self.ensure().coherent_trait(drop_trait);

View file

@ -53,7 +53,7 @@ impl<'a, 'tcx> ConstMutationChecker<'a, 'tcx> {
// //
// #[const_mutation_allowed] // #[const_mutation_allowed]
// pub const LOG: Log = Log { msg: "" }; // pub const LOG: Log = Log { msg: "" };
match self.tcx.calculate_dtor(def_id, &mut |_, _| Ok(())) { match self.tcx.calculate_dtor(def_id, |_, _| Ok(())) {
Some(_) => None, Some(_) => None,
None => Some(def_id), None => Some(def_id),
} }

View file

@ -264,7 +264,7 @@ pub fn provide(providers: &mut Providers) {
} }
fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::Destructor> { fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::Destructor> {
tcx.calculate_dtor(def_id, &mut dropck::check_drop_impl) tcx.calculate_dtor(def_id, dropck::check_drop_impl)
} }
/// If this `DefId` is a "primary tables entry", returns /// If this `DefId` is a "primary tables entry", returns