Skip to content

Commit

Permalink
Chunking Refactor Step 1 (#56467)
Browse files Browse the repository at this point in the history
### What?

This change moves a few methods around.

Module::as_chunk is moved to ChunkItem::as_chunk as temporary intermediate state.
EcmascriptPlaceable::as_chunk_item is moved to ChunkableModule::as_chunk_item. This generalizes the concept of converting a Module into a ChunkItem


### Why?

This is the first step of refactoring the chunking. In the end we want to avoid creating chunks from modules directly, but enforce everything going through the ChunkingContext to be chunked. This allows us to replace the existing chunking algorithm with a much more efficient one that avoid duplication between chunks in first place and doesn't require a post-chunking optimization.

### How?

see vercel/turborepo#6104

Closes WEB-1715

Co-authored-by: Justin Ridgewell <112982+jridgewell@users.noreply.github.com>
  • Loading branch information
sokra and jridgewell authored Oct 5, 2023
1 parent 11c1d07 commit 666ce7b
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 169 deletions.
66 changes: 33 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ swc_core = { version = "0.83.28", features = [
testing = { version = "0.34.1" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231002.1" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231005.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231002.1" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231005.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231002.1" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231005.2" }

# General Deps

Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use turbopack_binding::{
turbopack::{
core::{
asset::{Asset, AssetContent},
chunk::{ChunkableModule, ChunkingContext, EvaluatableAssets},
chunk::{ChunkableModuleExt, ChunkingContext, EvaluatableAssets},
file_source::FileSource,
output::{OutputAsset, OutputAssets},
virtual_output::VirtualOutputAsset,
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use turbopack_binding::{
turbopack::{
core::{
asset::AssetContent,
chunk::{ChunkableModule, ChunkingContext},
chunk::{ChunkableModuleExt, ChunkingContext},
context::AssetContext,
module::Module,
output::{OutputAsset, OutputAssets},
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use turbopack_binding::{
build::BuildChunkingContext,
core::{
asset::AssetContent,
chunk::{ChunkableModule, ChunkingContext, EvaluatableAssets},
chunk::{ChunkableModuleExt, ChunkingContext, EvaluatableAssets},
context::AssetContext,
file_source::FileSource,
issue::{IssueSeverity, OptionIssueSource},
Expand Down
18 changes: 13 additions & 5 deletions packages/next-swc/crates/next-api/src/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ use turbopack_binding::{
turbo::tasks_fs::{rope::RopeBuilder, File, FileSystemPath},
turbopack::{
core::{
asset::AssetContent, chunk::EvaluatableAsset, context::AssetContext, module::Module,
output::OutputAsset, reference::primary_referenced_modules,
reference_type::ReferenceType, virtual_output::VirtualOutputAsset,
asset::AssetContent,
chunk::{ChunkItemExt, ChunkableModule, EvaluatableAsset},
context::AssetContext,
module::Module,
output::OutputAsset,
reference::primary_referenced_modules,
reference_type::ReferenceType,
virtual_output::VirtualOutputAsset,
virtual_source::VirtualSource,
},
ecmascript::{
chunk::{EcmascriptChunkItemExt, EcmascriptChunkPlaceable, EcmascriptChunkingContext},
chunk::{EcmascriptChunkPlaceable, EcmascriptChunkingContext},
parse::ParseResult,
EcmascriptModuleAsset,
},
Expand Down Expand Up @@ -72,7 +77,10 @@ pub(crate) async fn create_server_actions_manifest(
bail!("loader module must be evaluatable");
};

let loader_id = loader.as_chunk_item(chunking_context).id().to_string();
let loader_id = loader
.as_chunk_item(Vc::upcast(chunking_context))
.id()
.to_string();
let manifest =
build_manifest(node_root, pathname, page_name, runtime, actions, loader_id).await?;
Ok((Some(evaluable), manifest))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use turbopack_binding::{
turbopack::{
build::BuildChunkingContext,
core::{
chunk::{ChunkableModule, ChunkingContext, EvaluatableAssets},
chunk::{ChunkableModuleExt, ChunkingContext, EvaluatableAssets},
compile_time_info::CompileTimeInfo,
context::AssetContext,
file_source::FileSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use turbo_tasks::{debug::ValueDebugFormat, trace::TraceRawVcs, TryJoinIterExt, V
use turbopack_binding::turbopack::{
build::BuildChunkingContext,
core::{
chunk::{ChunkableModule, ChunkingContext},
chunk::{ChunkableModuleExt, ChunkingContext},
output::OutputAssets,
},
ecmascript::chunk::EcmascriptChunkingContext,
Expand Down
Loading

0 comments on commit 666ce7b

Please sign in to comment.