Skip to content

Commit 906169d

Browse files
committed
Add a node type in place of hand-rolled records in infer
1 parent 8cc1149 commit 906169d

File tree

1 file changed

+66
-27
lines changed

1 file changed

+66
-27
lines changed

src/rustc/middle/typeck/infer.rs

Lines changed: 66 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ type vals_and_bindings<V:copy, T:copy> = {
275275
mut bindings: [(V, var_value<V, T>)]
276276
};
277277

278+
enum node<V:copy, T:copy> = {
279+
root: V,
280+
possible_types: T,
281+
};
282+
278283
enum infer_ctxt = @{
279284
tcx: ty::ctxt,
280285

@@ -639,7 +644,7 @@ impl unify_methods for infer_ctxt {
639644

640645
fn get<V:copy vid, T:copy>(
641646
vb: vals_and_bindings<V, T>, vid: V)
642-
-> {root: V, possible_types: T} {
647+
-> node<V, T> {
643648

644649
alt vb.vals.find(vid.to_uint()) {
645650
none {
@@ -649,15 +654,15 @@ impl unify_methods for infer_ctxt {
649654
some(var_val) {
650655
alt var_val {
651656
redirect(vid) {
652-
let {root: rt, possible_types: pt} = self.get(vb, vid);
653-
if rt != vid {
657+
let nde = self.get(vb, vid);
658+
if nde.root != vid {
654659
// Path compression
655-
vb.vals.insert(vid.to_uint(), redirect(rt));
660+
vb.vals.insert(vid.to_uint(), redirect(nde.root));
656661
}
657-
{root: rt, possible_types: pt}
662+
nde
658663
}
659664
root(pt) {
660-
{root: vid, possible_types: pt}
665+
node({root: vid, possible_types: pt})
661666
}
662667
}
663668
}
@@ -771,8 +776,12 @@ impl unify_methods for infer_ctxt {
771776
a_id: V, b_id: V) -> ures {
772777

773778
// Need to make sub_id a subtype of sup_id.
774-
let {root: a_id, possible_types: a_bounds} = self.get(vb, a_id);
775-
let {root: b_id, possible_types: b_bounds} = self.get(vb, b_id);
779+
let nde_a = self.get(vb, a_id);
780+
let nde_b = self.get(vb, b_id);
781+
let a_id = nde_a.root;
782+
let b_id = nde_b.root;
783+
let a_bounds = nde_a.possible_types;
784+
let b_bounds = nde_b.possible_types;
776785

777786
#debug["vars(%s=%s <: %s=%s)",
778787
a_id.to_str(), a_bounds.to_str(self),
@@ -809,8 +818,12 @@ impl unify_methods for infer_ctxt {
809818
vb: vals_and_bindings<V, int_ty_set>,
810819
a_id: V, b_id: V) -> ures {
811820

812-
let {root: a_id, possible_types: a_pt} = self.get(vb, a_id);
813-
let {root: b_id, possible_types: b_pt} = self.get(vb, b_id);
821+
let nde_a = self.get(vb, a_id);
822+
let nde_b = self.get(vb, b_id);
823+
let a_id = nde_a.root;
824+
let b_id = nde_b.root;
825+
let a_pt = nde_a.possible_types;
826+
let b_pt = nde_b.possible_types;
814827

815828
// If we're already dealing with the same two variables,
816829
// there's nothing to do.
@@ -831,7 +844,10 @@ impl unify_methods for infer_ctxt {
831844
vb: vals_and_bindings<V, bounds<T>>,
832845
a_id: V, b: T) -> ures {
833846

834-
let {root: a_id, possible_types: a_bounds} = self.get(vb, a_id);
847+
let nde_a = self.get(vb, a_id);
848+
let a_id = nde_a.root;
849+
let a_bounds = nde_a.possible_types;
850+
835851
#debug["vart(%s=%s <: %s)",
836852
a_id.to_str(), a_bounds.to_str(self),
837853
b.to_str(self)];
@@ -845,7 +861,9 @@ impl unify_methods for infer_ctxt {
845861

846862
assert ty::type_is_integral(b);
847863

848-
let {root: a_id, possible_types: a_pt} = self.get(vb, a_id);
864+
let nde_a = self.get(vb, a_id);
865+
let a_id = nde_a.root;
866+
let a_pt = nde_a.possible_types;
849867

850868
let intersection =
851869
intersection(a_pt, convert_integral_ty_to_int_ty_set(
@@ -862,7 +880,10 @@ impl unify_methods for infer_ctxt {
862880
a: T, b_id: V) -> ures {
863881

864882
let a_bounds = {lb: some(a), ub: none};
865-
let {root: b_id, possible_types: b_bounds} = self.get(vb, b_id);
883+
let nde_b = self.get(vb, b_id);
884+
let b_id = nde_b.root;
885+
let b_bounds = nde_b.possible_types;
886+
866887
#debug["tvar(%s <: %s=%s)",
867888
a.to_str(self),
868889
b_id.to_str(), b_bounds.to_str(self)];
@@ -875,7 +896,9 @@ impl unify_methods for infer_ctxt {
875896

876897
assert ty::type_is_integral(a);
877898

878-
let {root: b_id, possible_types: b_pt} = self.get(vb, b_id);
899+
let nde_b = self.get(vb, b_id);
900+
let b_id = nde_b.root;
901+
let b_pt = nde_b.possible_types;
879902

880903
let intersection =
881904
intersection(b_pt, convert_integral_ty_to_int_ty_set(
@@ -1101,8 +1124,9 @@ impl methods for resolve_state {
11011124
ret ty::re_var(rid);
11021125
} else {
11031126
vec::push(self.r_seen, rid);
1104-
let {root:_, possible_types: bounds} =
1105-
self.infcx.get(self.infcx.rb, rid);
1127+
let nde = self.infcx.get(self.infcx.rb, rid);
1128+
let bounds = nde.possible_types;
1129+
11061130
let r1 = alt bounds {
11071131
{ ub:_, lb:some(t) } { self.resolve_region(t) }
11081132
{ ub:some(t), lb:_ } { self.resolve_region(t) }
@@ -1135,8 +1159,9 @@ impl methods for resolve_state {
11351159
// tend to carry more restrictions or higher
11361160
// perf. penalties, so it pays to know more.
11371161

1138-
let {root:_, possible_types: bounds} =
1139-
self.infcx.get(self.infcx.tvb, vid);
1162+
let nde = self.infcx.get(self.infcx.tvb, vid);
1163+
let bounds = nde.possible_types;
1164+
11401165
let t1 = alt bounds {
11411166
{ ub:_, lb:some(t) } if !type_is_bot(t) { self.resolve1(t) }
11421167
{ ub:some(t), lb:_ } { self.resolve1(t) }
@@ -1157,8 +1182,9 @@ impl methods for resolve_state {
11571182
}
11581183

11591184
fn resolve_ty_var_integral(vid: tvi_vid) -> ty::t {
1160-
let {root:_, possible_types: pt} =
1161-
self.infcx.get(self.infcx.tvib, vid);
1185+
let nde = self.infcx.get(self.infcx.tvib, vid);
1186+
let pt = nde.possible_types;
1187+
11621188
// If there's only one type in the set of possible types, then
11631189
// that's the answer.
11641190
alt single_type_contained_in(self.infcx.tcx, pt) {
@@ -1258,21 +1284,28 @@ impl assignment for infer_ctxt {
12581284
}
12591285

12601286
(ty::ty_var(a_id), ty::ty_var(b_id)) {
1261-
let {root:_, possible_types: a_bounds} = self.get(self.tvb, a_id);
1262-
let {root:_, possible_types: b_bounds} = self.get(self.tvb, b_id);
1287+
let nde_a = self.get(self.tvb, a_id);
1288+
let nde_b = self.get(self.tvb, b_id);
1289+
let a_bounds = nde_a.possible_types;
1290+
let b_bounds = nde_b.possible_types;
1291+
12631292
let a_bnd = select(a_bounds.ub, a_bounds.lb);
12641293
let b_bnd = select(b_bounds.lb, b_bounds.ub);
12651294
self.assign_tys_or_sub(anmnt, a, b, a_bnd, b_bnd)
12661295
}
12671296

12681297
(ty::ty_var(a_id), _) {
1269-
let {root:_, possible_types:a_bounds} = self.get(self.tvb, a_id);
1298+
let nde_a = self.get(self.tvb, a_id);
1299+
let a_bounds = nde_a.possible_types;
1300+
12701301
let a_bnd = select(a_bounds.ub, a_bounds.lb);
12711302
self.assign_tys_or_sub(anmnt, a, b, a_bnd, some(b))
12721303
}
12731304

12741305
(_, ty::ty_var(b_id)) {
1275-
let {root:_, possible_types: b_bounds} = self.get(self.tvb, b_id);
1306+
let nde_b = self.get(self.tvb, b_id);
1307+
let b_bounds = nde_b.possible_types;
1308+
12761309
let b_bnd = select(b_bounds.lb, b_bounds.ub);
12771310
self.assign_tys_or_sub(anmnt, a, b, some(a), b_bnd)
12781311
}
@@ -2466,8 +2499,12 @@ fn lattice_vars<V:copy vid, T:copy to_str st, L:lattice_ops combine>(
24662499
// upper/lower/sub/super/etc.
24672500

24682501
// Need to find a type that is a supertype of both a and b:
2469-
let {root: a_vid, possible_types: a_bounds} = self.infcx().get(vb, a_vid);
2470-
let {root: b_vid, possible_types: b_bounds} = self.infcx().get(vb, b_vid);
2502+
let nde_a = self.infcx().get(vb, a_vid);
2503+
let nde_b = self.infcx().get(vb, b_vid);
2504+
let a_vid = nde_a.root;
2505+
let b_vid = nde_b.root;
2506+
let a_bounds = nde_a.possible_types;
2507+
let b_bounds = nde_b.possible_types;
24712508

24722509
#debug["%s.lattice_vars(%s=%s <: %s=%s)",
24732510
self.tag(),
@@ -2503,7 +2540,9 @@ fn lattice_var_t<V:copy vid, T:copy to_str st, L:lattice_ops combine>(
25032540
a_id: V, b: T,
25042541
c_ts: fn(T, T) -> cres<T>) -> cres<T> {
25052542

2506-
let {root: a_id, possible_types: a_bounds} = self.infcx().get(vb, a_id);
2543+
let nde_a = self.infcx().get(vb, a_id);
2544+
let a_id = nde_a.root;
2545+
let a_bounds = nde_a.possible_types;
25072546

25082547
// The comments in this function are written for LUB, but they
25092548
// apply equally well to GLB if you inverse upper/lower/sub/super/etc.

0 commit comments

Comments
 (0)