diff --git a/compiler/rustc_query_system/src/cache.rs b/compiler/rustc_middle/src/traits/cache.rs similarity index 82% rename from compiler/rustc_query_system/src/cache.rs rename to compiler/rustc_middle/src/traits/cache.rs index 4217d0a49b91d..ed41a69f97148 100644 --- a/compiler/rustc_query_system/src/cache.rs +++ b/compiler/rustc_middle/src/traits/cache.rs @@ -7,23 +7,23 @@ use rustc_data_structures::sync::Lock; use crate::dep_graph::{DepContext, DepNodeIndex}; -pub struct Cache { +pub struct WithDepNodeCache { hashmap: Lock>>, } -impl Clone for Cache { +impl Clone for WithDepNodeCache { fn clone(&self) -> Self { Self { hashmap: Lock::new(self.hashmap.borrow().clone()) } } } -impl Default for Cache { +impl Default for WithDepNodeCache { fn default() -> Self { Self { hashmap: Default::default() } } } -impl Cache { +impl WithDepNodeCache { pub fn get(&self, key: &Key, tcx: Tcx) -> Option { Some(self.hashmap.borrow().get(key)?.get(tcx)) } diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 3a1682614cbf1..75323bf5c8cc9 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -2,6 +2,7 @@ //! //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/resolution.html +pub mod cache; pub mod query; pub mod select; pub mod solve; diff --git a/compiler/rustc_middle/src/traits/select.rs b/compiler/rustc_middle/src/traits/select.rs index 3861efd364281..3a32029c60bd0 100644 --- a/compiler/rustc_middle/src/traits/select.rs +++ b/compiler/rustc_middle/src/traits/select.rs @@ -5,17 +5,20 @@ use rustc_errors::ErrorGuaranteed; use rustc_hir::def_id::DefId; use rustc_macros::{HashStable, TypeVisitable}; -use rustc_query_system::cache::Cache; use rustc_type_ir::solve::AliasBoundKind; use self::EvaluationResult::*; use super::{SelectionError, SelectionResult}; +use crate::traits::cache::WithDepNodeCache; use crate::ty; -pub type SelectionCache<'tcx, ENV> = - Cache<(ENV, ty::TraitPredicate<'tcx>), SelectionResult<'tcx, SelectionCandidate<'tcx>>>; +pub type SelectionCache<'tcx, ENV> = WithDepNodeCache< + (ENV, ty::TraitPredicate<'tcx>), + SelectionResult<'tcx, SelectionCandidate<'tcx>>, +>; -pub type EvaluationCache<'tcx, ENV> = Cache<(ENV, ty::PolyTraitPredicate<'tcx>), EvaluationResult>; +pub type EvaluationCache<'tcx, ENV> = + WithDepNodeCache<(ENV, ty::PolyTraitPredicate<'tcx>), EvaluationResult>; /// The selection process begins by considering all impls, where /// clauses, and so forth that might resolve an obligation. Sometimes diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 41e1388e31464..b283c08b90dee 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -40,7 +40,6 @@ use rustc_hir::lang_items::LangItem; use rustc_hir::limit::Limit; use rustc_hir::{self as hir, HirId, Node, TraitCandidate, find_attr}; use rustc_index::IndexVec; -use rustc_query_system::cache::WithDepNode; use rustc_query_system::dep_graph::DepNodeIndex; use rustc_query_system::ich::StableHashingContext; use rustc_serialize::opaque::{FileEncodeResult, FileEncoder}; @@ -71,6 +70,7 @@ use crate::query::plumbing::QuerySystem; use crate::query::{IntoQueryParam, LocalCrate, Providers, TyCtxtAt}; use crate::thir::Thir; use crate::traits; +use crate::traits::cache::WithDepNode; use crate::traits::solve::{ self, CanonicalInput, ExternalConstraints, ExternalConstraintsData, PredefinedOpaques, QueryResult, inspect, diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs index 61edf397886b1..b61b9b71b5283 100644 --- a/compiler/rustc_query_system/src/lib.rs +++ b/compiler/rustc_query_system/src/lib.rs @@ -5,7 +5,6 @@ #![feature(min_specialization)] // tidy-alphabetical-end -pub mod cache; pub mod dep_graph; mod error; pub mod ich;