]> Repositorios git - scryer-prolog.git/commitdiff
warn when overwriting a predicate (#848)
authorMark Thom <[email protected]>
Tue, 2 Mar 2021 18:43:47 +0000 (11:43 -0700)
committerMark Thom <[email protected]>
Tue, 2 Mar 2021 18:43:47 +0000 (11:43 -0700)
src/machine/compile.rs
src/machine/load_state.rs

index bfea3f2f40c22aba51e11f8e19d2ff6c714f4453..eea744a296354b48bb839d7c18c6974fa63ae6f0 100644 (file)
@@ -1293,6 +1293,26 @@ fn mergeable_indexed_subsequences(
     false
 }
 
+fn print_overwrite_warning(
+    compilation_target: &CompilationTarget,
+    code_ptr: IndexPtr,
+    key: &PredicateKey,
+) {
+    if let CompilationTarget::Module(ref module_name) = compilation_target {
+        match module_name.as_str() {
+            "builtins" | "loader" => return,
+            _ => {}
+        }
+    }
+
+    match code_ptr {
+        IndexPtr::DynamicUndefined | IndexPtr::Undefined => return,
+        _ => {}
+    }
+
+    println!("Warning: overwriting {}/{}", key.0, key.1);
+}
+
 impl<'a> LoadState<'a> {
     fn compile_standalone_clause(
         &mut self,
@@ -1403,7 +1423,7 @@ impl<'a> LoadState<'a> {
                         predicates.compilation_target.clone(),
                     );
                 }
-            }
+            };
 
             match self
                 .wam
@@ -1440,6 +1460,8 @@ impl<'a> LoadState<'a> {
             }
         }
 
+        print_overwrite_warning(&predicates.compilation_target, code_index.get(), &key);
+
         set_code_index(
             &mut self.retraction_info,
             &predicates.compilation_target,
index b25677259d966c24d20cb60158a4b77242e51e97..96f88d044f02fe60c12f4641974b414bc58a1ce6 100644 (file)
@@ -35,7 +35,6 @@ pub(super) fn set_code_index(
                 code_index.set(code_ptr);
                 RetractionRecord::AddedUserPredicate(key)
             } else {
-                // TODO: emit warning about overwriting previous record
                 let replaced = code_index.replace(code_ptr);
                 RetractionRecord::ReplacedUserPredicate(key, replaced)
             }
@@ -45,7 +44,6 @@ pub(super) fn set_code_index(
                 code_index.set(code_ptr);
                 RetractionRecord::AddedModulePredicate(module_name.clone(), key)
             } else {
-                // TODO: emit warning about overwriting previous record
                 let replaced = code_index.replace(code_ptr);
                 RetractionRecord::ReplacedModulePredicate(module_name.clone(), key, replaced)
             }