-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes attribute/argument parsing to the more usual `field = "value"` / `turbo_tasks(trace_ignore)`
- Loading branch information
1 parent
badc183
commit 0a4ac61
Showing
33 changed files
with
481 additions
and
420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 20 additions & 16 deletions
36
crates/turbo-tasks-macros-shared/src/value_trait_arguments.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,42 @@ | ||
use syn::{ | ||
parse::{Parse, ParseStream}, | ||
Ident, Token, | ||
punctuated::Punctuated, | ||
Meta, Token, | ||
}; | ||
|
||
/// Arguments to the `#[turbo_tasks::value_trait]` attribute macro. | ||
#[derive(Debug)] | ||
pub struct ValueTraitArguments { | ||
/// Whether the macro should generate a `ValueDebug`-like `dbg()` | ||
/// implementation on the trait's `Vc`. | ||
pub no_debug: bool, | ||
pub debug: bool, | ||
} | ||
|
||
impl Default for ValueTraitArguments { | ||
fn default() -> Self { | ||
Self { debug: true } | ||
} | ||
} | ||
|
||
impl Parse for ValueTraitArguments { | ||
fn parse(input: ParseStream) -> syn::Result<Self> { | ||
let mut result = ValueTraitArguments { no_debug: false }; | ||
let mut result = Self::default(); | ||
if input.is_empty() { | ||
return Ok(result); | ||
} | ||
loop { | ||
let path = input.parse::<Ident>()?; | ||
match path.to_string().as_ref() { | ||
"no_debug" => { | ||
result.no_debug = true; | ||
|
||
let punctuated: Punctuated<Meta, Token![,]> = input.parse_terminated(Meta::parse)?; | ||
for meta in punctuated { | ||
match meta.path().get_ident().map(ToString::to_string).as_deref() { | ||
Some("no_debug") => { | ||
result.debug = false; | ||
} | ||
_ => { | ||
return Err(input.error("unknown parameter")); | ||
return Err(syn::Error::new_spanned(meta, "unknown parameter")); | ||
} | ||
} | ||
if input.is_empty() { | ||
return Ok(result); | ||
} else if input.peek(Token![,]) { | ||
input.parse::<Token![,]>()?; | ||
} else { | ||
return Err(input.error("expected \",\" or end of attribute")); | ||
} | ||
} | ||
|
||
Ok(result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
mod trace_raw_vcs_macro; | ||
mod value_debug_macro; | ||
|
||
use syn::{spanned::Spanned, Attribute, Meta, MetaList, NestedMeta}; | ||
pub use trace_raw_vcs_macro::derive_trace_raw_vcs; | ||
pub use value_debug_macro::derive_value_debug; | ||
|
||
struct FieldAttributes { | ||
trace_ignore: bool, | ||
debug_ignore: bool, | ||
} | ||
|
||
impl From<&[Attribute]> for FieldAttributes { | ||
fn from(attrs: &[Attribute]) -> Self { | ||
let mut result = Self { | ||
trace_ignore: false, | ||
debug_ignore: false, | ||
}; | ||
|
||
for attr in attrs { | ||
if !attr | ||
.path | ||
.get_ident() | ||
.map(|ident| *ident == "turbo_tasks") | ||
.unwrap_or_default() | ||
{ | ||
continue; | ||
} | ||
if let Ok(Meta::List(MetaList { nested, .. })) = attr | ||
.parse_meta() | ||
.map_err(|err| err.span().unwrap().error(err.to_string()).emit()) | ||
{ | ||
for meta in nested { | ||
if let NestedMeta::Meta(Meta::Path(path)) = &meta { | ||
match path.get_ident().map(|ident| ident.to_string()).as_deref() { | ||
Some("trace_ignore") => result.trace_ignore = true, | ||
Some("debug_ignore") => result.debug_ignore = true, | ||
_ => path | ||
.span() | ||
.unwrap() | ||
.error("expected `trace_ignore` or `debug_ignore`") | ||
.emit(), | ||
} | ||
} else { | ||
meta.span() | ||
.unwrap() | ||
.error("expected `trace_ignore` or `debug_ignore`") | ||
.emit(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.