Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ use rustc_data_structures::sync::Lock;

use crate::dep_graph::{DepContext, DepNodeIndex};

pub struct Cache<Key, Value> {
pub struct WithDepNodeCache<Key, Value> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: This is a good example of my philosophy that an “inelegant” name is better than a name that is simple but confusing. 👍

hashmap: Lock<FxHashMap<Key, WithDepNode<Value>>>,
}

impl<Key: Clone, Value: Clone> Clone for Cache<Key, Value> {
impl<Key: Clone, Value: Clone> Clone for WithDepNodeCache<Key, Value> {
fn clone(&self) -> Self {
Self { hashmap: Lock::new(self.hashmap.borrow().clone()) }
}
}

impl<Key, Value> Default for Cache<Key, Value> {
impl<Key, Value> Default for WithDepNodeCache<Key, Value> {
fn default() -> Self {
Self { hashmap: Default::default() }
}
}

impl<Key: Eq + Hash, Value: Clone> Cache<Key, Value> {
impl<Key: Eq + Hash, Value: Clone> WithDepNodeCache<Key, Value> {
pub fn get<Tcx: DepContext>(&self, key: &Key, tcx: Tcx) -> Option<Value> {
Some(self.hashmap.borrow().get(key)?.get(tcx))
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_middle/src/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_query_system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![feature(min_specialization)]
// tidy-alphabetical-end

pub mod cache;
pub mod dep_graph;
mod error;
pub mod ich;
Expand Down
Loading