From 2db74f9c0f4a8e0fee2a747b8479e0559b483e74 Mon Sep 17 00:00:00 2001 From: Edward Amsden Date: Wed, 27 Sep 2023 22:55:00 -0500 Subject: [PATCH] interpreter: address lints for fast hints --- rust/ares/src/hamt.rs | 4 ++-- rust/ares/src/interpreter.rs | 14 +++++++++----- rust/ares/src/jets/cold.rs | 34 +++++++++++++++------------------- rust/ares/src/jets/hot.rs | 7 ++++--- rust/ares/src/jets/warm.rs | 11 ++++++----- rust/ares/src/mem.rs | 7 +++---- rust/ares/src/serf.rs | 1 + 7 files changed, 40 insertions(+), 38 deletions(-) diff --git a/rust/ares/src/hamt.rs b/rust/ares/src/hamt.rs index 4d340dc..f4f8852 100644 --- a/rust/ares/src/hamt.rs +++ b/rust/ares/src/hamt.rs @@ -455,7 +455,7 @@ impl Preserve for Hamt { position += 1; continue 'check_stem; } - Some((Left(next_stem), idx)) => { + Some((Left(next_stem), _idx)) => { stack.struct_is_in(next_stem.buffer, next_stem.size()); assert!(traversal_depth <= 5); // will increment traversal_stack[traversal_depth - 1].as_mut().unwrap().1 = position + 1; @@ -463,7 +463,7 @@ impl Preserve for Hamt { traversal_depth += 1; continue 'check; } - Some((Right(leaf), idx)) => { + Some((Right(leaf), _idx)) => { stack.struct_is_in(leaf.buffer, leaf.len); for pair in leaf.to_mut_slice().iter() { pair.0.assert_in_stack(stack); diff --git a/rust/ares/src/interpreter.rs b/rust/ares/src/interpreter.rs index abe09cc..536d62c 100644 --- a/rust/ares/src/interpreter.rs +++ b/rust/ares/src/interpreter.rs @@ -1,5 +1,5 @@ use crate::hamt::Hamt; -use crate::jets; + use crate::jets::cold::Cold; use crate::jets::hot::Hot; use crate::jets::warm::Warm; @@ -761,13 +761,15 @@ fn push_formula(stack: &mut NockStack, formula: Noun, tail: bool) { /** Note: axis must fit in a direct atom */ pub fn raw_slot(noun: Noun, axis: u64) -> Noun { - slot(noun, &BitSlice::from_element(&axis)) + slot(noun, BitSlice::from_element(&axis)) } +#[allow(clippy::result_unit_err)] pub fn raw_slot_result(noun: Noun, axis: u64) -> Result { - slot_result(noun, &BitSlice::from_element(&axis)) + slot_result(noun, BitSlice::from_element(&axis)) } +#[allow(clippy::result_unit_err)] pub fn slot_result(mut noun: Noun, axis: &BitSlice) -> Result { let mut cursor = if let Some(x) = axis.last_one() { Ok(x) @@ -866,10 +868,10 @@ pub fn inc(stack: &mut NockStack, atom: Atom) -> Atom { /** Match hints which apply before the formula is evaluated */ fn match_pre_hint( stack: &mut NockStack, - newt: &mut Option<&mut Newt>, + _newt: &mut Option<&mut Newt>, subject: Noun, cell: Cell, - formula: Noun, + _formula: Noun, cache: &Hamt, ) -> Result { let direct = cell.head().as_direct()?; @@ -913,6 +915,7 @@ fn match_pre_hint( } /** Match static hints and dynamic hints after they're evaluated */ +#[allow(clippy::too_many_arguments)] fn match_post_hint( stack: &mut NockStack, newt: &mut Option<&mut Newt>, @@ -937,6 +940,7 @@ fn match_post_hint( } } +#[allow(clippy::too_many_arguments)] fn match_post_hinted( stack: &mut NockStack, subject: Noun, diff --git a/rust/ares/src/jets/cold.rs b/rust/ares/src/jets/cold.rs index 9a7245c..914b811 100644 --- a/rust/ares/src/jets/cold.rs +++ b/rust/ares/src/jets/cold.rs @@ -170,13 +170,8 @@ impl Iterator for BatteriesList { } impl BatteriesList { - fn matches(self, stack: &mut NockStack, core: Noun) -> Option { - for batteries in self { - if batteries.matches(stack, core) { - return Some(batteries); - } - } - None + fn matches(mut self, stack: &mut NockStack, core: Noun) -> Option { + self.find(|&batteries| batteries.matches(stack, core)) } } @@ -283,9 +278,9 @@ impl Cold { unsafe { let cold_mem_ptr: *mut ColdMem = stack.struct_alloc(1); *cold_mem_ptr = ColdMem { - battery_to_paths: battery_to_paths, - root_to_paths: root_to_paths, - path_to_batteries: path_to_batteries, + battery_to_paths, + root_to_paths, + path_to_batteries, }; Cold(cold_mem_ptr) } @@ -304,6 +299,7 @@ impl Cold { /// already registered) /// /// XX TODO validate chum + #[allow(clippy::result_unit_err)] pub fn register( &mut self, stack: &mut NockStack, @@ -411,9 +407,9 @@ impl Cold { let batteries_mem_ptr: *mut BatteriesMem = stack.struct_alloc(1); *batteries_mem_ptr = BatteriesMem { - battery: battery, - parent_axis: parent_axis, - parent_batteries: parent_batteries, + battery, + parent_axis, + parent_batteries, }; let current_batteries_list = path_to_batteries @@ -460,9 +456,9 @@ impl Cold { let batteries_mem_ptr: *mut BatteriesMem = stack.struct_alloc(1); *batteries_mem_ptr = BatteriesMem { - battery: battery, - parent_axis: parent_axis, - parent_batteries: parent_batteries, + battery, + parent_axis, + parent_batteries, }; let current_batteries_list = path_to_batteries @@ -500,9 +496,9 @@ impl Cold { let cold_mem_ptr: *mut ColdMem = stack.struct_alloc(1); *cold_mem_ptr = ColdMem { - battery_to_paths: battery_to_paths, - root_to_paths: root_to_paths, - path_to_batteries: path_to_batteries, + battery_to_paths, + root_to_paths, + path_to_batteries, }; *self = Cold(cold_mem_ptr); diff --git a/rust/ares/src/jets/hot.rs b/rust/ares/src/jets/hot.rs index 0c59b3b..f0aba3b 100644 --- a/rust/ares/src/jets/hot.rs +++ b/rust/ares/src/jets/hot.rs @@ -7,6 +7,7 @@ use std::ptr::null_mut; const A_50: Either = Right((tas!(b"a"), 50)); // This is the const state all in one spot as literals +#[allow(clippy::complexity)] const HOT_STATE: &[(&[Either], u64, Jet)] = &[ (&[A_50, Left(tas!(b"dec"))], 1, jet_dec), (&[A_50, Left(tas!(b"add"))], 1, jet_add), @@ -68,10 +69,10 @@ impl Hot { let axis = DirectAtom::new_panic(*axe).as_atom(); let hot_mem_ptr: *mut HotMem = stack.struct_alloc(1); *hot_mem_ptr = HotMem { - a_path: a_path, - axis: axis, + a_path, + axis, jet: *jet, - next: next, + next, }; next = Hot(hot_mem_ptr); } diff --git a/rust/ares/src/jets/warm.rs b/rust/ares/src/jets/warm.rs index e359e36..18a819c 100644 --- a/rust/ares/src/jets/warm.rs +++ b/rust/ares/src/jets/warm.rs @@ -84,6 +84,7 @@ impl Iterator for WarmEntry { } impl Warm { + #[allow(clippy::new_without_default)] pub fn new() -> Self { Warm(Hamt::new()) } @@ -100,9 +101,9 @@ impl Warm { unsafe { let warm_entry_mem_ptr: *mut WarmEntryMem = stack.struct_alloc(1); *warm_entry_mem_ptr = WarmEntryMem { - batteries: batteries, - jet: jet, - path: path, + batteries, + jet, + path, next: current_warm_entry, }; self.0 = self.0.insert(stack, formula, WarmEntry(warm_entry_mem_ptr)); @@ -115,7 +116,7 @@ impl Warm { let batteries_list = cold.find(stack, &mut path); for batteries in batteries_list { let mut batteries_tmp = batteries; - let (mut battery, _parent_axis) = batteries_tmp + let (battery, _parent_axis) = batteries_tmp .next() .expect("IMPOSSIBLE: empty battery entry in cold state"); if let Ok(mut formula) = unsafe { slot_result(*battery, axis.as_bitslice()) } { @@ -131,7 +132,7 @@ impl Warm { pub fn find_jet(&mut self, stack: &mut NockStack, s: &mut Noun, f: &mut Noun) -> Option { let warm_it = self.0.lookup(stack, f)?; - for (path, batteries, jet) in warm_it { + for (_path, batteries, jet) in warm_it { if batteries.matches(stack, *s) { return Some(jet); } diff --git a/rust/ares/src/mem.rs b/rust/ares/src/mem.rs index a221bf2..1ceb0b5 100644 --- a/rust/ares/src/mem.rs +++ b/rust/ares/src/mem.rs @@ -1,7 +1,7 @@ use crate::assert_acyclic; use crate::noun::{Atom, Cell, CellMemory, IndirectAtom, Noun, NounAllocator}; use crate::snapshot::pma::{pma_in_arena, pma_malloc_w}; -use assert_no_alloc::permit_alloc; + use either::Either::{self, Left, Right}; use ibig::Stack; use libc::{c_void, memcmp}; @@ -453,9 +453,8 @@ impl NockStack { self.stack_pointer }) as usize; let (low, hi) = if ap > sp { (sp, ap) } else { (ap, sp) }; - if (ptr as usize) < low && (ptr.add(count) as usize) <= low { - return; - } else if (ptr as usize) >= hi && (ptr.add(count) as usize) > hi { + if ((ptr as usize) < low && (ptr.add(count) as usize) <= low) + || ((ptr as usize) >= hi && (ptr.add(count) as usize) > hi) { return; } panic!( diff --git a/rust/ares/src/serf.rs b/rust/ares/src/serf.rs index 4a8a6ae..ea250ed 100644 --- a/rust/ares/src/serf.rs +++ b/rust/ares/src/serf.rs @@ -130,6 +130,7 @@ pub fn serf() -> io::Result<()> { Ok(()) } +#[allow(clippy::too_many_arguments)] pub fn slam( stack: &mut NockStack, newt: &mut Newt,