@@ -196,8 +196,24 @@ impl<'tcx> LocalValue {
196
196
}
197
197
198
198
/// The virtual machine state during const-evaluation at a given point in time.
199
- type EvalSnapshot < ' a , ' mir , ' tcx , M >
200
- = ( M , Vec < Frame < ' mir , ' tcx > > , Memory < ' a , ' mir , ' tcx , M > ) ;
199
+ #[ derive( Eq , PartialEq , Hash ) ]
200
+ pub ( crate ) struct EvalSnapshot < ' a , ' mir , ' tcx : ' a + ' mir , M : Machine < ' mir , ' tcx > > {
201
+ machine : M ,
202
+ memory : Memory < ' a , ' mir , ' tcx , M > ,
203
+ stack : Vec < Frame < ' mir , ' tcx > > ,
204
+ }
205
+
206
+ impl < ' a , ' mir , ' tcx , M > EvalSnapshot < ' a , ' mir , ' tcx , M >
207
+ where M : Machine < ' mir , ' tcx > ,
208
+ {
209
+ fn new < ' b > ( machine : & M , memory : & Memory < ' a , ' mir , ' tcx , M > , stack : & [ Frame < ' mir , ' tcx > ] ) -> Self {
210
+ EvalSnapshot {
211
+ machine : machine. clone ( ) ,
212
+ memory : memory. clone ( ) ,
213
+ stack : stack. into ( ) ,
214
+ }
215
+ }
216
+ }
201
217
202
218
pub ( super ) struct InfiniteLoopDetector < ' a , ' mir , ' tcx : ' a + ' mir , M : Machine < ' mir , ' tcx > > {
203
219
/// The set of all `EvalSnapshot` *hashes* observed by this detector.
@@ -238,21 +254,20 @@ impl<'a, 'mir, 'tcx, M> InfiniteLoopDetector<'a, 'mir, 'tcx, M>
238
254
pub fn observe_and_analyze (
239
255
& mut self ,
240
256
machine : & M ,
241
- stack : & Vec < Frame < ' mir , ' tcx > > ,
242
257
memory : & Memory < ' a , ' mir , ' tcx , M > ,
258
+ stack : & [ Frame < ' mir , ' tcx > ] ,
243
259
) -> EvalResult < ' tcx , ( ) > {
244
- let snapshot = ( machine, stack, memory) ;
245
260
246
261
let mut fx = FxHasher :: default ( ) ;
247
- snapshot . hash ( & mut fx) ;
262
+ ( machine , memory , stack ) . hash ( & mut fx) ;
248
263
let hash = fx. finish ( ) ;
249
264
250
265
if self . hashes . insert ( hash) {
251
266
// No collision
252
267
return Ok ( ( ) )
253
268
}
254
269
255
- if self . snapshots . insert ( ( machine. clone ( ) , stack . clone ( ) , memory . clone ( ) ) ) {
270
+ if self . snapshots . insert ( EvalSnapshot :: new ( machine, memory , stack ) ) {
256
271
// Spurious collision or first cycle
257
272
return Ok ( ( ) )
258
273
}
0 commit comments