@@ -131,7 +131,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
131
131
}
132
132
133
133
// How to traverse a value and what to do when we are at the leaves.
134
- pub trait ValueVisitor < ' a , ' mir , ' tcx , M : Machine < ' a , ' mir , ' tcx > > : fmt:: Debug {
134
+ pub trait ValueVisitor < ' a , ' mir , ' tcx , M : Machine < ' a , ' mir , ' tcx > > : fmt:: Debug + Sized {
135
135
type V : Value < ' a , ' mir , ' tcx , M > ;
136
136
137
137
// There's a value in here.
@@ -143,16 +143,16 @@ pub trait ValueVisitor<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>>: fmt::Debug {
143
143
self . value ( ) . layout ( )
144
144
}
145
145
146
- // Replace the value by `val`, which must be the `field`th field of `self`,
147
- // then call `f ` and then un-do everything that might have happened to the visitor state.
146
+ // Replace the value by `val`, which must be the `field`th field of `self`, then call
147
+ // `visit_value ` and then un-do everything that might have happened to the visitor state.
148
148
// The point of this is that some visitors keep a stack of fields that we projected below,
149
149
// and this lets us avoid copying that stack; instead they will pop the stack after
150
- // executing `f `.
151
- fn with_field (
150
+ // executing `visit_value `.
151
+ fn visit_field (
152
152
& mut self ,
153
+ ectx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
153
154
val : Self :: V ,
154
155
field : usize ,
155
- f : impl FnOnce ( & mut Self ) -> EvalResult < ' tcx > ,
156
156
) -> EvalResult < ' tcx > ;
157
157
158
158
// This is an enum, downcast it to whatever the current variant is.
@@ -170,6 +170,14 @@ pub trait ValueVisitor<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>>: fmt::Debug {
170
170
Ok ( false )
171
171
}
172
172
173
+ // Execute visitor on the current value. Used for recursing.
174
+ #[ inline]
175
+ fn visit ( & mut self , ectx : & mut EvalContext < ' a , ' mir , ' tcx , M > )
176
+ -> EvalResult < ' tcx >
177
+ {
178
+ ectx. walk_value ( self )
179
+ }
180
+
173
181
// Actions on the leaves.
174
182
fn visit_uninhabited ( & mut self , ectx : & mut EvalContext < ' a , ' mir , ' tcx , M > )
175
183
-> EvalResult < ' tcx > ;
@@ -180,11 +188,11 @@ pub trait ValueVisitor<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>>: fmt::Debug {
180
188
}
181
189
182
190
impl < ' a , ' mir , ' tcx , M : Machine < ' a , ' mir , ' tcx > > EvalContext < ' a , ' mir , ' tcx , M > {
183
- pub fn visit_value < V : ValueVisitor < ' a , ' mir , ' tcx , M > > (
191
+ pub fn walk_value < V : ValueVisitor < ' a , ' mir , ' tcx , M > > (
184
192
& mut self ,
185
193
v : & mut V ,
186
194
) -> EvalResult < ' tcx > {
187
- trace ! ( "visit_value : {:?}" , v) ;
195
+ trace ! ( "walk_value : {:?}" , v) ;
188
196
189
197
// If this is a multi-variant layout, we have find the right one and proceed with that.
190
198
// (No benefit from making this recursion, but it is equivalent to that.)
@@ -205,7 +213,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
205
213
let dest = v. value ( ) . force_allocation ( self ) ?;
206
214
let inner = self . unpack_dyn_trait ( dest) ?. 1 ;
207
215
// recurse with the inner type
208
- return v. with_field ( Value :: from_mem_place ( inner) , 0 , |v| self . visit_value ( v ) ) ;
216
+ return v. visit_field ( self , Value :: from_mem_place ( inner) , 0 ) ;
209
217
} ,
210
218
_ => { } ,
211
219
} ;
@@ -256,7 +264,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
256
264
layout:: FieldPlacement :: Arbitrary { ref offsets, .. } => {
257
265
for i in 0 ..offsets. len ( ) {
258
266
let val = v. value ( ) . project_field ( self , i as u64 ) ?;
259
- v. with_field ( val , i , |v| self . visit_value ( v ) ) ?;
267
+ v. visit_field ( self , val , i ) ?;
260
268
}
261
269
} ,
262
270
layout:: FieldPlacement :: Array { .. } => {
@@ -272,7 +280,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
272
280
} ;
273
281
// Now iterate over it.
274
282
for ( i, field) in self . mplace_array_fields ( mplace) ?. enumerate ( ) {
275
- v. with_field ( Value :: from_mem_place ( field?) , i, |v| self . visit_value ( v ) ) ?;
283
+ v. visit_field ( self , Value :: from_mem_place ( field?) , i) ?;
276
284
}
277
285
}
278
286
}
0 commit comments