Skip to content

Commit

Permalink
std: rewrite Hash to make it more generic
Browse files Browse the repository at this point in the history
This patch merges IterBytes and Hash traits, which clears up the
confusion of using `#[deriving(IterBytes)]` to support hashing.
Instead, it now is much easier to use the new `#[deriving(Hash)]`
for making a type hashable with a stream hash.

Furthermore, it supports custom non-stream-based hashers, such as
if a value's hash was cached in a database.

This does not yet replace the old IterBytes-hash with this new
version.
  • Loading branch information
erickt committed Feb 22, 2014
1 parent 0135b52 commit d223dd1
Show file tree
Hide file tree
Showing 25 changed files with 1,154 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/etc/generate-deriving-span-tests.py
Expand Up @@ -119,7 +119,8 @@ def write_file(name, string):
('Clone', [], 1), ('DeepClone', ['Clone'], 1),
('Eq', [], 2), ('Ord', [], 8),
('TotalEq', [], 1), ('TotalOrd', ['TotalEq'], 1),
('Show', [], 1)]:
('Show', [], 1),
('Hash', [], 1)]:
traits[trait] = (ALL, supers, errs)

for (trait, (types, super_traits, error_count)) in traits.items():
Expand Down
1 change: 1 addition & 0 deletions src/libextra/stats.rs
Expand Up @@ -11,6 +11,7 @@
#[allow(missing_doc)];

use std::cmp;
use std::hash_old::Hash;
use std::hashmap;
use std::io;
use std::mem;
Expand Down
1 change: 1 addition & 0 deletions src/librustc/metadata/decoder.rs
Expand Up @@ -27,6 +27,7 @@ use middle::typeck;
use middle::astencode::vtable_decoder_helpers;

use std::u64;
use std::hash_old::Hash;
use std::io;
use std::io::extensions::u64_from_be_bytes;
use std::option;
Expand Down
1 change: 1 addition & 0 deletions src/librustc/metadata/encoder.rs
Expand Up @@ -26,6 +26,7 @@ use middle;
use serialize::Encodable;
use std::cast;
use std::cell::{Cell, RefCell};
use std::hash_old::Hash;
use std::hashmap::{HashMap, HashSet};
use std::io::MemWriter;
use std::str;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/ty.rs
Expand Up @@ -4916,7 +4916,7 @@ pub fn trait_method_of_method(tcx: ctxt,
/// Creates a hash of the type `t` which will be the same no matter what crate
/// context it's calculated within. This is used by the `type_id` intrinsic.
pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
use std::hash::{SipState, Streaming};
use std::hash_old::{SipState, Streaming};

let mut hash = SipState::new(0, 0);
let region = |_hash: &mut SipState, r: Region| {
Expand Down
1 change: 1 addition & 0 deletions src/libserialize/serialize.rs
Expand Up @@ -14,6 +14,7 @@
Core encoding and decoding interfaces.
*/

use std::hash_old::Hash;
use std::hashmap::{HashMap, HashSet};
use std::rc::Rc;
use std::trie::{TrieMap, TrieSet};
Expand Down

8 comments on commit d223dd1

@bors
Copy link
Contributor

@bors bors commented on d223dd1 Feb 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from acrichto
at erickt@d223dd1

@bors
Copy link
Contributor

@bors bors commented on d223dd1 Feb 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/hash = d223dd1 into auto

@bors
Copy link
Contributor

@bors bors commented on d223dd1 Feb 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erickt/rust/hash = d223dd1 merged ok, testing candidate = efe7c254

@bors
Copy link
Contributor

@bors bors commented on d223dd1 Feb 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on d223dd1 Feb 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from acrichto
at erickt@d223dd1

@bors
Copy link
Contributor

@bors bors commented on d223dd1 Feb 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/hash = d223dd1 into auto

@bors
Copy link
Contributor

@bors bors commented on d223dd1 Feb 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erickt/rust/hash = d223dd1 merged ok, testing candidate = ea7afe6e

Please sign in to comment.