1
Fork 0

Use the new field init shorthand.

This commit is contained in:
Scott Olson 2017-01-16 18:45:30 -08:00
parent 267f4a124d
commit ac2bf50f9d
6 changed files with 35 additions and 76 deletions

View file

@ -129,7 +129,7 @@ impl Default for ResourceLimits {
impl<'a, 'tcx> EvalContext<'a, 'tcx> {
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, limits: ResourceLimits) -> Self {
EvalContext {
tcx: tcx,
tcx,
memory: Memory::new(&tcx.data_layout, limits.memory_size),
globals: HashMap::new(),
stack: Vec::new(),
@ -283,15 +283,15 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
let locals = vec![Value::ByVal(PrimVal::Undef); num_locals];
self.stack.push(Frame {
mir: mir,
mir,
block: mir::START_BLOCK,
return_to_block: return_to_block,
return_lvalue: return_lvalue,
locals: locals,
return_to_block,
return_lvalue,
locals,
interpreter_temporaries: temporaries,
span: span,
def_id: def_id,
substs: substs,
span,
def_id,
substs,
stmt: 0,
});
@ -764,11 +764,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
// function items are zero sized
Value::ByRef(self.memory.allocate(0, 0)?)
} else {
let cid = GlobalId {
def_id: def_id,
substs: substs,
promoted: None,
};
let cid = GlobalId { def_id, substs, promoted: None };
self.read_lvalue(Lvalue::Global(cid))
}
}

View file

@ -2,9 +2,10 @@
btree_range,
collections,
collections_bound,
field_init_shorthand,
i128_type,
pub_restricted,
rustc_private,
i128_type,
)]
// From rustc.

View file

@ -63,7 +63,7 @@ pub struct Global<'tcx> {
impl<'tcx> Lvalue<'tcx> {
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) {
@ -101,7 +101,7 @@ impl<'tcx> Global<'tcx> {
Global {
value: Value::ByVal(PrimVal::Undef),
mutable: true,
ty: ty,
ty,
}
}
}
@ -137,22 +137,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
use rustc::mir::Lvalue::*;
let lvalue = match *mir_lvalue {
Local(mir::RETURN_POINTER) => self.frame().return_lvalue,
Local(local) => {
Lvalue::Local {
frame: self.stack.len() - 1,
local: local,
}
}
Local(local) => Lvalue::Local { frame: self.stack.len() - 1, local },
Static(def_id) => {
let substs = self.tcx.intern_substs(&[]);
let cid = GlobalId {
def_id: def_id,
substs: substs,
promoted: None,
};
Lvalue::Global(cid)
Lvalue::Global(GlobalId { def_id, substs, promoted: None })
}
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> {

View file

@ -52,7 +52,7 @@ pub struct Pointer {
impl Pointer {
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 {
@ -133,7 +133,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
functions: HashMap::new(),
function_alloc_cache: HashMap::new(),
next_id: AllocId(2),
layout: layout,
layout,
memory_size: max_memory,
memory_usage: 0,
}
@ -151,7 +151,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
sig: fn_ty.sig,
});
self.create_fn_alloc(FunctionDefinition {
def_id: def_id,
def_id,
substs: substs.substs,
abi: fn_ty.abi,
// 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 {
self.create_fn_alloc(FunctionDefinition {
def_id: def_id,
substs: substs,
def_id,
substs,
abi: fn_ty.abi,
// FIXME: why doesn't this compile?
//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],
relocations: BTreeMap::new(),
undef_mask: UndefMask::new(size),
align: align,
align,
immutable: false,
};
let id = self.next_id;
@ -423,12 +423,9 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
return Ok(&[]);
}
let alloc = self.get(ptr.alloc_id)?;
if ptr.offset + size > alloc.bytes.len() as u64 {
return Err(EvalError::PointerOutOfBounds {
ptr: ptr,
size: size,
allocation_size: alloc.bytes.len() as u64,
});
let allocation_size = alloc.bytes.len() as u64;
if ptr.offset + size > allocation_size {
return Err(EvalError::PointerOutOfBounds { ptr, size, allocation_size });
}
assert_eq!(ptr.offset as usize as u64, ptr.offset);
assert_eq!(size as usize as u64, size);
@ -441,12 +438,9 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
return Ok(&mut []);
}
let alloc = self.get_mut(ptr.alloc_id)?;
if ptr.offset + size > alloc.bytes.len() as u64 {
return Err(EvalError::PointerOutOfBounds {
ptr: ptr,
size: size,
allocation_size: alloc.bytes.len() as u64,
});
let allocation_size = alloc.bytes.len() as u64;
if ptr.offset + size > allocation_size {
return Err(EvalError::PointerOutOfBounds { ptr, size, allocation_size });
}
assert_eq!(ptr.offset as usize as u64, ptr.offset);
assert_eq!(size as usize as u64, size);

View file

@ -47,10 +47,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
ecx: self,
mir: Ref::clone(&mir),
new_constants: &mut new,
}.visit_statement(block, stmt, mir::Location {
block: block,
statement_index: stmt_id,
});
}.visit_statement(block, stmt, mir::Location { block, statement_index: stmt_id });
if new? == 0 {
self.statement(stmt)?;
}
@ -68,10 +65,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
ecx: self,
mir: Ref::clone(&mir),
new_constants: &mut new,
}.visit_terminator(block, terminator, mir::Location {
block: block,
statement_index: stmt_id,
});
}.visit_terminator(block, terminator, mir::Location { block, statement_index: stmt_id });
if new? == 0 {
self.terminator(terminator)?;
}
@ -153,11 +147,7 @@ struct ConstantExtractor<'a, 'b: 'a, 'tcx: 'b> {
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) {
let cid = GlobalId {
def_id: def_id,
substs: substs,
promoted: None,
};
let cid = GlobalId { def_id, substs, promoted: None };
if self.ecx.globals.contains_key(&cid) {
return;
}

View file

@ -646,14 +646,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
ty::TyStr | ty::TySlice(_) => LvalueExtra::Length(extra.to_u64()?),
_ => bug!("invalid fat pointer type: {}", ty),
};
self.drop(
Lvalue::Ptr {
ptr: ptr,
extra: extra,
},
contents_ty,
drop,
)?;
self.drop(Lvalue::Ptr { ptr, extra }, contents_ty, drop)?;
},
}
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
// a drop impl
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?
@ -798,11 +791,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
if self.type_is_sized(field_ty) {
self.drop(Lvalue::from_ptr(ptr), field_ty, drop)?;
} else {
let lvalue = Lvalue::Ptr {
ptr: ptr,
extra: extra,
};
self.drop(lvalue, field_ty, drop)?;
self.drop(Lvalue::Ptr { ptr, extra }, field_ty, drop)?;
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 {
method: node_item.item,
substs: substs,
substs,
is_provided: node_item.node.is_from_trait(),
}
}