@@ -42,7 +42,7 @@ fn method_ty_to_fn_ty(@type_store tystore, method m) -> t {
42
42
//
43
43
// TODO: It'd be really nice to be able to hide this definition from the
44
44
// outside world, to enforce the above invariants.
45
- type raw_t = rec ( sty struct , option. t[ str] cname , uint hash) ;
45
+ type raw_t = rec ( sty struct , option. t[ str] cname , uint magic , uint hash) ;
46
46
type t = @raw_t ;
47
47
48
48
// NB: If you change this, you'll probably want to change the corresponding
@@ -121,7 +121,8 @@ fn gen_ty(@type_store tystore, &sty st) -> t {
121
121
122
122
fn gen_ty_full ( @type_store tystore , & sty st, option. t[ str] cname ) -> t {
123
123
auto h = hash_type_info ( st, cname) ;
124
- auto new_type = @rec ( struct=st, cname=cname, hash=h) ;
124
+ auto magic = mk_magic ( st) ;
125
+ auto new_type = @rec ( struct=st, cname=cname, magic=magic, hash=h) ;
125
126
126
127
// Is it interned?
127
128
alt ( tystore. find ( new_type) ) {
@@ -789,6 +790,41 @@ fn def_to_str(ast.def_id did) -> str {
789
790
ret #fmt( "%d: %d", did. _0, did. _1) ;
790
791
}
791
792
793
+
794
+ // Generation of "magic numbers", which are workarounds for the lack of
795
+ // structural equality in rustboot.
796
+
797
+ fn mk_magic( & sty st) -> uint {
798
+ alt ( st) {
799
+ case ( ty_nil) { ret 1 u; }
800
+ case ( ty_bool) { ret 2 u; }
801
+ case ( ty_int) { ret 3 u; }
802
+ case ( ty_float) { ret 4 u; }
803
+ case ( ty_uint) { ret 5 u; }
804
+ case ( ty_char) { ret 6 u; }
805
+ case ( ty_str) { ret 7 u; }
806
+ case ( ty_task) { ret 8 u; }
807
+ case ( ty_type) { ret 9 u; }
808
+ case ( ty_native) { ret 10 u; }
809
+ case ( ty_machine( ?tm) ) {
810
+ alt ( tm) {
811
+ case ( common. ty_i8) { ret 11 u; }
812
+ case ( common. ty_i16) { ret 12 u; }
813
+ case ( common. ty_i32) { ret 13 u; }
814
+ case ( common. ty_i64) { ret 14 u; }
815
+ case ( common. ty_u8) { ret 15 u; }
816
+ case ( common. ty_u16) { ret 16 u; }
817
+ case ( common. ty_u32) { ret 17 u; }
818
+ case ( common. ty_u64) { ret 18 u; }
819
+ case ( common. ty_f32) { ret 19 u; }
820
+ case ( common. ty_f64) { ret 20 u; }
821
+ }
822
+ }
823
+ case ( _) { ret 0 u; }
824
+ }
825
+ }
826
+
827
+
792
828
// Type hashing. This function is private to this module (and slow); external
793
829
// users should use `hash_ty()` instead.
794
830
fn hash_type_structure( & sty st) -> uint {
@@ -1224,6 +1260,9 @@ fn equal_type_structures(&sty a, &sty b) -> bool {
1224
1260
// An expensive type equality function. This function is private to this
1225
1261
// module.
1226
1262
fn eq_ty_full( & t a, & t b) -> bool {
1263
+ // Check magic numbers (fast path).
1264
+ if ( a. magic != 0 u || b. magic != 0 u) { ret a. magic == b. magic; }
1265
+
1227
1266
// Check hashes (fast path).
1228
1267
if ( a. hash != b. hash) {
1229
1268
ret false;
0 commit comments