Skip to content

Commit

Permalink
Queryify Instance::resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Feb 28, 2020
1 parent eaa02f5 commit 8035fdb
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 25 deletions.
5 changes: 5 additions & 0 deletions src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1257,5 +1257,10 @@ rustc_queries! {
eval_always
desc { "looking up enabled feature gates" }
}

query resolve_instance(key: (ty::ParamEnv<'tcx>, DefId, SubstsRef<'tcx>)) -> Option<ty::Instance<'tcx>> {
no_force
desc { "resolving instance `{:?}` `{:?}` with {:?}", key.1, key.2, key.0 }
}
}
}
21 changes: 1 addition & 20 deletions src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::middle::lang_items::DropInPlaceFnLangItem;
use crate::ty::print::{FmtPrinter, Printer};
use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeFoldable};
use rustc_data_structures::AtomicRef;
use rustc_hir::def::Namespace;
use rustc_hir::def_id::{CrateNum, DefId};
use rustc_macros::HashStable;
Expand Down Expand Up @@ -279,7 +278,7 @@ impl<'tcx> Instance<'tcx> {
def_id: DefId,
substs: SubstsRef<'tcx>,
) -> Option<Instance<'tcx>> {
(*RESOLVE_INSTANCE)(tcx, param_env, def_id, substs)
tcx.resolve_instance((param_env, def_id, substs))
}

pub fn resolve_for_fn_ptr(
Expand Down Expand Up @@ -408,21 +407,3 @@ fn needs_fn_once_adapter_shim(
(ty::ClosureKind::FnMut, _) | (ty::ClosureKind::FnOnce, _) => Err(()),
}
}

fn resolve_instance_default(
_tcx: TyCtxt<'tcx>,
_param_env: ty::ParamEnv<'tcx>,
_def_id: DefId,
_substs: SubstsRef<'tcx>,
) -> Option<Instance<'tcx>> {
unimplemented!()
}

pub static RESOLVE_INSTANCE: AtomicRef<
for<'tcx> fn(
TyCtxt<'tcx>,
ty::ParamEnv<'tcx>,
DefId,
SubstsRef<'tcx>,
) -> Option<Instance<'tcx>>,
> = AtomicRef::new(&(resolve_instance_default as _));
1 change: 0 additions & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ pub use self::context::{
CtxtInterners, GeneratorInteriorTypeCause, GlobalCtxt, Lift, TypeckTables,
};

pub use self::instance::RESOLVE_INSTANCE;
pub use self::instance::{Instance, InstanceDef};

pub use self::trait_def::TraitDef;
Expand Down
11 changes: 11 additions & 0 deletions src/librustc/ty/query/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,14 @@ impl Key for (Symbol, u32, u32) {
DUMMY_SP
}
}

impl<'tcx> Key for (ty::ParamEnv<'tcx>, DefId, SubstsRef<'tcx>) {
type CacheSelector = DefaultCacheSelector;

fn query_crate(&self) -> CrateNum {
self.1.krate
}
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.def_span(self.1)
}
}
1 change: 0 additions & 1 deletion src/librustc_interface/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,4 @@ pub fn setup_callbacks() {
rustc_span::SPAN_DEBUG.swap(&(span_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
rustc_hir::def_id::DEF_ID_DEBUG.swap(&(def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
TRACK_DIAGNOSTICS.swap(&(track_diagnostic as fn(&_)));
rustc::ty::RESOLVE_INSTANCE.swap(&(rustc_ty::instance::resolve_instance as _));
}
8 changes: 5 additions & 3 deletions src/librustc_ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use log::debug;

pub fn resolve_instance<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
def_id: DefId,
substs: SubstsRef<'tcx>,
(param_env, def_id, substs): (ty::ParamEnv<'tcx>, DefId, SubstsRef<'tcx>),
) -> Option<Instance<'tcx>> {
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) {
Expand Down Expand Up @@ -134,3 +132,7 @@ fn resolve_associated_item<'tcx>(
traits::VtableAutoImpl(..) | traits::VtableParam(..) | traits::VtableTraitAlias(..) => None,
}
}

pub fn provide(providers: &mut ty::query::Providers<'_>) {
*providers = ty::query::Providers { resolve_instance, ..*providers };
}
1 change: 1 addition & 0 deletions src/librustc_ty/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ pub fn provide(providers: &mut Providers<'_>) {
common_traits::provide(providers);
needs_drop::provide(providers);
ty::provide(providers);
instance::provide(providers);
}

0 comments on commit 8035fdb

Please sign in to comment.