diff --git a/src/librustc_interface/callbacks.rs b/src/librustc_interface/callbacks.rs index 88c3d0ec56f..913c67d045e 100644 --- a/src/librustc_interface/callbacks.rs +++ b/src/librustc_interface/callbacks.rs @@ -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_middle::ty::RESOLVE_INSTANCE.swap(&(rustc_ty::instance::resolve_instance as _)); } diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 2ffbbfb1762..c26c043994f 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -1257,5 +1257,9 @@ fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String { eval_always desc { "looking up enabled feature gates" } } + + query resolve_instance(key: (ty::ParamEnv<'tcx>, DefId, SubstsRef<'tcx>)) -> Option> { + desc { "resolving instance `{:?}` `{:?}` with {:?}", key.1, key.2, key.0 } + } } } diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs index 5d47a6e13f4..cf0222370f2 100644 --- a/src/librustc_middle/ty/instance.rs +++ b/src/librustc_middle/ty/instance.rs @@ -1,7 +1,6 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; 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_hir::lang_items::DropInPlaceFnLangItem; @@ -289,7 +288,9 @@ pub fn resolve( def_id: DefId, substs: SubstsRef<'tcx>, ) -> Option> { - (*RESOLVE_INSTANCE)(tcx, param_env, def_id, substs) + // All regions in the result of this query are erased, so it's + // fine to erase all of the input regions. + tcx.resolve_instance((tcx.erase_regions(¶m_env), def_id, tcx.erase_regions(&substs))) } pub fn resolve_for_fn_ptr( @@ -440,21 +441,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> { - unimplemented!() -} - -pub static RESOLVE_INSTANCE: AtomicRef< - for<'tcx> fn( - TyCtxt<'tcx>, - ty::ParamEnv<'tcx>, - DefId, - SubstsRef<'tcx>, - ) -> Option>, -> = AtomicRef::new(&(resolve_instance_default as _)); diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 9b182333907..0ebd55a6c02 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -81,7 +81,6 @@ CtxtInterners, GeneratorInteriorTypeCause, GlobalCtxt, Lift, TypeckTables, }; -pub use self::instance::RESOLVE_INSTANCE; pub use self::instance::{Instance, InstanceDef}; pub use self::trait_def::TraitDef; diff --git a/src/librustc_middle/ty/query/keys.rs b/src/librustc_middle/ty/query/keys.rs index a261e484a85..438e7ed4331 100644 --- a/src/librustc_middle/ty/query/keys.rs +++ b/src/librustc_middle/ty/query/keys.rs @@ -296,3 +296,14 @@ fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { 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) + } +} diff --git a/src/librustc_ty/instance.rs b/src/librustc_ty/instance.rs index 677e373f2f4..955e2e36159 100644 --- a/src/librustc_ty/instance.rs +++ b/src/librustc_ty/instance.rs @@ -11,9 +11,7 @@ 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> { debug!("resolve(def_id={:?}, substs={:?})", def_id, substs); let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) { @@ -199,3 +197,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 }; +} diff --git a/src/librustc_ty/lib.rs b/src/librustc_ty/lib.rs index 04909b8b0c1..75e62e79640 100644 --- a/src/librustc_ty/lib.rs +++ b/src/librustc_ty/lib.rs @@ -25,4 +25,5 @@ pub fn provide(providers: &mut Providers<'_>) { common_traits::provide(providers); needs_drop::provide(providers); ty::provide(providers); + instance::provide(providers); }