Use the new field init shorthand.
This commit is contained in:
parent
267f4a124d
commit
ac2bf50f9d
6 changed files with 35 additions and 76 deletions
|
@ -129,7 +129,7 @@ impl Default for ResourceLimits {
|
||||||
impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, limits: ResourceLimits) -> Self {
|
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, limits: ResourceLimits) -> Self {
|
||||||
EvalContext {
|
EvalContext {
|
||||||
tcx: tcx,
|
tcx,
|
||||||
memory: Memory::new(&tcx.data_layout, limits.memory_size),
|
memory: Memory::new(&tcx.data_layout, limits.memory_size),
|
||||||
globals: HashMap::new(),
|
globals: HashMap::new(),
|
||||||
stack: Vec::new(),
|
stack: Vec::new(),
|
||||||
|
@ -283,15 +283,15 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
let locals = vec![Value::ByVal(PrimVal::Undef); num_locals];
|
let locals = vec![Value::ByVal(PrimVal::Undef); num_locals];
|
||||||
|
|
||||||
self.stack.push(Frame {
|
self.stack.push(Frame {
|
||||||
mir: mir,
|
mir,
|
||||||
block: mir::START_BLOCK,
|
block: mir::START_BLOCK,
|
||||||
return_to_block: return_to_block,
|
return_to_block,
|
||||||
return_lvalue: return_lvalue,
|
return_lvalue,
|
||||||
locals: locals,
|
locals,
|
||||||
interpreter_temporaries: temporaries,
|
interpreter_temporaries: temporaries,
|
||||||
span: span,
|
span,
|
||||||
def_id: def_id,
|
def_id,
|
||||||
substs: substs,
|
substs,
|
||||||
stmt: 0,
|
stmt: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -764,11 +764,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
// function items are zero sized
|
// function items are zero sized
|
||||||
Value::ByRef(self.memory.allocate(0, 0)?)
|
Value::ByRef(self.memory.allocate(0, 0)?)
|
||||||
} else {
|
} else {
|
||||||
let cid = GlobalId {
|
let cid = GlobalId { def_id, substs, promoted: None };
|
||||||
def_id: def_id,
|
|
||||||
substs: substs,
|
|
||||||
promoted: None,
|
|
||||||
};
|
|
||||||
self.read_lvalue(Lvalue::Global(cid))
|
self.read_lvalue(Lvalue::Global(cid))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
btree_range,
|
btree_range,
|
||||||
collections,
|
collections,
|
||||||
collections_bound,
|
collections_bound,
|
||||||
|
field_init_shorthand,
|
||||||
|
i128_type,
|
||||||
pub_restricted,
|
pub_restricted,
|
||||||
rustc_private,
|
rustc_private,
|
||||||
i128_type,
|
|
||||||
)]
|
)]
|
||||||
|
|
||||||
// From rustc.
|
// From rustc.
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub struct Global<'tcx> {
|
||||||
|
|
||||||
impl<'tcx> Lvalue<'tcx> {
|
impl<'tcx> Lvalue<'tcx> {
|
||||||
pub fn from_ptr(ptr: Pointer) -> Self {
|
pub fn from_ptr(ptr: Pointer) -> Self {
|
||||||
Lvalue::Ptr { ptr: ptr, extra: LvalueExtra::None }
|
Lvalue::Ptr { ptr, extra: LvalueExtra::None }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn to_ptr_and_extra(self) -> (Pointer, LvalueExtra) {
|
pub(super) fn to_ptr_and_extra(self) -> (Pointer, LvalueExtra) {
|
||||||
|
@ -101,7 +101,7 @@ impl<'tcx> Global<'tcx> {
|
||||||
Global {
|
Global {
|
||||||
value: Value::ByVal(PrimVal::Undef),
|
value: Value::ByVal(PrimVal::Undef),
|
||||||
mutable: true,
|
mutable: true,
|
||||||
ty: ty,
|
ty,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,22 +137,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
use rustc::mir::Lvalue::*;
|
use rustc::mir::Lvalue::*;
|
||||||
let lvalue = match *mir_lvalue {
|
let lvalue = match *mir_lvalue {
|
||||||
Local(mir::RETURN_POINTER) => self.frame().return_lvalue,
|
Local(mir::RETURN_POINTER) => self.frame().return_lvalue,
|
||||||
|
Local(local) => Lvalue::Local { frame: self.stack.len() - 1, local },
|
||||||
Local(local) => {
|
|
||||||
Lvalue::Local {
|
|
||||||
frame: self.stack.len() - 1,
|
|
||||||
local: local,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Static(def_id) => {
|
Static(def_id) => {
|
||||||
let substs = self.tcx.intern_substs(&[]);
|
let substs = self.tcx.intern_substs(&[]);
|
||||||
let cid = GlobalId {
|
Lvalue::Global(GlobalId { def_id, substs, promoted: None })
|
||||||
def_id: def_id,
|
|
||||||
substs: substs,
|
|
||||||
promoted: None,
|
|
||||||
};
|
|
||||||
Lvalue::Global(cid)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Projection(ref proj) => return self.eval_lvalue_projection(proj),
|
Projection(ref proj) => return self.eval_lvalue_projection(proj),
|
||||||
|
@ -321,7 +310,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Lvalue::Ptr { ptr: ptr, extra: extra })
|
Ok(Lvalue::Ptr { ptr, extra })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn lvalue_ty(&self, lvalue: &mir::Lvalue<'tcx>) -> Ty<'tcx> {
|
pub(super) fn lvalue_ty(&self, lvalue: &mir::Lvalue<'tcx>) -> Ty<'tcx> {
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub struct Pointer {
|
||||||
|
|
||||||
impl Pointer {
|
impl Pointer {
|
||||||
pub fn new(alloc_id: AllocId, offset: u64) -> Self {
|
pub fn new(alloc_id: AllocId, offset: u64) -> Self {
|
||||||
Pointer { alloc_id: alloc_id, offset: offset }
|
Pointer { alloc_id, offset }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn signed_offset(self, i: i64) -> Self {
|
pub fn signed_offset(self, i: i64) -> Self {
|
||||||
|
@ -133,7 +133,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
||||||
functions: HashMap::new(),
|
functions: HashMap::new(),
|
||||||
function_alloc_cache: HashMap::new(),
|
function_alloc_cache: HashMap::new(),
|
||||||
next_id: AllocId(2),
|
next_id: AllocId(2),
|
||||||
layout: layout,
|
layout,
|
||||||
memory_size: max_memory,
|
memory_size: max_memory,
|
||||||
memory_usage: 0,
|
memory_usage: 0,
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
||||||
sig: fn_ty.sig,
|
sig: fn_ty.sig,
|
||||||
});
|
});
|
||||||
self.create_fn_alloc(FunctionDefinition {
|
self.create_fn_alloc(FunctionDefinition {
|
||||||
def_id: def_id,
|
def_id,
|
||||||
substs: substs.substs,
|
substs: substs.substs,
|
||||||
abi: fn_ty.abi,
|
abi: fn_ty.abi,
|
||||||
// FIXME: why doesn't this compile?
|
// FIXME: why doesn't this compile?
|
||||||
|
@ -162,8 +162,8 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
||||||
|
|
||||||
pub fn create_fn_ptr(&mut self, _tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, substs: &'tcx Substs<'tcx>, fn_ty: &'tcx BareFnTy<'tcx>) -> Pointer {
|
pub fn create_fn_ptr(&mut self, _tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, substs: &'tcx Substs<'tcx>, fn_ty: &'tcx BareFnTy<'tcx>) -> Pointer {
|
||||||
self.create_fn_alloc(FunctionDefinition {
|
self.create_fn_alloc(FunctionDefinition {
|
||||||
def_id: def_id,
|
def_id,
|
||||||
substs: substs,
|
substs,
|
||||||
abi: fn_ty.abi,
|
abi: fn_ty.abi,
|
||||||
// FIXME: why doesn't this compile?
|
// FIXME: why doesn't this compile?
|
||||||
//sig: tcx.erase_late_bound_regions(&fn_ty.sig),
|
//sig: tcx.erase_late_bound_regions(&fn_ty.sig),
|
||||||
|
@ -202,7 +202,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
||||||
bytes: vec![0; size as usize],
|
bytes: vec![0; size as usize],
|
||||||
relocations: BTreeMap::new(),
|
relocations: BTreeMap::new(),
|
||||||
undef_mask: UndefMask::new(size),
|
undef_mask: UndefMask::new(size),
|
||||||
align: align,
|
align,
|
||||||
immutable: false,
|
immutable: false,
|
||||||
};
|
};
|
||||||
let id = self.next_id;
|
let id = self.next_id;
|
||||||
|
@ -423,12 +423,9 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
||||||
return Ok(&[]);
|
return Ok(&[]);
|
||||||
}
|
}
|
||||||
let alloc = self.get(ptr.alloc_id)?;
|
let alloc = self.get(ptr.alloc_id)?;
|
||||||
if ptr.offset + size > alloc.bytes.len() as u64 {
|
let allocation_size = alloc.bytes.len() as u64;
|
||||||
return Err(EvalError::PointerOutOfBounds {
|
if ptr.offset + size > allocation_size {
|
||||||
ptr: ptr,
|
return Err(EvalError::PointerOutOfBounds { ptr, size, allocation_size });
|
||||||
size: size,
|
|
||||||
allocation_size: alloc.bytes.len() as u64,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
assert_eq!(ptr.offset as usize as u64, ptr.offset);
|
assert_eq!(ptr.offset as usize as u64, ptr.offset);
|
||||||
assert_eq!(size as usize as u64, size);
|
assert_eq!(size as usize as u64, size);
|
||||||
|
@ -441,12 +438,9 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
||||||
return Ok(&mut []);
|
return Ok(&mut []);
|
||||||
}
|
}
|
||||||
let alloc = self.get_mut(ptr.alloc_id)?;
|
let alloc = self.get_mut(ptr.alloc_id)?;
|
||||||
if ptr.offset + size > alloc.bytes.len() as u64 {
|
let allocation_size = alloc.bytes.len() as u64;
|
||||||
return Err(EvalError::PointerOutOfBounds {
|
if ptr.offset + size > allocation_size {
|
||||||
ptr: ptr,
|
return Err(EvalError::PointerOutOfBounds { ptr, size, allocation_size });
|
||||||
size: size,
|
|
||||||
allocation_size: alloc.bytes.len() as u64,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
assert_eq!(ptr.offset as usize as u64, ptr.offset);
|
assert_eq!(ptr.offset as usize as u64, ptr.offset);
|
||||||
assert_eq!(size as usize as u64, size);
|
assert_eq!(size as usize as u64, size);
|
||||||
|
|
16
src/step.rs
16
src/step.rs
|
@ -47,10 +47,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
ecx: self,
|
ecx: self,
|
||||||
mir: Ref::clone(&mir),
|
mir: Ref::clone(&mir),
|
||||||
new_constants: &mut new,
|
new_constants: &mut new,
|
||||||
}.visit_statement(block, stmt, mir::Location {
|
}.visit_statement(block, stmt, mir::Location { block, statement_index: stmt_id });
|
||||||
block: block,
|
|
||||||
statement_index: stmt_id,
|
|
||||||
});
|
|
||||||
if new? == 0 {
|
if new? == 0 {
|
||||||
self.statement(stmt)?;
|
self.statement(stmt)?;
|
||||||
}
|
}
|
||||||
|
@ -68,10 +65,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
ecx: self,
|
ecx: self,
|
||||||
mir: Ref::clone(&mir),
|
mir: Ref::clone(&mir),
|
||||||
new_constants: &mut new,
|
new_constants: &mut new,
|
||||||
}.visit_terminator(block, terminator, mir::Location {
|
}.visit_terminator(block, terminator, mir::Location { block, statement_index: stmt_id });
|
||||||
block: block,
|
|
||||||
statement_index: stmt_id,
|
|
||||||
});
|
|
||||||
if new? == 0 {
|
if new? == 0 {
|
||||||
self.terminator(terminator)?;
|
self.terminator(terminator)?;
|
||||||
}
|
}
|
||||||
|
@ -153,11 +147,7 @@ struct ConstantExtractor<'a, 'b: 'a, 'tcx: 'b> {
|
||||||
|
|
||||||
impl<'a, 'b, 'tcx> ConstantExtractor<'a, 'b, 'tcx> {
|
impl<'a, 'b, 'tcx> ConstantExtractor<'a, 'b, 'tcx> {
|
||||||
fn global_item(&mut self, def_id: DefId, substs: &'tcx subst::Substs<'tcx>, span: Span, immutable: bool) {
|
fn global_item(&mut self, def_id: DefId, substs: &'tcx subst::Substs<'tcx>, span: Span, immutable: bool) {
|
||||||
let cid = GlobalId {
|
let cid = GlobalId { def_id, substs, promoted: None };
|
||||||
def_id: def_id,
|
|
||||||
substs: substs,
|
|
||||||
promoted: None,
|
|
||||||
};
|
|
||||||
if self.ecx.globals.contains_key(&cid) {
|
if self.ecx.globals.contains_key(&cid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -646,14 +646,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
ty::TyStr | ty::TySlice(_) => LvalueExtra::Length(extra.to_u64()?),
|
ty::TyStr | ty::TySlice(_) => LvalueExtra::Length(extra.to_u64()?),
|
||||||
_ => bug!("invalid fat pointer type: {}", ty),
|
_ => bug!("invalid fat pointer type: {}", ty),
|
||||||
};
|
};
|
||||||
self.drop(
|
self.drop(Lvalue::Ptr { ptr, extra }, contents_ty, drop)?;
|
||||||
Lvalue::Ptr {
|
|
||||||
ptr: ptr,
|
|
||||||
extra: extra,
|
|
||||||
},
|
|
||||||
contents_ty,
|
|
||||||
drop,
|
|
||||||
)?;
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
let box_free_fn = self.tcx.lang_items.box_free_fn().expect("no box_free lang item");
|
let box_free_fn = self.tcx.lang_items.box_free_fn().expect("no box_free lang item");
|
||||||
|
@ -771,7 +764,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
// FIXME: this creates a lot of stack frames if the element type has
|
// FIXME: this creates a lot of stack frames if the element type has
|
||||||
// a drop impl
|
// a drop impl
|
||||||
for i in 0..(len as u64) {
|
for i in 0..(len as u64) {
|
||||||
self.drop(Lvalue::Ptr { ptr: ptr.offset(i * size), extra: extra }, elem_ty, drop)?;
|
self.drop(Lvalue::Ptr { ptr: ptr.offset(i * size), extra }, elem_ty, drop)?;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// FIXME: what about TyClosure and TyAnon?
|
// FIXME: what about TyClosure and TyAnon?
|
||||||
|
@ -798,11 +791,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
if self.type_is_sized(field_ty) {
|
if self.type_is_sized(field_ty) {
|
||||||
self.drop(Lvalue::from_ptr(ptr), field_ty, drop)?;
|
self.drop(Lvalue::from_ptr(ptr), field_ty, drop)?;
|
||||||
} else {
|
} else {
|
||||||
let lvalue = Lvalue::Ptr {
|
self.drop(Lvalue::Ptr { ptr, extra }, field_ty, drop)?;
|
||||||
ptr: ptr,
|
|
||||||
extra: extra,
|
|
||||||
};
|
|
||||||
self.drop(lvalue, field_ty, drop)?;
|
|
||||||
break; // if it is not sized, then this is the last field anyway
|
break; // if it is not sized, then this is the last field anyway
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -845,7 +834,7 @@ pub(super) fn get_impl_method<'a, 'tcx>(
|
||||||
});
|
});
|
||||||
ImplMethod {
|
ImplMethod {
|
||||||
method: node_item.item,
|
method: node_item.item,
|
||||||
substs: substs,
|
substs,
|
||||||
is_provided: node_item.node.is_from_trait(),
|
is_provided: node_item.node.is_from_trait(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue