From 19d6bbb019f6bb9433268f946d7a1603dbf9ceff Mon Sep 17 00:00:00 2001 From: 0x009922 <43530070+0x009922@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:39:20 +0900 Subject: [PATCH 1/4] fix: address `check-cfg` warnings + chores Signed-off-by: 0x009922 <43530070+0x009922@users.noreply.github.com> --- Cargo.toml | 12 +++-- crates/iroha_crypto/src/lib.rs | 1 - crates/iroha_data_model/src/lib.rs | 1 - crates/iroha_derive/tests/ui.rs | 1 - crates/iroha_telemetry/Cargo.toml | 2 +- crates/iroha_telemetry_derive/Cargo.toml | 4 ++ crates/iroha_telemetry_derive/src/lib.rs | 44 +++++++++++-------- wasm_samples/default_executor/src/lib.rs | 1 - .../executor_with_migration_fail/src/lib.rs | 1 - .../query_assets_and_save_cursor/src/lib.rs | 2 - 10 files changed, 40 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f1e82af249e..9b1e540201c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -128,9 +128,9 @@ mv = { version = "0.1.0" } [workspace.lints] rustdoc.private_doc_tests = "deny" -rust.future_incompatible = {level = "deny", priority = -1 } -rust.nonstandard_style = {level = "deny", priority = -1 } -rust.rust_2018_idioms = {level = "deny", priority = -1 } +rust.future_incompatible = { level = "deny", priority = -1 } +rust.nonstandard_style = { level = "deny", priority = -1 } +rust.rust_2018_idioms = { level = "deny", priority = -1 } rust.unused = { level = "deny", priority = -1 } rust.anonymous_parameters = "deny" @@ -149,6 +149,12 @@ rust.single_use_lifetimes = "warn" rust.unused_lifetimes = "warn" # TODO: reenable # rust.unsafe_op_in_unsafe_fn = "deny" +rust.unexpected_cfgs = { level = "warn", check-cfg = [ + # FIXME: https://github.com/hyperledger/iroha/issues/3102 + 'cfg(feature, values("ffi_import"))', + # FIXME: was never supported + 'cfg(coverage)' +] } # pedantic clippy.pedantic = { level = "warn", priority = -1 } diff --git a/crates/iroha_crypto/src/lib.rs b/crates/iroha_crypto/src/lib.rs index 6c15aa8ad2e..939c707d3a4 100755 --- a/crates/iroha_crypto/src/lib.rs +++ b/crates/iroha_crypto/src/lib.rs @@ -995,7 +995,6 @@ mod ffi { } // NOTE: Makes sure that only one `dealloc` is exported per generated dynamic library - #[cfg(any(crate_type = "dylib", crate_type = "cdylib"))] #[cfg(all(feature = "ffi_export", not(feature = "ffi_import")))] mod dylib { #[cfg(not(feature = "std"))] diff --git a/crates/iroha_data_model/src/lib.rs b/crates/iroha_data_model/src/lib.rs index b0f296f2845..a74a339f478 100644 --- a/crates/iroha_data_model/src/lib.rs +++ b/crates/iroha_data_model/src/lib.rs @@ -468,7 +468,6 @@ mod ffi { } // NOTE: Makes sure that only one `dealloc` is exported per generated dynamic library - #[cfg(any(crate_type = "dylib", crate_type = "cdylib"))] #[cfg(all(feature = "ffi_export", not(feature = "ffi_import")))] mod dylib { #[cfg(not(feature = "std"))] diff --git a/crates/iroha_derive/tests/ui.rs b/crates/iroha_derive/tests/ui.rs index f85c931983c..f15eb517c30 100644 --- a/crates/iroha_derive/tests/ui.rs +++ b/crates/iroha_derive/tests/ui.rs @@ -1,4 +1,3 @@ -#![cfg(not(coverage))] use trybuild::TestCases; #[test] diff --git a/crates/iroha_telemetry/Cargo.toml b/crates/iroha_telemetry/Cargo.toml index 0688b839cf7..99dea48ec01 100644 --- a/crates/iroha_telemetry/Cargo.toml +++ b/crates/iroha_telemetry/Cargo.toml @@ -15,7 +15,7 @@ workspace = true # Should not be enabled on production builds. dev-telemetry = [] # Export Prometheus metrics. See https://prometheus.io/. -metric-instrumentation = [] +metric-instrumentation = ["iroha_telemetry_derive/metric-instrumentation"] [dependencies] iroha_telemetry_derive = { path = "../iroha_telemetry_derive" } diff --git a/crates/iroha_telemetry_derive/Cargo.toml b/crates/iroha_telemetry_derive/Cargo.toml index 3a4f7e9fe21..be453c38274 100644 --- a/crates/iroha_telemetry_derive/Cargo.toml +++ b/crates/iroha_telemetry_derive/Cargo.toml @@ -18,6 +18,10 @@ is-it-maintained-issue-resolution = { repository = "https://github.com/hyperledg is-it-maintained-open-issues = { repository = "https://github.com/hyperledger/iroha" } maintenance = { status = "actively-developed" } +[features] +# FIXME: it doesn't work https://github.com/hyperledger/iroha/issues/5134 +metric-instrumentation = [] + [dependencies] syn = { workspace = true } quote = { workspace = true } diff --git a/crates/iroha_telemetry_derive/src/lib.rs b/crates/iroha_telemetry_derive/src/lib.rs index 15c434f4598..d982766f733 100644 --- a/crates/iroha_telemetry_derive/src/lib.rs +++ b/crates/iroha_telemetry_derive/src/lib.rs @@ -1,6 +1,9 @@ //! Attribute-like macro for instrumenting `isi` for `prometheus` //! metrics. See [`macro@metrics`] for more details. +// FIXME +#![allow(unused)] + use iroha_macro_utils::Emitter; use manyhow::{emit, manyhow, Result}; use proc_macro2::TokenStream; @@ -181,12 +184,16 @@ pub fn metrics(attr: TokenStream, item: TokenStream) -> TokenStream { return emitter.finish_token_stream(); }; - let result = impl_metrics(&mut emitter, &metric_specs, &func); + let result = impl_metrics(&mut emitter, metric_specs, &func); emitter.finish_token_stream_with(result) } -fn impl_metrics(emitter: &mut Emitter, _specs: &MetricSpecs, func: &syn::ItemFn) -> TokenStream { +fn impl_metrics( + emitter: &mut Emitter, + #[cfg_attr(not(feature = "metric-instrumentation"), allow(unused))] specs: MetricSpecs, + func: &syn::ItemFn, +) -> TokenStream { let syn::ItemFn { attrs, vis, @@ -224,7 +231,8 @@ fn impl_metrics(emitter: &mut Emitter, _specs: &MetricSpecs, func: &syn::ItemFn) // Again this may seem fragile, but if we move the metrics from // the `WorldStateView`, we'd need to refactor many things anyway - let _metric_arg_ident = match arg_metrics(&sig.inputs) { + #[cfg_attr(not(feature = "metric-instrumentation"), allow(unused_variables))] + let metric_arg_ident = match arg_metrics(&sig.inputs) { Ok(ident) => ident, Err(args) => { emit!( @@ -237,9 +245,9 @@ fn impl_metrics(emitter: &mut Emitter, _specs: &MetricSpecs, func: &syn::ItemFn) }; #[cfg(feature = "metric-instrumentation")] - let res = { - let (totals, successes, times) = write_metrics(_metric_arg_ident, _specs); - quote!( + { + let (totals, successes, times) = write_metrics(metric_arg_ident, specs); + return quote!( #(#attrs)* #vis #sig { let _closure = || #block; let started_at = std::time::Instant::now(); @@ -256,14 +264,14 @@ fn impl_metrics(emitter: &mut Emitter, _specs: &MetricSpecs, func: &syn::ItemFn) }; #[cfg(not(feature = "metric-instrumentation"))] - let res = quote!( + quote!( #(#attrs)* #vis #sig { #block } - ); - res + ) } +// FIXME: metrics were removed https://github.com/hyperledger/iroha/issues/5134 #[cfg(feature = "metric-instrumentation")] fn write_metrics( metric_arg_ident: proc_macro2::Ident, @@ -271,19 +279,19 @@ fn write_metrics( ) -> (TokenStream, TokenStream, TokenStream) { let inc_metric = |spec: &MetricSpec, kind: &str| { quote!( - #metric_arg_ident - .metrics - .isi - .with_label_values( &[#spec, #kind ]).inc(); + // #metric_arg_ident + // .metrics + // .isi + // .with_label_values( &[#spec, #kind ]).inc(); ) }; let track_time = |spec: &MetricSpec| { quote!( - #metric_arg_ident - .metrics - .isi_times - .with_label_values( &[#spec]) - .observe(started_at.elapsed().as_millis() as f64); + // #metric_arg_ident + // .metrics + // .isi_times + // .with_label_values( &[#spec]) + // .observe(started_at.elapsed().as_millis() as f64); ) }; let totals: TokenStream = specs diff --git a/wasm_samples/default_executor/src/lib.rs b/wasm_samples/default_executor/src/lib.rs index 4e3d4a282d2..738ad185fa4 100644 --- a/wasm_samples/default_executor/src/lib.rs +++ b/wasm_samples/default_executor/src/lib.rs @@ -2,7 +2,6 @@ #![no_std] -extern crate alloc; #[cfg(not(test))] extern crate panic_halt; diff --git a/wasm_samples/executor_with_migration_fail/src/lib.rs b/wasm_samples/executor_with_migration_fail/src/lib.rs index 6417ccff63c..1bab3082384 100644 --- a/wasm_samples/executor_with_migration_fail/src/lib.rs +++ b/wasm_samples/executor_with_migration_fail/src/lib.rs @@ -2,7 +2,6 @@ #![no_std] -extern crate alloc; #[cfg(not(test))] extern crate panic_halt; diff --git a/wasm_samples/query_assets_and_save_cursor/src/lib.rs b/wasm_samples/query_assets_and_save_cursor/src/lib.rs index 7026bdf506a..d7a8784680d 100644 --- a/wasm_samples/query_assets_and_save_cursor/src/lib.rs +++ b/wasm_samples/query_assets_and_save_cursor/src/lib.rs @@ -5,8 +5,6 @@ #[cfg(not(test))] extern crate panic_halt; -extern crate alloc; - use dlmalloc::GlobalDlmalloc; use iroha_smart_contract::{ data_model::query::{ From cd1c561b0113cd7d9602560542d09740485b4f84 Mon Sep 17 00:00:00 2001 From: 0x009922 <43530070+0x009922@users.noreply.github.com> Date: Wed, 9 Oct 2024 12:38:05 +0900 Subject: [PATCH 2/4] fix: comment out more `metric-instrumentation` code Signed-off-by: 0x009922 <43530070+0x009922@users.noreply.github.com> --- crates/iroha_telemetry_derive/src/lib.rs | 56 ++++++++++++------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/crates/iroha_telemetry_derive/src/lib.rs b/crates/iroha_telemetry_derive/src/lib.rs index d982766f733..d5febea0894 100644 --- a/crates/iroha_telemetry_derive/src/lib.rs +++ b/crates/iroha_telemetry_derive/src/lib.rs @@ -244,26 +244,26 @@ fn impl_metrics( } }; - #[cfg(feature = "metric-instrumentation")] - { - let (totals, successes, times) = write_metrics(metric_arg_ident, specs); - return quote!( - #(#attrs)* #vis #sig { - let _closure = || #block; - let started_at = std::time::Instant::now(); - - #totals - let res = _closure(); - - #times - if let Ok(_) = res { - #successes - }; - res - }); - }; + // #[cfg(feature = "metric-instrumentation")] + // { + // let (totals, successes, times) = write_metrics(metric_arg_ident, specs); + // quote!( + // #(#attrs)* #vis #sig { + // let closure = || #block; + // let started_at = std::time::Instant::now(); + // + // #totals + // let res = closure(); + // + // #times + // if let Ok(_) = res { + // #successes + // }; + // res + // }) + // } - #[cfg(not(feature = "metric-instrumentation"))] + // #[cfg(not(feature = "metric-instrumentation"))] quote!( #(#attrs)* #vis #sig { #block @@ -279,19 +279,19 @@ fn write_metrics( ) -> (TokenStream, TokenStream, TokenStream) { let inc_metric = |spec: &MetricSpec, kind: &str| { quote!( - // #metric_arg_ident - // .metrics - // .isi - // .with_label_values( &[#spec, #kind ]).inc(); + #metric_arg_ident + .metrics + .isi + .with_label_values( &[#spec, #kind ]).inc(); ) }; let track_time = |spec: &MetricSpec| { quote!( - // #metric_arg_ident - // .metrics - // .isi_times - // .with_label_values( &[#spec]) - // .observe(started_at.elapsed().as_millis() as f64); + #metric_arg_ident + .metrics + .isi_times + .with_label_values( &[#spec]) + .observe(started_at.elapsed().as_millis() as f64); ) }; let totals: TokenStream = specs From a2ba893359932296b22dabed9eee52b6e8b5d6a7 Mon Sep 17 00:00:00 2001 From: 0x009922 <43530070+0x009922@users.noreply.github.com> Date: Wed, 9 Oct 2024 12:45:02 +0900 Subject: [PATCH 3/4] chore: put issue link Signed-off-by: 0x009922 <43530070+0x009922@users.noreply.github.com> --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9b1e540201c..9bda2f9f566 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -152,8 +152,8 @@ rust.unused_lifetimes = "warn" rust.unexpected_cfgs = { level = "warn", check-cfg = [ # FIXME: https://github.com/hyperledger/iroha/issues/3102 'cfg(feature, values("ffi_import"))', - # FIXME: was never supported - 'cfg(coverage)' + # FIXME: was never supported https://github.com/hyperledger/iroha/issues/5139 + # 'cfg(coverage)' ] } # pedantic From 4fee2ef85c9fb1d8f2eebe2f28488bd237ea4ffc Mon Sep 17 00:00:00 2001 From: 0x009922 <43530070+0x009922@users.noreply.github.com> Date: Wed, 9 Oct 2024 13:24:57 +0900 Subject: [PATCH 4/4] fix: restore `cfg(coverage)` usage Signed-off-by: 0x009922 <43530070+0x009922@users.noreply.github.com> --- Cargo.toml | 4 ++-- crates/iroha_derive/tests/ui.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9bda2f9f566..228caded553 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -152,8 +152,8 @@ rust.unused_lifetimes = "warn" rust.unexpected_cfgs = { level = "warn", check-cfg = [ # FIXME: https://github.com/hyperledger/iroha/issues/3102 'cfg(feature, values("ffi_import"))', - # FIXME: was never supported https://github.com/hyperledger/iroha/issues/5139 - # 'cfg(coverage)' + # It is set by `cargo-llvm-cov` + 'cfg(coverage)' ] } # pedantic diff --git a/crates/iroha_derive/tests/ui.rs b/crates/iroha_derive/tests/ui.rs index f15eb517c30..f85c931983c 100644 --- a/crates/iroha_derive/tests/ui.rs +++ b/crates/iroha_derive/tests/ui.rs @@ -1,3 +1,4 @@ +#![cfg(not(coverage))] use trybuild::TestCases; #[test]