Skip to content
Closed
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
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ pub struct DerivedObligationCause<'tcx> {
pub parent_code: InternedObligationCauseCode<'tcx>,
}

#[derive(Clone, Debug, TypeFoldable, TypeVisitable, Lift)]
#[derive(PartialEq, Eq, Clone, Debug, TypeFoldable, TypeVisitable, Lift)]
pub enum SelectionError<'tcx> {
/// The trait is not implemented.
Unimplemented,
Expand Down
14 changes: 12 additions & 2 deletions compiler/rustc_query_system/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::dep_graph::{DepContext, DepNodeIndex};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lock;

use std::fmt::Debug;
use std::hash::Hash;

pub struct Cache<Key, Value> {
Expand All @@ -30,13 +31,22 @@ impl<Key, Value> Cache<Key, Value> {
}
}

impl<Key: Eq + Hash, Value: Clone> Cache<Key, Value> {
impl<Key: Eq + Hash, Value: Eq + Clone + Debug> Cache<Key, Value> {
pub fn get<Tcx: DepContext>(&self, key: &Key, tcx: Tcx) -> Option<Value> {
Some(self.hashmap.borrow().get(key)?.get(tcx))
}

pub fn insert(&self, key: Key, dep_node: DepNodeIndex, value: Value) {
self.hashmap.borrow_mut().insert(key, WithDepNode::new(dep_node, value));
// FIXME(#50507): For some reason we're getting different `DepNodeIndex`es
// for the same evaluation in the parallel compiler. Once that's fixed
// we can just use `HashMap::insert_same` here instead of doing all this.
self.hashmap
.borrow_mut()
.entry(key)
.and_modify(|old_value| {
assert_eq!(old_value.cached_value, value, "unstable cached value")
})
.or_insert(WithDepNode::new(dep_node, value));
}
}

Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1333,10 +1333,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
if self.can_use_global_caches(param_env) {
if !trait_pred.needs_infer() {
debug!(?trait_pred, ?result, "insert_evaluation_cache global");
// This may overwrite the cache with the same value
// FIXME: Due to #50507 this overwrites the different values
// This should be changed to use HashMapExt::insert_same
// when that is fixed
self.tcx().evaluation_cache.insert((param_env, trait_pred), dep_node, result);
return;
}
Expand Down