1use anyhow::{Context, Result};
2use rustc_hash::FxHashSet;
3use turbo_tasks::{OperationVc, ResolvedVc, TryFlatJoinIterExt, Vc};
4
5use crate::{
6 module::{Module, Modules},
7 module_graph::{GraphTraversalAction, ModuleGraph, ModuleGraphLayer},
8};
9
10#[turbo_tasks::value(transparent)]
11pub struct ModulesSet(FxHashSet<ResolvedVc<Box<dyn Module>>>);
12
13/// This lists all the modules that are async (self or transitively because they reference another
14/// module in this list).
15#[turbo_tasks::value(transparent)]
16pub struct AsyncModulesInfo(FxHashSet<ResolvedVc<Box<dyn Module>>>);
17
18#[turbo_tasks::value_impl]
19impl AsyncModulesInfo {
20 #[turbo_tasks::function]
21 pub fn is_async(&self, module: ResolvedVc<Box<dyn Module>>) -> Vc<bool> {
22 Vc::cell(self.0.contains(&module))
23 }
24
25 #[turbo_tasks::function]
26 pub async fn is_async_multiple(&self, modules: ResolvedVc<Modules>) -> Result<Vc<ModulesSet>> {
27 Ok(Vc::cell(
28 modules
29 .await?
30 .iter()
31 .copied()
32 .filter(|m| self.0.contains(m))
33 .collect(),
34 ))
35 }
36}
37
38#[turbo_tasks::function(operation)]
39pub async fn compute_async_module_info(
40 graphs: ResolvedVc<ModuleGraph>,
41) -> Result<Vc<AsyncModulesInfo>> {
…lines 42–117 unchanged (76 lines)