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

@@ -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)]