Unverified Commit 7657545d authored by Jan Kassens's avatar Jan Kassens Committed by GitHub

Fix webpack build dependency cell creation order (#100597)

## Summary

Fix the `no-map-async-cell` violation in webpack loader build-dependency
tracking so `ast-grep scan --format github` passes again. Prepare
resolver options concurrently, then create their cells synchronously in
request order before resolving modules concurrently. This prevents async
completion order from determining Turbo Tasks cell order.

CI context: bc37b30d (#100569) aligned
the CI ast-grep version with the repository (0.31.0 → 0.42.0), restoring
enforcement of lint failures. #100562 fixed the analyzer occurrence, but
#99549 subsequently introduced this occurrence in
`build_module_requests_changed`.

Tradeoff: the two phases add an intermediate vector allocation and a
synchronization barrier: all options must be prepared before any module
resolution starts. This may reduce overlap; the performance impact has
not been measured. There may be a better approach, such as reading the
shared resolver options once and synchronously cloning/customizing them
before creating cells, avoiding the extra preparation join.

## Verification

- `pnpm exec ast-grep scan --format github`
- `ast-grep test` (7 passed)
- `cargo fmt --all -- --check`
- `cargo check -p turbopack-node --offline`
- `pnpm build-all`

<!-- NEXT_JS_LLM -->
parent 676b665e
...@@ -562,29 +562,39 @@ async fn resolve_build_module_request( ...@@ -562,29 +562,39 @@ async fn resolve_build_module_request(
async fn build_module_requests_changed( async fn build_module_requests_changed(
requests: Vec<ResolvedBuildModuleRequest>, requests: Vec<ResolvedBuildModuleRequest>,
) -> Result<Vc<Completion>> { ) -> Result<Vc<Completion>> {
requests let prepared_requests = requests
.into_iter() .into_iter()
.map( .map(async |request| {
async |ResolvedBuildModuleRequest { // Build dependencies use Node's resolver, not application aliases or the tracer's
lookup_path, // TypeScript-first extension order. Cached package children bypass exports in
request, // webpack.
expected_path, let mut options = node_cjs_resolve_options().owned().await?;
bypass_exports, if request.bypass_exports {
}| { options
// Build dependencies use Node's resolver, not application aliases or the tracer's .into_package
// TypeScript-first extension order. Cached package children bypass exports in .retain(|option| !matches!(option, ResolveIntoPackage::ExportsField { .. }));
// webpack. }
let mut options = node_cjs_resolve_options().owned().await?; Ok::<_, anyhow::Error>((request, options))
if bypass_exports { })
options.into_package.retain(|option| { .try_join()
!matches!(option, ResolveIntoPackage::ExportsField { .. }) .await?;
});
} prepared_requests
.into_iter()
.map(|(request, options)| {
let options = options.cell();
async move {
let ResolvedBuildModuleRequest {
lookup_path,
request,
expected_path,
..
} = request;
let result = resolve( let result = resolve(
lookup_path, lookup_path,
ReferenceType::Undefined, ReferenceType::Undefined,
Request::parse(Pattern::Constant(request)), Request::parse(Pattern::Constant(request)),
options.cell(), options,
) )
.await?; .await?;
assert!(result.primary_sources().count() <= 1); assert!(result.primary_sources().count() <= 1);
...@@ -598,8 +608,8 @@ async fn build_module_requests_changed( ...@@ -598,8 +608,8 @@ async fn build_module_requests_changed(
Completion::session_dependent().await?; Completion::session_dependent().await?;
} }
Ok::<_, anyhow::Error>(()) Ok::<_, anyhow::Error>(())
}, }
) })
.try_join() .try_join()
.await?; .await?;
......
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