Skip to content

Commit

Permalink
ChunkGroup TaskInput
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Feb 20, 2025
1 parent 96f0093 commit 08db4a6
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 56 deletions.
6 changes: 2 additions & 4 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1681,8 +1681,7 @@ impl AppEndpoint {
ChunkGroup::Entry {
entries: server_utils,
ty: ChunkGroupType::Entry,
}
.cell(),
},
module_graph,
Value::new(current_availability_info),
)
Expand Down Expand Up @@ -1723,8 +1722,7 @@ impl AppEndpoint {
server_component.await?.module,
)],
ty: ChunkGroupType::Entry,
}
.cell(),
},
module_graph,
Value::new(current_availability_info),
)
Expand Down
30 changes: 15 additions & 15 deletions crates/next-core/src/next_app/app_client_references_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub async fn get_app_client_references_chunks(
let ecmascript_client_reference_ref =
ecmascript_client_reference.await?;

Some(*ResolvedVc::upcast(
Some(ResolvedVc::upcast(
ecmascript_client_reference_ref.ssr_module,
))
}
Expand All @@ -218,11 +218,11 @@ pub async fn get_app_client_references_chunks(
ssr_chunking_context.chunk_group(
base_ident.with_modifier(ssr_modules_modifier()),
// TODO use correct parameters here, and sort the modules?
ChunkGroup::isolated_merged_interned(
0,
ECMASCRIPT_CLIENT_REFERENCE_MERGE_TAG_SSR.clone(),
ssr_modules,
),
ChunkGroup::IsolatedMerged {
parent: 0,
merge_tag: ECMASCRIPT_CLIENT_REFERENCE_MERGE_TAG_SSR.clone(),
entries: ssr_modules,
},
module_graph,
Value::new(current_ssr_availability_info),
)
Expand All @@ -237,11 +237,11 @@ pub async fn get_app_client_references_chunks(
Ok(match client_reference_ty {
ClientReferenceType::EcmascriptClientReference(
ecmascript_client_reference,
) => *ResolvedVc::upcast(
ecmascript_client_reference.await?.client_module,
),
) => {
ResolvedVc::upcast(ecmascript_client_reference.await?.client_module)
}
ClientReferenceType::CssClientReference(css_client_reference) => {
*ResolvedVc::upcast(*css_client_reference)
ResolvedVc::upcast(*css_client_reference)
}
})
})
Expand All @@ -257,11 +257,11 @@ pub async fn get_app_client_references_chunks(
Some(client_chunking_context.chunk_group(
base_ident.with_modifier(client_modules_modifier()),
// TODO use correct parameters here, and sort the modules?
ChunkGroup::isolated_merged_interned(
0,
ECMASCRIPT_CLIENT_REFERENCE_MERGE_TAG_CLIENT.clone(),
client_modules,
),
ChunkGroup::IsolatedMerged {
parent: 0,
merge_tag: ECMASCRIPT_CLIENT_REFERENCE_MERGE_TAG_CLIENT.clone(),
entries: client_modules,
},
module_graph,
Value::new(current_client_availability_info),
))
Expand Down
3 changes: 1 addition & 2 deletions turbopack/crates/turbopack-browser/src/chunking_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,13 @@ impl ChunkingContext for BrowserChunkingContext {
async fn chunk_group(
self: ResolvedVc<Self>,
ident: Vc<AssetIdent>,
chunk_group: Vc<ChunkGroup>,
chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>,
availability_info: Value<AvailabilityInfo>,
) -> Result<Vc<ChunkGroupResult>> {
let span = tracing::info_span!("chunking", ident = ident.to_string().await?.to_string());
async move {
let this = self.await?;
let chunk_group = chunk_group.await?;
let modules = chunk_group.entries();
let input_availability_info = availability_info.into_value();
let MakeChunkGroupResult {
Expand Down
18 changes: 9 additions & 9 deletions turbopack/crates/turbopack-core/src/chunk/chunking_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub trait ChunkingContext {
fn chunk_group(
self: Vc<Self>,
ident: Vc<AssetIdent>,
chunk_group: Vc<ChunkGroup>,
chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>,
availability_info: Value<AvailabilityInfo>,
) -> Vc<ChunkGroupResult>;
Expand Down Expand Up @@ -228,7 +228,7 @@ pub trait ChunkingContextExt {
fn root_chunk_group(
self: Vc<Self>,
ident: Vc<AssetIdent>,
chunk_group: Vc<ChunkGroup>,
chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>,
) -> Vc<ChunkGroupResult>
where
Expand All @@ -237,7 +237,7 @@ pub trait ChunkingContextExt {
fn root_chunk_group_assets(
self: Vc<Self>,
ident: Vc<AssetIdent>,
chunk_group: Vc<ChunkGroup>,
chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>,
) -> Vc<OutputAssets>
where
Expand Down Expand Up @@ -290,7 +290,7 @@ pub trait ChunkingContextExt {
fn chunk_group_assets(
self: Vc<Self>,
ident: Vc<AssetIdent>,
chunk_group: Vc<ChunkGroup>,
chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>,
availability_info: Value<AvailabilityInfo>,
) -> Vc<OutputAssets>
Expand All @@ -302,7 +302,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn root_chunk_group(
self: Vc<Self>,
ident: Vc<AssetIdent>,
chunk_group: Vc<ChunkGroup>,
chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>,
) -> Vc<ChunkGroupResult> {
self.chunk_group(
Expand All @@ -316,7 +316,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn root_chunk_group_assets(
self: Vc<Self>,
ident: Vc<AssetIdent>,
chunk_group: Vc<ChunkGroup>,
chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>,
) -> Vc<OutputAssets> {
root_chunk_group_assets(Vc::upcast(self), ident, chunk_group, module_graph)
Expand Down Expand Up @@ -398,7 +398,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn chunk_group_assets(
self: Vc<Self>,
ident: Vc<AssetIdent>,
chunk_group: Vc<ChunkGroup>,
chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>,
availability_info: Value<AvailabilityInfo>,
) -> Vc<OutputAssets> {
Expand All @@ -416,7 +416,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
async fn root_chunk_group_assets(
chunking_context: Vc<Box<dyn ChunkingContext>>,
ident: Vc<AssetIdent>,
chunk_group: Vc<ChunkGroup>,
chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>,
) -> Result<Vc<OutputAssets>> {
Ok(*chunking_context
Expand Down Expand Up @@ -466,7 +466,7 @@ async fn entry_chunk_group_asset(
async fn chunk_group_assets(
chunking_context: Vc<Box<dyn ChunkingContext>>,
ident: Vc<AssetIdent>,
chunk_group: Vc<ChunkGroup>,
chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>,
availability_info: Value<AvailabilityInfo>,
) -> Result<Vc<OutputAssets>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ pub struct ChunkGroupInfo {
pub chunk_groups: Vec<ChunkGroup>,
}

#[turbo_tasks::value(shared)]
#[derive(Debug, Clone, Hash)]
#[derive(Debug, Clone, Hash, TaskInput, PartialEq, Eq, Serialize, Deserialize)]
pub enum ChunkGroup {
/// e.g. a page
Entry {
Expand All @@ -119,23 +118,6 @@ pub enum ChunkGroup {
},
}

#[turbo_tasks::value_impl]
impl ChunkGroup {
#[turbo_tasks::function]
pub fn isolated_merged_interned(
parent: usize,
merge_tag: RcStr,
entries: Vec<ResolvedVc<Box<dyn Module>>>,
) -> Vc<Self> {
ChunkGroup::IsolatedMerged {
parent,
merge_tag,
entries,
}
.cell()
}
}

impl ChunkGroup {
pub fn entries(&self) -> impl Iterator<Item = ResolvedVc<Box<dyn Module>>> + '_ {
match self {
Expand Down
3 changes: 1 addition & 2 deletions turbopack/crates/turbopack-dev-server/src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ impl DevHtmlAsset {
ChunkGroup::Entry {
entries: vec![ResolvedVc::upcast(chunkable_module)],
ty: ChunkGroupType::Evaluated,
}
.cell(),
},
*module_graph,
)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl AsyncLoaderChunkItem {
}
Ok(self.chunking_context.chunk_group_assets(
module.inner.ident(),
ChunkGroup::Async(ResolvedVc::upcast(module.inner)).cell(),
ChunkGroup::Async(ResolvedVc::upcast(module.inner)),
*self.module_graph,
Value::new(module.availability_info),
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl ManifestAsyncModule {
pub(super) fn chunks(&self) -> Vc<OutputAssets> {
self.chunking_context.chunk_group_assets(
self.inner.ident(),
ChunkGroup::Async(ResolvedVc::upcast(self.inner)).cell(),
ChunkGroup::Async(ResolvedVc::upcast(self.inner)),
*self.module_graph,
Value::new(self.availability_info),
)
Expand All @@ -77,7 +77,7 @@ impl ManifestAsyncModule {
}
Ok(this.chunking_context.chunk_group_assets(
self.ident(),
ChunkGroup::Async(ResolvedVc::upcast(self)).cell(),
ChunkGroup::Async(ResolvedVc::upcast(self)),
*this.module_graph,
Value::new(this.availability_info),
))
Expand Down
3 changes: 1 addition & 2 deletions turbopack/crates/turbopack-nodejs/src/chunking_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,12 @@ impl ChunkingContext for NodeJsChunkingContext {
async fn chunk_group(
self: ResolvedVc<Self>,
ident: Vc<AssetIdent>,
chunk_group: Vc<ChunkGroup>,
chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>,
availability_info: Value<AvailabilityInfo>,
) -> Result<Vc<ChunkGroupResult>> {
let span = tracing::info_span!("chunking", module = ident.to_string().await?.to_string());
async move {
let chunk_group = chunk_group.await?;
let modules = chunk_group.entries();
let MakeChunkGroupResult {
chunks,
Expand Down

0 comments on commit 08db4a6

Please sign in to comment.