Skip to content

Commit e47d6c7

Browse files
committed
give it a scary name
1 parent 5b20da8 commit e47d6c7

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

compiler/rustc_const_eval/src/interpret/operand.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ impl<'tcx, Tag: Provenance> ImmTy<'tcx, Tag> {
252252
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
253253
/// Try reading an immediate in memory; this is interesting particularly for `ScalarPair`.
254254
/// Returns `None` if the layout does not permit loading this as a value.
255-
fn try_read_immediate_from_mplace(
255+
///
256+
/// This is an internal function; call `read_immediate` instead.
257+
fn read_immediate_from_mplace_raw(
256258
&self,
257259
mplace: &MPlaceTy<'tcx, M::PointerTag>,
258260
force: bool,
@@ -312,24 +314,25 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
312314
return Ok(None);
313315
}
314316

315-
/// Try returning an immediate for the operand.
316-
/// If the layout does not permit loading this as an immediate, return where in memory
317-
/// we can find the data.
317+
/// Try returning an immediate for the operand. If the layout does not permit loading this as an
318+
/// immediate, return where in memory we can find the data.
318319
/// Note that for a given layout, this operation will either always fail or always
319320
/// succeed! Whether it succeeds depends on whether the layout can be represented
320321
/// in an `Immediate`, not on which data is stored there currently.
321322
///
322323
/// If `force` is `true`, then even scalars with fields that can be ununit will be
323324
/// read. This means the load is lossy and should not be written back!
324325
/// This flag exists only for validity checking.
325-
pub fn try_read_immediate(
326+
///
327+
/// This is an internal function that should not usually be used; call `read_immediate` instead.
328+
pub fn read_immediate_raw(
326329
&self,
327330
src: &OpTy<'tcx, M::PointerTag>,
328331
force: bool,
329332
) -> InterpResult<'tcx, Result<ImmTy<'tcx, M::PointerTag>, MPlaceTy<'tcx, M::PointerTag>>> {
330333
Ok(match src.try_as_mplace() {
331334
Ok(ref mplace) => {
332-
if let Some(val) = self.try_read_immediate_from_mplace(mplace, force)? {
335+
if let Some(val) = self.read_immediate_from_mplace_raw(mplace, force)? {
333336
Ok(val)
334337
} else {
335338
Err(*mplace)
@@ -345,7 +348,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
345348
&self,
346349
op: &OpTy<'tcx, M::PointerTag>,
347350
) -> InterpResult<'tcx, ImmTy<'tcx, M::PointerTag>> {
348-
if let Ok(imm) = self.try_read_immediate(op, /*force*/ false)? {
351+
if let Ok(imm) = self.read_immediate_raw(op, /*force*/ false)? {
349352
Ok(imm)
350353
} else {
351354
span_bug!(self.cur_span(), "primitive read failed for type: {:?}", op.layout.ty);

compiler/rustc_const_eval/src/interpret/place.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ where
720720
}
721721
trace!("write_immediate: {:?} <- {:?}: {}", *dest, src, dest.layout.ty);
722722

723-
// See if we can avoid an allocation. This is the counterpart to `try_read_immediate`,
723+
// See if we can avoid an allocation. This is the counterpart to `read_immediate_raw`,
724724
// but not factored as a separate function.
725725
let mplace = match dest.place {
726726
Place::Local { frame, local } => {
@@ -879,7 +879,7 @@ where
879879
}
880880

881881
// Let us see if the layout is simple so we take a shortcut, avoid force_allocation.
882-
let src = match self.try_read_immediate(src, /*force*/ false)? {
882+
let src = match self.read_immediate_raw(src, /*force*/ false)? {
883883
Ok(src_val) => {
884884
assert!(!src.layout.is_unsized(), "cannot have unsized immediates");
885885
// Yay, we got a value that we can write directly.

compiler/rustc_const_eval/src/interpret/validity.rs

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

compiler/rustc_mir_transform/src/const_prop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
415415

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

712-
// FIXME> figure out what to do when try_read_immediate fails
713-
let imm = self.use_ecx(|this| this.ecx.try_read_immediate(value, /*force*/ false));
712+
// FIXME> figure out what to do when read_immediate_raw fails
713+
let imm = self.use_ecx(|this| this.ecx.read_immediate_raw(value, /*force*/ false));
714714

715715
if let Some(Ok(imm)) = imm {
716716
match *imm {

compiler/rustc_mir_transform/src/const_prop_lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
412412

413413
// Try to read the local as an immediate so that if it is representable as a scalar, we can
414414
// handle it as such, but otherwise, just return the value as is.
415-
Some(match self.ecx.try_read_immediate(&op, /*force*/ false) {
415+
Some(match self.ecx.read_immediate_raw(&op, /*force*/ false) {
416416
Ok(Ok(imm)) => imm.into(),
417417
_ => op,
418418
})

0 commit comments

Comments
 (0)