Skip to content

Commit 7dcbab2

Browse files
committed
---
yaml --- r: 2175 b: refs/heads/master c: 276a0f2 h: refs/heads/master i: 2173: 366391c 2171: 8f85000 2167: f423c12 2159: 03b96ec 2143: 4b62981 2111: df3ca7e 2047: 92c572a v: v3
1 parent 4e034f8 commit 7dcbab2

File tree

3 files changed

+57
-40
lines changed

3 files changed

+57
-40
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: cac7524c1aa63961973e3607d72a49dfccb09448
2+
refs/heads/master: 276a0f2de8d132e40ff1d29c32249ba1963bd73e

trunk/src/comp/middle/metadata.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ fn sty_str(ty.sty st, def_str ds) -> str {
136136
case (ty.ty_native) {ret "E";}
137137
case (ty.ty_param(?id)) {ret "p" + common.uistr(id);}
138138
case (ty.ty_type) {ret "Y";}
139+
140+
// These two don't appear in crate metadata, but are here because
141+
// `hash_ty()` uses this function.
142+
case (ty.ty_bound_param(?id)) {ret "o" + common.uistr(id);}
143+
case (ty.ty_local(?def)) {ret "L" + ds(def);}
139144
}
140145
}
141146

trunk/src/comp/middle/ty.rs

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn method_ty_to_fn_ty(method m) -> @ty.t {
4040
//
4141
// TODO: It'd be really nice to be able to hide this definition from the
4242
// outside world, to enforce the above invariant.
43-
type t = rec(sty struct, option.t[str] cname);
43+
type t = rec(sty struct, option.t[str] cname, uint hash);
4444

4545
// NB: If you change this, you'll probably want to change the corresponding
4646
// AST structure in front/ast.rs as well.
@@ -107,28 +107,34 @@ type type_cache = hashmap[ast.def_id,ty_param_count_and_ty];
107107

108108
// Type constructors
109109

110-
fn mk_nil() -> @t { ret plain_ty(ty_nil); }
111-
fn mk_bool() -> @t { ret plain_ty(ty_bool); }
112-
fn mk_int() -> @t { ret plain_ty(ty_int); }
113-
fn mk_float() -> @t { ret plain_ty(ty_float); }
114-
fn mk_uint() -> @t { ret plain_ty(ty_uint); }
115-
fn mk_mach(util.common.ty_mach tm) -> @t { ret plain_ty(ty_machine(tm)); }
116-
fn mk_char() -> @t { ret plain_ty(ty_char); }
117-
fn mk_str() -> @t { ret plain_ty(ty_str); }
110+
// This is a private constructor to this module. External users should always
111+
// use the mk_foo() functions below.
112+
fn gen_ty(&sty st) -> @t {
113+
ret @rec(struct=st, cname=none[str], hash=hash_type_structure(st));
114+
}
115+
116+
fn mk_nil() -> @t { ret gen_ty(ty_nil); }
117+
fn mk_bool() -> @t { ret gen_ty(ty_bool); }
118+
fn mk_int() -> @t { ret gen_ty(ty_int); }
119+
fn mk_float() -> @t { ret gen_ty(ty_float); }
120+
fn mk_uint() -> @t { ret gen_ty(ty_uint); }
121+
fn mk_mach(util.common.ty_mach tm) -> @t { ret gen_ty(ty_machine(tm)); }
122+
fn mk_char() -> @t { ret gen_ty(ty_char); }
123+
fn mk_str() -> @t { ret gen_ty(ty_str); }
118124

119125
fn mk_tag(ast.def_id did, vec[@t] tys) -> @t {
120-
ret plain_ty(ty_tag(did, tys));
126+
ret gen_ty(ty_tag(did, tys));
121127
}
122128

123-
fn mk_box(mt tm) -> @t { ret plain_ty(ty_box(tm)); }
129+
fn mk_box(mt tm) -> @t { ret gen_ty(ty_box(tm)); }
124130
fn mk_imm_box(@t ty) -> @t { ret mk_box(rec(ty=ty, mut=ast.imm)); }
125131

126-
fn mk_vec(mt tm) -> @t { ret plain_ty(ty_vec(tm)); }
127-
fn mk_port(@t ty) -> @t { ret plain_ty(ty_port(ty)); }
128-
fn mk_chan(@t ty) -> @t { ret plain_ty(ty_chan(ty)); }
129-
fn mk_task() -> @t { ret plain_ty(ty_task); }
132+
fn mk_vec(mt tm) -> @t { ret gen_ty(ty_vec(tm)); }
133+
fn mk_port(@t ty) -> @t { ret gen_ty(ty_port(ty)); }
134+
fn mk_chan(@t ty) -> @t { ret gen_ty(ty_chan(ty)); }
135+
fn mk_task() -> @t { ret gen_ty(ty_task); }
130136

131-
fn mk_tup(vec[mt] tms) -> @t { ret plain_ty(ty_tup(tms)); }
137+
fn mk_tup(vec[mt] tms) -> @t { ret gen_ty(ty_tup(tms)); }
132138
fn mk_imm_tup(vec[@t] tys) -> @t {
133139
// TODO: map
134140
let vec[ty.mt] mts = vec();
@@ -138,23 +144,23 @@ fn mk_imm_tup(vec[@t] tys) -> @t {
138144
ret mk_tup(mts);
139145
}
140146

141-
fn mk_rec(vec[field] fs) -> @t { ret plain_ty(ty_rec(fs)); }
147+
fn mk_rec(vec[field] fs) -> @t { ret gen_ty(ty_rec(fs)); }
142148

143149
fn mk_fn(ast.proto proto, vec[arg] args, @t ty) -> @t {
144-
ret plain_ty(ty_fn(proto, args, ty));
150+
ret gen_ty(ty_fn(proto, args, ty));
145151
}
146152

147153
fn mk_native_fn(ast.native_abi abi, vec[arg] args, @t ty) -> @t {
148-
ret plain_ty(ty_native_fn(abi, args, ty));
154+
ret gen_ty(ty_native_fn(abi, args, ty));
149155
}
150156

151-
fn mk_obj(vec[method] meths) -> @t { ret plain_ty(ty_obj(meths)); }
152-
fn mk_var(int v) -> @t { ret plain_ty(ty_var(v)); }
153-
fn mk_local(ast.def_id did) -> @t { ret plain_ty(ty_local(did)); }
154-
fn mk_param(uint n) -> @t { ret plain_ty(ty_param(n)); }
155-
fn mk_bound_param(uint n) -> @t { ret plain_ty(ty_bound_param(n)); }
156-
fn mk_type() -> @t { ret plain_ty(ty_type); }
157-
fn mk_native() -> @t { ret plain_ty(ty_native); }
157+
fn mk_obj(vec[method] meths) -> @t { ret gen_ty(ty_obj(meths)); }
158+
fn mk_var(int v) -> @t { ret gen_ty(ty_var(v)); }
159+
fn mk_local(ast.def_id did) -> @t { ret gen_ty(ty_local(did)); }
160+
fn mk_param(uint n) -> @t { ret gen_ty(ty_param(n)); }
161+
fn mk_bound_param(uint n) -> @t { ret gen_ty(ty_bound_param(n)); }
162+
fn mk_type() -> @t { ret gen_ty(ty_type); }
163+
fn mk_native() -> @t { ret gen_ty(ty_native); }
158164

159165

160166
// Stringification
@@ -478,13 +484,15 @@ fn fold_ty(ty_fold fld, @t ty_0) -> @t {
478484
// Type utilities
479485

480486
fn rename(@t typ, str new_cname) -> @t {
481-
ret @rec(struct=typ.struct, cname=some[str](new_cname));
487+
ret @rec(struct=typ.struct, cname=some[str](new_cname), hash=typ.hash);
482488
}
483489

484490
// Returns a type with the structural part taken from `struct_ty` and the
485491
// canonical name from `cname_ty`.
486492
fn copy_cname(@t struct_ty, @t cname_ty) -> @t {
487-
ret @rec(struct=struct_ty.struct, cname=cname_ty.cname);
493+
ret @rec(struct=struct_ty.struct,
494+
cname=cname_ty.cname,
495+
hash=struct_ty.hash);
488496
}
489497

490498
// FIXME: remove me when == works on these tags.
@@ -707,16 +715,12 @@ fn type_param(@t ty) -> option.t[uint] {
707715
ret none[uint];
708716
}
709717

710-
fn plain_ty(&sty st) -> @t {
711-
ret @rec(struct=st, cname=none[str]);
712-
}
713-
714718
fn def_to_str(ast.def_id did) -> str {
715719
ret #fmt("%d:%d", did._0, did._1);
716720
}
717721

718-
fn simple_ty_code(&@t ty) -> uint {
719-
alt (ty.struct) {
722+
fn simple_ty_code(&sty st) -> uint {
723+
alt (st) {
720724
case (ty_nil) { ret 0u; }
721725
case (ty_bool) { ret 1u; }
722726
case (ty_int) { ret 2u; }
@@ -749,20 +753,28 @@ fn simple_ty_code(&@t ty) -> uint {
749753
ret 0xffffu;
750754
}
751755

752-
fn hash_ty(&@t ty) -> uint {
753-
auto s = simple_ty_code(ty);
756+
// Type hashing. This function is private to this module (and slow); external
757+
// users should use `hash_ty()` instead.
758+
fn hash_type_structure(&sty st) -> uint {
759+
760+
auto s = simple_ty_code(st);
754761
if (s != 0xffffu) {
755762
ret s;
756763
}
757764
auto f = def_to_str;
758-
ret _str.hash(metadata.ty_str(ty, f));
765+
766+
// FIXME: Gross. Use structural hashing when we have it.
767+
auto fake_ty = @rec(struct=st, cname=none[str], hash=0u);
768+
ret _str.hash(metadata.ty_str(fake_ty, f));
759769
}
760770

771+
fn hash_ty(&@t typ) -> uint { ret typ.hash; }
772+
761773
fn eq_ty(&@t a, &@t b) -> bool {
762774

763-
auto sa = simple_ty_code(a);
775+
auto sa = simple_ty_code(a.struct);
764776
if (sa != 0xffffu) {
765-
auto sb = simple_ty_code(b);
777+
auto sb = simple_ty_code(b.struct);
766778
ret sa == sb;
767779
}
768780

0 commit comments

Comments
 (0)