@@ -30,43 +30,31 @@ impl<Tag> ScalarExt for ScalarMaybeUndef<Tag> {
30
30
}
31
31
}
32
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 > > {
33
+ impl < ' a , ' mir , ' tcx > EvalContextExt < ' a , ' mir , ' tcx > for crate :: MiriEvalContext < ' a , ' mir , ' tcx > { }
34
+ pub trait EvalContextExt < ' a , ' mir , ' tcx : ' a +' mir > : crate :: MiriEvalContextExt < ' a , ' mir , ' tcx > {
48
35
/// Get an instance for a path.
49
36
fn resolve_path ( & self , path : & [ & str ] ) -> EvalResult < ' tcx , ty:: Instance < ' tcx > > {
50
- self . tcx
37
+ let this = self . eval_context_ref ( ) ;
38
+ this. tcx
51
39
. crates ( )
52
40
. iter ( )
53
- . find ( |& & krate| self . tcx . original_crate_name ( krate) == path[ 0 ] )
41
+ . find ( |& & krate| this . tcx . original_crate_name ( krate) == path[ 0 ] )
54
42
. and_then ( |krate| {
55
43
let krate = DefId {
56
44
krate : * krate,
57
45
index : CRATE_DEF_INDEX ,
58
46
} ;
59
- let mut items = self . tcx . item_children ( krate) ;
47
+ let mut items = this . tcx . item_children ( krate) ;
60
48
let mut path_it = path. iter ( ) . skip ( 1 ) . peekable ( ) ;
61
49
62
50
while let Some ( segment) = path_it. next ( ) {
63
51
for item in mem:: replace ( & mut items, Default :: default ( ) ) . iter ( ) {
64
52
if item. ident . name == * segment {
65
53
if path_it. peek ( ) . is_none ( ) {
66
- return Some ( ty:: Instance :: mono ( self . tcx . tcx , item. def . def_id ( ) ) ) ;
54
+ return Some ( ty:: Instance :: mono ( this . tcx . tcx , item. def . def_id ( ) ) ) ;
67
55
}
68
56
69
- items = self . tcx . item_children ( item. def . def_id ( ) ) ;
57
+ items = this . tcx . item_children ( item. def . def_id ( ) ) ;
70
58
break ;
71
59
}
72
60
}
@@ -79,15 +67,18 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
79
67
} )
80
68
}
81
69
70
+ /// Visit the memory covered by `place`, sensitive to freezing: The 3rd parameter
71
+ /// will be true if this is frozen, false if this is in an `UnsafeCell`.
82
72
fn visit_freeze_sensitive (
83
73
& self ,
84
74
place : MPlaceTy < ' tcx , Borrow > ,
85
75
size : Size ,
86
76
mut action : impl FnMut ( Pointer < Borrow > , Size , bool ) -> EvalResult < ' tcx > ,
87
77
) -> EvalResult < ' tcx > {
78
+ let this = self . eval_context_ref ( ) ;
88
79
trace ! ( "visit_frozen(place={:?}, size={:?})" , * place, size) ;
89
80
debug_assert_eq ! ( size,
90
- self . size_and_align_of_mplace( place) ?
81
+ this . size_and_align_of_mplace( place) ?
91
82
. map( |( size, _) | size)
92
83
. unwrap_or_else( || place. layout. size)
93
84
) ;
@@ -106,8 +97,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
106
97
}
107
98
// We assume that we are given the fields in increasing offset order,
108
99
// 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 ) ;
100
+ let unsafe_cell_offset = unsafe_cell_ptr. get_ptr_offset ( this ) ;
101
+ let end_offset = end_ptr. get_ptr_offset ( this ) ;
111
102
assert ! ( unsafe_cell_offset >= end_offset) ;
112
103
let frozen_size = unsafe_cell_offset - end_offset;
113
104
// Everything between the end_ptr and this `UnsafeCell` is frozen.
@@ -119,18 +110,18 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
119
110
action ( unsafe_cell_ptr. to_ptr ( ) ?, unsafe_cell_size, /*frozen*/ false ) ?;
120
111
}
121
112
// Update end end_ptr.
122
- end_ptr = unsafe_cell_ptr. ptr_wrapping_offset ( unsafe_cell_size, self ) ;
113
+ end_ptr = unsafe_cell_ptr. ptr_wrapping_offset ( unsafe_cell_size, this ) ;
123
114
// Done
124
115
Ok ( ( ) )
125
116
} ;
126
117
// Run a visitor
127
118
{
128
119
let mut visitor = UnsafeCellVisitor {
129
- ecx : self ,
120
+ ecx : this ,
130
121
unsafe_cell_action : |place| {
131
122
trace ! ( "unsafe_cell_action on {:?}" , place. ptr) ;
132
123
// We need a size to go on.
133
- let unsafe_cell_size = self . size_and_align_of_mplace ( place) ?
124
+ let unsafe_cell_size = this . size_and_align_of_mplace ( place) ?
134
125
. map ( |( size, _) | size)
135
126
// for extern types, just cover what we can
136
127
. unwrap_or_else ( || place. layout . size ) ;
@@ -146,7 +137,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
146
137
}
147
138
// The part between the end_ptr and the end of the place is also frozen.
148
139
// So pretend there is a 0-sized `UnsafeCell` at the end.
149
- unsafe_cell_action ( place. ptr . ptr_wrapping_offset ( size, self ) , Size :: ZERO ) ?;
140
+ unsafe_cell_action ( place. ptr . ptr_wrapping_offset ( size, this ) , Size :: ZERO ) ?;
150
141
// Done!
151
142
return Ok ( ( ) ) ;
152
143
0 commit comments