Skip to content

Commit

Permalink
Revert "Chunking Context Refactor pt. 3: Address PR comments from pt.…
Browse files Browse the repository at this point in the history
… 2" (vercel#4588)

Reverts vercel#4546
  • Loading branch information
sokra authored and NicholasLYang committed Apr 21, 2023
1 parent ce2c981 commit 1f7c561
Show file tree
Hide file tree
Showing 22 changed files with 590 additions and 419 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

220 changes: 0 additions & 220 deletions crates/turbopack-core/src/chunk/containment_tree.rs

This file was deleted.

82 changes: 66 additions & 16 deletions crates/turbopack-core/src/chunk/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod availability_info;
pub mod available_assets;
pub(crate) mod chunking_context;
pub(crate) mod containment_tree;
pub(crate) mod evaluate;
pub mod optimize;

Expand All @@ -17,7 +16,7 @@ use serde::{Deserialize, Serialize};
use turbo_tasks::{
debug::ValueDebugFormat,
graph::{GraphTraversal, GraphTraversalResult, ReverseTopological, Visit, VisitControlFlow},
primitives::StringVc,
primitives::{BoolVc, StringVc},
trace::TraceRawVcs,
TryJoinIterExt, Value, ValueToString, ValueToStringVc,
};
Expand All @@ -28,6 +27,7 @@ use self::availability_info::AvailabilityInfo;
pub use self::{
chunking_context::{ChunkingContext, ChunkingContextVc},
evaluate::{EvaluatableAsset, EvaluatableAssetVc, EvaluatableAssets, EvaluatableAssetsVc},
optimize::optimize,
};
use crate::{
asset::{Asset, AssetVc, AssetsVc},
Expand Down Expand Up @@ -97,17 +97,13 @@ pub trait ChunkableAsset: Asset {
#[turbo_tasks::value(transparent)]
pub struct Chunks(Vec<ChunkVc>);

#[turbo_tasks::value_impl]
impl ChunksVc {
/// Creates a new empty [ChunksVc].
#[turbo_tasks::function]
pub fn empty() -> ChunksVc {
Self::cell(vec![])
}
}

/// A chunk is one type of asset.
/// It usually contains multiple chunk items.
/// There is an optional trait [ParallelChunkReference] that
/// [AssetReference]s from a [Chunk] can implement.
/// If they implement that and [ParallelChunkReference::is_loaded_in_parallel]
/// returns true, all referenced assets (if they are [Chunk]s) are placed in the
/// same chunk group.
#[turbo_tasks::value_trait]
pub trait Chunk: Asset {
fn chunking_context(&self) -> ChunkingContextVc;
Expand All @@ -118,11 +114,12 @@ pub trait Chunk: Asset {
fn path(&self) -> FileSystemPathVc {
self.ident().path()
}
/// Returns a list of chunks that should be loaded in parallel to this
/// chunk.
fn parallel_chunks(&self) -> ChunksVc {
ChunksVc::empty()
}
}

/// see [Chunk] for explanation
#[turbo_tasks::value_trait]
pub trait ParallelChunkReference: AssetReference + ValueToString {
fn is_loaded_in_parallel(&self) -> BoolVc;
}

/// Specifies how a chunk interacts with other chunks when building a chunk
Expand Down Expand Up @@ -169,6 +166,59 @@ pub trait ChunkableAssetReference: AssetReference + ValueToString {
}
}

/// A reference to a [Chunk]. Can be loaded in parallel, see [Chunk].
#[turbo_tasks::value]
pub struct ChunkReference {
chunk: ChunkVc,
parallel: bool,
}

#[turbo_tasks::value_impl]
impl ChunkReferenceVc {
#[turbo_tasks::function]
pub fn new(chunk: ChunkVc) -> Self {
Self::cell(ChunkReference {
chunk,
parallel: false,
})
}

#[turbo_tasks::function]
pub fn new_parallel(chunk: ChunkVc) -> Self {
Self::cell(ChunkReference {
chunk,
parallel: true,
})
}
}

#[turbo_tasks::value_impl]
impl AssetReference for ChunkReference {
#[turbo_tasks::function]
fn resolve_reference(&self) -> ResolveResultVc {
ResolveResult::asset(self.chunk.into()).into()
}
}

#[turbo_tasks::value_impl]
impl ValueToString for ChunkReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<StringVc> {
Ok(StringVc::cell(format!(
"chunk {}",
self.chunk.ident().to_string().await?
)))
}
}

#[turbo_tasks::value_impl]
impl ParallelChunkReference for ChunkReference {
#[turbo_tasks::function]
fn is_loaded_in_parallel(&self) -> BoolVc {
BoolVc::cell(self.parallel)
}
}

/// A reference to multiple chunks from a [ChunkGroup]
#[turbo_tasks::value]
pub struct ChunkGroupReference {
Expand Down
Loading

0 comments on commit 1f7c561

Please sign in to comment.