提交 9e4e6cdb 编写于 作者: O Oliver Schneider

Dropping arrays works again

上级 7c12ebc7
......@@ -16,6 +16,7 @@
use syntax::codemap::{self, DUMMY_SP, Span};
use syntax::ast;
use syntax::abi::Abi;
use syntax::symbol::Symbol;
use error::{EvalError, EvalResult};
use lvalue::{Global, GlobalId, Lvalue, LvalueExtra};
......@@ -231,7 +232,7 @@ pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, limits: ResourceLimits) -> Self {
span: DUMMY_SP,
ty: tcx.types.usize,
literal: mir::Literal::Value {
value: ConstVal::Integral(ConstInt::Usize(ConstUsize::new(0, tcx.sess.target.uint_type).unwrap())),
value: ConstVal::Integral(ConstInt::Usize(ConstUsize::new(1, tcx.sess.target.uint_type).unwrap())),
},
}),
)
......@@ -262,7 +263,7 @@ pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, limits: ResourceLimits) -> Self {
},
mir::LocalDecl {
mutability: mir::Mutability::Mut,
ty: tcx.mk_mut_ptr(tcx.mk_self_type()),
ty: tcx.mk_mut_ptr(tcx.mk_slice(tcx.mk_param(0, Symbol::intern("T")))),
name: None,
source_info: None,
},
......
......@@ -2,6 +2,7 @@
use rustc::mir;
use rustc::ty::{self, Ty};
use rustc::ty::layout::Layout;
use rustc::ty::subst::Kind;
use syntax::codemap::Span;
use syntax::attr;
use syntax::abi::Abi;
......@@ -76,24 +77,36 @@ pub(super) fn eval_terminator(
}
Drop { ref location, target, .. } => {
trace!("TerminatorKind::drop: {:?}, {:?}", location, self.substs());
let lval = self.eval_lvalue(location)?;
trace!("drop lval: {:#?}", lval);
let src_ptr = self.force_allocation(lval)?.to_ptr();
let ty = self.lvalue_ty(location);
self.goto_block(target);
let ty = ::eval_context::apply_param_substs(self.tcx, self.substs(), &ty);
self.goto_block(target);
let instance = ::eval_context::resolve_drop_in_place(self.tcx, ty);
let mut instance = ::eval_context::resolve_drop_in_place(self.tcx, ty);
if let ty::InstanceDef::DropGlue(_, None) = instance.def {
// we don't actually need to drop anything
return Ok(());
}
let arg;
let mir = match ty.sty {
ty::TyDynamic(..) => unimplemented!(),
ty::TyArray(..) | ty::TySlice(..) => ::eval_context::MirRef::clone(&self.seq_drop_glue),
_ => self.load_mir(instance.def)?,
ty::TyArray(elem, n) => {
instance.substs = self.tcx.mk_substs([
Kind::from(elem),
].iter().cloned());
arg = Value::ByValPair(PrimVal::Ptr(src_ptr), PrimVal::Bytes(n as u128));
::eval_context::MirRef::clone(&self.seq_drop_glue)
},
ty::TySlice(ref elem) => unimplemented!(),
_ => {
arg = Value::ByVal(PrimVal::Ptr(src_ptr));
self.load_mir(instance.def)?
},
};
self.push_stack_frame(
......@@ -109,7 +122,7 @@ pub(super) fn eval_terminator(
let arg_local = arg_locals.next().unwrap();
let dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?;
let arg_ty = self.tcx.mk_mut_ptr(ty);
self.write_value(Value::ByVal(PrimVal::Ptr(src_ptr)), dest, arg_ty)?;
self.write_value(arg, dest, arg_ty)?;
}
Assert { ref cond, expected, ref msg, target, .. } => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册