Skip to content

Commit

Permalink
remove more dead code from the old for
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Aug 12, 2013
1 parent b285f1e commit d99d337
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 102 deletions.
8 changes: 2 additions & 6 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,6 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
llreturn: None,
llself: None,
personality: None,
loop_ret: None,
has_immediate_return_value: is_immediate,
llargs: @mut HashMap::new(),
lllocals: @mut HashMap::new(),
Expand Down Expand Up @@ -1834,8 +1833,7 @@ pub fn trans_closure(ccx: @mut CrateContext,
id: ast::NodeId,
attributes: &[ast::Attribute],
output_type: ty::t,
maybe_load_env: &fn(@mut FunctionContext),
finish: &fn(@mut Block)) {
maybe_load_env: &fn(@mut FunctionContext)) {
ccx.stats.n_closures += 1;
let _icx = push_ctxt("trans_closure");
set_uwtable(llfndecl);
Expand Down Expand Up @@ -1885,7 +1883,6 @@ pub fn trans_closure(ccx: @mut CrateContext,
bcx = controlflow::trans_block(bcx, body, dest);
}

finish(bcx);
match fcx.llreturn {
Some(llreturn) => cleanup_and_Br(bcx, bcx_top, llreturn),
None => bcx = cleanup_block(bcx, Some(bcx_top.llbb))
Expand Down Expand Up @@ -1937,8 +1934,7 @@ pub fn trans_fn(ccx: @mut CrateContext,
&& fcx_has_nonzero_span(fcx) {
debuginfo::create_function_metadata(fcx);
}
},
|_bcx| { });
});
}

