diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..8c27f09 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,81 @@ +# add the below section to `.cargo/config.toml` + +[target.'cfg(all())'] +rustflags = [ + # BEGIN - Embark standard lints v6 for Rust 1.55+ + # do not change or add/remove here, but one can add exceptions after this section + # for more info see: + "-Dunsafe_code", + "-Wclippy::all", + "-Wclippy::await_holding_lock", + "-Wclippy::char_lit_as_u8", + "-Wclippy::checked_conversions", + "-Wclippy::dbg_macro", + "-Wclippy::debug_assert_with_mut_call", + "-Wclippy::doc_markdown", + "-Wclippy::empty_enum", + "-Wclippy::enum_glob_use", + "-Wclippy::exit", + "-Wclippy::expl_impl_clone_on_copy", + "-Wclippy::explicit_deref_methods", + "-Wclippy::explicit_into_iter_loop", + "-Wclippy::fallible_impl_from", + "-Wclippy::filter_map_next", + "-Wclippy::flat_map_option", + "-Wclippy::float_cmp_const", + "-Wclippy::fn_params_excessive_bools", + "-Wclippy::from_iter_instead_of_collect", + "-Wclippy::if_let_mutex", + "-Wclippy::implicit_clone", + "-Wclippy::imprecise_flops", + "-Wclippy::inefficient_to_string", + "-Wclippy::invalid_upcast_comparisons", + "-Wclippy::large_digit_groups", + "-Wclippy::large_stack_arrays", + "-Wclippy::large_types_passed_by_value", + "-Wclippy::let_unit_value", + "-Wclippy::linkedlist", + "-Wclippy::lossy_float_literal", + "-Wclippy::macro_use_imports", + "-Wclippy::manual_ok_or", + "-Wclippy::map_err_ignore", + "-Wclippy::map_flatten", + "-Wclippy::map_unwrap_or", + "-Wclippy::match_on_vec_items", + "-Wclippy::match_same_arms", + "-Wclippy::match_wild_err_arm", + "-Wclippy::match_wildcard_for_single_variants", + "-Wclippy::mem_forget", + "-Wclippy::mismatched_target_os", + "-Wclippy::missing_enforced_import_renames", + "-Wclippy::mut_mut", + "-Wclippy::mutex_integer", + "-Wclippy::needless_borrow", + "-Wclippy::needless_continue", + "-Wclippy::needless_for_each", + "-Wclippy::option_option", + "-Wclippy::path_buf_push_overwrite", + "-Wclippy::ptr_as_ptr", + "-Wclippy::rc_mutex", + "-Wclippy::ref_option_ref", + "-Wclippy::rest_pat_in_fully_bound_structs", + "-Wclippy::same_functions_in_if_condition", + "-Wclippy::semicolon_if_nothing_returned", + "-Wclippy::single_match_else", + "-Wclippy::string_add_assign", + "-Wclippy::string_add", + "-Wclippy::string_lit_as_bytes", + "-Wclippy::string_to_string", + "-Wclippy::todo", + "-Wclippy::trait_duplication_in_bounds", + "-Wclippy::unimplemented", + "-Wclippy::unnested_or_patterns", + "-Wclippy::unused_self", + "-Wclippy::useless_transmute", + "-Wclippy::verbose_file_reads", + "-Wclippy::zero_sized_map_values", + "-Wfuture_incompatible", + "-Wnonstandard_style", + "-Wrust_2018_idioms", + # END - Embark standard lints v6 for Rust 1.55+ +] diff --git a/crates/cervo-asset/src/lib.rs b/crates/cervo-asset/src/lib.rs index a726cd6..7d9a93d 100644 --- a/crates/cervo-asset/src/lib.rs +++ b/crates/cervo-asset/src/lib.rs @@ -26,7 +26,7 @@ use std::io::{Cursor, Read, Write}; /// Magic used to ensure assets are valid. pub const MAGIC: [u8; 4] = [b'C', b'R', b'V', b'O']; -/// AssetKind denotes what kind of policy is contained inside an [`AssetData`]. +/// `AssetKind` denotes what kind of policy is contained inside an [`AssetData`]. #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u8)] pub enum AssetKind { @@ -66,7 +66,7 @@ pub struct AssetData { } impl AssetData { - /// Create a new AssetData from parts. + /// Create a new `AssetData` from parts. /// /// Note: Does not validate the data. pub fn new>>(kind: AssetKind, data: Data) -> Self { @@ -76,7 +76,7 @@ impl AssetData { } } - /// Create a new AssetData from a reader and a kind. + /// Create a new `AssetData` from a reader and a kind. /// /// Note: Does not validate the data. pub fn from_reader(kind: AssetKind, mut reader: Reader) -> Result { @@ -146,7 +146,7 @@ impl AssetData { /// Load a simple unbatching inferer from this asset. /// - /// See ['BasicInferer'] for more details. + /// See ['`BasicInferer`'] for more details. pub fn load_basic(&self) -> Result { let mut cursor = Cursor::new(&self.data); match self.kind { diff --git a/crates/cervo-asset/tests/helpers.rs b/crates/cervo-asset/tests/helpers.rs index 804f3b4..ea4be75 100644 --- a/crates/cervo-asset/tests/helpers.rs +++ b/crates/cervo-asset/tests/helpers.rs @@ -20,7 +20,10 @@ pub fn get_file(name: &'static str) -> std::io::Result { std::fs::File::open(path) } -pub fn build_inputs_from_desc(count: u64, inputs: &[(String, Vec)]) -> HashMap { +pub fn build_inputs_from_desc( + count: u64, + inputs: &[(String, Vec)], +) -> HashMap> { (0..count) .map(|idx| { ( diff --git a/crates/cervo-core/src/batcher.rs b/crates/cervo-core/src/batcher.rs index f06d9e4..33b6817 100644 --- a/crates/cervo-core/src/batcher.rs +++ b/crates/cervo-core/src/batcher.rs @@ -117,9 +117,12 @@ impl Batcher { } } - Ok(HashMap::from_iter( - self.scratch.ids.drain(..).zip(outputs.into_iter()), - )) + Ok(self + .scratch + .ids + .drain(..) + .zip(outputs.into_iter()) + .collect::<_>()) } /// Check if there is any data to run on here. diff --git a/crates/cervo-core/src/batcher/scratch.rs b/crates/cervo-core/src/batcher/scratch.rs index 185ffdf..aa08103 100644 --- a/crates/cervo-core/src/batcher/scratch.rs +++ b/crates/cervo-core/src/batcher/scratch.rs @@ -83,7 +83,7 @@ impl ScratchPad { .iter() .map(|(name, shape)| { let count = shape.iter().product(); - ScratchPadData::new(name.to_owned(), count, capacity) + ScratchPadData::new(name.clone(), count, capacity) }) .collect(); @@ -91,7 +91,7 @@ impl ScratchPad { .iter() .map(|(name, shape)| { let count = shape.iter().product(); - ScratchPadData::new(name.to_owned(), count, capacity) + ScratchPadData::new(name.clone(), count, capacity) }) .collect(); diff --git a/crates/cervo-core/src/batcher/wrapper.rs b/crates/cervo-core/src/batcher/wrapper.rs index e9a4aeb..67280cb 100644 --- a/crates/cervo-core/src/batcher/wrapper.rs +++ b/crates/cervo-core/src/batcher/wrapper.rs @@ -10,7 +10,7 @@ use std::collections::HashMap; /// data-insertion and execution, which generally improves /// performance. /// -/// Can be easily constructed using [InfererExt::into_batched](crate::prelude::InfererExt::into_batched). +/// Can be easily constructed using [`InfererExt::into_batched`](crate::prelude::InfererExt::into_batched). pub struct Batched { inner: Inf, batcher: Batcher, diff --git a/crates/cervo-core/src/epsilon.rs b/crates/cervo-core/src/epsilon.rs index df03bb2..09aded7 100644 --- a/crates/cervo-core/src/epsilon.rs +++ b/crates/cervo-core/src/epsilon.rs @@ -14,7 +14,7 @@ use perchance::PerchanceContext; use rand::thread_rng; use rand_distr::{Distribution, StandardNormal}; -/// NoiseGenerators are consumed by the [`EpsilonInjector`] by generating noise sampled for a standard normal +/// `NoiseGenerators` are consumed by the [`EpsilonInjector`] by generating noise sampled for a standard normal /// distribution. Custom noise-generators can be implemented and passed via [`EpsilonInjector::with_generator`]. pub trait NoiseGenerator { fn generate(&self, count: usize, out: &mut [f32]); @@ -89,7 +89,7 @@ impl NoiseGenerator for LowQualityNoiseGenerator { /// use-cases. /// /// This implementation uses [`rand::thread_rng`] internally as the entropy source, and uses the optimized -/// StandardNormal distribution for sampling. +/// `StandardNormal` distribution for sampling. pub struct HighQualityNoiseGenerator { normal_distribution: StandardNormal, } diff --git a/crates/cervo-core/src/inferer.rs b/crates/cervo-core/src/inferer.rs index d0ef2c3..b6e2bd4 100644 --- a/crates/cervo-core/src/inferer.rs +++ b/crates/cervo-core/src/inferer.rs @@ -195,10 +195,10 @@ pub trait InfererExt: Inferer + Sized { } /// Execute the model on the provided pre-batched data. - fn infer_single<'this>(&'this self, input: State<'_>) -> Result, anyhow::Error> - where - Self: Sized, - { + fn infer_single<'this>( + &'this self, + input: State<'_>, + ) -> Result, anyhow::Error> { let mut batcher = Batcher::new_sized(self, 1); batcher.push(0, input)?; diff --git a/crates/cervo-core/src/model_api.rs b/crates/cervo-core/src/model_api.rs index 1c7a3ed..60722c6 100644 --- a/crates/cervo-core/src/model_api.rs +++ b/crates/cervo-core/src/model_api.rs @@ -9,7 +9,7 @@ use tract_core::{model::TypedModel, tract_data::TractResult}; use tract_hir::{infer::Factoid, prelude::InferenceModel}; -/// The ModelApi describes the inputs and outputs for a model. +/// The `ModelApi` describes the inputs and outputs for a model. pub struct ModelApi { /// The named model inputs. pub inputs: Vec<(String, Vec)>, diff --git a/crates/cervo-core/tests/batcher.rs b/crates/cervo-core/tests/batcher.rs index 98c6a86..24ab898 100644 --- a/crates/cervo-core/tests/batcher.rs +++ b/crates/cervo-core/tests/batcher.rs @@ -8,7 +8,7 @@ use cervo_core::prelude::{Batcher, Inferer, InfererExt, State}; struct TestInferer< B: Fn(usize) -> usize, - R: Fn(cervo_core::batcher::ScratchPadView) -> anyhow::Result<(), anyhow::Error>, + R: Fn(cervo_core::batcher::ScratchPadView<'_>) -> anyhow::Result<(), anyhow::Error>, > { batch_size: B, raw: R, @@ -19,7 +19,7 @@ struct TestInferer< impl Inferer for TestInferer where B: Fn(usize) -> usize, - R: Fn(cervo_core::batcher::ScratchPadView) -> anyhow::Result<(), anyhow::Error>, + R: Fn(cervo_core::batcher::ScratchPadView<'_>) -> anyhow::Result<(), anyhow::Error>, { fn select_batch_size(&self, max_count: usize) -> usize { (self.batch_size)(max_count) @@ -27,7 +27,7 @@ where fn infer_raw( &self, - batch: cervo_core::batcher::ScratchPadView, + batch: cervo_core::batcher::ScratchPadView<'_>, ) -> anyhow::Result<(), anyhow::Error> { (self.raw)(batch) } @@ -278,7 +278,7 @@ fn test_values() { let r = batcher.execute(&inf).unwrap(); assert_eq!(r.len(), 4); - dbg!(&r); + let _ = &r; for (id, vals) in r { assert_eq!(vals.data["out"].len(), 11); assert_eq!(vals.data["out"][0], id as f32); diff --git a/crates/cervo-nnef/src/lib.rs b/crates/cervo-nnef/src/lib.rs index b804c54..b47717a 100644 --- a/crates/cervo-nnef/src/lib.rs +++ b/crates/cervo-nnef/src/lib.rs @@ -45,7 +45,7 @@ lazy_static::lazy_static! { /// ahead of time. pub fn init() { use lazy_static::LazyStatic; - NNEF::initialize(&NNEF) + NNEF::initialize(&NNEF); } /// Utility function to check if a file name is `.nnef.tar`. diff --git a/crates/cervo-nnef/tests/helpers.rs b/crates/cervo-nnef/tests/helpers.rs index 71d0193..c6c1d4e 100644 --- a/crates/cervo-nnef/tests/helpers.rs +++ b/crates/cervo-nnef/tests/helpers.rs @@ -19,7 +19,10 @@ pub fn get_file(name: &'static str) -> std::io::Result { std::fs::File::open(path) } -pub fn build_inputs_from_desc(count: u64, inputs: &[(String, Vec)]) -> HashMap { +pub fn build_inputs_from_desc( + count: u64, + inputs: &[(String, Vec)], +) -> HashMap> { (0..count) .map(|idx| { ( diff --git a/crates/cervo-onnx/src/lib.rs b/crates/cervo-onnx/src/lib.rs index db9a7d5..3d7f769 100644 --- a/crates/cervo-onnx/src/lib.rs +++ b/crates/cervo-onnx/src/lib.rs @@ -90,9 +90,7 @@ pub fn builder(read: T) -> InfererBuilder> { pub fn to_nnef(reader: &mut dyn Read, batch_size: Option) -> Result> { let mut model = model_for_reader(reader)?; - let batch = batch_size - .map(|v| v.to_dim()) - .unwrap_or_else(|| Symbol::from('N').to_dim()); + let batch = batch_size.map_or_else(|| Symbol::from('N').to_dim(), |v| v.to_dim()); let input_outlets = model.input_outlets()?.to_vec(); diff --git a/crates/cervo-onnx/tests/helpers.rs b/crates/cervo-onnx/tests/helpers.rs index 804f3b4..ea4be75 100644 --- a/crates/cervo-onnx/tests/helpers.rs +++ b/crates/cervo-onnx/tests/helpers.rs @@ -20,7 +20,10 @@ pub fn get_file(name: &'static str) -> std::io::Result { std::fs::File::open(path) } -pub fn build_inputs_from_desc(count: u64, inputs: &[(String, Vec)]) -> HashMap { +pub fn build_inputs_from_desc( + count: u64, + inputs: &[(String, Vec)], +) -> HashMap> { (0..count) .map(|idx| { ( diff --git a/crates/cervo-runtime/src/runtime.rs b/crates/cervo-runtime/src/runtime.rs index c967a6a..5feb787 100644 --- a/crates/cervo-runtime/src/runtime.rs +++ b/crates/cervo-runtime/src/runtime.rs @@ -135,7 +135,7 @@ impl Runtime { match res { Some(res) => { result.insert(ticket.1, res); - executed.push(ticket.1) + executed.push(ticket.1); } None => { non_executed.push(ticket); @@ -420,7 +420,7 @@ mod tests { let err = res.unwrap_err(); if let CervoError::OrphanedData(keys) = err { - assert_eq!(keys, vec![k]) + assert_eq!(keys, vec![k]); } else { panic!("expected CervoError::OrphanedData") } @@ -439,7 +439,7 @@ mod tests { let err = res.unwrap_err(); if let CervoError::OrphanedData(keys) = err { - assert_eq!(keys, vec![k]) + assert_eq!(keys, vec![k]); } else { panic!("expected CervoError::OrphanedData") } diff --git a/crates/cervo-runtime/src/state.rs b/crates/cervo-runtime/src/state.rs index 3fdc38a..b041173 100644 --- a/crates/cervo-runtime/src/state.rs +++ b/crates/cervo-runtime/src/state.rs @@ -96,12 +96,11 @@ impl ModelState { let elapsed = start.elapsed(); let mut timings = self.timings.borrow_mut(); - match timings.iter_mut().find(|b| b.size == 1) { - Some(bucket) => bucket.add(elapsed), - None => { - timings.push(TimingBucket::new(1, elapsed)); - timings.sort_by_key(|b| b.size); - } + if let Some(bucket) = timings.iter_mut().find(|b| b.size == 1) { + bucket.add(elapsed); + } else { + timings.push(TimingBucket::new(1, elapsed)); + timings.sort_by_key(|b| b.size); } Ok(res) @@ -123,12 +122,11 @@ impl ModelState { let elapsed = start.elapsed(); let mut timings = self.timings.borrow_mut(); - match timings.iter_mut().find(|b| b.size == batch_size) { - Some(bucket) => bucket.add(elapsed), - None => { - timings.push(TimingBucket::new(batch_size, elapsed)); - timings.sort_by_key(|b| b.size); - } + if let Some(bucket) = timings.iter_mut().find(|b| b.size == batch_size) { + bucket.add(elapsed); + } else { + timings.push(TimingBucket::new(batch_size, elapsed)); + timings.sort_by_key(|b| b.size); } Ok(res) diff --git a/crates/cervo-runtime/src/timing.rs b/crates/cervo-runtime/src/timing.rs index a308fde..68871ab 100644 --- a/crates/cervo-runtime/src/timing.rs +++ b/crates/cervo-runtime/src/timing.rs @@ -78,7 +78,7 @@ mod tests { #[test] fn initial_mean_initial_value() { let state = WelfordState::new(Duration::from_secs_f32(1.0)); - assert!(is_close(state.mean().as_secs_f32(), 1.0)) + assert!(is_close(state.mean().as_secs_f32(), 1.0)); } #[test] @@ -89,7 +89,7 @@ mod tests { state.update(Duration::from_secs_f32(1.0)); } - assert_eq!(state.mean().as_secs_f32(), 1.0) + assert_eq!(state.mean().as_secs_f32(), 1.0); } #[test] @@ -100,7 +100,7 @@ mod tests { state.update(Duration::from_secs_f32(v as f32)); } - assert_eq!(state.mean().as_secs_f32(), 4.5) + assert_eq!(state.mean().as_secs_f32(), 4.5); } #[test] @@ -111,6 +111,6 @@ mod tests { state.update(Duration::from_secs_f32(v as f32)); } - assert_eq!(state.mean().as_secs_f32(), 49.5) + assert_eq!(state.mean().as_secs_f32(), 49.5); } } diff --git a/crates/cervo/src/commands/describe.rs b/crates/cervo/src/commands/describe.rs index f8e5f46..5a213ff 100644 --- a/crates/cervo/src/commands/describe.rs +++ b/crates/cervo/src/commands/describe.rs @@ -22,13 +22,13 @@ pub(super) fn describe(config: DescribeArgs) -> Result<()> { let mut reader = File::open(&config.file)?; if cervo_nnef::is_nnef_tar(&config.file) { - println!("a NNEF file") + println!("a NNEF file"); } else { match config.file.extension().and_then(|ext| ext.to_str()) { Some("onnx") => println!("an ONNX file"), Some("crvo") => { let asset = AssetData::deserialize(&mut reader)?; - println!("a native cervo file containing {} data", asset.kind()) + println!("a native cervo file containing {} data", asset.kind()); } Some(other) => bail!("unknown file type {:?}", other), None => bail!("missing file extension {:?}", config.file),