@@ -252,17 +252,17 @@ impl DepGraph {
252252 }
253253
254254 #[ inline( always) ]
255- pub fn with_task < ' tcx , Ctxt : HasDepContext < ' tcx > , A : Debug , R > (
255+ pub fn with_task < ' tcx , A : Debug , R > (
256256 & self ,
257- key : DepNode ,
258- cx : Ctxt ,
259- arg : A ,
260- task : fn ( Ctxt , A ) -> R ,
257+ dep_node : DepNode ,
258+ tcx : TyCtxt < ' tcx > ,
259+ task_arg : A ,
260+ task_fn : fn ( tcx : TyCtxt < ' tcx > , task_arg : A ) -> R ,
261261 hash_result : Option < fn ( & mut StableHashingContext < ' _ > , & R ) -> Fingerprint > ,
262262 ) -> ( R , DepNodeIndex ) {
263263 match self . data ( ) {
264- Some ( data) => data. with_task ( key , cx , arg , task , hash_result) ,
265- None => ( task ( cx , arg ) , self . next_virtual_depnode_index ( ) ) ,
264+ Some ( data) => data. with_task ( dep_node , tcx , task_arg , task_fn , hash_result) ,
265+ None => ( task_fn ( tcx , task_arg ) , self . next_virtual_depnode_index ( ) ) ,
266266 }
267267 }
268268
@@ -294,66 +294,50 @@ impl DepGraphData {
294294 /// prevent implicit 'leaks' of tracked state into the task (which
295295 /// could then be read without generating correct edges in the
296296 /// dep-graph -- see the [rustc dev guide] for more details on
297- /// the dep-graph). To this end, the task function gets exactly two
298- /// pieces of state: the context `cx` and an argument `arg`. Both
299- /// of these bits of state must be of some type that implements
300- /// `DepGraphSafe` and hence does not leak.
301- ///
302- /// The choice of two arguments is not fundamental. One argument
303- /// would work just as well, since multiple values can be
304- /// collected using tuples. However, using two arguments works out
305- /// to be quite convenient, since it is common to need a context
306- /// (`cx`) and some argument (e.g., a `DefId` identifying what
307- /// item to process).
297+ /// the dep-graph).
308298 ///
309- /// For cases where you need some other number of arguments:
310- ///
311- /// - If you only need one argument, just use `()` for the `arg`
312- /// parameter.
313- /// - If you need 3+ arguments, use a tuple for the
314- /// `arg` parameter.
299+ /// Therefore, the task function takes a `TyCtxt`, plus exactly one
300+ /// additional argument, `task_arg`. The additional argument type can be
301+ /// `()` if no argument is needed, or a tuple if multiple arguments are
302+ /// needed.
315303 ///
316304 /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html
317305 #[ inline( always) ]
318- pub fn with_task < ' tcx , Ctxt : HasDepContext < ' tcx > , A : Debug , R > (
306+ pub fn with_task < ' tcx , A : Debug , R > (
319307 & self ,
320- key : DepNode ,
321- cx : Ctxt ,
322- arg : A ,
323- task : fn ( Ctxt , A ) -> R ,
308+ dep_node : DepNode ,
309+ tcx : TyCtxt < ' tcx > ,
310+ task_arg : A ,
311+ task_fn : fn ( tcx : TyCtxt < ' tcx > , task_arg : A ) -> R ,
324312 hash_result : Option < fn ( & mut StableHashingContext < ' _ > , & R ) -> Fingerprint > ,
325313 ) -> ( R , DepNodeIndex ) {
326314 // If the following assertion triggers, it can have two reasons:
327315 // 1. Something is wrong with DepNode creation, either here or
328316 // in `DepGraph::try_mark_green()`.
329317 // 2. Two distinct query keys get mapped to the same `DepNode`
330318 // (see for example #48923).
331- self . assert_dep_node_not_yet_allocated_in_current_session (
332- cx. dep_context ( ) . sess ,
333- & key,
334- || {
335- format ! (
336- "forcing query with already existing `DepNode`\n \
337- - query-key: {arg:?}\n \
338- - dep-node: {key:?}"
339- )
340- } ,
341- ) ;
319+ self . assert_dep_node_not_yet_allocated_in_current_session ( tcx. sess , & dep_node, || {
320+ format ! (
321+ "forcing query with already existing `DepNode`\n \
322+ - query-key: {task_arg:?}\n \
323+ - dep-node: {dep_node:?}"
324+ )
325+ } ) ;
342326
343- let with_deps = |task_deps| with_deps ( task_deps, || task ( cx , arg ) ) ;
344- let ( result, edges) = if cx . dep_context ( ) . is_eval_always ( key . kind ) {
327+ let with_deps = |task_deps| with_deps ( task_deps, || task_fn ( tcx , task_arg ) ) ;
328+ let ( result, edges) = if tcx . is_eval_always ( dep_node . kind ) {
345329 ( with_deps ( TaskDepsRef :: EvalAlways ) , EdgesVec :: new ( ) )
346330 } else {
347331 let task_deps = Lock :: new ( TaskDeps :: new (
348332 #[ cfg( debug_assertions) ]
349- Some ( key ) ,
333+ Some ( dep_node ) ,
350334 0 ,
351335 ) ) ;
352336 ( with_deps ( TaskDepsRef :: Allow ( & task_deps) ) , task_deps. into_inner ( ) . reads )
353337 } ;
354338
355339 let dep_node_index =
356- self . hash_result_and_alloc_node ( cx . dep_context ( ) , key , edges, & result, hash_result) ;
340+ self . hash_result_and_alloc_node ( tcx , dep_node , edges, & result, hash_result) ;
357341
358342 ( result, dep_node_index)
359343 }
0 commit comments