fn insert_synthetic_type_entries(bcx: @mut Block,
Expand Down
74 changes: 8 additions & 66 deletions src/librustc/middle/trans/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ use middle::moves;
use middle::trans::base::*;
use middle::trans::build::*;
use middle::trans::common::*;
use middle::trans::datum::{Datum, INIT, ByRef, ZeroMem};
use middle::trans::datum::{Datum, INIT};
use middle::trans::expr;
use middle::trans::glue;
use middle::trans::type_of::*;
use middle::ty;
use util::ppaux::ty_to_str;

use middle::trans::type_::Type;

use std::vec;
use syntax::ast;
use syntax::ast_map::path_name;
Expand Down Expand Up @@ -259,8 +257,7 @@ pub fn store_environment(bcx: @mut Block,
// collects the upvars and packages them up for store_environment.
pub fn build_closure(bcx0: @mut Block,
cap_vars: &[moves::CaptureVar],
sigil: ast::Sigil,
include_ret_handle: Option<ValueRef>) -> ClosureResult {
sigil: ast::Sigil) -> ClosureResult {
let _icx = push_ctxt("closure::build_closure");

// If we need to, package up the iterator body to call
Expand Down Expand Up @@ -288,30 +285,6 @@ pub fn build_closure(bcx0: @mut Block,
}
}

// If this is a `for` loop body, add two special environment
// variables:
for flagptr in include_ret_handle.iter() {
// Flag indicating we have returned (a by-ref bool):
let flag_datum = Datum {val: *flagptr, ty: ty::mk_bool(),
mode: ByRef(ZeroMem)};
env_vals.push(EnvValue {action: EnvRef,
datum: flag_datum});

// Return value (we just pass a by-ref () and cast it later to
// the right thing):
let ret_true = match bcx.fcx.loop_ret {
Some((_, retptr)) => retptr,
None => match bcx.fcx.llretptr {
None => C_null(Type::nil().ptr_to()),
Some(retptr) => PointerCast(bcx, retptr, Type::nil().ptr_to()),
}
};
let ret_datum = Datum {val: ret_true, ty: ty::mk_nil(),
mode: ByRef(ZeroMem)};
env_vals.push(EnvValue {action: EnvRef,
datum: ret_datum});
}

return store_environment(bcx, env_vals, sigil);
}

Expand All @@ -321,12 +294,11 @@ pub fn build_closure(bcx0: @mut Block,
pub fn load_environment(fcx: @mut FunctionContext,
cdata_ty: ty::t,
cap_vars: &[moves::CaptureVar],
load_ret_handle: bool,
sigil: ast::Sigil) {
let _icx = push_ctxt("closure::load_environment");

// Don't bother to create the block if there's nothing to load
if cap_vars.len() == 0 && !load_ret_handle {
if cap_vars.len() == 0 {
return;
}

Expand All @@ -347,12 +319,6 @@ pub fn load_environment(fcx: @mut FunctionContext,
fcx.llupvars.insert(def_id.node, upvarptr);
i += 1u;
}
if load_ret_handle {
let flagptr = Load(bcx, GEPi(bcx, llcdata, [0u, i]));
let retptr = Load(bcx,
GEPi(bcx, llcdata, [0u, i+1u]));
fcx.loop_ret = Some((flagptr, retptr));
}
}

pub fn trans_expr_fn(bcx: @mut Block,
Expand All @@ -361,7 +327,6 @@ pub fn trans_expr_fn(bcx: @mut Block,
body: &ast::Block,
outer_id: ast::NodeId,
user_id: ast::NodeId,
is_loop_body: Option<Option<ValueRef>>,
dest: expr::Dest) -> @mut Block {
/*!
*
Expand All @@ -378,7 +343,6 @@ pub fn trans_expr_fn(bcx: @mut Block,
* - `user_id`: The id of the closure as the user expressed it.
Generally the same as `outer_id`
* - `cap_clause`: information about captured variables, if any.
* - `is_loop_body`: `Some()` if this is part of a `for` loop.
* - `dest`: where to write the closure value, which must be a
(fn ptr, env) pair
*/
Expand All @@ -405,28 +369,14 @@ pub fn trans_expr_fn(bcx: @mut Block,
"expr_fn");
let llfn = decl_internal_cdecl_fn(ccx.llmod, s, llfnty);

// Always mark inline if this is a loop body. This is important for
// performance on many programs with tight loops.
if is_loop_body.is_some() {
set_always_inline(llfn);
} else {
// Can't hurt.
set_inline_hint(llfn);
}

let real_return_type = if is_loop_body.is_some() {
ty::mk_bool()
} else {
ty::ty_fn_ret(fty)
};
// set an inline hint for all closures
set_inline_hint(llfn);

let Result {bcx: bcx, val: closure} = match sigil {
ast::BorrowedSigil | ast::ManagedSigil | ast::OwnedSigil => {
let cap_vars = ccx.maps.capture_map.get_copy(&user_id);
let ret_handle = match is_loop_body {Some(x) => x,
None => None};
let ClosureResult {llbox, cdata_ty, bcx}
= build_closure(bcx, cap_vars, sigil, ret_handle);
= build_closure(bcx, cap_vars, sigil);
trans_closure(ccx,
sub_path,
decl,
Expand All @@ -436,16 +386,8 @@ pub fn trans_expr_fn(bcx: @mut Block,
bcx.fcx.param_substs,
user_id,
[],
real_return_type,
|fcx| load_environment(fcx, cdata_ty, cap_vars,
ret_handle.is_some(), sigil),
|bcx| {
if is_loop_body.is_some() {
Store(bcx,
C_bool(true),
bcx.fcx.llretptr.unwrap());
}
});
ty::ty_fn_ret(fty),
|fcx| load_environment(fcx, cdata_ty, cap_vars, sigil));
rslt(bcx, llbox)
}
};
Expand Down
3 changes: 0 additions & 3 deletions src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ pub struct FunctionContext {
// The a value alloca'd for calls to upcalls.rust_personality. Used when
// outputting the resume instruction.
personality: Option<ValueRef>,
// If this is a for-loop body that returns, this holds the pointers needed
// for that (flagptr, retptr)
loop_ret: Option<(ValueRef, ValueRef)>,

// True if this function has an immediate return value, false otherwise.
// If this is false, the llretptr will alias the first argument of the
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use back::{upcall};
use driver::session;
use lib::llvm::{ContextRef, ModuleRef, ValueRef};
use lib::llvm::{llvm, TargetData, TypeNames};
use lib::llvm::{mk_target_data, False};
use lib::llvm::mk_target_data;
use metadata::common::LinkMeta;
use middle::astencode;
use middle::resolve;
Expand Down
25 changes: 5 additions & 20 deletions src/librustc/middle/trans/controlflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use middle::trans::callee;
use middle::trans::common::*;
use middle::trans::debuginfo;
use middle::trans::expr;
use middle::trans::type_of::*;
use middle::ty;
use util::common::indenter;
use util::ppaux;
Expand Down Expand Up @@ -341,29 +340,15 @@ pub fn trans_cont(bcx: @mut Block, label_opt: Option<ident>) -> @mut Block {
pub fn trans_ret(bcx: @mut Block, e: Option<@ast::expr>) -> @mut Block {
let _icx = push_ctxt("trans_ret");
let mut bcx = bcx;
let dest = match bcx.fcx.loop_ret {
Some((flagptr, retptr)) => {
// This is a loop body return. Must set continue flag (our retptr)
// to false, return flag to true, and then store the value in the
// parent's retptr.
Store(bcx, C_bool(true), flagptr);
Store(bcx, C_bool(false), bcx.fcx.llretptr.unwrap());
expr::SaveIn(match e {
Some(x) => PointerCast(bcx, retptr,
type_of(bcx.ccx(), expr_ty(bcx, x)).ptr_to()),
None => retptr
})
}
None => match bcx.fcx.llretptr {
let dest = match bcx.fcx.llretptr {
None => expr::Ignore,
Some(retptr) => expr::SaveIn(retptr),
}
};
match e {
Some(x) => {
bcx = expr::trans_into(bcx, x, dest);
}
_ => ()
Some(x) => {
bcx = expr::trans_into(bcx, x, dest);
}
_ => ()
}
cleanup_and_leave(bcx, None, Some(bcx.fcx.get_llreturn()));
Unreachable(bcx);
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,7 @@ fn trans_rvalue_dps_unadjusted(bcx: @mut Block, expr: @ast::expr,
expr_to_str(expr, tcx.sess.intr()),
expr_ty.repr(tcx));
return closure::trans_expr_fn(bcx, sigil, decl, body,
expr.id, expr.id,
None, dest);
expr.id, expr.id, dest);
}
ast::expr_do_body(blk) => {
return trans_into(bcx, blk, dest);
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/middle/typeck/check/regionck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
}

ast::expr_fn_block(*) => {
check_expr_fn_block(rcx, expr, v, false);
check_expr_fn_block(rcx, expr, v);
}

ast::expr_loop(ref body, _) => {
Expand All @@ -454,8 +454,7 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {

fn check_expr_fn_block(rcx: @mut Rcx,
expr: @ast::expr,
v: rvt,
is_loop_body: bool) {
v: rvt) {
let tcx = rcx.fcx.tcx();
match expr.node {
ast::expr_fn_block(_, ref body) => {
Expand All @@ -464,7 +463,7 @@ fn check_expr_fn_block(rcx: @mut Rcx,
ty::ty_closure(
ty::ClosureTy {
sigil: ast::BorrowedSigil, region: region, _}) => {
if get_freevars(tcx, expr.id).is_empty() && !is_loop_body {
if get_freevars(tcx, expr.id).is_empty() {
// No free variables means that the environment
// will be NULL at runtime and hence the closure
// has static lifetime.
Expand Down

0 comments on commit d99d337

Please sign in to comment.