]> Repositorios git - scryer-prolog.git/commitdiff
reuse tabu list
authorSkgland <[email protected]>
Sun, 17 May 2026 18:50:37 +0000 (20:50 +0200)
committerSkgland <[email protected]>
Sun, 17 May 2026 18:50:37 +0000 (20:50 +0200)
src/machine/machine_state.rs
src/machine/machine_state_impl.rs
src/machine/unify.rs

index 860cfb79ae4cf2440de17ceb756bd37796cc4855..56795ce6e7df5665fae2d1f81dfbb977b9e8d30b 100644 (file)
@@ -16,7 +16,9 @@ use crate::parser::ast::*;
 use crate::read::TermWriteResult;
 use crate::types::*;
 
+use fxhash::FxBuildHasher;
 use indexmap::IndexMap;
+use indexmap::IndexSet;
 
 use std::convert::TryFrom;
 use std::fmt;
@@ -116,6 +118,7 @@ pub struct MachineState {
     pub atom_tbl: Arc<AtomTable>,
     pub arena: Arena,
     pub(super) pdl: Vec<(HeapCellValue, HeapCellValue)>,
+    pub(super) unify_tabu_list: IndexSet<(HeapCellValue, HeapCellValue), FxBuildHasher>,
     pub(super) s: HeapPtr,
     pub(super) s_offset: usize,
     pub(super) p: usize,
index 390ad99d3529cadaef0aa604e448bce70a091b36..b9b5538f97515d3369ce2022a164e50196aeebc5 100644 (file)
@@ -1,3 +1,6 @@
+use fxhash::FxBuildHasher;
+use indexmap::IndexSet;
+
 use crate::arena::*;
 use crate::atom_table::*;
 use crate::forms::*;
@@ -31,6 +34,7 @@ impl MachineState {
             arena: Arena::new().unwrap(),
             atom_tbl: AtomTable::new().unwrap(),
             pdl: Vec::with_capacity(1024),
+            unify_tabu_list: IndexSet::with_hasher(FxBuildHasher::default()),
             s: HeapPtr::default(),
             s_offset: 0,
             p: 0,
index 0957537c97eff9628e2614d171b85158b1f026b3..e7516929350a9a790e2683c8e261807d44a9dd9e 100644 (file)
@@ -9,8 +9,6 @@ use crate::types::*;
 use std::ops::{Deref, DerefMut};
 
 use derive_more::*;
-use fxhash::FxBuildHasher;
-use indexmap::IndexSet;
 use num_order::NumOrd;
 
 impl MachineState {
@@ -348,7 +346,7 @@ pub(crate) trait Unifier: DerefMut<Target = MachineState> {
     }
 
     fn unify_internal(&mut self) {
-        let mut tabu_list = IndexSet::with_hasher(FxBuildHasher::default());
+        debug_assert!(self.unify_tabu_list.is_empty());
 
         while let Some((s1, s2)) = self.pdl.pop() {
             if self.fail {
@@ -378,7 +376,7 @@ pub(crate) trait Unifier: DerefMut<Target = MachineState> {
                         Self::unify_atom(self, name, d2);
                     }
                     (HeapCellValueTag::Str, s1) => {
-                        if tabu_list.contains(&(d1, d2)) {
+                        if self.unify_tabu_list.contains(&(d1, d2)) {
                             continue;
                         }
 
@@ -386,11 +384,11 @@ pub(crate) trait Unifier: DerefMut<Target = MachineState> {
 
                         if !self.fail {
                             let d2 = self.store(d2);
-                            tabu_list.insert((d1, d2));
+                            self.unify_tabu_list.insert((d1, d2));
                         }
                     }
                     (HeapCellValueTag::Lis, l1) => {
-                        if d2.is_ref() && tabu_list.contains(&(d1, d2)) {
+                        if d2.is_ref() && self.unify_tabu_list.contains(&(d1, d2)) {
                             continue;
                         }
 
@@ -398,7 +396,7 @@ pub(crate) trait Unifier: DerefMut<Target = MachineState> {
 
                         if !self.fail {
                             let d2 = self.store(d2);
-                            tabu_list.insert((d1, d2));
+                            self.unify_tabu_list.insert((d1, d2));
                         }
                     }
                     (HeapCellValueTag::PStrLoc, l) => {
@@ -406,7 +404,7 @@ pub(crate) trait Unifier: DerefMut<Target = MachineState> {
                             (HeapCellValueTag::PStrLoc |
                              HeapCellValueTag::Lis |
                              HeapCellValueTag::Str) => {
-                                if tabu_list.contains(&(d1, d2)) {
+                                if self.unify_tabu_list.contains(&(d1, d2)) {
                                     continue;
                                 }
                             }
@@ -424,7 +422,7 @@ pub(crate) trait Unifier: DerefMut<Target = MachineState> {
 
                         if !self.fail && !d2.is_constant() {
                             let d2 = self.store(d2);
-                            tabu_list.insert((d1, d2));
+                            self.unify_tabu_list.insert((d1, d2));
                         }
                     }
                     (HeapCellValueTag::F64Offset, f1) => {
@@ -445,6 +443,8 @@ pub(crate) trait Unifier: DerefMut<Target = MachineState> {
                 );
             }
         }
+
+        self.unify_tabu_list.clear();
     }
 
     fn bind(&mut self, r: Ref, value: HeapCellValue);