@@ -4,6 +4,7 @@ use std::fmt::Write;
4
4
use rustc:: hir:: def_id:: DefId ;
5
5
use rustc:: hir:: map:: definitions:: DefPathData ;
6
6
use rustc:: middle:: const_val:: ConstVal ;
7
+ use rustc:: middle:: region:: CodeExtent ;
7
8
use rustc:: mir;
8
9
use rustc:: traits:: Reveal ;
9
10
use rustc:: ty:: layout:: { self , Layout , Size } ;
@@ -21,6 +22,7 @@ use memory::{Memory, MemoryPointer, TlsKey, HasMemory};
21
22
use memory:: Kind as MemoryKind ;
22
23
use operator;
23
24
use value:: { PrimVal , PrimValKind , Value , Pointer } ;
25
+ use validation:: ValidationQuery ;
24
26
25
27
pub struct EvalContext < ' a , ' tcx : ' a > {
26
28
/// The results of the type checker, from rustc.
@@ -29,6 +31,11 @@ pub struct EvalContext<'a, 'tcx: 'a> {
29
31
/// The virtual memory system.
30
32
pub ( crate ) memory : Memory < ' a , ' tcx > ,
31
33
34
+ #[ allow( dead_code) ]
35
+ // FIXME(@RalfJung): validation branch
36
+ /// Lvalues that were suspended by the validation subsystem, and will be recovered later
37
+ pub ( crate ) suspended : HashMap < DynamicLifetime , Vec < ValidationQuery < ' tcx > > > ,
38
+
32
39
/// Precomputed statics, constants and promoteds.
33
40
pub ( crate ) globals : HashMap < GlobalId < ' tcx > , Global < ' tcx > > ,
34
41
@@ -112,6 +119,12 @@ pub enum StackPopCleanup {
112
119
None ,
113
120
}
114
121
122
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
123
+ pub struct DynamicLifetime {
124
+ pub frame : usize ,
125
+ pub region : Option < CodeExtent > , // "None" indicates "until the function ends"
126
+ }
127
+
115
128
#[ derive( Copy , Clone , Debug ) ]
116
129
pub struct ResourceLimits {
117
130
pub memory_size : u64 ,
@@ -134,6 +147,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
134
147
EvalContext {
135
148
tcx,
136
149
memory : Memory :: new ( & tcx. data_layout , limits. memory_size ) ,
150
+ suspended : HashMap :: new ( ) ,
137
151
globals : HashMap :: new ( ) ,
138
152
stack : Vec :: new ( ) ,
139
153
stack_limit : limits. stack_limit ,
@@ -169,6 +183,12 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
169
183
& self . stack
170
184
}
171
185
186
+ #[ inline]
187
+ pub fn cur_frame ( & self ) -> usize {
188
+ assert ! ( self . stack. len( ) > 0 ) ;
189
+ self . stack . len ( ) - 1
190
+ }
191
+
172
192
/// Returns true if the current frame or any parent frame is part of a ctfe.
173
193
///
174
194
/// Used to disable features in const eval, which do not have a rfc enabling
@@ -336,6 +356,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
336
356
stmt : 0 ,
337
357
} ) ;
338
358
359
+ let cur_frame = self . cur_frame ( ) ;
360
+ self . memory . set_cur_frame ( cur_frame) ;
361
+
339
362
if self . stack . len ( ) > self . stack_limit {
340
363
Err ( EvalError :: StackFrameLimitReached )
341
364
} else {
@@ -345,7 +368,13 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
345
368
346
369
pub ( super ) fn pop_stack_frame ( & mut self ) -> EvalResult < ' tcx > {
347
370
:: log_settings:: settings ( ) . indentation -= 1 ;
371
+ self . memory . locks_lifetime_ended ( None ) ;
348
372
let frame = self . stack . pop ( ) . expect ( "tried to pop a stack frame, but there were none" ) ;
373
+ if !self . stack . is_empty ( ) {
374
+ // TODO: IS this the correct time to start considering these accesses as originating from the returned-to stack frame?
375
+ let cur_frame = self . cur_frame ( ) ;
376
+ self . memory . set_cur_frame ( cur_frame) ;
377
+ }
349
378
match frame. return_to_block {
350
379
StackPopCleanup :: MarkStatic ( mutable) => if let Lvalue :: Global ( id) = frame. return_lvalue {
351
380
let global_value = self . globals . get_mut ( & id)
@@ -1551,9 +1580,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1551
1580
if let Lvalue :: Local { frame, local } = lvalue {
1552
1581
let mut allocs = Vec :: new ( ) ;
1553
1582
let mut msg = format ! ( "{:?}" , local) ;
1554
- let last_frame = self . stack . len ( ) - 1 ;
1555
- if frame != last_frame {
1556
- write ! ( msg, " ({} frames up)" , last_frame - frame) . unwrap ( ) ;
1583
+ if frame != self . cur_frame ( ) {
1584
+ write ! ( msg, " ({} frames up)" , self . cur_frame( ) - frame) . unwrap ( ) ;
1557
1585
}
1558
1586
write ! ( msg, ":" ) . unwrap ( ) ;
1559
1587
0 commit comments