diff options
| author | Ralf Jung <post@ralfj.de> | 2025-08-18 19:18:27 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2025-08-18 19:18:27 +0200 |
| commit | 704cb8f189504ff5903d7920bd8293f833b4e08e (patch) | |
| tree | c5923a51d16cc378c91b4c10cc1099e13e68904e /compiler/rustc_const_eval | |
| parent | 239e8b1b47b34120287ec36b33228c1e177f0c38 (diff) | |
| download | rust-704cb8f189504ff5903d7920bd8293f833b4e08e.tar.gz rust-704cb8f189504ff5903d7920bd8293f833b4e08e.zip | |
interpret: avoid forcing all integer newtypes into memory during clear_provenance
Diffstat (limited to 'compiler/rustc_const_eval')
| -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()?; |
