@@ -16,6 +16,7 @@ use rustc_target::spec::abi::Abi;
16
16
17
17
use crate :: concurrency:: data_race;
18
18
use crate :: concurrency:: sync:: SynchronizationState ;
19
+ use crate :: concurrency:: stack:: Stack ;
19
20
use crate :: * ;
20
21
21
22
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
@@ -116,7 +117,7 @@ pub struct Thread<'mir, 'tcx> {
116
117
thread_name : Option < Vec < u8 > > ,
117
118
118
119
/// The virtual call stack.
119
- stack : Vec < Frame < ' mir , ' tcx , Provenance , FrameData < ' tcx > > > ,
120
+ stack : Stack < ' mir , ' tcx > ,
120
121
121
122
/// The join status.
122
123
join_status : ThreadJoinStatus ,
@@ -166,7 +167,7 @@ impl<'mir, 'tcx> Default for Thread<'mir, 'tcx> {
166
167
Self {
167
168
state : ThreadState :: Enabled ,
168
169
thread_name : None ,
169
- stack : Vec :: new ( ) ,
170
+ stack : Stack :: new ( ) ,
170
171
join_status : ThreadJoinStatus :: Joinable ,
171
172
panic_payload : None ,
172
173
last_error : None ,
@@ -189,9 +190,7 @@ impl VisitTags for Thread<'_, '_> {
189
190
190
191
panic_payload. visit_tags ( visit) ;
191
192
last_error. visit_tags ( visit) ;
192
- for frame in stack {
193
- frame. visit_tags ( visit)
194
- }
193
+ stack. visit_tags ( visit) ;
195
194
}
196
195
}
197
196
@@ -345,20 +344,18 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
345
344
346
345
/// Borrow the stack of the active thread.
347
346
pub fn active_thread_stack ( & self ) -> & [ Frame < ' mir , ' tcx , Provenance , FrameData < ' tcx > > ] {
348
- & self . threads [ self . active_thread ] . stack
347
+ self . threads [ self . active_thread ] . stack . frames ( )
349
348
}
350
349
351
350
/// Mutably borrow the stack of the active thread.
352
- fn active_thread_stack_mut (
353
- & mut self ,
354
- ) -> & mut Vec < Frame < ' mir , ' tcx , Provenance , FrameData < ' tcx > > > {
355
- & mut self . threads [ self . active_thread ] . stack
351
+ pub fn active_thread_stack_mut ( & mut self ) -> & mut [ Frame < ' mir , ' tcx , Provenance , FrameData < ' tcx > > ] {
352
+ self . threads [ self . active_thread ] . stack . frames_mut ( )
356
353
}
357
354
358
355
pub fn all_stacks (
359
356
& self ,
360
357
) -> impl Iterator < Item = & [ Frame < ' mir , ' tcx , Provenance , FrameData < ' tcx > > ] > {
361
- self . threads . iter ( ) . map ( |t| & t. stack [ .. ] )
358
+ self . threads . iter ( ) . map ( |t| t. stack . frames ( ) )
362
359
}
363
360
364
361
/// Create a new thread and returns its id.
@@ -561,10 +558,11 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
561
558
// this allows us to have a deterministic scheduler.
562
559
for thread in self . threads . indices ( ) {
563
560
match self . timeout_callbacks . entry ( thread) {
564
- Entry :: Occupied ( entry) =>
561
+ Entry :: Occupied ( entry) => {
565
562
if entry. get ( ) . call_time . get_wait_time ( clock) == Duration :: new ( 0 , 0 ) {
566
563
return Some ( ( thread, entry. remove ( ) . callback ) ) ;
567
- } ,
564
+ }
565
+ }
568
566
Entry :: Vacant ( _) => { }
569
567
}
570
568
}
@@ -863,13 +861,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
863
861
}
864
862
865
863
#[ inline]
866
- fn active_thread_stack_mut (
867
- & mut self ,
868
- ) -> & mut Vec < Frame < ' mir , ' tcx , Provenance , FrameData < ' tcx > > > {
864
+ fn active_thread_stack_mut ( & mut self ) -> & mut [ Frame < ' mir , ' tcx , Provenance , FrameData < ' tcx > > ] {
869
865
let this = self . eval_context_mut ( ) ;
870
866
this. machine . threads . active_thread_stack_mut ( )
871
867
}
872
868
869
+ fn push_frame ( & mut self , frame : Frame < ' mir , ' tcx , Provenance , FrameData < ' tcx > > ) {
870
+ let this = self . eval_context_mut ( ) ;
871
+ this. machine . threads . active_thread_mut ( ) . stack . push ( frame) ;
872
+ }
873
+
874
+ fn pop_frame ( & mut self ) -> Option < Frame < ' mir , ' tcx , Provenance , FrameData < ' tcx > > > {
875
+ let this = self . eval_context_mut ( ) ;
876
+ this. machine . threads . active_thread_mut ( ) . stack . pop ( )
877
+ }
878
+
873
879
/// Set the name of the current thread. The buffer must not include the null terminator.
874
880
#[ inline]
875
881
fn set_thread_name ( & mut self , thread : ThreadId , new_thread_name : Vec < u8 > ) {
0 commit comments