Unverified Commit 6b0724ba authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: less turbo tasks for `chunk_item.id()` (#76110)

- Every `EcmascriptChunkItem` already had a `chunking_context()` getter via the `ChunkItem` supertrait.
- Produce less turbo tasks for `chunk_item.id()`
- In the future, we really want to move `chunking_context.chunk_item_id()` to the module graph, (or split it out and instead pass a `Vc<ModuleIdStrategy>`). That is however a refactoring we don't need to do right now.

This showed up in the traces, but overall it doesn't seem to have an effect on perf.
Before:
![Bildschirmfoto 2025-02-17 um 09 34 05](https://github.com/user-attachments/assets/99b4816e-9056-418c-8d69-4d6535b9d296)

After:
![Bildschirmfoto 2025-02-17 um 13 43 04](https://github.com/user-attachments/assets/e4409ef6-831e-464f-900c-ec071b916a88)
parent f0887fa0
...@@ -1365,7 +1365,6 @@ impl AppEndpoint { ...@@ -1365,7 +1365,6 @@ impl AppEndpoint {
client_references_chunks, client_references_chunks,
rsc_app_entry_chunks: **app_entry_chunks, rsc_app_entry_chunks: **app_entry_chunks,
rsc_app_entry_chunks_availability: Value::new(*app_entry_chunks_availability), rsc_app_entry_chunks_availability: Value::new(*app_entry_chunks_availability),
module_graph: *module_graphs.full,
client_chunking_context, client_chunking_context,
ssr_chunking_context, ssr_chunking_context,
next_config: project.next_config(), next_config: project.next_config(),
......
...@@ -31,8 +31,8 @@ use turbo_tasks::{ ...@@ -31,8 +31,8 @@ use turbo_tasks::{
}; };
use turbopack_core::{ use turbopack_core::{
chunk::{ chunk::{
availability_info::AvailabilityInfo, ChunkItem, ChunkItemExt, ChunkableModule, availability_info::AvailabilityInfo, ChunkItem, ChunkableModule, ChunkingContext,
ChunkingContext, ModuleId, ModuleChunkItemIdExt, ModuleId,
}, },
module::Module, module::Module,
module_graph::{ModuleGraph, SingleModuleGraph, SingleModuleGraphModuleNode}, module_graph::{ModuleGraph, SingleModuleGraph, SingleModuleGraphModuleNode},
...@@ -83,8 +83,7 @@ pub(crate) async fn collect_next_dynamic_chunks( ...@@ -83,8 +83,7 @@ pub(crate) async fn collect_next_dynamic_chunks(
let async_chunk_group = async_loader.references().to_resolved().await?; let async_chunk_group = async_loader.references().to_resolved().await?;
let module_id = dynamic_entry let module_id = dynamic_entry
.as_chunk_item(module_graph, Vc::upcast(chunking_context)) .chunk_item_id(Vc::upcast(chunking_context))
.id()
.to_resolved() .to_resolved()
.await?; .await?;
......
...@@ -1647,8 +1647,6 @@ async fn whole_app_module_graph_operation( ...@@ -1647,8 +1647,6 @@ async fn whole_app_module_graph_operation(
let base = ModuleGraph::from_single_graph(base_single_module_graph); let base = ModuleGraph::from_single_graph(base_single_module_graph);
let additional_entries = project.get_all_additional_entries(base); let additional_entries = project.get_all_additional_entries(base);
base.chunk_group_info().await?;
let additional_module_graph = SingleModuleGraph::new_with_entries_visited( let additional_module_graph = SingleModuleGraph::new_with_entries_visited(
additional_entries.await?.into_iter().map(|m| **m).collect(), additional_entries.await?.into_iter().map(|m| **m).collect(),
base_visited_modules, base_visited_modules,
......
...@@ -172,11 +172,6 @@ impl ChunkItem for HmrEntryChunkItem { ...@@ -172,11 +172,6 @@ impl ChunkItem for HmrEntryChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for HmrEntryChunkItem { impl EcmascriptChunkItem for HmrEntryChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> {
let this = self.module.await?; let this = self.module.await?;
......
...@@ -126,11 +126,6 @@ impl ChunkItem for IncludeModulesChunkItem { ...@@ -126,11 +126,6 @@ impl ChunkItem for IncludeModulesChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for IncludeModulesChunkItem { impl EcmascriptChunkItem for IncludeModulesChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn content(&self) -> Vc<EcmascriptChunkItemContent> { fn content(&self) -> Vc<EcmascriptChunkItemContent> {
EcmascriptChunkItemContent { EcmascriptChunkItemContent {
......
...@@ -336,11 +336,6 @@ impl EcmascriptChunkItem for EcmascriptClientReferenceProxyChunkItem { ...@@ -336,11 +336,6 @@ impl EcmascriptChunkItem for EcmascriptClientReferenceProxyChunkItem {
self.inner_chunk_item self.inner_chunk_item
.content_with_async_module_info(async_module_info) .content_with_async_module_info(async_module_info)
} }
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
EcmascriptChunkItem::chunking_context(*self.inner_chunk_item)
}
} }
#[turbo_tasks::value] #[turbo_tasks::value]
......
...@@ -6,7 +6,7 @@ use turbo_rcstr::RcStr; ...@@ -6,7 +6,7 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Vc}; use turbo_tasks::{ResolvedVc, Vc};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ChunkItem, ChunkItemExt, ChunkType, ChunkableModule, ChunkingContext}, chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt},
ident::AssetIdent, ident::AssetIdent,
module::Module, module::Module,
module_graph::ModuleGraph, module_graph::ModuleGraph,
...@@ -133,19 +133,13 @@ struct NextDynamicEntryChunkItem { ...@@ -133,19 +133,13 @@ struct NextDynamicEntryChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for NextDynamicEntryChunkItem { impl EcmascriptChunkItem for NextDynamicEntryChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> {
let inner = self.inner.await?; let inner = self.inner.await?;
let module_id = inner let module_id = inner
.module .module
.as_chunk_item(*self.module_graph, Vc::upcast(*self.chunking_context)) .chunk_item_id(Vc::upcast(*self.chunking_context))
.id()
.await?; .await?;
Ok(EcmascriptChunkItemContent { Ok(EcmascriptChunkItemContent {
inner_code: formatdoc!( inner_code: formatdoc!(
......
...@@ -12,10 +12,9 @@ use turbo_tasks_fs::{File, FileSystemPath}; ...@@ -12,10 +12,9 @@ use turbo_tasks_fs::{File, FileSystemPath};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ chunk::{
availability_info::AvailabilityInfo, ChunkItemExt, ChunkableModule, ChunkingContext, availability_info::AvailabilityInfo, ChunkableModule, ChunkingContext,
ModuleId as TurbopackModuleId, ModuleChunkItemIdExt, ModuleId as TurbopackModuleId,
}, },
module_graph::ModuleGraph,
output::{OutputAsset, OutputAssets}, output::{OutputAsset, OutputAssets},
virtual_output::VirtualOutputAsset, virtual_output::VirtualOutputAsset,
}; };
...@@ -39,7 +38,6 @@ pub struct ClientReferenceManifestOptions { ...@@ -39,7 +38,6 @@ pub struct ClientReferenceManifestOptions {
pub client_references_chunks: Vc<ClientReferencesChunks>, pub client_references_chunks: Vc<ClientReferencesChunks>,
pub rsc_app_entry_chunks: Vc<OutputAssets>, pub rsc_app_entry_chunks: Vc<OutputAssets>,
pub rsc_app_entry_chunks_availability: Value<AvailabilityInfo>, pub rsc_app_entry_chunks_availability: Value<AvailabilityInfo>,
pub module_graph: Vc<ModuleGraph>,
pub client_chunking_context: Vc<Box<dyn ChunkingContext>>, pub client_chunking_context: Vc<Box<dyn ChunkingContext>>,
pub ssr_chunking_context: Option<Vc<Box<dyn ChunkingContext>>>, pub ssr_chunking_context: Option<Vc<Box<dyn ChunkingContext>>>,
pub next_config: Vc<NextConfig>, pub next_config: Vc<NextConfig>,
...@@ -61,7 +59,6 @@ impl ClientReferenceManifest { ...@@ -61,7 +59,6 @@ impl ClientReferenceManifest {
client_references_chunks, client_references_chunks,
rsc_app_entry_chunks, rsc_app_entry_chunks,
rsc_app_entry_chunks_availability, rsc_app_entry_chunks_availability,
module_graph,
client_chunking_context, client_chunking_context,
ssr_chunking_context, ssr_chunking_context,
next_config, next_config,
...@@ -149,13 +146,10 @@ impl ClientReferenceManifest { ...@@ -149,13 +146,10 @@ impl ClientReferenceManifest {
let server_path = client_reference_module_ref.server_ident.to_string().await?; let server_path = client_reference_module_ref.server_ident.to_string().await?;
let client_module = client_reference_module_ref.client_module; let client_module = client_reference_module_ref.client_module;
let client_chunk_item = client_module let client_chunk_item_id = client_module
.as_chunk_item(module_graph, Vc::upcast(client_chunking_context)) .chunk_item_id(Vc::upcast(client_chunking_context))
.to_resolved()
.await?; .await?;
let client_module_id = client_chunk_item.id().await?;
let (client_chunks_paths, client_is_async) = let (client_chunks_paths, client_is_async) =
if let Some((client_chunks, client_availability_info)) = if let Some((client_chunks, client_availability_info)) =
client_component_client_chunks.get(&app_client_reference_ty) client_component_client_chunks.get(&app_client_reference_ty)
...@@ -193,17 +187,13 @@ impl ClientReferenceManifest { ...@@ -193,17 +187,13 @@ impl ClientReferenceManifest {
if let Some(ssr_chunking_context) = ssr_chunking_context { if let Some(ssr_chunking_context) = ssr_chunking_context {
let ssr_module = client_reference_module_ref.ssr_module; let ssr_module = client_reference_module_ref.ssr_module;
let ssr_chunk_item = ssr_module let ssr_chunk_item_id = ssr_module
.as_chunk_item(module_graph, Vc::upcast(ssr_chunking_context)) .chunk_item_id(Vc::upcast(ssr_chunking_context))
.to_resolved()
.await?; .await?;
let ssr_module_id = ssr_chunk_item.id().await?;
let rsc_chunk_item = client_reference_module let rsc_chunk_item_id = client_reference_module
.as_chunk_item(module_graph, Vc::upcast(ssr_chunking_context)) .chunk_item_id(Vc::upcast(ssr_chunking_context))
.to_resolved()
.await?; .await?;
let rsc_module_id = rsc_chunk_item.id().await?;
let (ssr_chunks_paths, ssr_is_async) = if runtime == NextRuntime::Edge { let (ssr_chunks_paths, ssr_is_async) = if runtime == NextRuntime::Edge {
// the chunks get added to the middleware-manifest.json instead // the chunks get added to the middleware-manifest.json instead
...@@ -277,7 +267,7 @@ impl ClientReferenceManifest { ...@@ -277,7 +267,7 @@ impl ClientReferenceManifest {
get_client_reference_module_key(&server_path, "*"), get_client_reference_module_key(&server_path, "*"),
ManifestNodeEntry { ManifestNodeEntry {
name: "*".into(), name: "*".into(),
id: (&*client_module_id).into(), id: (&*client_chunk_item_id).into(),
chunks: client_chunks_paths, chunks: client_chunks_paths,
// This should of course be client_is_async, but SSR can become // This should of course be client_is_async, but SSR can become
// async due to ESM externals, and // async due to ESM externals, and
...@@ -292,7 +282,7 @@ impl ClientReferenceManifest { ...@@ -292,7 +282,7 @@ impl ClientReferenceManifest {
"*".into(), "*".into(),
ManifestNodeEntry { ManifestNodeEntry {
name: "*".into(), name: "*".into(),
id: (&*ssr_module_id).into(), id: (&*ssr_chunk_item_id).into(),
chunks: ssr_chunks_paths, chunks: ssr_chunks_paths,
// See above // See above
r#async: client_is_async || ssr_is_async, r#async: client_is_async || ssr_is_async,
...@@ -304,7 +294,7 @@ impl ClientReferenceManifest { ...@@ -304,7 +294,7 @@ impl ClientReferenceManifest {
"*".into(), "*".into(),
ManifestNodeEntry { ManifestNodeEntry {
name: "*".into(), name: "*".into(),
id: (&*rsc_module_id).into(), id: (&*rsc_chunk_item_id).into(),
chunks: rsc_chunks_paths, chunks: rsc_chunks_paths,
r#async: rsc_is_async, r#async: rsc_is_async,
}, },
...@@ -314,18 +304,18 @@ impl ClientReferenceManifest { ...@@ -314,18 +304,18 @@ impl ClientReferenceManifest {
NextRuntime::NodeJs => { NextRuntime::NodeJs => {
entry_manifest entry_manifest
.ssr_module_mapping .ssr_module_mapping
.insert((&*client_module_id).into(), ssr_manifest_node); .insert((&*client_chunk_item_id).into(), ssr_manifest_node);
entry_manifest entry_manifest
.rsc_module_mapping .rsc_module_mapping
.insert((&*client_module_id).into(), rsc_manifest_node); .insert((&*client_chunk_item_id).into(), rsc_manifest_node);
} }
NextRuntime::Edge => { NextRuntime::Edge => {
entry_manifest entry_manifest
.edge_ssr_module_mapping .edge_ssr_module_mapping
.insert((&*client_module_id).into(), ssr_manifest_node); .insert((&*client_chunk_item_id).into(), ssr_manifest_node);
entry_manifest entry_manifest
.edge_rsc_module_mapping .edge_rsc_module_mapping
.insert((&*client_module_id).into(), rsc_manifest_node); .insert((&*client_chunk_item_id).into(), rsc_manifest_node);
} }
} }
} }
......
...@@ -7,7 +7,7 @@ use turbo_tasks::{ResolvedVc, Vc}; ...@@ -7,7 +7,7 @@ use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ChunkItem, ChunkItemExt, ChunkType, ChunkableModule, ChunkingContext}, chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt},
ident::AssetIdent, ident::AssetIdent,
module::Module, module::Module,
module_graph::ModuleGraph, module_graph::ModuleGraph,
...@@ -128,19 +128,13 @@ struct NextServerComponentChunkItem { ...@@ -128,19 +128,13 @@ struct NextServerComponentChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for NextServerComponentChunkItem { impl EcmascriptChunkItem for NextServerComponentChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> {
let inner = self.inner.await?; let inner = self.inner.await?;
let module_id = inner let module_id = inner
.module .module
.as_chunk_item(*self.module_graph, Vc::upcast(*self.chunking_context)) .chunk_item_id(Vc::upcast(*self.chunking_context))
.id()
.await?; .await?;
Ok(EcmascriptChunkItemContent { Ok(EcmascriptChunkItemContent {
inner_code: formatdoc!( inner_code: formatdoc!(
......
...@@ -7,7 +7,7 @@ use turbo_tasks::{ResolvedVc, Vc}; ...@@ -7,7 +7,7 @@ use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ChunkItem, ChunkItemExt, ChunkType, ChunkableModule, ChunkingContext}, chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt},
ident::AssetIdent, ident::AssetIdent,
module::Module, module::Module,
module_graph::ModuleGraph, module_graph::ModuleGraph,
...@@ -128,19 +128,13 @@ struct NextServerComponentChunkItem { ...@@ -128,19 +128,13 @@ struct NextServerComponentChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for NextServerComponentChunkItem { impl EcmascriptChunkItem for NextServerComponentChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> {
let inner = self.inner.await?; let inner = self.inner.await?;
let module_id = inner let module_id = inner
.module .module
.as_chunk_item(*self.module_graph, Vc::upcast(*self.chunking_context)) .chunk_item_id(Vc::upcast(*self.chunking_context))
.id()
.await?; .await?;
Ok(EcmascriptChunkItemContent { Ok(EcmascriptChunkItemContent {
inner_code: formatdoc!( inner_code: formatdoc!(
......
...@@ -9,8 +9,8 @@ use turbo_tasks_fs::{File, FileSystemPath}; ...@@ -9,8 +9,8 @@ use turbo_tasks_fs::{File, FileSystemPath};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ chunk::{
ChunkData, ChunkItemExt, ChunkableModule, ChunkingContext, ChunksData, EvaluatableAssets, ChunkData, ChunkingContext, ChunksData, EvaluatableAssets, MinifyType,
MinifyType, ModuleId, ModuleChunkItemIdExt, ModuleId,
}, },
code_builder::{Code, CodeBuilder}, code_builder::{Code, CodeBuilder},
ident::AssetIdent, ident::AssetIdent,
...@@ -104,15 +104,13 @@ impl EcmascriptDevEvaluateChunk { ...@@ -104,15 +104,13 @@ impl EcmascriptDevEvaluateChunk {
.iter() .iter()
.map({ .map({
let chunking_context = this.chunking_context; let chunking_context = this.chunking_context;
let module_graph = this.module_graph;
move |entry| async move { move |entry| async move {
if let Some(placeable) = if let Some(placeable) =
ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(*entry) ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(*entry)
{ {
Ok(Some( Ok(Some(
placeable placeable
.as_chunk_item(*module_graph, Vc::upcast(*chunking_context)) .chunk_item_id(Vc::upcast(*chunking_context))
.id()
.await?, .await?,
)) ))
} else { } else {
......
...@@ -224,8 +224,11 @@ pub trait ChunkingContext { ...@@ -224,8 +224,11 @@ pub trait ChunkingContext {
ident: Vc<AssetIdent>, ident: Vc<AssetIdent>,
) -> Result<Vc<ModuleId>>; ) -> Result<Vc<ModuleId>>;
fn chunk_item_id(self: Vc<Self>, chunk_item: Vc<Box<dyn ChunkItem>>) -> Vc<ModuleId> { fn chunk_item_id(self: Vc<Self>, module: Vc<Box<dyn ChunkItem>>) -> Vc<ModuleId> {
self.chunk_item_id_from_ident(chunk_item.asset_ident()) self.chunk_item_id_from_ident(module.asset_ident())
}
fn chunk_item_id_from_module(self: Vc<Self>, module: Vc<Box<dyn Module>>) -> Vc<ModuleId> {
self.chunk_item_id_from_ident(module.ident())
} }
} }
......
...@@ -347,6 +347,25 @@ where ...@@ -347,6 +347,25 @@ where
} }
} }
pub trait ModuleChunkItemIdExt {
/// Returns the chunk item id of this module.
fn chunk_item_id(
self: Vc<Self>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Vc<ModuleId>;
}
impl<T> ModuleChunkItemIdExt for T
where
T: Upcast<Box<dyn Module>>,
{
fn chunk_item_id(
self: Vc<Self>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Vc<ModuleId> {
chunking_context.chunk_item_id_from_module(Vc::upcast(self))
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
......
...@@ -9,7 +9,7 @@ use turbo_tasks::{FxIndexMap, ResolvedVc, Value, ValueToString, Vc}; ...@@ -9,7 +9,7 @@ use turbo_tasks::{FxIndexMap, ResolvedVc, Value, ValueToString, Vc};
use turbo_tasks_fs::{rope::Rope, FileSystemPath}; use turbo_tasks_fs::{rope::Rope, FileSystemPath};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ChunkItem, ChunkItemExt, ChunkType, ChunkableModule, ChunkingContext}, chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt},
context::{AssetContext, ProcessResult}, context::{AssetContext, ProcessResult},
ident::AssetIdent, ident::AssetIdent,
issue::{Issue, IssueExt, IssueSeverity, IssueStage, OptionStyledString, StyledString}, issue::{Issue, IssueExt, IssueSeverity, IssueStage, OptionStyledString, StyledString},
...@@ -320,11 +320,6 @@ impl ChunkItem for ModuleChunkItem { ...@@ -320,11 +320,6 @@ impl ChunkItem for ModuleChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for ModuleChunkItem { impl EcmascriptChunkItem for ModuleChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> {
let classes = self.module.classes().await?; let classes = self.module.classes().await?;
...@@ -378,8 +373,7 @@ impl EcmascriptChunkItem for ModuleChunkItem { ...@@ -378,8 +373,7 @@ impl EcmascriptChunkItem for ModuleChunkItem {
ResolvedVc::upcast(css_module); ResolvedVc::upcast(css_module);
let module_id = placeable let module_id = placeable
.as_chunk_item(*self.module_graph, Vc::upcast(*self.chunking_context)) .chunk_item_id(Vc::upcast(*self.chunking_context))
.id()
.await?; .await?;
let module_id = StringifyJs(&*module_id); let module_id = StringifyJs(&*module_id);
let original_name = StringifyJs(&original_name); let original_name = StringifyJs(&original_name);
......
...@@ -4,8 +4,8 @@ use turbo_rcstr::RcStr; ...@@ -4,8 +4,8 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Value, Vc}; use turbo_tasks::{ResolvedVc, TryJoinIterExt, Value, Vc};
use turbopack_core::{ use turbopack_core::{
chunk::{ chunk::{
ChunkData, ChunkItem, ChunkItemExt, ChunkType, ChunkableModule, ChunkingContext, ChunkData, ChunkItem, ChunkType, ChunkingContext, ChunkingContextExt, ChunksData,
ChunkingContextExt, ChunksData, ModuleChunkItemIdExt,
}, },
ident::AssetIdent, ident::AssetIdent,
module::Module, module::Module,
...@@ -59,11 +59,6 @@ impl AsyncLoaderChunkItem { ...@@ -59,11 +59,6 @@ impl AsyncLoaderChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for AsyncLoaderChunkItem { impl EcmascriptChunkItem for AsyncLoaderChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(self: Vc<Self>) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(self: Vc<Self>) -> Result<Vc<EcmascriptChunkItemContent>> {
let this = self.await?; let this = self.await?;
...@@ -74,11 +69,7 @@ impl EcmascriptChunkItem for AsyncLoaderChunkItem { ...@@ -74,11 +69,7 @@ impl EcmascriptChunkItem for AsyncLoaderChunkItem {
{ {
Some( Some(
placeable placeable
.as_chunk_item( .chunk_item_id(*ResolvedVc::upcast(this.chunking_context))
*this.module_graph,
*ResolvedVc::upcast(this.chunking_context),
)
.id()
.await?, .await?,
) )
} else { } else {
......
...@@ -7,7 +7,7 @@ use turbo_tasks::{ ...@@ -7,7 +7,7 @@ use turbo_tasks::{
}; };
use turbo_tasks_fs::{rope::Rope, FileSystemPath}; use turbo_tasks_fs::{rope::Rope, FileSystemPath};
use turbopack_core::{ use turbopack_core::{
chunk::{AsyncModuleInfo, ChunkItem, ChunkItemExt, ChunkItemTy, ChunkingContext}, chunk::{AsyncModuleInfo, ChunkItem, ChunkItemTy, ChunkingContext},
code_builder::{Code, CodeBuilder}, code_builder::{Code, CodeBuilder},
error::PrettyPrintError, error::PrettyPrintError,
issue::{code_gen::CodeGenerationIssue, IssueExt, IssueSeverity, StyledString}, issue::{code_gen::CodeGenerationIssue, IssueExt, IssueSeverity, StyledString},
...@@ -202,7 +202,6 @@ pub trait EcmascriptChunkItem: ChunkItem { ...@@ -202,7 +202,6 @@ pub trait EcmascriptChunkItem: ChunkItem {
) -> Vc<EcmascriptChunkItemContent> { ) -> Vc<EcmascriptChunkItemContent> {
self.content() self.content()
} }
fn chunking_context(self: Vc<Self>) -> Vc<Box<dyn ChunkingContext>>;
/// Specifies which availablility information the chunk item needs for code /// Specifies which availablility information the chunk item needs for code
/// generation /// generation
...@@ -240,7 +239,11 @@ async fn module_factory_with_code_generation_issue( ...@@ -240,7 +239,11 @@ async fn module_factory_with_code_generation_issue(
{ {
Ok(factory) => factory, Ok(factory) => factory,
Err(error) => { Err(error) => {
let id = chunk_item.id().to_string().await; let id = chunk_item
.chunking_context()
.chunk_item_id(Vc::upcast(chunk_item))
.to_string()
.await;
let id = id.as_ref().map_or_else(|_| "unknown", |id| &**id); let id = id.as_ref().map_or_else(|_| "unknown", |id| &**id);
let error = error.context(format!( let error = error.context(format!(
"An error occurred while generating the chunk item {}", "An error occurred while generating the chunk item {}",
......
...@@ -167,11 +167,6 @@ impl ChunkGroupFilesChunkItem { ...@@ -167,11 +167,6 @@ impl ChunkGroupFilesChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for ChunkGroupFilesChunkItem { impl EcmascriptChunkItem for ChunkGroupFilesChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(self: Vc<Self>) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(self: Vc<Self>) -> Result<Vc<EcmascriptChunkItemContent>> {
let chunks = self.chunks(); let chunks = self.chunks();
......
...@@ -58,6 +58,7 @@ use swc_core::{ ...@@ -58,6 +58,7 @@ use swc_core::{
visit::{VisitMutWith, VisitMutWithAstPath}, visit::{VisitMutWith, VisitMutWithAstPath},
}, },
}; };
use tracing::Instrument;
pub use transform::{ pub use transform::{
CustomTransformer, EcmascriptInputTransform, EcmascriptInputTransforms, TransformContext, CustomTransformer, EcmascriptInputTransform, EcmascriptInputTransforms, TransformContext,
TransformPlugin, UnsupportedServerActionIssue, TransformPlugin, UnsupportedServerActionIssue,
...@@ -709,11 +710,6 @@ impl ChunkItem for ModuleChunkItem { ...@@ -709,11 +710,6 @@ impl ChunkItem for ModuleChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for ModuleChunkItem { impl EcmascriptChunkItem for ModuleChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn content(self: Vc<Self>) -> Vc<EcmascriptChunkItemContent> { fn content(self: Vc<Self>) -> Vc<EcmascriptChunkItemContent> {
panic!("content() should not be called"); panic!("content() should not be called");
...@@ -798,49 +794,51 @@ impl EcmascriptModuleContent { ...@@ -798,49 +794,51 @@ impl EcmascriptModuleContent {
async_module_info, async_module_info,
} = input; } = input;
let additional_code_gens = [ let (esm_code_gens, additional_code_gens, code_gens) = async {
if let Some(async_module) = &*async_module.await? { let additional_code_gens = [
Some( if let Some(async_module) = &*async_module.await? {
async_module Some(
.code_generation( async_module
async_module_info, .code_generation(async_module_info, references, chunking_context)
references, .await?,
module_graph, )
chunking_context, } else {
) None
.await?, },
) if let EcmascriptExports::EsmExports(exports) = *exports.await? {
} else { Some(
None exports
}, .code_generation(module_graph, chunking_context)
if let EcmascriptExports::EsmExports(exports) = *exports.await? { .await?,
Some( )
exports } else {
.code_generation(module_graph, chunking_context) None
.await?, },
) ];
} else {
None
},
];
let esm_code_gens = esm_references let esm_code_gens = esm_references
.await? .await?
.iter() .iter()
.map(|r| r.code_generation(module_graph, chunking_context)) .map(|r| r.code_generation(chunking_context))
.try_join() .try_join()
.await?; .await?;
let code_gens = code_generation let code_gens = code_generation
.await? .await?
.iter() .iter()
.map(|c| c.code_generation(module_graph, chunking_context)) .map(|c| c.code_generation(module_graph, chunking_context))
.try_join() .try_join()
.await?; .await?;
anyhow::Ok((esm_code_gens, additional_code_gens, code_gens))
}
.instrument(tracing::info_span!("precompute code generation"))
.await?;
let code_gens = esm_code_gens let code_gens = esm_code_gens
.iter() .iter()
.chain(additional_code_gens.iter().flatten()) .chain(additional_code_gens.iter().flatten())
.chain(code_gens.iter()); .chain(code_gens.iter());
gen_content_with_code_gens( gen_content_with_code_gens(
parsed, parsed,
ident, ident,
...@@ -849,6 +847,7 @@ impl EcmascriptModuleContent { ...@@ -849,6 +847,7 @@ impl EcmascriptModuleContent {
generate_source_map, generate_source_map,
original_source_map, original_source_map,
) )
.instrument(tracing::info_span!("gen content with code gens"))
.await .await
} }
......
...@@ -37,11 +37,6 @@ impl ManifestChunkItem { ...@@ -37,11 +37,6 @@ impl ManifestChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for ManifestChunkItem { impl EcmascriptChunkItem for ManifestChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(self: Vc<Self>) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(self: Vc<Self>) -> Result<Vc<EcmascriptChunkItemContent>> {
let chunks_data = self.chunks_data().await?; let chunks_data = self.chunks_data().await?;
......
...@@ -6,7 +6,8 @@ use turbo_rcstr::RcStr; ...@@ -6,7 +6,8 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc}; use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
use turbopack_core::{ use turbopack_core::{
chunk::{ chunk::{
ChunkData, ChunkItem, ChunkItemExt, ChunkType, ChunkableModule, ChunkingContext, ChunksData, ChunkData, ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ChunksData,
ModuleChunkItemIdExt,
}, },
ident::AssetIdent, ident::AssetIdent,
module::Module, module::Module,
...@@ -130,11 +131,6 @@ impl ChunkItem for ManifestLoaderChunkItem { ...@@ -130,11 +131,6 @@ impl ChunkItem for ManifestLoaderChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for ManifestLoaderChunkItem { impl EcmascriptChunkItem for ManifestLoaderChunkItem {
#[turbo_tasks::function]
async fn chunking_context(&self) -> Result<Vc<Box<dyn ChunkingContext>>> {
Ok(*self.manifest.await?.chunking_context)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(self: Vc<Self>) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(self: Vc<Self>) -> Result<Vc<EcmascriptChunkItemContent>> {
let this = &*self.await?; let this = &*self.await?;
...@@ -152,11 +148,7 @@ impl EcmascriptChunkItem for ManifestLoaderChunkItem { ...@@ -152,11 +148,7 @@ impl EcmascriptChunkItem for ManifestLoaderChunkItem {
// exports a promise for all of the necessary chunk loads. // exports a promise for all of the necessary chunk loads.
let item_id = &*this let item_id = &*this
.manifest .manifest
.as_chunk_item( .chunk_item_id(*ResolvedVc::upcast(manifest.chunking_context))
*this.module_graph,
*ResolvedVc::upcast(manifest.chunking_context),
)
.id()
.await?; .await?;
// Finally, we need the id of the module that we're actually trying to // Finally, we need the id of the module that we're actually trying to
...@@ -165,11 +157,7 @@ impl EcmascriptChunkItem for ManifestLoaderChunkItem { ...@@ -165,11 +157,7 @@ impl EcmascriptChunkItem for ManifestLoaderChunkItem {
ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkPlaceable>>(manifest.inner) ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkPlaceable>>(manifest.inner)
.ok_or_else(|| anyhow!("asset is not placeable in ecmascript chunk"))?; .ok_or_else(|| anyhow!("asset is not placeable in ecmascript chunk"))?;
let dynamic_id = &*placeable let dynamic_id = &*placeable
.as_chunk_item( .chunk_item_id(*ResolvedVc::upcast(manifest.chunking_context))
*this.module_graph,
*ResolvedVc::upcast(manifest.chunking_context),
)
.id()
.await?; .await?;
// This is the code that will be executed when the dynamic import is reached. // This is the code that will be executed when the dynamic import is reached.
......
...@@ -157,7 +157,7 @@ impl AmdDefineWithDependenciesCodeGen { ...@@ -157,7 +157,7 @@ impl AmdDefineWithDependenciesCodeGen {
pub async fn code_generation( pub async fn code_generation(
&self, &self,
module_graph: Vc<ModuleGraph>, _module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<CodeGeneration> { ) -> Result<CodeGeneration> {
let mut visitors = Vec::new(); let mut visitors = Vec::new();
...@@ -174,7 +174,6 @@ impl AmdDefineWithDependenciesCodeGen { ...@@ -174,7 +174,6 @@ impl AmdDefineWithDependenciesCodeGen {
pattern_mapping: PatternMapping::resolve_request( pattern_mapping: PatternMapping::resolve_request(
**request, **request,
*self.origin, *self.origin,
module_graph,
Vc::upcast(chunking_context), Vc::upcast(chunking_context),
cjs_resolve( cjs_resolve(
*self.origin, *self.origin,
......
...@@ -11,7 +11,6 @@ use turbo_tasks::{ ...@@ -11,7 +11,6 @@ use turbo_tasks::{
}; };
use turbopack_core::{ use turbopack_core::{
chunk::{AsyncModuleInfo, ChunkableModuleReference, ChunkingContext, ChunkingType}, chunk::{AsyncModuleInfo, ChunkableModuleReference, ChunkingContext, ChunkingType},
module_graph::ModuleGraph,
reference::{ModuleReference, ModuleReferences}, reference::{ModuleReference, ModuleReferences},
resolve::ExternalType, resolve::ExternalType,
}; };
...@@ -103,7 +102,6 @@ impl AsyncModule { ...@@ -103,7 +102,6 @@ impl AsyncModule {
&self, &self,
async_module_info: Vc<AsyncModuleInfo>, async_module_info: Vc<AsyncModuleInfo>,
references: Vc<ModuleReferences>, references: Vc<ModuleReferences>,
module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<Vc<AsyncModuleIdents>> { ) -> Result<Vc<AsyncModuleIdents>> {
let async_module_info = async_module_info.await?; let async_module_info = async_module_info.await?;
...@@ -118,9 +116,7 @@ impl AsyncModule { ...@@ -118,9 +116,7 @@ impl AsyncModule {
Ok(match &*referenced_asset { Ok(match &*referenced_asset {
ReferencedAsset::External(_, ExternalType::EcmaScriptModule) => { ReferencedAsset::External(_, ExternalType::EcmaScriptModule) => {
if self.import_externals { if self.import_externals {
referenced_asset referenced_asset.get_ident(chunking_context).await?
.get_ident(module_graph, chunking_context)
.await?
} else { } else {
None None
} }
...@@ -130,9 +126,7 @@ impl AsyncModule { ...@@ -130,9 +126,7 @@ impl AsyncModule {
.referenced_async_modules .referenced_async_modules
.contains(&ResolvedVc::upcast(*placeable)) .contains(&ResolvedVc::upcast(*placeable))
{ {
referenced_asset referenced_asset.get_ident(chunking_context).await?
.get_ident(module_graph, chunking_context)
.await?
} else { } else {
None None
} }
...@@ -197,17 +191,11 @@ impl AsyncModule { ...@@ -197,17 +191,11 @@ impl AsyncModule {
self: Vc<Self>, self: Vc<Self>,
async_module_info: Option<Vc<AsyncModuleInfo>>, async_module_info: Option<Vc<AsyncModuleInfo>>,
references: Vc<ModuleReferences>, references: Vc<ModuleReferences>,
module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<CodeGeneration> { ) -> Result<CodeGeneration> {
if let Some(async_module_info) = async_module_info { if let Some(async_module_info) = async_module_info {
let async_idents = self let async_idents = self
.get_async_idents( .get_async_idents(async_module_info, references, chunking_context)
async_module_info,
references,
module_graph,
chunking_context,
)
.await?; .await?;
if !async_idents.is_empty() { if !async_idents.is_empty() {
......
...@@ -157,7 +157,7 @@ pub struct CjsRequireAssetReferenceCodeGen { ...@@ -157,7 +157,7 @@ pub struct CjsRequireAssetReferenceCodeGen {
impl CjsRequireAssetReferenceCodeGen { impl CjsRequireAssetReferenceCodeGen {
pub async fn code_generation( pub async fn code_generation(
&self, &self,
module_graph: Vc<ModuleGraph>, _module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<CodeGeneration> { ) -> Result<CodeGeneration> {
let reference = self.reference.await?; let reference = self.reference.await?;
...@@ -165,7 +165,6 @@ impl CjsRequireAssetReferenceCodeGen { ...@@ -165,7 +165,6 @@ impl CjsRequireAssetReferenceCodeGen {
let pm = PatternMapping::resolve_request( let pm = PatternMapping::resolve_request(
*reference.request, *reference.request,
*reference.origin, *reference.origin,
module_graph,
Vc::upcast(chunking_context), Vc::upcast(chunking_context),
self.reference.resolve_reference(), self.reference.resolve_reference(),
ResolveType::ChunkItem, ResolveType::ChunkItem,
...@@ -276,7 +275,7 @@ pub struct CjsRequireResolveAssetReferenceCodeGen { ...@@ -276,7 +275,7 @@ pub struct CjsRequireResolveAssetReferenceCodeGen {
impl CjsRequireResolveAssetReferenceCodeGen { impl CjsRequireResolveAssetReferenceCodeGen {
pub async fn code_generation( pub async fn code_generation(
&self, &self,
module_graph: Vc<ModuleGraph>, _module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<CodeGeneration> { ) -> Result<CodeGeneration> {
let reference = self.reference.await?; let reference = self.reference.await?;
...@@ -284,7 +283,6 @@ impl CjsRequireResolveAssetReferenceCodeGen { ...@@ -284,7 +283,6 @@ impl CjsRequireResolveAssetReferenceCodeGen {
let pm = PatternMapping::resolve_request( let pm = PatternMapping::resolve_request(
*reference.request, *reference.request,
*reference.origin, *reference.origin,
module_graph,
Vc::upcast(chunking_context), Vc::upcast(chunking_context),
self.reference.resolve_reference(), self.reference.resolve_reference(),
ResolveType::ChunkItem, ResolveType::ChunkItem,
......
...@@ -10,15 +10,14 @@ use turbo_tasks::{ResolvedVc, Value, ValueToString, Vc}; ...@@ -10,15 +10,14 @@ use turbo_tasks::{ResolvedVc, Value, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
chunk::{ chunk::{
ChunkItemExt, ChunkableModule, ChunkableModuleReference, ChunkingContext, ChunkingType, ChunkableModuleReference, ChunkingContext, ChunkingType, ChunkingTypeOption,
ChunkingTypeOption, ModuleChunkItemIdExt,
}, },
issue::{ issue::{
Issue, IssueExt, IssueSeverity, IssueSource, IssueStage, OptionIssueSource, Issue, IssueExt, IssueSeverity, IssueSource, IssueStage, OptionIssueSource,
OptionStyledString, StyledString, OptionStyledString, StyledString,
}, },
module::Module, module::Module,
module_graph::ModuleGraph,
reference::ModuleReference, reference::ModuleReference,
reference_type::{EcmaScriptModulesReferenceSubType, ImportWithType}, reference_type::{EcmaScriptModulesReferenceSubType, ImportWithType},
resolve::{ resolve::{
...@@ -52,12 +51,11 @@ pub enum ReferencedAsset { ...@@ -52,12 +51,11 @@ pub enum ReferencedAsset {
impl ReferencedAsset { impl ReferencedAsset {
pub async fn get_ident( pub async fn get_ident(
&self, &self,
module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<Option<String>> { ) -> Result<Option<String>> {
Ok(match self { Ok(match self {
ReferencedAsset::Some(asset) => { ReferencedAsset::Some(asset) => {
Some(Self::get_ident_from_placeable(asset, module_graph, chunking_context).await?) Some(Self::get_ident_from_placeable(asset, chunking_context).await?)
} }
ReferencedAsset::External(request, ty) => Some(magic_identifier::mangle(&format!( ReferencedAsset::External(request, ty) => Some(magic_identifier::mangle(&format!(
"{ty} external {request}" "{ty} external {request}"
...@@ -68,13 +66,9 @@ impl ReferencedAsset { ...@@ -68,13 +66,9 @@ impl ReferencedAsset {
pub(crate) async fn get_ident_from_placeable( pub(crate) async fn get_ident_from_placeable(
asset: &Vc<Box<dyn EcmascriptChunkPlaceable>>, asset: &Vc<Box<dyn EcmascriptChunkPlaceable>>,
module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<String> { ) -> Result<String> {
let id = asset let id = asset.chunk_item_id(Vc::upcast(chunking_context)).await?;
.as_chunk_item(module_graph, Vc::upcast(chunking_context))
.id()
.await?;
Ok(magic_identifier::mangle(&format!("imported module {}", id))) Ok(magic_identifier::mangle(&format!("imported module {}", id)))
} }
} }
...@@ -258,7 +252,6 @@ impl ChunkableModuleReference for EsmAssetReference { ...@@ -258,7 +252,6 @@ impl ChunkableModuleReference for EsmAssetReference {
impl EsmAssetReference { impl EsmAssetReference {
pub async fn code_generation( pub async fn code_generation(
self: Vc<Self>, self: Vc<Self>,
module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<CodeGeneration> { ) -> Result<CodeGeneration> {
let this = &*self.await?; let this = &*self.await?;
...@@ -276,10 +269,7 @@ impl EsmAssetReference { ...@@ -276,10 +269,7 @@ impl EsmAssetReference {
span: DUMMY_SP, span: DUMMY_SP,
}); });
Some((format!("throw {request}").into(), stmt)) Some((format!("throw {request}").into(), stmt))
} else if let Some(ident) = referenced_asset } else if let Some(ident) = referenced_asset.get_ident(chunking_context).await? {
.get_ident(module_graph, chunking_context)
.await?
{
let span = this let span = this
.issue_source .issue_source
.to_swc_offsets() .to_swc_offsets()
...@@ -292,10 +282,7 @@ impl EsmAssetReference { ...@@ -292,10 +282,7 @@ impl EsmAssetReference {
unreachable!() unreachable!()
} }
ReferencedAsset::Some(asset) => { ReferencedAsset::Some(asset) => {
let id = asset let id = asset.chunk_item_id(Vc::upcast(chunking_context)).await?;
.as_chunk_item(module_graph, Vc::upcast(chunking_context))
.id()
.await?;
let name = ident; let name = ident;
Some(( Some((
id.to_string().into(), id.to_string().into(),
......
...@@ -43,17 +43,14 @@ impl EsmBinding { ...@@ -43,17 +43,14 @@ impl EsmBinding {
pub async fn code_generation( pub async fn code_generation(
&self, &self,
module_graph: Vc<ModuleGraph>, _module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<CodeGeneration> { ) -> Result<CodeGeneration> {
let mut visitors = vec![]; let mut visitors = vec![];
let export = self.export.clone(); let export = self.export.clone();
let imported_module = self.reference.get_referenced_asset(); let imported_module = self.reference.get_referenced_asset();
let imported_module = imported_module let imported_module = imported_module.await?.get_ident(chunking_context).await?;
.await?
.get_ident(module_graph, chunking_context)
.await?;
let mut ast_path = self.ast_path.0.clone(); let mut ast_path = self.ast_path.0.clone();
loop { loop {
......
...@@ -132,7 +132,7 @@ pub struct EsmAsyncAssetReferenceCodeGen { ...@@ -132,7 +132,7 @@ pub struct EsmAsyncAssetReferenceCodeGen {
impl EsmAsyncAssetReferenceCodeGen { impl EsmAsyncAssetReferenceCodeGen {
pub async fn code_generation( pub async fn code_generation(
&self, &self,
module_graph: Vc<ModuleGraph>, _module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<CodeGeneration> { ) -> Result<CodeGeneration> {
let reference = self.reference.await?; let reference = self.reference.await?;
...@@ -140,7 +140,6 @@ impl EsmAsyncAssetReferenceCodeGen { ...@@ -140,7 +140,6 @@ impl EsmAsyncAssetReferenceCodeGen {
let pm = PatternMapping::resolve_request( let pm = PatternMapping::resolve_request(
*reference.request, *reference.request,
*reference.origin, *reference.origin,
module_graph,
Vc::upcast(chunking_context), Vc::upcast(chunking_context),
self.reference.resolve_reference(), self.reference.resolve_reference(),
if matches!( if matches!(
......
...@@ -492,19 +492,16 @@ impl EsmExports { ...@@ -492,19 +492,16 @@ impl EsmExports {
impl EsmExports { impl EsmExports {
pub async fn code_generation( pub async fn code_generation(
self: Vc<Self>, self: Vc<Self>,
module_graph: Vc<ModuleGraph>, _module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<CodeGeneration> { ) -> Result<CodeGeneration> {
let expanded = self.expand_exports().await?; let expanded = self.expand_exports().await?;
let mut dynamic_exports = Vec::<Box<Expr>>::new(); let mut dynamic_exports = Vec::<Box<Expr>>::new();
for dynamic_export_asset in &expanded.dynamic_exports { for dynamic_export_asset in &expanded.dynamic_exports {
let ident = ReferencedAsset::get_ident_from_placeable( let ident =
dynamic_export_asset, ReferencedAsset::get_ident_from_placeable(dynamic_export_asset, chunking_context)
module_graph, .await?;
chunking_context,
)
.await?;
dynamic_exports.push(quote_expr!( dynamic_exports.push(quote_expr!(
"$turbopack_dynamic($arg)", "$turbopack_dynamic($arg)",
...@@ -546,7 +543,6 @@ impl EsmExports { ...@@ -546,7 +543,6 @@ impl EsmExports {
let referenced_asset = let referenced_asset =
ReferencedAsset::from_resolve_result(esm_ref.resolve_reference()).await?; ReferencedAsset::from_resolve_result(esm_ref.resolve_reference()).await?;
referenced_asset.get_ident( referenced_asset.get_ident(
module_graph,
chunking_context chunking_context
).await?.map(|ident| { ).await?.map(|ident| {
let expr = MemberExpr { let expr = MemberExpr {
...@@ -588,7 +584,7 @@ impl EsmExports { ...@@ -588,7 +584,7 @@ impl EsmExports {
let referenced_asset = let referenced_asset =
ReferencedAsset::from_resolve_result(esm_ref.resolve_reference()).await?; ReferencedAsset::from_resolve_result(esm_ref.resolve_reference()).await?;
referenced_asset referenced_asset
.get_ident(module_graph, chunking_context) .get_ident(chunking_context)
.await? .await?
.map(|ident| { .map(|ident| {
quote!( quote!(
......
...@@ -6,10 +6,7 @@ use turbo_tasks::{ ...@@ -6,10 +6,7 @@ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, NonLocalValue, ResolvedVc, ValueToString, Vc, debug::ValueDebugFormat, trace::TraceRawVcs, NonLocalValue, ResolvedVc, ValueToString, Vc,
}; };
use turbopack_core::{ use turbopack_core::{
chunk::{ chunk::{ChunkableModuleReference, ChunkingContext, ChunkingTypeOption, ModuleChunkItemIdExt},
ChunkItemExt, ChunkableModule, ChunkableModuleReference, ChunkingContext,
ChunkingTypeOption,
},
module_graph::ModuleGraph, module_graph::ModuleGraph,
reference::ModuleReference, reference::ModuleReference,
resolve::ModuleResolveResult, resolve::ModuleResolveResult,
...@@ -86,7 +83,7 @@ pub struct EsmModuleIdAssetReferenceCodeGen { ...@@ -86,7 +83,7 @@ pub struct EsmModuleIdAssetReferenceCodeGen {
impl EsmModuleIdAssetReferenceCodeGen { impl EsmModuleIdAssetReferenceCodeGen {
pub async fn code_generation( pub async fn code_generation(
&self, &self,
module_graph: Vc<ModuleGraph>, _module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<CodeGeneration> { ) -> Result<CodeGeneration> {
let mut visitors = Vec::new(); let mut visitors = Vec::new();
...@@ -94,10 +91,7 @@ impl EsmModuleIdAssetReferenceCodeGen { ...@@ -94,10 +91,7 @@ impl EsmModuleIdAssetReferenceCodeGen {
if let ReferencedAsset::Some(asset) = if let ReferencedAsset::Some(asset) =
&*self.reference.await?.inner.get_referenced_asset().await? &*self.reference.await?.inner.get_referenced_asset().await?
{ {
let id = asset let id = asset.chunk_item_id(Vc::upcast(chunking_context)).await?;
.as_chunk_item(module_graph, Vc::upcast(chunking_context))
.id()
.await?;
let id = module_id_to_lit(&id); let id = module_id_to_lit(&id);
visitors.push(create_visitor!(self.path, visit_mut_expr(expr: &mut Expr) { visitors.push(create_visitor!(self.path, visit_mut_expr(expr: &mut Expr) {
*expr = id.clone() *expr = id.clone()
......
...@@ -11,8 +11,8 @@ use turbo_tasks::{ ...@@ -11,8 +11,8 @@ use turbo_tasks::{
}; };
use turbopack_core::{ use turbopack_core::{
chunk::{ chunk::{
ChunkItemExt, ChunkableModule, ChunkableModuleReference, ChunkingContext, ChunkingType, ChunkableModuleReference, ChunkingContext, ChunkingType, ChunkingTypeOption,
ChunkingTypeOption, ModuleChunkItemIdExt,
}, },
environment::Rendering, environment::Rendering,
issue::IssueSource, issue::IssueSource,
...@@ -170,7 +170,7 @@ impl UrlAssetReferenceCodeGen { ...@@ -170,7 +170,7 @@ impl UrlAssetReferenceCodeGen {
*/ */
pub async fn code_generation( pub async fn code_generation(
&self, &self,
module_graph: Vc<ModuleGraph>, _module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<CodeGeneration> { ) -> Result<CodeGeneration> {
let mut visitors = vec![]; let mut visitors = vec![];
...@@ -191,10 +191,7 @@ impl UrlAssetReferenceCodeGen { ...@@ -191,10 +191,7 @@ impl UrlAssetReferenceCodeGen {
ReferencedAsset::Some(asset) => { ReferencedAsset::Some(asset) => {
// We rewrite the first `new URL()` arguments to be a require() of the chunk // We rewrite the first `new URL()` arguments to be a require() of the chunk
// item, which exports the static asset path to the linked file. // item, which exports the static asset path to the linked file.
let id = asset let id = asset.chunk_item_id(Vc::upcast(chunking_context)).await?;
.as_chunk_item(module_graph, Vc::upcast(chunking_context))
.id()
.await?;
visitors.push(create_visitor!(self.path, visit_mut_expr(new_expr: &mut Expr) { visitors.push(create_visitor!(self.path, visit_mut_expr(new_expr: &mut Expr) {
let should_rewrite_to_relative = if let Expr::New(NewExpr { args: Some(args), .. }) = new_expr { let should_rewrite_to_relative = if let Expr::New(NewExpr { args: Some(args), .. }) = new_expr {
...@@ -259,10 +256,7 @@ impl UrlAssetReferenceCodeGen { ...@@ -259,10 +256,7 @@ impl UrlAssetReferenceCodeGen {
ReferencedAsset::Some(asset) => { ReferencedAsset::Some(asset) => {
// We rewrite the first `new URL()` arguments to be a require() of the // We rewrite the first `new URL()` arguments to be a require() of the
// chunk item, which returns the asset path as its exports. // chunk item, which returns the asset path as its exports.
let id = asset let id = asset.chunk_item_id(Vc::upcast(chunking_context)).await?;
.as_chunk_item(module_graph, Vc::upcast(chunking_context))
.id()
.await?;
// If there's a rewrite to the base url, then the current rendering // If there's a rewrite to the base url, then the current rendering
// environment should able to resolve the asset path // environment should able to resolve the asset path
......
...@@ -245,11 +245,6 @@ impl ChunkItem for CachedExternalModuleChunkItem { ...@@ -245,11 +245,6 @@ impl ChunkItem for CachedExternalModuleChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for CachedExternalModuleChunkItem { impl EcmascriptChunkItem for CachedExternalModuleChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn content(self: Vc<Self>) -> Vc<EcmascriptChunkItemContent> { fn content(self: Vc<Self>) -> Vc<EcmascriptChunkItemContent> {
panic!("content() should not be called"); panic!("content() should not be called");
......
...@@ -16,12 +16,11 @@ use turbo_tasks::{ ...@@ -16,12 +16,11 @@ use turbo_tasks::{
TryJoinIterExt, Vc, TryJoinIterExt, Vc,
}; };
use turbopack_core::{ use turbopack_core::{
chunk::{ChunkItemExt, ChunkableModule, ChunkingContext, ModuleId}, chunk::{ChunkableModule, ChunkingContext, ModuleChunkItemIdExt, ModuleId},
issue::{ issue::{
code_gen::CodeGenerationIssue, module::emit_unknown_module_type_error, IssueExt, code_gen::CodeGenerationIssue, module::emit_unknown_module_type_error, IssueExt,
IssueSeverity, StyledString, IssueSeverity, StyledString,
}, },
module_graph::ModuleGraph,
resolve::{ resolve::{
origin::ResolveOrigin, parse::Request, ExternalType, ModuleResolveResult, origin::ResolveOrigin, parse::Request, ExternalType, ModuleResolveResult,
ModuleResolveResultItem, ModuleResolveResultItem,
...@@ -321,7 +320,6 @@ impl PatternMapping { ...@@ -321,7 +320,6 @@ impl PatternMapping {
async fn to_single_pattern_mapping( async fn to_single_pattern_mapping(
origin: Vc<Box<dyn ResolveOrigin>>, origin: Vc<Box<dyn ResolveOrigin>>,
module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
resolve_item: &ModuleResolveResultItem, resolve_item: &ModuleResolveResultItem,
resolve_type: ResolveType, resolve_type: ResolveType,
...@@ -374,8 +372,8 @@ async fn to_single_pattern_mapping( ...@@ -374,8 +372,8 @@ async fn to_single_pattern_mapping(
return Ok(SinglePatternMapping::ModuleLoader(loader_id.owned().await?)); return Ok(SinglePatternMapping::ModuleLoader(loader_id.owned().await?));
} }
ResolveType::ChunkItem => { ResolveType::ChunkItem => {
let chunk_item = chunkable.as_chunk_item(module_graph, chunking_context); let item_id = chunkable.chunk_item_id(chunking_context);
return Ok(SinglePatternMapping::Module(chunk_item.id().owned().await?)); return Ok(SinglePatternMapping::Module(item_id.owned().await?));
} }
} }
} }
...@@ -402,7 +400,6 @@ impl PatternMapping { ...@@ -402,7 +400,6 @@ impl PatternMapping {
pub async fn resolve_request( pub async fn resolve_request(
request: Vc<Request>, request: Vc<Request>,
origin: Vc<Box<dyn ResolveOrigin>>, origin: Vc<Box<dyn ResolveOrigin>>,
module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
resolve_result: Vc<ModuleResolveResult>, resolve_result: Vc<ModuleResolveResult>,
resolve_type: ResolveType, resolve_type: ResolveType,
...@@ -415,14 +412,9 @@ impl PatternMapping { ...@@ -415,14 +412,9 @@ impl PatternMapping {
.cell()), .cell()),
1 => { 1 => {
let resolve_item = result.primary.first().unwrap().1; let resolve_item = result.primary.first().unwrap().1;
let single_pattern_mapping = to_single_pattern_mapping( let single_pattern_mapping =
origin, to_single_pattern_mapping(origin, chunking_context, resolve_item, resolve_type)
module_graph, .await?;
chunking_context,
resolve_item,
resolve_type,
)
.await?;
Ok(PatternMapping::Single(single_pattern_mapping).cell()) Ok(PatternMapping::Single(single_pattern_mapping).cell())
} }
_ => { _ => {
...@@ -435,14 +427,9 @@ impl PatternMapping { ...@@ -435,14 +427,9 @@ impl PatternMapping {
set.insert(request).then(|| (request.to_string(), v)) set.insert(request).then(|| (request.to_string(), v))
}) })
.map(|(k, v)| async move { .map(|(k, v)| async move {
let single_pattern_mapping = to_single_pattern_mapping( let single_pattern_mapping =
origin, to_single_pattern_mapping(origin, chunking_context, v, resolve_type)
module_graph, .await?;
chunking_context,
v,
resolve_type,
)
.await?;
Ok((k, single_pattern_mapping)) Ok((k, single_pattern_mapping))
}) })
.try_join() .try_join()
......
...@@ -22,8 +22,8 @@ use turbo_tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemPath}; ...@@ -22,8 +22,8 @@ use turbo_tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemPath};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ chunk::{
ChunkItem, ChunkItemExt, ChunkType, ChunkableModule, ChunkableModuleReference, ChunkItem, ChunkType, ChunkableModule, ChunkableModuleReference, ChunkingContext,
ChunkingContext, ModuleChunkItemIdExt,
}, },
ident::AssetIdent, ident::AssetIdent,
issue::IssueSource, issue::IssueSource,
...@@ -311,15 +311,15 @@ pub struct RequireContextAssetReferenceCodeGen { ...@@ -311,15 +311,15 @@ pub struct RequireContextAssetReferenceCodeGen {
impl RequireContextAssetReferenceCodeGen { impl RequireContextAssetReferenceCodeGen {
pub async fn code_generation( pub async fn code_generation(
&self, &self,
module_graph: Vc<ModuleGraph>, _module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<CodeGeneration> { ) -> Result<CodeGeneration> {
let chunk_item = self let module_id = self
.reference .reference
.await? .await?
.inner .inner
.as_chunk_item(module_graph, Vc::upcast(chunking_context)); .chunk_item_id(Vc::upcast(chunking_context))
let module_id = chunk_item.id().owned().await?; .await?;
let mut visitors = Vec::new(); let mut visitors = Vec::new();
...@@ -457,11 +457,6 @@ pub struct RequireContextChunkItem { ...@@ -457,11 +457,6 @@ pub struct RequireContextChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for RequireContextChunkItem { impl EcmascriptChunkItem for RequireContextChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> {
let map = &*self.map.await?; let map = &*self.map.await?;
...@@ -475,7 +470,6 @@ impl EcmascriptChunkItem for RequireContextChunkItem { ...@@ -475,7 +470,6 @@ impl EcmascriptChunkItem for RequireContextChunkItem {
let pm = PatternMapping::resolve_request( let pm = PatternMapping::resolve_request(
*entry.request, *entry.request,
*self.origin, *self.origin,
*self.module_graph,
*ResolvedVc::upcast(self.chunking_context), *ResolvedVc::upcast(self.chunking_context),
*entry.result, *entry.result,
ResolveType::ChunkItem, ResolveType::ChunkItem,
......
...@@ -76,7 +76,6 @@ impl EcmascriptChunkItem for EcmascriptModuleFacadeChunkItem { ...@@ -76,7 +76,6 @@ impl EcmascriptChunkItem for EcmascriptModuleFacadeChunkItem {
.code_generation( .code_generation(
async_module_info, async_module_info,
self.module.references(), self.module.references(),
*self.module_graph,
*chunking_context, *chunking_context,
) )
.await?, .await?,
...@@ -117,11 +116,6 @@ impl EcmascriptChunkItem for EcmascriptModuleFacadeChunkItem { ...@@ -117,11 +116,6 @@ impl EcmascriptChunkItem for EcmascriptModuleFacadeChunkItem {
} }
.cell()) .cell())
} }
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
......
...@@ -82,7 +82,7 @@ impl EcmascriptModuleFacadeModule { ...@@ -82,7 +82,7 @@ impl EcmascriptModuleFacadeModule {
.esm_evaluation_references .esm_evaluation_references
.await? .await?
.iter() .iter()
.map(|r| r.code_generation(module_graph, chunking_context)) .map(|r| r.code_generation(chunking_context))
.try_join() .try_join()
.await?; .await?;
code_gens.push( code_gens.push(
...@@ -106,7 +106,7 @@ impl EcmascriptModuleFacadeModule { ...@@ -106,7 +106,7 @@ impl EcmascriptModuleFacadeModule {
.esm_reexport_references .esm_reexport_references
.await? .await?
.iter() .iter()
.map(|r| r.code_generation(module_graph, chunking_context)) .map(|r| r.code_generation(chunking_context))
.try_join() .try_join()
.await?; .await?;
code_gens.push( code_gens.push(
......
...@@ -76,11 +76,6 @@ impl EcmascriptChunkItem for EcmascriptModuleLocalsChunkItem { ...@@ -76,11 +76,6 @@ impl EcmascriptChunkItem for EcmascriptModuleLocalsChunkItem {
async_module_options, async_module_options,
)) ))
} }
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
......
...@@ -4,8 +4,8 @@ use turbo_rcstr::RcStr; ...@@ -4,8 +4,8 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc}; use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbopack_core::{ use turbopack_core::{
chunk::{ chunk::{
ChunkItemExt, ChunkableModule, ChunkableModuleReference, ChunkingContext, ChunkingType, ChunkableModuleReference, ChunkingContext, ChunkingType, ChunkingTypeOption,
ChunkingTypeOption, ModuleChunkItemIdExt,
}, },
module::Module, module::Module,
module_graph::ModuleGraph, module_graph::ModuleGraph,
...@@ -112,23 +112,20 @@ impl ChunkableModuleReference for EcmascriptModulePartReference { ...@@ -112,23 +112,20 @@ impl ChunkableModuleReference for EcmascriptModulePartReference {
impl EcmascriptModulePartReference { impl EcmascriptModulePartReference {
pub async fn code_generation( pub async fn code_generation(
self: Vc<Self>, self: Vc<Self>,
module_graph: Vc<ModuleGraph>, _module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<CodeGeneration> { ) -> Result<CodeGeneration> {
let referenced_asset = ReferencedAsset::from_resolve_result(self.resolve_reference()); let referenced_asset = ReferencedAsset::from_resolve_result(self.resolve_reference());
let referenced_asset = referenced_asset.await?; let referenced_asset = referenced_asset.await?;
let ident = referenced_asset let ident = referenced_asset
.get_ident(module_graph, chunking_context) .get_ident(chunking_context)
.await? .await?
.context("part module reference should have an ident")?; .context("part module reference should have an ident")?;
let ReferencedAsset::Some(module) = *referenced_asset else { let ReferencedAsset::Some(module) = *referenced_asset else {
bail!("part module reference should have an module reference"); bail!("part module reference should have an module reference");
}; };
let id = module let id = module.chunk_item_id(Vc::upcast(chunking_context)).await?;
.as_chunk_item(module_graph, Vc::upcast(chunking_context))
.id()
.await?;
Ok(CodeGeneration::hoisted_stmt( Ok(CodeGeneration::hoisted_stmt(
ident.clone().into(), ident.clone().into(),
......
...@@ -2,9 +2,7 @@ use anyhow::Result; ...@@ -2,9 +2,7 @@ use anyhow::Result;
use turbo_tasks::{ResolvedVc, ValueDefault, Vc}; use turbo_tasks::{ResolvedVc, ValueDefault, Vc};
use turbo_tasks_fs::rope::RopeBuilder; use turbo_tasks_fs::rope::RopeBuilder;
use turbopack_core::{ use turbopack_core::{
chunk::{ chunk::{AsyncModuleInfo, ChunkItem, ChunkType, ChunkingContext, ModuleChunkItemIdExt},
AsyncModuleInfo, ChunkItem, ChunkItemExt, ChunkType, ChunkableModule, ChunkingContext,
},
ident::AssetIdent, ident::AssetIdent,
module::Module, module::Module,
module_graph::ModuleGraph, module_graph::ModuleGraph,
...@@ -85,11 +83,6 @@ impl EcmascriptChunkItem for EcmascriptModulePartChunkItem { ...@@ -85,11 +83,6 @@ impl EcmascriptChunkItem for EcmascriptModulePartChunkItem {
async_module_options, async_module_options,
)) ))
} }
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
...@@ -175,12 +168,7 @@ impl EcmascriptChunkItem for SideEffectsModuleChunkItem { ...@@ -175,12 +168,7 @@ impl EcmascriptChunkItem for SideEffectsModuleChunkItem {
format!( format!(
"{}{TURBOPACK_IMPORT}({});\n", "{}{TURBOPACK_IMPORT}({});\n",
if need_await { "await " } else { "" }, if need_await { "await " } else { "" },
StringifyModuleId( StringifyModuleId(&*side_effect.chunk_item_id(*self.chunking_context).await?)
&*side_effect
.as_chunk_item(*self.module_graph, *self.chunking_context)
.id()
.await?
)
) )
.as_bytes(), .as_bytes(),
); );
...@@ -192,8 +180,7 @@ impl EcmascriptChunkItem for SideEffectsModuleChunkItem { ...@@ -192,8 +180,7 @@ impl EcmascriptChunkItem for SideEffectsModuleChunkItem {
StringifyModuleId( StringifyModuleId(
&*module &*module
.resolved_as .resolved_as
.as_chunk_item(*self.module_graph, *self.chunking_context) .chunk_item_id(*self.chunking_context)
.id()
.await? .await?
) )
) )
...@@ -222,9 +209,4 @@ impl EcmascriptChunkItem for SideEffectsModuleChunkItem { ...@@ -222,9 +209,4 @@ impl EcmascriptChunkItem for SideEffectsModuleChunkItem {
} }
.cell()) .cell())
} }
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
} }
...@@ -73,11 +73,6 @@ impl WorkerLoaderChunkItem { ...@@ -73,11 +73,6 @@ impl WorkerLoaderChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for WorkerLoaderChunkItem { impl EcmascriptChunkItem for WorkerLoaderChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(self: Vc<Self>) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(self: Vc<Self>) -> Result<Vc<EcmascriptChunkItemContent>> {
let chunks_data = self.chunks_data().await?; let chunks_data = self.chunks_data().await?;
......
...@@ -121,11 +121,6 @@ impl ChunkItem for JsonChunkItem { ...@@ -121,11 +121,6 @@ impl ChunkItem for JsonChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for JsonChunkItem { impl EcmascriptChunkItem for JsonChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> {
// We parse to JSON and then stringify again to ensure that the // We parse to JSON and then stringify again to ensure that the
......
...@@ -7,7 +7,7 @@ use turbo_tasks::{ResolvedVc, ValueToString, Vc}; ...@@ -7,7 +7,7 @@ use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{File, FileSystemPath}; use turbo_tasks_fs::{File, FileSystemPath};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ChunkItemExt, ChunkableModule, ChunkingContext, EvaluatableAssets}, chunk::{ChunkingContext, EvaluatableAssets, ModuleChunkItemIdExt},
code_builder::{Code, CodeBuilder}, code_builder::{Code, CodeBuilder},
module_graph::ModuleGraph, module_graph::ModuleGraph,
output::{OutputAsset, OutputAssets}, output::{OutputAsset, OutputAssets},
...@@ -115,8 +115,7 @@ impl EcmascriptBuildNodeEntryChunk { ...@@ -115,8 +115,7 @@ impl EcmascriptBuildNodeEntryChunk {
ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(*evaluatable_asset) ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(*evaluatable_asset)
{ {
let runtime_module_id = placeable let runtime_module_id = placeable
.as_chunk_item(*this.module_graph, Vc::upcast(*this.chunking_context)) .chunk_item_id(Vc::upcast(*this.chunking_context))
.id()
.await?; .await?;
writedoc!( writedoc!(
...@@ -131,8 +130,7 @@ impl EcmascriptBuildNodeEntryChunk { ...@@ -131,8 +130,7 @@ impl EcmascriptBuildNodeEntryChunk {
let runtime_module_id = this let runtime_module_id = this
.exported_module .exported_module
.as_chunk_item(*this.module_graph, Vc::upcast(*this.chunking_context)) .chunk_item_id(Vc::upcast(*this.chunking_context))
.id()
.await?; .await?;
writedoc!( writedoc!(
......
...@@ -148,11 +148,6 @@ impl ChunkItem for ModuleChunkItem { ...@@ -148,11 +148,6 @@ impl ChunkItem for ModuleChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for ModuleChunkItem { impl EcmascriptChunkItem for ModuleChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> {
Ok(EcmascriptChunkItemContent { Ok(EcmascriptChunkItemContent {
......
...@@ -242,11 +242,6 @@ impl ChunkItem for ModuleChunkItem { ...@@ -242,11 +242,6 @@ impl ChunkItem for ModuleChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for ModuleChunkItem { impl EcmascriptChunkItem for ModuleChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn content(self: Vc<Self>) -> Vc<EcmascriptChunkItemContent> { fn content(self: Vc<Self>) -> Vc<EcmascriptChunkItemContent> {
panic!("content() should not be called"); panic!("content() should not be called");
......
...@@ -142,11 +142,6 @@ impl ChunkItem for RawModuleChunkItem { ...@@ -142,11 +142,6 @@ impl ChunkItem for RawModuleChunkItem {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptChunkItem for RawModuleChunkItem { impl EcmascriptChunkItem for RawModuleChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> { async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> {
let path = self.wasm_asset.path().await?; let path = self.wasm_asset.path().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