Skip to content

Commit

Permalink
SsoHashMap
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Sep 26, 2024
1 parent a9ea892 commit a9dd08c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/relate/type_relating.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sso::SsoHashSet;
use rustc_middle::traits::solve::Goal;
use rustc_middle::ty::relate::{
Relate, RelateResult, TypeRelation, relate_args_invariantly, relate_args_with_variances,
Expand All @@ -17,7 +17,7 @@ pub struct TypeRelating<'combine, 'a, 'tcx> {
fields: &'combine mut CombineFields<'a, 'tcx>,
structurally_relate_aliases: StructurallyRelateAliases,
ambient_variance: ty::Variance,
cache: FxHashSet<(ty::Variance, Ty<'tcx>, Ty<'tcx>)>,
cache: SsoHashSet<(ty::Variance, Ty<'tcx>, Ty<'tcx>)>,
}

impl<'combine, 'infcx, 'tcx> TypeRelating<'combine, 'infcx, 'tcx> {
Expand Down
23 changes: 10 additions & 13 deletions compiler/rustc_infer/src/infer/resolve.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sso::SsoHashMap;
use rustc_middle::bug;
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFolder, TypeSuperFoldable};
use rustc_middle::ty::visit::TypeVisitableExt;
Expand All @@ -16,7 +16,7 @@ use super::{FixupError, FixupResult, InferCtxt};
/// points for correctness.
pub struct OpportunisticVarResolver<'a, 'tcx> {
infcx: &'a InferCtxt<'tcx>,
cache: FxHashMap<Ty<'tcx>, Ty<'tcx>>,
cache: SsoHashMap<Ty<'tcx>, Ty<'tcx>>,
}

impl<'a, 'tcx> OpportunisticVarResolver<'a, 'tcx> {
Expand All @@ -33,19 +33,16 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for OpportunisticVarResolver<'a, 'tcx> {

#[inline]
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
if let Some(&ty) = self.cache.get(&t) {
return ty;
}

let res = if !t.has_non_region_infer() {
if !t.has_non_region_infer() {
t // micro-optimize -- if there is nothing in this type that this fold affects...
} else if let Some(&ty) = self.cache.get(&t) {
return ty;
} else {
let t = self.infcx.shallow_resolve(t);
t.super_fold_with(self)
};

assert!(self.cache.insert(t, res).is_none());
res
let shallow = self.infcx.shallow_resolve(t);
let res = shallow.super_fold_with(self);
assert!(self.cache.insert(t, res).is_none());
res
}
}

fn fold_const(&mut self, ct: Const<'tcx>) -> Const<'tcx> {
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/ty/fold.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sso::SsoHashMap;
use rustc_hir::def_id::DefId;
pub use rustc_type_ir::fold::{
FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable, shift_region, shift_vars,
Expand Down Expand Up @@ -165,7 +166,7 @@ struct BoundVarReplacer<'tcx, D> {

delegate: D,

cache: FxHashMap<(ty::DebruijnIndex, Ty<'tcx>), Ty<'tcx>>,
cache: SsoHashMap<(ty::DebruijnIndex, Ty<'tcx>), Ty<'tcx>>,
}

impl<'tcx, D: BoundVarReplacerDelegate<'tcx>> BoundVarReplacer<'tcx, D> {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_next_trait_solver/src/resolve.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_type_ir::data_structures::HashMap;
use rustc_data_structures::sso::SsoHashMap;
use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
use rustc_type_ir::inherent::*;
use rustc_type_ir::visit::TypeVisitableExt;
Expand All @@ -16,7 +16,7 @@ where
I: Interner,
{
delegate: &'a D,
cache: HashMap<I::Ty, I::Ty>,
cache: SsoHashMap<I::Ty, I::Ty>,
}

impl<'a, D: SolverDelegate> EagerResolver<'a, D> {
Expand Down

0 comments on commit a9dd08c

Please sign in to comment.