Skip to content

Commit 5c224a4

Browse files
committed
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.
1 parent 6f9a8a7 commit 5c224a4

File tree

10 files changed

+45
-41
lines changed

10 files changed

+45
-41
lines changed

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ pub mod vec_linked_list;
101101
pub mod work_queue;
102102
pub use atomic_ref::AtomicRef;
103103
pub mod frozen;
104-
pub mod mini_map;
105-
pub mod mini_set;
104+
pub mod sso;
106105
pub mod tagged_ptr;
107106
pub mod temp_dir;
108107
pub mod unhash;

compiler/rustc_data_structures/src/mini_map.rs renamed to compiler/rustc_data_structures/src/sso/map.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ use std::hash::Hash;
88
///
99
/// Stores elements in a small array up to a certain length
1010
/// and switches to `HashMap` when that length is exceeded.
11-
pub enum MiniMap<K, V> {
11+
pub enum SsoHashMap<K, V> {
1212
Array(ArrayVec<[(K, V); 8]>),
1313
Map(FxHashMap<K, V>),
1414
}
1515

16-
impl<K: Eq + Hash, V> MiniMap<K, V> {
17-
/// Creates an empty `MiniMap`.
16+
impl<K: Eq + Hash, V> SsoHashMap<K, V> {
17+
/// Creates an empty `SsoHashMap`.
1818
pub fn new() -> Self {
19-
MiniMap::Array(ArrayVec::new())
19+
SsoHashMap::Array(ArrayVec::new())
2020
}
2121

2222
/// Inserts or updates value in the map.
2323
pub fn insert(&mut self, key: K, value: V) {
2424
match self {
25-
MiniMap::Array(array) => {
25+
SsoHashMap::Array(array) => {
2626
for pair in array.iter_mut() {
2727
if pair.0 == key {
2828
pair.1 = value;
@@ -33,10 +33,10 @@ impl<K: Eq + Hash, V> MiniMap<K, V> {
3333
let mut map: FxHashMap<K, V> = array.drain(..).collect();
3434
let (key, value) = error.element();
3535
map.insert(key, value);
36-
*self = MiniMap::Map(map);
36+
*self = SsoHashMap::Map(map);
3737
}
3838
}
39-
MiniMap::Map(map) => {
39+
SsoHashMap::Map(map) => {
4040
map.insert(key, value);
4141
}
4242
}
@@ -45,15 +45,15 @@ impl<K: Eq + Hash, V> MiniMap<K, V> {
4545
/// Return value by key if any.
4646
pub fn get(&self, key: &K) -> Option<&V> {
4747
match self {
48-
MiniMap::Array(array) => {
48+
SsoHashMap::Array(array) => {
4949
for pair in array {
5050
if pair.0 == *key {
5151
return Some(&pair.1);
5252
}
5353
}
5454
return None;
5555
}
56-
MiniMap::Map(map) => {
56+
SsoHashMap::Map(map) => {
5757
return map.get(key);
5858
}
5959
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mod map;
2+
mod set;
3+
4+
pub use map::SsoHashMap;
5+
pub use set::SsoHashSet;

compiler/rustc_data_structures/src/mini_set.rs renamed to compiler/rustc_data_structures/src/sso/set.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use std::hash::Hash;
55
///
66
/// Stores elements in a small array up to a certain length
77
/// and switches to `HashSet` when that length is exceeded.
8-
pub enum MiniSet<T> {
8+
pub enum SsoHashSet<T> {
99
Array(ArrayVec<[T; 8]>),
1010
Set(FxHashSet<T>),
1111
}
1212

13-
impl<T: Eq + Hash> MiniSet<T> {
14-
/// Creates an empty `MiniSet`.
13+
impl<T: Eq + Hash> SsoHashSet<T> {
14+
/// Creates an empty `SsoHashSet`.
1515
pub fn new() -> Self {
16-
MiniSet::Array(ArrayVec::new())
16+
SsoHashSet::Array(ArrayVec::new())
1717
}
1818

1919
/// Adds a value to the set.
@@ -23,19 +23,19 @@ impl<T: Eq + Hash> MiniSet<T> {
2323
/// If the set did have this value present, false is returned.
2424
pub fn insert(&mut self, elem: T) -> bool {
2525
match self {
26-
MiniSet::Array(array) => {
26+
SsoHashSet::Array(array) => {
2727
if array.iter().any(|e| *e == elem) {
2828
false
2929
} else {
3030
if let Err(error) = array.try_push(elem) {
3131
let mut set: FxHashSet<T> = array.drain(..).collect();
3232
set.insert(error.element());
33-
*self = MiniSet::Set(set);
33+
*self = SsoHashSet::Set(set);
3434
}
3535
true
3636
}
3737
}
38-
MiniSet::Set(set) => set.insert(elem),
38+
SsoHashSet::Set(set) => set.insert(elem),
3939
}
4040
}
4141
}

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use super::{InferCtxt, MiscVariable, TypeTrace};
3535
use crate::traits::{Obligation, PredicateObligations};
3636

3737
use rustc_ast as ast;
38-
use rustc_data_structures::mini_map::MiniMap;
38+
use rustc_data_structures::sso::SsoHashMap;
3939
use rustc_hir::def_id::DefId;
4040
use rustc_middle::traits::ObligationCause;
4141
use rustc_middle::ty::error::TypeError;
@@ -429,7 +429,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
429429
needs_wf: false,
430430
root_ty: ty,
431431
param_env: self.param_env,
432-
cache: MiniMap::new(),
432+
cache: SsoHashMap::new(),
433433
};
434434

435435
let ty = match generalize.relate(ty, ty) {
@@ -490,7 +490,7 @@ struct Generalizer<'cx, 'tcx> {
490490

491491
param_env: ty::ParamEnv<'tcx>,
492492

493-
cache: MiniMap<Ty<'tcx>, RelateResult<'tcx, Ty<'tcx>>>,
493+
cache: SsoHashMap<Ty<'tcx>, RelateResult<'tcx, Ty<'tcx>>>,
494494
}
495495

496496
/// Result from a generalization operation. This includes

compiler/rustc_infer/src/infer/outlives/verify.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::infer::outlives::env::RegionBoundPairs;
22
use crate::infer::{GenericKind, VerifyBound};
33
use rustc_data_structures::captures::Captures;
4-
use rustc_data_structures::mini_set::MiniSet;
4+
use rustc_data_structures::sso::SsoHashSet;
55
use rustc_hir::def_id::DefId;
66
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
77
use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -32,7 +32,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
3232
/// Returns a "verify bound" that encodes what we know about
3333
/// `generic` and the regions it outlives.
3434
pub fn generic_bound(&self, generic: GenericKind<'tcx>) -> VerifyBound<'tcx> {
35-
let mut visited = MiniSet::new();
35+
let mut visited = SsoHashSet::new();
3636
match generic {
3737
GenericKind::Param(param_ty) => self.param_bound(param_ty),
3838
GenericKind::Projection(projection_ty) => {
@@ -44,7 +44,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
4444
fn type_bound(
4545
&self,
4646
ty: Ty<'tcx>,
47-
visited: &mut MiniSet<GenericArg<'tcx>>,
47+
visited: &mut SsoHashSet<GenericArg<'tcx>>,
4848
) -> VerifyBound<'tcx> {
4949
match *ty.kind() {
5050
ty::Param(p) => self.param_bound(p),
@@ -148,7 +148,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
148148
pub fn projection_bound(
149149
&self,
150150
projection_ty: ty::ProjectionTy<'tcx>,
151-
visited: &mut MiniSet<GenericArg<'tcx>>,
151+
visited: &mut SsoHashSet<GenericArg<'tcx>>,
152152
) -> VerifyBound<'tcx> {
153153
debug!("projection_bound(projection_ty={:?})", projection_ty);
154154

@@ -186,7 +186,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
186186
fn recursive_bound(
187187
&self,
188188
parent: GenericArg<'tcx>,
189-
visited: &mut MiniSet<GenericArg<'tcx>>,
189+
visited: &mut SsoHashSet<GenericArg<'tcx>>,
190190
) -> VerifyBound<'tcx> {
191191
let mut bounds = parent
192192
.walk_shallow(visited)

compiler/rustc_middle/src/ty/outlives.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use crate::ty::subst::{GenericArg, GenericArgKind};
66
use crate::ty::{self, Ty, TyCtxt, TypeFoldable};
7-
use rustc_data_structures::mini_set::MiniSet;
7+
use rustc_data_structures::sso::SsoHashSet;
88
use smallvec::SmallVec;
99

1010
#[derive(Debug)]
@@ -51,7 +51,7 @@ impl<'tcx> TyCtxt<'tcx> {
5151
/// Push onto `out` all the things that must outlive `'a` for the condition
5252
/// `ty0: 'a` to hold. Note that `ty0` must be a **fully resolved type**.
5353
pub fn push_outlives_components(self, ty0: Ty<'tcx>, out: &mut SmallVec<[Component<'tcx>; 4]>) {
54-
let mut visited = MiniSet::new();
54+
let mut visited = SsoHashSet::new();
5555
compute_components(self, ty0, out, &mut visited);
5656
debug!("components({:?}) = {:?}", ty0, out);
5757
}
@@ -61,7 +61,7 @@ fn compute_components(
6161
tcx: TyCtxt<'tcx>,
6262
ty: Ty<'tcx>,
6363
out: &mut SmallVec<[Component<'tcx>; 4]>,
64-
visited: &mut MiniSet<GenericArg<'tcx>>,
64+
visited: &mut SsoHashSet<GenericArg<'tcx>>,
6565
) {
6666
// Descend through the types, looking for the various "base"
6767
// components and collecting them into `out`. This is not written
@@ -142,7 +142,7 @@ fn compute_components(
142142
// OutlivesProjectionComponents. Continue walking
143143
// through and constrain Pi.
144144
let mut subcomponents = smallvec![];
145-
let mut subvisited = MiniSet::new();
145+
let mut subvisited = SsoHashSet::new();
146146
compute_components_recursive(tcx, ty.into(), &mut subcomponents, &mut subvisited);
147147
out.push(Component::EscapingProjection(subcomponents.into_iter().collect()));
148148
}
@@ -194,7 +194,7 @@ fn compute_components_recursive(
194194
tcx: TyCtxt<'tcx>,
195195
parent: GenericArg<'tcx>,
196196
out: &mut SmallVec<[Component<'tcx>; 4]>,
197-
visited: &mut MiniSet<GenericArg<'tcx>>,
197+
visited: &mut SsoHashSet<GenericArg<'tcx>>,
198198
) {
199199
for child in parent.walk_shallow(visited) {
200200
match child.unpack() {

compiler/rustc_middle/src/ty/print/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::ty::subst::{GenericArg, Subst};
22
use crate::ty::{self, DefIdTree, Ty, TyCtxt};
33

44
use rustc_data_structures::fx::FxHashSet;
5-
use rustc_data_structures::mini_set::MiniSet;
5+
use rustc_data_structures::sso::SsoHashSet;
66
use rustc_hir::def_id::{CrateNum, DefId};
77
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
88

@@ -269,7 +269,7 @@ pub trait Printer<'tcx>: Sized {
269269
/// deeply nested tuples that have no DefId.
270270
fn characteristic_def_id_of_type_cached<'a>(
271271
ty: Ty<'a>,
272-
visited: &mut MiniSet<Ty<'a>>,
272+
visited: &mut SsoHashSet<Ty<'a>>,
273273
) -> Option<DefId> {
274274
match *ty.kind() {
275275
ty::Adt(adt_def, _) => Some(adt_def.did),
@@ -316,7 +316,7 @@ fn characteristic_def_id_of_type_cached<'a>(
316316
}
317317
}
318318
pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
319-
characteristic_def_id_of_type_cached(ty, &mut MiniSet::new())
319+
characteristic_def_id_of_type_cached(ty, &mut SsoHashSet::new())
320320
}
321321

322322
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::RegionKind {

compiler/rustc_middle/src/ty/walk.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use crate::ty;
55
use crate::ty::subst::{GenericArg, GenericArgKind};
6-
use rustc_data_structures::mini_set::MiniSet;
6+
use rustc_data_structures::sso::SsoHashSet;
77
use smallvec::{self, SmallVec};
88

99
// 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]>;
1313
pub struct TypeWalker<'tcx> {
1414
stack: TypeWalkerStack<'tcx>,
1515
last_subtree: usize,
16-
visited: MiniSet<GenericArg<'tcx>>,
16+
visited: SsoHashSet<GenericArg<'tcx>>,
1717
}
1818

1919
/// An iterator for walking the type tree.
@@ -26,7 +26,7 @@ pub struct TypeWalker<'tcx> {
2626
/// skips any types that are already there.
2727
impl<'tcx> TypeWalker<'tcx> {
2828
pub fn new(root: GenericArg<'tcx>) -> Self {
29-
Self { stack: smallvec![root], last_subtree: 1, visited: MiniSet::new() }
29+
Self { stack: smallvec![root], last_subtree: 1, visited: SsoHashSet::new() }
3030
}
3131

3232
/// Skips the subtree corresponding to the last type
@@ -87,7 +87,7 @@ impl GenericArg<'tcx> {
8787
/// and skips any types that are already there.
8888
pub fn walk_shallow(
8989
self,
90-
visited: &mut MiniSet<GenericArg<'tcx>>,
90+
visited: &mut SsoHashSet<GenericArg<'tcx>>,
9191
) -> impl Iterator<Item = GenericArg<'tcx>> {
9292
let mut stack = SmallVec::new();
9393
push_inner(&mut stack, self);

compiler/rustc_trait_selection/src/traits/query/normalize.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::infer::canonical::OriginalQueryValues;
77
use crate::infer::{InferCtxt, InferOk};
88
use crate::traits::error_reporting::InferCtxtExt;
99
use crate::traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
10-
use rustc_data_structures::mini_map::MiniMap;
10+
use rustc_data_structures::sso::SsoHashMap;
1111
use rustc_data_structures::stack::ensure_sufficient_stack;
1212
use rustc_infer::traits::Normalized;
1313
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
@@ -58,7 +58,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
5858
param_env: self.param_env,
5959
obligations: vec![],
6060
error: false,
61-
cache: MiniMap::new(),
61+
cache: SsoHashMap::new(),
6262
anon_depth: 0,
6363
};
6464

@@ -87,7 +87,7 @@ struct QueryNormalizer<'cx, 'tcx> {
8787
cause: &'cx ObligationCause<'tcx>,
8888
param_env: ty::ParamEnv<'tcx>,
8989
obligations: Vec<PredicateObligation<'tcx>>,
90-
cache: MiniMap<Ty<'tcx>, Ty<'tcx>>,
90+
cache: SsoHashMap<Ty<'tcx>, Ty<'tcx>>,
9191
error: bool,
9292
anon_depth: usize,
9393
}

0 commit comments

Comments
 (0)