diff --git a/crates/next-core/src/next_manifests/client_reference_manifest.rs b/crates/next-core/src/next_manifests/client_reference_manifest.rs index 5b9656be5938e..87697c80e89ca 100644 --- a/crates/next-core/src/next_manifests/client_reference_manifest.rs +++ b/crates/next-core/src/next_manifests/client_reference_manifest.rs @@ -77,7 +77,9 @@ impl ClientReferenceManifest { let client_chunk_item = ecmascript_client_reference .client_module - .as_chunk_item(Vc::upcast(client_chunking_context)); + .as_chunk_item(Vc::upcast(client_chunking_context)) + .to_resolved() + .await?; let client_module_id = client_chunk_item.id().await?; @@ -116,16 +118,20 @@ impl ClientReferenceManifest { if let Some(ssr_chunking_context) = ssr_chunking_context { let ssr_chunk_item = ecmascript_client_reference .ssr_module - .as_chunk_item(Vc::upcast(ssr_chunking_context)); + .as_chunk_item(Vc::upcast(ssr_chunking_context)) + .to_resolved() + .await?; let ssr_module_id = ssr_chunk_item.id().await?; - let rsc_chunk_item: Vc> = + let rsc_chunk_item: ResolvedVc> = ResolvedVc::try_downcast_type::( parent_module, ) .await? .unwrap() - .as_chunk_item(Vc::upcast(ssr_chunking_context)); + .as_chunk_item(Vc::upcast(ssr_chunking_context)) + .to_resolved() + .await?; let rsc_module_id = rsc_chunk_item.id().await?; let (ssr_chunks_paths, ssr_is_async) = if runtime == NextRuntime::Edge { @@ -362,13 +368,13 @@ pub fn get_client_reference_module_key(server_path: &str, export_name: &str) -> async fn is_item_async( availability_info: &AvailabilityInfo, - chunk_item: Vc>, + chunk_item: ResolvedVc>, ) -> Result { let Some(available_chunk_items) = availability_info.available_chunk_items() else { return Ok(false); }; - let Some(info) = &*available_chunk_items.get(chunk_item).await? else { + let Some(info) = available_chunk_items.await?.get(chunk_item).await? else { return Ok(false); }; diff --git a/turbopack/crates/turbopack-browser/src/chunking_context.rs b/turbopack/crates/turbopack-browser/src/chunking_context.rs index abfa206dd4115..60226f7522a43 100644 --- a/turbopack/crates/turbopack-browser/src/chunking_context.rs +++ b/turbopack/crates/turbopack-browser/src/chunking_context.rs @@ -390,7 +390,7 @@ impl ChunkingContext for BrowserChunkingContext { #[turbo_tasks::function] async fn chunk_group( - self: Vc, + self: ResolvedVc, ident: Vc, module: ResolvedVc>, availability_info: Value, @@ -403,7 +403,7 @@ impl ChunkingContext for BrowserChunkingContext { chunks, availability_info, } = make_chunk_group( - Vc::upcast(self), + ResolvedVc::upcast(self), [ResolvedVc::upcast(module)], input_availability_info, ) @@ -454,7 +454,7 @@ impl ChunkingContext for BrowserChunkingContext { #[turbo_tasks::function] async fn evaluated_chunk_group( - self: Vc, + self: ResolvedVc, ident: Vc, evaluatable_assets: Vc, availability_info: Value, @@ -476,7 +476,7 @@ impl ChunkingContext for BrowserChunkingContext { let MakeChunkGroupResult { chunks, availability_info, - } = make_chunk_group(Vc::upcast(self), entries, availability_info).await?; + } = make_chunk_group(ResolvedVc::upcast(self), entries, availability_info).await?; let mut assets: Vec>> = chunks .iter() diff --git a/turbopack/crates/turbopack-browser/src/ecmascript/content_entry.rs b/turbopack/crates/turbopack-browser/src/ecmascript/content_entry.rs index c0aa848cd3b20..8c3d01e151437 100644 --- a/turbopack/crates/turbopack-browser/src/ecmascript/content_entry.rs +++ b/turbopack/crates/turbopack-browser/src/ecmascript/content_entry.rs @@ -59,7 +59,11 @@ impl EcmascriptDevChunkContentEntries { async move { Ok(( chunk_item.id().await?, - EcmascriptDevChunkContentEntry::new(chunk_item, async_module_info).await?, + EcmascriptDevChunkContentEntry::new( + *chunk_item, + async_module_info.map(|info| *info), + ) + .await?, )) } .instrument(info_span!( diff --git a/turbopack/crates/turbopack-core/src/chunk/availability_info.rs b/turbopack/crates/turbopack-core/src/chunk/availability_info.rs index 915e77be0810a..5c90ca87d299d 100644 --- a/turbopack/crates/turbopack-core/src/chunk/availability_info.rs +++ b/turbopack/crates/turbopack-core/src/chunk/availability_info.rs @@ -17,14 +17,14 @@ pub enum AvailabilityInfo { } impl AvailabilityInfo { - pub fn available_chunk_items(&self) -> Option> { + pub fn available_chunk_items(&self) -> Option> { match self { Self::Untracked => None, Self::Root => None, Self::Complete { available_chunk_items, .. - } => Some(**available_chunk_items), + } => Some(*available_chunk_items), } } diff --git a/turbopack/crates/turbopack-core/src/chunk/available_chunk_items.rs b/turbopack/crates/turbopack-core/src/chunk/available_chunk_items.rs index 6e0e6b9454b52..6415fbe18db8d 100644 --- a/turbopack/crates/turbopack-core/src/chunk/available_chunk_items.rs +++ b/turbopack/crates/turbopack-core/src/chunk/available_chunk_items.rs @@ -15,9 +15,6 @@ pub struct AvailableChunkItemInfo { pub is_async: bool, } -#[turbo_tasks::value(transparent)] -pub struct OptionAvailableChunkItemInfo(Option); - #[turbo_tasks::value(transparent)] pub struct AvailableChunkItemInfoMap( FxIndexMap>, AvailableChunkItemInfo>, @@ -48,12 +45,13 @@ impl AvailableChunkItems { self: ResolvedVc, chunk_items: ResolvedVc, ) -> Result> { + let this = &*self.await?; let chunk_items = chunk_items .await? .into_iter() .map(|(&chunk_item, &info)| async move { - Ok(self - .get(*chunk_item) + Ok(this + .get(chunk_item) .await? .is_none() .then_some((chunk_item, info))) @@ -87,18 +85,24 @@ impl AvailableChunkItems { } Ok(Vc::cell(hasher.finish())) } +} - #[turbo_tasks::function] +impl AvailableChunkItems { + // This is not a turbo-tasks function because: + // + // - We want to enforce that the `chunk_item` key is a `ResolvedVc`, so that it will actually + // match the entries in the `HashMap`. + // - This is a cheap operation that's unlikely to be worth caching. pub async fn get( &self, chunk_item: ResolvedVc>, - ) -> Result> { + ) -> Result> { if let Some(&info) = self.chunk_items.await?.get(&chunk_item) { - return Ok(Vc::cell(Some(info))); + return Ok(Some(info)); }; if let Some(parent) = self.parent { - return Ok(parent.get(*chunk_item)); + return Box::pin(parent.await?.get(chunk_item)).await; } - Ok(Vc::cell(None)) + Ok(None) } } diff --git a/turbopack/crates/turbopack-core/src/chunk/chunk_group.rs b/turbopack/crates/turbopack-core/src/chunk/chunk_group.rs index f3ac6cde3e001..c83de772181aa 100644 --- a/turbopack/crates/turbopack-core/src/chunk/chunk_group.rs +++ b/turbopack/crates/turbopack-core/src/chunk/chunk_group.rs @@ -2,9 +2,7 @@ use std::collections::HashSet; use anyhow::Result; use auto_hash_map::AutoSet; -use turbo_tasks::{ - FxIndexMap, FxIndexSet, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Value, Vc, -}; +use turbo_tasks::{FxIndexMap, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Value, Vc}; use super::{ availability_info::AvailabilityInfo, available_chunk_items::AvailableChunkItemInfo, @@ -22,7 +20,7 @@ pub struct MakeChunkGroupResult { /// Creates a chunk group from a set of entries. pub async fn make_chunk_group( - chunking_context: Vc>, + chunking_context: ResolvedVc>, chunk_group_entries: impl IntoIterator>>, availability_info: AvailabilityInfo, ) -> Result { @@ -53,7 +51,7 @@ pub async fn make_chunk_group( .keys() .copied() .chain(self_async_children.into_iter()) - .map(|chunk_item| (chunk_item, AutoSet::>>::new())) + .map(|chunk_item| (chunk_item, AutoSet::>>::new())) .collect::>(); // Propagate async inheritance @@ -86,7 +84,7 @@ pub async fn make_chunk_group( let mut chunk_items = chunk_items .into_iter() .map(|chunk_item| (chunk_item, None)) - .collect::>>>(); + .collect::>>>(); // Insert AsyncModuleInfo for every async module for (async_item, referenced_async_modules) in async_chunk_items { @@ -96,13 +94,18 @@ pub async fn make_chunk_group( .iter() .copied() .filter(|item| referenced_async_modules.contains(item)) + .map(|item| *item) .collect() } else { Default::default() }; chunk_items.insert( async_item, - Some(AsyncModuleInfo::new(referenced_async_modules)), + Some( + AsyncModuleInfo::new(referenced_async_modules) + .to_resolved() + .await?, + ), ); } @@ -112,7 +115,7 @@ pub async fn make_chunk_group( .iter() .map(|(&chunk_item, async_info)| async move { Ok(( - chunk_item.to_resolved().await?, + chunk_item, AvailableChunkItemInfo { is_async: async_info.is_some(), }, @@ -130,9 +133,12 @@ pub async fn make_chunk_group( let async_loaders = async_modules .into_iter() .map(|module| { - chunking_context.async_loader_chunk_item(*module, Value::new(availability_info)) + chunking_context + .async_loader_chunk_item(*module, Value::new(availability_info)) + .to_resolved() }) - .collect::>(); + .try_join() + .await?; let has_async_loaders = !async_loaders.is_empty(); let async_loader_chunk_items = async_loaders.iter().map(|&chunk_item| (chunk_item, None)); @@ -151,7 +157,7 @@ pub async fn make_chunk_group( let mut referenced_output_assets = (*external_output_assets.await?).clone(); referenced_output_assets.extend( - references_to_output_assets(external_module_references) + references_to_output_assets(&external_module_references) .await? .await? .iter() @@ -175,7 +181,7 @@ pub async fn make_chunk_group( // Pass chunk items to chunking algorithm let mut chunks = make_chunks( - chunking_context, + *chunking_context, Vc::cell(chunk_items.into_iter().collect()), "".into(), Vc::cell(referenced_output_assets), @@ -188,7 +194,7 @@ pub async fn make_chunk_group( // We want them to be separate since they are specific to this chunk group due // to available chunk items differing let async_loader_chunks = make_chunks( - chunking_context, + *chunking_context, Vc::cell(async_loader_chunk_items.into_iter().collect()), "async-loader-".into(), async_loader_external_module_references, @@ -206,7 +212,7 @@ pub async fn make_chunk_group( } pub async fn references_to_output_assets( - references: FxIndexSet>>, + references: impl IntoIterator>>, ) -> Result> { let output_assets = references .into_iter() diff --git a/turbopack/crates/turbopack-core/src/chunk/chunking.rs b/turbopack/crates/turbopack-core/src/chunk/chunking.rs index df9a3eb420547..ee4ab1b13a7f9 100644 --- a/turbopack/crates/turbopack-core/src/chunk/chunking.rs +++ b/turbopack/crates/turbopack-core/src/chunk/chunking.rs @@ -53,7 +53,9 @@ pub async fn make_chunks( .await? .iter() .map(|&(chunk_item, async_info)| async move { - let chunk_item_info = chunk_item_info(chunking_context, chunk_item, async_info).await?; + let chunk_item_info = + chunk_item_info(chunking_context, *chunk_item, async_info.map(|info| *info)) + .await?; Ok((chunk_item, async_info, chunk_item_info)) }) .try_join() @@ -118,8 +120,8 @@ pub async fn make_chunks( } type ChunkItemWithInfo = ( - Vc>, - Option>, + ResolvedVc>, + Option>, usize, ReadRef, ); diff --git a/turbopack/crates/turbopack-core/src/chunk/mod.rs b/turbopack/crates/turbopack-core/src/chunk/mod.rs index e2da34777dc96..fbf9e42d0cf13 100644 --- a/turbopack/crates/turbopack-core/src/chunk/mod.rs +++ b/turbopack/crates/turbopack-core/src/chunk/mod.rs @@ -209,14 +209,14 @@ pub trait ChunkableModuleReference: ModuleReference + ValueToString { } } -type AsyncInfo = FxIndexMap>, Vec>>>; +type AsyncInfo = FxIndexMap>, Vec>>>; pub struct ChunkContentResult { - pub chunk_items: FxIndexSet>>, + pub chunk_items: FxIndexSet>>, pub async_modules: FxIndexSet>>, pub traced_modules: FxIndexSet>>, - pub external_output_assets: Vc, - pub external_module_references: FxIndexSet>>, + pub external_output_assets: ResolvedVc, + pub external_module_references: FxIndexSet>>, /// A map from local module to all children from which the async module /// status is inherited pub forward_edges_inherit_async: AsyncInfo, @@ -229,7 +229,7 @@ pub struct ChunkContentResult { } pub async fn chunk_content( - chunking_context: Vc>, + chunking_context: ResolvedVc>, chunk_entries: impl IntoIterator>>, availability_info: AvailabilityInfo, ) -> Result { @@ -250,25 +250,25 @@ enum InheritAsyncEdge { AvailableAsyncModule, } -#[derive(Eq, PartialEq, Clone, Hash, Serialize, Deserialize, TraceRawVcs, Debug)] +#[derive(Eq, PartialEq, Clone, Hash, Serialize, Deserialize, TraceRawVcs, Debug, NonLocalValue)] enum ChunkContentGraphNode { // A chunk item not placed in the current chunk, but whose references we will // follow to find more graph nodes. PassthroughChunkItem { - item: Vc>, + item: ResolvedVc>, }, // Chunk items that are placed into the current chunk group ChunkItem { - item: Vc>, + item: ResolvedVc>, ident: ReadRef, }, // Async module that is referenced from the chunk group AsyncModule { - module: Vc>, + module: ResolvedVc>, }, // Module that is referenced as traced and will be turned into a separate RebasedAsset TracedModule { - module: Vc>, + module: ResolvedVc>, }, ExternalOutputAssets(ResolvedVc), // ModuleReferences that are not placed in the current chunk group @@ -276,7 +276,7 @@ enum ChunkContentGraphNode { /// A list of directly referenced chunk items from which `is_async_module` /// will be inherited. InheritAsyncInfo { - item: Vc>, + item: ResolvedVc>, references: Vec<(ResolvedVc>, InheritAsyncEdge)>, }, } @@ -287,14 +287,14 @@ enum ChunkGraphNodeToReferences { ChunkItem(ResolvedVc>), } -#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, TraceRawVcs)] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, TraceRawVcs, NonLocalValue)] struct ChunkGraphEdge { key: Option>>, node: ChunkContentGraphNode, } #[derive(Debug, Clone)] -#[turbo_tasks::value(transparent, local)] +#[turbo_tasks::value(transparent)] struct ChunkGraphEdges(Vec); #[turbo_tasks::function] @@ -307,7 +307,8 @@ async fn graph_node_to_referenced_nodes_with_available_chunk_items( let edges_ref = edges.await?; for (unchanged, edge) in edges_ref.iter().enumerate() { if let ChunkContentGraphNode::ChunkItem { item, .. } = edge.node { - if let Some(info) = *available_chunk_items.get(item).await? { + let available_chunk_items = available_chunk_items.await?; + if let Some(info) = available_chunk_items.get(item).await? { let mut new_edges = Vec::with_capacity(edges_ref.len()); new_edges.extend(edges_ref[0..unchanged].iter().cloned()); let mut available_chunk_item_info = HashMap::new(); @@ -315,7 +316,7 @@ async fn graph_node_to_referenced_nodes_with_available_chunk_items( for edge in edges_ref[unchanged + 1..].iter() { match edge.node { ChunkContentGraphNode::ChunkItem { item, .. } => { - if let Some(info) = *available_chunk_items.get(item).await? { + if let Some(info) = available_chunk_items.get(item).await? { available_chunk_item_info.insert(item, info); continue; } @@ -406,7 +407,7 @@ async fn graph_node_to_referenced_nodes( return Ok(( Some(ChunkGraphEdge { key: None, - node: ChunkContentGraphNode::TracedModule { module: *module }, + node: ChunkContentGraphNode::TracedModule { module }, }), None, )); @@ -431,7 +432,7 @@ async fn graph_node_to_referenced_nodes( ChunkingType::Parallel => { let chunk_item = chunkable_module .as_chunk_item(chunking_context) - .resolve() + .to_resolved() .await?; Ok(( Some(ChunkGraphEdge { @@ -447,7 +448,7 @@ async fn graph_node_to_referenced_nodes( ChunkingType::ParallelInheritAsync => { let chunk_item = chunkable_module .as_chunk_item(chunking_context) - .resolve() + .to_resolved() .await?; Ok(( Some(ChunkGraphEdge { @@ -457,16 +458,13 @@ async fn graph_node_to_referenced_nodes( ident: module.ident().to_string().await?, }, }), - Some(( - chunk_item.to_resolved().await?, - InheritAsyncEdge::LocalModule, - )), + Some((chunk_item, InheritAsyncEdge::LocalModule)), )) } ChunkingType::Passthrough => { let chunk_item = chunkable_module .as_chunk_item(chunking_context) - .resolve() + .to_resolved() .await?; Ok(( @@ -485,7 +483,7 @@ async fn graph_node_to_referenced_nodes( if matches!(*chunk_loading, ChunkLoading::Edge) { let chunk_item = chunkable_module .as_chunk_item(chunking_context) - .resolve() + .to_resolved() .await?; Ok(( Some(ChunkGraphEdge { @@ -502,7 +500,7 @@ async fn graph_node_to_referenced_nodes( Some(ChunkGraphEdge { key: None, node: ChunkContentGraphNode::AsyncModule { - module: *chunkable_module, + module: chunkable_module, }, }), None, @@ -537,7 +535,7 @@ async fn graph_node_to_referenced_nodes( graph_nodes.push(ChunkGraphEdge { key: None, node: ChunkContentGraphNode::InheritAsyncInfo { - item: *parent, + item: parent, references: inherit_async_references, }, }) @@ -560,9 +558,9 @@ async fn graph_node_to_referenced_nodes( } struct ChunkContentVisit { - chunking_context: Vc>, - available_chunk_items: Option>, - processed_modules: HashSet>>, + chunking_context: ResolvedVc>, + available_chunk_items: Option>, + processed_modules: HashSet>>, } type ChunkItemToGraphNodesEdges = impl Iterator; @@ -585,7 +583,7 @@ impl Visit for ChunkContentVisit { } }; - if !self.processed_modules.insert(*module) { + if !self.processed_modules.insert(module) { return VisitControlFlow::Skip(node); } @@ -601,10 +599,10 @@ impl Visit for ChunkContentVisit { async move { let node = match node { ChunkContentGraphNode::PassthroughChunkItem { item } => { - ChunkGraphNodeToReferences::PassthroughChunkItem(item.to_resolved().await?) + ChunkGraphNodeToReferences::PassthroughChunkItem(item) } ChunkContentGraphNode::ChunkItem { item, .. } => { - ChunkGraphNodeToReferences::ChunkItem(item.to_resolved().await?) + ChunkGraphNodeToReferences::ChunkItem(item) } _ => { return Ok(None.into_iter().flatten()); @@ -614,11 +612,11 @@ impl Visit for ChunkContentVisit { let nodes = if let Some(available_chunk_items) = available_chunk_items { graph_node_to_referenced_nodes_with_available_chunk_items( node, - chunking_context, - available_chunk_items, + *chunking_context, + *available_chunk_items, ) } else { - graph_node_to_referenced_nodes(node, chunking_context) + graph_node_to_referenced_nodes(node, *chunking_context) } .await?; Ok(Some(nodes.into_iter().cloned()).into_iter().flatten()) @@ -635,7 +633,7 @@ impl Visit for ChunkContentVisit { } async fn chunk_content_internal_parallel( - chunking_context: Vc>, + chunking_context: ResolvedVc>, chunk_entries: impl IntoIterator>>, availability_info: AvailabilityInfo, ) -> Result { @@ -650,7 +648,10 @@ async fn chunk_content_internal_parallel( Ok(Some(ChunkGraphEdge { key: Some(entry), node: ChunkContentGraphNode::ChunkItem { - item: chunkable_module.as_chunk_item(chunking_context), + item: chunkable_module + .as_chunk_item(*chunking_context) + .to_resolved() + .await?, ident: chunkable_module.ident().to_string().await?, }, })) @@ -686,19 +687,16 @@ async fn chunk_content_internal_parallel( match graph_node { ChunkContentGraphNode::PassthroughChunkItem { .. } => {} ChunkContentGraphNode::TracedModule { module } => { - let module = module.to_resolved().await?; traced_modules.insert(module); } ChunkContentGraphNode::ChunkItem { item, .. } => { - chunk_items.insert(*item.to_resolved().await?); + chunk_items.insert(item); } ChunkContentGraphNode::AsyncModule { module } => { - let module = module.to_resolved().await?; async_modules.insert(module); } ChunkContentGraphNode::ExternalModuleReference(reference) => { - let reference = reference.resolve().await?; - external_module_references.insert(*reference); + external_module_references.insert(reference); } ChunkContentGraphNode::ExternalOutputAssets(reference) => { for output_asset in reference.await? { @@ -709,12 +707,12 @@ async fn chunk_content_internal_parallel( for &(reference, ty) in &references { match ty { InheritAsyncEdge::LocalModule => local_back_edges_inherit_async - .entry(*reference) + .entry(reference) .or_insert_with(Vec::new) .push(item), InheritAsyncEdge::AvailableAsyncModule => { available_async_modules_back_edges_inherit_async - .entry(*reference) + .entry(reference) .or_insert_with(Vec::new) .push(item) } @@ -723,7 +721,7 @@ async fn chunk_content_internal_parallel( forward_edges_inherit_async .entry(item) .or_insert_with(Vec::new) - .extend(references.into_iter().map(|(r, _)| *r)); + .extend(references.into_iter().map(|(r, _)| r)); } } } @@ -732,7 +730,7 @@ async fn chunk_content_internal_parallel( chunk_items, async_modules, traced_modules, - external_output_assets: Vc::cell(external_output_assets.into_iter().collect()), + external_output_assets: ResolvedVc::cell(external_output_assets.into_iter().collect()), external_module_references, forward_edges_inherit_async, local_back_edges_inherit_async, @@ -809,23 +807,22 @@ pub struct AsyncModuleInfo { #[turbo_tasks::value_impl] impl AsyncModuleInfo { #[turbo_tasks::function] - pub async fn new(referenced_async_modules: Vec>>) -> Result> { - let resolved_modules = referenced_async_modules - .into_iter() - .map(|m| m.to_resolved()) - .try_join() - .await?; - + pub async fn new( + referenced_async_modules: Vec>>, + ) -> Result> { Ok(Self { - referenced_async_modules: resolved_modules.into_iter().collect(), + referenced_async_modules: referenced_async_modules.into_iter().collect(), } .cell()) } } -pub type ChunkItemWithAsyncModuleInfo = (Vc>, Option>); +pub type ChunkItemWithAsyncModuleInfo = ( + ResolvedVc>, + Option>, +); -#[turbo_tasks::value(transparent, local)] +#[turbo_tasks::value(transparent)] pub struct ChunkItemsWithAsyncModuleInfo(Vec); pub trait ChunkItemExt { diff --git a/turbopack/crates/turbopack-css/src/chunk/mod.rs b/turbopack/crates/turbopack-css/src/chunk/mod.rs index 56a0f0b354463..b22e48b58938e 100644 --- a/turbopack/crates/turbopack-css/src/chunk/mod.rs +++ b/turbopack/crates/turbopack-css/src/chunk/mod.rs @@ -3,7 +3,7 @@ pub mod source_map; use std::fmt::Write; -use anyhow::{bail, Result}; +use anyhow::{bail, Context, Result}; use turbo_rcstr::RcStr; use turbo_tasks::{FxIndexSet, ResolvedVc, TryJoinIterExt, Value, ValueDefault, ValueToString, Vc}; use turbo_tasks_fs::{rope::Rope, File, FileSystem}; @@ -502,13 +502,10 @@ impl ChunkType for CssChunkType { chunk_items: chunk_items .iter() .map(|(chunk_item, _async_info)| async move { - let Some(chunk_item) = - Vc::try_resolve_downcast::>(*chunk_item).await? - else { - bail!("Chunk item is not an css chunk item but reporting chunk type css"); - }; // CSS doesn't need to care about async_info, so we can discard it - chunk_item.to_resolved().await + ResolvedVc::try_downcast::>(*chunk_item) + .await? + .context("Chunk item is not an css chunk item but reporting chunk type css") }) .try_join() .await?, diff --git a/turbopack/crates/turbopack-ecmascript/src/async_chunk/chunk_item.rs b/turbopack/crates/turbopack-ecmascript/src/async_chunk/chunk_item.rs index a267b97524489..c15fc5b8ea018 100644 --- a/turbopack/crates/turbopack-ecmascript/src/async_chunk/chunk_item.rs +++ b/turbopack/crates/turbopack-ecmascript/src/async_chunk/chunk_item.rs @@ -34,11 +34,12 @@ impl AsyncLoaderChunkItem { let module = self.module.await?; if let Some(chunk_items) = module.availability_info.available_chunk_items() { if chunk_items + .await? .get( module .inner .as_chunk_item(*ResolvedVc::upcast(self.chunking_context)) - .resolve() + .to_resolved() .await?, ) .await? diff --git a/turbopack/crates/turbopack-ecmascript/src/chunk/chunk_type.rs b/turbopack/crates/turbopack-ecmascript/src/chunk/chunk_type.rs index 8b8cf9f12bf8e..52d4aba0dd2cb 100644 --- a/turbopack/crates/turbopack-ecmascript/src/chunk/chunk_type.rs +++ b/turbopack/crates/turbopack-ecmascript/src/chunk/chunk_type.rs @@ -1,6 +1,6 @@ use anyhow::{bail, Result}; use turbo_rcstr::RcStr; -use turbo_tasks::{TryJoinIterExt, ValueDefault, ValueToString, Vc}; +use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueDefault, ValueToString, Vc}; use turbopack_core::{ chunk::{ round_chunk_item_size, AsyncModuleInfo, Chunk, ChunkItem, ChunkItemWithAsyncModuleInfo, @@ -45,9 +45,9 @@ impl ChunkType for EcmascriptChunkType { let content = EcmascriptChunkContent { chunk_items: chunk_items .iter() - .map(|(chunk_item, async_info)| async move { + .map(|&(chunk_item, async_info)| async move { let Some(chunk_item) = - Vc::try_resolve_downcast::>(*chunk_item) + ResolvedVc::try_downcast::>(chunk_item) .await? else { bail!( @@ -55,7 +55,7 @@ impl ChunkType for EcmascriptChunkType { ecmascript" ); }; - Ok((chunk_item, *async_info)) + Ok((chunk_item, async_info)) }) .try_join() .await?, diff --git a/turbopack/crates/turbopack-ecmascript/src/chunk/content.rs b/turbopack/crates/turbopack-ecmascript/src/chunk/content.rs index ae7ac035937eb..bff643851d383 100644 --- a/turbopack/crates/turbopack-ecmascript/src/chunk/content.rs +++ b/turbopack/crates/turbopack-ecmascript/src/chunk/content.rs @@ -1,14 +1,14 @@ -use turbo_tasks::{ResolvedVc, Vc}; +use turbo_tasks::ResolvedVc; use turbopack_core::{chunk::AsyncModuleInfo, output::OutputAsset}; use super::item::EcmascriptChunkItem; type EcmascriptChunkItemWithAsyncInfo = ( - Vc>, - Option>, + ResolvedVc>, + Option>, ); -#[turbo_tasks::value(shared, local)] +#[turbo_tasks::value(shared)] pub struct EcmascriptChunkContent { pub chunk_items: Vec, pub referenced_output_assets: Vec>>, diff --git a/turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs b/turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs index 0eb91cd9f7979..d4f45dd54fde8 100644 --- a/turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs +++ b/turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs @@ -145,9 +145,8 @@ impl Chunk for EcmascriptChunk { Ok(ChunkItems( chunk_items .iter() - .map(|(item, _)| async move { Ok(ResolvedVc::upcast(item.to_resolved().await?)) }) - .try_join() - .await?, + .map(|&(item, _)| ResolvedVc::upcast(item)) + .collect(), ) .cell()) } diff --git a/turbopack/crates/turbopack-ecmascript/src/manifest/chunk_asset.rs b/turbopack/crates/turbopack-ecmascript/src/manifest/chunk_asset.rs index f44853c933346..1ca6696f1d10e 100644 --- a/turbopack/crates/turbopack-ecmascript/src/manifest/chunk_asset.rs +++ b/turbopack/crates/turbopack-ecmascript/src/manifest/chunk_asset.rs @@ -66,10 +66,11 @@ impl ManifestAsyncModule { let this = self.await?; if let Some(chunk_items) = this.availability_info.available_chunk_items() { if chunk_items + .await? .get( this.inner .as_chunk_item(*ResolvedVc::upcast(this.chunking_context)) - .resolve() + .to_resolved() .await?, ) .await? diff --git a/turbopack/crates/turbopack-nodejs/src/chunking_context.rs b/turbopack/crates/turbopack-nodejs/src/chunking_context.rs index da968b23f55d0..1e3e1329f7131 100644 --- a/turbopack/crates/turbopack-nodejs/src/chunking_context.rs +++ b/turbopack/crates/turbopack-nodejs/src/chunking_context.rs @@ -293,7 +293,7 @@ impl ChunkingContext for NodeJsChunkingContext { #[turbo_tasks::function] async fn chunk_group( - self: Vc, + self: ResolvedVc, _ident: Vc, module: ResolvedVc>, availability_info: Value, @@ -307,7 +307,7 @@ impl ChunkingContext for NodeJsChunkingContext { chunks, availability_info, } = make_chunk_group( - Vc::upcast(self), + ResolvedVc::upcast(self), [ResolvedVc::upcast(module)], availability_info.into_value(), ) @@ -334,7 +334,7 @@ impl ChunkingContext for NodeJsChunkingContext { /// * exports the result of evaluating the given module as a CommonJS default export. #[turbo_tasks::function] pub async fn entry_chunk_group( - self: Vc, + self: ResolvedVc, path: Vc, module: ResolvedVc>, evaluatable_assets: Vc, @@ -347,7 +347,7 @@ impl ChunkingContext for NodeJsChunkingContext { chunks, availability_info, } = make_chunk_group( - Vc::upcast(self), + ResolvedVc::upcast(self), once(module).chain( evaluatable_assets .await? @@ -378,7 +378,7 @@ impl ChunkingContext for NodeJsChunkingContext { let asset = ResolvedVc::upcast( EcmascriptBuildNodeEntryChunk::new( path, - self, + *self, Vc::cell(other_chunks), evaluatable_assets, *module, diff --git a/turbopack/crates/turbopack-nodejs/src/ecmascript/node/content.rs b/turbopack/crates/turbopack-nodejs/src/ecmascript/node/content.rs index 4652fa9f9f172..ae5f56537265c 100644 --- a/turbopack/crates/turbopack-nodejs/src/ecmascript/node/content.rs +++ b/turbopack/crates/turbopack-nodejs/src/ecmascript/node/content.rs @@ -55,7 +55,7 @@ pub(super) async fn chunk_items( .map(|&(chunk_item, async_module_info)| async move { Ok(( chunk_item.id().await?, - chunk_item.code(async_module_info).await?, + chunk_item.code(async_module_info.map(|info| *info)).await?, )) }) .try_join() diff --git a/turbopack/crates/turbopack-wasm/src/module_asset.rs b/turbopack/crates/turbopack-wasm/src/module_asset.rs index 292206747d46d..7a9ac9799395a 100644 --- a/turbopack/crates/turbopack-wasm/src/module_asset.rs +++ b/turbopack/crates/turbopack-wasm/src/module_asset.rs @@ -210,7 +210,7 @@ impl ChunkItem for ModuleChunkItem { #[turbo_tasks::function] async fn references(&self) -> Result> { let loader_references = self.module.loader().references().await?; - references_to_output_assets(loader_references.iter().map(|r| **r).collect::<_>()).await + references_to_output_assets(&*loader_references).await } #[turbo_tasks::function]