Skip to content

Commit 6c94305

Browse files
committed
use BTreeMap for region constraints
1 parent 2866fab commit 6c94305

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/librustc/infer/region_inference/graphviz.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use util::nodemap::{FxHashMap, FxHashSet};
3030

3131
use std::borrow::Cow;
3232
use std::collections::hash_map::Entry::Vacant;
33+
use std::collections::btree_map::BTreeMap;
3334
use std::env;
3435
use std::fs::File;
3536
use std::io;
@@ -124,7 +125,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
124125
struct ConstraintGraph<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
125126
graph_name: String,
126127
region_rels: &'a RegionRelations<'a, 'gcx, 'tcx>,
127-
map: &'a FxHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>,
128+
map: &'a BTreeMap<Constraint<'tcx>, SubregionOrigin<'tcx>>,
128129
node_ids: FxHashMap<Node, usize>,
129130
}
130131

@@ -264,7 +265,7 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
264265
}
265266
}
266267

267-
pub type ConstraintMap<'tcx> = FxHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>;
268+
pub type ConstraintMap<'tcx> = BTreeMap<Constraint<'tcx>, SubregionOrigin<'tcx>>;
268269

269270
fn dump_region_constraints_to<'a, 'gcx, 'tcx>(region_rels: &RegionRelations<'a, 'gcx, 'tcx>,
270271
map: &ConstraintMap<'tcx>,

src/librustc/infer/region_inference/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use ty::{Region, RegionVid};
2828
use ty::{ReEmpty, ReStatic, ReFree, ReEarlyBound, ReErased};
2929
use ty::{ReLateBound, ReScope, ReVar, ReSkolemized, BrFresh};
3030

31+
use std::collections::BTreeMap;
3132
use std::cell::{Cell, RefCell};
3233
use std::fmt;
3334
use std::mem;
@@ -36,7 +37,7 @@ use std::u32;
3637
mod graphviz;
3738

3839
/// A constraint that influences the inference process.
39-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
40+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
4041
pub enum Constraint<'tcx> {
4142
/// One region variable is subregion of another
4243
ConstrainVarSubVar(RegionVid, RegionVid),
@@ -186,7 +187,7 @@ pub struct RegionVarBindings<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
186187
/// Constraints of the form `A <= B` introduced by the region
187188
/// checker. Here at least one of `A` and `B` must be a region
188189
/// variable.
189-
constraints: RefCell<FxHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>>,
190+
constraints: RefCell<BTreeMap<Constraint<'tcx>, SubregionOrigin<'tcx>>>,
190191

191192
/// A "verify" is something that we need to verify after inference is
192193
/// done, but which does not directly affect inference in any way.
@@ -357,7 +358,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
357358
tcx,
358359
var_origins: RefCell::new(Vec::new()),
359360
values: RefCell::new(None),
360-
constraints: RefCell::new(FxHashMap()),
361+
constraints: RefCell::new(BTreeMap::new()),
361362
verifys: RefCell::new(Vec::new()),
362363
givens: RefCell::new(FxHashSet()),
363364
lubs: RefCell::new(FxHashMap()),

src/librustc/ty/sty.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
760760
/// is the outer fn.
761761
///
762762
/// [dbi]: http://en.wikipedia.org/wiki/De_Bruijn_index
763-
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug, Copy)]
763+
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug, Copy, PartialOrd, Ord)]
764764
pub struct DebruijnIndex {
765765
/// We maintain the invariant that this is never 0. So 1 indicates
766766
/// the innermost binder. To ensure this, create with `DebruijnIndex::new`.
@@ -825,7 +825,7 @@ pub type Region<'tcx> = &'tcx RegionKind;
825825
///
826826
/// [1] http://smallcultfollowing.com/babysteps/blog/2013/10/29/intermingled-parameter-lists/
827827
/// [2] http://smallcultfollowing.com/babysteps/blog/2013/11/04/intermingled-parameter-lists/
828-
#[derive(Clone, PartialEq, Eq, Hash, Copy, RustcEncodable, RustcDecodable)]
828+
#[derive(Clone, PartialEq, Eq, Hash, Copy, RustcEncodable, RustcDecodable, PartialOrd, Ord)]
829829
pub enum RegionKind {
830830
// Region bound in a type or fn declaration which will be
831831
// substituted 'early' -- that is, at the same time when type
@@ -871,7 +871,7 @@ pub enum RegionKind {
871871

872872
impl<'tcx> serialize::UseSpecializedDecodable for Region<'tcx> {}
873873

874-
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)]
874+
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug, PartialOrd, Ord)]
875875
pub struct EarlyBoundRegion {
876876
pub def_id: DefId,
877877
pub index: u32,
@@ -893,12 +893,12 @@ pub struct FloatVid {
893893
pub index: u32,
894894
}
895895

896-
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
896+
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy, PartialOrd, Ord)]
897897
pub struct RegionVid {
898898
pub index: u32,
899899
}
900900

901-
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
901+
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, PartialOrd, Ord)]
902902
pub struct SkolemizedRegionVid {
903903
pub index: u32,
904904
}

src/test/compile-fail/associated-types/cache/project-fn-ret-invariant.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ fn baz<'a,'b>(x: Type<'a>) -> Type<'static> {
6060

6161
#[cfg(krisskross)] // two instantiations, mixing and matching: BAD
6262
fn transmute<'a,'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
63-
let a = bar(foo, y);
64-
let b = bar(foo, x); //[krisskross]~ ERROR E0623
63+
let a = bar(foo, y); //[krisskross]~ ERROR E0623
64+
let b = bar(foo, x);
6565
(a, b) //[krisskross]~ ERROR E0623
6666
}
6767

0 commit comments

Comments
 (0)