diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-08-19 14:18:28 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-19 14:18:28 +1000 |
| commit | 531ec858e9a1c69840f70d4f2a485c288f50fc11 (patch) | |
| tree | 803b7bb87deb46b579af4ec13dc1f415d4ac4e73 /compiler/rustc_const_eval/src | |
| parent | 3ced940a31240700514d127670a050991383d2d5 (diff) | |
| parent | 704cb8f189504ff5903d7920bd8293f833b4e08e (diff) | |
| download | rust-531ec858e9a1c69840f70d4f2a485c288f50fc11.tar.gz rust-531ec858e9a1c69840f70d4f2a485c288f50fc11.zip | |
Rollup merge of #145584 - RalfJung:interpret-clear-provenance, r=compiler-errors
interpret: avoid forcing all integer newtypes into memory during clear_provenance While working on another PR I noticed locals moving into memory (via `force_allocation`) that I didn't expect to move there... turns out that is an issue I introduced when adding provenance clearing. This PR fixes that. r? `@oli-obk`
Diffstat (limited to 'compiler/rustc_const_eval/src')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/operand.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/place.rs | 7 |
2 files changed, 17 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 53a440b646b..560b0e1ae4e 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -175,6 +175,16 @@ impl<Prov: Provenance> Immediate<Prov> { } interp_ok(()) } + + pub fn has_provenance(&self) -> bool { + match self { + Immediate::Scalar(scalar) => matches!(scalar, Scalar::Ptr { .. }), + Immediate::ScalarPair(s1, s2) => { + matches!(s1, Scalar::Ptr { .. }) || matches!(s2, Scalar::Ptr { .. }) + } + Immediate::Uninit => false, + } + } } // 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 3255ffa54aa..e7fe4c0b34f 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -759,6 +759,13 @@ where &mut self, dest: &impl Writeable<'tcx, M::Provenance>, ) -> InterpResult<'tcx> { + // If this is an efficiently represented local variable without provenance, skip the + // `as_mplace_or_mutable_local` that would otherwise force this local into memory. + if let Right(imm) = dest.to_op(self)?.as_mplace_or_imm() { + if !imm.has_provenance() { + return interp_ok(()); + } + } match self.as_mplace_or_mutable_local(&dest.to_place())? { Right((local_val, _local_layout, local)) => { local_val.clear_provenance()?; |
