Skip to content

Commit 1854a73

Browse files
dgryskigraydon
authored andcommitted
rustc: use new siphash impl instead of sha1
Updating types std::sha1::sha1 -> hash::streaming was a relatively small change. Renaming the variables to reflect that things aren't sha1s any more touched far more lines.
1 parent 04f2073 commit 1854a73

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

src/rustc/back/link.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ mod write {
307307
*/
308308

309309
fn build_link_meta(sess: session, c: ast::crate, output: ~str,
310-
sha: sha1) -> link_meta {
310+
symbol_hasher: hash::streaming) -> link_meta {
311311

312312
type provided_metas =
313313
{name: option<@~str>,
@@ -338,7 +338,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: ~str,
338338
}
339339

340340
// This calculates CMH as defined above
341-
fn crate_meta_extras_hash(sha: sha1, _crate: ast::crate,
341+
fn crate_meta_extras_hash(symbol_hasher: hash::streaming, _crate: ast::crate,
342342
metas: provided_metas,
343343
dep_hashes: ~[@~str]) -> ~str {
344344
fn len_and_str(s: ~str) -> ~str {
@@ -351,15 +351,15 @@ fn build_link_meta(sess: session, c: ast::crate, output: ~str,
351351

352352
let cmh_items = attr::sort_meta_items(metas.cmh_items);
353353

354-
sha.reset();
354+
symbol_hasher.reset();
355355
for cmh_items.each |m_| {
356356
let m = m_;
357357
alt m.node {
358358
ast::meta_name_value(key, value) {
359-
sha.input_str(len_and_str(*key));
360-
sha.input_str(len_and_str_lit(value));
359+
symbol_hasher.input_str(len_and_str(*key));
360+
symbol_hasher.input_str(len_and_str_lit(value));
361361
}
362-
ast::meta_word(name) { sha.input_str(len_and_str(*name)); }
362+
ast::meta_word(name) { symbol_hasher.input_str(len_and_str(*name)); }
363363
ast::meta_list(_, _) {
364364
// FIXME (#607): Implement this
365365
fail ~"unimplemented meta_item variant";
@@ -368,10 +368,10 @@ fn build_link_meta(sess: session, c: ast::crate, output: ~str,
368368
}
369369

370370
for dep_hashes.each |dh| {
371-
sha.input_str(len_and_str(*dh));
371+
symbol_hasher.input_str(len_and_str(*dh));
372372
}
373373

374-
ret truncated_sha1_result(sha);
374+
ret truncated_hash_result(symbol_hasher);
375375
}
376376

377377
fn warn_missing(sess: session, name: ~str, default: ~str) {
@@ -419,40 +419,40 @@ fn build_link_meta(sess: session, c: ast::crate, output: ~str,
419419
let vers = crate_meta_vers(sess, c, provided_metas);
420420
let dep_hashes = cstore::get_dep_hashes(sess.cstore);
421421
let extras_hash =
422-
crate_meta_extras_hash(sha, c, provided_metas, dep_hashes);
422+
crate_meta_extras_hash(symbol_hasher, c, provided_metas, dep_hashes);
423423

424424
ret {name: name, vers: vers, extras_hash: extras_hash};
425425
}
426426

427-
fn truncated_sha1_result(sha: sha1) -> ~str unsafe {
428-
ret str::slice(sha.result_str(), 0u, 16u);
427+
fn truncated_hash_result(symbol_hasher: hash::streaming) -> ~str unsafe {
428+
symbol_hasher.result_str()
429429
}
430430

431431

432432
// This calculates STH for a symbol, as defined above
433-
fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t,
433+
fn symbol_hash(tcx: ty::ctxt, symbol_hasher: hash::streaming, t: ty::t,
434434
link_meta: link_meta) -> ~str {
435435
// NB: do *not* use abbrevs here as we want the symbol names
436436
// to be independent of one another in the crate.
437437

438-
sha.reset();
439-
sha.input_str(*link_meta.name);
440-
sha.input_str(~"-");
441-
sha.input_str(link_meta.extras_hash);
442-
sha.input_str(~"-");
443-
sha.input_str(encoder::encoded_ty(tcx, t));
444-
let hash = truncated_sha1_result(sha);
438+
symbol_hasher.reset();
439+
symbol_hasher.input_str(*link_meta.name);
440+
symbol_hasher.input_str(~"-");
441+
symbol_hasher.input_str(link_meta.extras_hash);
442+
symbol_hasher.input_str(~"-");
443+
symbol_hasher.input_str(encoder::encoded_ty(tcx, t));
444+
let hash = truncated_hash_result(symbol_hasher);
445445
// Prefix with _ so that it never blends into adjacent digits
446446
447447
ret ~"_" + hash;
448448
}
449449

450450
fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> ~str {
451-
alt ccx.type_sha1s.find(t) {
451+
alt ccx.type_hashcodes.find(t) {
452452
some(h) { ret h; }
453453
none {
454-
let hash = symbol_hash(ccx.tcx, ccx.sha, t, ccx.link_meta);
455-
ccx.type_sha1s.insert(t, hash);
454+
let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta);
455+
ccx.type_hashcodes.insert(t, hash);
456456
ret hash;
457457
}
458458
}

src/rustc/middle/trans/base.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5650,8 +5650,8 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
56505650
output: ~str, emap: resolve3::ExportMap,
56515651
maps: astencode::maps)
56525652
-> (ModuleRef, link_meta) {
5653-
let sha = std::sha1::sha1();
5654-
let link_meta = link::build_link_meta(sess, *crate, output, sha);
5653+
let symbol_hasher = hash::siphash(0,0);
5654+
let link_meta = link::build_link_meta(sess, *crate, output, symbol_hasher);
56555655
let reachable = reachable::find_reachable(crate.node.module, emap, tcx,
56565656
maps.method_map);
56575657

@@ -5724,8 +5724,8 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
57245724
module_data: str_hash::<ValueRef>(),
57255725
lltypes: ty::new_ty_hash(),
57265726
names: new_namegen(),
5727-
sha: sha,
5728-
type_sha1s: ty::new_ty_hash(),
5727+
symbol_hasher: symbol_hasher,
5728+
type_hashcodes: ty::new_ty_hash(),
57295729
type_short_names: ty::new_ty_hash(),
57305730
all_llvm_symbols: str_hash::<()>(),
57315731
tcx: tcx,

src/rustc/middle/trans/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ type crate_ctxt = {
110110
module_data: hashmap<~str, ValueRef>,
111111
lltypes: hashmap<ty::t, TypeRef>,
112112
names: namegen,
113-
sha: std::sha1::sha1,
114-
type_sha1s: hashmap<ty::t, ~str>,
113+
symbol_hasher: hash::streaming,
114+
type_hashcodes: hashmap<ty::t, ~str>,
115115
type_short_names: hashmap<ty::t, ~str>,
116116
all_llvm_symbols: set<~str>,
117117
tcx: ty::ctxt,

0 commit comments

Comments
 (0)