Navigation Menu

Skip to content

Commit

Permalink
rustc: remove obsolete monomorphization modes.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Apr 22, 2014
1 parent 811bbfc commit c709c1e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 60 deletions.
14 changes: 13 additions & 1 deletion src/librustc/middle/trans/adt.rs
Expand Up @@ -267,7 +267,19 @@ impl Case {
mk_struct(cx, self.tys.as_slice(), false).size == 0
}
fn find_ptr(&self) -> Option<uint> {
self.tys.iter().position(|&ty| mono_data_classify(ty) == MonoNonNull)
self.tys.iter().position(|&ty| {
match ty::get(ty).sty {
ty::ty_rptr(_, mt) => match ty::get(mt.ty).sty {
ty::ty_vec(_, None) => false,
_ => true,
},
ty::ty_uniq(..) | ty::ty_box(..) |
ty::ty_str(ty::VstoreUniq) |
ty::ty_bare_fn(..) => true,
// Is that everything? Would closures or slices qualify?
_ => false
}
})
}
}

Expand Down
39 changes: 5 additions & 34 deletions src/librustc/middle/trans/common.rs
Expand Up @@ -688,45 +688,16 @@ pub fn is_null(val: ValueRef) -> bool {

// Used to identify cached monomorphized functions and vtables
#[deriving(Eq, TotalEq, Hash)]
pub enum mono_param_id {
mono_precise(ty::t, Option<@Vec<mono_id> >),
mono_any,
mono_repr(uint /* size */,
uint /* align */,
MonoDataClass,
datum::RvalueMode),
}

#[deriving(Eq, TotalEq, Hash)]
pub enum MonoDataClass {
MonoBits, // Anything not treated differently from arbitrary integer data
MonoNonNull, // Non-null pointers (used for optional-pointer optimization)
// FIXME(#3547)---scalars and floats are
// treated differently in most ABIs. But we
// should be doing something more detailed
// here.
MonoFloat
}

pub fn mono_data_classify(t: ty::t) -> MonoDataClass {
match ty::get(t).sty {
ty::ty_float(_) => MonoFloat,
ty::ty_rptr(_, mt) => match ty::get(mt.ty).sty {
ty::ty_vec(_, None) => MonoBits,
_ => MonoNonNull,
},
ty::ty_uniq(..) | ty::ty_box(..) |
ty::ty_str(ty::VstoreUniq) |
ty::ty_bare_fn(..) => MonoNonNull,
// Is that everything? Would closures or slices qualify?
_ => MonoBits
}
pub struct MonoParamId {
pub subst: ty::t,
pub vtables: Vec<mono_id>
}

#[deriving(Eq, TotalEq, Hash)]
pub struct mono_id_ {
pub def: ast::DefId,
pub params: Vec<mono_param_id> }
pub params: Vec<MonoParamId>
}

pub type mono_id = @mono_id_;

Expand Down
44 changes: 19 additions & 25 deletions src/librustc/middle/trans/monomorphize.rs
Expand Up @@ -49,7 +49,6 @@ pub fn monomorphic_fn(ccx: &CrateContext,

assert!(real_substs.tps.iter().all(|t| !ty::type_needs_infer(*t)));
let _icx = push_ctxt("monomorphic_fn");
let mut must_cast = false;

let psubsts = @param_substs {
tys: real_substs.tps.clone(),
Expand All @@ -62,10 +61,6 @@ pub fn monomorphic_fn(ccx: &CrateContext,
for s in psubsts.tys.iter() { assert!(!ty::type_has_params(*s)); }

let hash_id = make_mono_id(ccx, fn_id, &*psubsts);
if hash_id.params.iter().any(
|p| match *p { mono_precise(_, _) => false, _ => true }) {
must_cast = true;
}

debug!("monomorphic_fn(\
fn_id={}, \
Expand All @@ -79,7 +74,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
Some(&val) => {
debug!("leaving monomorphic fn {}",
ty::item_path_str(ccx.tcx(), fn_id));
return (val, must_cast);
return (val, false);
}
None => ()
}
Expand Down Expand Up @@ -286,32 +281,31 @@ pub fn monomorphic_fn(ccx: &CrateContext,
ccx.monomorphizing.borrow_mut().insert(fn_id, depth);

debug!("leaving monomorphic fn {}", ty::item_path_str(ccx.tcx(), fn_id));
(lldecl, must_cast)
(lldecl, false)
}

pub fn make_mono_id(ccx: &CrateContext,
item: ast::DefId,
substs: &param_substs) -> mono_id {
// FIXME (possibly #5801): Need a lot of type hints to get
// .collect() to work.
let substs_iter = substs.self_ty.iter().chain(substs.tys.iter());
let precise_param_ids: Vec<(ty::t, Option<@Vec<mono_id> >)> = match substs.vtables {
Some(ref vts) => {
debug!("make_mono_id vtables={} substs={}",
vts.repr(ccx.tcx()), substs.tys.repr(ccx.tcx()));
let vts_iter = substs.self_vtables.iter().chain(vts.iter());
vts_iter.zip(substs_iter).map(|(vtable, subst)| {
let v = vtable.iter().map(|vt| meth::vtable_id(ccx, vt)).collect::<Vec<_>>();
(*subst, if !v.is_empty() { Some(@v) } else { None })
let param_ids: Vec<MonoParamId> = match substs.vtables {
Some(ref vts) => {
debug!("make_mono_id vtables={} substs={}",
vts.repr(ccx.tcx()), substs.tys.repr(ccx.tcx()));
let vts_iter = substs.self_vtables.iter().chain(vts.iter());
vts_iter.zip(substs_iter).map(|(vtable, subst)| MonoParamId {
subst: *subst,
vtables: vtable.iter().map(|vt| meth::vtable_id(ccx, vt)).collect()
}).collect()
}
None => substs_iter.map(|subst| MonoParamId {
subst: *subst,
vtables: Vec::new()
}).collect()
}
None => substs_iter.map(|subst| (*subst, None::<@Vec<mono_id> >)).collect()
};


let param_ids = precise_param_ids.iter().map(|x| {
let (a, b) = *x;
mono_precise(a, b)
}).collect();
@mono_id_ {def: item, params: param_ids}
@mono_id_ {
def: item,
params: param_ids
}
}

0 comments on commit c709c1e

Please sign in to comment.