@@ -21,7 +21,7 @@ use util::ppaux::{ty_to_str, proto_ty_to_str, tys_to_str};
21
21
use std:: serialization:: { serialize_Option,
22
22
deserialize_Option} ;
23
23
24
- export tv_vid , tvi_vid , region_vid, vid;
24
+ export ty_vid , int_vid , region_vid, vid;
25
25
export br_hashmap;
26
26
export is_instantiable;
27
27
export node_id_to_type;
@@ -99,8 +99,8 @@ export ty_tup, mk_tup;
99
99
export ty_type, mk_type;
100
100
export ty_uint, mk_uint, mk_mach_uint;
101
101
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 ;
104
104
export ty_self, mk_self, type_has_self;
105
105
export ty_class;
106
106
export region, bound_region, encl_region;
@@ -510,12 +510,11 @@ enum sty {
510
510
ty_class( def_id , substs ) ,
511
511
ty_tup( ~[ t ] ) ,
512
512
513
- ty_var( tv_vid ) , // type variable during typechecking
514
- ty_var_integral( tvi_vid ) , // type variable during typechecking, for
515
- // integral types only
516
513
ty_param( param_ty ) , // type parameter
517
514
ty_self, // special, implicit `self` type parameter
518
515
516
+ ty_infer( InferTy ) , // soething used only during inference/typeck
517
+
519
518
// "Fake" types, used for trans purposes
520
519
ty_type, // type_desc*
521
520
ty_opaque_box, // used by monomorphizer to represent any @ box
@@ -568,21 +567,26 @@ enum param_bound {
568
567
bound_trait( t ) ,
569
568
}
570
569
571
- enum tv_vid = uint;
572
- enum tvi_vid = uint;
570
+ enum ty_vid = uint;
571
+ enum int_vid = uint;
573
572
enum region_vid = uint;
574
573
574
+ enum InferTy {
575
+ TyVar ( ty_vid ) ,
576
+ IntVar ( int_vid )
577
+ }
578
+
575
579
trait vid {
576
580
pure fn to_uint ( ) -> uint ;
577
581
pure fn to_str ( ) -> ~str ;
578
582
}
579
583
580
- impl tv_vid : vid {
584
+ impl ty_vid : vid {
581
585
pure fn to_uint ( ) -> uint { * self }
582
586
pure fn to_str ( ) -> ~str { fmt ! ( "<V%u>" , self . to_uint( ) ) }
583
587
}
584
588
585
- impl tvi_vid : vid {
589
+ impl int_vid : vid {
586
590
pure fn to_uint ( ) -> uint { * self }
587
591
pure fn to_str ( ) -> ~str { fmt ! ( "<VI%u>" , self . to_uint( ) ) }
588
592
}
@@ -592,6 +596,22 @@ impl region_vid: vid {
592
596
pure fn to_str ( ) -> ~str { fmt ! ( "%?" , self ) }
593
597
}
594
598
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
+
595
615
trait purity_to_str {
596
616
pure fn to_str ( ) -> ~str ;
597
617
}
@@ -744,7 +764,7 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
744
764
ty_estr( _) | ty_type | ty_opaque_closure_ptr( _) |
745
765
ty_opaque_box => ( ) ,
746
766
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 ,
748
768
ty_self => flags |= has_self as uint ,
749
769
ty_enum( _, ref substs) | ty_class( _, ref substs)
750
770
| ty_trait( _, ref substs, _) => {
@@ -882,12 +902,14 @@ fn mk_class(cx: ctxt, class_id: ast::def_id, +substs: substs) -> t {
882
902
mk_t ( cx, ty_class ( class_id, substs) )
883
903
}
884
904
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) ) }
886
906
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) )
889
909
}
890
910
911
+ fn mk_infer ( cx : ctxt , it : InferTy ) -> t { mk_t ( cx, ty_infer ( it) ) }
912
+
891
913
fn mk_self ( cx : ctxt ) -> t { mk_t ( cx, ty_self) }
892
914
893
915
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) {
939
961
match get ( ty) . struct {
940
962
ty_nil | ty_bot | ty_bool | ty_int( _) | ty_uint( _) | ty_float( _) |
941
963
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( _) => {
944
965
}
945
966
ty_box( tm) | ty_evec( tm, _) | ty_unboxed_vec( tm) |
946
967
ty_ptr( tm) | ty_rptr( _, tm) => {
@@ -1023,8 +1044,7 @@ fn fold_sty(sty: &sty, fldop: fn(t) -> t) -> sty {
1023
1044
}
1024
1045
ty_nil | ty_bot | ty_bool | ty_int( _) | ty_uint( _) | ty_float( _) |
1025
1046
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 => {
1028
1048
* sty
1029
1049
}
1030
1050
}
@@ -1240,16 +1260,9 @@ fn type_is_nil(ty: t) -> bool { get(ty).struct == ty_nil }
1240
1260
1241
1261
fn type_is_bot(ty: t) -> bool { get(ty).struct == ty_bot }
1242
1262
1243
- fn type_is_var (ty: t) -> bool {
1263
+ fn type_is_ty_var (ty: t) -> bool {
1244
1264
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,
1253
1266
_ => false
1254
1267
}
1255
1268
}
@@ -1370,7 +1383,7 @@ pure fn type_is_unique(ty: t) -> bool {
1370
1383
pure fn type_is_scalar(ty: t) -> bool {
1371
1384
match get(ty).struct {
1372
1385
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,
1374
1387
_ => false
1375
1388
}
1376
1389
}
@@ -1852,7 +1865,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
1852
1865
// is never bounded in any way, hence it has the bottom kind.
1853
1866
ty_self => kind_noncopyable(),
1854
1867
1855
- ty_var(_) | ty_var_integral (_) => {
1868
+ ty_infer (_) => {
1856
1869
cx.sess.bug(~" Asked to compute kind of a type variable");
1857
1870
}
1858
1871
ty_type | ty_opaque_closure_ptr(_)
@@ -1923,7 +1936,7 @@ fn type_size(cx: ctxt, ty: t) -> uint {
1923
1936
1
1924
1937
}
1925
1938
1926
- ty_var(_) | ty_var_integral (_) => {
1939
+ ty_infer (_) => {
1927
1940
cx.sess.bug(~" Asked to compute kind of a type variable");
1928
1941
}
1929
1942
ty_type | ty_opaque_closure_ptr(_)
@@ -1969,8 +1982,7 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
1969
1982
ty_float(_) |
1970
1983
ty_estr(_) |
1971
1984
ty_fn(_) |
1972
- ty_var(_) |
1973
- ty_var_integral(_) |
1985
+ ty_infer(_) |
1974
1986
ty_param(_) |
1975
1987
ty_self |
1976
1988
ty_type |
@@ -2103,7 +2115,7 @@ fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool {
2103
2115
2104
2116
fn type_is_integral(ty: t) -> bool {
2105
2117
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,
2107
2119
_ => false
2108
2120
}
2109
2121
}
@@ -2176,7 +2188,7 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
2176
2188
result = false;
2177
2189
}
2178
2190
2179
- ty_var(*) | ty_var_integral (*) | ty_self(*) => {
2191
+ ty_infer (*) | ty_self(*) => {
2180
2192
cx.sess.bug(~" non concrete type in type_is_pod");
2181
2193
}
2182
2194
}
@@ -2353,8 +2365,7 @@ pure fn hash_type_structure(st: &sty) -> uint {
2353
2365
hash_subty(h, f.output)
2354
2366
}
2355
2367
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()),
2358
2369
ty_param(p) => hash_def(hash_uint(31u, p.idx), p.def_id),
2359
2370
ty_type => 32u,
2360
2371
ty_bot => 34u,
@@ -2462,21 +2473,23 @@ fn is_pred_ty(fty: t) -> bool {
2462
2473
is_fn_ty ( fty) && type_is_bool ( ty_fn_ret ( fty) )
2463
2474
}
2464
2475
2465
- fn ty_var_id ( typ : t ) -> tv_vid {
2476
+ /*
2477
+ fn ty_var_id(typ: t) -> ty_vid {
2466
2478
match get(typ).struct {
2467
- ty_var ( vid) => return vid,
2479
+ ty_infer(TyVar( vid) ) => return vid,
2468
2480
_ => { error!("ty_var_id called on non-var ty"); fail; }
2469
2481
}
2470
2482
}
2471
2483
2472
- fn ty_var_integral_id ( typ : t ) -> tvi_vid {
2484
+ fn int_var_id (typ: t) -> int_vid {
2473
2485
match get(typ).struct {
2474
- ty_var_integral ( vid) => return vid,
2486
+ ty_infer(IntVar( vid) ) => return vid,
2475
2487
_ => { error!("ty_var_integral_id called on ty other than \
2476
2488
ty_var_integral");
2477
2489
fail; }
2478
2490
}
2479
2491
}
2492
+ */
2480
2493
2481
2494
// Type accessors for AST nodes
2482
2495
fn block_ty ( cx : ctxt , b : & ast:: blk ) -> t {
@@ -2752,15 +2765,15 @@ fn param_tys_in_type(ty: t) -> ~[param_ty] {
2752
2765
rslt
2753
2766
}
2754
2767
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 ) {
2756
2769
2757
2770
// Returns a vec of all the type variables occurring in `ty`. It may
2758
2771
// 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 ] {
2760
2773
let mut rslt = ~[ ] ;
2761
2774
do walk_ty( ty) |ty| {
2762
2775
match get ( ty) . struct {
2763
- ty_var ( v ) => vec:: push ( rslt, v) ,
2776
+ ty_infer ( TyVar ( v ) ) => vec:: push ( rslt, v) ,
2764
2777
_ => ( )
2765
2778
}
2766
2779
}
@@ -2876,8 +2889,8 @@ fn ty_sort_str(cx: ctxt, t: t) -> ~str {
2876
2889
ty_trait ( id, _, _) => fmt ! ( "trait %s" , item_path_str( cx, id) ) ,
2877
2890
ty_class( id, _) => fmt ! ( "class %s" , item_path_str( cx, id) ) ,
2878
2891
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",
2881
2894
ty_param( _) => ~"type parameter",
2882
2895
ty_self => ~"self "
2883
2896
}
@@ -3487,7 +3500,7 @@ fn is_binopable(_cx: ctxt, ty: t, op: ast::binop) -> bool {
3487
3500
fn tycat ( ty : t ) -> int {
3488
3501
match get ( ty) . struct {
3489
3502
ty_bool => tycat_bool,
3490
- ty_int( _) | ty_uint( _) | ty_var_integral ( _ ) => tycat_int,
3503
+ ty_int( _) | ty_uint( _) | ty_infer ( IntVar ( _ ) ) => tycat_int,
3491
3504
ty_float( _) => tycat_float,
3492
3505
ty_rec( _) | ty_tup( _) | ty_enum( _, _) => tycat_struct,
3493
3506
ty_bot => tycat_bot,
@@ -3706,14 +3719,14 @@ impl fn_ty : cmp::Eq {
3706
3719
}
3707
3720
}
3708
3721
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 {
3711
3724
* self == * other
3712
3725
}
3713
3726
}
3714
3727
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 {
3717
3730
* self == * other
3718
3731
}
3719
3732
}
@@ -3800,6 +3813,12 @@ impl substs : cmp::Eq {
3800
3813
}
3801
3814
}
3802
3815
3816
+ impl InferTy : cmp:: Eq {
3817
+ pure fn eq ( & & other: InferTy ) -> bool {
3818
+ self . to_hash ( ) == other. to_hash ( )
3819
+ }
3820
+ }
3821
+
3803
3822
impl sty : cmp:: Eq {
3804
3823
pure fn eq ( & & other: sty ) -> bool {
3805
3824
match self {
@@ -3912,15 +3931,9 @@ impl sty : cmp::Eq {
3912
3931
_ => false
3913
3932
}
3914
3933
}
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) => {
3922
3935
match other {
3923
- ty_var_integral ( e0b) => e0a == e0b,
3936
+ ty_infer ( e0b) => e0a == e0b,
3924
3937
_ => false
3925
3938
}
3926
3939
}
0 commit comments