Unverified Commit 7aaf8ce5 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: NFT debugging (#83094)

parent 43d4532a
use anyhow::Result; use anyhow::Result;
use either::Either; use either::Either;
use tracing::Instrument;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, ValueToString, Vc}; use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
...@@ -156,7 +157,17 @@ impl ModuleReference for DirAssetReference { ...@@ -156,7 +157,17 @@ impl ModuleReference for DirAssetReference {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> { async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
let parent_path = self.source.ident().path().await?.parent(); let parent_path = self.source.ident().path().await?.parent();
Ok(resolve_reference_from_dir(parent_path, *self.path)) let span = tracing::info_span!(
"resolve DirAssetReference",
pattern = display(self.path.to_string().await?)
);
async {
resolve_reference_from_dir(parent_path, *self.path)
.resolve()
.await
}
.instrument(span)
.await
} }
} }
......
...@@ -31,6 +31,9 @@ pub struct Arguments { ...@@ -31,6 +31,9 @@ pub struct Arguments {
#[clap(long)] #[clap(long)]
pub show_issues: bool, pub show_issues: bool,
#[clap(long)]
pub depth: Option<usize>,
} }
#[global_allocator] #[global_allocator]
...@@ -95,6 +98,7 @@ async fn main_inner(args: Arguments) -> Result<()> { ...@@ -95,6 +98,7 @@ async fn main_inner(args: Arguments) -> Result<()> {
args.entry.into(), args.entry.into(),
args.graph, args.graph,
args.show_issues, args.show_issues,
args.depth,
) )
.await?; .await?;
Ok(Default::default()) Ok(Default::default())
......
...@@ -28,8 +28,9 @@ pub async fn node_file_trace( ...@@ -28,8 +28,9 @@ pub async fn node_file_trace(
input: RcStr, input: RcStr,
graph: bool, graph: bool,
show_issues: bool, show_issues: bool,
max_depth: Option<usize>,
) -> Result<()> { ) -> Result<()> {
let op = node_file_trace_operation(project_root.clone(), input.clone(), graph); let op = node_file_trace_operation(project_root.clone(), input.clone(), graph, max_depth);
let result = op.resolve_strongly_consistent().await?; let result = op.resolve_strongly_consistent().await?;
if show_issues { if show_issues {
...@@ -58,6 +59,7 @@ async fn node_file_trace_operation( ...@@ -58,6 +59,7 @@ async fn node_file_trace_operation(
project_root: RcStr, project_root: RcStr,
input: RcStr, input: RcStr,
graph: bool, graph: bool,
max_depth: Option<usize>,
) -> Result<Vc<Vec<RcStr>>> { ) -> Result<Vc<Vec<RcStr>>> {
let workspace_fs: Vc<Box<dyn FileSystem>> = Vc::upcast(DiskFileSystem::new( let workspace_fs: Vc<Box<dyn FileSystem>> = Vc::upcast(DiskFileSystem::new(
rcstr!("workspace"), rcstr!("workspace"),
...@@ -98,7 +100,7 @@ async fn node_file_trace_operation( ...@@ -98,7 +100,7 @@ async fn node_file_trace_operation(
..Default::default() ..Default::default()
} }
.cell(), .cell(),
Layer::new(rcstr!("test")), Layer::new(rcstr!("externals-tracing")),
); );
let module = module_asset_context let module = module_asset_context
.process(Vc::upcast(source), ReferenceType::Undefined) .process(Vc::upcast(source), ReferenceType::Undefined)
...@@ -107,7 +109,7 @@ async fn node_file_trace_operation( ...@@ -107,7 +109,7 @@ async fn node_file_trace_operation(
let asset = TracedAsset::new(module).to_resolved().await?; let asset = TracedAsset::new(module).to_resolved().await?;
Ok(Vc::cell(if graph { Ok(Vc::cell(if graph {
to_graph(ResolvedVc::upcast(asset)).await? to_graph(ResolvedVc::upcast(asset), max_depth.unwrap_or(usize::MAX)).await?
} else { } else {
to_list(ResolvedVc::upcast(asset)).await? to_list(ResolvedVc::upcast(asset)).await?
})) }))
...@@ -126,7 +128,7 @@ async fn to_list(asset: ResolvedVc<Box<dyn OutputAsset>>) -> Result<Vec<RcStr>> ...@@ -126,7 +128,7 @@ async fn to_list(asset: ResolvedVc<Box<dyn OutputAsset>>) -> Result<Vec<RcStr>>
Ok(assets) Ok(assets)
} }
async fn to_graph(asset: ResolvedVc<Box<dyn OutputAsset>>) -> Result<Vec<RcStr>> { async fn to_graph(asset: ResolvedVc<Box<dyn OutputAsset>>, max_depth: usize) -> Result<Vec<RcStr>> {
let mut visited = HashSet::new(); let mut visited = HashSet::new();
let mut queue = Vec::new(); let mut queue = Vec::new();
queue.push((0, asset)); queue.push((0, asset));
...@@ -139,8 +141,10 @@ async fn to_graph(asset: ResolvedVc<Box<dyn OutputAsset>>) -> Result<Vec<RcStr>> ...@@ -139,8 +141,10 @@ async fn to_graph(asset: ResolvedVc<Box<dyn OutputAsset>>) -> Result<Vec<RcStr>>
indent.push_str(" "); indent.push_str(" ");
} }
if visited.insert(asset) { if visited.insert(asset) {
for &asset in references.iter().rev() { if depth < max_depth {
queue.push((depth + 1, asset)); for &asset in references.iter().rev() {
queue.push((depth + 1, asset));
}
} }
result.push(format!("{}{}", indent, asset.path().to_string().await?).into()); result.push(format!("{}{}", indent, asset.path().to_string().await?).into());
} else if references.is_empty() { } else if references.is_empty() {
...@@ -149,5 +153,8 @@ async fn to_graph(asset: ResolvedVc<Box<dyn OutputAsset>>) -> Result<Vec<RcStr>> ...@@ -149,5 +153,8 @@ async fn to_graph(asset: ResolvedVc<Box<dyn OutputAsset>>) -> Result<Vec<RcStr>>
result.push(format!("{}{} *...", indent, asset.path().to_string().await?).into()); result.push(format!("{}{} *...", indent, asset.path().to_string().await?).into());
} }
} }
result.push("".into());
result.push("* : revisited and no references".into());
result.push("*... : revisited and references were already printed".into());
Ok(result) Ok(result)
} }
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