Skip to content

Deduplicate referenced_output_assets #6191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/turbo-tasks/src/vc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ where
pub async fn debug_identifier(vc: Self) -> Result<String> {
let resolved = vc.resolve().await?;
let raw_vc: RawVc = resolved.node;
if let RawVc::TaskCell(_, CellId { type_id, index }) = raw_vc {
if let RawVc::TaskCell(task_id, CellId { type_id, index }) = raw_vc {
let value_ty = registry::get_value_type(type_id);
Ok(format!("{}#{}", value_ty.name, index))
Ok(format!("{}#{}: {}", value_ty.name, index, task_id))
} else {
unreachable!()
}
Expand Down
10 changes: 7 additions & 3 deletions crates/turbopack-core/src/chunk/chunk_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::{
chunk_content, chunking::make_chunks, AsyncModuleInfo, Chunk, ChunkContentResult, ChunkItem,
ChunkingContext,
};
use crate::{module::Module, output::OutputAsset, reference::ModuleReference};
use crate::{module::Module, output::OutputAssets, reference::ModuleReference};

pub struct MakeChunkGroupResult {
pub chunks: Vec<Vc<Box<dyn Chunk>>>,
Expand Down Expand Up @@ -169,7 +169,7 @@ pub async fn make_chunk_group(

async fn references_to_output_assets(
references: IndexSet<Vc<Box<dyn ModuleReference>>>,
) -> Result<Vec<Vc<Box<dyn OutputAsset>>>> {
) -> Result<Vc<OutputAssets>> {
let output_assets = references
.into_iter()
.map(|reference| reference.resolve_reference().primary_output_assets())
Expand All @@ -182,5 +182,9 @@ async fn references_to_output_assets(
.copied()
.filter(|&asset| set.insert(asset))
.collect::<Vec<_>>();
Ok(output_assets)
Ok(if output_assets.is_empty() {
OutputAssets::empty()
} else {
OutputAssets::new(output_assets)
})
Comment on lines +185 to +189
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should put this (empty check) logic into OutputAssets::new

}
6 changes: 2 additions & 4 deletions crates/turbopack-core/src/chunk/chunking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tracing::Level;
use turbo_tasks::{ReadRef, TryJoinIterExt, ValueToString, Vc};

use super::{AsyncModuleInfo, Chunk, ChunkItem, ChunkType, ChunkingContext};
use crate::output::{OutputAsset, OutputAssets};
use crate::output::OutputAssets;

/// Creates chunks based on heuristics for the passed `chunk_items`. Also
/// attaches `referenced_output_assets` to the first chunk.
Expand All @@ -22,7 +22,7 @@ pub async fn make_chunks(
chunking_context: Vc<Box<dyn ChunkingContext>>,
chunk_items: impl IntoIterator<Item = (Vc<Box<dyn ChunkItem>>, Option<Vc<AsyncModuleInfo>>)>,
key_prefix: &str,
referenced_output_assets: Vec<Vc<Box<dyn OutputAsset>>>,
mut referenced_output_assets: Vc<OutputAssets>,
) -> Result<Vec<Vc<Box<dyn Chunk>>>> {
let chunk_items = chunk_items
.into_iter()
Expand All @@ -37,8 +37,6 @@ pub async fn make_chunks(
map.entry(ty).or_default().push((chunk_item, async_info));
}

let mut referenced_output_assets = Vc::cell(referenced_output_assets);

let mut chunks = Vec::new();
for (ty, chunk_items) in map {
let ty_name = ty.to_string().await?;
Expand Down
5 changes: 5 additions & 0 deletions crates/turbopack-core/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ pub struct OutputAssets(Vec<Vc<Box<dyn OutputAsset>>>);

#[turbo_tasks::value_impl]
impl OutputAssets {
#[turbo_tasks::function]
pub fn new(assets: Vec<Vc<Box<dyn OutputAsset>>>) -> Vc<Self> {
Vc::cell(assets)
}

#[turbo_tasks::function]
pub fn empty() -> Vc<Self> {
Vc::cell(vec![])
Expand Down