Skip to content

Commit

Permalink
[refactor] hyperledger-iroha#3911: Migrate iroha_futures_derive to sy…
Browse files Browse the repository at this point in the history
…n 2.0

Also, a drive-by fix to silence the "unused" lints in some other feature combinations

Signed-off-by: Nikita Strygin <dcnick3@users.noreply.github.com>
  • Loading branch information
DCNick3 committed Sep 22, 2023
1 parent dc5b0f3 commit 9981931
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion crypto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! This module contains structures and implementations related to the cryptographic parts of the Iroha.
#![cfg_attr(not(feature = "std"), no_std)]
// in no_std some code gets cfg-ed out, so we silence the warnings
#![cfg_attr(not(feature = "std"), allow(unused, unused_tuple_struct_fields))]
#![allow(clippy::arithmetic_side_effects)]

#[cfg(not(feature = "std"))]
Expand Down Expand Up @@ -120,6 +119,10 @@ impl FromStr for Algorithm {

/// Options for key generation
#[cfg(not(feature = "ffi_import"))]
#[cfg_attr(
any(not(feature = "std"), feature = "ffi_import"),
allow(unused_tuple_struct_fields)
)]
#[derive(Debug, Clone)]
enum KeyGenOption {
/// Use seed
Expand Down
4 changes: 3 additions & 1 deletion crypto/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ use ursa::{
},
};

use crate::{ffi, Error, PublicKey};
#[cfg(any(feature = "std", feature = "import_ffi"))]
use crate::Error;
use crate::{ffi, PublicKey};
#[cfg(feature = "std")]
use crate::{HashOf, KeyPair};

Expand Down
6 changes: 5 additions & 1 deletion data_model/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
use alloc::{boxed::Box, format, string::String, vec::Vec};
use core::{fmt::Display, time::Duration};

#[cfg(feature = "std")]
#[cfg(feature = "transparent_api")]
use iroha_crypto::KeyPair;

use derive_more::Display;
use getset::Getters;
use iroha_crypto::{HashOf, KeyPair, MerkleTree, SignaturesOf};
use iroha_crypto::{HashOf, MerkleTree, SignaturesOf};
use iroha_data_model_derive::model;
use iroha_macro::FromVariant;
use iroha_schema::IntoSchema;
Expand Down
4 changes: 2 additions & 2 deletions futures/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ telemetry = []
proc-macro = true

[dependencies]
syn = { workspace = true, features = ["default", "full"] }
syn2 = { workspace = true, features = ["default", "full"] }
quote = { workspace = true }
proc-macro2 = { workspace = true }
proc-macro-error = { workspace = true }
manyhow = { workspace = true }
30 changes: 16 additions & 14 deletions futures/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
clippy::std_instead_of_core
)]

use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use proc_macro_error::{abort, proc_macro_error};
use manyhow::{bail, manyhow, Result};
use proc_macro2::TokenStream;
use quote::quote;
use syn::{parse_macro_input, Generics, ItemFn, ReturnType, Signature};
use syn2::{Generics, ItemFn, ReturnType, Signature};

fn impl_telemetry_future(
ItemFn {
Expand All @@ -19,7 +18,7 @@ fn impl_telemetry_future(
sig,
block,
}: ItemFn,
) -> TokenStream2 {
) -> Result<TokenStream> {
let Signature {
asyncness,
ident,
Expand All @@ -34,8 +33,8 @@ fn impl_telemetry_future(
} = sig;

if asyncness.is_none() {
abort!(
asyncness,
bail!(
ident,
"Only async functions can be instrumented for `telemetry_future`"
);
}
Expand All @@ -45,26 +44,29 @@ fn impl_telemetry_future(
ReturnType::Default => quote! { () },
};

quote! {
Ok(quote! {
#(#attrs)*
#vis async fn #ident < #params > ( #inputs ) -> #output
#where_clause
{
let __future_name = concat!(module_path!(), "::", stringify!(#ident));
iroha_futures::TelemetryFuture::new(async #block, __future_name).await
}
}
})
}

/// Macro for wrapping future for getting telemetry info about poll times and numbers
#[proc_macro_error]
#[manyhow]
#[proc_macro_attribute]
pub fn telemetry_future(_args: TokenStream, input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as ItemFn);
pub fn telemetry_future(args: TokenStream, input: TokenStream) -> Result<TokenStream> {
if !args.is_empty() {
bail!(args, "Unexpected arguments")
}

let input = syn2::parse2(input)?;
if cfg!(feature = "telemetry") {
impl_telemetry_future(input)
} else {
quote! { #input }
Ok(quote! { #input })
}
.into()
}

0 comments on commit 9981931

Please sign in to comment.