Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: address check-cfg warnings + chores #5135

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"))',
# It is set by `cargo-llvm-cov`
'cfg(coverage)'
] }

# pedantic
clippy.pedantic = { level = "warn", priority = -1 }
Expand Down
1 change: 0 additions & 1 deletion crates/iroha_crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
1 change: 0 additions & 1 deletion crates/iroha_data_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_telemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 4 additions & 0 deletions crates/iroha_telemetry_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
58 changes: 33 additions & 25 deletions crates/iroha_telemetry_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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!(
Expand All @@ -236,34 +244,34 @@ 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!(
#(#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"))]
let res = quote!(
// #[cfg(not(feature = "metric-instrumentation"))]
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,
Expand Down
1 change: 0 additions & 1 deletion wasm_samples/default_executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![no_std]

extern crate alloc;
#[cfg(not(test))]
extern crate panic_halt;

Expand Down
1 change: 0 additions & 1 deletion wasm_samples/executor_with_migration_fail/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![no_std]

extern crate alloc;
#[cfg(not(test))]
extern crate panic_halt;

Expand Down
2 changes: 0 additions & 2 deletions wasm_samples/query_assets_and_save_cursor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#[cfg(not(test))]
extern crate panic_halt;

extern crate alloc;

use dlmalloc::GlobalDlmalloc;
use iroha_smart_contract::{
data_model::query::{
Expand Down
Loading