Skip to content

Commit e8c12d3

Browse files
committed
auto merge of #15079 : nikomatsakis/rust/issue-5527-unify-refactor, r=pnkfelix
This is just a cleanup of the code. Doesn't really change anything deep about the way we operate. This is a prelude to implementing a good solution for one-way matching for #5527. r? @pnkfelix (we were just crawling about this code, after all)
2 parents 7689213 + 020373f commit e8c12d3

File tree

15 files changed

+1353
-997
lines changed

15 files changed

+1353
-997
lines changed

src/librustc/middle/ty.rs

+14-28
Original file line numberDiff line numberDiff line change
@@ -850,17 +850,23 @@ impl CLike for BuiltinBound {
850850
}
851851

852852
#[deriving(Clone, PartialEq, Eq, Hash)]
853-
pub struct TyVid(pub uint);
853+
pub struct TyVid {
854+
pub index: uint
855+
}
854856

855857
#[deriving(Clone, PartialEq, Eq, Hash)]
856-
pub struct IntVid(pub uint);
858+
pub struct IntVid {
859+
pub index: uint
860+
}
857861

858862
#[deriving(Clone, PartialEq, Eq, Hash)]
859-
pub struct FloatVid(pub uint);
863+
pub struct FloatVid {
864+
pub index: uint
865+
}
860866

861867
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
862868
pub struct RegionVid {
863-
pub id: uint
869+
pub index: uint
864870
}
865871

866872
#[deriving(Clone, PartialEq, Eq, Hash)]
@@ -893,47 +899,27 @@ impl cmp::PartialEq for InferRegion {
893899
}
894900
}
895901

896-
pub trait Vid {
897-
fn to_uint(&self) -> uint;
898-
}
899-
900-
impl Vid for TyVid {
901-
fn to_uint(&self) -> uint { let TyVid(v) = *self; v }
902-
}
903-
904902
impl fmt::Show for TyVid {
905903
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{
906-
write!(f, "<generic #{}>", self.to_uint())
904+
write!(f, "<generic #{}>", self.index)
907905
}
908906
}
909907

910-
impl Vid for IntVid {
911-
fn to_uint(&self) -> uint { let IntVid(v) = *self; v }
912-
}
913-
914908
impl fmt::Show for IntVid {
915909
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
916-
write!(f, "<generic integer #{}>", self.to_uint())
910+
write!(f, "<generic integer #{}>", self.index)
917911
}
918912
}
919913

920-
impl Vid for FloatVid {
921-
fn to_uint(&self) -> uint { let FloatVid(v) = *self; v }
922-
}
923-
924914
impl fmt::Show for FloatVid {
925915
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
926-
write!(f, "<generic float #{}>", self.to_uint())
916+
write!(f, "<generic float #{}>", self.index)
927917
}
928918
}
929919

930-
impl Vid for RegionVid {
931-
fn to_uint(&self) -> uint { self.id }
932-
}
933-
934920
impl fmt::Show for RegionVid {
935921
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
936-
self.id.fmt(f)
922+
write!(f, "'<generic lifetime #{}>", self.index)
937923
}
938924
}
939925

