@@ -148,7 +148,6 @@ struct JobOwner<'tcx, CTX: QueryContext, C>
148
148
where
149
149
C : QueryCache ,
150
150
C :: Key : Eq + Hash + Clone + Debug ,
151
- C :: Value : Clone ,
152
151
{
153
152
state : & ' tcx QueryState < CTX , C > ,
154
153
key : C :: Key ,
@@ -159,7 +158,6 @@ impl<'tcx, CTX: QueryContext, C> JobOwner<'tcx, CTX, C>
159
158
where
160
159
C : QueryCache ,
161
160
C :: Key : Eq + Hash + Clone + Debug ,
162
- C :: Value : Clone ,
163
161
{
164
162
/// Either gets a `JobOwner` corresponding the query, allowing us to
165
163
/// start executing the query, or returns with the result of the query.
@@ -177,7 +175,7 @@ where
177
175
mut lookup : QueryLookup < ' a , CTX , C :: Key , C :: Sharded > ,
178
176
) -> TryGetJob < ' b , CTX , C >
179
177
where
180
- Q : QueryDescription < CTX , Key = C :: Key , Value = C :: Value , Cache = C > ,
178
+ Q : QueryDescription < CTX , Key = C :: Key , Stored = C :: Stored , Value = C :: Value , Cache = C > ,
181
179
CTX : QueryContext ,
182
180
{
183
181
let lock = & mut * lookup. lock ;
@@ -229,7 +227,8 @@ where
229
227
// so we just return the error.
230
228
#[ cfg( not( parallel_compiler) ) ]
231
229
return TryGetJob :: Cycle ( cold_path ( || {
232
- Q :: handle_cycle_error ( tcx, latch. find_cycle_in_stack ( tcx, span) )
230
+ let value = Q :: handle_cycle_error ( tcx, latch. find_cycle_in_stack ( tcx, span) ) ;
231
+ Q :: query_state ( tcx) . cache . store_nocache ( value)
233
232
} ) ) ;
234
233
235
234
// With parallel queries we might just have to wait on some other
@@ -239,7 +238,9 @@ where
239
238
let result = latch. wait_on ( tcx, span) ;
240
239
241
240
if let Err ( cycle) = result {
242
- return TryGetJob :: Cycle ( Q :: handle_cycle_error ( tcx, cycle) ) ;
241
+ let value = Q :: handle_cycle_error ( tcx, cycle) ;
242
+ let value = Q :: query_state ( tcx) . cache . store_nocache ( value) ;
243
+ return TryGetJob :: Cycle ( value) ;
243
244
}
244
245
245
246
let cached = try_get_cached (
@@ -261,26 +262,26 @@ where
261
262
/// Completes the query by updating the query cache with the `result`,
262
263
/// signals the waiter and forgets the JobOwner, so it won't poison the query
263
264
#[ inline( always) ]
264
- fn complete ( self , tcx : CTX , result : & C :: Value , dep_node_index : DepNodeIndex ) {
265
+ fn complete ( self , tcx : CTX , result : C :: Value , dep_node_index : DepNodeIndex ) -> C :: Stored {
265
266
// We can move out of `self` here because we `mem::forget` it below
266
267
let key = unsafe { ptr:: read ( & self . key ) } ;
267
268
let state = self . state ;
268
269
269
270
// Forget ourself so our destructor won't poison the query
270
271
mem:: forget ( self ) ;
271
272
272
- let job = {
273
- let result = result. clone ( ) ;
273
+ let ( job, result) = {
274
274
let mut lock = state. shards . get_shard_by_value ( & key) . lock ( ) ;
275
275
let job = match lock. active . remove ( & key) . unwrap ( ) {
276
276
QueryResult :: Started ( job) => job,
277
277
QueryResult :: Poisoned => panic ! ( ) ,
278
278
} ;
279
- state. cache . complete ( tcx, & mut lock. cache , key, result, dep_node_index) ;
280
- job
279
+ let result = state. cache . complete ( tcx, & mut lock. cache , key, result, dep_node_index) ;
280
+ ( job, result )
281
281
} ;
282
282
283
283
job. signal_complete ( ) ;
284
+ result
284
285
}
285
286
}
286
287
@@ -297,7 +298,6 @@ where
297
298
impl < ' tcx , CTX : QueryContext , C : QueryCache > Drop for JobOwner < ' tcx , CTX , C >
298
299
where
299
300
C :: Key : Eq + Hash + Clone + Debug ,
300
- C :: Value : Clone ,
301
301
{
302
302
#[ inline( never) ]
303
303
#[ cold]
@@ -331,7 +331,6 @@ pub struct CycleError<Q> {
331
331
enum TryGetJob < ' tcx , CTX : QueryContext , C : QueryCache >
332
332
where
333
333
C :: Key : Eq + Hash + Clone + Debug ,
334
- C :: Value : Clone ,
335
334
{
336
335
/// The query is not yet started. Contains a guard to the cache eventually used to start it.
337
336
NotYetStarted ( JobOwner < ' tcx , CTX , C > ) ,
@@ -340,10 +339,10 @@ where
340
339
/// Returns the result of the query and its dep-node index
341
340
/// if it succeeded or a cycle error if it failed.
342
341
#[ cfg( parallel_compiler) ]
343
- JobCompleted ( ( C :: Value , DepNodeIndex ) ) ,
342
+ JobCompleted ( ( C :: Stored , DepNodeIndex ) ) ,
344
343
345
344
/// Trying to execute the query resulted in a cycle.
346
- Cycle ( C :: Value ) ,
345
+ Cycle ( C :: Stored ) ,
347
346
}
348
347
349
348
/// Checks if the query is already computed and in the cache.
@@ -362,7 +361,7 @@ fn try_get_cached<CTX, C, R, OnHit, OnMiss>(
362
361
where
363
362
C : QueryCache ,
364
363
CTX : QueryContext ,
365
- OnHit : FnOnce ( & C :: Value , DepNodeIndex ) -> R ,
364
+ OnHit : FnOnce ( & C :: Stored , DepNodeIndex ) -> R ,
366
365
OnMiss : FnOnce ( C :: Key , QueryLookup < ' _ , CTX , C :: Key , C :: Sharded > ) -> R ,
367
366
{
368
367
state. cache . lookup (
@@ -388,7 +387,7 @@ fn try_execute_query<Q, CTX>(
388
387
span : Span ,
389
388
key : Q :: Key ,
390
389
lookup : QueryLookup < ' _ , CTX , Q :: Key , <Q :: Cache as QueryCache >:: Sharded > ,
391
- ) -> Q :: Value
390
+ ) -> Q :: Stored
392
391
where
393
392
Q : QueryDescription < CTX > ,
394
393
CTX : QueryContext ,
@@ -427,9 +426,7 @@ where
427
426
tcx. store_diagnostics_for_anon_node ( dep_node_index, diagnostics) ;
428
427
}
429
428
430
- job. complete ( tcx, & result, dep_node_index) ;
431
-
432
- return result;
429
+ return job. complete ( tcx, result, dep_node_index) ;
433
430
}
434
431
435
432
let dep_node = Q :: to_dep_node ( tcx, & key) ;
@@ -454,8 +451,7 @@ where
454
451
} )
455
452
} ) ;
456
453
if let Some ( ( result, dep_node_index) ) = loaded {
457
- job. complete ( tcx, & result, dep_node_index) ;
458
- return result;
454
+ return job. complete ( tcx, result, dep_node_index) ;
459
455
}
460
456
}
461
457
@@ -558,7 +554,7 @@ fn force_query_with_job<Q, CTX>(
558
554
key : Q :: Key ,
559
555
job : JobOwner < ' _ , CTX , Q :: Cache > ,
560
556
dep_node : DepNode < CTX :: DepKind > ,
561
- ) -> ( Q :: Value , DepNodeIndex )
557
+ ) -> ( Q :: Stored , DepNodeIndex )
562
558
where
563
559
Q : QueryDescription < CTX > ,
564
560
CTX : QueryContext ,
@@ -603,13 +599,13 @@ where
603
599
}
604
600
}
605
601
606
- job. complete ( tcx, & result, dep_node_index) ;
602
+ let result = job. complete ( tcx, result, dep_node_index) ;
607
603
608
604
( result, dep_node_index)
609
605
}
610
606
611
607
#[ inline( never) ]
612
- pub fn get_query < Q , CTX > ( tcx : CTX , span : Span , key : Q :: Key ) -> Q :: Value
608
+ pub fn get_query < Q , CTX > ( tcx : CTX , span : Span , key : Q :: Key ) -> Q :: Stored
613
609
where
614
610
Q : QueryDescription < CTX > ,
615
611
CTX : QueryContext ,
0 commit comments