@@ -22,17 +22,18 @@ use petgraph::prelude::*;
2222use rustc_hash:: { FxHashMap , FxHashSet } ;
2323use std:: mem;
2424use std:: sync:: Arc ;
25+ use tokio:: sync:: RwLock ;
2526use tracing:: { debug, instrument, trace} ;
2627
2728macro_rules! insert_node_or_exit {
2829 ( $builder: ident, $node: expr) => { {
2930 let node = $node;
3031
31- match $builder. get_index_from_node( & node) {
32+ match $builder. get_index_from_node( & node) . await {
3233 Some ( index) => {
3334 return Ok ( Some ( index) ) ;
3435 }
35- None => $builder. insert_node( node) ,
36+ None => $builder. insert_node( node) . await ,
3637 }
3738 } } ;
3839}
@@ -78,7 +79,7 @@ pub struct ActionGraphBuilder<'query> {
7879 all_query : Option < Criteria < ' query > > ,
7980 app_context : Arc < AppContext > ,
8081 graph : DiGraph < ActionNode , ( ) > ,
81- nodes : FxHashMap < ActionNode , NodeIndex > ,
82+ nodes : RwLock < FxHashMap < ActionNode , NodeIndex > > ,
8283 options : ActionGraphBuilderOptions ,
8384 platform_manager : Option < PlatformManager > ,
8485 workspace_graph : Arc < WorkspaceGraph > ,
@@ -106,7 +107,7 @@ impl<'query> ActionGraphBuilder<'query> {
106107 all_query : None ,
107108 app_context,
108109 graph : DiGraph :: new ( ) ,
109- nodes : FxHashMap :: default ( ) ,
110+ nodes : RwLock :: new ( FxHashMap :: default ( ) ) ,
110111 options,
111112 passthrough_targets : FxHashSet :: default ( ) ,
112113 platform_manager : None ,
@@ -269,10 +270,10 @@ impl<'query> ActionGraphBuilder<'query> {
269270 return Ok ( None ) ;
270271 } ;
271272
272- let mut edges = vec ! [
273+ let mut edges = FxHashSet :: from_iter ( [
273274 self . sync_workspace ( ) . await ?,
274275 self . setup_toolchain_legacy ( runtime) . await ?,
275- ] ;
276+ ] ) ;
276277
277278 let platform_manager = match & self . platform_manager {
278279 Some ( manager) => manager,
@@ -312,7 +313,7 @@ impl<'query> ActionGraphBuilder<'query> {
312313 ) ;
313314 }
314315
315- edges. push ( self . setup_toolchain_legacy ( & new_runtime) . await ?) ;
316+ edges. insert ( self . setup_toolchain_legacy ( & new_runtime) . await ?) ;
316317
317318 let index = insert_node_or_exit ! (
318319 self ,
@@ -329,7 +330,7 @@ impl<'query> ActionGraphBuilder<'query> {
329330 }
330331 ) ;
331332
332- self . link_optional_requirements ( index, edges) ;
333+ self . link_optional_requirements ( index, edges. into_iter ( ) . collect ( ) ) ;
333334
334335 Ok ( Some ( index) )
335336 }
@@ -833,7 +834,7 @@ impl<'query> ActionGraphBuilder<'query> {
833834 } ) ;
834835
835836 // Check if the node exists to avoid all the overhead below
836- if let Some ( index) = self . get_index_from_node ( & node) {
837+ if let Some ( index) = self . get_index_from_node ( & node) . await {
837838 return Ok ( Some ( index) ) ;
838839 }
839840
@@ -851,7 +852,7 @@ impl<'query> ActionGraphBuilder<'query> {
851852 }
852853
853854 // Insert and then link edges
854- let index = self . insert_node ( node) ;
855+ let index = self . insert_node ( node) . await ;
855856
856857 if !task. deps . is_empty ( ) {
857858 child_reqs. skip_affected = true ;
@@ -1037,8 +1038,8 @@ impl<'query> ActionGraphBuilder<'query> {
10371038
10381039 // PRIVATE
10391040
1040- fn get_index_from_node ( & self , node : & ActionNode ) -> Option < NodeIndex > {
1041- self . nodes . get ( node) . cloned ( )
1041+ async fn get_index_from_node ( & self , node : & ActionNode ) -> Option < NodeIndex > {
1042+ self . nodes . read ( ) . await . get ( node) . cloned ( )
10421043 }
10431044
10441045 fn link_first_requirement ( & mut self , index : NodeIndex , edges : Vec < Option < NodeIndex > > ) {
@@ -1069,11 +1070,13 @@ impl<'query> ActionGraphBuilder<'query> {
10691070 }
10701071 }
10711072
1072- fn insert_node ( & mut self , node : ActionNode ) -> NodeIndex {
1073+ async fn insert_node ( & mut self , node : ActionNode ) -> NodeIndex {
1074+ let mut nodes = self . nodes . write ( ) . await ;
1075+
10731076 let label = node. label ( ) ;
10741077 let index = self . graph . add_node ( node. clone ( ) ) ;
10751078
1076- self . nodes . insert ( node, index) ;
1079+ nodes. insert ( node, index) ;
10771080
10781081 debug ! (
10791082 index = index. index( ) ,
0 commit comments