Revert "rustc: Avoid SHA-1 hashing every type, since they're interned"

This reverts commit df90f57a5f.
This commit is contained in:
Patrick Walton 2011-07-21 11:44:12 -07:00
parent b49bdad499
commit a44fb04d57
2 changed files with 29 additions and 9 deletions

View File

@ -399,18 +399,38 @@ fn truncated_sha1_result(sha1 sha) -> str {
ret str::substr(sha.result_str(), 0u, 16u);
}
fn hash_link_meta(sha1 sha, &link_meta link_meta) -> str {
// This calculates STH for a symbol, as defined above
fn symbol_hash(ty::ctxt tcx, sha1 sha, &ty::t t,
&link_meta link_meta) -> str {
// NB: do *not* use abbrevs here as we want the symbol names
// to be independent of one another in the crate.
sha.reset();
sha.input_str(link_meta.name);
sha.input_str("-");
sha.input_str(link_meta.vers);
// FIXME: This wants to be link_meta.meta_hash
sha.input_str(link_meta.name);
sha.input_str("-");
sha.input_str(link_meta.extras_hash);
ret truncated_sha1_result(sha);
sha.input_str(encoder::encoded_ty(tcx, t));
auto hash = truncated_sha1_result(sha);
// Prefix with _ so that it never blends into adjacent digits
ret "_" + hash;
}
fn get_symbol_hash(&@crate_ctxt ccx, &ty::t t) -> str {
ret #fmt("_%s_%u", ccx.link_meta_hash, t);
auto hash = "";
alt (ccx.type_sha1s.find(t)) {
case (some(?h)) { hash = h; }
case (none) {
hash =
symbol_hash(ccx.tcx, ccx.sha, t,
ccx.link_meta);
ccx.type_sha1s.insert(t, hash);
}
}
ret hash;
}
fn mangle(&str[] ss) -> str {

View File

@ -136,7 +136,6 @@ type crate_ctxt =
hashmap[ast::node_id, str] item_symbols,
mutable option::t[ValueRef] main_fn,
link::link_meta link_meta,
str link_meta_hash,
// TODO: hashmap[tup(tag_id,subtys), @tag_info]
hashmap[ty::t, uint] tag_sizes,
@ -151,6 +150,7 @@ type crate_ctxt =
@glue_fns glues,
namegen names,
std::sha1::sha1 sha,
hashmap[ty::t, str] type_sha1s,
hashmap[ty::t, str] type_short_names,
ty::ctxt tcx,
stats stats,
@ -8601,9 +8601,9 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
auto tag_sizes = map::mk_hashmap[ty::t, uint](hasher, eqer);
auto tydescs = map::mk_hashmap[ty::t, @tydesc_info](hasher, eqer);
auto lltypes = map::mk_hashmap[ty::t, TypeRef](hasher, eqer);
auto sha1s = map::mk_hashmap[ty::t, str](hasher, eqer);
auto short_names = map::mk_hashmap[ty::t, str](hasher, eqer);
auto sha = std::sha1::mk_sha1();
auto link_meta = link::build_link_meta(sess, *crate, output, sha);
auto ccx =
@rec(sess=sess,
llmod=llmod,
@ -8615,8 +8615,7 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
ast_map=amap,
item_symbols=new_int_hash[str](),
mutable main_fn=none[ValueRef],
link_meta=link_meta,
link_meta_hash=link::hash_link_meta(sha, link_meta),
link_meta=link::build_link_meta(sess, *crate, output, sha),
tag_sizes=tag_sizes,
discrims=new_int_hash[ValueRef](),
discrim_symbols=new_int_hash[str](),
@ -8629,6 +8628,7 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
glues=glues,
names=namegen(0),
sha=sha,
type_sha1s=sha1s,
type_short_names=short_names,
tcx=tcx,
stats=rec(mutable n_static_tydescs=0u,