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 {
async fn children(&self) -> Result<Vc<IntrospectableChildren>> {
let mut children = FxIndexSet::default();
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))
}
}
......@@ -6,9 +6,9 @@ pub mod utils;
use turbo_rcstr::RcStr;
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)>);
#[turbo_tasks::value_trait(local)]
......
......@@ -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))
......
......@@ -86,7 +86,7 @@ impl Introspectable for SourceMapAsset {
let mut children = FxIndexSet::default();
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))
}
......
......@@ -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()
......
......@@ -36,7 +36,7 @@ impl Introspectable for IntrospectionSource {
#[turbo_tasks::function]
fn children(&self) -> Vc<IntrospectableChildren> {
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 {
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<RcStr> {
fn fully_expanded_introspectable_type() -> Vc<RcStr> {
Vc::cell("fully expanded asset graph content source".into())
}
#[turbo_tasks::value]
struct FullyExpaned(ResolvedVc<AssetGraphContentSource>);
struct FullyExpanded(ResolvedVc<AssetGraphContentSource>);
#[turbo_tasks::value_impl]
impl Introspectable for FullyExpaned {
impl Introspectable for FullyExpanded {
#[turbo_tasks::function]
fn ty(&self) -> Vc<RcStr> {
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))
......
......@@ -97,7 +97,7 @@ impl Introspectable for CombinedContentSource {
.await?
.into_iter()
.flatten()
.map(|i| (source, *i))
.map(|i| (source, i))
.collect(),
))
}
......
......@@ -141,10 +141,10 @@ impl Introspectable for ConditionalContentSource {
[
ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(self.activator)
.await?
.map(|i| (activator_key(), *i)),
.map(|i| (activator_key(), i)),
ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(self.action)
.await?
.map(|i| (action_key(), *i)),
.map(|i| (action_key(), i)),
]
.into_iter()
.flatten()
......
......@@ -48,13 +48,11 @@ impl Introspectable for LazyInstantiatedContentSource {
#[turbo_tasks::function]
async fn children(&self) -> Result<Vc<IntrospectableChildren>> {
Ok(Vc::cell(
[
Vc::try_resolve_sidecast::<Box<dyn Introspectable>>(
self.get_source.content_source(),
)
.await?
.map(|i| (source_key(), i)),
]
[ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(
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)) })
......
......@@ -66,7 +66,7 @@ async fn get_introspection_children(
.map(|(path, source)| async move {
Ok(ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(source)
.await?
.map(|i| (ResolvedVc::cell(path), *i)))
.map(|i| (ResolvedVc::cell(path), i)))
})
.try_join()
.await?
......
......@@ -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))
}
......
......@@ -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))
......
......@@ -247,12 +247,14 @@ impl Introspectable for ChunkGroupFilesAsset {
}
#[turbo_tasks::function]
fn children(&self) -> Vc<IntrospectableChildren> {
async fn children(&self) -> Result<Vc<IntrospectableChildren>> {
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))
}
}
......@@ -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))
......
......@@ -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))
......
......@@ -148,9 +148,7 @@ impl Introspectable for EcmascriptBuildNodeChunk {
#[turbo_tasks::function]
async fn children(&self) -> Result<Vc<IntrospectableChildren>> {
let mut children = FxIndexSet::default();
let introspectable_chunk = ResolvedVc::upcast::<Box<dyn Introspectable>>(self.chunk)
.resolve()
.await?;
let introspectable_chunk = ResolvedVc::upcast::<Box<dyn Introspectable>>(self.chunk);
children.insert((ResolvedVc::cell("chunk".into()), introspectable_chunk));
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