Skip to content

Check lifetime parameters when resolving impls; use ty::substs in trans #14055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/metadata/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub enum astencode_tag { // Reserves 0x40 -- 0x5f
tag_table_val = 0x45,
tag_table_def = 0x46,
tag_table_node_type = 0x47,
tag_table_node_type_subst = 0x48,
tag_table_item_subst = 0x48,
tag_table_freevars = 0x49,
tag_table_tcache = 0x4a,
tag_table_param_defs = 0x4b,
Expand Down
39 changes: 30 additions & 9 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,13 +657,13 @@ pub fn encode_vtable_origin(ecx: &e::EncodeContext,
vtable_origin: &typeck::vtable_origin) {
ebml_w.emit_enum("vtable_origin", |ebml_w| {
match *vtable_origin {
typeck::vtable_static(def_id, ref tys, ref vtable_res) => {
typeck::vtable_static(def_id, ref substs, ref vtable_res) => {
ebml_w.emit_enum_variant("vtable_static", 0u, 3u, |ebml_w| {
ebml_w.emit_enum_variant_arg(0u, |ebml_w| {
Ok(ebml_w.emit_def_id(def_id))
});
ebml_w.emit_enum_variant_arg(1u, |ebml_w| {
Ok(ebml_w.emit_tys(ecx, tys.as_slice()))
Ok(ebml_w.emit_substs(ecx, substs))
});
ebml_w.emit_enum_variant_arg(2u, |ebml_w| {
Ok(encode_vtable_res(ecx, ebml_w, vtable_res))
Expand Down Expand Up @@ -744,7 +744,7 @@ impl<'a> vtable_decoder_helpers for reader::Decoder<'a> {
Ok(this.read_def_id_noxcx(cdata))
}).unwrap(),
this.read_enum_variant_arg(1u, |this| {
Ok(this.read_tys_noxcx(tcx, cdata))
Ok(this.read_substs_noxcx(tcx, cdata))
}).unwrap(),
this.read_enum_variant_arg(2u, |this| {
Ok(this.read_vtable_res(tcx, cdata))
Expand Down Expand Up @@ -962,11 +962,11 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
})
}

for tys in tcx.node_type_substs.borrow().find(&id).iter() {
ebml_w.tag(c::tag_table_node_type_subst, |ebml_w| {
for &item_substs in tcx.item_substs.borrow().find(&id).iter() {
ebml_w.tag(c::tag_table_item_subst, |ebml_w| {
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.emit_tys(ecx, tys.as_slice())
ebml_w.emit_substs(ecx, &item_substs.substs);
})
})
}
Expand Down Expand Up @@ -1091,6 +1091,9 @@ trait ebml_decoder_decoder_helpers {
fn read_tys_noxcx(&mut self,
tcx: &ty::ctxt,
cdata: &cstore::crate_metadata) -> Vec<ty::t>;
fn read_substs_noxcx(&mut self, tcx: &ty::ctxt,
cdata: &cstore::crate_metadata)
-> ty::substs;
}

impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
Expand All @@ -1115,6 +1118,21 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
.collect()
}

fn read_substs_noxcx(&mut self,
tcx: &ty::ctxt,
cdata: &cstore::crate_metadata)
-> ty::substs
{
self.read_opaque(|_, doc| {
Ok(tydecode::parse_substs_data(
doc.data,
cdata.cnum,
doc.start,
tcx,
|_, id| decoder::translate_def_id(cdata, id)))
}).unwrap()
}

fn read_ty(&mut self, xcx: &ExtendedDecodeContext) -> ty::t {
// Note: regions types embed local node ids. In principle, we
// should translate these node ids into the new decode
Expand Down Expand Up @@ -1312,9 +1330,12 @@ fn decode_side_tables(xcx: &ExtendedDecodeContext,
id, ty_to_str(dcx.tcx, ty));
dcx.tcx.node_types.borrow_mut().insert(id as uint, ty);
}
c::tag_table_node_type_subst => {
let tys = val_dsr.read_tys(xcx);
dcx.tcx.node_type_substs.borrow_mut().insert(id, tys);
c::tag_table_item_subst => {
let item_substs = ty::ItemSubsts {
substs: val_dsr.read_substs(xcx)
};
dcx.tcx.item_substs.borrow_mut().insert(
id, item_substs);
}
c::tag_table_freevars => {
let fv_info = val_dsr.read_to_vec(|val_dsr| {
Expand Down
26 changes: 15 additions & 11 deletions src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ pub fn check_expr(cx: &mut Context, e: &Expr) {
{
let method_map = cx.tcx.method_map.borrow();
let method = method_map.find(&typeck::MethodCall::expr(e.id));
let node_type_substs = cx.tcx.node_type_substs.borrow();
let item_substs = cx.tcx.item_substs.borrow();
let r = match method {
Some(method) => Some(&method.substs.tps),
None => node_type_substs.find(&e.id)
None => item_substs.find(&e.id).map(|s| &s.substs.tps)
};
for ts in r.iter() {
let def_map = cx.tcx.def_map.borrow();
Expand Down Expand Up @@ -341,15 +341,19 @@ fn check_trait_cast(cx: &mut Context, source_ty: ty::t, target_ty: ty::t, span:
fn check_ty(cx: &mut Context, aty: &Ty) {
match aty.node {
TyPath(_, _, id) => {
let node_type_substs = cx.tcx.node_type_substs.borrow();
let r = node_type_substs.find(&id);
for ts in r.iter() {
let def_map = cx.tcx.def_map.borrow();
let did = ast_util::def_id_of_def(def_map.get_copy(&id));
let generics = ty::lookup_item_type(cx.tcx, did).generics;
let type_param_defs = generics.type_param_defs();
for (&ty, type_param_def) in ts.iter().zip(type_param_defs.iter()) {
check_typaram_bounds(cx, aty.span, ty, type_param_def)
match cx.tcx.item_substs.borrow().find(&id) {
None => { }
Some(ref item_substs) => {
let def_map = cx.tcx.def_map.borrow();
let did = ast_util::def_id_of_def(def_map.get_copy(&id));
let generics = ty::lookup_item_type(cx.tcx, did).generics;
let type_param_defs = generics.type_param_defs();
for (&ty, type_param_def) in
item_substs.substs.tps.iter().zip(
type_param_defs.iter())
{
check_typaram_bounds(cx, aty.span, ty, type_param_def)
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/librustc/middle/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ impl Subst for ty::substs {
}
}

impl Subst for ty::ItemSubsts {
fn subst_spanned(&self, tcx: &ty::ctxt,
substs: &ty::substs,
span: Option<Span>)
-> ty::ItemSubsts {
ty::ItemSubsts {
substs: self.substs.subst_spanned(tcx, substs, span)
}
}
}

impl Subst for ty::RegionSubsts {
fn subst_spanned(&self, tcx: &ty::ctxt,
substs: &ty::substs,
Expand Down
62 changes: 15 additions & 47 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,35 +478,29 @@ pub fn note_unique_llvm_symbol(ccx: &CrateContext, sym: ~str) {
pub fn get_res_dtor(ccx: &CrateContext,
did: ast::DefId,
parent_id: ast::DefId,
substs: &[ty::t])
substs: &ty::substs)
-> ValueRef {
let _icx = push_ctxt("trans_res_dtor");
let did = if did.krate != ast::LOCAL_CRATE {
inline::maybe_instantiate_inline(ccx, did)
} else {
did
};
if !substs.is_empty() {

if !substs.tps.is_empty() || !substs.self_ty.is_none() {
assert_eq!(did.krate, ast::LOCAL_CRATE);
let tsubsts = ty::substs {
regions: ty::ErasedRegions,
self_ty: None,
tps: Vec::from_slice(substs),
};

let vtables = typeck::check::vtable::trans_resolve_method(ccx.tcx(), did.node, &tsubsts);
let (val, _) = monomorphize::monomorphic_fn(ccx, did, &tsubsts, vtables, None, None);
let vtables = typeck::check::vtable::trans_resolve_method(ccx.tcx(), did.node, substs);
let (val, _) = monomorphize::monomorphic_fn(ccx, did, substs, vtables, None, None);

val
} else if did.krate == ast::LOCAL_CRATE {
get_item_val(ccx, did.node)
} else {
let tcx = ccx.tcx();
let name = csearch::get_symbol(&ccx.sess().cstore, did);
let class_ty = ty::subst_tps(tcx,
substs,
None,
ty::lookup_item_type(tcx, parent_id).ty);
let class_ty = ty::subst(tcx, substs,
ty::lookup_item_type(tcx, parent_id).ty);
let llty = type_of_dtor(ccx, class_ty);

get_extern_fn(&mut *ccx.externs.borrow_mut(), ccx.llmod, name,
Expand Down Expand Up @@ -670,7 +664,7 @@ pub fn iter_structural_ty<'r,
repr: &adt::Repr,
av: ValueRef,
variant: &ty::VariantInfo,
tps: &[ty::t],
substs: &ty::substs,
f: val_and_ty_fn<'r,'b>)
-> &'b Block<'b> {
let _icx = push_ctxt("iter_variant");
Expand All @@ -680,7 +674,7 @@ pub fn iter_structural_ty<'r,
for (i, &arg) in variant.args.iter().enumerate() {
cx = f(cx,
adt::trans_field_ptr(cx, repr, av, variant.disr_val, i),
ty::subst_tps(tcx, tps, None, arg));
ty::subst(tcx, substs, arg));
}
return cx;
}
Expand Down Expand Up @@ -722,7 +716,7 @@ pub fn iter_structural_ty<'r,
match adt::trans_switch(cx, &*repr, av) {
(_match::single, None) => {
cx = iter_variant(cx, &*repr, av, &**variants.get(0),
substs.tps.as_slice(), f);
substs, f);
}
(_match::switch, Some(lldiscrim_a)) => {
cx = f(cx, lldiscrim_a, ty::mk_int());
Expand All @@ -748,7 +742,7 @@ pub fn iter_structural_ty<'r,
&*repr,
av,
&**variant,
substs.tps.as_slice(),
substs,
|x,y,z| f(x,y,z));
Br(variant_cx, next_cx.llbb);
}
Expand Down Expand Up @@ -1153,15 +1147,7 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
},
id, param_substs.map(|s| s.repr(ccx.tcx())));

let substd_output_type = match param_substs {
None => output_type,
Some(substs) => {
ty::subst_tps(ccx.tcx(),
substs.tys.as_slice(),
substs.self_ty,
output_type)
}
};
let substd_output_type = output_type.substp(ccx.tcx(), param_substs);
let uses_outptr = type_of::return_uses_outptr(ccx, substd_output_type);
let debug_context = debuginfo::create_function_debug_context(ccx, id, param_substs, llfndecl);

Expand Down Expand Up @@ -1213,15 +1199,7 @@ pub fn init_function<'a>(fcx: &'a FunctionContext<'a>,

// This shouldn't need to recompute the return type,
// as new_fn_ctxt did it already.
let substd_output_type = match fcx.param_substs {
None => output_type,
Some(substs) => {
ty::subst_tps(fcx.ccx.tcx(),
substs.tys.as_slice(),
substs.self_ty,
output_type)
}
};
let substd_output_type = output_type.substp(fcx.ccx.tcx(), fcx.param_substs);

if !return_type_is_void(fcx.ccx, substd_output_type) {
// If the function returns nil/bot, there is no real return
Expand Down Expand Up @@ -1508,18 +1486,8 @@ fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext,
disr: ty::Disr,
param_substs: Option<&param_substs>,
llfndecl: ValueRef) {
let ctor_ty = {
let no_substs: &[ty::t] = [];
let ty_param_substs: &[ty::t] = match param_substs {
Some(substs) => substs.tys.as_slice(),
None => no_substs
};

ty::subst_tps(ccx.tcx(),
ty_param_substs,
None,
ty::node_id_to_type(ccx.tcx(), ctor_id))
};
let ctor_ty = ty::node_id_to_type(ccx.tcx(), ctor_id);
let ctor_ty = ctor_ty.substp(ccx.tcx(), param_substs);

let result_ty = match ty::get(ctor_ty).sty {
ty::ty_bare_fn(ref bft) => bft.sig.output,
Expand Down
Loading