Unverified Commit 5070ad0d authored by Matt Mastracci's avatar Matt Mastracci Committed by GitHub

[turbopack] Add #[derive(ValueToString)] and convert ~45 manual impls (#89788)

## What

Add a `#[derive(ValueToString)]` proc macro and convert ~45 manual `ValueToString` implementations across turbopack crates to use it (-660 lines of boilerplate, 49 files touched).

## Why

Nearly every `ValueToString` impl follows the same pattern: format some fields into a string, possibly awaiting `Vc` values first. These hand-written impls are noisy boilerplate that obscure the actual format string.

## How

The derive macro generates the `#[turbo_tasks::value_impl] impl ValueToString` block automatically. A helper trait `ValueToStringify` with a blanket impl for `Display` and specializations for `Vc<T>`/`ResolvedVc<T>` handles async resolution of fields.

### Supported forms

- **No attribute** — delegates to `Display::to_string(&self)`
- `#[value_to_string("constant")]` — emits `rcstr!` directly
- `#[value_to_string("{field} text {other_field}")]` — auto-resolves named/positional fields via `ValueToStringify`
- `#[value_to_string("fmt {}", expr1, expr2)]` — explicit expressions as format args
- `#[value_to_string(expr)]` — single expression delegation

Enums support per-variant attributes (defaulting to variant name) or a single top-level attribute.
parent 02f2183d
......@@ -9580,6 +9580,7 @@ name = "turbo-tasks-macros"
version = "0.1.0"
dependencies = [
"either",
"indexmap 2.9.0",
"proc-macro-error",
"proc-macro2",
"quote",
......
use std::io::Write;
use anyhow::Result;
use turbo_rcstr::{RcStr, rcstr};
use turbo_rcstr::rcstr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{FileSystem, VirtualFileSystem, rope::RopeBuilder};
use turbopack_core::{
......@@ -143,6 +143,8 @@ impl EcmascriptChunkPlaceable for HmrEntryModule {
impl EvaluatableAsset for HmrEntryModule {}
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string("entry")]
pub struct HmrEntryModuleReference {
pub module: ResolvedVc<Box<dyn Module>>,
}
......@@ -155,14 +157,6 @@ impl HmrEntryModuleReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for HmrEntryModuleReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("entry"))
}
}
#[turbo_tasks::value_impl]
impl ModuleReference for HmrEntryModuleReference {
#[turbo_tasks::function]
......
use anyhow::Result;
use turbo_rcstr::{RcStr, rcstr};
use turbo_rcstr::rcstr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::FileContent;
use turbopack_core::{
......@@ -78,6 +78,8 @@ impl Asset for CssClientReferenceModule {
}
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string("css client reference to client")]
pub(crate) struct CssClientReference {
module: ResolvedVc<Box<dyn Module>>,
}
......@@ -105,11 +107,3 @@ impl ModuleReference for CssClientReference {
}))
}
}
#[turbo_tasks::value_impl]
impl ValueToString for CssClientReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("css client reference to client"))
}
}
......@@ -350,6 +350,8 @@ impl EcmascriptChunkItem for EcmascriptClientReferenceProxyChunkItem {
}
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string(self.description)]
pub(crate) struct EcmascriptClientReference {
module: ResolvedVc<Box<dyn Module>>,
ty: ChunkGroupType,
......@@ -390,11 +392,3 @@ impl ModuleReference for EcmascriptClientReference {
}))
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EcmascriptClientReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(self.description.clone())
}
}
use anyhow::Result;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbopack_core::{
chunk::{ChunkingType, ChunkingTypeOption},
......@@ -9,6 +7,8 @@ use turbopack_core::{
};
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string("Next.js Server Component {}", self.asset.ident())]
pub struct NextServerComponentModuleReference {
asset: ResolvedVc<Box<dyn Module>>,
}
......@@ -21,20 +21,6 @@ impl NextServerComponentModuleReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for NextServerComponentModuleReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!(
"Next.js Server Component {}",
self.asset.ident().to_string().await?
)
.into(),
))
}
}
#[turbo_tasks::value_impl]
impl ModuleReference for NextServerComponentModuleReference {
#[turbo_tasks::function]
......
use anyhow::Result;
use once_cell::sync::Lazy;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
......@@ -10,6 +9,8 @@ use turbopack_core::{
};
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string("Next.js server utility {}", self.asset.ident())]
pub struct NextServerUtilityModuleReference {
asset: ResolvedVc<Box<dyn Module>>,
}
......@@ -22,20 +23,6 @@ impl NextServerUtilityModuleReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for NextServerUtilityModuleReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!(
"Next.js server utility {}",
self.asset.ident().to_string().await?
)
.into(),
))
}
}
pub static NEXT_SERVER_UTILITY_MERGE_TAG: Lazy<RcStr> = Lazy::new(|| rcstr!("next-server-utility"));
#[turbo_tasks::value_impl]
......
#![feature(arbitrary_self_types)]
#![feature(arbitrary_self_types_pointers)]
#![allow(clippy::needless_return)] // tokio macro-generated code doesn't respect this
use std::fmt;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_testing::{Registration, register, run_once};
static REGISTRATION: Registration = register!();
// --- Test types ---
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
struct SimpleDisplay(u32);
impl fmt::Display for SimpleDisplay {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "simple:{}", self.0)
}
}
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("item {name} (count: {count})")]
struct NamedFields {
name: RcStr,
count: u32,
}
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("wrapped({0})")]
struct TupleStruct(u32);
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("constant-value")]
struct ConstantString;
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string(self.name)]
struct DirectExpr {
name: RcStr,
#[allow(dead_code)]
other: u32,
}
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("prefix({name}) suffix({count})")]
struct FormatExprs {
name: RcStr,
count: u32,
}
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("inner: {inner}")]
struct VcExprDelegate {
inner: ResolvedVc<NamedFields>,
}
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
enum Kind {
#[value_to_string("module")]
Module,
#[value_to_string("asset({0})")]
Asset(RcStr),
#[value_to_string("entry {name}")]
Entry { name: RcStr },
}
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
enum DefaultNames {
Alpha,
Beta,
}
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
enum MixedEnum {
#[value_to_string("literal")]
Literal,
#[value_to_string(_0)]
Delegate(ResolvedVc<ConstantString>),
#[value_to_string("wrapped({})", name)]
ExprNamed { name: RcStr },
}
// --- Tests ---
/// No attribute: delegates to Display::to_string(self).
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_display_delegation() {
run_once(&REGISTRATION, || async {
let v: Vc<SimpleDisplay> = SimpleDisplay(42).cell();
assert_eq!(&*v.to_string().await?, "simple:42");
anyhow::Ok(())
})
.await
.unwrap()
}
/// FormatAutoFields on structs: named fields, positional fields, and constant strings.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_struct_format_strings() {
run_once(&REGISTRATION, || async {
let v1: Vc<NamedFields> = NamedFields {
name: "foo".into(),
count: 7,
}
.cell();
assert_eq!(&*v1.to_string().await?, "item foo (count: 7)");
let v2: Vc<TupleStruct> = TupleStruct(99).cell();
assert_eq!(&*v2.to_string().await?, "wrapped(99)");
let v3: Vc<ConstantString> = ConstantString.cell();
assert_eq!(&*v3.to_string().await?, "constant-value");
anyhow::Ok(())
})
.await
.unwrap()
}
/// DirectExpr form: single expression delegation.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_struct_direct_expr() {
run_once(&REGISTRATION, || async {
let v: Vc<DirectExpr> = DirectExpr {
name: "hello".into(),
other: 42,
}
.cell();
assert_eq!(&*v.to_string().await?, "hello");
anyhow::Ok(())
})
.await
.unwrap()
}
/// FormatExprs on structs: format string with explicit expressions, including Vc delegation.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_struct_format_exprs() {
run_once(&REGISTRATION, || async {
let v1: Vc<FormatExprs> = FormatExprs {
name: "test".into(),
count: 5,
}
.cell();
assert_eq!(&*v1.to_string().await?, "prefix(test) suffix(5)");
let inner = NamedFields {
name: "bar".into(),
count: 3,
}
.resolved_cell();
let v2: Vc<VcExprDelegate> = VcExprDelegate { inner }.cell();
assert_eq!(&*v2.to_string().await?, "inner: item bar (count: 3)");
anyhow::Ok(())
})
.await
.unwrap()
}
/// Enum with per-variant auto-field format strings and default variant names.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_enum_variants() {
run_once(&REGISTRATION, || async {
// Per-variant attributes
assert_eq!(&*Kind::Module.cell().to_string().await?, "module");
assert_eq!(
&*Kind::Asset("main.js".into()).cell().to_string().await?,
"asset(main.js)"
);
assert_eq!(
&*(Kind::Entry {
name: "index".into()
})
.cell()
.to_string()
.await?,
"entry index"
);
// Default variant names (no attribute)
assert_eq!(&*DefaultNames::Alpha.cell().to_string().await?, "Alpha");
assert_eq!(&*DefaultNames::Beta.cell().to_string().await?, "Beta");
anyhow::Ok(())
})
.await
.unwrap()
}
/// Enum with mixed forms: constant literal, Vc delegation, and format exprs.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_mixed_enum() {
run_once(&REGISTRATION, || async {
assert_eq!(&*MixedEnum::Literal.cell().to_string().await?, "literal");
let inner = ConstantString.resolved_cell();
let v2: Vc<MixedEnum> = MixedEnum::Delegate(inner).cell();
assert_eq!(&*v2.to_string().await?, "constant-value");
let v3: Vc<MixedEnum> = (MixedEnum::ExprNamed {
name: "world".into(),
})
.cell();
assert_eq!(&*v3.to_string().await?, "wrapped(world)");
anyhow::Ok(())
})
.await
.unwrap()
}
......@@ -8,6 +8,8 @@ use crate::{FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawD
/// "subdirectory" in the given root [FileSystem].
///
/// Caveat: The `child_path` itself is not visible as a directory entry.
#[derive(ValueToString)]
#[value_to_string("{root_fs}-with-{child_fs}")]
#[turbo_tasks::value]
pub struct AttachedFileSystem {
root_fs: ResolvedVc<Box<dyn FileSystem>>,
......@@ -141,15 +143,3 @@ impl FileSystem for AttachedFileSystem {
Ok(self.get_inner_fs_path(path).await?.metadata())
}
}
#[turbo_tasks::value_impl]
impl ValueToString for AttachedFileSystem {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
let root_fs_str = self.root_fs.to_string().await?;
let child_fs_str = self.child_fs.to_string().await?;
Ok(Vc::cell(
format!("{root_fs_str}-with-{child_fs_str}").into(),
))
}
}
......@@ -9,6 +9,8 @@ use crate::{
RawDirectoryEntry,
};
#[derive(ValueToString)]
#[value_to_string(self.name)]
#[turbo_tasks::value(serialization = "none", cell = "new", eq = "manual")]
pub struct EmbeddedFileSystem {
name: RcStr,
......@@ -88,11 +90,3 @@ impl FileSystem for EmbeddedFileSystem {
Ok(FileMeta::default().cell())
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EmbeddedFileSystem {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(self.name.clone())
}
}
......@@ -495,6 +495,8 @@ impl DiskFileSystemInner {
}
}
#[derive(ValueToString)]
#[value_to_string(self.inner.name)]
#[turbo_tasks::value(cell = "new", eq = "manual")]
pub struct DiskFileSystem {
inner: Arc<DiskFileSystemInner>,
......@@ -1289,16 +1291,9 @@ fn remove_symbolic_link_dir_helper(path: &Path) -> io::Result<()> {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for DiskFileSystem {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(self.inner.name.clone())
}
}
#[derive(Debug, Clone, Hash, TaskInput, ValueToString)]
#[value_to_string("[{fs}]/{path}")]
#[turbo_tasks::value(shared)]
#[derive(Debug, Clone, Hash, TaskInput)]
pub struct FileSystemPath {
pub fs: ResolvedVc<Box<dyn FileSystem>>,
pub path: RcStr,
......@@ -1764,14 +1759,6 @@ impl FileSystemPath {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for FileSystemPath {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
self.value_to_string()
}
}
#[derive(Clone, Debug)]
#[turbo_tasks::value(shared)]
pub struct RealPathResult {
......@@ -2538,6 +2525,8 @@ impl DirectoryContent {
}
}
#[derive(ValueToString)]
#[value_to_string("null")]
#[turbo_tasks::value(shared)]
pub struct NullFileSystem;
......@@ -2574,14 +2563,6 @@ impl FileSystem for NullFileSystem {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for NullFileSystem {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("null"))
}
}
pub async fn to_sys_path(mut path: FileSystemPath) -> Result<Option<PathBuf>> {
loop {
if let Some(fs) = ResolvedVc::try_downcast_type::<AttachedFileSystem>(path.fs) {
......
......@@ -4,6 +4,8 @@ use turbo_tasks::{ValueDefault, ValueToString, Vc};
use crate::{FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent};
#[derive(ValueToString)]
#[value_to_string(self.name)]
#[turbo_tasks::value]
pub struct VirtualFileSystem {
pub name: RcStr,
......@@ -75,11 +77,3 @@ impl FileSystem for VirtualFileSystem {
bail!("Reading is not possible on the virtual file system")
}
}
#[turbo_tasks::value_impl]
impl ValueToString for VirtualFileSystem {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(self.name.clone())
}
}
......@@ -14,6 +14,7 @@ workspace = true
[dependencies]
either = { workspace = true }
indexmap = { workspace = true }
proc-macro-error = "1.0.4"
proc-macro2 = { workspace = true }
quote = { workspace = true }
......
......@@ -6,6 +6,7 @@ mod task_storage_macro;
mod trace_raw_vcs_macro;
mod value_debug_format_macro;
mod value_debug_macro;
pub(crate) mod value_to_string_macro;
pub use deterministic_hash_macro::derive_deterministic_hash;
pub use non_local_value_macro::derive_non_local_value;
......
......@@ -57,6 +57,11 @@ pub fn derive_task_input(input: TokenStream) -> TokenStream {
derive::derive_task_input(input)
}
#[proc_macro_derive(ValueToString, attributes(value_to_string))]
pub fn derive_value_to_string(input: TokenStream) -> TokenStream {
derive::value_to_string_macro::derive_value_to_string(input)
}
/// <!--
/// Documentation for this macro is available on the re-export:
/// <https://turbopack-rust-docs.vercel.sh/rustdoc/turbo_tasks/attr.task_storage.html>
......
use std::{
fmt::{self, Display},
future::Future,
};
use anyhow::Result;
use turbo_rcstr::RcStr;
use turbo_tasks::Vc;
pub use turbo_tasks_macros::ValueToString;
use crate::{self as turbo_tasks};
use crate::{self as turbo_tasks, ReadRef, vc::ResolvedVc};
/// Converts a value to a string, like [`Display`], but returning `Vc<RcStr>`.
#[turbo_tasks::value_trait]
pub trait ValueToString {
#[turbo_tasks::function]
fn to_string(self: Vc<Self>) -> Vc<RcStr>;
}
/// A helper trait used by the `#[derive(ValueToString)]` macro.
///
/// Provides async string conversion with a blanket implementation for `Display`
/// types. `Vc<T>` and `ResolvedVc<T>` have specialized implementations that
/// await the inner value's `ValueToString` implementation.
///
/// Note that these methods are inlined and these function calls are only used for
/// effecient macro codegen.
#[doc(hidden)]
pub trait ValueToStringify {
fn to_stringify(&self) -> impl Future<Output = Result<StringifyType>> + Send;
}
/// Used only for macro codegen.
#[doc(hidden)]
pub enum StringifyType {
RcStr(ReadRef<RcStr>),
String(String),
}
impl AsRef<str> for StringifyType {
fn as_ref(&self) -> &str {
match self {
StringifyType::RcStr(s) => s.as_str(),
StringifyType::String(s) => s.as_str(),
}
}
}
impl Display for StringifyType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_ref())
}
}
impl From<StringifyType> for RcStr {
fn from(s: StringifyType) -> Self {
match s {
StringifyType::RcStr(r) => (*r).clone(),
StringifyType::String(s) => RcStr::from(s),
}
}
}
/// Blanket implementation for all `Display` types.
impl<T: Display + Send + Sync> ValueToStringify for T {
#[inline(always)]
fn to_stringify(&self) -> impl Future<Output = Result<StringifyType>> + Send {
let s = self.to_string();
async move { Ok(StringifyType::String(s)) }
}
}
/// Implementation for `Vc<T>` that awaits the turbo-tasks `ValueToString` result.
impl<T: Send> ValueToStringify for Vc<T>
where
T: ValueToString,
{
#[inline(always)]
fn to_stringify(&self) -> impl Future<Output = Result<StringifyType>> + Send {
let vc = *self;
async move {
let s = vc.to_string().await?;
Ok(StringifyType::RcStr(s))
}
}
}
/// Implementation for `ResolvedVc<T>` that delegates to the `Vc<T>` implementation.
impl<T: Send> ValueToStringify for ResolvedVc<T>
where
T: ValueToString,
{
#[inline(always)]
fn to_stringify(&self) -> impl Future<Output = Result<StringifyType>> + Send {
let vc = *self;
async move {
let s = vc.to_string().await?;
Ok(StringifyType::RcStr(s))
}
}
}
......@@ -45,7 +45,7 @@ mod capture_future;
mod collectibles;
mod completion;
pub mod debug;
mod display;
pub mod display;
pub mod duration_span;
mod effect;
mod error;
......
......@@ -17,6 +17,8 @@ use crate::{BrowserChunkingContext, ecmascript::content::EcmascriptBrowserChunkC
/// Development Ecmascript chunk.
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("Ecmascript Dev Chunk")]
pub struct EcmascriptBrowserChunk {
chunking_context: ResolvedVc<BrowserChunkingContext>,
chunk: ResolvedVc<EcmascriptChunk>,
......@@ -56,14 +58,6 @@ impl EcmascriptBrowserChunk {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EcmascriptBrowserChunk {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("Ecmascript Dev Chunk"))
}
}
#[turbo_tasks::value_impl]
impl OutputChunk for EcmascriptBrowserChunk {
#[turbo_tasks::function]
......
......@@ -4,7 +4,7 @@ use anyhow::{Result, bail};
use either::Either;
use indoc::writedoc;
use serde::Serialize;
use turbo_rcstr::{RcStr, rcstr};
use turbo_rcstr::rcstr;
use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::{File, FileContent, FileSystemPath};
use turbopack_core::{
......@@ -36,6 +36,8 @@ use crate::{
/// * Contains the Turbopack browser runtime code; and
/// * Evaluates a list of runtime entries.
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("Ecmascript Browser Evaluate Chunk")]
pub(crate) struct EcmascriptBrowserEvaluateChunk {
chunking_context: ResolvedVc<BrowserChunkingContext>,
ident: ResolvedVc<AssetIdent>,
......@@ -238,14 +240,6 @@ impl EcmascriptBrowserEvaluateChunk {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EcmascriptBrowserEvaluateChunk {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("Ecmascript Browser Evaluate Chunk"))
}
}
#[turbo_tasks::value_impl]
impl OutputAssetsReference for EcmascriptBrowserEvaluateChunk {
#[turbo_tasks::function]
......
use anyhow::Result;
use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
use turbo_rcstr::{RcStr, rcstr};
use turbo_rcstr::rcstr;
use turbo_tasks::{NonLocalValue, ResolvedVc, TaskInput, ValueToString, Vc, trace::TraceRawVcs};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
......@@ -27,6 +27,8 @@ use crate::BrowserChunkingContext;
/// * moving a module from one chunk to another;
/// * changing a chunk's path.
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("Ecmascript Dev Chunk List")]
pub(crate) struct EcmascriptDevChunkList {
pub(super) chunking_context: ResolvedVc<BrowserChunkingContext>,
pub(super) ident: ResolvedVc<AssetIdent>,
......@@ -62,14 +64,6 @@ impl EcmascriptDevChunkList {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EcmascriptDevChunkList {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("Ecmascript Dev Chunk List"))
}
}
#[turbo_tasks::value_impl]
impl OutputAssetsReference for EcmascriptDevChunkList {
#[turbo_tasks::function]
......
......@@ -21,6 +21,8 @@ use turbopack_ecmascript::minify::minify;
/// The worker receives a JSON array via URL params of the following structure:
/// `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...forwarded_global_values]`
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("Ecmascript Browser Worker Entrypoint")]
pub struct EcmascriptBrowserWorkerEntrypoint {
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
/// Global variable names to forward from main thread to worker.
......@@ -84,14 +86,6 @@ impl EcmascriptBrowserWorkerEntrypoint {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EcmascriptBrowserWorkerEntrypoint {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("Ecmascript Browser Worker Entrypoint"))
}
}
#[turbo_tasks::value_impl]
impl OutputAssetsReference for EcmascriptBrowserWorkerEntrypoint {
#[turbo_tasks::function]
......
......@@ -48,7 +48,7 @@ use crate::{
/// A module id, which can be a number or string
#[turbo_tasks::value(shared, operation)]
#[derive(Debug, Clone, Hash, Ord, PartialOrd, DeterministicHash, Serialize)]
#[derive(Debug, Clone, Hash, Ord, PartialOrd, DeterministicHash, Serialize, ValueToString)]
#[serde(untagged)]
pub enum ModuleId {
Number(u64),
......@@ -64,14 +64,6 @@ impl Display for ModuleId {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for ModuleId {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(self.to_string().into())
}
}
impl ModuleId {
pub fn parse(id: &str) -> Result<ModuleId> {
Ok(match id.parse::<u64>() {
......
......@@ -60,6 +60,8 @@ impl ModuleReferences {
/// A reference that always resolves to a single module.
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string(self.description)]
pub struct SingleModuleReference {
asset: ResolvedVc<Box<dyn Module>>,
description: RcStr,
......@@ -73,14 +75,6 @@ impl ModuleReference for SingleModuleReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for SingleModuleReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(self.description.clone())
}
}
#[turbo_tasks::value_impl]
impl SingleModuleReference {
/// Create a new [Vc<SingleModuleReference>] that resolves to the given
......@@ -98,6 +92,8 @@ impl SingleModuleReference {
}
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string(self.description)]
pub struct SingleChunkableModuleReference {
asset: ResolvedVc<Box<dyn Module>>,
description: RcStr,
......@@ -145,16 +141,10 @@ impl ModuleReference for SingleChunkableModuleReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for SingleChunkableModuleReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(self.description.clone())
}
}
/// A reference that always resolves to a single module.
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string(self.description)]
pub struct SingleOutputAssetReference {
asset: ResolvedVc<Box<dyn OutputAsset>>,
description: RcStr,
......@@ -168,14 +158,6 @@ impl ModuleReference for SingleOutputAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for SingleOutputAssetReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(self.description.clone())
}
}
#[turbo_tasks::value_impl]
impl SingleOutputAssetReference {
/// Create a new [Vc<SingleOutputAssetReference>] that resolves to the given
......@@ -230,6 +212,8 @@ pub async fn referenced_modules_and_affecting_sources(
}
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string("traced {}", self.module.ident())]
pub struct TracedModuleReference {
module: ResolvedVc<Box<dyn Module>>,
}
......@@ -247,16 +231,6 @@ impl ModuleReference for TracedModuleReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for TracedModuleReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("traced {}", self.module.ident().to_string().await?).into(),
))
}
}
#[turbo_tasks::value_impl]
impl TracedModuleReference {
#[turbo_tasks::function]
......
use anyhow::Result;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{File, FileContent, FileSystemEntryType, FileSystemPath};
......@@ -12,6 +11,8 @@ use crate::{
};
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string("source map file is referenced by {from}")]
pub struct SourceMapReference {
from: FileSystemPath,
file: FileSystemPath,
......@@ -69,17 +70,3 @@ impl GenerateSourceMap for SourceMapReference {
}
}
}
#[turbo_tasks::value_impl]
impl ValueToString for SourceMapReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!(
"source map file is referenced by {}",
self.from.value_to_string().await?
)
.into(),
))
}
}
......@@ -19,7 +19,8 @@ use turbo_tasks_fs::{
use turbo_unix_path::normalize_path;
#[turbo_tasks::value]
#[derive(Hash, Clone, Debug, Default)]
#[derive(Hash, Clone, Debug, Default, ValueToString)]
#[value_to_string(self.describe_as_string())]
pub enum Pattern {
Constant(RcStr),
#[default]
......@@ -1483,14 +1484,6 @@ impl Pattern {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for Pattern {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(self.describe_as_string().into())
}
}
#[derive(
Debug, PartialEq, Eq, Clone, TraceRawVcs, ValueDebugFormat, NonLocalValue, Encode, Decode,
)]
......
use anyhow::{Result, bail};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ValueToString, Vc};
use turbo_tasks_fs::{
FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent,
};
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string("root-of-the-server")]
pub struct ServerFileSystem {}
#[turbo_tasks::value_impl]
......@@ -48,11 +49,3 @@ impl FileSystem for ServerFileSystem {
bail!("Reading is not possible from the marker filesystem for the server")
}
}
#[turbo_tasks::value_impl]
impl ValueToString for ServerFileSystem {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("root-of-the-server"))
}
}
use std::fmt::Display;
use bincode::{Decode, Encode};
use turbo_tasks::{NonLocalValue, Vc, trace::TraceRawVcs};
use turbo_tasks::{NonLocalValue, ValueToString, Vc, trace::TraceRawVcs};
#[turbo_tasks::value(shared)]
#[derive(Hash, Debug, Copy, Clone)]
#[derive(Hash, Debug, Copy, Clone, ValueToString)]
pub struct CompileTarget {
/// <https://nodejs.org/api/os.html#osarch>
pub arch: Arch,
......
......@@ -522,18 +522,11 @@ impl Introspectable for CssChunk {
}
}
#[derive(Default)]
#[derive(Default, ValueToString)]
#[value_to_string("css")]
#[turbo_tasks::value]
pub struct CssChunkType {}
#[turbo_tasks::value_impl]
impl ValueToString for CssChunkType {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("css"))
}
}
#[turbo_tasks::value_impl]
impl ChunkType for CssChunkType {
#[turbo_tasks::function]
......
use anyhow::Result;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbopack_core::{
chunk::{ChunkingType, ChunkingTypeOption},
......@@ -12,7 +10,8 @@ use crate::references::css_resolve;
/// A `composes: ... from ...` CSS module reference.
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("compose(url) {request}")]
pub struct CssModuleComposeReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub request: ResolvedVc<Request>,
......@@ -51,13 +50,3 @@ impl ModuleReference for CssModuleComposeReference {
}))
}
}
#[turbo_tasks::value_impl]
impl ValueToString for CssModuleComposeReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("compose(url) {}", self.request.to_string().await?,).into(),
))
}
}
......@@ -6,7 +6,6 @@ use lightningcss::{
traits::ToCss,
values::string::CowArcStr,
};
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbopack_core::{
chunk::{ChunkingContext, ChunkingType, ChunkingTypeOption},
......@@ -80,7 +79,8 @@ impl ImportAttributes {
}
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("import(url) {request}")]
pub struct ImportAssetReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub request: ResolvedVc<Request>,
......@@ -151,16 +151,6 @@ impl ModuleReference for ImportAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for ImportAssetReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("import(url) {}", self.request.to_string().await?,).into(),
))
}
}
#[turbo_tasks::value_impl]
impl CodeGenerateable for ImportAssetReference {
#[turbo_tasks::function]
......
use anyhow::Result;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbopack_core::{
chunk::{ChunkingType, ChunkingTypeOption},
......@@ -10,7 +8,8 @@ use turbopack_core::{
/// A reference to an internal CSS asset.
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("internal css {}", self.module.ident())]
pub struct InternalCssAssetReference {
module: ResolvedVc<Box<dyn Module>>,
}
......@@ -39,13 +38,3 @@ impl ModuleReference for InternalCssAssetReference {
}))
}
}
#[turbo_tasks::value_impl]
impl ValueToString for InternalCssAssetReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("internal css {}", self.module.ident().to_string().await?).into(),
))
}
}
......@@ -30,7 +30,8 @@ pub enum ReferencedAsset {
}
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("url {request}")]
pub struct UrlAssetReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub request: ResolvedVc<Request>,
......@@ -94,16 +95,6 @@ impl ModuleReference for UrlAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for UrlAssetReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("url {}", self.request.to_string().await?,).into(),
))
}
}
#[turbo_tasks::function]
pub async fn resolve_url_reference(
url: Vc<UrlAssetReference>,
......
use anyhow::{Result, bail};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueDefault, ValueToString, Vc};
use turbopack_core::chunk::{
AsyncModuleInfo, Chunk, ChunkItem, ChunkItemBatchGroup, ChunkItemOrBatchWithAsyncModuleInfo,
......@@ -10,17 +9,10 @@ use super::{EcmascriptChunk, EcmascriptChunkContent, EcmascriptChunkItem};
use crate::chunk::batch::{EcmascriptChunkItemBatchGroup, EcmascriptChunkItemOrBatchWithAsyncInfo};
#[turbo_tasks::value]
#[derive(Default)]
#[derive(Default, ValueToString)]
#[value_to_string("ecmascript")]
pub struct EcmascriptChunkType {}
#[turbo_tasks::value_impl]
impl ValueToString for EcmascriptChunkType {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("ecmascript"))
}
}
#[turbo_tasks::value_impl]
impl ChunkType for EcmascriptChunkType {
#[turbo_tasks::function]
......
......@@ -175,16 +175,6 @@ impl Chunk for EcmascriptChunk {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EcmascriptChunk {
#[turbo_tasks::function]
async fn to_string(self: Vc<Self>) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("chunk {}", self.ident().to_string().await?).into(),
))
}
}
#[turbo_tasks::value_impl]
impl EcmascriptChunk {
#[turbo_tasks::function]
......
......@@ -10,7 +10,6 @@ use swc_core::{
},
quote, quote_expr,
};
use turbo_rcstr::RcStr;
use turbo_tasks::{
NonLocalValue, ReadRef, ResolvedVc, TryJoinIterExt, ValueToString, Vc, debug::ValueDebugFormat,
trace::TraceRawVcs,
......@@ -35,7 +34,8 @@ use crate::{
};
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("AMD define dependency {request}")]
pub struct AmdDefineAssetReference {
origin: ResolvedVc<Box<dyn ResolveOrigin>>,
request: ResolvedVc<Request>,
......@@ -83,16 +83,6 @@ impl ModuleReference for AmdDefineAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for AmdDefineAssetReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("AMD define dependency {}", self.request.to_string().await?,).into(),
))
}
}
#[derive(
ValueDebugFormat, Debug, PartialEq, Eq, TraceRawVcs, Clone, NonLocalValue, Hash, Encode, Decode,
)]
......
......@@ -5,7 +5,6 @@ use swc_core::{
ecma::ast::{CallExpr, Expr, ExprOrSpread, Lit},
quote,
};
use turbo_rcstr::RcStr;
use turbo_tasks::{
NonLocalValue, ResolvedVc, ValueToString, Vc, debug::ValueDebugFormat, trace::TraceRawVcs,
};
......@@ -29,7 +28,8 @@ use crate::{
};
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("generic commonjs {request}")]
pub struct CjsAssetReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub request: ResolvedVc<Request>,
......@@ -77,18 +77,9 @@ impl ModuleReference for CjsAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for CjsAssetReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("generic commonjs {}", self.request.to_string().await?,).into(),
))
}
}
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("require {request}")]
pub struct CjsRequireAssetReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub request: ResolvedVc<Request>,
......@@ -134,16 +125,6 @@ impl ModuleReference for CjsRequireAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for CjsRequireAssetReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("require {}", self.request.to_string().await?,).into(),
))
}
}
impl IntoCodeGenReference for CjsRequireAssetReference {
fn into_code_gen_reference(
self,
......@@ -220,7 +201,8 @@ impl CjsRequireAssetReferenceCodeGen {
}
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("require.resolve {request}")]
pub struct CjsRequireResolveAssetReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub request: ResolvedVc<Request>,
......@@ -266,16 +248,6 @@ impl ModuleReference for CjsRequireResolveAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for CjsRequireResolveAssetReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("require.resolve {}", self.request.to_string().await?,).into(),
))
}
}
impl IntoCodeGenReference for CjsRequireResolveAssetReference {
fn into_code_gen_reference(
self,
......
......@@ -318,7 +318,8 @@ impl EsmAssetReferences {
}
#[turbo_tasks::value(shared)]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("import {request} with {annotations}")]
pub struct EsmAssetReference {
pub module: ResolvedVc<EcmascriptModuleAsset>,
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
......@@ -512,14 +513,6 @@ impl ModuleReference for EsmAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EsmAssetReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(format!("import {} with {}", self.request, self.annotations).into())
}
}
impl EsmAssetReference {
pub async fn code_generation(
self: ResolvedVc<Self>,
......
......@@ -5,7 +5,6 @@ use swc_core::{
ecma::ast::{CallExpr, Callee, Expr, ExprOrSpread, Lit},
quote_expr,
};
use turbo_rcstr::RcStr;
use turbo_tasks::{
NonLocalValue, ResolvedVc, ValueToString, Vc, debug::ValueDebugFormat, trace::TraceRawVcs,
};
......@@ -34,7 +33,8 @@ use crate::{
};
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("dynamic import {request}")]
pub struct EsmAsyncAssetReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub request: ResolvedVc<Request>,
......@@ -94,16 +94,6 @@ impl ModuleReference for EsmAsyncAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EsmAsyncAssetReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("dynamic import {}", self.request.to_string().await?,).into(),
))
}
}
impl IntoCodeGenReference for EsmAsyncAssetReference {
fn into_code_gen_reference(
self,
......
use anyhow::Result;
use bincode::{Decode, Encode};
use swc_core::quote;
use turbo_rcstr::RcStr;
use turbo_tasks::{
NonLocalValue, ResolvedVc, ValueToString, Vc, debug::ValueDebugFormat, trace::TraceRawVcs,
};
......@@ -22,7 +21,8 @@ use crate::{
};
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("module id of {inner}")]
pub struct EsmModuleIdAssetReference {
inner: ResolvedVc<EsmAssetReference>,
}
......@@ -46,16 +46,6 @@ impl ModuleReference for EsmModuleIdAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EsmModuleIdAssetReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("module id of {}", self.inner.to_string().await?,).into(),
))
}
}
impl IntoCodeGenReference for EsmModuleIdAssetReference {
fn into_code_gen_reference(
self,
......
......@@ -4,7 +4,6 @@ use swc_core::{
ecma::ast::{Expr, ExprOrSpread, NewExpr},
quote,
};
use turbo_rcstr::RcStr;
use turbo_tasks::{
NonLocalValue, ResolvedVc, TaskInput, ValueToString, Vc, debug::ValueDebugFormat,
trace::TraceRawVcs,
......@@ -52,6 +51,8 @@ pub enum UrlRewriteBehavior {
/// It's responsible rewriting the `URL` constructor's arguments to allow the
/// referenced file to be imported/fetched/etc.
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string("new URL({request})")]
pub struct UrlAssetReference {
origin: ResolvedVc<Box<dyn ResolveOrigin>>,
request: ResolvedVc<Request>,
......@@ -107,16 +108,6 @@ impl ModuleReference for UrlAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for UrlAssetReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("new URL({})", self.request.to_string().await?,).into(),
))
}
}
impl IntoCodeGenReference for UrlAssetReference {
fn into_code_gen_reference(
self,
......
use anyhow::Result;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
......@@ -8,7 +7,8 @@ use turbopack_core::{
};
#[turbo_tasks::value]
#[derive(Hash, Clone, Debug)]
#[derive(Hash, Clone, Debug, ValueToString)]
#[value_to_string("package.json {package_json}")]
pub struct PackageJsonReference {
pub package_json: FileSystemPath,
}
......@@ -32,17 +32,3 @@ impl ModuleReference for PackageJsonReference {
)))
}
}
#[turbo_tasks::value_impl]
impl ValueToString for PackageJsonReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!(
"package.json {}",
self.package_json.value_to_string().await?
)
.into(),
))
}
}
use anyhow::{Result, bail};
use tracing::Instrument;
use turbo_rcstr::{RcStr, rcstr};
use turbo_rcstr::rcstr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
......@@ -19,7 +19,8 @@ use turbopack_core::{
use crate::references::util::check_and_emit_too_many_matches_warning;
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("raw asset {path}")]
pub struct FileSourceReference {
context_dir: FileSystemPath,
path: ResolvedVc<Pattern>,
......@@ -83,18 +84,9 @@ impl ModuleReference for FileSourceReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for FileSourceReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("raw asset {}", self.path.to_string().await?,).into(),
))
}
}
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("directory assets {path}")]
pub struct DirAssetReference {
context_dir: FileSystemPath,
path: ResolvedVc<Pattern>,
......@@ -220,13 +212,3 @@ impl ModuleReference for DirAssetReference {
Vc::cell(Some(ChunkingType::Traced))
}
}
#[turbo_tasks::value_impl]
impl ValueToString for DirAssetReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("directory assets {}", self.path.to_string().await?,).into(),
))
}
}
......@@ -14,7 +14,7 @@ use swc_core::{
quote, quote_expr,
};
use turbo_esregex::EsRegex;
use turbo_rcstr::{RcStr, rcstr};
use turbo_rcstr::RcStr;
use turbo_tasks::{
FxIndexMap, NonLocalValue, ResolvedVc, ValueToString, Vc, debug::ValueDebugFormat,
trace::TraceRawVcs,
......@@ -227,7 +227,8 @@ impl RequireContextMap {
/// A reference for `require.context()`, will replace it with an inlined map
/// wrapped in `__turbopack_module_context__`;
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("require.context {}/{}", self.dir, {if self.include_subdirs { "**" } else { "*" }})]
pub struct RequireContextAssetReference {
pub inner: ResolvedVc<RequireContextAsset>,
pub dir: RcStr,
......@@ -293,21 +294,6 @@ impl ModuleReference for RequireContextAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for RequireContextAssetReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(
format!(
"require.context {}/{}",
self.dir,
if self.include_subdirs { "**" } else { "*" },
)
.into(),
)
}
}
impl IntoCodeGenReference for RequireContextAssetReference {
fn into_code_gen_reference(
self,
......@@ -366,6 +352,8 @@ impl RequireContextAssetReferenceCodeGen {
}
#[turbo_tasks::value(transparent)]
#[derive(ValueToString)]
#[value_to_string("resolved reference")]
pub struct ResolvedModuleReference(ResolvedVc<ModuleResolveResult>);
#[turbo_tasks::value_impl]
......@@ -384,14 +372,6 @@ impl ModuleReference for ResolvedModuleReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for ResolvedModuleReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("resolved reference"))
}
}
#[turbo_tasks::value]
pub struct RequireContextAsset {
source: ResolvedVc<Box<dyn Source>>,
......
......@@ -14,7 +14,8 @@ use turbopack_resolve::typescript::type_resolve;
use crate::typescript::TsConfigModuleAsset;
#[turbo_tasks::value]
#[derive(Hash, Clone, Debug)]
#[derive(Hash, Clone, Debug, ValueToString)]
#[value_to_string("tsconfig {tsconfig}")]
pub struct TsConfigReference {
pub tsconfig: FileSystemPath,
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
......@@ -43,18 +44,9 @@ impl ModuleReference for TsConfigReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for TsConfigReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("tsconfig {}", self.tsconfig.value_to_string().await?).into(),
))
}
}
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("typescript reference path comment {path}")]
pub struct TsReferencePathAssetReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub path: RcStr,
......@@ -98,16 +90,9 @@ impl ModuleReference for TsReferencePathAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for TsReferencePathAssetReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(format!("typescript reference path comment {}", self.path,).into())
}
}
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("typescript reference type comment {module}")]
pub struct TsReferenceTypeAssetReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub module: RcStr,
......@@ -136,11 +121,3 @@ impl ModuleReference for TsReferenceTypeAssetReference {
)
}
}
#[turbo_tasks::value_impl]
impl ValueToString for TsReferenceTypeAssetReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(format!("typescript reference type comment {}", self.module,).into())
}
}
......@@ -5,7 +5,6 @@ use swc_core::{
ecma::ast::{Ident, Lit},
quote,
};
use turbo_rcstr::RcStr;
use turbo_tasks::{NonLocalValue, ResolvedVc, ValueToString, Vc, trace::TraceRawVcs};
use turbopack_core::{
chunk::{ChunkingContext, ChunkingType, ChunkingTypeOption, ModuleChunkItemIdExt},
......@@ -35,6 +34,8 @@ enum EcmascriptModulePartReferenceMode {
/// A reference to the [EcmascriptModuleLocalsModule] variant of an original
/// module.
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string(self.part)]
pub struct EcmascriptModulePartReference {
module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
part: ModulePart,
......@@ -84,14 +85,6 @@ impl EcmascriptModulePartReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EcmascriptModulePartReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(self.part.to_string().into())
}
}
#[turbo_tasks::value_impl]
impl ModuleReference for EcmascriptModulePartReference {
#[turbo_tasks::function]
......
......@@ -178,7 +178,8 @@ impl Module for TsConfigModuleAsset {
}
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("compiler reference {request}")]
pub struct CompilerReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub request: ResolvedVc<Request>,
......@@ -209,18 +210,9 @@ impl ModuleReference for CompilerReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for CompilerReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("compiler reference {}", self.request.to_string().await?).into(),
))
}
}
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("tsconfig extends {}", self.config.ident())]
pub struct TsExtendsReference {
pub config: ResolvedVc<Box<dyn Source>>,
}
......@@ -243,22 +235,9 @@ impl ModuleReference for TsExtendsReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for TsExtendsReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!(
"tsconfig extends {}",
self.config.ident().to_string().await?,
)
.into(),
))
}
}
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("tsconfig tsnode require {request}")]
pub struct TsNodeRequireReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub request: ResolvedVc<Request>,
......@@ -289,22 +268,9 @@ impl ModuleReference for TsNodeRequireReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for TsNodeRequireReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!(
"tsconfig tsnode require {}",
self.request.to_string().await?
)
.into(),
))
}
}
#[turbo_tasks::value]
#[derive(Hash, Debug)]
#[derive(Hash, Debug, ValueToString)]
#[value_to_string("tsconfig types {request}")]
pub struct TsConfigTypesReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub request: ResolvedVc<Request>,
......@@ -328,13 +294,3 @@ impl ModuleReference for TsConfigTypesReference {
type_resolve(*self.origin, *self.request)
}
}
#[turbo_tasks::value_impl]
impl ValueToString for TsConfigTypesReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("tsconfig types {}", self.request.to_string().await?,).into(),
))
}
}
......@@ -69,6 +69,8 @@ impl Module for WebpackModuleAsset {
}
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("webpack chunk {}", self.chunk_id())]
pub struct WebpackChunkAssetReference {
#[turbo_tasks(trace_ignore)]
#[bincode(with_serde)]
......@@ -77,6 +79,16 @@ pub struct WebpackChunkAssetReference {
pub transforms: ResolvedVc<EcmascriptInputTransforms>,
}
impl WebpackChunkAssetReference {
pub fn chunk_id(&self) -> RcStr {
match &self.chunk_id {
Lit::Str(s) => RcStr::from(s.value.to_string_lossy().to_string()),
Lit::Num(n) => RcStr::from(n.to_string()),
_ => panic!("Unexpected literal type"),
}
}
}
#[turbo_tasks::value_impl]
impl ModuleReference for WebpackChunkAssetReference {
#[turbo_tasks::function]
......@@ -107,20 +119,9 @@ impl ModuleReference for WebpackChunkAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for WebpackChunkAssetReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
let chunk_id = match &self.chunk_id {
Lit::Str(str) => str.value.to_string_lossy().into_owned(),
Lit::Num(num) => format!("{num}"),
_ => todo!(),
};
Vc::cell(format!("webpack chunk {chunk_id}").into())
}
}
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("webpack entry")]
pub struct WebpackEntryAssetReference {
pub source: ResolvedVc<Box<dyn Source>>,
pub runtime: ResolvedVc<WebpackRuntime>,
......@@ -139,15 +140,9 @@ impl ModuleReference for WebpackEntryAssetReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for WebpackEntryAssetReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("webpack entry"))
}
}
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("webpack {request}")]
pub struct WebpackRuntimeAssetReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub request: ResolvedVc<Request>,
......@@ -183,13 +178,3 @@ impl ModuleReference for WebpackRuntimeAssetReference {
.cell())
}
}
#[turbo_tasks::value_impl]
impl ValueToString for WebpackRuntimeAssetReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("webpack {}", self.request.to_string().await?,).into(),
))
}
}
use anyhow::{Result, bail};
use indoc::formatdoc;
use turbo_rcstr::{RcStr, rcstr};
use turbo_rcstr::rcstr;
use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use turbopack_core::{
chunk::{
......@@ -306,6 +306,8 @@ impl EcmascriptChunkPlaceable for WorkerLoaderModule {
}
#[turbo_tasks::value]
#[derive(ValueToString)]
#[value_to_string("{} module", self.worker_type.friendly_str())]
struct WorkerModuleReference {
module: ResolvedVc<Box<dyn Module>>,
worker_type: WorkerType,
......@@ -340,15 +342,3 @@ impl ModuleReference for WorkerModuleReference {
}))
}
}
#[turbo_tasks::value_impl]
impl ValueToString for WorkerModuleReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(match self.worker_type {
WorkerType::WebWorker => rcstr!("web worker module"),
WorkerType::NodeWorkerThread => rcstr!("node worker thread module"),
WorkerType::SharedWebWorker => rcstr!("shared web worker module"),
})
}
}
......@@ -27,6 +27,14 @@ impl WorkerType {
}
}
pub fn friendly_str(&self) -> RcStr {
match self {
WorkerType::WebWorker => rcstr!("web worker"),
WorkerType::SharedWebWorker => rcstr!("shared web worker"),
WorkerType::NodeWorkerThread => rcstr!("node worker thread"),
}
}
pub fn reference_type(&self) -> ReferenceType {
ReferenceType::Worker(match self {
WorkerType::WebWorker => WorkerReferenceSubType::WebWorker,
......
......@@ -17,6 +17,8 @@ use crate::NodeJsChunkingContext;
/// Production Ecmascript chunk targeting Node.js.
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("Ecmascript Build Node Chunk")]
pub(crate) struct EcmascriptBuildNodeChunk {
chunking_context: ResolvedVc<NodeJsChunkingContext>,
chunk: ResolvedVc<EcmascriptChunk>,
......@@ -48,14 +50,6 @@ impl EcmascriptBuildNodeChunk {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EcmascriptBuildNodeChunk {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("Ecmascript Build Node Chunk"))
}
}
fn modifier() -> RcStr {
rcstr!("ecmascript build node chunk")
}
......
......@@ -2,7 +2,6 @@ use std::io::Write;
use anyhow::{Result, bail};
use indoc::writedoc;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{File, FileContent, FileSystemPath};
use turbopack_core::{
......@@ -24,6 +23,8 @@ use crate::NodeJsChunkingContext;
/// An Ecmascript chunk that loads a list of parallel chunks, then instantiates
/// runtime entries.
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("Ecmascript Build Node Entry Chunk")]
pub(crate) struct EcmascriptBuildNodeEntryChunk {
path: FileSystemPath,
other_chunks: ResolvedVc<OutputAssets>,
......@@ -162,14 +163,6 @@ impl EcmascriptBuildNodeEntryChunk {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EcmascriptBuildNodeEntryChunk {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("Ecmascript Build Node Entry Chunk"))
}
}
#[turbo_tasks::value_impl]
impl OutputAssetsReference for EcmascriptBuildNodeEntryChunk {
#[turbo_tasks::function]
......
......@@ -2,7 +2,7 @@ use std::io::Write;
use anyhow::{Result, bail};
use indoc::writedoc;
use turbo_rcstr::{RcStr, rcstr};
use turbo_rcstr::rcstr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{File, FileContent, FileSystem, FileSystemPath};
use turbopack_core::{
......@@ -20,6 +20,8 @@ use crate::NodeJsChunkingContext;
/// An Ecmascript chunk that contains the Node.js runtime code.
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("Ecmascript Build Node Runtime Chunk")]
pub(crate) struct EcmascriptBuildNodeRuntimeChunk {
chunking_context: ResolvedVc<NodeJsChunkingContext>,
}
......@@ -143,14 +145,6 @@ impl EcmascriptBuildNodeRuntimeChunk {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for EcmascriptBuildNodeRuntimeChunk {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell(rcstr!("Ecmascript Build Node Runtime Chunk"))
}
}
#[turbo_tasks::value_impl]
impl OutputAssetsReference for EcmascriptBuildNodeRuntimeChunk {
#[turbo_tasks::function]
......
......@@ -32,7 +32,8 @@ struct NodePreGypConfig {
}
#[turbo_tasks::value]
#[derive(Hash, Clone, Debug)]
#[derive(Hash, Clone, Debug, ValueToString)]
#[value_to_string("node-gyp in {context_dir} with {config_file_pattern} for {compile_target}")]
pub struct NodePreGypConfigReference {
pub context_dir: FileSystemPath,
pub config_file_pattern: ResolvedVc<Pattern>,
......@@ -72,20 +73,6 @@ impl ModuleReference for NodePreGypConfigReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for NodePreGypConfigReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
let context_dir = self.context_dir.value_to_string().await?;
let config_file_pattern = self.config_file_pattern.to_string().await?;
let compile_target = self.compile_target.await?;
Ok(Vc::cell(
format!("node-gyp in {context_dir} with {config_file_pattern} for {compile_target}")
.into(),
))
}
}
async fn resolve_node_pre_gyp_files(
context_dir: FileSystemPath,
config_file_pattern: Vc<Pattern>,
......@@ -229,7 +216,8 @@ async fn resolve_node_pre_gyp_files(
}
#[turbo_tasks::value]
#[derive(Hash, Clone, Debug)]
#[derive(Hash, Clone, Debug, ValueToString)]
#[value_to_string("node-gyp in {context_dir} for {compile_target}")]
pub struct NodeGypBuildReference {
pub context_dir: FileSystemPath,
collect_affecting_sources: bool,
......@@ -265,18 +253,6 @@ impl ModuleReference for NodeGypBuildReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for NodeGypBuildReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
let context_dir = self.context_dir.value_to_string().await?;
let compile_target = self.compile_target.await?;
Ok(Vc::cell(
format!("node-gyp in {context_dir} for {compile_target}").into(),
))
}
}
async fn resolve_node_gyp_build_files(
context_dir: FileSystemPath,
collect_affecting_sources: bool,
......@@ -362,7 +338,8 @@ async fn resolve_node_gyp_build_files(
}
#[turbo_tasks::value]
#[derive(Hash, Clone, Debug)]
#[derive(Hash, Clone, Debug, ValueToString)]
#[value_to_string("bindings in {context_dir}")]
pub struct NodeBindingsReference {
pub context_dir: FileSystemPath,
pub file_name: RcStr,
......@@ -398,16 +375,6 @@ impl ModuleReference for NodeBindingsReference {
}
}
#[turbo_tasks::value_impl]
impl ValueToString for NodeBindingsReference {
#[turbo_tasks::function]
async fn to_string(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("bindings in {}", self.context_dir.value_to_string().await?,).into(),
))
}
}
async fn resolve_node_bindings_files(
context_dir: FileSystemPath,
file_name: RcStr,
......
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