Skip to content

Commit 3ee630b

Browse files
committed
Add ty::new_ty_hash, clean up comparing of ty::t's
1 parent e2e077c commit 3ee630b

File tree

4 files changed

+30
-49
lines changed

4 files changed

+30
-49
lines changed

src/comp/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ fn encode_hash(ebml_w: ebml::writer, hash: str) {
653653

654654
fn encode_metadata(cx: @crate_ctxt, crate: @crate) -> str {
655655

656-
let abbrevs = map::mk_hashmap(ty::hash_ty, ty::eq_ty);
656+
let abbrevs = ty::new_ty_hash();
657657
let ecx = @{ccx: cx, type_abbrevs: abbrevs};
658658

659659
let string_w = io::string_writer();

src/comp/middle/debuginfo.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: @ast::ty)
267267
let cache = get_cache(cx);
268268
let tg = BasicTypeDescriptorTag;
269269
alt cached_metadata::<@metadata<tydesc_md>>(
270-
cache, tg,
271-
{|md| ty::hash_ty(t) == ty::hash_ty(md.data.hash)}) {
270+
cache, tg, {|md| t == md.data.hash}) {
272271
option::some(md) { ret md; }
273272
option::none. {}
274273
}
@@ -311,7 +310,7 @@ fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: @ast::ty)
311310
lli32(0), //XXX flags?
312311
lli32(encoding)];
313312
let llnode = llmdnode(lldata);
314-
let mdval = @{node: llnode, data: {hash: ty::hash_ty(t)}};
313+
let mdval = @{node: llnode, data: {hash: t}};
315314
update_cache(cache, tg, tydesc_metadata(mdval));
316315
add_named_metadata(cx, "llvm.dbg.ty", llnode);
317316
ret mdval;
@@ -333,7 +332,7 @@ fn create_pointer_type(cx: @crate_ctxt, t: ty::t, span: codemap::span,
333332
//let cu_node = create_compile_unit(cx, fname);
334333
let llnode = create_derived_type(tg, file_node.node, "", 0, size * 8,
335334
align * 8, 0, pointee.node);
336-
let mdval = @{node: llnode, data: {hash: ty::hash_ty(t)}};
335+
let mdval = @{node: llnode, data: {hash: t}};
337336
//update_cache(cache, tg, tydesc_metadata(mdval));
338337
add_named_metadata(cx, "llvm.dbg.ty", llnode);
339338
ret mdval;

src/comp/middle/trans.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4348,7 +4348,7 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: span, llfndecl: ValueRef,
43484348
lllocals: new_int_hash::<local_val>(),
43494349
llupvars: new_int_hash::<ValueRef>(),
43504350
mutable lltydescs: [],
4351-
derived_tydescs: map::mk_hashmap(ty::hash_ty, ty::eq_ty),
4351+
derived_tydescs: ty::new_ty_hash(),
43524352
id: id,
43534353
ret_style: rstyle,
43544354
sp: sp,
@@ -5642,13 +5642,6 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
56425642
tn.associate("taskptr", taskptr_type);
56435643
let tydesc_type = T_tydesc(targ_cfg);
56445644
tn.associate("tydesc", tydesc_type);
5645-
let hasher = ty::hash_ty;
5646-
let eqer = ty::eq_ty;
5647-
let tag_sizes = map::mk_hashmap::<ty::t, uint>(hasher, eqer);
5648-
let tydescs = map::mk_hashmap::<ty::t, @tydesc_info>(hasher, eqer);
5649-
let lltypes = map::mk_hashmap::<ty::t, TypeRef>(hasher, eqer);
5650-
let sha1s = map::mk_hashmap::<ty::t, str>(hasher, eqer);
5651-
let short_names = map::mk_hashmap::<ty::t, str>(hasher, eqer);
56525645
let crate_map = decl_crate_map(sess, link_meta.name, llmod);
56535646
let dbg_cx = if sess.get_opts().debuginfo {
56545647
option::some(@{llmetadata: map::new_int_hash(),
@@ -5669,18 +5662,18 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
56695662
item_symbols: new_int_hash::<str>(),
56705663
mutable main_fn: none::<ValueRef>,
56715664
link_meta: link_meta,
5672-
tag_sizes: tag_sizes,
5665+
tag_sizes: ty::new_ty_hash(),
56735666
discrims: ast_util::new_def_id_hash::<ValueRef>(),
56745667
discrim_symbols: new_int_hash::<str>(),
56755668
consts: new_int_hash::<ValueRef>(),
56765669
obj_methods: new_int_hash::<()>(),
5677-
tydescs: tydescs,
5670+
tydescs: ty::new_ty_hash(),
56785671
module_data: new_str_hash::<ValueRef>(),
5679-
lltypes: lltypes,
5672+
lltypes: ty::new_ty_hash(),
56805673
names: namegen(0),
56815674
sha: sha,
5682-
type_sha1s: sha1s,
5683-
type_short_names: short_names,
5675+
type_sha1s: ty::new_ty_hash(),
5676+
type_short_names: ty::new_ty_hash(),
56845677
tcx: tcx,
56855678
mut_map: mut_map,
56865679
copy_map: copy_map,

src/comp/middle/ty.rs

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export constr_table;
3636
export count_ty_params;
3737
export ctxt;
3838
export def_has_ty_params;
39-
export eq_ty;
4039
export expr_has_ty_params;
4140
export expr_ty;
4241
export expr_ty_params_and_ty;
@@ -47,7 +46,6 @@ export field_idx;
4746
export get_field;
4847
export fm_general;
4948
export get_element_type;
50-
export hash_ty;
5149
export idx_nil;
5250
export is_binopable;
5351
export is_pred_ty;
@@ -103,6 +101,7 @@ export stmt_node_id;
103101
export sty;
104102
export substitute_type_params;
105103
export t;
104+
export new_ty_hash;
106105
export tag_variants;
107106
export tag_variant_with_id;
108107
export ty_param_substs_opt_and_ty;
@@ -398,12 +397,16 @@ fn mk_rcache() -> creader_cache {
398397
ret map::mk_hashmap(hash_cache_entry, eq_cache_entries);
399398
}
400399

400+
fn new_ty_hash<copy V>() -> map::hashmap<t, V> { map::new_uint_hash() }
401401

402402
fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
403403
freevars: freevars::freevar_map) -> ctxt {
404404
let ntt: node_type_table =
405405
@smallintmap::mk::<ty::ty_param_substs_opt_and_ty>();
406406
let tcache = new_def_hash::<ty::ty_param_kinds_and_ty>();
407+
fn eq_raw_ty(&&a: @raw_t, &&b: @raw_t) -> bool {
408+
ret a.hash == b.hash && a.struct == b.struct;
409+
}
407410
let ts = @interner::mk::<@raw_t>(hash_raw_ty, eq_raw_ty);
408411
let cx =
409412
@{ts: ts,
@@ -414,9 +417,9 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
414417
freevars: freevars,
415418
tcache: tcache,
416419
rcache: mk_rcache(),
417-
short_names_cache: map::mk_hashmap(ty::hash_ty, ty::eq_ty),
418-
needs_drop_cache: map::mk_hashmap(ty::hash_ty, ty::eq_ty),
419-
kind_cache: map::mk_hashmap(ty::hash_ty, ty::eq_ty),
420+
short_names_cache: new_ty_hash(),
421+
needs_drop_cache: new_ty_hash(),
422+
kind_cache: new_ty_hash(),
420423
ast_ty_to_ty_cache:
421424
map::mk_hashmap(ast_util::hash_ty, ast_util::eq_ty),
422425
tag_var_cache: @smallintmap::mk()};
@@ -1233,8 +1236,7 @@ fn type_autoderef(cx: ctxt, t: ty::t) -> ty::t {
12331236
ret t1;
12341237
}
12351238

1236-
// Type hashing. This function is private to this module (and slow); external
1237-
// users should use `hash_ty()` instead.
1239+
// Type hashing.
12381240
fn hash_type_structure(st: sty) -> uint {
12391241
fn hash_uint(id: uint, n: uint) -> uint {
12401242
let h = id;
@@ -1249,7 +1251,7 @@ fn hash_type_structure(st: sty) -> uint {
12491251
}
12501252
fn hash_subty(id: uint, subty: t) -> uint {
12511253
let h = id;
1252-
h += (h << 5u) + hash_ty(subty);
1254+
h += (h << 5u) + subty;
12531255
ret h;
12541256
}
12551257
fn hash_subtys(id: uint, subtys: [t]) -> uint {
@@ -1284,8 +1286,8 @@ fn hash_type_structure(st: sty) -> uint {
12841286

12851287
fn hash_fn(id: uint, args: [arg], rty: t) -> uint {
12861288
let h = id;
1287-
for a: arg in args { h += (h << 5u) + hash_ty(a.ty); }
1288-
h += (h << 5u) + hash_ty(rty);
1289+
for a: arg in args { h += (h << 5u) + a.ty; }
1290+
h += (h << 5u) + rty;
12891291
ret h;
12901292
}
12911293
alt st {
@@ -1308,14 +1310,14 @@ fn hash_type_structure(st: sty) -> uint {
13081310
ty_str. { ret 17u; }
13091311
ty_tag(did, tys) {
13101312
let h = hash_def(18u, did);
1311-
for typ: t in tys { h += (h << 5u) + hash_ty(typ); }
1313+
for typ: t in tys { h += (h << 5u) + typ; }
13121314
ret h;
13131315
}
13141316
ty_box(mt) { ret hash_subty(19u, mt.ty); }
13151317
ty_vec(mt) { ret hash_subty(21u, mt.ty); }
13161318
ty_rec(fields) {
13171319
let h = 26u;
1318-
for f: field in fields { h += (h << 5u) + hash_ty(f.mt.ty); }
1320+
for f: field in fields { h += (h << 5u) + f.mt.ty; }
13191321
ret h;
13201322
}
13211323
ty_tup(ts) { ret hash_subtys(25u, ts); }
@@ -1354,13 +1356,6 @@ fn hash_type_structure(st: sty) -> uint {
13541356

13551357
fn hash_raw_ty(&&rt: @raw_t) -> uint { ret rt.hash; }
13561358

1357-
fn hash_ty(&&typ: t) -> uint { ret typ; }
1358-
1359-
1360-
// Type equality. This function is private to this module (and slow); external
1361-
// users should use `eq_ty()` instead.
1362-
fn eq_int(&&x: uint, &&y: uint) -> bool { ret x == y; }
1363-
13641359
fn arg_eq<T>(eq: fn(T, T) -> bool, a: @sp_constr_arg<T>, b: @sp_constr_arg<T>)
13651360
-> bool {
13661361
alt a.node {
@@ -1389,6 +1384,7 @@ fn args_eq<T>(eq: fn(T, T) -> bool, a: [@sp_constr_arg<T>],
13891384
}
13901385

13911386
fn constr_eq(c: @constr, d: @constr) -> bool {
1387+
fn eq_int(&&x: uint, &&y: uint) -> bool { ret x == y; }
13921388
ret path_to_str(c.node.path) == path_to_str(d.node.path) &&
13931389
// FIXME: hack
13941390
args_eq(eq_int, c.node.args, d.node.args);
@@ -1401,16 +1397,6 @@ fn constrs_eq(cs: [@constr], ds: [@constr]) -> bool {
14011397
ret true;
14021398
}
14031399

1404-
// This function is private to this module.
1405-
fn eq_raw_ty(&&a: @raw_t, &&b: @raw_t) -> bool {
1406-
ret a.hash == b.hash && a.struct == b.struct;
1407-
}
1408-
1409-
1410-
// This is the equality function the public should use. It works as long as
1411-
// the types are interned.
1412-
fn eq_ty(&&a: t, &&b: t) -> bool { a == b }
1413-
14141400
// Type lookups
14151401
fn node_id_to_ty_param_substs_opt_and_ty(cx: ctxt, id: ast::node_id) ->
14161402
ty_param_substs_opt_and_ty {
@@ -2088,12 +2074,15 @@ mod unify {
20882074

20892075
fn unify_step(cx: @ctxt, expected: t, actual: t,
20902076
variance: variance) -> result {
2091-
// TODO: rewrite this using tuple pattern matching when available, to
2077+
// FIXME: rewrite this using tuple pattern matching when available, to
20922078
// avoid all this rightward drift and spikiness.
2079+
// NOTE: we have tuple matching now, but that involves copying the
2080+
// matched elements into a tuple first, which is expensive, since sty
2081+
// holds vectors, which are currently unique
20932082

20942083
// Fast path.
2084+
if expected == actual { ret ures_ok(expected); }
20952085

2096-
if eq_ty(expected, actual) { ret ures_ok(expected); }
20972086
// Stage 1: Handle the cases in which one side or another is a type
20982087
// variable.
20992088

0 commit comments

Comments
 (0)