Skip to content

Commit 205dac9

Browse files
Move "rust-call" tuple spreading out of ArgDecl
If MIR is for a "rust-call" ABI function, the last arg would always have `spread` set to `true`. Move this flag into `Mir` instead.
1 parent 3bf4a7a commit 205dac9

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/librustc/mir/repr.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ pub struct Mir<'tcx> {
9393
/// the first argument is either the closure or a reference to it.
9494
pub upvar_decls: Vec<UpvarDecl>,
9595

96+
/// A boolean indicating whether the last argument (which must be a tuple)
97+
/// is passed as its individual components at the LLVM level.
98+
///
99+
/// This is used for the "rust-call" ABI.
100+
pub spread_last_arg: bool,
101+
96102
/// A span representing this MIR, for error reporting
97103
pub span: Span,
98104

@@ -123,6 +129,7 @@ impl<'tcx> Mir<'tcx> {
123129
arg_decls: arg_decls,
124130
temp_decls: temp_decls,
125131
upvar_decls: upvar_decls,
132+
spread_last_arg: false,
126133
span: span,
127134
cache: Cache::new()
128135
}
@@ -341,10 +348,6 @@ pub struct TempDecl<'tcx> {
341348
pub struct ArgDecl<'tcx> {
342349
pub ty: Ty<'tcx>,
343350

344-
/// If true, this argument is a tuple after monomorphization,
345-
/// and has to be collected from multiple actual arguments.
346-
pub spread: bool,
347-
348351
/// Either keywords::Invalid or the name of a single-binding
349352
/// pattern associated with this argument. Useful for debuginfo.
350353
pub debug_name: Name

src/librustc/mir/visit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,6 @@ macro_rules! make_mir_visitor {
665665
arg_decl: & $($mutability)* ArgDecl<'tcx>) {
666666
let ArgDecl {
667667
ref $($mutability)* ty,
668-
spread: _,
669668
debug_name: _
670669
} = *arg_decl;
671670

src/librustc_mir/build/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
169169
tcx.region_maps.lookup_code_extent(
170170
CodeExtentData::ParameterScope { fn_id: fn_id, body_id: body_id });
171171
let mut block = START_BLOCK;
172-
let mut arg_decls = unpack!(block = builder.in_scope(call_site_extent, block, |builder| {
172+
let arg_decls = unpack!(block = builder.in_scope(call_site_extent, block, |builder| {
173173
let arg_decls = unpack!(block = builder.in_scope(arg_extent, block, |builder| {
174174
builder.args_and_body(block, return_ty, arguments, arg_extent, ast_block)
175175
}));
@@ -184,12 +184,11 @@ pub fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
184184
}));
185185
assert_eq!(block, builder.return_block());
186186

187+
let mut spread_last_arg = false;
187188
match tcx.node_id_to_type(fn_id).sty {
188189
ty::TyFnDef(_, _, f) if f.abi == Abi::RustCall => {
189190
// RustCall pseudo-ABI untuples the last argument.
190-
if let Some(last_arg) = arg_decls.last() {
191-
arg_decls[last_arg].spread = true;
192-
}
191+
spread_last_arg = true;
193192
}
194193
_ => {}
195194
}
@@ -218,7 +217,9 @@ pub fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
218217
}).collect()
219218
});
220219

221-
builder.finish(upvar_decls, arg_decls, return_ty)
220+
let (mut mir, aux) = builder.finish(upvar_decls, arg_decls, return_ty);
221+
mir.spread_last_arg = spread_last_arg;
222+
(mir, aux)
222223
}
223224

224225
pub fn construct_const<'a, 'gcx, 'tcx>(hir: Cx<'a, 'gcx, 'tcx>,
@@ -331,7 +332,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
331332

332333
ArgDecl {
333334
ty: ty,
334-
spread: false,
335335
debug_name: name
336336
}
337337
}).collect();

src/librustc_trans/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ fn arg_local_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
349349
mir.arg_decls.iter().enumerate().map(|(arg_index, arg_decl)| {
350350
let arg_ty = bcx.monomorphize(&arg_decl.ty);
351351
let local = mir.local_index(&mir::Lvalue::Arg(mir::Arg::new(arg_index))).unwrap();
352-
if arg_decl.spread {
352+
if mir.spread_last_arg && arg_index == mir.arg_decls.len() - 1 {
353353
// This argument (e.g. the last argument in the "rust-call" ABI)
354354
// is a tuple that was spread at the ABI level and now we have
355355
// to reconstruct it into a tuple local variable, from multiple

0 commit comments

Comments
 (0)