1
Fork 0

give it a scary name

This commit is contained in:
Ralf Jung 2022-05-05 09:55:38 +02:00
parent 5b20da8180
commit e47d6c7a6b
5 changed files with 17 additions and 14 deletions

View file

@ -252,7 +252,9 @@ impl<'tcx, Tag: Provenance> ImmTy<'tcx, Tag> {
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
/// Try reading an immediate in memory; this is interesting particularly for `ScalarPair`. /// Try reading an immediate in memory; this is interesting particularly for `ScalarPair`.
/// Returns `None` if the layout does not permit loading this as a value. /// Returns `None` if the layout does not permit loading this as a value.
fn try_read_immediate_from_mplace( ///
/// This is an internal function; call `read_immediate` instead.
fn read_immediate_from_mplace_raw(
&self, &self,
mplace: &MPlaceTy<'tcx, M::PointerTag>, mplace: &MPlaceTy<'tcx, M::PointerTag>,
force: bool, force: bool,
@ -312,9 +314,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
return Ok(None); return Ok(None);
} }
/// Try returning an immediate for the operand. /// Try returning an immediate for the operand. If the layout does not permit loading this as an
/// If the layout does not permit loading this as an immediate, return where in memory /// immediate, return where in memory we can find the data.
/// we can find the data.
/// Note that for a given layout, this operation will either always fail or always /// Note that for a given layout, this operation will either always fail or always
/// succeed! Whether it succeeds depends on whether the layout can be represented /// succeed! Whether it succeeds depends on whether the layout can be represented
/// in an `Immediate`, not on which data is stored there currently. /// in an `Immediate`, not on which data is stored there currently.
@ -322,14 +323,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
/// If `force` is `true`, then even scalars with fields that can be ununit will be /// If `force` is `true`, then even scalars with fields that can be ununit will be
/// read. This means the load is lossy and should not be written back! /// read. This means the load is lossy and should not be written back!
/// This flag exists only for validity checking. /// This flag exists only for validity checking.
pub fn try_read_immediate( ///
/// This is an internal function that should not usually be used; call `read_immediate` instead.
pub fn read_immediate_raw(
&self, &self,
src: &OpTy<'tcx, M::PointerTag>, src: &OpTy<'tcx, M::PointerTag>,
force: bool, force: bool,
) -> InterpResult<'tcx, Result<ImmTy<'tcx, M::PointerTag>, MPlaceTy<'tcx, M::PointerTag>>> { ) -> InterpResult<'tcx, Result<ImmTy<'tcx, M::PointerTag>, MPlaceTy<'tcx, M::PointerTag>>> {
Ok(match src.try_as_mplace() { Ok(match src.try_as_mplace() {
Ok(ref mplace) => { Ok(ref mplace) => {
if let Some(val) = self.try_read_immediate_from_mplace(mplace, force)? { if let Some(val) = self.read_immediate_from_mplace_raw(mplace, force)? {
Ok(val) Ok(val)
} else { } else {
Err(*mplace) Err(*mplace)
@ -345,7 +348,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
&self, &self,
op: &OpTy<'tcx, M::PointerTag>, op: &OpTy<'tcx, M::PointerTag>,
) -> InterpResult<'tcx, ImmTy<'tcx, M::PointerTag>> { ) -> InterpResult<'tcx, ImmTy<'tcx, M::PointerTag>> {
if let Ok(imm) = self.try_read_immediate(op, /*force*/ false)? { if let Ok(imm) = self.read_immediate_raw(op, /*force*/ false)? {
Ok(imm) Ok(imm)
} else { } else {
span_bug!(self.cur_span(), "primitive read failed for type: {:?}", op.layout.ty); span_bug!(self.cur_span(), "primitive read failed for type: {:?}", op.layout.ty);

View file

@ -720,7 +720,7 @@ where
} }
trace!("write_immediate: {:?} <- {:?}: {}", *dest, src, dest.layout.ty); trace!("write_immediate: {:?} <- {:?}: {}", *dest, src, dest.layout.ty);
// See if we can avoid an allocation. This is the counterpart to `try_read_immediate`, // See if we can avoid an allocation. This is the counterpart to `read_immediate_raw`,
// but not factored as a separate function. // but not factored as a separate function.
let mplace = match dest.place { let mplace = match dest.place {
Place::Local { frame, local } => { Place::Local { frame, local } => {
@ -879,7 +879,7 @@ where
} }
// Let us see if the layout is simple so we take a shortcut, avoid force_allocation. // Let us see if the layout is simple so we take a shortcut, avoid force_allocation.
let src = match self.try_read_immediate(src, /*force*/ false)? { let src = match self.read_immediate_raw(src, /*force*/ false)? {
Ok(src_val) => { Ok(src_val) => {
assert!(!src.layout.is_unsized(), "cannot have unsized immediates"); assert!(!src.layout.is_unsized(), "cannot have unsized immediates");
// Yay, we got a value that we can write directly. // Yay, we got a value that we can write directly.

View file

@ -492,7 +492,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
op: &OpTy<'tcx, M::PointerTag>, op: &OpTy<'tcx, M::PointerTag>,
) -> InterpResult<'tcx, Immediate<M::PointerTag>> { ) -> InterpResult<'tcx, Immediate<M::PointerTag>> {
Ok(*try_validation!( Ok(*try_validation!(
self.ecx.try_read_immediate(op, /*force*/ true), self.ecx.read_immediate_raw(op, /*force*/ true),
self.path, self.path,
err_unsup!(ReadPointerAsBytes) => { "(potentially part of) a pointer" } expected { "plain (non-pointer) bytes" }, err_unsup!(ReadPointerAsBytes) => { "(potentially part of) a pointer" } expected { "plain (non-pointer) bytes" },
).unwrap()) ).unwrap())

View file

@ -415,7 +415,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
// Try to read the local as an immediate so that if it is representable as a scalar, we can // Try to read the local as an immediate so that if it is representable as a scalar, we can
// handle it as such, but otherwise, just return the value as is. // handle it as such, but otherwise, just return the value as is.
Some(match self.ecx.try_read_immediate(&op, /*force*/ false) { Some(match self.ecx.read_immediate_raw(&op, /*force*/ false) {
Ok(Ok(imm)) => imm.into(), Ok(Ok(imm)) => imm.into(),
_ => op, _ => op,
}) })
@ -709,8 +709,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
return; return;
} }
// FIXME> figure out what to do when try_read_immediate fails // FIXME> figure out what to do when read_immediate_raw fails
let imm = self.use_ecx(|this| this.ecx.try_read_immediate(value, /*force*/ false)); let imm = self.use_ecx(|this| this.ecx.read_immediate_raw(value, /*force*/ false));
if let Some(Ok(imm)) = imm { if let Some(Ok(imm)) = imm {
match *imm { match *imm {

View file

@ -412,7 +412,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
// Try to read the local as an immediate so that if it is representable as a scalar, we can // Try to read the local as an immediate so that if it is representable as a scalar, we can
// handle it as such, but otherwise, just return the value as is. // handle it as such, but otherwise, just return the value as is.
Some(match self.ecx.try_read_immediate(&op, /*force*/ false) { Some(match self.ecx.read_immediate_raw(&op, /*force*/ false) {
Ok(Ok(imm)) => imm.into(), Ok(Ok(imm)) => imm.into(),
_ => op, _ => op,
}) })