Check that only input/output predicates are used in specification
This commit is contained in:
parent
e2281042c9
commit
80d39c8c0a
@ -44,6 +44,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
match problem.check_that_only_input_and_output_predicates_are_used()
|
||||
{
|
||||
Ok(_) => (),
|
||||
Err(error) =>
|
||||
{
|
||||
log::error!("{}", error);
|
||||
std::process::exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
match problem.restrict_to_output_predicates()
|
||||
{
|
||||
Ok(_) => (),
|
||||
|
12
src/error.rs
12
src/error.rs
@ -24,6 +24,7 @@ pub enum Kind
|
||||
FormulaNotClosed(std::rc::Rc<foliage::VariableDeclarations>),
|
||||
NoCompletedDefinitionFound(std::rc::Rc<foliage::PredicateDeclaration>),
|
||||
CannotHidePredicate(std::rc::Rc<foliage::PredicateDeclaration>),
|
||||
PredicateShouldNotOccurInSpecification(std::rc::Rc<foliage::PredicateDeclaration>),
|
||||
WriteTPTPProgram,
|
||||
RunVampire,
|
||||
// TODO: rename to something Vampire-specific
|
||||
@ -164,6 +165,13 @@ impl Error
|
||||
Self::new(Kind::CannotHidePredicate(predicate_declaration))
|
||||
}
|
||||
|
||||
pub(crate) fn new_predicate_should_not_occur_in_specification(
|
||||
predicate_declaration: std::rc::Rc<foliage::PredicateDeclaration>)
|
||||
-> Self
|
||||
{
|
||||
Self::new(Kind::PredicateShouldNotOccurInSpecification(predicate_declaration))
|
||||
}
|
||||
|
||||
pub(crate) fn new_write_tptp_program<S: Into<Source>>(source: S) -> Self
|
||||
{
|
||||
Self::new(Kind::WriteTPTPProgram).with(source)
|
||||
@ -241,6 +249,10 @@ impl std::fmt::Debug for Error
|
||||
write!(formatter,
|
||||
"cannot hide predicate {} (the completed definition transitively depends on itself)",
|
||||
predicate_declaration),
|
||||
Kind::PredicateShouldNotOccurInSpecification(ref predicate_declaration) =>
|
||||
write!(formatter,
|
||||
"predicate {} should not occur in specification (it is not declared as an input or output predicate)",
|
||||
predicate_declaration),
|
||||
Kind::RunVampire => write!(formatter, "could not run Vampire"),
|
||||
Kind::ProveProgram(exit_code, ref stdout, ref stderr) =>
|
||||
{
|
||||
|
@ -82,6 +82,54 @@ impl Problem
|
||||
section.push(statement);
|
||||
}
|
||||
|
||||
pub(crate) fn check_that_only_input_and_output_predicates_are_used(&self)
|
||||
-> Result<(), crate::Error>
|
||||
{
|
||||
let predicate_declarations = self.predicate_declarations.borrow();
|
||||
let input_predicate_declarations = self.input_predicate_declarations.borrow();
|
||||
let output_predicate_declarations = self.output_predicate_declarations.borrow();
|
||||
|
||||
if output_predicate_declarations.is_empty()
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Check that only input and output predicates are used in the specification
|
||||
for predicate_declaration in predicate_declarations.iter()
|
||||
{
|
||||
if input_predicate_declarations.contains(predicate_declaration)
|
||||
|| output_predicate_declarations.contains(predicate_declaration)
|
||||
// TODO: refactor
|
||||
// Auxiliary predicates may occur anywhere
|
||||
|| predicate_declaration.name.starts_with("p__")
|
||||
&& predicate_declaration.name.ends_with("__")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (section_key, statements) in self.statements.borrow().iter()
|
||||
{
|
||||
for statement in statements
|
||||
{
|
||||
match statement.kind
|
||||
{
|
||||
crate::problem::StatementKind::CompletedDefinition(_)
|
||||
| crate::problem::StatementKind::IntegrityConstraint => continue,
|
||||
_ => (),
|
||||
}
|
||||
|
||||
if crate::formula_contains_predicate(&statement.formula, predicate_declaration)
|
||||
{
|
||||
return Err(crate::Error::new_predicate_should_not_occur_in_specification(
|
||||
std::rc::Rc::clone(predicate_declaration)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn restrict_to_output_predicates(&mut self) -> Result<(), crate::Error>
|
||||
{
|
||||
let predicate_declarations = self.predicate_declarations.borrow();
|
||||
|
@ -1,4 +1,4 @@
|
||||
fn formula_contains_predicate(formula: &foliage::Formula,
|
||||
pub(crate) fn formula_contains_predicate(formula: &foliage::Formula,
|
||||
predicate_declaration: &foliage::PredicateDeclaration)
|
||||
-> bool
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user