Skip to content
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

Remove unnecessary ValueDebugFormat item, hide Vc field #5567

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,18 @@ pub fn derive_value_debug_format(input: TokenStream) -> TokenStream {
let formatting_logic =
match_expansion(&derive_input, &format_named, &format_unnamed, &format_unit);

let value_debug_format_ident = get_value_debug_format_ident(ident);

quote! {
#[doc(hidden)]
impl #impl_generics #ident #ty_generics #where_clause {
#[doc(hidden)]
#[allow(non_snake_case)]
async fn #value_debug_format_ident(&self, depth: usize) -> anyhow::Result<turbo_tasks::Vc<turbo_tasks::debug::ValueDebugString>> {
if depth == 0 {
return Ok(turbo_tasks::debug::ValueDebugString::new(stringify!(#ident).to_string()));
}

use turbo_tasks::debug::internal::*;
use turbo_tasks::debug::ValueDebugFormat;
Ok(turbo_tasks::debug::ValueDebugString::new(format!("{:#?}", #formatting_logic)))
}
}

impl #impl_generics turbo_tasks::debug::ValueDebugFormat for #ident #ty_generics #where_clause {
fn value_debug_format<'a>(&'a self, depth: usize) -> turbo_tasks::debug::ValueDebugFormatString<'a> {
turbo_tasks::debug::ValueDebugFormatString::Async(
Box::pin(async move {
Ok(self.#value_debug_format_ident(depth).await?.await?.to_string())
if depth == 0 {
return Ok(stringify!(#ident).to_string());
}

use turbo_tasks::debug::internal::*;
use turbo_tasks::debug::ValueDebugFormat;
Ok(format!("{:#?}", #formatting_logic))
})
)
}
Expand Down Expand Up @@ -122,7 +111,3 @@ fn format_unit(ident: &Ident) -> (TokenStream2, TokenStream2) {
},
)
}

pub(crate) fn get_value_debug_format_ident(ident: &Ident) -> Ident {
Ident::new(&format!("__value_debug_format_{}", ident), ident.span())
}
7 changes: 2 additions & 5 deletions crates/turbo-tasks-macros/src/derive/value_debug_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@ use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};

use super::value_debug_format_macro::get_value_debug_format_ident;

/// This macro generates the implementation of the `ValueDebug` trait for a
/// given type.
///
/// This requires the type to implement the `ValueDebugFormat` trait.
pub fn derive_value_debug(input: TokenStream) -> TokenStream {
let derive_input = parse_macro_input!(input as DeriveInput);
let ident = &derive_input.ident;
let value_debug_format_ident = get_value_debug_format_ident(ident);
quote! {
#[turbo_tasks::value_impl]
impl turbo_tasks::debug::ValueDebug for #ident {
#[turbo_tasks::function]
async fn dbg(&self) -> anyhow::Result<turbo_tasks::Vc<turbo_tasks::debug::ValueDebugString>> {
self.#value_debug_format_ident(usize::MAX).await
turbo_tasks::debug::ValueDebugFormat::value_debug_format(self, usize::MAX).try_to_value_debug_string().await
}

#[turbo_tasks::function]
async fn dbg_depth(&self, depth: usize) -> anyhow::Result<turbo_tasks::Vc<turbo_tasks::debug::ValueDebugString>> {
self.#value_debug_format_ident(depth).await
turbo_tasks::debug::ValueDebugFormat::value_debug_format(self, depth).try_to_value_debug_string().await
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/turbo-tasks/src/vc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ where
// accessible.
#[doc(hidden)]
pub node: RawVc,
#[doc(hidden)]
pub(crate) _t: PhantomData<T>,
}

Expand Down
Loading