@@ -28,6 +28,8 @@ use crate::util::storage::AlwaysLiveLocals;
28
28
29
29
pub struct InterpCx < ' mir , ' tcx , M : Machine < ' mir , ' tcx > > {
30
30
/// Stores the `Machine` instance.
31
+ ///
32
+ /// Note: the stack is provided by the machine.
31
33
pub machine : M ,
32
34
33
35
/// The results of the type checker, from rustc.
@@ -39,9 +41,6 @@ pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
39
41
/// The virtual memory system.
40
42
pub memory : Memory < ' mir , ' tcx , M > ,
41
43
42
- /// The virtual call stack.
43
- pub ( crate ) stack : Vec < Frame < ' mir , ' tcx , M :: PointerTag , M :: FrameExtra > > ,
44
-
45
44
/// A cache for deduplicating vtables
46
45
pub ( super ) vtables :
47
46
FxHashMap < ( Ty < ' tcx > , Option < ty:: PolyExistentialTraitRef < ' tcx > > ) , Pointer < M :: PointerTag > > ,
@@ -297,7 +296,7 @@ pub(super) fn from_known_layout<'tcx>(
297
296
}
298
297
}
299
298
300
- impl < ' mir , ' tcx , M : Machine < ' mir , ' tcx > > InterpCx < ' mir , ' tcx , M > {
299
+ impl < ' mir , ' tcx : ' mir , M : Machine < ' mir , ' tcx > > InterpCx < ' mir , ' tcx , M > {
301
300
pub fn new (
302
301
tcx : TyCtxtAt < ' tcx > ,
303
302
param_env : ty:: ParamEnv < ' tcx > ,
@@ -309,7 +308,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
309
308
tcx,
310
309
param_env,
311
310
memory : Memory :: new ( tcx, memory_extra) ,
312
- stack : Vec :: new ( ) ,
313
311
vtables : FxHashMap :: default ( ) ,
314
312
}
315
313
}
@@ -349,24 +347,32 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
349
347
}
350
348
351
349
#[ inline( always) ]
352
- pub fn stack ( & self ) -> & [ Frame < ' mir , ' tcx , M :: PointerTag , M :: FrameExtra > ] {
353
- & self . stack
350
+ pub ( crate ) fn stack ( & self ) -> & [ Frame < ' mir , ' tcx , M :: PointerTag , M :: FrameExtra > ] {
351
+ M :: stack ( self )
352
+ }
353
+
354
+ #[ inline( always) ]
355
+ pub ( crate ) fn stack_mut (
356
+ & mut self ,
357
+ ) -> & mut Vec < Frame < ' mir , ' tcx , M :: PointerTag , M :: FrameExtra > > {
358
+ M :: stack_mut ( self )
354
359
}
355
360
356
361
#[ inline( always) ]
357
- pub fn cur_frame ( & self ) -> usize {
358
- assert ! ( !self . stack. is_empty( ) ) ;
359
- self . stack . len ( ) - 1
362
+ pub fn frame_idx ( & self ) -> usize {
363
+ let stack = self . stack ( ) ;
364
+ assert ! ( !stack. is_empty( ) ) ;
365
+ stack. len ( ) - 1
360
366
}
361
367
362
368
#[ inline( always) ]
363
369
pub fn frame ( & self ) -> & Frame < ' mir , ' tcx , M :: PointerTag , M :: FrameExtra > {
364
- self . stack . last ( ) . expect ( "no call frames exist" )
370
+ self . stack ( ) . last ( ) . expect ( "no call frames exist" )
365
371
}
366
372
367
373
#[ inline( always) ]
368
374
pub fn frame_mut ( & mut self ) -> & mut Frame < ' mir , ' tcx , M :: PointerTag , M :: FrameExtra > {
369
- self . stack . last_mut ( ) . expect ( "no call frames exist" )
375
+ self . stack_mut ( ) . last_mut ( ) . expect ( "no call frames exist" )
370
376
}
371
377
372
378
#[ inline( always) ]
@@ -596,8 +602,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
596
602
return_place : Option < PlaceTy < ' tcx , M :: PointerTag > > ,
597
603
return_to_block : StackPopCleanup ,
598
604
) -> InterpResult < ' tcx > {
599
- if !self . stack . is_empty ( ) {
600
- info ! ( "PAUSING({}) {}" , self . cur_frame ( ) , self . frame( ) . instance) ;
605
+ if !self . stack ( ) . is_empty ( ) {
606
+ info ! ( "PAUSING({}) {}" , self . frame_idx ( ) , self . frame( ) . instance) ;
601
607
}
602
608
:: log_settings:: settings ( ) . indentation += 1 ;
603
609
@@ -615,7 +621,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
615
621
extra : ( ) ,
616
622
} ;
617
623
let frame = M :: init_frame_extra ( self , pre_frame) ?;
618
- self . stack . push ( frame) ;
624
+ self . stack_mut ( ) . push ( frame) ;
619
625
620
626
// don't allocate at all for trivial constants
621
627
if body. local_decls . len ( ) > 1 {
@@ -648,9 +654,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
648
654
}
649
655
650
656
M :: after_stack_push ( self ) ?;
651
- info ! ( "ENTERING({}) {}" , self . cur_frame ( ) , self . frame( ) . instance) ;
657
+ info ! ( "ENTERING({}) {}" , self . frame_idx ( ) , self . frame( ) . instance) ;
652
658
653
- if self . stack . len ( ) > * self . tcx . sess . recursion_limit . get ( ) {
659
+ if self . stack ( ) . len ( ) > * self . tcx . sess . recursion_limit . get ( ) {
654
660
throw_exhaust ! ( StackFrameLimitReached )
655
661
} else {
656
662
Ok ( ( ) )
@@ -705,7 +711,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
705
711
pub ( super ) fn pop_stack_frame ( & mut self , unwinding : bool ) -> InterpResult < ' tcx > {
706
712
info ! (
707
713
"LEAVING({}) {} (unwinding = {})" ,
708
- self . cur_frame ( ) ,
714
+ self . frame_idx ( ) ,
709
715
self . frame( ) . instance,
710
716
unwinding
711
717
) ;
@@ -720,7 +726,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
720
726
) ;
721
727
722
728
:: log_settings:: settings ( ) . indentation -= 1 ;
723
- let frame = self . stack . pop ( ) . expect ( "tried to pop a stack frame, but there were none" ) ;
729
+ let frame =
730
+ self . stack_mut ( ) . pop ( ) . expect ( "tried to pop a stack frame, but there were none" ) ;
724
731
725
732
// Now where do we jump next?
726
733
@@ -735,7 +742,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
735
742
} ;
736
743
737
744
if !cleanup {
738
- assert ! ( self . stack. is_empty( ) , "only the topmost frame should ever be leaked" ) ;
745
+ assert ! ( self . stack( ) . is_empty( ) , "only the topmost frame should ever be leaked" ) ;
739
746
assert ! ( next_block. is_none( ) , "tried to skip cleanup when we have a next block!" ) ;
740
747
assert ! ( !unwinding, "tried to skip cleanup during unwinding" ) ;
741
748
// Leak the locals, skip validation, skip machine hook.
@@ -784,10 +791,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
784
791
}
785
792
}
786
793
787
- if !self . stack . is_empty ( ) {
794
+ if !self . stack ( ) . is_empty ( ) {
788
795
info ! (
789
796
"CONTINUING({}) {} (unwinding = {})" ,
790
- self . cur_frame ( ) ,
797
+ self . frame_idx ( ) ,
791
798
self . frame( ) . instance,
792
799
unwinding
793
800
) ;
@@ -895,12 +902,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
895
902
Place :: Local { frame, local } => {
896
903
let mut allocs = Vec :: new ( ) ;
897
904
let mut msg = format ! ( "{:?}" , local) ;
898
- if frame != self . cur_frame ( ) {
899
- write ! ( msg, " ({} frames up)" , self . cur_frame ( ) - frame) . unwrap ( ) ;
905
+ if frame != self . frame_idx ( ) {
906
+ write ! ( msg, " ({} frames up)" , self . frame_idx ( ) - frame) . unwrap ( ) ;
900
907
}
901
908
write ! ( msg, ":" ) . unwrap ( ) ;
902
909
903
- match self . stack [ frame] . locals [ local] . value {
910
+ match self . stack ( ) [ frame] . locals [ local] . value {
904
911
LocalValue :: Dead => write ! ( msg, " is dead" ) . unwrap ( ) ,
905
912
LocalValue :: Uninitialized => write ! ( msg, " is uninitialized" ) . unwrap ( ) ,
906
913
LocalValue :: Live ( Operand :: Indirect ( mplace) ) => match mplace. ptr {
0 commit comments