11
11
use std:: fmt:: Write ;
12
12
use std:: mem;
13
13
14
+ use syntax:: source_map:: { self , Span , DUMMY_SP } ;
14
15
use rustc:: hir:: def_id:: DefId ;
15
16
use rustc:: hir:: def:: Def ;
16
17
use rustc:: hir:: map:: definitions:: DefPathData ;
@@ -29,8 +30,6 @@ use rustc::mir::interpret::{
29
30
} ;
30
31
use rustc_data_structures:: fx:: FxHashMap ;
31
32
32
- use syntax:: source_map:: { self , Span } ;
33
-
34
33
use super :: {
35
34
Value , Operand , MemPlace , MPlaceTy , Place , PlaceTy , ScalarMaybeUndef ,
36
35
Memory , Machine
@@ -216,51 +215,48 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
216
215
}
217
216
}
218
217
218
+ #[ inline( always) ]
219
219
pub fn memory ( & self ) -> & Memory < ' a , ' mir , ' tcx , M > {
220
220
& self . memory
221
221
}
222
222
223
+ #[ inline( always) ]
223
224
pub fn memory_mut ( & mut self ) -> & mut Memory < ' a , ' mir , ' tcx , M > {
224
225
& mut self . memory
225
226
}
226
227
228
+ #[ inline( always) ]
227
229
pub fn stack ( & self ) -> & [ Frame < ' mir , ' tcx , M :: PointerTag > ] {
228
230
& self . stack
229
231
}
230
232
231
- #[ inline]
233
+ #[ inline( always ) ]
232
234
pub fn cur_frame ( & self ) -> usize {
233
235
assert ! ( self . stack. len( ) > 0 ) ;
234
236
self . stack . len ( ) - 1
235
237
}
236
238
237
- /// Mark a storage as live, killing the previous content and returning it.
238
- /// Remember to deallocate that!
239
- pub fn storage_live (
240
- & mut self ,
241
- local : mir:: Local
242
- ) -> EvalResult < ' tcx , LocalValue < M :: PointerTag > > {
243
- assert ! ( local != mir:: RETURN_PLACE , "Cannot make return place live" ) ;
244
- trace ! ( "{:?} is now live" , local) ;
245
-
246
- let layout = self . layout_of_local ( self . cur_frame ( ) , local) ?;
247
- let init = LocalValue :: Live ( self . uninit_operand ( layout) ?) ;
248
- // StorageLive *always* kills the value that's currently stored
249
- Ok ( mem:: replace ( & mut self . frame_mut ( ) . locals [ local] , init) )
239
+ #[ inline( always) ]
240
+ pub fn frame ( & self ) -> & Frame < ' mir , ' tcx , M :: PointerTag > {
241
+ self . stack . last ( ) . expect ( "no call frames exist" )
250
242
}
251
243
252
- /// Returns the old value of the local.
253
- /// Remember to deallocate that!
254
- pub fn storage_dead ( & mut self , local : mir:: Local ) -> LocalValue < M :: PointerTag > {
255
- assert ! ( local != mir:: RETURN_PLACE , "Cannot make return place dead" ) ;
256
- trace ! ( "{:?} is now dead" , local) ;
244
+ #[ inline( always) ]
245
+ pub fn frame_mut ( & mut self ) -> & mut Frame < ' mir , ' tcx , M :: PointerTag > {
246
+ self . stack . last_mut ( ) . expect ( "no call frames exist" )
247
+ }
257
248
258
- mem:: replace ( & mut self . frame_mut ( ) . locals [ local] , LocalValue :: Dead )
249
+ #[ inline( always) ]
250
+ pub ( super ) fn mir ( & self ) -> & ' mir mir:: Mir < ' tcx > {
251
+ self . frame ( ) . mir
259
252
}
260
253
261
- pub fn str_to_value ( & mut self , s : & str ) -> EvalResult < ' tcx , Value < M :: PointerTag > > {
262
- let ptr = self . memory . allocate_static_bytes ( s. as_bytes ( ) ) ;
263
- Ok ( Value :: new_slice ( Scalar :: Ptr ( ptr) , s. len ( ) as u64 , self . tcx . tcx ) )
254
+ pub fn substs ( & self ) -> & ' tcx Substs < ' tcx > {
255
+ if let Some ( frame) = self . stack . last ( ) {
256
+ frame. instance . substs
257
+ } else {
258
+ Substs :: empty ( )
259
+ }
264
260
}
265
261
266
262
pub ( super ) fn resolve (
@@ -284,10 +280,14 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
284
280
) . ok_or_else ( || EvalErrorKind :: TooGeneric . into ( ) )
285
281
}
286
282
287
- pub ( super ) fn type_is_sized ( & self , ty : Ty < ' tcx > ) -> bool {
283
+ pub fn type_is_sized ( & self , ty : Ty < ' tcx > ) -> bool {
288
284
ty. is_sized ( self . tcx , self . param_env )
289
285
}
290
286
287
+ pub fn type_is_freeze ( & self , ty : Ty < ' tcx > ) -> bool {
288
+ ty. is_freeze ( * self . tcx , self . param_env , DUMMY_SP )
289
+ }
290
+
291
291
pub fn load_mir (
292
292
& self ,
293
293
instance : ty:: InstanceDef < ' tcx > ,
@@ -335,6 +335,11 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
335
335
self . layout_of ( local_ty)
336
336
}
337
337
338
+ pub fn str_to_value ( & mut self , s : & str ) -> EvalResult < ' tcx , Value < M :: PointerTag > > {
339
+ let ptr = self . memory . allocate_static_bytes ( s. as_bytes ( ) ) ;
340
+ Ok ( Value :: new_slice ( Scalar :: Ptr ( ptr) , s. len ( ) as u64 , self . tcx . tcx ) )
341
+ }
342
+
338
343
/// Return the actual dynamic size and alignment of the place at the given type.
339
344
/// Only the "meta" (metadata) part of the place matters.
340
345
/// This can fail to provide an answer for extern types.
@@ -551,6 +556,30 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
551
556
Ok ( ( ) )
552
557
}
553
558
559
+ /// Mark a storage as live, killing the previous content and returning it.
560
+ /// Remember to deallocate that!
561
+ pub fn storage_live (
562
+ & mut self ,
563
+ local : mir:: Local
564
+ ) -> EvalResult < ' tcx , LocalValue < M :: PointerTag > > {
565
+ assert ! ( local != mir:: RETURN_PLACE , "Cannot make return place live" ) ;
566
+ trace ! ( "{:?} is now live" , local) ;
567
+
568
+ let layout = self . layout_of_local ( self . cur_frame ( ) , local) ?;
569
+ let init = LocalValue :: Live ( self . uninit_operand ( layout) ?) ;
570
+ // StorageLive *always* kills the value that's currently stored
571
+ Ok ( mem:: replace ( & mut self . frame_mut ( ) . locals [ local] , init) )
572
+ }
573
+
574
+ /// Returns the old value of the local.
575
+ /// Remember to deallocate that!
576
+ pub fn storage_dead ( & mut self , local : mir:: Local ) -> LocalValue < M :: PointerTag > {
577
+ assert ! ( local != mir:: RETURN_PLACE , "Cannot make return place dead" ) ;
578
+ trace ! ( "{:?} is now dead" , local) ;
579
+
580
+ mem:: replace ( & mut self . frame_mut ( ) . locals [ local] , LocalValue :: Dead )
581
+ }
582
+
554
583
pub ( super ) fn deallocate_local (
555
584
& mut self ,
556
585
local : LocalValue < M :: PointerTag > ,
@@ -575,28 +604,6 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
575
604
. map_err ( |err| EvalErrorKind :: ReferencedConstant ( err) . into ( ) )
576
605
}
577
606
578
- #[ inline( always) ]
579
- pub fn frame ( & self ) -> & Frame < ' mir , ' tcx , M :: PointerTag > {
580
- self . stack . last ( ) . expect ( "no call frames exist" )
581
- }
582
-
583
- #[ inline( always) ]
584
- pub fn frame_mut ( & mut self ) -> & mut Frame < ' mir , ' tcx , M :: PointerTag > {
585
- self . stack . last_mut ( ) . expect ( "no call frames exist" )
586
- }
587
-
588
- pub ( super ) fn mir ( & self ) -> & ' mir mir:: Mir < ' tcx > {
589
- self . frame ( ) . mir
590
- }
591
-
592
- pub fn substs ( & self ) -> & ' tcx Substs < ' tcx > {
593
- if let Some ( frame) = self . stack . last ( ) {
594
- frame. instance . substs
595
- } else {
596
- Substs :: empty ( )
597
- }
598
- }
599
-
600
607
pub fn dump_place ( & self , place : Place < M :: PointerTag > ) {
601
608
// Debug output
602
609
if !log_enabled ! ( :: log:: Level :: Trace ) {
0 commit comments