From a2d221b9da2cdc471293dc225d72417f4a1c6c45 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Tue, 17 Dec 2024 15:48:46 -0800 Subject: [PATCH] refactor(turbopack): Make various types directly or indirectly included in `State` types into OperationValues and/or NonLocalValues (#74008) This is a refactor ahead of #73876 This adds the `OperationValue` trait (and in a few cases, `NonLocalValue`) to a large number of types where it can be trivially done. These types are needed in #73876 because they're used somewhere inside of a `State<...>` type (most likely transitively). --- crates/next-api/src/project.rs | 41 ++- crates/next-core/src/next_config.rs | 247 ++++++++++++++---- .../transforms/modularize_imports.rs | 24 +- .../crates/turbo-tasks/src/marker_trait.rs | 4 + .../crates/turbopack-core/src/code_builder.rs | 16 +- .../crates/turbopack-core/src/version.rs | 6 +- .../crates/turbopack-css/src/chunk/mod.rs | 2 +- .../src/chunk/single_item_chunk/chunk.rs | 2 +- .../crates/turbopack-dev-server/src/html.rs | 4 +- .../turbopack-dev-server/src/source/mod.rs | 3 +- .../src/source/request.rs | 5 +- .../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 +- 20 files changed, 311 insertions(+), 90 deletions(-) diff --git a/crates/next-api/src/project.rs b/crates/next-api/src/project.rs index 1846d6b97e3eb..a5f5d5513deb0 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, ReadRef, + ResolvedVc, State, TaskInput, TransientInstance, TryFlatJoinIterExt, Value, Vc, }; use turbo_tasks_env::{EnvMap, ProcessEnv}; use turbo_tasks_fs::{DiskFileSystem, FileSystem, FileSystemPath, VirtualFileSystem}; @@ -73,7 +73,17 @@ use crate::{ }; #[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 { 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/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/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/version.rs b/turbopack/crates/turbopack-core/src/version.rs index 2b35e956aac4d..d9ed885c43eb3 100644 --- a/turbopack/crates/turbopack-core/src/version.rs +++ b/turbopack/crates/turbopack-core/src/version.rs @@ -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] @@ -209,7 +209,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, 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/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-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)>,