Skip to content

Commit 727a5d5

Browse files
committed
Prefer alloc_ty() instead of alloca() where possible
1 parent 95337a2 commit 727a5d5

File tree

7 files changed

+9
-20
lines changed

7 files changed

+9
-20
lines changed

src/librustc_trans/trans/_match.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
11961196
let unsized_ty = def.struct_variant().fields.last().map(|field| {
11971197
monomorphize::field_ty(bcx.tcx(), substs, field)
11981198
}).unwrap();
1199-
let llty = type_of::type_of(bcx.ccx(), unsized_ty);
1200-
let scratch = alloca(bcx, llty, "__struct_field_fat_ptr");
1199+
let scratch = alloc_ty(bcx, unsized_ty, "__struct_field_fat_ptr");
12011200
let data = adt::trans_field_ptr(bcx, &*repr, struct_val, 0, arg_count);
12021201
let len = Load(bcx, expr::get_meta(bcx, val.val));
12031202
Store(bcx, data, expr::get_dataptr(bcx, scratch));

src/librustc_trans/trans/base.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,7 @@ pub fn alloc_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, name: &str) ->
10201020
let ccx = bcx.ccx();
10211021
let ty = type_of::type_of(ccx, t);
10221022
assert!(!t.has_param_types());
1023-
let val = alloca(bcx, ty, name);
1024-
return val;
1023+
alloca(bcx, ty, name)
10251024
}
10261025

10271026
pub fn alloca(cx: Block, ty: Type, name: &str) -> ValueRef {

src/librustc_trans/trans/datum.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ use trans::cleanup;
101101
use trans::cleanup::{CleanupMethods, DropHintDatum, DropHintMethods};
102102
use trans::expr;
103103
use trans::tvec;
104-
use trans::type_of;
105104
use middle::ty::Ty;
106105

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

308306
// Subtle. Populate the scratch memory *before* scheduling cleanup.
309307
call_lifetime_start(bcx, scratch);
@@ -323,8 +321,7 @@ pub fn rvalue_scratch_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
323321
ty: Ty<'tcx>,
324322
name: &str)
325323
-> Datum<'tcx, Rvalue> {
326-
let llty = type_of::type_of(bcx.ccx(), ty);
327-
let scratch = alloca(bcx, llty, name);
324+
let scratch = alloc_ty(bcx, ty, name);
328325
call_lifetime_start(bcx, scratch);
329326
Datum::new(scratch, ty, Rvalue::new(ByRef))
330327
}

src/librustc_trans/trans/expr.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ pub fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
246246
// Maybe just get the value directly, instead of loading it?
247247
immediate_rvalue(load_ty(bcx, global, const_ty), const_ty)
248248
} else {
249-
let llty = type_of::type_of(bcx.ccx(), const_ty);
250-
let scratch = alloca(bcx, llty, "const");
249+
let scratch = alloc_ty(bcx, const_ty, "const");
251250
call_lifetime_start(bcx, scratch);
252251
let lldest = if !const_ty.is_structural() {
253252
// Cast pointer to slot, because constants have different types.
@@ -410,9 +409,8 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
410409
datum.to_rvalue_datum(bcx, "__coerce_source"));
411410

412411
let target = bcx.monomorphize(&target);
413-
let llty = type_of::type_of(bcx.ccx(), target);
414412

415-
let scratch = alloca(bcx, llty, "__coerce_target");
413+
let scratch = alloc_ty(bcx, target, "__coerce_target");
416414
call_lifetime_start(bcx, scratch);
417415
let target_datum = Datum::new(scratch, target,
418416
Rvalue::new(ByRef));

src/librustc_trans/trans/foreign.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,7 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
296296
// Ensure that we always have the Rust value indirectly,
297297
// because it makes bitcasting easier.
298298
if !rust_indirect {
299-
let scratch =
300-
base::alloca(bcx,
301-
type_of::type_of(ccx, passed_arg_tys[i]),
302-
"__arg");
299+
let scratch = base::alloc_ty(bcx, passed_arg_tys[i], "__arg");
303300
if type_is_fat_ptr(ccx.tcx(), passed_arg_tys[i]) {
304301
Store(bcx, llargs_rust[i + offset], expr::get_dataptr(bcx, scratch));
305302
Store(bcx, llargs_rust[i + offset + 1], expr::get_meta(bcx, scratch));

src/librustc_trans/trans/glue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub fn drop_ty_immediate<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
187187
skip_dtor: bool)
188188
-> Block<'blk, 'tcx> {
189189
let _icx = push_ctxt("drop_ty_immediate");
190-
let vp = alloca(bcx, type_of(bcx.ccx(), t), "");
190+
let vp = alloc_ty(bcx, t, "");
191191
call_lifetime_start(bcx, vp);
192192
store_ty(bcx, v, vp, t);
193193
let bcx = drop_ty_core(bcx, vp, t, debug_loc, skip_dtor, None);

src/librustc_trans/trans/tvec.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,10 @@ pub fn trans_slice_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
106106
debug!(" vt={}, count={}", vt.to_string(ccx), count);
107107

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

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

116115
if count > 0 {

0 commit comments

Comments
 (0)