]> git.lizzy.rs Git - rust.git/commitdiff
Also reuse function pointer shims and drop glue from rustc
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 23 Aug 2017 15:46:36 +0000 (17:46 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 23 Aug 2017 15:46:36 +0000 (17:46 +0200)
src/librustc_mir/interpret/terminator/mod.rs

index c0d91cfb0d1446f5829acc5d88f92987bd5e8614..d8a432cfa482b5b3b2834abca3eb8dd007dbe4de 100644 (file)
@@ -256,6 +256,7 @@ fn eval_fn_call(
                 self.dump_local(ret);
                 Ok(())
             }
+            // FIXME: figure out why we can't just go through the shim
             ty::InstanceDef::ClosureOnceShim { .. } => {
                 let mut args = Vec::new();
                 for arg in arg_operands {
@@ -297,6 +298,8 @@ fn eval_fn_call(
                 }
                 Ok(())
             }
+            ty::InstanceDef::FnPtrShim(..) |
+            ty::InstanceDef::DropGlue(..) |
             ty::InstanceDef::CloneShim(..) |
             ty::InstanceDef::Item(_) => {
                 let mut args = Vec::new();
@@ -395,47 +398,7 @@ fn eval_fn_call(
                 }
                 Ok(())
             }
-            ty::InstanceDef::DropGlue(..) => {
-                assert_eq!(arg_operands.len(), 1);
-                assert_eq!(sig.abi, Abi::Rust);
-                let val = self.eval_operand(&arg_operands[0])?;
-                let ty = self.operand_ty(&arg_operands[0]);
-                let (_, target) = destination.expect("diverging drop glue");
-                self.goto_block(target);
-                // FIXME: deduplicate these matches
-                let pointee_type = match ty.sty {
-                    ty::TyRawPtr(ref tam) |
-                    ty::TyRef(_, ref tam) => tam.ty,
-                    ty::TyAdt(def, _) if def.is_box() => ty.boxed_ty(),
-                    _ => bug!("can only deref pointer types"),
-                };
-                self.drop(val, instance, pointee_type, span)
-            }
-            ty::InstanceDef::FnPtrShim(..) => {
-                trace!("ABI: {}", sig.abi);
-                let mut args = Vec::new();
-                for arg in arg_operands {
-                    let arg_val = self.eval_operand(arg)?;
-                    let arg_ty = self.operand_ty(arg);
-                    args.push((arg_val, arg_ty));
-                }
-                if M::eval_fn_call(self, instance, destination, arg_operands, span, sig)? {
-                    return Ok(());
-                }
-                let arg_locals = self.frame().mir.args_iter();
-                match sig.abi {
-                    Abi::Rust => {
-                        args.remove(0);
-                    }
-                    Abi::RustCall => {}
-                    _ => unimplemented!(),
-                };
-                for (arg_local, (arg_val, arg_ty)) in arg_locals.zip(args) {
-                    let dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?;
-                    self.write_value(arg_val, dest, arg_ty)?;
-                }
-                Ok(())
-            }
+            // cannot use the shim here, because that will only result in infinite recursion
             ty::InstanceDef::Virtual(_, idx) => {
                 let ptr_size = self.memory.pointer_size();
                 let (_, vtable) = self.eval_operand(&arg_operands[0])?.into_ptr_vtable_pair(