diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 9ded10e9c26..d0f2a4148d3 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -101,8 +101,7 @@ macro_rules! unlikely { pub mod work_queue; pub use atomic_ref::AtomicRef; pub mod frozen; -pub mod mini_map; -pub mod mini_set; +pub mod sso; pub mod tagged_ptr; pub mod temp_dir; pub mod unhash; diff --git a/compiler/rustc_data_structures/src/mini_map.rs b/compiler/rustc_data_structures/src/sso/map.rs similarity index 79% rename from compiler/rustc_data_structures/src/mini_map.rs rename to compiler/rustc_data_structures/src/sso/map.rs index cd3e949d383..c253e9d6616 100644 --- a/compiler/rustc_data_structures/src/mini_map.rs +++ b/compiler/rustc_data_structures/src/sso/map.rs @@ -8,21 +8,21 @@ /// /// Stores elements in a small array up to a certain length /// and switches to `HashMap` when that length is exceeded. -pub enum MiniMap { +pub enum SsoHashMap { Array(ArrayVec<[(K, V); 8]>), Map(FxHashMap), } -impl MiniMap { - /// Creates an empty `MiniMap`. +impl SsoHashMap { + /// Creates an empty `SsoHashMap`. pub fn new() -> Self { - MiniMap::Array(ArrayVec::new()) + SsoHashMap::Array(ArrayVec::new()) } /// Inserts or updates value in the map. pub fn insert(&mut self, key: K, value: V) { match self { - MiniMap::Array(array) => { + SsoHashMap::Array(array) => { for pair in array.iter_mut() { if pair.0 == key { pair.1 = value; @@ -33,10 +33,10 @@ pub fn insert(&mut self, key: K, value: V) { let mut map: FxHashMap = array.drain(..).collect(); let (key, value) = error.element(); map.insert(key, value); - *self = MiniMap::Map(map); + *self = SsoHashMap::Map(map); } } - MiniMap::Map(map) => { + SsoHashMap::Map(map) => { map.insert(key, value); } } @@ -45,7 +45,7 @@ pub fn insert(&mut self, key: K, value: V) { /// Return value by key if any. pub fn get(&self, key: &K) -> Option<&V> { match self { - MiniMap::Array(array) => { + SsoHashMap::Array(array) => { for pair in array { if pair.0 == *key { return Some(&pair.1); @@ -53,7 +53,7 @@ pub fn get(&self, key: &K) -> Option<&V> { } return None; } - MiniMap::Map(map) => { + SsoHashMap::Map(map) => { return map.get(key); } } diff --git a/compiler/rustc_data_structures/src/sso/mod.rs b/compiler/rustc_data_structures/src/sso/mod.rs new file mode 100644 index 00000000000..ef634b9adce --- /dev/null +++ b/compiler/rustc_data_structures/src/sso/mod.rs @@ -0,0 +1,5 @@ +mod map; +mod set; + +pub use map::SsoHashMap; +pub use set::SsoHashSet; diff --git a/compiler/rustc_data_structures/src/mini_set.rs b/compiler/rustc_data_structures/src/sso/set.rs similarity index 77% rename from compiler/rustc_data_structures/src/mini_set.rs rename to compiler/rustc_data_structures/src/sso/set.rs index 9d45af723de..b403c9dcc33 100644 --- a/compiler/rustc_data_structures/src/mini_set.rs +++ b/compiler/rustc_data_structures/src/sso/set.rs @@ -5,15 +5,15 @@ /// /// Stores elements in a small array up to a certain length /// and switches to `HashSet` when that length is exceeded. -pub enum MiniSet { +pub enum SsoHashSet { Array(ArrayVec<[T; 8]>), Set(FxHashSet), } -impl MiniSet { - /// Creates an empty `MiniSet`. +impl SsoHashSet { + /// Creates an empty `SsoHashSet`. pub fn new() -> Self { - MiniSet::Array(ArrayVec::new()) + SsoHashSet::Array(ArrayVec::new()) } /// Adds a value to the set. @@ -23,19 +23,19 @@ pub fn new() -> Self { /// If the set did have this value present, false is returned. pub fn insert(&mut self, elem: T) -> bool { match self { - MiniSet::Array(array) => { + SsoHashSet::Array(array) => { if array.iter().any(|e| *e == elem) { false } else { if let Err(error) = array.try_push(elem) { let mut set: FxHashSet = array.drain(..).collect(); set.insert(error.element()); - *self = MiniSet::Set(set); + *self = SsoHashSet::Set(set); } true } } - MiniSet::Set(set) => set.insert(elem), + SsoHashSet::Set(set) => set.insert(elem), } } } diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index a540face4f2..6a1715ef818 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -35,7 +35,7 @@ use crate::traits::{Obligation, PredicateObligations}; use rustc_ast as ast; -use rustc_data_structures::mini_map::MiniMap; +use rustc_data_structures::sso::SsoHashMap; use rustc_hir::def_id::DefId; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::error::TypeError; @@ -429,7 +429,7 @@ fn generalize( needs_wf: false, root_ty: ty, param_env: self.param_env, - cache: MiniMap::new(), + cache: SsoHashMap::new(), }; let ty = match generalize.relate(ty, ty) { @@ -490,7 +490,7 @@ struct Generalizer<'cx, 'tcx> { param_env: ty::ParamEnv<'tcx>, - cache: MiniMap, RelateResult<'tcx, Ty<'tcx>>>, + cache: SsoHashMap, RelateResult<'tcx, Ty<'tcx>>>, } /// Result from a generalization operation. This includes diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index 21b0836563f..07924298c24 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -1,7 +1,7 @@ use crate::infer::outlives::env::RegionBoundPairs; use crate::infer::{GenericKind, VerifyBound}; use rustc_data_structures::captures::Captures; -use rustc_data_structures::mini_set::MiniSet; +use rustc_data_structures::sso::SsoHashSet; use rustc_hir::def_id::DefId; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -32,7 +32,7 @@ pub fn new( /// Returns a "verify bound" that encodes what we know about /// `generic` and the regions it outlives. pub fn generic_bound(&self, generic: GenericKind<'tcx>) -> VerifyBound<'tcx> { - let mut visited = MiniSet::new(); + let mut visited = SsoHashSet::new(); match generic { GenericKind::Param(param_ty) => self.param_bound(param_ty), GenericKind::Projection(projection_ty) => { @@ -44,7 +44,7 @@ pub fn generic_bound(&self, generic: GenericKind<'tcx>) -> VerifyBound<'tcx> { fn type_bound( &self, ty: Ty<'tcx>, - visited: &mut MiniSet>, + visited: &mut SsoHashSet>, ) -> VerifyBound<'tcx> { match *ty.kind() { ty::Param(p) => self.param_bound(p), @@ -148,7 +148,7 @@ pub fn projection_declared_bounds_from_trait( pub fn projection_bound( &self, projection_ty: ty::ProjectionTy<'tcx>, - visited: &mut MiniSet>, + visited: &mut SsoHashSet>, ) -> VerifyBound<'tcx> { debug!("projection_bound(projection_ty={:?})", projection_ty); @@ -186,7 +186,7 @@ pub fn projection_bound( fn recursive_bound( &self, parent: GenericArg<'tcx>, - visited: &mut MiniSet>, + visited: &mut SsoHashSet>, ) -> VerifyBound<'tcx> { let mut bounds = parent .walk_shallow(visited) diff --git a/compiler/rustc_middle/src/ty/outlives.rs b/compiler/rustc_middle/src/ty/outlives.rs index ca992d36e95..4c20141bbe6 100644 --- a/compiler/rustc_middle/src/ty/outlives.rs +++ b/compiler/rustc_middle/src/ty/outlives.rs @@ -4,7 +4,7 @@ use crate::ty::subst::{GenericArg, GenericArgKind}; use crate::ty::{self, Ty, TyCtxt, TypeFoldable}; -use rustc_data_structures::mini_set::MiniSet; +use rustc_data_structures::sso::SsoHashSet; use smallvec::SmallVec; #[derive(Debug)] @@ -51,7 +51,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Push onto `out` all the things that must outlive `'a` for the condition /// `ty0: 'a` to hold. Note that `ty0` must be a **fully resolved type**. pub fn push_outlives_components(self, ty0: Ty<'tcx>, out: &mut SmallVec<[Component<'tcx>; 4]>) { - let mut visited = MiniSet::new(); + let mut visited = SsoHashSet::new(); compute_components(self, ty0, out, &mut visited); debug!("components({:?}) = {:?}", ty0, out); } @@ -61,7 +61,7 @@ fn compute_components( tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, out: &mut SmallVec<[Component<'tcx>; 4]>, - visited: &mut MiniSet>, + visited: &mut SsoHashSet>, ) { // Descend through the types, looking for the various "base" // components and collecting them into `out`. This is not written @@ -142,7 +142,7 @@ fn compute_components( // OutlivesProjectionComponents. Continue walking // through and constrain Pi. let mut subcomponents = smallvec![]; - let mut subvisited = MiniSet::new(); + let mut subvisited = SsoHashSet::new(); compute_components_recursive(tcx, ty.into(), &mut subcomponents, &mut subvisited); out.push(Component::EscapingProjection(subcomponents.into_iter().collect())); } @@ -194,7 +194,7 @@ fn compute_components_recursive( tcx: TyCtxt<'tcx>, parent: GenericArg<'tcx>, out: &mut SmallVec<[Component<'tcx>; 4]>, - visited: &mut MiniSet>, + visited: &mut SsoHashSet>, ) { for child in parent.walk_shallow(visited) { match child.unpack() { diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index 225ea2399fb..2e00be2395b 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -2,7 +2,7 @@ use crate::ty::{self, DefIdTree, Ty, TyCtxt}; use rustc_data_structures::fx::FxHashSet; -use rustc_data_structures::mini_set::MiniSet; +use rustc_data_structures::sso::SsoHashSet; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData}; @@ -269,7 +269,7 @@ fn default_print_impl_path( /// deeply nested tuples that have no DefId. fn characteristic_def_id_of_type_cached<'a>( ty: Ty<'a>, - visited: &mut MiniSet>, + visited: &mut SsoHashSet>, ) -> Option { match *ty.kind() { ty::Adt(adt_def, _) => Some(adt_def.did), @@ -316,7 +316,7 @@ fn characteristic_def_id_of_type_cached<'a>( } } pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option { - characteristic_def_id_of_type_cached(ty, &mut MiniSet::new()) + characteristic_def_id_of_type_cached(ty, &mut SsoHashSet::new()) } impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::RegionKind { diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index 80ade7dda4c..357a0dd65c4 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -3,7 +3,7 @@ use crate::ty; use crate::ty::subst::{GenericArg, GenericArgKind}; -use rustc_data_structures::mini_set::MiniSet; +use rustc_data_structures::sso::SsoHashSet; use smallvec::{self, SmallVec}; // The TypeWalker's stack is hot enough that it's worth going to some effort to @@ -13,7 +13,7 @@ pub struct TypeWalker<'tcx> { stack: TypeWalkerStack<'tcx>, last_subtree: usize, - visited: MiniSet>, + visited: SsoHashSet>, } /// An iterator for walking the type tree. @@ -26,7 +26,7 @@ pub struct TypeWalker<'tcx> { /// skips any types that are already there. impl<'tcx> TypeWalker<'tcx> { pub fn new(root: GenericArg<'tcx>) -> Self { - Self { stack: smallvec![root], last_subtree: 1, visited: MiniSet::new() } + Self { stack: smallvec![root], last_subtree: 1, visited: SsoHashSet::new() } } /// Skips the subtree corresponding to the last type @@ -87,7 +87,7 @@ pub fn walk(self) -> TypeWalker<'tcx> { /// and skips any types that are already there. pub fn walk_shallow( self, - visited: &mut MiniSet>, + visited: &mut SsoHashSet>, ) -> impl Iterator> { let mut stack = SmallVec::new(); push_inner(&mut stack, self); diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 3dcebbcc244..bdbf45f78a2 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -7,7 +7,7 @@ use crate::infer::{InferCtxt, InferOk}; use crate::traits::error_reporting::InferCtxtExt; use crate::traits::{Obligation, ObligationCause, PredicateObligation, Reveal}; -use rustc_data_structures::mini_map::MiniMap; +use rustc_data_structures::sso::SsoHashMap; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_infer::traits::Normalized; use rustc_middle::ty::fold::{TypeFoldable, TypeFolder}; @@ -58,7 +58,7 @@ fn normalize(&self, value: &T) -> Result, NoSolution> param_env: self.param_env, obligations: vec![], error: false, - cache: MiniMap::new(), + cache: SsoHashMap::new(), anon_depth: 0, }; @@ -87,7 +87,7 @@ struct QueryNormalizer<'cx, 'tcx> { cause: &'cx ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, obligations: Vec>, - cache: MiniMap, Ty<'tcx>>, + cache: SsoHashMap, Ty<'tcx>>, error: bool, anon_depth: usize, }