Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-browser/src/ecmascript/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
4 changes: 2 additions & 2 deletions turbopack/crates/turbopack-core/src/introspect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
13 changes: 10 additions & 3 deletions turbopack/crates/turbopack-core/src/introspect/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,20 @@ 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()
.primary_output_assets()
.await?
.iter()
{
children.insert((key, IntrospectableOutputAsset::new(*output_asset)));
children.insert((
key,
IntrospectableOutputAsset::new(*output_asset)
.to_resolved()
.await?,
));
}
}
Ok(Vc::cell(children))
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
4 changes: 3 additions & 1 deletion turbopack/crates/turbopack-css/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
50 changes: 33 additions & 17 deletions turbopack/crates/turbopack-dev-server/src/source/asset_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,49 +322,60 @@ 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(),
))
}
}

#[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]
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Introspectable for CombinedContentSource {
.await?
.into_iter()
.flatten()
.map(|i| (source, *i))
.map(|i| (source, i))
.collect(),
))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) })
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-dev-server/src/source/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
42 changes: 27 additions & 15 deletions turbopack/crates/turbopack-dev-server/src/source/static_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
4 changes: 3 additions & 1 deletion turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
8 changes: 6 additions & 2 deletions turbopack/crates/turbopack-node/src/render/node_api_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,19 @@ 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()),
IntrospectableOutputAsset::new(get_intermediate_asset(
*entry.chunking_context,
Vc::upcast(*entry.module),
*entry.runtime_entries,
)),
))
.to_resolved()
.await?,
));
}
Ok(Vc::cell(set))
Expand Down
8 changes: 6 additions & 2 deletions turbopack/crates/turbopack-node/src/render/rendered_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,19 @@ 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()),
IntrospectableOutputAsset::new(get_intermediate_asset(
*entry.chunking_context,
*entry.module,
*entry.runtime_entries,
)),
))
.to_resolved()
.await?,
));
}
Ok(Vc::cell(set))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
Loading