trans: use Instance in trans_closure and FunctionContext::new.
This commit is contained in:
parent
a563711b6a
commit
35a6e6a02b
@ -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);
|
||||
@ -1810,8 +1813,7 @@ 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,
|
||||
@ -1819,18 +1821,17 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
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);
|
||||
@ -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,
|
||||
@ -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);
|
||||
|
@ -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};
|
||||
@ -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);
|
||||
|
@ -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,
|
||||
@ -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);
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user