1
Fork 0

Replace Scalar::zst with a Scalar::ZST constant

This commit is contained in:
oli 2020-11-01 17:04:13 +00:00
parent b8751c1fbb
commit 8282d526e0
5 changed files with 7 additions and 10 deletions

View file

@ -178,10 +178,7 @@ impl<'tcx, Tag> Scalar<Tag> {
Scalar::Int(ScalarInt::null(cx.data_layout().pointer_size)) Scalar::Int(ScalarInt::null(cx.data_layout().pointer_size))
} }
#[inline] pub const ZST: Self = Scalar::Int(ScalarInt::ZST);
pub fn zst() -> Self {
Scalar::Int(ScalarInt::ZST)
}
#[inline(always)] #[inline(always)]
fn ptr_op( fn ptr_op(

View file

@ -132,7 +132,7 @@ impl<'tcx> Const<'tcx> {
#[inline] #[inline]
/// Creates an interned zst constant. /// Creates an interned zst constant.
pub fn zero_sized(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> &'tcx Self { pub fn zero_sized(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> &'tcx Self {
Self::from_scalar(tcx, Scalar::zst(), ty) Self::from_scalar(tcx, Scalar::ZST, ty)
} }
#[inline] #[inline]

View file

@ -844,7 +844,7 @@ impl<'tcx> CommonConsts<'tcx> {
CommonConsts { CommonConsts {
unit: mk_const(ty::Const { unit: mk_const(ty::Const {
val: ty::ConstKind::Value(ConstValue::Scalar(Scalar::zst())), val: ty::ConstKind::Value(ConstValue::Scalar(Scalar::ZST)),
ty: types.unit, ty: types.unit,
}), }),
} }

View file

@ -146,7 +146,7 @@ pub(super) fn op_to_const<'tcx>(
"this MPlaceTy must come from a validated constant, thus we can assume the \ "this MPlaceTy must come from a validated constant, thus we can assume the \
alignment is correct", alignment is correct",
); );
ConstValue::Scalar(Scalar::zst()) ConstValue::Scalar(Scalar::ZST)
} }
}; };
match immediate { match immediate {

View file

@ -259,7 +259,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
} }
return Ok(Some(ImmTy { return Ok(Some(ImmTy {
// zero-sized type // zero-sized type
imm: Scalar::zst().into(), imm: Scalar::ZST.into(),
layout: mplace.layout, layout: mplace.layout,
})); }));
} }
@ -358,7 +358,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let field_layout = op.layout.field(self, field)?; let field_layout = op.layout.field(self, field)?;
if field_layout.is_zst() { if field_layout.is_zst() {
let immediate = Scalar::zst().into(); let immediate = Scalar::ZST.into();
return Ok(OpTy { op: Operand::Immediate(immediate), layout: field_layout }); return Ok(OpTy { op: Operand::Immediate(immediate), layout: field_layout });
} }
let offset = op.layout.fields.offset(field); let offset = op.layout.fields.offset(field);
@ -443,7 +443,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let layout = self.layout_of_local(frame, local, layout)?; let layout = self.layout_of_local(frame, local, layout)?;
let op = if layout.is_zst() { let op = if layout.is_zst() {
// Do not read from ZST, they might not be initialized // Do not read from ZST, they might not be initialized
Operand::Immediate(Scalar::zst().into()) Operand::Immediate(Scalar::ZST.into())
} else { } else {
M::access_local(&self, frame, local)? M::access_local(&self, frame, local)?
}; };