From 4cfda6ae966aafed35cc9ac00374c63f09df25df Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 23 Aug 2017 16:47:12 +0200 Subject: [PATCH 1/3] hack to make xargo libstd build work again --- xargo/build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/xargo/build.sh b/xargo/build.sh index 15a7c770910..b842c04ae09 100755 --- a/xargo/build.sh +++ b/xargo/build.sh @@ -1,3 +1,4 @@ #!/bin/sh cd "$(dirname "$0")" +sed 's/gcc = "0\.3\.50"/gcc = "=0\.3\.50"/' -i ~/.rustup/toolchains/*/lib/rustlib/src/rust/src/libstd/Cargo.toml RUSTFLAGS='-Zalways-encode-mir -Zmir-emit-validate=1' xargo build From 7b8e2c772df6c62e01ab376d2ca2b539bbc0989a Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 23 Aug 2017 17:24:38 +0200 Subject: [PATCH 2/3] Rustup (`Clone` is now a builtin trait) --- src/librustc_mir/interpret/eval_context.rs | 6 ++++++ src/librustc_mir/interpret/terminator/mod.rs | 1 + 2 files changed, 7 insertions(+) diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index a5f5072dc29..d4b7761567d 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -2270,6 +2270,12 @@ fn resolve_associated_item<'a, 'tcx>( substs: rcvr_substs, } } + ::rustc::traits::VtableBuiltin(..) if Some(trait_id) == tcx.lang_items.clone_trait() => { + ty::Instance { + def: ty::InstanceDef::CloneShim(def_id, trait_ref.self_ty()), + substs: rcvr_substs + } + } _ => bug!("static call to invalid vtable: {:?}", vtbl), } } diff --git a/src/librustc_mir/interpret/terminator/mod.rs b/src/librustc_mir/interpret/terminator/mod.rs index dde541ed5f7..c0d91cfb0d1 100644 --- a/src/librustc_mir/interpret/terminator/mod.rs +++ b/src/librustc_mir/interpret/terminator/mod.rs @@ -297,6 +297,7 @@ fn eval_fn_call( } Ok(()) } + ty::InstanceDef::CloneShim(..) | ty::InstanceDef::Item(_) => { let mut args = Vec::new(); for arg in arg_operands { From f75dd90961261760fc87031284135a6bb0b46ba1 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 23 Aug 2017 17:46:36 +0200 Subject: [PATCH 3/3] Also reuse function pointer shims and drop glue from rustc --- src/librustc_mir/interpret/terminator/mod.rs | 45 ++------------------ 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/src/librustc_mir/interpret/terminator/mod.rs b/src/librustc_mir/interpret/terminator/mod.rs index c0d91cfb0d1..d8a432cfa48 100644 --- a/src/librustc_mir/interpret/terminator/mod.rs +++ b/src/librustc_mir/interpret/terminator/mod.rs @@ -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(