1111use std:: fmt:: Write ;
1212use std:: mem;
1313
14+ use syntax:: source_map:: { self , Span , DUMMY_SP } ;
1415use rustc:: hir:: def_id:: DefId ;
1516use rustc:: hir:: def:: Def ;
1617use rustc:: hir:: map:: definitions:: DefPathData ;
@@ -29,8 +30,6 @@ use rustc::mir::interpret::{
2930} ;
3031use rustc_data_structures:: fx:: FxHashMap ;
3132
32- use syntax:: source_map:: { self , Span } ;
33-
3433use super :: {
3534 Value , Operand , MemPlace , MPlaceTy , Place , PlaceTy , ScalarMaybeUndef ,
3635 Memory , Machine
@@ -216,51 +215,48 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
216215 }
217216 }
218217
218+ #[ inline( always) ]
219219 pub fn memory ( & self ) -> & Memory < ' a , ' mir , ' tcx , M > {
220220 & self . memory
221221 }
222222
223+ #[ inline( always) ]
223224 pub fn memory_mut ( & mut self ) -> & mut Memory < ' a , ' mir , ' tcx , M > {
224225 & mut self . memory
225226 }
226227
228+ #[ inline( always) ]
227229 pub fn stack ( & self ) -> & [ Frame < ' mir , ' tcx , M :: PointerTag > ] {
228230 & self . stack
229231 }
230232
231- #[ inline]
233+ #[ inline( always ) ]
232234 pub fn cur_frame ( & self ) -> usize {
233235 assert ! ( self . stack. len( ) > 0 ) ;
234236 self . stack . len ( ) - 1
235237 }
236238
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" )
250242 }
251243
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+ }
257248
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
259252 }
260253
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+ }
264260 }
265261
266262 pub ( super ) fn resolve (
@@ -284,10 +280,14 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
284280 ) . ok_or_else ( || EvalErrorKind :: TooGeneric . into ( ) )
285281 }
286282
287- pub ( super ) fn type_is_sized ( & self , ty : Ty < ' tcx > ) -> bool {
283+ pub fn type_is_sized ( & self , ty : Ty < ' tcx > ) -> bool {
288284 ty. is_sized ( self . tcx , self . param_env )
289285 }
290286
287+ pub fn type_is_freeze ( & self , ty : Ty < ' tcx > ) -> bool {
288+ ty. is_freeze ( * self . tcx , self . param_env , DUMMY_SP )
289+ }
290+
291291 pub fn load_mir (
292292 & self ,
293293 instance : ty:: InstanceDef < ' tcx > ,
@@ -335,6 +335,11 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
335335 self . layout_of ( local_ty)
336336 }
337337
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+
338343 /// Return the actual dynamic size and alignment of the place at the given type.
339344 /// Only the "meta" (metadata) part of the place matters.
340345 /// 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
551556 Ok ( ( ) )
552557 }
553558
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+
554583 pub ( super ) fn deallocate_local (
555584 & mut self ,
556585 local : LocalValue < M :: PointerTag > ,
@@ -575,28 +604,6 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
575604 . map_err ( |err| EvalErrorKind :: ReferencedConstant ( err) . into ( ) )
576605 }
577606
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-
600607 pub fn dump_place ( & self , place : Place < M :: PointerTag > ) {
601608 // Debug output
602609 if !log_enabled ! ( :: log:: Level :: Trace ) {
0 commit comments