Skip to content

Commit 8035fdb

Browse files
committed
Queryify Instance::resolve
1 parent eaa02f5 commit 8035fdb

File tree

7 files changed

+23
-25
lines changed

7 files changed

+23
-25
lines changed

src/librustc/query/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1257,5 +1257,10 @@ rustc_queries! {
12571257
eval_always
12581258
desc { "looking up enabled feature gates" }
12591259
}
1260+
1261+
query resolve_instance(key: (ty::ParamEnv<'tcx>, DefId, SubstsRef<'tcx>)) -> Option<ty::Instance<'tcx>> {
1262+
no_force
1263+
desc { "resolving instance `{:?}` `{:?}` with {:?}", key.1, key.2, key.0 }
1264+
}
12601265
}
12611266
}

src/librustc/ty/instance.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
22
use crate::middle::lang_items::DropInPlaceFnLangItem;
33
use crate::ty::print::{FmtPrinter, Printer};
44
use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeFoldable};
5-
use rustc_data_structures::AtomicRef;
65
use rustc_hir::def::Namespace;
76
use rustc_hir::def_id::{CrateNum, DefId};
87
use rustc_macros::HashStable;
@@ -279,7 +278,7 @@ impl<'tcx> Instance<'tcx> {
279278
def_id: DefId,
280279
substs: SubstsRef<'tcx>,
281280
) -> Option<Instance<'tcx>> {
282-
(*RESOLVE_INSTANCE)(tcx, param_env, def_id, substs)
281+
tcx.resolve_instance((param_env, def_id, substs))
283282
}
284283

285284
pub fn resolve_for_fn_ptr(
@@ -408,21 +407,3 @@ fn needs_fn_once_adapter_shim(
408407
(ty::ClosureKind::FnMut, _) | (ty::ClosureKind::FnOnce, _) => Err(()),
409408
}
410409
}
411-
412-
fn resolve_instance_default(
413-
_tcx: TyCtxt<'tcx>,
414-
_param_env: ty::ParamEnv<'tcx>,
415-
_def_id: DefId,
416-
_substs: SubstsRef<'tcx>,
417-
) -> Option<Instance<'tcx>> {
418-
unimplemented!()
419-
}
420-
421-
pub static RESOLVE_INSTANCE: AtomicRef<
422-
for<'tcx> fn(
423-
TyCtxt<'tcx>,
424-
ty::ParamEnv<'tcx>,
425-
DefId,
426-
SubstsRef<'tcx>,
427-
) -> Option<Instance<'tcx>>,
428-
> = AtomicRef::new(&(resolve_instance_default as _));

src/librustc/ty/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ pub use self::context::{
8484
CtxtInterners, GeneratorInteriorTypeCause, GlobalCtxt, Lift, TypeckTables,
8585
};
8686

87-
pub use self::instance::RESOLVE_INSTANCE;
8887
pub use self::instance::{Instance, InstanceDef};
8988

9089
pub use self::trait_def::TraitDef;

src/librustc/ty/query/keys.rs

+11
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,14 @@ impl Key for (Symbol, u32, u32) {
285285
DUMMY_SP
286286
}
287287
}
288+
289+
impl<'tcx> Key for (ty::ParamEnv<'tcx>, DefId, SubstsRef<'tcx>) {
290+
type CacheSelector = DefaultCacheSelector;
291+
292+
fn query_crate(&self) -> CrateNum {
293+
self.1.krate
294+
}
295+
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
296+
tcx.def_span(self.1)
297+
}
298+
}

src/librustc_interface/callbacks.rs

-1
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,4 @@ pub fn setup_callbacks() {
5858
rustc_span::SPAN_DEBUG.swap(&(span_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
5959
rustc_hir::def_id::DEF_ID_DEBUG.swap(&(def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
6060
TRACK_DIAGNOSTICS.swap(&(track_diagnostic as fn(&_)));
61-
rustc::ty::RESOLVE_INSTANCE.swap(&(rustc_ty::instance::resolve_instance as _));
6261
}

src/librustc_ty/instance.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ use log::debug;
88

99
pub fn resolve_instance<'tcx>(
1010
tcx: TyCtxt<'tcx>,
11-
param_env: ty::ParamEnv<'tcx>,
12-
def_id: DefId,
13-
substs: SubstsRef<'tcx>,
11+
(param_env, def_id, substs): (ty::ParamEnv<'tcx>, DefId, SubstsRef<'tcx>),
1412
) -> Option<Instance<'tcx>> {
1513
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
1614
let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) {
@@ -134,3 +132,7 @@ fn resolve_associated_item<'tcx>(
134132
traits::VtableAutoImpl(..) | traits::VtableParam(..) | traits::VtableTraitAlias(..) => None,
135133
}
136134
}
135+
136+
pub fn provide(providers: &mut ty::query::Providers<'_>) {
137+
*providers = ty::query::Providers { resolve_instance, ..*providers };
138+
}

src/librustc_ty/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ pub fn provide(providers: &mut Providers<'_>) {
2525
common_traits::provide(providers);
2626
needs_drop::provide(providers);
2727
ty::provide(providers);
28+
instance::provide(providers);
2829
}

0 commit comments

Comments
 (0)