Issue 3223: First phase of migration to Rust Edition 2024

Update cargo dependencies
Apply cargo fix --edition
Change cargo.toml edition property to `2024`

^ Conflicts:
^	Cargo.lock
^	src/ffi.rs

^ Conflicts:
^	src/offset_table.rs
^	src/raw_block.rs
This commit is contained in:
Alexander McLin
2026-04-02 15:55:45 -04:00
parent daaab1cb37
commit efbddeaeee
32 changed files with 389 additions and 395 deletions

View File

@@ -281,14 +281,14 @@ pub trait ArenaAllocated {
unsafe fn typed_ptr(ptr: UntypedArenaPtr) -> TypedArenaPtr<Self>
where
Self::Payload: Sized,
{
{ unsafe {
TypedArenaPtr(NonNull::new_unchecked(
ptr.get_ptr()
.byte_add(Self::header_offset_from_payload())
.cast_mut()
.cast::<Self::Payload>(),
))
}
}}
#[allow(clippy::missing_safety_doc)]
fn alloc(arena: &mut Arena, value: Self::Payload) -> TypedArenaPtr<Self>
@@ -496,7 +496,7 @@ impl Arena {
}
}
unsafe fn drop_slab_in_place(value: NonNull<AllocSlab>, tag: ArenaHeaderTag) {
unsafe fn drop_slab_in_place(value: NonNull<AllocSlab>, tag: ArenaHeaderTag) { unsafe {
macro_rules! drop_typed_slab_in_place {
($payload: ty, $value: expr) => {
<$payload as ArenaAllocated>::dealloc($value.cast::<TypedAllocSlab<$payload>>())
@@ -580,7 +580,7 @@ unsafe fn drop_slab_in_place(value: NonNull<AllocSlab>, tag: ArenaHeaderTag) {
unreachable!("NullStream is never arena allocated!");
}
}
}
}}
impl Drop for Arena {
fn drop(&mut self) {

View File

@@ -361,7 +361,7 @@ pub(crate) fn rnd_i(n: &'_ Number, arena: &mut Arena) -> Result<Number, EvalErro
)))
}
}
Number::Rational(ref r) => {
Number::Rational(r) => {
let floor = r.floor();
if let Ok(value) = Fixnum::build_with_checked(&floor) {
@@ -384,9 +384,9 @@ impl From<Fixnum> for Integer {
pub(crate) fn rnd_f(n: &Number) -> f64 {
match n {
&Number::Fixnum(n) => n.get_num() as f64,
Number::Integer(ref n) => n.to_f64().value(),
Number::Integer(n) => n.to_f64().value(),
&Number::Float(OrderedFloat(f)) => f,
Number::Rational(ref r) => r.to_f64().value(),
Number::Rational(r) => r.to_f64().value(),
}
}
@@ -514,33 +514,33 @@ impl PartialEq for Number {
fn eq(&self, rhs: &Self) -> bool {
match (self, rhs) {
(&Number::Fixnum(n1), &Number::Fixnum(n2)) => n1.eq(&n2),
(&Number::Fixnum(n1), Number::Integer(ref n2)) => n1.get_num().num_eq(&**n2),
(Number::Integer(ref n1), &Number::Fixnum(n2)) => n1.num_eq(&n2.get_num()),
(&Number::Fixnum(n1), Number::Rational(ref n2)) => {
(&Number::Fixnum(n1), Number::Integer(n2)) => n1.get_num().num_eq(&**n2),
(Number::Integer(n1), &Number::Fixnum(n2)) => n1.num_eq(&n2.get_num()),
(&Number::Fixnum(n1), Number::Rational(n2)) => {
Integer::from(n1.get_num()).num_eq(&**n2)
}
(Number::Rational(ref n1), &Number::Fixnum(n2)) => {
(Number::Rational(n1), &Number::Fixnum(n2)) => {
n1.num_eq(&Integer::from(n2.get_num()))
}
(&Number::Fixnum(n1), &Number::Float(n2)) => OrderedFloat(n1.get_num() as f64).eq(&n2),
(&Number::Float(n1), &Number::Fixnum(n2)) => n1.eq(&OrderedFloat(n2.get_num() as f64)),
(Number::Integer(ref n1), Number::Integer(ref n2)) => n1.eq(n2),
(Number::Integer(ref n1), Number::Float(n2)) => {
(Number::Integer(n1), Number::Integer(n2)) => n1.eq(n2),
(Number::Integer(n1), Number::Float(n2)) => {
OrderedFloat(n1.to_f64().value()).eq(n2)
}
(&Number::Float(n1), Number::Integer(ref n2)) => {
(&Number::Float(n1), Number::Integer(n2)) => {
n1.eq(&OrderedFloat(n2.to_f64().value()))
}
(Number::Integer(ref n1), Number::Rational(ref n2)) => n1.num_eq(&**n2),
(Number::Rational(ref n1), Number::Integer(ref n2)) => n1.num_eq(&**n2),
(Number::Rational(ref n1), &Number::Float(n2)) => {
(Number::Integer(n1), Number::Rational(n2)) => n1.num_eq(&**n2),
(Number::Rational(n1), Number::Integer(n2)) => n1.num_eq(&**n2),
(Number::Rational(n1), &Number::Float(n2)) => {
OrderedFloat(n1.to_f64().value()).eq(&n2)
}
(&Number::Float(n1), Number::Rational(ref n2)) => {
(&Number::Float(n1), Number::Rational(n2)) => {
n1.eq(&OrderedFloat(n2.to_f64().value()))
}
(&Number::Float(f1), &Number::Float(f2)) => f1.eq(&f2),
(Number::Rational(ref r1), Number::Rational(ref r2)) => r1.eq(r2),
(Number::Rational(r1), Number::Rational(r2)) => r1.eq(r2),
}
}
}
@@ -607,7 +607,7 @@ impl Ord for Number {
(&Number::Float(n1), &Number::Fixnum(n2)) => n1.cmp(&OrderedFloat(n2.get_num() as f64)),
(&Number::Integer(n1), &Number::Integer(n2)) => (*n1).cmp(&*n2),
(&Number::Integer(n1), Number::Float(n2)) => OrderedFloat(n1.to_f64().value()).cmp(n2),
(&Number::Float(n1), Number::Integer(ref n2)) => {
(&Number::Float(n1), Number::Integer(n2)) => {
n1.cmp(&OrderedFloat(n2.to_f64().value()))
}
(&Number::Integer(n1), &Number::Rational(n2)) => {

View File

@@ -387,10 +387,12 @@ impl Atom {
}
}
unsafe fn write_to_ptr(string: &str, ptr: *mut u8) {
ptr::write(ptr as *mut _, AtomHeader::build_with(string.len() as u64));
let str_ptr = ptr.add(mem::size_of::<AtomHeader>());
ptr::copy_nonoverlapping(string.as_ptr(), str_ptr, string.len());
unsafe fn write_to_ptr(string: &str, ptr: *mut u8) {
unsafe { ptr::write(ptr as *mut _, AtomHeader::build_with(string.len() as u64)); }
unsafe {
let str_ptr = ptr.add(mem::size_of::<AtomHeader>());
ptr::copy_nonoverlapping(string.as_ptr(), str_ptr, string.len());
}
}
impl PartialOrd for Atom {

View File

@@ -345,10 +345,10 @@ impl<'a> AddToFreeList<'a, QueryInstruction> for CodeGenerator {
fn structure_cell(term: &Term) -> Option<&Cell<RegType>> {
match term {
&Term::Cons(ref cell, ..)
| &Term::Clause(ref cell, ..)
| Term::PartialString(ref cell, ..)
| Term::CompleteString(ref cell, ..) => Some(cell),
Term::Cons(cell, ..)
| Term::Clause(cell, ..)
| Term::PartialString(cell, ..)
| Term::CompleteString(cell, ..) => Some(cell),
_ => None,
}
}
@@ -401,18 +401,18 @@ impl CodeGenerator {
&Term::AnonVar => {
Self::add_or_increment_void_instr::<Target>(target);
}
&Term::Cons(ref cell, ..)
| &Term::Clause(ref cell, ..)
| Term::PartialString(ref cell, ..)
| Term::CompleteString(ref cell, ..) => {
Term::Cons(cell, ..)
| Term::Clause(cell, ..)
| Term::PartialString(cell, ..)
| Term::CompleteString(cell, ..) => {
self.marker
.mark_non_var::<Target>(Level::Deep, term_loc, cell, target);
target.push_back(Target::clause_arg_to_instr(cell.get()));
}
Term::Literal(_, ref constant) => {
Term::Literal(_, constant) => {
target.push_back(Target::constant_subterm(*constant));
}
Term::Var(ref cell, ref var_ptr) => {
Term::Var(cell, var_ptr) => {
self.deep_var_instr::<Target>(
cell,
var_ptr.to_var_num().unwrap(),
@@ -572,7 +572,7 @@ impl CodeGenerator {
Term::Literal(_, Literal::Atom(..)) => {
instr!("$succeed")
}
Term::Var(ref vr, ref name) => {
Term::Var(vr, name) => {
self.marker.reset_arg(1);
let r = self.marker.mark_non_callable(
@@ -600,7 +600,7 @@ impl CodeGenerator {
Term::Literal(..) => {
instr!("$succeed")
}
Term::Var(ref vr, ref name) => {
Term::Var(vr, name) => {
self.marker.reset_arg(1);
let r = self.marker.mark_non_callable(
@@ -621,7 +621,7 @@ impl CodeGenerator {
| Term::CompleteString(..) => {
instr!("$succeed")
}
Term::Var(ref vr, ref name) => {
Term::Var(vr, name) => {
self.marker.reset_arg(1);
let r = self.marker.mark_non_callable(
@@ -733,7 +733,7 @@ impl CodeGenerator {
Term::Literal(_, Literal::Integer(_)) | Term::Literal(_, Literal::Fixnum(_)) => {
instr!("$succeed")
}
Term::Var(ref vr, name) => {
Term::Var(vr, name) => {
self.marker.reset_arg(1);
let r = self.marker.mark_non_callable(
@@ -828,7 +828,7 @@ impl CodeGenerator {
self.marker
.mark_anon_var::<QueryInstruction>(Level::Shallow, term_loc, code);
if let Term::Var(ref vr, ref var) = &terms[1] {
if let Term::Var(vr, var) = &terms[1] {
let var_num = var.to_var_num().unwrap();
// if var is an anonymous variable, insert

View File

@@ -158,7 +158,7 @@ impl DebrayAllocator {
for var_num in subsumed_hits {
match &mut self.var_data.records[var_num].allocation {
VarAlloc::Perm(_, ref mut allocation) => {
VarAlloc::Perm(_, allocation) => {
if let PermVarAllocation::Done {
shallow_safety,
deep_safety,
@@ -551,7 +551,7 @@ impl DebrayAllocator {
} else if let Some(&temp_var_num) = self.shallow_temp_mappings.get(&self.arg_c) {
match &mut self.var_data.records[temp_var_num].allocation {
VarAlloc::Temp {
ref mut to_perm_var_num,
to_perm_var_num,
..
} => {
*to_perm_var_num = Some(var_num);
@@ -560,7 +560,7 @@ impl DebrayAllocator {
}
}
}
VarAlloc::Temp { ref mut safety, .. } => {
VarAlloc::Temp { safety, .. } => {
*safety = VarSafetyStatus::GloballyUnneeded;
}
_ => {
@@ -581,7 +581,7 @@ impl DebrayAllocator {
VarAlloc::Perm(
_,
PermVarAllocation::Done {
ref mut shallow_safety,
shallow_safety,
..
},
) => {
@@ -617,7 +617,7 @@ impl DebrayAllocator {
VarAlloc::Perm(
_,
PermVarAllocation::Done {
ref mut deep_safety,
deep_safety,
..
},
) => {
@@ -631,7 +631,7 @@ impl DebrayAllocator {
Target::unsafe_subterm_to_value(r)
}
}
VarAlloc::Temp { ref mut safety, .. } => {
VarAlloc::Temp { safety, .. } => {
if self
.branch_stack
.safety_unneeded_in_branch(safety, &branch_designator)
@@ -874,7 +874,7 @@ impl Allocator for DebrayAllocator {
self.arity = args.len();
for (idx, arg) in args.iter().enumerate() {
if let Term::Var(_, ref var) = arg {
if let Term::Var(_, var) = arg {
let var_num = var.to_var_num().unwrap();
let r = self.get_binding(var_num);

View File

@@ -53,27 +53,27 @@ pub struct FunctionImpl {
}
impl FunctionImpl {
unsafe fn call_void(&self, args: &[Arg], _: &mut Arena) -> Result<Value, FfiError> {
unsafe fn call_void(&self, args: &[Arg], _: &mut Arena) -> Result<Value, FfiError> { unsafe {
self.cif.call_return_into(self.code_ptr, args, Ret::void());
Ok(Value::Number(Number::Fixnum(Fixnum::build_with(0))))
}
}}
unsafe fn call_int<T>(&self, args: &[Arg], arena: &mut Arena) -> Result<Value, FfiError>
where
Integer: From<T>,
T: Copy + TryInto<i64> + MightNotFitInFixnum,
{
{ unsafe {
let n = self.cif.call::<T>(self.code_ptr, args);
Ok(Value::Number(fixnum!(Number, n, arena)))
}
}}
unsafe fn call_float<T>(&self, args: &[Arg], _: &mut Arena) -> Result<Value, FfiError>
where
T: Into<f64>,
{
{ unsafe {
let n = self.cif.call::<T>(self.code_ptr, args);
Ok(Value::Number(Number::Float(OrderedFloat(n.into()))))
}
}}
unsafe fn call_ptr(&self, args: &[Arg], arena: &mut Arena) -> Result<Value, FfiError> {
let ptr = unsafe { self.cif.call::<*mut c_void>(self.code_ptr, args) };
@@ -197,14 +197,14 @@ impl StructImpl {
ptr: NonNull<c_void>,
layout: &mut Layout,
val: T,
) -> Result<(), FfiError> {
) -> Result<(), FfiError> { unsafe {
let (new_layout, offset) = layout
.extend(Layout::new::<T>())
.map_err(|_| FfiError::LayoutError)?;
*layout = new_layout;
ptr.byte_offset(offset as isize).cast::<T>().write(val);
Ok(())
}
}}
for arg in args {
unsafe {
@@ -258,14 +258,14 @@ impl StructImpl {
unsafe fn read_primitive<T>(
ptr: *mut c_void,
layout: &mut Layout,
) -> Result<T, FfiError> {
) -> Result<T, FfiError> { unsafe {
let (new_layout, offset) = layout
.extend(Layout::new::<T>())
.map_err(|_| FfiError::LayoutError)?;
*layout = new_layout;
let n = std::ptr::read::<T>(ptr.byte_offset(offset as isize).cast());
Ok(n)
}
}}
unsafe fn read_int<T>(
ptr: *mut c_void,
@@ -275,10 +275,10 @@ impl StructImpl {
where
T: Copy + TryInto<i64> + MightNotFitInFixnum,
Integer: From<T>,
{
{ unsafe {
let n = read_primitive::<T>(ptr, layout)?;
Ok(Value::Number(fixnum!(Number, n, arena)))
}
}}
unsafe fn read_float<T>(
ptr: *mut c_void,
@@ -286,10 +286,10 @@ impl StructImpl {
) -> Result<Value, FfiError>
where
T: Into<f64>,
{
{ unsafe {
let n = read_primitive::<T>(ptr, layout)?;
Ok(Value::Number(Number::Float(OrderedFloat(n.into()))))
}
}}
let mut layout = Layout::from_size_align(0, 1).map_err(|_| FfiError::LayoutError)?;
@@ -788,10 +788,10 @@ impl ForeignFunctionTable {
where
T: Copy + TryInto<i64> + MightNotFitInFixnum,
Integer: From<T>,
{
{ unsafe {
let n = ptr.cast::<T>().read();
Value::Number(fixnum!(Number, n, arena))
}
}}
let ptr = ptr.as_ptr()?;
@@ -924,7 +924,7 @@ impl Value {
fn as_ptr(&mut self) -> Result<*mut c_void, FfiError> {
match self {
Value::CString(ref mut cstr) => Ok(cstr.as_ptr().cast_mut().cast()),
Value::CString(cstr) => Ok(cstr.as_ptr().cast_mut().cast()),
Value::Number(Number::Fixnum(fixnum)) => Ok(std::ptr::with_exposed_provenance_mut(
fixnum.get_num() as usize,
)),

View File

@@ -389,15 +389,15 @@ impl ClauseInfo for Rule {
impl ClauseInfo for PredicateClause {
fn name(&self) -> Option<Atom> {
match self {
PredicateClause::Fact(ref term, ..) => term.head.name(),
PredicateClause::Rule(ref rule, ..) => rule.name(),
PredicateClause::Fact(term, ..) => term.head.name(),
PredicateClause::Rule(rule, ..) => rule.name(),
}
}
fn arity(&self) -> usize {
match self {
PredicateClause::Fact(ref term, ..) => term.head.arity(),
PredicateClause::Rule(ref rule, ..) => rule.arity(),
PredicateClause::Fact(term, ..) => term.head.arity(),
PredicateClause::Rule(rule, ..) => rule.arity(),
}
}
}
@@ -582,7 +582,7 @@ pub(crate) fn fetch_op_spec_from_existing(
op_desc: Option<OpDesc>,
op_dir: &OpDir,
) -> Option<OpDesc> {
if let Some(ref op_desc) = &op_desc {
if let Some(op_desc) = &op_desc {
if op_desc.arity() != arity {
/* it's possible to extend operator functors with
* additional terms. When that happens,
@@ -843,9 +843,9 @@ impl Number {
pub(crate) fn is_positive(&self) -> bool {
match self {
Number::Fixnum(n) => n.get_num() > 0,
Number::Integer(ref n) => n.is_positive(),
Number::Integer(n) => n.is_positive(),
Number::Float(f) => f.is_sign_positive(),
Number::Rational(ref r) => r.is_positive(),
Number::Rational(r) => r.is_positive(),
}
}
@@ -853,9 +853,9 @@ impl Number {
pub(crate) fn is_negative(&self) -> bool {
match self {
Number::Fixnum(n) => n.get_num() < 0,
Number::Integer(ref n) => n.is_negative(),
Number::Integer(n) => n.is_negative(),
&Number::Float(OrderedFloat(f)) => f.is_sign_negative() && f != -0f64,
Number::Rational(ref r) => r.is_negative(),
Number::Rational(r) => r.is_negative(),
}
}
@@ -863,9 +863,9 @@ impl Number {
pub(crate) fn is_zero(&self) -> bool {
match self {
Number::Fixnum(n) => n.get_num() == 0,
Number::Integer(ref n) => n.is_zero(),
Number::Integer(n) => n.is_zero(),
&Number::Float(OrderedFloat(f)) => f == 0.0 || f == -0.0,
Number::Rational(ref r) => r.is_zero(),
Number::Rational(r) => r.is_zero(),
}
}
@@ -920,9 +920,9 @@ impl OptArgIndexKey {
#[inline]
pub(crate) fn set_switch_on_term_loc(&mut self, value: usize) {
match self {
OptArgIndexKey::Literal(_, ref mut loc, ..)
| OptArgIndexKey::Structure(_, ref mut loc, ..)
| OptArgIndexKey::List(_, ref mut loc) => {
OptArgIndexKey::Literal(_, loc, ..)
| OptArgIndexKey::Structure(_, loc, ..)
| OptArgIndexKey::List(_, loc) => {
*loc = value;
}
OptArgIndexKey::None => {}
@@ -934,9 +934,9 @@ impl AddAssign<usize> for OptArgIndexKey {
#[inline]
fn add_assign(&mut self, n: usize) {
match self {
OptArgIndexKey::Literal(_, ref mut o, ..)
| OptArgIndexKey::List(_, ref mut o)
| OptArgIndexKey::Structure(_, ref mut o, ..) => {
OptArgIndexKey::Literal(_, o, ..)
| OptArgIndexKey::List(_, o)
| OptArgIndexKey::Structure(_, o, ..) => {
*o += n;
}
OptArgIndexKey::None => {}

View File

@@ -387,7 +387,7 @@ fn negated_op_needs_bracketing(
op_dir: &OpDir,
op: &Option<DirectedOp>,
) -> bool {
if let Some(ref op) = op {
if let Some(op) = op {
op.is_negative_sign()
&& iter.leftmost_leaf_has_property(op_dir, |addr| {
match Number::try_from((addr, f64_tbl)) {
@@ -1452,7 +1452,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
});
for op in &[op, parent_op] {
if let Some(ref op) = &op {
if let Some(op) = &op {
if op.is_left()
&& (op.is_prefix() || requires_space(&op.as_atom().as_str(), "("))
{

View File

@@ -167,7 +167,7 @@ impl<'a> IndexingCodeMergingPtr<'a> {
.push(IndexingLine::IndexedChoice(third_level_index));
match &mut self.indexing_code[self.offset] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnConstant(ref mut constants)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnConstant(constants)) => {
constants.insert(
constant,
IndexingCodePtr::Internal(indexing_code_len - self.offset),
@@ -196,7 +196,7 @@ impl<'a> IndexingCodeMergingPtr<'a> {
.push(IndexingLine::DynamicIndexedChoice(third_level_index));
match &mut self.indexing_code[self.offset] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnConstant(ref mut constants)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnConstant(constants)) => {
constants.insert(
constant,
IndexingCodePtr::Internal(indexing_code_len - self.offset),
@@ -210,22 +210,22 @@ impl<'a> IndexingCodeMergingPtr<'a> {
fn extend_indexed_choice(&mut self, index: usize) {
match &mut self.indexing_code[self.offset] {
IndexingLine::IndexedChoice(ref mut indexed_choice_instrs)
IndexingLine::IndexedChoice(indexed_choice_instrs)
if self.append_or_prepend.is_append() =>
{
uncap_choice_seq_with_trust(indexed_choice_instrs.make_contiguous());
indexed_choice_instrs.push_back(IndexedChoiceInstruction::Trust(index));
}
IndexingLine::IndexedChoice(ref mut indexed_choice_instrs) => {
IndexingLine::IndexedChoice(indexed_choice_instrs) => {
uncap_choice_seq_with_try(indexed_choice_instrs.make_contiguous());
indexed_choice_instrs.push_front(IndexedChoiceInstruction::Try(index));
}
IndexingLine::DynamicIndexedChoice(ref mut indexed_choice_instrs)
IndexingLine::DynamicIndexedChoice(indexed_choice_instrs)
if self.append_or_prepend.is_append() =>
{
indexed_choice_instrs.push_back(index);
}
IndexingLine::DynamicIndexedChoice(ref mut indexed_choice_instrs) => {
IndexingLine::DynamicIndexedChoice(indexed_choice_instrs) => {
indexed_choice_instrs.push_front(index);
}
_ => {
@@ -244,7 +244,7 @@ impl<'a> IndexingCodeMergingPtr<'a> {
let indexing_code_len = self.indexing_code.len();
match &mut self.indexing_code[self.offset] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, ref mut c, ..)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, c, ..)) => {
match *c {
IndexingCodePtr::Fail if self.is_dynamic => {
*c = IndexingCodePtr::DynamicExternal(index);
@@ -322,7 +322,7 @@ impl<'a> IndexingCodeMergingPtr<'a> {
let indexing_code_len = self.indexing_code.len();
match &mut self.indexing_code[self.offset] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, ref mut c, ..)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, c, ..)) => {
match *c {
IndexingCodePtr::Fail if self.is_dynamic => {
*c = IndexingCodePtr::DynamicExternal(index);
@@ -445,7 +445,7 @@ impl<'a> IndexingCodeMergingPtr<'a> {
.push(IndexingLine::IndexedChoice(third_level_index));
match &mut self.indexing_code[self.offset] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnStructure(ref mut structures)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnStructure(structures)) => {
structures.insert(
key,
IndexingCodePtr::Internal(indexing_code_len - self.offset),
@@ -474,7 +474,7 @@ impl<'a> IndexingCodeMergingPtr<'a> {
.push(IndexingLine::DynamicIndexedChoice(third_level_index));
match &mut self.indexing_code[self.offset] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnStructure(ref mut structures)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnStructure(structures)) => {
structures.insert(
key,
IndexingCodePtr::Internal(indexing_code_len - self.offset),
@@ -496,7 +496,7 @@ impl<'a> IndexingCodeMergingPtr<'a> {
_,
_,
_,
ref mut s,
s,
)) => match *s {
IndexingCodePtr::Fail if self.is_dynamic => {
*s = IndexingCodePtr::DynamicExternal(index);
@@ -559,7 +559,7 @@ impl<'a> IndexingCodeMergingPtr<'a> {
let indexing_code_len = self.indexing_code.len();
match &mut self.indexing_code[self.offset] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, _, ref mut l, _)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, _, l, _)) => {
match *l {
IndexingCodePtr::Fail if self.is_dynamic => {
*l = IndexingCodePtr::DynamicExternal(index);
@@ -632,7 +632,7 @@ pub(crate) fn merge_clause_index(
);
match &opt_arg_index_key {
OptArgIndexKey::Literal(_, index_loc, constant, ref overlapping_constants) => {
OptArgIndexKey::Literal(_, index_loc, constant, overlapping_constants) => {
let offset = new_clause_loc - index_loc + 1;
merging_ptr.index_constant(HeapCellValue::from(*constant), offset);
@@ -676,7 +676,7 @@ pub(crate) fn remove_constant_indices(
let iter = once(&constant).chain(overlapping_constants.iter());
match &mut indexing_code[index] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, ref mut c, ..)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, c, ..)) => {
match *c {
IndexingCodePtr::DynamicExternal(_) | IndexingCodePtr::External(_) => {
*c = IndexingCodePtr::Fail;
@@ -701,7 +701,7 @@ pub(crate) fn remove_constant_indices(
loop {
match &mut indexing_code[index] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnConstant(
ref mut constants,
constants,
)) => {
constants_index = index;
@@ -720,7 +720,7 @@ pub(crate) fn remove_constant_indices(
}
}
}
IndexingLine::IndexedChoice(ref mut indexed_choice_instrs) => {
IndexingLine::IndexedChoice(indexed_choice_instrs) => {
StaticCodeIndices::remove_instruction_with_offset(
indexed_choice_instrs,
offset,
@@ -734,13 +734,13 @@ pub(crate) fn remove_constant_indices(
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(
_,
_,
ref mut c,
c,
..,
)) => {
*c = ext;
}
IndexingLine::Indexing(IndexingInstruction::SwitchOnConstant(
ref mut constants,
constants,
)) => {
constants.insert(constant, ext);
}
@@ -753,7 +753,7 @@ pub(crate) fn remove_constant_indices(
break;
}
IndexingLine::DynamicIndexedChoice(ref mut indexed_choice_instrs) => {
IndexingLine::DynamicIndexedChoice(indexed_choice_instrs) => {
DynamicCodeIndices::remove_instruction_with_offset(
indexed_choice_instrs,
offset,
@@ -767,13 +767,13 @@ pub(crate) fn remove_constant_indices(
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(
_,
_,
ref mut c,
c,
..,
)) => {
*c = ext;
}
IndexingLine::Indexing(IndexingInstruction::SwitchOnConstant(
ref mut constants,
constants,
)) => {
constants.insert(constant, ext);
}
@@ -794,11 +794,11 @@ pub(crate) fn remove_constant_indices(
}
match &indexing_code[constants_index] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnConstant(ref constants))
IndexingLine::Indexing(IndexingInstruction::SwitchOnConstant(constants))
if constants.is_empty() =>
{
match &mut indexing_code[0] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, ref mut c, ..)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, c, ..)) => {
*c = IndexingCodePtr::Fail;
}
_ => {
@@ -819,7 +819,7 @@ pub(crate) fn remove_structure_index(
let mut index = 0;
match &mut indexing_code[index] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, _, _, ref mut s)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, _, _, s)) => {
match *s {
IndexingCodePtr::DynamicExternal(_) | IndexingCodePtr::External(_) => {
*s = IndexingCodePtr::Fail;
@@ -842,7 +842,7 @@ pub(crate) fn remove_structure_index(
loop {
match &mut indexing_code[index] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnStructure(ref mut structures)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnStructure(structures)) => {
structures_index = index;
match structures.get(&(name, arity)).cloned() {
@@ -859,7 +859,7 @@ pub(crate) fn remove_structure_index(
}
}
}
IndexingLine::IndexedChoice(ref mut indexed_choice_instrs) => {
IndexingLine::IndexedChoice(indexed_choice_instrs) => {
StaticCodeIndices::remove_instruction_with_offset(indexed_choice_instrs, offset);
if indexed_choice_instrs.len() == 1 {
@@ -872,12 +872,12 @@ pub(crate) fn remove_structure_index(
_,
_,
_,
ref mut s,
s,
)) => {
*s = ext;
}
IndexingLine::Indexing(IndexingInstruction::SwitchOnStructure(
ref mut structures,
structures,
)) => {
structures.insert((name, arity), ext);
}
@@ -890,7 +890,7 @@ pub(crate) fn remove_structure_index(
break;
}
IndexingLine::DynamicIndexedChoice(ref mut indexed_choice_instrs) => {
IndexingLine::DynamicIndexedChoice(indexed_choice_instrs) => {
DynamicCodeIndices::remove_instruction_with_offset(indexed_choice_instrs, offset);
if indexed_choice_instrs.len() == 1 {
@@ -903,12 +903,12 @@ pub(crate) fn remove_structure_index(
_,
_,
_,
ref mut s,
s,
)) => {
*s = ext;
}
IndexingLine::Indexing(IndexingInstruction::SwitchOnStructure(
ref mut structures,
structures,
)) => {
structures.insert((name, arity), ext);
}
@@ -928,7 +928,7 @@ pub(crate) fn remove_structure_index(
}
match &indexing_code[structures_index] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnStructure(ref structures))
IndexingLine::Indexing(IndexingInstruction::SwitchOnStructure(structures))
if structures.is_empty() =>
{
match &mut indexing_code[0] {
@@ -937,7 +937,7 @@ pub(crate) fn remove_structure_index(
_,
_,
_,
ref mut s,
s,
)) => {
*s = IndexingCodePtr::Fail;
}
@@ -954,7 +954,7 @@ pub(crate) fn remove_list_index(indexing_code: &mut [IndexingLine], offset: usiz
let mut index = 0;
match &mut indexing_code[index] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, _, ref mut l, _)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, _, l, _)) => {
match *l {
IndexingCodePtr::DynamicExternal(_) | IndexingCodePtr::External(_) => {
*l = IndexingCodePtr::Fail;
@@ -974,7 +974,7 @@ pub(crate) fn remove_list_index(indexing_code: &mut [IndexingLine], offset: usiz
}
match &mut indexing_code[index] {
IndexingLine::IndexedChoice(ref mut indexed_choice_instrs) => {
IndexingLine::IndexedChoice(indexed_choice_instrs) => {
StaticCodeIndices::remove_instruction_with_offset(indexed_choice_instrs, offset);
if indexed_choice_instrs.len() == 1 {
@@ -986,7 +986,7 @@ pub(crate) fn remove_list_index(indexing_code: &mut [IndexingLine], offset: usiz
_,
_,
_,
ref mut l,
l,
_,
)) => {
*l = ext;
@@ -998,7 +998,7 @@ pub(crate) fn remove_list_index(indexing_code: &mut [IndexingLine], offset: usiz
}
}
}
IndexingLine::DynamicIndexedChoice(ref mut indexed_choice_instrs) => {
IndexingLine::DynamicIndexedChoice(indexed_choice_instrs) => {
DynamicCodeIndices::remove_instruction_with_offset(indexed_choice_instrs, offset);
if indexed_choice_instrs.len() == 1 {
@@ -1010,7 +1010,7 @@ pub(crate) fn remove_list_index(indexing_code: &mut [IndexingLine], offset: usiz
_,
_,
_,
ref mut l,
l,
_,
)) => {
*l = ext;
@@ -1034,7 +1034,7 @@ pub(crate) fn remove_index(
clause_loc: usize,
) {
match opt_arg_index_key {
OptArgIndexKey::Literal(_, _, constant, ref overlapping_constants) => {
OptArgIndexKey::Literal(_, _, constant, overlapping_constants) => {
remove_constant_indices(*constant, *overlapping_constants, indexing_code, clause_loc);
}
OptArgIndexKey::Structure(_, _, name, arity) => {
@@ -1525,11 +1525,11 @@ impl<I: Indexer> CodeOffsets<I> {
&mut prelude,
);
if let IndexingCodePtr::Internal(ref mut i) = &mut str_loc {
if let IndexingCodePtr::Internal(i) = &mut str_loc {
*i += emitted_switch_on_constant as usize; // con_loc.is_internal() as usize;
}
if let IndexingCodePtr::Internal(ref mut i) = &mut lst_loc {
if let IndexingCodePtr::Internal(i) = &mut lst_loc {
*i += emitted_switch_on_constant as usize; // con_loc.is_internal() as usize;
*i += emitted_switch_on_structure as usize; // str_loc.is_internal() as usize;
}

View File

@@ -251,7 +251,7 @@ impl Instruction {
#[inline]
pub fn to_indexing_line_mut(&mut self) -> Option<&mut Vec<IndexingLine>> {
match self {
Instruction::IndexingCode(ref mut indexing_code) => Some(indexing_code),
Instruction::IndexingCode(indexing_code) => Some(indexing_code),
_ => None,
}
}
@@ -259,7 +259,7 @@ impl Instruction {
#[inline]
pub fn to_indexing_line(&self) -> Option<&Vec<IndexingLine>> {
match self {
Instruction::IndexingCode(ref indexing_code) => Some(indexing_code),
Instruction::IndexingCode(indexing_code) => Some(indexing_code),
_ => None,
}
}
@@ -1372,12 +1372,12 @@ impl Instruction {
impl CompareNumber {
pub fn set_terms(&mut self, l_at_1: ArithmeticTerm, l_at_2: ArithmeticTerm) {
match self {
CompareNumber::NumberGreaterThan(ref mut at_1, ref mut at_2)
| CompareNumber::NumberLessThan(ref mut at_1, ref mut at_2)
| CompareNumber::NumberGreaterThanOrEqual(ref mut at_1, ref mut at_2)
| CompareNumber::NumberLessThanOrEqual(ref mut at_1, ref mut at_2)
| CompareNumber::NumberNotEqual(ref mut at_1, ref mut at_2)
| CompareNumber::NumberEqual(ref mut at_1, ref mut at_2) => {
CompareNumber::NumberGreaterThan(at_1, at_2)
| CompareNumber::NumberLessThan(at_1, at_2)
| CompareNumber::NumberGreaterThanOrEqual(at_1, at_2)
| CompareNumber::NumberLessThanOrEqual(at_1, at_2)
| CompareNumber::NumberNotEqual(at_1, at_2)
| CompareNumber::NumberEqual(at_1, at_2) => {
*at_1 = l_at_1;
*at_2 = l_at_2;
}

View File

@@ -103,11 +103,11 @@ impl<'a> QueryIterator<'a> {
fn extend_state(&mut self, lvl: Level, term: &'a QueryTerm) {
match term {
QueryTerm::Clause(ref cell, ClauseType::CallN(_), ref terms, _) => {
QueryTerm::Clause(cell, ClauseType::CallN(_), terms, _) => {
self.state_stack
.push(TermIterState::Clause(lvl, 1, cell, atom!("$call"), terms));
}
QueryTerm::Clause(ref cell, ref ct, ref terms, _) => {
QueryTerm::Clause(cell, ct, terms, _) => {
self.state_stack
.push(TermIterState::Clause(lvl, 0, cell, ct.name(), terms));
}
@@ -419,7 +419,7 @@ impl<'a> Iterator for ClauseIterator<'a> {
self.state_stack
.push(ClauseIteratorState::RemainingBranches(branch_nums, arms, 0));
}
ChunkedTerms::Chunk { ref terms } => {
ChunkedTerms::Chunk { terms } => {
return Some(ClauseItem::Chunk { terms });
}
}

View File

@@ -62,7 +62,7 @@ impl MachineState {
.attr_var_init
.bindings
.iter()
.map(|(ref h, _)| attr_var_as_cell!(*h));
.map(|(h, _)| attr_var_as_cell!(*h));
let var_list_addr = sized_iter_to_heap_list(&mut self.heap, size, iter)?;
let iter = self.attr_var_init.bindings.drain(0..).map(|(_, ref v)| *v);

View File

@@ -80,19 +80,19 @@ fn derelictize_try_me_else(
) -> Option<usize> {
match &mut code[index] {
Instruction::DynamicElse(_, _, NextOrFail::Next(0)) => None,
Instruction::DynamicElse(_, _, NextOrFail::Next(ref mut o)) => {
Instruction::DynamicElse(_, _, NextOrFail::Next(o)) => {
retraction_info.push_record(RetractionRecord::ReplacedDynamicElseOffset(index, *o));
Some(mem::replace(o, 0))
}
Instruction::DynamicInternalElse(_, _, NextOrFail::Next(0)) => None,
Instruction::DynamicInternalElse(_, _, NextOrFail::Next(ref mut o)) => {
Instruction::DynamicInternalElse(_, _, NextOrFail::Next(o)) => {
retraction_info.push_record(RetractionRecord::ReplacedDynamicElseOffset(index, *o));
Some(mem::replace(o, 0))
}
Instruction::DynamicElse(_, _, NextOrFail::Fail(_))
| Instruction::DynamicInternalElse(_, _, NextOrFail::Fail(_)) => None,
Instruction::TryMeElse(0) => None,
Instruction::TryMeElse(ref mut o) => {
Instruction::TryMeElse(o) => {
retraction_info.push_record(RetractionRecord::ModifiedTryMeElse(index, *o));
Some(mem::replace(o, 0))
}
@@ -275,7 +275,7 @@ fn merge_indexed_subsequences(
.unwrap(),
);
if let Instruction::TryMeElse(ref mut o) = &mut code[inner_try_me_else_loc] {
if let Instruction::TryMeElse(o) = &mut code[inner_try_me_else_loc] {
retraction_info.push_record(RetractionRecord::ModifiedTryMeElse(
inner_try_me_else_loc,
*o,
@@ -324,7 +324,7 @@ fn merge_indexed_subsequences(
);
}
None => {
if let Instruction::TryMeElse(ref mut o) = &mut code[outer_threaded_choice_instr_loc] {
if let Instruction::TryMeElse(o) = &mut code[outer_threaded_choice_instr_loc] {
retraction_info
.push_record(RetractionRecord::ModifiedTryMeElse(inner_trust_me_loc, *o));
@@ -472,7 +472,7 @@ fn set_switch_var_offset(
let target_indexing_line = code[index_loc].to_indexing_line_mut().unwrap();
let old_v = match &mut target_indexing_line[0] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, ref mut v, ..)) => match *v {
IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, v, ..)) => match *v {
IndexingCodePtr::DynamicExternal(_) => {
mem::replace(v, IndexingCodePtr::DynamicExternal(offset))
}
@@ -497,7 +497,7 @@ fn internalize_choice_instr_at(
match &mut code[instr_loc] {
Instruction::DynamicElse(_, _, NextOrFail::Fail(_))
| Instruction::DynamicInternalElse(_, _, NextOrFail::Fail(_)) => {}
Instruction::DynamicElse(_, _, ref mut o @ NextOrFail::Next(0)) => {
Instruction::DynamicElse(_, _, o @ NextOrFail::Next(0)) => {
retraction_info.push_record(RetractionRecord::ReplacedDynamicElseOffset(instr_loc, 0));
*o = NextOrFail::Fail(0);
}
@@ -516,7 +516,7 @@ fn internalize_choice_instr_at(
}
}
}
Instruction::DynamicInternalElse(_, _, ref mut o @ NextOrFail::Next(0)) => {
Instruction::DynamicInternalElse(_, _, o @ NextOrFail::Next(0)) => {
retraction_info.push_record(RetractionRecord::ReplacedDynamicElseOffset(instr_loc, 0));
*o = NextOrFail::Fail(0);
}
@@ -564,7 +564,7 @@ fn thread_choice_instr_at_to(
) {
loop {
match &mut code[instr_loc] {
Instruction::TryMeElse(ref mut o) | Instruction::RetryMeElse(ref mut o)
Instruction::TryMeElse(o) | Instruction::RetryMeElse(o)
if target_loc >= instr_loc =>
{
retraction_info.push_record(RetractionRecord::ReplacedChoiceOffset(instr_loc, *o));
@@ -572,8 +572,8 @@ fn thread_choice_instr_at_to(
*o = target_loc - instr_loc;
return;
}
Instruction::DynamicElse(_, _, NextOrFail::Next(ref mut o))
| Instruction::DynamicInternalElse(_, _, NextOrFail::Next(ref mut o))
Instruction::DynamicElse(_, _, NextOrFail::Next(o))
| Instruction::DynamicInternalElse(_, _, NextOrFail::Next(o))
if target_loc >= instr_loc =>
{
retraction_info
@@ -588,7 +588,7 @@ fn thread_choice_instr_at_to(
Instruction::TryMeElse(o) | Instruction::RetryMeElse(o) => {
instr_loc += *o;
}
Instruction::RevJmpBy(ref mut o) if instr_loc >= target_loc => {
Instruction::RevJmpBy(o) if instr_loc >= target_loc => {
retraction_info.push_record(RetractionRecord::ModifiedRevJmpBy(instr_loc, *o));
*o = instr_loc - target_loc;
@@ -631,7 +631,7 @@ fn thread_choice_instr_at_to(
Instruction::DynamicInternalElse(_, _, NextOrFail::Fail(o)) if *o > 0 => {
instr_loc += *o;
}
Instruction::TrustMe(ref mut o) if target_loc >= instr_loc => {
Instruction::TrustMe(o) if target_loc >= instr_loc => {
retraction_info.push_record(
RetractionRecord::AppendedTrustMe(instr_loc, *o, false),
//choice_instr.is_default()),
@@ -657,7 +657,7 @@ fn remove_non_leading_clause(
retraction_info: &mut RetractionInfo,
) -> Option<IndexPtr> {
match &mut code[non_indexed_choice_instr_loc] {
Instruction::RetryMeElse(ref mut o) => {
Instruction::RetryMeElse(o) => {
let o = *o;
thread_choice_instr_at_to(
@@ -680,7 +680,7 @@ fn remove_non_leading_clause(
None
}
Instruction::TryMeElse(ref mut o) => {
Instruction::TryMeElse(o) => {
retraction_info.push_record(RetractionRecord::ModifiedTryMeElse(
preceding_choice_instr_loc,
*o,
@@ -730,7 +730,7 @@ fn remove_leading_unindexed_clause(
retraction_info: &mut RetractionInfo,
) -> Option<IndexPtr> {
match &mut code[non_indexed_choice_instr_loc] {
Instruction::TryMeElse(ref mut o) => {
Instruction::TryMeElse(o) => {
if *o > 0 {
retraction_info.push_record(RetractionRecord::ModifiedTryMeElse(
non_indexed_choice_instr_loc,
@@ -935,10 +935,10 @@ fn prepend_compiled_clause(
let prepend_queue_len = prepend_queue.len();
match &mut prepend_queue[1] {
Instruction::TryMeElse(ref mut o) if *o == 0 => {
Instruction::TryMeElse(o) if *o == 0 => {
*o = prepend_queue_len - 2;
}
Instruction::DynamicInternalElse(_, _, ref mut o @ NextOrFail::Next(0)) => {
Instruction::DynamicInternalElse(_, _, o @ NextOrFail::Next(0)) => {
*o = NextOrFail::Fail(prepend_queue_len - 2);
}
_ => {
@@ -1632,8 +1632,8 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
};
match &mut self.wam_prelude.code[clause_loc] {
Instruction::DynamicElse(_, ref mut d, _)
| Instruction::DynamicInternalElse(_, ref mut d, _) => {
Instruction::DynamicElse(_, d, _)
| Instruction::DynamicInternalElse(_, d, _) => {
*d = Death::Finite(LS::machine_st(&mut self.payload).global_clock);
}
_ => unreachable!(),

View File

@@ -1365,8 +1365,8 @@ impl Machine {
let p = self.machine_st.p;
let indexed_choice_instrs = match &self.code[p] {
Instruction::IndexingCode(ref indexing_code) => match &indexing_code[oi as usize] {
IndexingLine::DynamicIndexedChoice(ref indexed_choice_instrs) => {
Instruction::IndexingCode(indexing_code) => match &indexing_code[oi as usize] {
IndexingLine::DynamicIndexedChoice(indexed_choice_instrs) => {
indexed_choice_instrs
}
_ => unreachable!(),
@@ -1376,7 +1376,7 @@ impl Machine {
loop {
match &indexed_choice_instrs.get(ii as usize) {
Some(&offset) => match &self.code[p + offset - 1] {
&Some(&offset) => match &self.code[p + offset - 1] {
&Instruction::DynamicInternalElse(birth, death, next_or_fail) => {
if birth < self.machine_st.cc && Death::Finite(self.machine_st.cc) <= death
{
@@ -2670,7 +2670,7 @@ impl Machine {
self.machine_st.backtrack();
}
}
Instruction::CallNumberLessThanOrEqual(ref at_1, ref at_2) => {
Instruction::CallNumberLessThanOrEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2692,7 +2692,7 @@ impl Machine {
}
}
}
Instruction::ExecuteNumberLessThanOrEqual(ref at_1, ref at_2) => {
Instruction::ExecuteNumberLessThanOrEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2714,7 +2714,7 @@ impl Machine {
}
}
}
Instruction::CallNumberEqual(ref at_1, ref at_2) => {
Instruction::CallNumberEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2736,7 +2736,7 @@ impl Machine {
}
}
}
Instruction::ExecuteNumberEqual(ref at_1, ref at_2) => {
Instruction::ExecuteNumberEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2758,7 +2758,7 @@ impl Machine {
}
}
}
Instruction::CallNumberNotEqual(ref at_1, ref at_2) => {
Instruction::CallNumberNotEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2780,7 +2780,7 @@ impl Machine {
}
}
}
Instruction::ExecuteNumberNotEqual(ref at_1, ref at_2) => {
Instruction::ExecuteNumberNotEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2802,7 +2802,7 @@ impl Machine {
}
}
}
Instruction::CallNumberGreaterThanOrEqual(ref at_1, ref at_2) => {
Instruction::CallNumberGreaterThanOrEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2824,7 +2824,7 @@ impl Machine {
}
}
}
Instruction::ExecuteNumberGreaterThanOrEqual(ref at_1, ref at_2) => {
Instruction::ExecuteNumberGreaterThanOrEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2846,7 +2846,7 @@ impl Machine {
}
}
}
Instruction::CallNumberGreaterThan(ref at_1, ref at_2) => {
Instruction::CallNumberGreaterThan(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2868,7 +2868,7 @@ impl Machine {
}
}
}
Instruction::ExecuteNumberGreaterThan(ref at_1, ref at_2) => {
Instruction::ExecuteNumberGreaterThan(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2890,7 +2890,7 @@ impl Machine {
}
}
}
Instruction::CallNumberLessThan(ref at_1, ref at_2) => {
Instruction::CallNumberLessThan(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2912,7 +2912,7 @@ impl Machine {
}
}
}
Instruction::ExecuteNumberLessThan(ref at_1, ref at_2) => {
Instruction::ExecuteNumberLessThan(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2934,7 +2934,7 @@ impl Machine {
}
}
}
Instruction::DefaultCallNumberLessThanOrEqual(ref at_1, ref at_2) => {
Instruction::DefaultCallNumberLessThanOrEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2955,7 +2955,7 @@ impl Machine {
}
}
}
Instruction::DefaultExecuteNumberLessThanOrEqual(ref at_1, ref at_2) => {
Instruction::DefaultExecuteNumberLessThanOrEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2976,7 +2976,7 @@ impl Machine {
}
}
}
Instruction::DefaultCallNumberNotEqual(ref at_1, ref at_2) => {
Instruction::DefaultCallNumberNotEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -2997,7 +2997,7 @@ impl Machine {
}
}
}
Instruction::DefaultExecuteNumberNotEqual(ref at_1, ref at_2) => {
Instruction::DefaultExecuteNumberNotEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -3018,7 +3018,7 @@ impl Machine {
}
}
}
Instruction::DefaultCallNumberEqual(ref at_1, ref at_2) => {
Instruction::DefaultCallNumberEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -3039,7 +3039,7 @@ impl Machine {
}
}
}
Instruction::DefaultExecuteNumberEqual(ref at_1, ref at_2) => {
Instruction::DefaultExecuteNumberEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -3060,7 +3060,7 @@ impl Machine {
}
}
}
Instruction::DefaultCallNumberGreaterThanOrEqual(ref at_1, ref at_2) => {
Instruction::DefaultCallNumberGreaterThanOrEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -3081,7 +3081,7 @@ impl Machine {
}
}
}
Instruction::DefaultExecuteNumberGreaterThanOrEqual(ref at_1, ref at_2) => {
Instruction::DefaultExecuteNumberGreaterThanOrEqual(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -3102,7 +3102,7 @@ impl Machine {
}
}
}
Instruction::DefaultCallNumberGreaterThan(ref at_1, ref at_2) => {
Instruction::DefaultCallNumberGreaterThan(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -3123,7 +3123,7 @@ impl Machine {
}
}
}
Instruction::DefaultExecuteNumberGreaterThan(ref at_1, ref at_2) => {
Instruction::DefaultExecuteNumberGreaterThan(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -3144,7 +3144,7 @@ impl Machine {
}
}
}
Instruction::DefaultCallNumberLessThan(ref at_1, ref at_2) => {
Instruction::DefaultCallNumberLessThan(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -3165,7 +3165,7 @@ impl Machine {
}
}
}
Instruction::DefaultExecuteNumberLessThan(ref at_1, ref at_2) => {
Instruction::DefaultExecuteNumberLessThan(at_1, at_2) => {
let n1 = try_or_throw!(
self.machine_st,
self.machine_st.get_number(at_1),
@@ -3640,7 +3640,7 @@ impl Machine {
&Instruction::Proceed => {
self.machine_st.p = self.machine_st.cp;
}
Instruction::IndexingCode(ref indexing_lines) => {
Instruction::IndexingCode(indexing_lines) => {
match &indexing_lines[self.machine_st.oip as usize] {
IndexingLine::Indexing(_) => {
self.execute_switch_on_term();
@@ -3649,7 +3649,7 @@ impl Machine {
self.machine_st.backtrack();
}
}
IndexingLine::IndexedChoice(ref indexed_choice) => {
IndexingLine::IndexedChoice(indexed_choice) => {
match indexed_choice[self.machine_st.iip as usize] {
IndexedChoiceInstruction::Try(offset) => {
backtrack_on_resource_error!(

View File

@@ -57,7 +57,7 @@ struct InnerHeap {
}
impl InnerHeap {
unsafe fn grow(&mut self) -> bool {
unsafe fn grow(&mut self) -> bool { unsafe {
let new_cap = if self.byte_cap == 0 {
256 * 256 * 8
} else {
@@ -88,7 +88,7 @@ impl InnerHeap {
} else {
false
}
}
}}
}
unsafe impl Send for Heap {}
@@ -101,7 +101,7 @@ pub struct HeapStringScan<'a> {
}
// The heap_slice should be inside the heap
unsafe fn scan_slice_to_str(heap_slice: &[u8]) -> HeapStringScan<'_> {
unsafe fn scan_slice_to_str(heap_slice: &[u8]) -> HeapStringScan<'_> { unsafe {
let string_len = heap_slice
.iter()
.position(|b| *b == 0u8)
@@ -120,11 +120,11 @@ unsafe fn scan_slice_to_str(heap_slice: &[u8]) -> HeapStringScan<'_> {
string: std::str::from_utf8_unchecked(str_slice),
tail_idx,
}
}
}}
// Same as scan_slice_to_str but assumes that the slice is from the start of a string.
// Can be used on strings out of the heap.
unsafe fn scan_slice_to_str_from_start(heap_slice: &[u8]) -> HeapStringScan<'_> {
unsafe fn scan_slice_to_str_from_start(heap_slice: &[u8]) -> HeapStringScan<'_> { unsafe {
let string_len = heap_slice
.iter()
.position(|b| *b == 0u8)
@@ -142,7 +142,7 @@ unsafe fn scan_slice_to_str_from_start(heap_slice: &[u8]) -> HeapStringScan<'_>
string: std::str::from_utf8_unchecked(str_slice),
tail_idx,
}
}
}}
#[derive(Debug, Clone, Copy)]
pub(crate) enum PStrContinuable {
@@ -585,9 +585,9 @@ impl Heap {
}
#[inline(always)]
unsafe fn grow(&mut self) -> bool {
unsafe fn grow(&mut self) -> bool { unsafe {
self.inner.grow()
}
}}
#[inline]
fn resource_error_offset(&self) -> usize {

View File

@@ -34,7 +34,7 @@ pub(super) fn set_code_index<'a, LS: LoadState<'a>>(
RetractionRecord::ReplacedUserPredicate(key, replaced)
}
}
CompilationTarget::Module(ref module_name) => {
CompilationTarget::Module(module_name) => {
if IndexPtrTag::Undefined == code_idx_ptr.tag() {
*code_idx_ptr = code_ptr;
RetractionRecord::AddedModulePredicate(*module_name, key)
@@ -98,7 +98,7 @@ pub(super) fn add_op_decl(
CompilationTarget::User => {
retraction_info.push_record(RetractionRecord::ReplacedUserOp(*op_decl, op_desc));
}
CompilationTarget::Module(ref module_name) => {
CompilationTarget::Module(module_name) => {
retraction_info.push_record(RetractionRecord::ReplacedModuleOp(
*module_name,
*op_decl,
@@ -110,7 +110,7 @@ pub(super) fn add_op_decl(
CompilationTarget::User => {
retraction_info.push_record(RetractionRecord::AddedUserOp(*op_decl));
}
CompilationTarget::Module(ref module_name) => {
CompilationTarget::Module(module_name) => {
retraction_info
.push_record(RetractionRecord::AddedModuleOp(*module_name, *op_decl));
}
@@ -167,7 +167,7 @@ pub(super) fn import_module_exports<'a, LS: LoadState<'a>>(
));
}
}
ModuleExport::OpDecl(ref op_decl) => {
ModuleExport::OpDecl(op_decl) => {
add_op_decl(
&mut payload.retraction_info,
compilation_target,
@@ -221,7 +221,7 @@ fn import_module_exports_into_module<'a, LS: LoadState<'a>>(
));
}
}
ModuleExport::OpDecl(ref op_decl) => {
ModuleExport::OpDecl(op_decl) => {
add_op_decl_as_module_export::<LS>(payload, op_dir, wam_op_dir, op_decl);
}
}
@@ -276,7 +276,7 @@ fn import_qualified_module_exports<'a, LS: LoadState<'a>>(
));
}
}
ModuleExport::OpDecl(ref op_decl) => {
ModuleExport::OpDecl(op_decl) => {
add_op_decl(
&mut payload.retraction_info,
compilation_target,
@@ -336,7 +336,7 @@ fn import_qualified_module_exports_into_module<'a, LS: LoadState<'a>>(
));
}
}
ModuleExport::OpDecl(ref op_decl) => {
ModuleExport::OpDecl(op_decl) => {
add_op_decl_as_module_export::<LS>(payload, op_dir, wam_op_dir, op_decl);
}
}
@@ -545,7 +545,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
) {
for export in removed_module.module_decl.exports.iter() {
match export {
ModuleExport::PredicateKey(ref key) => {
ModuleExport::PredicateKey(key) => {
if let (Some(module_code_idx), Some(target_code_idx)) = (
removed_module.code_dir.get(key).cloned(),
code_dir.get_mut(key).cloned(),
@@ -1050,7 +1050,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
);
for export in &module.module_decl.exports {
if let ModuleExport::OpDecl(ref op_decl) = export {
if let ModuleExport::OpDecl(op_decl) = export {
add_op_decl_as_module_export::<LS>(
&mut self.payload,
&mut module.op_dir,
@@ -1084,7 +1084,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
&mut self.wam_prelude.indices.meta_predicates,
)?;
}
CompilationTarget::Module(ref defining_module_name) => {
CompilationTarget::Module(defining_module_name) => {
match self
.wam_prelude
.indices
@@ -1137,7 +1137,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
&exports,
&mut self.wam_prelude,
),
CompilationTarget::Module(ref defining_module_name) => {
CompilationTarget::Module(defining_module_name) => {
match self
.wam_prelude
.indices

View File

@@ -160,7 +160,7 @@ impl fmt::Display for CompilationTarget {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CompilationTarget::User => write!(f, "user"),
CompilationTarget::Module(ref module_name) => write!(f, "{}", module_name.as_str()),
CompilationTarget::Module(module_name) => write!(f, "{}", module_name.as_str()),
}
}
}
@@ -821,7 +821,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
{
if let IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(
_,
ref mut v,
v,
..,
)) = &mut indexing_code[0]
{
@@ -1110,7 +1110,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
}
}
}
CompilationTarget::Module(ref module_name) => {
CompilationTarget::Module(module_name) => {
match self.wam_prelude.indices.modules.get_mut(module_name) {
Some(ref mut module) => match module.extensible_predicates.get_mut(&key) {
Some(ref mut skeleton) => {
@@ -1364,7 +1364,7 @@ impl<'a> MachinePreludeView<'a> {
) -> CompositeOpDir<'_, '_> {
match compilation_target {
CompilationTarget::User => CompositeOpDir::new(&self.indices.op_dir, None),
CompilationTarget::Module(ref module_name) => {
CompilationTarget::Module(module_name) => {
match self.indices.modules.get(module_name) {
Some(module) => CompositeOpDir::new(&self.indices.op_dir, Some(&module.op_dir)),
None => {
@@ -2374,7 +2374,7 @@ impl Machine {
MetaSpec::Plus => atom_as_cell!(atom!("-")),
MetaSpec::Either => atom_as_cell!(atom!("?")),
MetaSpec::Colon => atom_as_cell!(atom!(":")),
MetaSpec::RequiresExpansionWithArgument(ref arg_num) => {
MetaSpec::RequiresExpansionWithArgument(arg_num) => {
fixnum_as_cell!(/* FIXME this is not safe */ unsafe {
Fixnum::build_with_unchecked(*arg_num as i64)
})

View File

@@ -900,7 +900,7 @@ impl CompilationError {
CompilationError::InvalidUseModuleDecl => {
functor!(atom!("invalid_use_module_declaration"))
}
CompilationError::ParserError(ref err) => {
CompilationError::ParserError(err) => {
functor!(err.as_atom())
}
CompilationError::FiniteMemoryInHeap(_) => {

View File

@@ -292,7 +292,7 @@ impl IndexStore {
) -> Option<&mut PredicateSkeleton> {
match compilation_target {
CompilationTarget::User => self.extensible_predicates.get_mut(key),
CompilationTarget::Module(ref module_name) => {
CompilationTarget::Module(module_name) => {
if let Some(module) = self.modules.get_mut(module_name) {
module.extensible_predicates.get_mut(key)
} else {
@@ -309,7 +309,7 @@ impl IndexStore {
) -> Option<&PredicateSkeleton> {
match compilation_target {
CompilationTarget::User => self.extensible_predicates.get(key),
CompilationTarget::Module(ref module_name) => {
CompilationTarget::Module(module_name) => {
if let Some(module) = self.modules.get(module_name) {
module.extensible_predicates.get(key)
} else {
@@ -380,7 +380,7 @@ impl IndexStore {
) -> Option<PredicateSkeleton> {
match compilation_target {
CompilationTarget::User => self.extensible_predicates.swap_remove(key),
CompilationTarget::Module(ref module_name) => {
CompilationTarget::Module(module_name) => {
if let Some(module) = self.modules.get_mut(module_name) {
module.extensible_predicates.swap_remove(key)
} else {
@@ -413,7 +413,7 @@ impl IndexStore {
) -> Option<&Vec<MetaSpec>> {
match compilation_target {
CompilationTarget::User => self.meta_predicates.get(&(name, arity)),
CompilationTarget::Module(ref module_name) => match self.modules.get(module_name) {
CompilationTarget::Module(module_name) => match self.modules.get(module_name) {
Some(module) => module
.meta_predicates
.get(&(name, arity))

View File

@@ -1133,7 +1133,7 @@ impl CWIL {
limit = limit.strict_add(self.local_count);
match self.limits.last() {
Some((ref inner_limit, _)) if *inner_limit <= limit => {}
Some((inner_limit, _)) if *inner_limit <= limit => {}
_ => self.limits.push((limit, block)),
}

View File

@@ -1224,7 +1224,7 @@ impl Machine {
let key = Atom::from(h as u64);
match self.indices.global_variables.get_mut(&key) {
Some((_, ref mut loc)) => *loc = None,
Some((_, loc)) => *loc = None,
None => unreachable!(),
}
}
@@ -1233,7 +1233,7 @@ impl Machine {
let value_cell = HeapCellValue::from(u64::from(self.machine_st.trail[i + 1]));
match self.indices.global_variables.get_mut(&key) {
Some((_, ref mut loc)) => *loc = Some(value_cell),
Some((_, loc)) => *loc = Some(value_cell),
None => unreachable!(),
}
}

View File

@@ -82,7 +82,7 @@ fn setup_op_decl(mut terms: Vec<Term>) -> Result<OpDecl, CompilationError> {
fn setup_predicate_indicator(term: &mut Term) -> Result<PredicateKey, CompilationError> {
match term {
Term::Clause(_, slash, ref mut terms)
Term::Clause(_, slash, terms)
if (*slash == atom!("/") || *slash == atom!("//")) && terms.len() == 2 =>
{
let arity = terms.pop().unwrap();

View File

@@ -175,7 +175,7 @@ impl Stack {
}
#[inline(always)]
unsafe fn alloc(&mut self, frame_size: usize) -> Result<NonNull<u8>, AllocError> {
unsafe fn alloc(&mut self, frame_size: usize) -> Result<NonNull<u8>, AllocError> { unsafe {
loop {
let ptr = self.buf.alloc(frame_size);
if let Some(ptr) = NonNull::new(ptr) {
@@ -183,7 +183,7 @@ impl Stack {
}
self.buf.grow()?;
}
}
}}
pub(crate) fn allocate_and_frame(&mut self, num_cells: usize) -> Result<usize, AllocError> {
let frame_size = AndFrame::size_of(num_cells);

View File

@@ -750,49 +750,49 @@ impl Stream {
pub fn options(&self) -> &StreamOptions {
match self {
Stream::Byte(ref ptr) => &ptr.options,
Stream::InputFile(ref ptr) => &ptr.options,
Stream::OutputFile(ref ptr) => &ptr.options,
Stream::StaticString(ref ptr) => &ptr.options,
Stream::NamedTcp(ref ptr) => &ptr.options,
Stream::Byte(ptr) => &ptr.options,
Stream::InputFile(ptr) => &ptr.options,
Stream::OutputFile(ptr) => &ptr.options,
Stream::StaticString(ptr) => &ptr.options,
Stream::NamedTcp(ptr) => &ptr.options,
#[cfg(feature = "tls")]
Stream::NamedTls(ref ptr) => &ptr.options,
Stream::NamedTls(ptr) => &ptr.options,
#[cfg(feature = "http")]
Stream::HttpRead(ref ptr) => &ptr.options,
Stream::HttpRead(ptr) => &ptr.options,
#[cfg(feature = "http")]
Stream::HttpWrite(ref ptr) => &ptr.options,
Stream::Null(ref options) => options,
Stream::Readline(ref ptr) => &ptr.options,
Stream::StandardOutput(ref ptr) => &ptr.options,
Stream::StandardError(ref ptr) => &ptr.options,
Stream::Callback(ref ptr) => &ptr.options,
Stream::InputChannel(ref ptr) => &ptr.options,
Stream::PipeReader(ref ptr) => &ptr.options,
Stream::PipeWriter(ref ptr) => &ptr.options,
Stream::HttpWrite(ptr) => &ptr.options,
Stream::Null(options) => options,
Stream::Readline(ptr) => &ptr.options,
Stream::StandardOutput(ptr) => &ptr.options,
Stream::StandardError(ptr) => &ptr.options,
Stream::Callback(ptr) => &ptr.options,
Stream::InputChannel(ptr) => &ptr.options,
Stream::PipeReader(ptr) => &ptr.options,
Stream::PipeWriter(ptr) => &ptr.options,
}
}
pub(super) fn options_mut(&mut self) -> &mut StreamOptions {
match self {
Stream::Byte(ref mut ptr) => &mut ptr.options,
Stream::InputFile(ref mut ptr) => &mut ptr.options,
Stream::OutputFile(ref mut ptr) => &mut ptr.options,
Stream::StaticString(ref mut ptr) => &mut ptr.options,
Stream::NamedTcp(ref mut ptr) => &mut ptr.options,
Stream::Byte(ptr) => &mut ptr.options,
Stream::InputFile(ptr) => &mut ptr.options,
Stream::OutputFile(ptr) => &mut ptr.options,
Stream::StaticString(ptr) => &mut ptr.options,
Stream::NamedTcp(ptr) => &mut ptr.options,
#[cfg(feature = "tls")]
Stream::NamedTls(ref mut ptr) => &mut ptr.options,
Stream::NamedTls(ptr) => &mut ptr.options,
#[cfg(feature = "http")]
Stream::HttpRead(ref mut ptr) => &mut ptr.options,
Stream::HttpRead(ptr) => &mut ptr.options,
#[cfg(feature = "http")]
Stream::HttpWrite(ref mut ptr) => &mut ptr.options,
Stream::Null(ref mut options) => options,
Stream::Readline(ref mut ptr) => &mut ptr.options,
Stream::StandardOutput(ref mut ptr) => &mut ptr.options,
Stream::StandardError(ref mut ptr) => &mut ptr.options,
Stream::Callback(ref mut ptr) => &mut ptr.options,
Stream::InputChannel(ref mut ptr) => &mut ptr.options,
Stream::PipeReader(ref mut ptr) => &mut ptr.options,
Stream::PipeWriter(ref mut ptr) => &mut ptr.options,
Stream::HttpWrite(ptr) => &mut ptr.options,
Stream::Null(options) => options,
Stream::Readline(ptr) => &mut ptr.options,
Stream::StandardOutput(ptr) => &mut ptr.options,
Stream::StandardError(ptr) => &mut ptr.options,
Stream::Callback(ptr) => &mut ptr.options,
Stream::InputChannel(ptr) => &mut ptr.options,
Stream::PipeReader(ptr) => &mut ptr.options,
Stream::PipeWriter(ptr) => &mut ptr.options,
}
}
@@ -960,17 +960,17 @@ impl CharRead for Stream {
fn consume(&mut self, nread: usize) {
match self {
Stream::InputFile(ref mut file) => file.consume(nread),
Stream::NamedTcp(ref mut tcp_stream) => tcp_stream.consume(nread),
Stream::InputFile(file) => file.consume(nread),
Stream::NamedTcp(tcp_stream) => tcp_stream.consume(nread),
#[cfg(feature = "tls")]
Stream::NamedTls(ref mut tls_stream) => tls_stream.consume(nread),
Stream::NamedTls(tls_stream) => tls_stream.consume(nread),
#[cfg(feature = "http")]
Stream::HttpRead(ref mut http_stream) => http_stream.consume(nread),
Stream::Readline(ref mut rl_stream) => rl_stream.consume(nread),
Stream::StaticString(ref mut src) => src.consume(nread),
Stream::Byte(ref mut cursor) => cursor.consume(nread),
Stream::InputChannel(ref mut cursor) => cursor.consume(nread),
Stream::PipeReader(ref mut cursor) => cursor.consume(nread),
Stream::HttpRead(http_stream) => http_stream.consume(nread),
Stream::Readline(rl_stream) => rl_stream.consume(nread),
Stream::StaticString(src) => src.consume(nread),
Stream::Byte(cursor) => cursor.consume(nread),
Stream::InputChannel(cursor) => cursor.consume(nread),
Stream::PipeReader(cursor) => cursor.consume(nread),
#[cfg(feature = "http")]
Stream::HttpWrite(_) => {}
Stream::OutputFile(_)
@@ -1019,17 +1019,17 @@ impl Read for Stream {
impl Write for Stream {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
match self {
Stream::OutputFile(ref mut file) => file.write(buf),
Stream::NamedTcp(ref mut tcp_stream) => tcp_stream.get_mut().write(buf),
Stream::OutputFile(file) => file.write(buf),
Stream::NamedTcp(tcp_stream) => tcp_stream.get_mut().write(buf),
#[cfg(feature = "tls")]
Stream::NamedTls(ref mut tls_stream) => tls_stream.get_mut().write(buf),
Stream::Byte(ref mut cursor) => cursor.get_mut().write(buf),
Stream::Callback(ref mut callback_stream) => callback_stream.get_mut().write(buf),
Stream::NamedTls(tls_stream) => tls_stream.get_mut().write(buf),
Stream::Byte(cursor) => cursor.get_mut().write(buf),
Stream::Callback(callback_stream) => callback_stream.get_mut().write(buf),
Stream::StandardOutput(stream) => stream.write(buf),
Stream::StandardError(stream) => stream.write(buf),
#[cfg(feature = "http")]
Stream::HttpWrite(ref mut stream) => stream.get_mut().write(buf),
Stream::PipeWriter(ref mut stream) => stream.get_mut().write(buf),
Stream::HttpWrite(stream) => stream.get_mut().write(buf),
Stream::PipeWriter(stream) => stream.get_mut().write(buf),
#[cfg(feature = "http")]
Stream::HttpRead(_) => Err(std::io::Error::new(
ErrorKind::PermissionDenied,
@@ -1049,17 +1049,17 @@ impl Write for Stream {
fn flush(&mut self) -> std::io::Result<()> {
match self {
Stream::OutputFile(ref mut file) => file.stream.flush(),
Stream::NamedTcp(ref mut tcp_stream) => tcp_stream.stream.get_mut().flush(),
Stream::OutputFile(file) => file.stream.flush(),
Stream::NamedTcp(tcp_stream) => tcp_stream.stream.get_mut().flush(),
#[cfg(feature = "tls")]
Stream::NamedTls(ref mut tls_stream) => tls_stream.stream.get_mut().flush(),
Stream::Byte(ref mut cursor) => cursor.stream.get_mut().flush(),
Stream::Callback(ref mut callback_stream) => callback_stream.stream.get_mut().flush(),
Stream::NamedTls(tls_stream) => tls_stream.stream.get_mut().flush(),
Stream::Byte(cursor) => cursor.stream.get_mut().flush(),
Stream::Callback(callback_stream) => callback_stream.stream.get_mut().flush(),
Stream::StandardError(stream) => stream.stream.flush(),
Stream::StandardOutput(stream) => stream.stream.flush(),
Stream::PipeWriter(ref mut stream) => stream.stream.get_mut().flush(),
Stream::PipeWriter(stream) => stream.stream.get_mut().flush(),
#[cfg(feature = "http")]
Stream::HttpWrite(ref mut stream) => stream.stream.get_mut().flush(),
Stream::HttpWrite(stream) => stream.stream.get_mut().flush(),
#[cfg(feature = "http")]
Stream::HttpRead(_) => Err(std::io::Error::new(
ErrorKind::PermissionDenied,
@@ -1530,58 +1530,58 @@ impl Stream {
#[inline]
pub(crate) fn close(&mut self) -> Result<(), std::io::Error> {
match self {
Stream::NamedTcp(ref mut tcp_stream) => {
Stream::NamedTcp(tcp_stream) => {
tcp_stream.inner_mut().tcp_stream.shutdown(Shutdown::Both)
}
#[cfg(feature = "tls")]
Stream::NamedTls(ref mut tls_stream) => tls_stream.inner_mut().tls_stream.shutdown(),
Stream::NamedTls(tls_stream) => tls_stream.inner_mut().tls_stream.shutdown(),
#[cfg(feature = "http")]
Stream::HttpRead(ref mut http_stream) => {
Stream::HttpRead(http_stream) => {
http_stream.drop_payload();
Ok(())
}
#[cfg(feature = "http")]
Stream::HttpWrite(mut http_stream) => {
&mut Stream::HttpWrite(mut http_stream) => {
http_stream.drop_payload();
Ok(())
}
Stream::InputFile(mut file_stream) => {
&mut Stream::InputFile(mut file_stream) => {
// close the stream by dropping the inner File.
file_stream.drop_payload();
Ok(())
}
Stream::OutputFile(mut file_stream) => {
&mut Stream::OutputFile(mut file_stream) => {
// close the stream by dropping the inner File.
file_stream.drop_payload();
Ok(())
}
Stream::Byte(mut stream) => {
&mut Stream::Byte(mut stream) => {
stream.drop_payload();
Ok(())
}
Stream::Callback(mut stream) => {
&mut Stream::Callback(mut stream) => {
stream.drop_payload();
Ok(())
}
Stream::InputChannel(mut stream) => {
&mut Stream::InputChannel(mut stream) => {
stream.drop_payload();
Ok(())
}
Stream::StaticString(mut stream) => {
&mut Stream::StaticString(mut stream) => {
stream.drop_payload();
Ok(())
}
Stream::PipeReader(mut stream) => {
&mut Stream::PipeReader(mut stream) => {
stream.drop_payload();
Ok(())
}
Stream::PipeWriter(mut stream) => {
&mut Stream::PipeWriter(mut stream) => {
stream.drop_payload();
Ok(())
}
@@ -1644,11 +1644,11 @@ impl Stream {
self.set_past_end_of_stream(false);
match self {
Stream::Byte(ref mut cursor) => {
Stream::Byte(cursor) => {
cursor.stream.get_mut().0.set_position(0);
true
}
Stream::InputFile(ref mut file_stream) => {
Stream::InputFile(file_stream) => {
file_stream
.stream
.get_mut()
@@ -1657,11 +1657,11 @@ impl Stream {
.unwrap();
true
}
Stream::Readline(ref mut readline_stream) => {
Stream::Readline(readline_stream) => {
readline_stream.reset();
true
}
Stream::InputChannel(ref mut input_channel_stream) => {
Stream::InputChannel(input_channel_stream) => {
input_channel_stream.stream.get_mut().inner.set_position(0);
true
}
@@ -1672,7 +1672,7 @@ impl Stream {
#[inline]
pub(crate) fn peek_byte(&mut self) -> std::io::Result<u8> {
match self {
Stream::Byte(ref mut cursor) => {
Stream::Byte(cursor) => {
let mut b = [0u8; 1];
let pos = cursor.stream.get_mut().0.position();
@@ -1684,15 +1684,15 @@ impl Stream {
_ => Err(std::io::Error::new(ErrorKind::UnexpectedEof, "end of file")),
}
}
Stream::InputFile(ref mut file) => match file.peek_byte() {
Stream::InputFile(file) => match file.peek_byte() {
Some(result) => Ok(result?),
_ => Err(std::io::Error::new(
ErrorKind::UnexpectedEof,
StreamError::PeekByteFailed,
)),
},
Stream::Readline(ref mut stream) => stream.stream.peek_byte(),
Stream::NamedTcp(ref mut stream) => {
Stream::Readline(stream) => stream.stream.peek_byte(),
Stream::NamedTcp(stream) => {
let mut b = [0u8; 1];
stream.stream.get_mut().tcp_stream.peek(&mut b)?;
Ok(b[0])

View File

@@ -1252,7 +1252,7 @@ impl Machine {
loop {
match &self.code[bp] {
Instruction::IndexingCode(ref indexing_code) => {
Instruction::IndexingCode(indexing_code) => {
let indexing_code_ptr = match &indexing_code[0] {
&IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(
_,
@@ -1275,10 +1275,10 @@ impl Machine {
let boip = extract_ptr!(indexing_code_ptr);
let boip = match &indexing_code[boip] {
IndexingLine::Indexing(IndexingInstruction::SwitchOnStructure(ref hm)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnStructure(hm)) => {
boip + extract_ptr!(hm.get(&key).cloned().unwrap())
}
IndexingLine::Indexing(IndexingInstruction::SwitchOnConstant(ref hm)) => {
IndexingLine::Indexing(IndexingInstruction::SwitchOnConstant(hm)) => {
boip + extract_ptr!(hm.get(&atom_as_cell!(key.0)).cloned().unwrap())
}
_ => boip,
@@ -3138,7 +3138,7 @@ impl Machine {
let addr = self.machine_st.registers[2];
match self.indices.global_variables.get_mut(&key) {
Some((ref ball, ref mut loc)) => match loc {
Some(&mut (ref ball, ref mut loc)) => match loc {
Some(value_loc) => {
unify_fn!(self.machine_st, addr, *value_loc);
}
@@ -4319,7 +4319,7 @@ impl Machine {
#[inline(always)]
pub(crate) fn maybe(&mut self) {
self.machine_st.fail = self.rng.gen();
self.machine_st.fail = self.rng.r#gen();
}
#[cfg(not(target_arch = "wasm32"))]
@@ -7522,8 +7522,8 @@ impl Machine {
let new_value = self.deref_register(2);
match self.indices.global_variables.get_mut(&key) {
Some((_, ref mut loc)) => match loc {
Some(ref mut value) => {
Some((_, loc)) => match loc {
Some(value) => {
self.machine_st
.trail(TrailRef::BlackboardOffset(key, *value));
*value = new_value;
@@ -8667,7 +8667,8 @@ impl Machine {
.value_to_str_like(self.machine_st.registers[2])
.unwrap();
env::set_var(&*key.as_str(), &*value.as_str());
// TODO: Audit that the environment access only happens in single-threaded code.
unsafe { env::set_var(&*key.as_str(), &*value.as_str()) };
}
#[inline(always)]
@@ -8676,7 +8677,8 @@ impl Machine {
.machine_st
.value_to_str_like(self.machine_st.registers[1])
.unwrap();
env::remove_var(&*key.as_str());
// TODO: Audit that the environment access only happens in single-threaded code.
unsafe { env::remove_var(&*key.as_str()) };
}
#[inline(always)]

View File

@@ -211,7 +211,7 @@ impl<T: RawBlockTraits> SerialOffsetTable<T> {
})
}
unsafe fn build_with(&mut self, value: T) -> usize {
unsafe fn build_with(&mut self, value: T) -> usize { unsafe {
let mut ptr;
loop {
@@ -228,17 +228,17 @@ impl<T: RawBlockTraits> SerialOffsetTable<T> {
ptr::write(ptr as *mut T, value);
// SAFETY: `ptr` was obtained from `self.block.alloc()`
self.block.get_offset(ptr)
}
}}
#[inline]
unsafe fn lookup(&self, offset: usize) -> &T {
unsafe fn lookup(&self, offset: usize) -> &T { unsafe {
&*self.block.get_unchecked(offset).cast::<T>()
}
}}
#[inline]
unsafe fn lookup_mut(&mut self, offset: usize) -> &mut T {
unsafe fn lookup_mut(&mut self, offset: usize) -> &mut T { unsafe {
&mut *self.block.get_unchecked(offset).cast::<T>().cast_mut()
}
}}
#[allow(clippy::wrong_self_convention)]
fn to_concurrent(&mut self) -> ConcurrentOffsetTable<T>

View File

@@ -877,7 +877,7 @@ pub enum Term {
impl Term {
pub fn first_arg(&self) -> Option<&Term> {
match self {
Term::Clause(_, _, ref terms) => terms.first(),
Term::Clause(_, _, terms) => terms.first(),
_ => None,
}
}
@@ -892,14 +892,14 @@ impl Term {
pub fn arity(&self) -> usize {
match self {
Term::Clause(_, _, ref child_terms, ..) => child_terms.len(),
Term::Clause(_, _, child_terms, ..) => child_terms.len(),
_ => 0,
}
}
}
pub(crate) fn unfold_by_str_once(term: &mut Term, s: Atom) -> Option<(Term, Term)> {
if let Term::Clause(_, ref name, ref mut subterms) = term {
if let &mut Term::Clause(_, ref name, ref mut subterms) = term {
if let Some(Term::Literal(_, Literal::CodeIndexOffset(_))) = subterms.last() {
subterms.pop();
}

View File

@@ -761,9 +761,9 @@ impl UntypedArenaPtr {
pub unsafe fn as_typed_ptr<T: ?Sized + ArenaAllocated>(self) -> TypedArenaPtr<T>
where
T::Payload: Sized,
{
{ unsafe {
T::typed_ptr(self)
}
}}
#[inline]
pub fn get_mark_bit(self) -> bool {

View File

@@ -105,9 +105,9 @@ impl VarAlloc {
#[inline]
pub(crate) fn set_register(&mut self, reg_num: usize) {
match self {
VarAlloc::Perm(ref mut p, _) => *p = reg_num,
VarAlloc::Perm(p, _) => *p = reg_num,
VarAlloc::Temp {
ref mut temp_reg, ..
temp_reg, ..
} => *temp_reg = reg_num,
};
}