Skip to content

Commit

Permalink
Auto merge of #122010 - oli-obk:intrinsics3.0, r=pnkfelix
Browse files Browse the repository at this point in the history
Avoid invoking the `intrinsic` query for DefKinds other than `Fn` or `AssocFn`

fixes the perf regression from #120675 by only invoking (and thus inserting into the dep graph) the `intrinsic` query if the `DefKind` matches items that can actually be intrinsics
  • Loading branch information
bors committed Mar 9, 2024
2 parents 01d73d4 + b0f71f1 commit 4d4bb49
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ provide! { tcx, def_id, other, cdata,
cdata.get_stability_implications(tcx).iter().copied().collect()
}
stripped_cfg_items => { cdata.get_stripped_cfg_items(cdata.cnum, tcx) }
intrinsic => { cdata.get_intrinsic(def_id.index) }
intrinsic_raw => { cdata.get_intrinsic(def_id.index) }
defined_lang_items => { cdata.get_lang_items(tcx) }
diagnostic_items => { cdata.get_diagnostic_items() }
missing_lang_items => { cdata.get_missing_lang_items(tcx) }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ rustc_queries! {
separate_provide_extern
}
/// Whether the function is an intrinsic
query intrinsic(def_id: DefId) -> Option<rustc_middle::ty::IntrinsicDef> {
query intrinsic_raw(def_id: DefId) -> Option<rustc_middle::ty::IntrinsicDef> {
desc { |tcx| "fetch intrinsic name if `{}` is an intrinsic", tcx.def_path_str(def_id) }
separate_provide_extern
}
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,14 @@ impl<'tcx> TyCtxt<'tcx> {
)
}

pub fn intrinsic(self, def_id: impl IntoQueryParam<DefId> + Copy) -> Option<ty::IntrinsicDef> {
match self.def_kind(def_id) {
DefKind::Fn | DefKind::AssocFn => {}
_ => return None,
}
self.intrinsic_raw(def_id)
}

pub fn local_def_id_to_hir_id(self, local_def_id: LocalDefId) -> HirId {
self.opt_local_def_id_to_hir_id(local_def_id).unwrap()
}
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,11 +1642,7 @@ pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
}

/// Determines whether an item is an intrinsic (which may be via Abi or via the `rustc_intrinsic` attribute)
pub fn intrinsic(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::IntrinsicDef> {
match tcx.def_kind(def_id) {
DefKind::Fn | DefKind::AssocFn => {}
_ => return None,
}
pub fn intrinsic_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::IntrinsicDef> {
if matches!(tcx.fn_sig(def_id).skip_binder().abi(), Abi::RustIntrinsic)
|| tcx.has_attr(def_id, sym::rustc_intrinsic)
{
Expand All @@ -1664,7 +1660,7 @@ pub fn provide(providers: &mut Providers) {
reveal_opaque_types_in_bounds,
is_doc_hidden,
is_doc_notable_trait,
intrinsic,
intrinsic_raw,
..*providers
}
}

0 comments on commit 4d4bb49

Please sign in to comment.