Skip to content

[turbopack] Remove the _for_input options from turbo_tasks::value and the TypedForInput trait. #80185

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions crates/next-core/src/next_image/module.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use turbo_tasks::{ResolvedVc, TaskInput, Vc, fxindexmap};
use serde::{Deserialize, Serialize};
use turbo_tasks::{NonLocalValue, ResolvedVc, TaskInput, Vc, fxindexmap, trace::TraceRawVcs};
use turbopack::{ModuleAssetContext, module_options::CustomModuleType};
use turbopack_core::{
context::AssetContext, module::Module, reference_type::ReferenceType, resolve::ModulePart,
Expand All @@ -9,8 +10,21 @@ use turbopack_static::ecma::StaticUrlJsModule;

use super::source_asset::StructuredImageFileSource;

#[turbo_tasks::value(serialization = "auto_for_input")]
#[derive(Clone, Copy, Debug, PartialOrd, Ord, Hash, TaskInput)]
#[derive(
Eq,
PartialEq,
Clone,
Copy,
Debug,
PartialOrd,
Ord,
Hash,
TaskInput,
TraceRawVcs,
NonLocalValue,
Serialize,
Deserialize,
)]
pub enum BlurPlaceholderMode {
/// Do not generate a blur placeholder at all.
None,
Expand Down
40 changes: 9 additions & 31 deletions turbopack/crates/turbo-tasks-macros/src/value_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ impl TryFrom<LitStr> for CellMode {
enum SerializationMode {
None,
Auto,
AutoForInput,
Custom,
CustomForInput,
}

impl Parse for SerializationMode {
Expand All @@ -91,13 +89,10 @@ impl TryFrom<LitStr> for SerializationMode {
match lit.value().as_str() {
"none" => Ok(SerializationMode::None),
"auto" => Ok(SerializationMode::Auto),
"auto_for_input" => Ok(SerializationMode::AutoForInput),
"custom" => Ok(SerializationMode::Custom),
"custom_for_input" => Ok(SerializationMode::CustomForInput),
_ => Err(Error::new_spanned(
&lit,
"expected \"none\", \"auto\", \"auto_for_input\", \"custom\" or \
\"custom_for_input\"",
"expected \"none\", \"auto\", or \"custom\"",
)),
}
}
Expand Down Expand Up @@ -358,17 +353,14 @@ pub fn value(args: TokenStream, input: TokenStream) -> TokenStream {
#[shrink_to_fit(crate = "turbo_tasks::macro_helpers::shrink_to_fit")]
}];
match serialization_mode {
SerializationMode::Auto | SerializationMode::AutoForInput => {
struct_attributes.push(quote! {
#[derive(
turbo_tasks::macro_helpers::serde::Serialize,
turbo_tasks::macro_helpers::serde::Deserialize,
)]
#[serde(crate = "turbo_tasks::macro_helpers::serde")]
})
}
SerializationMode::None | SerializationMode::Custom | SerializationMode::CustomForInput => {
}
SerializationMode::Auto => struct_attributes.push(quote! {
#[derive(
turbo_tasks::macro_helpers::serde::Serialize,
turbo_tasks::macro_helpers::serde::Deserialize,
)]
#[serde(crate = "turbo_tasks::macro_helpers::serde")]
}),
SerializationMode::None | SerializationMode::Custom => {}
};
if inner_type.is_some() {
// Transparent structs have their own manual `ValueDebug` implementation.
Expand Down Expand Up @@ -404,18 +396,6 @@ pub fn value(args: TokenStream, input: TokenStream) -> TokenStream {
turbo_tasks::ValueType::new_with_any_serialization::<#ident>()
}
}
SerializationMode::AutoForInput | SerializationMode::CustomForInput => {
quote! {
turbo_tasks::ValueType::new_with_magic_serialization::<#ident>()
}
}
};

let for_input_marker = match serialization_mode {
SerializationMode::None | SerializationMode::Auto | SerializationMode::Custom => quote! {},
SerializationMode::AutoForInput | SerializationMode::CustomForInput => quote! {
impl turbo_tasks::TypedForInput for #ident {}
},
};

