Skip to content

A couple cleanup patches to the new Hash framework #12522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcollections/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn resize_at(capacity: uint) -> uint {
(capacity * 3) / 4
}

impl<K:Hash + Eq,V> HashMap<K, V> {
impl<K:Hash + Eq, V> HashMap<K, V> {
#[inline]
fn to_bucket(&self, h: uint) -> uint {
// A good hash function with entropy spread over all of the
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ pub fn is_null(val: ValueRef) -> bool {
}

// Used to identify cached monomorphized functions and vtables
#[deriving(Eq,Hash)]
#[deriving(Eq, Hash)]
pub enum mono_param_id {
mono_precise(ty::t, Option<@~[mono_id]>),
mono_any,
Expand All @@ -732,7 +732,7 @@ pub enum mono_param_id {
datum::RvalueMode),
}

#[deriving(Eq,Hash)]
#[deriving(Eq, Hash)]
pub enum MonoDataClass {
MonoBits, // Anything not treated differently from arbitrary integer data
MonoNonNull, // Non-null pointers (used for optional-pointer optimization)
Expand All @@ -754,8 +754,7 @@ pub fn mono_data_classify(t: ty::t) -> MonoDataClass {
}
}


#[deriving(Eq,Hash)]
#[deriving(Eq, Hash)]
pub struct mono_id_ {
def: ast::DefId,
params: ~[mono_param_id]
Expand Down
58 changes: 28 additions & 30 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub struct field_ty {

// Contains information needed to resolve types and (in the future) look up
// the types of AST nodes.
#[deriving(Eq,Hash)]
#[deriving(Eq, Hash)]
pub struct creader_cache_key {
cnum: CrateNum,
pos: uint,
Expand Down Expand Up @@ -4925,13 +4925,11 @@ 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::{sip, Hash};

let mut hash = sip::SipState::new(0, 0);
macro_rules! byte( ($b:expr) => { ($b as u8).hash(&mut hash) } );
macro_rules! hash( ($e:expr) => { $e.hash(&mut hash) } );
let mut state = sip::SipState::new(0, 0);
macro_rules! byte( ($b:expr) => { ($b as u8).hash(&mut state) } );
macro_rules! hash( ($e:expr) => { $e.hash(&mut state) } );

let region = |_hash: &mut sip::SipState, r: Region| {
let region = |_state: &mut sip::SipState, r: Region| {
match r {
ReStatic => {}

Expand All @@ -4945,27 +4943,27 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
}
}
};
let vstore = |hash: &mut sip::SipState, v: vstore| {
let vstore = |state: &mut sip::SipState, v: vstore| {
match v {
vstore_fixed(_) => 0u8.hash(hash),
vstore_uniq => 1u8.hash(hash),
vstore_fixed(_) => 0u8.hash(state),
vstore_uniq => 1u8.hash(state),
vstore_slice(r) => {
2u8.hash(hash);
region(hash, r);
2u8.hash(state);
region(state, r);
}
}
};
let did = |hash: &mut sip::SipState, did: DefId| {
let did = |state: &mut sip::SipState, did: DefId| {
let h = if ast_util::is_local(did) {
local_hash.clone()
} else {
tcx.sess.cstore.get_crate_hash(did.krate)
};
h.as_bytes().hash(hash);
did.node.hash(hash);
h.as_bytes().hash(state);
did.node.hash(state);
};
let mt = |hash: &mut sip::SipState, mt: mt| {
mt.mutbl.hash(hash);
let mt = |state: &mut sip::SipState, mt: mt| {
mt.mutbl.hash(state);
};
ty::walk_ty(t, |t| {
match ty::get(t).sty {
Expand Down Expand Up @@ -5001,17 +4999,17 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
}
ty_vec(m, v) => {
byte!(11);
mt(&mut hash, m);
vstore(&mut hash, v);
mt(&mut state, m);
vstore(&mut state, v);
}
ty_ptr(m) => {
byte!(12);
mt(&mut hash, m);
mt(&mut state, m);
}
ty_rptr(r, m) => {
byte!(13);
region(&mut hash, r);
mt(&mut hash, m);
region(&mut state, r);
mt(&mut state, m);
}
ty_bare_fn(ref b) => {
byte!(14);
Expand All @@ -5024,24 +5022,24 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
hash!(c.sigil);
hash!(c.onceness);
hash!(c.bounds);
region(&mut hash, c.region);
region(&mut state, c.region);
}
ty_trait(d, _, store, m, bounds) => {
byte!(17);
did(&mut hash, d);
did(&mut state, d);
match store {
UniqTraitStore => byte!(0),
RegionTraitStore(r) => {
byte!(1)
region(&mut hash, r);
region(&mut state, r);
}
}
hash!(m);
hash!(bounds);
}
ty_struct(d, _) => {
byte!(18);
did(&mut hash, d);
did(&mut state, d);
}
ty_tup(ref inner) => {
byte!(19);
Expand All @@ -5050,22 +5048,22 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
ty_param(p) => {
byte!(20);
hash!(p.idx);
did(&mut hash, p.def_id);
did(&mut state, p.def_id);
}
ty_self(d) => {
byte!(21);
did(&mut hash, d);
did(&mut state, d);
}
ty_infer(_) => unreachable!(),
ty_err => byte!(23),
ty_unboxed_vec(m) => {
byte!(24);
mt(&mut hash, m);
mt(&mut state, m);
}
}
});

hash.result()
state.result()
}

impl Variance {
Expand Down
10 changes: 1 addition & 9 deletions src/libstd/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ use str::OwnedStr;
use container::Container;
use cast;
use fmt;
use hash::{Hash, sip};
use iter::Iterator;
use vec::{ImmutableVector, MutableVector, Vector};
use option::{Option, Some, None};

/// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero.
#[deriving(Clone, Eq, Ord, TotalOrd, TotalEq)]
#[deriving(Clone, Eq, Ord, TotalOrd, TotalEq, Hash)]
pub struct Ascii { priv chr: u8 }

impl Ascii {
Expand Down Expand Up @@ -306,13 +305,6 @@ impl IntoStr for ~[Ascii] {
}
}

impl Hash for Ascii {
#[inline]
fn hash(&self, s: &mut sip::SipState) {
self.to_byte().hash(s)
}
}

/// Trait to convert to an owned byte array by consuming self
pub trait IntoBytes {
/// Converts to an owned byte array by consuming self
Expand Down
1 change: 0 additions & 1 deletion src/libstd/io/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub struct SocketAddr {
port: Port,
}


impl fmt::Show for SocketAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.ip {
Expand Down
1 change: 0 additions & 1 deletion src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ pub mod container;
pub mod default;
pub mod any;


/* Common data structures */

pub mod option;
Expand Down
9 changes: 1 addition & 8 deletions src/libsyntax/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::hash::{Hash, sip};
use std::fmt;
use std::fmt::Show;

#[deriving(Eq)]
pub enum Os { OsWin32, OsMacos, OsLinux, OsAndroid, OsFreebsd, }

#[deriving(Eq)]
#[deriving(Eq, Hash)]
pub enum Abi {
// NB: This ordering MUST match the AbiDatas array below.
// (This is ensured by the test indices_are_correct().)
Expand Down Expand Up @@ -267,12 +266,6 @@ impl AbiSet {
}
}

impl Hash for Abi {
fn hash(&self, s: &mut sip::SipState) {
self.index().hash(s)
}
}

impl fmt::Show for Abi {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.data().name.fmt(f)
Expand Down
Loading