Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_const_eval/src/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
Loading