File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
compiler/rustc_const_eval/src/interpret Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ( ) ?;
You can’t perform that action at this time.
0 commit comments