Unverified Commit 51e00434 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

[Turbopack] Compute module batches and use them for chunking (#76133)

### What?

Compute module batches and refactor chunking to work on the batches graph instead of the modules graph

With many pages we run into the problem that each page has a lot of modules, even if the total amount of modules is not super high. This multiples the number of edges needed in our graph.

To reduce that, group modules to module batches and module batches to batch groups and query information on these batches resp. batch groups to reduce the work needed.

A module batch will be formed from modules that are always used in a specific execution order.
A batch group will be formed from module batches that are in the same chunk groups.

Usually we work with module batches in a certain order and a unordered list of batch groups. We query information from the batch group and sort the results based on the order of module batches.
parent dbb19c55
......@@ -9215,6 +9215,7 @@ dependencies = [
"serde_json",
"serde_regex",
"shrink-to-fit",
"smallvec",
"thiserror",
"tokio",
"tokio-util",
......@@ -9539,6 +9540,7 @@ name = "turbopack-browser"
version = "0.1.0"
dependencies = [
"anyhow",
"either",
"indexmap 2.7.1",
"indoc",
"rustc-hash 2.1.0",
......@@ -9641,6 +9643,7 @@ dependencies = [
"serde",
"serde_bytes",
"serde_json",
"smallvec",
"sourcemap",
"swc_core 16.0.0",
"tokio",
......@@ -9752,6 +9755,7 @@ dependencies = [
"rustc-hash 2.1.0",
"serde",
"serde_json",
"smallvec",
"sourcemap",
"strsim 0.11.1",
"swc_core 16.0.0",
......@@ -9931,10 +9935,12 @@ name = "turbopack-nodejs"
version = "0.1.0"
dependencies = [
"anyhow",
"either",
"indexmap 2.7.1",
"indoc",
"rustc-hash 2.1.0",
"serde",
"smallvec",
"tracing",
"turbo-rcstr",
"turbo-tasks",
......
......@@ -1902,10 +1902,23 @@ impl Endpoint for AppEndpoint {
#[turbo_tasks::function]
async fn entries(self: Vc<Self>) -> Result<Vc<GraphEntries>> {
Ok(Vc::cell(vec![(
vec![self.app_endpoint_entry().await?.rsc_entry],
ChunkGroupType::Entry,
)]))
let this = self.await?;
Ok(Vc::cell(vec![
(
vec![self.app_endpoint_entry().await?.rsc_entry],
ChunkGroupType::Entry,
),
(
this.app_project
.client_runtime_entries()
.await?
.iter()
.copied()
.map(ResolvedVc::upcast)
.collect(),
ChunkGroupType::Entry,
),
]))
}
#[turbo_tasks::function]
......
......@@ -2,7 +2,7 @@ use anyhow::Result;
use serde::Serialize;
use turbo_rcstr::RcStr;
use turbo_tasks::{FxIndexMap, FxIndexSet, ResolvedVc, Vc};
use turbopack_browser::ecmascript::EcmascriptDevChunk;
use turbopack_browser::ecmascript::EcmascriptBrowserChunk;
use turbopack_core::{
chunk::{Chunk, ChunkItem},
output::OutputAsset,
......@@ -27,7 +27,7 @@ where
continue;
};
if let Some(chunk) = ResolvedVc::try_downcast_type::<EcmascriptDevChunk>(*asset) {
if let Some(chunk) = ResolvedVc::try_downcast_type::<EcmascriptBrowserChunk>(*asset) {
let chunk_ident = normalize_client_path(&chunk.path().await?.path);
chunks.push(WebpackStatsChunk {
size: asset_len,
......
......@@ -13,6 +13,7 @@ name = "mod"
harness = false
[features]
default = []
# Enables dynamic linking (and hot reloading) of embedded files/dirs.
# A binary built with this option **is not portable**, the directory
# path will be embedded into the binary.
......
......@@ -42,6 +42,7 @@ serde = { workspace = true, features = ["rc", "derive"] }
serde_json = { workspace = true }
serde_regex = "1.1.0"
shrink-to-fit = { workspace=true,features = ["indexmap", "serde_json", "smallvec", "nightly"] }
smallvec = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"] }
tokio-util = { workspace = true }
......
use std::fmt::{Debug, Display};
use auto_hash_map::{AutoMap, AutoSet};
use smallvec::SmallVec;
use turbo_rcstr::RcStr;
use turbo_tasks::{FxIndexMap, FxIndexSet, Vc};
pub use turbo_tasks_macros::ValueDebugFormat;
......@@ -157,6 +158,37 @@ where
}
}
impl<T, const N: usize> ValueDebugFormat for SmallVec<[T; N]>
where
T: ValueDebugFormat,
{
fn value_debug_format(&self, depth: usize) -> ValueDebugFormatString {
if depth == 0 {
return ValueDebugFormatString::Sync(std::any::type_name::<Self>().to_string());
}
let values = self
.iter()
.map(|value| value.value_debug_format(depth.saturating_sub(1)))
.collect::<Vec<_>>();
ValueDebugFormatString::Async(Box::pin(async move {
let mut values_string = vec![];
for value in values {
match value {
ValueDebugFormatString::Sync(string) => {
values_string.push(PassthroughDebug::new_string(string));
}
ValueDebugFormatString::Async(future) => {
values_string.push(PassthroughDebug::new_string(future.await?));
}
}
}
Ok(format!("{:#?}", values_string))
}))
}
}
impl<K> ValueDebugFormat for AutoSet<K>
where
K: ValueDebugFormat,
......
......@@ -47,6 +47,7 @@ macro_rules! impl_auto_marker_trait {
unsafe impl<T: $trait> $trait for ::std::option::Option<T> {}
unsafe impl<T: $trait> $trait for ::std::vec::Vec<T> {}
unsafe impl<T: $trait, const N: usize> $trait for ::smallvec::SmallVec<[T; N]> {}
unsafe impl<T: $trait, const N: usize> $trait for [T; N] {}
unsafe impl<T: $trait> $trait for [T] {}
unsafe impl<T: $trait, S> $trait for ::std::collections::HashSet<T, S> {}
......
......@@ -11,6 +11,7 @@ use std::{
use auto_hash_map::{AutoMap, AutoSet};
use either::Either;
use indexmap::{IndexMap, IndexSet};
use smallvec::SmallVec;
use turbo_rcstr::RcStr;
use crate::RawVc;
......@@ -130,6 +131,14 @@ impl<T: TraceRawVcs> TraceRawVcs for Box<[T]> {
}
}
impl<T: TraceRawVcs, const N: usize> TraceRawVcs for SmallVec<[T; N]> {
fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) {
for item in self.iter() {
TraceRawVcs::trace_raw_vcs(item, trace_context);
}
}
}
impl<T: TraceRawVcs, const N: usize> TraceRawVcs for [T; N] {
fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) {
for item in self.iter() {
......
......@@ -4,6 +4,7 @@ use std::{
future::IntoFuture,
hash::{Hash, Hasher},
marker::PhantomData,
mem::transmute,
ops::Deref,
};
......@@ -205,6 +206,20 @@ where
node: Vc::upcast(this.node),
}
}
/// Cheaply converts a Vec of resolved Vcs to a Vec of Vcs.
pub fn deref_vec(vec: Vec<ResolvedVc<T>>) -> Vec<Vc<T>> {
debug_assert!(size_of::<ResolvedVc<T>>() == size_of::<Vc<T>>());
// Safety: The memory layout of `ResolvedVc<T>` and `Vc<T>` is the same.
unsafe { transmute::<Vec<ResolvedVc<T>>, Vec<Vc<T>>>(vec) }
}
/// Cheaply converts a slice of resolved Vcs to a slice of Vcs.
pub fn deref_slice(slice: &[ResolvedVc<T>]) -> &[Vc<T>] {
debug_assert!(size_of::<ResolvedVc<T>>() == size_of::<Vc<T>>());
// Safety: The memory layout of `ResolvedVc<T>` and `Vc<T>` is the same.
unsafe { transmute::<&[ResolvedVc<T>], &[Vc<T>]>(slice) }
}
}
impl<T> ResolvedVc<T>
......
......@@ -20,6 +20,7 @@ workspace = true
[dependencies]
anyhow = { workspace = true }
either = { workspace = true }
indexmap = { workspace = true }
indoc = { workspace = true }
rustc-hash = { workspace = true }
......
......@@ -27,8 +27,8 @@ use turbopack_ecmascript::{
use turbopack_ecmascript_runtime::RuntimeType;
use crate::ecmascript::{
chunk::EcmascriptDevChunk,
evaluate::chunk::EcmascriptDevEvaluateChunk,
chunk::EcmascriptBrowserChunk,
evaluate::chunk::EcmascriptBrowserEvaluateChunk,
list::asset::{EcmascriptDevChunkList, EcmascriptDevChunkListSource},
};
......@@ -236,7 +236,7 @@ impl BrowserChunkingContext {
// TODO(sokra) remove this argument and pass chunk items instead
module_graph: Vc<ModuleGraph>,
) -> Vc<Box<dyn OutputAsset>> {
Vc::upcast(EcmascriptDevEvaluateChunk::new(
Vc::upcast(EcmascriptBrowserEvaluateChunk::new(
self,
ident,
other_chunks,
......@@ -271,7 +271,7 @@ impl BrowserChunkingContext {
if let Some(ecmascript_chunk) =
Vc::try_resolve_downcast_type::<EcmascriptChunk>(chunk).await?
{
Vc::upcast(EcmascriptDevChunk::new(self, ecmascript_chunk))
Vc::upcast(EcmascriptBrowserChunk::new(self, ecmascript_chunk))
} else if let Some(output_asset) =
Vc::try_resolve_sidecast::<Box<dyn OutputAsset>>(chunk).await?
{
......
......@@ -12,24 +12,24 @@ use turbopack_core::{
};
use turbopack_ecmascript::chunk::EcmascriptChunk;
use crate::{ecmascript::content::EcmascriptDevChunkContent, BrowserChunkingContext};
use crate::{ecmascript::content::EcmascriptBrowserChunkContent, BrowserChunkingContext};
/// Development Ecmascript chunk.
#[turbo_tasks::value(shared)]
pub struct EcmascriptDevChunk {
pub struct EcmascriptBrowserChunk {
chunking_context: ResolvedVc<BrowserChunkingContext>,
chunk: ResolvedVc<EcmascriptChunk>,
}
#[turbo_tasks::value_impl]
impl EcmascriptDevChunk {
impl EcmascriptBrowserChunk {
/// Creates a new [`Vc<EcmascriptDevChunk>`].
#[turbo_tasks::function]
pub fn new(
chunking_context: ResolvedVc<BrowserChunkingContext>,
chunk: ResolvedVc<EcmascriptChunk>,
) -> Vc<Self> {
EcmascriptDevChunk {
EcmascriptBrowserChunk {
chunking_context,
chunk,
}
......@@ -38,7 +38,7 @@ impl EcmascriptDevChunk {
}
#[turbo_tasks::value_impl]
impl ValueToString for EcmascriptDevChunk {
impl ValueToString for EcmascriptBrowserChunk {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell("Ecmascript Dev Chunk".into())
......@@ -46,7 +46,7 @@ impl ValueToString for EcmascriptDevChunk {
}
#[turbo_tasks::value_impl]
impl OutputChunk for EcmascriptDevChunk {
impl OutputChunk for EcmascriptBrowserChunk {
#[turbo_tasks::function]
async fn runtime_info(&self) -> Result<Vc<OutputChunkRuntimeInfo>> {
Ok(OutputChunkRuntimeInfo {
......@@ -63,11 +63,11 @@ fn modifier() -> Vc<RcStr> {
}
#[turbo_tasks::value_impl]
impl EcmascriptDevChunk {
impl EcmascriptBrowserChunk {
#[turbo_tasks::function]
async fn own_content(self: Vc<Self>) -> Result<Vc<EcmascriptDevChunkContent>> {
async fn own_content(self: Vc<Self>) -> Result<Vc<EcmascriptBrowserChunkContent>> {
let this = self.await?;
Ok(EcmascriptDevChunkContent::new(
Ok(EcmascriptBrowserChunkContent::new(
*this.chunking_context,
self,
this.chunk.chunk_content(),
......@@ -81,7 +81,7 @@ impl EcmascriptDevChunk {
}
#[turbo_tasks::value_impl]
impl OutputAsset for EcmascriptDevChunk {
impl OutputAsset for EcmascriptBrowserChunk {
#[turbo_tasks::function]
fn path(&self) -> Vc<FileSystemPath> {
let ident = self.chunk.ident().with_modifier(modifier());
......@@ -117,7 +117,7 @@ impl OutputAsset for EcmascriptDevChunk {
}
#[turbo_tasks::value_impl]
impl Asset for EcmascriptDevChunk {
impl Asset for EcmascriptBrowserChunk {
#[turbo_tasks::function]
fn content(self: Vc<Self>) -> Vc<AssetContent> {
self.own_content().content()
......@@ -130,7 +130,7 @@ impl Asset for EcmascriptDevChunk {
}
#[turbo_tasks::value_impl]
impl GenerateSourceMap for EcmascriptDevChunk {
impl GenerateSourceMap for EcmascriptBrowserChunk {
#[turbo_tasks::function]
fn generate_source_map(self: Vc<Self>) -> Vc<OptionStringifiedSourceMap> {
self.own_content().generate_source_map()
......@@ -153,7 +153,7 @@ fn introspectable_details() -> Vc<RcStr> {
}
#[turbo_tasks::value_impl]
impl Introspectable for EcmascriptDevChunk {
impl Introspectable for EcmascriptBrowserChunk {
#[turbo_tasks::function]
fn ty(&self) -> Vc<RcStr> {
introspectable_type()
......
......@@ -16,51 +16,48 @@ use turbopack_core::{
use turbopack_ecmascript::{chunk::EcmascriptChunkContent, minify::minify, utils::StringifyJs};
use super::{
chunk::EcmascriptDevChunk, content_entry::EcmascriptDevChunkContentEntries,
merged::merger::EcmascriptDevChunkContentMerger, version::EcmascriptDevChunkVersion,
chunk::EcmascriptBrowserChunk, content_entry::EcmascriptBrowserChunkContentEntries,
merged::merger::EcmascriptBrowserChunkContentMerger, version::EcmascriptBrowserChunkVersion,
};
use crate::BrowserChunkingContext;
#[turbo_tasks::value(serialization = "none")]
pub struct EcmascriptDevChunkContent {
pub(super) entries: ResolvedVc<EcmascriptDevChunkContentEntries>,
pub struct EcmascriptBrowserChunkContent {
pub(super) chunking_context: ResolvedVc<BrowserChunkingContext>,
pub(super) chunk: ResolvedVc<EcmascriptDevChunk>,
pub(super) chunk: ResolvedVc<EcmascriptBrowserChunk>,
pub(super) content: ResolvedVc<EcmascriptChunkContent>,
}
#[turbo_tasks::value_impl]
impl EcmascriptDevChunkContent {
impl EcmascriptBrowserChunkContent {
#[turbo_tasks::function]
pub(crate) async fn new(
chunking_context: ResolvedVc<BrowserChunkingContext>,
chunk: ResolvedVc<EcmascriptDevChunk>,
content: Vc<EcmascriptChunkContent>,
chunk: ResolvedVc<EcmascriptBrowserChunk>,
content: ResolvedVc<EcmascriptChunkContent>,
) -> Result<Vc<Self>> {
let entries = EcmascriptDevChunkContentEntries::new(content)
.to_resolved()
.await?;
Ok(EcmascriptDevChunkContent {
entries,
Ok(EcmascriptBrowserChunkContent {
chunking_context,
chunk,
content,
}
.cell())
}
#[turbo_tasks::function]
pub fn entries(&self) -> Vc<EcmascriptDevChunkContentEntries> {
*self.entries
pub fn entries(&self) -> Vc<EcmascriptBrowserChunkContentEntries> {
EcmascriptBrowserChunkContentEntries::new(*self.content)
}
}
#[turbo_tasks::value_impl]
impl EcmascriptDevChunkContent {
impl EcmascriptBrowserChunkContent {
#[turbo_tasks::function]
pub(crate) fn own_version(&self) -> Vc<EcmascriptDevChunkVersion> {
EcmascriptDevChunkVersion::new(
pub(crate) fn own_version(&self) -> Vc<EcmascriptBrowserChunkVersion> {
EcmascriptBrowserChunkVersion::new(
self.chunking_context.output_root(),
self.chunk.path(),
*self.entries,
*self.content,
)
}
......@@ -99,10 +96,14 @@ impl EcmascriptDevChunkContent {
chunk_path = StringifyJs(chunk_server_path)
)?;
for (id, entry) in this.entries.await?.iter() {
write!(code, "\n{}: ", StringifyJs(&id))?;
code.push_code(&*entry.code.await?);
write!(code, ",")?;
let content = this.content.await?;
let chunk_items = content.chunk_item_code_and_ids().await?;
for item in chunk_items {
for (id, item_code) in item {
write!(code, "\n{}: ", StringifyJs(&id))?;
code.push_code(item_code);
write!(code, ",")?;
}
}
write!(code, "\n}}]);")?;
......@@ -129,7 +130,7 @@ impl EcmascriptDevChunkContent {
}
#[turbo_tasks::value_impl]
impl VersionedContent for EcmascriptDevChunkContent {
impl VersionedContent for EcmascriptBrowserChunkContent {
#[turbo_tasks::function]
async fn content(self: Vc<Self>) -> Result<Vc<AssetContent>> {
let code = self.code().await?;
......@@ -145,26 +146,27 @@ impl VersionedContent for EcmascriptDevChunkContent {
}
#[turbo_tasks::value_impl]
impl MergeableVersionedContent for EcmascriptDevChunkContent {
impl MergeableVersionedContent for EcmascriptBrowserChunkContent {
#[turbo_tasks::function]
fn get_merger(&self) -> Vc<Box<dyn VersionedContentMerger>> {
Vc::upcast(EcmascriptDevChunkContentMerger::new())
Vc::upcast(EcmascriptBrowserChunkContentMerger::new())
}
}
#[turbo_tasks::value_impl]
impl GenerateSourceMap for EcmascriptDevChunkContent {
impl GenerateSourceMap for EcmascriptBrowserChunkContent {
#[turbo_tasks::function]
fn generate_source_map(self: Vc<Self>) -> Vc<OptionStringifiedSourceMap> {
self.code().generate_source_map()
}
#[turbo_tasks::function]
async fn by_section(&self, section: RcStr) -> Result<Vc<OptionStringifiedSourceMap>> {
async fn by_section(self: Vc<Self>, section: RcStr) -> Result<Vc<OptionStringifiedSourceMap>> {
// Weirdly, the ContentSource will have already URL decoded the ModuleId, and we
// can't reparse that via serde.
if let Ok(id) = ModuleId::parse(&section) {
for (entry_id, entry) in self.entries.await?.iter() {
let entries = self.entries().await?;
for (entry_id, entry) in entries.iter() {
if id == **entry_id {
let sm = entry.code.generate_source_map();
return Ok(sm);
......
use anyhow::Result;
use tracing::{info_span, Instrument};
use turbo_tasks::{FxIndexMap, ReadRef, ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use either::Either;
use turbo_tasks::{FxIndexMap, ReadRef, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc};
use turbopack_core::{
chunk::{AsyncModuleInfo, ChunkItem, ChunkItemExt, ModuleId},
chunk::{AsyncModuleInfo, ChunkItemExt, ModuleId},
code_builder::Code,
};
use turbopack_ecmascript::chunk::{
EcmascriptChunkContent, EcmascriptChunkItem, EcmascriptChunkItemExt,
EcmascriptChunkItemWithAsyncInfo,
EcmascriptChunkItemOrBatchWithAsyncInfo, EcmascriptChunkItemWithAsyncInfo,
};
/// A chunk item's content entry.
......@@ -37,44 +37,60 @@ impl EcmascriptDevChunkContentEntry {
}
#[turbo_tasks::value(transparent)]
pub struct EcmascriptDevChunkContentEntries(
pub struct EcmascriptBrowserChunkContentEntries(
FxIndexMap<ReadRef<ModuleId>, EcmascriptDevChunkContentEntry>,
);
#[turbo_tasks::value_impl]
impl EcmascriptDevChunkContentEntries {
impl EcmascriptBrowserChunkContentEntries {
#[turbo_tasks::function]
pub async fn new(
chunk_content: Vc<EcmascriptChunkContent>,
) -> Result<Vc<EcmascriptDevChunkContentEntries>> {
) -> Result<Vc<EcmascriptBrowserChunkContentEntries>> {
let chunk_content = chunk_content.await?;
let entries: FxIndexMap<_, _> = chunk_content
.chunk_items
.iter()
.map(
|&EcmascriptChunkItemWithAsyncInfo {
chunk_item,
async_info,
}| async move {
async move {
Ok((
chunk_item.id().await?,
EcmascriptDevChunkContentEntry::new(
chunk_item,
async_info.map(|info| *info),
)
.await?,
))
.map(async |item| {
Ok(match item {
&EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem(
EcmascriptChunkItemWithAsyncInfo {
chunk_item,
async_info,
},
) => Either::Left(std::iter::once((
chunk_item.id().await?,
EcmascriptDevChunkContentEntry::new(
chunk_item,
async_info.map(|info| *info),
)
.await?,
))),
EcmascriptChunkItemOrBatchWithAsyncInfo::Batch(batch) => {
let batch = batch.await?;
Either::Right(
batch
.chunk_items
.iter()
.map(|item| async move {
Ok((
item.chunk_item.id().await?,
EcmascriptDevChunkContentEntry::new(
item.chunk_item,
item.async_info.map(|info| *info),
)
.await?,
))
})
.try_join()
.await?
.into_iter(),
)
}
.instrument(info_span!(
"chunk item",
name = display(chunk_item.asset_ident().to_string().await?)
))
.await
},
)
.try_join()
})
})
.try_flat_join()
.await?
.into_iter()
.collect();
......
......@@ -29,10 +29,10 @@ use turbopack_ecmascript_runtime::RuntimeType;
use crate::BrowserChunkingContext;
/// An Ecmascript chunk that:
/// * Contains the Turbopack dev runtime code; and
/// * Contains the Turbopack browser runtime code; and
/// * Evaluates a list of runtime entries.
#[turbo_tasks::value(shared)]
pub(crate) struct EcmascriptDevEvaluateChunk {
pub(crate) struct EcmascriptBrowserEvaluateChunk {
chunking_context: ResolvedVc<BrowserChunkingContext>,
ident: ResolvedVc<AssetIdent>,
other_chunks: ResolvedVc<OutputAssets>,
......@@ -43,8 +43,8 @@ pub(crate) struct EcmascriptDevEvaluateChunk {
}
#[turbo_tasks::value_impl]
impl EcmascriptDevEvaluateChunk {
/// Creates a new [`Vc<EcmascriptDevEvaluateChunk>`].
impl EcmascriptBrowserEvaluateChunk {
/// Creates a new [`Vc<EcmascriptBrowserEvaluateChunk>`].
#[turbo_tasks::function]
pub fn new(
chunking_context: ResolvedVc<BrowserChunkingContext>,
......@@ -53,7 +53,7 @@ impl EcmascriptDevEvaluateChunk {
evaluatable_assets: ResolvedVc<EvaluatableAssets>,
module_graph: ResolvedVc<ModuleGraph>,
) -> Vc<Self> {
EcmascriptDevEvaluateChunk {
EcmascriptBrowserEvaluateChunk {
chunking_context,
ident,
other_chunks,
......@@ -124,7 +124,7 @@ impl EcmascriptDevEvaluateChunk {
.flatten()
.collect();
let params = EcmascriptDevChunkRuntimeParams {
let params = EcmascriptBrowserChunkRuntimeParams {
other_chunks: &other_chunks_data,
runtime_module_ids,
};
......@@ -197,20 +197,20 @@ impl EcmascriptDevEvaluateChunk {
}
#[turbo_tasks::value_impl]
impl ValueToString for EcmascriptDevEvaluateChunk {
impl ValueToString for EcmascriptBrowserEvaluateChunk {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell("Ecmascript Dev Evaluate Chunk".into())
Vc::cell("Ecmascript Browser Evaluate Chunk".into())
}
}
#[turbo_tasks::function]
fn modifier() -> Vc<RcStr> {
Vc::cell("ecmascript dev evaluate chunk".into())
Vc::cell("ecmascript browser evaluate chunk".into())
}
#[turbo_tasks::value_impl]
impl OutputAsset for EcmascriptDevEvaluateChunk {
impl OutputAsset for EcmascriptBrowserEvaluateChunk {
#[turbo_tasks::function]
async fn path(&self) -> Result<Vc<FileSystemPath>> {
let mut ident = self.ident.owned().await?;
......@@ -264,7 +264,7 @@ impl OutputAsset for EcmascriptDevEvaluateChunk {
}
#[turbo_tasks::value_impl]
impl Asset for EcmascriptDevEvaluateChunk {
impl Asset for EcmascriptBrowserEvaluateChunk {
#[turbo_tasks::function]
async fn content(self: Vc<Self>) -> Result<Vc<AssetContent>> {
let code = self.code().await?;
......@@ -275,7 +275,7 @@ impl Asset for EcmascriptDevEvaluateChunk {
}
#[turbo_tasks::value_impl]
impl GenerateSourceMap for EcmascriptDevEvaluateChunk {
impl GenerateSourceMap for EcmascriptBrowserEvaluateChunk {
#[turbo_tasks::function]
fn generate_source_map(self: Vc<Self>) -> Vc<OptionStringifiedSourceMap> {
self.code().generate_source_map()
......@@ -284,7 +284,7 @@ impl GenerateSourceMap for EcmascriptDevEvaluateChunk {
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
struct EcmascriptDevChunkRuntimeParams<'a, T> {
struct EcmascriptBrowserChunkRuntimeParams<'a, T> {
/// Other chunks in the chunk group this chunk belongs to, if any. Does not
/// include the chunk itself.
///
......
......@@ -6,8 +6,8 @@ use turbopack_core::{
};
use super::{
super::content::EcmascriptDevChunkContent, update::update_ecmascript_merged_chunk,
version::EcmascriptDevMergedChunkVersion,
super::content::EcmascriptBrowserChunkContent, update::update_ecmascript_merged_chunk,
version::EcmascriptBrowserMergedChunkVersion,
};
/// Composite [`EcmascriptChunkContent`] that is the result of merging multiple
......@@ -16,15 +16,15 @@ use super::{
///
/// [`EcmascriptChunkContentMerger`]: super::merger::EcmascriptChunkContentMerger
#[turbo_tasks::value(serialization = "none", shared)]
pub(super) struct EcmascriptDevMergedChunkContent {
pub contents: Vec<ResolvedVc<EcmascriptDevChunkContent>>,
pub(super) struct EcmascriptBrowserMergedChunkContent {
pub contents: Vec<ResolvedVc<EcmascriptBrowserChunkContent>>,
}
#[turbo_tasks::value_impl]
impl EcmascriptDevMergedChunkContent {
impl EcmascriptBrowserMergedChunkContent {
#[turbo_tasks::function]
pub async fn version(&self) -> Result<Vc<EcmascriptDevMergedChunkVersion>> {
Ok(EcmascriptDevMergedChunkVersion {
pub async fn version(&self) -> Result<Vc<EcmascriptBrowserMergedChunkVersion>> {
Ok(EcmascriptBrowserMergedChunkVersion {
versions: self
.contents
.iter()
......@@ -37,7 +37,7 @@ impl EcmascriptDevMergedChunkContent {
}
#[turbo_tasks::value_impl]
impl VersionedContent for EcmascriptDevMergedChunkContent {
impl VersionedContent for EcmascriptBrowserMergedChunkContent {
#[turbo_tasks::function]
fn content(self: Vc<Self>) -> Result<Vc<AssetContent>> {
bail!("EcmascriptDevMergedChunkContent does not have content")
......
......@@ -2,25 +2,27 @@ use anyhow::{bail, Result};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
use turbopack_core::version::{VersionedContent, VersionedContentMerger, VersionedContents};
use super::{super::content::EcmascriptDevChunkContent, content::EcmascriptDevMergedChunkContent};
use super::{
super::content::EcmascriptBrowserChunkContent, content::EcmascriptBrowserMergedChunkContent,
};
/// Merges multiple [`EcmascriptChunkContent`] into a single
/// [`EcmascriptDevMergedChunkContent`]. This is useful for generating a single
/// update for multiple ES chunks updating all at the same time.
#[turbo_tasks::value]
pub(crate) struct EcmascriptDevChunkContentMerger;
pub(crate) struct EcmascriptBrowserChunkContentMerger;
#[turbo_tasks::value_impl]
impl EcmascriptDevChunkContentMerger {
impl EcmascriptBrowserChunkContentMerger {
/// Creates a new [`EcmascriptDevChunkContentMerger`].
#[turbo_tasks::function]
pub fn new() -> Vc<Self> {
Self::cell(EcmascriptDevChunkContentMerger)
Self::cell(EcmascriptBrowserChunkContentMerger)
}
}
#[turbo_tasks::value_impl]
impl VersionedContentMerger for EcmascriptDevChunkContentMerger {
impl VersionedContentMerger for EcmascriptBrowserChunkContentMerger {
#[turbo_tasks::function]
async fn merge(
&self,
......@@ -31,18 +33,18 @@ impl VersionedContentMerger for EcmascriptDevChunkContentMerger {
.iter()
.map(|content| async move {
if let Some(content) =
ResolvedVc::try_downcast_type::<EcmascriptDevChunkContent>(*content)
ResolvedVc::try_downcast_type::<EcmascriptBrowserChunkContent>(*content)
{
Ok(content)
} else {
bail!("expected Vc<EcmascriptDevChunkContent>")
bail!("expected Vc<EcmascriptBrowserChunkContent>")
}
})
.try_join()
.await?;
Ok(Vc::upcast(
EcmascriptDevMergedChunkContent { contents }.cell(),
EcmascriptBrowserMergedChunkContent { contents }.cell(),
))
}
}
......@@ -15,10 +15,10 @@ use turbopack_core::{
use super::{
super::{
update::{update_ecmascript_chunk, EcmascriptChunkUpdate},
version::EcmascriptDevChunkVersion,
version::EcmascriptBrowserChunkVersion,
},
content::EcmascriptDevMergedChunkContent,
version::EcmascriptDevMergedChunkVersion,
content::EcmascriptBrowserMergedChunkContent,
version::EcmascriptBrowserMergedChunkVersion,
};
#[derive(Serialize, Default)]
......@@ -108,12 +108,12 @@ impl EcmascriptModuleEntry {
/// versions, without having to actually merge the versions into a single
/// hashmap, which would be expensive.
struct MergedModuleMap {
versions: Vec<ReadRef<EcmascriptDevChunkVersion>>,
versions: Vec<ReadRef<EcmascriptBrowserChunkVersion>>,
}
impl MergedModuleMap {
/// Creates a new `MergedModuleMap` from the given versions.
fn new(versions: Vec<ReadRef<EcmascriptDevChunkVersion>>) -> Self {
fn new(versions: Vec<ReadRef<EcmascriptBrowserChunkVersion>>) -> Self {
Self { versions }
}
......@@ -130,12 +130,12 @@ impl MergedModuleMap {
}
pub(super) async fn update_ecmascript_merged_chunk(
content: Vc<EcmascriptDevMergedChunkContent>,
content: Vc<EcmascriptBrowserMergedChunkContent>,
from_version: Vc<Box<dyn Version>>,
) -> Result<Update> {
let to_merged_version = content.version();
let from_merged_version = if let Some(from) =
Vc::try_resolve_downcast_type::<EcmascriptDevMergedChunkVersion>(from_version).await?
Vc::try_resolve_downcast_type::<EcmascriptBrowserMergedChunkVersion>(from_version).await?
{
from
} else {
......@@ -170,17 +170,18 @@ pub(super) async fn update_ecmascript_merged_chunk(
.contents
.iter()
.map(|content| async move {
let entries = content.entries().await?;
let content_ref = content.await?;
let output_root = content_ref.chunking_context.output_root().await?;
let path = content_ref.chunk.path().await?;
Ok((*content, content_ref, output_root, path))
Ok((*content, entries, output_root, path))
})
.try_join()
.await?;
let mut merged_update = EcmascriptMergedUpdate::default();
for (content, content_ref, output_root, path) in &to_contents {
for (content, entries, output_root, path) in &to_contents {
let Some(chunk_path) = output_root.get_path_to(path) else {
continue;
};
......@@ -230,7 +231,7 @@ pub(super) async fn update_ecmascript_merged_chunk(
// The chunk was added in this version.
let mut added = EcmascriptMergedChunkAdded::default();
for (id, entry) in &content_ref.entries.await? {
for (id, entry) in entries {
let hash = *entry.hash.await?;
added.modules.insert(id.clone());
......
......@@ -4,18 +4,18 @@ use turbo_tasks::{ReadRef, TryJoinIterExt, Vc};
use turbo_tasks_hash::{encode_hex, Xxh3Hash64Hasher};
use turbopack_core::version::Version;
use super::super::version::EcmascriptDevChunkVersion;
use super::super::version::EcmascriptBrowserChunkVersion;
/// The version of a [`super::content::EcmascriptMergedChunkContent`]. This is
/// essentially a composite [`EcmascriptChunkVersion`].
#[turbo_tasks::value(serialization = "none", shared)]
pub(super) struct EcmascriptDevMergedChunkVersion {
pub(super) struct EcmascriptBrowserMergedChunkVersion {
#[turbo_tasks(trace_ignore)]
pub(super) versions: Vec<ReadRef<EcmascriptDevChunkVersion>>,
pub(super) versions: Vec<ReadRef<EcmascriptBrowserChunkVersion>>,
}
#[turbo_tasks::value_impl]
impl Version for EcmascriptDevMergedChunkVersion {
impl Version for EcmascriptBrowserMergedChunkVersion {
#[turbo_tasks::function]
async fn id(&self) -> Result<Vc<RcStr>> {
let mut hasher = Xxh3Hash64Hasher::new();
......
......@@ -7,5 +7,5 @@ pub(crate) mod merged;
pub(crate) mod update;
pub(crate) mod version;
pub use chunk::EcmascriptDevChunk;
pub use content::EcmascriptDevChunkContent;
pub use chunk::EcmascriptBrowserChunk;
pub use content::EcmascriptBrowserChunkContent;
......@@ -2,7 +2,7 @@ use anyhow::Result;
use turbo_tasks::{FxIndexMap, ReadRef, ResolvedVc, Vc};
use turbopack_core::{chunk::ModuleId, code_builder::Code};
use super::{content::EcmascriptDevChunkContent, version::EcmascriptDevChunkVersion};
use super::{content::EcmascriptBrowserChunkContent, version::EcmascriptBrowserChunkVersion};
#[allow(clippy::large_enum_variant)]
pub(super) enum EcmascriptChunkUpdate {
......@@ -17,8 +17,8 @@ pub(super) struct EcmascriptChunkPartialUpdate {
}
pub(super) async fn update_ecmascript_chunk(
content: Vc<EcmascriptDevChunkContent>,
from: &ReadRef<EcmascriptDevChunkVersion>,
content: Vc<EcmascriptBrowserChunkContent>,
from: &ReadRef<EcmascriptBrowserChunkVersion>,
) -> Result<EcmascriptChunkUpdate> {
let to = content.own_version().await?;
......@@ -29,9 +29,7 @@ pub(super) async fn update_ecmascript_chunk(
return Ok(EcmascriptChunkUpdate::None);
}
let content = content.await?;
let entries = content.entries.await?;
let entries = content.entries().await?;
let mut added = FxIndexMap::default();
let mut modified = FxIndexMap::default();
let mut deleted = FxIndexMap::default();
......
......@@ -4,22 +4,23 @@ use turbo_tasks::{FxIndexMap, ReadRef, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbo_tasks_hash::{encode_hex, Xxh3Hash64Hasher};
use turbopack_core::{chunk::ModuleId, version::Version};
use turbopack_ecmascript::chunk::EcmascriptChunkContent;
use super::content_entry::EcmascriptDevChunkContentEntries;
use super::content_entry::EcmascriptBrowserChunkContentEntries;
#[turbo_tasks::value(serialization = "none")]
pub(super) struct EcmascriptDevChunkVersion {
pub(super) struct EcmascriptBrowserChunkVersion {
pub(super) chunk_path: String,
pub(super) entries_hashes: FxIndexMap<ReadRef<ModuleId>, u64>,
}
#[turbo_tasks::value_impl]
impl EcmascriptDevChunkVersion {
impl EcmascriptBrowserChunkVersion {
#[turbo_tasks::function]
pub async fn new(
output_root: Vc<FileSystemPath>,
chunk_path: Vc<FileSystemPath>,
entries: Vc<EcmascriptDevChunkContentEntries>,
content: Vc<EcmascriptChunkContent>,
) -> Result<Vc<Self>> {
let output_root = output_root.await?;
let chunk_path = chunk_path.await?;
......@@ -32,13 +33,13 @@ impl EcmascriptDevChunkVersion {
output_root.to_string()
);
};
let entries = entries.await?;
let entries = EcmascriptBrowserChunkContentEntries::new(content).await?;
let mut entries_hashes =
FxIndexMap::with_capacity_and_hasher(entries.len(), Default::default());
for (id, entry) in entries.iter() {
entries_hashes.insert(id.clone(), *entry.hash.await?);
}
Ok(EcmascriptDevChunkVersion {
Ok(EcmascriptBrowserChunkVersion {
chunk_path: chunk_path.to_string(),
entries_hashes,
}
......@@ -47,7 +48,7 @@ impl EcmascriptDevChunkVersion {
}
#[turbo_tasks::value_impl]
impl Version for EcmascriptDevChunkVersion {
impl Version for EcmascriptBrowserChunkVersion {
#[turbo_tasks::function]
fn id(&self) -> Vc<RcStr> {
let mut hasher = Xxh3Hash64Hasher::new();
......
......@@ -32,6 +32,7 @@ regex = { workspace = true }
serde = { workspace = true, features = ["rc"] }
serde_bytes = { workspace = true }
serde_json = { workspace = true, features = ["preserve_order"] }
smallvec = { workspace = true }
sourcemap = { workspace = true }
swc_core = { workspace = true, features = ["ecma_preset_env", "common"] }
tracing = { workspace = true }
......
use anyhow::Result;
use turbo_tasks::{ResolvedVc, Vc};
use super::available_modules::{AvailableModuleInfoMap, AvailableModules};
use super::available_modules::{AvailableModules, AvailableModulesSet};
#[turbo_tasks::value(serialization = "auto_for_input")]
#[derive(Hash, Clone, Copy, Debug)]
......@@ -27,7 +27,7 @@ impl AvailabilityInfo {
}
}
pub async fn with_modules(self, modules: Vc<AvailableModuleInfoMap>) -> Result<Self> {
pub async fn with_modules(self, modules: Vc<AvailableModulesSet>) -> Result<Self> {
Ok(match self {
AvailabilityInfo::Untracked => AvailabilityInfo::Untracked,
AvailabilityInfo::Root => AvailabilityInfo::Complete {
......
use anyhow::Result;
use turbo_tasks::{FxIndexSet, ReadRef, ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks::{FxIndexSet, ReadRef, ResolvedVc, TryJoinIterExt, Vc};
use turbo_tasks_hash::Xxh3Hash64Hasher;
use super::ChunkableModule;
use crate::module::Module;
use crate::module_graph::module_batch::{ChunkableModuleOrBatch, IdentStrings};
#[turbo_tasks::value(transparent)]
#[derive(Debug, Clone)]
pub struct AvailableModuleInfoMap(FxIndexSet<ResolvedVc<Box<dyn ChunkableModule>>>);
pub struct AvailableModulesSet(FxIndexSet<ChunkableModuleOrBatch>);
/// Allows to gather information about which assets are already available.
/// Adding more roots will form a linked list like structure to allow caching
......@@ -15,13 +14,13 @@ pub struct AvailableModuleInfoMap(FxIndexSet<ResolvedVc<Box<dyn ChunkableModule>
#[turbo_tasks::value]
pub struct AvailableModules {
parent: Option<ResolvedVc<AvailableModules>>,
modules: ResolvedVc<AvailableModuleInfoMap>,
modules: ResolvedVc<AvailableModulesSet>,
}
#[turbo_tasks::value_impl]
impl AvailableModules {
#[turbo_tasks::function]
pub fn new(modules: ResolvedVc<AvailableModuleInfoMap>) -> Vc<Self> {
pub fn new(modules: ResolvedVc<AvailableModulesSet>) -> Vc<Self> {
AvailableModules {
parent: None,
modules,
......@@ -32,7 +31,7 @@ impl AvailableModules {
#[turbo_tasks::function]
pub async fn with_modules(
self: ResolvedVc<Self>,
modules: ResolvedVc<AvailableModuleInfoMap>,
modules: ResolvedVc<AvailableModulesSet>,
) -> Result<Vc<Self>> {
Ok(AvailableModules {
parent: Some(self),
......@@ -53,22 +52,30 @@ impl AvailableModules {
.modules
.await?
.iter()
.map(|module| module.ident().to_string())
.map(|&module| module.ident_strings())
.try_join()
.await?;
for ident in item_idents {
hasher.write_value(ident);
for idents in item_idents {
match idents {
IdentStrings::Single(ident) => hasher.write_value(ident),
IdentStrings::Multiple(idents) => {
for ident in idents {
hasher.write_value(ident);
}
}
IdentStrings::None => {}
}
}
Ok(Vc::cell(hasher.finish()))
}
#[turbo_tasks::function]
pub async fn get(&self, module: ResolvedVc<Box<dyn ChunkableModule>>) -> Result<Vc<bool>> {
if self.modules.await?.contains(&module) {
pub async fn get(&self, module_or_batch: ChunkableModuleOrBatch) -> Result<Vc<bool>> {
if self.modules.await?.contains(&module_or_batch) {
return Ok(Vc::cell(true));
};
if let Some(parent) = self.parent {
return Ok(parent.get(*module));
return Ok(parent.get(module_or_batch));
}
Ok(Vc::cell(false))
}
......@@ -90,15 +97,15 @@ impl AvailableModules {
#[derive(Debug, Clone)]
pub struct AvailableModulesSnapshot {
parent: Option<ReadRef<AvailableModulesSnapshot>>,
modules: ReadRef<AvailableModuleInfoMap>,
modules: ReadRef<AvailableModulesSet>,
}
impl AvailableModulesSnapshot {
pub fn get(&self, module: ResolvedVc<Box<dyn ChunkableModule>>) -> bool {
self.modules.contains(&module)
pub fn get(&self, module_or_batch: ChunkableModuleOrBatch) -> bool {
self.modules.contains(&module_or_batch)
|| self
.parent
.as_ref()
.is_some_and(|parent| parent.get(module))
.is_some_and(|parent| parent.get(module_or_batch))
}
}
This diff is collapsed.
use std::{borrow::Cow, mem::take};
use anyhow::Result;
use anyhow::{bail, Result};
use either::Either;
use once_cell::sync::Lazy;
use regex::Regex;
use tracing::Level;
use turbo_tasks::FxIndexMap;
use turbo_tasks::{FxIndexMap, ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use crate::chunk::chunking::{make_chunk, ChunkItemWithInfo, SplitContext};
use crate::chunk::{
chunking::{make_chunk, ChunkItemOrBatchWithInfo, SplitContext},
ChunkItem, ChunkItemWithAsyncModuleInfo, ChunkType, ChunkingContext,
};
/// Handle chunk items based on their total size. If the total size is too
/// small, they will be pushed into `remaining`, if possible. If the total size
/// is too large, it will return `false` and the caller should hand of the chunk
/// items to be further split. Otherwise it creates a chunk.
async fn handle_split_group(
chunk_items: &mut Vec<ChunkItemWithInfo>,
async fn handle_split_group<'l>(
chunk_items: &mut Vec<&'l ChunkItemOrBatchWithInfo>,
key: &mut String,
split_context: &mut SplitContext<'_>,
remaining: Option<&mut Vec<ChunkItemWithInfo>>,
remaining: Option<&mut Vec<&'l ChunkItemOrBatchWithInfo>>,
) -> Result<bool> {
Ok(match (chunk_size(chunk_items), remaining) {
(ChunkSize::Large, _) => false,
(ChunkSize::Perfect, _) | (ChunkSize::Small, None) => {
make_chunk(take(chunk_items), key, split_context).await?;
make_chunk(take(chunk_items), Vec::new(), key, split_context).await?;
true
}
(ChunkSize::Small, Some(remaining)) => {
......@@ -31,11 +35,51 @@ async fn handle_split_group(
})
}
/// Expands all batches and ensures that there are only terminal ChunkItems left.
pub async fn expand_batches(
chunk_items: Vec<&ChunkItemOrBatchWithInfo>,
ty: ResolvedVc<Box<dyn ChunkType>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<Vec<ChunkItemOrBatchWithInfo>> {
let mut expanded = Vec::new();
for item in chunk_items {
match item {
ChunkItemOrBatchWithInfo::ChunkItem { .. } => {
expanded.push(item.clone());
}
ChunkItemOrBatchWithInfo::Batch { batch, .. } => {
expanded.extend(
batch
.await?
.chunk_items
.iter()
.map(async |item| {
let size = ty.chunk_item_size(
chunking_context,
*item.chunk_item,
item.async_info.map(|i| *i),
);
let asset_ident = item.chunk_item.asset_ident().to_string();
Ok(ChunkItemOrBatchWithInfo::ChunkItem {
chunk_item: item.clone(),
size: *size.await?,
asset_ident: asset_ident.owned().await?,
})
})
.try_join()
.await?,
);
}
}
}
Ok(expanded)
}
/// Split chunk items into app code and vendor code. Continues splitting with
/// [package_name_split] if necessary.
#[tracing::instrument(level = Level::TRACE, skip_all, fields(name = display(&name)))]
pub async fn app_vendors_split(
chunk_items: Vec<ChunkItemWithInfo>,
pub async fn app_vendors_split<'l>(
chunk_items: Vec<&'l ChunkItemOrBatchWithInfo>,
mut name: String,
split_context: &mut SplitContext<'_>,
) -> Result<()> {
......@@ -43,11 +87,14 @@ pub async fn app_vendors_split(
let mut app_chunk_items = Vec::new();
let mut vendors_chunk_items = Vec::new();
for item in chunk_items {
let ChunkItemWithInfo {
let ChunkItemOrBatchWithInfo::ChunkItem {
chunk_item: ChunkItemWithAsyncModuleInfo { module, .. },
asset_ident,
module,
..
} = &item;
} = &item
else {
bail!("Batch items are not supported");
};
if module.is_none() {
// This happens for async module loaders.
// We want them to be in a separate chunk.
......@@ -60,7 +107,13 @@ pub async fn app_vendors_split(
}
if !chunk_group_specific_chunk_items.is_empty() {
let mut name = format!("{}-specific", name);
make_chunk(chunk_group_specific_chunk_items, &mut name, split_context).await?;
make_chunk(
chunk_group_specific_chunk_items,
Vec::new(),
&mut name,
split_context,
)
.await?;
}
let mut remaining = Vec::new();
let mut key = format!("{}-app", name);
......@@ -96,14 +149,16 @@ pub async fn app_vendors_split(
/// Split chunk items by node_modules package name. Continues splitting with
/// [folder_split] if necessary.
#[tracing::instrument(level = Level::TRACE, skip_all, fields(name = display(&name)))]
async fn package_name_split(
chunk_items: Vec<ChunkItemWithInfo>,
async fn package_name_split<'l>(
chunk_items: Vec<&'l ChunkItemOrBatchWithInfo>,
mut name: String,
split_context: &mut SplitContext<'_>,
) -> Result<()> {
let mut map = FxIndexMap::<_, Vec<ChunkItemWithInfo>>::default();
let mut map = FxIndexMap::<_, Vec<_>>::default();
for item in chunk_items {
let ChunkItemWithInfo { asset_ident, .. } = &item;
let ChunkItemOrBatchWithInfo::ChunkItem { asset_ident, .. } = &item else {
bail!("Batch items are not supported");
};
let package_name = package_name(asset_ident);
if let Some(list) = map.get_mut(package_name) {
list.push(item);
......@@ -128,16 +183,23 @@ async fn package_name_split(
/// Split chunk items by folder structure.
#[tracing::instrument(level = Level::TRACE, skip_all, fields(name = display(&name), location))]
async fn folder_split(
mut chunk_items: Vec<ChunkItemWithInfo>,
async fn folder_split<'l>(
chunk_items: Vec<&'l ChunkItemOrBatchWithInfo>,
mut location: usize,
name: Cow<'_, str>,
split_context: &mut SplitContext<'_>,
) -> Result<()> {
let mut map = FxIndexMap::<_, (_, Vec<ChunkItemWithInfo>)>::default();
let mut map = FxIndexMap::<_, (_, Vec<_>)>::default();
let mut chunk_items: Either<_, Vec<&'l ChunkItemOrBatchWithInfo>> = Either::Left(chunk_items);
loop {
for item in chunk_items {
let ChunkItemWithInfo { asset_ident, .. } = &item;
let iter = match chunk_items {
Either::Left(iter) => Either::Left(iter.into_iter()),
Either::Right(list) => Either::Right(list.into_iter()),
};
for item in iter {
let ChunkItemOrBatchWithInfo::ChunkItem { asset_ident, .. } = &item else {
bail!("Batch items are not supported");
};
let (folder_name, new_location) = folder_name(asset_ident, location);
if let Some((_, list)) = map.get_mut(folder_name) {
list.push(item);
......@@ -149,13 +211,13 @@ async fn folder_split(
// shortcut
let (folder_name, (new_location, list)) = map.into_iter().next().unwrap();
if let Some(new_location) = new_location {
chunk_items = list;
chunk_items = Either::Right(list);
location = new_location;
map = FxIndexMap::default();
continue;
} else {
let mut key = format!("{}-{}", name, folder_name);
make_chunk(list, &mut key, split_context).await?;
make_chunk(list, Vec::new(), &mut key, split_context).await?;
return Ok(());
}
} else {
......@@ -175,15 +237,17 @@ async fn folder_split(
))
.await?;
} else {
make_chunk(list, &mut key, split_context).await?;
make_chunk(list, Vec::new(), &mut key, split_context).await?;
}
}
}
if !remaining.is_empty() {
let ChunkItemWithInfo { asset_ident, .. } = &remaining[0];
let ChunkItemOrBatchWithInfo::ChunkItem { asset_ident, .. } = &remaining[0] else {
bail!("Batch items are not supported");
};
let mut key = format!("{}-{}", name, &asset_ident[..location]);
if !handle_split_group(&mut remaining, &mut key, split_context, None).await? {
make_chunk(remaining, &mut key, split_context).await?;
make_chunk(remaining, Vec::new(), &mut key, split_context).await?;
}
}
Ok(())
......@@ -227,10 +291,10 @@ enum ChunkSize {
/// Determines the total size of the passed chunk items. Returns too small, too
/// large or perfect fit.
fn chunk_size(chunk_items: &[ChunkItemWithInfo]) -> ChunkSize {
fn chunk_size(chunk_items: &[&ChunkItemOrBatchWithInfo]) -> ChunkSize {
let mut total_size = 0;
for ChunkItemWithInfo { size, .. } in chunk_items {
total_size += size;
for item in chunk_items {
total_size += item.size();
}
if total_size >= LARGE_CHUNK {
ChunkSize::Large
......
......@@ -12,7 +12,7 @@ use crate::{
environment::Environment,
ident::AssetIdent,
module::Module,
module_graph::{chunk_group_info::ChunkGroup, ModuleGraph},
module_graph::{chunk_group_info::ChunkGroup, module_batches::BatchingConfig, ModuleGraph},
output::{OutputAsset, OutputAssets},
};
......@@ -165,8 +165,10 @@ pub trait ChunkingContext {
Vc::cell(Default::default())
}
fn is_smart_chunk_enabled(self: Vc<Self>) -> Vc<bool> {
Vc::cell(false)
fn batching_config(self: Vc<Self>) -> Vc<BatchingConfig> {
BatchingConfig::new(BatchingConfig {
..Default::default()
})
}
fn is_tracing_enabled(self: Vc<Self>) -> Vc<bool> {
......
pub mod availability_info;
pub mod available_modules;
pub mod chunk_group;
pub(crate) mod chunk_item_batch;
pub mod chunking;
pub(crate) mod chunking_context;
pub(crate) mod containment_tree;
......@@ -22,6 +23,10 @@ use turbo_tasks::{
use turbo_tasks_hash::DeterministicHash;
pub use self::{
chunk_item_batch::{
batch_info, ChunkItemBatchGroup, ChunkItemBatchWithAsyncModuleInfo,
ChunkItemOrBatchWithAsyncModuleInfo,
},
chunking_context::{
ChunkGroupResult, ChunkGroupType, ChunkingConfig, ChunkingConfigs, ChunkingContext,
ChunkingContextExt, EntryChunkGroupResult, MinifyType, SourceMapsType,
......@@ -30,8 +35,15 @@ pub use self::{
evaluate::{EvaluatableAsset, EvaluatableAssetExt, EvaluatableAssets},
};
use crate::{
asset::Asset, ident::AssetIdent, module::Module, module_graph::ModuleGraph,
output::OutputAssets, reference::ModuleReference,
asset::Asset,
ident::AssetIdent,
module::Module,
module_graph::{
module_batch::{ChunkableModuleOrBatch, ModuleBatchGroup},
ModuleGraph,
},
output::OutputAssets,
reference::ModuleReference,
};
/// A module id, which can be a number or string
......@@ -202,6 +214,36 @@ impl ChunkingType {
ChunkingType::Traced => false,
}
}
pub fn is_parallel(&self) -> bool {
match self {
ChunkingType::Parallel => true,
ChunkingType::ParallelInheritAsync => true,
ChunkingType::Async => false,
ChunkingType::Isolated { .. } => false,
ChunkingType::Shared { .. } => false,
ChunkingType::Traced => false,
}
}
pub fn without_inherit_async(&self) -> Self {
match self {
ChunkingType::Parallel | ChunkingType::ParallelInheritAsync => ChunkingType::Parallel,
ChunkingType::Async => ChunkingType::Async,
ChunkingType::Isolated { _ty, merge_tag } => ChunkingType::Isolated {
_ty: *_ty,
merge_tag: merge_tag.clone(),
},
ChunkingType::Shared {
inherit_async: _,
merge_tag,
} => ChunkingType::Shared {
inherit_async: false,
merge_tag: merge_tag.clone(),
},
ChunkingType::Traced => ChunkingType::Traced,
}
}
}
#[turbo_tasks::value(transparent)]
......@@ -222,7 +264,8 @@ pub trait ChunkableModuleReference: ModuleReference + ValueToString {
#[derive(Default)]
pub struct ChunkGroupContent {
pub chunkable_modules: FxIndexSet<ResolvedVc<Box<dyn ChunkableModule>>>,
pub chunkable_items: FxIndexSet<ChunkableModuleOrBatch>,
pub batch_groups: FxIndexSet<ResolvedVc<ModuleBatchGroup>>,
pub async_modules: FxIndexSet<ResolvedVc<Box<dyn ChunkableModule>>>,
pub traced_modules: FxIndexSet<ResolvedVc<Box<dyn Module>>>,
}
......@@ -264,7 +307,8 @@ pub trait ChunkType: ValueToString {
fn chunk(
&self,
chunking_context: Vc<Box<dyn ChunkingContext>>,
chunk_items: Vec<ChunkItemWithAsyncModuleInfo>,
chunk_items: Vec<ChunkItemOrBatchWithAsyncModuleInfo>,
batch_groups: Vec<ResolvedVc<ChunkItemBatchGroup>>,
referenced_output_assets: Vc<OutputAssets>,
) -> Vc<Box<dyn Chunk>>;
......@@ -305,7 +349,6 @@ impl AsyncModuleInfo {
#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash, TraceRawVcs, TaskInput, NonLocalValue,
)]
// #[turbo_tasks::value]
pub struct ChunkItemWithAsyncModuleInfo {
pub chunk_item: ResolvedVc<Box<dyn ChunkItem>>,
pub module: Option<ResolvedVc<Box<dyn ChunkableModule>>>,
......
......@@ -139,7 +139,7 @@ pub enum ChunkGroup {
}
impl ChunkGroup {
pub fn entries(&self) -> impl Iterator<Item = ResolvedVc<Box<dyn Module>>> + '_ {
pub fn entries(&self) -> impl Iterator<Item = ResolvedVc<Box<dyn Module>>> + Clone + '_ {
match self {
ChunkGroup::Async(e) | ChunkGroup::Isolated(e) | ChunkGroup::Shared(e) => {
Either::Left(std::iter::once(*e))
......
......@@ -8,7 +8,7 @@ use petgraph::{
graph::{DiGraph, EdgeIndex, NodeIndex},
visit::{Dfs, EdgeRef, IntoNodeReferences, NodeIndexable, VisitMap, Visitable},
};
use rustc_hash::FxHashMap;
use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize};
use tracing::{Instrument, Span};
use turbo_rcstr::RcStr;
......@@ -26,6 +26,7 @@ use crate::{
module_graph::{
async_module_info::{compute_async_module_info, AsyncModulesInfo},
chunk_group_info::{compute_chunk_group_info, ChunkGroupInfo},
module_batches::{compute_module_batches, ModuleBatchesGraph},
traced_di_graph::{iter_neighbors_rev, TracedDiGraph},
},
reference::primary_chunkable_referenced_modules,
......@@ -33,8 +34,12 @@ use crate::{
pub mod async_module_info;
pub mod chunk_group_info;
pub mod module_batch;
pub(crate) mod module_batches;
mod traced_di_graph;
pub use self::module_batches::BatchingConfig;
#[derive(
Debug, Copy, Clone, Eq, PartialOrd, Ord, Hash, PartialEq, Serialize, Deserialize, TraceRawVcs,
)]
......@@ -509,7 +514,6 @@ impl SingleModuleGraph {
/// * `visit_postorder` - Called after visiting the children of a node. Return
/// - Receives: (originating &SingleModuleGraphNode, edge &ChunkingType), target
/// &SingleModuleGraphNode, state &S
/// - Can return [GraphTraversalAction]s to control the traversal
pub fn traverse_edges_from_entries_topological<'a, S>(
&'a self,
entries: impl IntoIterator<Item = ResolvedVc<Box<dyn Module>>>,
......@@ -537,7 +541,7 @@ impl SingleModuleGraph {
let mut stack: Vec<(TopologicalPass, Option<(NodeIndex, EdgeIndex)>, NodeIndex)> = entries
.map(|e| (TopologicalPass::ExpandAndVisit, None, e))
.collect();
let mut expanded = HashSet::new();
let mut expanded = FxHashSet::default();
while let Some((pass, parent, current)) = stack.pop() {
let parent_arg = parent.map(|parent| {
(
......@@ -721,6 +725,15 @@ impl ModuleGraph {
compute_chunk_group_info(self).await
}
#[turbo_tasks::function]
pub async fn module_batches(
self: Vc<Self>,
config: Vc<BatchingConfig>,
) -> Result<Vc<ModuleBatchesGraph>> {
// TODO dev: Return modules only
compute_module_batches(self, &*config.await?).await
}
#[turbo_tasks::function]
pub async fn async_module_info(self: Vc<Self>) -> Result<Vc<AsyncModulesInfo>> {
// `compute_async_module_info` calls `module.is_self_async()`, so we need to again ignore
......
use std::fmt::Debug;
use anyhow::Result;
use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr;
use turbo_tasks::{
trace::TraceRawVcs, NonLocalValue, ReadRef, ResolvedVc, TaskInput, TryJoinIterExt,
ValueToString, Vc,
};
use crate::{
chunk::ChunkableModule, module::Module, module_graph::chunk_group_info::RoaringBitmapWrapper,
};
#[derive(
Debug,
Copy,
Clone,
Hash,
PartialEq,
Eq,
Serialize,
Deserialize,
TraceRawVcs,
NonLocalValue,
TaskInput,
)]
pub enum ModuleOrBatch {
Module(ResolvedVc<Box<dyn Module>>),
Batch(ResolvedVc<ModuleBatch>),
None(usize),
}
#[derive(
Debug,
Copy,
Clone,
Hash,
PartialEq,
Eq,
Serialize,
Deserialize,
TraceRawVcs,
NonLocalValue,
TaskInput,
)]
pub enum ChunkableModuleOrBatch {
Module(ResolvedVc<Box<dyn ChunkableModule>>),
Batch(ResolvedVc<ModuleBatch>),
None(usize),
}
impl ChunkableModuleOrBatch {
pub fn from_module_or_batch(module_or_batch: ModuleOrBatch) -> Option<Self> {
match module_or_batch {
ModuleOrBatch::Module(module) => ResolvedVc::try_downcast(module).map(Self::Module),
ModuleOrBatch::Batch(batch) => Some(Self::Batch(batch)),
ModuleOrBatch::None(i) => Some(Self::None(i)),
}
}
pub async fn ident_strings(self) -> Result<IdentStrings> {
Ok(match self {
ChunkableModuleOrBatch::Module(module) => {
IdentStrings::Single(module.ident().to_string().await?)
}
ChunkableModuleOrBatch::Batch(batch) => {
IdentStrings::Multiple(batch.ident_strings().await?)
}
ChunkableModuleOrBatch::None(_) => IdentStrings::None,
})
}
}
impl From<ChunkableModuleOrBatch> for ModuleOrBatch {
fn from(chunkable_module_or_batch: ChunkableModuleOrBatch) -> Self {
match chunkable_module_or_batch {
ChunkableModuleOrBatch::Module(module) => Self::Module(ResolvedVc::upcast(module)),
ChunkableModuleOrBatch::Batch(batch) => Self::Batch(batch),
ChunkableModuleOrBatch::None(i) => Self::None(i),
}
}
}
pub enum IdentStrings {
None,
Single(ReadRef<RcStr>),
Multiple(ReadRef<Vec<RcStr>>),
}
impl Debug for IdentStrings {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
IdentStrings::None => write!(f, "None"),
IdentStrings::Single(ident) => ident.fmt(f),
IdentStrings::Multiple(idents) => idents.fmt(f),
}
}
}
#[turbo_tasks::value]
pub struct ModuleBatch {
pub modules: Vec<ResolvedVc<Box<dyn ChunkableModule>>>,
pub chunk_groups: Option<RoaringBitmapWrapper>,
}
#[turbo_tasks::value_impl]
impl ModuleBatch {
#[turbo_tasks::function]
pub fn new(
modules: Vec<ResolvedVc<Box<dyn ChunkableModule>>>,
chunk_groups: Option<RoaringBitmapWrapper>,
) -> Vc<Self> {
Self {
modules,
chunk_groups,
}
.cell()
}
#[turbo_tasks::function]
pub async fn ident_strings(&self) -> Result<Vc<Vec<RcStr>>> {
Ok(Vc::cell(
self.modules
.iter()
.map(|module| module.ident().to_string().owned())
.try_join()
.await?,
))
}
}
#[turbo_tasks::value]
pub struct ModuleBatchGroup {
pub items: Vec<ModuleOrBatch>,
pub chunk_groups: RoaringBitmapWrapper,
}
#[turbo_tasks::value_impl]
impl ModuleBatchGroup {
#[turbo_tasks::function]
pub fn new(items: Vec<ModuleOrBatch>, chunk_groups: RoaringBitmapWrapper) -> Vc<Self> {
Self {
items,
chunk_groups,
}
.cell()
}
}
#[turbo_tasks::value]
pub struct ChunkableModuleBatchGroup {
pub items: Vec<ChunkableModuleOrBatch>,
pub chunk_groups: RoaringBitmapWrapper,
}
#[turbo_tasks::value_impl]
impl ChunkableModuleBatchGroup {
#[turbo_tasks::function]
pub async fn from_module_batch_group(batch_group: Vc<ModuleBatchGroup>) -> Result<Vc<Self>> {
let batch_group = batch_group.await?;
let items = batch_group
.items
.iter()
.filter_map(|batch| match *batch {
ModuleOrBatch::Module(module) => {
ResolvedVc::try_downcast(module).map(ChunkableModuleOrBatch::Module)
}
ModuleOrBatch::Batch(batch) => Some(ChunkableModuleOrBatch::Batch(batch)),
ModuleOrBatch::None(_) => None,
})
.collect();
Ok(Self {
items,
chunk_groups: batch_group.chunk_groups.clone(),
}
.cell())
}
}
......@@ -9,7 +9,7 @@ use turbo_tasks::{
};
#[derive(Clone, Debug, ValueDebugFormat, Serialize, Deserialize)]
pub struct TracedDiGraph<N, E>(DiGraph<N, E>);
pub struct TracedDiGraph<N, E>(pub DiGraph<N, E>);
impl<N, E> Default for TracedDiGraph<N, E> {
fn default() -> Self {
Self(Default::default())
......
......@@ -13,8 +13,9 @@ use turbo_tasks_fs::{rope::Rope, File, FileSystem, FileSystemPath};
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{
round_chunk_item_size, AsyncModuleInfo, Chunk, ChunkItem, ChunkItemWithAsyncModuleInfo,
ChunkType, ChunkableModule, ChunkingContext, ModuleId, OutputChunk, OutputChunkRuntimeInfo,
round_chunk_item_size, AsyncModuleInfo, Chunk, ChunkItem, ChunkItemBatchGroup,
ChunkItemOrBatchWithAsyncModuleInfo, ChunkItemWithAsyncModuleInfo, ChunkType,
ChunkableModule, ChunkingContext, ModuleId, OutputChunk, OutputChunkRuntimeInfo,
},
code_builder::{Code, CodeBuilder},
ident::AssetIdent,
......@@ -496,9 +497,23 @@ impl ChunkType for CssChunkType {
async fn chunk(
&self,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
chunk_items: Vec<ChunkItemWithAsyncModuleInfo>,
chunk_items_or_batches: Vec<ChunkItemOrBatchWithAsyncModuleInfo>,
_batch_groups: Vec<ResolvedVc<ChunkItemBatchGroup>>,
referenced_output_assets: ResolvedVc<OutputAssets>,
) -> Result<Vc<Box<dyn Chunk>>> {
let mut chunk_items = Vec::new();
// TODO operate with batches
for item in chunk_items_or_batches {
match item {
ChunkItemOrBatchWithAsyncModuleInfo::ChunkItem(chunk_item) => {
chunk_items.push(chunk_item);
}
ChunkItemOrBatchWithAsyncModuleInfo::Batch(batch) => {
let batch = batch.await?;
chunk_items.extend(batch.chunk_items.iter().cloned());
}
}
}
let content = CssChunkContent {
chunk_items: chunk_items
.iter()
......
......@@ -30,6 +30,7 @@ rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sourcemap = { workspace = true }
smallvec = { workspace = true }
strsim = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
......
......@@ -9,7 +9,9 @@ use turbopack_core::{
},
ident::AssetIdent,
module::Module,
module_graph::{chunk_group_info::ChunkGroup, ModuleGraph},
module_graph::{
chunk_group_info::ChunkGroup, module_batch::ChunkableModuleOrBatch, ModuleGraph,
},
output::OutputAssets,
};
......@@ -36,8 +38,18 @@ impl AsyncLoaderChunkItem {
pub(super) async fn chunks(&self) -> Result<Vc<OutputAssets>> {
let module = self.module.await?;
if let Some(chunk_items) = module.availability_info.available_modules() {
if *chunk_items.get(*module.inner).await? {
return Ok(Vc::cell(vec![]));
let inner_module = ResolvedVc::upcast(module.inner);
let batches = self
.module_graph
.module_batches(self.chunking_context.batching_config())
.await?;
let module_or_batch = batches.get_entry(inner_module).await?;
if let Some(chunkable_module_or_batch) =
ChunkableModuleOrBatch::from_module_or_batch(module_or_batch)
{
if *chunk_items.get(chunkable_module_or_batch).await? {
return Ok(Vc::cell(vec![]));
}
}
}
Ok(self.chunking_context.chunk_group_assets(
......
use anyhow::Result;
use serde::{Deserialize, Serialize};
use turbo_tasks::{trace::TraceRawVcs, NonLocalValue, ResolvedVc, TaskInput, TryJoinIterExt, Vc};
use turbopack_core::{
chunk::{
ChunkItem, ChunkItemBatchGroup, ChunkItemBatchWithAsyncModuleInfo,
ChunkItemOrBatchWithAsyncModuleInfo,
},
output::OutputAssets,
};
use crate::chunk::EcmascriptChunkItemWithAsyncInfo;
#[derive(
Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, TaskInput,
)]
pub enum EcmascriptChunkItemOrBatchWithAsyncInfo {
ChunkItem(EcmascriptChunkItemWithAsyncInfo),
Batch(ResolvedVc<EcmascriptChunkBatchWithAsyncInfo>),
}
impl EcmascriptChunkItemOrBatchWithAsyncInfo {
pub async fn from_chunk_item_or_batch(
item: &ChunkItemOrBatchWithAsyncModuleInfo,
) -> Result<Self> {
Ok(match item {
ChunkItemOrBatchWithAsyncModuleInfo::ChunkItem(chunk_item) => {
EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem(
EcmascriptChunkItemWithAsyncInfo::from_chunk_item(chunk_item)?,
)
}
&ChunkItemOrBatchWithAsyncModuleInfo::Batch(batch) => {
EcmascriptChunkItemOrBatchWithAsyncInfo::Batch(
EcmascriptChunkBatchWithAsyncInfo::from_batch(*batch)
.to_resolved()
.await?,
)
}
})
}
pub fn references(&self) -> Vc<OutputAssets> {
match self {
EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem(item) => {
item.chunk_item.references()
}
EcmascriptChunkItemOrBatchWithAsyncInfo::Batch(batch) => batch.references(),
}
}
}
#[turbo_tasks::value]
pub struct EcmascriptChunkBatchWithAsyncInfo {
pub chunk_items: Vec<EcmascriptChunkItemWithAsyncInfo>,
}
#[turbo_tasks::value_impl]
impl EcmascriptChunkBatchWithAsyncInfo {
#[turbo_tasks::function]
pub async fn from_batch(batch: Vc<ChunkItemBatchWithAsyncModuleInfo>) -> Result<Vc<Self>> {
Ok(Self {
chunk_items: batch
.await?
.chunk_items
.iter()
.map(EcmascriptChunkItemWithAsyncInfo::from_chunk_item)
.collect::<Result<Vec<_>>>()?,
}
.cell())
}
#[turbo_tasks::function]
pub async fn references(&self) -> Result<Vc<OutputAssets>> {
let mut references = Vec::new();
// We expect most references to be empty, and avoiding try_join to avoid allocating the Vec
for item in &self.chunk_items {
references.extend(item.chunk_item.references().await?.into_iter().copied());
}
Ok(Vc::cell(references))
}
}
#[turbo_tasks::value]
pub struct EcmascriptChunkItemBatchGroup {
pub items: Vec<EcmascriptChunkItemOrBatchWithAsyncInfo>,
}
#[turbo_tasks::value_impl]
impl EcmascriptChunkItemBatchGroup {
#[turbo_tasks::function]
pub async fn from_chunk_item_batch_group(
batch_group: Vc<ChunkItemBatchGroup>,
) -> Result<Vc<Self>> {
Ok(Self {
items: batch_group
.await?
.items
.iter()
.map(EcmascriptChunkItemOrBatchWithAsyncInfo::from_chunk_item_or_batch)
.try_join()
.await?,
}
.cell())
}
}
use anyhow::{bail, Result};
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, ValueDefault, ValueToString, Vc};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueDefault, ValueToString, Vc};
use turbopack_core::{
chunk::{
round_chunk_item_size, AsyncModuleInfo, Chunk, ChunkItem, ChunkItemWithAsyncModuleInfo,
ChunkType, ChunkingContext,
round_chunk_item_size, AsyncModuleInfo, Chunk, ChunkItem, ChunkItemBatchGroup,
ChunkItemOrBatchWithAsyncModuleInfo, ChunkType, ChunkingContext,
},
output::OutputAssets,
};
use super::{
item::EcmascriptChunkItemWithAsyncInfo, EcmascriptChunk, EcmascriptChunkContent,
EcmascriptChunkItem,
};
use super::{EcmascriptChunk, EcmascriptChunkContent, EcmascriptChunkItem};
use crate::chunk::batch::{EcmascriptChunkItemBatchGroup, EcmascriptChunkItemOrBatchWithAsyncInfo};
#[turbo_tasks::value]
#[derive(Default)]
......@@ -37,7 +35,8 @@ impl ChunkType for EcmascriptChunkType {
async fn chunk(
&self,
chunking_context: Vc<Box<dyn ChunkingContext>>,
chunk_items: Vec<ChunkItemWithAsyncModuleInfo>,
chunk_items: Vec<ChunkItemOrBatchWithAsyncModuleInfo>,
batch_groups: Vec<ResolvedVc<ChunkItemBatchGroup>>,
referenced_output_assets: Vc<OutputAssets>,
) -> Result<Vc<Box<dyn Chunk>>> {
let Some(chunking_context) =
......@@ -45,32 +44,21 @@ impl ChunkType for EcmascriptChunkType {
else {
bail!("Ecmascript chunking context not found");
};
fn to_ecmascript_chunk_item(
chunk_item: &ChunkItemWithAsyncModuleInfo,
) -> Result<EcmascriptChunkItemWithAsyncInfo> {
let ChunkItemWithAsyncModuleInfo {
chunk_item,
module: _,
async_info,
} = chunk_item;
let Some(chunk_item) =
ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkItem>>(*chunk_item)
else {
bail!(
"Chunk item is not an ecmascript chunk item but reporting chunk type \
ecmascript"
);
};
Ok(EcmascriptChunkItemWithAsyncInfo {
chunk_item,
async_info: *async_info,
})
}
let content = EcmascriptChunkContent {
chunk_items: chunk_items
.iter()
.map(to_ecmascript_chunk_item)
.collect::<Result<Vec<_>>>()?,
.map(EcmascriptChunkItemOrBatchWithAsyncInfo::from_chunk_item_or_batch)
.try_join()
.await?,
batch_groups: batch_groups
.into_iter()
.map(|batch_group| {
EcmascriptChunkItemBatchGroup::from_chunk_item_batch_group(*batch_group)
.to_resolved()
})
.try_join()
.await?,
referenced_output_assets: referenced_output_assets.owned().await?,
}
.cell();
......
use anyhow::Result;
use rustc_hash::FxHashMap;
use smallvec::{smallvec, SmallVec};
use turbo_tasks::{ReadRef, TryJoinIterExt, Vc};
use turbopack_core::{
chunk::{ChunkItemExt, ModuleId},
code_builder::Code,
};
use crate::chunk::{
EcmascriptChunkItemBatchGroup, EcmascriptChunkItemExt, EcmascriptChunkItemOrBatchWithAsyncInfo,
EcmascriptChunkItemWithAsyncInfo,
};
#[turbo_tasks::value(transparent, serialization = "none")]
pub struct CodeAndIds(SmallVec<[(ReadRef<ModuleId>, ReadRef<Code>); 1]>);
#[turbo_tasks::value(transparent, serialization = "none")]
pub struct BatchGroupCodeAndIds(
FxHashMap<EcmascriptChunkItemOrBatchWithAsyncInfo, ReadRef<CodeAndIds>>,
);
#[turbo_tasks::function]
pub async fn batch_group_code_and_ids(
batch_group: Vc<EcmascriptChunkItemBatchGroup>,
) -> Result<Vc<BatchGroupCodeAndIds>> {
Ok(Vc::cell(
batch_group
.await?
.items
.iter()
.map(async |item| Ok((item.clone(), item_code_and_ids(item.clone()).await?)))
.try_join()
.await?
.into_iter()
.collect(),
))
}
#[turbo_tasks::function]
pub async fn item_code_and_ids(
item: EcmascriptChunkItemOrBatchWithAsyncInfo,
) -> Result<Vc<CodeAndIds>> {
Ok(Vc::cell(match item {
EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem(EcmascriptChunkItemWithAsyncInfo {
chunk_item,
async_info,
..
}) => {
let id = chunk_item.id();
let code = chunk_item.code(async_info.map(|info| *info));
smallvec![(id.await?, code.await?)]
}
EcmascriptChunkItemOrBatchWithAsyncInfo::Batch(batch) => batch
.await?
.chunk_items
.iter()
.map(|item| async {
Ok((
item.chunk_item.id().await?,
item.chunk_item
.code(item.async_info.map(|info| *info))
.await?,
))
})
.try_join()
.await?
.into(),
}))
}
use std::future::IntoFuture;
use anyhow::Result;
use turbo_tasks::{ResolvedVc, Vc};
use either::Either;
use turbo_tasks::{ReadRef, ResolvedVc, TryJoinIterExt, Vc};
use turbopack_core::{
chunk::{ChunkItem, ChunkItems},
chunk::{batch_info, ChunkItem, ChunkItems},
output::OutputAsset,
};
use super::item::EcmascriptChunkItemWithAsyncInfo;
use crate::chunk::{
batch::{EcmascriptChunkItemBatchGroup, EcmascriptChunkItemOrBatchWithAsyncInfo},
batch_group_code_and_ids, item_code_and_ids, CodeAndIds,
};
#[turbo_tasks::value(shared)]
pub struct EcmascriptChunkContent {
pub chunk_items: Vec<EcmascriptChunkItemWithAsyncInfo>,
pub chunk_items: Vec<EcmascriptChunkItemOrBatchWithAsyncInfo>,
pub batch_groups: Vec<ResolvedVc<EcmascriptChunkItemBatchGroup>>,
pub referenced_output_assets: Vec<ResolvedVc<Box<dyn OutputAsset>>>,
}
......@@ -20,10 +27,38 @@ impl EcmascriptChunkContent {
Ok(ChunkItems(
self.chunk_items
.iter()
.map(|EcmascriptChunkItemWithAsyncInfo { chunk_item, .. }| chunk_item)
.map(|item| ResolvedVc::upcast::<Box<dyn ChunkItem>>(*item))
.map(async |item| match item {
EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem(item) => {
Ok(Either::Left(item.chunk_item))
}
EcmascriptChunkItemOrBatchWithAsyncInfo::Batch(batch) => {
Ok(Either::Right(batch.await?))
}
})
.try_join()
.await?
.iter()
.flat_map(|item| match item {
Either::Left(item) => Either::Left(std::iter::once(*item)),
Either::Right(batch) => {
Either::Right(batch.chunk_items.iter().map(|item| item.chunk_item))
}
})
.map(ResolvedVc::upcast::<Box<dyn ChunkItem>>)
.collect(),
)
.cell())
}
}
impl EcmascriptChunkContent {
pub async fn chunk_item_code_and_ids(&self) -> Result<Vec<ReadRef<CodeAndIds>>> {
batch_info(
&self.batch_groups,
&self.chunk_items,
|batch| batch_group_code_and_ids(batch).into_future(),
|item| item_code_and_ids(item.clone()).into_future(),
)
.await
}
}
......@@ -7,7 +7,7 @@ use turbo_tasks::{
};
use turbo_tasks_fs::{rope::Rope, FileSystemPath};
use turbopack_core::{
chunk::{AsyncModuleInfo, ChunkItem, ChunkingContext},
chunk::{AsyncModuleInfo, ChunkItem, ChunkItemWithAsyncModuleInfo, ChunkingContext},
code_builder::{Code, CodeBuilder},
error::PrettyPrintError,
issue::{code_gen::CodeGenerationIssue, IssueExt, IssueSeverity, StyledString},
......@@ -192,6 +192,27 @@ pub struct EcmascriptChunkItemWithAsyncInfo {
pub async_info: Option<ResolvedVc<AsyncModuleInfo>>,
}
impl EcmascriptChunkItemWithAsyncInfo {
pub fn from_chunk_item(
chunk_item: &ChunkItemWithAsyncModuleInfo,
) -> Result<EcmascriptChunkItemWithAsyncInfo> {
let ChunkItemWithAsyncModuleInfo {
chunk_item,
module: _,
async_info,
} = chunk_item;
let Some(chunk_item) =
ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkItem>>(*chunk_item)
else {
bail!("Chunk item is not an ecmascript chunk item but reporting chunk type ecmascript");
};
Ok(EcmascriptChunkItemWithAsyncInfo {
chunk_item,
async_info: *async_info,
})
}
}
#[turbo_tasks::value_trait]
pub trait EcmascriptChunkItem: ChunkItem {
fn content(self: Vc<Self>) -> Vc<EcmascriptChunkItemContent>;
......
pub(crate) mod batch;
pub(crate) mod chunk_type;
pub(crate) mod code_and_ids;
pub(crate) mod content;
pub(crate) mod data;
pub(crate) mod item;
......@@ -22,7 +24,12 @@ use turbopack_core::{
};
pub use self::{
batch::{
EcmascriptChunkBatchWithAsyncInfo, EcmascriptChunkItemBatchGroup,
EcmascriptChunkItemOrBatchWithAsyncInfo,
},
chunk_type::EcmascriptChunkType,
code_and_ids::{batch_group_code_and_ids, item_code_and_ids, BatchGroupCodeAndIds, CodeAndIds},
content::EcmascriptChunkContent,
data::EcmascriptChunkData,
item::{
......@@ -137,14 +144,7 @@ impl Chunk for EcmascriptChunk {
let mut referenced_output_assets: Vec<ResolvedVc<Box<dyn OutputAsset>>> = content
.chunk_items
.iter()
.map(async |with_info| {
Ok(with_info
.chunk_item
.references()
.await?
.into_iter()
.copied())
})
.map(async |with_info| Ok(with_info.references().await?.into_iter().copied()))
.try_flat_join()
.await?;
referenced_output_assets.extend(content.referenced_output_assets.iter().copied());
......
......@@ -8,7 +8,9 @@ use turbopack_core::{
},
ident::AssetIdent,
module::Module,
module_graph::{chunk_group_info::ChunkGroup, ModuleGraph},
module_graph::{
chunk_group_info::ChunkGroup, module_batch::ChunkableModuleOrBatch, ModuleGraph,
},
output::OutputAssets,
reference::{ModuleReferences, SingleOutputAssetReference},
};
......@@ -71,8 +73,18 @@ impl ManifestAsyncModule {
pub async fn manifest_chunks(self: ResolvedVc<Self>) -> Result<Vc<OutputAssets>> {
let this = self.await?;
if let Some(chunk_items) = this.availability_info.available_modules() {
if *chunk_items.get(*this.inner).await? {
return Ok(Vc::cell(vec![]));
let inner_module = ResolvedVc::upcast(this.inner);
let batches = this
.module_graph
.module_batches(this.chunking_context.batching_config())
.await?;
let module_or_batch = batches.get_entry(inner_module).await?;
if let Some(chunkable_module_or_batch) =
ChunkableModuleOrBatch::from_module_or_batch(module_or_batch)
{
if *chunk_items.get(chunkable_module_or_batch).await? {
return Ok(Vc::cell(vec![]));
}
}
}
Ok(this.chunking_context.chunk_group_assets(
......
......@@ -20,10 +20,12 @@ workspace = true
[dependencies]
anyhow = { workspace = true }
either = { workspace = true }
indexmap = { workspace = true }
indoc = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true }
smallvec = { workspace = true }
tracing = { workspace = true }
urlencoding = { workspace = true }
......
use std::io::Write;
use anyhow::Result;
use indoc::writedoc;
use turbo_tasks::{ReadRef, ResolvedVc, TryJoinIterExt, Vc};
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::File;
use turbopack_core::{
asset::AssetContent,
chunk::{ChunkItemExt, ChunkingContext, MinifyType, ModuleId},
chunk::{ChunkingContext, MinifyType},
code_builder::{Code, CodeBuilder},
output::OutputAsset,
source_map::{GenerateSourceMap, OptionStringifiedSourceMap},
version::{Version, VersionedContent},
};
use turbopack_ecmascript::{
chunk::{EcmascriptChunkContent, EcmascriptChunkItemExt, EcmascriptChunkItemWithAsyncInfo},
minify::minify,
utils::StringifyJs,
};
use turbopack_ecmascript::{chunk::EcmascriptChunkContent, minify::minify, utils::StringifyJs};
use super::{chunk::EcmascriptBuildNodeChunk, version::EcmascriptBuildNodeChunkVersion};
use crate::NodeJsChunkingContext;
......@@ -45,33 +39,11 @@ impl EcmascriptBuildNodeChunkContent {
}
}
pub(super) async fn chunk_items(
content: Vc<EcmascriptChunkContent>,
) -> Result<Vec<(ReadRef<ModuleId>, ReadRef<Code>)>> {
content
.await?
.chunk_items
.iter()
.map(
async |&EcmascriptChunkItemWithAsyncInfo {
chunk_item,
async_info,
..
}| {
Ok((
chunk_item.id().await?,
chunk_item.code(async_info.map(|info| *info)).await?,
))
},
)
.try_join()
.await
}
#[turbo_tasks::value_impl]
impl EcmascriptBuildNodeChunkContent {
#[turbo_tasks::function]
async fn code(self: Vc<Self>) -> Result<Vc<Code>> {
use std::io::Write;
let this = self.await?;
let source_maps = this
.chunking_context
......@@ -89,10 +61,14 @@ impl EcmascriptBuildNodeChunkContent {
"#,
)?;
for (id, item_code) in chunk_items(*this.content).await? {
write!(code, "{}: ", StringifyJs(&id))?;
code.push_code(&item_code);
writeln!(code, ",")?;
let content = this.content.await?;
let chunk_items = content.chunk_item_code_and_ids().await?;
for item in chunk_items {
for (id, item_code) in item {
write!(code, "{}: ", StringifyJs(&id))?;
code.push_code(item_code);
writeln!(code, ",")?;
}
}
write!(code, "\n}};")?;
......
......@@ -3,19 +3,13 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{ReadRef, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbo_tasks_hash::{encode_hex, Xxh3Hash64Hasher};
use turbopack_core::{
chunk::{MinifyType, ModuleId},
code_builder::Code,
version::Version,
};
use turbopack_ecmascript::chunk::EcmascriptChunkContent;
use super::content::chunk_items;
use turbopack_core::{chunk::MinifyType, version::Version};
use turbopack_ecmascript::chunk::{CodeAndIds, EcmascriptChunkContent};
#[turbo_tasks::value(serialization = "none")]
pub(super) struct EcmascriptBuildNodeChunkVersion {
chunk_path: String,
chunk_items: Vec<(ReadRef<ModuleId>, ReadRef<Code>)>,
chunk_items: Vec<ReadRef<CodeAndIds>>,
minify_type: MinifyType,
}
......@@ -39,7 +33,7 @@ impl EcmascriptBuildNodeChunkVersion {
output_root.to_string()
);
};
let chunk_items = chunk_items(content).await?;
let chunk_items = content.await?.chunk_item_code_and_ids().await?;
Ok(EcmascriptBuildNodeChunkVersion {
chunk_path: chunk_path.to_string(),
chunk_items,
......@@ -57,8 +51,10 @@ impl Version for EcmascriptBuildNodeChunkVersion {
hasher.write_ref(&self.chunk_path);
hasher.write_ref(&self.minify_type);
hasher.write_value(self.chunk_items.len());
for (module_id, code) in &self.chunk_items {
hasher.write_value((module_id, code.source_code()));
for item in &self.chunk_items {
for (module_id, code) in item {
hasher.write_value((module_id, code.source_code()));
}
}
let hash = hasher.finish();
let hex_hash = encode_hex(hash);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4c35f_tests_snapshot_basic-tree-shake_dynamic-import_input_index_51f42d2d.js",
"output/4c35f_tests_snapshot_basic-tree-shake_dynamic-import_input_index_2edf9bff.js",
{},
{"otherChunks":["output/4c35f_tests_snapshot_basic-tree-shake_dynamic-import_input_lib_44a9b7f1.js","output/4c35f_tests_snapshot_basic-tree-shake_dynamic-import_input_index_92a5f455.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/dynamic-import/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4c35f_tests_snapshot_basic-tree-shake_export-named_input_index_1fc789c3.js",
"output/4c35f_tests_snapshot_basic-tree-shake_export-named_input_index_dc82d916.js",
{},
{"otherChunks":["output/b1abf_turbopack-tests_tests_snapshot_basic-tree-shake_export-named_input_8a727493._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-named/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4c35f_tests_snapshot_basic-tree-shake_export-namespace_input_index_fe20a07c.js",
"output/4c35f_tests_snapshot_basic-tree-shake_export-namespace_input_index_26ed2d28.js",
{},
{"otherChunks":["output/b1abf_turbopack-tests_tests_snapshot_basic-tree-shake_export-namespace_input_c06df669._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4c35f_tests_snapshot_basic-tree-shake_import-named-all_input_index_7c8a966f.js",
"output/4c35f_tests_snapshot_basic-tree-shake_import-named-all_input_index_4828f7e8.js",
{},
{"otherChunks":["output/b1abf_turbopack-tests_tests_snapshot_basic-tree-shake_import-named-all_input_d3502989._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-named-all/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4c35f_tests_snapshot_basic-tree-shake_import-named_input_index_219f97cc.js",
"output/4c35f_tests_snapshot_basic-tree-shake_import-named_input_index_ce63c19c.js",
{},
{"otherChunks":["output/b1abf_turbopack-tests_tests_snapshot_basic-tree-shake_import-named_input_b80bd217._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-named/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4c35f_tests_snapshot_basic-tree-shake_import-namespace_input_index_20aeb057.js",
"output/4c35f_tests_snapshot_basic-tree-shake_import-namespace_input_index_d57c23a2.js",
{},
{"otherChunks":["output/b1abf_turbopack-tests_tests_snapshot_basic-tree-shake_import-namespace_input_78f1a109._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4c35f_tests_snapshot_basic-tree-shake_import-side-effect_input_index_1ff96ba8.js",
"output/4c35f_tests_snapshot_basic-tree-shake_import-side-effect_input_index_cec5094b.js",
{},
{"otherChunks":["output/4c35f_tests_snapshot_basic-tree-shake_import-side-effect_input_65b48228._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-side-effect/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4c35f_tests_snapshot_basic-tree-shake_require-side-effect_input_index_615d125d.js",
"output/4c35f_tests_snapshot_basic-tree-shake_require-side-effect_input_index_7f73310e.js",
{},
{"otherChunks":["output/4c35f_tests_snapshot_basic-tree-shake_require-side-effect_input_eb5a8232._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/require-side-effect/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4c35f_tests_snapshot_basic-tree-shake_tree-shake-test-1_input_index_c667b603.js",
"output/4c35f_tests_snapshot_basic-tree-shake_tree-shake-test-1_input_index_3fa86f6f.js",
{},
{"otherChunks":["output/4c35f_tests_snapshot_basic-tree-shake_tree-shake-test-1_input_index_7800ef35.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/tree-shake-test-1/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4e721_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_97926e82.js",
"output/4e721_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_bc13c746.js",
{},
{"otherChunks":["output/4e721_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_import_46e42b9f.js","output/turbopack_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_46366300._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4e721_crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_c76541f9.js",
"output/4e721_crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_e84770ed.js",
{},
{"otherChunks":["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_chunked_input_1efdaca0._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/chunked/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4e721_crates_turbopack-tests_tests_snapshot_basic_shebang_input_index_ff7d9337.js",
"output/4e721_crates_turbopack-tests_tests_snapshot_basic_shebang_input_index_b1051af4.js",
{},
{"otherChunks":["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_shebang_input_d5e8dcd4._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/shebang/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/b1abf_turbopack-tests_tests_snapshot_basic_top-level-await_input_index_f028bdd0.js",
"output/b1abf_turbopack-tests_tests_snapshot_basic_top-level-await_input_index_d8ec24f7.js",
{},
{"otherChunks":["output/b1abf_turbopack-tests_tests_snapshot_basic_top-level-await_input_UserAPI_ba56f92c.js","output/4e721_crates_turbopack-tests_tests_snapshot_basic_top-level-await_input_9acd43f4._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/top-level-await/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4e721_crates_turbopack-tests_tests_snapshot_comptime_define_input_index_26b3197f.js",
"output/4e721_crates_turbopack-tests_tests_snapshot_comptime_define_input_index_bc305fa6.js",
{},
{"otherChunks":["output/4e721_crates_turbopack-tests_tests_snapshot_comptime_define_input_index_4d74c0a3.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/comptime/define/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/b1abf_turbopack-tests_tests_snapshot_comptime_early-return_input_index_7d597fea.js",
"output/b1abf_turbopack-tests_tests_snapshot_comptime_early-return_input_index_b8ede9b1.js",
{},
{"otherChunks":["output/4e721_crates_turbopack-tests_tests_snapshot_comptime_early-return_input_82bbae08._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/comptime/early-return/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4e721_crates_turbopack-tests_tests_snapshot_comptime_typeof_input_index_d3b80ebf.js",
"output/4e721_crates_turbopack-tests_tests_snapshot_comptime_typeof_input_index_c194d309.js",
{},
{"otherChunks":["output/turbopack_crates_turbopack-tests_tests_snapshot_comptime_typeof_input_80f5724c._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/comptime/typeof/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4e721_crates_turbopack-tests_tests_snapshot_comptime_unreachable_input_index_0d3fc1f0.js",
"output/4e721_crates_turbopack-tests_tests_snapshot_comptime_unreachable_input_index_5bee135e.js",
{},
{"otherChunks":["output/4e721_crates_turbopack-tests_tests_snapshot_comptime_unreachable_input_index_9022a405.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/comptime/unreachable/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/b1abf_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_2d222560.js",
"output/b1abf_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_a83c65b3.js",
{},
{"otherChunks":[{"path":"output/4e721_crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_b44448e2._.css","included":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/other.css [test] (css)","[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/withduplicateurl.css [test] (css)","[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/index.css [test] (css)"],"moduleChunks":["output/b1abf_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_other_7d7e1c0b.css","output/4c35f_tests_snapshot_css_absolute-uri-import_input_withduplicateurl_7d7e1c0b.css","output/b1abf_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_7d7e1c0b.css","output/b1abf_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_other_7d7e1c0b.css","output/4c35f_tests_snapshot_css_absolute-uri-import_input_withduplicateurl_7d7e1c0b.css"]},"output/b1abf_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_e42d0fe1.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/b1abf_turbopack-tests_tests_snapshot_css_chained-attributes_input_index_0d8ea084.js",
"output/b1abf_turbopack-tests_tests_snapshot_css_chained-attributes_input_index_12edca17.js",
{},
{"otherChunks":[{"path":"output/4e721_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_0c8b8533._.css","included":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/c.css [test] (css, layer(layer) layer(foo) print and (orientation: landscape) supports(not(display: inline-grid)) supports(font-format(woff2)))","[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/c.css [test] (css, layer(layer) layer(bar) print and (orientation: portrait) supports(not(display: inline-grid)) supports(font-format(woff2)))","[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/b.css [test] (css, layer(layer) print supports(not(display: inline-grid)) supports(font-format(woff2)))","[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/a.css [test] (css, layer(layer) print supports(not(display: inline-grid)))","[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/style.css [test] (css)"],"moduleChunks":["output/4e721_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_c_823b12e8.css","output/4e721_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_c_163c6a17.css","output/4e721_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_b_dc1da6d5.css","output/4e721_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_a_bf62fcb8.css","output/b1abf_turbopack-tests_tests_snapshot_css_chained-attributes_input_style_7d7e1c0b.css","output/4e721_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_c_823b12e8.css","output/4e721_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_c_163c6a17.css","output/4e721_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_b_dc1da6d5.css","output/4e721_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_a_bf62fcb8.css"]},"output/b1abf_turbopack-tests_tests_snapshot_css_chained-attributes_input_index_0d5b04e3.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/b1abf_turbopack-tests_tests_snapshot_css_css-legacy-nesting_input_index_d3e6ec35.js",
"output/b1abf_turbopack-tests_tests_snapshot_css_css-legacy-nesting_input_index_6c9f2d9d.js",
{},
{"otherChunks":[{"path":"output/b1abf_turbopack-tests_tests_snapshot_css_css-legacy-nesting_input_style_da464693.css","included":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/css-legacy-nesting/input/style.css [test] (css)"],"moduleChunks":["output/b1abf_turbopack-tests_tests_snapshot_css_css-legacy-nesting_input_style_7d7e1c0b.css"]},"output/b1abf_turbopack-tests_tests_snapshot_css_css-legacy-nesting_input_index_49d4edb8.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/css-legacy-nesting/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/4e721_crates_turbopack-tests_tests_snapshot_css_css-modules_input_index_01f1e498.js",
"output/4e721_crates_turbopack-tests_tests_snapshot_css_css-modules_input_index_c72e8e7c.js",
{},
{"otherChunks":[{"path":"output/b1abf_turbopack-tests_tests_snapshot_css_css-modules_input_style_module_76a2527b.css","included":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/css-modules/input/style.module.css [test] (css)"],"moduleChunks":["output/b1abf_turbopack-tests_tests_snapshot_css_css-modules_input_style_module_7d7e1c0b.css"]},"output/b1abf_turbopack-tests_tests_snapshot_css_css-modules_input_style_module_css_adb3ea2d._.js","output/turbopack_crates_turbopack-tests_tests_snapshot_css_css-modules_input_8f2e7f32._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/css-modules/input/index.js [test] (ecmascript)"]}
]);
......
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push([
"output/turbopack_crates_turbopack-tests_tests_snapshot_css_css_input_index_f7be3e30.js",
"output/turbopack_crates_turbopack-tests_tests_snapshot_css_css_input_index_977cc8e4.js",
{},
{"otherChunks":[{"path":"output/turbopack_crates_turbopack-tests_tests_snapshot_css_css_input_94f90ccb._.css","included":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/css/input/node_modules/foo/style.css [test] (css)","[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/css/input/imported.css [test] (css)","[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/css/input/imported.css [test] (css, layer(layer) print)","[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/css/input/style.css [test] (css)","[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/css/input/node_modules/foo/style.module.css [test] (css)","[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/css/input/style.module.css [test] (css)"],"moduleChunks":["output/08d19_foo_style_7d7e1c0b.css","output/turbopack_crates_turbopack-tests_tests_snapshot_css_css_input_imported_7d7e1c0b.css","output/turbopack_crates_turbopack-tests_tests_snapshot_css_css_input_imported_9f97d980.css","output/turbopack_crates_turbopack-tests_tests_snapshot_css_css_input_style_7d7e1c0b.css","output/08d19_foo_style_module_7d7e1c0b.css","output/4e721_crates_turbopack-tests_tests_snapshot_css_css_input_style_module_7d7e1c0b.css","output/turbopack_crates_turbopack-tests_tests_snapshot_css_css_input_imported_7d7e1c0b.css","output/turbopack_crates_turbopack-tests_tests_snapshot_css_css_input_imported_7d7e1c0b.css","output/turbopack_crates_turbopack-tests_tests_snapshot_css_css_input_imported_9f97d980.css"]},"output/08d19_foo_style_css_7d60f23f._.js","output/turbopack_crates_turbopack-tests_tests_snapshot_css_css_input_6dc4af09._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/css/input/index.js [test] (ecmascript)"]}
]);
......
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