Skip to content

Commit

Permalink
feat(turbo-tasks): Ignore fields annotated with `#[turbo_tasks(trace_…
Browse files Browse the repository at this point in the history
…ignore)]` (#70375)

This annotation implies that the field does not contain any `Vc` types,
so we can re-use that here. We can skip checking for `ResolvedValue` on
these fields.

As we start codemodding stuff, we should consider renaming this
annotation to something more generic (e.g.
`#[turbo_tasks(does_not_contain_vc)]`), but this is good enough for now.
  • Loading branch information
bgw committed Sep 24, 2024
1 parent bd68cef commit 538b1c6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::marker::PhantomData;

use turbo_tasks::ResolvedValue;

struct UnannotatedValue<T>(PhantomData<T>);

#[derive(ResolvedValue)]
struct ContainsIgnore<T> {
#[turbo_tasks(trace_ignore)]
a: UnannotatedValue<T>,
}

fn main() {
let _ = ContainsIgnore {
a: UnannotatedValue(PhantomData::<u32>),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use proc_macro2::TokenStream as TokenStream2;
use quote::{quote, quote_spanned};
use syn::{parse_macro_input, spanned::Spanned, Data, DeriveInput, Generics};

use crate::derive::trace_raw_vcs_macro::filter_field;

pub fn derive_resolved_value(input: TokenStream) -> TokenStream {
let derive_input = parse_macro_input!(input as DeriveInput);
let ident = &derive_input.ident;
Expand Down Expand Up @@ -31,15 +33,18 @@ fn assert_fields_impl_resolved_value(generics: &Generics, data: &Data) -> TokenS
// this technique is based on the trick used by
// `static_assertions::assert_impl_all`, but extended to support generics.
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
let field_types: Vec<_> = iter_data_fields(data).map(|field| &field.ty).collect();
let assertion_calls = field_types.iter().map(|ty| {
quote_spanned! {
// attribute type assertion errors to the line where the field is defined
ty.span() =>
// this call is only valid if ty is a ResolvedValue
Self::assert_impl_resolved_value::<#ty>();
}
});
let field_types = iter_data_fields(data).map(|field| &field.ty);
let assertion_calls = iter_data_fields(data)
.filter(|field| filter_field(field))
.map(|field| {
let ty = &field.ty;
quote_spanned! {
// attribute type assertion errors to the line where the field is defined
ty.span() =>
// this call is only valid if ty is a ResolvedValue
Self::assert_impl_resolved_value::<#ty>();
}
});
quote! {
const _: fn() = || {
// create this struct just to hold onto our generics...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use turbo_tasks_macros_shared::{generate_destructuring, match_expansion};

use super::FieldAttributes;

fn filter_field(field: &Field) -> bool {
pub fn filter_field(field: &Field) -> bool {
!FieldAttributes::from(field.attrs.as_slice()).trace_ignore
}

Expand Down

0 comments on commit 538b1c6

Please sign in to comment.