From 45cf3cfde2c32f5b27c469ef1b5f04dd195fb462 Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Sat, 27 Aug 2016 01:44:46 -0600 Subject: [PATCH] Update for changes in rustc. --- Cargo.lock | 45 +++++++++++----- src/bin/miri.rs | 12 +++-- src/interpreter/mod.rs | 68 ++++++++++------------- src/interpreter/step.rs | 16 ++++-- src/interpreter/terminator.rs | 80 +++++++++++++--------------- tests/compile-fail/cast_fn_ptr.rs | 4 +- tests/compile-fail/execute_memory.rs | 4 +- 7 files changed, 121 insertions(+), 108 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d0b785a061f..0217a26fddd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,8 +3,8 @@ name = "miri" version = "0.1.0" dependencies = [ "byteorder 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "compiletest_rs 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "compiletest_rs 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -24,7 +24,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "compiletest_rs" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -33,11 +33,11 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.1.71 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.1.73 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -45,7 +45,7 @@ name = "kernel32-sys" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -56,7 +56,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.12" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -77,24 +77,24 @@ name = "memchr" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex" -version = "0.1.71" +version = "0.1.73" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "thread_local 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex-syntax" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -108,7 +108,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -126,7 +126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -134,3 +134,22 @@ name = "winapi-build" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[metadata] +"checksum aho-corasick 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2b3fb52b09c1710b961acb35390d514be82e4ac96a9969a8e38565a29b878dc9" +"checksum byteorder 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96c8b41881888cc08af32d47ac4edd52bc7fa27fef774be47a92443756451304" +"checksum compiletest_rs 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0bcddebf582c5c035cce855a89596eb686cc40b9e77da1026fba735dcca2fbd3" +"checksum env_logger 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "82dcb9ceed3868a03b335657b85a159736c961900f7e7747d3b0b97b9ccb5ccb" +"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +"checksum lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "49247ec2a285bb3dcb23cbd9c35193c025e7251bfce77c1d5da97e6362dffe7f" +"checksum libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "23e3757828fa702a20072c37ff47938e9dd331b92fac6e223d26d4b7a55f7ee2" +"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054" +"checksum log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3d382732ea0fbc09790c4899db3255bdea0fc78b54bf234bd18a63bb603915b6" +"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" +"checksum regex 0.1.73 (registry+https://github.com/rust-lang/crates.io-index)" = "56b7ee9f764ecf412c6e2fff779bca4b22980517ae335a21aeaf4e32625a5df2" +"checksum regex-syntax 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "31040aad7470ad9d8c46302dcffba337bb4289ca5da2e3cd6e37b64109a85199" +"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b" +"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" +"checksum thread_local 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "55dd963dbaeadc08aa7266bf7f91c3154a7805e32bb94b820b769d2ef3b4744d" +"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" +"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/src/bin/miri.rs b/src/bin/miri.rs index 14a947302c6..728266a755d 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -33,8 +33,9 @@ fn build_controller( let tcx = state.tcx.unwrap(); let mir_map = state.mir_map.unwrap(); - let (node_id, _) = state.session.entry_fn.borrow() + let (entry_node_id, _) = state.session.entry_fn.borrow() .expect("no main or start function found"); + let entry_def_id = tcx.map.local_def_id(entry_node_id); let krate = state.hir_crate.as_ref().unwrap(); let mut memory_size = 100*1024*1024; // 100MB @@ -66,9 +67,12 @@ fn extract_str(lit: &syntax::ast::Lit) -> syntax::parse::token::InternedString { } } - let mut mir_map = MirMap { map: mir_map.map.clone() }; - run_mir_passes(tcx, &mut mir_map); - eval_main(tcx, &mir_map, node_id, memory_size, step_limit, stack_limit); + let mut mir_map_copy = MirMap::new(tcx.dep_graph.clone()); + for def_id in mir_map.map.keys() { + mir_map_copy.map.insert(def_id, mir_map.map.get(&def_id).unwrap().clone()); + } + run_mir_passes(tcx, &mut mir_map_copy); + eval_main(tcx, &mir_map_copy, entry_def_id, memory_size, step_limit, stack_limit); state.session.abort_if_errors(); }); diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index c1e1fff999f..5ef423f21fb 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -2,7 +2,7 @@ use rustc::hir::def_id::DefId; use rustc::mir::mir_map::MirMap; use rustc::mir::repr as mir; -use rustc::traits::ProjectionMode; +use rustc::traits::Reveal; use rustc::ty::layout::{self, Layout, Size}; use rustc::ty::subst::{self, Subst, Substs}; use rustc::ty::{self, Ty, TyCtxt}; @@ -12,7 +12,6 @@ use std::ops::Deref; use std::rc::Rc; use std::iter; -use syntax::ast; use syntax::codemap::{self, DUMMY_SP}; use error::{EvalError, EvalResult}; @@ -148,15 +147,10 @@ pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir_map: &'a MirMap<'tcx>, memory_size: } } - pub fn alloc_ret_ptr(&mut self, output_ty: ty::FnOutput<'tcx>, substs: &'tcx Substs<'tcx>) -> EvalResult<'tcx, Option> { - match output_ty { - ty::FnConverging(ty) => { - let size = self.type_size_with_substs(ty, substs); - let align = self.type_align_with_substs(ty, substs); - self.memory.allocate(size, align).map(Some) - } - ty::FnDiverging => Ok(None), - } + pub fn alloc_ret_ptr(&mut self, ty: Ty<'tcx>, substs: &'tcx Substs<'tcx>) -> EvalResult<'tcx, Pointer> { + let size = self.type_size_with_substs(ty, substs); + let align = self.type_align_with_substs(ty, substs); + self.memory.allocate(size, align) } pub fn memory(&self) -> &Memory<'a, 'tcx> { @@ -251,22 +245,21 @@ fn type_is_sized(&self, ty: Ty<'tcx>) -> bool { } pub fn load_mir(&self, def_id: DefId) -> CachedMir<'a, 'tcx> { - match self.tcx.map.as_local_node_id(def_id) { - Some(node_id) => CachedMir::Ref(self.mir_map.map.get(&node_id).unwrap()), - None => { - let mut mir_cache = self.mir_cache.borrow_mut(); - if let Some(mir) = mir_cache.get(&def_id) { - return CachedMir::Owned(mir.clone()); - } - - let cs = &self.tcx.sess.cstore; - let mir = cs.maybe_get_item_mir(self.tcx, def_id).unwrap_or_else(|| { - panic!("no mir for `{}`", self.tcx.item_path_str(def_id)); - }); - let cached = Rc::new(mir); - mir_cache.insert(def_id, cached.clone()); - CachedMir::Owned(cached) + if def_id.is_local() { + CachedMir::Ref(self.mir_map.map.get(&def_id).unwrap()) + } else { + let mut mir_cache = self.mir_cache.borrow_mut(); + if let Some(mir) = mir_cache.get(&def_id) { + return CachedMir::Owned(mir.clone()); } + + let cs = &self.tcx.sess.cstore; + let mir = cs.maybe_get_item_mir(self.tcx, def_id).unwrap_or_else(|| { + panic!("no mir for `{}`", self.tcx.item_path_str(def_id)); + }); + let cached = Rc::new(mir); + mir_cache.insert(def_id, cached.clone()); + CachedMir::Owned(cached) } } @@ -299,7 +292,7 @@ fn type_layout_with_substs(&self, ty: Ty<'tcx>, substs: &'tcx Substs<'tcx>) -> & // TODO(solson): Is this inefficient? Needs investigation. let ty = self.monomorphize(ty, substs); - self.tcx.normalizing_infer_ctxt(ProjectionMode::Any).enter(|infcx| { + self.tcx.normalizing_infer_ctxt(Reveal::All).enter(|infcx| { // TODO(solson): Report this error properly. ty.layout(&infcx).unwrap() }) @@ -755,7 +748,7 @@ fn eval_lvalue(&mut self, lvalue: &mir::Lvalue<'tcx>) -> EvalResult<'tcx, Lvalue Temp(i) => self.frame().locals[self.frame().temp_offset + i.index()], Static(def_id) => { - let substs = self.tcx.mk_substs(subst::Substs::empty()); + let substs = subst::Substs::empty(self.tcx); let cid = ConstantId { def_id: def_id, substs: substs, @@ -846,11 +839,11 @@ fn eval_lvalue(&mut self, lvalue: &mir::Lvalue<'tcx>) -> EvalResult<'tcx, Lvalue } fn lvalue_ty(&self, lvalue: &mir::Lvalue<'tcx>) -> Ty<'tcx> { - self.monomorphize(self.mir().lvalue_ty(self.tcx, lvalue).to_ty(self.tcx), self.substs()) + self.monomorphize(lvalue.ty(&self.mir(), self.tcx).to_ty(self.tcx), self.substs()) } fn operand_ty(&self, operand: &mir::Operand<'tcx>) -> Ty<'tcx> { - self.monomorphize(self.mir().operand_ty(self.tcx, operand), self.substs()) + self.monomorphize(operand.ty(&self.mir(), self.tcx), self.substs()) } fn move_(&mut self, src: Pointer, dest: Pointer, ty: Ty<'tcx>) -> EvalResult<'tcx, ()> { @@ -961,21 +954,19 @@ fn deref(&self) -> &mir::Mir<'tcx> { pub fn eval_main<'a, 'tcx: 'a>( tcx: TyCtxt<'a, 'tcx, 'tcx>, mir_map: &'a MirMap<'tcx>, - node_id: ast::NodeId, + def_id: DefId, memory_size: usize, step_limit: u64, stack_limit: usize, ) { - let mir = mir_map.map.get(&node_id).expect("no mir for main function"); - let def_id = tcx.map.local_def_id(node_id); + let mir = mir_map.map.get(&def_id).expect("no mir for main function"); let mut ecx = EvalContext::new(tcx, mir_map, memory_size, stack_limit); - let substs = tcx.mk_substs(subst::Substs::empty()); + let substs = subst::Substs::empty(tcx); let return_ptr = ecx.alloc_ret_ptr(mir.return_ty, substs) - .expect("should at least be able to allocate space for the main function's return value") - .expect("main function should not be diverging"); + .expect("should at least be able to allocate space for the main function's return value"); ecx.push_stack_frame(def_id, mir.span, CachedMir::Ref(mir), substs, Some(return_ptr)) - .expect("could not allocate first stack frame"); + .expect("could not allocate first stack frame"); if mir.arg_decls.len() == 2 { // start function @@ -1018,8 +1009,7 @@ fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) { struct Instance<'tcx>(DefId, &'tcx subst::Substs<'tcx>); impl<'tcx> fmt::Display for Instance<'tcx> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - ppaux::parameterized(f, self.1, self.0, ppaux::Ns::Value, &[], - |tcx| Some(tcx.lookup_item_type(self.0).generics)) + ppaux::parameterized(f, self.1, self.0, ppaux::Ns::Value, &[]) } } err.span_note(span, &format!("inside call to {}", Instance(def_id, substs))); diff --git a/src/interpreter/step.rs b/src/interpreter/step.rs index 5bfe85fff92..75dc7ee0941 100644 --- a/src/interpreter/step.rs +++ b/src/interpreter/step.rs @@ -66,8 +66,16 @@ pub fn step(&mut self) -> EvalResult<'tcx, bool> { fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> EvalResult<'tcx, ()> { trace!("{:?}", stmt); - let mir::StatementKind::Assign(ref lvalue, ref rvalue) = stmt.kind; - self.eval_assignment(lvalue, rvalue)?; + + use rustc::mir::repr::StatementKind::*; + match stmt.kind { + Assign(ref lvalue, ref rvalue) => self.eval_assignment(lvalue, rvalue)?, + SetDiscriminant { .. } => unimplemented!(), + + // Miri can safely ignore these. Only translation needs them. + StorageLive(_) | StorageDead(_) => {} + } + self.frame_mut().stmt += 1; Ok(()) } @@ -110,7 +118,6 @@ fn global_item(&mut self, def_id: DefId, substs: &'tcx subst::Substs<'tcx>, span let mir = self.ecx.load_mir(def_id); self.try(|this| { let ptr = this.ecx.alloc_ret_ptr(mir.return_ty, substs)?; - let ptr = ptr.expect("there's no such thing as an unreachable static"); this.ecx.statics.insert(cid.clone(), ptr); this.ecx.push_stack_frame(def_id, span, mir, substs, Some(ptr)) }); @@ -155,7 +162,6 @@ fn visit_constant(&mut self, constant: &mir::Constant<'tcx>) { let return_ty = mir.return_ty; self.try(|this| { let return_ptr = this.ecx.alloc_ret_ptr(return_ty, cid.substs)?; - let return_ptr = return_ptr.expect("there's no such thing as an unreachable static"); let mir = CachedMir::Owned(Rc::new(mir)); this.ecx.statics.insert(cid.clone(), return_ptr); this.ecx.push_stack_frame(this.def_id, constant.span, mir, this.substs, Some(return_ptr)) @@ -167,7 +173,7 @@ fn visit_constant(&mut self, constant: &mir::Constant<'tcx>) { fn visit_lvalue(&mut self, lvalue: &mir::Lvalue<'tcx>, context: LvalueContext) { self.super_lvalue(lvalue, context); if let mir::Lvalue::Static(def_id) = *lvalue { - let substs = self.ecx.tcx.mk_substs(subst::Substs::empty()); + let substs = subst::Substs::empty(self.ecx.tcx); let span = self.span; self.global_item(def_id, substs, span); } diff --git a/src/interpreter/terminator.rs b/src/interpreter/terminator.rs index 568d8358f08..b8f8b132088 100644 --- a/src/interpreter/terminator.rs +++ b/src/interpreter/terminator.rs @@ -1,9 +1,9 @@ use rustc::hir::def_id::DefId; use rustc::mir::repr as mir; -use rustc::traits::{self, ProjectionMode}; +use rustc::traits::{self, Reveal}; use rustc::ty::fold::TypeFoldable; use rustc::ty::layout::Layout; -use rustc::ty::subst::{self, Substs}; +use rustc::ty::subst::Substs; use rustc::ty::{self, Ty, TyCtxt, BareFnTy}; use std::rc::Rc; use std::iter; @@ -150,25 +150,16 @@ fn eval_fn_call( use syntax::abi::Abi; match fn_ty.abi { Abi::RustIntrinsic => { - let name = self.tcx.item_name(def_id).as_str(); - match fn_ty.sig.0.output { - ty::FnConverging(ty) => { - let layout = self.type_layout(ty); - let ret = return_ptr.unwrap(); - self.call_intrinsic(&name, substs, args, ret, layout) - } - ty::FnDiverging => unimplemented!(), - } + let ty = fn_ty.sig.0.output; + let layout = self.type_layout(ty); + let ret = return_ptr.unwrap(); + self.call_intrinsic(def_id, substs, args, ret, layout) } Abi::C => { - match fn_ty.sig.0.output { - ty::FnConverging(ty) => { - let size = self.type_size(ty); - self.call_c_abi(def_id, args, return_ptr.unwrap(), size) - } - ty::FnDiverging => unimplemented!(), - } + let ty = fn_ty.sig.0.output; + let size = self.type_size(ty); + self.call_c_abi(def_id, args, return_ptr.unwrap(), size) } Abi::Rust | Abi::RustCall => { @@ -176,11 +167,12 @@ fn eval_fn_call( // FnMut closure via FnOnce::call_once. // Only trait methods can have a Self parameter. - let (resolved_def_id, resolved_substs) = if substs.self_ty().is_some() { - self.trait_method(def_id, substs) - } else { - (def_id, substs) - }; + let (resolved_def_id, resolved_substs) = + if let Some(trait_id) = self.tcx.trait_of_item(def_id) { + self.trait_method(trait_id, def_id, substs) + } else { + (def_id, substs) + }; let mut arg_srcs = Vec::new(); for arg in args { @@ -265,7 +257,7 @@ fn read_nonnull_discriminant_value(&self, ptr: Pointer, nndiscr: u64) -> EvalRes fn call_intrinsic( &mut self, - name: &str, + def_id: DefId, substs: &'tcx Substs<'tcx>, args: &[mir::Operand<'tcx>], dest: Pointer, @@ -275,10 +267,9 @@ fn call_intrinsic( .map(|arg| self.eval_operand(arg)) .collect(); let args_ptrs = args_res?; - let pointer_size = self.memory.pointer_size(); - match name { + match &self.tcx.item_name(def_id).as_str()[..] { "add_with_overflow" => self.intrinsic_with_overflow(mir::BinOp::Add, &args[0], &args[1], dest, dest_layout)?, "sub_with_overflow" => self.intrinsic_with_overflow(mir::BinOp::Sub, &args[0], &args[1], dest, dest_layout)?, "mul_with_overflow" => self.intrinsic_with_overflow(mir::BinOp::Mul, &args[0], &args[1], dest, dest_layout)?, @@ -287,7 +278,7 @@ fn call_intrinsic( "assume" => {} "copy_nonoverlapping" => { - let elem_ty = *substs.types.get(subst::FnSpace, 0); + let elem_ty = substs.types[0]; let elem_size = self.type_size(elem_ty); let elem_align = self.type_align(elem_ty); let src = self.memory.read_ptr(args_ptrs[0])?; @@ -297,7 +288,7 @@ fn call_intrinsic( } "discriminant_value" => { - let ty = *substs.types.get(subst::FnSpace, 0); + let ty = substs.types[0]; let adt_ptr = self.memory.read_ptr(args_ptrs[0])?; let discr_val = self.read_discriminant_value(adt_ptr, ty)?; self.memory.write_uint(dest, discr_val, 8)?; @@ -308,19 +299,19 @@ fn call_intrinsic( "init" => self.memory.write_repeat(dest, 0, dest_layout.size(&self.tcx.data_layout).bytes() as usize)?, "min_align_of" => { - let elem_ty = *substs.types.get(subst::FnSpace, 0); + let elem_ty = substs.types[0]; let elem_align = self.type_align(elem_ty); self.memory.write_uint(dest, elem_align as u64, pointer_size)?; } "move_val_init" => { - let ty = *substs.types.get(subst::FnSpace, 0); + let ty = substs.types[0]; let ptr = self.memory.read_ptr(args_ptrs[0])?; self.move_(args_ptrs[1], ptr, ty)?; } "offset" => { - let pointee_ty = *substs.types.get(subst::FnSpace, 0); + let pointee_ty = substs.types[0]; let pointee_size = self.type_size(pointee_ty) as isize; let ptr_arg = args_ptrs[0]; let offset = self.memory.read_isize(args_ptrs[1])?; @@ -342,21 +333,23 @@ fn call_intrinsic( "overflowing_sub" => { self.intrinsic_overflowing(mir::BinOp::Sub, &args[0], &args[1], dest)?; } + "overflowing_mul" => { self.intrinsic_overflowing(mir::BinOp::Mul, &args[0], &args[1], dest)?; } + "overflowing_add" => { self.intrinsic_overflowing(mir::BinOp::Add, &args[0], &args[1], dest)?; } "size_of" => { - let ty = *substs.types.get(subst::FnSpace, 0); + let ty = substs.types[0]; let size = self.type_size(ty) as u64; self.memory.write_uint(dest, size, pointer_size)?; } "size_of_val" => { - let ty = *substs.types.get(subst::FnSpace, 0); + let ty = substs.types[0]; if self.type_is_sized(ty) { let size = self.type_size(ty) as u64; self.memory.write_uint(dest, size, pointer_size)?; @@ -376,7 +369,7 @@ fn call_intrinsic( } "transmute" => { - let ty = *substs.types.get(subst::FnSpace, 0); + let ty = substs.types[0]; self.move_(args_ptrs[0], dest, ty)?; } "uninit" => self.memory.mark_definedness(dest, dest_layout.size(&self.tcx.data_layout).bytes() as usize, false)?, @@ -464,7 +457,7 @@ fn call_c_abi( fn fulfill_obligation(&self, trait_ref: ty::PolyTraitRef<'tcx>) -> traits::Vtable<'tcx, ()> { // Do the initial selection for the obligation. This yields the shallow result we are // looking for -- that is, what specific impl. - self.tcx.normalizing_infer_ctxt(ProjectionMode::Any).enter(|infcx| { + self.tcx.normalizing_infer_ctxt(Reveal::All).enter(|infcx| { let mut selcx = traits::SelectionContext::new(&infcx); let obligation = traits::Obligation::new( @@ -486,21 +479,20 @@ fn fulfill_obligation(&self, trait_ref: ty::PolyTraitRef<'tcx>) -> traits::Vtabl /// Trait method, which has to be resolved to an impl method. fn trait_method( &self, + trait_id: DefId, def_id: DefId, substs: &'tcx Substs<'tcx> ) -> (DefId, &'tcx Substs<'tcx>) { - let method_item = self.tcx.impl_or_trait_item(def_id); - let trait_id = method_item.container().id(); - let trait_ref = ty::Binder(substs.to_trait_ref(self.tcx, trait_id)); + let trait_ref = ty::TraitRef::from_method(self.tcx, trait_id, substs); + let trait_ref = self.tcx.normalize_associated_type(&ty::Binder(trait_ref)); + match self.fulfill_obligation(trait_ref) { traits::VtableImpl(vtable_impl) => { let impl_did = vtable_impl.impl_def_id; let mname = self.tcx.item_name(def_id); // Create a concatenated set of substitutions which includes those from the impl // and those from the method: - let impl_substs = vtable_impl.substs.with_method_from(substs); - let substs = self.tcx.mk_substs(impl_substs); - let mth = get_impl_method(self.tcx, impl_did, substs, mname); + let mth = get_impl_method(self.tcx, substs, impl_did, vtable_impl.substs, mname); (mth.method.def_id, mth.substs) } @@ -573,8 +565,9 @@ struct ImplMethod<'tcx> { /// Locates the applicable definition of a method, given its name. fn get_impl_method<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, - impl_def_id: DefId, substs: &'tcx Substs<'tcx>, + impl_def_id: DefId, + impl_substs: &'tcx Substs<'tcx>, name: ast::Name, ) -> ImplMethod<'tcx> { assert!(!substs.types.needs_infer()); @@ -584,7 +577,8 @@ fn get_impl_method<'a, 'tcx>( match trait_def.ancestors(impl_def_id).fn_defs(tcx, name).next() { Some(node_item) => { - let substs = tcx.normalizing_infer_ctxt(ProjectionMode::Any).enter(|infcx| { + let substs = tcx.normalizing_infer_ctxt(Reveal::All).enter(|infcx| { + let substs = substs.rebase_onto(tcx, trait_def_id, impl_substs); let substs = traits::translate_substs(&infcx, impl_def_id, substs, node_item.node); tcx.lift(&substs).unwrap_or_else(|| { diff --git a/tests/compile-fail/cast_fn_ptr.rs b/tests/compile-fail/cast_fn_ptr.rs index db87e9e422b..f35aad87270 100644 --- a/tests/compile-fail/cast_fn_ptr.rs +++ b/tests/compile-fail/cast_fn_ptr.rs @@ -1,7 +1,7 @@ -fn main() { //~ ERROR tried to call a function of type +fn main() { fn f() {} - let g = unsafe { + let g = unsafe { //~ ERROR tried to call a function of type std::mem::transmute::(f) }; diff --git a/tests/compile-fail/execute_memory.rs b/tests/compile-fail/execute_memory.rs index 054f91b3cf9..c7d25a66315 100644 --- a/tests/compile-fail/execute_memory.rs +++ b/tests/compile-fail/execute_memory.rs @@ -1,10 +1,10 @@ #![feature(box_syntax)] -// FIXME: This span is wrong. -fn main() { //~ ERROR: tried to treat a memory pointer as a function pointer +fn main() { let x = box 42; unsafe { let f = std::mem::transmute::, fn()>(x); + //~^ ERROR: tried to treat a memory pointer as a function pointer f() } } -- 2.44.0