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;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
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_env::{CommandLineProcessEnv, ProcessEnv};
use turbo_tasks_fetch::{HttpResponseBody, fetch};
......@@ -624,7 +624,7 @@ async fn font_options_from_query_map(
let options =
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> {
let query_map = qstring::QString::from(query.as_str());
......
......@@ -2,7 +2,7 @@ use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{
FxIndexMap, FxIndexSet, NonLocalValue, Value, Vc, fxindexset, trace::TraceRawVcs,
FxIndexMap, FxIndexSet, NonLocalValue, TaskInput, Vc, fxindexset, trace::TraceRawVcs,
};
use super::request::{NextFontRequest, OneOrManyStrings};
......@@ -11,8 +11,8 @@ const ALLOWED_DISPLAY_VALUES: &[&str] = &["auto", "block", "swap", "fallback", "
pub(super) type FontData = FxIndexMap<RcStr, FontDataEntry>;
#[turbo_tasks::value(serialization = "auto_for_input")]
#[derive(Clone, Debug, PartialOrd, Ord, Hash)]
#[turbo_tasks::value]
#[derive(Clone, Debug, PartialOrd, Ord, Hash, TaskInput)]
pub(super) struct NextFontGoogleOptions {
/// Name of the requested font from Google. Contains literal spaces.
pub font_family: RcStr,
......@@ -38,8 +38,8 @@ impl NextFontGoogleOptions {
#[turbo_tasks::value_impl]
impl NextFontGoogleOptions {
#[turbo_tasks::function]
pub fn new(options: Value<NextFontGoogleOptions>) -> Vc<NextFontGoogleOptions> {
Self::cell(options.into_value())
pub fn new(options: NextFontGoogleOptions) -> Vc<NextFontGoogleOptions> {
Self::cell(options)
}
}
......@@ -55,6 +55,7 @@ impl NextFontGoogleOptions {
Deserialize,
TraceRawVcs,
NonLocalValue,
TaskInput,
)]
pub(super) enum FontWeights {
Variable,
......
......@@ -3,7 +3,7 @@ use font_fallback::FontFallbackResult;
use indoc::formatdoc;
use serde::{Deserialize, Serialize};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, Value, Vc};
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::{
FileContent, FileSystemPath, glob::Glob, json::parse_json_with_source_context,
};
......@@ -226,7 +226,7 @@ impl BeforeResolvePlugin for NextFontLocalResolvePlugin {
path,
preload,
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 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>>
bail!("Expected one entry");
};
options_from_request(&parse_json_with_source_context(&json)?)
.map(|o| NextFontLocalOptions::new(Value::new(o)))
options_from_request(&parse_json_with_source_context(&json)?).map(NextFontLocalOptions::new)
}
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());
if query_map.len() != 1 {
......
......@@ -3,7 +3,7 @@ use std::{fmt::Display, str::FromStr};
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr;
use turbo_tasks::{NonLocalValue, Value, Vc, trace::TraceRawVcs};
use turbo_tasks::{NonLocalValue, TaskInput, Vc, trace::TraceRawVcs};
use super::request::{
AdjustFontFallback, NextFontLocalRequest, NextFontLocalRequestArguments, SrcDescriptor,
......@@ -12,8 +12,8 @@ use super::request::{
/// A normalized, Vc-friendly struct derived from validating and transforming
/// [[NextFontLocalRequest]]
#[turbo_tasks::value(serialization = "auto_for_input")]
#[derive(Clone, Debug, PartialOrd, Ord, Hash)]
#[turbo_tasks::value]
#[derive(Clone, Debug, PartialOrd, Ord, Hash, TaskInput)]
pub(super) struct NextFontLocalOptions {
pub fonts: FontDescriptors,
pub default_weight: Option<FontWeight>,
......@@ -43,8 +43,8 @@ impl NextFontLocalOptions {
#[turbo_tasks::value_impl]
impl NextFontLocalOptions {
#[turbo_tasks::function]
pub fn new(options: Value<NextFontLocalOptions>) -> Vc<NextFontLocalOptions> {
Self::cell(options.into_value())
pub fn new(options: NextFontLocalOptions) -> Vc<NextFontLocalOptions> {
Self::cell(options)
}
}
......@@ -62,6 +62,7 @@ impl NextFontLocalOptions {
Serialize,
TraceRawVcs,
NonLocalValue,
TaskInput,
)]
pub(super) struct FontDescriptor {
pub weight: Option<FontWeight>,
......@@ -103,6 +104,7 @@ impl FontDescriptor {
Serialize,
TraceRawVcs,
NonLocalValue,
TaskInput,
)]
pub(super) enum FontDescriptors {
/// `One` is a special case when the user did not provide a `src` field and
......@@ -125,6 +127,7 @@ pub(super) enum FontDescriptors {
Hash,
TraceRawVcs,
NonLocalValue,
TaskInput,
)]
pub(super) enum FontWeight {
Variable(RcStr, RcStr),
......
use serde::{Deserialize, Serialize};
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
/// `next/font/local` generated by the next/font swc transform. e.g.
......@@ -58,6 +58,7 @@ pub(super) struct SrcDescriptor {
Serialize,
TraceRawVcs,
NonLocalValue,
TaskInput,
)]
pub(super) enum AdjustFontFallback {
Arial,
......
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_core::{
context::AssetContext, module::Module, reference_type::ReferenceType, resolve::ModulePart,
......@@ -58,9 +58,9 @@ impl StructuredImageModuleType {
}
#[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 {
blur_placeholder_mode: blur_placeholder_mode.into_value(),
blur_placeholder_mode,
})
}
}
......
......@@ -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_track_dynamic_imports::get_next_track_dynamic_imports_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 turbopack::module_options::{ModuleRule, ModuleRuleEffect, ModuleType, RuleCondition};
use turbopack_core::reference_type::{ReferenceType, UrlReferenceSubType};
......@@ -67,7 +67,7 @@ pub async fn get_next_image_rule() -> Result<ModuleRule> {
]),
vec![ModuleRuleEffect::ModuleType(ModuleType::Custom(
ResolvedVc::upcast(
StructuredImageModuleType::new(Value::new(BlurPlaceholderMode::DataUrl))
StructuredImageModuleType::new(BlurPlaceholderMode::DataUrl)
.to_resolved()
.await?,
),
......
use anyhow::Result;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Value, ValueToString, Vc};
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbopack_core::{
chunk::ChunkableModuleReference,
reference::ModuleReference,
......@@ -37,7 +37,7 @@ impl ModuleReference for CssModuleComposeReference {
css_resolve(
*self.origin,
*self.request,
Value::new(CssReferenceSubType::Compose),
CssReferenceSubType::Compose,
// TODO: add real issue source, currently impossible because `CssClassName` doesn't
// contain the source span
// https://docs.rs/swc_css_modules/0.21.16/swc_css_modules/enum.CssClassName.html
......
......@@ -5,7 +5,7 @@ use lightningcss::{
traits::ToCss,
};
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Value, ValueToString, Vc};
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbopack_core::{
chunk::{ChunkableModuleReference, ChunkingContext},
issue::IssueSource,
......@@ -138,7 +138,7 @@ impl ModuleReference for ImportAssetReference {
Ok(css_resolve(
*self.origin,
*self.request,
Value::new(CssReferenceSubType::AtImport(import_context)),
CssReferenceSubType::AtImport(import_context),
Some(self.issue_source.clone()),
))
}
......
......@@ -8,7 +8,7 @@ use lightningcss::{
visitor::{Visit, Visitor},
};
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Value, Vc};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
use turbopack_core::{
issue::IssueSource,
reference::ModuleReference,
......@@ -177,14 +177,8 @@ impl Visitor<'_> for ModuleReferencesVisitor<'_> {
pub fn css_resolve(
origin: Vc<Box<dyn ResolveOrigin>>,
request: Vc<Request>,
ty: Value<CssReferenceSubType>,
ty: CssReferenceSubType,
issue_source: Option<IssueSource>,
) -> Vc<ModuleResolveResult> {
url_resolve(
origin,
request,
ReferenceType::Css(ty.into_value()),
issue_source,
false,
)
url_resolve(origin, request, ReferenceType::Css(ty), issue_source, false)
}
......@@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
use tracing_subscriber::{Registry, layer::SubscriberExt, util::SubscriberInitExt};
use turbo_rcstr::{RcStr, rcstr};
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,
};
use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage};
......@@ -74,7 +74,7 @@ struct JsResult {
}
#[turbo_tasks::value]
#[derive(Copy, Clone, Debug, Hash)]
#[derive(Copy, Clone, Debug, Hash, TaskInput)]
enum IssueSnapshotMode {
Snapshots,
NoSnapshots,
......@@ -200,8 +200,7 @@ async fn run(resource: PathBuf, snapshot_mode: IssueSnapshotMode) -> Result<JsRe
));
let result = tt
.run_once(async move {
let emit_op =
run_inner_operation(resource.to_str().unwrap().into(), Value::new(snapshot_mode));
let emit_op = run_inner_operation(resource.to_str().unwrap().into(), snapshot_mode);
let result = emit_op.read_strongly_consistent().owned().await?;
apply_effects(emit_op).await?;
......@@ -217,11 +216,11 @@ async fn run(resource: PathBuf, snapshot_mode: IssueSnapshotMode) -> Result<JsRe
#[turbo_tasks::function(operation)]
async fn run_inner_operation(
resource: RcStr,
snapshot_mode: Value<IssueSnapshotMode>,
snapshot_mode: IssueSnapshotMode,
) -> Result<Vc<JsResult>> {
let prepared_test = prepare_test(resource).to_resolved().await?;
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?;
}
......
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