Remove Pointer::zero in favor of Pointer::from
This commit is contained in:
parent
d7324631ae
commit
3bbf2fd715
6 changed files with 16 additions and 21 deletions
|
|
@ -115,15 +115,18 @@ pub struct Pointer {
|
|||
pub offset: Size,
|
||||
}
|
||||
|
||||
/// Produces a `Pointer` which points to the beginning of the Allocation
|
||||
impl From<AllocId> for Pointer {
|
||||
fn from(alloc_id: AllocId) -> Self {
|
||||
Pointer::new(alloc_id, Size::ZERO)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Pointer {
|
||||
pub fn new(alloc_id: AllocId, offset: Size) -> Self {
|
||||
Pointer { alloc_id, offset }
|
||||
}
|
||||
|
||||
pub fn zero(alloc_id: AllocId) -> Self {
|
||||
Pointer::new(alloc_id, Size::ZERO)
|
||||
}
|
||||
|
||||
pub(crate) fn wrapping_signed_offset<C: HasDataLayout>(self, i: i64, cx: C) -> Self {
|
||||
Pointer::new(
|
||||
self.alloc_id,
|
||||
|
|
|
|||
|
|
@ -182,16 +182,14 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
|
|||
LitKind::Str(ref s, _) => {
|
||||
let s = s.as_str();
|
||||
let id = self.tcx.allocate_bytes(s.as_bytes());
|
||||
let ptr = Pointer::zero(id);
|
||||
ConstValue::ScalarPair(
|
||||
Scalar::Ptr(ptr),
|
||||
Scalar::Ptr(id.into()),
|
||||
Scalar::from_u128(s.len() as u128),
|
||||
)
|
||||
},
|
||||
LitKind::ByteStr(ref data) => {
|
||||
let id = self.tcx.allocate_bytes(data);
|
||||
let ptr = Pointer::zero(id);
|
||||
ConstValue::Scalar(ptr.into())
|
||||
ConstValue::Scalar(Scalar::Ptr(id.into()))
|
||||
},
|
||||
LitKind::Byte(n) => ConstValue::Scalar(Scalar::Bytes(n as u128)),
|
||||
LitKind::Int(n, _) if neg => {
|
||||
|
|
|
|||
|
|
@ -1128,16 +1128,14 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
|
|||
LitKind::Str(ref s, _) => {
|
||||
let s = s.as_str();
|
||||
let id = tcx.allocate_bytes(s.as_bytes());
|
||||
let ptr = Pointer::zero(id);
|
||||
ConstValue::ScalarPair(
|
||||
Scalar::Ptr(ptr),
|
||||
Scalar::Ptr(id.into()),
|
||||
Scalar::from_u128(s.len() as u128),
|
||||
)
|
||||
},
|
||||
LitKind::ByteStr(ref data) => {
|
||||
let id = tcx.allocate_bytes(data);
|
||||
let ptr = Pointer::zero(id);
|
||||
ConstValue::Scalar(ptr.into())
|
||||
ConstValue::Scalar(Scalar::Ptr(id.into()))
|
||||
},
|
||||
LitKind::Byte(n) => ConstValue::Scalar(Scalar::Bytes(n as u128)),
|
||||
LitKind::Int(n, _) => {
|
||||
|
|
|
|||
|
|
@ -1019,8 +1019,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
|
|||
.lock()
|
||||
.intern_static(gid.instance.def_id());
|
||||
let layout = self.layout_of(ty)?;
|
||||
let ptr = Pointer::zero(alloc_id);
|
||||
return Ok(Value::ByRef(ptr.into(), layout.align))
|
||||
return Ok(Value::ByRef(Scalar::Ptr(alloc_id.into()), layout.align))
|
||||
}
|
||||
let cv = self.const_eval(gid)?;
|
||||
self.const_to_value(&cv.val, ty)
|
||||
|
|
|
|||
|
|
@ -72,13 +72,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
|
|||
}
|
||||
|
||||
pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> Pointer {
|
||||
let id = self.tcx.alloc_map.lock().create_fn_alloc(instance);
|
||||
Pointer::zero(id)
|
||||
self.tcx.alloc_map.lock().create_fn_alloc(instance).into()
|
||||
}
|
||||
|
||||
pub fn allocate_bytes(&mut self, bytes: &[u8]) -> Pointer {
|
||||
let id = self.tcx.allocate_bytes(bytes);
|
||||
Pointer::zero(id)
|
||||
self.tcx.allocate_bytes(bytes).into()
|
||||
}
|
||||
|
||||
/// kind is `None` for statics
|
||||
|
|
@ -109,8 +107,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
|
|||
align: Align,
|
||||
kind: Option<MemoryKind<M::MemoryKinds>>,
|
||||
) -> EvalResult<'tcx, Pointer> {
|
||||
let id = self.allocate_value(Allocation::undef(size, align), kind)?;
|
||||
Ok(Pointer::zero(id))
|
||||
self.allocate_value(Allocation::undef(size, align), kind).map(Pointer::from)
|
||||
}
|
||||
|
||||
pub fn reallocate(
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
|
|||
};
|
||||
let alloc = Machine::init_static(self, cid)?;
|
||||
Place::Ptr {
|
||||
ptr: Pointer::zero(alloc).into(),
|
||||
ptr: Scalar::Ptr(alloc.into()),
|
||||
align: layout.align,
|
||||
extra: PlaceExtra::None,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue