Skip to content

Commit

Permalink
Make trans ignore last use
Browse files Browse the repository at this point in the history
  • Loading branch information
catamorphism committed Oct 13, 2012
1 parent c4155f5 commit c6780fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
5 changes: 2 additions & 3 deletions src/rustc/middle/trans/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ fn store_environment(bcx: block,
fn build_closure(bcx0: block,
cap_vars: ~[capture::capture_var],
ck: ty::closure_kind,
id: ast::node_id,
include_ret_handle: Option<ValueRef>) -> closure_result {
let _icx = bcx0.insn_ctxt("closure::build_closure");
// If we need to, package up the iterator body to call
Expand All @@ -255,7 +254,7 @@ fn build_closure(bcx0: block,
let mut env_vals = ~[];
for vec::each(cap_vars) |cap_var| {
debug!("Building closure: captured variable %?", *cap_var);
let datum = expr::trans_local_var(bcx, id, cap_var.def);
let datum = expr::trans_local_var(bcx, cap_var.def);
match cap_var.mode {
capture::cap_ref => {
assert ck == ty::ck_block;
Expand Down Expand Up @@ -370,7 +369,7 @@ fn trans_expr_fn(bcx: block,
let cap_vars = capture::compute_capture_vars(ccx.tcx, id, proto,
cap_clause);
let ret_handle = match is_loop_body { Some(x) => x, None => None };
let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, ck, id,
let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, ck,
ret_handle);
trans_closure(ccx, sub_path, decl, body, llfn, no_self,
bcx.fcx.param_substs, id, |fcx| {
Expand Down
21 changes: 7 additions & 14 deletions src/rustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,13 +748,13 @@ fn trans_def_lvalue(bcx: block, ref_expr: @ast::expr,
_ => {
DatumBlock {
bcx: bcx,
datum: trans_local_var(bcx, ref_expr.id, def)
datum: trans_local_var(bcx, def)
}
}
}
}

fn trans_local_var(bcx: block, ref_id: ast::node_id, def: ast::def) -> Datum {
fn trans_local_var(bcx: block, def: ast::def) -> Datum {
let _icx = bcx.insn_ctxt("trans_local_var");

return match def {
Expand All @@ -776,10 +776,10 @@ fn trans_local_var(bcx: block, ref_id: ast::node_id, def: ast::def) -> Datum {
}
}
ast::def_arg(nid, _) => {
take_local(bcx, ref_id, bcx.fcx.llargs, nid)
take_local(bcx, bcx.fcx.llargs, nid)
}
ast::def_local(nid, _) | ast::def_binding(nid, _) => {
take_local(bcx, ref_id, bcx.fcx.lllocals, nid)
take_local(bcx, bcx.fcx.lllocals, nid)
}
ast::def_self(nid) => {
let self_info: ValSelfData = match bcx.fcx.llself {
Expand Down Expand Up @@ -809,15 +809,8 @@ fn trans_local_var(bcx: block, ref_id: ast::node_id, def: ast::def) -> Datum {
};

fn take_local(bcx: block,
ref_id: ast::node_id,
table: HashMap<ast::node_id, local_val>,
nid: ast::node_id) -> Datum {
let is_last_use = match bcx.ccx().maps.last_use_map.find(ref_id) {
None => false,
Some(vars) => (*vars).contains(&nid)
};

let source = if is_last_use {FromLastUseLvalue} else {FromLvalue};

let (v, mode) = match table.find(nid) {
Some(local_mem(v)) => (v, ByRef),
Expand All @@ -829,10 +822,10 @@ fn trans_local_var(bcx: block, ref_id: ast::node_id, def: ast::def) -> Datum {
};
let ty = node_id_type(bcx, nid);

debug!("take_local(nid=%?, last_use=%b, v=%s, mode=%?, ty=%s)",
nid, is_last_use, bcx.val_str(v), mode, bcx.ty_to_str(ty));
debug!("take_local(nid=%?, v=%s, mode=%?, ty=%s)",
nid, bcx.val_str(v), mode, bcx.ty_to_str(ty));

Datum { val: v, ty: ty, mode: mode, source: source }
Datum { val: v, ty: ty, mode: mode, source: FromLvalue }
}
}

Expand Down

0 comments on commit c6780fb

Please sign in to comment.