Skip to content

Commit

Permalink
trans: use Instance in trans_closure and FunctionContext::new.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Apr 11, 2016
1 parent a563711 commit 35a6e6a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 30 deletions.
34 changes: 16 additions & 18 deletions src/librustc_trans/base.rs
Expand Up @@ -1400,20 +1400,23 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
pub fn new(ccx: &'blk CrateContext<'blk, 'tcx>,
llfndecl: ValueRef,
fn_ty: FnType,
def_id: Option<DefId>,
param_substs: &'tcx Substs<'tcx>,
instance: Option<Instance<'tcx>>,
block_arena: &'blk TypedArena<common::BlockS<'blk, 'tcx>>)
-> FunctionContext<'blk, 'tcx> {
common::validate_substs(param_substs);
let (param_substs, def_id) = match instance {
Some(instance) => {
common::validate_substs(instance.substs);
(instance.substs, Some(instance.def))
}
None => (ccx.tcx().mk_substs(Substs::empty()), None)
};

let inlined_did = def_id.and_then(|def_id| inline::get_local_instance(ccx, def_id));
let inlined_id = inlined_did.and_then(|id| ccx.tcx().map.as_local_node_id(id));
let local_id = def_id.and_then(|id| ccx.tcx().map.as_local_node_id(id));

debug!("FunctionContext::new(path={}, def_id={:?}, param_substs={:?})",
inlined_id.map_or(String::new(), |id| ccx.tcx().node_path_str(id)),
def_id,
param_substs);
debug!("FunctionContext::new({})",
instance.map_or(String::new(), |i| i.to_string()));

let debug_context = debuginfo::create_function_debug_context(ccx,
inlined_id.unwrap_or(ast::DUMMY_NODE_ID), param_substs, llfndecl);
Expand Down Expand Up @@ -1810,27 +1813,25 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
decl: &hir::FnDecl,
body: &hir::Block,
llfndecl: ValueRef,
param_substs: &'tcx Substs<'tcx>,
def_id: DefId,
instance: Instance<'tcx>,
inlined_id: ast::NodeId,
fn_ty: FnType,
abi: Abi,
closure_env: closure::ClosureEnv) {
ccx.stats().n_closures.set(ccx.stats().n_closures.get() + 1);

if collector::collecting_debug_information(ccx) {
ccx.record_translation_item_as_generated(
TransItem::Fn(Instance::new(def_id, param_substs)));
ccx.record_translation_item_as_generated(TransItem::Fn(instance));
}

let _icx = push_ctxt("trans_closure");
attributes::emit_uwtable(llfndecl, true);

debug!("trans_closure(..., param_substs={:?})", param_substs);
debug!("trans_closure(..., {})", instance);

let (arena, fcx): (TypedArena<_>, FunctionContext);
arena = TypedArena::new();
fcx = FunctionContext::new(ccx, llfndecl, fn_ty, Some(def_id), param_substs, &arena);
fcx = FunctionContext::new(ccx, llfndecl, fn_ty, Some(instance), &arena);

if fcx.mir.is_some() {
return mir::trans_mir(&fcx);
Expand Down Expand Up @@ -1921,8 +1922,7 @@ pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
decl,
body,
llfndecl,
param_substs,
def_id,
Instance::new(def_id, param_substs),
id,
fn_ty,
abi,
Expand Down Expand Up @@ -2015,9 +2015,7 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,

let (arena, fcx): (TypedArena<_>, FunctionContext);
arena = TypedArena::new();
fcx = FunctionContext::new(ccx, llfndecl, fn_ty,
Some(ccx.tcx().map.local_def_id(ctor_id)),
param_substs, &arena);
fcx = FunctionContext::new(ccx, llfndecl, fn_ty, None, &arena);
let bcx = fcx.init(false, None);

assert!(!fcx.needs_ret_allocas);
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_trans/callee.rs
Expand Up @@ -24,7 +24,6 @@ use middle::cstore::LOCAL_CRATE;
use rustc::hir::def_id::DefId;
use rustc::infer;
use rustc::ty::subst;
use rustc::ty::subst::{Substs};
use rustc::traits;
use rustc::hir::map as hir_map;
use abi::{Abi, FnType};
Expand Down Expand Up @@ -385,10 +384,9 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
let llfn = declare::define_internal_fn(ccx, &function_name, tuple_fn_ty);

//
let empty_substs = tcx.mk_substs(Substs::empty());
let (block_arena, fcx): (TypedArena<_>, FunctionContext);
block_arena = TypedArena::new();
fcx = FunctionContext::new(ccx, llfn, fn_ty, None, empty_substs, &block_arena);
fcx = FunctionContext::new(ccx, llfn, fn_ty, None, &block_arena);
let mut bcx = fcx.init(false, None);

let llargs = get_params(fcx.llfn);
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_trans/closure.rs
Expand Up @@ -240,8 +240,7 @@ pub fn trans_closure_expr<'a, 'tcx>(dest: Dest<'a, 'tcx>,
decl,
body,
llfn,
param_substs,
closure_def_id,
Instance::new(closure_def_id, param_substs),
id,
fn_ty,
Abi::RustCall,
Expand Down Expand Up @@ -387,7 +386,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(

let (block_arena, fcx): (TypedArena<_>, FunctionContext);
block_arena = TypedArena::new();
fcx = FunctionContext::new(ccx, lloncefn, fn_ty, None, substs.func_substs, &block_arena);
fcx = FunctionContext::new(ccx, lloncefn, fn_ty, None, &block_arena);
let mut bcx = fcx.init(false, None);


Expand Down
3 changes: 1 addition & 2 deletions src/librustc_trans/glue.rs
Expand Up @@ -272,10 +272,9 @@ fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,

let _s = StatRecorder::new(ccx, format!("drop {:?}", t));

let empty_substs = ccx.tcx().mk_substs(Substs::empty());
let (arena, fcx): (TypedArena<_>, FunctionContext);
arena = TypedArena::new();
fcx = FunctionContext::new(ccx, llfn, fn_ty, None, empty_substs, &arena);
fcx = FunctionContext::new(ccx, llfn, fn_ty, None, &arena);

let bcx = fcx.init(false, None);

Expand Down
3 changes: 1 addition & 2 deletions src/librustc_trans/intrinsic.rs
Expand Up @@ -1319,10 +1319,9 @@ fn gen_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
sig: ty::Binder(sig)
});
let llfn = declare::define_internal_fn(ccx, name, rust_fn_ty);
let empty_substs = ccx.tcx().mk_substs(Substs::empty());
let (fcx, block_arena);
block_arena = TypedArena::new();
fcx = FunctionContext::new(ccx, llfn, fn_ty, None, empty_substs, &block_arena);
fcx = FunctionContext::new(ccx, llfn, fn_ty, None, &block_arena);
let bcx = fcx.init(true, None);
trans(bcx);
fcx.cleanup();
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_trans/meth.rs
Expand Up @@ -93,10 +93,9 @@ pub fn trans_object_shim<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
symbol_names::internal_name_from_type_and_suffix(ccx, method_ty, "object_shim");
let llfn = declare::define_internal_fn(ccx, &function_name, method_ty);

let empty_substs = tcx.mk_substs(Substs::empty());
let (block_arena, fcx): (TypedArena<_>, FunctionContext);
block_arena = TypedArena::new();
fcx = FunctionContext::new(ccx, llfn, fn_ty, None, empty_substs, &block_arena);
fcx = FunctionContext::new(ccx, llfn, fn_ty, None, &block_arena);
let mut bcx = fcx.init(false, None);
assert!(!fcx.needs_ret_allocas);

Expand Down

0 comments on commit 35a6e6a

Please sign in to comment.