diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2014-04-20 19:29:56 +0300 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2014-04-22 19:06:55 +0300 |
| commit | 7b3d6afe0a1d7fb2c918e9ba1ed8c2d859c6e772 (patch) | |
| tree | fed27dadc4443ddfd85efc4a1e061b2ad4a85651 | |
| parent | 5fa7be659c00eb0cc2fc7cce1ad1ab65b2219637 (diff) | |
| download | rust-7b3d6afe0a1d7fb2c918e9ba1ed8c2d859c6e772.tar.gz rust-7b3d6afe0a1d7fb2c918e9ba1ed8c2d859c6e772.zip | |
rustc: de-@ mono_id.
| -rw-r--r-- | src/librustc/middle/trans/common.rs | 16 | ||||
| -rw-r--r-- | src/librustc/middle/trans/context.rs | 7 | ||||
| -rw-r--r-- | src/librustc/middle/trans/monomorphize.rs | 48 |
3 files changed, 37 insertions, 34 deletions
diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 78fe4135259..d1be86dfdbe 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -686,22 +686,6 @@ pub fn is_null(val: ValueRef) -> bool { } } -// Used to identify cached monomorphized functions and vtables -#[deriving(Eq, TotalEq, Hash)] -pub struct MonoParamId { - pub subst: ty::t, - // Do we really need the vtables to be hashed? Isn't the type enough? - pub vtables: Vec<mono_id> -} - -#[deriving(Eq, TotalEq, Hash)] -pub struct mono_id_ { - pub def: ast::DefId, - pub params: Vec<MonoParamId> -} - -pub type mono_id = @mono_id_; - pub fn monomorphize_type(bcx: &Block, t: ty::t) -> ty::t { match bcx.fcx.param_substs { Some(substs) => { diff --git a/src/librustc/middle/trans/context.rs b/src/librustc/middle/trans/context.rs index 4aad1cded1e..edd801d1347 100644 --- a/src/librustc/middle/trans/context.rs +++ b/src/librustc/middle/trans/context.rs @@ -20,8 +20,9 @@ use middle::resolve; use middle::trans::adt; use middle::trans::base; use middle::trans::builder::Builder; -use middle::trans::common::{mono_id,ExternMap,tydesc_info,BuilderRef_res,Stats}; +use middle::trans::common::{ExternMap,tydesc_info,BuilderRef_res,Stats}; use middle::trans::debuginfo; +use middle::trans::monomorphize::MonoId; use middle::trans::type_::Type; use middle::ty; use util::sha2::Sha256; @@ -61,10 +62,10 @@ pub struct CrateContext { /// that is generated pub non_inlineable_statics: RefCell<NodeSet>, /// Cache instances of monomorphized functions - pub monomorphized: RefCell<HashMap<mono_id, ValueRef>>, + pub monomorphized: RefCell<HashMap<MonoId, ValueRef>>, pub monomorphizing: RefCell<DefIdMap<uint>>, /// Cache generated vtables - pub vtables: RefCell<HashMap<(ty::t, mono_id), ValueRef>>, + pub vtables: RefCell<HashMap<(ty::t, MonoId), ValueRef>>, /// Cache of constant strings, pub const_cstr_cache: RefCell<HashMap<InternedString, ValueRef>>, diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 16fef63482f..81152523cdd 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -16,7 +16,6 @@ use middle::trans::base::{trans_enum_variant, push_ctxt, get_item_val}; use middle::trans::base::{trans_fn, decl_internal_rust_fn}; use middle::trans::base; use middle::trans::common::*; -use middle::trans::meth; use middle::trans::intrinsic; use middle::ty; use middle::typeck; @@ -26,7 +25,7 @@ use syntax::abi; use syntax::ast; use syntax::ast_map; use syntax::ast_util::local_def; -use std::hash::sip; +use std::hash::{sip, Hash}; pub fn monomorphic_fn(ccx: &CrateContext, fn_id: ast::DefId, @@ -71,7 +70,7 @@ pub fn monomorphic_fn(ccx: &CrateContext, }).collect() }; - let hash_id = @mono_id_ { + let hash_id = MonoId { def: fn_id, params: param_ids }; @@ -194,16 +193,22 @@ pub fn monomorphic_fn(ccx: &CrateContext, } let s = ccx.tcx.map.with_path(fn_id.node, |path| { - exported_name(path, format!("h{}", sip::hash(&(hash_id, mono_ty))), + let mut state = sip::SipState::new(); + hash_id.hash(&mut state); + mono_ty.hash(&mut state); + + exported_name(path, format!("h{}", state.result()), ccx.link_meta.crateid.version_or_default()) }); debug!("monomorphize_fn mangled to {}", s); + // This shouldn't need to option dance. + let mut hash_id = Some(hash_id); let mk_lldecl = || { let lldecl = decl_internal_rust_fn(ccx, false, f.sig.inputs.as_slice(), f.sig.output, s); - ccx.monomorphized.borrow_mut().insert(hash_id, lldecl); + ccx.monomorphized.borrow_mut().insert(hash_id.take_unwrap(), lldecl); lldecl }; @@ -305,21 +310,34 @@ pub fn monomorphic_fn(ccx: &CrateContext, (lldecl, false) } +// Used to identify cached monomorphized functions and vtables +#[deriving(Eq, TotalEq, Hash)] +pub struct MonoParamId { + pub subst: ty::t, + // Do we really need the vtables to be hashed? Isn't the type enough? + pub vtables: Vec<MonoId> +} + +#[deriving(Eq, TotalEq, Hash)] +pub struct MonoId { + pub def: ast::DefId, + pub params: Vec<MonoParamId> +} + pub fn make_vtable_id(ccx: &CrateContext, origin: &typeck::vtable_origin) - -> mono_id { + -> MonoId { match origin { &typeck::vtable_static(impl_id, ref substs, ref sub_vtables) => { - let param_ids = sub_vtables.iter().zip(substs.iter()).map(|(vtable, subst)| { - MonoParamId { - subst: *subst, - vtables: vtable.iter().map(|vt| make_vtable_id(ccx, vt)).collect() - } - }).collect(); - - @mono_id_ { + MonoId { def: impl_id, - params: param_ids + params: sub_vtables.iter().zip(substs.iter()).map(|(vtable, subst)| { + MonoParamId { + subst: *subst, + // Do we really need the vtables to be hashed? Isn't the type enough? + vtables: vtable.iter().map(|vt| make_vtable_id(ccx, vt)).collect() + } + }).collect() } } |
