@@ -5,68 +5,31 @@ use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX};
55
66use crate :: * ;
77
8- pub trait ScalarExt {
9- /// HACK: this function just extracts all bits if `defined != 0`
10- /// Mainly used for args of C-functions and we should totally correctly fetch the size
11- /// of their arguments
12- fn to_bytes ( self ) -> EvalResult < ' static , u128 > ;
13- }
14-
15- impl < Tag > ScalarExt for Scalar < Tag > {
16- fn to_bytes ( self ) -> EvalResult < ' static , u128 > {
17- match self {
18- Scalar :: Bits { bits, size } => {
19- assert_ne ! ( size, 0 ) ;
20- Ok ( bits)
21- } ,
22- Scalar :: Ptr ( _) => err ! ( ReadPointerAsBytes ) ,
23- }
24- }
25- }
26-
27- impl < Tag > ScalarExt for ScalarMaybeUndef < Tag > {
28- fn to_bytes ( self ) -> EvalResult < ' static , u128 > {
29- self . not_undef ( ) ?. to_bytes ( )
30- }
31- }
32-
33- pub trait EvalContextExt < ' tcx > {
34- fn resolve_path ( & self , path : & [ & str ] ) -> EvalResult < ' tcx , ty:: Instance < ' tcx > > ;
35-
36- /// Visit the memory covered by `place`, sensitive to freezing: The 3rd parameter
37- /// will be true if this is frozen, false if this is in an `UnsafeCell`.
38- fn visit_freeze_sensitive (
39- & self ,
40- place : MPlaceTy < ' tcx , Borrow > ,
41- size : Size ,
42- action : impl FnMut ( Pointer < Borrow > , Size , bool ) -> EvalResult < ' tcx > ,
43- ) -> EvalResult < ' tcx > ;
44- }
45-
46-
47- impl < ' a , ' mir , ' tcx > EvalContextExt < ' tcx > for EvalContext < ' a , ' mir , ' tcx , super :: Evaluator < ' tcx > > {
8+ impl < ' a , ' mir , ' tcx > EvalContextExt < ' a , ' mir , ' tcx > for crate :: MiriEvalContext < ' a , ' mir , ' tcx > { }
9+ pub trait EvalContextExt < ' a , ' mir , ' tcx : ' a +' mir > : crate :: MiriEvalContextExt < ' a , ' mir , ' tcx > {
4810 /// Get an instance for a path.
4911 fn resolve_path ( & self , path : & [ & str ] ) -> EvalResult < ' tcx , ty:: Instance < ' tcx > > {
50- self . tcx
12+ let this = self . eval_context_ref ( ) ;
13+ this. tcx
5114 . crates ( )
5215 . iter ( )
53- . find ( |& & krate| self . tcx . original_crate_name ( krate) == path[ 0 ] )
16+ . find ( |& & krate| this . tcx . original_crate_name ( krate) == path[ 0 ] )
5417 . and_then ( |krate| {
5518 let krate = DefId {
5619 krate : * krate,
5720 index : CRATE_DEF_INDEX ,
5821 } ;
59- let mut items = self . tcx . item_children ( krate) ;
22+ let mut items = this . tcx . item_children ( krate) ;
6023 let mut path_it = path. iter ( ) . skip ( 1 ) . peekable ( ) ;
6124
6225 while let Some ( segment) = path_it. next ( ) {
6326 for item in mem:: replace ( & mut items, Default :: default ( ) ) . iter ( ) {
6427 if item. ident . name == * segment {
6528 if path_it. peek ( ) . is_none ( ) {
66- return Some ( ty:: Instance :: mono ( self . tcx . tcx , item. def . def_id ( ) ) ) ;
29+ return Some ( ty:: Instance :: mono ( this . tcx . tcx , item. def . def_id ( ) ) ) ;
6730 }
6831
69- items = self . tcx . item_children ( item. def . def_id ( ) ) ;
32+ items = this . tcx . item_children ( item. def . def_id ( ) ) ;
7033 break ;
7134 }
7235 }
@@ -79,15 +42,18 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
7942 } )
8043 }
8144
45+ /// Visit the memory covered by `place`, sensitive to freezing: The 3rd parameter
46+ /// will be true if this is frozen, false if this is in an `UnsafeCell`.
8247 fn visit_freeze_sensitive (
8348 & self ,
8449 place : MPlaceTy < ' tcx , Borrow > ,
8550 size : Size ,
8651 mut action : impl FnMut ( Pointer < Borrow > , Size , bool ) -> EvalResult < ' tcx > ,
8752 ) -> EvalResult < ' tcx > {
53+ let this = self . eval_context_ref ( ) ;
8854 trace ! ( "visit_frozen(place={:?}, size={:?})" , * place, size) ;
8955 debug_assert_eq ! ( size,
90- self . size_and_align_of_mplace( place) ?
56+ this . size_and_align_of_mplace( place) ?
9157 . map( |( size, _) | size)
9258 . unwrap_or_else( || place. layout. size)
9359 ) ;
@@ -106,8 +72,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
10672 }
10773 // We assume that we are given the fields in increasing offset order,
10874 // and nothing else changes.
109- let unsafe_cell_offset = unsafe_cell_ptr. get_ptr_offset ( self ) ;
110- let end_offset = end_ptr. get_ptr_offset ( self ) ;
75+ let unsafe_cell_offset = unsafe_cell_ptr. get_ptr_offset ( this ) ;
76+ let end_offset = end_ptr. get_ptr_offset ( this ) ;
11177 assert ! ( unsafe_cell_offset >= end_offset) ;
11278 let frozen_size = unsafe_cell_offset - end_offset;
11379 // Everything between the end_ptr and this `UnsafeCell` is frozen.
@@ -119,18 +85,18 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
11985 action ( unsafe_cell_ptr. to_ptr ( ) ?, unsafe_cell_size, /*frozen*/ false ) ?;
12086 }
12187 // Update end end_ptr.
122- end_ptr = unsafe_cell_ptr. ptr_wrapping_offset ( unsafe_cell_size, self ) ;
88+ end_ptr = unsafe_cell_ptr. ptr_wrapping_offset ( unsafe_cell_size, this ) ;
12389 // Done
12490 Ok ( ( ) )
12591 } ;
12692 // Run a visitor
12793 {
12894 let mut visitor = UnsafeCellVisitor {
129- ecx : self ,
95+ ecx : this ,
13096 unsafe_cell_action : |place| {
13197 trace ! ( "unsafe_cell_action on {:?}" , place. ptr) ;
13298 // We need a size to go on.
133- let unsafe_cell_size = self . size_and_align_of_mplace ( place) ?
99+ let unsafe_cell_size = this . size_and_align_of_mplace ( place) ?
134100 . map ( |( size, _) | size)
135101 // for extern types, just cover what we can
136102 . unwrap_or_else ( || place. layout . size ) ;
@@ -146,7 +112,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
146112 }
147113 // The part between the end_ptr and the end of the place is also frozen.
148114 // So pretend there is a 0-sized `UnsafeCell` at the end.
149- unsafe_cell_action ( place. ptr . ptr_wrapping_offset ( size, self ) , Size :: ZERO ) ?;
115+ unsafe_cell_action ( place. ptr . ptr_wrapping_offset ( size, this ) , Size :: ZERO ) ?;
150116 // Done!
151117 return Ok ( ( ) ) ;
152118
0 commit comments