Unverified Commit ea7319c1 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

codemod(turbopack): Rewrite Vc fields in structs as ResolvedVc (part 4) (#71804)

Generated using a version of https://github.com/vercel/turbopack-resolved-vc-codemod . This uses Anthropic Claude Sonnet 3.5 for more complicated errors we don't have hardcoded logic for.

- Part 1: #70927
- Part 2: #71172
- Part 3: #71665

Closes PACK-3336
parent 0f43e4ea
...@@ -61,7 +61,7 @@ impl Transition for NextEcmascriptClientReferenceTransition { ...@@ -61,7 +61,7 @@ impl Transition for NextEcmascriptClientReferenceTransition {
let this = self.await?; let this = self.await?;
let ident = match part { let ident = match part {
Some(part) => source.ident().with_part(part), Some(part) => source.ident().with_part(*part),
None => source.ident(), None => source.ident(),
}; };
let ident_ref = ident.await?; let ident_ref = ident.await?;
......
...@@ -23,8 +23,8 @@ use serde::Deserialize; ...@@ -23,8 +23,8 @@ use serde::Deserialize;
use serde::Serialize; use serde::Serialize;
use tokio::sync::mpsc::channel; use tokio::sync::mpsc::channel;
use turbo_tasks::{ use turbo_tasks::{
backend::Backend, util::FormatDuration, RcStr, ReadConsistency, TaskId, TransientInstance, backend::Backend, util::FormatDuration, RcStr, ReadConsistency, ResolvedVc, TaskId,
TransientValue, TurboTasks, UpdateInfo, Value, Vc, TransientInstance, TransientValue, TurboTasks, UpdateInfo, Value, Vc,
}; };
use turbo_tasks_fs::{ use turbo_tasks_fs::{
glob::Glob, DirectoryEntry, DiskFileSystem, FileSystem, FileSystemPath, ReadGlobResult, glob::Glob, DirectoryEntry, DiskFileSystem, FileSystem, FileSystemPath, ReadGlobResult,
...@@ -565,11 +565,11 @@ async fn main_operation( ...@@ -565,11 +565,11 @@ async fn main_operation(
#[turbo_tasks::function] #[turbo_tasks::function]
async fn create_module_asset( async fn create_module_asset(
root: Vc<FileSystemPath>, root: ResolvedVc<FileSystemPath>,
process_cwd: Option<RcStr>, process_cwd: Option<RcStr>,
module_options: TransientInstance<ModuleOptionsContext>, module_options: TransientInstance<ModuleOptionsContext>,
resolve_options: TransientInstance<ResolveOptionsContext>, resolve_options: TransientInstance<ResolveOptionsContext>,
) -> Vc<ModuleAssetContext> { ) -> Result<Vc<ModuleAssetContext>> {
let env = Environment::new(Value::new(ExecutionEnvironment::NodeJsLambda( let env = Environment::new(Value::new(ExecutionEnvironment::NodeJsLambda(
NodeJsEnvironment { NodeJsEnvironment {
cwd: Vc::cell(process_cwd), cwd: Vc::cell(process_cwd),
...@@ -581,13 +581,17 @@ async fn create_module_asset( ...@@ -581,13 +581,17 @@ async fn create_module_asset(
let glob_mappings = vec![ let glob_mappings = vec![
( (
root, root,
Glob::new("**/*/next/dist/server/next.js".into()), Glob::new("**/*/next/dist/server/next.js".into())
ImportMapping::Ignore.into(), .to_resolved()
.await?,
ImportMapping::Ignore.resolved_cell(),
), ),
( (
root, root,
Glob::new("**/*/next/dist/bin/next".into()), Glob::new("**/*/next/dist/bin/next".into())
ImportMapping::Ignore.into(), .to_resolved()
.await?,
ImportMapping::Ignore.resolved_cell(),
), ),
]; ];
let mut resolve_options = ResolveOptionsContext::clone(&*resolve_options); let mut resolve_options = ResolveOptionsContext::clone(&*resolve_options);
...@@ -603,13 +607,13 @@ async fn create_module_asset( ...@@ -603,13 +607,13 @@ async fn create_module_asset(
); );
} }
ModuleAssetContext::new( Ok(ModuleAssetContext::new(
Default::default(), Default::default(),
compile_time_info, compile_time_info,
ModuleOptionsContext::clone(&*module_options).cell(), ModuleOptionsContext::clone(&*module_options).cell(),
resolve_options.cell(), resolve_options.cell(),
Vc::cell("node_file_trace".into()), Vc::cell("node_file_trace".into()),
) ))
} }
fn register() { fn register() {
......
...@@ -386,7 +386,7 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -386,7 +386,7 @@ impl ChunkingContext for BrowserChunkingContext {
let mut assets: Vec<Vc<Box<dyn OutputAsset>>> = chunks let mut assets: Vec<Vc<Box<dyn OutputAsset>>> = chunks
.iter() .iter()
.map(|chunk| self.generate_chunk(*chunk)) .map(|chunk| self.generate_chunk(**chunk))
.collect(); .collect();
if this.enable_hot_module_replacement { if this.enable_hot_module_replacement {
...@@ -455,7 +455,7 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -455,7 +455,7 @@ impl ChunkingContext for BrowserChunkingContext {
let mut assets: Vec<Vc<Box<dyn OutputAsset>>> = chunks let mut assets: Vec<Vc<Box<dyn OutputAsset>>> = chunks
.iter() .iter()
.map(|chunk| self.generate_chunk(*chunk)) .map(|chunk| self.generate_chunk(**chunk))
.collect(); .collect();
let other_assets = Vc::cell(assets.clone()); let other_assets = Vc::cell(assets.clone());
......
...@@ -215,7 +215,7 @@ pub(super) async fn update_ecmascript_merged_chunk( ...@@ -215,7 +215,7 @@ pub(super) async fn update_ecmascript_merged_chunk(
if merged_module_map.get(&module_id) != Some(module_hash) { if merged_module_map.get(&module_id) != Some(module_hash) {
let entry = EcmascriptModuleEntry::from_code( let entry = EcmascriptModuleEntry::from_code(
&module_id, &module_id,
module_code, *module_code,
chunk_path, chunk_path,
) )
.await?; .await?;
...@@ -227,7 +227,7 @@ pub(super) async fn update_ecmascript_merged_chunk( ...@@ -227,7 +227,7 @@ pub(super) async fn update_ecmascript_merged_chunk(
for (module_id, module_code) in chunk_partial.modified { for (module_id, module_code) in chunk_partial.modified {
let entry = let entry =
EcmascriptModuleEntry::from_code(&module_id, module_code, chunk_path) EcmascriptModuleEntry::from_code(&module_id, *module_code, chunk_path)
.await?; .await?;
merged_update.entries.insert(module_id, entry); merged_update.entries.insert(module_id, entry);
} }
......
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{FxIndexMap, ReadRef, Vc}; use turbo_tasks::{FxIndexMap, ReadRef, ResolvedVc, Vc};
use turbopack_core::{chunk::ModuleId, code_builder::Code}; use turbopack_core::{chunk::ModuleId, code_builder::Code};
use super::{content::EcmascriptDevChunkContent, version::EcmascriptDevChunkVersion}; use super::{content::EcmascriptDevChunkContent, version::EcmascriptDevChunkVersion};
...@@ -11,9 +11,9 @@ pub(super) enum EcmascriptChunkUpdate { ...@@ -11,9 +11,9 @@ pub(super) enum EcmascriptChunkUpdate {
} }
pub(super) struct EcmascriptChunkPartialUpdate { pub(super) struct EcmascriptChunkPartialUpdate {
pub added: FxIndexMap<ReadRef<ModuleId>, (u64, Vc<Code>)>, pub added: FxIndexMap<ReadRef<ModuleId>, (u64, ResolvedVc<Code>)>,
pub deleted: FxIndexMap<ReadRef<ModuleId>, u64>, pub deleted: FxIndexMap<ReadRef<ModuleId>, u64>,
pub modified: FxIndexMap<ReadRef<ModuleId>, Vc<Code>>, pub modified: FxIndexMap<ReadRef<ModuleId>, ResolvedVc<Code>>,
} }
pub(super) async fn update_ecmascript_chunk( pub(super) async fn update_ecmascript_chunk(
...@@ -40,7 +40,8 @@ pub(super) async fn update_ecmascript_chunk( ...@@ -40,7 +40,8 @@ pub(super) async fn update_ecmascript_chunk(
for (id, from_hash) in &from.entries_hashes { for (id, from_hash) in &from.entries_hashes {
if let Some(entry) = entries.get(id) { if let Some(entry) = entries.get(id) {
if *entry.hash.await? != *from_hash { if *entry.hash.await? != *from_hash {
modified.insert(id.clone(), entry.code); let resolved_code = entry.code.to_resolved().await?;
modified.insert(id.clone(), resolved_code);
} }
} else { } else {
deleted.insert(id.clone(), *from_hash); deleted.insert(id.clone(), *from_hash);
...@@ -50,7 +51,10 @@ pub(super) async fn update_ecmascript_chunk( ...@@ -50,7 +51,10 @@ pub(super) async fn update_ecmascript_chunk(
// Remaining entries are added // Remaining entries are added
for (id, entry) in entries.iter() { for (id, entry) in entries.iter() {
if !from.entries_hashes.contains_key(id) { if !from.entries_hashes.contains_key(id) {
added.insert(id.clone(), (*entry.hash.await?, entry.code)); added.insert(
id.clone(),
(*entry.hash.await?, entry.code.to_resolved().await?),
);
} }
} }
......
...@@ -62,7 +62,7 @@ impl RuntimeEntry { ...@@ -62,7 +62,7 @@ impl RuntimeEntry {
} }
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct RuntimeEntries(Vec<Vc<RuntimeEntry>>); pub struct RuntimeEntries(Vec<ResolvedVc<RuntimeEntry>>);
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl RuntimeEntries { impl RuntimeEntries {
......
...@@ -118,7 +118,7 @@ impl TurbopackBuildBuilder { ...@@ -118,7 +118,7 @@ impl TurbopackBuildBuilder {
self.entry_requests self.entry_requests
.iter() .iter()
.cloned() .cloned()
.map(EntryRequest::cell) .map(EntryRequest::resolved_cell)
.collect(), .collect(),
) )
.cell(), .cell(),
......
...@@ -72,7 +72,7 @@ pub async fn get_client_runtime_entries( ...@@ -72,7 +72,7 @@ pub async fn get_client_runtime_entries(
request.to_resolved().await?, request.to_resolved().await?,
project_path.join("_".into()).to_resolved().await?, project_path.join("_".into()).to_resolved().await?,
) )
.cell(), .resolved_cell(),
) )
}; };
...@@ -82,7 +82,7 @@ pub async fn get_client_runtime_entries( ...@@ -82,7 +82,7 @@ pub async fn get_client_runtime_entries(
.to_resolved() .to_resolved()
.await?, .await?,
)) ))
.cell(), .resolved_cell(),
); );
Ok(Vc::cell(runtime_entries)) Ok(Vc::cell(runtime_entries))
......
...@@ -2,11 +2,11 @@ use std::{env::current_dir, path::PathBuf}; ...@@ -2,11 +2,11 @@ use std::{env::current_dir, path::PathBuf};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use dunce::canonicalize; use dunce::canonicalize;
use turbo_tasks::{RcStr, Vc}; use turbo_tasks::{RcStr, ResolvedVc, Vc};
use turbo_tasks_fs::{DiskFileSystem, FileSystem}; use turbo_tasks_fs::{DiskFileSystem, FileSystem};
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct EntryRequests(pub Vec<Vc<EntryRequest>>); pub struct EntryRequests(pub Vec<ResolvedVc<EntryRequest>>);
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
#[derive(Clone)] #[derive(Clone)]
......
...@@ -17,7 +17,9 @@ pub struct AvailableChunkItemInfo { ...@@ -17,7 +17,9 @@ pub struct AvailableChunkItemInfo {
pub struct OptionAvailableChunkItemInfo(Option<AvailableChunkItemInfo>); pub struct OptionAvailableChunkItemInfo(Option<AvailableChunkItemInfo>);
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct AvailableChunkItemInfoMap(FxIndexMap<Vc<Box<dyn ChunkItem>>, AvailableChunkItemInfo>); pub struct AvailableChunkItemInfoMap(
FxIndexMap<ResolvedVc<Box<dyn ChunkItem>>, AvailableChunkItemInfo>,
);
/// Allows to gather information about which assets are already available. /// Allows to gather information about which assets are already available.
/// Adding more roots will form a linked list like structure to allow caching /// Adding more roots will form a linked list like structure to allow caching
...@@ -41,7 +43,7 @@ impl AvailableChunkItems { ...@@ -41,7 +43,7 @@ impl AvailableChunkItems {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn with_chunk_items( pub async fn with_chunk_items(
self: Vc<Self>, self: ResolvedVc<Self>,
chunk_items: Vc<AvailableChunkItemInfoMap>, chunk_items: Vc<AvailableChunkItemInfoMap>,
) -> Result<Vc<Self>> { ) -> Result<Vc<Self>> {
let chunk_items = chunk_items let chunk_items = chunk_items
...@@ -49,7 +51,7 @@ impl AvailableChunkItems { ...@@ -49,7 +51,7 @@ impl AvailableChunkItems {
.into_iter() .into_iter()
.map(|(&chunk_item, &info)| async move { .map(|(&chunk_item, &info)| async move {
Ok(self Ok(self
.get(chunk_item) .get(*chunk_item)
.await? .await?
.is_none() .is_none()
.then_some((chunk_item, info))) .then_some((chunk_item, info)))
...@@ -57,7 +59,7 @@ impl AvailableChunkItems { ...@@ -57,7 +59,7 @@ impl AvailableChunkItems {
.try_flat_join() .try_flat_join()
.await?; .await?;
Ok(AvailableChunkItems { Ok(AvailableChunkItems {
parent: Some(self.to_resolved().await?), parent: Some(self),
chunk_items: Vc::cell(chunk_items.into_iter().collect()), chunk_items: Vc::cell(chunk_items.into_iter().collect()),
} }
.cell()) .cell())
...@@ -87,13 +89,13 @@ impl AvailableChunkItems { ...@@ -87,13 +89,13 @@ impl AvailableChunkItems {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn get( pub async fn get(
&self, &self,
chunk_item: Vc<Box<dyn ChunkItem>>, chunk_item: ResolvedVc<Box<dyn ChunkItem>>,
) -> Result<Vc<OptionAvailableChunkItemInfo>> { ) -> Result<Vc<OptionAvailableChunkItemInfo>> {
if let Some(&info) = self.chunk_items.await?.get(&chunk_item) { if let Some(&info) = self.chunk_items.await?.get(&chunk_item) {
return Ok(Vc::cell(Some(info))); return Ok(Vc::cell(Some(info)));
}; };
if let Some(parent) = self.parent { if let Some(parent) = self.parent {
return Ok(parent.get(chunk_item)); return Ok(parent.get(*chunk_item));
} }
Ok(Vc::cell(None)) Ok(Vc::cell(None))
} }
......
...@@ -2,7 +2,9 @@ use std::collections::HashSet; ...@@ -2,7 +2,9 @@ use std::collections::HashSet;
use anyhow::Result; use anyhow::Result;
use auto_hash_map::AutoSet; use auto_hash_map::AutoSet;
use turbo_tasks::{FxIndexMap, FxIndexSet, TryFlatJoinIterExt, TryJoinIterExt, Value, Vc}; use turbo_tasks::{
FxIndexMap, FxIndexSet, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Value, Vc,
};
use super::{ use super::{
availability_info::AvailabilityInfo, available_chunk_items::AvailableChunkItemInfo, availability_info::AvailabilityInfo, available_chunk_items::AvailableChunkItemInfo,
...@@ -12,7 +14,7 @@ use super::{ ...@@ -12,7 +14,7 @@ use super::{
use crate::{module::Module, output::OutputAssets, reference::ModuleReference}; use crate::{module::Module, output::OutputAssets, reference::ModuleReference};
pub struct MakeChunkGroupResult { pub struct MakeChunkGroupResult {
pub chunks: Vec<Vc<Box<dyn Chunk>>>, pub chunks: Vec<ResolvedVc<Box<dyn Chunk>>>,
pub availability_info: AvailabilityInfo, pub availability_info: AvailabilityInfo,
} }
...@@ -104,14 +106,17 @@ pub async fn make_chunk_group( ...@@ -104,14 +106,17 @@ pub async fn make_chunk_group(
let availability_info = { let availability_info = {
let map = chunk_items let map = chunk_items
.iter() .iter()
.map(|(&chunk_item, async_info)| { .map(|(&chunk_item, async_info)| async move {
( Ok((
chunk_item, chunk_item.to_resolved().await?,
AvailableChunkItemInfo { AvailableChunkItemInfo {
is_async: async_info.is_some(), is_async: async_info.is_some(),
}, },
) ))
}) })
.try_join()
.await?
.into_iter()
.collect(); .collect();
let map = Vc::cell(map); let map = Vc::cell(map);
availability_info.with_chunk_items(map).await? availability_info.with_chunk_items(map).await?
...@@ -121,7 +126,7 @@ pub async fn make_chunk_group( ...@@ -121,7 +126,7 @@ pub async fn make_chunk_group(
let async_loaders = async_modules let async_loaders = async_modules
.into_iter() .into_iter()
.map(|module| { .map(|module| {
chunking_context.async_loader_chunk_item(module, Value::new(availability_info)) chunking_context.async_loader_chunk_item(*module, Value::new(availability_info))
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let has_async_loaders = !async_loaders.is_empty(); let has_async_loaders = !async_loaders.is_empty();
...@@ -164,8 +169,14 @@ pub async fn make_chunk_group( ...@@ -164,8 +169,14 @@ pub async fn make_chunk_group(
chunks.extend(async_loader_chunks.iter().copied()); chunks.extend(async_loader_chunks.iter().copied());
} }
let resolved_chunks = chunks
.into_iter()
.map(|chunk| chunk.to_resolved())
.try_join()
.await?;
Ok(MakeChunkGroupResult { Ok(MakeChunkGroupResult {
chunks, chunks: resolved_chunks,
availability_info, availability_info,
}) })
} }
......
...@@ -190,7 +190,7 @@ type AsyncInfo = FxIndexMap<Vc<Box<dyn ChunkItem>>, Vec<Vc<Box<dyn ChunkItem>>>> ...@@ -190,7 +190,7 @@ type AsyncInfo = FxIndexMap<Vc<Box<dyn ChunkItem>>, Vec<Vc<Box<dyn ChunkItem>>>>
pub struct ChunkContentResult { pub struct ChunkContentResult {
pub chunk_items: FxIndexSet<Vc<Box<dyn ChunkItem>>>, pub chunk_items: FxIndexSet<Vc<Box<dyn ChunkItem>>>,
pub async_modules: FxIndexSet<Vc<Box<dyn ChunkableModule>>>, pub async_modules: FxIndexSet<ResolvedVc<Box<dyn ChunkableModule>>>,
pub external_module_references: FxIndexSet<Vc<Box<dyn ModuleReference>>>, pub external_module_references: FxIndexSet<Vc<Box<dyn ModuleReference>>>,
/// A map from local module to all children from which the async module /// A map from local module to all children from which the async module
/// status is inherited /// status is inherited
...@@ -245,7 +245,7 @@ enum ChunkContentGraphNode { ...@@ -245,7 +245,7 @@ enum ChunkContentGraphNode {
/// will be inherited. /// will be inherited.
InheritAsyncInfo { InheritAsyncInfo {
item: Vc<Box<dyn ChunkItem>>, item: Vc<Box<dyn ChunkItem>>,
references: Vec<(Vc<Box<dyn ChunkItem>>, InheritAsyncEdge)>, references: Vec<(ResolvedVc<Box<dyn ChunkItem>>, InheritAsyncEdge)>,
}, },
} }
...@@ -413,7 +413,10 @@ async fn graph_node_to_referenced_nodes( ...@@ -413,7 +413,10 @@ async fn graph_node_to_referenced_nodes(
ident: module.ident().to_string().await?, ident: module.ident().to_string().await?,
}, },
}), }),
Some((chunk_item, InheritAsyncEdge::LocalModule)), Some((
chunk_item.to_resolved().await?,
InheritAsyncEdge::LocalModule,
)),
)) ))
} }
ChunkingType::Passthrough => { ChunkingType::Passthrough => {
...@@ -590,10 +593,7 @@ async fn chunk_content_internal_parallel( ...@@ -590,10 +593,7 @@ async fn chunk_content_internal_parallel(
Ok(Some(ChunkGraphEdge { Ok(Some(ChunkGraphEdge {
key: Some(entry.to_resolved().await?), key: Some(entry.to_resolved().await?),
node: ChunkContentGraphNode::ChunkItem { node: ChunkContentGraphNode::ChunkItem {
item: chunkable_module item: chunkable_module.as_chunk_item(chunking_context),
.as_chunk_item(chunking_context)
.resolve()
.await?,
ident: chunkable_module.ident().to_string().await?, ident: chunkable_module.ident().to_string().await?,
}, },
})) }))
...@@ -626,10 +626,10 @@ async fn chunk_content_internal_parallel( ...@@ -626,10 +626,10 @@ async fn chunk_content_internal_parallel(
match graph_node { match graph_node {
ChunkContentGraphNode::PassthroughChunkItem { .. } => {} ChunkContentGraphNode::PassthroughChunkItem { .. } => {}
ChunkContentGraphNode::ChunkItem { item, .. } => { ChunkContentGraphNode::ChunkItem { item, .. } => {
chunk_items.insert(item); chunk_items.insert(*item.to_resolved().await?);
} }
ChunkContentGraphNode::AsyncModule { module } => { ChunkContentGraphNode::AsyncModule { module } => {
let module = module.resolve().await?; let module = module.to_resolved().await?;
async_modules.insert(module); async_modules.insert(module);
} }
ChunkContentGraphNode::ExternalModuleReference(reference) => { ChunkContentGraphNode::ExternalModuleReference(reference) => {
...@@ -640,12 +640,12 @@ async fn chunk_content_internal_parallel( ...@@ -640,12 +640,12 @@ async fn chunk_content_internal_parallel(
for &(reference, ty) in &references { for &(reference, ty) in &references {
match ty { match ty {
InheritAsyncEdge::LocalModule => local_back_edges_inherit_async InheritAsyncEdge::LocalModule => local_back_edges_inherit_async
.entry(reference) .entry(*reference)
.or_insert_with(Vec::new) .or_insert_with(Vec::new)
.push(item), .push(item),
InheritAsyncEdge::AvailableAsyncModule => { InheritAsyncEdge::AvailableAsyncModule => {
available_async_modules_back_edges_inherit_async available_async_modules_back_edges_inherit_async
.entry(reference) .entry(*reference)
.or_insert_with(Vec::new) .or_insert_with(Vec::new)
.push(item) .push(item)
} }
...@@ -654,7 +654,7 @@ async fn chunk_content_internal_parallel( ...@@ -654,7 +654,7 @@ async fn chunk_content_internal_parallel(
forward_edges_inherit_async forward_edges_inherit_async
.entry(item) .entry(item)
.or_insert_with(Vec::new) .or_insert_with(Vec::new)
.extend(references.into_iter().map(|(r, _)| r)); .extend(references.into_iter().map(|(r, _)| *r));
} }
} }
} }
...@@ -733,17 +733,23 @@ pub struct ChunkItems(pub Vec<Vc<Box<dyn ChunkItem>>>); ...@@ -733,17 +733,23 @@ pub struct ChunkItems(pub Vec<Vc<Box<dyn ChunkItem>>>);
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct AsyncModuleInfo { pub struct AsyncModuleInfo {
pub referenced_async_modules: AutoSet<Vc<Box<dyn ChunkItem>>>, pub referenced_async_modules: AutoSet<ResolvedVc<Box<dyn ChunkItem>>>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl AsyncModuleInfo { impl AsyncModuleInfo {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(referenced_async_modules: Vec<Vc<Box<dyn ChunkItem>>>) -> Vc<Self> { pub async fn new(referenced_async_modules: Vec<Vc<Box<dyn ChunkItem>>>) -> Result<Vc<Self>> {
Self { let resolved_modules = referenced_async_modules
referenced_async_modules: referenced_async_modules.into_iter().collect(), .into_iter()
.map(|m| m.to_resolved())
.try_join()
.await?;
Ok(Self {
referenced_async_modules: resolved_modules.into_iter().collect(),
} }
.cell() .cell())
} }
} }
......
...@@ -4,17 +4,17 @@ ...@@ -4,17 +4,17 @@
//! their size and eliminating duplicates between them. //! their size and eliminating duplicates between them.
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{TryJoinIterExt, Vc}; use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
use turbo_tasks_fs::{FileSystemPath, FileSystemPathOption}; use turbo_tasks_fs::{FileSystemPath, FileSystemPathOption};
use crate::chunk::containment_tree::{ContainmentTree, ContainmentTreeKey}; use crate::chunk::containment_tree::{ContainmentTree, ContainmentTreeKey};
#[derive(Debug, Clone, Eq, PartialEq, Hash)] #[derive(Debug, Clone, Eq, PartialEq, Hash)]
struct FileSystemPathKey(Vc<FileSystemPath>); struct FileSystemPathKey(ResolvedVc<FileSystemPath>);
impl FileSystemPathKey { impl FileSystemPathKey {
async fn new(path: Vc<FileSystemPath>) -> Result<Self> { async fn new(path: Vc<FileSystemPath>) -> Result<Self> {
Ok(Self(path.resolve().await?)) Ok(Self(path.to_resolved().await?))
} }
} }
......
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{RcStr, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, ValueToString, Vc};
use super::{ use super::{
utils::{children_from_output_assets, content_to_details}, utils::{children_from_output_assets, content_to_details},
...@@ -8,15 +8,19 @@ use super::{ ...@@ -8,15 +8,19 @@ use super::{
use crate::{asset::Asset, output::OutputAsset}; use crate::{asset::Asset, output::OutputAsset};
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct IntrospectableOutputAsset(Vc<Box<dyn OutputAsset>>); pub struct IntrospectableOutputAsset(ResolvedVc<Box<dyn OutputAsset>>);
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl IntrospectableOutputAsset { impl IntrospectableOutputAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn new(asset: Vc<Box<dyn OutputAsset>>) -> Result<Vc<Box<dyn Introspectable>>> { pub async fn new(
Ok(Vc::try_resolve_sidecast::<Box<dyn Introspectable>>(asset) asset: ResolvedVc<Box<dyn OutputAsset>>,
) -> Result<Vc<Box<dyn Introspectable>>> {
Ok(*ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(asset)
.await? .await?
.unwrap_or_else(|| Vc::upcast(IntrospectableOutputAsset(asset).cell()))) .unwrap_or_else(|| {
ResolvedVc::upcast(IntrospectableOutputAsset(asset).resolved_cell())
}))
} }
} }
......
use std::fmt::Display; use std::fmt::Display;
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{FxIndexMap, RcStr, Vc}; use turbo_tasks::{FxIndexMap, RcStr, ResolvedVc, Vc};
use crate::{module::Module, resolve::ModulePart}; use crate::{module::Module, resolve::ModulePart};
...@@ -42,7 +42,7 @@ pub enum ImportWithType { ...@@ -42,7 +42,7 @@ pub enum ImportWithType {
#[turbo_tasks::value(serialization = "auto_for_input")] #[turbo_tasks::value(serialization = "auto_for_input")]
#[derive(Debug, Default, Clone, Hash)] #[derive(Debug, Default, Clone, Hash)]
pub enum EcmaScriptModulesReferenceSubType { pub enum EcmaScriptModulesReferenceSubType {
ImportPart(Vc<ModulePart>), ImportPart(ResolvedVc<ModulePart>),
Import, Import,
ImportWithType(ImportWithType), ImportWithType(ImportWithType),
DynamicImport, DynamicImport,
......
...@@ -117,7 +117,7 @@ pub enum ReplacedImportMapping { ...@@ -117,7 +117,7 @@ pub enum ReplacedImportMapping {
Ignore, Ignore,
Empty, Empty,
Alternatives(Vec<Vc<ReplacedImportMapping>>), Alternatives(Vec<Vc<ReplacedImportMapping>>),
Dynamic(Vc<Box<dyn ImportMappingReplacement>>), Dynamic(ResolvedVc<Box<dyn ImportMappingReplacement>>),
} }
impl ImportMapping { impl ImportMapping {
...@@ -162,7 +162,9 @@ impl AliasTemplate for Vc<ImportMapping> { ...@@ -162,7 +162,9 @@ impl AliasTemplate for Vc<ImportMapping> {
.try_join() .try_join()
.await?, .await?,
), ),
ImportMapping::Dynamic(replacement) => ReplacedImportMapping::Dynamic(*replacement), ImportMapping::Dynamic(replacement) => {
ReplacedImportMapping::Dynamic(replacement.to_resolved().await?)
}
} }
.cell()) .cell())
}) })
...@@ -300,14 +302,18 @@ impl ImportMap { ...@@ -300,14 +302,18 @@ impl ImportMap {
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct ResolvedMap { pub struct ResolvedMap {
pub by_glob: Vec<(Vc<FileSystemPath>, Vc<Glob>, Vc<ImportMapping>)>, pub by_glob: Vec<(
ResolvedVc<FileSystemPath>,
ResolvedVc<Glob>,
ResolvedVc<ImportMapping>,
)>,
} }
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum ImportMapResult { pub enum ImportMapResult {
Result(Vc<ResolveResult>), Result(Vc<ResolveResult>),
Alias(Vc<Request>, Option<Vc<FileSystemPath>>), Alias(ResolvedVc<Request>, Option<ResolvedVc<FileSystemPath>>),
Alternatives(Vec<ImportMapResult>), Alternatives(Vec<ImportMapResult>),
NoEntry, NoEntry,
} }
...@@ -320,25 +326,28 @@ async fn import_mapping_to_result( ...@@ -320,25 +326,28 @@ async fn import_mapping_to_result(
Ok(match &*mapping.await? { Ok(match &*mapping.await? {
ReplacedImportMapping::Direct(result) => ImportMapResult::Result(*result), ReplacedImportMapping::Direct(result) => ImportMapResult::Result(*result),
ReplacedImportMapping::External(name, ty) => ImportMapResult::Result( ReplacedImportMapping::External(name, ty) => ImportMapResult::Result(
ResolveResult::primary(if let Some(name) = name { *ResolveResult::primary(if let Some(name) = name {
ResolveResultItem::External(name.clone(), *ty) ResolveResultItem::External(name.clone(), *ty)
} else if let Some(request) = request.await?.request() { } else if let Some(request) = request.await?.request() {
ResolveResultItem::External(request, *ty) ResolveResultItem::External(request, *ty)
} else { } else {
bail!("Cannot resolve external reference without request") bail!("Cannot resolve external reference without request")
}) })
.cell(), .resolved_cell(),
),
ReplacedImportMapping::Ignore => ImportMapResult::Result(
*ResolveResult::primary(ResolveResultItem::Ignore).resolved_cell(),
),
ReplacedImportMapping::Empty => ImportMapResult::Result(
*ResolveResult::primary(ResolveResultItem::Empty).resolved_cell(),
), ),
ReplacedImportMapping::Ignore => {
ImportMapResult::Result(ResolveResult::primary(ResolveResultItem::Ignore).into())
}
ReplacedImportMapping::Empty => {
ImportMapResult::Result(ResolveResult::primary(ResolveResultItem::Empty).into())
}
ReplacedImportMapping::PrimaryAlternative(name, context) => { ReplacedImportMapping::PrimaryAlternative(name, context) => {
let request = Request::parse(Value::new(name.clone())); let request = Request::parse(Value::new(name.clone()));
let context_resolved = match context {
ImportMapResult::Alias(request, *context) Some(c) => Some((*c).to_resolved().await?),
None => None,
};
ImportMapResult::Alias(request.to_resolved().await?, context_resolved)
} }
ReplacedImportMapping::Alternatives(list) => ImportMapResult::Alternatives( ReplacedImportMapping::Alternatives(list) => ImportMapResult::Alternatives(
list.iter() list.iter()
......
...@@ -9,7 +9,7 @@ use lazy_static::lazy_static; ...@@ -9,7 +9,7 @@ use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument; use tracing::Instrument;
use turbo_tasks::{trace::TraceRawVcs, RcStr, Value, ValueToString, Vc}; use turbo_tasks::{trace::TraceRawVcs, RcStr, ResolvedVc, Value, ValueToString, Vc};
use turbo_tasks_fs::{ use turbo_tasks_fs::{
util::normalize_path, DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath, util::normalize_path, DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath,
LinkContent, LinkType, LinkContent, LinkType,
...@@ -1322,7 +1322,7 @@ pub struct PatternMatches(Vec<PatternMatch>); ...@@ -1322,7 +1322,7 @@ pub struct PatternMatches(Vec<PatternMatch>);
/// symlinks when they are interested in that. /// symlinks when they are interested in that.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn read_matches( pub async fn read_matches(
lookup_dir: Vc<FileSystemPath>, lookup_dir: ResolvedVc<FileSystemPath>,
prefix: RcStr, prefix: RcStr,
force_in_lookup_dir: bool, force_in_lookup_dir: bool,
pattern: Vc<Pattern>, pattern: Vc<Pattern>,
...@@ -1468,17 +1468,17 @@ pub async fn read_matches( ...@@ -1468,17 +1468,17 @@ pub async fn read_matches(
if let Some(pos) = pat.match_position(&prefix) { if let Some(pos) = pat.match_position(&prefix) {
results.push(( results.push((
pos, pos,
PatternMatch::Directory(prefix.clone().into(), lookup_dir), PatternMatch::Directory(prefix.clone().into(), *lookup_dir),
)); ));
} }
prefix.pop(); prefix.pop();
} }
if prefix.is_empty() { if prefix.is_empty() {
if let Some(pos) = pat.match_position("./") { if let Some(pos) = pat.match_position("./") {
results.push((pos, PatternMatch::Directory("./".into(), lookup_dir))); results.push((pos, PatternMatch::Directory("./".into(), *lookup_dir)));
} }
if let Some(pos) = pat.could_match_position("./") { if let Some(pos) = pat.could_match_position("./") {
nested.push((pos, read_matches(lookup_dir, "./".into(), false, pattern))); nested.push((pos, read_matches(*lookup_dir, "./".into(), false, pattern)));
} }
} else { } else {
prefix.push('/'); prefix.push('/');
...@@ -1486,7 +1486,7 @@ pub async fn read_matches( ...@@ -1486,7 +1486,7 @@ pub async fn read_matches(
if let Some(pos) = pat.could_match_position(&prefix) { if let Some(pos) = pat.could_match_position(&prefix) {
nested.push(( nested.push((
pos, pos,
read_matches(lookup_dir, prefix.to_string().into(), false, pattern), read_matches(*lookup_dir, prefix.to_string().into(), false, pattern),
)); ));
} }
prefix.pop(); prefix.pop();
...@@ -1495,7 +1495,7 @@ pub async fn read_matches( ...@@ -1495,7 +1495,7 @@ pub async fn read_matches(
if let Some(pos) = pat.could_match_position(&prefix) { if let Some(pos) = pat.could_match_position(&prefix) {
nested.push(( nested.push((
pos, pos,
read_matches(lookup_dir, prefix.to_string().into(), false, pattern), read_matches(*lookup_dir, prefix.to_string().into(), false, pattern),
)); ));
} }
prefix.pop(); prefix.pop();
......
...@@ -123,7 +123,7 @@ impl AsyncModule { ...@@ -123,7 +123,7 @@ impl AsyncModule {
ReferencedAsset::Some(placeable) => { ReferencedAsset::Some(placeable) => {
let chunk_item = placeable let chunk_item = placeable
.as_chunk_item(Vc::upcast(chunking_context)) .as_chunk_item(Vc::upcast(chunking_context))
.resolve() .to_resolved()
.await?; .await?;
if async_module_info if async_module_info
.referenced_async_modules .referenced_async_modules
......
...@@ -153,7 +153,7 @@ impl ModuleReference for EsmAssetReference { ...@@ -153,7 +153,7 @@ impl ModuleReference for EsmAssetReference {
let ty = if matches!(self.annotations.module_type(), Some("json")) { let ty = if matches!(self.annotations.module_type(), Some("json")) {
EcmaScriptModulesReferenceSubType::ImportWithType(ImportWithType::Json) EcmaScriptModulesReferenceSubType::ImportWithType(ImportWithType::Json)
} else if let Some(part) = &self.export_name { } else if let Some(part) = &self.export_name {
EcmaScriptModulesReferenceSubType::ImportPart(**part) EcmaScriptModulesReferenceSubType::ImportPart(*part)
} else { } else {
EcmaScriptModulesReferenceSubType::Import EcmaScriptModulesReferenceSubType::Import
}; };
......
...@@ -282,7 +282,7 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -282,7 +282,7 @@ impl ChunkingContext for NodeJsChunkingContext {
let mut assets: Vec<Vc<Box<dyn OutputAsset>>> = chunks let mut assets: Vec<Vc<Box<dyn OutputAsset>>> = chunks
.iter() .iter()
.map(|chunk| self.generate_chunk(*chunk)) .map(|chunk| self.generate_chunk(**chunk))
.collect(); .collect();
// Resolve assets // Resolve assets
...@@ -333,7 +333,7 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -333,7 +333,7 @@ impl ChunkingContext for NodeJsChunkingContext {
let other_chunks: Vec<_> = extra_chunks let other_chunks: Vec<_> = extra_chunks
.iter() .iter()
.copied() .copied()
.chain(chunks.iter().map(|chunk| self.generate_chunk(*chunk))) .chain(chunks.iter().map(|chunk| self.generate_chunk(**chunk)))
.collect(); .collect();
let Some(module) = Vc::try_resolve_downcast(module).await? else { let Some(module) = Vc::try_resolve_downcast(module).await? else {
......
...@@ -484,7 +484,7 @@ async fn process_default_internal( ...@@ -484,7 +484,7 @@ async fn process_default_internal(
let reference_type = reference_type.into_value(); let reference_type = reference_type.into_value();
let part: Option<Vc<ModulePart>> = match &reference_type { let part: Option<Vc<ModulePart>> = match &reference_type {
ReferenceType::EcmaScriptModules(EcmaScriptModulesReferenceSubType::ImportPart(part)) => { ReferenceType::EcmaScriptModules(EcmaScriptModulesReferenceSubType::ImportPart(part)) => {
Some(*part) Some(**part)
} }
_ => None, _ => None,
}; };
......
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