Skip to content

Commit da16ee5

Browse files
committed
Upgrade to syn 2.0
1 parent d4a94fb commit da16ee5

File tree

10 files changed

+47
-35
lines changed

10 files changed

+47
-35
lines changed

components/salsa-2022-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ proc-macro = true
1010
heck = "0.4"
1111
proc-macro2 = "1.0"
1212
quote = "1.0"
13-
syn = { version = "1.0", features = ["full", "extra-traits", "visit-mut"] }
13+
syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"] }
1414
eyre = "0.6.5"

components/salsa-2022-macros/src/configuration.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ pub(crate) struct Configuration {
44
pub(crate) key_ty: syn::Type,
55
pub(crate) value_ty: syn::Type,
66
pub(crate) cycle_strategy: CycleRecoveryStrategy,
7-
pub(crate) backdate_fn: syn::ImplItemMethod,
8-
pub(crate) execute_fn: syn::ImplItemMethod,
9-
pub(crate) recover_fn: syn::ImplItemMethod,
7+
pub(crate) backdate_fn: syn::ImplItemFn,
8+
pub(crate) execute_fn: syn::ImplItemFn,
9+
pub(crate) recover_fn: syn::ImplItemFn,
1010
}
1111

1212
impl Configuration {
@@ -56,7 +56,7 @@ impl quote::ToTokens for CycleRecoveryStrategy {
5656

5757
/// Returns an appropriate definition for `should_backdate_value` depending on
5858
/// whether this value is memoized or not.
59-
pub(crate) fn should_backdate_value_fn(should_backdate: bool) -> syn::ImplItemMethod {
59+
pub(crate) fn should_backdate_value_fn(should_backdate: bool) -> syn::ImplItemFn {
6060
if should_backdate {
6161
parse_quote! {
6262
fn should_backdate_value(v1: &Self::Value, v2: &Self::Value) -> bool {
@@ -74,7 +74,7 @@ pub(crate) fn should_backdate_value_fn(should_backdate: bool) -> syn::ImplItemMe
7474

7575
/// Returns an appropriate definition for `recover_from_cycle` for cases where
7676
/// the cycle recovery is panic.
77-
pub(crate) fn panic_cycle_recovery_fn() -> syn::ImplItemMethod {
77+
pub(crate) fn panic_cycle_recovery_fn() -> syn::ImplItemFn {
7878
parse_quote! {
7979
fn recover_from_cycle(
8080
_db: &salsa::function::DynDb<Self>,

components/salsa-2022-macros/src/input.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl InputStruct {
8181
let field_tys: Vec<_> = self.all_field_tys();
8282
let field_clones: Vec<_> = self.all_fields().map(SalsaField::is_clone_field).collect();
8383
let get_field_names: Vec<_> = self.all_get_field_names();
84-
let field_getters: Vec<syn::ImplItemMethod> = field_indices.iter().zip(&get_field_names).zip(&field_vises).zip(&field_tys).zip(&field_clones).map(|((((field_index, get_field_name), field_vis), field_ty), is_clone_field)|
84+
let field_getters: Vec<syn::ImplItemFn> = field_indices.iter().zip(&get_field_names).zip(&field_vises).zip(&field_tys).zip(&field_clones).map(|((((field_index, get_field_name), field_vis), field_ty), is_clone_field)|
8585
if !*is_clone_field {
8686
parse_quote! {
8787
#field_vis fn #get_field_name<'db>(self, __db: &'db #db_dyn_ty) -> &'db #field_ty
@@ -106,7 +106,7 @@ impl InputStruct {
106106

107107
// setters
108108
let set_field_names = self.all_set_field_names();
109-
let field_setters: Vec<syn::ImplItemMethod> = field_indices.iter()
109+
let field_setters: Vec<syn::ImplItemFn> = field_indices.iter()
110110
.zip(&set_field_names)
111111
.zip(&field_vises)
112112
.zip(&field_tys)
@@ -126,7 +126,7 @@ impl InputStruct {
126126
let constructor_name = self.constructor_name();
127127
let singleton = self.0.is_isingleton();
128128

129-
let constructor: syn::ImplItemMethod = if singleton {
129+
let constructor: syn::ImplItemFn = if singleton {
130130
parse_quote! {
131131
/// Creates a new singleton input
132132
///
@@ -160,7 +160,7 @@ impl InputStruct {
160160
};
161161

162162
if singleton {
163-
let get: syn::ImplItemMethod = parse_quote! {
163+
let get: syn::ImplItemFn = parse_quote! {
164164
#[track_caller]
165165
pub fn get(__db: &#db_dyn_ty) -> Self {
166166
let (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(__db);
@@ -169,7 +169,7 @@ impl InputStruct {
169169
}
170170
};
171171

172-
let try_get: syn::ImplItemMethod = parse_quote! {
172+
let try_get: syn::ImplItemFn = parse_quote! {
173173
#[track_caller]
174174
pub fn try_get(__db: &#db_dyn_ty) -> Option<Self> {
175175
let (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(__db);

components/salsa-2022-macros/src/interned.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl InternedStruct {
8888
let db_dyn_ty = self.db_dyn_ty();
8989
let jar_ty = self.jar_ty();
9090

91-
let field_getters: Vec<syn::ImplItemMethod> = self
91+
let field_getters: Vec<syn::ImplItemFn> = self
9292
.all_fields()
9393
.map(|field| {
9494
let field_name = field.name();
@@ -119,7 +119,7 @@ impl InternedStruct {
119119
let field_tys = self.all_field_tys();
120120
let data_ident = self.data_ident();
121121
let constructor_name = self.constructor_name();
122-
let new_method: syn::ImplItemMethod = parse_quote! {
122+
let new_method: syn::ImplItemFn = parse_quote! {
123123
#vis fn #constructor_name(
124124
db: &#db_dyn_ty,
125125
#(#field_names: #field_tys,)*

components/salsa-2022-macros/src/salsa_struct.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<A: AllowedOptions> SalsaStruct<A> {
172172
.struct_item
173173
.attrs
174174
.iter()
175-
.filter(|attr| !attr.path.is_ident("derive"))
175+
.filter(|attr| !attr.path().is_ident("derive"))
176176
.collect();
177177

178178
parse_quote! {
@@ -426,7 +426,7 @@ impl SalsaField {
426426
// Scan the attributes and look for the salsa attributes:
427427
for attr in &field.attrs {
428428
for (fa, func) in FIELD_OPTION_ATTRIBUTES {
429-
if attr.path.is_ident(fa) {
429+
if attr.path().is_ident(fa) {
430430
func(attr, &mut result);
431431
}
432432
}

components/salsa-2022-macros/src/tracked_fn.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ pub(crate) fn tracked_impl(
110110
.iter_mut()
111111
.filter_map(|item| {
112112
let item_method = match item {
113-
syn::ImplItem::Method(item_method) => item_method,
113+
syn::ImplItem::Fn(item_method) => item_method,
114114
_ => return None,
115115
};
116116
let salsa_tracked_attr = item_method.attrs.iter().position(|attr| {
117-
let path = &attr.path.segments;
117+
let path = &attr.path().segments;
118118
path.len() == 2
119119
&& path[0].arguments == syn::PathArguments::None
120120
&& path[0].ident == "salsa"
@@ -185,7 +185,7 @@ impl crate::options::AllowedOptions for TrackedImpl {
185185
fn tracked_method(
186186
outer_args: &ImplArgs,
187187
mut args: FnArgs,
188-
item_method: &mut syn::ImplItemMethod,
188+
item_method: &mut syn::ImplItemFn,
189189
self_type: &syn::TypePath,
190190
name: &str,
191191
) -> syn::Result<TokenStream> {
@@ -633,7 +633,7 @@ fn setter_fn(
633633
args: &FnArgs,
634634
item_fn: &syn::ItemFn,
635635
config_ty: &syn::Type,
636-
) -> syn::Result<syn::ImplItemMethod> {
636+
) -> syn::Result<syn::ImplItemFn> {
637637
// The setter has *always* the same signature as the original:
638638
// but it takes a value arg and has no return type.
639639
let jar_ty = args.jar_ty();
@@ -654,7 +654,7 @@ fn setter_fn(
654654
let value_arg = syn::Ident::new("__value", item_fn.sig.output.span());
655655
setter_sig.inputs.push(parse_quote!(#value_arg: #value_ty));
656656
setter_sig.output = ReturnType::Default;
657-
Ok(syn::ImplItemMethod {
657+
Ok(syn::ImplItemFn {
658658
attrs: vec![],
659659
vis: item_fn.vis.clone(),
660660
defaultness: None,
@@ -685,7 +685,7 @@ fn setter_fn(
685685
fn set_lru_capacity_fn(
686686
args: &FnArgs,
687687
config_ty: &syn::Type,
688-
) -> syn::Result<Option<syn::ImplItemMethod>> {
688+
) -> syn::Result<Option<syn::ImplItemFn>> {
689689
if args.lru.is_none() {
690690
return Ok(None);
691691
}
@@ -707,7 +707,7 @@ fn specify_fn(
707707
args: &FnArgs,
708708
item_fn: &syn::ItemFn,
709709
config_ty: &syn::Type,
710-
) -> syn::Result<Option<syn::ImplItemMethod>> {
710+
) -> syn::Result<Option<syn::ImplItemFn>> {
711711
if args.specify.is_none() {
712712
return Ok(None);
713713
}
@@ -722,7 +722,7 @@ fn specify_fn(
722722
let value_arg = syn::Ident::new("__value", item_fn.sig.output.span());
723723
setter_sig.inputs.push(parse_quote!(#value_arg: #value_ty));
724724
setter_sig.output = ReturnType::Default;
725-
Ok(Some(syn::ImplItemMethod {
725+
Ok(Some(syn::ImplItemFn {
726726
attrs: vec![],
727727
vis: item_fn.vis.clone(),
728728
defaultness: None,
@@ -746,7 +746,7 @@ fn make_fn_return_ref(mut fn_sig: &mut syn::Signature) -> syn::Result<()> {
746746
let (db_lifetime, _) = db_lifetime_and_ty(fn_sig)?;
747747

748748
let (right_arrow, elem) = match fn_sig.output.clone() {
749-
ReturnType::Default => (syn::Token![->](fn_sig.paren_token.span), parse_quote!(())),
749+
ReturnType::Default => (syn::Token![->]([fn_sig.paren_token.span]), parse_quote!(())),
750750
ReturnType::Type(rarrow, ty) => (rarrow, ty),
751751
};
752752

@@ -783,7 +783,7 @@ fn db_lifetime_and_ty(func: &mut syn::Signature) -> syn::Result<(syn::Lifetime,
783783
let ident = syn::Ident::new("__db", and_token_span);
784784
func.generics.params.insert(
785785
0,
786-
syn::LifetimeDef {
786+
syn::LifetimeParam {
787787
attrs: vec![],
788788
lifetime: syn::Lifetime {
789789
apostrophe: and_token_span,

components/salsa-2022-macros/src/tracked_struct.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl TrackedStruct {
9191
let id_field_tys: Vec<_> = self.id_fields().map(SalsaField::ty).collect();
9292
let id_field_vises: Vec<_> = self.id_fields().map(SalsaField::vis).collect();
9393
let id_field_clones: Vec<_> = self.id_fields().map(SalsaField::is_clone_field).collect();
94-
let id_field_getters: Vec<syn::ImplItemMethod> = id_field_indices.iter().zip(&id_field_get_names).zip(&id_field_tys).zip(&id_field_vises).zip(&id_field_clones).map(|((((field_index, field_get_name), field_ty), field_vis), is_clone_field)|
94+
let id_field_getters: Vec<syn::ImplItemFn> = id_field_indices.iter().zip(&id_field_get_names).zip(&id_field_tys).zip(&id_field_vises).zip(&id_field_clones).map(|((((field_index, field_get_name), field_ty), field_vis), is_clone_field)|
9595
if !*is_clone_field {
9696
parse_quote! {
9797
#field_vis fn #field_get_name<'db>(self, __db: &'db #db_dyn_ty) -> &'db #field_ty
@@ -123,7 +123,7 @@ impl TrackedStruct {
123123
.value_fields()
124124
.map(SalsaField::is_clone_field)
125125
.collect();
126-
let value_field_getters: Vec<syn::ImplItemMethod> = value_field_indices.iter().zip(&value_field_get_names).zip(&value_field_tys).zip(&value_field_vises).zip(&value_field_clones).map(|((((field_index, field_get_name), field_ty), field_vis), is_clone_field)|
126+
let value_field_getters: Vec<syn::ImplItemFn> = value_field_indices.iter().zip(&value_field_get_names).zip(&value_field_tys).zip(&value_field_vises).zip(&value_field_clones).map(|((((field_index, field_get_name), field_ty), field_vis), is_clone_field)|
127127
if !*is_clone_field {
128128
parse_quote! {
129129
#field_vis fn #field_get_name<'db>(self, __db: &'db #db_dyn_ty) -> &'db #field_ty

components/salsa-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ proc-macro = true
1414
heck = "0.4"
1515
proc-macro2 = "1.0"
1616
quote = "1.0"
17-
syn = { version = "1.0", features = ["full", "extra-traits"] }
17+
syn = { version = "2.0", features = ["full", "extra-traits"] }

components/salsa-macros/src/database_storage.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ struct QueryGroupList {
220220

221221
impl Parse for QueryGroupList {
222222
fn parse(input: ParseStream) -> syn::Result<Self> {
223-
let query_groups: PunctuatedQueryGroups = input.parse_terminated(QueryGroup::parse)?;
223+
let query_groups: PunctuatedQueryGroups =
224+
input.parse_terminated(QueryGroup::parse, Token![,])?;
224225
Ok(QueryGroupList { query_groups })
225226
}
226227
}

components/salsa-macros/src/query_group.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::convert::TryFrom;
1+
use std::{convert::TryFrom, iter::FromIterator};
22

33
use crate::parenthesized::Parenthesized;
44
use heck::ToUpperCamelCase;
@@ -36,7 +36,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
3636
// Decompose the trait into the corresponding queries.
3737
let mut queries = vec![];
3838
for item in input.items {
39-
if let TraitItem::Method(method) = item {
39+
if let TraitItem::Fn(method) = item {
4040
let query_name = method.sig.ident.to_string();
4141

4242
let mut storage = QueryStorage::Memoized;
@@ -277,7 +277,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
277277
specific durability instead of the default of
278278
`Durability::LOW`. You can use `Durability::MAX`
279279
to promise that its value will never change again.
280-
280+
281281
See `{fn_name}` for details.
282282
283283
*Note:* Setting values will trigger cancellation
@@ -681,13 +681,24 @@ impl TryFrom<syn::Attribute> for SalsaAttr {
681681
type Error = syn::Attribute;
682682

683683
fn try_from(attr: syn::Attribute) -> Result<SalsaAttr, syn::Attribute> {
684-
if is_not_salsa_attr_path(&attr.path) {
684+
if is_not_salsa_attr_path(attr.path()) {
685685
return Err(attr);
686686
}
687687

688688
let span = attr.span();
689-
let name = attr.path.segments[1].ident.to_string();
690-
let tts = attr.tokens.into();
689+
let name = attr.path().segments[1].ident.to_string();
690+
let tts = match attr.meta {
691+
syn::Meta::Path(path) => path.into_token_stream(),
692+
syn::Meta::List(ref list) => {
693+
let tts = list
694+
.into_token_stream()
695+
.into_iter()
696+
.skip(attr.path().to_token_stream().into_iter().count());
697+
proc_macro2::TokenStream::from_iter(tts)
698+
}
699+
syn::Meta::NameValue(nv) => nv.into_token_stream(),
700+
}
701+
.into();
691702

692703
Ok(SalsaAttr { name, tts, span })
693704
}

0 commit comments

Comments
 (0)