Skip to content

Commit f24a0c4

Browse files
committed
---
yaml --- r: 29751 b: refs/heads/incoming c: 6d2bef5 h: refs/heads/master i: 29749: 232dc44 29747: 1666d64 29743: 34ccb5c v: v3
1 parent a573060 commit f24a0c4

File tree

2 files changed

+59
-44
lines changed

2 files changed

+59
-44
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 6d5b8701b19b1e25c5a6522ae038ad3496e0c906
9+
refs/heads/incoming: 6d2bef53aa99564c2da205fb7e17271707d0a03b
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/rustc/middle/typeck/infer.rs

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,14 @@ enum infer_ctxt = @{
308308
// We instantiate vals_and_bindings with bounds<ty::t> because the
309309
// types that might instantiate a general type variable have an
310310
// order, represented by its upper and lower bounds.
311-
tvb: vals_and_bindings<ty::tv_vid, bounds<ty::t>>,
311+
ty_var_bindings: vals_and_bindings<ty::tv_vid, bounds<ty::t>>,
312312

313313
// The types that might instantiate an integral type variable are
314314
// represented by an int_ty_set.
315-
tvib: vals_and_bindings<ty::tvi_vid, int_ty_set>,
315+
ty_var_integral_bindings: vals_and_bindings<ty::tvi_vid, int_ty_set>,
316316

317317
// For region variables.
318-
rb: vals_and_bindings<ty::region_vid, bounds<ty::region>>,
318+
region_var_bindings: vals_and_bindings<ty::region_vid, bounds<ty::region>>,
319319

320320
// For keeping track of existing type and region variables.
321321
ty_var_counter: @mut uint,
@@ -352,11 +352,15 @@ fn fixup_err_to_str(f: fixup_err) -> ~str {
352352
type ures = result::result<(), ty::type_err>;
353353
type fres<T> = result::result<T, fixup_err>;
354354

355+
fn new_vals_and_bindings<V:copy, T:copy>() -> vals_and_bindings<V, T> {
356+
{vals: smallintmap::mk(), mut bindings: ~[]}
357+
}
358+
355359
fn new_infer_ctxt(tcx: ty::ctxt) -> infer_ctxt {
356360
infer_ctxt(@{tcx: tcx,
357-
tvb: {vals: smallintmap::mk(), mut bindings: ~[]},
358-
tvib: {vals: smallintmap::mk(), mut bindings: ~[]},
359-
rb: {vals: smallintmap::mk(), mut bindings: ~[]},
361+
ty_var_bindings: new_vals_and_bindings(),
362+
ty_var_integral_bindings: new_vals_and_bindings(),
363+
region_var_bindings: new_vals_and_bindings(),
360364
ty_var_counter: @mut 0u,
361365
ty_var_integral_counter: @mut 0u,
362366
region_var_counter: @mut 0u,
@@ -582,24 +586,24 @@ impl infer_ctxt {
582586
/// Execute `f` and commit the bindings if successful
583587
fn commit<T,E>(f: fn() -> result<T,E>) -> result<T,E> {
584588

585-
assert self.tvb.bindings.len() == 0u;
586-
assert self.rb.bindings.len() == 0u;
589+
assert self.ty_var_bindings.bindings.len() == 0u;
590+
assert self.region_var_bindings.bindings.len() == 0u;
587591

588592
let r <- self.try(f);
589593

590594
// FIXME (#2814)---could use a vec::clear() that ran destructors but
591595
// kept the vec at its currently allocated length
592-
self.tvb.bindings = ~[];
593-
self.rb.bindings = ~[];
596+
self.ty_var_bindings.bindings = ~[];
597+
self.region_var_bindings.bindings = ~[];
594598

595599
return r;
596600
}
597601

598602
/// Execute `f`, unroll bindings on failure
599603
fn try<T,E>(f: fn() -> result<T,E>) -> result<T,E> {
600604

601-
let tvbl = self.tvb.bindings.len();
602-
let rbl = self.rb.bindings.len();
605+
let tvbl = self.ty_var_bindings.bindings.len();
606+
let rbl = self.region_var_bindings.bindings.len();
603607
let bl = self.borrowings.len();
604608

605609
debug!{"try(tvbl=%u, rbl=%u)", tvbl, rbl};
@@ -608,8 +612,8 @@ impl infer_ctxt {
608612
result::ok(_) => debug!{"try--ok"},
609613
result::err(_) => {
610614
debug!{"try--rollback"};
611-
rollback_to(&self.tvb, tvbl);
612-
rollback_to(&self.rb, rbl);
615+
rollback_to(&self.ty_var_bindings, tvbl);
616+
rollback_to(&self.region_var_bindings, rbl);
613617
while self.borrowings.len() != bl { self.borrowings.pop(); }
614618
}
615619
}
@@ -618,11 +622,11 @@ impl infer_ctxt {
618622

619623
/// Execute `f` then unroll any bindings it creates
620624
fn probe<T,E>(f: fn() -> result<T,E>) -> result<T,E> {
621-
assert self.tvb.bindings.len() == 0u;
622-
assert self.rb.bindings.len() == 0u;
625+
assert self.ty_var_bindings.bindings.len() == 0u;
626+
assert self.region_var_bindings.bindings.len() == 0u;
623627
let r <- f();
624-
rollback_to(&self.tvb, 0u);
625-
rollback_to(&self.rb, 0u);
628+
rollback_to(&self.ty_var_bindings, 0u);
629+
rollback_to(&self.region_var_bindings, 0u);
626630
return r;
627631
}
628632
}
@@ -631,7 +635,7 @@ impl infer_ctxt {
631635
fn next_ty_var_id() -> tv_vid {
632636
let id = *self.ty_var_counter;
633637
*self.ty_var_counter += 1u;
634-
self.tvb.vals.insert(id,
638+
self.ty_var_bindings.vals.insert(id,
635639
root({lb: none, ub: none}, 0u));
636640
return tv_vid(id);
637641
}
@@ -648,7 +652,7 @@ impl infer_ctxt {
648652
let id = *self.ty_var_integral_counter;
649653
*self.ty_var_integral_counter += 1u;
650654

651-
self.tvib.vals.insert(id,
655+
self.ty_var_integral_bindings.vals.insert(id,
652656
root(int_ty_set_all(), 0u));
653657
return tvi_vid(id);
654658
}
@@ -660,7 +664,7 @@ impl infer_ctxt {
660664
fn next_region_var_id(bnds: bounds<ty::region>) -> region_vid {
661665
let id = *self.region_var_counter;
662666
*self.region_var_counter += 1u;
663-
self.rb.vals.insert(id, root(bnds, 0));
667+
self.region_var_bindings.vals.insert(id, root(bnds, 0));
664668
return region_vid(id);
665669
}
666670

@@ -947,6 +951,7 @@ impl infer_ctxt {
947951
uok()
948952
}
949953

954+
/// make variable a subtype of T
950955
fn vart<V: copy vid, T: copy to_str st>(
951956
vb: &vals_and_bindings<V, bounds<T>>,
952957
a_id: V, b: T) -> ures {
@@ -983,6 +988,7 @@ impl infer_ctxt {
983988
uok()
984989
}
985990

991+
/// make T a subtype of variable
986992
fn tvar<V: copy vid, T: copy to_str st>(
987993
vb: &vals_and_bindings<V, bounds<T>>,
988994
a: T, b_id: V) -> ures {
@@ -1213,7 +1219,7 @@ impl resolve_state {
12131219
if !self.should(resolve_rvar) {
12141220
return ty::re_var(rid)
12151221
}
1216-
let nde = self.infcx.get(&self.infcx.rb, rid);
1222+
let nde = self.infcx.get(&self.infcx.region_var_bindings, rid);
12171223
let bounds = nde.possible_types;
12181224
match bounds {
12191225
{ ub:_, lb:some(r) } => { self.assert_not_rvar(rid, r); r }
@@ -1250,7 +1256,7 @@ impl resolve_state {
12501256
// tend to carry more restrictions or higher
12511257
// perf. penalties, so it pays to know more.
12521258

1253-
let nde = self.infcx.get(&self.infcx.tvb, vid);
1259+
let nde = self.infcx.get(&self.infcx.ty_var_bindings, vid);
12541260
let bounds = nde.possible_types;
12551261

12561262
let t1 = match bounds {
@@ -1274,7 +1280,7 @@ impl resolve_state {
12741280
return ty::mk_var_integral(self.infcx.tcx, vid);
12751281
}
12761282

1277-
let nde = self.infcx.get(&self.infcx.tvib, vid);
1283+
let nde = self.infcx.get(&self.infcx.ty_var_integral_bindings, vid);
12781284
let pt = nde.possible_types;
12791285

12801286
// If there's only one type in the set of possible types, then
@@ -1286,7 +1292,7 @@ impl resolve_state {
12861292
// As a last resort, default to int.
12871293
let ty = ty::mk_int(self.infcx.tcx);
12881294
self.infcx.set(
1289-
&self.infcx.tvib, vid,
1295+
&self.infcx.ty_var_integral_bindings, vid,
12901296
root(convert_integral_ty_to_int_ty_set(self.infcx.tcx,
12911297
ty),
12921298
nde.rank));
@@ -1372,8 +1378,8 @@ impl infer_ctxt {
13721378
}
13731379

13741380
(ty::ty_var(a_id), ty::ty_var(b_id)) => {
1375-
let nde_a = self.get(&self.tvb, a_id);
1376-
let nde_b = self.get(&self.tvb, b_id);
1381+
let nde_a = self.get(&self.ty_var_bindings, a_id);
1382+
let nde_b = self.get(&self.ty_var_bindings, b_id);
13771383
let a_bounds = nde_a.possible_types;
13781384
let b_bounds = nde_b.possible_types;
13791385

@@ -1383,15 +1389,15 @@ impl infer_ctxt {
13831389
}
13841390

13851391
(ty::ty_var(a_id), _) => {
1386-
let nde_a = self.get(&self.tvb, a_id);
1392+
let nde_a = self.get(&self.ty_var_bindings, a_id);
13871393
let a_bounds = nde_a.possible_types;
13881394

13891395
let a_bnd = select(a_bounds.ub, a_bounds.lb);
13901396
self.assign_tys_or_sub(anmnt, a, b, a_bnd, some(b))
13911397
}
13921398

13931399
(_, ty::ty_var(b_id)) => {
1394-
let nde_b = self.get(&self.tvb, b_id);
1400+
let nde_b = self.get(&self.ty_var_bindings, b_id);
13951401
let b_bounds = nde_b.possible_types;
13961402

13971403
let b_bnd = select(b_bounds.lb, b_bounds.ub);
@@ -1750,17 +1756,20 @@ fn super_tys<C:combine>(
17501756

17511757
// Have to handle these first
17521758
(ty::ty_var_integral(a_id), ty::ty_var_integral(b_id)) => {
1753-
self.infcx().vars_integral(&self.infcx().tvib, a_id, b_id)
1759+
self.infcx().vars_integral(&self.infcx().ty_var_integral_bindings,
1760+
a_id, b_id)
17541761
.then(|| ok(a) )
17551762
}
17561763
(ty::ty_var_integral(a_id), ty::ty_int(_)) |
17571764
(ty::ty_var_integral(a_id), ty::ty_uint(_)) => {
1758-
self.infcx().vart_integral(&self.infcx().tvib, a_id, b)
1765+
self.infcx().vart_integral(&self.infcx().ty_var_integral_bindings,
1766+
a_id, b)
17591767
.then(|| ok(a) )
17601768
}
17611769
(ty::ty_int(_), ty::ty_var_integral(b_id)) |
17621770
(ty::ty_uint(_), ty::ty_var_integral(b_id)) => {
1763-
self.infcx().tvar_integral(&self.infcx().tvib, a, b_id)
1771+
self.infcx().tvar_integral(&self.infcx().ty_var_integral_bindings,
1772+
a, b_id)
17641773
.then(|| ok(a) )
17651774
}
17661775

@@ -1902,17 +1911,20 @@ impl sub: combine {
19021911
do indent {
19031912
match (a, b) {
19041913
(ty::re_var(a_id), ty::re_var(b_id)) => {
1905-
do self.infcx().vars(&self.rb, a_id, b_id).then {
1914+
do self.infcx().vars(&self.region_var_bindings,
1915+
a_id, b_id).then {
19061916
ok(a)
19071917
}
19081918
}
19091919
(ty::re_var(a_id), _) => {
1910-
do self.infcx().vart(&self.rb, a_id, b).then {
1920+
do self.infcx().vart(&self.region_var_bindings,
1921+
a_id, b).then {
19111922
ok(a)
19121923
}
19131924
}
19141925
(_, ty::re_var(b_id)) => {
1915-
do self.infcx().tvar(&self.rb, a, b_id).then {
1926+
do self.infcx().tvar(&self.region_var_bindings,
1927+
a, b_id).then {
19161928
ok(a)
19171929
}
19181930
}
@@ -1973,13 +1985,16 @@ impl sub: combine {
19731985
ok(a)
19741986
}
19751987
(ty::ty_var(a_id), ty::ty_var(b_id)) => {
1976-
self.infcx().vars(&self.tvb, a_id, b_id).then(|| ok(a) )
1988+
self.infcx().vars(&self.ty_var_bindings,
1989+
a_id, b_id).then(|| ok(a) )
19771990
}
19781991
(ty::ty_var(a_id), _) => {
1979-
self.infcx().vart(&self.tvb, a_id, b).then(|| ok(a) )
1992+
self.infcx().vart(&self.ty_var_bindings,
1993+
a_id, b).then(|| ok(a) )
19801994
}
19811995
(_, ty::ty_var(b_id)) => {
1982-
self.infcx().tvar(&self.tvb, a, b_id).then(|| ok(a) )
1996+
self.infcx().tvar(&self.ty_var_bindings,
1997+
a, b_id).then(|| ok(a) )
19831998
}
19841999
(_, ty::ty_bot) => {
19852000
err(ty::terr_sorts(b, a))
@@ -2483,18 +2498,18 @@ fn lattice_tys<L:lattice_ops combine>(
24832498
(_, ty::ty_bot) => self.ty_bot(a),
24842499

24852500
(ty::ty_var(a_id), ty::ty_var(b_id)) => {
2486-
lattice_vars(self, &self.infcx().tvb,
2501+
lattice_vars(self, &self.infcx().ty_var_bindings,
24872502
a, a_id, b_id,
24882503
|x, y| self.tys(x, y) )
24892504
}
24902505

24912506
(ty::ty_var(a_id), _) => {
2492-
lattice_var_t(self, &self.infcx().tvb, a_id, b,
2507+
lattice_var_t(self, &self.infcx().ty_var_bindings, a_id, b,
24932508
|x, y| self.tys(x, y) )
24942509
}
24952510

24962511
(_, ty::ty_var(b_id)) => {
2497-
lattice_var_t(self, &self.infcx().tvb, b_id, a,
2512+
lattice_var_t(self, &self.infcx().ty_var_bindings, b_id, a,
24982513
|x, y| self.tys(x, y) )
24992514
}
25002515
_ => {
@@ -2510,13 +2525,13 @@ fn lattice_rvars<L:lattice_ops combine>(
25102525

25112526
match (a, b) {
25122527
(ty::re_var(a_id), ty::re_var(b_id)) => {
2513-
lattice_vars(self, &self.infcx().rb,
2528+
lattice_vars(self, &self.infcx().region_var_bindings,
25142529
a, a_id, b_id,
25152530
|x, y| self.regions(x, y) )
25162531
}
25172532

25182533
(ty::re_var(v_id), r) | (r, ty::re_var(v_id)) => {
2519-
lattice_var_t(self, &self.infcx().rb,
2534+
lattice_var_t(self, &self.infcx().region_var_bindings,
25202535
v_id, r,
25212536
|x, y| self.regions(x, y) )
25222537
}

0 commit comments

Comments
 (0)