diff options
| author | Ralf Jung <post@ralfj.de> | 2023-09-12 15:57:40 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-09-14 11:56:55 +0200 |
| commit | 7aa44eee997e51154eb4dd04ee13a08fe7dc53af (patch) | |
| tree | ab6ee701949f15fdba62265221839d4f3b0e5edc /compiler/rustc_middle | |
| parent | 430c386821ad0df43360cf41a4bb35ac0f1d2d77 (diff) | |
| download | rust-7aa44eee997e51154eb4dd04ee13a08fe7dc53af.tar.gz rust-7aa44eee997e51154eb4dd04ee13a08fe7dc53af.zip | |
don't force all slice-typed ConstValue to be ConstValue::Slice
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/mir/interpret/mod.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/interpret/value.rs | 23 |
2 files changed, 7 insertions, 18 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/mod.rs b/compiler/rustc_middle/src/mir/interpret/mod.rs index f03a28d210d..44d1dcbbe17 100644 --- a/compiler/rustc_middle/src/mir/interpret/mod.rs +++ b/compiler/rustc_middle/src/mir/interpret/mod.rs @@ -149,7 +149,7 @@ pub use self::error::{ UnsupportedOpInfo, ValidationErrorInfo, ValidationErrorKind, }; -pub use self::value::{get_slice_bytes, ConstAlloc, ConstValue, Scalar}; +pub use self::value::{ConstAlloc, ConstValue, Scalar}; pub use self::allocation::{ alloc_range, AllocBytes, AllocError, AllocRange, AllocResult, Allocation, ConstAllocation, diff --git a/compiler/rustc_middle/src/mir/interpret/value.rs b/compiler/rustc_middle/src/mir/interpret/value.rs index a77d16e42e9..6207a35e4f3 100644 --- a/compiler/rustc_middle/src/mir/interpret/value.rs +++ b/compiler/rustc_middle/src/mir/interpret/value.rs @@ -12,7 +12,7 @@ use rustc_target::abi::{HasDataLayout, Size}; use crate::ty::{ParamEnv, ScalarInt, Ty, TyCtxt}; use super::{ - AllocId, AllocRange, ConstAllocation, InterpResult, Pointer, PointerArithmetic, Provenance, + AllocId, ConstAllocation, InterpResult, Pointer, PointerArithmetic, Provenance, ScalarSizeMismatch, }; @@ -40,10 +40,14 @@ pub enum ConstValue<'tcx> { /// Used for `&[u8]` and `&str`. /// - /// This is worth the optimization since Rust has literals of that type. + /// This is worth an optimized representation since Rust has literals of these types. + /// Not having to indirect those through an `AllocId` (or two, if we used `Indirect`) has shown + /// measurable performance improvements on stress tests. Slice { data: ConstAllocation<'tcx>, start: usize, end: usize }, /// A value not representable by the other variants; needs to be stored in-memory. + /// + /// Must *not* be used for scalars or ZST, but having `&str` or other slices in this variant is fine. Indirect { /// The backing memory of the value. May contain more memory than needed for just the value /// if this points into some other larger ConstValue. @@ -511,18 +515,3 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> { Ok(Double::from_bits(self.to_u64()?.into())) } } - -/// Gets the bytes of a constant slice value. -pub fn get_slice_bytes<'tcx>(cx: &impl HasDataLayout, val: ConstValue<'tcx>) -> &'tcx [u8] { - if let ConstValue::Slice { data, start, end } = val { - let len = end - start; - data.inner() - .get_bytes_strip_provenance( - cx, - AllocRange { start: Size::from_bytes(start), size: Size::from_bytes(len) }, - ) - .unwrap_or_else(|err| bug!("const slice is invalid: {:?}", err)) - } else { - bug!("expected const slice, but found another const value"); - } -} |
