]> git.lizzy.rs Git - rust.git/commitdiff
Address review comments
authorJonas Schievink <jonasschievink@gmail.com>
Tue, 27 Sep 2016 00:03:35 +0000 (02:03 +0200)
committerJonas Schievink <jonasschievink@gmail.com>
Tue, 27 Sep 2016 00:03:35 +0000 (02:03 +0200)
src/librustc/mir/repr.rs
src/librustc_trans/mir/mod.rs

index 9616ad708b4852f0f27b3f57251cc6025358f437..34b46ed66a24636d9b6fe4543c213affe01f8c80 100644 (file)
@@ -222,8 +222,10 @@ pub fn args_iter(&self) -> impl Iterator<Item=Local> {
     /// Returns an iterator over all user-defined variables and compiler-generated temporaries (all
     /// locals that are neither arguments nor the return pointer).
     #[inline]
-    pub fn vars_and_temps_iter<'a>(&'a self) -> impl Iterator<Item=Local> + 'a {
-        (self.arg_count+1..self.local_decls.len()).map(Local::new)
+    pub fn vars_and_temps_iter(&self) -> impl Iterator<Item=Local> {
+        let arg_count = self.arg_count;
+        let local_count = self.local_decls.len();
+        (arg_count+1..local_count).map(Local::new)
     }
 
     /// Changes a statement to a nop. This is both faster than deleting instructions and avoids
index 737718c282506f940274ea36487107f59ac8ea46..fe71023ea34dea34dc16af6908eaee6cc12f5da6 100644 (file)
@@ -360,59 +360,57 @@ fn arg_local_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
         let arg_decl = &mir.local_decls[local];
         let arg_ty = bcx.monomorphize(&arg_decl.ty);
 
-        if let Some(spread_local) = mir.spread_arg {
-            if local == spread_local {
-                // This argument (e.g. the last argument in the "rust-call" ABI)
-                // is a tuple that was spread at the ABI level and now we have
-                // to reconstruct it into a tuple local variable, from multiple
-                // individual LLVM function arguments.
-
-                let tupled_arg_tys = match arg_ty.sty {
-                    ty::TyTuple(ref tys) => tys,
-                    _ => bug!("spread argument isn't a tuple?!")
-                };
+        if Some(local) == mir.spread_arg {
+            // This argument (e.g. the last argument in the "rust-call" ABI)
+            // is a tuple that was spread at the ABI level and now we have
+            // to reconstruct it into a tuple local variable, from multiple
+            // individual LLVM function arguments.
+
+            let tupled_arg_tys = match arg_ty.sty {
+                ty::TyTuple(ref tys) => tys,
+                _ => bug!("spread argument isn't a tuple?!")
+            };
 
-                let lltuplety = type_of::type_of(bcx.ccx(), arg_ty);
-                let lltemp = bcx.with_block(|bcx| {
-                    base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index))
-                });
-                for (i, &tupled_arg_ty) in tupled_arg_tys.iter().enumerate() {
-                    let dst = bcx.struct_gep(lltemp, i);
-                    let arg = &fcx.fn_ty.args[idx];
+            let lltuplety = type_of::type_of(bcx.ccx(), arg_ty);
+            let lltemp = bcx.with_block(|bcx| {
+                base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index))
+            });
+            for (i, &tupled_arg_ty) in tupled_arg_tys.iter().enumerate() {
+                let dst = bcx.struct_gep(lltemp, i);
+                let arg = &fcx.fn_ty.args[idx];
+                idx += 1;
+                if common::type_is_fat_ptr(tcx, tupled_arg_ty) {
+                    // We pass fat pointers as two words, but inside the tuple
+                    // they are the two sub-fields of a single aggregate field.
+                    let meta = &fcx.fn_ty.args[idx];
                     idx += 1;
-                    if common::type_is_fat_ptr(tcx, tupled_arg_ty) {
-                        // We pass fat pointers as two words, but inside the tuple
-                        // they are the two sub-fields of a single aggregate field.
-                        let meta = &fcx.fn_ty.args[idx];
-                        idx += 1;
-                        arg.store_fn_arg(bcx, &mut llarg_idx, get_dataptr(bcx, dst));
-                        meta.store_fn_arg(bcx, &mut llarg_idx, get_meta(bcx, dst));
-                    } else {
-                        arg.store_fn_arg(bcx, &mut llarg_idx, dst);
-                    }
-
-                    bcx.with_block(|bcx| arg_scope.map(|scope| {
-                        let byte_offset_of_var_in_tuple =
-                            machine::llelement_offset(bcx.ccx(), lltuplety, i);
-
-                        let ops = unsafe {
-                            [llvm::LLVMRustDIBuilderCreateOpDeref(),
-                             llvm::LLVMRustDIBuilderCreateOpPlus(),
-                             byte_offset_of_var_in_tuple as i64]
-                        };
-
-                        let variable_access = VariableAccess::IndirectVariable {
-                            alloca: lltemp,
-                            address_operations: &ops
-                        };
-                        declare_local(bcx, keywords::Invalid.name(),
-                                      tupled_arg_ty, scope, variable_access,
-                                      VariableKind::ArgumentVariable(arg_index + i + 1),
-                                      bcx.fcx().span.unwrap_or(DUMMY_SP));
-                    }));
+                    arg.store_fn_arg(bcx, &mut llarg_idx, get_dataptr(bcx, dst));
+                    meta.store_fn_arg(bcx, &mut llarg_idx, get_meta(bcx, dst));
+                } else {
+                    arg.store_fn_arg(bcx, &mut llarg_idx, dst);
                 }
-                return LocalRef::Lvalue(LvalueRef::new_sized(lltemp, LvalueTy::from_ty(arg_ty)));
+
+                bcx.with_block(|bcx| arg_scope.map(|scope| {
+                    let byte_offset_of_var_in_tuple =
+                        machine::llelement_offset(bcx.ccx(), lltuplety, i);
+
+                    let ops = unsafe {
+                        [llvm::LLVMRustDIBuilderCreateOpDeref(),
+                         llvm::LLVMRustDIBuilderCreateOpPlus(),
+                         byte_offset_of_var_in_tuple as i64]
+                    };
+
+                    let variable_access = VariableAccess::IndirectVariable {
+                        alloca: lltemp,
+                        address_operations: &ops
+                    };
+                    declare_local(bcx, keywords::Invalid.name(),
+                                  tupled_arg_ty, scope, variable_access,
+                                  VariableKind::ArgumentVariable(arg_index + i + 1),
+                                  bcx.fcx().span.unwrap_or(DUMMY_SP));
+                }));
             }
+            return LocalRef::Lvalue(LvalueRef::new_sized(lltemp, LvalueTy::from_ty(arg_ty)));
         }
 
         let arg = &fcx.fn_ty.args[idx];