diff options
| author | Ralf Jung <post@ralfj.de> | 2022-05-05 09:55:38 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2022-05-05 09:55:38 +0200 |
| commit | e47d6c7a6b643e836455d4ebf5e7fb1eaad5c870 (patch) | |
| tree | 0ae81bd402d2c0103466cc3dbcb42e56d36654ea /compiler/rustc_const_eval/src | |
| parent | 5b20da81805c70c1991f58452b8fa1b7dc5b3256 (diff) | |
| download | rust-e47d6c7a6b643e836455d4ebf5e7fb1eaad5c870.tar.gz rust-e47d6c7a6b643e836455d4ebf5e7fb1eaad5c870.zip | |
give it a scary name
Diffstat (limited to 'compiler/rustc_const_eval/src')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/operand.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/place.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/validity.rs | 2 |
3 files changed, 13 insertions, 10 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 494ce3787e3..a8a5ac2f9d9 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -252,7 +252,9 @@ impl<'tcx, Tag: Provenance> ImmTy<'tcx, Tag> { 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 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { 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 @@ 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 /// 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 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { &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); diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 4cc4080c27a..df6e05bb13c 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -720,7 +720,7 @@ where } 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 @@ where } // 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. diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index c2782db3221..92e3ac04dc4 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -492,7 +492,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' 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()) |
