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.
This commit is contained in:
Valerii Lashmanov 2020-09-23 23:32:11 -05:00
parent 6f9a8a7f9b
commit 5c224a484d
10 changed files with 45 additions and 41 deletions

View File

@ -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;

View File

@ -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<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 @@ pub fn insert(&mut self, key: K, value: 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 @@ 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);
}
}

View File

@ -0,0 +1,5 @@
mod map;
mod set;
pub use map::SsoHashMap;
pub use set::SsoHashSet;

View File

@ -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<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 @@ 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<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),
}
}
}

View File

@ -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<Ty<'tcx>, RelateResult<'tcx, Ty<'tcx>>>,
cache: SsoHashMap<Ty<'tcx>, RelateResult<'tcx, Ty<'tcx>>>,
}
/// Result from a generalization operation. This includes

View File

@ -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<GenericArg<'tcx>>,
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> 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<GenericArg<'tcx>>,
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> 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<GenericArg<'tcx>>,
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> VerifyBound<'tcx> {
let mut bounds = parent
.walk_shallow(visited)

View File

@ -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() {

View File

@ -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<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 {

View File

@ -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<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 @@ pub fn walk(self) -> TypeWalker<'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);

View File

@ -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<T>(&self, value: &T) -> Result<Normalized<'tcx, T>, 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<PredicateObligation<'tcx>>,
cache: MiniMap<Ty<'tcx>, Ty<'tcx>>,
cache: SsoHashMap<Ty<'tcx>, Ty<'tcx>>,
error: bool,
anon_depth: usize,
}