@@ -23,7 +23,7 @@ use {super::debug::EdgeFilter, std::env};
2323
2424use super :: query:: DepGraphQuery ;
2525use super :: serialized:: { GraphEncoder , SerializedDepGraph , SerializedDepNodeIndex } ;
26- use super :: { DepKind , DepNode , HasDepContext , WorkProductId , read_deps, with_deps} ;
26+ use super :: { DepKind , DepNode , WorkProductId , read_deps, with_deps} ;
2727use crate :: dep_graph:: edges:: EdgesVec ;
2828use crate :: ich:: StableHashingContext ;
2929use crate :: ty:: TyCtxt ;
@@ -268,17 +268,17 @@ impl DepGraph {
268268 }
269269
270270 #[ inline( always) ]
271- pub fn with_task < ' tcx , Ctxt : HasDepContext < ' tcx > , A : Debug , R > (
271+ pub fn with_task < ' tcx , A : Debug , R > (
272272 & self ,
273- key : DepNode ,
274- cx : Ctxt ,
275- arg : A ,
276- task : fn ( Ctxt , A ) -> R ,
273+ dep_node : DepNode ,
274+ tcx : TyCtxt < ' tcx > ,
275+ task_arg : A ,
276+ task_fn : fn ( tcx : TyCtxt < ' tcx > , task_arg : A ) -> R ,
277277 hash_result : Option < fn ( & mut StableHashingContext < ' _ > , & R ) -> Fingerprint > ,
278278 ) -> ( R , DepNodeIndex ) {
279279 match self . data ( ) {
280- Some ( data) => data. with_task ( key , cx , arg , task , hash_result) ,
281- None => ( task ( cx , arg ) , self . next_virtual_depnode_index ( ) ) ,
280+ Some ( data) => data. with_task ( dep_node , tcx , task_arg , task_fn , hash_result) ,
281+ None => ( task_fn ( tcx , task_arg ) , self . next_virtual_depnode_index ( ) ) ,
282282 }
283283 }
284284
@@ -310,66 +310,50 @@ impl DepGraphData {
310310 /// prevent implicit 'leaks' of tracked state into the task (which
311311 /// could then be read without generating correct edges in the
312312 /// dep-graph -- see the [rustc dev guide] for more details on
313- /// the dep-graph). To this end, the task function gets exactly two
314- /// pieces of state: the context `cx` and an argument `arg`. Both
315- /// of these bits of state must be of some type that implements
316- /// `DepGraphSafe` and hence does not leak.
317- ///
318- /// The choice of two arguments is not fundamental. One argument
319- /// would work just as well, since multiple values can be
320- /// collected using tuples. However, using two arguments works out
321- /// to be quite convenient, since it is common to need a context
322- /// (`cx`) and some argument (e.g., a `DefId` identifying what
323- /// item to process).
313+ /// the dep-graph).
324314 ///
325- /// For cases where you need some other number of arguments:
326- ///
327- /// - If you only need one argument, just use `()` for the `arg`
328- /// parameter.
329- /// - If you need 3+ arguments, use a tuple for the
330- /// `arg` parameter.
315+ /// Therefore, the task function takes a `TyCtxt`, plus exactly one
316+ /// additional argument, `task_arg`. The additional argument type can be
317+ /// `()` if no argument is needed, or a tuple if multiple arguments are
318+ /// needed.
331319 ///
332320 /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html
333321 #[ inline( always) ]
334- pub fn with_task < ' tcx , Ctxt : HasDepContext < ' tcx > , A : Debug , R > (
322+ pub fn with_task < ' tcx , A : Debug , R > (
335323 & self ,
336- key : DepNode ,
337- cx : Ctxt ,
338- arg : A ,
339- task : fn ( Ctxt , A ) -> R ,
324+ dep_node : DepNode ,
325+ tcx : TyCtxt < ' tcx > ,
326+ task_arg : A ,
327+ task_fn : fn ( tcx : TyCtxt < ' tcx > , task_arg : A ) -> R ,
340328 hash_result : Option < fn ( & mut StableHashingContext < ' _ > , & R ) -> Fingerprint > ,
341329 ) -> ( R , DepNodeIndex ) {
342330 // If the following assertion triggers, it can have two reasons:
343331 // 1. Something is wrong with DepNode creation, either here or
344332 // in `DepGraph::try_mark_green()`.
345333 // 2. Two distinct query keys get mapped to the same `DepNode`
346334 // (see for example #48923).
347- self . assert_dep_node_not_yet_allocated_in_current_session (
348- cx. dep_context ( ) . sess ,
349- & key,
350- || {
351- format ! (
352- "forcing query with already existing `DepNode`\n \
353- - query-key: {arg:?}\n \
354- - dep-node: {key:?}"
355- )
356- } ,
357- ) ;
335+ self . assert_dep_node_not_yet_allocated_in_current_session ( tcx. sess , & dep_node, || {
336+ format ! (
337+ "forcing query with already existing `DepNode`\n \
338+ - query-key: {task_arg:?}\n \
339+ - dep-node: {dep_node:?}"
340+ )
341+ } ) ;
358342
359- let with_deps = |task_deps| with_deps ( task_deps, || task ( cx , arg ) ) ;
360- let ( result, edges) = if cx . dep_context ( ) . is_eval_always ( key . kind ) {
343+ let with_deps = |task_deps| with_deps ( task_deps, || task_fn ( tcx , task_arg ) ) ;
344+ let ( result, edges) = if tcx . is_eval_always ( dep_node . kind ) {
361345 ( with_deps ( TaskDepsRef :: EvalAlways ) , EdgesVec :: new ( ) )
362346 } else {
363347 let task_deps = Lock :: new ( TaskDeps :: new (
364348 #[ cfg( debug_assertions) ]
365- Some ( key ) ,
349+ Some ( dep_node ) ,
366350 0 ,
367351 ) ) ;
368352 ( with_deps ( TaskDepsRef :: Allow ( & task_deps) ) , task_deps. into_inner ( ) . reads )
369353 } ;
370354
371355 let dep_node_index =
372- self . hash_result_and_alloc_node ( cx . dep_context ( ) , key , edges, & result, hash_result) ;
356+ self . hash_result_and_alloc_node ( tcx , dep_node , edges, & result, hash_result) ;
373357
374358 ( result, dep_node_index)
375359 }
@@ -954,7 +938,7 @@ impl DepGraphData {
954938
955939 // We failed to mark it green, so we try to force the query.
956940 debug ! ( "trying to force dependency {dep_dep_node:?}" ) ;
957- if !tcx. dep_context ( ) . try_force_from_dep_node ( * dep_dep_node, parent_dep_node_index, frame) {
941+ if !tcx. try_force_from_dep_node ( * dep_dep_node, parent_dep_node_index, frame) {
958942 // The DepNode could not be forced.
959943 debug ! ( "dependency {dep_dep_node:?} could not be forced" ) ;
960944 return None ;
@@ -1001,10 +985,7 @@ impl DepGraphData {
1001985 let frame = MarkFrame { index : prev_dep_node_index, parent : frame } ;
1002986
1003987 // We never try to mark eval_always nodes as green
1004- debug_assert ! (
1005- !tcx. dep_context( )
1006- . is_eval_always( self . previous. index_to_node( prev_dep_node_index) . kind)
1007- ) ;
988+ debug_assert ! ( !tcx. is_eval_always( self . previous. index_to_node( prev_dep_node_index) . kind) ) ;
1008989
1009990 let prev_deps = self . previous . edge_targets_from ( prev_dep_node_index) ;
1010991
0 commit comments