From a5baea64af47147258a1cad1cc54ebce1524eb83 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 24 Aug 2018 14:44:30 +0200 Subject: [PATCH] terminator/drop.rs is just one fn... merge it together with the other terminator stuff --- .../{terminator/mod.rs => terminator.rs} | 49 ++++++++++++++- src/librustc_mir/interpret/terminator/drop.rs | 63 ------------------- 2 files changed, 46 insertions(+), 66 deletions(-) rename src/librustc_mir/interpret/{terminator/mod.rs => terminator.rs} (91%) delete mode 100644 src/librustc_mir/interpret/terminator/drop.rs diff --git a/src/librustc_mir/interpret/terminator/mod.rs b/src/librustc_mir/interpret/terminator.rs similarity index 91% rename from src/librustc_mir/interpret/terminator/mod.rs rename to src/librustc_mir/interpret/terminator.rs index 5ec7313eb5f..c6651620576 100644 --- a/src/librustc_mir/interpret/terminator/mod.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -16,11 +16,9 @@ use rustc::mir::interpret::{EvalResult, Scalar}; use super::{ - EvalContext, Machine, Value, OpTy, Place, PlaceTy, ValTy, Operand, StackPopCleanup + EvalContext, Machine, Value, OpTy, Place, PlaceTy, PlaceExtra, ValTy, Operand, StackPopCleanup }; -mod drop; - impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> { #[inline] pub fn goto_block(&mut self, target: Option) -> EvalResult<'tcx> { @@ -442,4 +440,49 @@ fn eval_fn_call( } } } + + fn drop_in_place( + &mut self, + place: PlaceTy<'tcx>, + instance: ty::Instance<'tcx>, + span: Span, + target: mir::BasicBlock, + ) -> EvalResult<'tcx> { + trace!("drop_in_place: {:?},\n {:?}, {:?}", *place, place.layout.ty, instance); + // We take the address of the object. This may well be unaligned, which is fine + // for us here. However, unaligned accesses will probably make the actual drop + // implementation fail -- a problem shared by rustc. + let place = self.force_allocation(place)?; + + let (instance, place) = match place.layout.ty.sty { + ty::Dynamic(..) => { + // Dropping a trait object. + let vtable = match place.extra { + PlaceExtra::Vtable(vtable) => vtable, + _ => bug!("Expected vtable when dropping {:#?}", place), + }; + let place = self.unpack_unsized_mplace(place)?; + let instance = self.read_drop_type_from_vtable(vtable)?; + (instance, place) + } + _ => (instance, place), + }; + + let arg = OpTy { + op: Operand::Immediate(place.to_ref(&self)), + layout: self.layout_of(self.tcx.mk_mut_ptr(place.layout.ty))?, + }; + + let ty = self.tcx.mk_tup((&[] as &[ty::Ty<'tcx>]).iter()); // return type is () + let dest = PlaceTy::null(&self, self.layout_of(ty)?); + + self.eval_fn_call( + instance, + &[arg], + Some(dest), + Some(target), + span, + None, + ) + } } diff --git a/src/librustc_mir/interpret/terminator/drop.rs b/src/librustc_mir/interpret/terminator/drop.rs deleted file mode 100644 index e592f1e5d5a..00000000000 --- a/src/librustc_mir/interpret/terminator/drop.rs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use rustc::mir::BasicBlock; -use rustc::ty::{self, layout::LayoutOf}; -use syntax::source_map::Span; - -use rustc::mir::interpret::EvalResult; -use interpret::{Machine, EvalContext, PlaceTy, PlaceExtra, OpTy, Operand}; - -impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> { - pub(crate) fn drop_in_place( - &mut self, - place: PlaceTy<'tcx>, - instance: ty::Instance<'tcx>, - span: Span, - target: BasicBlock, - ) -> EvalResult<'tcx> { - trace!("drop_in_place: {:?},\n {:?}, {:?}", *place, place.layout.ty, instance); - // We take the address of the object. This may well be unaligned, which is fine for us - // here. However, unaligned accesses will probably make the actual drop implementation fail - // -- a problem shared by rustc. - let place = self.force_allocation(place)?; - - let (instance, place) = match place.layout.ty.sty { - ty::Dynamic(..) => { - // Dropping a trait object. - let vtable = match place.extra { - PlaceExtra::Vtable(vtable) => vtable, - _ => bug!("Expected vtable when dropping {:#?}", place), - }; - let place = self.unpack_unsized_mplace(place)?; - let instance = self.read_drop_type_from_vtable(vtable)?; - (instance, place) - } - _ => (instance, place), - }; - - let arg = OpTy { - op: Operand::Immediate(place.to_ref(&self)), - layout: self.layout_of(self.tcx.mk_mut_ptr(place.layout.ty))?, - }; - - let ty = self.tcx.mk_tup((&[] as &[ty::Ty<'tcx>]).iter()); // return type is () - let dest = PlaceTy::null(&self, self.layout_of(ty)?); - - self.eval_fn_call( - instance, - &[arg], - Some(dest), - Some(target), - span, - None, - ) - } -} -- GitLab