diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-05-23 00:38:39 -0700 | 
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-05-23 00:43:02 -0700 | 
| commit | 4756556748fe7fa247c02f36dc481c8eeae9908d (patch) | |
| tree | a914d555843f7325f8d3120e262cedc914b17a81 | |
| parent | 8ec467d521e6e39f80a0c74c049a5aa719a01dde (diff) | |
| download | rust-4756556748fe7fa247c02f36dc481c8eeae9908d.tar.gz rust-4756556748fe7fa247c02f36dc481c8eeae9908d.zip  | |
rustc: Move new_def_hash to ast_util
| -rw-r--r-- | src/librustsyntax/ast_util.rs | 17 | ||||
| -rw-r--r-- | src/rustc/metadata/cstore.rs | 1 | ||||
| -rw-r--r-- | src/rustc/middle/region.rs | 2 | ||||
| -rw-r--r-- | src/rustc/middle/resolve.rs | 6 | ||||
| -rw-r--r-- | src/rustc/middle/trans/base.rs | 4 | ||||
| -rw-r--r-- | src/rustc/middle/trans/shape.rs | 4 | ||||
| -rw-r--r-- | src/rustc/middle/tstate/collect_locals.rs | 1 | ||||
| -rw-r--r-- | src/rustc/middle/tstate/pre_post_conditions.rs | 2 | ||||
| -rw-r--r-- | src/rustc/middle/ty.rs | 7 | ||||
| -rw-r--r-- | src/rustc/util/common.rs | 17 | ||||
| -rw-r--r-- | src/rustdoc/reexport_pass.rs | 9 | 
11 files changed, 35 insertions, 35 deletions
diff --git a/src/librustsyntax/ast_util.rs b/src/librustsyntax/ast_util.rs index 55743f91713..0357b5dbf87 100644 --- a/src/librustsyntax/ast_util.rs +++ b/src/librustsyntax/ast_util.rs @@ -225,6 +225,23 @@ fn hash_ty(&&t: @ty) -> uint { ret res; } +fn def_eq(a: ast::def_id, b: ast::def_id) -> bool { + ret a.crate == b.crate && a.node == b.node; +} + +fn hash_def(d: ast::def_id) -> uint { + let mut h = 5381u; + h = (h << 5u) + h ^ (d.crate as uint); + h = (h << 5u) + h ^ (d.node as uint); + ret h; +} + +fn new_def_hash<V: copy>() -> std::map::hashmap<ast::def_id, V> { + let hasher: std::map::hashfn<ast::def_id> = hash_def; + let eqer: std::map::eqfn<ast::def_id> = def_eq; + ret std::map::hashmap::<ast::def_id, V>(hasher, eqer); +} + fn hash_def_id(&&id: def_id) -> uint { (id.crate as uint << 16u) + (id.node as uint) } diff --git a/src/rustc/metadata/cstore.rs b/src/rustc/metadata/cstore.rs index b3907d84f48..ceabf27d622 100644 --- a/src/rustc/metadata/cstore.rs +++ b/src/rustc/metadata/cstore.rs @@ -4,6 +4,7 @@ import std::map; import std::map::hashmap; import syntax::{ast, attr}; +import syntax::ast_util::new_def_hash; import util::common::*; export cstore::{}; diff --git a/src/rustc/middle/region.rs b/src/rustc/middle/region.rs index b12836e6125..51109c1155a 100644 --- a/src/rustc/middle/region.rs +++ b/src/rustc/middle/region.rs @@ -137,7 +137,7 @@ import middle::ty; import syntax::{ast, visit}; import syntax::codemap::span; import syntax::print::pprust; -import util::common::new_def_hash; +import syntax::ast_util::new_def_hash; import std::list; import std::list::list; diff --git a/src/rustc/middle/resolve.rs b/src/rustc/middle/resolve.rs index 9521b0d1488..3c713329268 100644 --- a/src/rustc/middle/resolve.rs +++ b/src/rustc/middle/resolve.rs @@ -1,7 +1,7 @@ import syntax::{ast, ast_util, codemap, ast_map}; import syntax::ast::*; import ast::{ident, fn_ident, def, def_id, node_id}; -import syntax::ast_util::{local_def, def_id_of_def, +import syntax::ast_util::{local_def, def_id_of_def, new_def_hash, class_item_ident, path_to_ident}; import pat_util::*; @@ -73,10 +73,10 @@ type ext_hash = hashmap<{did: def_id, ident: str, ns: namespace}, def>; fn new_ext_hash() -> ext_hash { type key = {did: def_id, ident: str, ns: namespace}; fn hash(v: key) -> uint { - str::hash(v.ident) + util::common::hash_def(v.did) + v.ns as uint + str::hash(v.ident) + ast_util::hash_def(v.did) + v.ns as uint } fn eq(v1: key, v2: key) -> bool { - ret util::common::def_eq(v1.did, v2.did) && + ret ast_util::def_eq(v1.did, v2.did) && str::eq(v1.ident, v2.ident) && v1.ns == v2.ns; } std::map::hashmap(hash, {|a, b| a == b}) diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index a4970268efd..07cbc4a96bc 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -5492,10 +5492,10 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt, discrims: ast_util::new_def_id_hash::<ValueRef>(), discrim_symbols: int_hash::<str>(), tydescs: ty::new_ty_hash(), - external: util::common::new_def_hash(), + external: ast_util::new_def_hash(), monomorphized: map::hashmap(hash_mono_id, {|a, b| a == b}), monomorphizing: ast_util::new_def_id_hash(), - type_use_cache: util::common::new_def_hash(), + type_use_cache: ast_util::new_def_hash(), vtables: map::hashmap(hash_mono_id, {|a, b| a == b}), const_cstr_cache: map::str_hash(), module_data: str_hash::<ValueRef>(), diff --git a/src/rustc/middle/trans/shape.rs b/src/rustc/middle/trans/shape.rs index 9e3c6255c89..d5517dc5ee2 100644 --- a/src/rustc/middle/trans/shape.rs +++ b/src/rustc/middle/trans/shape.rs @@ -11,7 +11,7 @@ import back::abi; import middle::ty; import middle::ty::field; import syntax::ast; -import syntax::ast_util::dummy_sp; +import syntax::ast_util::{dummy_sp, new_def_hash}; import syntax::util::interner; import util::common; import syntax::codemap::span; @@ -273,7 +273,7 @@ fn mk_ctxt(llmod: ModuleRef) -> ctxt { ret {mut next_tag_id: 0u16, pad: 0u16, - tag_id_to_index: common::new_def_hash(), + tag_id_to_index: new_def_hash(), tag_order: dvec(), resources: interner::mk(hash_res_info, {|a, b| a == b}), llshapetablesty: llshapetablesty, diff --git a/src/rustc/middle/tstate/collect_locals.rs b/src/rustc/middle/tstate/collect_locals.rs index b6f1de95984..88a353f4cd8 100644 --- a/src/rustc/middle/tstate/collect_locals.rs +++ b/src/rustc/middle/tstate/collect_locals.rs @@ -3,7 +3,6 @@ import pat_util::*; import syntax::ast::*; import syntax::ast_util::*; import syntax::visit; -import util::common::new_def_hash; import syntax::codemap::span; import syntax::ast_util::respan; import driver::session::session; diff --git a/src/rustc/middle/tstate/pre_post_conditions.rs b/src/rustc/middle/tstate/pre_post_conditions.rs index 7b8c864580d..3d1db2f6e66 100644 --- a/src/rustc/middle/tstate/pre_post_conditions.rs +++ b/src/rustc/middle/tstate/pre_post_conditions.rs @@ -9,7 +9,7 @@ import pat_util::*; import syntax::ast::*; import syntax::ast_util::*; import syntax::visit; -import util::common::{new_def_hash, log_expr, field_exprs, +import util::common::{log_expr, field_exprs, has_nonlocal_exits, log_stmt}; import syntax::codemap::span; import driver::session::session; diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index 7ad4bb0103b..84b4d4f6594 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -6,7 +6,8 @@ import session::session; import syntax::{ast, ast_map}; import syntax::ast::*; import syntax::ast_util; -import syntax::ast_util::{is_local, local_def, split_class_items}; +import syntax::ast_util::{is_local, local_def, split_class_items, + new_def_hash}; import syntax::codemap::span; import metadata::csearch; import util::common::*; @@ -478,7 +479,7 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map, items: amap, intrinsic_ifaces: map::str_hash(), freevars: freevars, - tcache: new_def_hash(), + tcache: ast_util::new_def_hash(), rcache: mk_rcache(), short_names_cache: new_ty_hash(), needs_drop_cache: new_ty_hash(), @@ -2524,7 +2525,7 @@ fn enum_variant_with_id(cx: ctxt, enum_id: ast::def_id, let mut i = 0u; while i < vec::len::<variant_info>(*variants) { let variant = variants[i]; - if def_eq(variant.id, variant_id) { ret variant; } + if ast_util::def_eq(variant.id, variant_id) { ret variant; } i += 1u; } cx.sess.bug("enum_variant_with_id(): no variant exists with that ID"); diff --git a/src/rustc/util/common.rs b/src/rustc/util/common.rs index 0cd45e0dcf5..daab9eb33f1 100644 --- a/src/rustc/util/common.rs +++ b/src/rustc/util/common.rs @@ -25,23 +25,6 @@ fn indenter() -> _indenter { type flag = hashmap<str, ()>; -fn def_eq(a: ast::def_id, b: ast::def_id) -> bool { - ret a.crate == b.crate && a.node == b.node; -} - -fn hash_def(d: ast::def_id) -> uint { - let mut h = 5381u; - h = (h << 5u) + h ^ (d.crate as uint); - h = (h << 5u) + h ^ (d.node as uint); - ret h; -} - -fn new_def_hash<V: copy>() -> std::map::hashmap<ast::def_id, V> { - let hasher: std::map::hashfn<ast::def_id> = hash_def; - let eqer: std::map::eqfn<ast::def_id> = def_eq; - ret std::map::hashmap::<ast::def_id, V>(hasher, eqer); -} - fn field_expr(f: ast::field) -> @ast::expr { ret f.node.expr; } fn field_exprs(fields: [ast::field]) -> [@ast::expr] { diff --git a/src/rustdoc/reexport_pass.rs b/src/rustdoc/reexport_pass.rs index 2637f8755d0..338c5d70f28 100644 --- a/src/rustdoc/reexport_pass.rs +++ b/src/rustdoc/reexport_pass.rs @@ -5,7 +5,6 @@ import std::map::hashmap; import std::list; import syntax::ast; import syntax::ast_util; -import rustc::util::common; import syntax::ast_map; import syntax::visit; import syntax::codemap; @@ -69,7 +68,7 @@ fn from_assoc_list<K:copy, V:copy>( fn from_def_assoc_list<V:copy>( list: [(ast::def_id, V)] ) -> map::hashmap<ast::def_id, V> { - from_assoc_list(list, bind common::new_def_hash()) + from_assoc_list(list, bind ast_util::new_def_hash()) } fn from_str_assoc_list<V:copy>( @@ -80,7 +79,7 @@ fn from_str_assoc_list<V:copy>( fn build_reexport_def_set(srv: astsrv::srv) -> def_set { let assoc_list = astsrv::exec(srv) {|ctxt| - let def_set = common::new_def_hash(); + let def_set = ast_util::new_def_hash(); for ctxt.exp_map.each {|_id, defs| for defs.each {|def| if def.reexp { @@ -120,7 +119,7 @@ fn build_reexport_def_map( let ctxt = { srv: srv, def_set: def_set, - def_map: common::new_def_hash() + def_map: ast_util::new_def_hash() }; // FIXME: Do a parallel fold @@ -289,7 +288,7 @@ fn for_each_reexported_impl( } fn all_impls(m: ast::_mod) -> map::set<ast::def_id> { - let all_impls = common::new_def_hash(); + let all_impls = ast_util::new_def_hash(); for m.items.each {|item| alt item.node { ast::item_impl(_, _, _, _, _) {  | 
