Skip to content

[turbopack] Remove uses of Value<..> instead make the payloads impl Taskinput #80142

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

Open
wants to merge 3 commits into
base: value_delenda_est_8
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl EcmascriptBrowserEvaluateChunk {
.await?,
);

Ok(AssetIdent::new(Value::new(ident)))
Ok(AssetIdent::new(ident))
}

#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl OutputAsset for EcmascriptDevChunkList {
// ident, because it must remain stable whenever a chunk is added or
// removed from the list.

let ident = AssetIdent::new(Value::new(ident));
let ident = AssetIdent::new(ident);
Ok(this
.chunking_context
.chunk_path(Some(Vc::upcast(self)), ident, rcstr!(".js")))
Expand Down
12 changes: 11 additions & 1 deletion turbopack/crates/turbopack-core/src/chunk/chunking_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,17 @@ pub struct EntryChunkGroupResult {
}

#[derive(
Default, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, TraceRawVcs, NonLocalValue,
Default,
Debug,
Clone,
PartialEq,
Eq,
Hash,
Serialize,
Deserialize,
TraceRawVcs,
NonLocalValue,
TaskInput,
)]
pub struct ChunkingConfig {
/// Try to avoid creating more than 1 chunk smaller than this size.
Expand Down
30 changes: 15 additions & 15 deletions turbopack/crates/turbopack-core/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use anyhow::Result;
use once_cell::sync::Lazy;
use regex::Regex;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Value, ValueToString, Vc};
use turbo_tasks::{ResolvedVc, TaskInput, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbo_tasks_hash::{DeterministicHash, Xxh3Hash64Hasher, encode_hex, hash_xxh3_hash64};

use crate::resolve::ModulePart;

#[turbo_tasks::value(serialization = "auto_for_input")]
#[derive(Clone, Debug, Hash)]
#[turbo_tasks::value]
#[derive(Clone, Debug, Hash, TaskInput)]
pub struct AssetIdent {
/// The primary path of the asset
pub path: ResolvedVc<FileSystemPath>,
Expand Down Expand Up @@ -118,7 +118,7 @@ impl ValueToString for AssetIdent {
#[turbo_tasks::value_impl]
impl AssetIdent {
#[turbo_tasks::function]
pub async fn new(ident: Value<AssetIdent>) -> Result<Vc<Self>> {
pub async fn new(ident: AssetIdent) -> Result<Vc<Self>> {
debug_assert!(
ident.query.is_empty() || ident.query.starts_with("?"),
"query should be empty or start with a `?`"
Expand All @@ -127,13 +127,13 @@ impl AssetIdent {
ident.fragment.is_empty() || ident.fragment.starts_with("#"),
"query should be empty or start with a `?`"
);
Ok(ident.into_value().cell())
Ok(ident.cell())
}

/// Creates an [AssetIdent] from a [Vc<FileSystemPath>]
#[turbo_tasks::function]
pub fn from_path(path: ResolvedVc<FileSystemPath>) -> Vc<Self> {
Self::new(Value::new(AssetIdent {
Self::new(AssetIdent {
path,
query: RcStr::default(),
fragment: RcStr::default(),
Expand All @@ -142,63 +142,63 @@ impl AssetIdent {
parts: Vec::new(),
layer: None,
content_type: None,
}))
})
}

#[turbo_tasks::function]
pub fn with_query(&self, query: RcStr) -> Vc<Self> {
let mut this = self.clone();
this.query = query;
Self::new(Value::new(this))
Self::new(this)
}

#[turbo_tasks::function]
pub fn with_fragment(&self, fragment: RcStr) -> Vc<Self> {
let mut this = self.clone();
this.fragment = fragment;
Self::new(Value::new(this))
Self::new(this)
}

#[turbo_tasks::function]
pub fn with_modifier(&self, modifier: RcStr) -> Vc<Self> {
let mut this = self.clone();
this.add_modifier(modifier);
Self::new(Value::new(this))
Self::new(this)
}

#[turbo_tasks::function]
pub fn with_part(&self, part: ModulePart) -> Vc<Self> {
let mut this = self.clone();
this.parts.push(part);
Self::new(Value::new(this))
Self::new(this)
}

#[turbo_tasks::function]
pub fn with_path(&self, path: ResolvedVc<FileSystemPath>) -> Vc<Self> {
let mut this = self.clone();
this.path = path;
Self::new(Value::new(this))
Self::new(this)
}

#[turbo_tasks::function]
pub fn with_layer(&self, layer: RcStr) -> Vc<Self> {
let mut this = self.clone();
this.layer = Some(layer);
Self::new(Value::new(this))
Self::new(this)
}

#[turbo_tasks::function]
pub fn with_content_type(&self, content_type: RcStr) -> Vc<Self> {
let mut this = self.clone();
this.content_type = Some(content_type);
Self::new(Value::new(this))
Self::new(this)
}

#[turbo_tasks::function]
pub async fn rename_as(&self, pattern: RcStr) -> Result<Vc<Self>> {
let mut this = self.clone();
this.rename_as_ref(&pattern).await?;
Ok(Self::new(Value::new(this)))
Ok(Self::new(this))
}

#[turbo_tasks::function]
Expand Down
19 changes: 9 additions & 10 deletions turbopack/crates/turbopack-core/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tracing::{Instrument, Level};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{
FxIndexMap, FxIndexSet, NonLocalValue, ReadRef, ResolvedVc, SliceMap, TaskInput,
TryJoinIterExt, Value, ValueToString, Vc, trace::TraceRawVcs,
TryJoinIterExt, ValueToString, Vc, trace::TraceRawVcs,
};
use turbo_tasks_fs::{
FileSystemEntryType, FileSystemPath, RealPathResult, util::normalize_request,
Expand Down Expand Up @@ -482,8 +482,8 @@ pub enum ResolveResultItem {
/// A primary factor is the actual request string, but there are
/// other factors like exports conditions that can affect resolting and become
/// part of the key (assuming the condition is unknown at compile time)
#[derive(Clone, Debug, Default, Hash)]
#[turbo_tasks::value(serialization = "auto_for_input")]
#[derive(Clone, Debug, Default, Hash, TaskInput)]
#[turbo_tasks::value]
pub struct RequestKey {
pub request: Option<RcStr>,
pub conditions: BTreeMap<String, bool>,
Expand Down Expand Up @@ -1016,9 +1016,8 @@ impl ResolveResult {
pub fn with_replaced_request_key(
&self,
old_request_key: RcStr,
request_key: Value<RequestKey>,
request_key: RequestKey,
) -> Result<Vc<Self>> {
let request_key = request_key.into_value();
let new_primary = self
.primary
.iter()
Expand Down Expand Up @@ -1323,13 +1322,13 @@ pub async fn find_context_file(
pub async fn find_context_file_or_package_key(
lookup_path: Vc<FileSystemPath>,
names: Vc<Vec<RcStr>>,
package_key: Value<RcStr>,
package_key: RcStr,
) -> Result<Vc<FindContextFileResult>> {
let mut refs = Vec::new();
let package_json_path = lookup_path.join(rcstr!("package.json"));
if let Some(package_json_path) = exists(package_json_path, &mut refs).await?
&& let Some(json) = &*read_package_json(*package_json_path).await?
&& json.get(&**package_key).is_some()
&& json.get(&*package_key).is_some()
{
return Ok(FindContextFileResult::Found(package_json_path, refs).into());
}
Expand Down Expand Up @@ -2440,7 +2439,7 @@ async fn apply_in_package(
.with_fragment(fragment.clone()),
options,
)
.with_replaced_request_key(value.into(), Value::new(request_key))
.with_replaced_request_key(value.into(), request_key)
.with_affecting_sources(refs.into_iter().map(|src| *src).collect()),
));
}
Expand Down Expand Up @@ -2597,7 +2596,7 @@ async fn resolve_module_request(

let module_result =
merge_results_with_affecting_sources(results, result.affecting_sources.clone())
.with_replaced_request_key(rcstr!("."), Value::new(RequestKey::new(module.into())));
.with_replaced_request_key(rcstr!("."), RequestKey::new(module.into()));

if options_value.prefer_relative {
let module_prefix: RcStr = format!("./{module}").into();
Expand All @@ -2612,7 +2611,7 @@ async fn resolve_module_request(
let relative_result =
Box::pin(resolve_internal_inline(lookup_path, *relative, options)).await?;
let relative_result = relative_result
.with_replaced_request_key(module_prefix, Value::new(RequestKey::new(module.into())));
.with_replaced_request_key(module_prefix, RequestKey::new(module.into()));

Ok(merge_results(vec![relative_result, module_result]))
} else {
Expand Down
5 changes: 2 additions & 3 deletions turbopack/crates/turbopack-css/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use anyhow::{Result, bail};
use swc_core::common::pass::Either;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{
FxIndexSet, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Value, ValueDefault, ValueToString,
Vc,
FxIndexSet, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, ValueDefault, ValueToString, Vc,
};
use turbo_tasks_fs::{
File, FileSystem, FileSystemPath,
Expand Down Expand Up @@ -201,7 +200,7 @@ impl CssChunk {
content_type: None,
};

Ok(AssetIdent::new(Value::new(ident)))
Ok(AssetIdent::new(ident))
}
}

Expand Down
14 changes: 12 additions & 2 deletions turbopack/crates/turbopack-ecmascript-runtime/src/runtime_type.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
use serde::{Deserialize, Serialize};
use turbo_tasks::{NonLocalValue, trace::TraceRawVcs};
use turbo_tasks::{NonLocalValue, TaskInput, trace::TraceRawVcs};

#[derive(
Serialize, Deserialize, Debug, Clone, Copy, Hash, PartialEq, Eq, TraceRawVcs, NonLocalValue,
Serialize,
Deserialize,
Debug,
Clone,
Copy,
Hash,
PartialEq,
Eq,
TraceRawVcs,
NonLocalValue,
TaskInput,
)]
pub enum RuntimeType {
Development,
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::fmt::Write;

use anyhow::Result;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Value, ValueToString, Vc};
use turbo_tasks::{ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::FileSystem;
use turbopack_core::{
chunk::{Chunk, ChunkItem, ChunkItems, ChunkingContext, ModuleIds},
Expand Down Expand Up @@ -120,7 +120,7 @@ impl Chunk for EcmascriptChunk {
content_type: None,
};

Ok(AssetIdent::new(Value::new(ident)))
Ok(AssetIdent::new(ident))
}

#[turbo_tasks::function]
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-ecmascript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ impl Module for EcmascriptModuleAsset {
}
ident.add_modifier(rcstr!("ecmascript"));
ident.layer = Some(self.asset_context.layer().owned().await?);
Ok(AssetIdent::new(Value::new(ident)))
Ok(AssetIdent::new(ident))
}

#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,8 @@ impl EcmascriptModuleFacadeModule {
#[turbo_tasks::value_impl]
impl Module for EcmascriptModuleFacadeModule {
#[turbo_tasks::function]
async fn ident(&self) -> Result<Vc<AssetIdent>> {
let inner = self.module.ident();

Ok(inner.with_part(self.ty.clone()))
fn ident(&self) -> Vc<AssetIdent> {
self.module.ident().with_part(self.ty.clone())
}

#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ impl EcmascriptModuleLocalsModule {
impl Module for EcmascriptModuleLocalsModule {
#[turbo_tasks::function]
fn ident(&self) -> Vc<AssetIdent> {
let inner = self.module.ident();

inner.with_part(ModulePart::locals())
self.module.ident().with_part(ModulePart::locals())
}

#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Value, Vc};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
use turbo_tasks_fs::glob::Glob;
use turbopack_core::{
asset::{Asset, AssetContent},
Expand Down Expand Up @@ -70,7 +70,7 @@ impl Module for SideEffectsModule {
);
}

Ok(AssetIdent::new(Value::new(ident)))
Ok(AssetIdent::new(ident))
}

#[turbo_tasks::function]
Expand Down
13 changes: 5 additions & 8 deletions turbopack/crates/turbopack-node/src/transforms/postcss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use indoc::formatdoc;
use serde::{Deserialize, Serialize};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{
Completion, Completions, NonLocalValue, ResolvedVc, TaskInput, TryFlatJoinIterExt, Value, Vc,
Completion, Completions, NonLocalValue, ResolvedVc, TaskInput, TryFlatJoinIterExt, Vc,
fxindexmap, trace::TraceRawVcs,
};
use turbo_tasks_bytes::stream::SingleValue;
Expand Down Expand Up @@ -420,12 +420,9 @@ async fn find_config_in_location(
location: PostCssConfigLocation,
source: Vc<Box<dyn Source>>,
) -> Result<Option<Vc<FileSystemPath>>> {
if let FindContextFileResult::Found(config_path, _) = *find_context_file_or_package_key(
project_path,
postcss_configs(),
Value::new(rcstr!("postcss")),
)
.await?
if let FindContextFileResult::Found(config_path, _) =
*find_context_file_or_package_key(project_path, postcss_configs(), rcstr!("postcss"))
.await?
{
return Ok(Some(*config_path));
}
Expand All @@ -434,7 +431,7 @@ async fn find_config_in_location(
&& let FindContextFileResult::Found(config_path, _) = *find_context_file_or_package_key(
source.ident().path().parent(),
postcss_configs(),
Value::new(rcstr!("postcss")),
rcstr!("postcss"),
)
.await?
{
Expand Down
Loading
Loading