Skip to content

Commit 941d27a

Browse files
committed
---
yaml --- r: 2207 b: refs/heads/master c: 2b298fa h: refs/heads/master i: 2205: dc707b9 2203: 9880192 2199: dafdd64 2191: 80fbdb0 2175: 7dcbab2 v: v3
1 parent 17b28a3 commit 941d27a

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 94e5ca4df862b1ff3e1fdc1c02828813050845d6
2+
refs/heads/master: 2b298fa3e86fe76f1902fda096a7eeeff4c48937

trunk/src/comp/middle/ty.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn method_ty_to_fn_ty(@type_store tystore, method m) -> t {
4242
//
4343
// TODO: It'd be really nice to be able to hide this definition from the
4444
// 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);
4646
type t = @raw_t;
4747

4848
// 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 {
121121

122122
fn gen_ty_full(@type_store tystore, &sty st, option.t[str] cname) -> t {
123123
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);
125126

126127
// Is it interned?
127128
alt (tystore.find(new_type)) {
@@ -789,6 +790,41 @@ fn def_to_str(ast.def_id did) -> str {
789790
ret #fmt("%d:%d", did._0, did._1);
790791
}
791792

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 1u; }
800+
case (ty_bool) { ret 2u; }
801+
case (ty_int) { ret 3u; }
802+
case (ty_float) { ret 4u; }
803+
case (ty_uint) { ret 5u; }
804+
case (ty_char) { ret 6u; }
805+
case (ty_str) { ret 7u; }
806+
case (ty_task) { ret 8u; }
807+
case (ty_type) { ret 9u; }
808+
case (ty_native) { ret 10u; }
809+
case (ty_machine(?tm)) {
810+
alt (tm) {
811+
case (common.ty_i8) { ret 11u; }
812+
case (common.ty_i16) { ret 12u; }
813+
case (common.ty_i32) { ret 13u; }
814+
case (common.ty_i64) { ret 14u; }
815+
case (common.ty_u8) { ret 15u; }
816+
case (common.ty_u16) { ret 16u; }
817+
case (common.ty_u32) { ret 17u; }
818+
case (common.ty_u64) { ret 18u; }
819+
case (common.ty_f32) { ret 19u; }
820+
case (common.ty_f64) { ret 20u; }
821+
}
822+
}
823+
case (_) { ret 0u; }
824+
}
825+
}
826+
827+
792828
// Type hashing. This function is private to this module (and slow); external
793829
// users should use `hash_ty()` instead.
794830
fn hash_type_structure(&sty st) -> uint {
@@ -1224,6 +1260,9 @@ fn equal_type_structures(&sty a, &sty b) -> bool {
12241260
// An expensive type equality function. This function is private to this
12251261
// module.
12261262
fn eq_ty_full(&t a, &t b) -> bool {
1263+
// Check magic numbers (fast path).
1264+
if (a.magic != 0u || b.magic != 0u) { ret a.magic == b.magic; }
1265+
12271266
// Check hashes (fast path).
12281267
if (a.hash != b.hash) {
12291268
ret false;

0 commit comments

Comments
 (0)