From 28c3e571adfeefdea6d4e518ea96dee9e758fcaf Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Fri, 3 Jan 2025 16:39:05 -0800 Subject: [PATCH] refactor(turbopack-core): Use ResolvedVc in IntrospectableChildren --- .../turbopack-browser/src/ecmascript/chunk.rs | 2 +- .../turbopack-core/src/introspect/mod.rs | 4 +- .../turbopack-core/src/introspect/utils.rs | 13 +++-- .../src/source_map/source_map_asset.rs | 2 +- .../crates/turbopack-css/src/chunk/mod.rs | 4 +- .../src/introspect/mod.rs | 2 +- .../src/source/asset_graph.rs | 50 ++++++++++++------- .../src/source/combined.rs | 2 +- .../src/source/conditional.rs | 4 +- .../src/source/lazy_instantiated.rs | 12 ++--- .../turbopack-dev-server/src/source/router.rs | 2 +- .../src/source/static_assets.rs | 42 ++++++++++------ .../turbopack-ecmascript/src/chunk/mod.rs | 4 +- .../src/chunk_group_files_asset.rs | 8 +-- .../src/render/node_api_source.rs | 8 ++- .../src/render/rendered_source.rs | 8 ++- .../src/ecmascript/node/chunk.rs | 4 +- 17 files changed, 108 insertions(+), 63 deletions(-) diff --git a/turbopack/crates/turbopack-browser/src/ecmascript/chunk.rs b/turbopack/crates/turbopack-browser/src/ecmascript/chunk.rs index 6c053d2a184c4..15a1b3f65ba8e 100644 --- a/turbopack/crates/turbopack-browser/src/ecmascript/chunk.rs +++ b/turbopack/crates/turbopack-browser/src/ecmascript/chunk.rs @@ -173,7 +173,7 @@ impl Introspectable for EcmascriptDevChunk { async fn children(&self) -> Result> { let mut children = FxIndexSet::default(); let chunk = ResolvedVc::upcast::>(self.chunk); - children.insert((ResolvedVc::cell("chunk".into()), *chunk)); + children.insert((ResolvedVc::cell("chunk".into()), chunk)); Ok(Vc::cell(children)) } } diff --git a/turbopack/crates/turbopack-core/src/introspect/mod.rs b/turbopack/crates/turbopack-core/src/introspect/mod.rs index c140dcb3cd0c4..edac398244e7c 100644 --- a/turbopack/crates/turbopack-core/src/introspect/mod.rs +++ b/turbopack/crates/turbopack-core/src/introspect/mod.rs @@ -6,9 +6,9 @@ pub mod utils; use turbo_rcstr::RcStr; use turbo_tasks::{FxIndexSet, ResolvedVc, Vc}; -type VcDynIntrospectable = Vc>; +type VcDynIntrospectable = ResolvedVc>; -#[turbo_tasks::value(transparent, local)] +#[turbo_tasks::value(transparent)] pub struct IntrospectableChildren(FxIndexSet<(ResolvedVc, VcDynIntrospectable)>); #[turbo_tasks::value_trait(local)] diff --git a/turbopack/crates/turbopack-core/src/introspect/utils.rs b/turbopack/crates/turbopack-core/src/introspect/utils.rs index 74c46d1efde39..354769e9685e4 100644 --- a/turbopack/crates/turbopack-core/src/introspect/utils.rs +++ b/turbopack/crates/turbopack-core/src/introspect/utils.rs @@ -101,7 +101,7 @@ pub async fn children_from_module_references( .await? .iter() { - children.insert((key, IntrospectableModule::new(*module))); + children.insert((key, IntrospectableModule::new(*module).to_resolved().await?)); } for &output_asset in reference .resolve_reference() @@ -109,7 +109,12 @@ pub async fn children_from_module_references( .await? .iter() { - children.insert((key, IntrospectableOutputAsset::new(*output_asset))); + children.insert(( + key, + IntrospectableOutputAsset::new(*output_asset) + .to_resolved() + .await?, + )); } } Ok(Vc::cell(children)) @@ -125,7 +130,9 @@ pub async fn children_from_output_assets( for &reference in &*references { children.insert(( key, - IntrospectableOutputAsset::new(*ResolvedVc::upcast(reference)), + IntrospectableOutputAsset::new(*ResolvedVc::upcast(reference)) + .to_resolved() + .await?, )); } Ok(Vc::cell(children)) diff --git a/turbopack/crates/turbopack-core/src/source_map/source_map_asset.rs b/turbopack/crates/turbopack-core/src/source_map/source_map_asset.rs index b9cf2ea37874a..ba52ac76e1a3a 100644 --- a/turbopack/crates/turbopack-core/src/source_map/source_map_asset.rs +++ b/turbopack/crates/turbopack-core/src/source_map/source_map_asset.rs @@ -86,7 +86,7 @@ impl Introspectable for SourceMapAsset { let mut children = FxIndexSet::default(); if let Some(asset) = ResolvedVc::try_sidecast::>(self.asset).await? { - children.insert((ResolvedVc::cell("asset".into()), *asset)); + children.insert((ResolvedVc::cell("asset".into()), asset)); } Ok(Vc::cell(children)) } diff --git a/turbopack/crates/turbopack-css/src/chunk/mod.rs b/turbopack/crates/turbopack-css/src/chunk/mod.rs index b22e48b58938e..0601eccd78b1a 100644 --- a/turbopack/crates/turbopack-css/src/chunk/mod.rs +++ b/turbopack/crates/turbopack-css/src/chunk/mod.rs @@ -462,7 +462,9 @@ impl Introspectable for CssChunk { .map(|chunk_item| async move { Ok(( entry_module_key().to_resolved().await?, - IntrospectableModule::new(chunk_item.module()), + IntrospectableModule::new(chunk_item.module()) + .to_resolved() + .await?, )) }) .try_join() diff --git a/turbopack/crates/turbopack-dev-server/src/introspect/mod.rs b/turbopack/crates/turbopack-dev-server/src/introspect/mod.rs index 16b518c2feeed..ba3a7a489330a 100644 --- a/turbopack/crates/turbopack-dev-server/src/introspect/mod.rs +++ b/turbopack/crates/turbopack-dev-server/src/introspect/mod.rs @@ -36,7 +36,7 @@ impl Introspectable for IntrospectionSource { #[turbo_tasks::function] fn children(&self) -> Vc { let name = ResolvedVc::cell("root".into()); - Vc::cell(self.roots.iter().map(|root| (name, **root)).collect()) + Vc::cell(self.roots.iter().map(|root| (name, *root)).collect()) } } diff --git a/turbopack/crates/turbopack-dev-server/src/source/asset_graph.rs b/turbopack/crates/turbopack-dev-server/src/source/asset_graph.rs index f3bb796729a87..5ad8e86a0afbc 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/asset_graph.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/asset_graph.rs @@ -322,30 +322,41 @@ impl Introspectable for AssetGraphContentSource { let expanded_key = ResolvedVc::cell("expanded".into()); let root_assets = this.root_assets.await?; - let root_asset_children = root_assets.iter().map(|&asset| { - ( - key, - IntrospectableOutputAsset::new(*ResolvedVc::upcast(asset)), - ) - }); + let root_asset_children = root_assets + .iter() + .map(|&asset| async move { + Ok(( + key, + IntrospectableOutputAsset::new(*ResolvedVc::upcast(asset)) + .to_resolved() + .await?, + )) + }) + .try_join() + .await?; let expanded_assets = self.all_assets_map().await?; let expanded_asset_children = expanded_assets .values() .filter(|&a| !root_assets.contains(a)) - .map(|&asset| { - ( + .map(|&asset| async move { + Ok(( inner_key, - IntrospectableOutputAsset::new(*ResolvedVc::upcast(asset)), - ) - }); + IntrospectableOutputAsset::new(*ResolvedVc::upcast(asset)) + .to_resolved() + .await?, + )) + }) + .try_join() + .await?; Ok(Vc::cell( root_asset_children + .into_iter() .chain(expanded_asset_children) .chain(once(( expanded_key, - Vc::upcast(FullyExpaned(self.to_resolved().await?).cell()), + ResolvedVc::upcast(FullyExpanded(self.to_resolved().await?).resolved_cell()), ))) .collect(), )) @@ -353,18 +364,18 @@ impl Introspectable for AssetGraphContentSource { } #[turbo_tasks::function] -fn fully_expaned_introspectable_type() -> Vc { +fn fully_expanded_introspectable_type() -> Vc { Vc::cell("fully expanded asset graph content source".into()) } #[turbo_tasks::value] -struct FullyExpaned(ResolvedVc); +struct FullyExpanded(ResolvedVc); #[turbo_tasks::value_impl] -impl Introspectable for FullyExpaned { +impl Introspectable for FullyExpanded { #[turbo_tasks::function] fn ty(&self) -> Vc { - fully_expaned_introspectable_type() + fully_expanded_introspectable_type() } #[turbo_tasks::function] @@ -381,7 +392,12 @@ impl Introspectable for FullyExpaned { expand(&*source.root_assets.await?, &*source.root_path.await?, None).await?; let children = expanded_assets .iter() - .map(|(_k, &v)| (key, IntrospectableOutputAsset::new(*v))) + .map(|(_k, &v)| async move { + Ok((key, IntrospectableOutputAsset::new(*v).to_resolved().await?)) + }) + .try_join() + .await? + .into_iter() .collect(); Ok(Vc::cell(children)) diff --git a/turbopack/crates/turbopack-dev-server/src/source/combined.rs b/turbopack/crates/turbopack-dev-server/src/source/combined.rs index 48f5f2667598d..dde095c8e1c1e 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/combined.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/combined.rs @@ -97,7 +97,7 @@ impl Introspectable for CombinedContentSource { .await? .into_iter() .flatten() - .map(|i| (source, *i)) + .map(|i| (source, i)) .collect(), )) } diff --git a/turbopack/crates/turbopack-dev-server/src/source/conditional.rs b/turbopack/crates/turbopack-dev-server/src/source/conditional.rs index 150d5a471809f..e3edcd53e26bd 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/conditional.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/conditional.rs @@ -141,10 +141,10 @@ impl Introspectable for ConditionalContentSource { [ ResolvedVc::try_sidecast::>(self.activator) .await? - .map(|i| (activator_key(), *i)), + .map(|i| (activator_key(), i)), ResolvedVc::try_sidecast::>(self.action) .await? - .map(|i| (action_key(), *i)), + .map(|i| (action_key(), i)), ] .into_iter() .flatten() diff --git a/turbopack/crates/turbopack-dev-server/src/source/lazy_instantiated.rs b/turbopack/crates/turbopack-dev-server/src/source/lazy_instantiated.rs index 821a6b2a9495d..bf56dded69e37 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/lazy_instantiated.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/lazy_instantiated.rs @@ -48,13 +48,11 @@ impl Introspectable for LazyInstantiatedContentSource { #[turbo_tasks::function] async fn children(&self) -> Result> { Ok(Vc::cell( - [ - Vc::try_resolve_sidecast::>( - self.get_source.content_source(), - ) - .await? - .map(|i| (source_key(), i)), - ] + [ResolvedVc::try_sidecast::>( + self.get_source.content_source().to_resolved().await?, + ) + .await? + .map(|i| (source_key(), i))] .into_iter() .flatten() .map(|(k, v)| async move { Ok((k.to_resolved().await?, v)) }) diff --git a/turbopack/crates/turbopack-dev-server/src/source/router.rs b/turbopack/crates/turbopack-dev-server/src/source/router.rs index 3239ee3fb9706..c35f6f45f4c32 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/router.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/router.rs @@ -66,7 +66,7 @@ async fn get_introspection_children( .map(|(path, source)| async move { Ok(ResolvedVc::try_sidecast::>(source) .await? - .map(|i| (ResolvedVc::cell(path), *i))) + .map(|i| (ResolvedVc::cell(path), i))) }) .try_join() .await? diff --git a/turbopack/crates/turbopack-dev-server/src/source/static_assets.rs b/turbopack/crates/turbopack-dev-server/src/source/static_assets.rs index adf6313590f14..443896b2450b1 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/static_assets.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/static_assets.rs @@ -121,22 +121,34 @@ impl Introspectable for StaticAssetsContentSource { let prefix = self.prefix.await?; let children = entries .iter() - .map(|(name, entry)| { - let child = match entry { - DirectoryEntry::File(path) | DirectoryEntry::Symlink(path) => { - IntrospectableSource::new(Vc::upcast(FileSource::new(**path))) - } - DirectoryEntry::Directory(path) => { - Vc::upcast(StaticAssetsContentSource::with_prefix( - Vc::cell(format!("{}{name}/", &*prefix).into()), - **path, - )) - } - DirectoryEntry::Other(_) => todo!("what's DirectoryContent::Other?"), - DirectoryEntry::Error => todo!(), - }; - (ResolvedVc::cell(name.clone()), child) + .map(move |(name, entry)| { + let prefix = prefix.clone(); + async move { + let child = match entry { + DirectoryEntry::File(path) | DirectoryEntry::Symlink(path) => { + ResolvedVc::upcast( + IntrospectableSource::new(Vc::upcast(FileSource::new(**path))) + .to_resolved() + .await?, + ) + } + DirectoryEntry::Directory(path) => ResolvedVc::upcast( + StaticAssetsContentSource::with_prefix( + Vc::cell(format!("{}{name}/", &*prefix).into()), + **path, + ) + .to_resolved() + .await?, + ), + DirectoryEntry::Other(_) => todo!("what's DirectoryContent::Other?"), + DirectoryEntry::Error => todo!(), + }; + Ok((ResolvedVc::cell(name.clone()), child)) + } }) + .try_join() + .await? + .into_iter() .collect(); Ok(Vc::cell(children)) } diff --git a/turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs b/turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs index d4f45dd54fde8..acbef76d16dea 100644 --- a/turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs +++ b/turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs @@ -229,7 +229,9 @@ impl Introspectable for EcmascriptChunk { for &(chunk_item, _) in self.await?.content.await?.chunk_items.iter() { children.insert(( chunk_item_module_key, - IntrospectableModule::new(chunk_item.module()), + IntrospectableModule::new(chunk_item.module()) + .to_resolved() + .await?, )); } Ok(Vc::cell(children)) diff --git a/turbopack/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs b/turbopack/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs index 382e0a5cff232..cb68ef1a54fa2 100644 --- a/turbopack/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs +++ b/turbopack/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs @@ -247,12 +247,14 @@ impl Introspectable for ChunkGroupFilesAsset { } #[turbo_tasks::function] - fn children(&self) -> Vc { + async fn children(&self) -> Result> { let mut children = FxIndexSet::default(); children.insert(( ResolvedVc::cell("inner asset".into()), - IntrospectableModule::new(*ResolvedVc::upcast(self.module)), + IntrospectableModule::new(*ResolvedVc::upcast(self.module)) + .to_resolved() + .await?, )); - Vc::cell(children) + Ok(Vc::cell(children)) } } diff --git a/turbopack/crates/turbopack-node/src/render/node_api_source.rs b/turbopack/crates/turbopack-node/src/render/node_api_source.rs index eb15696cdadb9..02acddba9ba3c 100644 --- a/turbopack/crates/turbopack-node/src/render/node_api_source.rs +++ b/turbopack/crates/turbopack-node/src/render/node_api_source.rs @@ -191,7 +191,9 @@ impl Introspectable for NodeApiContentSource { let entry = entry.await?; set.insert(( ResolvedVc::cell("module".into()), - IntrospectableModule::new(Vc::upcast(*entry.module)), + IntrospectableModule::new(Vc::upcast(*entry.module)) + .to_resolved() + .await?, )); set.insert(( ResolvedVc::cell("intermediate asset".into()), @@ -199,7 +201,9 @@ impl Introspectable for NodeApiContentSource { *entry.chunking_context, Vc::upcast(*entry.module), *entry.runtime_entries, - )), + )) + .to_resolved() + .await?, )); } Ok(Vc::cell(set)) diff --git a/turbopack/crates/turbopack-node/src/render/rendered_source.rs b/turbopack/crates/turbopack-node/src/render/rendered_source.rs index a16f4b9e991a9..a6a44f3c74519 100644 --- a/turbopack/crates/turbopack-node/src/render/rendered_source.rs +++ b/turbopack/crates/turbopack-node/src/render/rendered_source.rs @@ -293,7 +293,9 @@ impl Introspectable for NodeRenderContentSource { let entry = entry.await?; set.insert(( ResolvedVc::cell("module".into()), - IntrospectableModule::new(Vc::upcast(*entry.module)), + IntrospectableModule::new(Vc::upcast(*entry.module)) + .to_resolved() + .await?, )); set.insert(( ResolvedVc::cell("intermediate asset".into()), @@ -301,7 +303,9 @@ impl Introspectable for NodeRenderContentSource { *entry.chunking_context, *entry.module, *entry.runtime_entries, - )), + )) + .to_resolved() + .await?, )); } Ok(Vc::cell(set)) diff --git a/turbopack/crates/turbopack-nodejs/src/ecmascript/node/chunk.rs b/turbopack/crates/turbopack-nodejs/src/ecmascript/node/chunk.rs index 7de67cd9654f9..b80e1ed1c6371 100644 --- a/turbopack/crates/turbopack-nodejs/src/ecmascript/node/chunk.rs +++ b/turbopack/crates/turbopack-nodejs/src/ecmascript/node/chunk.rs @@ -148,9 +148,7 @@ impl Introspectable for EcmascriptBuildNodeChunk { #[turbo_tasks::function] async fn children(&self) -> Result> { let mut children = FxIndexSet::default(); - let introspectable_chunk = ResolvedVc::upcast::>(self.chunk) - .resolve() - .await?; + let introspectable_chunk = ResolvedVc::upcast::>(self.chunk); children.insert((ResolvedVc::cell("chunk".into()), introspectable_chunk)); Ok(Vc::cell(children)) }