Merge pull request #3189 from Skgland/fix-function_casts_as_integer
fix `function_casts_as_integer` warning
This commit is contained in:
@@ -29,6 +29,7 @@ crypto-full = []
|
||||
unexpected_cfgs = { level = "deny", check-cfg = [
|
||||
'cfg(rust_version, values("1.87.0"))',
|
||||
] }
|
||||
function_casts_as_integer = "deny"
|
||||
|
||||
|
||||
[build-dependencies]
|
||||
|
||||
@@ -1099,7 +1099,7 @@ impl MachineState {
|
||||
}
|
||||
_ => {
|
||||
push_cell!(self, heap_loc_as_cell!(h), return);
|
||||
(self.bind_fn)(self, Ref::heap_cell(h), value);
|
||||
self.occurs_check.bind(self, Ref::heap_cell(h), value);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -1147,7 +1147,7 @@ impl MachineState {
|
||||
push_cell!(self, heap_loc_as_cell!(h), return);
|
||||
|
||||
let addr = self.store(self[r]);
|
||||
(self.bind_fn)(self, Ref::heap_cell(h), addr);
|
||||
self.occurs_check.bind(self, Ref::heap_cell(h), addr);
|
||||
|
||||
// the former code of this match arm was:
|
||||
|
||||
@@ -1230,7 +1230,7 @@ impl MachineState {
|
||||
let h = self.heap.cell_len();
|
||||
push_cell!(self, heap_loc_as_cell!(h), return);
|
||||
|
||||
(self.bind_fn)(self, Ref::heap_cell(h), addr);
|
||||
self.occurs_check.bind(self, Ref::heap_cell(h), addr);
|
||||
self.registers[arg] = heap_loc_as_cell!(h);
|
||||
}
|
||||
|
||||
@@ -1276,7 +1276,7 @@ impl MachineState {
|
||||
if stored_v.is_stack_var() {
|
||||
let h = self.heap.cell_len();
|
||||
push_cell!(self, heap_loc_as_cell!(h), return);
|
||||
(self.bind_fn)(self, Ref::heap_cell(h), stored_v);
|
||||
self.occurs_check.bind(self, Ref::heap_cell(h), stored_v);
|
||||
} else {
|
||||
push_cell!(self, stored_v, return);
|
||||
}
|
||||
|
||||
@@ -57,6 +57,62 @@ pub enum OnEOF {
|
||||
Return,
|
||||
Continue,
|
||||
}
|
||||
pub(crate) trait OccursCheckImpl {
|
||||
fn flag_value(&self) -> Atom;
|
||||
fn unify(&self, state: &mut MachineState);
|
||||
fn bind(&self, state: &mut MachineState, r: Ref, h: HeapCellValue);
|
||||
}
|
||||
|
||||
/// Not subject to occurs-check
|
||||
pub(crate) struct Nsto;
|
||||
|
||||
impl OccursCheckImpl for Nsto {
|
||||
fn flag_value(&self) -> Atom {
|
||||
atom!("false")
|
||||
}
|
||||
|
||||
fn unify(&self, state: &mut MachineState) {
|
||||
state.unify();
|
||||
}
|
||||
|
||||
fn bind(&self, state: &mut MachineState, r: Ref, h: HeapCellValue) {
|
||||
state.bind(r, h);
|
||||
}
|
||||
}
|
||||
|
||||
/// Subject to occurs-check
|
||||
pub(crate) struct Sto;
|
||||
|
||||
impl OccursCheckImpl for Sto {
|
||||
fn flag_value(&self) -> Atom {
|
||||
atom!("true")
|
||||
}
|
||||
|
||||
fn unify(&self, state: &mut MachineState) {
|
||||
state.unify_with_occurs_check();
|
||||
}
|
||||
|
||||
fn bind(&self, state: &mut MachineState, r: Ref, h: HeapCellValue) {
|
||||
state.bind_with_occurs_check_wrapper(r, h);
|
||||
}
|
||||
}
|
||||
|
||||
/// Subject to occurs-check -> error
|
||||
pub(crate) struct StoError;
|
||||
|
||||
impl OccursCheckImpl for StoError {
|
||||
fn flag_value(&self) -> Atom {
|
||||
atom!("error")
|
||||
}
|
||||
|
||||
fn unify(&self, state: &mut MachineState) {
|
||||
state.unify_with_occurs_check_with_error();
|
||||
}
|
||||
|
||||
fn bind(&self, state: &mut MachineState, r: Ref, h: HeapCellValue) {
|
||||
state.bind_with_occurs_check_with_error_wrapper(r, h);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MachineState {
|
||||
pub atom_tbl: Arc<AtomTable>,
|
||||
@@ -94,8 +150,7 @@ pub struct MachineState {
|
||||
pub(crate) cc: usize,
|
||||
pub(crate) global_clock: usize,
|
||||
pub(crate) dynamic_mode: FirstOrNext,
|
||||
pub(crate) unify_fn: fn(&mut MachineState),
|
||||
pub(crate) bind_fn: fn(&mut MachineState, Ref, HeapCellValue),
|
||||
pub(crate) occurs_check: &'static dyn OccursCheckImpl,
|
||||
pub(crate) run_cleaners_fn: fn(&mut Machine) -> bool,
|
||||
}
|
||||
|
||||
@@ -129,28 +184,8 @@ impl fmt::Debug for MachineState {
|
||||
.field("cc", &self.cc)
|
||||
.field("global_clock", &self.global_clock)
|
||||
.field("dynamic_mode", &self.dynamic_mode)
|
||||
.field(
|
||||
"unify_fn",
|
||||
if self.unify_fn as usize == MachineState::unify as usize {
|
||||
&"MachineState::unify"
|
||||
} else if self.unify_fn as usize == MachineState::unify_with_occurs_check as usize {
|
||||
&"MachineState::unify_with_occurs_check"
|
||||
} else {
|
||||
&"MachineState::unify_with_occurs_check_with_error"
|
||||
},
|
||||
)
|
||||
.field(
|
||||
"bind_fn",
|
||||
if self.bind_fn as usize == MachineState::bind as usize {
|
||||
&"MachineState::bind"
|
||||
} else if self.bind_fn as usize
|
||||
== MachineState::bind_with_occurs_check_wrapper as usize
|
||||
{
|
||||
&"MachineState::bind_with_occurs_check"
|
||||
} else {
|
||||
&"MachineState::bind_with_occurs_check_with_error_wrapper"
|
||||
},
|
||||
)
|
||||
.field("unify_fn", &&*self.occurs_check.flag_value().as_str())
|
||||
.field("bind_fn", &&*self.occurs_check.flag_value().as_str())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,8 +61,7 @@ impl MachineState {
|
||||
cc: 0,
|
||||
global_clock: 0,
|
||||
dynamic_mode: FirstOrNext::First,
|
||||
unify_fn: MachineState::unify,
|
||||
bind_fn: MachineState::bind,
|
||||
occurs_check: &Nsto,
|
||||
run_cleaners_fn: |_| false,
|
||||
throwing_resource_error: false,
|
||||
}
|
||||
@@ -624,7 +623,7 @@ impl MachineState {
|
||||
}
|
||||
};
|
||||
|
||||
(self.bind_fn)(self, r, f_a);
|
||||
self.occurs_check.bind(self, r, f_a);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,42 @@ use crate::machine::machine_errors::CycleSearchResult;
|
||||
use crate::machine::system_calls::BrentAlgState;
|
||||
use crate::types::*;
|
||||
|
||||
trait StepperImpl {
|
||||
fn step<'a>(&self, iter: &mut HeapPStrIter<'a>) -> Option<PStrIteratee>;
|
||||
fn is_cyclic(&self) -> bool;
|
||||
}
|
||||
|
||||
struct PreCycleDiscoverStepper;
|
||||
|
||||
impl StepperImpl for PreCycleDiscoverStepper {
|
||||
fn step<'a>(&self, iter: &mut HeapPStrIter<'a>) -> Option<PStrIteratee> {
|
||||
iter.pre_cycle_discovery_stepper()
|
||||
}
|
||||
|
||||
fn is_cyclic(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
struct PostCycleDiscoverStepper;
|
||||
|
||||
impl StepperImpl for PostCycleDiscoverStepper {
|
||||
fn step<'a>(&self, iter: &mut HeapPStrIter<'a>) -> Option<PStrIteratee> {
|
||||
iter.post_cycle_discovery_stepper()
|
||||
}
|
||||
|
||||
fn is_cyclic(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct HeapPStrIter<'a> {
|
||||
pub heap: &'a Heap,
|
||||
// pub focus: HeapCellValue,
|
||||
orig_focus: usize,
|
||||
brent_st: BrentAlgState,
|
||||
stepper: fn(&mut HeapPStrIter<'a>) -> Option<PStrIteratee>,
|
||||
stepper: &'static dyn StepperImpl,
|
||||
}
|
||||
|
||||
struct PStrIterStep {
|
||||
@@ -33,7 +62,7 @@ impl<'a> HeapPStrIter<'a> {
|
||||
heap,
|
||||
orig_focus,
|
||||
brent_st: BrentAlgState::new(orig_focus),
|
||||
stepper: HeapPStrIter::pre_cycle_discovery_stepper,
|
||||
stepper: &PreCycleDiscoverStepper,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +190,7 @@ impl<'a> HeapPStrIter<'a> {
|
||||
debug_assert!(matches!(cycle_result, CycleSearchResult::Cyclic { .. }));
|
||||
|
||||
self.walk_hare_to_cycle_end();
|
||||
self.stepper = HeapPStrIter::post_cycle_discovery_stepper;
|
||||
self.stepper = &PostCycleDiscoverStepper;
|
||||
}
|
||||
None => {
|
||||
// self.focus = self.heap[next_hare];
|
||||
@@ -194,7 +223,7 @@ impl<'a> HeapPStrIter<'a> {
|
||||
}
|
||||
|
||||
pub(crate) fn is_cyclic(&self) -> bool {
|
||||
self.stepper as usize == Self::post_cycle_discovery_stepper as usize
|
||||
self.stepper.is_cyclic()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +232,7 @@ impl<'a> Iterator for HeapPStrIter<'a> {
|
||||
|
||||
#[inline(always)]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
(self.stepper)(self)
|
||||
self.stepper.step(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9230,36 +9230,25 @@ impl Machine {
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn is_sto_enabled(&mut self) {
|
||||
if self.machine_st.unify_fn as usize == MachineState::unify_with_occurs_check as usize {
|
||||
self.machine_st
|
||||
.unify_atom(atom!("true"), self.machine_st.registers[1]);
|
||||
} else if self.machine_st.unify_fn as usize
|
||||
== MachineState::unify_with_occurs_check_with_error as usize
|
||||
{
|
||||
self.machine_st
|
||||
.unify_atom(atom!("error"), self.machine_st.registers[1]);
|
||||
} else {
|
||||
self.machine_st
|
||||
.unify_atom(atom!("false"), self.machine_st.registers[1]);
|
||||
}
|
||||
self.machine_st.unify_atom(
|
||||
self.machine_st.occurs_check.flag_value(),
|
||||
self.machine_st.registers[1],
|
||||
);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn set_sto_as_unify(&mut self) {
|
||||
self.machine_st.unify_fn = MachineState::unify_with_occurs_check;
|
||||
self.machine_st.bind_fn = MachineState::bind_with_occurs_check_wrapper;
|
||||
self.machine_st.occurs_check = &Sto;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn set_nsto_as_unify(&mut self) {
|
||||
self.machine_st.unify_fn = MachineState::unify;
|
||||
self.machine_st.bind_fn = MachineState::bind;
|
||||
self.machine_st.occurs_check = &Nsto;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn set_sto_with_error_as_unify(&mut self) {
|
||||
self.machine_st.unify_fn = MachineState::unify_with_occurs_check_with_error;
|
||||
self.machine_st.bind_fn = MachineState::bind_with_occurs_check_with_error_wrapper;
|
||||
self.machine_st.occurs_check = &StoError;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
||||
@@ -415,7 +415,7 @@ macro_rules! unify {
|
||||
macro_rules! unify_fn {
|
||||
($machine_st:expr, $($value:expr),*) => {{
|
||||
$($machine_st.pdl.push($value);)*
|
||||
($machine_st.unify_fn)(&mut $machine_st)
|
||||
$machine_st.occurs_check.unify(&mut $machine_st)
|
||||
}};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user