@@ -18,6 +18,11 @@ use syntax_pos::Span;
1818use ty:: tls;
1919use ty:: query:: Query ;
2020use ty:: query:: plumbing:: CycleError ;
21+ #[ cfg( not( parallel_queries) ) ]
22+ use ty:: query:: {
23+ plumbing:: TryGetJob ,
24+ config:: QueryDescription ,
25+ } ;
2126use ty:: context:: TyCtxt ;
2227use errors:: Diagnostic ;
2328use std:: process;
@@ -83,41 +88,49 @@ impl<'tcx> QueryJob<'tcx> {
8388 ///
8489 /// For single threaded rustc there's no concurrent jobs running, so if we are waiting for any
8590 /// query that means that there is a query cycle, thus this always running a cycle error.
86- pub ( super ) fn await < ' lcx > (
91+ #[ cfg( not( parallel_queries) ) ]
92+ #[ inline( never) ]
93+ #[ cold]
94+ pub ( super ) fn await < ' lcx , ' a , D : QueryDescription < ' tcx > > (
8795 & self ,
8896 tcx : TyCtxt < ' _ , ' tcx , ' lcx > ,
8997 span : Span ,
90- ) -> Result < ( ) , CycleError < ' tcx > > {
91- #[ cfg( not( parallel_queries) ) ]
92- {
93- self . find_cycle_in_stack ( tcx, span)
94- }
95-
96- #[ cfg( parallel_queries) ]
97- {
98- tls:: with_related_context ( tcx, move |icx| {
99- let mut waiter = Lrc :: new ( QueryWaiter {
100- query : icx. query . clone ( ) ,
101- span,
102- cycle : Lock :: new ( None ) ,
103- condvar : Condvar :: new ( ) ,
104- } ) ;
105- self . latch . await ( & waiter) ;
98+ ) -> TryGetJob < ' a , ' tcx , D > {
99+ TryGetJob :: JobCompleted ( Err ( Box :: new ( self . find_cycle_in_stack ( tcx, span) ) ) )
100+ }
106101
107- match Lrc :: get_mut ( & mut waiter) . unwrap ( ) . cycle . get_mut ( ) . take ( ) {
108- None => Ok ( ( ) ) ,
109- Some ( cycle) => Err ( cycle)
110- }
111- } )
112- }
102+ /// Awaits for the query job to complete.
103+ ///
104+ /// For single threaded rustc there's no concurrent jobs running, so if we are waiting for any
105+ /// query that means that there is a query cycle, thus this always running a cycle error.
106+ #[ cfg( parallel_queries) ]
107+ pub ( super ) fn await < ' lcx > (
108+ & self ,
109+ tcx : TyCtxt < ' _ , ' tcx , ' lcx > ,
110+ span : Span ,
111+ ) -> Result < ( ) , Box < CycleError < ' tcx > > > {
112+ tls:: with_related_context ( tcx, move |icx| {
113+ let mut waiter = Lrc :: new ( QueryWaiter {
114+ query : icx. query . clone ( ) ,
115+ span,
116+ cycle : Lock :: new ( None ) ,
117+ condvar : Condvar :: new ( ) ,
118+ } ) ;
119+ self . latch . await ( & waiter) ;
120+
121+ match Lrc :: get_mut ( & mut waiter) . unwrap ( ) . cycle . get_mut ( ) . take ( ) {
122+ None => Ok ( ( ) ) ,
123+ Some ( cycle) => Err ( Box :: new ( cycle) )
124+ }
125+ } )
113126 }
114127
115128 #[ cfg( not( parallel_queries) ) ]
116129 fn find_cycle_in_stack < ' lcx > (
117130 & self ,
118131 tcx : TyCtxt < ' _ , ' tcx , ' lcx > ,
119132 span : Span ,
120- ) -> Result < ( ) , CycleError < ' tcx > > {
133+ ) -> CycleError < ' tcx > {
121134 // Get the current executing query (waiter) and find the waitee amongst its parents
122135 let mut current_job = tls:: with_related_context ( tcx, |icx| icx. query . clone ( ) ) ;
123136 let mut cycle = Vec :: new ( ) ;
@@ -137,7 +150,7 @@ impl<'tcx> QueryJob<'tcx> {
137150 let usage = job. parent . as_ref ( ) . map ( |parent| {
138151 ( job. info . span , parent. info . query . clone ( ) )
139152 } ) ;
140- return Err ( CycleError { usage, cycle } ) ;
153+ return CycleError { usage, cycle } ;
141154 }
142155
143156 current_job = job. parent . clone ( ) ;
0 commit comments