Unverified Commit 16c8ea5d authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

Prefer using join over try_join when you don't want a vec (#98547)

Adopt `join` over `try_join` in a number of places to avoid temporary
Vec allocations

`try_join` always copies a `Vec<Result<T>>` to a `Result<Vec<T>>` which
is sometimes convenient but at least sometimes wasteful if you are
immediately transforming into another collection type.

Adopt it to turn `primary_modules` into a `SmallVec` since in the vast
majority of cases there is only one module and so we can save a bunch of
allocations of tiny arrays

---------
Co-authored-by: 's avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
parent 93bb22ad
...@@ -10496,6 +10496,7 @@ dependencies = [ ...@@ -10496,6 +10496,7 @@ dependencies = [
"either", "either",
"erased-serde", "erased-serde",
"indexmap 2.14.0", "indexmap 2.14.0",
"itertools 0.10.5",
"num-bigint", "num-bigint",
"patricia_tree", "patricia_tree",
"petgraph 0.8.3", "petgraph 0.8.3",
......
...@@ -24,8 +24,8 @@ bincode = { workspace = true } ...@@ -24,8 +24,8 @@ bincode = { workspace = true }
byteorder = { workspace = true } byteorder = { workspace = true }
either = { workspace = true } either = { workspace = true }
futures = { workspace = true } futures = { workspace = true }
indexmap = { workspace = true }
itertools = { workspace = true } itertools = { workspace = true }
indexmap = { workspace = true }
next-core = { workspace = true } next-core = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
roaring = { workspace = true } roaring = { workspace = true }
......
...@@ -8,7 +8,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; ...@@ -8,7 +8,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
use serde::Serialize; use serde::Serialize;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
FxIndexSet, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, ValueToString, ValueToStringRef, Vc, FxIndexSet, JoinIterExt, ResolvedVc, TryFlatJoinIterExt, ValueToString, ValueToStringRef, Vc,
}; };
use turbo_tasks_fs::{ use turbo_tasks_fs::{
File, FileContent, FileSystemPath, File, FileContent, FileSystemPath,
...@@ -555,19 +555,19 @@ pub async fn analyze_module_graphs(module_graph: Vc<ModuleGraph>) -> Result<Vc<F ...@@ -555,19 +555,19 @@ pub async fn analyze_module_graphs(module_graph: Vc<ModuleGraph>) -> Result<Vc<F
Ok(Some((from_ident, to_ident))) Ok(Some((from_ident, to_ident)))
} }
let all_modules = all_modules let modules = all_modules
.iter() .iter()
.copied() .copied()
.map(async |module| { .map(async |module| {
let ident = module.ident().to_string().owned().await?; let ident = module.ident().to_string().owned().await?;
let path = module.ident().await?.path.to_string_ref().await?; let path = module.ident().await?.path.to_string_ref().await?;
Ok((ident, path)) anyhow::Ok((ident, path))
}) })
.try_join() .join()
.await?; .await;
for module in modules {
for (ident, path) in &all_modules { let (ident, path) = module?;
builder.ensure_module(ident, path); builder.ensure_module(&ident, &path);
} }
let all_edges = all_edges let all_edges = all_edges
......
...@@ -6,7 +6,7 @@ use next_core::{ ...@@ -6,7 +6,7 @@ use next_core::{
}; };
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use turbo_tasks::{ use turbo_tasks::{
NonLocalValue, ResolvedVc, TryFlatJoinIterExt, Vc, debug::ValueDebugFormat, trace::TraceRawVcs, JoinIterExt, NonLocalValue, ResolvedVc, Vc, debug::ValueDebugFormat, trace::TraceRawVcs,
}; };
use turbopack_core::{module::Module, module_graph::ModuleGraphLayer}; use turbopack_core::{module::Module, module_graph::ModuleGraphLayer};
use turbopack_css::chunk::CssChunkPlaceable; use turbopack_css::chunk::CssChunkPlaceable;
...@@ -65,10 +65,11 @@ pub async fn map_client_references( ...@@ -65,10 +65,11 @@ pub async fn map_client_references(
Ok(None) Ok(None)
} }
}) })
.try_flat_join() .join()
.await? .await
.into_iter() .into_iter()
.collect::<FxHashMap<_, _>>(); .filter_map(Result::transpose)
.collect::<Result<FxHashMap<_, _>>>()?;
Ok(Vc::cell(manifest)) Ok(Vc::cell(manifest))
} }
...@@ -2,10 +2,11 @@ use std::fmt::Display; ...@@ -2,10 +2,11 @@ use std::fmt::Display;
use anyhow::Result; use anyhow::Result;
use bincode::{Decode, Encode}; use bincode::{Decode, Encode};
use itertools::Itertools;
use next_core::app_structure::FileSystemPathVec; use next_core::app_structure::FileSystemPathVec;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
Completion, FxIndexMap, FxIndexSet, NonLocalValue, OperationVc, ResolvedVc, TryFlatJoinIterExt, Completion, FxIndexMap, FxIndexSet, JoinIterExt, NonLocalValue, OperationVc, ResolvedVc,
TryJoinIterExt, Vc, debug::ValueDebugFormat, trace::TraceRawVcs, TryJoinIterExt, Vc, debug::ValueDebugFormat, trace::TraceRawVcs,
}; };
use turbopack_core::{ use turbopack_core::{
...@@ -187,13 +188,15 @@ async fn output_of_endpoints(endpoints: Vec<Vc<Box<dyn Endpoint>>>) -> Result<Vc ...@@ -187,13 +188,15 @@ async fn output_of_endpoints(endpoints: Vec<Vc<Box<dyn Endpoint>>>) -> Result<Vc
async fn module_graphs_of_endpoints( async fn module_graphs_of_endpoints(
endpoints: Vec<Vc<Box<dyn Endpoint>>>, endpoints: Vec<Vc<Box<dyn Endpoint>>>,
) -> Result<Vc<ModuleGraphs>> { ) -> Result<Vc<ModuleGraphs>> {
// Deduplicate while preserving first-seen order, then hand back a `Vec`.
let module_graphs = endpoints let module_graphs = endpoints
.iter() .iter()
.map(async |endpoint| Ok(endpoint.module_graphs().await?.into_iter())) .map(async |endpoint| anyhow::Ok(endpoint.module_graphs().await?.into_iter()))
.try_flat_join() .join()
.await? .await
.into_iter() .into_iter()
.collect::<FxIndexSet<_>>() .flatten_ok()
.collect::<Result<FxIndexSet<_>>>()?
.into_iter() .into_iter()
.collect::<Vec<_>>(); .collect::<Vec<_>>();
Ok(Vc::cell(module_graphs)) Ok(Vc::cell(module_graphs))
......
...@@ -5,7 +5,7 @@ use regex::Regex; ...@@ -5,7 +5,7 @@ use regex::Regex;
use smallvec::smallvec; use smallvec::smallvec;
use tracing::Instrument; use tracing::Instrument;
use turbo_rcstr::rcstr; use turbo_rcstr::rcstr;
use turbo_tasks::{FxIndexMap, FxIndexSet, ResolvedVc, TryJoinIterExt, ValueToString, Vc}; use turbo_tasks::{FxIndexMap, FxIndexSet, JoinIterExt, ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{FileContent, rope::Rope}; use turbo_tasks_fs::{FileContent, rope::Rope};
use turbopack::{ModuleAssetContext, module_options::CustomModuleType}; use turbopack::{ModuleAssetContext, module_options::CustomModuleType};
use turbopack_core::{ use turbopack_core::{
...@@ -202,10 +202,10 @@ impl EcmascriptChunkPlaceable for RawEcmascriptModule { ...@@ -202,10 +202,10 @@ impl EcmascriptChunkPlaceable for RawEcmascriptModule {
}, },
)) ))
}) })
.try_join() .join()
.await? .await
.into_iter() .into_iter()
.collect::<FxIndexMap<_, _>>() .collect::<Result<FxIndexMap<_, _>>>()?
) )
)?; )?;
code += "};\n"; code += "};\n";
......
...@@ -18,8 +18,7 @@ use swc_core::{ ...@@ -18,8 +18,7 @@ use swc_core::{
}; };
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
NonLocalValue, ResolvedVc, TryJoinIterExt, ValueDefault, Vc, trace::TraceRawVcs, JoinIterExt, NonLocalValue, ResolvedVc, ValueDefault, Vc, trace::TraceRawVcs, util::WrapFuture,
util::WrapFuture,
}; };
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
...@@ -1362,11 +1361,11 @@ async fn parse_segment_config_from_loader_tree_internal( ...@@ -1362,11 +1361,11 @@ async fn parse_segment_config_from_loader_tree_internal(
.parallel_routes .parallel_routes
.values() .values()
.map(|loader_tree| Box::pin(parse_segment_config_from_loader_tree_internal(loader_tree))) .map(|loader_tree| Box::pin(parse_segment_config_from_loader_tree_internal(loader_tree)))
.try_join() .join()
.await?; .await;
for tree in parallel_configs { for tree in parallel_configs {
config.apply_parallel_config(&tree)?; config.apply_parallel_config(&tree?)?;
} }
let modules = &loader_tree.modules; let modules = &loader_tree.modules;
......
...@@ -25,6 +25,7 @@ data-encoding = { workspace = true } ...@@ -25,6 +25,7 @@ data-encoding = { workspace = true }
either = { workspace = true } either = { workspace = true }
erased-serde = { workspace = true } erased-serde = { workspace = true }
indexmap = { workspace = true } indexmap = { workspace = true }
itertools = { workspace = true }
num-bigint = "0.4" num-bigint = "0.4"
patricia_tree = { version = "0.10.1", features = ["serde"] } patricia_tree = { version = "0.10.1", features = ["serde"] }
petgraph = { workspace = true, features = ["serde-1"] } petgraph = { workspace = true, features = ["serde-1"] }
......
use anyhow::Result; use anyhow::Result;
use bincode::{Decode, Encode}; use bincode::{Decode, Encode};
use turbo_tasks::{ use turbo_tasks::{
FxIndexSet, OperationVc, ReadRef, ResolvedVc, TryJoinIterExt, ValueToString, Vc, FxIndexSet, JoinIterExt, OperationVc, ReadRef, ResolvedVc, ValueToString, Vc,
trace::TraceRawVcs, turbofmt, trace::TraceRawVcs, turbofmt,
}; };
use turbo_tasks_hash::Xxh3Hash64Hasher; use turbo_tasks_hash::Xxh3Hash64Hasher;
...@@ -100,9 +100,10 @@ impl AvailableModules { ...@@ -100,9 +100,10 @@ impl AvailableModules {
.await? .await?
.iter() .iter()
.map(async |&module| module.ident_strings().await) .map(async |&module| module.ident_strings().await)
.try_join() .join()
.await?; .await;
for idents in item_idents { for idents in item_idents {
let idents = idents?;
match idents { match idents {
IdentStrings::Single(ident) => hasher.write_value(ident), IdentStrings::Single(ident) => hasher.write_value(ident),
IdentStrings::Multiple(idents) => { IdentStrings::Multiple(idents) => {
......
...@@ -6,7 +6,8 @@ use rustc_hash::{FxHashMap, FxHashSet}; ...@@ -6,7 +6,8 @@ use rustc_hash::{FxHashMap, FxHashSet};
use tracing::Instrument; use tracing::Instrument;
use turbo_rcstr::rcstr; use turbo_rcstr::rcstr;
use turbo_tasks::{ use turbo_tasks::{
FxIndexSet, OperationVc, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc, trace::TraceRawVcs, FxIndexSet, JoinIterExt, OperationVc, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc,
trace::TraceRawVcs,
}; };
use super::{ use super::{
...@@ -90,11 +91,11 @@ pub async fn make_chunk_group( ...@@ -90,11 +91,11 @@ pub async fn make_chunk_group(
*chunking_context, *chunking_context,
) )
}) })
.try_join() .join()
.await? .await
.into_iter() .into_iter()
.flatten() .filter_map(Result::transpose)
.collect::<Vec<_>>(); .collect::<Result<Vec<_>>>()?;
let chunk_item_batch_groups = batch_groups let chunk_item_batch_groups = batch_groups
.iter() .iter()
......
...@@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize}; ...@@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize};
use tracing::{Instrument, Level, Span}; use tracing::{Instrument, Level, Span};
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
CollectiblesSource, FxIndexMap, NonLocalValue, OperationVc, ReadRef, ResolvedVc, CollectiblesSource, FxIndexMap, JoinIterExt, NonLocalValue, OperationVc, ReadRef, ResolvedVc,
TryFlatJoinIterExt, TryJoinIterExt, ValueToString, Vc, TryFlatJoinIterExt, TryJoinIterExt, ValueToString, Vc,
debug::ValueDebugFormat, debug::ValueDebugFormat,
graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow}, graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow},
...@@ -1184,13 +1184,12 @@ impl ModuleGraphSnapshot { ...@@ -1184,13 +1184,12 @@ impl ModuleGraphSnapshot {
/// Returns a map of all modules in the graphs to their identifiers. /// Returns a map of all modules in the graphs to their identifiers.
/// This is primarily useful for debugging. /// This is primarily useful for debugging.
pub async fn get_ids(&self) -> Result<FxHashMap<ResolvedVc<Box<dyn Module>>, ReadRef<RcStr>>> { pub async fn get_ids(&self) -> Result<FxHashMap<ResolvedVc<Box<dyn Module>>, ReadRef<RcStr>>> {
Ok(self self.iter_nodes()
.iter_nodes()
.map(async |n| Ok((n, n.ident().to_string().await?))) .map(async |n| Ok((n, n.ident().to_string().await?)))
.try_join() .join()
.await? .await
.into_iter() .into_iter()
.collect::<FxHashMap<_, _>>()) .collect()
} }
/// Traverses all reachable nodes exactly once and calls the visitor. /// Traverses all reachable nodes exactly once and calls the visitor.
......
...@@ -7,14 +7,15 @@ use std::{ ...@@ -7,14 +7,15 @@ use std::{
use anyhow::{Context, Result, bail}; use anyhow::{Context, Result, bail};
use bincode::{Decode, Encode}; use bincode::{Decode, Encode};
use either::Either; use either::Either;
use itertools::Itertools;
use petgraph::graph::{DiGraph, EdgeIndex, NodeIndex}; use petgraph::graph::{DiGraph, EdgeIndex, NodeIndex};
use rustc_hash::{FxHashMap, FxHashSet, FxHasher}; use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument; use tracing::Instrument;
use turbo_prehash::BuildHasherExt; use turbo_prehash::BuildHasherExt;
use turbo_tasks::{ use turbo_tasks::{
FxIndexMap, FxIndexSet, NonLocalValue, ResolvedVc, TryJoinIterExt, ValueToString, Vc, FxIndexMap, FxIndexSet, JoinIterExt, NonLocalValue, ResolvedVc, TryJoinIterExt, ValueToString,
trace::TraceRawVcs, turbobail, Vc, trace::TraceRawVcs, turbobail,
}; };
use crate::{ use crate::{
...@@ -848,7 +849,7 @@ pub async fn compute_module_batches( ...@@ -848,7 +849,7 @@ pub async fn compute_module_batches(
.into_iter() .into_iter()
.map(async |(key, items)| { .map(async |(key, items)| {
if items.len() == 1 { if items.len() == 1 {
Ok(Either::Left(std::iter::empty())) anyhow::Ok(Either::Left(std::iter::empty()))
} else { } else {
let batch_group = ModuleBatchGroup::new(items.clone(), (*key).clone()) let batch_group = ModuleBatchGroup::new(items.clone(), (*key).clone())
.to_resolved() .to_resolved()
...@@ -858,11 +859,11 @@ pub async fn compute_module_batches( ...@@ -858,11 +859,11 @@ pub async fn compute_module_batches(
)) ))
} }
}) })
.try_join() .join()
.await? .await
.into_iter() .into_iter()
.flatten() .flatten_ok()
.collect::<FxHashMap<_, _>>(); .collect::<Result<FxHashMap<_, _>>>()?;
// Insert batches into the graph and store the NodeIndices // Insert batches into the graph and store the NodeIndices
let mut batches_count = 0; let mut batches_count = 0;
......
use anyhow::Result; use anyhow::Result;
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc}; use turbo_tasks::{JoinIterExt, ResolvedVc, Vc};
use crate::{ use crate::{
module::{Module, ModuleSideEffects}, module::{Module, ModuleSideEffects},
...@@ -62,10 +62,10 @@ async fn compute_side_effect_free_module_info_single( ...@@ -62,10 +62,10 @@ async fn compute_side_effect_free_module_info_single(
), ),
}) })
}) })
.try_join() .join()
.await? .await
.into_iter() .into_iter()
.collect::<FxHashMap<_, _>>(); .collect::<Result<FxHashMap<_, _>>>()?;
// Modules are categorized as side-effectful, locally side effect free and side effect free. // Modules are categorized as side-effectful, locally side effect free and side effect free.
// So we are really just interested in determining what modules that are locally side effect // So we are really just interested in determining what modules that are locally side effect
......
...@@ -2,6 +2,7 @@ use std::collections::HashSet; ...@@ -2,6 +2,7 @@ use std::collections::HashSet;
use anyhow::Result; use anyhow::Result;
use bincode::{Decode, Encode}; use bincode::{Decode, Encode};
use smallvec::SmallVec;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
NonLocalValue, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, ValueToString, Vc, NonLocalValue, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, ValueToString, Vc,
...@@ -135,9 +136,8 @@ pub async fn referenced_modules_and_affecting_sources( ...@@ -135,9 +136,8 @@ pub async fn referenced_modules_and_affecting_sources(
let trait_ref = reference.into_trait_ref().await?; let trait_ref = reference.into_trait_ref().await?;
let resolve_result = reference.resolve_reference().await?; let resolve_result = reference.resolve_reference().await?;
if let Some(chunking_type) = &trait_ref.chunking_type() { if let Some(chunking_type) = &trait_ref.chunking_type() {
let mut modules = resolve_result let mut modules: SmallVec<[_; 2]> =
.primary_modules_raw_iter() resolve_result.primary_modules_raw_iter().collect();
.collect::<Vec<_>>();
modules.extend( modules.extend(
resolve_result resolve_result
.affecting_sources_iter() .affecting_sources_iter()
...@@ -225,7 +225,7 @@ pub async fn primary_referenced_modules(module: Vc<Box<dyn Module>>) -> Result<V ...@@ -225,7 +225,7 @@ pub async fn primary_referenced_modules(module: Vc<Box<dyn Module>>) -> Result<V
pub struct ResolvedReference { pub struct ResolvedReference {
pub chunking_type: ChunkingType, pub chunking_type: ChunkingType,
pub binding_usage: BindingUsage, pub binding_usage: BindingUsage,
pub modules: Vec<ResolvedVc<Box<dyn Module>>>, pub modules: SmallVec<[ResolvedVc<Box<dyn Module>>; 2]>,
} }
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
......
...@@ -17,8 +17,8 @@ use tracing::{Instrument, Level}; ...@@ -17,8 +17,8 @@ use tracing::{Instrument, Level};
use turbo_frozenmap::{FrozenMap, FrozenSet}; use turbo_frozenmap::{FrozenMap, FrozenSet};
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
FxIndexMap, NonLocalValue, ReadRef, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, FxIndexMap, JoinIterExt, NonLocalValue, ReadRef, ResolvedVc, TryFlatJoinIterExt,
ValueToString, ValueToStringRef, Vc, trace::TraceRawVcs, TryJoinIterExt, ValueToString, ValueToStringRef, Vc, trace::TraceRawVcs,
}; };
use turbo_tasks_fs::{FileSystemEntryType, FileSystemPath, RealPathErrorType}; use turbo_tasks_fs::{FileSystemEntryType, FileSystemPath, RealPathErrorType};
use turbo_unix_path::normalize_request; use turbo_unix_path::normalize_request;
...@@ -346,12 +346,15 @@ impl ModuleResolveResult { ...@@ -346,12 +346,15 @@ impl ModuleResolveResult {
/// Returns primary modules (no duplicates). Emits errors for Unknown items. /// Returns primary modules (no duplicates). Emits errors for Unknown items.
/// Duplicates are already marked at construction time so no extra dedup is /// Duplicates are already marked at construction time so no extra dedup is
/// needed here. /// needed here.
pub async fn primary_modules(&self) -> Result<Vec<ResolvedVc<Box<dyn Module>>>> { pub async fn primary_modules(&self) -> Result<SmallVec<[ResolvedVc<Box<dyn Module>>; 2]>> {
self.primary self.primary
.iter() .iter()
.map(async |(_, item)| item.as_module().await) .map(async |(_, item)| item.as_module().await)
.try_flat_join() .join()
.await .await
.into_iter()
.filter_map(Result::transpose)
.collect()
} }
/// Returns the first module in the result, or None. /// Returns the first module in the result, or None.
...@@ -3991,7 +3994,7 @@ mod tests { ...@@ -3991,7 +3994,7 @@ mod tests {
// primary_modules() yields each module exactly once, in first-seen order. // primary_modules() yields each module exactly once, in first-seen order.
let modules = result.primary_modules().await?; let modules = result.primary_modules().await?;
assert_eq!(modules, vec![m_a, m_b]); assert_eq!(modules.as_slice(), [m_a, m_b]);
Ok(Vc::cell(snapshot_primary(&result).await?)) Ok(Vc::cell(snapshot_primary(&result).await?))
} }
...@@ -4025,7 +4028,7 @@ mod tests { ...@@ -4025,7 +4028,7 @@ mod tests {
.await?; .await?;
assert_eq!(result.first_module().await?, Some(m)); assert_eq!(result.first_module().await?, Some(m));
assert_eq!(result.primary_modules().await?, vec![m]); assert_eq!(result.primary_modules().await?.as_slice(), [m]);
Ok(Vc::cell(snapshot_primary(&result).await?)) Ok(Vc::cell(snapshot_primary(&result).await?))
} }
tt.run_once(async move { tt.run_once(async move {
...@@ -4067,7 +4070,7 @@ mod tests { ...@@ -4067,7 +4070,7 @@ mod tests {
ModuleResolveResultItem::Module(m), ModuleResolveResultItem::Module(m),
); );
let result: ModuleResolveResult = builder.into(); let result: ModuleResolveResult = builder.into();
assert_eq!(result.primary_modules().await?, vec![m]); assert_eq!(result.primary_modules().await?.as_slice(), [m]);
Ok(Vc::cell(snapshot_primary(&result).await?)) Ok(Vc::cell(snapshot_primary(&result).await?))
} }
tt.run_once(async move { tt.run_once(async move {
...@@ -4104,7 +4107,7 @@ mod tests { ...@@ -4104,7 +4107,7 @@ mod tests {
let r2 = *ModuleResolveResult::module(m_b); let r2 = *ModuleResolveResult::module(m_b);
let merged = ModuleResolveResult::alternatives(vec![r1, r2]).await?; let merged = ModuleResolveResult::alternatives(vec![r1, r2]).await?;
assert_eq!(merged.primary_modules().await?, vec![m_a, m_b]); assert_eq!(merged.primary_modules().await?.as_slice(), [m_a, m_b]);
// Verify every Duplicate(i) is well-formed // Verify every Duplicate(i) is well-formed
for (i, (_, item)) in merged.primary.iter().enumerate() { for (i, (_, item)) in merged.primary.iter().enumerate() {
......
...@@ -262,9 +262,7 @@ impl EcmascriptChunkPlaceable for EcmascriptCollectModuleWithChunkGroup { ...@@ -262,9 +262,7 @@ impl EcmascriptChunkPlaceable for EcmascriptCollectModuleWithChunkGroup {
)) ))
}) })
.try_join() .try_join()
.await? .await?;
.into_iter()
.collect::<Vec<_>>();
let mut code = RopeBuilder::default(); let mut code = RopeBuilder::default();
......
...@@ -68,8 +68,8 @@ use tokio::sync::OnceCell; ...@@ -68,8 +68,8 @@ use tokio::sync::OnceCell;
use tracing::Instrument; use tracing::Instrument;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
FxIndexMap, FxIndexSet, NonLocalValue, PrettyPrintError, ReadRef, ResolvedVc, TaskInput, FxIndexMap, FxIndexSet, JoinIterExt, NonLocalValue, PrettyPrintError, ReadRef, ResolvedVc,
TryJoinIterExt, Upcast, ValueToString, Vc, trace::TraceRawVcs, turbofmt, TaskInput, TryJoinIterExt, Upcast, ValueToString, Vc, trace::TraceRawVcs, turbofmt,
}; };
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
...@@ -3117,11 +3117,11 @@ where ...@@ -3117,11 +3117,11 @@ where
) )
.to_resolved() .to_resolved()
}) })
.try_join() .join()
.await?; .await;
for resolved_dir_ref in resolved_dirs { for resolved_dir_ref in resolved_dirs {
analysis.add_reference(resolved_dir_ref); analysis.add_reference(resolved_dir_ref?);
} }
return Ok(()); return Ok(());
......
...@@ -3,7 +3,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; ...@@ -3,7 +3,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
use smallvec::SmallVec; use smallvec::SmallVec;
use tracing::Instrument; use tracing::Instrument;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ReadRef, ResolvedVc, TryJoinIterExt, ValueToString, Vc}; use turbo_tasks::{JoinIterExt, ReadRef, ResolvedVc, ValueToString, Vc};
use turbo_tasks_hash::hash_xxh3_hash64; use turbo_tasks_hash::hash_xxh3_hash64;
use turbopack_core::{ use turbopack_core::{
chunk::{ chunk::{
...@@ -55,10 +55,10 @@ pub async fn get_global_module_id_strategy( ...@@ -55,10 +55,10 @@ pub async fn get_global_module_id_strategy(
let hash = hash_xxh3_hash64(&ident_str); let hash = hash_xxh3_hash64(&ident_str);
Ok((ident, (ident_str, hash))) Ok((ident, (ident_str, hash)))
}) })
.try_join() .join()
.await? .await
.into_iter() .into_iter()
.collect::<FxHashMap<_, _>>(); .collect::<Result<FxHashMap<_, _>>>()?;
finalize_module_ids(&mut module_id_map); finalize_module_ids(&mut module_id_map);
......
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