diff options
| author | Valerii Lashmanov <vflashm@gmail.com> | 2020-09-23 23:32:11 -0500 |
|---|---|---|
| committer | Valerii Lashmanov <vflashm@gmail.com> | 2020-09-26 14:30:05 -0500 |
| commit | 5c224a484dc6ba2a70c9cd0d73a04849f6d7aa68 (patch) | |
| tree | 16919ad7dbdbb6ba195ac59da944d37d93bb6c18 | |
| parent | 6f9a8a7f9b9732c55511d2a2a3914e8feafc7c52 (diff) | |
| download | rust-5c224a484dc6ba2a70c9cd0d73a04849f6d7aa68.tar.gz rust-5c224a484dc6ba2a70c9cd0d73a04849f6d7aa68.zip | |
MiniSet/MiniMap moved and renamed into SsoHashSet/SsoHashMap
It is a more descriptive name and with upcoming changes there will be nothing "mini" about them.
| -rw-r--r-- | compiler/rustc_data_structures/src/lib.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/sso/map.rs (renamed from compiler/rustc_data_structures/src/mini_map.rs) | 18 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/sso/mod.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/sso/set.rs (renamed from compiler/rustc_data_structures/src/mini_set.rs) | 14 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/combine.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/outlives/verify.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/outlives.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/print/mod.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/walk.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/query/normalize.rs | 6 |
10 files changed, 45 insertions, 41 deletions
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 @@ pub mod vec_linked_list; 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 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 @@ use std::hash::Hash; /// /// Stores elements in a small array up to a certain length /// and switches to `HashMap` when that length is exceeded. -pub enum MiniMap<K, V> { +pub enum SsoHashMap<K, V> { Array(ArrayVec<[(K, V); 8]>), Map(FxHashMap<K, V>), } -impl<K: Eq + Hash, V> MiniMap<K, V> { - /// Creates an empty `MiniMap`. +impl<K: Eq + Hash, V> SsoHashMap<K, V> { + /// 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 @@ impl<K: Eq + Hash, V> MiniMap<K, V> { let mut map: FxHashMap<K, V> = 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 @@ impl<K: Eq + Hash, V> MiniMap<K, 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 @@ impl<K: Eq + Hash, V> MiniMap<K, 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 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 @@ use std::hash::Hash; /// /// Stores elements in a small array up to a certain length /// and switches to `HashSet` when that length is exceeded. -pub enum MiniSet<T> { +pub enum SsoHashSet<T> { Array(ArrayVec<[T; 8]>), Set(FxHashSet<T>), } -impl<T: Eq + Hash> MiniSet<T> { - /// Creates an empty `MiniSet`. +impl<T: Eq + Hash> SsoHashSet<T> { + /// 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 @@ impl<T: Eq + Hash> MiniSet<T> { /// 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<T> = 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 super::{InferCtxt, MiscVariable, TypeTrace}; 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 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> { 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<Ty<'tcx>, RelateResult<'tcx, Ty<'tcx>>>, + cache: SsoHashMap<Ty<'tcx>, 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 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { /// 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 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { fn type_bound( &self, ty: Ty<'tcx>, - visited: &mut MiniSet<GenericArg<'tcx>>, + visited: &mut SsoHashSet<GenericArg<'tcx>>, ) -> VerifyBound<'tcx> { match *ty.kind() { ty::Param(p) => self.param_bound(p), @@ -148,7 +148,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { pub fn projection_bound( &self, projection_ty: ty::ProjectionTy<'tcx>, - visited: &mut MiniSet<GenericArg<'tcx>>, + visited: &mut SsoHashSet<GenericArg<'tcx>>, ) -> VerifyBound<'tcx> { debug!("projection_bound(projection_ty={:?})", projection_ty); @@ -186,7 +186,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { fn recursive_bound( &self, parent: GenericArg<'tcx>, - visited: &mut MiniSet<GenericArg<'tcx>>, + visited: &mut SsoHashSet<GenericArg<'tcx>>, ) -> 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<GenericArg<'tcx>>, + visited: &mut SsoHashSet<GenericArg<'tcx>>, ) { // 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<GenericArg<'tcx>>, + visited: &mut SsoHashSet<GenericArg<'tcx>>, ) { 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::subst::{GenericArg, Subst}; 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 @@ pub trait Printer<'tcx>: Sized { /// deeply nested tuples that have no DefId. fn characteristic_def_id_of_type_cached<'a>( ty: Ty<'a>, - visited: &mut MiniSet<Ty<'a>>, + visited: &mut SsoHashSet<Ty<'a>>, ) -> Option<DefId> { 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<DefId> { - 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 @@ type TypeWalkerStack<'tcx> = SmallVec<[GenericArg<'tcx>; 8]>; pub struct TypeWalker<'tcx> { stack: TypeWalkerStack<'tcx>, last_subtree: usize, - visited: MiniSet<GenericArg<'tcx>>, + visited: SsoHashSet<GenericArg<'tcx>>, } /// 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 @@ impl GenericArg<'tcx> { /// and skips any types that are already there. pub fn walk_shallow( self, - visited: &mut MiniSet<GenericArg<'tcx>>, + visited: &mut SsoHashSet<GenericArg<'tcx>>, ) -> impl Iterator<Item = GenericArg<'tcx>> { 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::canonical::OriginalQueryValues; 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 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> { 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<PredicateObligation<'tcx>>, - cache: MiniMap<Ty<'tcx>, Ty<'tcx>>, + cache: SsoHashMap<Ty<'tcx>, Ty<'tcx>>, error: bool, anon_depth: usize, } |
