Introduce some sanity checking assertions in trans, erase regions more aggressively.

This commit is contained in:
Niko Matsakis 2014-11-15 16:50:34 -05:00
parent 4ab0c588ff
commit 0b90cded14
11 changed files with 42 additions and 21 deletions

View File

@ -5824,7 +5824,8 @@ pub fn erase_late_bound_regions<HR>(
{ {
/*! /*!
* Replace any late-bound regions bound in `value` with `'static`. * Replace any late-bound regions bound in `value` with `'static`.
* Useful in trans. * Useful in trans but also method lookup and a few other places
* where precise region relationships are not required.
*/ */
replace_late_bound_regions(tcx, value, |_, _| ty::ReStatic).0 replace_late_bound_regions(tcx, value, |_, _| ty::ReStatic).0

View File

@ -519,8 +519,9 @@ pub fn get_res_dtor(ccx: &CrateContext,
let name = csearch::get_symbol(&ccx.sess().cstore, did); let name = csearch::get_symbol(&ccx.sess().cstore, did);
let class_ty = ty::lookup_item_type(tcx, parent_id).ty.subst(tcx, substs); let class_ty = ty::lookup_item_type(tcx, parent_id).ty.subst(tcx, substs);
let llty = type_of_dtor(ccx, class_ty); let llty = type_of_dtor(ccx, class_ty);
let dtor_ty = ty::mk_ctor_fn(ccx.tcx(), ast::DUMMY_NODE_ID, let dtor_ty = ty::mk_ctor_fn(ccx.tcx(),
&[glue::get_drop_glue_type(ccx, t)], ty::mk_nil(ccx.tcx())); &[glue::get_drop_glue_type(ccx, t)],
ty::mk_nil(ccx.tcx()));
get_extern_fn(ccx, get_extern_fn(ccx,
&mut *ccx.externs().borrow_mut(), &mut *ccx.externs().borrow_mut(),
name.as_slice(), name.as_slice(),

View File

@ -432,6 +432,8 @@ pub fn trans_fn_ref_with_substs(
substs.repr(tcx)); substs.repr(tcx));
assert!(substs.types.all(|t| !ty::type_needs_infer(*t))); assert!(substs.types.all(|t| !ty::type_needs_infer(*t)));
assert!(substs.types.all(|t| !ty::type_has_escaping_regions(*t)));
let substs = substs.erase_regions();
// Load the info for the appropriate trait if necessary. // Load the info for the appropriate trait if necessary.
match ty::trait_of_item(tcx, def_id) { match ty::trait_of_item(tcx, def_id) {
@ -470,8 +472,9 @@ pub fn trans_fn_ref_with_substs(
default methods"); default methods");
// Compute the first substitution // Compute the first substitution
let first_subst = make_substs_for_receiver_types( let first_subst =
tcx, &*trait_ref, &*method); make_substs_for_receiver_types(tcx, &*trait_ref, &*method)
.erase_regions();
// And compose them // And compose them
let new_substs = first_subst.subst(tcx, &substs); let new_substs = first_subst.subst(tcx, &substs);
@ -661,7 +664,7 @@ pub fn trans_lang_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
trans_fn_ref_with_substs_to_callee(bcx, trans_fn_ref_with_substs_to_callee(bcx,
did, did,
0, 0,
subst::Substs::empty()) subst::Substs::trans_empty())
}, },
ArgVals(args), ArgVals(args),
dest) dest)

View File

@ -486,7 +486,7 @@ pub fn trans_unboxed_closure<'blk, 'tcx>(
let llfn = get_or_create_declaration_if_unboxed_closure( let llfn = get_or_create_declaration_if_unboxed_closure(
bcx, bcx,
closure_id, closure_id,
&bcx.fcx.param_substs.substs).unwrap(); bcx.fcx.param_substs.substs()).unwrap();
let function_type = (*bcx.tcx().unboxed_closures.borrow())[closure_id] let function_type = (*bcx.tcx().unboxed_closures.borrow())[closure_id]
.closure_type .closure_type

View File

@ -191,10 +191,21 @@ pub type ExternMap = FnvHashMap<String, ValueRef>;
// Here `self_ty` is the real type of the self parameter to this method. It // Here `self_ty` is the real type of the self parameter to this method. It
// will only be set in the case of default methods. // will only be set in the case of default methods.
pub struct param_substs { pub struct param_substs {
pub substs: subst::Substs, substs: subst::Substs,
} }
impl param_substs { impl param_substs {
pub fn new(substs: subst::Substs) -> param_substs {
assert!(substs.types.all(|t| !ty::type_needs_infer(*t)));
assert!(substs.types.all(|t| !ty::type_has_params(*t)));
assert!(substs.types.all(|t| !ty::type_has_escaping_regions(*t)));
param_substs { substs: substs.erase_regions() }
}
pub fn substs(&self) -> &subst::Substs {
&self.substs
}
pub fn empty() -> param_substs { pub fn empty() -> param_substs {
param_substs { param_substs {
substs: subst::Substs::trans_empty(), substs: subst::Substs::trans_empty(),
@ -822,6 +833,8 @@ pub fn fulfill_obligation(ccx: &CrateContext,
None => { } None => { }
} }
debug!("trans fulfill_obligation: trait_ref={}", trait_ref.repr(ccx.tcx()));
ty::populate_implementations_for_trait_if_necessary(tcx, trait_ref.def_id); ty::populate_implementations_for_trait_if_necessary(tcx, trait_ref.def_id);
let infcx = infer::new_infer_ctxt(tcx); let infcx = infer::new_infer_ctxt(tcx);

View File

@ -1410,7 +1410,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
file_metadata: DIFile, file_metadata: DIFile,
name_to_append_suffix_to: &mut String) name_to_append_suffix_to: &mut String)
-> DIArray { -> DIArray {
let self_type = param_substs.substs.self_ty(); let self_type = param_substs.substs().self_ty();
// Only true for static default methods: // Only true for static default methods:
let has_self_type = self_type.is_some(); let has_self_type = self_type.is_some();
@ -1467,7 +1467,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
} }
// Handle other generic parameters // Handle other generic parameters
let actual_types = param_substs.substs.types.get_slice(subst::FnSpace); let actual_types = param_substs.substs().types.get_slice(subst::FnSpace);
for (index, &ast::TyParam{ ident, .. }) in generics.ty_params.iter().enumerate() { for (index, &ast::TyParam{ ident, .. }) in generics.ty_params.iter().enumerate() {
let actual_type = actual_types[index]; let actual_type = actual_types[index];
// Add actual type name to <...> clause of function name // Add actual type name to <...> clause of function name

View File

@ -329,12 +329,12 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
bcx.ty_to_string(unsized_ty)).as_slice()) bcx.ty_to_string(unsized_ty)).as_slice())
}, },
&ty::UnsizeVtable(ty::TyTrait { ref principal, .. }, _) => { &ty::UnsizeVtable(ty::TyTrait { ref principal, .. }, _) => {
let substs = principal.substs.with_self_ty(unsized_ty); let substs = principal.substs.with_self_ty(unsized_ty).erase_regions();
let trait_ref = let trait_ref =
Rc::new(ty::TraitRef { def_id: principal.def_id, Rc::new(ty::TraitRef { def_id: principal.def_id,
substs: substs }); substs: substs });
let trait_ref = let trait_ref =
trait_ref.subst(bcx.tcx(), &bcx.fcx.param_substs.substs); trait_ref.subst(bcx.tcx(), bcx.fcx.param_substs.substs());
let box_ty = mk_ty(unsized_ty); let box_ty = mk_ty(unsized_ty);
PointerCast(bcx, PointerCast(bcx,
meth::get_vtable(bcx, box_ty, trait_ref), meth::get_vtable(bcx, box_ty, trait_ref),
@ -1122,7 +1122,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
.map(|t| (*t).clone()) .map(|t| (*t).clone())
.unwrap(); .unwrap();
let trait_ref = let trait_ref =
trait_ref.subst(bcx.tcx(), &bcx.fcx.param_substs.substs); trait_ref.subst(bcx.tcx(), bcx.fcx.param_substs.substs());
let datum = unpack_datum!(bcx, trans(bcx, &**val)); let datum = unpack_datum!(bcx, trans(bcx, &**val));
meth::trans_trait_cast(bcx, datum, expr.id, meth::trans_trait_cast(bcx, datum, expr.id,
trait_ref, dest) trait_ref, dest)

View File

@ -536,7 +536,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
let _icx = push_ctxt("foreign::build_foreign_fn"); let _icx = push_ctxt("foreign::build_foreign_fn");
let fnty = ty::node_id_to_type(ccx.tcx(), id); let fnty = ty::node_id_to_type(ccx.tcx(), id);
let mty = fnty.subst(ccx.tcx(), &param_substs.substs); let mty = fnty.subst(ccx.tcx(), param_substs.substs());
let tys = foreign_types_for_fn_ty(ccx, mty); let tys = foreign_types_for_fn_ty(ccx, mty);
unsafe { // unsafe because we call LLVM operations unsafe { // unsafe because we call LLVM operations
@ -558,7 +558,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
let _icx = push_ctxt("foreign::foreign::build_rust_fn"); let _icx = push_ctxt("foreign::foreign::build_rust_fn");
let tcx = ccx.tcx(); let tcx = ccx.tcx();
let t = ty::node_id_to_type(tcx, id).subst( let t = ty::node_id_to_type(tcx, id).subst(
ccx.tcx(), &param_substs.substs); ccx.tcx(), param_substs.substs());
let ps = ccx.tcx().map.with_path(id, |path| { let ps = ccx.tcx().map.with_path(id, |path| {
let abi = Some(ast_map::PathName(special_idents::clownshoe_abi.name)); let abi = Some(ast_map::PathName(special_idents::clownshoe_abi.name));

View File

@ -287,8 +287,9 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
val, *ty); val, *ty);
} }
let dtor_ty = ty::mk_ctor_fn(variant_cx.tcx(), ast::DUMMY_NODE_ID, let dtor_ty = ty::mk_ctor_fn(bcx.tcx(),
&[get_drop_glue_type(bcx.ccx(), t)], ty::mk_nil(bcx.tcx())); &[get_drop_glue_type(bcx.ccx(), t)],
ty::mk_nil(bcx.tcx()));
let (_, variant_cx) = invoke(variant_cx, dtor_addr, args, dtor_ty, None, false); let (_, variant_cx) = invoke(variant_cx, dtor_addr, args, dtor_ty, None, false);
variant_cx.fcx.pop_and_trans_custom_cleanup_scope(variant_cx, field_scope); variant_cx.fcx.pop_and_trans_custom_cleanup_scope(variant_cx, field_scope);

View File

@ -137,8 +137,11 @@ pub fn trans_method_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
}) => { }) => {
let trait_ref = let trait_ref =
Rc::new(trait_ref.subst(bcx.tcx(), Rc::new(trait_ref.subst(bcx.tcx(),
&bcx.fcx.param_substs.substs)); bcx.fcx.param_substs.substs()));
let span = bcx.tcx().map.span(method_call.expr_id); let span = bcx.tcx().map.span(method_call.expr_id);
debug!("method_call={} trait_ref={}",
method_call,
trait_ref.repr(bcx.tcx()));
let origin = fulfill_obligation(bcx.ccx(), let origin = fulfill_obligation(bcx.ccx(),
span, span,
(*trait_ref).clone()); (*trait_ref).clone());

View File

@ -63,9 +63,8 @@ pub fn monomorphic_fn(ccx: &CrateContext,
None => () None => ()
} }
let psubsts = param_substs { debug!("creating param_substs with real_substs={}", real_substs.repr(ccx.tcx()));
substs: (*real_substs).clone(), let psubsts = param_substs::new((*real_substs).clone());
};
debug!("monomorphic_fn(\ debug!("monomorphic_fn(\
fn_id={}, \ fn_id={}, \