]> Repositorios git - scryer-prolog.git/commitdiff
retract discontiguous non-multifile predicates between consultations (#1202, #1058...
authorMark <[email protected]>
Sat, 5 Aug 2023 18:15:28 +0000 (12:15 -0600)
committerMark <[email protected]>
Sat, 5 Aug 2023 23:42:33 +0000 (17:42 -0600)
src/machine/compile.rs
src/machine/loader.rs
src/machine/term_stream.rs

index 0faf34c33455ec2d61c5dea4b901a660ccd4df2a..a3575c7ff7951e82db4d5d4faff22d5420b25ed3 100644 (file)
@@ -1258,7 +1258,7 @@ fn print_overwrite_warning(
         _ => {}
     }
 
-    println!("Warning: overwriting {}/{}", key.0.as_str(), key.1);
+    println!("Warning: overwriting {}/{} because the clauses are discontiguous", key.0.as_str(), key.1);
 }
 
 impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
@@ -2220,7 +2220,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
 
         let payload_compilation_target = self.payload.compilation_target;
 
-        let local_predicate_info = self
+        let mut local_predicate_info = self
             .wam_prelude
             .indices
             .get_local_predicate_skeleton(
@@ -2242,6 +2242,8 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
         let is_cross_module_clause =
             payload_compilation_target != self.payload.predicates.compilation_target;
 
+        local_predicate_info.is_discontiguous = predicate_info.is_discontiguous;
+
         if local_predicate_info.must_retract_local_clauses(is_cross_module_clause) {
             self.retract_local_clauses(&key, predicate_info.is_dynamic);
         }
index 9d66ce64b908b43aaaf1c39ef8c2135984ccd2a6..0fe88cbbfdef1d3b50c6e762fc7a5a3006722f54 100644 (file)
@@ -32,8 +32,7 @@ use std::ops::{Deref, DerefMut};
  * loader.pl does a few high-level things more easily handled from
  * Prolog that are not supported (or needed) during bootstrapping:
  * term and goal expansion, loading modules from different streams,
- * verifying certain kinds of declarations, perhaps (in the future?)
- * compiling inline disjunctions.
+ * and verifying certain kinds of declarations.
  *
  * Since the loader can operate incrementally, it uses an intermittent
  * structure to rebuild the loader between invocations. Preprocessor
@@ -1279,6 +1278,17 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
         name: Atom,
         arity: usize,
     ) -> Result<(), SessionError> {
+        let key = (name, arity);
+
+        let predicate_info = self
+            .wam_prelude
+            .indices
+            .get_predicate_skeleton(&self.payload.predicates.compilation_target, &key)
+            .map(|skeleton| skeleton.predicate_info())
+            .unwrap_or_default();
+
+        self.retract_local_clauses(&key, predicate_info.is_dynamic);
+
         self.add_extensible_predicate_declaration(
             compilation_target,
             name,
index 8c6b055da006d9b5a608c15ef85fe7233c9aafef..e352fc45e8fff3906f366a05ba775c116c311766 100644 (file)
@@ -9,6 +9,7 @@ use crate::read::devour_whitespace;
 
 use crate::predicate_queue;
 
+use fxhash::FxBuildHasher;
 use indexmap::IndexSet;
 
 use std::collections::VecDeque;
@@ -19,7 +20,7 @@ pub struct LoadStatePayload<TS> {
     pub(super) compilation_target: CompilationTarget,
     pub(super) retraction_info: RetractionInfo,
     pub(super) module_op_exports: ModuleOpExports,
-    pub(super) non_counted_bt_preds: IndexSet<PredicateKey>,
+    pub(super) non_counted_bt_preds: IndexSet<PredicateKey, FxBuildHasher>,
     pub(super) predicates: PredicateQueue,
     pub(super) clause_clauses: Vec<(Term, Term)>,
 }
@@ -97,10 +98,10 @@ impl<TS> LoadStatePayload<TS> {
             compilation_target: CompilationTarget::default(),
             retraction_info: RetractionInfo::new(code_repo_len),
             module_op_exports: vec![],
-            non_counted_bt_preds: IndexSet::new(),
+            non_counted_bt_preds: IndexSet::with_hasher(FxBuildHasher::default()),
             predicates: predicate_queue![],
             clause_clauses: vec![],
-        }
+         }
     }
 }