Skip to content

Commit

Permalink
Fix remaining clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bakaq committed Feb 19, 2025
1 parent 8f90499 commit c61b9cb
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn push_literal(interm: &mut Vec<ArithmeticTerm>, c: HeapCellValue) -> Result<()
Number::Float(OrderedFloat(std::f64::consts::PI)),
)),
atom!("epsilon") => interm.push(ArithmeticTerm::Number(
Number::Float(OrderedFloat(std::f64::EPSILON)),
Number::Float(OrderedFloat(f64::EPSILON)),
)),
atom!("e") => interm.push(ArithmeticTerm::Number(
Number::Float(OrderedFloat(std::f64::consts::E)),
Expand Down
12 changes: 5 additions & 7 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ impl CodeGenerator {
| HeapCellValueTag::PStrLoc) => {
let r = self.marker.mark_non_var::<Target>(Level::Deep, heap_loc, context, target);
target.push_back(Target::clause_arg_to_instr(r));
return Some(r);
Some(r)
}
_ => {
target.push_back(Target::constant_subterm(subterm));
Expand Down Expand Up @@ -528,12 +528,10 @@ impl CodeGenerator {
target.push_back(instr);
}

for r_opt in free_list_regs {
if let Some(r) = r_opt {
<CodeGenerator as AddToFreeList<'a, Target>>::add_subterm_to_free_list(
self, r,
);
}
for r_opt in free_list_regs.into_iter().flatten() {
<CodeGenerator as AddToFreeList<'a, Target>>::add_subterm_to_free_list(
self, r_opt,
);
}
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/debray_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,13 +747,12 @@ impl Allocator for DebrayAllocator {

if let GenContext::Last(chunk_num) = context {
if let Some(new_r) = self.evacuate_arg::<Target>(chunk_num, code) {
self.non_var_register_heap_locs
.swap_remove(&k)
.map(|old_heap_loc| {
self.non_var_registers.insert(old_heap_loc, new_r.reg_num());
self.non_var_register_heap_locs
.insert(new_r.reg_num(), old_heap_loc);
});
if let Some(old_heap_loc) = self.non_var_register_heap_locs.swap_remove(&k)
{
self.non_var_registers.insert(old_heap_loc, new_r.reg_num());
self.non_var_register_heap_locs
.insert(new_r.reg_num(), old_heap_loc);
}

self.non_var_registers.insert(heap_loc, k);
self.non_var_register_heap_locs.insert(k, heap_loc);
Expand Down
12 changes: 6 additions & 6 deletions src/forms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ pub enum PredicateClause {

impl PredicateClause {
pub(crate) fn args(&self, heap: &Heap) -> Option<std::ops::RangeInclusive<usize>> {
let focus = match self {
&PredicateClause::Fact(Fact { term_loc }, _) => term_loc,
&PredicateClause::Rule(Rule { term_loc, .. }, _) => {
let focus = match *self {
PredicateClause::Fact(Fact { term_loc }, _) => term_loc,
PredicateClause::Rule(Rule { term_loc, .. }, _) => {
term_nth_arg(heap, term_loc, 1).unwrap()
}
};
Expand Down Expand Up @@ -345,11 +345,11 @@ pub enum ModuleSource {

impl ModuleSource {
pub(crate) fn as_functor_stub(&self) -> MachineStub {
match self {
&ModuleSource::Library(name) => {
match *self {
ModuleSource::Library(name) => {
functor!(atom!("library"), [atom_as_cell(name)])
}
&ModuleSource::File(name) => {
ModuleSource::File(name) => {
functor!(name)
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/functor_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ macro_rules! functor {
vec![FunctorElement::Cell(atom_as_cell!($name))]
});
($name:expr, [$($dt:ident($($value:tt),*)),+]) => ({
build_functor!([$($dt($($value),*)),*],
#[allow(unused_parens)]
{
build_functor!([$($dt($($value),*)),*],
[FunctorElement::Cell(atom_as_cell!($name, count!($($dt) *)))],
1,
[])
}
});
}

Expand Down
7 changes: 1 addition & 6 deletions src/machine/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,6 @@ impl<'a> ReservedHeapSection<'a> {
let cells_written;
let str_byte_len = src.len();

const ALIGN_CELL: usize = Heap::heap_cell_alignment();

unsafe {
ptr::copy_nonoverlapping(
src.as_ptr(),
Expand Down Expand Up @@ -646,7 +644,6 @@ impl Heap {
}
}

#[must_use]
pub fn reserve(&mut self, num_cells: usize) -> Result<HeapWriter, usize> {
let section;
let len = heap_index!(num_cells);
Expand Down Expand Up @@ -1001,8 +998,6 @@ impl Heap {
let (s, tail_loc) = self.scan_slice_to_str(pstr_loc);
let s_len = s.len();

const ALIGN_CELL: usize = Heap::heap_cell_alignment();

let align_offset = pstr_sentinel_length(s_len);

let copy_size = s_len + align_offset;
Expand Down Expand Up @@ -1321,7 +1316,7 @@ pub fn heap_bound_store(heap: &impl SizedHeap, value: HeapCellValue) -> HeapCell
}

#[allow(dead_code)]
pub fn print_heap_terms<'a, I: Iterator<Item = HeapCellValue>>(heap: I, h: usize) {
pub fn print_heap_terms<I: Iterator<Item = HeapCellValue>>(heap: I, h: usize) {
for (index, term) in heap.enumerate() {
println!("{} : {:?}", h + index, term);
}
Expand Down
8 changes: 5 additions & 3 deletions src/machine/machine_indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,11 @@ impl IndexStore {
_ => self
.get_meta_predicate_spec(key.0, key.1, &compilation_target)
.map(|meta_specs| {
meta_specs.iter().find(|meta_spec| match meta_spec {
MetaSpec::Colon | MetaSpec::RequiresExpansionWithArgument(_) => true,
_ => false,
meta_specs.iter().find(|meta_spec| {
matches!(
meta_spec,
MetaSpec::Colon | MetaSpec::RequiresExpansionWithArgument(_)
)
})
})
.map(|meta_spec_opt| meta_spec_opt.is_some())
Expand Down
1 change: 1 addition & 0 deletions src/machine/partial_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct HeapPStrIter<'a> {
stepper: fn(&mut HeapPStrIter<'a>) -> Option<PStrIteratee>,
}

#[allow(clippy::enum_variant_names)]
#[derive(Debug, Clone, Copy)]
pub enum PStrCmpResult<'a> {
ListMatch {
Expand Down
2 changes: 1 addition & 1 deletion src/machine/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fn setup_use_module_decl(term: &FocusedHeapRefMut) -> Result<ModuleSource, Compi
)
}

return Err(CompilationError::InvalidModuleDecl);
Err(CompilationError::InvalidModuleDecl)
}
(HeapCellValueTag::Atom, (name, arity)) => {
if arity == 0 {
Expand Down
8 changes: 4 additions & 4 deletions src/machine/system_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7308,18 +7308,18 @@ impl Machine {
instr.enqueue_functors(&mut self.machine_st.arena, &mut functors);
let new_len = functors.len();

for index in old_len..new_len {
let functor_len = functors[index].len();
for functor in &functors[old_len..new_len] {
let functor_len = functor.len();

match functor_len {
0 => {}
1 => {
functor_list.push(heap_loc_as_cell!(h));
h += cell_index!(Heap::compute_functor_byte_size(&functors[index]));
h += cell_index!(Heap::compute_functor_byte_size(functor));
}
_ => {
functor_list.push(str_loc_as_cell!(h));
h += cell_index!(Heap::compute_functor_byte_size(&functors[index]));
h += cell_index!(Heap::compute_functor_byte_size(functor));
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,6 @@ macro_rules! heap_index {

macro_rules! cell_index {
($idx:expr) => {
(($idx) / std::mem::size_of::<HeapCellValue>())
($idx) / std::mem::size_of::<HeapCellValue>()
};
}
15 changes: 7 additions & 8 deletions src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,16 +529,15 @@ impl<'a> Parser<'a> {
}
}

if is_yf!(desc1.spec) && affirm_yf(desc1, desc2) {
if (is_yf!(desc1.spec) && affirm_yf(desc1, desc2))
|| (is_xf!(desc1.spec) && affirm_xf(desc1, desc2))
|| (is_xf!(desc1.spec) && affirm_xf(desc1, desc2))
{
self.push_unary_op(desc1, desc2, LTERM);
continue;
} else if is_xf!(desc1.spec) && affirm_xf(desc1, desc2) {
self.push_unary_op(desc1, desc2, LTERM);
continue;
} else if is_fy!(desc2.spec) && affirm_fy(priority, desc1, desc2) {
self.push_unary_op(desc2, desc1, TERM);
continue;
} else if is_fx!(desc2.spec) && affirm_fx(priority, desc1, desc2) {
} else if (is_fy!(desc2.spec) && affirm_fy(priority, desc1, desc2))
|| (is_fx!(desc2.spec) && affirm_fx(priority, desc1, desc2))
{
self.push_unary_op(desc2, desc1, TERM);
continue;
} else {
Expand Down

0 comments on commit c61b9cb

Please sign in to comment.