Skip to content

Commit

Permalink
Remove unnecessary ValueDebugFormat item, hide Vc field (vercel/turbo…
Browse files Browse the repository at this point in the history
…repo#5567)

### Description

This removes unnecessary items from the IDE's autosuggestion.

I'd also like to get rid of all the `*_inline` suggestions, but RA will
ignore `#[doc(hidden)]` when inside the same crate. I don't think
there's a way to indicate "never, ever suggest this item". We could move
some of these to be private to some generated module, but that module
would probably still show up as a top level suggestion.

### Testing Instructions

Automated tests.
  • Loading branch information
alexkirsz committed Jul 19, 2023
1 parent 5d5e34c commit 0482c15
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
29 changes: 7 additions & 22 deletions crates/turbo-tasks-macros/src/derive/value_debug_format_macro.rs
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

0 comments on commit 0482c15

Please sign in to comment.