interpreter: address lints for fast hints

This commit is contained in:
Edward Amsden 2023-09-27 22:55:00 -05:00
parent 4e292b88a0
commit 2db74f9c0f
7 changed files with 40 additions and 38 deletions

View File

@ -455,7 +455,7 @@ impl<T: Copy + Preserve> Preserve for Hamt<T> {
position += 1; position += 1;
continue 'check_stem; continue 'check_stem;
} }
Some((Left(next_stem), idx)) => { Some((Left(next_stem), _idx)) => {
stack.struct_is_in(next_stem.buffer, next_stem.size()); stack.struct_is_in(next_stem.buffer, next_stem.size());
assert!(traversal_depth <= 5); // will increment assert!(traversal_depth <= 5); // will increment
traversal_stack[traversal_depth - 1].as_mut().unwrap().1 = position + 1; traversal_stack[traversal_depth - 1].as_mut().unwrap().1 = position + 1;
@ -463,7 +463,7 @@ impl<T: Copy + Preserve> Preserve for Hamt<T> {
traversal_depth += 1; traversal_depth += 1;
continue 'check; continue 'check;
} }
Some((Right(leaf), idx)) => { Some((Right(leaf), _idx)) => {
stack.struct_is_in(leaf.buffer, leaf.len); stack.struct_is_in(leaf.buffer, leaf.len);
for pair in leaf.to_mut_slice().iter() { for pair in leaf.to_mut_slice().iter() {
pair.0.assert_in_stack(stack); pair.0.assert_in_stack(stack);

View File

@ -1,5 +1,5 @@
use crate::hamt::Hamt; use crate::hamt::Hamt;
use crate::jets;
use crate::jets::cold::Cold; use crate::jets::cold::Cold;
use crate::jets::hot::Hot; use crate::jets::hot::Hot;
use crate::jets::warm::Warm; 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 */ /** Note: axis must fit in a direct atom */
pub fn raw_slot(noun: Noun, axis: u64) -> Noun { 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<Noun, ()> { pub fn raw_slot_result(noun: Noun, axis: u64) -> Result<Noun, ()> {
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<u64, Lsb0>) -> Result<Noun, ()> { pub fn slot_result(mut noun: Noun, axis: &BitSlice<u64, Lsb0>) -> Result<Noun, ()> {
let mut cursor = if let Some(x) = axis.last_one() { let mut cursor = if let Some(x) = axis.last_one() {
Ok(x) Ok(x)
@ -866,10 +868,10 @@ pub fn inc(stack: &mut NockStack, atom: Atom) -> Atom {
/** Match hints which apply before the formula is evaluated */ /** Match hints which apply before the formula is evaluated */
fn match_pre_hint( fn match_pre_hint(
stack: &mut NockStack, stack: &mut NockStack,
newt: &mut Option<&mut Newt>, _newt: &mut Option<&mut Newt>,
subject: Noun, subject: Noun,
cell: Cell, cell: Cell,
formula: Noun, _formula: Noun,
cache: &Hamt<Noun>, cache: &Hamt<Noun>,
) -> Result<Noun, ()> { ) -> Result<Noun, ()> {
let direct = cell.head().as_direct()?; let direct = cell.head().as_direct()?;
@ -913,6 +915,7 @@ fn match_pre_hint(
} }
/** Match static hints and dynamic hints after they're evaluated */ /** Match static hints and dynamic hints after they're evaluated */
#[allow(clippy::too_many_arguments)]
fn match_post_hint( fn match_post_hint(
stack: &mut NockStack, stack: &mut NockStack,
newt: &mut Option<&mut Newt>, newt: &mut Option<&mut Newt>,
@ -937,6 +940,7 @@ fn match_post_hint(
} }
} }
#[allow(clippy::too_many_arguments)]
fn match_post_hinted( fn match_post_hinted(
stack: &mut NockStack, stack: &mut NockStack,
subject: Noun, subject: Noun,

View File

@ -170,13 +170,8 @@ impl Iterator for BatteriesList {
} }
impl BatteriesList { impl BatteriesList {
fn matches(self, stack: &mut NockStack, core: Noun) -> Option<Batteries> { fn matches(mut self, stack: &mut NockStack, core: Noun) -> Option<Batteries> {
for batteries in self { self.find(|&batteries| batteries.matches(stack, core))
if batteries.matches(stack, core) {
return Some(batteries);
}
}
None
} }
} }
@ -283,9 +278,9 @@ impl Cold {
unsafe { unsafe {
let cold_mem_ptr: *mut ColdMem = stack.struct_alloc(1); let cold_mem_ptr: *mut ColdMem = stack.struct_alloc(1);
*cold_mem_ptr = ColdMem { *cold_mem_ptr = ColdMem {
battery_to_paths: battery_to_paths, battery_to_paths,
root_to_paths: root_to_paths, root_to_paths,
path_to_batteries: path_to_batteries, path_to_batteries,
}; };
Cold(cold_mem_ptr) Cold(cold_mem_ptr)
} }
@ -304,6 +299,7 @@ impl Cold {
/// already registered) /// already registered)
/// ///
/// XX TODO validate chum /// XX TODO validate chum
#[allow(clippy::result_unit_err)]
pub fn register( pub fn register(
&mut self, &mut self,
stack: &mut NockStack, stack: &mut NockStack,
@ -411,9 +407,9 @@ impl Cold {
let batteries_mem_ptr: *mut BatteriesMem = stack.struct_alloc(1); let batteries_mem_ptr: *mut BatteriesMem = stack.struct_alloc(1);
*batteries_mem_ptr = BatteriesMem { *batteries_mem_ptr = BatteriesMem {
battery: battery, battery,
parent_axis: parent_axis, parent_axis,
parent_batteries: parent_batteries, parent_batteries,
}; };
let current_batteries_list = path_to_batteries let current_batteries_list = path_to_batteries
@ -460,9 +456,9 @@ impl Cold {
let batteries_mem_ptr: *mut BatteriesMem = stack.struct_alloc(1); let batteries_mem_ptr: *mut BatteriesMem = stack.struct_alloc(1);
*batteries_mem_ptr = BatteriesMem { *batteries_mem_ptr = BatteriesMem {
battery: battery, battery,
parent_axis: parent_axis, parent_axis,
parent_batteries: parent_batteries, parent_batteries,
}; };
let current_batteries_list = path_to_batteries let current_batteries_list = path_to_batteries
@ -500,9 +496,9 @@ impl Cold {
let cold_mem_ptr: *mut ColdMem = stack.struct_alloc(1); let cold_mem_ptr: *mut ColdMem = stack.struct_alloc(1);
*cold_mem_ptr = ColdMem { *cold_mem_ptr = ColdMem {
battery_to_paths: battery_to_paths, battery_to_paths,
root_to_paths: root_to_paths, root_to_paths,
path_to_batteries: path_to_batteries, path_to_batteries,
}; };
*self = Cold(cold_mem_ptr); *self = Cold(cold_mem_ptr);

View File

@ -7,6 +7,7 @@ use std::ptr::null_mut;
const A_50: Either<u64, (u64, u64)> = Right((tas!(b"a"), 50)); const A_50: Either<u64, (u64, u64)> = Right((tas!(b"a"), 50));
// This is the const state all in one spot as literals // This is the const state all in one spot as literals
#[allow(clippy::complexity)]
const HOT_STATE: &[(&[Either<u64, (u64, u64)>], u64, Jet)] = &[ const HOT_STATE: &[(&[Either<u64, (u64, u64)>], u64, Jet)] = &[
(&[A_50, Left(tas!(b"dec"))], 1, jet_dec), (&[A_50, Left(tas!(b"dec"))], 1, jet_dec),
(&[A_50, Left(tas!(b"add"))], 1, jet_add), (&[A_50, Left(tas!(b"add"))], 1, jet_add),
@ -68,10 +69,10 @@ impl Hot {
let axis = DirectAtom::new_panic(*axe).as_atom(); let axis = DirectAtom::new_panic(*axe).as_atom();
let hot_mem_ptr: *mut HotMem = stack.struct_alloc(1); let hot_mem_ptr: *mut HotMem = stack.struct_alloc(1);
*hot_mem_ptr = HotMem { *hot_mem_ptr = HotMem {
a_path: a_path, a_path,
axis: axis, axis,
jet: *jet, jet: *jet,
next: next, next,
}; };
next = Hot(hot_mem_ptr); next = Hot(hot_mem_ptr);
} }

View File

@ -84,6 +84,7 @@ impl Iterator for WarmEntry {
} }
impl Warm { impl Warm {
#[allow(clippy::new_without_default)]
pub fn new() -> Self { pub fn new() -> Self {
Warm(Hamt::new()) Warm(Hamt::new())
} }
@ -100,9 +101,9 @@ impl Warm {
unsafe { unsafe {
let warm_entry_mem_ptr: *mut WarmEntryMem = stack.struct_alloc(1); let warm_entry_mem_ptr: *mut WarmEntryMem = stack.struct_alloc(1);
*warm_entry_mem_ptr = WarmEntryMem { *warm_entry_mem_ptr = WarmEntryMem {
batteries: batteries, batteries,
jet: jet, jet,
path: path, path,
next: current_warm_entry, next: current_warm_entry,
}; };
self.0 = self.0.insert(stack, formula, WarmEntry(warm_entry_mem_ptr)); 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); let batteries_list = cold.find(stack, &mut path);
for batteries in batteries_list { for batteries in batteries_list {
let mut batteries_tmp = batteries; let mut batteries_tmp = batteries;
let (mut battery, _parent_axis) = batteries_tmp let (battery, _parent_axis) = batteries_tmp
.next() .next()
.expect("IMPOSSIBLE: empty battery entry in cold state"); .expect("IMPOSSIBLE: empty battery entry in cold state");
if let Ok(mut formula) = unsafe { slot_result(*battery, axis.as_bitslice()) } { 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<Jet> { pub fn find_jet(&mut self, stack: &mut NockStack, s: &mut Noun, f: &mut Noun) -> Option<Jet> {
let warm_it = self.0.lookup(stack, f)?; 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) { if batteries.matches(stack, *s) {
return Some(jet); return Some(jet);
} }

View File

@ -1,7 +1,7 @@
use crate::assert_acyclic; use crate::assert_acyclic;
use crate::noun::{Atom, Cell, CellMemory, IndirectAtom, Noun, NounAllocator}; use crate::noun::{Atom, Cell, CellMemory, IndirectAtom, Noun, NounAllocator};
use crate::snapshot::pma::{pma_in_arena, pma_malloc_w}; use crate::snapshot::pma::{pma_in_arena, pma_malloc_w};
use assert_no_alloc::permit_alloc;
use either::Either::{self, Left, Right}; use either::Either::{self, Left, Right};
use ibig::Stack; use ibig::Stack;
use libc::{c_void, memcmp}; use libc::{c_void, memcmp};
@ -453,9 +453,8 @@ impl NockStack {
self.stack_pointer self.stack_pointer
}) as usize; }) as usize;
let (low, hi) = if ap > sp { (sp, ap) } else { (ap, sp) }; let (low, hi) = if ap > sp { (sp, ap) } else { (ap, sp) };
if (ptr as usize) < low && (ptr.add(count) as usize) <= low { if ((ptr as usize) < low && (ptr.add(count) as usize) <= low)
return; || ((ptr as usize) >= hi && (ptr.add(count) as usize) > hi) {
} else if (ptr as usize) >= hi && (ptr.add(count) as usize) > hi {
return; return;
} }
panic!( panic!(

View File

@ -130,6 +130,7 @@ pub fn serf() -> io::Result<()> {
Ok(()) Ok(())
} }
#[allow(clippy::too_many_arguments)]
pub fn slam( pub fn slam(
stack: &mut NockStack, stack: &mut NockStack,
newt: &mut Newt, newt: &mut Newt,