From 520121b2b2cc21b0fc805a7ea6b5a94fdfc5900f Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Wed, 8 Dec 2021 23:20:08 -0700 Subject: [PATCH] remove skeletons from replaced modules --- src/lib/builtins.pl | 11 +++++------ src/loader.pl | 2 ++ src/machine/load_state.rs | 39 ++++++++++++++++++++++--------------- src/machine/loader.rs | 15 ++++++++++---- src/machine/system_calls.rs | 2 +- 5 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/lib/builtins.pl b/src/lib/builtins.pl index 79b94a51..f1b2f2d9 100644 --- a/src/lib/builtins.pl +++ b/src/lib/builtins.pl @@ -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)) ) diff --git a/src/loader.pl b/src/loader.pl index d1e86b1a..20933268 100644 --- a/src/loader.pl +++ b/src/loader.pl @@ -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) -> diff --git a/src/machine/load_state.rs b/src/machine/load_state.rs index 2b8c0fb5..036c31d7 100644 --- a/src/machine/load_state.rs +++ b/src/machine/load_state.rs @@ -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) } diff --git a/src/machine/loader.rs b/src/machine/loader.rs index ba1a5cea..061452ab 100644 --- a/src/machine/loader.rs +++ b/src/machine/loader.rs @@ -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; } } diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 81bdccfe..0720c265 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -3365,7 +3365,7 @@ impl MachineState { .unwrap_or(IndexPtr::DynamicUndefined); match index { - IndexPtr::DynamicUndefined => false, + IndexPtr::DynamicUndefined | IndexPtr::Undefined => false, _ => true, } } -- 2.54.0