From 7db7c5ce27f02ae059c47fbf6ca20103382a395a Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Fri, 15 Nov 2024 17:58:27 -0800 Subject: [PATCH] draft(turbo-tasks): Make State require OperationValue --- crates/next-api/src/app.rs | 19 +- crates/next-api/src/instrumentation.rs | 12 +- crates/next-api/src/middleware.rs | 12 +- crates/next-api/src/pages.rs | 19 +- crates/next-api/src/project.rs | 64 +++-- crates/next-api/src/versioned_content_map.rs | 134 ++++++---- crates/next-core/src/next_config.rs | 247 ++++++++++++++---- .../transforms/modularize_imports.rs | 24 +- turbopack/crates/turbo-tasks-fs/src/rope.rs | 2 +- .../crates/turbo-tasks/src/marker_trait.rs | 4 + turbopack/crates/turbo-tasks/src/state.rs | 9 +- .../crates/turbopack-cli/src/build/mod.rs | 14 +- turbopack/crates/turbopack-cli/src/dev/mod.rs | 2 +- .../crates/turbopack-core/src/chunk/mod.rs | 2 +- .../crates/turbopack-core/src/code_builder.rs | 16 +- .../crates/turbopack-core/src/issue/mod.rs | 13 +- .../crates/turbopack-core/src/version.rs | 33 ++- .../crates/turbopack-css/src/chunk/mod.rs | 2 +- .../src/chunk/single_item_chunk/chunk.rs | 2 +- .../crates/turbopack-dev-server/src/html.rs | 4 +- .../crates/turbopack-dev-server/src/http.rs | 56 ++-- .../crates/turbopack-dev-server/src/lib.rs | 20 +- .../turbopack-dev-server/src/source/mod.rs | 3 +- .../src/source/request.rs | 5 +- .../src/source/resolve.rs | 12 +- .../turbopack-dev-server/src/update/stream.rs | 14 +- .../src/transform/emotion.rs | 8 +- .../src/transform/relay.rs | 10 +- .../src/transform/styled_components.rs | 2 +- .../turbopack-ecmascript/src/chunk/item.rs | 5 +- .../crates/turbopack-ecmascript/src/minify.rs | 6 +- .../turbopack-ecmascript/src/static_code.rs | 2 +- turbopack/crates/turbopack-mdx/src/lib.rs | 4 +- .../turbopack-node/src/transforms/webpack.rs | 8 +- .../src/ecmascript/node/version.rs | 2 +- 35 files changed, 542 insertions(+), 249 deletions(-) diff --git a/crates/next-api/src/app.rs b/crates/next-api/src/app.rs index fc97c77c4e8dc..35ebeb0dda0de 100644 --- a/crates/next-api/src/app.rs +++ b/crates/next-api/src/app.rs @@ -870,11 +870,6 @@ impl AppEndpoint { Ok(app_entry) } - #[turbo_tasks::function] - fn output_assets(self: Vc) -> Vc { - self.output().output_assets() - } - #[turbo_tasks::function] async fn output(self: Vc) -> Result> { let this = self.await?; @@ -1577,7 +1572,7 @@ async fn create_app_paths_manifest( #[turbo_tasks::value_impl] impl Endpoint for AppEndpoint { #[turbo_tasks::function] - async fn write_to_disk(self: Vc) -> Result> { + async fn write_to_disk(self: ResolvedVc) -> Result> { let this = self.await?; let page_name = this.page.to_string(); let span = match this.ty { @@ -1602,9 +1597,8 @@ impl Endpoint for AppEndpoint { }; async move { let output = self.output().await?; - // Must use self.output_assets() instead of output.output_assets() to make it a - // single operation - let output_assets = self.output_assets(); + let output_assets_op = output_assets_operation(self); + let output_assets = output_assets_op.connect(); let node_root = this.app_project.project().node_root(); @@ -1613,7 +1607,7 @@ impl Endpoint for AppEndpoint { let _ = this .app_project .project() - .emit_all_output_assets(Vc::cell(output_assets)); + .emit_all_output_assets(output_assets_op); let (server_paths, client_paths) = if this .app_project @@ -1684,6 +1678,11 @@ impl Endpoint for AppEndpoint { } } +#[turbo_tasks::function(operation)] +fn output_assets_operation(endpoint: ResolvedVc) -> Vc { + endpoint.output().output_assets() +} + #[turbo_tasks::value] enum AppEndpointOutput { NodeJs { diff --git a/crates/next-api/src/instrumentation.rs b/crates/next-api/src/instrumentation.rs index 666f19e487ce2..fa075a0bfbdc0 100644 --- a/crates/next-api/src/instrumentation.rs +++ b/crates/next-api/src/instrumentation.rs @@ -244,15 +244,16 @@ struct InstrumentationCoreModules { #[turbo_tasks::value_impl] impl Endpoint for InstrumentationEndpoint { #[turbo_tasks::function] - async fn write_to_disk(self: Vc) -> Result> { + async fn write_to_disk(self: ResolvedVc) -> Result> { let span = tracing::info_span!("instrumentation endpoint"); async move { let this = self.await?; - let output_assets = self.output_assets(); + let output_assets_op = output_assets_operation(self); + let output_assets = output_assets_op.connect(); let _ = output_assets.resolve().await?; let _ = this .project - .emit_all_output_assets(Vc::cell(output_assets)) + .emit_all_output_assets(output_assets_op) .resolve() .await?; @@ -294,3 +295,8 @@ impl Endpoint for InstrumentationEndpoint { ])) } } + +#[turbo_tasks::function(operation)] +fn output_assets_operation(endpoint: ResolvedVc) -> Vc { + endpoint.output_assets() +} diff --git a/crates/next-api/src/middleware.rs b/crates/next-api/src/middleware.rs index dbde23d3c9a84..f25b6070437ae 100644 --- a/crates/next-api/src/middleware.rs +++ b/crates/next-api/src/middleware.rs @@ -269,15 +269,16 @@ impl MiddlewareEndpoint { #[turbo_tasks::value_impl] impl Endpoint for MiddlewareEndpoint { #[turbo_tasks::function] - async fn write_to_disk(self: Vc) -> Result> { + async fn write_to_disk(self: ResolvedVc) -> Result> { let span = tracing::info_span!("middleware endpoint"); async move { let this = self.await?; - let output_assets = self.output_assets(); + let output_assets_op = output_assets_operation(self); + let output_assets = output_assets_op.connect(); let _ = output_assets.resolve().await?; let _ = this .project - .emit_all_output_assets(Vc::cell(output_assets)) + .emit_all_output_assets(output_assets_op) .resolve() .await?; @@ -324,3 +325,8 @@ impl Endpoint for MiddlewareEndpoint { Ok(Vc::cell(vec![self.userland_module().to_resolved().await?])) } } + +#[turbo_tasks::function(operation)] +fn output_assets_operation(endpoint: ResolvedVc) -> Vc { + endpoint.output_assets() +} diff --git a/crates/next-api/src/pages.rs b/crates/next-api/src/pages.rs index 3b03887ee8779..bef02e435a0f1 100644 --- a/crates/next-api/src/pages.rs +++ b/crates/next-api/src/pages.rs @@ -1086,11 +1086,6 @@ impl PageEndpoint { )) } - #[turbo_tasks::function] - fn output_assets(self: Vc) -> Vc { - self.output().output_assets() - } - #[turbo_tasks::function] async fn output(self: Vc) -> Result> { let this = self.await?; @@ -1298,7 +1293,7 @@ pub struct InternalSsrChunkModule { #[turbo_tasks::value_impl] impl Endpoint for PageEndpoint { #[turbo_tasks::function] - async fn write_to_disk(self: Vc) -> Result> { + async fn write_to_disk(self: ResolvedVc) -> Result> { let this = self.await?; let original_name = this.original_name.await?; let span = { @@ -1319,14 +1314,13 @@ impl Endpoint for PageEndpoint { }; async move { let output = self.output().await?; - // Must use self.output_assets() instead of output.output_assets() to make it a - // single operation - let output_assets = self.output_assets(); + let output_assets_op = output_assets_operation(self); + let output_assets = output_assets_op.connect(); let _ = this .pages_project .project() - .emit_all_output_assets(Vc::cell(output_assets)) + .emit_all_output_assets(output_assets_op) .resolve() .await?; @@ -1411,6 +1405,11 @@ impl Endpoint for PageEndpoint { } } +#[turbo_tasks::function(operation)] +fn output_assets_operation(endpoint: ResolvedVc) -> Vc { + endpoint.output().output_assets() +} + #[turbo_tasks::value] enum PageEndpointOutput { NodeJs { diff --git a/crates/next-api/src/project.rs b/crates/next-api/src/project.rs index 1846d6b97e3eb..d4f43e4a1a95f 100644 --- a/crates/next-api/src/project.rs +++ b/crates/next-api/src/project.rs @@ -28,8 +28,8 @@ use turbo_tasks::{ fxindexmap, graph::{AdjacencyMap, GraphTraversal}, trace::TraceRawVcs, - Completion, Completions, FxIndexMap, IntoTraitRef, NonLocalValue, ReadRef, ResolvedVc, State, - TaskInput, TransientInstance, TryFlatJoinIterExt, Value, Vc, + Completion, Completions, FxIndexMap, IntoTraitRef, NonLocalValue, OperationValue, OperationVc, + ReadRef, ResolvedVc, State, TaskInput, TransientInstance, TryFlatJoinIterExt, Value, Vc, }; use turbo_tasks_env::{EnvMap, ProcessEnv}; use turbo_tasks_fs::{DiskFileSystem, FileSystem, FileSystemPath, VirtualFileSystem}; @@ -69,11 +69,21 @@ use crate::{ middleware::MiddlewareEndpoint, pages::PagesProject, route::{AppPageRoute, Endpoint, Route}, - versioned_content_map::{OutputAssetsOperation, VersionedContentMap}, + versioned_content_map::VersionedContentMap, }; #[derive( - Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, Hash, TraceRawVcs, NonLocalValue, + Debug, + Serialize, + Deserialize, + Clone, + TaskInput, + PartialEq, + Eq, + Hash, + TraceRawVcs, + NonLocalValue, + OperationValue, )] #[serde(rename_all = "camelCase")] pub struct DraftModeOptions { @@ -95,6 +105,7 @@ pub struct DraftModeOptions { Hash, TraceRawVcs, NonLocalValue, + OperationValue, )] #[serde(rename_all = "camelCase")] pub struct WatchOptions { @@ -107,7 +118,17 @@ pub struct WatchOptions { } #[derive( - Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, Hash, TraceRawVcs, NonLocalValue, + Debug, + Serialize, + Deserialize, + Clone, + TaskInput, + PartialEq, + Eq, + Hash, + TraceRawVcs, + NonLocalValue, + OperationValue, )] #[serde(rename_all = "camelCase")] pub struct ProjectOptions { @@ -192,7 +213,17 @@ pub struct PartialProjectOptions { } #[derive( - Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, Hash, TraceRawVcs, NonLocalValue, + Debug, + Serialize, + Deserialize, + Clone, + TaskInput, + PartialEq, + Eq, + Hash, + TraceRawVcs, + NonLocalValue, + OperationValue, )] #[serde(rename_all = "camelCase")] pub struct DefineEnv { @@ -228,7 +259,7 @@ impl ProjectContainer { // we only need to enable versioning in dev mode, since build // is assumed to be operating over a static snapshot versioned_content_map: if dev { - Some(VersionedContentMap::new().to_resolved().await?) + Some(VersionedContentMap::new()) } else { None }, @@ -1269,7 +1300,7 @@ impl Project { #[turbo_tasks::function] pub async fn emit_all_output_assets( self: Vc, - output_assets: Vc, + output_assets: OperationVc, ) -> Result<()> { let span = tracing::info_span!("emitting"); async move { @@ -1292,7 +1323,7 @@ impl Project { Ok(()) } else { let _ = emit_assets( - *all_output_assets.await?, + all_output_assets.connect(), node_root, client_relative_path, node_root, @@ -1469,21 +1500,14 @@ async fn get_referenced_output_assets( Ok(parent.references().await?.clone_value().into_iter()) } -#[turbo_tasks::function] -async fn all_assets_from_entries_operation_inner( - operation: Vc, +#[turbo_tasks::function(operation)] +async fn all_assets_from_entries_operation( + operation: OperationVc, ) -> Result> { - let assets = *operation.await?; - Vc::connect(assets); + let assets = operation.connect(); Ok(all_assets_from_entries(assets)) } -fn all_assets_from_entries_operation( - operation: Vc, -) -> Vc { - Vc::cell(all_assets_from_entries_operation_inner(operation)) -} - #[turbo_tasks::function] fn stable_endpoint(endpoint: Vc>) -> Vc> { endpoint diff --git a/crates/next-api/src/versioned_content_map.rs b/crates/next-api/src/versioned_content_map.rs index 8e7124f820d9b..4b8b5ca55b415 100644 --- a/crates/next-api/src/versioned_content_map.rs +++ b/crates/next-api/src/versioned_content_map.rs @@ -5,8 +5,9 @@ use next_core::emit_assets; use serde::{Deserialize, Serialize}; use turbo_rcstr::RcStr; use turbo_tasks::{ - debug::ValueDebugFormat, trace::TraceRawVcs, FxIndexSet, ResolvedVc, State, TryFlatJoinIterExt, - TryJoinIterExt, ValueDefault, ValueToString, Vc, + debug::ValueDebugFormat, trace::TraceRawVcs, FxIndexSet, NonLocalValue, OperationValue, + OperationVc, ResolvedVc, State, TryFlatJoinIterExt, TryJoinIterExt, ValueDefault, + ValueToString, Vc, }; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ @@ -16,28 +17,50 @@ use turbopack_core::{ version::OptionVersionedContent, }; -/// An unresolved output assets operation. We need to pass an operation here as -/// it's stored for later usage and we want to reconnect this operation when -/// it's received from the map again. -#[turbo_tasks::value(transparent, local)] -pub struct OutputAssetsOperation(Vc); - -#[derive(Clone, TraceRawVcs, PartialEq, Eq, ValueDebugFormat, Serialize, Deserialize, Debug)] +#[derive( + Clone, + TraceRawVcs, + PartialEq, + Eq, + ValueDebugFormat, + Serialize, + Deserialize, + Debug, + NonLocalValue, +)] struct MapEntry { // must not be resolved - assets_operation: Vc, + assets_operation: OperationVc, /// Precomputed map for quick access to output asset by filepath - path_to_asset: HashMap, Vc>>, + path_to_asset: HashMap, ResolvedVc>>, } -#[turbo_tasks::value(transparent, local)] +// HACK: This is technically incorrect because `path_to_asset` contains `ResolvedVc`... +unsafe impl OperationValue for MapEntry {} + +#[turbo_tasks::value(transparent, operation)] struct OptionMapEntry(Option); -type PathToOutputOperation = HashMap, FxIndexSet>>; +#[turbo_tasks::value] +#[derive(Debug)] +pub struct PathToOutputOperation( + /// We need to use an operation for outputs as it's stored for later usage and we want to + /// reconnect this operation when it's received from the map again. + /// + /// It may not be 100% correct for the key (`FileSystemPath`) to be in a `ResolvedVc` here, but + /// it's impractical to make it an `OperationVc`/`OperationValue`, and it's unlikely to + /// change/break? + HashMap, FxIndexSet>>, +); + +// HACK: This is technically incorrect because the map's key is a `ResolvedVc`... +unsafe impl OperationValue for PathToOutputOperation {} + // A precomputed map for quick access to output asset by filepath -type OutputOperationToComputeEntry = HashMap, Vc>; +type OutputOperationToComputeEntry = + HashMap, OperationVc>; -#[turbo_tasks::value(local)] +#[turbo_tasks::value] pub struct VersionedContentMap { // TODO: turn into a bi-directional multimap, OutputAssets -> FxIndexSet map_path_to_op: State, @@ -46,19 +69,19 @@ pub struct VersionedContentMap { impl ValueDefault for VersionedContentMap { fn value_default() -> Vc { - VersionedContentMap { - map_path_to_op: State::new(HashMap::new()), - map_op_to_compute_entry: State::new(HashMap::new()), - } - .cell() + *VersionedContentMap::new() } } impl VersionedContentMap { // NOTE(alexkirsz) This must not be a `#[turbo_tasks::function]` because it // should be a singleton for each project. - pub fn new() -> Vc { - Self::value_default() + pub fn new() -> ResolvedVc { + VersionedContentMap { + map_path_to_op: State::new(PathToOutputOperation(HashMap::new())), + map_op_to_compute_entry: State::new(HashMap::new()), + } + .resolved_cell() } } @@ -68,23 +91,24 @@ impl VersionedContentMap { /// awaited will emit the assets that were inserted. #[turbo_tasks::function] pub async fn insert_output_assets( - self: Vc, + self: ResolvedVc, // Output assets to emit - assets_operation: Vc, - node_root: Vc, - client_relative_path: Vc, - client_output_path: Vc, + assets_operation: OperationVc, + node_root: ResolvedVc, + client_relative_path: ResolvedVc, + client_output_path: ResolvedVc, ) -> Result<()> { let this = self.await?; - let compute_entry = self.compute_entry( + let compute_entry = compute_entry_operation( + self, assets_operation, node_root, client_relative_path, client_output_path, ); - let assets = *assets_operation.await?; - this.map_op_to_compute_entry - .update_conditionally(|map| map.insert(assets, compute_entry) != Some(compute_entry)); + this.map_op_to_compute_entry.update_conditionally(|map| { + map.insert(assets_operation, compute_entry) != Some(compute_entry) + }); Ok(()) } @@ -93,21 +117,21 @@ impl VersionedContentMap { #[turbo_tasks::function] async fn compute_entry( &self, - assets_operation: Vc, + assets_operation: OperationVc, node_root: Vc, client_relative_path: Vc, client_output_path: Vc, ) -> Result> { - let assets = *assets_operation.await?; + let assets = assets_operation.connect(); async fn get_entries( assets: Vc, - ) -> Result, Vc>)>> { + ) -> Result, ResolvedVc>)>> { let assets_ref = assets.await?; let entries = assets_ref .iter() .map(|&asset| async move { let path = asset.ident().path().to_resolved().await?; - Ok((path, *asset)) + Ok((path, asset)) }) .try_join() .await?; @@ -119,10 +143,10 @@ impl VersionedContentMap { let mut changed = false; // get current map's keys, subtract keys that don't exist in operation - let mut stale_assets = map.keys().copied().collect::>(); + let mut stale_assets = map.0.keys().copied().collect::>(); for (k, _) in entries.iter() { - let res = map.entry(*k).or_default().insert(assets); + let res = map.0.entry(*k).or_default().insert(assets_operation); stale_assets.remove(k); changed = changed || res; } @@ -130,10 +154,11 @@ impl VersionedContentMap { // Make more efficient with reverse map for k in &stale_assets { let res = map + .0 .get_mut(k) // guaranteed .unwrap() - .swap_remove(&assets); + .swap_remove(&assets_operation); changed = changed || res } changed @@ -144,7 +169,7 @@ impl VersionedContentMap { .resolve() .await?; let map_entry = Vc::cell(Some(MapEntry { - assets_operation: assets, + assets_operation, path_to_asset: entries.into_iter().collect(), })); Ok(map_entry) @@ -196,8 +221,8 @@ impl VersionedContentMap { path_to_asset, }) = &*result { - if let Some(asset) = path_to_asset.get(&path) { - return Ok(Vc::cell(Some(asset.to_resolved().await?))); + if let Some(&asset) = path_to_asset.get(&path) { + return Ok(Vc::cell(Some(asset))); } else { let path = path.to_string().await?; bail!( @@ -213,7 +238,7 @@ impl VersionedContentMap { #[turbo_tasks::function] pub async fn keys_in_path(&self, root: Vc) -> Result>> { let keys = { - let map = self.map_path_to_op.get(); + let map = &self.map_path_to_op.get().0; map.keys().copied().collect::>() }; let root = &root.await?; @@ -228,14 +253,14 @@ impl VersionedContentMap { #[turbo_tasks::function] fn raw_get(&self, path: ResolvedVc) -> Vc { let assets = { - let map = self.map_path_to_op.get(); + let map = &self.map_path_to_op.get().0; map.get(&path).and_then(|m| m.iter().next().copied()) }; let Some(assets) = assets else { return Vc::cell(None); }; // Need to reconnect the operation to the map - Vc::connect(assets); + let _ = assets.connect(); let compute_entry = { let map = self.map_op_to_compute_entry.get(); @@ -244,9 +269,22 @@ impl VersionedContentMap { let Some(compute_entry) = compute_entry else { return Vc::cell(None); }; - // Need to reconnect the operation to the map - Vc::connect(compute_entry); - - compute_entry + compute_entry.connect() } } + +#[turbo_tasks::function(operation)] +fn compute_entry_operation( + map: ResolvedVc, + assets_operation: OperationVc, + node_root: ResolvedVc, + client_relative_path: ResolvedVc, + client_output_path: ResolvedVc, +) -> Vc { + map.compute_entry( + assets_operation, + *node_root, + *client_relative_path, + *client_output_path, + ) +} diff --git a/crates/next-core/src/next_config.rs b/crates/next-core/src/next_config.rs index 6e80200c95617..c42342324d2f5 100644 --- a/crates/next-core/src/next_config.rs +++ b/crates/next-core/src/next_config.rs @@ -6,8 +6,8 @@ use serde::{Deserialize, Deserializer, Serialize}; use serde_json::Value as JsonValue; use turbo_rcstr::RcStr; use turbo_tasks::{ - debug::ValueDebugFormat, trace::TraceRawVcs, FxIndexMap, NonLocalValue, ResolvedVc, TaskInput, - Vc, + debug::ValueDebugFormat, trace::TraceRawVcs, FxIndexMap, NonLocalValue, OperationValue, + ResolvedVc, TaskInput, Vc, }; use turbo_tasks_env::EnvMap; use turbo_tasks_fs::FileSystemPath; @@ -48,7 +48,7 @@ pub struct ModularizeImports(FxIndexMap); pub struct CacheKinds(FxHashSet); #[turbo_tasks::value(serialization = "custom", eq = "manual")] -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, OperationValue)] #[serde(rename_all = "camelCase")] pub struct NextConfig { // TODO all fields should be private and access should be wrapped within a turbo-tasks function @@ -127,27 +127,59 @@ pub struct NextConfig { webpack: Option, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "kebab-case")] pub enum CrossOriginConfig { Anonymous, UseCredentials, } -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, + Debug, + Default, + PartialEq, + Serialize, + Deserialize, + TraceRawVcs, + NonLocalValue, + OperationValue, +)] #[serde(rename_all = "camelCase")] struct AmpConfig { canonical_base: Option, } -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, + Debug, + Default, + PartialEq, + Serialize, + Deserialize, + TraceRawVcs, + NonLocalValue, + OperationValue, +)] #[serde(rename_all = "camelCase")] struct EslintConfig { dirs: Option>, ignore_during_builds: Option, } -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, + Debug, + Default, + PartialEq, + Serialize, + Deserialize, + TraceRawVcs, + NonLocalValue, + OperationValue, +)] #[serde(rename_all = "kebab-case")] pub enum BuildActivityPositions { #[default] @@ -157,27 +189,59 @@ pub enum BuildActivityPositions { TopLeft, } -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, + Debug, + Default, + PartialEq, + Serialize, + Deserialize, + TraceRawVcs, + NonLocalValue, + OperationValue, +)] #[serde(rename_all = "camelCase")] pub struct DevIndicatorsConfig { pub build_activity: Option, pub build_activity_position: Option, } -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, + Debug, + Default, + PartialEq, + Serialize, + Deserialize, + TraceRawVcs, + NonLocalValue, + OperationValue, +)] #[serde(rename_all = "camelCase")] struct OnDemandEntriesConfig { max_inactive_age: f64, pages_buffer_length: f64, } -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, + Debug, + Default, + PartialEq, + Serialize, + Deserialize, + TraceRawVcs, + NonLocalValue, + OperationValue, +)] #[serde(rename_all = "camelCase")] struct HttpAgentConfig { keep_alive: bool, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "camelCase")] pub struct DomainLocale { pub default_locale: String, @@ -186,7 +250,9 @@ pub struct DomainLocale { pub locales: Option>, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "camelCase")] pub struct I18NConfig { pub default_locale: String, @@ -195,7 +261,9 @@ pub struct I18NConfig { pub locales: Vec, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "kebab-case")] pub enum OutputType { Standalone, @@ -215,6 +283,7 @@ pub enum OutputType { Serialize, Deserialize, NonLocalValue, + OperationValue, )] #[serde(tag = "type", rename_all = "kebab-case")] pub enum RouteHas { @@ -260,14 +329,18 @@ pub struct Header { pub missing: Option>, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "camelCase")] pub enum RedirectStatus { StatusCode(f64), Permanent(bool), } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "camelCase")] pub struct Redirect { pub source: String, @@ -309,14 +382,24 @@ pub struct Rewrites { pub fallback: Vec, } -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, + Debug, + Default, + PartialEq, + Serialize, + Deserialize, + TraceRawVcs, + NonLocalValue, + OperationValue, +)] #[serde(rename_all = "camelCase")] pub struct TypeScriptConfig { pub ignore_build_errors: Option, pub ts_config_path: Option, } -#[turbo_tasks::value(eq = "manual")] +#[turbo_tasks::value(eq = "manual", operation)] #[derive(Clone, Debug, PartialEq)] #[serde(rename_all = "camelCase")] pub struct ImageConfig { @@ -367,7 +450,9 @@ impl Default for ImageConfig { } } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "kebab-case")] pub enum ImageLoader { Default, @@ -377,7 +462,9 @@ pub enum ImageLoader { Custom, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] pub enum ImageFormat { #[serde(rename = "image/webp")] Webp, @@ -385,7 +472,17 @@ pub enum ImageFormat { Avif, } -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, + Debug, + Default, + PartialEq, + Serialize, + Deserialize, + TraceRawVcs, + NonLocalValue, + OperationValue, +)] #[serde(rename_all = "camelCase")] pub struct RemotePattern { pub hostname: String, @@ -397,14 +494,26 @@ pub struct RemotePattern { pub pathname: Option, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "kebab-case")] pub enum RemotePatternProtocal { Http, Https, } -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, + Debug, + Default, + PartialEq, + Serialize, + Deserialize, + TraceRawVcs, + NonLocalValue, + OperationValue, +)] #[serde(rename_all = "camelCase")] pub struct ExperimentalTurboConfig { /// This option has been replaced by `rules`. @@ -418,7 +527,9 @@ pub struct ExperimentalTurboConfig { pub unstable_persistent_caching: Option, } -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "camelCase")] pub struct RuleConfigItemOptions { pub loaders: Vec, @@ -426,14 +537,18 @@ pub struct RuleConfigItemOptions { pub rename_as: Option, } -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "camelCase", untagged)] pub enum RuleConfigItemOrShortcut { Loaders(Vec), Advanced(RuleConfigItem), } -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "camelCase", untagged)] pub enum RuleConfigItem { Options(RuleConfigItemOptions), @@ -441,14 +556,16 @@ pub enum RuleConfigItem { Boolean(bool), } -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(untagged)] pub enum LoaderItem { LoaderName(RcStr), LoaderOptions(WebpackLoaderItem), } -#[turbo_tasks::value] +#[turbo_tasks::value(operation)] #[derive(Clone, Debug)] #[serde(rename_all = "camelCase")] pub enum ModuleIdStrategy { @@ -459,14 +576,16 @@ pub enum ModuleIdStrategy { #[turbo_tasks::value(transparent)] pub struct OptionModuleIdStrategy(pub Option); -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(untagged)] pub enum MdxRsOptions { Boolean(bool), Option(MdxTransformOptions), } -#[turbo_tasks::value(shared)] +#[turbo_tasks::value(shared, operation)] #[derive(Clone, Debug)] #[serde(rename_all = "camelCase")] pub enum ReactCompilerMode { @@ -476,7 +595,7 @@ pub enum ReactCompilerMode { } /// Subset of react compiler options -#[turbo_tasks::value(shared)] +#[turbo_tasks::value(shared, operation)] #[derive(Clone, Debug)] #[serde(rename_all = "camelCase")] pub struct ReactCompilerOptions { @@ -486,7 +605,9 @@ pub struct ReactCompilerOptions { pub panic_threshold: Option, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(untagged)] pub enum ReactCompilerOptionsOrBoolean { Boolean(bool), @@ -506,6 +627,7 @@ pub struct OptionalReactCompilerOptions(Option> TraceRawVcs, ValueDebugFormat, NonLocalValue, + OperationValue, )] #[serde(rename_all = "camelCase")] pub struct ExperimentalConfig { @@ -607,7 +729,9 @@ pub struct ExperimentalConfig { worker_threads: Option, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "camelCase")] pub struct CacheLifeProfile { #[serde(skip_serializing_if = "Option::is_none")] @@ -662,13 +786,17 @@ fn test_cache_life_profiles_invalid() { ); } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "lowercase")] pub enum ExperimentalPartialPrerenderingIncrementalValue { Incremental, } -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Deserialize, Serialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(untagged)] pub enum ExperimentalPartialPrerendering { Boolean(bool), @@ -705,13 +833,17 @@ fn test_parse_experimental_partial_prerendering() { assert!(config.is_err()); } -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "camelCase")] pub struct SubResourceIntegrity { pub algorithm: Option, } -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Deserialize, Serialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(untagged)] pub enum ServerActionsOrLegacyBool { /// The current way to configure server actions sub behaviors. @@ -722,13 +854,17 @@ pub enum ServerActionsOrLegacyBool { LegacyBool(bool), } -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Deserialize, Serialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "kebab-case")] pub enum EsmExternalsValue { Loose, } -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Deserialize, Serialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(untagged)] pub enum EsmExternals { Loose(EsmExternalsValue), @@ -755,7 +891,16 @@ fn test_esm_externals_deserialization() { } #[derive( - Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize, TraceRawVcs, NonLocalValue, + Clone, + Debug, + Default, + PartialEq, + Eq, + Deserialize, + Serialize, + TraceRawVcs, + NonLocalValue, + OperationValue, )] #[serde(rename_all = "camelCase")] pub struct ServerActions { @@ -763,7 +908,7 @@ pub struct ServerActions { pub body_size_limit: Option, } -#[derive(Clone, Debug, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive(Clone, Debug, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue)] #[serde(untagged)] pub enum SizeLimit { Number(f64), @@ -784,14 +929,18 @@ impl PartialEq for SizeLimit { impl Eq for SizeLimit {} -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "kebab-case")] pub enum MiddlewarePrefetchType { Strict, Flexible, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(untagged)] pub enum EmotionTransformOptionsOrBoolean { Boolean(bool), @@ -807,7 +956,9 @@ impl EmotionTransformOptionsOrBoolean { } } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(untagged)] pub enum StyledComponentsTransformOptionsOrBoolean { Boolean(bool), @@ -824,7 +975,7 @@ impl StyledComponentsTransformOptionsOrBoolean { } #[turbo_tasks::value(eq = "manual")] -#[derive(Clone, Debug, PartialEq, Default)] +#[derive(Clone, Debug, PartialEq, Default, OperationValue)] #[serde(rename_all = "camelCase")] pub struct CompilerConfig { pub react_remove_properties: Option, @@ -834,7 +985,9 @@ pub struct CompilerConfig { pub styled_components: Option, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(untagged, rename_all = "camelCase")] pub enum ReactRemoveProperties { Boolean(bool), @@ -850,7 +1003,9 @@ impl ReactRemoveProperties { } } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(untagged)] pub enum RemoveConsoleConfig { Boolean(bool), diff --git a/crates/next-core/src/next_shared/transforms/modularize_imports.rs b/crates/next-core/src/next_shared/transforms/modularize_imports.rs index 79a8b854272cb..6656e8460c24f 100644 --- a/crates/next-core/src/next_shared/transforms/modularize_imports.rs +++ b/crates/next-core/src/next_shared/transforms/modularize_imports.rs @@ -5,14 +5,23 @@ use async_trait::async_trait; use modularize_imports::{modularize_imports, PackageConfig}; use serde::{Deserialize, Serialize}; use swc_core::ecma::ast::Program; -use turbo_tasks::{trace::TraceRawVcs, FxIndexMap, NonLocalValue, ResolvedVc}; +use turbo_tasks::{trace::TraceRawVcs, FxIndexMap, NonLocalValue, OperationValue, ResolvedVc}; use turbopack::module_options::{ModuleRule, ModuleRuleEffect}; use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext}; use super::module_rule_match_js_no_url; #[derive( - Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, + Clone, + Debug, + Default, + PartialEq, + Eq, + Serialize, + Deserialize, + TraceRawVcs, + NonLocalValue, + OperationValue, )] #[serde(rename_all = "camelCase")] pub struct ModularizeImportPackageConfig { @@ -24,7 +33,16 @@ pub struct ModularizeImportPackageConfig { } #[derive( - Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, + Clone, + Debug, + Default, + PartialEq, + Eq, + Serialize, + Deserialize, + TraceRawVcs, + NonLocalValue, + OperationValue, )] #[serde(untagged)] pub enum Transform { diff --git a/turbopack/crates/turbo-tasks-fs/src/rope.rs b/turbopack/crates/turbo-tasks-fs/src/rope.rs index 83fe89724517f..7152f648a8747 100644 --- a/turbopack/crates/turbo-tasks-fs/src/rope.rs +++ b/turbopack/crates/turbo-tasks-fs/src/rope.rs @@ -27,7 +27,7 @@ static EMPTY_BUF: &[u8] = &[]; /// sharing the contents of one Rope can be done by just cloning an Arc. /// /// Ropes are immutable, in order to construct one see [RopeBuilder]. -#[turbo_tasks::value(shared, serialization = "custom", eq = "manual")] +#[turbo_tasks::value(shared, serialization = "custom", eq = "manual", operation)] #[derive(Clone, Debug, Default)] pub struct Rope { /// Total length of all held bytes. diff --git a/turbopack/crates/turbo-tasks/src/marker_trait.rs b/turbopack/crates/turbo-tasks/src/marker_trait.rs index cf28a6ba51253..eaf5e5d8f293f 100644 --- a/turbopack/crates/turbo-tasks/src/marker_trait.rs +++ b/turbopack/crates/turbo-tasks/src/marker_trait.rs @@ -67,12 +67,16 @@ macro_rules! impl_auto_marker_trait { unsafe impl $trait for ::std::cell::RefCell {} unsafe impl $trait for ::std::marker::PhantomData {} + unsafe impl $trait for $crate::TraitRef {} unsafe impl $trait for $crate::ReadRef where T: $crate::VcValueType, <::Read as $crate::VcRead>::Target: $trait {} unsafe impl $trait for $crate::State {} + unsafe impl $trait for $crate::Value {} + unsafe impl $trait for $crate::TransientValue {} + unsafe impl $trait for $crate::TransientInstance {} unsafe impl $trait for &T {} unsafe impl $trait for &mut T {} diff --git a/turbopack/crates/turbo-tasks/src/state.rs b/turbopack/crates/turbo-tasks/src/state.rs index e06d1e3073580..011d817c37cad 100644 --- a/turbopack/crates/turbo-tasks/src/state.rs +++ b/turbopack/crates/turbo-tasks/src/state.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; use crate::{ get_invalidator, mark_session_dependent, mark_stateful, trace::TraceRawVcs, Invalidator, - SerializationInvalidator, + OperationValue, SerializationInvalidator, }; #[derive(Serialize, Deserialize)] @@ -135,7 +135,7 @@ impl TraceRawVcs for State { } } -impl Default for State { +impl Default for State { fn default() -> Self { // Need to be explicit to ensure marking as stateful. Self::new(Default::default()) @@ -150,7 +150,10 @@ impl PartialEq for State { impl Eq for State {} impl State { - pub fn new(value: T) -> Self { + pub fn new(value: T) -> Self + where + T: OperationValue, + { Self { serialization_invalidator: mark_stateful(), inner: Mutex::new(StateInner::new(value)), diff --git a/turbopack/crates/turbopack-cli/src/build/mod.rs b/turbopack/crates/turbopack-cli/src/build/mod.rs index 5271f8caff389..f2de763ca4ae9 100644 --- a/turbopack/crates/turbopack-cli/src/build/mod.rs +++ b/turbopack/crates/turbopack-cli/src/build/mod.rs @@ -113,7 +113,7 @@ impl TurbopackBuildBuilder { pub async fn build(self) -> Result<()> { let task = self.turbo_tasks.spawn_once_task::<(), _>(async move { - let build_result = build_internal( + let build_result_op = build_internal( self.project_dir.clone(), self.root_dir, EntryRequests( @@ -123,15 +123,15 @@ impl TurbopackBuildBuilder { .map(EntryRequest::resolved_cell) .collect(), ) - .cell(), + .resolved_cell(), self.browserslist_query, self.minify_type, ); // Await the result to propagate any errors. - build_result.strongly_consistent().await?; + build_result_op.connect().strongly_consistent().await?; - apply_effects(build_result).await?; + apply_effects(build_result_op).await?; let issue_reporter: Vc> = Vc::upcast(ConsoleUi::new(TransientInstance::new(LogOptions { @@ -143,7 +143,7 @@ impl TurbopackBuildBuilder { }))); handle_issues( - build_result, + build_result_op, issue_reporter, IssueSeverity::Error.into(), None, @@ -162,11 +162,11 @@ impl TurbopackBuildBuilder { } } -#[turbo_tasks::function] +#[turbo_tasks::function(operation)] async fn build_internal( project_dir: RcStr, root_dir: RcStr, - entry_requests: Vc, + entry_requests: ResolvedVc, browserslist_query: RcStr, minify_type: MinifyType, ) -> Result> { diff --git a/turbopack/crates/turbopack-cli/src/dev/mod.rs b/turbopack/crates/turbopack-cli/src/dev/mod.rs index 00b4c1a90ae0c..d2d6c0b2cee8b 100644 --- a/turbopack/crates/turbopack-cli/src/dev/mod.rs +++ b/turbopack/crates/turbopack-cli/src/dev/mod.rs @@ -226,7 +226,7 @@ impl TurbopackDevServerBuilder { } } -#[turbo_tasks::function] +#[turbo_tasks::function(operation)] async fn source( root_dir: RcStr, project_dir: RcStr, diff --git a/turbopack/crates/turbopack-core/src/chunk/mod.rs b/turbopack/crates/turbopack-core/src/chunk/mod.rs index 2502743a22487..5edccf34e2a77 100644 --- a/turbopack/crates/turbopack-core/src/chunk/mod.rs +++ b/turbopack/crates/turbopack-core/src/chunk/mod.rs @@ -50,7 +50,7 @@ use crate::{ }; /// A module id, which can be a number or string -#[turbo_tasks::value(shared)] +#[turbo_tasks::value(shared, operation)] #[derive(Debug, Clone, Hash, Ord, PartialOrd, DeterministicHash)] #[serde(untagged)] pub enum ModuleId { diff --git a/turbopack/crates/turbopack-core/src/code_builder.rs b/turbopack/crates/turbopack-core/src/code_builder.rs index f267bee6fad3f..6e8e0e0e34a31 100644 --- a/turbopack/crates/turbopack-core/src/code_builder.rs +++ b/turbopack/crates/turbopack-core/src/code_builder.rs @@ -6,7 +6,7 @@ use std::{ use anyhow::{Context, Result}; use indexmap::{IndexMap, IndexSet}; -use turbo_tasks::Vc; +use turbo_tasks::{ResolvedVc, Vc}; use turbo_tasks_fs::{ rope::{Rope, RopeBuilder}, util::uri_from_file, @@ -21,14 +21,13 @@ use crate::{ }; /// A mapping of byte-offset in the code string to an associated source map. -pub type Mapping = (usize, Option>>); +pub type Mapping = (usize, Option>>); /// Code stores combined output code and the source map of that output code. -#[turbo_tasks::value(shared, local)] +#[turbo_tasks::value(shared)] #[derive(Debug, Clone)] pub struct Code { code: Rope, - mappings: Vec, } @@ -36,7 +35,6 @@ pub struct Code { #[derive(Default)] pub struct CodeBuilder { code: RopeBuilder, - mappings: Vec, } @@ -63,7 +61,11 @@ impl CodeBuilder { /// Pushes original user code with an optional source map if one is /// available. If it's not, this is no different than pushing Synthetic /// code. - pub fn push_source(&mut self, code: &Rope, map: Option>>) { + pub fn push_source( + &mut self, + code: &Rope, + map: Option>>, + ) { self.push_map(map); self.code += code; } @@ -98,7 +100,7 @@ impl CodeBuilder { /// original code section. By inserting an empty source map when reaching a /// synthetic section directly after an original section, we tell Chrome /// that the previous map ended at this point. - fn push_map(&mut self, map: Option>>) { + fn push_map(&mut self, map: Option>>) { if map.is_none() && matches!(self.mappings.last(), None | Some((_, None))) { // No reason to push an empty map directly after an empty map return; diff --git a/turbopack/crates/turbopack-core/src/issue/mod.rs b/turbopack/crates/turbopack-core/src/issue/mod.rs index c2880fc71f707..c6d6a962de957 100644 --- a/turbopack/crates/turbopack-core/src/issue/mod.rs +++ b/turbopack/crates/turbopack-core/src/issue/mod.rs @@ -14,8 +14,8 @@ use auto_hash_map::AutoSet; use serde::Serialize; use turbo_rcstr::RcStr; use turbo_tasks::{ - emit, CollectiblesSource, RawVc, ReadRef, ResolvedVc, TransientInstance, TransientValue, - TryJoinIterExt, Upcast, ValueToString, Vc, + emit, CollectiblesSource, OperationVc, RawVc, ReadRef, ResolvedVc, TransientInstance, + TransientValue, TryJoinIterExt, Upcast, ValueToString, Vc, }; use turbo_tasks_fs::{FileContent, FileLine, FileLinesContent, FileSystemPath}; use turbo_tasks_hash::{DeterministicHash, Xxh3Hash64Hasher}; @@ -1036,18 +1036,19 @@ where } pub async fn handle_issues( - source: Vc, + source_op: OperationVc, issue_reporter: Vc>, min_failing_severity: Vc, path: Option<&str>, operation: Option<&str>, ) -> Result<()> { - let _ = source.resolve_strongly_consistent().await?; - let issues = source.peek_issues_with_path().await?; + let source_vc = source_op.connect(); + let _ = source_vc.resolve_strongly_consistent().await?; + let issues = source_op.peek_issues_with_path().await?; let has_fatal = issue_reporter.report_issues( TransientInstance::new(issues), - TransientValue::new(Vc::into_raw(source)), + TransientValue::new(Vc::into_raw(source_vc)), min_failing_severity, ); diff --git a/turbopack/crates/turbopack-core/src/version.rs b/turbopack/crates/turbopack-core/src/version.rs index 2b35e956aac4d..c288616638a87 100644 --- a/turbopack/crates/turbopack-core/src/version.rs +++ b/turbopack/crates/turbopack-core/src/version.rs @@ -3,8 +3,8 @@ use std::sync::Arc; use anyhow::{anyhow, Result}; use turbo_rcstr::RcStr; use turbo_tasks::{ - debug::ValueDebugFormat, trace::TraceRawVcs, IntoTraitRef, NonLocalValue, ReadRef, ResolvedVc, - State, TraitRef, Vc, + debug::ValueDebugFormat, trace::TraceRawVcs, IntoTraitRef, NonLocalValue, OperationValue, + ReadRef, ResolvedVc, State, TraitRef, Vc, }; use turbo_tasks_fs::{FileContent, LinkType}; use turbo_tasks_hash::{encode_hex, hash_xxh3_hash64}; @@ -35,7 +35,7 @@ pub trait VersionedContent { let to_ref = to.into_trait_ref().await?; // Fast path: versions are the same. - if from_ref == to_ref { + if TraitRef::ptr_eq(&from_ref, &to_ref) { return Ok(Update::None.into()); } @@ -121,7 +121,7 @@ impl VersionedContentExt for AssetContent { /// Describes the current version of an object, and how to update them from an /// earlier version. -#[turbo_tasks::value_trait(local)] +#[turbo_tasks::value_trait] pub trait Version { /// Get a unique identifier of the version as a string. There is no way /// to convert an id back to its original `Version`, so the original object @@ -149,7 +149,7 @@ pub trait VersionedContentMerger { #[turbo_tasks::value(transparent)] pub struct VersionedContents(Vec>>); -#[turbo_tasks::value] +#[turbo_tasks::value(operation)] pub struct NotFoundVersion; #[turbo_tasks::value_impl] @@ -191,6 +191,7 @@ pub enum Update { #[derive(PartialEq, Eq, Debug, Clone, TraceRawVcs, ValueDebugFormat, NonLocalValue)] pub struct TotalUpdate { /// The version this update will bring the object to. + // TODO: This trace_ignore is *very* wrong, and could cause problems if/when we add a GC #[turbo_tasks(trace_ignore)] pub to: TraitRef>, } @@ -199,6 +200,7 @@ pub struct TotalUpdate { #[derive(PartialEq, Eq, Debug, Clone, TraceRawVcs, ValueDebugFormat, NonLocalValue)] pub struct PartialUpdate { /// The version this update will bring the object to. + // TODO: This trace_ignore is *very* wrong, and could cause problems if/when we add a GC #[turbo_tasks(trace_ignore)] pub to: TraitRef>, /// The instructions to be passed to a remote system in order to update the @@ -209,7 +211,7 @@ pub struct PartialUpdate { /// [`Version`] implementation that hashes a file at a given path and returns /// the hex encoded hash as a version identifier. -#[turbo_tasks::value] +#[turbo_tasks::value(operation)] #[derive(Clone)] pub struct FileHashVersion { hash: RcStr, @@ -242,17 +244,26 @@ impl Version for FileHashVersion { } } +/// This is a dummy wrapper type to (incorrectly) implement [`OperationValue`] (required by +/// [`State`]), because the [`Version`] trait is not (yet?) a subtype of [`OperationValue`]. +#[derive(Debug, Eq, PartialEq, TraceRawVcs, NonLocalValue, OperationValue)] +struct VersionRef( + // TODO: This trace_ignore is *very* wrong, and could cause problems if/when we add a GC. + // It also allows to `Version`s that don't implement `OperationValue`, which could lead to + // incorrect results when attempting to strongly resolve Vcs. + #[turbo_tasks(trace_ignore)] TraitRef>, +); + #[turbo_tasks::value(serialization = "none")] pub struct VersionState { - #[turbo_tasks(trace_ignore)] - version: State>>, + version: State, } #[turbo_tasks::value_impl] impl VersionState { #[turbo_tasks::function] pub fn get(&self) -> Vc> { - let version = TraitRef::cell(self.version.get().clone()); + let version = TraitRef::cell(self.version.get().0.clone()); version } } @@ -260,13 +271,13 @@ impl VersionState { impl VersionState { pub async fn new(version: TraitRef>) -> Result> { Ok(Self::cell(VersionState { - version: State::new(version), + version: State::new(VersionRef(version)), })) } pub async fn set(self: Vc, new_version: TraitRef>) -> Result<()> { let this = self.await?; - this.version.set(new_version); + this.version.set(VersionRef(new_version)); Ok(()) } } diff --git a/turbopack/crates/turbopack-css/src/chunk/mod.rs b/turbopack/crates/turbopack-css/src/chunk/mod.rs index eb80b1ef89f77..3cd40c7f49789 100644 --- a/turbopack/crates/turbopack-css/src/chunk/mod.rs +++ b/turbopack/crates/turbopack-css/src/chunk/mod.rs @@ -94,7 +94,7 @@ impl CssChunk { content.source_map.map(ResolvedVc::upcast) }; - body.push_source(&content.inner_code, source_map.map(|v| *v)); + body.push_source(&content.inner_code, source_map); writeln!(body, "{close}")?; writeln!(body)?; diff --git a/turbopack/crates/turbopack-css/src/chunk/single_item_chunk/chunk.rs b/turbopack/crates/turbopack-css/src/chunk/single_item_chunk/chunk.rs index 96970ee1b8354..d724ed4bbb7b8 100644 --- a/turbopack/crates/turbopack-css/src/chunk/single_item_chunk/chunk.rs +++ b/turbopack/crates/turbopack-css/src/chunk/single_item_chunk/chunk.rs @@ -59,7 +59,7 @@ impl SingleItemCssChunk { code.push_source( &content.inner_code, - content.source_map.map(ResolvedVc::upcast).map(|v| *v), + content.source_map.map(ResolvedVc::upcast), ); write!(code, "{close}")?; diff --git a/turbopack/crates/turbopack-dev-server/src/html.rs b/turbopack/crates/turbopack-dev-server/src/html.rs index b6560a91cb054..9302215ab044a 100644 --- a/turbopack/crates/turbopack-dev-server/src/html.rs +++ b/turbopack/crates/turbopack-dev-server/src/html.rs @@ -164,7 +164,7 @@ impl DevHtmlAsset { } } -#[turbo_tasks::value] +#[turbo_tasks::value(operation)] struct DevHtmlAssetContent { chunk_paths: Vec, body: Option, @@ -234,7 +234,7 @@ impl VersionedContent for DevHtmlAssetContent { } } -#[turbo_tasks::value] +#[turbo_tasks::value(operation)] struct DevHtmlAssetVersion { content: ReadRef, } diff --git a/turbopack/crates/turbopack-dev-server/src/http.rs b/turbopack/crates/turbopack-dev-server/src/http.rs index eff6d6be100a6..2bb4e1369bd99 100644 --- a/turbopack/crates/turbopack-dev-server/src/http.rs +++ b/turbopack/crates/turbopack-dev-server/src/http.rs @@ -11,7 +11,8 @@ use hyper::{ use mime::Mime; use tokio_util::io::{ReaderStream, StreamReader}; use turbo_tasks::{ - apply_effects, util::SharedError, CollectiblesSource, ReadRef, TransientInstance, Vc, + apply_effects, util::SharedError, CollectiblesSource, OperationVc, ReadRef, TransientInstance, + Vc, }; use turbo_tasks_bytes::Bytes; use turbo_tasks_fs::FileContent; @@ -41,37 +42,39 @@ enum GetFromSourceResult { /// Resolves a [SourceRequest] within a [super::ContentSource], returning the /// corresponding content as a -#[turbo_tasks::function] +#[turbo_tasks::function(operation)] async fn get_from_source( - source: Vc>, + source: OperationVc>, request: TransientInstance, ) -> Result> { - Ok(match &*resolve_source_request(source, request).await? { - ResolveSourceRequestResult::Static(static_content_vc, header_overwrites) => { - let static_content = static_content_vc.await?; - if let AssetContent::File(file) = &*static_content.content.content().await? { - GetFromSourceResult::Static { - content: file.await?, - status_code: static_content.status_code, - headers: static_content.headers.await?, - header_overwrites: header_overwrites.await?, + Ok( + match &*resolve_source_request(source, request).connect().await? { + ResolveSourceRequestResult::Static(static_content_vc, header_overwrites) => { + let static_content = static_content_vc.await?; + if let AssetContent::File(file) = &*static_content.content.content().await? { + GetFromSourceResult::Static { + content: file.await?, + status_code: static_content.status_code, + headers: static_content.headers.await?, + header_overwrites: header_overwrites.await?, + } + } else { + GetFromSourceResult::NotFound } - } else { - GetFromSourceResult::NotFound } + ResolveSourceRequestResult::HttpProxy(proxy) => { + GetFromSourceResult::HttpProxy(proxy.await?) + } + ResolveSourceRequestResult::NotFound => GetFromSourceResult::NotFound, } - ResolveSourceRequestResult::HttpProxy(proxy) => { - GetFromSourceResult::HttpProxy(proxy.await?) - } - ResolveSourceRequestResult::NotFound => GetFromSourceResult::NotFound, - } - .cell()) + .cell(), + ) } /// Processes an HTTP request within a given content source and returns the /// response. pub async fn process_request_with_content_source( - source: Vc>, + source: OperationVc>, request: Request, issue_reporter: Vc>, ) -> Result<( @@ -80,12 +83,13 @@ pub async fn process_request_with_content_source( )> { let original_path = request.uri().path().to_string(); let request = http_request_to_source_request(request).await?; - let result = get_from_source(source, TransientInstance::new(request)); - let resolved_result = result.resolve_strongly_consistent().await?; - apply_effects(result).await?; - let side_effects: AutoSet>> = result.peek_collectibles(); + let result_op = get_from_source(source, TransientInstance::new(request)); + let result_vc = result_op.connect(); + let resolved_result = result_vc.resolve_strongly_consistent().await?; + apply_effects(result_op).await?; + let side_effects: AutoSet>> = result_op.peek_collectibles(); handle_issues( - result, + result_op, issue_reporter, IssueSeverity::Fatal.cell(), Some(&original_path), diff --git a/turbopack/crates/turbopack-dev-server/src/lib.rs b/turbopack/crates/turbopack-dev-server/src/lib.rs index 4d083d476dc68..e792d5d31f531 100644 --- a/turbopack/crates/turbopack-dev-server/src/lib.rs +++ b/turbopack/crates/turbopack-dev-server/src/lib.rs @@ -34,7 +34,7 @@ use tokio::task::JoinHandle; use tracing::{event, info_span, Instrument, Level, Span}; use turbo_tasks::{ apply_effects, run_once_with_reason, trace::TraceRawVcs, util::FormatDuration, NonLocalValue, - TurboTasksApi, Vc, + OperationVc, TurboTasksApi, Vc, }; use turbopack_core::{ error::PrettyPrintError, @@ -49,14 +49,14 @@ use crate::{ pub trait SourceProvider: Send + Clone + 'static { /// must call a turbo-tasks function internally - fn get_source(&self) -> Vc>; + fn get_source(&self) -> OperationVc>; } impl SourceProvider for T where - T: Fn() -> Vc> + Send + Clone + 'static, + T: Fn() -> OperationVc> + Send + Clone + 'static, { - fn get_source(&self) -> Vc> { + fn get_source(&self) -> OperationVc> { self() } } @@ -211,7 +211,8 @@ impl DevServerBuilder { let uri = request.uri(); let path = uri.path().to_string(); let source = source_provider.get_source(); - let resolved_source = source.resolve_strongly_consistent().await?; + // HACK: Resolve `source` now so that we can get any issues on it + let _ = source.connect().resolve_strongly_consistent().await?; apply_effects(source).await?; handle_issues( source, @@ -223,7 +224,14 @@ impl DevServerBuilder { .await?; let (response, side_effects) = http::process_request_with_content_source( - resolved_source, + // HACK: pass `source` here (instead of `resolved_source` + // because the underlying API wants to do it's own + // `resolve_strongly_consistent` call. + // + // It's unlikely (the calls happen one-after-another), but this + // could cause inconsistency between the reported issues and + // the generated HTTP response. + source, request, issue_reporter, ) diff --git a/turbopack/crates/turbopack-dev-server/src/source/mod.rs b/turbopack/crates/turbopack-dev-server/src/source/mod.rs index 5f7945f36ebcc..f11b6cb8b3feb 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/mod.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/mod.rs @@ -33,13 +33,14 @@ use self::{ }; /// The result of proxying a request to another HTTP server. -#[turbo_tasks::value(shared)] +#[turbo_tasks::value(shared, operation)] pub struct ProxyResult { /// The HTTP status code to return. pub status: u16, /// Headers arranged as contiguous (name, value) pairs. pub headers: Vec<(RcStr, RcStr)>, /// The body to return. + #[turbo_tasks(trace_ignore)] pub body: Body, } diff --git a/turbopack/crates/turbopack-dev-server/src/source/request.rs b/turbopack/crates/turbopack-dev-server/src/source/request.rs index 23ba2395fe7dd..c73a2aec3a11a 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/request.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/request.rs @@ -1,15 +1,18 @@ use hyper::{HeaderMap, Uri}; +use turbo_tasks::NonLocalValue; use super::Body; /// A request to a content source. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, NonLocalValue)] pub struct SourceRequest { /// The HTTP method to use. pub method: String, /// The URI to request. + #[turbo_tasks(trace_ignore)] pub uri: Uri, /// The headers to send. + #[turbo_tasks(trace_ignore)] pub headers: HeaderMap, /// The body to send. pub body: Body, diff --git a/turbopack/crates/turbopack-dev-server/src/source/resolve.rs b/turbopack/crates/turbopack-dev-server/src/source/resolve.rs index 791931d945712..94e0574e6cb6d 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/resolve.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/resolve.rs @@ -9,7 +9,7 @@ use hyper::{ Uri, }; use turbo_rcstr::RcStr; -use turbo_tasks::{ResolvedVc, TransientInstance, Value, Vc}; +use turbo_tasks::{OperationVc, ResolvedVc, TransientInstance, Value, Vc}; use super::{ headers::{HeaderValue, Headers}, @@ -37,9 +37,9 @@ pub enum ResolveSourceRequestResult { /// version of the content. We don't make resolve_source_request strongly /// consistent as we want get_routes and get to be independent consistent and /// any side effect in get should not wait for recomputing of get_routes. -#[turbo_tasks::function] +#[turbo_tasks::function(operation)] pub async fn resolve_source_request( - source: Vc>, + source: OperationVc>, request: TransientInstance, ) -> Result> { let original_path = request.uri.path().to_string(); @@ -47,7 +47,11 @@ pub async fn resolve_source_request( let mut current_asset_path: RcStr = urlencoding::decode(&original_path[1..])?.into(); let mut request_overwrites = (*request).clone(); let mut response_header_overwrites = Vec::new(); - let mut route_tree = source.get_routes().resolve_strongly_consistent().await?; + let mut route_tree = source + .connect() + .get_routes() + .resolve_strongly_consistent() + .await?; 'routes: loop { let mut sources = route_tree.get(current_asset_path.clone()); 'sources: loop { diff --git a/turbopack/crates/turbopack-dev-server/src/update/stream.rs b/turbopack/crates/turbopack-dev-server/src/update/stream.rs index 8d9a3457c9833..80ba3f4b29a28 100644 --- a/turbopack/crates/turbopack-dev-server/src/update/stream.rs +++ b/turbopack/crates/turbopack-dev-server/src/update/stream.rs @@ -6,7 +6,7 @@ use tokio::sync::mpsc::Sender; use tokio_stream::wrappers::ReceiverStream; use tracing::Instrument; use turbo_rcstr::RcStr; -use turbo_tasks::{IntoTraitRef, ReadRef, ResolvedVc, TransientInstance, Vc}; +use turbo_tasks::{IntoTraitRef, OperationVc, ReadRef, ResolvedVc, TransientInstance, Vc}; use turbo_tasks_fs::{FileSystem, FileSystemPath}; use turbopack_core::{ error::PrettyPrintError, @@ -23,7 +23,7 @@ use turbopack_core::{ use crate::source::{resolve::ResolveSourceRequestResult, ProxyResult}; -type GetContentFn = Box Vc + Send + Sync>; +type GetContentFn = Box OperationVc + Send + Sync>; async fn peek_issues(source: Vc) -> Result>> { let captured = source.peek_issues_with_path().await?; @@ -47,11 +47,11 @@ async fn get_update_stream_item( from: Vc, get_content: TransientInstance, ) -> Result> { - let content = get_content(); - let _ = content.resolve_strongly_consistent().await?; - let mut plain_issues = peek_issues(content).await?; + let content_vc = get_content().connect(); + let content_result = content_vc.strongly_consistent().await; + let mut plain_issues = peek_issues(content_vc).await?; - let content_value = match content.await { + let content_value = match content_result { Ok(content) => content, Err(e) => { plain_issues.push( @@ -191,7 +191,7 @@ impl UpdateStream { let content = get_content(); // We can ignore issues reported in content here since [compute_update_stream] // will handle them - let version = match *content.await? { + let version = match *content.connect().await? { ResolveSourceRequestResult::Static(static_content, _) => { static_content.await?.content.version() } diff --git a/turbopack/crates/turbopack-ecmascript-plugins/src/transform/emotion.rs b/turbopack/crates/turbopack-ecmascript-plugins/src/transform/emotion.rs index 96c855e73cea9..294abfcc5c92e 100644 --- a/turbopack/crates/turbopack-ecmascript-plugins/src/transform/emotion.rs +++ b/turbopack/crates/turbopack-ecmascript-plugins/src/transform/emotion.rs @@ -14,10 +14,12 @@ use swc_core::{ visit::FoldWith, }, }; -use turbo_tasks::{trace::TraceRawVcs, NonLocalValue, ValueDefault, Vc}; +use turbo_tasks::{trace::TraceRawVcs, NonLocalValue, OperationValue, ValueDefault, Vc}; use turbopack_ecmascript::{CustomTransformer, TransformContext}; -#[derive(Clone, PartialEq, Eq, Debug, TraceRawVcs, Serialize, Deserialize, NonLocalValue)] +#[derive( + Clone, PartialEq, Eq, Debug, TraceRawVcs, Serialize, Deserialize, NonLocalValue, OperationValue, +)] #[serde(rename_all = "kebab-case")] pub enum EmotionLabelKind { DevOnly, @@ -27,7 +29,7 @@ pub enum EmotionLabelKind { //[TODO]: need to support importmap, there are type mismatch between //next.config.js to swc's emotion options -#[turbo_tasks::value(shared)] +#[turbo_tasks::value(shared, operation)] #[derive(Default, Clone, Debug)] #[serde(rename_all = "camelCase")] pub struct EmotionTransformConfig { diff --git a/turbopack/crates/turbopack-ecmascript-plugins/src/transform/relay.rs b/turbopack/crates/turbopack-ecmascript-plugins/src/transform/relay.rs index 46ca6d010f306..d16be3a7ab949 100644 --- a/turbopack/crates/turbopack-ecmascript-plugins/src/transform/relay.rs +++ b/turbopack/crates/turbopack-ecmascript-plugins/src/transform/relay.rs @@ -5,11 +5,13 @@ use async_trait::async_trait; use serde::{Deserialize, Serialize}; use swc_core::{common::FileName, ecma::ast::Program}; use swc_relay::RelayLanguageConfig; -use turbo_tasks::{trace::TraceRawVcs, NonLocalValue}; +use turbo_tasks::{trace::TraceRawVcs, NonLocalValue, OperationValue}; use turbo_tasks_fs::FileSystemPath; use turbopack_ecmascript::{CustomTransformer, TransformContext}; -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "camelCase")] pub struct RelayConfig { pub src: String, @@ -17,7 +19,9 @@ pub struct RelayConfig { pub language: Option, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] +#[derive( + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, +)] #[serde(rename_all = "lowercase")] pub enum RelayLanguage { TypeScript, diff --git a/turbopack/crates/turbopack-ecmascript-plugins/src/transform/styled_components.rs b/turbopack/crates/turbopack-ecmascript-plugins/src/transform/styled_components.rs index 88d3a0b5beba4..576a445ba41f8 100644 --- a/turbopack/crates/turbopack-ecmascript-plugins/src/transform/styled_components.rs +++ b/turbopack/crates/turbopack-ecmascript-plugins/src/transform/styled_components.rs @@ -9,7 +9,7 @@ use swc_core::{ use turbo_tasks::{ValueDefault, Vc}; use turbopack_ecmascript::{CustomTransformer, TransformContext}; -#[turbo_tasks::value(shared)] +#[turbo_tasks::value(shared, operation)] #[derive(Clone, Debug)] #[serde(default, rename_all = "camelCase")] pub struct StyledComponentsTransformConfig { diff --git a/turbopack/crates/turbopack-ecmascript/src/chunk/item.rs b/turbopack/crates/turbopack-ecmascript/src/chunk/item.rs index 86f5856f2a751..d8061333cfecc 100644 --- a/turbopack/crates/turbopack-ecmascript/src/chunk/item.rs +++ b/turbopack/crates/turbopack-ecmascript/src/chunk/item.rs @@ -155,12 +155,11 @@ impl EcmascriptChunkItemContent { match source_map { Some(map) => fileify_source_map(map, *rewrite_source_path) .await? - .map(|v| *v) - .map(Vc::upcast), + .map(ResolvedVc::upcast), None => None, } } else { - self.source_map.map(|v| *v) + self.source_map }; code.push_source(&self.inner_code, source_map); diff --git a/turbopack/crates/turbopack-ecmascript/src/minify.rs b/turbopack/crates/turbopack-ecmascript/src/minify.rs index 21c368f901fc5..9cea1161a513d 100644 --- a/turbopack/crates/turbopack-ecmascript/src/minify.rs +++ b/turbopack/crates/turbopack-ecmascript/src/minify.rs @@ -19,7 +19,7 @@ use swc_core::{ transforms::base::fixer::paren_remover, }, }; -use turbo_tasks::Vc; +use turbo_tasks::{ResolvedVc, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ code_builder::{Code, CodeBuilder}, @@ -106,8 +106,8 @@ pub async fn minify(path: Vc, code: Vc) -> Result let mut builder = CodeBuilder::default(); builder.push_source( &src.into(), - Some(Vc::upcast( - ParseResultSourceMap::new(cm, src_map_buf, original_map).cell(), + Some(ResolvedVc::upcast( + ParseResultSourceMap::new(cm, src_map_buf, original_map).resolved_cell(), )), ); diff --git a/turbopack/crates/turbopack-ecmascript/src/static_code.rs b/turbopack/crates/turbopack-ecmascript/src/static_code.rs index dba3a444eb44d..5e22cc860f6a0 100644 --- a/turbopack/crates/turbopack-ecmascript/src/static_code.rs +++ b/turbopack/crates/turbopack-ecmascript/src/static_code.rs @@ -54,7 +54,7 @@ impl StaticEcmascriptCode { let mut code = CodeBuilder::default(); code.push_source( &runtime_base_content.inner_code, - runtime_base_content.source_map.map(|v| *v), + runtime_base_content.source_map, ); Ok(Code::cell(code.build())) } diff --git a/turbopack/crates/turbopack-mdx/src/lib.rs b/turbopack/crates/turbopack-mdx/src/lib.rs index 6e32e1ca4a1ea..994375343a6da 100644 --- a/turbopack/crates/turbopack-mdx/src/lib.rs +++ b/turbopack/crates/turbopack-mdx/src/lib.rs @@ -24,7 +24,7 @@ fn modifier() -> Vc { Vc::cell("mdx".into()) } -#[turbo_tasks::value(shared)] +#[turbo_tasks::value(shared, operation)] #[derive(Hash, Debug, Clone)] #[serde(rename_all = "camelCase")] pub enum MdxParseConstructs { @@ -35,7 +35,7 @@ pub enum MdxParseConstructs { /// Subset of mdxjs::Options to allow to inherit turbopack's jsx-related configs /// into mdxjs. This is thin, near straightforward subset of mdxjs::Options to /// enable turbo tasks. -#[turbo_tasks::value(shared)] +#[turbo_tasks::value(shared, operation)] #[derive(Hash, Debug, Clone)] #[serde(rename_all = "camelCase", default)] pub struct MdxTransformOptions { diff --git a/turbopack/crates/turbopack-node/src/transforms/webpack.rs b/turbopack/crates/turbopack-node/src/transforms/webpack.rs index 21e2143df19bf..2851a8da9a668 100644 --- a/turbopack/crates/turbopack-node/src/transforms/webpack.rs +++ b/turbopack/crates/turbopack-node/src/transforms/webpack.rs @@ -8,8 +8,8 @@ use serde_json::{json, Value as JsonValue}; use serde_with::serde_as; use turbo_rcstr::RcStr; use turbo_tasks::{ - trace::TraceRawVcs, Completion, NonLocalValue, ResolvedVc, TaskInput, TryJoinIterExt, Value, - ValueToString, Vc, + trace::TraceRawVcs, Completion, NonLocalValue, OperationValue, ResolvedVc, TaskInput, + TryJoinIterExt, Value, ValueToString, Vc, }; use turbo_tasks_bytes::stream::SingleValue; use turbo_tasks_env::ProcessEnv; @@ -75,7 +75,9 @@ struct WebpackLoadersProcessingResult { assets: Option>, } -#[derive(Clone, PartialEq, Eq, Debug, TraceRawVcs, Serialize, Deserialize, NonLocalValue)] +#[derive( + Clone, PartialEq, Eq, Debug, TraceRawVcs, Serialize, Deserialize, NonLocalValue, OperationValue, +)] pub struct WebpackLoaderItem { pub loader: RcStr, pub options: serde_json::Map, diff --git a/turbopack/crates/turbopack-nodejs/src/ecmascript/node/version.rs b/turbopack/crates/turbopack-nodejs/src/ecmascript/node/version.rs index ed94fbb6128d9..fd3e691dda7fc 100644 --- a/turbopack/crates/turbopack-nodejs/src/ecmascript/node/version.rs +++ b/turbopack/crates/turbopack-nodejs/src/ecmascript/node/version.rs @@ -12,7 +12,7 @@ use turbopack_ecmascript::chunk::EcmascriptChunkContent; use super::content::chunk_items; -#[turbo_tasks::value(serialization = "none", local)] +#[turbo_tasks::value(serialization = "none")] pub(super) struct EcmascriptBuildNodeChunkVersion { chunk_path: String, chunk_items: Vec<(ReadRef, ReadRef)>,