diff options
| author | Ralf Jung <post@ralfj.de> | 2023-11-28 22:30:55 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-12-07 17:46:48 +0100 |
| commit | 8188bd45489a1dbd7e3f61d33233576e36f9c48c (patch) | |
| tree | 7a2db1de253674db8a62be010ce61139dcc50211 /compiler/rustc_const_eval/src/interpret | |
| parent | 29c95e98e318be711169862c996982c7dffd2372 (diff) | |
| download | rust-8188bd45489a1dbd7e3f61d33233576e36f9c48c.tar.gz rust-8188bd45489a1dbd7e3f61d33233576e36f9c48c.zip | |
avoid marking as immutable what is already immutable
this has been demonstrated to help performance
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/operand.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/place.rs | 6 |
2 files changed, 12 insertions, 5 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 66cf38c09a0..b39b219b46a 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -93,6 +93,17 @@ impl<Prov: Provenance> Immediate<Prov> { Immediate::Uninit => bug!("Got uninit where a scalar pair was expected"), } } + + /// Returns the scalar from the first component and optionally the 2nd component as metadata. + #[inline] + #[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980) + pub fn to_scalar_and_meta(self) -> (Scalar<Prov>, MemPlaceMeta<Prov>) { + match self { + Immediate::ScalarPair(val1, val2) => (val1, MemPlaceMeta::Meta(val2)), + Immediate::Scalar(val) => (val, MemPlaceMeta::None), + Immediate::Uninit => bug!("Got uninit where a scalar or scalar pair was expected"), + } + } } // ScalarPair needs a type to interpret, so we often have an immediate and a type together diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 148228f0796..639b269ac25 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -406,11 +406,7 @@ where let pointee_type = val.layout.ty.builtin_deref(true).expect("`ref_to_mplace` called on non-ptr type").ty; let layout = self.layout_of(pointee_type)?; - let (ptr, meta) = match **val { - Immediate::Scalar(ptr) => (ptr, MemPlaceMeta::None), - Immediate::ScalarPair(ptr, meta) => (ptr, MemPlaceMeta::Meta(meta)), - Immediate::Uninit => throw_ub!(InvalidUninitBytes(None)), - }; + let (ptr, meta) = val.to_scalar_and_meta(); // `ref_to_mplace` is called on raw pointers even if they don't actually get dereferenced; // we hence can't call `size_and_align_of` since that asserts more validity than we want. |