let value_debug_impl = if inner_type.is_some() {
Expand Down Expand Up @@ -462,8 +442,6 @@ pub fn value(args: TokenStream, input: TokenStream) -> TokenStream {

#value_type_and_register_code

#for_input_marker

#value_debug_impl
};

Expand Down
8 changes: 2 additions & 6 deletions turbopack/crates/turbo-tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ pub use value::{TransientInstance, TransientValue};
pub use value_type::{TraitMethod, TraitType, ValueType};
pub use vc::{
Dynamic, NonLocalValue, OperationValue, OperationVc, OptionVcExt, ReadVcFuture, ResolvedVc,
TypedForInput, Upcast, ValueDefault, Vc, VcCast, VcCellNewMode, VcCellSharedMode,
VcDefaultRead, VcRead, VcTransparentRead, VcValueTrait, VcValueTraitCast, VcValueType,
VcValueTypeCast,
Upcast, ValueDefault, Vc, VcCast, VcCellNewMode, VcCellSharedMode, VcDefaultRead, VcRead,
VcTransparentRead, VcValueTrait, VcValueTraitCast, VcValueType, VcValueTypeCast,
};

pub type SliceMap<K, V> = Box<[(K, V)]>;
Expand Down Expand Up @@ -239,11 +238,8 @@ macro_rules! fxindexset {
/// required for persistent caching of tasks to disk.
///
/// - **`"auto"` *(default)*:** Derives the serialization traits and enables serialization.
/// - **`"auto_for_input"`:** Same as `"auto"`, but also adds the marker trait [`TypedForInput`].
/// - **`"custom"`:** Prevents deriving the serialization traits, but still enables serialization
/// (you must manually implement [`serde::Serialize`] and [`serde::Deserialize`]).
/// - **`"custom_for_input"`:** Same as `"custom"`, but also adds the marker trait
/// [`TypedForInput`].
/// - **`"none"`:** Disables serialization and prevents deriving the traits.
///
/// ## `shared`
Expand Down
17 changes: 0 additions & 17 deletions turbopack/crates/turbo-tasks/src/value_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,6 @@ impl ValueType {
}
}

/// This is internally used by `#[turbo_tasks::value]`
pub fn new_with_magic_serialization<
T: VcValueType + Debug + Eq + Hash + Serialize + for<'de> Deserialize<'de> + TraceRawVcs,
>() -> Self {
Self {
name: std::any::type_name::<T>().to_string(),
traits: AutoSet::new(),
trait_methods: AutoMap::new(),
magic_serialization: Some((
<dyn MagicAny>::as_serialize::<T>,
MagicAnyDeserializeSeed::new::<T>(),
)),
any_serialization: Some((any_as_serialize::<T>, AnyDeserializeSeed::new::<T>())),
raw_cell: <T::CellMode as VcCellMode<T>>::raw_cell,
}
}

/// This is internally used by `#[turbo_tasks::value]`
pub fn new_with_any_serialization<
T: VcValueType + Any + Serialize + for<'de> Deserialize<'de>,
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbo-tasks/src/vc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use self::{
operation::{OperationValue, OperationVc},
read::{ReadOwnedVcFuture, ReadVcFuture, VcDefaultRead, VcRead, VcTransparentRead},
resolved::ResolvedVc,
traits::{Dynamic, TypedForInput, Upcast, VcValueTrait, VcValueType},
traits::{Dynamic, Upcast, VcValueTrait, VcValueType},
};
use crate::{
CellId, RawVc, ResolveTypeError,
Expand Down
7 changes: 0 additions & 7 deletions turbopack/crates/turbo-tasks/src/vc/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,3 @@ where
T: VcValueTrait + ?Sized,
{
}

/// Marker trait that a turbo_tasks::value is prepared for serialization as
/// [`Value<...>`][crate::Value] input.
///
/// Either use [`#[turbo_tasks::value(serialization = "auto_for_input")]`][macro@crate::value] or
/// avoid [`Value<...>`][crate::Value] in favor of a real [Vc][crate::Vc].
pub trait TypedForInput: VcValueType {}
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-browser/src/chunking_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl BrowserChunkingContextBuilder {
/// It also uses a chunking heuristic that is incremental and cacheable.
/// It splits "node_modules" separately as these are less likely to change
/// during development
#[turbo_tasks::value(serialization = "auto_for_input")]
#[turbo_tasks::value]
#[derive(Debug, Clone, Hash, TaskInput)]
pub struct BrowserChunkingContext {
name: Option<RcStr>,
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-core/src/compile_time_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl From<serde_json::Value> for CompileTimeDefineValue {
}
}

#[turbo_tasks::value(serialization = "auto_for_input")]
#[turbo_tasks::value]
#[derive(Debug, Clone, Hash)]
pub enum DefineableNameSegment {
Name(RcStr),
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-core/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Environment {
}
}

#[turbo_tasks::value(serialization = "auto_for_input")]
#[turbo_tasks::value]
#[derive(Debug, Hash, Clone, Copy, TaskInput)]
pub enum ExecutionEnvironment {
NodeJsBuildTime(ResolvedVc<NodeJsEnvironment>),
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-core/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Display;
use serde::{Deserialize, Serialize};
use turbo_tasks::{NonLocalValue, Vc, trace::TraceRawVcs};

#[turbo_tasks::value(shared, serialization = "auto_for_input")]
#[turbo_tasks::value(shared)]
#[derive(Hash, Debug, Copy, Clone)]
pub struct CompileTarget {
/// <https://nodejs.org/api/os.html#osarch>
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-dev-server/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl ContentSourceDataFilter {
/// Describes additional information that need to be sent to requests to
/// ContentSource. By sending these information ContentSource responses are
/// cached-keyed by them and they can access them.
#[turbo_tasks::value(shared, serialization = "auto_for_input")]
#[turbo_tasks::value(shared)]
#[derive(Debug, Default, Clone, Hash)]
pub struct ContentSourceDataVary {
pub method: bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
tree_shake::{PartId, find_turbopack_part_id_in_asserts},
};

#[turbo_tasks::value(serialization = "auto_for_input")]
#[turbo_tasks::value]
#[derive(Default, Debug, Clone, Hash)]
pub struct ImportAnnotations {
// TODO store this in more structured way
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbopack-ecmascript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub enum TreeShakingMode {
#[turbo_tasks::value(transparent)]
pub struct OptionTreeShaking(pub Option<TreeShakingMode>);

#[turbo_tasks::value(shared, serialization = "auto_for_input")]
#[turbo_tasks::value(shared)]
#[derive(Hash, Debug, Default, Copy, Clone)]
pub struct EcmascriptOptions {
pub refresh: bool,
Expand Down Expand Up @@ -185,7 +185,7 @@ pub struct EcmascriptOptions {
pub keep_last_successful_parse: bool,
}

#[turbo_tasks::value(serialization = "auto_for_input")]
#[turbo_tasks::value]
#[derive(Hash, Debug, Copy, Clone, TaskInput)]
pub enum EcmascriptModuleAssetType {
/// Module with EcmaScript code
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbopack-ecmascript/src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use turbopack_core::{
issue::{Issue, IssueSeverity, IssueStage, StyledString},
};

#[turbo_tasks::value(serialization = "auto_for_input")]
#[turbo_tasks::value]
#[derive(Debug, Clone, Hash)]
pub enum EcmascriptInputTransform {
Plugin(ResolvedVc<TransformPlugin>),
Expand Down Expand Up @@ -88,7 +88,7 @@ impl CustomTransformer for TransformPlugin {
}
}

#[turbo_tasks::value(transparent, serialization = "auto_for_input")]
#[turbo_tasks::value(transparent)]
#[derive(Debug, Clone, Hash)]
pub struct EcmascriptInputTransforms(Vec<EcmascriptInputTransform>);

Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-nodejs/src/chunking_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl NodeJsChunkingContextBuilder {
}

/// A chunking context for build mode.
#[turbo_tasks::value(serialization = "auto_for_input")]
#[turbo_tasks::value]
#[derive(Debug, Clone, Hash, TaskInput)]
pub struct NodeJsChunkingContext {
/// The root path of the project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub enum ModuleRuleEffect {
Ignore,
}

#[turbo_tasks::value(serialization = "auto_for_input", shared)]
#[turbo_tasks::value(shared)]
#[derive(Hash, Debug, Copy, Clone)]
pub enum ModuleType {
Ecmascript {
Expand Down
Loading