rustc: Remove magic numbers; they aren't a win

This commit is contained in:
Patrick Walton 2011-05-11 16:10:17 -07:00
parent df914e8904
commit 6953841e25

View file

@ -73,7 +73,6 @@ fn method_ty_to_fn_ty(ctxt cx, method m) -> t {
// outside world, to enforce the above invariants.
type raw_t = rec(sty struct,
Option.t[str] cname,
uint magic,
uint hash,
bool has_params,
bool has_bound_params,
@ -236,7 +235,6 @@ fn mk_ctxt(session.session s) -> ctxt {
fn mk_ty_full(&sty st, &Option.t[str] cname) -> t {
auto h = hash_type_info(st, cname);
auto magic = mk_magic(st);
let bool has_params = false;
let bool has_bound_params = false;
@ -352,7 +350,7 @@ fn mk_ty_full(&sty st, &Option.t[str] cname) -> t {
case (_) { }
}
ret @rec(struct=st, cname=cname, magic=magic, hash=h,
ret @rec(struct=st, cname=cname, hash=h,
has_params = has_params,
has_bound_params = has_bound_params,
has_vars = has_vars,
@ -1048,40 +1046,6 @@ fn def_to_str(&ast.def_id did) -> str {
}
// Generation of "magic numbers", which are workarounds for the lack of
// structural equality in rustboot.
fn mk_magic(&sty st) -> uint {
alt (st) {
case (ty_nil) { ret 1u; }
case (ty_bool) { ret 2u; }
case (ty_int) { ret 3u; }
case (ty_float) { ret 4u; }
case (ty_uint) { ret 5u; }
case (ty_char) { ret 6u; }
case (ty_str) { ret 7u; }
case (ty_task) { ret 8u; }
case (ty_type) { ret 9u; }
case (ty_native) { ret 10u; }
case (ty_machine(?tm)) {
alt (tm) {
case (common.ty_i8) { ret 11u; }
case (common.ty_i16) { ret 12u; }
case (common.ty_i32) { ret 13u; }
case (common.ty_i64) { ret 14u; }
case (common.ty_u8) { ret 15u; }
case (common.ty_u16) { ret 16u; }
case (common.ty_u32) { ret 17u; }
case (common.ty_u64) { ret 18u; }
case (common.ty_f32) { ret 19u; }
case (common.ty_f64) { ret 20u; }
}
}
case (_) { ret 0u; }
}
}
// Type hashing. This function is private to this module (and slow); external
// users should use `hash_ty()` instead.
fn hash_type_structure(&sty st) -> uint {
@ -1503,10 +1467,9 @@ fn equal_type_structures(&sty a, &sty b) -> bool {
// An expensive type equality function. This function is private to this
// module.
//
// FIXME: Use structural comparison, but this loops forever and segfaults.
fn eq_ty_full(&t a, &t b) -> bool {
// Check magic numbers (fast path).
if (a.magic != 0u || b.magic != 0u) { ret a.magic == b.magic; }
// Check hashes (fast path).
if (a.hash != b.hash) {
ret false;