diff --git a/src/librustc/infer/higher_ranked/mod.rs b/src/librustc/infer/higher_ranked/mod.rs index b8437e39ddca48c6118fbbc91ba5e0b52fed6297..acd5c44c1a4d807a71d5cab62a86a116b0dc0650 100644 --- a/src/librustc/infer/higher_ranked/mod.rs +++ b/src/librustc/infer/higher_ranked/mod.rs @@ -19,10 +19,10 @@ use super::combine::CombineFields; use super::region_constraints::{TaintDirections}; -use rustc_data_structures::lazy_btree_map::LazyBTreeMap; use ty::{self, TyCtxt, Binder, TypeFoldable}; use ty::error::TypeError; use ty::relate::{Relate, RelateResult, TypeRelation}; +use std::collections::BTreeMap; use syntax_pos::Span; use util::nodemap::{FxHashMap, FxHashSet}; @@ -247,8 +247,7 @@ fn generalize_region<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, snapshot: &CombinedSnapshot<'a, 'tcx>, debruijn: ty::DebruijnIndex, new_vars: &[ty::RegionVid], - a_map: &LazyBTreeMap>, + a_map: &BTreeMap>, r0: ty::Region<'tcx>) -> ty::Region<'tcx> { // Regions that pre-dated the LUB computation stay as they are. @@ -344,8 +343,7 @@ fn generalize_region<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, snapshot: &CombinedSnapshot<'a, 'tcx>, debruijn: ty::DebruijnIndex, new_vars: &[ty::RegionVid], - a_map: &LazyBTreeMap>, + a_map: &BTreeMap>, a_vars: &[ty::RegionVid], b_vars: &[ty::RegionVid], r0: ty::Region<'tcx>) @@ -414,7 +412,7 @@ fn generalize_region<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, fn rev_lookup<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, span: Span, - a_map: &LazyBTreeMap>, + a_map: &BTreeMap>, r: ty::Region<'tcx>) -> ty::Region<'tcx> { for (a_br, a_r) in a_map { @@ -437,7 +435,7 @@ fn fresh_bound_variable<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, } fn var_ids<'a, 'gcx, 'tcx>(fields: &CombineFields<'a, 'gcx, 'tcx>, - map: &LazyBTreeMap>) + map: &BTreeMap>) -> Vec { map.iter() .map(|(_, &r)| match *r { diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 1cc65dcfd1027003ae9258d07fe993d21e0c32e8..f105ecf7ee4f8c63aea365128d5ea250adeae313 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -28,9 +28,9 @@ use ty::fold::TypeFoldable; use ty::relate::RelateResult; use traits::{self, ObligationCause, PredicateObligations}; -use rustc_data_structures::lazy_btree_map::LazyBTreeMap; use rustc_data_structures::unify as ut; use std::cell::{Cell, RefCell, Ref, RefMut}; +use std::collections::BTreeMap; use std::fmt; use syntax::ast; use errors::DiagnosticBuilder; @@ -198,7 +198,7 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { /// A map returned by `skolemize_late_bound_regions()` indicating the skolemized /// region that each late-bound region was replaced with. -pub type SkolemizationMap<'tcx> = LazyBTreeMap>; +pub type SkolemizationMap<'tcx> = BTreeMap>; /// See `error_reporting` module for more details #[derive(Clone, Debug)] @@ -1235,7 +1235,7 @@ pub fn replace_late_bound_regions_with_fresh_var( span: Span, lbrct: LateBoundRegionConversionTime, value: &ty::Binder) - -> (T, LazyBTreeMap>) + -> (T, BTreeMap>) where T : TypeFoldable<'tcx> { self.tcx.replace_late_bound_regions( diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index a1f9fd76b02dcefd79a9b55fc047414336e0b801..250f33d9dbafb6800eb4ef27f7503f60e7f6877a 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -43,7 +43,7 @@ use hir::def_id::DefId; use ty::{self, Binder, Ty, TyCtxt, TypeFlags}; -use rustc_data_structures::lazy_btree_map::LazyBTreeMap; +use std::collections::BTreeMap; use std::fmt; use util::nodemap::FxHashSet; @@ -332,7 +332,7 @@ struct RegionReplacer<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { tcx: TyCtxt<'a, 'gcx, 'tcx>, current_depth: u32, fld_r: &'a mut (dyn FnMut(ty::BoundRegion) -> ty::Region<'tcx> + 'a), - map: LazyBTreeMap> + map: BTreeMap> } impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { @@ -347,7 +347,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn replace_late_bound_regions(self, value: &Binder, mut f: F) - -> (T, LazyBTreeMap>) + -> (T, BTreeMap>) where F : FnMut(ty::BoundRegion) -> ty::Region<'tcx>, T : TypeFoldable<'tcx>, { @@ -460,7 +460,7 @@ fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, fld_r: &'a mut F) tcx, current_depth: 1, fld_r, - map: LazyBTreeMap::default() + map: BTreeMap::default() } } } diff --git a/src/librustc_data_structures/lazy_btree_map.rs b/src/librustc_data_structures/lazy_btree_map.rs deleted file mode 100644 index 74f91af10fe637888342d6a7c39407a3e239cd3e..0000000000000000000000000000000000000000 --- a/src/librustc_data_structures/lazy_btree_map.rs +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::collections::btree_map; -use std::collections::BTreeMap; - -/// A thin wrapper around BTreeMap that avoids allocating upon creation. -/// -/// Vec, HashSet and HashMap all have the nice feature that they don't do any -/// heap allocation when creating a new structure of the default size. In -/// contrast, BTreeMap *does* allocate in that situation. The compiler uses -/// B-Tree maps in some places such that many maps are created but few are -/// inserted into, so having a BTreeMap alternative that avoids allocating on -/// creation is a performance win. -/// -/// Only a fraction of BTreeMap's functionality is currently supported. -/// Additional functionality should be added on demand. -#[derive(Debug)] -pub struct LazyBTreeMap(Option>); - -impl LazyBTreeMap { - pub fn new() -> LazyBTreeMap { - LazyBTreeMap(None) - } - - pub fn iter(&self) -> Iter { - Iter(self.0.as_ref().map(|btm| btm.iter())) - } - - pub fn is_empty(&self) -> bool { - self.0.as_ref().map_or(true, |btm| btm.is_empty()) - } -} - -impl LazyBTreeMap { - fn instantiate(&mut self) -> &mut BTreeMap { - if let Some(ref mut btm) = self.0 { - btm - } else { - let btm = BTreeMap::new(); - self.0 = Some(btm); - self.0.as_mut().unwrap() - } - } - - pub fn insert(&mut self, key: K, value: V) -> Option { - self.instantiate().insert(key, value) - } - - pub fn entry(&mut self, key: K) -> btree_map::Entry { - self.instantiate().entry(key) - } - - pub fn values<'a>(&'a self) -> Values<'a, K, V> { - Values(self.0.as_ref().map(|btm| btm.values())) - } -} - -impl Default for LazyBTreeMap { - fn default() -> LazyBTreeMap { - LazyBTreeMap::new() - } -} - -impl<'a, K: 'a, V: 'a> IntoIterator for &'a LazyBTreeMap { - type Item = (&'a K, &'a V); - type IntoIter = Iter<'a, K, V>; - - fn into_iter(self) -> Iter<'a, K, V> { - self.iter() - } -} - -pub struct Iter<'a, K: 'a, V: 'a>(Option>); - -impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> { - type Item = (&'a K, &'a V); - - fn next(&mut self) -> Option<(&'a K, &'a V)> { - self.0.as_mut().and_then(|iter| iter.next()) - } - - fn size_hint(&self) -> (usize, Option) { - self.0.as_ref().map_or_else(|| (0, Some(0)), |iter| iter.size_hint()) - } -} - -pub struct Values<'a, K: 'a, V: 'a>(Option>); - -impl<'a, K, V> Iterator for Values<'a, K, V> { - type Item = &'a V; - - fn next(&mut self) -> Option<&'a V> { - self.0.as_mut().and_then(|values| values.next()) - } - - fn size_hint(&self) -> (usize, Option) { - self.0.as_ref().map_or_else(|| (0, Some(0)), |values| values.size_hint()) - } -} - diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index b2e7450e76cdf4a9063e4dbb9e5bf6c147d9165d..5bac1bd9a7b08986b8c6231a77613caf4ee4995c 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -61,7 +61,6 @@ pub mod graph; pub mod indexed_set; pub mod indexed_vec; -pub mod lazy_btree_map; pub mod obligation_forest; pub mod sip128; pub mod snapshot_map;