Skip to content

Commit 7b3d6af

Browse files
committed
rustc: de-@ mono_id.
1 parent 5fa7be6 commit 7b3d6af

File tree

3 files changed

+37
-34
lines changed

3 files changed

+37
-34
lines changed

src/librustc/middle/trans/common.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -686,22 +686,6 @@ pub fn is_null(val: ValueRef) -> bool {
686686
}
687687
}
688688

689-
// Used to identify cached monomorphized functions and vtables
690-
#[deriving(Eq, TotalEq, Hash)]
691-
pub struct MonoParamId {
692-
pub subst: ty::t,
693-
// Do we really need the vtables to be hashed? Isn't the type enough?
694-
pub vtables: Vec<mono_id>
695-
}
696-
697-
#[deriving(Eq, TotalEq, Hash)]
698-
pub struct mono_id_ {
699-
pub def: ast::DefId,
700-
pub params: Vec<MonoParamId>
701-
}
702-
703-
pub type mono_id = @mono_id_;
704-
705689
pub fn monomorphize_type(bcx: &Block, t: ty::t) -> ty::t {
706690
match bcx.fcx.param_substs {
707691
Some(substs) => {

src/librustc/middle/trans/context.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ use middle::resolve;
2020
use middle::trans::adt;
2121
use middle::trans::base;
2222
use middle::trans::builder::Builder;
23-
use middle::trans::common::{mono_id,ExternMap,tydesc_info,BuilderRef_res,Stats};
23+
use middle::trans::common::{ExternMap,tydesc_info,BuilderRef_res,Stats};
2424
use middle::trans::debuginfo;
25+
use middle::trans::monomorphize::MonoId;
2526
use middle::trans::type_::Type;
2627
use middle::ty;
2728
use util::sha2::Sha256;
@@ -61,10 +62,10 @@ pub struct CrateContext {
6162
/// that is generated
6263
pub non_inlineable_statics: RefCell<NodeSet>,
6364
/// Cache instances of monomorphized functions
64-
pub monomorphized: RefCell<HashMap<mono_id, ValueRef>>,
65+
pub monomorphized: RefCell<HashMap<MonoId, ValueRef>>,
6566
pub monomorphizing: RefCell<DefIdMap<uint>>,
6667
/// Cache generated vtables
67-
pub vtables: RefCell<HashMap<(ty::t, mono_id), ValueRef>>,
68+
pub vtables: RefCell<HashMap<(ty::t, MonoId), ValueRef>>,
6869
/// Cache of constant strings,
6970
pub const_cstr_cache: RefCell<HashMap<InternedString, ValueRef>>,
7071

src/librustc/middle/trans/monomorphize.rs

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use middle::trans::base::{trans_enum_variant, push_ctxt, get_item_val};
1616
use middle::trans::base::{trans_fn, decl_internal_rust_fn};
1717
use middle::trans::base;
1818
use middle::trans::common::*;
19-
use middle::trans::meth;
2019
use middle::trans::intrinsic;
2120
use middle::ty;
2221
use middle::typeck;
@@ -26,7 +25,7 @@ use syntax::abi;
2625
use syntax::ast;
2726
use syntax::ast_map;
2827
use syntax::ast_util::local_def;
29-
use std::hash::sip;
28+
use std::hash::{sip, Hash};
3029

3130
pub fn monomorphic_fn(ccx: &CrateContext,
3231
fn_id: ast::DefId,
@@ -71,7 +70,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
7170
}).collect()
7271
};
7372

74-
let hash_id = @mono_id_ {
73+
let hash_id = MonoId {
7574
def: fn_id,
7675
params: param_ids
7776
};
@@ -194,16 +193,22 @@ pub fn monomorphic_fn(ccx: &CrateContext,
194193
}
195194

196195
let s = ccx.tcx.map.with_path(fn_id.node, |path| {
197-
exported_name(path, format!("h{}", sip::hash(&(hash_id, mono_ty))),
196+
let mut state = sip::SipState::new();
197+
hash_id.hash(&mut state);
198+
mono_ty.hash(&mut state);
199+
200+
exported_name(path, format!("h{}", state.result()),
198201
ccx.link_meta.crateid.version_or_default())
199202
});
200203
debug!("monomorphize_fn mangled to {}", s);
201204

205+
// This shouldn't need to option dance.
206+
let mut hash_id = Some(hash_id);
202207
let mk_lldecl = || {
203208
let lldecl = decl_internal_rust_fn(ccx, false,
204209
f.sig.inputs.as_slice(),
205210
f.sig.output, s);
206-
ccx.monomorphized.borrow_mut().insert(hash_id, lldecl);
211+
ccx.monomorphized.borrow_mut().insert(hash_id.take_unwrap(), lldecl);
207212
lldecl
208213
};
209214

@@ -305,21 +310,34 @@ pub fn monomorphic_fn(ccx: &CrateContext,
305310
(lldecl, false)
306311
}
307312

313+
// Used to identify cached monomorphized functions and vtables
314+
#[deriving(Eq, TotalEq, Hash)]
315+
pub struct MonoParamId {
316+
pub subst: ty::t,
317+
// Do we really need the vtables to be hashed? Isn't the type enough?
318+
pub vtables: Vec<MonoId>
319+
}
320+
321+
#[deriving(Eq, TotalEq, Hash)]
322+
pub struct MonoId {
323+
pub def: ast::DefId,
324+
pub params: Vec<MonoParamId>
325+
}
326+
308327
pub fn make_vtable_id(ccx: &CrateContext,
309328
origin: &typeck::vtable_origin)
310-
-> mono_id {
329+
-> MonoId {
311330
match origin {
312331
&typeck::vtable_static(impl_id, ref substs, ref sub_vtables) => {
313-
let param_ids = sub_vtables.iter().zip(substs.iter()).map(|(vtable, subst)| {
314-
MonoParamId {
315-
subst: *subst,
316-
vtables: vtable.iter().map(|vt| make_vtable_id(ccx, vt)).collect()
317-
}
318-
}).collect();
319-
320-
@mono_id_ {
332+
MonoId {
321333
def: impl_id,
322-
params: param_ids
334+
params: sub_vtables.iter().zip(substs.iter()).map(|(vtable, subst)| {
335+
MonoParamId {
336+
subst: *subst,
337+
// Do we really need the vtables to be hashed? Isn't the type enough?
338+
vtables: vtable.iter().map(|vt| make_vtable_id(ccx, vt)).collect()
339+
}
340+
}).collect()
323341
}
324342
}
325343

0 commit comments

Comments
 (0)