Skip to content

Commit fe9f055

Browse files
committed
Refactor ty_var and ty_var_integral into one ty_infer variant
1 parent d5b3e44 commit fe9f055

File tree

17 files changed

+182
-174
lines changed

17 files changed

+182
-174
lines changed

src/rustc/metadata/tydecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
274274
parse_ty_rust_fn(st, conv)
275275
}
276276
'X' => {
277-
return ty::mk_var(st.tcx, ty::tv_vid(parse_int(st) as uint));
277+
return ty::mk_var(st.tcx, ty::ty_vid(parse_int(st) as uint));
278278
}
279279
'Y' => return ty::mk_type(st.tcx),
280280
'C' => {

src/rustc/metadata/tyencode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ fn enc_sty(w: io::Writer, cx: @ctxt, st: ty::sty) {
274274
ty::ty_fn(f) => {
275275
enc_ty_fn(w, cx, f);
276276
}
277-
ty::ty_var(id) => {
277+
ty::ty_infer(ty::TyVar(id)) => {
278278
w.write_char('X');
279279
w.write_uint(id.to_uint());
280280
}
281-
ty::ty_var_integral(id) => {
281+
ty::ty_infer(ty::IntVar(id)) => {
282282
w.write_char('X');
283283
w.write_char('I');
284284
w.write_uint(id.to_uint());

src/rustc/middle/trans/reflect.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ impl reflector {
272272

273273
// Miscallaneous extra types
274274
ty::ty_trait(_, _, _) => self.leaf(~"trait"),
275-
ty::ty_var(_) => self.leaf(~"var"),
276-
ty::ty_var_integral(_) => self.leaf(~"var_integral"),
275+
ty::ty_infer(_) => self.leaf(~"infer"),
277276
ty::ty_param(p) => self.visit(~"param", ~[self.c_uint(p.idx)]),
278277
ty::ty_self => self.leaf(~"self"),
279278
ty::ty_type => self.leaf(~"type"),

src/rustc/middle/trans/shape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] {
363363
~[shape_bare_fn],
364364
ty::ty_opaque_closure_ptr(_) =>
365365
~[shape_opaque_closure_ptr],
366-
ty::ty_var(_) | ty::ty_var_integral(_) | ty::ty_self =>
366+
ty::ty_infer(_) | ty::ty_self =>
367367
ccx.sess.bug(~"shape_of: unexpected type struct found")
368368
}
369369
}

src/rustc/middle/trans/type_of.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,8 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
171171
common::T_named_struct(llvm_type_name(cx, a_class, did, substs.tps))
172172
}
173173
ty::ty_self => cx.tcx.sess.unimpl(~"type_of: ty_self"),
174-
ty::ty_var(_) => cx.tcx.sess.bug(~"type_of with ty_var"),
174+
ty::ty_infer(*) => cx.tcx.sess.bug(~"type_of with ty_infer"),
175175
ty::ty_param(*) => cx.tcx.sess.bug(~"type_of with ty_param"),
176-
ty::ty_var_integral(_) => {
177-
cx.tcx.sess.bug(~"type_of shouldn't see a ty_var_integral");
178-
}
179176
};
180177

181178
cx.lltypes.insert(t, llty);

src/rustc/middle/ty.rs

Lines changed: 71 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use util::ppaux::{ty_to_str, proto_ty_to_str, tys_to_str};
2121
use std::serialization::{serialize_Option,
2222
deserialize_Option};
2323

24-
export tv_vid, tvi_vid, region_vid, vid;
24+
export ty_vid, int_vid, region_vid, vid;
2525
export br_hashmap;
2626
export is_instantiable;
2727
export node_id_to_type;
@@ -99,8 +99,8 @@ export ty_tup, mk_tup;
9999
export ty_type, mk_type;
100100
export ty_uint, mk_uint, mk_mach_uint;
101101
export ty_uniq, mk_uniq, mk_imm_uniq, type_is_unique_box;
102-
export ty_var, mk_var, type_is_var;
103-
export ty_var_integral, mk_var_integral, type_is_var_integral;
102+
export ty_infer, mk_infer, type_is_ty_var, mk_var, mk_int_var;
103+
export InferTy, TyVar, IntVar;
104104
export ty_self, mk_self, type_has_self;
105105
export ty_class;
106106
export region, bound_region, encl_region;
@@ -510,12 +510,11 @@ enum sty {
510510
ty_class(def_id, substs),
511511
ty_tup(~[t]),
512512

513-
ty_var(tv_vid), // type variable during typechecking
514-
ty_var_integral(tvi_vid), // type variable during typechecking, for
515-
// integral types only
516513
ty_param(param_ty), // type parameter
517514
ty_self, // special, implicit `self` type parameter
518515

516+
ty_infer(InferTy), // soething used only during inference/typeck
517+
519518
// "Fake" types, used for trans purposes
520519
ty_type, // type_desc*
521520
ty_opaque_box, // used by monomorphizer to represent any @ box
@@ -568,21 +567,26 @@ enum param_bound {
568567
bound_trait(t),
569568
}
570569

571-
enum tv_vid = uint;
572-
enum tvi_vid = uint;
570+
enum ty_vid = uint;
571+
enum int_vid = uint;
573572
enum region_vid = uint;
574573

574+
enum InferTy {
575+
TyVar(ty_vid),
576+
IntVar(int_vid)
577+
}
578+
575579
trait vid {
576580
pure fn to_uint() -> uint;
577581
pure fn to_str() -> ~str;
578582
}
579583

580-
impl tv_vid: vid {
584+
impl ty_vid: vid {
581585
pure fn to_uint() -> uint { *self }
582586
pure fn to_str() -> ~str { fmt!("<V%u>", self.to_uint()) }
583587
}
584588

585-
impl tvi_vid: vid {
589+
impl int_vid: vid {
586590
pure fn to_uint() -> uint { *self }
587591
pure fn to_str() -> ~str { fmt!("<VI%u>", self.to_uint()) }
588592
}
@@ -592,6 +596,22 @@ impl region_vid: vid {
592596
pure fn to_str() -> ~str { fmt!("%?", self) }
593597
}
594598

599+
impl InferTy {
600+
pure fn to_hash() -> uint {
601+
match self {
602+
TyVar(v) => v.to_uint() << 1,
603+
IntVar(v) => (v.to_uint() << 1) + 1
604+
}
605+
}
606+
607+
pure fn to_str() -> ~str {
608+
match self {
609+
TyVar(v) => v.to_str(),
610+
IntVar(v) => v.to_str()
611+
}
612+
}
613+
}
614+
595615
trait purity_to_str {
596616
pure fn to_str() -> ~str;
597617
}
@@ -744,7 +764,7 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
744764
ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) |
745765
ty_opaque_box => (),
746766
ty_param(_) => flags |= has_params as uint,
747-
ty_var(_) | ty_var_integral(_) => flags |= needs_infer as uint,
767+
ty_infer(_) => flags |= needs_infer as uint,
748768
ty_self => flags |= has_self as uint,
749769
ty_enum(_, ref substs) | ty_class(_, ref substs)
750770
| ty_trait(_, ref substs, _) => {
@@ -882,12 +902,14 @@ fn mk_class(cx: ctxt, class_id: ast::def_id, +substs: substs) -> t {
882902
mk_t(cx, ty_class(class_id, substs))
883903
}
884904

885-
fn mk_var(cx: ctxt, v: tv_vid) -> t { mk_t(cx, ty_var(v)) }
905+
fn mk_var(cx: ctxt, v: ty_vid) -> t { mk_infer(cx, TyVar(v)) }
886906

887-
fn mk_var_integral(cx: ctxt, v: tvi_vid) -> t {
888-
mk_t(cx, ty_var_integral(v))
907+
fn mk_int_var(cx: ctxt, v: int_vid) -> t {
908+
mk_infer(cx, IntVar(v))
889909
}
890910

911+
fn mk_infer(cx: ctxt, it: InferTy) -> t { mk_t(cx, ty_infer(it)) }
912+
891913
fn mk_self(cx: ctxt) -> t { mk_t(cx, ty_self) }
892914

893915
fn mk_param(cx: ctxt, n: uint, k: def_id) -> t {
@@ -939,8 +961,7 @@ fn maybe_walk_ty(ty: t, f: fn(t) -> bool) {
939961
match get(ty).struct {
940962
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
941963
ty_estr(_) | ty_type | ty_opaque_box | ty_self |
942-
ty_opaque_closure_ptr(_) | ty_var(_) | ty_var_integral(_) |
943-
ty_param(_) => {
964+
ty_opaque_closure_ptr(_) | ty_infer(_) | ty_param(_) => {
944965
}
945966
ty_box(tm) | ty_evec(tm, _) | ty_unboxed_vec(tm) |
946967
ty_ptr(tm) | ty_rptr(_, tm) => {
@@ -1023,8 +1044,7 @@ fn fold_sty(sty: &sty, fldop: fn(t) -> t) -> sty {
10231044
}
10241045
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
10251046
ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) |
1026-
ty_opaque_box | ty_var(_) | ty_var_integral(_) |
1027-
ty_param(*) | ty_self => {
1047+
ty_opaque_box | ty_infer(_) | ty_param(*) | ty_self => {
10281048
*sty
10291049
}
10301050
}
@@ -1240,16 +1260,9 @@ fn type_is_nil(ty: t) -> bool { get(ty).struct == ty_nil }
12401260
12411261
fn type_is_bot(ty: t) -> bool { get(ty).struct == ty_bot }
12421262
1243-
fn type_is_var(ty: t) -> bool {
1263+
fn type_is_ty_var(ty: t) -> bool {
12441264
match get(ty).struct {
1245-
ty_var(_) => true,
1246-
_ => false
1247-
}
1248-
}
1249-
1250-
fn type_is_var_integral(ty: t) -> bool {
1251-
match get(ty).struct {
1252-
ty_var_integral(_) => true,
1265+
ty_infer(TyVar(_)) => true,
12531266
_ => false
12541267
}
12551268
}
@@ -1370,7 +1383,7 @@ pure fn type_is_unique(ty: t) -> bool {
13701383
pure fn type_is_scalar(ty: t) -> bool {
13711384
match get(ty).struct {
13721385
ty_nil | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
1373-
ty_var_integral(_) | ty_type | ty_ptr(_) => true,
1386+
ty_infer(IntVar(_)) | ty_type | ty_ptr(_) => true,
13741387
_ => false
13751388
}
13761389
}
@@ -1852,7 +1865,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
18521865
// is never bounded in any way, hence it has the bottom kind.
18531866
ty_self => kind_noncopyable(),
18541867
1855-
ty_var(_) | ty_var_integral(_) => {
1868+
ty_infer(_) => {
18561869
cx.sess.bug(~"Asked to compute kind of a type variable");
18571870
}
18581871
ty_type | ty_opaque_closure_ptr(_)
@@ -1923,7 +1936,7 @@ fn type_size(cx: ctxt, ty: t) -> uint {
19231936
1
19241937
}
19251938
1926-
ty_var(_) | ty_var_integral(_) => {
1939+
ty_infer(_) => {
19271940
cx.sess.bug(~"Asked to compute kind of a type variable");
19281941
}
19291942
ty_type | ty_opaque_closure_ptr(_)
@@ -1969,8 +1982,7 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
19691982
ty_float(_) |
19701983
ty_estr(_) |
19711984
ty_fn(_) |
1972-
ty_var(_) |
1973-
ty_var_integral(_) |
1985+
ty_infer(_) |
19741986
ty_param(_) |
19751987
ty_self |
19761988
ty_type |
@@ -2103,7 +2115,7 @@ fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool {
21032115
21042116
fn type_is_integral(ty: t) -> bool {
21052117
match get(ty).struct {
2106-
ty_var_integral(_) | ty_int(_) | ty_uint(_) | ty_bool => true,
2118+
ty_infer(IntVar(_)) | ty_int(_) | ty_uint(_) | ty_bool => true,
21072119
_ => false
21082120
}
21092121
}
@@ -2176,7 +2188,7 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
21762188
result = false;
21772189
}
21782190
2179-
ty_var(*) | ty_var_integral(*) | ty_self(*) => {
2191+
ty_infer(*) | ty_self(*) => {
21802192
cx.sess.bug(~"non concrete type in type_is_pod");
21812193
}
21822194
}
@@ -2353,8 +2365,7 @@ pure fn hash_type_structure(st: &sty) -> uint {
23532365
hash_subty(h, f.output)
23542366
}
23552367
ty_self => 28u,
2356-
ty_var(v) => hash_uint(29u, v.to_uint()),
2357-
ty_var_integral(v) => hash_uint(30u, v.to_uint()),
2368+
ty_infer(v) => hash_uint(29u, v.to_hash()),
23582369
ty_param(p) => hash_def(hash_uint(31u, p.idx), p.def_id),
23592370
ty_type => 32u,
23602371
ty_bot => 34u,
@@ -2462,21 +2473,23 @@ fn is_pred_ty(fty: t) -> bool {
24622473
is_fn_ty(fty) && type_is_bool(ty_fn_ret(fty))
24632474
}
24642475

2465-
fn ty_var_id(typ: t) -> tv_vid {
2476+
/*
2477+
fn ty_var_id(typ: t) -> ty_vid {
24662478
match get(typ).struct {
2467-
ty_var(vid) => return vid,
2479+
ty_infer(TyVar(vid)) => return vid,
24682480
_ => { error!("ty_var_id called on non-var ty"); fail; }
24692481
}
24702482
}
24712483
2472-
fn ty_var_integral_id(typ: t) -> tvi_vid {
2484+
fn int_var_id(typ: t) -> int_vid {
24732485
match get(typ).struct {
2474-
ty_var_integral(vid) => return vid,
2486+
ty_infer(IntVar(vid)) => return vid,
24752487
_ => { error!("ty_var_integral_id called on ty other than \
24762488
ty_var_integral");
24772489
fail; }
24782490
}
24792491
}
2492+
*/
24802493

24812494
// Type accessors for AST nodes
24822495
fn block_ty(cx: ctxt, b: &ast::blk) -> t {
@@ -2752,15 +2765,15 @@ fn param_tys_in_type(ty: t) -> ~[param_ty] {
27522765
rslt
27532766
}
27542767

2755-
fn occurs_check(tcx: ctxt, sp: span, vid: tv_vid, rt: t) {
2768+
fn occurs_check(tcx: ctxt, sp: span, vid: ty_vid, rt: t) {
27562769

27572770
// Returns a vec of all the type variables occurring in `ty`. It may
27582771
// contain duplicates. (Integral type vars aren't counted.)
2759-
fn vars_in_type(ty: t) -> ~[tv_vid] {
2772+
fn vars_in_type(ty: t) -> ~[ty_vid] {
27602773
let mut rslt = ~[];
27612774
do walk_ty(ty) |ty| {
27622775
match get(ty).struct {
2763-
ty_var(v) => vec::push(rslt, v),
2776+
ty_infer(TyVar(v)) => vec::push(rslt, v),
27642777
_ => ()
27652778
}
27662779
}
@@ -2876,8 +2889,8 @@ fn ty_sort_str(cx: ctxt, t: t) -> ~str {
28762889
ty_trait(id, _, _) => fmt!("trait %s", item_path_str(cx, id)),
28772890
ty_class(id, _) => fmt!("class %s", item_path_str(cx, id)),
28782891
ty_tup(_) => ~"tuple",
2879-
ty_var(_) => ~"variable",
2880-
ty_var_integral(_) => ~"integral variable",
2892+
ty_infer(TyVar(_)) => ~"inferred type",
2893+
ty_infer(IntVar(_)) => ~"integral variable",
28812894
ty_param(_) => ~"type parameter",
28822895
ty_self => ~"self"
28832896
}
@@ -3487,7 +3500,7 @@ fn is_binopable(_cx: ctxt, ty: t, op: ast::binop) -> bool {
34873500
fn tycat(ty: t) -> int {
34883501
match get(ty).struct {
34893502
ty_bool => tycat_bool,
3490-
ty_int(_) | ty_uint(_) | ty_var_integral(_) => tycat_int,
3503+
ty_int(_) | ty_uint(_) | ty_infer(IntVar(_)) => tycat_int,
34913504
ty_float(_) => tycat_float,
34923505
ty_rec(_) | ty_tup(_) | ty_enum(_, _) => tycat_struct,
34933506
ty_bot => tycat_bot,
@@ -3706,14 +3719,14 @@ impl fn_ty : cmp::Eq {
37063719
}
37073720
}
37083721

3709-
impl tv_vid: cmp::Eq {
3710-
pure fn eq(&&other: tv_vid) -> bool {
3722+
impl ty_vid: cmp::Eq {
3723+
pure fn eq(&&other: ty_vid) -> bool {
37113724
*self == *other
37123725
}
37133726
}
37143727

3715-
impl tvi_vid: cmp::Eq {
3716-
pure fn eq(&&other: tvi_vid) -> bool {
3728+
impl int_vid: cmp::Eq {
3729+
pure fn eq(&&other: int_vid) -> bool {
37173730
*self == *other
37183731
}
37193732
}
@@ -3800,6 +3813,12 @@ impl substs : cmp::Eq {
38003813
}
38013814
}
38023815

3816+
impl InferTy : cmp::Eq {
3817+
pure fn eq(&&other: InferTy) -> bool {
3818+
self.to_hash() == other.to_hash()
3819+
}
3820+
}
3821+
38033822
impl sty : cmp::Eq {
38043823
pure fn eq(&&other: sty) -> bool {
38053824
match self {
@@ -3912,15 +3931,9 @@ impl sty : cmp::Eq {
39123931
_ => false
39133932
}
39143933
}
3915-
ty_var(e0a) => {
3916-
match other {
3917-
ty_var(e0b) => e0a == e0b,
3918-
_ => false
3919-
}
3920-
}
3921-
ty_var_integral(e0a) => {
3934+
ty_infer(e0a) => {
39223935
match other {
3923-
ty_var_integral(e0b) => e0a == e0b,
3936+
ty_infer(e0b) => e0a == e0b,
39243937
_ => false
39253938
}
39263939
}

0 commit comments

Comments
 (0)