Auto merge of #85154 - cjgillot:lessfn, r=bjorn3
Reduce amount of function pointers in query invocation. r? `@ghost`
This commit is contained in:
commit
12d0849f9d
5 changed files with 167 additions and 114 deletions
|
@ -14,7 +14,7 @@ use rustc_span::{Span, DUMMY_SP};
|
||||||
pub trait Key {
|
pub trait Key {
|
||||||
/// Given an instance of this key, what crate is it referring to?
|
/// Given an instance of this key, what crate is it referring to?
|
||||||
/// This is used to find the provider.
|
/// 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
|
/// 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?
|
/// given for a query with key `self`, what span should we use?
|
||||||
|
@ -22,8 +22,9 @@ pub trait Key {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for () {
|
impl Key for () {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||||
|
@ -32,8 +33,9 @@ impl Key for () {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Key for ty::InstanceDef<'tcx> {
|
impl<'tcx> Key for ty::InstanceDef<'tcx> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
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> {
|
impl<'tcx> Key for ty::Instance<'tcx> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
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> {
|
impl<'tcx> Key for mir::interpret::GlobalId<'tcx> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.instance.query_crate()
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
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> {
|
impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||||
|
@ -72,8 +77,9 @@ impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for CrateNum {
|
impl Key for CrateNum {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
*self
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
*self == LOCAL_CRATE
|
||||||
}
|
}
|
||||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||||
DUMMY_SP
|
DUMMY_SP
|
||||||
|
@ -81,8 +87,9 @@ impl Key for CrateNum {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for LocalDefId {
|
impl Key for LocalDefId {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.to_def_id().query_crate()
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
self.to_def_id().default_span(tcx)
|
self.to_def_id().default_span(tcx)
|
||||||
|
@ -90,8 +97,9 @@ impl Key for LocalDefId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for DefId {
|
impl Key for DefId {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.krate
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
self.krate == LOCAL_CRATE
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
tcx.def_span(*self)
|
tcx.def_span(*self)
|
||||||
|
@ -99,8 +107,9 @@ impl Key for DefId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for ty::WithOptConstParam<LocalDefId> {
|
impl Key for ty::WithOptConstParam<LocalDefId> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.did.query_crate()
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
self.did.default_span(tcx)
|
self.did.default_span(tcx)
|
||||||
|
@ -108,8 +117,9 @@ impl Key for ty::WithOptConstParam<LocalDefId> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for (DefId, DefId) {
|
impl Key for (DefId, DefId) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.0.krate
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
self.0.krate == LOCAL_CRATE
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
self.1.default_span(tcx)
|
self.1.default_span(tcx)
|
||||||
|
@ -117,8 +127,9 @@ impl Key for (DefId, DefId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for (ty::Instance<'tcx>, LocalDefId) {
|
impl Key for (ty::Instance<'tcx>, LocalDefId) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.0.query_crate()
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
self.0.default_span(tcx)
|
self.0.default_span(tcx)
|
||||||
|
@ -126,8 +137,9 @@ impl Key for (ty::Instance<'tcx>, LocalDefId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for (DefId, LocalDefId) {
|
impl Key for (DefId, LocalDefId) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.0.krate
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
self.0.krate == LOCAL_CRATE
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
self.1.default_span(tcx)
|
self.1.default_span(tcx)
|
||||||
|
@ -135,8 +147,9 @@ impl Key for (DefId, LocalDefId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for (LocalDefId, DefId) {
|
impl Key for (LocalDefId, DefId) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
self.0.default_span(tcx)
|
self.0.default_span(tcx)
|
||||||
|
@ -144,8 +157,9 @@ impl Key for (LocalDefId, DefId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for (DefId, Option<Ident>) {
|
impl Key for (DefId, Option<Ident>) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.0.krate
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
self.0.krate == LOCAL_CRATE
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
tcx.def_span(self.0)
|
tcx.def_span(self.0)
|
||||||
|
@ -153,8 +167,9 @@ impl Key for (DefId, Option<Ident>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for (DefId, LocalDefId, Ident) {
|
impl Key for (DefId, LocalDefId, Ident) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.0.krate
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
self.0.krate == LOCAL_CRATE
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
self.1.default_span(tcx)
|
self.1.default_span(tcx)
|
||||||
|
@ -162,8 +177,9 @@ impl Key for (DefId, LocalDefId, Ident) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for (CrateNum, DefId) {
|
impl Key for (CrateNum, DefId) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.0
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
self.0 == LOCAL_CRATE
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
self.1.default_span(tcx)
|
self.1.default_span(tcx)
|
||||||
|
@ -171,8 +187,9 @@ impl Key for (CrateNum, DefId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for (DefId, SimplifiedType) {
|
impl Key for (DefId, SimplifiedType) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.0.krate
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
self.0.krate == LOCAL_CRATE
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
self.0.default_span(tcx)
|
self.0.default_span(tcx)
|
||||||
|
@ -180,8 +197,9 @@ impl Key for (DefId, SimplifiedType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Key for SubstsRef<'tcx> {
|
impl<'tcx> Key for SubstsRef<'tcx> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||||
DUMMY_SP
|
DUMMY_SP
|
||||||
|
@ -189,8 +207,9 @@ impl<'tcx> Key for SubstsRef<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Key for (DefId, SubstsRef<'tcx>) {
|
impl<'tcx> Key for (DefId, SubstsRef<'tcx>) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.0.krate
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
self.0.krate == LOCAL_CRATE
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
self.0.default_span(tcx)
|
self.0.default_span(tcx)
|
||||||
|
@ -203,8 +222,9 @@ impl<'tcx> Key
|
||||||
(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
|
(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
(self.0).0.did.krate
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
(self.0).0.did.krate == LOCAL_CRATE
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
(self.0).0.did.default_span(tcx)
|
(self.0).0.did.default_span(tcx)
|
||||||
|
@ -212,8 +232,9 @@ impl<'tcx> Key
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Key for (LocalDefId, DefId, SubstsRef<'tcx>) {
|
impl<'tcx> Key for (LocalDefId, DefId, SubstsRef<'tcx>) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
self.0.default_span(tcx)
|
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>) {
|
impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.1.def_id().krate
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
self.1.def_id().krate == LOCAL_CRATE
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
tcx.def_span(self.1.def_id())
|
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) {
|
impl<'tcx> Key for (&'tcx ty::Const<'tcx>, mir::Field) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||||
DUMMY_SP
|
DUMMY_SP
|
||||||
|
@ -239,8 +262,9 @@ impl<'tcx> Key for (&'tcx ty::Const<'tcx>, mir::Field) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Key for mir::interpret::ConstAlloc<'tcx> {
|
impl<'tcx> Key for mir::interpret::ConstAlloc<'tcx> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||||
DUMMY_SP
|
DUMMY_SP
|
||||||
|
@ -248,8 +272,9 @@ impl<'tcx> Key for mir::interpret::ConstAlloc<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Key for ty::PolyTraitRef<'tcx> {
|
impl<'tcx> Key for ty::PolyTraitRef<'tcx> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.def_id().krate
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
self.def_id().krate == LOCAL_CRATE
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
tcx.def_span(self.def_id())
|
tcx.def_span(self.def_id())
|
||||||
|
@ -257,8 +282,9 @@ impl<'tcx> Key for ty::PolyTraitRef<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Key for GenericArg<'tcx> {
|
impl<'tcx> Key for GenericArg<'tcx> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||||
DUMMY_SP
|
DUMMY_SP
|
||||||
|
@ -266,8 +292,9 @@ impl<'tcx> Key for GenericArg<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Key for mir::ConstantKind<'tcx> {
|
impl<'tcx> Key for mir::ConstantKind<'tcx> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||||
DUMMY_SP
|
DUMMY_SP
|
||||||
|
@ -275,8 +302,9 @@ impl<'tcx> Key for mir::ConstantKind<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Key for &'tcx ty::Const<'tcx> {
|
impl<'tcx> Key for &'tcx ty::Const<'tcx> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||||
DUMMY_SP
|
DUMMY_SP
|
||||||
|
@ -284,8 +312,9 @@ impl<'tcx> Key for &'tcx ty::Const<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Key for Ty<'tcx> {
|
impl<'tcx> Key for Ty<'tcx> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||||
DUMMY_SP
|
DUMMY_SP
|
||||||
|
@ -293,8 +322,9 @@ impl<'tcx> Key for Ty<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Key for &'tcx ty::List<ty::Predicate<'tcx>> {
|
impl<'tcx> Key for &'tcx ty::List<ty::Predicate<'tcx>> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||||
DUMMY_SP
|
DUMMY_SP
|
||||||
|
@ -302,8 +332,9 @@ impl<'tcx> Key for &'tcx ty::List<ty::Predicate<'tcx>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Key for ty::ParamEnv<'tcx> {
|
impl<'tcx> Key for ty::ParamEnv<'tcx> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||||
DUMMY_SP
|
DUMMY_SP
|
||||||
|
@ -311,8 +342,9 @@ impl<'tcx> Key for ty::ParamEnv<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> {
|
impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
self.value.query_crate()
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
self.value.query_crate_is_local()
|
||||||
}
|
}
|
||||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
self.value.default_span(tcx)
|
self.value.default_span(tcx)
|
||||||
|
@ -320,8 +352,9 @@ impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Key for Symbol {
|
impl Key for Symbol {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||||
DUMMY_SP
|
DUMMY_SP
|
||||||
|
@ -331,8 +364,9 @@ impl Key for Symbol {
|
||||||
/// Canonical query goals correspond to abstract trait operations that
|
/// Canonical query goals correspond to abstract trait operations that
|
||||||
/// are not tied to any crate in particular.
|
/// are not tied to any crate in particular.
|
||||||
impl<'tcx, T> Key for Canonical<'tcx, T> {
|
impl<'tcx, T> Key for Canonical<'tcx, T> {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
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) {
|
impl Key for (Symbol, u32, u32) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
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>) {
|
impl<'tcx> Key for (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>) {
|
||||||
fn query_crate(&self) -> CrateNum {
|
#[inline(always)]
|
||||||
LOCAL_CRATE
|
fn query_crate_is_local(&self) -> bool {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
|
||||||
|
|
|
@ -15,7 +15,6 @@ extern crate tracing;
|
||||||
use rustc_data_structures::fingerprint::Fingerprint;
|
use rustc_data_structures::fingerprint::Fingerprint;
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_errors::{DiagnosticBuilder, Handler};
|
use rustc_errors::{DiagnosticBuilder, Handler};
|
||||||
use rustc_hir::def_id::LOCAL_CRATE;
|
|
||||||
use rustc_middle::dep_graph;
|
use rustc_middle::dep_graph;
|
||||||
use rustc_middle::ich::StableHashingContext;
|
use rustc_middle::ich::StableHashingContext;
|
||||||
use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values};
|
use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values};
|
||||||
|
|
|
@ -353,14 +353,14 @@ macro_rules! define_queries {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn compute(tcx: QueryCtxt<'tcx>, key: Self::Key) -> Self::Value {
|
fn compute_fn(tcx: QueryCtxt<'tcx>, key: &Self::Key) ->
|
||||||
let is_local = key.query_crate() == LOCAL_CRATE;
|
fn(TyCtxt<'tcx>, Self::Key) -> Self::Value
|
||||||
let provider = if is_local {
|
{
|
||||||
|
if key.query_crate_is_local() {
|
||||||
tcx.queries.local_providers.$name
|
tcx.queries.local_providers.$name
|
||||||
} else {
|
} else {
|
||||||
tcx.queries.extern_providers.$name
|
tcx.queries.extern_providers.$name
|
||||||
};
|
}
|
||||||
provider(*tcx, key)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash_result(
|
fn hash_result(
|
||||||
|
|
|
@ -23,9 +23,6 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
|
||||||
pub dep_kind: CTX::DepKind,
|
pub dep_kind: CTX::DepKind,
|
||||||
pub eval_always: bool,
|
pub eval_always: bool,
|
||||||
|
|
||||||
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
|
||||||
pub compute: fn(CTX, K) -> V,
|
|
||||||
|
|
||||||
pub hash_result: fn(&mut CTX::StableHashingContext, &V) -> Option<Fingerprint>,
|
pub hash_result: fn(&mut CTX::StableHashingContext, &V) -> Option<Fingerprint>,
|
||||||
pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_>) -> V,
|
pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_>) -> V,
|
||||||
pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool,
|
pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool,
|
||||||
|
@ -40,10 +37,6 @@ impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
|
||||||
DepNode::construct(tcx, self.dep_kind, key)
|
DepNode::construct(tcx, self.dep_kind, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute(&self, tcx: CTX, key: K) -> V {
|
|
||||||
(self.compute)(tcx, key)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn hash_result(
|
pub(crate) fn hash_result(
|
||||||
&self,
|
&self,
|
||||||
hcx: &mut CTX::StableHashingContext,
|
hcx: &mut CTX::StableHashingContext,
|
||||||
|
@ -79,7 +72,7 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig {
|
||||||
CTX: 'a;
|
CTX: 'a;
|
||||||
|
|
||||||
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
||||||
fn compute(tcx: CTX, key: Self::Key) -> Self::Value;
|
fn compute_fn(tcx: CTX, key: &Self::Key) -> fn(CTX::DepContext, Self::Key) -> Self::Value;
|
||||||
|
|
||||||
fn hash_result(
|
fn hash_result(
|
||||||
hcx: &mut CTX::StableHashingContext,
|
hcx: &mut CTX::StableHashingContext,
|
||||||
|
@ -115,7 +108,6 @@ where
|
||||||
anon: Q::ANON,
|
anon: Q::ANON,
|
||||||
dep_kind: Q::DEP_KIND,
|
dep_kind: Q::DEP_KIND,
|
||||||
eval_always: Q::EVAL_ALWAYS,
|
eval_always: Q::EVAL_ALWAYS,
|
||||||
compute: Q::compute,
|
|
||||||
hash_result: Q::hash_result,
|
hash_result: Q::hash_result,
|
||||||
handle_cycle_error: Q::handle_cycle_error,
|
handle_cycle_error: Q::handle_cycle_error,
|
||||||
cache_on_disk: Q::cache_on_disk,
|
cache_on_disk: Q::cache_on_disk,
|
||||||
|
|
|
@ -428,6 +428,7 @@ fn try_execute_query<CTX, C>(
|
||||||
key: C::Key,
|
key: C::Key,
|
||||||
lookup: QueryLookup,
|
lookup: QueryLookup,
|
||||||
query: &QueryVtable<CTX, C::Key, C::Value>,
|
query: &QueryVtable<CTX, C::Key, C::Value>,
|
||||||
|
compute: fn(CTX::DepContext, C::Key) -> C::Value,
|
||||||
) -> C::Stored
|
) -> C::Stored
|
||||||
where
|
where
|
||||||
C: QueryCache,
|
C: QueryCache,
|
||||||
|
@ -457,7 +458,7 @@ where
|
||||||
// Fast path for when incr. comp. is off.
|
// Fast path for when incr. comp. is off.
|
||||||
if !dep_graph.is_fully_enabled() {
|
if !dep_graph.is_fully_enabled() {
|
||||||
let prof_timer = tcx.dep_context().profiler().query_provider();
|
let prof_timer = tcx.dep_context().profiler().query_provider();
|
||||||
let result = tcx.start_query(job.id, None, || query.compute(tcx, key));
|
let result = tcx.start_query(job.id, None, || compute(*tcx.dep_context(), key));
|
||||||
let dep_node_index = dep_graph.next_virtual_depnode_index();
|
let dep_node_index = dep_graph.next_virtual_depnode_index();
|
||||||
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
|
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
|
||||||
return job.complete(result, dep_node_index);
|
return job.complete(result, dep_node_index);
|
||||||
|
@ -468,8 +469,9 @@ where
|
||||||
|
|
||||||
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
|
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
|
||||||
tcx.start_query(job.id, diagnostics, || {
|
tcx.start_query(job.id, diagnostics, || {
|
||||||
dep_graph
|
dep_graph.with_anon_task(*tcx.dep_context(), query.dep_kind, || {
|
||||||
.with_anon_task(*tcx.dep_context(), query.dep_kind, || query.compute(tcx, key))
|
compute(*tcx.dep_context(), key)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -501,6 +503,7 @@ where
|
||||||
dep_node_index,
|
dep_node_index,
|
||||||
&dep_node,
|
&dep_node,
|
||||||
query,
|
query,
|
||||||
|
compute,
|
||||||
),
|
),
|
||||||
dep_node_index,
|
dep_node_index,
|
||||||
)
|
)
|
||||||
|
@ -511,7 +514,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (result, dep_node_index) = force_query_with_job(tcx, key, job, dep_node, query);
|
let (result, dep_node_index) = force_query_with_job(tcx, key, job, dep_node, query, compute);
|
||||||
dep_graph.read_index(dep_node_index);
|
dep_graph.read_index(dep_node_index);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -523,6 +526,7 @@ fn load_from_disk_and_cache_in_memory<CTX, K, V: Debug>(
|
||||||
dep_node_index: DepNodeIndex,
|
dep_node_index: DepNodeIndex,
|
||||||
dep_node: &DepNode<CTX::DepKind>,
|
dep_node: &DepNode<CTX::DepKind>,
|
||||||
query: &QueryVtable<CTX, K, V>,
|
query: &QueryVtable<CTX, K, V>,
|
||||||
|
compute: fn(CTX::DepContext, K) -> V,
|
||||||
) -> V
|
) -> V
|
||||||
where
|
where
|
||||||
CTX: QueryContext,
|
CTX: QueryContext,
|
||||||
|
@ -565,7 +569,7 @@ where
|
||||||
let prof_timer = tcx.dep_context().profiler().query_provider();
|
let prof_timer = tcx.dep_context().profiler().query_provider();
|
||||||
|
|
||||||
// The dep-graph for this computation is already in-place.
|
// The dep-graph for this computation is already in-place.
|
||||||
let result = tcx.dep_context().dep_graph().with_ignore(|| query.compute(tcx, key));
|
let result = tcx.dep_context().dep_graph().with_ignore(|| compute(*tcx.dep_context(), key));
|
||||||
|
|
||||||
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
|
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
|
||||||
|
|
||||||
|
@ -627,6 +631,7 @@ fn force_query_with_job<C, CTX>(
|
||||||
job: JobOwner<'_, CTX::DepKind, C>,
|
job: JobOwner<'_, CTX::DepKind, C>,
|
||||||
dep_node: DepNode<CTX::DepKind>,
|
dep_node: DepNode<CTX::DepKind>,
|
||||||
query: &QueryVtable<CTX, C::Key, C::Value>,
|
query: &QueryVtable<CTX, C::Key, C::Value>,
|
||||||
|
compute: fn(CTX::DepContext, C::Key) -> C::Value,
|
||||||
) -> (C::Stored, DepNodeIndex)
|
) -> (C::Stored, DepNodeIndex)
|
||||||
where
|
where
|
||||||
C: QueryCache,
|
C: QueryCache,
|
||||||
|
@ -653,17 +658,17 @@ where
|
||||||
if query.eval_always {
|
if query.eval_always {
|
||||||
tcx.dep_context().dep_graph().with_eval_always_task(
|
tcx.dep_context().dep_graph().with_eval_always_task(
|
||||||
dep_node,
|
dep_node,
|
||||||
tcx,
|
*tcx.dep_context(),
|
||||||
key,
|
key,
|
||||||
query.compute,
|
compute,
|
||||||
query.hash_result,
|
query.hash_result,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
tcx.dep_context().dep_graph().with_task(
|
tcx.dep_context().dep_graph().with_task(
|
||||||
dep_node,
|
dep_node,
|
||||||
tcx,
|
*tcx.dep_context(),
|
||||||
key,
|
key,
|
||||||
query.compute,
|
compute,
|
||||||
query.hash_result,
|
query.hash_result,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -690,13 +695,14 @@ fn get_query_impl<CTX, C>(
|
||||||
key: C::Key,
|
key: C::Key,
|
||||||
lookup: QueryLookup,
|
lookup: QueryLookup,
|
||||||
query: &QueryVtable<CTX, C::Key, C::Value>,
|
query: &QueryVtable<CTX, C::Key, C::Value>,
|
||||||
|
compute: fn(CTX::DepContext, C::Key) -> C::Value,
|
||||||
) -> C::Stored
|
) -> C::Stored
|
||||||
where
|
where
|
||||||
CTX: QueryContext,
|
CTX: QueryContext,
|
||||||
C: QueryCache,
|
C: QueryCache,
|
||||||
C::Key: DepNodeParams<CTX::DepContext>,
|
C::Key: DepNodeParams<CTX::DepContext>,
|
||||||
{
|
{
|
||||||
try_execute_query(tcx, state, cache, span, key, lookup, query)
|
try_execute_query(tcx, state, cache, span, key, lookup, query, compute)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensure that either this query has all green inputs or been executed.
|
/// Ensure that either this query has all green inputs or been executed.
|
||||||
|
@ -744,8 +750,10 @@ fn force_query_impl<CTX, C>(
|
||||||
tcx: CTX,
|
tcx: CTX,
|
||||||
state: &QueryState<CTX::DepKind, C::Key>,
|
state: &QueryState<CTX::DepKind, C::Key>,
|
||||||
cache: &QueryCacheStore<C>,
|
cache: &QueryCacheStore<C>,
|
||||||
|
key: C::Key,
|
||||||
dep_node: DepNode<CTX::DepKind>,
|
dep_node: DepNode<CTX::DepKind>,
|
||||||
query: &QueryVtable<CTX, C::Key, C::Value>,
|
query: &QueryVtable<CTX, C::Key, C::Value>,
|
||||||
|
compute: fn(CTX::DepContext, C::Key) -> C::Value,
|
||||||
) -> bool
|
) -> bool
|
||||||
where
|
where
|
||||||
C: QueryCache,
|
C: QueryCache,
|
||||||
|
@ -754,18 +762,6 @@ where
|
||||||
{
|
{
|
||||||
debug_assert!(!query.anon);
|
debug_assert!(!query.anon);
|
||||||
|
|
||||||
if !<C::Key as DepNodeParams<CTX::DepContext>>::can_reconstruct_query_key() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let key = if let Some(key) =
|
|
||||||
<C::Key as DepNodeParams<CTX::DepContext>>::recover(*tcx.dep_context(), &dep_node)
|
|
||||||
{
|
|
||||||
key
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// We may be concurrently trying both execute and force a query.
|
// We may be concurrently trying both execute and force a query.
|
||||||
// Ensure that only one of them runs the query.
|
// Ensure that only one of them runs the query.
|
||||||
let cached = cache.cache.lookup(cache, &key, |_, index| {
|
let cached = cache.cache.lookup(cache, &key, |_, index| {
|
||||||
|
@ -798,7 +794,7 @@ where
|
||||||
TryGetJob::JobCompleted(_) => return true,
|
TryGetJob::JobCompleted(_) => return true,
|
||||||
};
|
};
|
||||||
|
|
||||||
force_query_with_job(tcx, key, job, dep_node, query);
|
force_query_with_job(tcx, key, job, dep_node, query, compute);
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -828,8 +824,17 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span);
|
debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span);
|
||||||
let value =
|
let compute = Q::compute_fn(tcx, &key);
|
||||||
get_query_impl(tcx, Q::query_state(tcx), Q::query_cache(tcx), span, key, lookup, query);
|
let value = get_query_impl(
|
||||||
|
tcx,
|
||||||
|
Q::query_state(tcx),
|
||||||
|
Q::query_cache(tcx),
|
||||||
|
span,
|
||||||
|
key,
|
||||||
|
lookup,
|
||||||
|
query,
|
||||||
|
compute,
|
||||||
|
);
|
||||||
Some(value)
|
Some(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -843,5 +848,26 @@ where
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
force_query_impl(tcx, Q::query_state(tcx), Q::query_cache(tcx), *dep_node, &Q::VTABLE)
|
if !<Q::Key as DepNodeParams<CTX::DepContext>>::can_reconstruct_query_key() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let key = if let Some(key) =
|
||||||
|
<Q::Key as DepNodeParams<CTX::DepContext>>::recover(*tcx.dep_context(), &dep_node)
|
||||||
|
{
|
||||||
|
key
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
let compute = Q::compute_fn(tcx, &key);
|
||||||
|
force_query_impl(
|
||||||
|
tcx,
|
||||||
|
Q::query_state(tcx),
|
||||||
|
Q::query_cache(tcx),
|
||||||
|
key,
|
||||||
|
*dep_node,
|
||||||
|
&Q::VTABLE,
|
||||||
|
compute,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue