]> Repositorios git - scryer-prolog.git/commitdiff
remove skeletons from replaced modules
authorMark Thom <[email protected]>
Thu, 9 Dec 2021 06:20:08 +0000 (23:20 -0700)
committerMark Thom <[email protected]>
Fri, 7 Jan 2022 04:44:41 +0000 (21:44 -0700)
src/lib/builtins.pl
src/loader.pl
src/machine/load_state.rs
src/machine/loader.rs
src/machine/system_calls.rs

index 79b94a51bc8221fc984a7fcae83e8e4fe2273e66..f1b2f2d9e0bd3d31a583e8b4c8cc2d8622247eca 100644 (file)
@@ -746,11 +746,11 @@ setof(Template, Goal, Solution) :-
     (  var(H) ->
        throw(error(instantiation_error, clause/2))
     ;  callable(H), functor(H, Name, Arity) ->
-       (  '$head_is_dynamic'(Module, H) ->
+       (  '$no_such_predicate'(Module, H) ->
+          '$fail'
+       ;  '$head_is_dynamic'(Module, H) ->
           '$clause_body_is_valid'(B),
           Module:'$clause'(H, B)
-       ;  '$no_such_predicate'(Module, H) ->
-          '$fail'
        ;  throw(error(permission_error(access, private_procedure, Name/Arity),
                       clause/2))
        )
@@ -767,12 +767,11 @@ clause(H, B) :-
           arg(1, H, Module),
           arg(2, H, F),
           '$module_clause'(F, B, Module)
+       ;  '$no_such_predicate'(user, H) ->
+          '$fail'
        ;  '$head_is_dynamic'(user, H) ->
           '$clause_body_is_valid'(B),
           '$clause'(H, B)
-       ;  '$no_such_predicate'(user, H) ->  %% '$no_such_predicate' fails if
-                                            %% H is not callable.
-          '$fail'
        ;  throw(error(permission_error(access, private_procedure, Name/Arity),
                       clause/2))
        )
index d1e86b1a677e9a32c5d77b0261f8b33027105422..209332682a29adbd6e1a81f624df68aada36db7b 100644 (file)
@@ -89,6 +89,8 @@ unload_evacuable(Evacuable) :-
 
 run_initialization_goals(Module) :-
     (  predicate_property(Module:'$initialization_goals'(_), dynamic) ->
+       % FIXME: failing here. also, see add_module.
+       '$debug_hook',
        findall(Module:Goal, '$call'(builtins:retract(Module:'$initialization_goals'(Goal))), Goals),
        abolish(Module:'$initialization_goals'/1),
        (  maplist(Module:call, Goals) ->
index 2b8c0fb51d897ea989d77a0cab8272e0603f82f6..036c31d78b27043645c1ae040844a663989632f4 100644 (file)
@@ -459,7 +459,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
     }
 
     pub(super) fn remove_replaced_in_situ_module(&mut self, module_name: Atom) {
-        let removed_module = match self.wam_prelude.indices.modules.remove(&module_name) {
+        let mut removed_module = match self.wam_prelude.indices.modules.remove(&module_name) {
             Some(module) => module,
             None => return,
         };
@@ -467,22 +467,29 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
         for (key, code_index) in &removed_module.code_dir {
             match removed_module
                 .local_extensible_predicates
-                .get(&(CompilationTarget::User, key.clone()))
+                .get(&(CompilationTarget::User, *key))
             {
                 Some(skeleton) if skeleton.is_multifile => continue,
                 _ => {}
             }
 
-            if code_index.get() != IndexPtr::Undefined {
-                let old_index_ptr = code_index.replace(IndexPtr::Undefined);
+            let old_index_ptr = code_index.replace(IndexPtr::Undefined);
 
-                self.payload.retraction_info
-                    .push_record(RetractionRecord::ReplacedModulePredicate(
-                        module_name.clone(),
-                        key.clone(),
-                        old_index_ptr,
-                    ));
-            }
+            self.payload.retraction_info
+                .push_record(RetractionRecord::ReplacedModulePredicate(
+                    module_name,
+                    *key,
+                    old_index_ptr,
+                ));
+        }
+
+        for (key, skeleton) in removed_module.extensible_predicates.drain(..) {
+            self.payload.retraction_info
+                .push_record(RetractionRecord::RemovedSkeleton(
+                    CompilationTarget::Module(module_name),
+                    key,
+                    skeleton,
+                ));
         }
 
         self.wam_prelude.indices.modules.insert(module_name, removed_module);
@@ -861,7 +868,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
         let mut module = Module::new(module_decl, listing_src);
 
         self.import_builtins_in_module(
-            module_name.clone(),
+            module_name,
             &mut module.code_dir,
             &mut module.op_dir,
             &mut module.meta_predicates,
@@ -904,10 +911,10 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
         module_decl: ModuleDecl,
         listing_src: &ListingSource,
     ) {
-        let module_name = module_decl.name.clone();
+        let module_name = module_decl.name;
 
-        self.remove_module_exports(module_name.clone());
-        self.remove_replaced_in_situ_module(module_name.clone());
+        self.remove_module_exports(module_name);
+        self.remove_replaced_in_situ_module(module_name);
 
         match self.wam_prelude.indices.modules.get_mut(&module_name) {
             Some(module) => {
@@ -970,7 +977,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
             None => {
                 self.payload
                     .retraction_info
-                    .push_record(RetractionRecord::AddedModule(module_name.clone()));
+                    .push_record(RetractionRecord::AddedModule(module_name));
 
                 Module::new(module_decl, listing_src)
             }
index ba1a5cea0fc3d238a5c4e79ab9f47dc268f486ec..061452abc8427af2df02df1bb6a7f7295bcbe3f5 100644 (file)
@@ -1974,13 +1974,21 @@ impl Machine {
             loader
                 .wam_prelude
                 .indices
-                .get_predicate_skeleton_mut(&compilation_target, &key)
-                .map(|skeleton| skeleton.reset());
+                .remove_predicate_skeleton(&compilation_target, &key);
 
             let code_index = loader
                 .get_or_insert_code_index(key, compilation_target);
 
-            code_index.set(IndexPtr::DynamicUndefined);
+            code_index.set(IndexPtr::Undefined);
+
+            /*
+            loader
+                .wam_prelude
+                .indices
+                .get_predicate_skeleton_mut(&compilation_target, &key)
+                .map(|skeleton| skeleton.reset());
+
+            */
 
             loader.payload.compilation_target = clause_clause_compilation_target;
 
@@ -2269,7 +2277,6 @@ impl Machine {
             ClauseType::Named(name, arity, _) => {
                 if let Some(module) = self.indices.modules.get(&(atom!("builtins"))) {
                     self.machine_st.fail = !module.code_dir.contains_key(&(name, arity));
-
                     return;
                 }
             }
index 81bdccfed1cb3e0236fc19740e90ba8c3df40d23..0720c265c19d9868ed80151a421a0957a11fa9cb 100644 (file)
@@ -3365,7 +3365,7 @@ impl MachineState {
                             .unwrap_or(IndexPtr::DynamicUndefined);
 
                             match index {
-                                IndexPtr::DynamicUndefined => false,
+                                IndexPtr::DynamicUndefined | IndexPtr::Undefined => false,
                                 _ => true,
                             }
                         }