correct faulty removal of clauses in abolish/1
This commit is contained in:
18
src/forms.rs
18
src/forms.rs
@@ -711,5 +711,21 @@ impl PredicateSkeleton {
|
|||||||
clauses: self.clauses,
|
clauses: self.clauses,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
pub fn target_pos_of_clause_clause_loc(
|
||||||
|
&self,
|
||||||
|
clause_clause_loc: usize,
|
||||||
|
clause_assert_margin: usize,
|
||||||
|
) -> usize {
|
||||||
|
let search_result = self.clause_clause_locs[0..clause_assert_margin]
|
||||||
|
.binary_search_by(|loc| clause_clause_loc.cmp(&loc));
|
||||||
|
|
||||||
|
search_result.unwrap_or_else(|_| {
|
||||||
|
self.clause_clause_locs[clause_assert_margin..]
|
||||||
|
.binary_search_by(|loc| loc.cmp(&clause_clause_loc))
|
||||||
|
.unwrap()
|
||||||
|
+ clause_assert_margin
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1047,7 +1047,7 @@ impl<'a> LoadState<'a> {
|
|||||||
match self
|
match self
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&self.compilation_target, &key)
|
.get_predicate_skeleton_mut(&self.compilation_target, &key)
|
||||||
{
|
{
|
||||||
Some(skeleton) => {
|
Some(skeleton) => {
|
||||||
self.retraction_info
|
self.retraction_info
|
||||||
@@ -1120,7 +1120,7 @@ impl<'a> LoadState<'a> {
|
|||||||
let skeleton = match self
|
let skeleton = match self
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&self.compilation_target, &key)
|
.get_predicate_skeleton_mut(&self.compilation_target, &key)
|
||||||
{
|
{
|
||||||
Some(skeleton) if !skeleton.clauses.is_empty() => skeleton,
|
Some(skeleton) if !skeleton.clauses.is_empty() => skeleton,
|
||||||
_ => {
|
_ => {
|
||||||
@@ -1212,7 +1212,7 @@ impl<'a> LoadState<'a> {
|
|||||||
let skeleton = match self
|
let skeleton = match self
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&self.compilation_target, &key)
|
.get_predicate_skeleton_mut(&self.compilation_target, &key)
|
||||||
{
|
{
|
||||||
Some(skeleton) => skeleton,
|
Some(skeleton) => skeleton,
|
||||||
None => {
|
None => {
|
||||||
@@ -1540,7 +1540,7 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.load_state.wam.indices.get_predicate_skeleton(
|
match self.load_state.wam.indices.get_predicate_skeleton_mut(
|
||||||
&self.load_state.compilation_target,
|
&self.load_state.compilation_target,
|
||||||
&(clause_name!("$clause"), 2),
|
&(clause_name!("$clause"), 2),
|
||||||
) {
|
) {
|
||||||
@@ -1563,7 +1563,7 @@ impl<'a, TS: TermStream> Loader<'a, TS> {
|
|||||||
.load_state
|
.load_state
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&compilation_target, &key)
|
.get_predicate_skeleton_mut(&compilation_target, &key)
|
||||||
{
|
{
|
||||||
Some(skeleton) if append_or_prepend.is_append() => {
|
Some(skeleton) if append_or_prepend.is_append() => {
|
||||||
self.load_state.retraction_info.push_record(
|
self.load_state.retraction_info.push_record(
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ impl<'a> Drop for LoadState<'a> {
|
|||||||
RetractionRecord::AppendedModuleExtensiblePredicate(module_name, key) => {
|
RetractionRecord::AppendedModuleExtensiblePredicate(module_name, key) => {
|
||||||
self.wam
|
self.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&CompilationTarget::Module(module_name), &key)
|
.get_predicate_skeleton_mut(&CompilationTarget::Module(module_name), &key)
|
||||||
.map(|skeleton| {
|
.map(|skeleton| {
|
||||||
skeleton.clauses.pop_back();
|
skeleton.clauses.pop_back();
|
||||||
});
|
});
|
||||||
@@ -207,7 +207,7 @@ impl<'a> Drop for LoadState<'a> {
|
|||||||
RetractionRecord::PrependedModuleExtensiblePredicate(module_name, key) => {
|
RetractionRecord::PrependedModuleExtensiblePredicate(module_name, key) => {
|
||||||
self.wam
|
self.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&CompilationTarget::Module(module_name), &key)
|
.get_predicate_skeleton_mut(&CompilationTarget::Module(module_name), &key)
|
||||||
.map(|skeleton| {
|
.map(|skeleton| {
|
||||||
skeleton.clauses.pop_front();
|
skeleton.clauses.pop_front();
|
||||||
});
|
});
|
||||||
@@ -266,7 +266,7 @@ impl<'a> Drop for LoadState<'a> {
|
|||||||
RetractionRecord::AppendedUserExtensiblePredicate(key) => {
|
RetractionRecord::AppendedUserExtensiblePredicate(key) => {
|
||||||
self.wam
|
self.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&CompilationTarget::User, &key)
|
.get_predicate_skeleton_mut(&CompilationTarget::User, &key)
|
||||||
.map(|skeleton| {
|
.map(|skeleton| {
|
||||||
skeleton.clauses.pop_back();
|
skeleton.clauses.pop_back();
|
||||||
});
|
});
|
||||||
@@ -274,7 +274,7 @@ impl<'a> Drop for LoadState<'a> {
|
|||||||
RetractionRecord::PrependedUserExtensiblePredicate(key) => {
|
RetractionRecord::PrependedUserExtensiblePredicate(key) => {
|
||||||
self.wam
|
self.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&CompilationTarget::User, &key)
|
.get_predicate_skeleton_mut(&CompilationTarget::User, &key)
|
||||||
.map(|skeleton| {
|
.map(|skeleton| {
|
||||||
skeleton.clauses.pop_front();
|
skeleton.clauses.pop_front();
|
||||||
});
|
});
|
||||||
@@ -412,7 +412,7 @@ impl<'a> Drop for LoadState<'a> {
|
|||||||
match self
|
match self
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&compilation_target, &key)
|
.get_predicate_skeleton_mut(&compilation_target, &key)
|
||||||
{
|
{
|
||||||
Some(skeleton) => {
|
Some(skeleton) => {
|
||||||
skeleton.clause_clause_locs.truncate_front(len);
|
skeleton.clause_clause_locs.truncate_front(len);
|
||||||
@@ -430,7 +430,7 @@ impl<'a> Drop for LoadState<'a> {
|
|||||||
match self
|
match self
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&compilation_target, &(clause_name!("$clause"), 2))
|
.get_predicate_skeleton_mut(&compilation_target, &(clause_name!("$clause"), 2))
|
||||||
{
|
{
|
||||||
Some(skeleton) => {
|
Some(skeleton) => {
|
||||||
skeleton.clause_clause_locs.truncate_front(len);
|
skeleton.clause_clause_locs.truncate_front(len);
|
||||||
@@ -446,7 +446,7 @@ impl<'a> Drop for LoadState<'a> {
|
|||||||
match self
|
match self
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&compilation_target, &key)
|
.get_predicate_skeleton_mut(&compilation_target, &key)
|
||||||
{
|
{
|
||||||
Some(skeleton) => {
|
Some(skeleton) => {
|
||||||
skeleton.clause_clause_locs.truncate_back(len);
|
skeleton.clause_clause_locs.truncate_back(len);
|
||||||
@@ -464,7 +464,7 @@ impl<'a> Drop for LoadState<'a> {
|
|||||||
match self
|
match self
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&compilation_target, &(clause_name!("$clause"), 2))
|
.get_predicate_skeleton_mut(&compilation_target, &(clause_name!("$clause"), 2))
|
||||||
{
|
{
|
||||||
Some(skeleton) => {
|
Some(skeleton) => {
|
||||||
skeleton.clause_clause_locs.truncate_back(len);
|
skeleton.clause_clause_locs.truncate_back(len);
|
||||||
@@ -476,7 +476,7 @@ impl<'a> Drop for LoadState<'a> {
|
|||||||
match self
|
match self
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&compilation_target, &key)
|
.get_predicate_skeleton_mut(&compilation_target, &key)
|
||||||
{
|
{
|
||||||
Some(skeleton) => {
|
Some(skeleton) => {
|
||||||
skeleton.clauses.pop_back();
|
skeleton.clauses.pop_back();
|
||||||
@@ -488,7 +488,7 @@ impl<'a> Drop for LoadState<'a> {
|
|||||||
match self
|
match self
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&compilation_target, &key)
|
.get_predicate_skeleton_mut(&compilation_target, &key)
|
||||||
{
|
{
|
||||||
Some(skeleton) => {
|
Some(skeleton) => {
|
||||||
skeleton.clauses.pop_front();
|
skeleton.clauses.pop_front();
|
||||||
@@ -500,7 +500,7 @@ impl<'a> Drop for LoadState<'a> {
|
|||||||
match self
|
match self
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&compilation_target, &key)
|
.get_predicate_skeleton_mut(&compilation_target, &key)
|
||||||
{
|
{
|
||||||
Some(skeleton) => {
|
Some(skeleton) => {
|
||||||
skeleton.clauses.truncate_back(len);
|
skeleton.clauses.truncate_back(len);
|
||||||
@@ -517,7 +517,7 @@ impl<'a> Drop for LoadState<'a> {
|
|||||||
match self
|
match self
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&compilation_target, &key)
|
.get_predicate_skeleton_mut(&compilation_target, &key)
|
||||||
{
|
{
|
||||||
Some(skeleton) => {
|
Some(skeleton) => {
|
||||||
skeleton.clauses[target_pos].clause_start = clause_start;
|
skeleton.clauses[target_pos].clause_start = clause_start;
|
||||||
@@ -535,7 +535,7 @@ impl<'a> Drop for LoadState<'a> {
|
|||||||
match self
|
match self
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&compilation_target, &key)
|
.get_predicate_skeleton_mut(&compilation_target, &key)
|
||||||
{
|
{
|
||||||
Some(skeleton) => {
|
Some(skeleton) => {
|
||||||
skeleton
|
skeleton
|
||||||
@@ -1365,7 +1365,7 @@ impl Machine {
|
|||||||
.load_state
|
.load_state
|
||||||
.wam
|
.wam
|
||||||
.indices
|
.indices
|
||||||
.get_predicate_skeleton(&compilation_target, &key)
|
.get_predicate_skeleton_mut(&compilation_target, &key)
|
||||||
.map(|skeleton| skeleton.is_dynamic = true);
|
.map(|skeleton| skeleton.is_dynamic = true);
|
||||||
|
|
||||||
loader.compile_clause_clauses(
|
loader.compile_clause_clauses(
|
||||||
@@ -1407,53 +1407,98 @@ impl Machine {
|
|||||||
_ => CompilationTarget::Module(module_name),
|
_ => CompilationTarget::Module(module_name),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut loader = Loader::new(LiveTermStream::new(ListingSource::User), self);
|
let abolish_clause = || {
|
||||||
loader.load_state.compilation_target = compilation_target;
|
let mut loader = Loader::new(LiveTermStream::new(ListingSource::User), self);
|
||||||
|
loader.load_state.compilation_target = compilation_target;
|
||||||
|
|
||||||
match loader
|
let clause_clause_compilation_target =
|
||||||
.load_state
|
match &loader.load_state.compilation_target {
|
||||||
.wam
|
CompilationTarget::User => {
|
||||||
.indices
|
CompilationTarget::Module(clause_name!("builtins"))
|
||||||
.get_predicate_skeleton(&loader.load_state.compilation_target, &key)
|
}
|
||||||
{
|
module => {
|
||||||
Some(skeleton) => {
|
module.clone()
|
||||||
skeleton.clauses.clear();
|
}
|
||||||
skeleton.clause_clause_locs.clear();
|
};
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
unreachable!();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let code_index = loader.load_state.get_or_insert_code_index(key);
|
let mut clause_assert_margin = loader
|
||||||
code_index.set(IndexPtr::DynamicUndefined);
|
.load_state
|
||||||
|
.wam
|
||||||
|
.indices
|
||||||
|
.modules
|
||||||
|
.get(&clause_clause_compilation_target.module_name())
|
||||||
|
.map(|module| module.clause_assert_margin)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
match loader.load_state.compilation_target {
|
let mut clause_clause_target_poses: Vec<_> = loader
|
||||||
CompilationTarget::User => {
|
.load_state
|
||||||
loader.load_state.compilation_target =
|
.wam
|
||||||
CompilationTarget::Module(clause_name!("builtins"));
|
.indices
|
||||||
|
.get_predicate_skeleton(&loader.load_state.compilation_target, &key)
|
||||||
|
.map(|skeleton| {
|
||||||
|
loader
|
||||||
|
.load_state
|
||||||
|
.wam
|
||||||
|
.indices
|
||||||
|
.get_predicate_skeleton(
|
||||||
|
&clause_clause_compilation_target,
|
||||||
|
&(clause_name!("$clause"), 2),
|
||||||
|
)
|
||||||
|
.map(|clause_clause_skeleton| {
|
||||||
|
skeleton.clause_clause_locs
|
||||||
|
.iter()
|
||||||
|
.map(|clause_clause_loc| {
|
||||||
|
clause_clause_skeleton.target_pos_of_clause_clause_loc(
|
||||||
|
*clause_clause_loc,
|
||||||
|
clause_assert_margin,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
loader
|
||||||
|
.load_state
|
||||||
|
.wam
|
||||||
|
.indices
|
||||||
|
.get_predicate_skeleton_mut(&loader.load_state.compilation_target, &key)
|
||||||
|
.map(|skeleton| {
|
||||||
|
skeleton.clauses.clear();
|
||||||
|
skeleton.clause_clause_locs.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
let code_index = loader.load_state.get_or_insert_code_index(key);
|
||||||
|
code_index.set(IndexPtr::DynamicUndefined);
|
||||||
|
|
||||||
|
loader.load_state.compilation_target = clause_clause_compilation_target;
|
||||||
|
|
||||||
|
while let Some(target_pos) = clause_clause_target_poses.pop() {
|
||||||
|
loader.load_state.retract_clause((clause_name!("$clause"), 2), target_pos);
|
||||||
|
|
||||||
|
if target_pos < clause_assert_margin {
|
||||||
|
clause_assert_margin -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
|
loader
|
||||||
|
.load_state
|
||||||
|
.wam
|
||||||
|
.indices
|
||||||
|
.modules
|
||||||
|
.get_mut(&loader.load_state.compilation_target.module_name())
|
||||||
|
.map(|module| module.clause_assert_margin = clause_assert_margin);
|
||||||
|
|
||||||
|
LiveTermStream::evacuate(loader)
|
||||||
};
|
};
|
||||||
|
|
||||||
match loader.load_state.wam.indices.get_predicate_skeleton(
|
match abolish_clause() {
|
||||||
&loader.load_state.compilation_target,
|
Ok(_) => {}
|
||||||
&(clause_name!("$clause"), 2),
|
Err(e) => {
|
||||||
) {
|
self.throw_session_error(e, (clause_name!("abolish"), 1));
|
||||||
Some(skeleton) => {
|
|
||||||
skeleton.clauses.clear();
|
|
||||||
skeleton.clause_clause_locs.clear();
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
unreachable!();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let clause_clause_code_index = loader
|
|
||||||
.load_state
|
|
||||||
.get_or_insert_code_index((clause_name!("$clause"), 2));
|
|
||||||
|
|
||||||
clause_clause_code_index.set(IndexPtr::DynamicUndefined);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn retract_clause(&mut self) {
|
pub(crate) fn retract_clause(&mut self) {
|
||||||
@@ -1507,17 +1552,12 @@ impl Machine {
|
|||||||
&(clause_name!("$clause"), 2),
|
&(clause_name!("$clause"), 2),
|
||||||
) {
|
) {
|
||||||
Some(skeleton) => {
|
Some(skeleton) => {
|
||||||
let search_result = skeleton.clause_clause_locs[0..clause_assert_margin]
|
let target_pos = skeleton.target_pos_of_clause_clause_loc(
|
||||||
.binary_search_by(|loc| clause_clause_loc.cmp(&loc));
|
clause_clause_loc,
|
||||||
|
clause_assert_margin,
|
||||||
|
);
|
||||||
|
|
||||||
let result = search_result.unwrap_or_else(|_| {
|
if target_pos < clause_assert_margin {
|
||||||
skeleton.clause_clause_locs[clause_assert_margin..]
|
|
||||||
.binary_search_by(|loc| loc.cmp(&clause_clause_loc))
|
|
||||||
.unwrap()
|
|
||||||
+ clause_assert_margin
|
|
||||||
});
|
|
||||||
|
|
||||||
if result < clause_assert_margin {
|
|
||||||
loader
|
loader
|
||||||
.load_state
|
.load_state
|
||||||
.wam
|
.wam
|
||||||
@@ -1527,7 +1567,7 @@ impl Machine {
|
|||||||
.map(|module| module.clause_assert_margin -= 1);
|
.map(|module| module.clause_assert_margin -= 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
target_pos
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
|
|||||||
@@ -720,7 +720,7 @@ impl Default for IndexStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl IndexStore {
|
impl IndexStore {
|
||||||
pub fn get_predicate_skeleton(
|
pub fn get_predicate_skeleton_mut(
|
||||||
&mut self,
|
&mut self,
|
||||||
compilation_target: &CompilationTarget,
|
compilation_target: &CompilationTarget,
|
||||||
key: &PredicateKey,
|
key: &PredicateKey,
|
||||||
@@ -740,6 +740,26 @@ impl IndexStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_predicate_skeleton(
|
||||||
|
&self,
|
||||||
|
compilation_target: &CompilationTarget,
|
||||||
|
key: &PredicateKey,
|
||||||
|
) -> Option<&PredicateSkeleton> {
|
||||||
|
match (key.0.as_str(), key.1) {
|
||||||
|
("term_expansion", 2) => self.extensible_predicates.get(key),
|
||||||
|
_ => match compilation_target {
|
||||||
|
CompilationTarget::User => self.extensible_predicates.get(key),
|
||||||
|
CompilationTarget::Module(ref module_name) => {
|
||||||
|
if let Some(module) = self.modules.get(module_name) {
|
||||||
|
module.extensible_predicates.get(key)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn remove_predicate_skeleton(
|
pub fn remove_predicate_skeleton(
|
||||||
&mut self,
|
&mut self,
|
||||||
compilation_target: &CompilationTarget,
|
compilation_target: &CompilationTarget,
|
||||||
|
|||||||
@@ -4631,7 +4631,7 @@ impl MachineState {
|
|||||||
|
|
||||||
copy_term(
|
copy_term(
|
||||||
CopyBallTerm::new(&mut self.stack, &mut self.heap, &mut ball.stub),
|
CopyBallTerm::new(&mut self.stack, &mut self.heap, &mut ball.stub),
|
||||||
value.clone(),
|
value,
|
||||||
AttrVarPolicy::DeepCopy,
|
AttrVarPolicy::DeepCopy,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user