@@ -27,6 +27,7 @@ use util::common::{profq_msg, ProfileQueriesMsg, QueryMsg};
27
27
28
28
use rustc_data_structures:: fx:: { FxHashMap } ;
29
29
use rustc_data_structures:: sync:: { Lrc , Lock } ;
30
+ use rustc_data_structures:: by_move:: { Move , MoveSlot } ;
30
31
use std:: mem;
31
32
use std:: ptr;
32
33
use std:: intrinsics:: unlikely;
@@ -115,6 +116,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
115
116
tcx : TyCtxt < ' a , ' tcx , ' _ > ,
116
117
span : Span ,
117
118
key : & Q :: Key ,
119
+ mut job_storage : MoveSlot < ' a , JobOwner < ' a , ' tcx , Q > > ,
118
120
) -> TryGetJob < ' a , ' tcx , Q > {
119
121
let cache = Q :: query_cache ( tcx) ;
120
122
loop {
@@ -144,12 +146,12 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
144
146
query : Q :: query ( key. clone ( ) ) ,
145
147
} ;
146
148
let job = Lrc :: new ( QueryJob :: new ( info, icx. query . clone ( ) ) ) ;
147
- let owner = JobOwner {
149
+ let owner = job_storage . init ( JobOwner {
148
150
cache,
149
151
job : job. clone ( ) ,
150
152
key : ( * key) . clone ( ) ,
151
153
layout_depth : icx. layout_depth ,
152
- } ;
154
+ } ) ;
153
155
entry. insert ( QueryResult :: Started ( job) ) ;
154
156
TryGetJob :: NotYetStarted ( owner)
155
157
} )
@@ -172,7 +174,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
172
174
/// Completes the query by updating the query cache with the `result`,
173
175
/// signals the waiter and forgets the JobOwner, so it won't poison the query
174
176
#[ inline]
175
- pub ( super ) fn complete ( self , result : & Q :: Value , dep_node_index : DepNodeIndex ) {
177
+ pub ( super ) fn complete ( self : Move < ' _ , Self > , result : & Q :: Value , dep_node_index : DepNodeIndex ) {
176
178
// We can move out of `self` here because we `mem::forget` it below
177
179
let key = unsafe { ptr:: read ( & self . key ) } ;
178
180
let job = unsafe { ptr:: read ( & self . job ) } ;
@@ -236,14 +238,14 @@ pub struct CycleError<'tcx> {
236
238
}
237
239
238
240
/// The result of `try_get_lock`
239
- pub ( super ) enum TryGetJob < ' a , ' tcx : ' a , D : QueryDescription < ' tcx > + ' a > {
241
+ pub ( super ) enum TryGetJob < ' a , ' tcx : ' a , Q : QueryDescription < ' tcx > + ' a > {
240
242
/// The query is not yet started. Contains a guard to the cache eventually used to start it.
241
- NotYetStarted ( JobOwner < ' a , ' tcx , D > ) ,
243
+ NotYetStarted ( Move < ' a , JobOwner < ' a , ' tcx , Q > > ) ,
242
244
243
245
/// The query was already completed.
244
246
/// Returns the result of the query and its dep node index
245
247
/// if it succeeded or a cycle error if it failed
246
- JobCompleted ( Result < ( D :: Value , DepNodeIndex ) , Box < CycleError < ' tcx > > > ) ,
248
+ JobCompleted ( Result < ( Q :: Value , DepNodeIndex ) , Box < CycleError < ' tcx > > > ) ,
247
249
}
248
250
249
251
impl < ' a , ' gcx > TyCtxt < ' a , ' gcx , ' gcx > {
@@ -372,7 +374,8 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
372
374
373
375
self . sess . profiler ( |p| p. record_query ( Q :: CATEGORY ) ) ;
374
376
375
- let job = match JobOwner :: try_get ( self , span, & key) {
377
+ let job_slot = uninit_slot ! ( ) ;
378
+ let job = match JobOwner :: try_get ( self , span, & key, Move :: uninit ( job_slot) ) {
376
379
TryGetJob :: NotYetStarted ( job) => job,
377
380
TryGetJob :: JobCompleted ( result) => {
378
381
return result. map ( |( v, index) | {
@@ -438,7 +441,7 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
438
441
fn load_from_disk_and_cache_in_memory < Q : QueryDescription < ' gcx > > (
439
442
self ,
440
443
key : Q :: Key ,
441
- job : JobOwner < ' a , ' gcx , Q > ,
444
+ job : Move < ' _ , JobOwner < ' _ , ' gcx , Q > > ,
442
445
dep_node_index : DepNodeIndex ,
443
446
dep_node : & DepNode
444
447
) -> Result < Q :: Value , Box < CycleError < ' gcx > > >
@@ -521,7 +524,7 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
521
524
fn force_query_with_job < Q : QueryDescription < ' gcx > > (
522
525
self ,
523
526
key : Q :: Key ,
524
- job : JobOwner < ' _ , ' gcx , Q > ,
527
+ job : Move < ' _ , JobOwner < ' _ , ' gcx , Q > > ,
525
528
dep_node : DepNode )
526
529
-> Result < ( Q :: Value , DepNodeIndex ) , Box < CycleError < ' gcx > > > {
527
530
// If the following assertion triggers, it can have two reasons:
@@ -616,7 +619,8 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
616
619
617
620
// We may be concurrently trying both execute and force a query
618
621
// Ensure that only one of them runs the query
619
- let job = match JobOwner :: try_get ( self , span, & key) {
622
+ let job_slot = uninit_slot ! ( ) ;
623
+ let job = match JobOwner :: try_get ( self , span, & key, Move :: uninit ( job_slot) ) {
620
624
TryGetJob :: NotYetStarted ( job) => job,
621
625
TryGetJob :: JobCompleted ( _) => return ,
622
626
} ;
0 commit comments