diff --git a/crates/next-api/src/app.rs b/crates/next-api/src/app.rs index 4cdae31d843f1..df0e62eb36994 100644 --- a/crates/next-api/src/app.rs +++ b/crates/next-api/src/app.rs @@ -38,8 +38,8 @@ use next_core::{ use serde::{Deserialize, Serialize}; use tracing::Instrument; use turbo_tasks::{ - fxindexset, trace::TraceRawVcs, Completion, FxIndexMap, FxIndexSet, RcStr, TryJoinIterExt, - Value, ValueToString, Vc, + fxindexset, trace::TraceRawVcs, Completion, FxIndexMap, FxIndexSet, RcStr, ResolvedVc, + TryJoinIterExt, Value, ValueToString, Vc, }; use turbo_tasks_env::{CustomProcessEnv, ProcessEnv}; use turbo_tasks_fs::{File, FileContent, FileSystemPath}; @@ -611,7 +611,7 @@ impl AppProject { .await? .context("expected Next.js client runtime to resolve to a module")?; - Ok(client_main_module) + Ok(*client_main_module) } } @@ -889,7 +889,7 @@ impl AppEndpoint { let ServerEntries { server_component_entries, server_utils, - } = &*find_server_entries(rsc_entry).await?; + } = &*find_server_entries(*rsc_entry).await?; let mut client_references = client_reference_graph( server_utils.clone(), @@ -901,7 +901,7 @@ impl AppEndpoint { for module in server_component_entries .iter() .map(|m| Vc::upcast::>(*m)) - .chain(std::iter::once(rsc_entry)) + .chain(std::iter::once(*rsc_entry)) { let current_client_references = client_reference_graph(vec![module], client_references.visited_nodes) @@ -1085,7 +1085,7 @@ impl AppEndpoint { let server_action_manifest_loader = if let Some(app_server_reference_modules) = app_server_reference_modules { let server_action_manifest = create_server_actions_manifest( - Vc::upcast(app_entry.rsc_entry), + *ResolvedVc::upcast(app_entry.rsc_entry), app_server_reference_modules, this.app_project.project().project_path(), node_root, @@ -1240,7 +1240,7 @@ impl AppEndpoint { // create react-loadable-manifest for next/dynamic let mut dynamic_import_modules = collect_next_dynamic_imports( - vec![Vc::upcast(app_entry.rsc_entry)], + vec![*ResolvedVc::upcast(app_entry.rsc_entry)], Vc::upcast(this.app_project.client_module_context()), VisitedDynamicImportModules::empty(), ) @@ -1290,7 +1290,7 @@ impl AppEndpoint { // create react-loadable-manifest for next/dynamic let availability_info = Value::new(AvailabilityInfo::Root); let mut dynamic_import_modules = collect_next_dynamic_imports( - vec![Vc::upcast(app_entry.rsc_entry)], + vec![*ResolvedVc::upcast(app_entry.rsc_entry)], Vc::upcast(this.app_project.client_module_context()), VisitedDynamicImportModules::empty(), ) @@ -1353,10 +1353,10 @@ impl AppEndpoint { .edge_rsc_runtime_entries() .await? .clone_value(); - let evaluatable = Vc::try_resolve_sidecast(app_entry.rsc_entry) + let evaluatable = ResolvedVc::try_sidecast(app_entry.rsc_entry) .await? .context("Entry module must be evaluatable")?; - evaluatable_assets.push(evaluatable); + evaluatable_assets.push(*evaluatable); if let Some(server_action_manifest_loader) = server_action_manifest_loader { evaluatable_assets.push(server_action_manifest_loader); @@ -1461,7 +1461,7 @@ impl AppEndpoint { ) .into(), ), - app_entry.rsc_entry, + *app_entry.rsc_entry, Vc::cell(evaluatable_assets), current_chunks, Value::new(current_availability_info), diff --git a/crates/next-api/src/dynamic_imports.rs b/crates/next-api/src/dynamic_imports.rs index 77ac436dc4655..98d4cf68ee9cc 100644 --- a/crates/next-api/src/dynamic_imports.rs +++ b/crates/next-api/src/dynamic_imports.rs @@ -28,7 +28,7 @@ use turbopack_core::{ use turbopack_ecmascript::{parse::ParseResult, resolve::esm_resolve, EcmascriptParsable}; async fn collect_chunk_group_inner( - dynamic_import_entries: FxIndexMap>, DynamicImportedModules>, + dynamic_import_entries: FxIndexMap>, DynamicImportedModules>, mut build_chunk: F, ) -> Result> where @@ -46,7 +46,7 @@ where *chunk } else { let Some(module) = - Vc::try_resolve_sidecast::>(imported_module).await? + ResolvedVc::try_sidecast::>(imported_module).await? else { bail!("module must be evaluatable"); }; @@ -57,7 +57,7 @@ where // naive hash to have additional // chunks in case if there are same modules being imported in different // origins. - let chunk_group = build_chunk(module).await?; + let chunk_group = build_chunk(*module).await?; chunks_hash.insert(imported_raw_str.clone(), chunk_group); chunk_group }; @@ -74,7 +74,7 @@ where pub(crate) async fn collect_chunk_group( chunking_context: Vc>, - dynamic_import_entries: FxIndexMap>, DynamicImportedModules>, + dynamic_import_entries: FxIndexMap>, DynamicImportedModules>, availability_info: Value, ) -> Result> { collect_chunk_group_inner(dynamic_import_entries, |module| async move { @@ -85,7 +85,7 @@ pub(crate) async fn collect_chunk_group( pub(crate) async fn collect_evaluated_chunk_group( chunking_context: Vc>, - dynamic_import_entries: FxIndexMap>, DynamicImportedModules>, + dynamic_import_entries: FxIndexMap>, DynamicImportedModules>, ) -> Result> { collect_chunk_group_inner(dynamic_import_entries, |module| async move { if let Some(module) = Vc::try_resolve_downcast::>(module).await? { @@ -103,7 +103,7 @@ pub(crate) async fn collect_evaluated_chunk_group( #[turbo_tasks::value(shared)] pub struct NextDynamicImportsResult { - pub client_dynamic_imports: FxIndexMap>, DynamicImportedModules>, + pub client_dynamic_imports: FxIndexMap>, DynamicImportedModules>, pub visited_modules: Vc, } @@ -186,7 +186,7 @@ pub(crate) async fn collect_next_dynamic_imports( }); // Consolidate import mappings into a single indexmap - let mut import_mappings: FxIndexMap>, DynamicImportedModules> = + let mut import_mappings: FxIndexMap>, DynamicImportedModules> = FxIndexMap::default(); for module_mapping in imported_modules_mapping { @@ -282,10 +282,10 @@ impl turbo_tasks::graph::Visit for NextDynamicVisit { #[turbo_tasks::function] async fn build_dynamic_imports_map_for_module( client_asset_context: Vc>, - server_module: Vc>, + server_module: ResolvedVc>, ) -> Result> { let Some(ecmascript_asset) = - Vc::try_resolve_sidecast::>(server_module).await? + ResolvedVc::try_sidecast::>(server_module).await? else { return Ok(Vc::cell(None)); }; @@ -409,17 +409,19 @@ impl Visit for CollectImportSourceVisitor { } } -pub type DynamicImportedModules = Vec<(RcStr, Vc>)>; +pub type DynamicImportedModules = Vec<(RcStr, ResolvedVc>)>; pub type DynamicImportedOutputAssets = Vec<(RcStr, Vc)>; /// A struct contains mapping for the dynamic imports to construct chunk per /// each individual module (Origin Module, Vec<(ImportSourceString, Module)>) #[turbo_tasks::value(transparent)] -pub struct DynamicImportsMap(pub (Vc>, DynamicImportedModules)); +pub struct DynamicImportsMap(pub (ResolvedVc>, DynamicImportedModules)); /// An Option wrapper around [DynamicImportsMap]. #[turbo_tasks::value(transparent)] pub struct OptionDynamicImportsMap(Option>); #[turbo_tasks::value(transparent)] -pub struct DynamicImportedChunks(pub FxIndexMap>, DynamicImportedOutputAssets>); +pub struct DynamicImportedChunks( + pub FxIndexMap>, DynamicImportedOutputAssets>, +); diff --git a/crates/next-api/src/instrumentation.rs b/crates/next-api/src/instrumentation.rs index a0ce8a84509bc..72c63186c348a 100644 --- a/crates/next-api/src/instrumentation.rs +++ b/crates/next-api/src/instrumentation.rs @@ -6,7 +6,7 @@ use next_core::{ next_server::{get_server_runtime_entries, ServerContextType}, }; use tracing::Instrument; -use turbo_tasks::{Completion, RcStr, Value, Vc}; +use turbo_tasks::{Completion, RcStr, ResolvedVc, Value, Vc}; use turbo_tasks_fs::{File, FileContent, FileSystemPath}; use turbopack_core::{ asset::AssetContent, @@ -65,27 +65,31 @@ impl InstrumentationEndpoint { } #[turbo_tasks::function] - fn core_modules(&self) -> Vc { + async fn core_modules(&self) -> Result> { let userland_module = self .asset_context .process( self.source, Value::new(ReferenceType::Entry(EntryReferenceSubType::Instrumentation)), ) - .module(); + .module() + .to_resolved() + .await?; let edge_entry_module = wrap_edge_entry( self.asset_context, self.project.project_path(), - userland_module, + *userland_module, "instrumentation".into(), - ); + ) + .to_resolved() + .await?; - InstrumentationCoreModules { + Ok(InstrumentationCoreModules { userland_module, edge_entry_module, } - .cell() + .cell()) } #[turbo_tasks::function] @@ -107,15 +111,15 @@ impl InstrumentationEndpoint { .clone_value(); let Some(module) = - Vc::try_resolve_downcast::>(module).await? + ResolvedVc::try_downcast::>(module).await? else { bail!("Entry module must be evaluatable"); }; - let Some(evaluatable) = Vc::try_resolve_sidecast(module).await? else { + let Some(evaluatable) = ResolvedVc::try_sidecast(module).await? else { bail!("Entry module must be evaluatable"); }; - evaluatable_assets.push(evaluatable); + evaluatable_assets.push(*evaluatable); let edge_chunking_context = this.project.edge_chunking_context(false); @@ -136,7 +140,7 @@ impl InstrumentationEndpoint { let userland_module = self.core_modules().await?.userland_module; - let Some(module) = Vc::try_resolve_downcast(userland_module).await? else { + let Some(module) = ResolvedVc::try_downcast(userland_module).await? else { bail!("Entry module must be evaluatable"); }; @@ -145,7 +149,7 @@ impl InstrumentationEndpoint { this.project .node_root() .join("server/instrumentation.js".into()), - module, + *module, get_server_runtime_entries( Value::new(ServerContextType::Instrumentation { app_dir: this.app_dir, @@ -211,8 +215,8 @@ impl InstrumentationEndpoint { #[turbo_tasks::value] struct InstrumentationCoreModules { - pub userland_module: Vc>, - pub edge_entry_module: Vc>, + pub userland_module: ResolvedVc>, + pub edge_entry_module: ResolvedVc>, } #[turbo_tasks::value_impl] diff --git a/crates/next-api/src/middleware.rs b/crates/next-api/src/middleware.rs index a5266655dfa7f..a7dd8eec6d42c 100644 --- a/crates/next-api/src/middleware.rs +++ b/crates/next-api/src/middleware.rs @@ -309,7 +309,7 @@ impl Endpoint for MiddlewareEndpoint { } #[turbo_tasks::function] - fn root_modules(self: Vc) -> Vc { - Vc::cell(vec![self.userland_module()]) + async fn root_modules(self: Vc) -> Result> { + Ok(Vc::cell(vec![self.userland_module().to_resolved().await?])) } } diff --git a/crates/next-api/src/pages.rs b/crates/next-api/src/pages.rs index e2887ed623c28..51839dbeb909a 100644 --- a/crates/next-api/src/pages.rs +++ b/crates/next-api/src/pages.rs @@ -28,7 +28,8 @@ use next_core::{ use serde::{Deserialize, Serialize}; use tracing::Instrument; use turbo_tasks::{ - trace::TraceRawVcs, Completion, FxIndexMap, RcStr, TaskInput, TryJoinIterExt, Value, Vc, + trace::TraceRawVcs, Completion, FxIndexMap, RcStr, ResolvedVc, TaskInput, TryJoinIterExt, + Value, Vc, }; use turbo_tasks_fs::{ self, File, FileContent, FileSystem, FileSystemPath, FileSystemPathOption, VirtualFileSystem, @@ -583,7 +584,7 @@ impl PagesProject { .await? .context("expected Next.js client runtime to resolve to a module")?; - Ok(client_main_module) + Ok(*client_main_module) } } @@ -787,7 +788,7 @@ impl PageEndpoint { }; Ok(InternalSsrChunkModule { - ssr_module, + ssr_module: ssr_module.to_resolved().await?, runtime: config.runtime, } .cell()) @@ -812,7 +813,7 @@ impl PageEndpoint { } = *self.internal_ssr_chunk_module().await?; let dynamic_import_modules = collect_next_dynamic_imports( - vec![Vc::upcast(ssr_module)], + vec![*ResolvedVc::upcast(ssr_module)], this.pages_project.client_module_context(), VisitedDynamicImportModules::empty(), ) @@ -823,7 +824,7 @@ impl PageEndpoint { let is_edge = matches!(runtime, NextRuntime::Edge); if is_edge { let mut evaluatable_assets = edge_runtime_entries.await?.clone_value(); - let evaluatable = Vc::try_resolve_sidecast(ssr_module) + let evaluatable = *ResolvedVc::try_sidecast(ssr_module) .await? .context("could not process page loader entry module")?; evaluatable_assets.push(evaluatable); @@ -860,7 +861,7 @@ impl PageEndpoint { } = *chunking_context .entry_chunk_group( ssr_entry_chunk_path, - ssr_module, + *ssr_module, runtime_entries, OutputAssets::empty(), Value::new(AvailabilityInfo::Root), @@ -1211,16 +1212,10 @@ impl PageEndpoint { #[turbo_tasks::value] pub struct InternalSsrChunkModule { - pub ssr_module: Vc>, + pub ssr_module: ResolvedVc>, pub runtime: NextRuntime, } -#[turbo_tasks::value] -pub struct ClientChunksModules { - pub client_module: Vc>, - pub client_main_module: Vc>, -} - #[turbo_tasks::value_impl] impl Endpoint for PageEndpoint { #[turbo_tasks::function] @@ -1314,7 +1309,7 @@ impl Endpoint for PageEndpoint { modules.push(ssr_chunk_module.ssr_module); if let PageEndpointType::Html = this.ty { - modules.push(self.client_module()); + modules.push(self.client_module().to_resolved().await?); } Ok(Vc::cell(modules)) diff --git a/crates/next-api/src/project.rs b/crates/next-api/src/project.rs index 0b9127f93da1e..d344e3b28edc6 100644 --- a/crates/next-api/src/project.rs +++ b/crates/next-api/src/project.rs @@ -1278,10 +1278,10 @@ impl Project { #[turbo_tasks::function] pub async fn client_main_modules(self: Vc) -> Result> { let pages_project = self.pages_project(); - let mut modules = vec![pages_project.client_main_module()]; + let mut modules = vec![pages_project.client_main_module().to_resolved().await?]; if let Some(app_project) = *self.app_project().await? { - modules.push(app_project.client_main_module()); + modules.push(app_project.client_main_module().to_resolved().await?); } Ok(Vc::cell(modules)) diff --git a/crates/next-api/src/server_actions.rs b/crates/next-api/src/server_actions.rs index 69290b003fcd1..b776d16aae235 100644 --- a/crates/next-api/src/server_actions.rs +++ b/crates/next-api/src/server_actions.rs @@ -19,7 +19,7 @@ use swc_core::{ use tracing::Instrument; use turbo_tasks::{ graph::{GraphTraversal, NonDeterministic}, - FxIndexMap, RcStr, TryFlatJoinIterExt, Value, ValueToString, Vc, + FxIndexMap, RcStr, ResolvedVc, TryFlatJoinIterExt, Value, ValueToString, Vc, }; use turbo_tasks_fs::{self, rope::RopeBuilder, File, FileSystemPath}; use turbopack_core::{ @@ -181,7 +181,7 @@ async fn build_manifest( /// returned along with the module which exports that action. #[turbo_tasks::function] async fn get_actions( - rsc_entry: Vc>, + rsc_entry: ResolvedVc>, server_reference_modules: Vc, asset_context: Vc>, ) -> Result> { @@ -213,7 +213,7 @@ async fn get_actions( let module = if *layer == ActionLayer::Rsc { *module } else { - to_rsc_context(*module, asset_context).await? + to_rsc_context(**module, asset_context).await? }; for (hash_id, name) in &*actions_map.await? { @@ -242,7 +242,7 @@ async fn get_actions( async fn to_rsc_context( module: Vc>, asset_context: Vc>, -) -> Result>> { +) -> Result>> { let source = FileSource::new_with_query(module.ident().path(), module.ident().query()); let module = asset_context .process( @@ -251,16 +251,18 @@ async fn to_rsc_context( EcmaScriptModulesReferenceSubType::Undefined, )), ) - .module(); + .module() + .to_resolved() + .await?; Ok(module) } /// Our graph traversal visitor, which finds the primary modules directly /// referenced by parent. async fn get_referenced_modules( - (layer, module): (ActionLayer, Vc>), -) -> Result>)> + Send> { - primary_referenced_modules(module) + (layer, module): (ActionLayer, ResolvedVc>), +) -> Result>)> + Send> { + primary_referenced_modules(*module) .await .map(|modules| modules.into_iter().map(move |&m| (layer, m))) } @@ -409,16 +411,16 @@ fn all_export_names(program: &Program) -> Vec { /// Converts our cached [parse_actions] call into a data type suitable for /// collecting into a flat-mapped [FxIndexMap]. async fn parse_actions_filter_map( - (layer, module): (ActionLayer, Vc>), -) -> Result>), Vc)>> { - parse_actions(module).await.map(|option_action_map| { + (layer, module): (ActionLayer, ResolvedVc>), +) -> Result>), Vc)>> { + parse_actions(*module).await.map(|option_action_map| { option_action_map .clone_value() .map(|action_map| ((layer, module), action_map)) }) } -type HashToLayerNameModule = FxIndexMap>)>; +type HashToLayerNameModule = FxIndexMap>)>; /// A mapping of every module which exports a Server Action, with the hashed id /// and exported name of each found action. diff --git a/crates/next-core/src/app_page_loader_tree.rs b/crates/next-core/src/app_page_loader_tree.rs index f043b4f3e6669..f639414f7e57f 100644 --- a/crates/next-core/src/app_page_loader_tree.rs +++ b/crates/next-core/src/app_page_loader_tree.rs @@ -4,7 +4,7 @@ use std::{ }; use anyhow::Result; -use turbo_tasks::{FxIndexMap, RcStr, Vc}; +use turbo_tasks::{FxIndexMap, RcStr, ResolvedVc, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack::{transition::Transition, ModuleAssetContext}; use turbopack_core::{file_source::FileSource, module::Module}; @@ -187,7 +187,7 @@ impl AppPageLoaderTreeBuilder { app_page.clone(), ); - let module = self.base.process_source(source); + let module = self.base.process_source(source).to_resolved().await?; self.base .inner_assets .insert(inner_module_id.into(), module); @@ -227,7 +227,7 @@ impl AppPageLoaderTreeBuilder { BlurPlaceholderMode::None, self.base.module_asset_context, )); - let module = self.base.process_module(module); + let module = self.base.process_module(module).to_resolved().await?; self.base .inner_assets .insert(inner_module_id.into(), module); @@ -274,7 +274,9 @@ impl AppPageLoaderTreeBuilder { .base .process_source(Vc::upcast(TextContentFileSource::new(Vc::upcast( FileSource::new(alt_path), - )))); + )))) + .to_resolved() + .await?; self.base .inner_assets @@ -373,7 +375,9 @@ impl AppPageLoaderTreeBuilder { if let Some(global_error) = modules.global_error { let module = self .base - .process_source(Vc::upcast(FileSource::new(*global_error))); + .process_source(Vc::upcast(FileSource::new(*global_error))) + .to_resolved() + .await?; self.base.inner_assets.insert(GLOBAL_ERROR.into(), module); }; @@ -390,7 +394,7 @@ impl AppPageLoaderTreeBuilder { pub struct AppPageLoaderTreeModule { pub imports: Vec, pub loader_tree_code: RcStr, - pub inner_assets: FxIndexMap>>, + pub inner_assets: FxIndexMap>>, pub pages: Vec>, } diff --git a/crates/next-core/src/base_loader_tree.rs b/crates/next-core/src/base_loader_tree.rs index 58d1a715b4c8a..686041654c8a0 100644 --- a/crates/next-core/src/base_loader_tree.rs +++ b/crates/next-core/src/base_loader_tree.rs @@ -1,6 +1,6 @@ use anyhow::Result; use indoc::formatdoc; -use turbo_tasks::{FxIndexMap, RcStr, Value, ValueToString, Vc}; +use turbo_tasks::{FxIndexMap, RcStr, ResolvedVc, Value, ValueToString, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack::{transition::Transition, ModuleAssetContext}; use turbopack_core::{ @@ -12,7 +12,7 @@ use turbopack_core::{ use turbopack_ecmascript::{magic_identifier, utils::StringifyJs}; pub struct BaseLoaderTreeBuilder { - pub inner_assets: FxIndexMap>>, + pub inner_assets: FxIndexMap>>, counter: usize, pub imports: Vec, pub module_asset_context: Vc, @@ -101,7 +101,10 @@ impl BaseLoaderTreeBuilder { .into(), ); - let module = self.process_source(Vc::upcast(FileSource::new(path))); + let module = self + .process_source(Vc::upcast(FileSource::new(path))) + .to_resolved() + .await?; self.inner_assets .insert(format!("MODULE_{i}").into(), module); diff --git a/crates/next-core/src/bootstrap.rs b/crates/next-core/src/bootstrap.rs index 6807b7a2892e2..685d2c1503399 100644 --- a/crates/next-core/src/bootstrap.rs +++ b/crates/next-core/src/bootstrap.rs @@ -1,5 +1,5 @@ use anyhow::{bail, Context, Result}; -use turbo_tasks::{FxIndexMap, Value, ValueToString, Vc}; +use turbo_tasks::{FxIndexMap, ResolvedVc, Value, ValueToString, Vc}; use turbo_tasks_fs::{File, FileSystemPath}; use turbopack_core::{ asset::AssetContent, @@ -43,7 +43,7 @@ impl BootstrapConfig { #[turbo_tasks::function] pub async fn bootstrap( - asset: Vc>, + asset: ResolvedVc>, asset_context: Vc>, base_path: Vc, bootstrap_asset: Vc>, @@ -91,7 +91,9 @@ pub async fn bootstrap( )), Value::new(ReferenceType::Internal(InnerAssets::empty())), ) - .module(); + .module() + .to_resolved() + .await?; let mut inner_assets = inner_assets.await?.clone_value(); inner_assets.insert("ENTRY".into(), asset); @@ -102,13 +104,15 @@ pub async fn bootstrap( bootstrap_asset, Value::new(ReferenceType::Internal(Vc::cell(inner_assets))), ) - .module(); + .module() + .to_resolved() + .await?; - let asset = Vc::try_resolve_sidecast::>(asset) + let asset = ResolvedVc::try_sidecast::>(asset) .await? .context("internal module must be evaluatable")?; - Ok(asset) + Ok(*asset) } /// This normalizes an app page to a pathname. diff --git a/crates/next-core/src/middleware.rs b/crates/next-core/src/middleware.rs index ea10bc4a25d73..57649cefa49fb 100644 --- a/crates/next-core/src/middleware.rs +++ b/crates/next-core/src/middleware.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use turbo_tasks::{fxindexmap, FxIndexMap, RcStr, Value, Vc}; +use turbo_tasks::{fxindexmap, FxIndexMap, RcStr, ResolvedVc, Value, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{context::AssetContext, module::Module, reference_type::ReferenceType}; @@ -24,7 +24,7 @@ pub async fn middleware_files(page_extensions: Vc>) -> Result>, project_root: Vc, - userland_module: Vc>, + userland_module: ResolvedVc>, ) -> Result>> { const INNER: &str = "INNER_MIDDLEWARE_MODULE"; diff --git a/crates/next-core/src/next_app/app_client_references_chunks.rs b/crates/next-core/src/next_app/app_client_references_chunks.rs index 780ab2904cf5c..0ea549a80e820 100644 --- a/crates/next-core/src/next_app/app_client_references_chunks.rs +++ b/crates/next-core/src/next_app/app_client_references_chunks.rs @@ -1,7 +1,7 @@ use anyhow::Result; use tracing::Instrument; use turbo_tasks::{ - FxIndexMap, RcStr, TryFlatJoinIterExt, TryJoinIterExt, Value, ValueToString, Vc, + FxIndexMap, RcStr, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Value, ValueToString, Vc, }; use turbopack_core::{ chunk::{availability_info::AvailabilityInfo, ChunkingContext, ChunkingContextExt}, @@ -69,7 +69,7 @@ pub async fn get_app_client_references_chunks( ecmascript_client_reference.await?; let client_chunk_group = client_chunking_context - .root_chunk_group(Vc::upcast( + .root_chunk_group(*ResolvedVc::upcast( ecmascript_client_reference_ref.client_module, )) .await?; @@ -81,7 +81,7 @@ pub async fn get_app_client_references_chunks( ), if let Some(ssr_chunking_context) = ssr_chunking_context { let ssr_chunk_group = ssr_chunking_context - .root_chunk_group(Vc::upcast( + .root_chunk_group(*ResolvedVc::upcast( ecmascript_client_reference_ref.ssr_module, )) .await?; @@ -183,7 +183,9 @@ pub async fn get_app_client_references_chunks( let ecmascript_client_reference_ref = ecmascript_client_reference.await?; - Some(Vc::upcast(ecmascript_client_reference_ref.ssr_module)) + Some(*ResolvedVc::upcast( + ecmascript_client_reference_ref.ssr_module, + )) } _ => None, }) @@ -223,7 +225,7 @@ pub async fn get_app_client_references_chunks( } => { let ecmascript_client_reference_ref = ecmascript_client_reference.await?; - Vc::upcast(ecmascript_client_reference_ref.client_module) + *ResolvedVc::upcast(ecmascript_client_reference_ref.client_module) } ClientReferenceType::CssClientReference(css_module) => { Vc::upcast(*css_module) @@ -331,7 +333,12 @@ pub async fn get_app_server_reference_modules( .. } => { let ecmascript_client_reference_ref = ecmascript_client_reference.await?; - Some(Vc::upcast(ecmascript_client_reference_ref.client_module)) + Some(ResolvedVc::upcast( + ecmascript_client_reference_ref + .client_module + .to_resolved() + .await?, + )) } _ => None, }) diff --git a/crates/next-core/src/next_app/app_entry.rs b/crates/next-core/src/next_app/app_entry.rs index d5e26c135965b..5c3cf7b04961f 100644 --- a/crates/next-core/src/next_app/app_entry.rs +++ b/crates/next-core/src/next_app/app_entry.rs @@ -1,4 +1,4 @@ -use turbo_tasks::{RcStr, Vc}; +use turbo_tasks::{RcStr, ResolvedVc, Vc}; use turbopack_core::module::Module; use crate::app_segment_config::NextSegmentConfig; @@ -12,7 +12,7 @@ pub struct AppEntry { /// the pathname to refer to this entry. pub original_name: RcStr, /// The RSC module asset for the route or page. - pub rsc_entry: Vc>, + pub rsc_entry: ResolvedVc>, /// The source code config for this entry. pub config: Vc, } diff --git a/crates/next-core/src/next_app/app_page_entry.rs b/crates/next-core/src/next_app/app_page_entry.rs index 773c73ca4372e..f1b7ebb24ea38 100644 --- a/crates/next-core/src/next_app/app_page_entry.rs +++ b/crates/next-core/src/next_app/app_page_entry.rs @@ -1,7 +1,7 @@ use std::io::Write; use anyhow::Result; -use turbo_tasks::{fxindexmap, RcStr, TryJoinIterExt, Value, ValueToString, Vc}; +use turbo_tasks::{fxindexmap, RcStr, ResolvedVc, TryJoinIterExt, Value, ValueToString, Vc}; use turbo_tasks_fs::{self, rope::RopeBuilder, File, FileSystemPath}; use turbopack::ModuleAssetContext; use turbopack_core::{ @@ -130,7 +130,7 @@ pub async fn get_app_page_entry( Ok(AppEntry { pathname, original_name, - rsc_entry, + rsc_entry: rsc_entry.to_resolved().await?, config, } .cell()) @@ -140,7 +140,7 @@ pub async fn get_app_page_entry( async fn wrap_edge_page( asset_context: Vc>, project_root: Vc, - entry: Vc>, + entry: ResolvedVc>, page: AppPage, next_config: Vc, ) -> Result>> { diff --git a/crates/next-core/src/next_app/app_route_entry.rs b/crates/next-core/src/next_app/app_route_entry.rs index dd320e1dcdcb3..a875592622ad4 100644 --- a/crates/next-core/src/next_app/app_route_entry.rs +++ b/crates/next-core/src/next_app/app_route_entry.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use turbo_tasks::{fxindexmap, RcStr, Value, ValueToString, Vc}; +use turbo_tasks::{fxindexmap, RcStr, ResolvedVc, Value, ValueToString, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack::ModuleAssetContext; use turbopack_core::{ @@ -94,7 +94,9 @@ pub async fn get_app_route_entry( source, Value::new(ReferenceType::Entry(EntryReferenceSubType::AppRoute)), ) - .module(); + .module() + .to_resolved() + .await?; let inner_assets = fxindexmap! { INNER.into() => userland_module @@ -120,7 +122,7 @@ pub async fn get_app_route_entry( Ok(AppEntry { pathname, original_name, - rsc_entry, + rsc_entry: rsc_entry.to_resolved().await?, config, } .cell()) @@ -130,7 +132,7 @@ pub async fn get_app_route_entry( async fn wrap_edge_route( asset_context: Vc>, project_root: Vc, - entry: Vc>, + entry: ResolvedVc>, page: AppPage, next_config: Vc, ) -> Result>> { diff --git a/crates/next-core/src/next_client/runtime_entry.rs b/crates/next-core/src/next_client/runtime_entry.rs index eb8f0353017db..6a5fcb325c44b 100644 --- a/crates/next-core/src/next_client/runtime_entry.rs +++ b/crates/next-core/src/next_client/runtime_entry.rs @@ -46,9 +46,9 @@ impl RuntimeEntry { let mut runtime_entries = Vec::with_capacity(modules.len()); for &module in &modules { if let Some(entry) = - Vc::try_resolve_downcast::>(module).await? + ResolvedVc::try_downcast::>(module).await? { - runtime_entries.push(entry); + runtime_entries.push(*entry); } else { bail!( "runtime reference resolved to an asset ({}) that cannot be evaluated", diff --git a/crates/next-core/src/next_client_reference/ecmascript_client_reference/ecmascript_client_reference_module.rs b/crates/next-core/src/next_client_reference/ecmascript_client_reference/ecmascript_client_reference_module.rs index d7411d106b137..e83bb7662fc5f 100644 --- a/crates/next-core/src/next_client_reference/ecmascript_client_reference/ecmascript_client_reference_module.rs +++ b/crates/next-core/src/next_client_reference/ecmascript_client_reference/ecmascript_client_reference_module.rs @@ -1,6 +1,6 @@ #![allow(rustdoc::private_intra_doc_links)] use anyhow::{bail, Result}; -use turbo_tasks::{RcStr, Vc}; +use turbo_tasks::{RcStr, ResolvedVc, Vc}; use turbopack_core::{ asset::{Asset, AssetContent}, ident::AssetIdent, @@ -14,8 +14,8 @@ use turbopack_ecmascript::chunk::EcmascriptChunkPlaceable; #[turbo_tasks::value] pub struct EcmascriptClientReferenceModule { pub server_ident: Vc, - pub client_module: Vc>, - pub ssr_module: Vc>, + pub client_module: ResolvedVc>, + pub ssr_module: ResolvedVc>, } #[turbo_tasks::value_impl] @@ -31,8 +31,8 @@ impl EcmascriptClientReferenceModule { #[turbo_tasks::function] pub fn new( server_ident: Vc, - client_module: Vc>, - ssr_module: Vc>, + client_module: ResolvedVc>, + ssr_module: ResolvedVc>, ) -> Vc { EcmascriptClientReferenceModule { server_ident, @@ -58,8 +58,8 @@ impl Module for EcmascriptClientReferenceModule { #[turbo_tasks::function] fn additional_layers_modules(&self) -> Vc { - let client_module = Vc::upcast(self.client_module); - let ssr_module = Vc::upcast(self.ssr_module); + let client_module = ResolvedVc::upcast(self.client_module); + let ssr_module = ResolvedVc::upcast(self.ssr_module); Vc::cell(vec![client_module, ssr_module]) } } diff --git a/crates/next-core/src/next_client_reference/visit_client_reference.rs b/crates/next-core/src/next_client_reference/visit_client_reference.rs index 1b67ba5064907..780b8745dc70d 100644 --- a/crates/next-core/src/next_client_reference/visit_client_reference.rs +++ b/crates/next-core/src/next_client_reference/visit_client_reference.rs @@ -186,7 +186,9 @@ pub async fn client_reference_graph( client_references_by_server_component .entry(client_reference.server_component) .or_insert_with(Vec::new) - .push(Vc::upcast::>(entry.await?.ssr_module)); + .push(*ResolvedVc::upcast::>( + entry.await?.ssr_module, + )); } } VisitClientReferenceNodeType::ServerUtilEntry(server_util, _) => { diff --git a/crates/next-core/src/next_edge/entry.rs b/crates/next-core/src/next_edge/entry.rs index 436e9d65cc14d..935bc36e58f78 100644 --- a/crates/next-core/src/next_edge/entry.rs +++ b/crates/next-core/src/next_edge/entry.rs @@ -1,5 +1,5 @@ use indoc::formatdoc; -use turbo_tasks::{fxindexmap, RcStr, Value, Vc}; +use turbo_tasks::{fxindexmap, RcStr, ResolvedVc, Value, Vc}; use turbo_tasks_fs::{File, FileSystemPath}; use turbopack_core::{ asset::AssetContent, context::AssetContext, module::Module, reference_type::ReferenceType, @@ -11,7 +11,7 @@ use turbopack_ecmascript::utils::StringifyJs; pub async fn wrap_edge_entry( asset_context: Vc>, project_root: Vc, - entry: Vc>, + entry: ResolvedVc>, pathname: RcStr, ) -> Vc> { // The wrapped module could be an async module, we handle that with the proxy diff --git a/crates/next-core/src/next_image/module.rs b/crates/next-core/src/next_image/module.rs index 04be97c5d0aaa..fe292b6036010 100644 --- a/crates/next-core/src/next_image/module.rs +++ b/crates/next-core/src/next_image/module.rs @@ -1,4 +1,5 @@ -use turbo_tasks::{fxindexmap, TaskInput, Value, Vc}; +use anyhow::Result; +use turbo_tasks::{fxindexmap, ResolvedVc, TaskInput, Value, Vc}; use turbopack::{module_options::CustomModuleType, ModuleAssetContext}; use turbopack_core::{ context::AssetContext, module::Module, reference_type::ReferenceType, resolve::ModulePart, @@ -38,9 +39,11 @@ impl StructuredImageModuleType { source: Vc>, blur_placeholder_mode: BlurPlaceholderMode, module_asset_context: Vc, - ) -> Vc> { - let static_asset = StaticModuleAsset::new(source, Vc::upcast(module_asset_context)); - module_asset_context + ) -> Result>> { + let static_asset = StaticModuleAsset::new(source, Vc::upcast(module_asset_context)) + .to_resolved() + .await?; + Ok(module_asset_context .process( Vc::upcast( StructuredImageFileSource { @@ -50,10 +53,10 @@ impl StructuredImageModuleType { .cell(), ), Value::new(ReferenceType::Internal(Vc::cell(fxindexmap!( - "IMAGE".into() => Vc::upcast(static_asset) + "IMAGE".into() => ResolvedVc::upcast(static_asset) )))), ) - .module() + .module()) } #[turbo_tasks::function] diff --git a/crates/next-core/src/next_pages/page_entry.rs b/crates/next-core/src/next_pages/page_entry.rs index c8e88c7fa5036..c37b40fcb1615 100644 --- a/crates/next-core/src/next_pages/page_entry.rs +++ b/crates/next-core/src/next_pages/page_entry.rs @@ -2,7 +2,7 @@ use std::io::Write; use anyhow::{bail, Result}; use serde::Serialize; -use turbo_tasks::{fxindexmap, FxIndexMap, RcStr, Value, Vc}; +use turbo_tasks::{fxindexmap, FxIndexMap, RcStr, ResolvedVc, Value, Vc}; use turbo_tasks_fs::{rope::RopeBuilder, File, FileSystemPath}; use turbopack_core::{ asset::{Asset, AssetContent}, @@ -39,7 +39,9 @@ pub async fn create_page_ssr_entry_module( let ssr_module = ssr_module_context .process(source, reference_type.clone()) - .module(); + .module() + .to_resolved() + .await?; let reference_type = reference_type.into_value(); @@ -120,7 +122,9 @@ pub async fn create_page_ssr_entry_module( pages_structure.document(), Value::new(reference_type.clone()), ssr_module_context, - ), + ) + .to_resolved() + .await?, ); inner_assets.insert( INNER_APP.into(), @@ -128,7 +132,9 @@ pub async fn create_page_ssr_entry_module( pages_structure.app(), Value::new(reference_type.clone()), ssr_module_context, - ), + ) + .to_resolved() + .await?, ); } @@ -178,7 +184,7 @@ fn process_global_item( async fn wrap_edge_page( asset_context: Vc>, project_root: Vc, - entry: Vc>, + entry: ResolvedVc>, page: RcStr, pathname: RcStr, reference_type: Value, @@ -233,9 +239,21 @@ async fn wrap_edge_page( let inner_assets = fxindexmap! { INNER.into() => entry, - INNER_DOCUMENT.into() => process_global_item(pages_structure.document(), reference_type.clone(), asset_context), - INNER_APP.into() => process_global_item(pages_structure.app(), reference_type.clone(), asset_context), - INNER_ERROR.into() => process_global_item(pages_structure.error(), reference_type.clone(), asset_context), + INNER_DOCUMENT.into() => process_global_item( + pages_structure.document(), + reference_type.clone(), + asset_context, + ).to_resolved().await?, + INNER_APP.into() => process_global_item( + pages_structure.app(), + reference_type.clone(), + asset_context, + ).to_resolved().await?, + INNER_ERROR.into() => process_global_item( + pages_structure.error(), + reference_type.clone(), + asset_context, + ).to_resolved().await?, }; let wrapped = asset_context diff --git a/crates/next-core/src/next_server_component/server_component_module.rs b/crates/next-core/src/next_server_component/server_component_module.rs index d69c8dfe36e61..6cecec3776942 100644 --- a/crates/next-core/src/next_server_component/server_component_module.rs +++ b/crates/next-core/src/next_server_component/server_component_module.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use anyhow::{bail, Result}; use indoc::formatdoc; -use turbo_tasks::{RcStr, Vc}; +use turbo_tasks::{RcStr, ResolvedVc, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ asset::{Asset, AssetContent}, @@ -66,15 +66,19 @@ impl Module for NextServerComponentModule { } #[turbo_tasks::function] - fn additional_layers_modules(self: Vc) -> Vc { + async fn additional_layers_modules(self: Vc) -> Result> { let base_ident = self.ident(); - let ssr_entry_module = Vc::upcast(IncludeIdentModule::new( - base_ident.with_modifier(client_modules_ssr_modifier()), - )); - let client_entry_module = Vc::upcast(IncludeIdentModule::new( - base_ident.with_modifier(client_modules_modifier()), - )); - Vc::cell(vec![ssr_entry_module, client_entry_module]) + let ssr_entry_module = ResolvedVc::upcast( + IncludeIdentModule::new(base_ident.with_modifier(client_modules_ssr_modifier())) + .to_resolved() + .await?, + ); + let client_entry_module = ResolvedVc::upcast( + IncludeIdentModule::new(base_ident.with_modifier(client_modules_modifier())) + .to_resolved() + .await?, + ); + Ok(Vc::cell(vec![ssr_entry_module, client_entry_module])) } } diff --git a/crates/next-core/src/page_loader.rs b/crates/next-core/src/page_loader.rs index 88e434df4ff08..9feedc4d106aa 100644 --- a/crates/next-core/src/page_loader.rs +++ b/crates/next-core/src/page_loader.rs @@ -54,7 +54,9 @@ pub async fn create_page_loader_entry_module( entry_asset, Value::new(ReferenceType::Entry(EntryReferenceSubType::Page)), ) - .module(); + .module() + .to_resolved() + .await?; let module = client_context .process( diff --git a/turbopack/crates/node-file-trace/src/lib.rs b/turbopack/crates/node-file-trace/src/lib.rs index 36b746e90e2f9..5f9c7832120ec 100644 --- a/turbopack/crates/node-file-trace/src/lib.rs +++ b/turbopack/crates/node-file-trace/src/lib.rs @@ -200,7 +200,7 @@ async fn create_fs(name: &str, root: &str, watch: bool) -> Result>, result: Vc, - list: &mut Vec>>, + list: &mut Vec>>, ) -> Result<()> { let result = result.await?; for entry in result.results.values() { @@ -211,7 +211,9 @@ async fn add_glob_results( source, Value::new(turbopack_core::reference_type::ReferenceType::Undefined), ) - .module(); + .module() + .to_resolved() + .await?; list.push(module); } } @@ -219,7 +221,7 @@ async fn add_glob_results( fn recurse<'a>( asset_context: Vc>, result: Vc, - list: &'a mut Vec>>, + list: &'a mut Vec>>, ) -> Pin> + Send + 'a>> { Box::pin(add_glob_results(asset_context, result, list)) } @@ -260,7 +262,9 @@ async fn input_to_modules( source, Value::new(turbopack_core::reference_type::ReferenceType::Undefined), ) - .module(); + .module() + .to_resolved() + .await?; list.push(module); } else { let glob = Glob::new(input); @@ -490,7 +494,7 @@ async fn main_operation( ) .await?; for module in modules.iter() { - let set = all_modules_and_affecting_sources(*module) + let set = all_modules_and_affecting_sources(**module) .issue_file_path(module.ident().path(), "gathering list of assets") .await?; for asset in set.await?.iter() { @@ -517,7 +521,7 @@ async fn main_operation( .await? .iter() { - let nft_asset = NftJsonAsset::new(*module); + let nft_asset = NftJsonAsset::new(**module); let path = nft_asset.ident().path().await?.path.clone(); output_nft_assets.push(path); emits.push(emit_asset(Vc::upcast(nft_asset))); @@ -550,7 +554,7 @@ async fn main_operation( .await? .iter() { - let rebased = Vc::upcast(RebasedAsset::new(*module, input_dir, output_dir)); + let rebased = Vc::upcast(RebasedAsset::new(**module, input_dir, output_dir)); emits.push(emit_with_completion(rebased, output_dir)); } // Wait for all files to be emitted diff --git a/turbopack/crates/turbopack-cli-utils/src/runtime_entry.rs b/turbopack/crates/turbopack-cli-utils/src/runtime_entry.rs index 8f38df55b861a..032f15cf95297 100644 --- a/turbopack/crates/turbopack-cli-utils/src/runtime_entry.rs +++ b/turbopack/crates/turbopack-cli-utils/src/runtime_entry.rs @@ -46,9 +46,9 @@ impl RuntimeEntry { let mut runtime_entries = Vec::with_capacity(modules.len()); for &module in &modules { if let Some(entry) = - Vc::try_resolve_sidecast::>(module).await? + ResolvedVc::try_sidecast::>(module).await? { - runtime_entries.push(entry); + runtime_entries.push(*entry); } else { bail!( "runtime reference resolved to an asset ({}) that cannot be evaluated", diff --git a/turbopack/crates/turbopack-cli/src/build/mod.rs b/turbopack/crates/turbopack-cli/src/build/mod.rs index bc794d3f1bdd6..e59361ea170e5 100644 --- a/turbopack/crates/turbopack-cli/src/build/mod.rs +++ b/turbopack/crates/turbopack-cli/src/build/mod.rs @@ -7,7 +7,7 @@ use std::{ use anyhow::{bail, Context, Result}; use turbo_tasks::{ - RcStr, ReadConsistency, TransientInstance, TryJoinIterExt, TurboTasks, Value, Vc, + RcStr, ReadConsistency, ResolvedVc, TransientInstance, TryJoinIterExt, TurboTasks, Value, Vc, }; use turbo_tasks_fs::FileSystem; use turbo_tasks_memory::MemoryBackend; @@ -262,7 +262,7 @@ async fn build_internal( .map(|entry_module| async move { Ok( if let Some(ecmascript) = - Vc::try_resolve_sidecast::>(entry_module).await? + ResolvedVc::try_sidecast::>(entry_module).await? { Vc::cell(vec![ Vc::try_resolve_downcast_type::(chunking_context) @@ -281,8 +281,8 @@ async fn build_internal( .into(), ) .with_extension("entry.js".into()), - Vc::upcast(ecmascript), - EvaluatableAssets::one(Vc::upcast(ecmascript)), + *ResolvedVc::upcast(ecmascript), + EvaluatableAssets::one(*ResolvedVc::upcast(ecmascript)), OutputAssets::empty(), Value::new(AvailabilityInfo::Root), ) @@ -290,9 +290,9 @@ async fn build_internal( .asset, ]) } else if let Some(chunkable) = - Vc::try_resolve_sidecast::>(entry_module).await? + ResolvedVc::try_sidecast::>(entry_module).await? { - chunking_context.root_chunk_group_assets(chunkable) + chunking_context.root_chunk_group_assets(*chunkable) } else { // TODO convert into a serve-able asset bail!( diff --git a/turbopack/crates/turbopack-cli/src/dev/web_entry_source.rs b/turbopack/crates/turbopack-cli/src/dev/web_entry_source.rs index e336c8abe54d4..ddb1a64acf2f7 100644 --- a/turbopack/crates/turbopack-cli/src/dev/web_entry_source.rs +++ b/turbopack/crates/turbopack-cli/src/dev/web_entry_source.rs @@ -130,16 +130,16 @@ pub async fn create_web_entry_source( .flatten() .map(|module| async move { if let (Some(chnkable), Some(entry)) = ( - Vc::try_resolve_sidecast::>(module).await?, - Vc::try_resolve_sidecast::>(module).await?, + ResolvedVc::try_sidecast::>(module).await?, + ResolvedVc::try_sidecast::>(module).await?, ) { Ok(( chnkable, chunking_context, - Some(runtime_entries.with_entry(entry)), + Some(runtime_entries.with_entry(*entry)), )) } else if let Some(chunkable) = - Vc::try_resolve_sidecast::>(module).await? + ResolvedVc::try_sidecast::>(module).await? { // TODO this is missing runtime code, so it's probably broken and we should also // add an ecmascript chunk with the runtime code diff --git a/turbopack/crates/turbopack-core/src/changed.rs b/turbopack/crates/turbopack-core/src/changed.rs index 7a03c9dce12d9..21187ed0e3e47 100644 --- a/turbopack/crates/turbopack-core/src/changed.rs +++ b/turbopack/crates/turbopack-core/src/changed.rs @@ -1,7 +1,7 @@ use anyhow::Result; use turbo_tasks::{ graph::{GraphTraversal, NonDeterministic}, - Completion, Completions, Vc, + Completion, Completions, ResolvedVc, Vc, }; use crate::{ @@ -18,9 +18,9 @@ async fn get_referenced_output_assets( } pub async fn get_referenced_modules( - parent: Vc>, -) -> Result>> + Send> { - Ok(primary_referenced_modules(parent) + parent: ResolvedVc>, +) -> Result>> + Send> { + Ok(primary_referenced_modules(*parent) .await? .clone_value() .into_iter()) @@ -29,7 +29,9 @@ pub async fn get_referenced_modules( /// Returns a completion that changes when any content of any asset in the whole /// asset graph changes. #[turbo_tasks::function] -pub async fn any_content_changed_of_module(root: Vc>) -> Result> { +pub async fn any_content_changed_of_module( + root: ResolvedVc>, +) -> Result> { let completions = NonDeterministic::new() .skip_duplicates() .visit([root], get_referenced_modules) @@ -37,7 +39,7 @@ pub async fn any_content_changed_of_module(root: Vc>) -> Result< .completed()? .into_inner() .into_iter() - .map(|m| content_changed(Vc::upcast(m))) + .map(|m| content_changed(*ResolvedVc::upcast(m))) .collect(); Ok(Vc::::cell(completions).completed()) diff --git a/turbopack/crates/turbopack-core/src/chunk/mod.rs b/turbopack/crates/turbopack-core/src/chunk/mod.rs index 9971d7ce1af1e..7d85afd17af72 100644 --- a/turbopack/crates/turbopack-core/src/chunk/mod.rs +++ b/turbopack/crates/turbopack-core/src/chunk/mod.rs @@ -370,7 +370,7 @@ async fn graph_node_to_referenced_nodes( .into_iter() .map(|&module| async move { let Some(chunkable_module) = - Vc::try_resolve_sidecast::>(module).await? + ResolvedVc::try_sidecast::>(module).await? else { return Ok(( Some(ChunkGraphEdge { @@ -458,7 +458,7 @@ async fn graph_node_to_referenced_nodes( Some(ChunkGraphEdge { key: None, node: ChunkContentGraphNode::AsyncModule { - module: chunkable_module, + module: *chunkable_module, }, }), None, diff --git a/turbopack/crates/turbopack-core/src/introspect/utils.rs b/turbopack/crates/turbopack-core/src/introspect/utils.rs index dba8f83b335a3..316c5d9e0d81c 100644 --- a/turbopack/crates/turbopack-core/src/introspect/utils.rs +++ b/turbopack/crates/turbopack-core/src/introspect/utils.rs @@ -87,7 +87,7 @@ pub async fn children_from_module_references( .await? .iter() { - children.insert((key, IntrospectableModule::new(module))); + children.insert((key, IntrospectableModule::new(*module))); } for &output_asset in reference .resolve_reference() diff --git a/turbopack/crates/turbopack-core/src/module.rs b/turbopack/crates/turbopack-core/src/module.rs index 994e43e14496a..753b74abf4755 100644 --- a/turbopack/crates/turbopack-core/src/module.rs +++ b/turbopack/crates/turbopack-core/src/module.rs @@ -1,4 +1,4 @@ -use turbo_tasks::Vc; +use turbo_tasks::{ResolvedVc, Vc}; use crate::{asset::Asset, ident::AssetIdent, reference::ModuleReferences}; @@ -22,10 +22,10 @@ pub trait Module: Asset { } #[turbo_tasks::value(transparent)] -pub struct OptionModule(Option>>); +pub struct OptionModule(Option>>); #[turbo_tasks::value(transparent)] -pub struct Modules(Vec>>); +pub struct Modules(Vec>>); #[turbo_tasks::value_impl] impl Modules { diff --git a/turbopack/crates/turbopack-core/src/reference/mod.rs b/turbopack/crates/turbopack-core/src/reference/mod.rs index 24612664f638b..79120c69349ed 100644 --- a/turbopack/crates/turbopack-core/src/reference/mod.rs +++ b/turbopack/crates/turbopack-core/src/reference/mod.rs @@ -3,7 +3,7 @@ use std::collections::{HashSet, VecDeque}; use anyhow::Result; use turbo_tasks::{ graph::{AdjacencyMap, GraphTraversal}, - FxIndexSet, RcStr, TryJoinIterExt, ValueToString, Vc, + FxIndexSet, RcStr, ResolvedVc, TryJoinIterExt, ValueToString, Vc, }; use crate::{ @@ -162,7 +162,7 @@ pub async fn referenced_modules_and_affecting_sources( } let mut resolved_modules = FxIndexSet::default(); for module in modules { - resolved_modules.insert(module.resolve().await?); + resolved_modules.insert(module.to_resolved().await?); } Ok(Vc::cell(resolved_modules.into_iter().collect())) } @@ -201,10 +201,12 @@ pub async fn primary_referenced_modules(module: Vc>) -> Result>) -> Result> { +pub async fn all_modules_and_affecting_sources( + asset: ResolvedVc>, +) -> Result> { // TODO need to track import path here let mut queue = VecDeque::with_capacity(32); - queue.push_back((asset, referenced_modules_and_affecting_sources(asset))); + queue.push_back((asset, referenced_modules_and_affecting_sources(*asset))); let mut assets = HashSet::new(); assets.insert(asset); while let Some((parent, references)) = queue.pop_front() { @@ -213,7 +215,7 @@ pub async fn all_modules_and_affecting_sources(asset: Vc>) -> Re .await?; for asset in references.await?.iter() { if assets.insert(*asset) { - queue.push_back((*asset, referenced_modules_and_affecting_sources(*asset))); + queue.push_back((*asset, referenced_modules_and_affecting_sources(**asset))); } } } diff --git a/turbopack/crates/turbopack-core/src/reference_type.rs b/turbopack/crates/turbopack-core/src/reference_type.rs index 76fd2c332a354..4f777d99caee0 100644 --- a/turbopack/crates/turbopack-core/src/reference_type.rs +++ b/turbopack/crates/turbopack-core/src/reference_type.rs @@ -10,7 +10,7 @@ use crate::{module::Module, resolve::ModulePart}; /// /// Name is usually in UPPER_CASE to make it clear that this is an inner asset. #[turbo_tasks::value(transparent)] -pub struct InnerAssets(FxIndexMap>>); +pub struct InnerAssets(FxIndexMap>>); #[turbo_tasks::value_impl] impl InnerAssets { diff --git a/turbopack/crates/turbopack-core/src/resolve/mod.rs b/turbopack/crates/turbopack-core/src/resolve/mod.rs index 2b8b044001569..26ef4f9a47882 100644 --- a/turbopack/crates/turbopack-core/src/resolve/mod.rs +++ b/turbopack/crates/turbopack-core/src/resolve/mod.rs @@ -325,11 +325,17 @@ impl ModuleResolveResult { } #[turbo_tasks::function] - pub fn first_module(&self) -> Vc { - Vc::cell(self.primary.iter().find_map(|(_, item)| match item { + pub async fn first_module(&self) -> Result> { + let first = self.primary.iter().find_map(|(_, item)| match item { &ModuleResolveResultItem::Module(a) => Some(a), _ => None, - })) + }); + let first_resolved = if let Some(first) = first { + Some(first.to_resolved().await?) + } else { + None + }; + Ok(Vc::cell(first_resolved)) } /// Returns a set (no duplicates) of primary modules in the result. All @@ -340,17 +346,17 @@ impl ModuleResolveResult { let Some(first) = iter.next() else { return Ok(Vc::cell(vec![])); }; - let first = first.resolve().await?; + let first = first.to_resolved().await?; let Some(second) = iter.next() else { return Ok(Vc::cell(vec![first])); }; - let second = second.resolve().await?; + let second = second.to_resolved().await?; // We have at least two items, so we need to deduplicate them let mut set = fxindexset![first, second]; for module in self.primary_modules_iter() { - set.insert(module.resolve().await?); + set.insert(module.to_resolved().await?); } Ok(Vc::cell(set.into_iter().collect())) } diff --git a/turbopack/crates/turbopack-core/src/resolve/origin.rs b/turbopack/crates/turbopack-core/src/resolve/origin.rs index ca292c03e7681..79867df8f67ff 100644 --- a/turbopack/crates/turbopack-core/src/resolve/origin.rs +++ b/turbopack/crates/turbopack-core/src/resolve/origin.rs @@ -84,7 +84,7 @@ async fn resolve_asset( reference_type: Value, ) -> Result> { if let Some(asset) = *resolve_origin.get_inner_asset(request).await? { - return Ok(ModuleResolveResult::module(asset).cell()); + return Ok(ModuleResolveResult::module(*asset).cell()); } Ok(resolve_origin .asset_context() diff --git a/turbopack/crates/turbopack-css/src/asset.rs b/turbopack/crates/turbopack-css/src/asset.rs index 93b3b005eecaf..cf25b1cf194c3 100644 --- a/turbopack/crates/turbopack-css/src/asset.rs +++ b/turbopack/crates/turbopack-css/src/asset.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use turbo_tasks::{RcStr, TryJoinIterExt, ValueToString, Vc}; +use turbo_tasks::{RcStr, ResolvedVc, TryJoinIterExt, ValueToString, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ asset::{Asset, AssetContent}, @@ -232,7 +232,7 @@ impl CssChunkItem for CssModuleChunkItem { .iter() { if let Some(placeable) = - Vc::try_resolve_downcast::>(module).await? + ResolvedVc::try_downcast::>(module).await? { let item = placeable.as_chunk_item(chunking_context); if let Some(css_item) = @@ -257,7 +257,7 @@ impl CssChunkItem for CssModuleChunkItem { .iter() { if let Some(placeable) = - Vc::try_resolve_downcast::>(module).await? + ResolvedVc::try_downcast::>(module).await? { let item = placeable.as_chunk_item(chunking_context); if let Some(css_item) = diff --git a/turbopack/crates/turbopack-css/src/module_asset.rs b/turbopack/crates/turbopack-css/src/module_asset.rs index ceac2b06d1332..108172c0361e2 100644 --- a/turbopack/crates/turbopack-css/src/module_asset.rs +++ b/turbopack/crates/turbopack-css/src/module_asset.rs @@ -4,7 +4,7 @@ use anyhow::{bail, Context, Result}; use indoc::formatdoc; use lightningcss::css_modules::CssModuleReference; use swc_core::common::{BytePos, FileName, LineCol, SourceMap}; -use turbo_tasks::{FxIndexMap, RcStr, Value, ValueToString, Vc}; +use turbo_tasks::{FxIndexMap, RcStr, ResolvedVc, Value, ValueToString, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ asset::{Asset, AssetContent}, @@ -339,7 +339,7 @@ impl EcmascriptChunkItem for ModuleChunkItem { }; let Some(css_module) = - Vc::try_resolve_downcast_type::(*resolved_module) + ResolvedVc::try_downcast_type::(*resolved_module) .await? else { CssModuleComposesIssue { @@ -358,8 +358,8 @@ impl EcmascriptChunkItem for ModuleChunkItem { // TODO(alexkirsz) We should also warn if `original_name` can't be found in // the target module. - let placeable: Vc> = - Vc::upcast(css_module); + let placeable: ResolvedVc> = + ResolvedVc::upcast(css_module); let module_id = placeable .as_chunk_item(Vc::upcast(self.chunking_context)) diff --git a/turbopack/crates/turbopack-css/src/references/url.rs b/turbopack/crates/turbopack-css/src/references/url.rs index 94591797322be..207a87a5f8d7a 100644 --- a/turbopack/crates/turbopack-css/src/references/url.rs +++ b/turbopack/crates/turbopack-css/src/references/url.rs @@ -62,7 +62,7 @@ impl UrlAssetReference { ) -> Result> { if let Some(module) = *self.resolve_reference().first_module().await? { if let Some(chunkable) = - Vc::try_resolve_downcast::>(module).await? + ResolvedVc::try_downcast::>(module).await? { let chunk_item = chunkable.as_chunk_item(chunking_context); if let Some(embeddable) = diff --git a/turbopack/crates/turbopack-dev-server/src/html.rs b/turbopack/crates/turbopack-dev-server/src/html.rs index a628d268ecb61..6903a8d798a28 100644 --- a/turbopack/crates/turbopack-dev-server/src/html.rs +++ b/turbopack/crates/turbopack-dev-server/src/html.rs @@ -1,6 +1,6 @@ use anyhow::{anyhow, Result}; use mime_guess::mime::TEXT_HTML_UTF_8; -use turbo_tasks::{RcStr, ReadRef, TryJoinIterExt, Value, Vc}; +use turbo_tasks::{RcStr, ReadRef, ResolvedVc, TryJoinIterExt, Value, Vc}; use turbo_tasks_fs::{File, FileSystemPath}; use turbo_tasks_hash::{encode_hex, Xxh3Hash64Hasher}; use turbopack_core::{ @@ -18,7 +18,7 @@ use turbopack_core::{ // TODO(WEB-945) This should become a struct once we have a // `turbo_tasks::input` attribute macro/`Input` derive macro. type DevHtmlEntry = ( - Vc>, + ResolvedVc>, Vc>, Option>, ); @@ -135,9 +135,9 @@ impl DevHtmlAsset { let assets = if let Some(runtime_entries) = runtime_entries { let runtime_entries = if let Some(evaluatable) = - Vc::try_resolve_downcast(chunkable_module).await? + ResolvedVc::try_downcast(chunkable_module).await? { - runtime_entries.with_entry(evaluatable) + runtime_entries.with_entry(*evaluatable) } else { runtime_entries }; @@ -147,7 +147,7 @@ impl DevHtmlAsset { Value::new(AvailabilityInfo::Root), ) } else { - chunking_context.root_chunk_group_assets(Vc::upcast(chunkable_module)) + chunking_context.root_chunk_group_assets(*ResolvedVc::upcast(chunkable_module)) }; assets.await diff --git a/turbopack/crates/turbopack-ecmascript/src/global_module_id_strategy.rs b/turbopack/crates/turbopack-ecmascript/src/global_module_id_strategy.rs index a04089fea5a88..bedec6ee755a6 100644 --- a/turbopack/crates/turbopack-ecmascript/src/global_module_id_strategy.rs +++ b/turbopack/crates/turbopack-ecmascript/src/global_module_id_strategy.rs @@ -36,18 +36,19 @@ impl ReferencedModule { } } -// TODO(LichuAcu): Reduce type complexity -#[allow(clippy::type_complexity)] -type ModulesAndAsyncLoaders = Vec<(Vec>>, Option>>)>; - #[turbo_tasks::value(transparent)] -pub struct ReferencedModules(Vec>); +pub struct ReferencedModules(Vec>); #[turbo_tasks::function] async fn referenced_modules(module: Vc>) -> Result> { let references = module.references().await?; - let mut set = FxIndexSet::default(); + // TODO(LichuAcu): Reduce type complexity + #[allow(clippy::type_complexity)] + type ModulesAndAsyncLoaders = Vec<( + Vec>>, + Option>>, + )>; let modules_and_async_loaders: ModulesAndAsyncLoaders = references .iter() .map(|reference| async move { @@ -79,20 +80,18 @@ async fn referenced_modules(module: Vc>) -> Result>) -> Result, -) -> Result> + Send> { + parent: ResolvedVc, +) -> Result> + Send> { let parent_module = parent.await?.module(); let mut modules = referenced_modules(parent_module).await?.clone_value(); for module in parent_module.additional_layers_modules().await? { - modules.push(ReferencedModule::Module(*module).cell()); + modules.push(ReferencedModule::Module(**module).resolved_cell()); } Ok(modules.into_iter()) } @@ -125,7 +124,7 @@ pub async fn children_modules_idents( root_modules .await? .iter() - .map(|module| ReferencedModule::Module(*module).cell()) + .map(|module| ReferencedModule::Module(**module).resolved_cell()) .collect::>(), get_children_modules, ) diff --git a/turbopack/crates/turbopack-ecmascript/src/references/esm/base.rs b/turbopack/crates/turbopack-ecmascript/src/references/esm/base.rs index 190e745d0115f..0e4a1949e8eb9 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/esm/base.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/esm/base.rs @@ -188,12 +188,12 @@ impl ModuleReference for EsmAssetReference { let part = part.await?; if let &ModulePart::Export(export_name) = &*part { for &module in result.primary_modules().await? { - if let Some(module) = Vc::try_resolve_downcast(module).await? { + if let Some(module) = ResolvedVc::try_downcast(module).await? { let export = export_name.await?; - if *is_export_missing(module, export.clone_value()).await? { + if *is_export_missing(*module, export.clone_value()).await? { InvalidExport { export: *export_name, - module, + module: *module, source: self.issue_source, } .cell() diff --git a/turbopack/crates/turbopack-ecmascript/src/references/worker.rs b/turbopack/crates/turbopack-ecmascript/src/references/worker.rs index 2729772f4738f..c1b8462d19088 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/worker.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/worker.rs @@ -3,7 +3,7 @@ use swc_core::{ ecma::ast::{Expr, ExprOrSpread, Lit, NewExpr}, quote_expr, }; -use turbo_tasks::{RcStr, Value, ValueToString, Vc}; +use turbo_tasks::{RcStr, ResolvedVc, Value, ValueToString, Vc}; use turbopack_core::{ chunk::{ChunkableModule, ChunkableModuleReference, ChunkingContext}, issue::{code_gen::CodeGenerationIssue, IssueExt, IssueSeverity, IssueSource, StyledString}, @@ -66,7 +66,7 @@ impl WorkerAssetReference { let Some(module) = *module.first_module().await? else { bail!("Expected worker to resolve to a module"); }; - let Some(chunkable) = Vc::try_resolve_downcast::>(module).await? + let Some(chunkable) = ResolvedVc::try_downcast::>(module).await? else { CodeGenerationIssue { severity: IssueSeverity::Bug.into(), @@ -79,7 +79,7 @@ impl WorkerAssetReference { return Ok(None); }; - Ok(Some(WorkerLoaderModule::new(chunkable))) + Ok(Some(WorkerLoaderModule::new(*chunkable))) } } diff --git a/turbopack/crates/turbopack-node/src/evaluate.rs b/turbopack/crates/turbopack-node/src/evaluate.rs index b4bdbb58fe04e..86fdce54016ed 100644 --- a/turbopack/crates/turbopack-node/src/evaluate.rs +++ b/turbopack/crates/turbopack-node/src/evaluate.rs @@ -13,7 +13,7 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde_json::Value as JsonValue; use turbo_tasks::{ duration_span, fxindexmap, mark_finished, prevent_gc, util::SharedError, Completion, RawVc, - TaskInput, TryJoinIterExt, Value, Vc, + ResolvedVc, TaskInput, TryJoinIterExt, Value, Vc, }; use turbo_tasks_bytes::{Bytes, Stream}; use turbo_tasks_env::ProcessEnv; @@ -81,7 +81,7 @@ pub struct JavaScriptEvaluation(#[turbo_tasks(trace_ignore)] JavaScriptStream); /// Pass the file you cared as `runtime_entries` to invalidate and reload the /// evaluated result automatically. pub async fn get_evaluate_pool( - module_asset: Vc>, + module_asset: ResolvedVc>, cwd: Vc, env: Vc>, asset_context: Vc>, @@ -95,7 +95,9 @@ pub async fn get_evaluate_pool( Vc::upcast(FileSource::new(embed_file_path("ipc/evaluate.ts".into()))), Value::new(ReferenceType::Internal(InnerAssets::empty())), ) - .module(); + .module() + .to_resolved() + .await?; let module_path = module_asset.ident().path().await?; let file_name = module_path.file_name(); diff --git a/turbopack/crates/turbopack-node/src/transforms/postcss.rs b/turbopack/crates/turbopack-node/src/transforms/postcss.rs index 369cca8e678be..86a795d15ab17 100644 --- a/turbopack/crates/turbopack-node/src/transforms/postcss.rs +++ b/turbopack/crates/turbopack-node/src/transforms/postcss.rs @@ -366,7 +366,9 @@ async fn postcss_executor( config_loader_source(project_path, postcss_config_path), Value::new(ReferenceType::Entry(EntryReferenceSubType::Undefined)), ) - .module(); + .module() + .to_resolved() + .await?; Ok(asset_context.process( Vc::upcast(VirtualSource::new( diff --git a/turbopack/crates/turbopack-tests/tests/execution.rs b/turbopack/crates/turbopack-tests/tests/execution.rs index d31ed600227bc..c07130b033f36 100644 --- a/turbopack/crates/turbopack-tests/tests/execution.rs +++ b/turbopack/crates/turbopack-tests/tests/execution.rs @@ -341,7 +341,9 @@ async fn run_test(prepared_test: Vc) -> Result> Vc::upcast(test_source), Value::new(ReferenceType::Internal(InnerAssets::empty())), ) - .module(); + .module() + .to_resolved() + .await?; let jest_entry_asset = asset_context .process( diff --git a/turbopack/crates/turbopack-wasm/src/module_asset.rs b/turbopack/crates/turbopack-wasm/src/module_asset.rs index 521d5e9526ef2..3c85cd8b71706 100644 --- a/turbopack/crates/turbopack-wasm/src/module_asset.rs +++ b/turbopack/crates/turbopack-wasm/src/module_asset.rs @@ -1,5 +1,5 @@ use anyhow::{bail, Context, Result}; -use turbo_tasks::{fxindexmap, RcStr, Value, Vc}; +use turbo_tasks::{fxindexmap, RcStr, ResolvedVc, Value, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ asset::{Asset, AssetContent}, @@ -73,7 +73,7 @@ impl WebAssemblyModuleAsset { let module = this.asset_context.process( loader_source, Value::new(ReferenceType::Internal(Vc::cell(fxindexmap! { - "WASM_PATH".into() => Vc::upcast(RawWebAssemblyModuleAsset::new(this.source, this.asset_context)), + "WASM_PATH".into() => ResolvedVc::upcast(RawWebAssemblyModuleAsset::new(this.source, this.asset_context).to_resolved().await?), }))), ).module(); diff --git a/turbopack/crates/turbopack/src/rebase/mod.rs b/turbopack/crates/turbopack/src/rebase/mod.rs index e33ff3e0d184e..81b9a9008d375 100644 --- a/turbopack/crates/turbopack/src/rebase/mod.rs +++ b/turbopack/crates/turbopack/src/rebase/mod.rs @@ -56,7 +56,7 @@ impl OutputAsset for RebasedAsset { .iter() { references.push(Vc::upcast(RebasedAsset::new( - module, + *module, self.input_dir, self.output_dir, )));