Skip to content

Commit bd009dc

Browse files
Remove fn_ty from FunctionContext
1 parent 15b9b27 commit bd009dc

File tree

8 files changed

+40
-50
lines changed

8 files changed

+40
-50
lines changed

src/librustc_trans/base.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,9 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
598598

599599
let fn_ty = FnType::new(ccx, abi, &sig, &[]);
600600

601-
let fcx = FunctionContext::new(ccx, lldecl, fn_ty);
602-
601+
let fcx = FunctionContext::new(ccx, lldecl);
603602
let mir = ccx.tcx().item_mir(instance.def);
604-
mir::trans_mir(&fcx, &mir, instance, &sig, abi);
603+
mir::trans_mir(&fcx, fn_ty, &mir, instance, &sig, abi);
605604
}
606605

607606
pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
@@ -618,28 +617,28 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
618617
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&ctor_ty.fn_sig());
619618
let fn_ty = FnType::new(ccx, Abi::Rust, &sig, &[]);
620619

621-
let fcx = FunctionContext::new(ccx, llfndecl, fn_ty);
620+
let fcx = FunctionContext::new(ccx, llfndecl);
622621
let bcx = fcx.get_entry_block();
623-
if !fcx.fn_ty.ret.is_ignore() {
622+
if !fn_ty.ret.is_ignore() {
624623
// But if there are no nested returns, we skip the indirection
625624
// and have a single retslot
626-
let dest = if fcx.fn_ty.ret.is_indirect() {
625+
let dest = if fn_ty.ret.is_indirect() {
627626
get_param(fcx.llfn, 0)
628627
} else {
629628
// We create an alloca to hold a pointer of type `ret.original_ty`
630629
// which will hold the pointer to the right alloca which has the
631630
// final ret value
632-
fcx.alloca(fcx.fn_ty.ret.memory_ty(ccx), "sret_slot")
631+
fcx.alloca(fn_ty.ret.memory_ty(ccx), "sret_slot")
633632
};
634633
let dest_val = adt::MaybeSizedValue::sized(dest); // Can return unsized value
635-
let mut llarg_idx = fcx.fn_ty.ret.is_indirect() as usize;
634+
let mut llarg_idx = fn_ty.ret.is_indirect() as usize;
636635
let mut arg_idx = 0;
637636
for (i, arg_ty) in sig.inputs().iter().enumerate() {
638637
let lldestptr = adt::trans_field_ptr(&bcx, sig.output(), dest_val, Disr::from(disr), i);
639-
let arg = &fcx.fn_ty.args[arg_idx];
638+
let arg = &fn_ty.args[arg_idx];
640639
arg_idx += 1;
641640
if common::type_is_fat_ptr(bcx.ccx, arg_ty) {
642-
let meta = &fcx.fn_ty.args[arg_idx];
641+
let meta = &fn_ty.args[arg_idx];
643642
arg_idx += 1;
644643
arg.store_fn_arg(&bcx, &mut llarg_idx, get_dataptr(&bcx, lldestptr));
645644
meta.store_fn_arg(&bcx, &mut llarg_idx, get_meta(&bcx, lldestptr));
@@ -649,14 +648,14 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
649648
}
650649
adt::trans_set_discr(&bcx, sig.output(), dest, disr);
651650

652-
if fcx.fn_ty.ret.is_indirect() {
651+
if fn_ty.ret.is_indirect() {
653652
bcx.ret_void();
654653
return;
655654
}
656655

657-
if let Some(cast_ty) = fcx.fn_ty.ret.cast {
656+
if let Some(cast_ty) = fn_ty.ret.cast {
658657
let load = bcx.load(bcx.pointercast(dest, cast_ty.ptr_to()));
659-
let llalign = llalign_of_min(ccx, fcx.fn_ty.ret.ty);
658+
let llalign = llalign_of_min(ccx, fn_ty.ret.ty);
660659
unsafe {
661660
llvm::LLVMSetAlignment(load, llalign);
662661
}

src/librustc_trans/callee.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
328328
let lloncefn = declare::define_internal_fn(ccx, &function_name, llonce_fn_ty);
329329
attributes::set_frame_pointer_elimination(ccx, lloncefn);
330330

331-
let fcx = FunctionContext::new(ccx, lloncefn, fn_ty);
331+
let orig_fn_ty = fn_ty;
332+
let fcx = FunctionContext::new(ccx, lloncefn);
332333
let mut bcx = fcx.get_entry_block();
333334

334335
let callee = Callee {
@@ -342,7 +343,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
342343
let fn_ret = callee.ty.fn_ret();
343344
let fn_ty = callee.direct_fn_type(bcx.ccx, &[]);
344345
let idx = fn_ty.ret.is_indirect() as usize;
345-
let env_arg = &fcx.fn_ty.args[0];
346+
let env_arg = &orig_fn_ty.args[0];
346347
let llenv = if env_arg.is_indirect() {
347348
llargs[idx]
348349
} else {
@@ -494,12 +495,12 @@ fn trans_fn_pointer_shim<'a, 'tcx>(
494495
let llfn = declare::define_internal_fn(ccx, &function_name, tuple_fn_ty);
495496
attributes::set_frame_pointer_elimination(ccx, llfn);
496497
//
497-
let fcx = FunctionContext::new(ccx, llfn, fn_ty);
498+
let fcx = FunctionContext::new(ccx, llfn);
498499
let bcx = fcx.get_entry_block();
499500

500501
let mut llargs = get_params(fcx.llfn);
501502

502-
let self_arg = llargs.remove(fcx.fn_ty.ret.is_indirect() as usize);
503+
let self_arg = llargs.remove(fn_ty.ret.is_indirect() as usize);
503504
let llfnpointer = llfnpointer.unwrap_or_else(|| {
504505
// the first argument (`self`) will be ptr to the fn pointer
505506
if is_by_ref {

src/librustc_trans/common.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc::hir::def_id::DefId;
2121
use rustc::hir::map::DefPathData;
2222
use rustc::util::common::MemoizationMap;
2323
use middle::lang_items::LangItem;
24-
use abi::{Abi, FnType};
24+
use abi::Abi;
2525
use base;
2626
use builder::Builder;
2727
use callee::Callee;
@@ -236,9 +236,6 @@ pub struct FunctionContext<'a, 'tcx: 'a> {
236236
// allocas, so that LLVM will coalesce them into a single alloca call.
237237
alloca_insert_pt: Option<ValueRef>,
238238

239-
// Describes the return/argument LLVM types and their ABI handling.
240-
pub fn_ty: FnType,
241-
242239
// This function's enclosing crate context.
243240
pub ccx: &'a CrateContext<'a, 'tcx>,
244241

@@ -248,15 +245,10 @@ pub struct FunctionContext<'a, 'tcx: 'a> {
248245
impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
249246
/// Create a function context for the given function.
250247
/// Call FunctionContext::get_entry_block for the first entry block.
251-
pub fn new(
252-
ccx: &'a CrateContext<'a, 'tcx>,
253-
llfndecl: ValueRef,
254-
fn_ty: FnType,
255-
) -> FunctionContext<'a, 'tcx> {
248+
pub fn new(ccx: &'a CrateContext<'a, 'tcx>, llfndecl: ValueRef) -> FunctionContext<'a, 'tcx> {
256249
let mut fcx = FunctionContext {
257250
llfn: llfndecl,
258251
alloca_insert_pt: None,
259-
fn_ty: fn_ty,
260252
ccx: ccx,
261253
alloca_builder: Builder::with_ccx(ccx),
262254
};

src/librustc_trans/glue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, g: DropGlueKind<'t
186186

187187
pub fn implement_drop_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, g: DropGlueKind<'tcx>) {
188188
assert_eq!(g.ty(), get_drop_glue_type(ccx.shared(), g.ty()));
189-
let (llfn, fn_ty) = ccx.drop_glues().borrow().get(&g).unwrap().clone();
189+
let (llfn, _) = ccx.drop_glues().borrow().get(&g).unwrap().clone();
190190

191-
let fcx = FunctionContext::new(ccx, llfn, fn_ty);
191+
let fcx = FunctionContext::new(ccx, llfn);
192192
let bcx = fcx.get_entry_block();
193193

194194
ccx.stats().n_glues_created.set(ccx.stats().n_glues_created.get() + 1);

src/librustc_trans/intrinsic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,15 +878,14 @@ fn gen_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
878878
-> ValueRef {
879879
let ccx = fcx.ccx;
880880
let sig = ccx.tcx().mk_fn_sig(inputs.into_iter(), output, false);
881-
let fn_ty = FnType::new(ccx, Abi::Rust, &sig, &[]);
882881

883882
let rust_fn_ty = ccx.tcx().mk_fn_ptr(ccx.tcx().mk_bare_fn(ty::BareFnTy {
884883
unsafety: hir::Unsafety::Unsafe,
885884
abi: Abi::Rust,
886885
sig: ty::Binder(sig)
887886
}));
888887
let llfn = declare::define_internal_fn(ccx, name, rust_fn_ty);
889-
let fcx = FunctionContext::new(ccx, llfn, fn_ty);
888+
let fcx = FunctionContext::new(ccx, llfn);
890889
trans(fcx.get_entry_block());
891890
llfn
892891
}

src/librustc_trans/meth.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use attributes;
1212
use llvm::{ValueRef, get_params};
1313
use rustc::traits;
14-
use abi::FnType;
1514
use callee::{Callee, CalleeData};
1615
use common::*;
1716
use consts;
@@ -63,25 +62,20 @@ pub fn get_virtual_method<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
6362
pub fn trans_object_shim<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
6463
callee: Callee<'tcx>)
6564
-> ValueRef {
66-
let tcx = ccx.tcx();
67-
6865
debug!("trans_object_shim({:?})", callee);
6966

70-
let (sig, abi, function_name) = match callee.ty.sty {
71-
ty::TyFnDef(def_id, substs, f) => {
67+
let function_name = match callee.ty.sty {
68+
ty::TyFnDef(def_id, substs, _) => {
7269
let instance = Instance::new(def_id, substs);
73-
(&f.sig, f.abi, instance.symbol_name(ccx.shared()))
70+
instance.symbol_name(ccx.shared())
7471
}
7572
_ => bug!()
7673
};
7774

78-
let sig = tcx.erase_late_bound_regions_and_normalize(sig);
79-
let fn_ty = FnType::new(ccx, abi, &sig, &[]);
80-
8175
let llfn = declare::define_internal_fn(ccx, &function_name, callee.ty);
8276
attributes::set_frame_pointer_elimination(ccx, llfn);
8377

84-
let fcx = FunctionContext::new(ccx, llfn, fn_ty);
78+
let fcx = FunctionContext::new(ccx, llfn);
8579
let bcx = fcx.get_entry_block();
8680

8781
let mut llargs = get_params(fcx.llfn);
@@ -103,7 +97,7 @@ pub fn trans_object_shim<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
10397
if fn_ret.0.is_never() {
10498
bcx.unreachable();
10599
} else {
106-
if fn_ty.ret.is_indirect() || fcx.fn_ty.ret.is_ignore() {
100+
if fn_ty.ret.is_indirect() || fn_ty.ret.is_ignore() {
107101
bcx.ret_void();
108102
} else {
109103
bcx.ret(llret);

src/librustc_trans/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
192192
}
193193

194194
mir::TerminatorKind::Return => {
195-
let ret = bcx.fcx().fn_ty.ret;
195+
let ret = self.fn_ty.ret;
196196
if ret.is_ignore() || ret.is_indirect() {
197197
bcx.ret_void();
198198
return;

src/librustc_trans/mir/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use base;
2222
use common::{self, BlockAndBuilder, CrateContext, FunctionContext, C_null, Funclet};
2323
use debuginfo::{self, declare_local, VariableAccess, VariableKind, FunctionDebugContext};
2424
use monomorphize::{self, Instance};
25+
use abi::FnType;
2526
use machine;
2627
use type_of;
2728

@@ -52,6 +53,8 @@ pub struct MirContext<'a, 'tcx:'a> {
5253

5354
ccx: &'a CrateContext<'a, 'tcx>,
5455

56+
fn_ty: FnType,
57+
5558
/// When unwinding is initiated, we have to store this personality
5659
/// value somewhere so that we can load it and re-use it in the
5760
/// resume instruction. The personality is (afaik) some kind of
@@ -197,6 +200,7 @@ impl<'tcx> LocalRef<'tcx> {
197200

198201
pub fn trans_mir<'a, 'tcx: 'a>(
199202
fcx: &'a FunctionContext<'a, 'tcx>,
203+
fn_ty: FnType,
200204
mir: &'a Mir<'tcx>,
201205
instance: Instance<'tcx>,
202206
sig: &ty::FnSig<'tcx>,
@@ -224,6 +228,7 @@ pub fn trans_mir<'a, 'tcx: 'a>(
224228
let mut mircx = MirContext {
225229
mir: mir,
226230
fcx: fcx,
231+
fn_ty: fn_ty,
227232
ccx: fcx.ccx,
228233
llpersonalityslot: None,
229234
blocks: block_bcxs,
@@ -271,7 +276,7 @@ pub fn trans_mir<'a, 'tcx: 'a>(
271276
LocalRef::Lvalue(lvalue)
272277
} else {
273278
// Temporary or return pointer
274-
if local == mir::RETURN_POINTER && fcx.fn_ty.ret.is_indirect() {
279+
if local == mir::RETURN_POINTER && mircx.fn_ty.ret.is_indirect() {
275280
debug!("alloc: {:?} (return pointer) -> lvalue", local);
276281
let llretptr = llvm::get_param(fcx.llfn, 0);
277282
LocalRef::Lvalue(LvalueRef::new_sized(llretptr, LvalueTy::from_ty(ty)))
@@ -351,7 +356,7 @@ fn arg_local_refs<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
351356
let fcx = bcx.fcx();
352357
let tcx = bcx.tcx();
353358
let mut idx = 0;
354-
let mut llarg_idx = fcx.fn_ty.ret.is_indirect() as usize;
359+
let mut llarg_idx = mircx.fn_ty.ret.is_indirect() as usize;
355360

356361
// Get the argument scope, if it exists and if we need it.
357362
let arg_scope = scopes[mir::ARGUMENT_VISIBILITY_SCOPE];
@@ -379,12 +384,12 @@ fn arg_local_refs<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
379384
let lltemp = base::alloc_ty(&bcx, arg_ty, &format!("arg{}", arg_index));
380385
for (i, &tupled_arg_ty) in tupled_arg_tys.iter().enumerate() {
381386
let dst = bcx.struct_gep(lltemp, i);
382-
let arg = &fcx.fn_ty.args[idx];
387+
let arg = &mircx.fn_ty.args[idx];
383388
idx += 1;
384389
if common::type_is_fat_ptr(bcx.ccx, tupled_arg_ty) {
385390
// We pass fat pointers as two words, but inside the tuple
386391
// they are the two sub-fields of a single aggregate field.
387-
let meta = &fcx.fn_ty.args[idx];
392+
let meta = &mircx.fn_ty.args[idx];
388393
idx += 1;
389394
arg.store_fn_arg(bcx, &mut llarg_idx, base::get_dataptr(bcx, dst));
390395
meta.store_fn_arg(bcx, &mut llarg_idx, base::get_meta(bcx, dst));
@@ -413,7 +418,7 @@ fn arg_local_refs<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
413418
return LocalRef::Lvalue(LvalueRef::new_sized(lltemp, LvalueTy::from_ty(arg_ty)));
414419
}
415420

416-
let arg = &fcx.fn_ty.args[idx];
421+
let arg = &mircx.fn_ty.args[idx];
417422
idx += 1;
418423
let llval = if arg.is_indirect() && bcx.sess().opts.debuginfo != FullDebugInfo {
419424
// Don't copy an indirect argument to an alloca, the caller
@@ -442,7 +447,7 @@ fn arg_local_refs<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
442447
let llarg = llvm::get_param(fcx.llfn, llarg_idx as c_uint);
443448
llarg_idx += 1;
444449
let val = if common::type_is_fat_ptr(bcx.ccx, arg_ty) {
445-
let meta = &fcx.fn_ty.args[idx];
450+
let meta = &mircx.fn_ty.args[idx];
446451
idx += 1;
447452
assert_eq!((meta.cast, meta.pad), (None, None));
448453
let llmeta = llvm::get_param(fcx.llfn, llarg_idx as c_uint);
@@ -462,7 +467,7 @@ fn arg_local_refs<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
462467
// we pass fat pointers as two words, but we want to
463468
// represent them internally as a pointer to two words,
464469
// so make an alloca to store them in.
465-
let meta = &fcx.fn_ty.args[idx];
470+
let meta = &mircx.fn_ty.args[idx];
466471
idx += 1;
467472
arg.store_fn_arg(bcx, &mut llarg_idx, base::get_dataptr(bcx, lltemp));
468473
meta.store_fn_arg(bcx, &mut llarg_idx, base::get_meta(bcx, lltemp));

0 commit comments

Comments
 (0)