src/librustc/middle/typeck/coherence.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ impl<'a> CoherenceChecker<'a> {
519519
fn can_unify_universally_quantified<'a>(&self,
520520
a: &'a UniversalQuantificationResult,
521521
b: &'a UniversalQuantificationResult)
522-
-> bool {
522+
-> bool
523+
{
523524
infer::can_mk_subty(&self.inference_context,
524525
a.monotype,
525526
b.monotype).is_ok()

src/librustc/middle/typeck/infer/coercion.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ use middle::ty;
7171
use middle::typeck::infer::{CoerceResult, resolve_type, Coercion};
7272
use middle::typeck::infer::combine::{CombineFields, Combine};
7373
use middle::typeck::infer::sub::Sub;
74-
use middle::typeck::infer::to_str::InferStr;
7574
use middle::typeck::infer::resolve::try_resolve_tvar_shallow;
7675
use util::common::indenter;
76+
use util::ppaux::Repr;
7777

7878
use syntax::abi;
7979
use syntax::ast::MutImmutable;
@@ -91,8 +91,8 @@ impl<'f> Coerce<'f> {
9191

9292
pub fn tys(&self, a: ty::t, b: ty::t) -> CoerceResult {
9393
debug!("Coerce.tys({} => {})",
94-
a.inf_str(self.get_ref().infcx),
95-
b.inf_str(self.get_ref().infcx));
94+
a.repr(self.get_ref().infcx.tcx),
95+
b.repr(self.get_ref().infcx.tcx));
9696
let _indent = indenter();
9797

9898
// Examine the supertype and consider auto-borrowing.
@@ -233,8 +233,8 @@ impl<'f> Coerce<'f> {
233233
mt_b: ty::mt)
234234
-> CoerceResult {
235235
debug!("coerce_borrowed_pointer(a={}, sty_a={:?}, b={}, mt_b={:?})",
236-
a.inf_str(self.get_ref().infcx), sty_a,
237-
b.inf_str(self.get_ref().infcx), mt_b);
236+
a.repr(self.get_ref().infcx.tcx), sty_a,
237+
b.repr(self.get_ref().infcx.tcx), mt_b);
238238

239239
// If we have a parameter of type `&M T_a` and the value
240240
// provided is `expr`, we will be adding an implicit borrow,
@@ -270,8 +270,8 @@ impl<'f> Coerce<'f> {
270270
b: ty::t)
271271
-> CoerceResult {
272272
debug!("coerce_borrowed_string(a={}, sty_a={:?}, b={})",
273-
a.inf_str(self.get_ref().infcx), sty_a,
274-
b.inf_str(self.get_ref().infcx));
273+
a.repr(self.get_ref().infcx.tcx), sty_a,
274+
b.repr(self.get_ref().infcx.tcx));
275275

276276
match *sty_a {
277277
ty::ty_uniq(t) => match ty::get(t).sty {
@@ -300,8 +300,8 @@ impl<'f> Coerce<'f> {
300300
mutbl_b: ast::Mutability)
301301
-> CoerceResult {
302302
debug!("coerce_borrowed_vector(a={}, sty_a={:?}, b={})",
303-
a.inf_str(self.get_ref().infcx), sty_a,
304-
b.inf_str(self.get_ref().infcx));
303+
a.repr(self.get_ref().infcx.tcx), sty_a,
304+
b.repr(self.get_ref().infcx.tcx));
305305

306306
let sub = Sub(self.get_ref().clone());
307307
let coercion = Coercion(self.get_ref().trace.clone());
@@ -336,8 +336,8 @@ impl<'f> Coerce<'f> {
336336
b_mutbl: ast::Mutability) -> CoerceResult
337337
{
338338
debug!("coerce_borrowed_object(a={}, sty_a={:?}, b={})",
339-
a.inf_str(self.get_ref().infcx), sty_a,
340-
b.inf_str(self.get_ref().infcx));
339+
a.repr(self.get_ref().infcx.tcx), sty_a,
340+
b.repr(self.get_ref().infcx.tcx));
341341

342342
let tcx = self.get_ref().infcx.tcx;
343343
let coercion = Coercion(self.get_ref().trace.clone());
@@ -376,8 +376,8 @@ impl<'f> Coerce<'f> {
376376
b: ty::t)
377377
-> CoerceResult {
378378
debug!("coerce_borrowed_fn(a={}, sty_a={:?}, b={})",
379-
a.inf_str(self.get_ref().infcx), sty_a,
380-
b.inf_str(self.get_ref().infcx));
379+
a.repr(self.get_ref().infcx.tcx), sty_a,
380+
b.repr(self.get_ref().infcx.tcx));
381381

382382
match *sty_a {
383383
ty::ty_bare_fn(ref f) => {
@@ -400,7 +400,7 @@ impl<'f> Coerce<'f> {
400400
self.unpack_actual_value(b, |sty_b| {
401401

402402
debug!("coerce_from_bare_fn(a={}, b={})",
403-
a.inf_str(self.get_ref().infcx), b.inf_str(self.get_ref().infcx));
403+
a.repr(self.get_ref().infcx.tcx), b.repr(self.get_ref().infcx.tcx));
404404

405405
if fn_ty_a.abi != abi::Rust || fn_ty_a.fn_style != ast::NormalFn {
406406
return self.subtype(a, b);
@@ -429,8 +429,8 @@ impl<'f> Coerce<'f> {
429429
mt_b: ty::mt)
430430
-> CoerceResult {
431431
debug!("coerce_unsafe_ptr(a={}, sty_a={:?}, b={})",
432-
a.inf_str(self.get_ref().infcx), sty_a,
433-
b.inf_str(self.get_ref().infcx));
432+
a.repr(self.get_ref().infcx.tcx), sty_a,
433+
b.repr(self.get_ref().infcx.tcx));
434434

435435
let mt_a = match *sty_a {
436436
ty::ty_rptr(_, mt) => mt,
@@ -462,8 +462,8 @@ impl<'f> Coerce<'f> {
462462
bounds: ty::BuiltinBounds) -> CoerceResult {
463463

464464
debug!("coerce_object(a={}, sty_a={:?}, b={})",
465-
a.inf_str(self.get_ref().infcx), sty_a,
466-
b.inf_str(self.get_ref().infcx));
465+
a.repr(self.get_ref().infcx.tcx), sty_a,
466+
b.repr(self.get_ref().infcx.tcx));
467467

468468
Ok(Some(ty::AutoObject(trait_store, bounds,
469469
trait_def_id, trait_substs.clone())))

src/librustc/middle/typeck/infer/combine.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ use middle::typeck::infer::{ToUres};
5757
use middle::typeck::infer::glb::Glb;
5858
use middle::typeck::infer::lub::Lub;
5959
use middle::typeck::infer::sub::Sub;
60-
use middle::typeck::infer::to_str::InferStr;
61-
use middle::typeck::infer::unify::InferCtxtMethods;
60+
use middle::typeck::infer::unify::InferCtxtMethodsForSimplyUnifiableTypes;
6261
use middle::typeck::infer::{InferCtxt, cres, ures};
6362
use middle::typeck::infer::{TypeTrace};
6463
use util::common::indent;
@@ -263,7 +262,7 @@ pub trait Combine {
263262
a: ty::TraitStore,
264263
b: ty::TraitStore)
265264
-> cres<ty::TraitStore> {
266-
debug!("{}.trait_stores(a={:?}, b={:?})", self.tag(), a, b);
265+
debug!("{}.trait_stores(a={}, b={})", self.tag(), a, b);
267266

268267
match (a, b) {
269268
(ty::RegionTraitStore(a_r, a_m),
@@ -409,8 +408,8 @@ pub fn super_tys<C:Combine>(this: &C, a: ty::t, b: ty::t) -> cres<ty::t> {
409408
tcx.sess.bug(
410409
format!("{}: bot and var types should have been handled ({},{})",
411410
this.tag(),
412-
a.inf_str(this.infcx()),
413-
b.inf_str(this.infcx())).as_slice());
411+
a.repr(this.infcx().tcx),
412+
b.repr(this.infcx().tcx)).as_slice());
414413
}
415414

416415
// Relate integral variables to other types

src/librustc/middle/typeck/infer/glb.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ use middle::typeck::infer::combine::*;
1717
use middle::typeck::infer::lattice::*;
1818
use middle::typeck::infer::lub::Lub;
1919
use middle::typeck::infer::sub::Sub;
20-
use middle::typeck::infer::to_str::InferStr;
2120
use middle::typeck::infer::{cres, InferCtxt};
2221
use middle::typeck::infer::{TypeTrace, Subtype};
2322
use middle::typeck::infer::fold_regions_in_sig;
23+
use middle::typeck::infer::region_inference::RegionMark;
2424
use syntax::ast::{Many, Once, MutImmutable, MutMutable};
2525
use syntax::ast::{NormalFn, UnsafeFn, NodeId};
2626
use syntax::ast::{Onceness, FnStyle};
2727
use std::collections::HashMap;
2828
use util::common::{indenter};
2929
use util::ppaux::mt_to_str;
30+
use util::ppaux::Repr;
3031

3132
pub struct Glb<'f>(pub CombineFields<'f>); // "greatest lower bound" (common subtype)
3233

@@ -104,8 +105,8 @@ impl<'f> Combine for Glb<'f> {
104105
fn regions(&self, a: ty::Region, b: ty::Region) -> cres<ty::Region> {
105106
debug!("{}.regions({:?}, {:?})",
106107
self.tag(),
107-
a.inf_str(self.get_ref().infcx),
108-
b.inf_str(self.get_ref().infcx));
108+
a.repr(self.get_ref().infcx.tcx),
109+
b.repr(self.get_ref().infcx.tcx));
109110

110111
Ok(self.get_ref().infcx.region_vars.glb_regions(Subtype(self.trace()), a, b))
111112
}
@@ -124,14 +125,12 @@ impl<'f> Combine for Glb<'f> {
124125
// please see the large comment in `region_inference.rs`.
125126

126127
debug!("{}.fn_sigs({:?}, {:?})",
127-
self.tag(), a.inf_str(self.get_ref().infcx), b.inf_str(self.get_ref().infcx));
128+
self.tag(), a.repr(self.get_ref().infcx.tcx), b.repr(self.get_ref().infcx.tcx));
128129
let _indenter = indenter();
129130

130-
// Take a snapshot. We'll never roll this back, but in later
131-
// phases we do want to be able to examine "all bindings that
132-
// were created as part of this type comparison", and making a
133-
// snapshot is a convenient way to do that.
134-
let snapshot = self.get_ref().infcx.region_vars.start_snapshot();
131+
// Make a mark so we can examine "all bindings that were
132+
// created as part of this type comparison".
133+
let mark = self.get_ref().infcx.region_vars.mark();
135134

136135
// Instantiate each bound region with a fresh region variable.
137136
let (a_with_fresh, a_map) =
@@ -145,30 +144,30 @@ impl<'f> Combine for Glb<'f> {
145144

146145
// Collect constraints.
147146
let sig0 = if_ok!(super_fn_sigs(self, &a_with_fresh, &b_with_fresh));
148-
debug!("sig0 = {}", sig0.inf_str(self.get_ref().infcx));
147+
debug!("sig0 = {}", sig0.repr(self.get_ref().infcx.tcx));
149148

150149
// Generalize the regions appearing in fn_ty0 if possible
151150
let new_vars =
152-
self.get_ref().infcx.region_vars.vars_created_since_snapshot(snapshot);
151+
self.get_ref().infcx.region_vars.vars_created_since_mark(mark);
153152
let sig1 =
154153
fold_regions_in_sig(
155154
self.get_ref().infcx.tcx,
156155
&sig0,
157156
|r| {
158157
generalize_region(self,
159-
snapshot,
158+
mark,
160159
new_vars.as_slice(),
161160
sig0.binder_id,
162161
&a_map,
163162
a_vars.as_slice(),
164163
b_vars.as_slice(),
165164
r)
166165
});
167-
debug!("sig1 = {}", sig1.inf_str(self.get_ref().infcx));
166+
debug!("sig1 = {}", sig1.repr(self.get_ref().infcx.tcx));
168167
return Ok(sig1);
169168

170169
fn generalize_region(this: &Glb,
171-
snapshot: uint,
170+
mark: RegionMark,
172171
new_vars: &[RegionVid],
173172
new_binder_id: NodeId,
174173
a_map: &HashMap<ty::BoundRegion, ty::Region>,
@@ -180,7 +179,7 @@ impl<'f> Combine for Glb<'f> {
180179
return r0;
181180
}
182181

183-
let tainted = this.get_ref().infcx.region_vars.tainted(snapshot, r0);
182+
let tainted = this.get_ref().infcx.region_vars.tainted(mark, r0);
184183

185184
let mut a_r = None;
186185
let mut b_r = None;

0 commit comments

Comments
 (0)