@@ -7,6 +7,8 @@ use crate::query::caches::QueryCache;
77use crate :: query:: config:: { QueryDescription , QueryVTable } ;
88use crate :: query:: job:: { report_cycle, QueryInfo , QueryJob , QueryJobId , QueryJobInfo } ;
99use crate :: query:: { QueryContext , QueryMap , QuerySideEffects , QueryStackFrame } ;
10+ use crate :: values:: Value ;
11+ use crate :: HandleCycleError ;
1012use rustc_data_structures:: fingerprint:: Fingerprint ;
1113use rustc_data_structures:: fx:: FxHashMap ;
1214#[ cfg( parallel_compiler) ]
@@ -118,19 +120,46 @@ where
118120fn mk_cycle < CTX , V , R > (
119121 tcx : CTX ,
120122 error : CycleError ,
121- handle_cycle_error : fn ( CTX , DiagnosticBuilder < ' _ , ErrorGuaranteed > ) -> V ,
123+ handler : HandleCycleError ,
122124 cache : & dyn crate :: query:: QueryStorage < Value = V , Stored = R > ,
123125) -> R
124126where
125127 CTX : QueryContext ,
126- V : std:: fmt:: Debug ,
128+ V : std:: fmt:: Debug + Value < CTX :: DepContext > ,
127129 R : Clone ,
128130{
129131 let error = report_cycle ( tcx. dep_context ( ) . sess ( ) , error) ;
130- let value = handle_cycle_error ( tcx, error) ;
132+ let value = handle_cycle_error ( * tcx. dep_context ( ) , error, handler ) ;
131133 cache. store_nocache ( value)
132134}
133135
136+ fn handle_cycle_error < CTX , V > (
137+ tcx : CTX ,
138+ mut error : DiagnosticBuilder < ' _ , ErrorGuaranteed > ,
139+ handler : HandleCycleError ,
140+ ) -> V
141+ where
142+ CTX : DepContext ,
143+ V : Value < CTX > ,
144+ {
145+ use HandleCycleError :: * ;
146+ match handler {
147+ Error => {
148+ error. emit ( ) ;
149+ Value :: from_cycle_error ( tcx)
150+ }
151+ Fatal => {
152+ error. emit ( ) ;
153+ tcx. sess ( ) . abort_if_errors ( ) ;
154+ unreachable ! ( )
155+ }
156+ DelayBug => {
157+ error. delay_as_bug ( ) ;
158+ Value :: from_cycle_error ( tcx)
159+ }
160+ }
161+ }
162+
134163impl < ' tcx , K > JobOwner < ' tcx , K >
135164where
136165 K : Eq + Hash + Clone ,
@@ -336,6 +365,7 @@ fn try_execute_query<CTX, C>(
336365where
337366 C : QueryCache ,
338367 C :: Key : Clone + DepNodeParams < CTX :: DepContext > ,
368+ C :: Value : Value < CTX :: DepContext > ,
339369 CTX : QueryContext ,
340370{
341371 match JobOwner :: < ' _ , C :: Key > :: try_start ( & tcx, state, span, key. clone ( ) ) {
@@ -686,6 +716,7 @@ pub fn get_query<Q, CTX>(tcx: CTX, span: Span, key: Q::Key, mode: QueryMode) ->
686716where
687717 Q : QueryDescription < CTX > ,
688718 Q :: Key : DepNodeParams < CTX :: DepContext > ,
719+ Q :: Value : Value < CTX :: DepContext > ,
689720 CTX : QueryContext ,
690721{
691722 let query = Q :: make_vtable ( tcx, & key) ;
@@ -718,6 +749,7 @@ pub fn force_query<Q, CTX>(tcx: CTX, key: Q::Key, dep_node: DepNode<CTX::DepKind
718749where
719750 Q : QueryDescription < CTX > ,
720751 Q :: Key : DepNodeParams < CTX :: DepContext > ,
752+ Q :: Value : Value < CTX :: DepContext > ,
721753 CTX : QueryContext ,
722754{
723755 // We may be concurrently trying both execute and force a query.
0 commit comments