Globally upgrade to syn 2.x and latest quote and proc_macro2 1x versions (#13846)

* globally upgrade quote to latest 1.0.x (1.0.26)

* globally upgrade syn to final 1.0.x version (1.0.109)

* globally upgrade proc-macro2 to 1.0.56

* upgrade to syn v2.0.13 and fix everything except NestedMeta

* fix parse nested metadata code in decl_runtime_apis.rs

* Port more stuff to syn 2.0

* Make the rest compile

* Ignore error

* update to syn 2.0.14

---------

Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
Sam Johnson
2023-04-12 14:42:22 -04:00
committed by GitHub
parent 03c99fe003
commit b83bf4784e
62 changed files with 402 additions and 478 deletions
@@ -18,6 +18,6 @@ proc-macro = true
[dependencies]
Inflector = "0.11.4"
proc-macro-crate = "1.1.3"
proc-macro2 = "1.0.37"
quote = "1.0.10"
syn = { version = "1.0.98", features = ["full", "visit", "fold", "extra-traits"] }
proc-macro2 = "1.0.56"
quote = "1.0.26"
syn = { version = "2.0.14", features = ["full", "visit", "fold", "extra-traits"] }
@@ -36,8 +36,7 @@ use crate::utils::{
};
use syn::{
parse_quote, spanned::Spanned, FnArg, Ident, ItemTrait, Result, Signature, Token,
TraitItemMethod,
parse_quote, spanned::Spanned, FnArg, Ident, ItemTrait, Result, Signature, Token, TraitItemFn,
};
use proc_macro2::{Span, TokenStream};
@@ -116,7 +115,7 @@ fn function_no_std_impl(
quote! {}
};
let attrs = method.attrs.iter().filter(|a| !a.path.is_ident("version"));
let attrs = method.attrs.iter().filter(|a| !a.path().is_ident("version"));
let cfg_wasm_only = if is_wasm_only {
quote! { #[cfg(target_arch = "wasm32")] }
@@ -139,12 +138,12 @@ fn function_no_std_impl(
/// Generate call to latest function version for `cfg((feature = "std")`
///
/// This should generate simple `fn func(..) { func_version_<latest_version>(..) }`.
fn function_std_latest_impl(method: &TraitItemMethod, latest_version: u32) -> Result<TokenStream> {
fn function_std_latest_impl(method: &TraitItemFn, latest_version: u32) -> Result<TokenStream> {
let function_name = &method.sig.ident;
let args = get_function_arguments(&method.sig).map(FnArg::Typed);
let arg_names = get_function_argument_names(&method.sig).collect::<Vec<_>>();
let return_value = &method.sig.output;
let attrs = method.attrs.iter().filter(|a| !a.path.is_ident("version"));
let attrs = method.attrs.iter().filter(|a| !a.path().is_ident("version"));
let latest_function_name =
create_function_ident_with_version(&method.sig.ident, latest_version);
@@ -162,7 +161,7 @@ fn function_std_latest_impl(method: &TraitItemMethod, latest_version: u32) -> Re
/// Generates the bare function implementation for `cfg(feature = "std")`.
fn function_std_impl(
trait_name: &Ident,
method: &TraitItemMethod,
method: &TraitItemFn,
version: u32,
is_wasm_only: bool,
tracing: bool,
@@ -185,7 +184,7 @@ fn function_std_impl(
.take(1),
);
let return_value = &method.sig.output;
let attrs = method.attrs.iter().filter(|a| !a.path.is_ident("version"));
let attrs = method.attrs.iter().filter(|a| !a.path().is_ident("version"));
// Don't make the function public accessible when this is a wasm only interface.
let call_to_trait = generate_call_to_trait(trait_name, method, version, is_wasm_only);
let call_to_trait = if !tracing {
@@ -210,7 +209,7 @@ fn function_std_impl(
/// Generate the call to the interface trait.
fn generate_call_to_trait(
trait_name: &Ident,
method: &TraitItemMethod,
method: &TraitItemFn,
version: u32,
is_wasm_only: bool,
) -> TokenStream {
@@ -30,7 +30,7 @@ use crate::utils::{
};
use syn::{
spanned::Spanned, Error, Ident, ItemTrait, Pat, Result, ReturnType, Signature, TraitItemMethod,
spanned::Spanned, Error, Ident, ItemTrait, Pat, Result, ReturnType, Signature, TraitItemFn,
};
use proc_macro2::{Span, TokenStream};
@@ -78,7 +78,7 @@ pub fn generate(trait_def: &ItemTrait, is_wasm_only: bool) -> Result<TokenStream
/// Generate the extern host function for the given method.
fn generate_extern_host_function(
method: &TraitItemMethod,
method: &TraitItemFn,
version: u32,
trait_name: &Ident,
) -> Result<TokenStream> {
@@ -136,7 +136,7 @@ fn generate_extern_host_function(
}
/// Generate the host exchangeable function for the given method.
fn generate_exchangeable_host_function(method: &TraitItemMethod) -> Result<TokenStream> {
fn generate_exchangeable_host_function(method: &TraitItemFn) -> Result<TokenStream> {
let crate_ = generate_crate_access();
let arg_types = get_function_argument_types(&method.sig);
let function = &method.sig.ident;
@@ -26,7 +26,7 @@ use crate::utils::{
use syn::{
fold::{self, Fold},
spanned::Spanned,
Error, Generics, ItemTrait, Receiver, Result, TraitItemMethod, Type, Visibility,
Error, Generics, ItemTrait, Receiver, Result, TraitItemFn, Type, Visibility,
};
use proc_macro2::TokenStream;
@@ -51,7 +51,7 @@ pub fn process(trait_def: &ItemTrait, is_wasm_only: bool) -> Result<TokenStream>
struct ToEssentialTraitDef {
/// All errors found while doing the conversion.
errors: Vec<Error>,
methods: Vec<TraitItemMethod>,
methods: Vec<TraitItemFn>,
}
impl ToEssentialTraitDef {
@@ -59,7 +59,7 @@ impl ToEssentialTraitDef {
ToEssentialTraitDef { errors: vec![], methods: vec![] }
}
fn into_methods(self) -> Result<Vec<TraitItemMethod>> {
fn into_methods(self) -> Result<Vec<TraitItemFn>> {
let mut errors = self.errors;
let methods = self.methods;
if let Some(first_error) = errors.pop() {
@@ -72,8 +72,8 @@ impl ToEssentialTraitDef {
}
}
fn process(&mut self, method: &TraitItemMethod, version: u32) {
let mut folded = self.fold_trait_item_method(method.clone());
fn process(&mut self, method: &TraitItemFn, version: u32) {
let mut folded = self.fold_trait_item_fn(method.clone());
folded.sig.ident = create_function_ident_with_version(&folded.sig.ident, version);
self.methods.push(folded);
}
@@ -90,7 +90,7 @@ impl ToEssentialTraitDef {
}
impl Fold for ToEssentialTraitDef {
fn fold_trait_item_method(&mut self, mut method: TraitItemMethod) -> TraitItemMethod {
fn fold_trait_item_fn(&mut self, mut method: TraitItemFn) -> TraitItemFn {
if method.default.take().is_none() {
self.push_error(&method, "Methods need to have an implementation.");
}
@@ -105,9 +105,9 @@ impl Fold for ToEssentialTraitDef {
self.error_on_generic_parameters(&method.sig.generics);
method.attrs.retain(|a| !a.path.is_ident("version"));
method.attrs.retain(|a| !a.path().is_ident("version"));
fold::fold_trait_item_method(self, method)
fold::fold_trait_item_fn(self, method)
}
fn fold_item_trait(&mut self, mut trait_def: ItemTrait) -> ItemTrait {
@@ -154,7 +154,7 @@ fn impl_trait_for_externalities(trait_def: &ItemTrait, is_wasm_only: bool) -> Re
let interface = get_runtime_interface(trait_def)?;
let methods = interface.all_versions().map(|(version, method)| {
let mut cloned = (*method).clone();
cloned.attrs.retain(|a| !a.path.is_ident("version"));
cloned.attrs.retain(|a| !a.path().is_ident("version"));
cloned.sig.ident = create_function_ident_with_version(&cloned.sig.ident, version);
cloned
});
@@ -21,7 +21,7 @@ use proc_macro2::{Span, TokenStream};
use syn::{
parse::Parse, parse_quote, spanned::Spanned, token, Error, FnArg, Ident, ItemTrait, LitInt,
Pat, PatType, Result, Signature, TraitItem, TraitItemMethod, Type,
Pat, PatType, Result, Signature, TraitItem, TraitItemFn, Type,
};
use proc_macro_crate::{crate_name, FoundCrate};
@@ -41,23 +41,23 @@ mod attributes {
/// A concrete, specific version of a runtime interface function.
pub struct RuntimeInterfaceFunction {
item: TraitItemMethod,
item: TraitItemFn,
should_trap_on_return: bool,
}
impl std::ops::Deref for RuntimeInterfaceFunction {
type Target = TraitItemMethod;
type Target = TraitItemFn;
fn deref(&self) -> &Self::Target {
&self.item
}
}
impl RuntimeInterfaceFunction {
fn new(item: &TraitItemMethod) -> Result<Self> {
fn new(item: &TraitItemFn) -> Result<Self> {
let mut item = item.clone();
let mut should_trap_on_return = false;
item.attrs.retain(|attr| {
if attr.path.is_ident("trap_on_return") {
if attr.path().is_ident("trap_on_return") {
should_trap_on_return = true;
false
} else {
@@ -87,7 +87,7 @@ struct RuntimeInterfaceFunctionSet {
}
impl RuntimeInterfaceFunctionSet {
fn new(version: VersionAttribute, trait_item: &TraitItemMethod) -> Result<Self> {
fn new(version: VersionAttribute, trait_item: &TraitItemFn) -> Result<Self> {
Ok(Self {
latest_version_to_call: version.is_callable().then(|| version.version),
versions: BTreeMap::from([(
@@ -115,11 +115,7 @@ impl RuntimeInterfaceFunctionSet {
}
/// Add a different version of the function.
fn add_version(
&mut self,
version: VersionAttribute,
trait_item: &TraitItemMethod,
) -> Result<()> {
fn add_version(&mut self, version: VersionAttribute, trait_item: &TraitItemFn) -> Result<()> {
if let Some(existing_item) = self.versions.get(&version.version) {
let mut err = Error::new(trait_item.span(), "Duplicated version attribute");
err.combine(Error::new(
@@ -275,9 +271,9 @@ pub fn get_function_argument_types_ref_and_mut(
}
/// Returns an iterator over all trait methods for the given trait definition.
fn get_trait_methods(trait_def: &ItemTrait) -> impl Iterator<Item = &TraitItemMethod> {
fn get_trait_methods(trait_def: &ItemTrait) -> impl Iterator<Item = &TraitItemFn> {
trait_def.items.iter().filter_map(|i| match i {
TraitItem::Method(ref method) => Some(method),
TraitItem::Fn(ref method) => Some(method),
_ => None,
})
}
@@ -326,10 +322,10 @@ impl Parse for VersionAttribute {
}
/// Return [`VersionAttribute`], if present.
fn get_item_version(item: &TraitItemMethod) -> Result<Option<VersionAttribute>> {
fn get_item_version(item: &TraitItemFn) -> Result<Option<VersionAttribute>> {
item.attrs
.iter()
.find(|attr| attr.path.is_ident("version"))
.find(|attr| attr.path().is_ident("version"))
.map(|attr| attr.parse_args())
.transpose()
}