Skip to content

Commit

Permalink
fix retraction of local dynamic predicates (#2215, #2232)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthom committed Dec 18, 2023
1 parent b943afb commit f30cee7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/machine/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,8 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
.clause_clause_locs
.extend(&clause_clause_locs.make_contiguous()[0..]);

let skeleton = cg.skeleton;
let mut skeleton = cg.skeleton;
skeleton.core.is_dynamic = settings.is_dynamic();

self.add_extensible_predicate(key, skeleton, predicates.compilation_target);
}
Expand Down Expand Up @@ -2138,7 +2139,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
.map(|skeleton| skeleton.predicate_info())
.unwrap_or_default();

let mut predicate_info = self
let predicate_info = self
.wam_prelude
.indices
.get_predicate_skeleton(&self.payload.predicates.compilation_target, &key)
Expand Down Expand Up @@ -2200,8 +2201,6 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
(0..skeleton.clauses.len()).map(Some).collect(),
false, // the builtin M:'$clause'/2 is never dynamic.
);

predicate_info.is_dynamic = false;
}

self.payload
Expand Down
38 changes: 32 additions & 6 deletions src/machine/load_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,39 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
None => return,
};

let mut skipped_local_predicates = IndexSet::with_hasher(FxBuildHasher::default());

for ((local_compilation_target, key), skeleton) in
removed_module.local_extensible_predicates.iter()
{
skipped_local_predicates.insert(key);

if skeleton.is_multifile {
continue;
}

if let Some(code_index) = removed_module.code_dir.get_mut(key) {
if let Some(global_skeleton) = self
.wam_prelude
.indices
.get_predicate_skeleton(local_compilation_target, key)
{
let old_index_ptr = code_index.replace(if global_skeleton.core.is_dynamic {
IndexPtr::dynamic_undefined()
} else {
IndexPtr::undefined()
});

self.payload.retraction_info.push_record(
RetractionRecord::ReplacedModulePredicate(module_name, *key, old_index_ptr),
);
}
}
}

for (key, code_index) in removed_module.code_dir.iter_mut() {
match removed_module
.local_extensible_predicates
.get(&(CompilationTarget::User, *key))
{
Some(skeleton) if skeleton.is_multifile => continue,
_ => {}
if skipped_local_predicates.contains(&key) {
continue;
}

let old_index_ptr = code_index.replace(IndexPtr::undefined());
Expand Down

0 comments on commit f30cee7

Please sign in to comment.