diff options
| author | bors <bors@rust-lang.org> | 2021-06-15 14:52:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-06-15 14:52:58 +0000 |
| commit | 12d0849f9ddb7515be7c1451a37cfacdcfef50c9 (patch) | |
| tree | b91f541ff465b4718a3eadeca8c66130922a8ae1 /compiler/rustc_query_impl | |
| parent | 6936ca8c993a82c5b5d453c3203d3b7df74c1b4b (diff) | |
| parent | 8ed82ebb2ad82b1cb95b7f68482a3a6d201a7462 (diff) | |
| download | rust-12d0849f9ddb7515be7c1451a37cfacdcfef50c9.tar.gz rust-12d0849f9ddb7515be7c1451a37cfacdcfef50c9.zip | |
Auto merge of #85154 - cjgillot:lessfn, r=bjorn3
Reduce amount of function pointers in query invocation. r? `@ghost`
Diffstat (limited to 'compiler/rustc_query_impl')
| -rw-r--r-- | compiler/rustc_query_impl/src/keys.rs | 182 | ||||
| -rw-r--r-- | compiler/rustc_query_impl/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_query_impl/src/plumbing.rs | 10 |
3 files changed, 114 insertions, 79 deletions
diff --git a/compiler/rustc_query_impl/src/keys.rs b/compiler/rustc_query_impl/src/keys.rs index 27a0dc47682..b3cc7de4662 100644 --- a/compiler/rustc_query_impl/src/keys.rs +++ b/compiler/rustc_query_impl/src/keys.rs @@ -14,7 +14,7 @@ use rustc_span::{Span, DUMMY_SP}; pub trait Key { /// Given an instance of this key, what crate is it referring to? /// This is used to find the provider. - fn query_crate(&self) -> CrateNum; + fn query_crate_is_local(&self) -> bool; /// In the event that a cycle occurs, if no explicit span has been /// given for a query with key `self`, what span should we use? @@ -22,8 +22,9 @@ pub trait Key { } impl Key for () { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _: TyCtxt<'_>) -> Span { @@ -32,8 +33,9 @@ impl Key for () { } impl<'tcx> Key for ty::InstanceDef<'tcx> { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { @@ -42,8 +44,9 @@ impl<'tcx> Key for ty::InstanceDef<'tcx> { } impl<'tcx> Key for ty::Instance<'tcx> { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { @@ -52,8 +55,9 @@ impl<'tcx> Key for ty::Instance<'tcx> { } impl<'tcx> Key for mir::interpret::GlobalId<'tcx> { - fn query_crate(&self) -> CrateNum { - self.instance.query_crate() + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { @@ -62,8 +66,9 @@ impl<'tcx> Key for mir::interpret::GlobalId<'tcx> { } impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { @@ -72,8 +77,9 @@ impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> { } impl Key for CrateNum { - fn query_crate(&self) -> CrateNum { - *self + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + *self == LOCAL_CRATE } fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP @@ -81,8 +87,9 @@ impl Key for CrateNum { } impl Key for LocalDefId { - fn query_crate(&self) -> CrateNum { - self.to_def_id().query_crate() + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.to_def_id().default_span(tcx) @@ -90,8 +97,9 @@ impl Key for LocalDefId { } impl Key for DefId { - fn query_crate(&self) -> CrateNum { - self.krate + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + self.krate == LOCAL_CRATE } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(*self) @@ -99,8 +107,9 @@ impl Key for DefId { } impl Key for ty::WithOptConstParam<LocalDefId> { - fn query_crate(&self) -> CrateNum { - self.did.query_crate() + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.did.default_span(tcx) @@ -108,8 +117,9 @@ impl Key for ty::WithOptConstParam<LocalDefId> { } impl Key for (DefId, DefId) { - fn query_crate(&self) -> CrateNum { - self.0.krate + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + self.0.krate == LOCAL_CRATE } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.1.default_span(tcx) @@ -117,8 +127,9 @@ impl Key for (DefId, DefId) { } impl Key for (ty::Instance<'tcx>, LocalDefId) { - fn query_crate(&self) -> CrateNum { - self.0.query_crate() + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.0.default_span(tcx) @@ -126,8 +137,9 @@ impl Key for (ty::Instance<'tcx>, LocalDefId) { } impl Key for (DefId, LocalDefId) { - fn query_crate(&self) -> CrateNum { - self.0.krate + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + self.0.krate == LOCAL_CRATE } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.1.default_span(tcx) @@ -135,8 +147,9 @@ impl Key for (DefId, LocalDefId) { } impl Key for (LocalDefId, DefId) { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.0.default_span(tcx) @@ -144,8 +157,9 @@ impl Key for (LocalDefId, DefId) { } impl Key for (DefId, Option<Ident>) { - fn query_crate(&self) -> CrateNum { - self.0.krate + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + self.0.krate == LOCAL_CRATE } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(self.0) @@ -153,8 +167,9 @@ impl Key for (DefId, Option<Ident>) { } impl Key for (DefId, LocalDefId, Ident) { - fn query_crate(&self) -> CrateNum { - self.0.krate + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + self.0.krate == LOCAL_CRATE } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.1.default_span(tcx) @@ -162,8 +177,9 @@ impl Key for (DefId, LocalDefId, Ident) { } impl Key for (CrateNum, DefId) { - fn query_crate(&self) -> CrateNum { - self.0 + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + self.0 == LOCAL_CRATE } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.1.default_span(tcx) @@ -171,8 +187,9 @@ impl Key for (CrateNum, DefId) { } impl Key for (DefId, SimplifiedType) { - fn query_crate(&self) -> CrateNum { - self.0.krate + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + self.0.krate == LOCAL_CRATE } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.0.default_span(tcx) @@ -180,8 +197,9 @@ impl Key for (DefId, SimplifiedType) { } impl<'tcx> Key for SubstsRef<'tcx> { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP @@ -189,8 +207,9 @@ impl<'tcx> Key for SubstsRef<'tcx> { } impl<'tcx> Key for (DefId, SubstsRef<'tcx>) { - fn query_crate(&self) -> CrateNum { - self.0.krate + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + self.0.krate == LOCAL_CRATE } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.0.default_span(tcx) @@ -203,8 +222,9 @@ impl<'tcx> Key (ty::WithOptConstParam<DefId>, SubstsRef<'tcx>), ) { - fn query_crate(&self) -> CrateNum { - (self.0).0.did.krate + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + (self.0).0.did.krate == LOCAL_CRATE } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { (self.0).0.did.default_span(tcx) @@ -212,8 +232,9 @@ impl<'tcx> Key } impl<'tcx> Key for (LocalDefId, DefId, SubstsRef<'tcx>) { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.0.default_span(tcx) @@ -221,8 +242,9 @@ impl<'tcx> Key for (LocalDefId, DefId, SubstsRef<'tcx>) { } impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) { - fn query_crate(&self) -> CrateNum { - self.1.def_id().krate + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + self.1.def_id().krate == LOCAL_CRATE } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(self.1.def_id()) @@ -230,8 +252,9 @@ impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) { } impl<'tcx> Key for (&'tcx ty::Const<'tcx>, mir::Field) { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP @@ -239,8 +262,9 @@ impl<'tcx> Key for (&'tcx ty::Const<'tcx>, mir::Field) { } impl<'tcx> Key for mir::interpret::ConstAlloc<'tcx> { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP @@ -248,8 +272,9 @@ impl<'tcx> Key for mir::interpret::ConstAlloc<'tcx> { } impl<'tcx> Key for ty::PolyTraitRef<'tcx> { - fn query_crate(&self) -> CrateNum { - self.def_id().krate + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + self.def_id().krate == LOCAL_CRATE } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(self.def_id()) @@ -257,8 +282,9 @@ impl<'tcx> Key for ty::PolyTraitRef<'tcx> { } impl<'tcx> Key for GenericArg<'tcx> { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP @@ -266,8 +292,9 @@ impl<'tcx> Key for GenericArg<'tcx> { } impl<'tcx> Key for mir::ConstantKind<'tcx> { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP @@ -275,8 +302,9 @@ impl<'tcx> Key for mir::ConstantKind<'tcx> { } impl<'tcx> Key for &'tcx ty::Const<'tcx> { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP @@ -284,8 +312,9 @@ impl<'tcx> Key for &'tcx ty::Const<'tcx> { } impl<'tcx> Key for Ty<'tcx> { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP @@ -293,8 +322,9 @@ impl<'tcx> Key for Ty<'tcx> { } impl<'tcx> Key for &'tcx ty::List<ty::Predicate<'tcx>> { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP @@ -302,8 +332,9 @@ impl<'tcx> Key for &'tcx ty::List<ty::Predicate<'tcx>> { } impl<'tcx> Key for ty::ParamEnv<'tcx> { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP @@ -311,8 +342,9 @@ impl<'tcx> Key for ty::ParamEnv<'tcx> { } impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> { - fn query_crate(&self) -> CrateNum { - self.value.query_crate() + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + self.value.query_crate_is_local() } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.value.default_span(tcx) @@ -320,8 +352,9 @@ impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> { } impl Key for Symbol { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { DUMMY_SP @@ -331,8 +364,9 @@ impl Key for Symbol { /// Canonical query goals correspond to abstract trait operations that /// are not tied to any crate in particular. impl<'tcx, T> Key for Canonical<'tcx, T> { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { @@ -341,8 +375,9 @@ impl<'tcx, T> Key for Canonical<'tcx, T> { } impl Key for (Symbol, u32, u32) { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { @@ -351,8 +386,9 @@ impl Key for (Symbol, u32, u32) { } impl<'tcx> Key for (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>) { - fn query_crate(&self) -> CrateNum { - LOCAL_CRATE + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true } fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 4175fb6925a..1d831affd1d 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -15,7 +15,6 @@ extern crate tracing; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_errors::{DiagnosticBuilder, Handler}; -use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::dep_graph; use rustc_middle::ich::StableHashingContext; use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values}; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index b4191c135b4..5907a587e16 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -353,14 +353,14 @@ macro_rules! define_queries { } #[inline] - fn compute(tcx: QueryCtxt<'tcx>, key: Self::Key) -> Self::Value { - let is_local = key.query_crate() == LOCAL_CRATE; - let provider = if is_local { + fn compute_fn(tcx: QueryCtxt<'tcx>, key: &Self::Key) -> + fn(TyCtxt<'tcx>, Self::Key) -> Self::Value + { + if key.query_crate_is_local() { tcx.queries.local_providers.$name } else { tcx.queries.extern_providers.$name - }; - provider(*tcx, key) + } } fn hash_result( |
