1- use anyhow:: Result ;
1+ use anyhow:: { Context , Result } ;
22use rustc_hash:: FxHashSet ;
3- use turbo_tasks:: { ResolvedVc , TryFlatJoinIterExt , Vc } ;
3+ use turbo_tasks:: { OperationVc , ResolvedVc , TryFlatJoinIterExt , Vc } ;
44
55use crate :: {
66 module:: { Module , Modules } ,
@@ -40,20 +40,26 @@ pub async fn compute_async_module_info(
4040 graphs : ResolvedVc < ModuleGraph > ,
4141) -> Result < Vc < AsyncModulesInfo > > {
4242 // Layout segment optimization, we can individually compute the async modules for each graph.
43- let mut result: Vc < AsyncModulesInfo > = Vc :: cell ( Default :: default ( ) ) ;
43+ let mut result = None ;
4444 for graph in graphs. iter_graphs ( ) . await ? {
45- result = compute_async_module_info_single ( graph. connect ( ) , result) ;
45+ result = Some ( compute_async_module_info_single ( * graph, result) ) ;
4646 }
47- Ok ( result)
47+ Ok ( result
48+ . context ( "There must be at least one single graph in the module graph" ) ?
49+ . connect ( ) )
4850}
4951
50- #[ turbo_tasks:: function]
52+ #[ turbo_tasks:: function( operation ) ]
5153async fn compute_async_module_info_single (
52- graph : ResolvedVc < ModuleGraphLayer > ,
53- parent_async_modules : Vc < AsyncModulesInfo > ,
54+ graph : OperationVc < ModuleGraphLayer > ,
55+ parent_async_modules : Option < OperationVc < AsyncModulesInfo > > ,
5456) -> Result < Vc < AsyncModulesInfo > > {
55- let parent_async_modules = parent_async_modules. await ?;
56- let graph = graph. await ?;
57+ let parent_async_modules = if let Some ( parent_async_modules) = parent_async_modules {
58+ Some ( parent_async_modules. read_strongly_consistent ( ) . await ?)
59+ } else {
60+ None
61+ } ;
62+ let graph = graph. read_strongly_consistent ( ) . await ?;
5763 let self_async_modules = graph
5864 . enumerate_nodes ( )
5965 . map ( async |( _, node) | {
@@ -64,7 +70,10 @@ async fn compute_async_module_info_single(
6470 super :: SingleModuleGraphNode :: VisitedModule { idx : _, module } => {
6571 // If a module is async in the parent then we need to mark reverse dependencies
6672 // async in this graph as well.
67- parent_async_modules. contains ( module) . then_some ( * module)
73+ parent_async_modules
74+ . as_ref ( )
75+ . map_or ( false , |set| set. contains ( module) )
76+ . then_some ( * module)
6877 }
6978 } )
7079 } )
@@ -101,7 +110,7 @@ async fn compute_async_module_info_single(
101110 ) ?;
102111
103112 // Accumulate the parent modules at the end. Not all parent async modules were in this graph
104- async_modules. extend ( parent_async_modules) ;
113+ async_modules. extend ( parent_async_modules. into_iter ( ) . flatten ( ) ) ;
105114
106115 Ok ( Vc :: cell ( async_modules) )
107116}
0 commit comments