Unverified Commit 9bbacd4d authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

refactor(turbopack): chunk chunk groups by key (#99750)

### What?

Chunking APIs take chunk group keys instead of chunk groups:

- `ChunkingContext::chunk_group` takes `chunk_groups:
SmallVec<[ChunkGroupKey; 1]>`.
- `evaluated_chunk_group`, `entry_chunk_group` and all
`ChunkingContextExt` helpers take `chunk_group: ChunkGroupKey`.
- The browser and Node.js chunking contexts resolve each key with the
new `ChunkGroupInfo::get_chunk_group(key)` and chunk the registered
group, using its entries for evaluation and bootstrapping.
- Callers pass keys: `ChunkGroupKey::{Entry, Async, Isolated, Shared}`,
or the `.key()` of a graph-derived merged group.

### Why?

Chunking already resolved every group by key and failed if the group
wasn't registered, so the entries a caller passed in were redundant at
best and inconsistent with the graph at worst. With key-only APIs,
`ChunkGroupInfo` is the single source of a group's contents, and callers
can no longer construct a group that disagrees with the module graph.

This is PR 4 of a six-PR stack, based on `canary` (#98733, #99686 and
#99749 are already merged):

1. #98823 — Pages Router dev client graph chaining
2. #99910 — regression test for Pages Router `_app` availability
(#99789)
3. #98734 — use graph-derived merged groups
4. **This PR** — chunking takes a `ChunkGroupKey`
5. #98685 — chunk-group availability bitmaps
6. #99050 — keyed chunk-group index lookups

### Verification

- The tree of this PR is identical to the previous #98734 head, which
passed:
- Workspace `cargo clippy --all-targets -D warnings`, per-layer `cargo
fmt` and workspace check
  - Turbopack snapshots: 132 passed, no snapshot changes
- Turbopack production and dev `404-page-router`,
`app-dir/actions/app-action` and `app-dir/initial-css-order`; production
`edge-pages-support`, `app-dir/css-order` and
`layout-segment-chunk-sharing`

<!-- NEXT_JS_LLM -->


<!-- fleet 4f67c6f7-bbe2-454b-9a17-822a60ef8f7e -->
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent 5f4692ea
...@@ -59,7 +59,7 @@ use turbopack_core::{ ...@@ -59,7 +59,7 @@ use turbopack_core::{
module_graph::{ module_graph::{
GraphEntries, ModuleGraph, SingleModuleGraph, VisitedModules, GraphEntries, ModuleGraph, SingleModuleGraph, VisitedModules,
binding_usage_info::compute_binding_usage_info, binding_usage_info::compute_binding_usage_info,
chunk_group_info::{ChunkGroup, ChunkGroupEntry, EntryHeuristics}, chunk_group_info::{ChunkGroupEntry, ChunkGroupKey, EntryHeuristics},
}, },
output::{OutputAsset, OutputAssets, OutputAssetsWithReferenced}, output::{OutputAsset, OutputAssets, OutputAssetsWithReferenced},
reference::all_assets_from_entries, reference::all_assets_from_entries,
...@@ -1916,7 +1916,7 @@ impl AppEndpoint { ...@@ -1916,7 +1916,7 @@ impl AppEndpoint {
NextRuntime::Edge => { NextRuntime::Edge => {
let chunk_group1 = chunking_context.chunk_group( let chunk_group1 = chunking_context.chunk_group(
server_action_manifest_loader.ident(), server_action_manifest_loader.ident(),
smallvec![ChunkGroup::Shared(ResolvedVc::upcast( smallvec![ChunkGroupKey::Shared(ResolvedVc::upcast(
server_action_manifest_loader, server_action_manifest_loader,
))], ))],
module_graph, module_graph,
...@@ -1925,7 +1925,7 @@ impl AppEndpoint { ...@@ -1925,7 +1925,7 @@ impl AppEndpoint {
let chunk_group2_assets = chunking_context.evaluated_chunk_group_assets( let chunk_group2_assets = chunking_context.evaluated_chunk_group_assets(
app_entry.rsc_entry.ident(), app_entry.rsc_entry.ident(),
ChunkGroup::Entry(vec![app_entry.rsc_entry]), ChunkGroupKey::Entry(vec![app_entry.rsc_entry]),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
chunk_group1.await?.availability_info, chunk_group1.await?.availability_info,
...@@ -1939,7 +1939,7 @@ impl AppEndpoint { ...@@ -1939,7 +1939,7 @@ impl AppEndpoint {
async { async {
let mut current_chunk_group = ChunkGroupResult::empty_resolved(); let mut current_chunk_group = ChunkGroupResult::empty_resolved();
let entry_chunk_group = ChunkGroup::Entry(vec![app_entry.rsc_entry]); let entry_chunk_group = ChunkGroupKey::Entry(vec![app_entry.rsc_entry]);
let client_references = client_references.await?; let client_references = client_references.await?;
...@@ -1970,7 +1970,7 @@ impl AppEndpoint { ...@@ -1970,7 +1970,7 @@ impl AppEndpoint {
None None
} else { } else {
let entry_index = *chunk_group_info let entry_index = *chunk_group_info
.get_index_of(entry_chunk_group.key()) .get_index_of(entry_chunk_group.clone())
.await?; .await?;
let merged = chunk_group_info let merged = chunk_group_info
.get_shared_merged_chunk_group( .get_shared_merged_chunk_group(
...@@ -1978,7 +1978,7 @@ impl AppEndpoint { ...@@ -1978,7 +1978,7 @@ impl AppEndpoint {
NEXT_SERVER_UTILITY_MERGE_TAG, NEXT_SERVER_UTILITY_MERGE_TAG,
) )
.await?; .await?;
merged.as_ref().map(|group| group.chunk_group.clone()) merged.as_ref().map(|group| group.chunk_group.key())
}; };
ensure!( ensure!(
...@@ -2033,7 +2033,9 @@ impl AppEndpoint { ...@@ -2033,7 +2033,9 @@ impl AppEndpoint {
async { async {
let chunk_group = chunking_context.chunk_group( let chunk_group = chunking_context.chunk_group(
server_component.ident(), server_component.ident(),
smallvec![ChunkGroup::Shared(ResolvedVc::upcast(server_component))], smallvec![ChunkGroupKey::Shared(ResolvedVc::upcast(
server_component
))],
module_graph, module_graph,
current_chunk_group.await?.availability_info, current_chunk_group.await?.availability_info,
); );
...@@ -2052,7 +2054,7 @@ impl AppEndpoint { ...@@ -2052,7 +2054,7 @@ impl AppEndpoint {
{ {
let chunk_group = chunking_context.chunk_group( let chunk_group = chunking_context.chunk_group(
server_action_manifest_loader.ident(), server_action_manifest_loader.ident(),
smallvec![ChunkGroup::Shared(ResolvedVc::upcast( smallvec![ChunkGroupKey::Shared(ResolvedVc::upcast(
server_action_manifest_loader, server_action_manifest_loader,
))], ))],
module_graph, module_graph,
......
...@@ -18,7 +18,7 @@ use turbopack_core::{ ...@@ -18,7 +18,7 @@ use turbopack_core::{
module::Module, module::Module,
module_graph::{ module_graph::{
GraphEntries, GraphEntries,
chunk_group_info::{ChunkGroup, ChunkGroupEntry, EntryHeuristics}, chunk_group_info::{ChunkGroupEntry, ChunkGroupKey, EntryHeuristics},
}, },
output::{OutputAsset, OutputAssets, OutputAssetsWithReferenced}, output::{OutputAsset, OutputAssets, OutputAssetsWithReferenced},
reference_type::{EntryReferenceSubType, ReferenceType}, reference_type::{EntryReferenceSubType, ReferenceType},
...@@ -107,7 +107,7 @@ impl InstrumentationEndpoint { ...@@ -107,7 +107,7 @@ impl InstrumentationEndpoint {
let edge_chunking_context = this.project.edge_chunking_context(false); let edge_chunking_context = this.project.edge_chunking_context(false);
Ok(edge_chunking_context.evaluated_chunk_group_assets( Ok(edge_chunking_context.evaluated_chunk_group_assets(
module.ident(), module.ident(),
ChunkGroup::Entry(vec![module]), ChunkGroupKey::Entry(vec![module]),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
AvailabilityInfo::root(), AvailabilityInfo::root(),
...@@ -132,7 +132,7 @@ impl InstrumentationEndpoint { ...@@ -132,7 +132,7 @@ impl InstrumentationEndpoint {
.node_root() .node_root()
.await? .await?
.join("server/instrumentation.js")?, .join("server/instrumentation.js")?,
ChunkGroup::Entry(vec![userland_module]), ChunkGroupKey::Entry(vec![userland_module]),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
......
...@@ -20,7 +20,7 @@ use turbopack_core::{ ...@@ -20,7 +20,7 @@ use turbopack_core::{
module::Module, module::Module,
module_graph::{ module_graph::{
GraphEntries, GraphEntries,
chunk_group_info::{ChunkGroup, ChunkGroupEntry, EntryHeuristics}, chunk_group_info::{ChunkGroupEntry, ChunkGroupKey, EntryHeuristics},
}, },
output::{OutputAsset, OutputAssets, OutputAssetsWithReferenced}, output::{OutputAsset, OutputAssets, OutputAssetsWithReferenced},
reference_type::{EntryReferenceSubType, ReferenceType}, reference_type::{EntryReferenceSubType, ReferenceType},
...@@ -118,7 +118,7 @@ impl MiddlewareEndpoint { ...@@ -118,7 +118,7 @@ impl MiddlewareEndpoint {
let edge_chunking_context = this.project.edge_chunking_context(false); let edge_chunking_context = this.project.edge_chunking_context(false);
let edge_chunk_grou = edge_chunking_context.evaluated_chunk_group_assets( let edge_chunk_grou = edge_chunking_context.evaluated_chunk_group_assets(
module.ident(), module.ident(),
ChunkGroup::Entry(vec![module]), ChunkGroupKey::Entry(vec![module]),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
AvailabilityInfo::root(), AvailabilityInfo::root(),
...@@ -144,7 +144,7 @@ impl MiddlewareEndpoint { ...@@ -144,7 +144,7 @@ impl MiddlewareEndpoint {
.node_root() .node_root()
.await? .await?
.join("server/middleware.js")?, .join("server/middleware.js")?,
ChunkGroup::Entry(vec![userland_module]), ChunkGroupKey::Entry(vec![userland_module]),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
......
...@@ -58,7 +58,7 @@ use turbopack_core::{ ...@@ -58,7 +58,7 @@ use turbopack_core::{
module_graph::{ module_graph::{
GraphEntries, ModuleGraph, SingleModuleGraph, VisitedModules, GraphEntries, ModuleGraph, SingleModuleGraph, VisitedModules,
binding_usage_info::compute_binding_usage_info, binding_usage_info::compute_binding_usage_info,
chunk_group_info::{ChunkGroup, ChunkGroupEntry, EntryHeuristics}, chunk_group_info::{ChunkGroupEntry, ChunkGroupKey, EntryHeuristics},
}, },
output::{OptionOutputAsset, OutputAsset, OutputAssets}, output::{OptionOutputAsset, OutputAsset, OutputAssets},
reference::all_assets_from_entries, reference::all_assets_from_entries,
...@@ -956,7 +956,7 @@ impl PageEndpoint { ...@@ -956,7 +956,7 @@ impl PageEndpoint {
}; };
let client_chunk_group = client_chunking_context.evaluated_chunk_group( let client_chunk_group = client_chunking_context.evaluated_chunk_group(
AssetIdent::from_path(this.page.await?.base_path.clone()).into_vc(), AssetIdent::from_path(this.page.await?.base_path.clone()).into_vc(),
ChunkGroup::Entry(evaluatable_assets), ChunkGroupKey::Entry(evaluatable_assets),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
availability_info, availability_info,
...@@ -1159,7 +1159,7 @@ impl PageEndpoint { ...@@ -1159,7 +1159,7 @@ impl PageEndpoint {
// Registered as an entry group by `layout_chunk_group_entry`. // Registered as an entry group by `layout_chunk_group_entry`.
let chunk_group = chunking_context.chunk_group( let chunk_group = chunking_context.chunk_group(
layout.ident(), layout.ident(),
smallvec![ChunkGroup::Entry(vec![layout])], smallvec![ChunkGroupKey::Entry(vec![layout])],
ssr_module_graph, ssr_module_graph,
current_chunk_group.await?.availability_info, current_chunk_group.await?.availability_info,
); );
...@@ -1179,7 +1179,7 @@ impl PageEndpoint { ...@@ -1179,7 +1179,7 @@ impl PageEndpoint {
if is_edge { if is_edge {
let chunk_assets = edge_chunking_context.evaluated_chunk_group_assets( let chunk_assets = edge_chunking_context.evaluated_chunk_group_assets(
ssr_module.ident(), ssr_module.ident(),
ChunkGroup::Entry(vec![ssr_module]), ChunkGroupKey::Entry(vec![ssr_module]),
ssr_module_graph, ssr_module_graph,
OutputAssets::empty(), OutputAssets::empty(),
current_chunk_group.await?.availability_info, current_chunk_group.await?.availability_info,
...@@ -1208,7 +1208,7 @@ impl PageEndpoint { ...@@ -1208,7 +1208,7 @@ impl PageEndpoint {
let ssr_entry_chunk = node_chunking_context let ssr_entry_chunk = node_chunking_context
.entry_chunk_group_asset( .entry_chunk_group_asset(
ssr_entry_chunk_path, ssr_entry_chunk_path,
ChunkGroup::Entry(vec![ssr_module]), ChunkGroupKey::Entry(vec![ssr_module]),
ssr_module_graph, ssr_module_graph,
current_chunk_group.primary_assets(), current_chunk_group.primary_assets(),
current_chunk_group.referenced_assets(), current_chunk_group.referenced_assets(),
...@@ -1790,7 +1790,7 @@ pub struct InternalSsrChunkModule { ...@@ -1790,7 +1790,7 @@ pub struct InternalSsrChunkModule {
/// A layout is an entry group of its own, like the standalone `/_document` and `/_app` /// A layout is an entry group of its own, like the standalone `/_document` and `/_app`
/// endpoints register their module, so the graph never has to choose between a shared and an /// endpoints register their module, so the graph never has to choose between a shared and an
/// entry group for the same module and `internal_ssr_chunk` can always chunk it as /// entry group for the same module and `internal_ssr_chunk` can always chunk it as
/// `ChunkGroup::Entry(vec![layout])`. Default heuristics keep a page's clusters off the layout /// `ChunkGroupKey::Entry(vec![layout])`. Default heuristics keep a page's clusters off the layout
/// groups shared between pages. /// groups shared between pages.
fn layout_chunk_group_entry(layout: ResolvedVc<Box<dyn Module>>) -> ChunkGroupEntry { fn layout_chunk_group_entry(layout: ResolvedVc<Box<dyn Module>>) -> ChunkGroupEntry {
ChunkGroupEntry::Entry { ChunkGroupEntry::Entry {
......
...@@ -49,7 +49,7 @@ use turbopack_core::{ ...@@ -49,7 +49,7 @@ use turbopack_core::{
module::{Module, Modules}, module::{Module, Modules},
module_graph::{ module_graph::{
GraphTraversalAction, ModuleGraph, ModuleGraphLayer, async_module_info::AsyncModulesInfo, GraphTraversalAction, ModuleGraph, ModuleGraphLayer, async_module_info::AsyncModulesInfo,
binding_usage_info::ModuleExportUsage, chunk_group_info::ChunkGroup, binding_usage_info::ModuleExportUsage, chunk_group_info::ChunkGroupKey,
}, },
output::{OutputAsset, OutputAssets, OutputAssetsReference}, output::{OutputAsset, OutputAssets, OutputAssetsReference},
reference_type::{EcmaScriptModulesReferenceSubType, ReferenceType}, reference_type::{EcmaScriptModulesReferenceSubType, ReferenceType},
...@@ -1240,7 +1240,7 @@ impl ChunkingContext for UseCacheContentHashChunkingContext { ...@@ -1240,7 +1240,7 @@ impl ChunkingContext for UseCacheContentHashChunkingContext {
async fn chunk_group( async fn chunk_group(
self: Vc<Self>, self: Vc<Self>,
_ident: Vc<AssetIdent>, _ident: Vc<AssetIdent>,
_chunk_groups: SmallVec<[ChunkGroup; 1]>, _chunk_groups: SmallVec<[ChunkGroupKey; 1]>,
_module_graph: ResolvedVc<ModuleGraph>, _module_graph: ResolvedVc<ModuleGraph>,
_availability_info: AvailabilityInfo, _availability_info: AvailabilityInfo,
) -> Result<Vc<ChunkGroupResult>> { ) -> Result<Vc<ChunkGroupResult>> {
...@@ -1251,7 +1251,7 @@ impl ChunkingContext for UseCacheContentHashChunkingContext { ...@@ -1251,7 +1251,7 @@ impl ChunkingContext for UseCacheContentHashChunkingContext {
async fn evaluated_chunk_group( async fn evaluated_chunk_group(
self: Vc<Self>, self: Vc<Self>,
_ident: Vc<AssetIdent>, _ident: Vc<AssetIdent>,
_chunk_group: ChunkGroup, _chunk_group: ChunkGroupKey,
_module_graph: ResolvedVc<ModuleGraph>, _module_graph: ResolvedVc<ModuleGraph>,
_extra_chunks: Vc<OutputAssets>, _extra_chunks: Vc<OutputAssets>,
_input_availability_info: AvailabilityInfo, _input_availability_info: AvailabilityInfo,
...@@ -1273,7 +1273,7 @@ impl ChunkingContext for UseCacheContentHashChunkingContext { ...@@ -1273,7 +1273,7 @@ impl ChunkingContext for UseCacheContentHashChunkingContext {
async fn entry_chunk_group( async fn entry_chunk_group(
self: Vc<Self>, self: Vc<Self>,
_path: FileSystemPath, _path: FileSystemPath,
_chunk_group: ChunkGroup, _chunk_group: ChunkGroupKey,
_module_graph: ResolvedVc<ModuleGraph>, _module_graph: ResolvedVc<ModuleGraph>,
_extra_chunks: Vc<OutputAssets>, _extra_chunks: Vc<OutputAssets>,
_extra_referenced_assets: Vc<OutputAssets>, _extra_referenced_assets: Vc<OutputAssets>,
......
...@@ -11,7 +11,7 @@ use turbopack_core::{ ...@@ -11,7 +11,7 @@ use turbopack_core::{
module::Module, module::Module,
module_graph::{ module_graph::{
ModuleGraph, SingleModuleGraph, ModuleGraph, SingleModuleGraph,
chunk_group_info::{ChunkGroup, ChunkGroupEntry, EntryHeuristics}, chunk_group_info::{ChunkGroupEntry, ChunkGroupKey, EntryHeuristics},
}, },
output::{OutputAsset, OutputAssets}, output::{OutputAsset, OutputAssets},
reference_type::{EntryReferenceSubType, ReferenceType}, reference_type::{EntryReferenceSubType, ReferenceType},
...@@ -126,7 +126,7 @@ async fn service_worker_chunk( ...@@ -126,7 +126,7 @@ async fn service_worker_chunk(
.join("static")? .join("static")?
.join("service-worker")? .join("service-worker")?
.join(&filename)?, .join(&filename)?,
ChunkGroup::Entry(vec![module]), ChunkGroupKey::Entry(vec![module]),
own_graph, own_graph,
/* extra_chunks */ OutputAssets::empty(), /* extra_chunks */ OutputAssets::empty(),
/* extra_referenced_chunks */ OutputAssets::empty(), /* extra_referenced_chunks */ OutputAssets::empty(),
......
...@@ -11,7 +11,7 @@ use turbopack_core::{ ...@@ -11,7 +11,7 @@ use turbopack_core::{
module::Module, module::Module,
module_graph::{ module_graph::{
ModuleGraph, ModuleGraph,
chunk_group_info::{ChunkGroup, ChunkGroupInfo}, chunk_group_info::{ChunkGroup, ChunkGroupInfo, ChunkGroupKey},
}, },
output::{OutputAsset, OutputAssets, OutputAssetsWithReferenced}, output::{OutputAsset, OutputAssets, OutputAssetsWithReferenced},
}; };
...@@ -80,13 +80,13 @@ struct ClientReferenceWithContext { ...@@ -80,13 +80,13 @@ struct ClientReferenceWithContext {
server_component: Option<ResolvedVc<Box<dyn Module>>>, server_component: Option<ResolvedVc<Box<dyn Module>>>,
} }
/// Returns the graph-derived isolated merged groups (tagged `merge_tag`) that chunk `references`, /// Returns the keys of the graph-derived isolated merged groups (tagged `merge_tag`) that chunk
/// with their entries as derived by the module graph. /// `references`. Chunking looks the groups up by key, so their entries come from the graph.
async fn derived_isolated_merged_groups( async fn derived_isolated_merged_groups(
chunk_group_info: Vc<ChunkGroupInfo>, chunk_group_info: Vc<ChunkGroupInfo>,
references: &[ClientReferenceWithContext], references: &[ClientReferenceWithContext],
merge_tag: &RcStr, merge_tag: &RcStr,
) -> Result<SmallVec<[ChunkGroup; 1]>> { ) -> Result<SmallVec<[ChunkGroupKey; 1]>> {
let mut groups = FxIndexMap::default(); let mut groups = FxIndexMap::default();
for &ClientReferenceWithContext { for &ClientReferenceWithContext {
...@@ -124,7 +124,7 @@ async fn derived_isolated_merged_groups( ...@@ -124,7 +124,7 @@ async fn derived_isolated_merged_groups(
found = true; found = true;
groups groups
.entry(group.index) .entry(group.index)
.or_insert_with(|| group.chunk_group.clone()); .or_insert_with(|| group.chunk_group.key());
} }
} }
if !found { if !found {
......
...@@ -6,7 +6,7 @@ use turbopack_core::{ ...@@ -6,7 +6,7 @@ use turbopack_core::{
ChunkGroupResult, ChunkingContext, EvaluatableAssets, availability_info::AvailabilityInfo, ChunkGroupResult, ChunkingContext, EvaluatableAssets, availability_info::AvailabilityInfo,
}, },
ident::AssetIdent, ident::AssetIdent,
module_graph::{ModuleGraph, chunk_group_info::ChunkGroup}, module_graph::{ModuleGraph, chunk_group_info::ChunkGroupKey},
output::OutputAssets, output::OutputAssets,
}; };
...@@ -26,7 +26,7 @@ pub async fn get_app_client_shared_chunk_group( ...@@ -26,7 +26,7 @@ pub async fn get_app_client_shared_chunk_group(
client_chunking_context client_chunking_context
.evaluated_chunk_group( .evaluated_chunk_group(
ident, ident,
ChunkGroup::Entry( ChunkGroupKey::Entry(
app_client_runtime_entries app_client_runtime_entries
.await? .await?
.iter() .iter()
......
...@@ -27,7 +27,7 @@ use turbopack_core::{ ...@@ -27,7 +27,7 @@ use turbopack_core::{
module_graph::{ module_graph::{
ModuleGraph, ModuleGraph,
binding_usage_info::{BindingUsageInfo, ModuleExportUsage}, binding_usage_info::{BindingUsageInfo, ModuleExportUsage},
chunk_group_info::ChunkGroup, chunk_group_info::{ChunkGroup, ChunkGroupKey},
}, },
output::{ExpandOutputAssetsInput, OutputAsset, OutputAssets, expand_output_assets}, output::{ExpandOutputAssetsInput, OutputAsset, OutputAssets, expand_output_assets},
}; };
...@@ -878,19 +878,24 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -878,19 +878,24 @@ impl ChunkingContext for BrowserChunkingContext {
async fn chunk_group( async fn chunk_group(
self: ResolvedVc<Self>, self: ResolvedVc<Self>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_groups: SmallVec<[ChunkGroup; 1]>, chunk_groups: SmallVec<[ChunkGroupKey; 1]>,
module_graph: ResolvedVc<ModuleGraph>, module_graph: ResolvedVc<ModuleGraph>,
availability_info: AvailabilityInfo, availability_info: AvailabilityInfo,
) -> Result<Vc<ChunkGroupResult>> { ) -> Result<Vc<ChunkGroupResult>> {
let span = tracing::info_span!("chunking", name = display(ident.to_string().await?)); let span = tracing::info_span!("chunking", name = display(ident.to_string().await?));
async move { async move {
let chunk_group_info = module_graph.chunk_group_info();
let mut groups = SmallVec::with_capacity(chunk_groups.len());
for key in chunk_groups {
groups.push(chunk_group_info.get_chunk_group(key).await?);
}
let input_availability_info = availability_info; let input_availability_info = availability_info;
let MakeChunkGroupResult { let MakeChunkGroupResult {
chunks, chunks,
references, references,
availability_info, availability_info,
} = make_chunk_group( } = make_chunk_group(
chunk_groups, groups,
module_graph, module_graph,
ResolvedVc::upcast(self), ResolvedVc::upcast(self),
input_availability_info, input_availability_info,
...@@ -922,7 +927,7 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -922,7 +927,7 @@ impl ChunkingContext for BrowserChunkingContext {
async fn evaluated_chunk_group( async fn evaluated_chunk_group(
self: ResolvedVc<Self>, self: ResolvedVc<Self>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: ResolvedVc<ModuleGraph>, module_graph: ResolvedVc<ModuleGraph>,
// Extra chunks to include in the HMR chunk list beyond what is reachable from this chunk // Extra chunks to include in the HMR chunk list beyond what is reachable from this chunk
// group. Used to cover RSC client reference chunks that are built separately. // group. Used to cover RSC client reference chunks that are built separately.
...@@ -936,6 +941,10 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -936,6 +941,10 @@ impl ChunkingContext for BrowserChunkingContext {
); );
async move { async move {
let this = self.await?; let this = self.await?;
let chunk_group = module_graph
.chunk_group_info()
.get_chunk_group(chunk_group)
.await?;
let MakeChunkGroupResult { let MakeChunkGroupResult {
chunks, chunks,
references, references,
...@@ -1106,7 +1115,7 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -1106,7 +1115,7 @@ impl ChunkingContext for BrowserChunkingContext {
async fn entry_chunk_group( async fn entry_chunk_group(
self: ResolvedVc<Self>, self: ResolvedVc<Self>,
path: FileSystemPath, path: FileSystemPath,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: ResolvedVc<ModuleGraph>, module_graph: ResolvedVc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -1126,6 +1135,10 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -1126,6 +1135,10 @@ impl ChunkingContext for BrowserChunkingContext {
chunking_type = "single-chunk entry", chunking_type = "single-chunk entry",
); );
async move { async move {
let chunk_group = module_graph
.chunk_group_info()
.get_chunk_group(chunk_group)
.await?;
let MakeChunkGroupResult { let MakeChunkGroupResult {
chunks, chunks,
references, references,
......
...@@ -36,7 +36,7 @@ use turbopack_core::{ ...@@ -36,7 +36,7 @@ use turbopack_core::{
module_graph::{ module_graph::{
GraphEntries, ModuleGraph, SingleModuleGraph, GraphEntries, ModuleGraph, SingleModuleGraph,
binding_usage_info::compute_binding_usage_info, binding_usage_info::compute_binding_usage_info,
chunk_group_info::{ChunkGroup, ChunkGroupEntry, EntryHeuristics}, chunk_group_info::{ChunkGroupEntry, ChunkGroupKey, EntryHeuristics},
}, },
output::{OutputAsset, OutputAssets, OutputAssetsWithReferenced}, output::{OutputAsset, OutputAssets, OutputAssetsWithReferenced},
reference_type::{EntryReferenceSubType, ReferenceType}, reference_type::{EntryReferenceSubType, ReferenceType},
...@@ -457,7 +457,7 @@ async fn build_internal( ...@@ -457,7 +457,7 @@ async fn build_internal(
.with_extension("entry.js"), .with_extension("entry.js"),
) )
.into_vc(), .into_vc(),
ChunkGroup::Entry( ChunkGroupKey::Entry(
[ResolvedVc::upcast(ecmascript)].into_iter().collect(), [ResolvedVc::upcast(ecmascript)].into_iter().collect(),
), ),
module_graph, module_graph,
...@@ -478,7 +478,9 @@ async fn build_internal( ...@@ -478,7 +478,9 @@ async fn build_internal(
.unwrap(), .unwrap(),
)? )?
.with_extension("entry.js"), .with_extension("entry.js"),
ChunkGroup::Entry(vec![ResolvedVc::upcast(ecmascript)]), ChunkGroupKey::Entry(vec![ResolvedVc::upcast(
ecmascript,
)]),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
......
...@@ -19,7 +19,7 @@ use crate::{ ...@@ -19,7 +19,7 @@ use crate::{
json::RcJsonRawValue, json::RcJsonRawValue,
module::Module, module::Module,
module_graph::{ module_graph::{
ModuleGraph, binding_usage_info::ModuleExportUsage, chunk_group_info::ChunkGroup, ModuleGraph, binding_usage_info::ModuleExportUsage, chunk_group_info::ChunkGroupKey,
module_batches::BatchingConfig, style_groups::StyleGroupsAlgorithm, module_batches::BatchingConfig, style_groups::StyleGroupsAlgorithm,
}, },
output::{ output::{
...@@ -475,15 +475,19 @@ pub trait ChunkingContext { ...@@ -475,15 +475,19 @@ pub trait ChunkingContext {
chunk_item: ResolvedVc<Box<dyn ChunkItem>>, chunk_item: ResolvedVc<Box<dyn ChunkItem>>,
) -> Vc<Box<dyn OutputAsset>>; ) -> Vc<Box<dyn OutputAsset>>;
/// Chunks `chunk_groups` together as one chunk group, in a single task. /// Chunks the chunk groups identified by `chunk_groups` together as one chunk group, in a
/// single task.
/// ///
/// The groups must be registered in `module_graph`'s
/// [`ChunkGroupInfo`](crate::module_graph::chunk_group_info::ChunkGroupInfo); their contents
/// (e.g. the entries of a merged group) are looked up there, so callers only name the groups.
/// The modules of all groups are collected once each and chunked together, and the resulting /// The modules of all groups are collected once each and chunked together, and the resulting
/// availability includes every group. `chunk_groups` must not be empty. /// availability includes every group. `chunk_groups` must not be empty.
#[turbo_tasks::function] #[turbo_tasks::function]
fn chunk_group( fn chunk_group(
self: Vc<Self>, self: Vc<Self>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_groups: SmallVec<[ChunkGroup; 1]>, chunk_groups: SmallVec<[ChunkGroupKey; 1]>,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
availability_info: AvailabilityInfo, availability_info: AvailabilityInfo,
) -> Vc<ChunkGroupResult>; ) -> Vc<ChunkGroupResult>;
...@@ -500,7 +504,7 @@ pub trait ChunkingContext { ...@@ -500,7 +504,7 @@ pub trait ChunkingContext {
fn evaluated_chunk_group( fn evaluated_chunk_group(
self: Vc<Self>, self: Vc<Self>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
availability_info: AvailabilityInfo, availability_info: AvailabilityInfo,
...@@ -529,7 +533,7 @@ pub trait ChunkingContext { ...@@ -529,7 +533,7 @@ pub trait ChunkingContext {
fn entry_chunk_group( fn entry_chunk_group(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -569,7 +573,7 @@ pub trait ChunkingContextExt { ...@@ -569,7 +573,7 @@ pub trait ChunkingContextExt {
fn root_chunk_group( fn root_chunk_group(
self: Vc<Self>, self: Vc<Self>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
) -> Vc<ChunkGroupResult> ) -> Vc<ChunkGroupResult>
where where
...@@ -578,7 +582,7 @@ pub trait ChunkingContextExt { ...@@ -578,7 +582,7 @@ pub trait ChunkingContextExt {
fn root_chunk_group_assets( fn root_chunk_group_assets(
self: Vc<Self>, self: Vc<Self>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
) -> Vc<OutputAssetsWithReferenced> ) -> Vc<OutputAssetsWithReferenced>
where where
...@@ -587,7 +591,7 @@ pub trait ChunkingContextExt { ...@@ -587,7 +591,7 @@ pub trait ChunkingContextExt {
fn evaluated_chunk_group_assets( fn evaluated_chunk_group_assets(
self: Vc<Self>, self: Vc<Self>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
availability_info: AvailabilityInfo, availability_info: AvailabilityInfo,
...@@ -598,7 +602,7 @@ pub trait ChunkingContextExt { ...@@ -598,7 +602,7 @@ pub trait ChunkingContextExt {
fn entry_chunk_group_asset( fn entry_chunk_group_asset(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -610,7 +614,7 @@ pub trait ChunkingContextExt { ...@@ -610,7 +614,7 @@ pub trait ChunkingContextExt {
fn root_entry_chunk_group( fn root_entry_chunk_group(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -621,7 +625,7 @@ pub trait ChunkingContextExt { ...@@ -621,7 +625,7 @@ pub trait ChunkingContextExt {
fn root_entry_chunk_group_asset( fn root_entry_chunk_group_asset(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -632,7 +636,7 @@ pub trait ChunkingContextExt { ...@@ -632,7 +636,7 @@ pub trait ChunkingContextExt {
fn chunk_group_assets( fn chunk_group_assets(
self: Vc<Self>, self: Vc<Self>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
availability_info: AvailabilityInfo, availability_info: AvailabilityInfo,
) -> Vc<OutputAssetsWithReferenced> ) -> Vc<OutputAssetsWithReferenced>
...@@ -651,7 +655,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte ...@@ -651,7 +655,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn root_chunk_group( fn root_chunk_group(
self: Vc<Self>, self: Vc<Self>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
) -> Vc<ChunkGroupResult> { ) -> Vc<ChunkGroupResult> {
self.chunk_group( self.chunk_group(
...@@ -665,7 +669,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte ...@@ -665,7 +669,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn root_chunk_group_assets( fn root_chunk_group_assets(
self: Vc<Self>, self: Vc<Self>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
) -> Vc<OutputAssetsWithReferenced> { ) -> Vc<OutputAssetsWithReferenced> {
root_chunk_group_assets( root_chunk_group_assets(
...@@ -679,7 +683,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte ...@@ -679,7 +683,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn evaluated_chunk_group_assets( fn evaluated_chunk_group_assets(
self: Vc<Self>, self: Vc<Self>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
availability_info: AvailabilityInfo, availability_info: AvailabilityInfo,
...@@ -697,7 +701,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte ...@@ -697,7 +701,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn entry_chunk_group_asset( fn entry_chunk_group_asset(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -717,7 +721,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte ...@@ -717,7 +721,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn root_entry_chunk_group( fn root_entry_chunk_group(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -735,7 +739,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte ...@@ -735,7 +739,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn root_entry_chunk_group_asset( fn root_entry_chunk_group_asset(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -754,7 +758,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte ...@@ -754,7 +758,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn chunk_group_assets( fn chunk_group_assets(
self: Vc<Self>, self: Vc<Self>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
availability_info: AvailabilityInfo, availability_info: AvailabilityInfo,
) -> Vc<OutputAssetsWithReferenced> { ) -> Vc<OutputAssetsWithReferenced> {
...@@ -817,7 +821,7 @@ async fn relative_path_from_chunk_root_to_project_root( ...@@ -817,7 +821,7 @@ async fn relative_path_from_chunk_root_to_project_root(
fn root_chunk_group_assets( fn root_chunk_group_assets(
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
) -> Vc<OutputAssetsWithReferenced> { ) -> Vc<OutputAssetsWithReferenced> {
chunking_context chunking_context
...@@ -829,7 +833,7 @@ fn root_chunk_group_assets( ...@@ -829,7 +833,7 @@ fn root_chunk_group_assets(
fn evaluated_chunk_group_assets( fn evaluated_chunk_group_assets(
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
availability_info: AvailabilityInfo, availability_info: AvailabilityInfo,
...@@ -849,7 +853,7 @@ fn evaluated_chunk_group_assets( ...@@ -849,7 +853,7 @@ fn evaluated_chunk_group_assets(
async fn entry_chunk_group_asset( async fn entry_chunk_group_asset(
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
path: FileSystemPath, path: FileSystemPath,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -872,7 +876,7 @@ async fn entry_chunk_group_asset( ...@@ -872,7 +876,7 @@ async fn entry_chunk_group_asset(
fn chunk_group_assets( fn chunk_group_assets(
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
availability_info: AvailabilityInfo, availability_info: AvailabilityInfo,
) -> Vc<OutputAssetsWithReferenced> { ) -> Vc<OutputAssetsWithReferenced> {
......
...@@ -204,6 +204,17 @@ impl ChunkGroupInfo { ...@@ -204,6 +204,17 @@ impl ChunkGroupInfo {
} }
} }
impl ChunkGroupInfo {
/// Returns the registered chunk group identified by `key`.
///
/// Chunking takes a [`ChunkGroupKey`] and resolves the group here, so a group's contents (e.g.
/// the entries of a merged group) always come from the module graph rather than the caller.
pub async fn get_chunk_group(self: Vc<Self>, key: ChunkGroupKey) -> Result<ChunkGroup> {
let index = *self.get_index_of(key).await?;
Ok(self.await?.chunk_groups[index].clone())
}
}
/// Per-entry chunking heuristics. /// Per-entry chunking heuristics.
#[turbo_tasks::task_input] #[turbo_tasks::task_input]
#[derive(Debug, Default, Clone, Hash, PartialEq, Eq, Encode, Decode)] #[derive(Debug, Default, Clone, Hash, PartialEq, Eq, Encode, Decode)]
......
...@@ -12,7 +12,7 @@ use turbopack_core::{ ...@@ -12,7 +12,7 @@ use turbopack_core::{
availability_info::AvailabilityInfo, availability_info::AvailabilityInfo,
}, },
module::Module, module::Module,
module_graph::{ModuleGraph, chunk_group_info::ChunkGroup}, module_graph::{ModuleGraph, chunk_group_info::ChunkGroupKey},
output::{OutputAsset, OutputAssets, OutputAssetsReference, OutputAssetsWithReferenced}, output::{OutputAsset, OutputAssets, OutputAssetsReference, OutputAssetsWithReferenced},
version::{Version, VersionedContent}, version::{Version, VersionedContent},
}; };
...@@ -152,7 +152,7 @@ impl DevHtmlAsset { ...@@ -152,7 +152,7 @@ impl DevHtmlAsset {
chunking_context chunking_context
.evaluated_chunk_group_assets( .evaluated_chunk_group_assets(
chunkable_module.ident(), chunkable_module.ident(),
ChunkGroup::Entry( ChunkGroupKey::Entry(
runtime_entries runtime_entries
.await? .await?
.iter() .iter()
...@@ -168,7 +168,7 @@ impl DevHtmlAsset { ...@@ -168,7 +168,7 @@ impl DevHtmlAsset {
chunking_context chunking_context
.root_chunk_group_assets( .root_chunk_group_assets(
chunkable_module.ident(), chunkable_module.ident(),
ChunkGroup::Entry(vec![ResolvedVc::upcast(chunkable_module)]), ChunkGroupKey::Entry(vec![ResolvedVc::upcast(chunkable_module)]),
*module_graph, *module_graph,
) )
.await? .await?
......
...@@ -11,7 +11,7 @@ use turbopack_core::{ ...@@ -11,7 +11,7 @@ use turbopack_core::{
ident::AssetIdent, ident::AssetIdent,
module::{Module, ModuleSideEffects}, module::{Module, ModuleSideEffects},
module_graph::{ module_graph::{
ModuleGraph, chunk_group_info::ChunkGroup, module_batch::ChunkableModuleOrBatch, ModuleGraph, chunk_group_info::ChunkGroupKey, module_batch::ChunkableModuleOrBatch,
}, },
output::OutputAssetsWithReferenced, output::OutputAssetsWithReferenced,
reference::ModuleReferences, reference::ModuleReferences,
...@@ -85,7 +85,7 @@ impl AsyncLoaderModule { ...@@ -85,7 +85,7 @@ impl AsyncLoaderModule {
} }
Ok(self.chunking_context.chunk_group_assets( Ok(self.chunking_context.chunk_group_assets(
self.inner.ident(), self.inner.ident(),
ChunkGroup::Async(ResolvedVc::upcast(self.inner)), ChunkGroupKey::Async(ResolvedVc::upcast(self.inner)),
module_graph, module_graph,
self.availability_info, self.availability_info,
)) ))
......
...@@ -10,7 +10,7 @@ use turbopack_core::{ ...@@ -10,7 +10,7 @@ use turbopack_core::{
ident::AssetIdent, ident::AssetIdent,
module::{Module, ModuleSideEffects}, module::{Module, ModuleSideEffects},
module_graph::{ module_graph::{
ModuleGraph, chunk_group_info::ChunkGroup, module_batch::ChunkableModuleOrBatch, ModuleGraph, chunk_group_info::ChunkGroupKey, module_batch::ChunkableModuleOrBatch,
}, },
output::{OutputAssets, OutputAssetsWithReferenced}, output::{OutputAssets, OutputAssetsWithReferenced},
}; };
...@@ -65,7 +65,7 @@ impl ManifestAsyncModule { ...@@ -65,7 +65,7 @@ impl ManifestAsyncModule {
pub(super) fn chunk_group(&self) -> Vc<OutputAssetsWithReferenced> { pub(super) fn chunk_group(&self) -> Vc<OutputAssetsWithReferenced> {
self.chunking_context.chunk_group_assets( self.chunking_context.chunk_group_assets(
self.inner.ident(), self.inner.ident(),
ChunkGroup::Async(ResolvedVc::upcast(self.inner)), ChunkGroupKey::Async(ResolvedVc::upcast(self.inner)),
*self.module_graph, *self.module_graph,
self.availability_info, self.availability_info,
) )
......
...@@ -13,7 +13,7 @@ use turbopack_core::{ ...@@ -13,7 +13,7 @@ use turbopack_core::{
file_source::FileSource, file_source::FileSource,
ident::AssetIdent, ident::AssetIdent,
module::{Module, ModuleSideEffects}, module::{Module, ModuleSideEffects},
module_graph::{ModuleGraph, chunk_group_info::ChunkGroup}, module_graph::{ModuleGraph, chunk_group_info::ChunkGroupKey},
output::{OutputAsset, OutputAssets, OutputAssetsWithReferenced}, output::{OutputAsset, OutputAssets, OutputAssetsWithReferenced},
reference::{ModuleReference, ModuleReferences, SingleChunkableModuleReference}, reference::{ModuleReference, ModuleReferences, SingleChunkableModuleReference},
reference_type::{EcmaScriptModulesReferenceSubType, ReferenceType}, reference_type::{EcmaScriptModulesReferenceSubType, ReferenceType},
...@@ -75,7 +75,7 @@ impl WorkerLoaderModule { ...@@ -75,7 +75,7 @@ impl WorkerLoaderModule {
.into_vc(); .into_vc();
chunking_context.evaluated_chunk_group_assets( chunking_context.evaluated_chunk_group_assets(
ident, ident,
ChunkGroup::Isolated(ResolvedVc::upcast(this.inner)), ChunkGroupKey::Isolated(ResolvedVc::upcast(this.inner)),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
AvailabilityInfo::root(), AvailabilityInfo::root(),
...@@ -98,7 +98,7 @@ impl WorkerLoaderModule { ...@@ -98,7 +98,7 @@ impl WorkerLoaderModule {
let entry_result = chunking_context let entry_result = chunking_context
.root_entry_chunk_group( .root_entry_chunk_group(
worker_path, worker_path,
ChunkGroup::Isolated(ResolvedVc::upcast(evaluatable)), ChunkGroupKey::Isolated(ResolvedVc::upcast(evaluatable)),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
......
...@@ -26,7 +26,7 @@ use turbopack_core::{ ...@@ -26,7 +26,7 @@ use turbopack_core::{
module::Module, module::Module,
module_graph::{ module_graph::{
GraphEntries, ModuleGraph, GraphEntries, ModuleGraph,
chunk_group_info::{ChunkGroup, ChunkGroupEntry, EntryHeuristics}, chunk_group_info::{ChunkGroupEntry, ChunkGroupKey, EntryHeuristics},
}, },
output::{OutputAsset, OutputAssets}, output::{OutputAsset, OutputAssets},
reference_type::{InnerAssets, ReferenceType}, reference_type::{InnerAssets, ReferenceType},
...@@ -162,7 +162,7 @@ async fn emit_evaluate_pool_assets_operation( ...@@ -162,7 +162,7 @@ async fn emit_evaluate_pool_assets_operation(
let bootstrap = chunking_context.root_entry_chunk_group_asset( let bootstrap = chunking_context.root_entry_chunk_group_asset(
entrypoint.clone(), entrypoint.clone(),
ChunkGroup::Entry(entries.iter().cloned().map(ResolvedVc::upcast).collect()), ChunkGroupKey::Entry(entries.iter().cloned().map(ResolvedVc::upcast).collect()),
*module_graph, *module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
......
...@@ -34,7 +34,7 @@ use turbopack_core::{ ...@@ -34,7 +34,7 @@ use turbopack_core::{
module::Module, module::Module,
module_graph::{ module_graph::{
ModuleGraph, SingleModuleGraph, ModuleGraph, SingleModuleGraph,
chunk_group_info::{ChunkGroup, ChunkGroupEntry, EntryHeuristics}, chunk_group_info::{ChunkGroupEntry, ChunkGroupKey, EntryHeuristics},
}, },
output::{ExpandOutputAssetsInput, OutputAsset, OutputAssets, expand_output_assets}, output::{ExpandOutputAssetsInput, OutputAsset, OutputAssets, expand_output_assets},
reference_type::{EcmaScriptModulesReferenceSubType, InnerAssets, ReferenceType}, reference_type::{EcmaScriptModulesReferenceSubType, InnerAssets, ReferenceType},
...@@ -996,7 +996,7 @@ impl EvaluateContext for WebpackLoaderContext { ...@@ -996,7 +996,7 @@ impl EvaluateContext for WebpackLoaderContext {
let bootstrap = self.chunking_context.root_entry_chunk_group_asset( let bootstrap = self.chunking_context.root_entry_chunk_group_asset(
entry_path.clone(), entry_path.clone(),
ChunkGroup::Entry(vec![ResolvedVc::upcast(evaluatable)]), ChunkGroupKey::Entry(vec![ResolvedVc::upcast(evaluatable)]),
*import_module_graph, *import_module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
......
...@@ -25,7 +25,7 @@ use turbopack_core::{ ...@@ -25,7 +25,7 @@ use turbopack_core::{
module_graph::{ module_graph::{
ModuleGraph, ModuleGraph,
binding_usage_info::{BindingUsageInfo, ModuleExportUsage}, binding_usage_info::{BindingUsageInfo, ModuleExportUsage},
chunk_group_info::ChunkGroup, chunk_group_info::ChunkGroupKey,
}, },
output::{OutputAsset, OutputAssets}, output::{OutputAsset, OutputAssets},
}; };
...@@ -566,18 +566,23 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -566,18 +566,23 @@ impl ChunkingContext for NodeJsChunkingContext {
async fn chunk_group( async fn chunk_group(
self: ResolvedVc<Self>, self: ResolvedVc<Self>,
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
chunk_groups: SmallVec<[ChunkGroup; 1]>, chunk_groups: SmallVec<[ChunkGroupKey; 1]>,
module_graph: ResolvedVc<ModuleGraph>, module_graph: ResolvedVc<ModuleGraph>,
availability_info: AvailabilityInfo, availability_info: AvailabilityInfo,
) -> Result<Vc<ChunkGroupResult>> { ) -> Result<Vc<ChunkGroupResult>> {
let span = tracing::info_span!("chunking", name = display(ident.to_string().await?)); let span = tracing::info_span!("chunking", name = display(ident.to_string().await?));
async move { async move {
let chunk_group_info = module_graph.chunk_group_info();
let mut groups = SmallVec::with_capacity(chunk_groups.len());
for key in chunk_groups {
groups.push(chunk_group_info.get_chunk_group(key).await?);
}
let MakeChunkGroupResult { let MakeChunkGroupResult {
chunks, chunks,
references, references,
availability_info, availability_info,
} = make_chunk_group( } = make_chunk_group(
chunk_groups, groups,
module_graph, module_graph,
ResolvedVc::upcast(self), ResolvedVc::upcast(self),
availability_info, availability_info,
...@@ -609,7 +614,7 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -609,7 +614,7 @@ impl ChunkingContext for NodeJsChunkingContext {
pub async fn entry_chunk_group( pub async fn entry_chunk_group(
self: ResolvedVc<Self>, self: ResolvedVc<Self>,
path: FileSystemPath, path: FileSystemPath,
chunk_group: ChunkGroup, chunk_group: ChunkGroupKey,
module_graph: ResolvedVc<ModuleGraph>, module_graph: ResolvedVc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -621,6 +626,10 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -621,6 +626,10 @@ impl ChunkingContext for NodeJsChunkingContext {
chunking_type = "entry", chunking_type = "entry",
); );
async move { async move {
let chunk_group = module_graph
.chunk_group_info()
.get_chunk_group(chunk_group)
.await?;
let MakeChunkGroupResult { let MakeChunkGroupResult {
chunks, chunks,
references, references,
...@@ -693,7 +702,7 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -693,7 +702,7 @@ impl ChunkingContext for NodeJsChunkingContext {
fn evaluated_chunk_group( fn evaluated_chunk_group(
self: Vc<Self>, self: Vc<Self>,
_ident: Vc<AssetIdent>, _ident: Vc<AssetIdent>,
_chunk_group: ChunkGroup, _chunk_group: ChunkGroupKey,
_module_graph: Vc<ModuleGraph>, _module_graph: Vc<ModuleGraph>,
_extra_chunks: Vc<OutputAssets>, _extra_chunks: Vc<OutputAssets>,
_availability_info: AvailabilityInfo, _availability_info: AvailabilityInfo,
......
...@@ -49,7 +49,7 @@ use turbopack_core::{ ...@@ -49,7 +49,7 @@ use turbopack_core::{
module_graph::{ module_graph::{
GraphEntries, ModuleGraph, SingleModuleGraph, GraphEntries, ModuleGraph, SingleModuleGraph,
binding_usage_info::compute_binding_usage_info, binding_usage_info::compute_binding_usage_info,
chunk_group_info::{ChunkGroup, ChunkGroupEntry, EntryHeuristics}, chunk_group_info::{ChunkGroupEntry, ChunkGroupKey, EntryHeuristics},
}, },
output::{OutputAsset, OutputAssets, OutputAssetsReference, OutputAssetsWithReferenced}, output::{OutputAsset, OutputAssets, OutputAssetsReference, OutputAssetsWithReferenced},
reference_type::{EntryReferenceSubType, ReferenceType, ReferenceTypeCondition}, reference_type::{EntryReferenceSubType, ReferenceType, ReferenceTypeCondition},
...@@ -641,7 +641,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -641,7 +641,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
chunk_root_path chunk_root_path
.join(entry_module.ident().await?.path.file_stem().unwrap())? .join(entry_module.ident().await?.path.file_stem().unwrap())?
.with_extension("entry.js"), .with_extension("entry.js"),
ChunkGroup::Entry(entry_modules), ChunkGroupKey::Entry(entry_modules),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
...@@ -656,7 +656,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -656,7 +656,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
.cell(), .cell(),
Runtime::Browser => chunking_context.evaluated_chunk_group_assets( Runtime::Browser => chunking_context.evaluated_chunk_group_assets(
entry_module.ident(), entry_module.ident(),
ChunkGroup::Entry(entry_modules.into_iter().collect()), ChunkGroupKey::Entry(entry_modules.into_iter().collect()),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
AvailabilityInfo::root(), AvailabilityInfo::root(),
...@@ -670,7 +670,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -670,7 +670,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
chunk_root_path chunk_root_path
.join(entry_module.ident().await?.path.file_stem().unwrap())? .join(entry_module.ident().await?.path.file_stem().unwrap())?
.with_extension("entry.js"), .with_extension("entry.js"),
ChunkGroup::Entry(entry_modules), ChunkGroupKey::Entry(entry_modules),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
......
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