Skip to content

Commit e3293b8

Browse files
Address review comments
1 parent a0fa204 commit e3293b8

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

src/librustc/mir/repr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ impl<'tcx> Mir<'tcx> {
222222
/// Returns an iterator over all user-defined variables and compiler-generated temporaries (all
223223
/// locals that are neither arguments nor the return pointer).
224224
#[inline]
225-
pub fn vars_and_temps_iter<'a>(&'a self) -> impl Iterator<Item=Local> + 'a {
226-
(self.arg_count+1..self.local_decls.len()).map(Local::new)
225+
pub fn vars_and_temps_iter(&self) -> impl Iterator<Item=Local> {
226+
let arg_count = self.arg_count;
227+
let local_count = self.local_decls.len();
228+
(arg_count+1..local_count).map(Local::new)
227229
}
228230

229231
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids

src/librustc_trans/mir/mod.rs

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -360,59 +360,57 @@ fn arg_local_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
360360
let arg_decl = &mir.local_decls[local];
361361
let arg_ty = bcx.monomorphize(&arg_decl.ty);
362362

363-
if let Some(spread_local) = mir.spread_arg {
364-
if local == spread_local {
365-
// This argument (e.g. the last argument in the "rust-call" ABI)
366-
// is a tuple that was spread at the ABI level and now we have
367-
// to reconstruct it into a tuple local variable, from multiple
368-
// individual LLVM function arguments.
369-
370-
let tupled_arg_tys = match arg_ty.sty {
371-
ty::TyTuple(ref tys) => tys,
372-
_ => bug!("spread argument isn't a tuple?!")
373-
};
363+
if Some(local) == mir.spread_arg {
364+
// This argument (e.g. the last argument in the "rust-call" ABI)
365+
// is a tuple that was spread at the ABI level and now we have
366+
// to reconstruct it into a tuple local variable, from multiple
367+
// individual LLVM function arguments.
368+
369+
let tupled_arg_tys = match arg_ty.sty {
370+
ty::TyTuple(ref tys) => tys,
371+
_ => bug!("spread argument isn't a tuple?!")
372+
};
374373

375-
let lltuplety = type_of::type_of(bcx.ccx(), arg_ty);
376-
let lltemp = bcx.with_block(|bcx| {
377-
base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index))
378-
});
379-
for (i, &tupled_arg_ty) in tupled_arg_tys.iter().enumerate() {
380-
let dst = bcx.struct_gep(lltemp, i);
381-
let arg = &fcx.fn_ty.args[idx];
374+
let lltuplety = type_of::type_of(bcx.ccx(), arg_ty);
375+
let lltemp = bcx.with_block(|bcx| {
376+
base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index))
377+
});
378+
for (i, &tupled_arg_ty) in tupled_arg_tys.iter().enumerate() {
379+
let dst = bcx.struct_gep(lltemp, i);
380+
let arg = &fcx.fn_ty.args[idx];
381+
idx += 1;
382+
if common::type_is_fat_ptr(tcx, tupled_arg_ty) {
383+
// We pass fat pointers as two words, but inside the tuple
384+
// they are the two sub-fields of a single aggregate field.
385+
let meta = &fcx.fn_ty.args[idx];
382386
idx += 1;
383-
if common::type_is_fat_ptr(tcx, tupled_arg_ty) {
384-
// We pass fat pointers as two words, but inside the tuple
385-
// they are the two sub-fields of a single aggregate field.
386-
let meta = &fcx.fn_ty.args[idx];
387-
idx += 1;
388-
arg.store_fn_arg(bcx, &mut llarg_idx, get_dataptr(bcx, dst));
389-
meta.store_fn_arg(bcx, &mut llarg_idx, get_meta(bcx, dst));
390-
} else {
391-
arg.store_fn_arg(bcx, &mut llarg_idx, dst);
392-
}
393-
394-
bcx.with_block(|bcx| arg_scope.map(|scope| {
395-
let byte_offset_of_var_in_tuple =
396-
machine::llelement_offset(bcx.ccx(), lltuplety, i);
397-
398-
let ops = unsafe {
399-
[llvm::LLVMRustDIBuilderCreateOpDeref(),
400-
llvm::LLVMRustDIBuilderCreateOpPlus(),
401-
byte_offset_of_var_in_tuple as i64]
402-
};
403-
404-
let variable_access = VariableAccess::IndirectVariable {
405-
alloca: lltemp,
406-
address_operations: &ops
407-
};
408-
declare_local(bcx, keywords::Invalid.name(),
409-
tupled_arg_ty, scope, variable_access,
410-
VariableKind::ArgumentVariable(arg_index + i + 1),
411-
bcx.fcx().span.unwrap_or(DUMMY_SP));
412-
}));
387+
arg.store_fn_arg(bcx, &mut llarg_idx, get_dataptr(bcx, dst));
388+
meta.store_fn_arg(bcx, &mut llarg_idx, get_meta(bcx, dst));
389+
} else {
390+
arg.store_fn_arg(bcx, &mut llarg_idx, dst);
413391
}
414-
return LocalRef::Lvalue(LvalueRef::new_sized(lltemp, LvalueTy::from_ty(arg_ty)));
392+
393+
bcx.with_block(|bcx| arg_scope.map(|scope| {
394+
let byte_offset_of_var_in_tuple =
395+
machine::llelement_offset(bcx.ccx(), lltuplety, i);
396+
397+
let ops = unsafe {
398+
[llvm::LLVMRustDIBuilderCreateOpDeref(),
399+
llvm::LLVMRustDIBuilderCreateOpPlus(),
400+
byte_offset_of_var_in_tuple as i64]
401+
};
402+
403+
let variable_access = VariableAccess::IndirectVariable {
404+
alloca: lltemp,
405+
address_operations: &ops
406+
};
407+
declare_local(bcx, keywords::Invalid.name(),
408+
tupled_arg_ty, scope, variable_access,
409+
VariableKind::ArgumentVariable(arg_index + i + 1),
410+
bcx.fcx().span.unwrap_or(DUMMY_SP));
411+
}));
415412
}
413+
return LocalRef::Lvalue(LvalueRef::new_sized(lltemp, LvalueTy::from_ty(arg_ty)));
416414
}
417415

418416
let arg = &fcx.fn_ty.args[idx];

0 commit comments

Comments
 (0)