Apply lints suggested by cargo clippy

This commit is contained in:
Peter McEvoy 2023-03-10 12:18:40 -05:00
parent 7ed735e1e3
commit b60100c806
11 changed files with 104 additions and 140 deletions

View File

@ -1,7 +1,6 @@
use ares::mem::NockStack;
use ares::noun::{DirectAtom, IndirectAtom};
use ares::serialization::{cue, jam};
use memmap;
use std::env;
use std::fs::{File, OpenOptions};
use std::io;
@ -11,7 +10,7 @@ use std::time::SystemTime;
fn main() -> io::Result<()> {
let filename = env::args().nth(1).expect("Must provide input filename");
let output_filename = format!("{}.out", filename.clone());
let output_filename = format!("{}.out", filename);
let f = File::open(filename)?;
let in_len = f.metadata()?.len();
let mut stack = NockStack::new(1 << 10 << 10 << 10, 0);

View File

@ -69,7 +69,7 @@ impl<T: Copy> MutHamt<T> {
unsafe {
'lookup: loop {
let chunk = mug & 0x1f;
mug = mug >> 5;
mug >>= 5;
match (*stem).entry(chunk) {
None => {
break None;
@ -79,8 +79,8 @@ impl<T: Copy> MutHamt<T> {
}
Some(Right(leaf)) => {
for pair in leaf.to_mut_slice().iter_mut() {
if unifying_equality(stack, n, &mut (*pair).0) {
break 'lookup Some((*pair).1);
if unifying_equality(stack, n, &mut pair.0) {
break 'lookup Some(pair.1);
}
}
break None;
@ -97,13 +97,13 @@ impl<T: Copy> MutHamt<T> {
unsafe {
'insert: loop {
let chunk = mug & 0x1f;
mug = mug >> 5;
mug >>= 5;
match (*stem).entry(chunk) {
None => {
let new_leaf_buffer = stack.struct_alloc(1);
*new_leaf_buffer = (*n, t);
(*stem).bitmap = (*stem).bitmap | chunk_to_bit(chunk);
(*stem).typemap = (*stem).typemap & !chunk_to_bit(chunk);
(*stem).bitmap |= chunk_to_bit(chunk);
(*stem).typemap &= !chunk_to_bit(chunk);
(*stem).buffer[chunk as usize] = MutEntry {
leaf: Leaf {
len: 1,
@ -119,8 +119,8 @@ impl<T: Copy> MutHamt<T> {
}
Some(Right(leaf)) => {
for pair in leaf.to_mut_slice().iter_mut() {
if unifying_equality(stack, n, &mut (*pair).0) {
(*pair).1 = t;
if unifying_equality(stack, n, &mut pair.0) {
pair.1 = t;
break 'insert;
}
}
@ -142,9 +142,9 @@ impl<T: Copy> MutHamt<T> {
let leaf_chunk = (leaf_mug >> ((depth + 1) * 5)) & 0x1f;
(*new_stem).bitmap = chunk_to_bit(leaf_chunk);
(*new_stem).typemap = 0;
(*new_stem).buffer[leaf_chunk as usize] = MutEntry { leaf: leaf };
(*new_stem).buffer[leaf_chunk as usize] = MutEntry { leaf };
(*stem).buffer[chunk as usize] = MutEntry { stem: new_stem };
(*stem).typemap = (*stem).typemap | chunk_to_bit(chunk);
(*stem).typemap |= chunk_to_bit(chunk);
stem = new_stem;
depth += 1;
continue;
@ -281,7 +281,7 @@ impl<T: Copy> Hamt<T> {
let mut mug = mug_u32(stack, *n);
'lookup: loop {
let chunk = mug & 0x1F; // 5 bits
mug = mug >> 5;
mug >>= 5;
match stem.entry(chunk) {
None => {
break None;
@ -314,7 +314,7 @@ impl<T: Copy> Hamt<T> {
unsafe {
'insert: loop {
let chunk = mug & 0x1F; // 5 bits
mug = mug >> 5;
mug >>= 5;
match stem.entry(chunk) {
None => {
let new_leaf_buffer = stack.struct_alloc(1);
@ -399,7 +399,7 @@ impl<T: Copy> Hamt<T> {
// next time around
assert!(leaf.len == 1);
let fake_buffer = stack.struct_alloc(1);
*fake_buffer = Entry { leaf: leaf };
*fake_buffer = Entry { leaf };
// get the mug chunk for the noun at *the next level* so
// we can build a fake stem for it
let fake_mug = mug_u32(stack, (*leaf.buffer).0);
@ -430,13 +430,13 @@ impl<T: Copy> Hamt<T> {
impl<T: Copy + Preserve> Preserve for Hamt<T> {
unsafe fn preserve(&mut self, stack: &mut NockStack) {
if stack.in_frame((*self).0.buffer) {
let dest_buffer = stack.struct_alloc_in_previous_frame((*self).0.size());
copy_nonoverlapping((*self).0.buffer, dest_buffer, (*self).0.size());
(*self).0.buffer = dest_buffer;
if stack.in_frame(self.0.buffer) {
let dest_buffer = stack.struct_alloc_in_previous_frame(self.0.size());
copy_nonoverlapping(self.0.buffer, dest_buffer, self.0.size());
self.0.buffer = dest_buffer;
let traversal_stack = stack.struct_alloc::<(Stem<T>, u32)>(6);
let mut traversal_depth = 1;
*traversal_stack = ((*self).0, 0);
*traversal_stack = (self.0, 0);
'preserve: loop {
if traversal_depth == 0 {
break;
@ -487,8 +487,8 @@ impl<T: Copy + Preserve> Preserve for Hamt<T> {
buffer: dest_buffer,
};
for pair in new_leaf.to_mut_slice().iter_mut() {
(*pair).0.preserve(stack);
(*pair).1.preserve(stack);
pair.0.preserve(stack);
pair.1.preserve(stack);
}
*(stem.buffer.add(idx) as *mut Entry<T>) = Entry { leaf: new_leaf };
}

View File

@ -653,20 +653,20 @@ fn match_pre_hint(
return Err(());
}
}
return Ok(jet_res);
Ok(jet_res)
} else {
// Print jet errors and punt to Nock
eprintln!("\rJet {} failed", jet_name);
return Err(());
Err(())
}
}
tas!(b"memo") => {
let formula = unsafe { *stack.local_noun_pointer(2) };
let mut key = Cell::new(stack, subject, formula).as_noun();
if let Some(res) = cache.lookup(stack, &mut key) {
return Ok(res);
Ok(res)
} else {
return Err(());
Err(())
}
}
_ => Err(()),
@ -711,10 +711,8 @@ fn match_post_hinted(
let formula = unsafe { *stack.local_noun_pointer(2) };
let mut key = Cell::new(stack, subject, formula).as_noun();
*cache = cache.insert(stack, &mut key, res);
return Ok(());
}
_ => {
return Err(());
Ok(())
}
_ => Err(()),
}
}

View File

@ -21,7 +21,7 @@ use bitvec::prelude::{BitSlice, Lsb0};
use either::Either::*;
use ibig::ops::DivRem;
use ibig::UBig;
use std::cmp;
use std::{cmp, convert::TryFrom};
crate::gdb!();
@ -136,15 +136,13 @@ pub fn jet_div(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
if unsafe { b.as_noun().raw_equals(D(0)) } {
Err(Deterministic)
} else if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) {
Ok(unsafe { DirectAtom::new_unchecked(a.data() / b.data()) }.as_noun())
} else {
if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) {
Ok(unsafe { DirectAtom::new_unchecked(a.data() / b.data()) }.as_noun())
} else {
let a_big = a.as_ubig(stack);
let b_big = b.as_ubig(stack);
let res = UBig::div_stack(stack, a_big, b_big);
Ok(Atom::from_ubig(stack, &res).as_noun())
}
let a_big = a.as_ubig(stack);
let b_big = b.as_ubig(stack);
let res = UBig::div_stack(stack, a_big, b_big);
Ok(Atom::from_ubig(stack, &res).as_noun())
}
}
@ -155,13 +153,11 @@ pub fn jet_mod(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
if unsafe { b.as_noun().raw_equals(D(0)) } {
Err(Deterministic)
} else if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) {
Ok(unsafe { DirectAtom::new_unchecked(a.data() % b.data()) }.as_noun())
} else {
if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) {
Ok(unsafe { DirectAtom::new_unchecked(a.data() % b.data()) }.as_noun())
} else {
let res = a.as_ubig(stack) % b.as_ubig(stack);
Ok(Atom::from_ubig(stack, &res).as_noun())
}
let res = a.as_ubig(stack) % b.as_ubig(stack);
Ok(Atom::from_ubig(stack, &res).as_noun())
}
}
@ -204,18 +200,14 @@ pub fn jet_lth(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
} else {
NO
}
} else if a.bit_size() < b.bit_size() {
YES
} else if a.bit_size() > b.bit_size() {
NO
} else if a.as_ubig(stack) < b.as_ubig(stack) {
YES
} else {
if a.bit_size() < b.bit_size() {
YES
} else if a.bit_size() > b.bit_size() {
NO
} else {
if a.as_ubig(stack) < b.as_ubig(stack) {
YES
} else {
NO
}
}
NO
})
}
@ -230,18 +222,14 @@ pub fn jet_lte(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
} else {
NO
}
} else if a.bit_size() < b.bit_size() {
YES
} else if a.bit_size() > b.bit_size() {
NO
} else if a.as_ubig(stack) <= b.as_ubig(stack) {
YES
} else {
if a.bit_size() < b.bit_size() {
YES
} else if a.bit_size() > b.bit_size() {
NO
} else {
if a.as_ubig(stack) <= b.as_ubig(stack) {
YES
} else {
NO
}
}
NO
})
}
@ -256,18 +244,14 @@ pub fn jet_gth(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
} else {
NO
}
} else if a.bit_size() > b.bit_size() {
YES
} else if a.bit_size() < b.bit_size() {
NO
} else if a.as_ubig(stack) > b.as_ubig(stack) {
YES
} else {
if a.bit_size() > b.bit_size() {
YES
} else if a.bit_size() < b.bit_size() {
NO
} else {
if a.as_ubig(stack) > b.as_ubig(stack) {
YES
} else {
NO
}
}
NO
})
}
@ -282,18 +266,14 @@ pub fn jet_gte(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
} else {
NO
}
} else if a.bit_size() > b.bit_size() {
YES
} else if a.bit_size() < b.bit_size() {
NO
} else if a.as_ubig(stack) >= b.as_ubig(stack) {
YES
} else {
if a.bit_size() > b.bit_size() {
YES
} else if a.bit_size() < b.bit_size() {
NO
} else {
if a.as_ubig(stack) >= b.as_ubig(stack) {
YES
} else {
NO
}
}
NO
})
}
@ -468,7 +448,7 @@ pub fn jet_can(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
}
let original_list = raw_slot(arg, 3);
let mut len = 0 as usize;
let mut len = 0usize;
let mut list = original_list;
loop {
if unsafe { list.raw_equals(D(0)) } {
@ -477,7 +457,7 @@ pub fn jet_can(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
let cell = list.as_cell()?;
let item = cell.head().as_cell()?;
let step = item.head().as_direct()?.data() as usize;
let step = usize::try_from(item.head().as_direct()?.data()).unwrap();
len = len.checked_add(step).ok_or(NonDeterministic)?;
list = cell.tail();
@ -515,7 +495,7 @@ pub fn jet_rep(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
let (bloq, step) = bite(raw_slot(arg, 2))?;
let original_list = raw_slot(arg, 3);
let mut len = 0 as usize;
let mut len = 0usize;
let mut list = original_list;
loop {
if unsafe { list.raw_equals(D(0)) } {
@ -663,13 +643,11 @@ unsafe fn chop(
pub fn met(bloq: usize, a: Atom) -> usize {
if unsafe { a.as_noun().raw_equals(D(0)) } {
0
} else if bloq < 6 {
(a.bit_size() + ((1 << bloq) - 1)) >> bloq
} else {
if bloq < 6 {
(a.bit_size() + ((1 << bloq) - 1)) >> bloq
} else {
let bloq_word = bloq - 6;
(a.size() + ((1 << bloq_word) - 1)) >> bloq_word
}
let bloq_word = bloq - 6;
(a.size() + ((1 << bloq_word) - 1)) >> bloq_word
}
}

View File

@ -33,7 +33,7 @@ fn main() -> io::Result<()> {
return serf();
}
let output_filename = format!("{}.out", filename.clone());
let output_filename = format!("{}.out", filename);
let f = File::open(filename)?;
let in_len = f.metadata()?.len();
let mut stack = NockStack::new(8 << 10 << 10, 0);

View File

@ -98,12 +98,12 @@ impl NockStack {
*frame_pointer.add(1) = ptr::null::<u64>() as u64;
};
NockStack {
start: start,
size: size,
start,
size,
polarity: Polarity::West,
stack_pointer: stack_pointer,
frame_pointer: frame_pointer,
memory: memory,
stack_pointer,
frame_pointer,
memory,
}
}

View File

@ -82,7 +82,7 @@ impl Newt {
fn write_noun(&mut self, stack: &mut NockStack, noun: Noun) {
let atom = jam(stack, noun);
let size = atom.size() << 3;
let mut buf = vec![0 as u8; size + 5];
let mut buf = vec![0u8; size + 5];
buf[1] = size as u8;
buf[2] = (size >> 8) as u8;
buf[3] = (size >> 16) as u8;
@ -192,8 +192,7 @@ impl Newt {
/** Fetch next message. */
pub fn next(&mut self, stack: &mut NockStack) -> Option<Noun> {
let mut header: Vec<u8> = Vec::with_capacity(5);
header.resize(5, 0);
let mut header: Vec<u8> = vec![0; 5];
if let Err(err) = self.input.read_exact(&mut header) {
if err.kind() == std::io::ErrorKind::UnexpectedEof {
return None;

View File

@ -63,7 +63,7 @@ fn acyclic_noun_go(noun: Noun, seen: &mut IntMap<()>) -> bool {
match noun.as_either_atom_cell() {
Either::Left(_atom) => true,
Either::Right(cell) => {
if let Some(_) = seen.get(cell.0) {
if seen.get(cell.0).is_some() {
false
} else {
seen.insert(cell.0, ());
@ -155,8 +155,8 @@ impl DirectAtom {
self.0
}
pub fn as_bitslice<'a>(&'a self) -> &'a BitSlice<u64, Lsb0> {
&(BitSlice::from_element(&self.0))
pub fn as_bitslice(&self) -> &BitSlice<u64, Lsb0> {
BitSlice::from_element(&self.0)
}
}
@ -345,16 +345,16 @@ impl IndirectAtom {
unsafe { self.to_raw_pointer().add(2) as *const u64 }
}
pub fn as_slice<'a>(&'a self) -> &'a [u64] {
pub fn as_slice(&self) -> &[u64] {
unsafe { from_raw_parts(self.data_pointer(), self.size()) }
}
pub fn as_bytes<'a>(&'a self) -> &'a [u8] {
pub fn as_bytes(&self) -> &[u8] {
unsafe { from_raw_parts(self.data_pointer() as *const u8, self.size() << 3) }
}
/** BitSlice view on an indirect atom, with lifetime tied to reference to indirect atom. */
pub fn as_bitslice<'a>(&'a self) -> &'a BitSlice<u64, Lsb0> {
pub fn as_bitslice(&self) -> &BitSlice<u64, Lsb0> {
BitSlice::from_slice(self.as_slice())
}
@ -617,11 +617,11 @@ impl Atom {
}
}
pub fn as_bitslice<'a>(&'a self) -> &'a BitSlice<u64, Lsb0> {
pub fn as_bitslice(&self) -> &BitSlice<u64, Lsb0> {
if self.is_indirect() {
unsafe { self.indirect.as_bitslice() }
} else {
unsafe { &(self.direct.as_bitslice()) }
unsafe { self.direct.as_bitslice() }
}
}
@ -843,7 +843,7 @@ impl Noun {
}
pub unsafe fn from_raw(raw: u64) -> Noun {
Noun { raw: raw }
Noun { raw }
}
/** Produce the total size of a noun, in words

View File

@ -31,8 +31,8 @@ pub fn serf() -> io::Result<()> {
snap_path.push("chk");
create_dir_all(&snap_path)?;
let ref mut stack = NockStack::new(96 << 10 << 10, 0);
let ref mut newt = Newt::new();
let stack = &mut NockStack::new(96 << 10 << 10, 0);
let newt = &mut Newt::new();
let mut event_number;
let mut arvo;
@ -42,13 +42,7 @@ pub fn serf() -> io::Result<()> {
newt.ripe(stack, event_number, mug as u64);
// Can't use for loop because it borrows newt
loop {
let writ = if let Some(writ) = newt.next(stack) {
writ
} else {
break;
};
while let Some(writ) = newt.next(stack) {
let tag = raw_slot(writ, 2).as_direct().unwrap();
match tag.data() {
tas!(b"live") => {
@ -89,18 +83,14 @@ pub fn serf() -> io::Result<()> {
// event_number = raw_slot(writ, 6).as_direct().unwrap().data();
let mut lit = raw_slot(writ, 7);
loop {
if let Ok(cell) = lit.as_cell() {
if run {
let ovo = cell.head();
let res = slam(stack, newt, arvo, POKE_AXIS, ovo).as_cell().unwrap();
arvo = res.tail();
}
event_number += 1;
lit = cell.tail();
} else {
break;
while let Ok(cell) = lit.as_cell() {
if run {
let ovo = cell.head();
let res = slam(stack, newt, arvo, POKE_AXIS, ovo).as_cell().unwrap();
arvo = res.tail();
}
event_number += 1;
lit = cell.tail();
}
newt.play_done(stack, 0);
}

View File

@ -168,9 +168,9 @@ pub fn jam(stack: &mut NockStack, noun: Noun) -> Atom {
let (atom, slice) = unsafe { IndirectAtom::new_raw_mut_bitslice(stack, size) };
let mut state = JamState {
cursor: 0,
size: size,
atom: atom,
slice: slice,
size,
atom,
slice,
};
stack.push(1);
unsafe {

View File

@ -97,7 +97,7 @@ fn latest_snapshot(
snap_path: PathBuf,
) -> io::Result<(u8, u64, IndirectAtom)> {
let res0 = load_snapshot(stack, snap_path.clone(), 0);
let res1 = load_snapshot(stack, snap_path.clone(), 1);
let res1 = load_snapshot(stack, snap_path, 1);
match (res0, res1) {
(Ok((event_number_0, state_0)), Ok((event_number_1, state_1))) => {