@@ -5,68 +5,31 @@ use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX};
5
5
6
6
use crate :: * ;
7
7
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 > {
48
10
/// Get an instance for a path.
49
11
fn resolve_path ( & self , path : & [ & str ] ) -> EvalResult < ' tcx , ty:: Instance < ' tcx > > {
50
- self . tcx
12
+ let this = self . eval_context_ref ( ) ;
13
+ this. tcx
51
14
. crates ( )
52
15
. iter ( )
53
- . find ( |& & krate| self . tcx . original_crate_name ( krate) == path[ 0 ] )
16
+ . find ( |& & krate| this . tcx . original_crate_name ( krate) == path[ 0 ] )
54
17
. and_then ( |krate| {
55
18
let krate = DefId {
56
19
krate : * krate,
57
20
index : CRATE_DEF_INDEX ,
58
21
} ;
59
- let mut items = self . tcx . item_children ( krate) ;
22
+ let mut items = this . tcx . item_children ( krate) ;
60
23
let mut path_it = path. iter ( ) . skip ( 1 ) . peekable ( ) ;
61
24
62
25
while let Some ( segment) = path_it. next ( ) {
63
26
for item in mem:: replace ( & mut items, Default :: default ( ) ) . iter ( ) {
64
27
if item. ident . name == * segment {
65
28
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 ( ) ) ) ;
67
30
}
68
31
69
- items = self . tcx . item_children ( item. def . def_id ( ) ) ;
32
+ items = this . tcx . item_children ( item. def . def_id ( ) ) ;
70
33
break ;
71
34
}
72
35
}
@@ -79,15 +42,18 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
79
42
} )
80
43
}
81
44
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`.
82
47
fn visit_freeze_sensitive (
83
48
& self ,
84
49
place : MPlaceTy < ' tcx , Borrow > ,
85
50
size : Size ,
86
51
mut action : impl FnMut ( Pointer < Borrow > , Size , bool ) -> EvalResult < ' tcx > ,
87
52
) -> EvalResult < ' tcx > {
53
+ let this = self . eval_context_ref ( ) ;
88
54
trace ! ( "visit_frozen(place={:?}, size={:?})" , * place, size) ;
89
55
debug_assert_eq ! ( size,
90
- self . size_and_align_of_mplace( place) ?
56
+ this . size_and_align_of_mplace( place) ?
91
57
. map( |( size, _) | size)
92
58
. unwrap_or_else( || place. layout. size)
93
59
) ;
@@ -106,8 +72,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
106
72
}
107
73
// We assume that we are given the fields in increasing offset order,
108
74
// 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 ) ;
111
77
assert ! ( unsafe_cell_offset >= end_offset) ;
112
78
let frozen_size = unsafe_cell_offset - end_offset;
113
79
// 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:
119
85
action ( unsafe_cell_ptr. to_ptr ( ) ?, unsafe_cell_size, /*frozen*/ false ) ?;
120
86
}
121
87
// 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 ) ;
123
89
// Done
124
90
Ok ( ( ) )
125
91
} ;
126
92
// Run a visitor
127
93
{
128
94
let mut visitor = UnsafeCellVisitor {
129
- ecx : self ,
95
+ ecx : this ,
130
96
unsafe_cell_action : |place| {
131
97
trace ! ( "unsafe_cell_action on {:?}" , place. ptr) ;
132
98
// 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) ?
134
100
. map ( |( size, _) | size)
135
101
// for extern types, just cover what we can
136
102
. unwrap_or_else ( || place. layout . size ) ;
@@ -146,7 +112,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
146
112
}
147
113
// The part between the end_ptr and the end of the place is also frozen.
148
114
// 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 ) ?;
150
116
// Done!
151
117
return Ok ( ( ) ) ;
152
118
0 commit comments