Skip to content

Commit

Permalink
Prefer alloc_ty() instead of alloca() where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
dotdash committed Aug 25, 2015
1 parent 95337a2 commit 727a5d5
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/librustc_trans/trans/_match.rs
Expand Up @@ -1196,8 +1196,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
let unsized_ty = def.struct_variant().fields.last().map(|field| {
monomorphize::field_ty(bcx.tcx(), substs, field)
}).unwrap();
let llty = type_of::type_of(bcx.ccx(), unsized_ty);
let scratch = alloca(bcx, llty, "__struct_field_fat_ptr");
let scratch = alloc_ty(bcx, unsized_ty, "__struct_field_fat_ptr");
let data = adt::trans_field_ptr(bcx, &*repr, struct_val, 0, arg_count);
let len = Load(bcx, expr::get_meta(bcx, val.val));
Store(bcx, data, expr::get_dataptr(bcx, scratch));
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_trans/trans/base.rs
Expand Up @@ -1020,8 +1020,7 @@ pub fn alloc_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, name: &str) ->
let ccx = bcx.ccx();
let ty = type_of::type_of(ccx, t);
assert!(!t.has_param_types());
let val = alloca(bcx, ty, name);
return val;
alloca(bcx, ty, name)
}

pub fn alloca(cx: Block, ty: Type, name: &str) -> ValueRef {
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_trans/trans/datum.rs
Expand Up @@ -101,7 +101,6 @@ use trans::cleanup;
use trans::cleanup::{CleanupMethods, DropHintDatum, DropHintMethods};
use trans::expr;
use trans::tvec;
use trans::type_of;
use middle::ty::Ty;

use std::fmt;
Expand Down Expand Up @@ -302,8 +301,7 @@ pub fn lvalue_scratch_datum<'blk, 'tcx, A, F>(bcx: Block<'blk, 'tcx>,
-> DatumBlock<'blk, 'tcx, Lvalue> where
F: FnOnce(A, Block<'blk, 'tcx>, ValueRef) -> Block<'blk, 'tcx>,
{
let llty = type_of::type_of(bcx.ccx(), ty);
let scratch = alloca(bcx, llty, name);
let scratch = alloc_ty(bcx, ty, name);

// Subtle. Populate the scratch memory *before* scheduling cleanup.
call_lifetime_start(bcx, scratch);
Expand All @@ -323,8 +321,7 @@ pub fn rvalue_scratch_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
ty: Ty<'tcx>,
name: &str)
-> Datum<'tcx, Rvalue> {
let llty = type_of::type_of(bcx.ccx(), ty);
let scratch = alloca(bcx, llty, name);
let scratch = alloc_ty(bcx, ty, name);
call_lifetime_start(bcx, scratch);
Datum::new(scratch, ty, Rvalue::new(ByRef))
}
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_trans/trans/expr.rs
Expand Up @@ -246,8 +246,7 @@ pub fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// Maybe just get the value directly, instead of loading it?
immediate_rvalue(load_ty(bcx, global, const_ty), const_ty)
} else {
let llty = type_of::type_of(bcx.ccx(), const_ty);
let scratch = alloca(bcx, llty, "const");
let scratch = alloc_ty(bcx, const_ty, "const");
call_lifetime_start(bcx, scratch);
let lldest = if !const_ty.is_structural() {
// Cast pointer to slot, because constants have different types.
Expand Down Expand Up @@ -410,9 +409,8 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
datum.to_rvalue_datum(bcx, "__coerce_source"));

let target = bcx.monomorphize(&target);
let llty = type_of::type_of(bcx.ccx(), target);

let scratch = alloca(bcx, llty, "__coerce_target");
let scratch = alloc_ty(bcx, target, "__coerce_target");
call_lifetime_start(bcx, scratch);
let target_datum = Datum::new(scratch, target,
Rvalue::new(ByRef));
Expand Down
5 changes: 1 addition & 4 deletions src/librustc_trans/trans/foreign.rs
Expand Up @@ -296,10 +296,7 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// Ensure that we always have the Rust value indirectly,
// because it makes bitcasting easier.
if !rust_indirect {
let scratch =
base::alloca(bcx,
type_of::type_of(ccx, passed_arg_tys[i]),
"__arg");
let scratch = base::alloc_ty(bcx, passed_arg_tys[i], "__arg");
if type_is_fat_ptr(ccx.tcx(), passed_arg_tys[i]) {
Store(bcx, llargs_rust[i + offset], expr::get_dataptr(bcx, scratch));
Store(bcx, llargs_rust[i + offset + 1], expr::get_meta(bcx, scratch));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/glue.rs
Expand Up @@ -187,7 +187,7 @@ pub fn drop_ty_immediate<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
skip_dtor: bool)
-> Block<'blk, 'tcx> {
let _icx = push_ctxt("drop_ty_immediate");
let vp = alloca(bcx, type_of(bcx.ccx(), t), "");
let vp = alloc_ty(bcx, t, "");
call_lifetime_start(bcx, vp);
store_ty(bcx, v, vp, t);
let bcx = drop_ty_core(bcx, vp, t, debug_loc, skip_dtor, None);
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_trans/trans/tvec.rs
Expand Up @@ -106,11 +106,10 @@ pub fn trans_slice_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
debug!(" vt={}, count={}", vt.to_string(ccx), count);

let fixed_ty = bcx.tcx().mk_array(vt.unit_ty, count);
let llfixed_ty = type_of::type_of(bcx.ccx(), fixed_ty);

// Always create an alloca even if zero-sized, to preserve
// the non-null invariant of the inner slice ptr
let llfixed = base::alloca(bcx, llfixed_ty, "");
let llfixed = base::alloc_ty(bcx, fixed_ty, "");
call_lifetime_start(bcx, llfixed);

if count > 0 {
Expand Down

0 comments on commit 727a5d5

Please sign in to comment.