Unverified Commit 413b357d authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

refactor(turbopack-core): Use ResolvedVc in IntrospectableChildren (#74510)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the PR.
- Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to understand the PR)
- When linking to a Slack thread, you might want to share details of the conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
parent f612720f
...@@ -173,7 +173,7 @@ impl Introspectable for EcmascriptDevChunk { ...@@ -173,7 +173,7 @@ impl Introspectable for EcmascriptDevChunk {
async fn children(&self) -> Result<Vc<IntrospectableChildren>> { async fn children(&self) -> Result<Vc<IntrospectableChildren>> {
let mut children = FxIndexSet::default(); let mut children = FxIndexSet::default();
let chunk = ResolvedVc::upcast::<Box<dyn Introspectable>>(self.chunk); let chunk = ResolvedVc::upcast::<Box<dyn Introspectable>>(self.chunk);
children.insert((ResolvedVc::cell("chunk".into()), *chunk)); children.insert((ResolvedVc::cell("chunk".into()), chunk));
Ok(Vc::cell(children)) Ok(Vc::cell(children))
} }
} }
...@@ -6,9 +6,9 @@ pub mod utils; ...@@ -6,9 +6,9 @@ pub mod utils;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{FxIndexSet, ResolvedVc, Vc}; use turbo_tasks::{FxIndexSet, ResolvedVc, Vc};
type VcDynIntrospectable = Vc<Box<dyn Introspectable>>; type VcDynIntrospectable = ResolvedVc<Box<dyn Introspectable>>;
#[turbo_tasks::value(transparent, local)] #[turbo_tasks::value(transparent)]
pub struct IntrospectableChildren(FxIndexSet<(ResolvedVc<RcStr>, VcDynIntrospectable)>); pub struct IntrospectableChildren(FxIndexSet<(ResolvedVc<RcStr>, VcDynIntrospectable)>);
#[turbo_tasks::value_trait(local)] #[turbo_tasks::value_trait(local)]
......
...@@ -101,7 +101,7 @@ pub async fn children_from_module_references( ...@@ -101,7 +101,7 @@ pub async fn children_from_module_references(
.await? .await?
.iter() .iter()
{ {
children.insert((key, IntrospectableModule::new(*module))); children.insert((key, IntrospectableModule::new(*module).to_resolved().await?));
} }
for &output_asset in reference for &output_asset in reference
.resolve_reference() .resolve_reference()
...@@ -109,7 +109,12 @@ pub async fn children_from_module_references( ...@@ -109,7 +109,12 @@ pub async fn children_from_module_references(
.await? .await?
.iter() .iter()
{ {
children.insert((key, IntrospectableOutputAsset::new(*output_asset))); children.insert((
key,
IntrospectableOutputAsset::new(*output_asset)
.to_resolved()
.await?,
));
} }
} }
Ok(Vc::cell(children)) Ok(Vc::cell(children))
...@@ -125,7 +130,9 @@ pub async fn children_from_output_assets( ...@@ -125,7 +130,9 @@ pub async fn children_from_output_assets(
for &reference in &*references { for &reference in &*references {
children.insert(( children.insert((
key, key,
IntrospectableOutputAsset::new(*ResolvedVc::upcast(reference)), IntrospectableOutputAsset::new(*ResolvedVc::upcast(reference))
.to_resolved()
.await?,
)); ));
} }
Ok(Vc::cell(children)) Ok(Vc::cell(children))
......
...@@ -86,7 +86,7 @@ impl Introspectable for SourceMapAsset { ...@@ -86,7 +86,7 @@ impl Introspectable for SourceMapAsset {
let mut children = FxIndexSet::default(); let mut children = FxIndexSet::default();
if let Some(asset) = ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(self.asset).await? if let Some(asset) = ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(self.asset).await?
{ {
children.insert((ResolvedVc::cell("asset".into()), *asset)); children.insert((ResolvedVc::cell("asset".into()), asset));
} }
Ok(Vc::cell(children)) Ok(Vc::cell(children))
} }
......
...@@ -462,7 +462,9 @@ impl Introspectable for CssChunk { ...@@ -462,7 +462,9 @@ impl Introspectable for CssChunk {
.map(|chunk_item| async move { .map(|chunk_item| async move {
Ok(( Ok((
entry_module_key().to_resolved().await?, entry_module_key().to_resolved().await?,
IntrospectableModule::new(chunk_item.module()), IntrospectableModule::new(chunk_item.module())
.to_resolved()
.await?,
)) ))
}) })
.try_join() .try_join()
......
...@@ -36,7 +36,7 @@ impl Introspectable for IntrospectionSource { ...@@ -36,7 +36,7 @@ impl Introspectable for IntrospectionSource {
#[turbo_tasks::function] #[turbo_tasks::function]
fn children(&self) -> Vc<IntrospectableChildren> { fn children(&self) -> Vc<IntrospectableChildren> {
let name = ResolvedVc::cell("root".into()); 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())
} }
} }
......
...@@ -322,30 +322,41 @@ impl Introspectable for AssetGraphContentSource { ...@@ -322,30 +322,41 @@ impl Introspectable for AssetGraphContentSource {
let expanded_key = ResolvedVc::cell("expanded".into()); let expanded_key = ResolvedVc::cell("expanded".into());
let root_assets = this.root_assets.await?; let root_assets = this.root_assets.await?;
let root_asset_children = root_assets.iter().map(|&asset| { let root_asset_children = root_assets
( .iter()
key, .map(|&asset| async move {
IntrospectableOutputAsset::new(*ResolvedVc::upcast(asset)), Ok((
) key,
}); IntrospectableOutputAsset::new(*ResolvedVc::upcast(asset))
.to_resolved()
.await?,
))
})
.try_join()
.await?;
let expanded_assets = self.all_assets_map().await?; let expanded_assets = self.all_assets_map().await?;
let expanded_asset_children = expanded_assets let expanded_asset_children = expanded_assets
.values() .values()
.filter(|&a| !root_assets.contains(a)) .filter(|&a| !root_assets.contains(a))
.map(|&asset| { .map(|&asset| async move {
( Ok((
inner_key, inner_key,
IntrospectableOutputAsset::new(*ResolvedVc::upcast(asset)), IntrospectableOutputAsset::new(*ResolvedVc::upcast(asset))
) .to_resolved()
}); .await?,
))
})
.try_join()
.await?;
Ok(Vc::cell( Ok(Vc::cell(
root_asset_children root_asset_children
.into_iter()
.chain(expanded_asset_children) .chain(expanded_asset_children)
.chain(once(( .chain(once((
expanded_key, expanded_key,
Vc::upcast(FullyExpaned(self.to_resolved().await?).cell()), ResolvedVc::upcast(FullyExpanded(self.to_resolved().await?).resolved_cell()),
))) )))
.collect(), .collect(),
)) ))
...@@ -353,18 +364,18 @@ impl Introspectable for AssetGraphContentSource { ...@@ -353,18 +364,18 @@ impl Introspectable for AssetGraphContentSource {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn fully_expaned_introspectable_type() -> Vc<RcStr> { fn fully_expanded_introspectable_type() -> Vc<RcStr> {
Vc::cell("fully expanded asset graph content source".into()) Vc::cell("fully expanded asset graph content source".into())
} }
#[turbo_tasks::value] #[turbo_tasks::value]
struct FullyExpaned(ResolvedVc<AssetGraphContentSource>); struct FullyExpanded(ResolvedVc<AssetGraphContentSource>);
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl Introspectable for FullyExpaned { impl Introspectable for FullyExpanded {
#[turbo_tasks::function] #[turbo_tasks::function]
fn ty(&self) -> Vc<RcStr> { fn ty(&self) -> Vc<RcStr> {
fully_expaned_introspectable_type() fully_expanded_introspectable_type()
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -381,7 +392,12 @@ impl Introspectable for FullyExpaned { ...@@ -381,7 +392,12 @@ impl Introspectable for FullyExpaned {
expand(&*source.root_assets.await?, &*source.root_path.await?, None).await?; expand(&*source.root_assets.await?, &*source.root_path.await?, None).await?;
let children = expanded_assets let children = expanded_assets
.iter() .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(); .collect();
Ok(Vc::cell(children)) Ok(Vc::cell(children))
......
...@@ -97,7 +97,7 @@ impl Introspectable for CombinedContentSource { ...@@ -97,7 +97,7 @@ impl Introspectable for CombinedContentSource {
.await? .await?
.into_iter() .into_iter()
.flatten() .flatten()
.map(|i| (source, *i)) .map(|i| (source, i))
.collect(), .collect(),
)) ))
} }
......
...@@ -141,10 +141,10 @@ impl Introspectable for ConditionalContentSource { ...@@ -141,10 +141,10 @@ impl Introspectable for ConditionalContentSource {
[ [
ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(self.activator) ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(self.activator)
.await? .await?
.map(|i| (activator_key(), *i)), .map(|i| (activator_key(), i)),
ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(self.action) ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(self.action)
.await? .await?
.map(|i| (action_key(), *i)), .map(|i| (action_key(), i)),
] ]
.into_iter() .into_iter()
.flatten() .flatten()
......
...@@ -48,13 +48,11 @@ impl Introspectable for LazyInstantiatedContentSource { ...@@ -48,13 +48,11 @@ impl Introspectable for LazyInstantiatedContentSource {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn children(&self) -> Result<Vc<IntrospectableChildren>> { async fn children(&self) -> Result<Vc<IntrospectableChildren>> {
Ok(Vc::cell( Ok(Vc::cell(
[ [ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(
Vc::try_resolve_sidecast::<Box<dyn Introspectable>>( self.get_source.content_source().to_resolved().await?,
self.get_source.content_source(), )
) .await?
.await? .map(|i| (source_key(), i))]
.map(|i| (source_key(), i)),
]
.into_iter() .into_iter()
.flatten() .flatten()
.map(|(k, v)| async move { Ok((k.to_resolved().await?, v)) }) .map(|(k, v)| async move { Ok((k.to_resolved().await?, v)) })
......
...@@ -66,7 +66,7 @@ async fn get_introspection_children( ...@@ -66,7 +66,7 @@ async fn get_introspection_children(
.map(|(path, source)| async move { .map(|(path, source)| async move {
Ok(ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(source) Ok(ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(source)
.await? .await?
.map(|i| (ResolvedVc::cell(path), *i))) .map(|i| (ResolvedVc::cell(path), i)))
}) })
.try_join() .try_join()
.await? .await?
......
...@@ -121,22 +121,34 @@ impl Introspectable for StaticAssetsContentSource { ...@@ -121,22 +121,34 @@ impl Introspectable for StaticAssetsContentSource {
let prefix = self.prefix.await?; let prefix = self.prefix.await?;
let children = entries let children = entries
.iter() .iter()
.map(|(name, entry)| { .map(move |(name, entry)| {
let child = match entry { let prefix = prefix.clone();
DirectoryEntry::File(path) | DirectoryEntry::Symlink(path) => { async move {
IntrospectableSource::new(Vc::upcast(FileSource::new(**path))) let child = match entry {
} DirectoryEntry::File(path) | DirectoryEntry::Symlink(path) => {
DirectoryEntry::Directory(path) => { ResolvedVc::upcast(
Vc::upcast(StaticAssetsContentSource::with_prefix( IntrospectableSource::new(Vc::upcast(FileSource::new(**path)))
Vc::cell(format!("{}{name}/", &*prefix).into()), .to_resolved()
**path, .await?,
)) )
} }
DirectoryEntry::Other(_) => todo!("what's DirectoryContent::Other?"), DirectoryEntry::Directory(path) => ResolvedVc::upcast(
DirectoryEntry::Error => todo!(), StaticAssetsContentSource::with_prefix(
}; Vc::cell(format!("{}{name}/", &*prefix).into()),
(ResolvedVc::cell(name.clone()), child) **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(); .collect();
Ok(Vc::cell(children)) Ok(Vc::cell(children))
} }
......
...@@ -229,7 +229,9 @@ impl Introspectable for EcmascriptChunk { ...@@ -229,7 +229,9 @@ impl Introspectable for EcmascriptChunk {
for &(chunk_item, _) in self.await?.content.await?.chunk_items.iter() { for &(chunk_item, _) in self.await?.content.await?.chunk_items.iter() {
children.insert(( children.insert((
chunk_item_module_key, chunk_item_module_key,
IntrospectableModule::new(chunk_item.module()), IntrospectableModule::new(chunk_item.module())
.to_resolved()
.await?,
)); ));
} }
Ok(Vc::cell(children)) Ok(Vc::cell(children))
......
...@@ -247,12 +247,14 @@ impl Introspectable for ChunkGroupFilesAsset { ...@@ -247,12 +247,14 @@ impl Introspectable for ChunkGroupFilesAsset {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn children(&self) -> Vc<IntrospectableChildren> { async fn children(&self) -> Result<Vc<IntrospectableChildren>> {
let mut children = FxIndexSet::default(); let mut children = FxIndexSet::default();
children.insert(( children.insert((
ResolvedVc::cell("inner asset".into()), 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))
} }
} }
...@@ -191,7 +191,9 @@ impl Introspectable for NodeApiContentSource { ...@@ -191,7 +191,9 @@ impl Introspectable for NodeApiContentSource {
let entry = entry.await?; let entry = entry.await?;
set.insert(( set.insert((
ResolvedVc::cell("module".into()), ResolvedVc::cell("module".into()),
IntrospectableModule::new(Vc::upcast(*entry.module)), IntrospectableModule::new(Vc::upcast(*entry.module))
.to_resolved()
.await?,
)); ));
set.insert(( set.insert((
ResolvedVc::cell("intermediate asset".into()), ResolvedVc::cell("intermediate asset".into()),
...@@ -199,7 +201,9 @@ impl Introspectable for NodeApiContentSource { ...@@ -199,7 +201,9 @@ impl Introspectable for NodeApiContentSource {
*entry.chunking_context, *entry.chunking_context,
Vc::upcast(*entry.module), Vc::upcast(*entry.module),
*entry.runtime_entries, *entry.runtime_entries,
)), ))
.to_resolved()
.await?,
)); ));
} }
Ok(Vc::cell(set)) Ok(Vc::cell(set))
......
...@@ -293,7 +293,9 @@ impl Introspectable for NodeRenderContentSource { ...@@ -293,7 +293,9 @@ impl Introspectable for NodeRenderContentSource {
let entry = entry.await?; let entry = entry.await?;
set.insert(( set.insert((
ResolvedVc::cell("module".into()), ResolvedVc::cell("module".into()),
IntrospectableModule::new(Vc::upcast(*entry.module)), IntrospectableModule::new(Vc::upcast(*entry.module))
.to_resolved()
.await?,
)); ));
set.insert(( set.insert((
ResolvedVc::cell("intermediate asset".into()), ResolvedVc::cell("intermediate asset".into()),
...@@ -301,7 +303,9 @@ impl Introspectable for NodeRenderContentSource { ...@@ -301,7 +303,9 @@ impl Introspectable for NodeRenderContentSource {
*entry.chunking_context, *entry.chunking_context,
*entry.module, *entry.module,
*entry.runtime_entries, *entry.runtime_entries,
)), ))
.to_resolved()
.await?,
)); ));
} }
Ok(Vc::cell(set)) Ok(Vc::cell(set))
......
...@@ -148,9 +148,7 @@ impl Introspectable for EcmascriptBuildNodeChunk { ...@@ -148,9 +148,7 @@ impl Introspectable for EcmascriptBuildNodeChunk {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn children(&self) -> Result<Vc<IntrospectableChildren>> { async fn children(&self) -> Result<Vc<IntrospectableChildren>> {
let mut children = FxIndexSet::default(); let mut children = FxIndexSet::default();
let introspectable_chunk = ResolvedVc::upcast::<Box<dyn Introspectable>>(self.chunk) let introspectable_chunk = ResolvedVc::upcast::<Box<dyn Introspectable>>(self.chunk);
.resolve()
.await?;
children.insert((ResolvedVc::cell("chunk".into()), introspectable_chunk)); children.insert((ResolvedVc::cell("chunk".into()), introspectable_chunk));
Ok(Vc::cell(children)) Ok(Vc::cell(children))
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment