give it a scary name
This commit is contained in:
parent
5b20da8180
commit
e47d6c7a6b
@ -252,7 +252,9 @@ pub fn to_const_int(self) -> ConstInt {
|
||||
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
/// 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.
|
||||
fn try_read_immediate_from_mplace(
|
||||
///
|
||||
/// This is an internal function; call `read_immediate` instead.
|
||||
fn read_immediate_from_mplace_raw(
|
||||
&self,
|
||||
mplace: &MPlaceTy<'tcx, M::PointerTag>,
|
||||
force: bool,
|
||||
@ -312,9 +314,8 @@ fn try_read_immediate_from_mplace(
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
/// Try returning an immediate for the operand.
|
||||
/// If the layout does not permit loading this as an immediate, return where in memory
|
||||
/// we can find the data.
|
||||
/// Try returning an immediate for the operand. If the layout does not permit loading this as an
|
||||
/// immediate, return where in memory we can find the data.
|
||||
/// 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
|
||||
/// in an `Immediate`, not on which data is stored there currently.
|
||||
@ -322,14 +323,16 @@ fn try_read_immediate_from_mplace(
|
||||
/// 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!
|
||||
/// 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,
|
||||
src: &OpTy<'tcx, M::PointerTag>,
|
||||
force: bool,
|
||||
) -> InterpResult<'tcx, Result<ImmTy<'tcx, M::PointerTag>, MPlaceTy<'tcx, M::PointerTag>>> {
|
||||
Ok(match src.try_as_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)
|
||||
} else {
|
||||
Err(*mplace)
|
||||
@ -345,7 +348,7 @@ pub fn read_immediate(
|
||||
&self,
|
||||
op: &OpTy<'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)
|
||||
} else {
|
||||
span_bug!(self.cur_span(), "primitive read failed for type: {:?}", op.layout.ty);
|
||||
|
@ -720,7 +720,7 @@ fn write_immediate_no_validate(
|
||||
}
|
||||
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.
|
||||
let mplace = match dest.place {
|
||||
Place::Local { frame, local } => {
|
||||
@ -879,7 +879,7 @@ fn copy_op_no_validate(
|
||||
}
|
||||
|
||||
// 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) => {
|
||||
assert!(!src.layout.is_unsized(), "cannot have unsized immediates");
|
||||
// Yay, we got a value that we can write directly.
|
||||
|
@ -492,7 +492,7 @@ fn read_immediate_forced(
|
||||
op: &OpTy<'tcx, M::PointerTag>,
|
||||
) -> InterpResult<'tcx, Immediate<M::PointerTag>> {
|
||||
Ok(*try_validation!(
|
||||
self.ecx.try_read_immediate(op, /*force*/ true),
|
||||
self.ecx.read_immediate_raw(op, /*force*/ true),
|
||||
self.path,
|
||||
err_unsup!(ReadPointerAsBytes) => { "(potentially part of) a pointer" } expected { "plain (non-pointer) bytes" },
|
||||
).unwrap())
|
||||
|
@ -415,7 +415,7 @@ fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
|
||||
|
||||
// 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.
|
||||
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(),
|
||||
_ => op,
|
||||
})
|
||||
@ -709,8 +709,8 @@ fn replace_with_const(
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME> figure out what to do when try_read_immediate fails
|
||||
let imm = self.use_ecx(|this| this.ecx.try_read_immediate(value, /*force*/ false));
|
||||
// FIXME> figure out what to do when read_immediate_raw fails
|
||||
let imm = self.use_ecx(|this| this.ecx.read_immediate_raw(value, /*force*/ false));
|
||||
|
||||
if let Some(Ok(imm)) = imm {
|
||||
match *imm {
|
||||
|
@ -412,7 +412,7 @@ fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
|
||||
|
||||
// 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.
|
||||
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(),
|
||||
_ => op,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user