Skip to content

Commit 531ec85

Browse files
authored
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`
2 parents 3ced940 + 704cb8f commit 531ec85

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ impl<Prov: Provenance> Immediate<Prov> {
175175
}
176176
interp_ok(())
177177
}
178+
179+
pub fn has_provenance(&self) -> bool {
180+
match self {
181+
Immediate::Scalar(scalar) => matches!(scalar, Scalar::Ptr { .. }),
182+
Immediate::ScalarPair(s1, s2) => {
183+
matches!(s1, Scalar::Ptr { .. }) || matches!(s2, Scalar::Ptr { .. })
184+
}
185+
Immediate::Uninit => false,
186+
}
187+
}
178188
}
179189

180190
// ScalarPair needs a type to interpret, so we often have an immediate and a type together

compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,13 @@ where
759759
&mut self,
760760
dest: &impl Writeable<'tcx, M::Provenance>,
761761
) -> InterpResult<'tcx> {
762+
// If this is an efficiently represented local variable without provenance, skip the
763+
// `as_mplace_or_mutable_local` that would otherwise force this local into memory.
764+
if let Right(imm) = dest.to_op(self)?.as_mplace_or_imm() {
765+
if !imm.has_provenance() {
766+
return interp_ok(());
767+
}
768+
}
762769
match self.as_mplace_or_mutable_local(&dest.to_place())? {
763770
Right((local_val, _local_layout, local)) => {
764771
local_val.clear_provenance()?;

0 commit comments

Comments
 (0)