Unverified Commit 1009c506 authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

[turbopack] Remove uses of `Value<..>` instead make the payloads impl Taskinput (#80141)

Remove uses of `Value<..>` instead make the payloads impl Taskinput

### Why?
The Value<> type is confusing and error prone, lets destroy it!

As discussed over slack, turbo_tasks::Value type always implements is_resolved as true and is_transient as false which is incorrect and can enable smuggling transient vcs into turbo tasks.

• https://vercel.slack.com/archives/C03EWR7LGEN/p1743456121241529
• https://vercel.slack.com/archives/C04NGV98TPS/p1743455453764879
parent f05106da
...@@ -6,7 +6,7 @@ use indoc::formatdoc; ...@@ -6,7 +6,7 @@ use indoc::formatdoc;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{Completion, FxIndexMap, ResolvedVc, Value, Vc}; use turbo_tasks::{Completion, FxIndexMap, ResolvedVc, Vc};
use turbo_tasks_bytes::stream::SingleValue; use turbo_tasks_bytes::stream::SingleValue;
use turbo_tasks_env::{CommandLineProcessEnv, ProcessEnv}; use turbo_tasks_env::{CommandLineProcessEnv, ProcessEnv};
use turbo_tasks_fetch::{HttpResponseBody, fetch}; use turbo_tasks_fetch::{HttpResponseBody, fetch};
...@@ -624,7 +624,7 @@ async fn font_options_from_query_map( ...@@ -624,7 +624,7 @@ async fn font_options_from_query_map(
let options = let options =
options_from_request(&parse_json_with_source_context(&json)?, &*font_data.await?)?; options_from_request(&parse_json_with_source_context(&json)?, &*font_data.await?)?;
Ok(NextFontGoogleOptions::new(Value::new(options))) Ok(NextFontGoogleOptions::new(options))
} }
fn font_file_options_from_query_map(query: &RcStr) -> Result<NextFontGoogleFontFileOptions> { fn font_file_options_from_query_map(query: &RcStr) -> Result<NextFontGoogleFontFileOptions> {
let query_map = qstring::QString::from(query.as_str()); let query_map = qstring::QString::from(query.as_str());
......
...@@ -2,7 +2,7 @@ use anyhow::{Context, Result}; ...@@ -2,7 +2,7 @@ use anyhow::{Context, Result};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
FxIndexMap, FxIndexSet, NonLocalValue, Value, Vc, fxindexset, trace::TraceRawVcs, FxIndexMap, FxIndexSet, NonLocalValue, TaskInput, Vc, fxindexset, trace::TraceRawVcs,
}; };
use super::request::{NextFontRequest, OneOrManyStrings}; use super::request::{NextFontRequest, OneOrManyStrings};
...@@ -11,8 +11,8 @@ const ALLOWED_DISPLAY_VALUES: &[&str] = &["auto", "block", "swap", "fallback", " ...@@ -11,8 +11,8 @@ const ALLOWED_DISPLAY_VALUES: &[&str] = &["auto", "block", "swap", "fallback", "
pub(super) type FontData = FxIndexMap<RcStr, FontDataEntry>; pub(super) type FontData = FxIndexMap<RcStr, FontDataEntry>;
#[turbo_tasks::value(serialization = "auto_for_input")] #[turbo_tasks::value]
#[derive(Clone, Debug, PartialOrd, Ord, Hash)] #[derive(Clone, Debug, PartialOrd, Ord, Hash, TaskInput)]
pub(super) struct NextFontGoogleOptions { pub(super) struct NextFontGoogleOptions {
/// Name of the requested font from Google. Contains literal spaces. /// Name of the requested font from Google. Contains literal spaces.
pub font_family: RcStr, pub font_family: RcStr,
...@@ -38,8 +38,8 @@ impl NextFontGoogleOptions { ...@@ -38,8 +38,8 @@ impl NextFontGoogleOptions {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl NextFontGoogleOptions { impl NextFontGoogleOptions {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(options: Value<NextFontGoogleOptions>) -> Vc<NextFontGoogleOptions> { pub fn new(options: NextFontGoogleOptions) -> Vc<NextFontGoogleOptions> {
Self::cell(options.into_value()) Self::cell(options)
} }
} }
...@@ -55,6 +55,7 @@ impl NextFontGoogleOptions { ...@@ -55,6 +55,7 @@ impl NextFontGoogleOptions {
Deserialize, Deserialize,
TraceRawVcs, TraceRawVcs,
NonLocalValue, NonLocalValue,
TaskInput,
)] )]
pub(super) enum FontWeights { pub(super) enum FontWeights {
Variable, Variable,
......
...@@ -3,7 +3,7 @@ use font_fallback::FontFallbackResult; ...@@ -3,7 +3,7 @@ use font_fallback::FontFallbackResult;
use indoc::formatdoc; use indoc::formatdoc;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, Value, Vc}; use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::{ use turbo_tasks_fs::{
FileContent, FileSystemPath, glob::Glob, json::parse_json_with_source_context, FileContent, FileSystemPath, glob::Glob, json::parse_json_with_source_context,
}; };
...@@ -226,7 +226,7 @@ impl BeforeResolvePlugin for NextFontLocalResolvePlugin { ...@@ -226,7 +226,7 @@ impl BeforeResolvePlugin for NextFontLocalResolvePlugin {
path, path,
preload, preload,
has_size_adjust: size_adjust, has_size_adjust: size_adjust,
} = font_file_options_from_query_map(query).await?; } = font_file_options_from_query_map(query)?;
let (filename, ext) = split_extension(&path); let (filename, ext) = split_extension(&path);
let ext = ext.with_context(|| format!("font {} needs an extension", &path))?; let ext = ext.with_context(|| format!("font {} needs an extension", &path))?;
...@@ -303,11 +303,10 @@ fn font_options_from_query_map(query: RcStr) -> Result<Vc<NextFontLocalOptions>> ...@@ -303,11 +303,10 @@ fn font_options_from_query_map(query: RcStr) -> Result<Vc<NextFontLocalOptions>>
bail!("Expected one entry"); bail!("Expected one entry");
}; };
options_from_request(&parse_json_with_source_context(&json)?) options_from_request(&parse_json_with_source_context(&json)?).map(NextFontLocalOptions::new)
.map(|o| NextFontLocalOptions::new(Value::new(o)))
} }
async fn font_file_options_from_query_map(query: &RcStr) -> Result<NextFontLocalFontFileOptions> { fn font_file_options_from_query_map(query: &RcStr) -> Result<NextFontLocalFontFileOptions> {
let query_map = qstring::QString::from(query.as_str()); let query_map = qstring::QString::from(query.as_str());
if query_map.len() != 1 { if query_map.len() != 1 {
......
...@@ -3,7 +3,7 @@ use std::{fmt::Display, str::FromStr}; ...@@ -3,7 +3,7 @@ use std::{fmt::Display, str::FromStr};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{NonLocalValue, Value, Vc, trace::TraceRawVcs}; use turbo_tasks::{NonLocalValue, TaskInput, Vc, trace::TraceRawVcs};
use super::request::{ use super::request::{
AdjustFontFallback, NextFontLocalRequest, NextFontLocalRequestArguments, SrcDescriptor, AdjustFontFallback, NextFontLocalRequest, NextFontLocalRequestArguments, SrcDescriptor,
...@@ -12,8 +12,8 @@ use super::request::{ ...@@ -12,8 +12,8 @@ use super::request::{
/// A normalized, Vc-friendly struct derived from validating and transforming /// A normalized, Vc-friendly struct derived from validating and transforming
/// [[NextFontLocalRequest]] /// [[NextFontLocalRequest]]
#[turbo_tasks::value(serialization = "auto_for_input")] #[turbo_tasks::value]
#[derive(Clone, Debug, PartialOrd, Ord, Hash)] #[derive(Clone, Debug, PartialOrd, Ord, Hash, TaskInput)]
pub(super) struct NextFontLocalOptions { pub(super) struct NextFontLocalOptions {
pub fonts: FontDescriptors, pub fonts: FontDescriptors,
pub default_weight: Option<FontWeight>, pub default_weight: Option<FontWeight>,
...@@ -43,8 +43,8 @@ impl NextFontLocalOptions { ...@@ -43,8 +43,8 @@ impl NextFontLocalOptions {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl NextFontLocalOptions { impl NextFontLocalOptions {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(options: Value<NextFontLocalOptions>) -> Vc<NextFontLocalOptions> { pub fn new(options: NextFontLocalOptions) -> Vc<NextFontLocalOptions> {
Self::cell(options.into_value()) Self::cell(options)
} }
} }
...@@ -62,6 +62,7 @@ impl NextFontLocalOptions { ...@@ -62,6 +62,7 @@ impl NextFontLocalOptions {
Serialize, Serialize,
TraceRawVcs, TraceRawVcs,
NonLocalValue, NonLocalValue,
TaskInput,
)] )]
pub(super) struct FontDescriptor { pub(super) struct FontDescriptor {
pub weight: Option<FontWeight>, pub weight: Option<FontWeight>,
...@@ -103,6 +104,7 @@ impl FontDescriptor { ...@@ -103,6 +104,7 @@ impl FontDescriptor {
Serialize, Serialize,
TraceRawVcs, TraceRawVcs,
NonLocalValue, NonLocalValue,
TaskInput,
)] )]
pub(super) enum FontDescriptors { pub(super) enum FontDescriptors {
/// `One` is a special case when the user did not provide a `src` field and /// `One` is a special case when the user did not provide a `src` field and
...@@ -125,6 +127,7 @@ pub(super) enum FontDescriptors { ...@@ -125,6 +127,7 @@ pub(super) enum FontDescriptors {
Hash, Hash,
TraceRawVcs, TraceRawVcs,
NonLocalValue, NonLocalValue,
TaskInput,
)] )]
pub(super) enum FontWeight { pub(super) enum FontWeight {
Variable(RcStr, RcStr), Variable(RcStr, RcStr),
......
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{NonLocalValue, trace::TraceRawVcs}; use turbo_tasks::{NonLocalValue, TaskInput, trace::TraceRawVcs};
/// The top-most structure encoded into the query param in requests to /// The top-most structure encoded into the query param in requests to
/// `next/font/local` generated by the next/font swc transform. e.g. /// `next/font/local` generated by the next/font swc transform. e.g.
...@@ -58,6 +58,7 @@ pub(super) struct SrcDescriptor { ...@@ -58,6 +58,7 @@ pub(super) struct SrcDescriptor {
Serialize, Serialize,
TraceRawVcs, TraceRawVcs,
NonLocalValue, NonLocalValue,
TaskInput,
)] )]
pub(super) enum AdjustFontFallback { pub(super) enum AdjustFontFallback {
Arial, Arial,
......
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{ResolvedVc, TaskInput, Value, Vc, fxindexmap}; use turbo_tasks::{ResolvedVc, TaskInput, Vc, fxindexmap};
use turbopack::{ModuleAssetContext, module_options::CustomModuleType}; use turbopack::{ModuleAssetContext, module_options::CustomModuleType};
use turbopack_core::{ use turbopack_core::{
context::AssetContext, module::Module, reference_type::ReferenceType, resolve::ModulePart, context::AssetContext, module::Module, reference_type::ReferenceType, resolve::ModulePart,
...@@ -58,9 +58,9 @@ impl StructuredImageModuleType { ...@@ -58,9 +58,9 @@ impl StructuredImageModuleType {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(blur_placeholder_mode: Value<BlurPlaceholderMode>) -> Vc<Self> { pub fn new(blur_placeholder_mode: BlurPlaceholderMode) -> Vc<Self> {
StructuredImageModuleType::cell(StructuredImageModuleType { StructuredImageModuleType::cell(StructuredImageModuleType {
blur_placeholder_mode: blur_placeholder_mode.into_value(), blur_placeholder_mode,
}) })
} }
} }
......
...@@ -33,7 +33,7 @@ pub use next_lint::get_next_lint_transform_rule; ...@@ -33,7 +33,7 @@ pub use next_lint::get_next_lint_transform_rule;
pub use next_strip_page_exports::get_next_pages_transforms_rule; pub use next_strip_page_exports::get_next_pages_transforms_rule;
pub use next_track_dynamic_imports::get_next_track_dynamic_imports_transform_rule; pub use next_track_dynamic_imports::get_next_track_dynamic_imports_transform_rule;
pub use server_actions::get_server_actions_transform_rule; pub use server_actions::get_server_actions_transform_rule;
use turbo_tasks::{ReadRef, ResolvedVc, Value}; use turbo_tasks::{ReadRef, ResolvedVc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect, ModuleType, RuleCondition}; use turbopack::module_options::{ModuleRule, ModuleRuleEffect, ModuleType, RuleCondition};
use turbopack_core::reference_type::{ReferenceType, UrlReferenceSubType}; use turbopack_core::reference_type::{ReferenceType, UrlReferenceSubType};
...@@ -67,7 +67,7 @@ pub async fn get_next_image_rule() -> Result<ModuleRule> { ...@@ -67,7 +67,7 @@ pub async fn get_next_image_rule() -> Result<ModuleRule> {
]), ]),
vec![ModuleRuleEffect::ModuleType(ModuleType::Custom( vec![ModuleRuleEffect::ModuleType(ModuleType::Custom(
ResolvedVc::upcast( ResolvedVc::upcast(
StructuredImageModuleType::new(Value::new(BlurPlaceholderMode::DataUrl)) StructuredImageModuleType::new(BlurPlaceholderMode::DataUrl)
.to_resolved() .to_resolved()
.await?, .await?,
), ),
......
use anyhow::Result; use anyhow::Result;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Value, ValueToString, Vc}; use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbopack_core::{ use turbopack_core::{
chunk::ChunkableModuleReference, chunk::ChunkableModuleReference,
reference::ModuleReference, reference::ModuleReference,
...@@ -37,7 +37,7 @@ impl ModuleReference for CssModuleComposeReference { ...@@ -37,7 +37,7 @@ impl ModuleReference for CssModuleComposeReference {
css_resolve( css_resolve(
*self.origin, *self.origin,
*self.request, *self.request,
Value::new(CssReferenceSubType::Compose), CssReferenceSubType::Compose,
// TODO: add real issue source, currently impossible because `CssClassName` doesn't // TODO: add real issue source, currently impossible because `CssClassName` doesn't
// contain the source span // contain the source span
// https://docs.rs/swc_css_modules/0.21.16/swc_css_modules/enum.CssClassName.html // https://docs.rs/swc_css_modules/0.21.16/swc_css_modules/enum.CssClassName.html
......
...@@ -5,7 +5,7 @@ use lightningcss::{ ...@@ -5,7 +5,7 @@ use lightningcss::{
traits::ToCss, traits::ToCss,
}; };
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Value, ValueToString, Vc}; use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbopack_core::{ use turbopack_core::{
chunk::{ChunkableModuleReference, ChunkingContext}, chunk::{ChunkableModuleReference, ChunkingContext},
issue::IssueSource, issue::IssueSource,
...@@ -138,7 +138,7 @@ impl ModuleReference for ImportAssetReference { ...@@ -138,7 +138,7 @@ impl ModuleReference for ImportAssetReference {
Ok(css_resolve( Ok(css_resolve(
*self.origin, *self.origin,
*self.request, *self.request,
Value::new(CssReferenceSubType::AtImport(import_context)), CssReferenceSubType::AtImport(import_context),
Some(self.issue_source.clone()), Some(self.issue_source.clone()),
)) ))
} }
......
...@@ -8,7 +8,7 @@ use lightningcss::{ ...@@ -8,7 +8,7 @@ use lightningcss::{
visitor::{Visit, Visitor}, visitor::{Visit, Visitor},
}; };
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Value, Vc}; use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
use turbopack_core::{ use turbopack_core::{
issue::IssueSource, issue::IssueSource,
reference::ModuleReference, reference::ModuleReference,
...@@ -177,14 +177,8 @@ impl Visitor<'_> for ModuleReferencesVisitor<'_> { ...@@ -177,14 +177,8 @@ impl Visitor<'_> for ModuleReferencesVisitor<'_> {
pub fn css_resolve( pub fn css_resolve(
origin: Vc<Box<dyn ResolveOrigin>>, origin: Vc<Box<dyn ResolveOrigin>>,
request: Vc<Request>, request: Vc<Request>,
ty: Value<CssReferenceSubType>, ty: CssReferenceSubType,
issue_source: Option<IssueSource>, issue_source: Option<IssueSource>,
) -> Vc<ModuleResolveResult> { ) -> Vc<ModuleResolveResult> {
url_resolve( url_resolve(origin, request, ReferenceType::Css(ty), issue_source, false)
origin,
request,
ReferenceType::Css(ty.into_value()),
issue_source,
false,
)
} }
...@@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize}; ...@@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
use tracing_subscriber::{Registry, layer::SubscriberExt, util::SubscriberInitExt}; use tracing_subscriber::{Registry, layer::SubscriberExt, util::SubscriberInitExt};
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
Completion, NonLocalValue, OperationVc, ResolvedVc, TurboTasks, Value, Vc, apply_effects, Completion, NonLocalValue, OperationVc, ResolvedVc, TaskInput, TurboTasks, Vc, apply_effects,
debug::ValueDebugFormat, fxindexmap, trace::TraceRawVcs, debug::ValueDebugFormat, fxindexmap, trace::TraceRawVcs,
}; };
use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage}; use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage};
...@@ -74,7 +74,7 @@ struct JsResult { ...@@ -74,7 +74,7 @@ struct JsResult {
} }
#[turbo_tasks::value] #[turbo_tasks::value]
#[derive(Copy, Clone, Debug, Hash)] #[derive(Copy, Clone, Debug, Hash, TaskInput)]
enum IssueSnapshotMode { enum IssueSnapshotMode {
Snapshots, Snapshots,
NoSnapshots, NoSnapshots,
...@@ -200,8 +200,7 @@ async fn run(resource: PathBuf, snapshot_mode: IssueSnapshotMode) -> Result<JsRe ...@@ -200,8 +200,7 @@ async fn run(resource: PathBuf, snapshot_mode: IssueSnapshotMode) -> Result<JsRe
)); ));
let result = tt let result = tt
.run_once(async move { .run_once(async move {
let emit_op = let emit_op = run_inner_operation(resource.to_str().unwrap().into(), snapshot_mode);
run_inner_operation(resource.to_str().unwrap().into(), Value::new(snapshot_mode));
let result = emit_op.read_strongly_consistent().owned().await?; let result = emit_op.read_strongly_consistent().owned().await?;
apply_effects(emit_op).await?; apply_effects(emit_op).await?;
...@@ -217,11 +216,11 @@ async fn run(resource: PathBuf, snapshot_mode: IssueSnapshotMode) -> Result<JsRe ...@@ -217,11 +216,11 @@ async fn run(resource: PathBuf, snapshot_mode: IssueSnapshotMode) -> Result<JsRe
#[turbo_tasks::function(operation)] #[turbo_tasks::function(operation)]
async fn run_inner_operation( async fn run_inner_operation(
resource: RcStr, resource: RcStr,
snapshot_mode: Value<IssueSnapshotMode>, snapshot_mode: IssueSnapshotMode,
) -> Result<Vc<JsResult>> { ) -> Result<Vc<JsResult>> {
let prepared_test = prepare_test(resource).to_resolved().await?; let prepared_test = prepare_test(resource).to_resolved().await?;
let run_result_op = run_test_operation(prepared_test); let run_result_op = run_test_operation(prepared_test);
if *snapshot_mode == IssueSnapshotMode::Snapshots { if snapshot_mode == IssueSnapshotMode::Snapshots {
snapshot_issues(*prepared_test, run_result_op).await?; snapshot_issues(*prepared_test, run_result_op).await?;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment