Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce result class #26

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open

Introduce result class #26

wants to merge 34 commits into from

Conversation

woosh
Copy link
Collaborator

@woosh woosh commented Feb 20, 2025

Summary

This PR introduces a Result trait and related classes in order to introduce more structure into the post processing of the result from the horn solver. Therefore this PR makes substantial changes to these parts of the code, especially the post-processors related to translation of explicit heap into implicit form more suitable for ACSL contract generation.

An ambition has been to introduce an interface between the translator (CCReader) the solver and the result. A major change is a move away from the existing FunctionContext and ACSLTranslator.FunctionContext. These classes kept too much information in a form tightly bound to the problem description for them to be practical to use.

the ResultConverter.hornSolverSolutionToResult() converts the solution from the horn solver and data from CCReader into a Solution result (see below). As part of this conversion, the predicate variables representing program variables of some kind (globals, parameters, or locals in the case of loop invariants) are replaced with symbolic constants. However, in order to keep necessary meta data about them the IConstant is instantiated with a special type of constant, ProgVarProxy, derived from ConstantTerm. That way they can be separated from any other constant in the expressions. ProgVarProxy does not rely on prefix or suffix information in the name in order to keep track of various attributes. Instead such informtion is kept in separate variables.

Introduced concepts

  • Result trait. A container for a the result. There are case classes for Empty, CounterExample and Solution.
  • A Solution is a set of FunctionInvariants, one for each function we are inferring contracts for.
  • A FunctionInvariant is a PreCondition, PostCondition, and LoopInvariants and some meta-data.
  • PreCondition, PostCondition, and LoopInvariants are cases extending the InvariantContext trait.
  • PreCondition and PostCondition each contains an Invariant.
  • Invariant is a container for an IFormula and some meta-data for heap operations.
  • HeapInfo is a class that contains information regarding the heap and objects and functions related to that.
  • ProgVarProxy is derived from ConstantTerm and is used as a proxy for program variables in IFormula and IExpressions. ProgVarProxy carries meta data about scope (global, parameter etc.) and context (pre-execution, post-execution). This is utilized in ACSL contract generation.

Comments

  • There are still "DeBruijn" and "invariant" versions of ValSetReader EqualitySwapper and friends. I can't see this being necessary anymore, since all free variables are replaced by symbolic constants before any processing is started. However, I noticed some differences in their implementation and have therefore kept both. This needs further consideration
  • I have moved a lot of the presentation and printing stuff into separate functions in an effort to emphasize the flow of the data. Presentation and calculations are still entangled in the counter-example part of the result processing. This needs further consideration.

mkString(PrepareACSLPrinting(i)))))
}

// SSSOWO TODO: This doesn't seem to be used anywhere. Remove?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zafer-esen Please advice on this.

(result: Either[Option[HornPreprocessor.Solution], hornconcurrency.VerificationLoop.Counterexample])
: Result = {
import scala.collection.mutable.HashSet
// SSSOWO TODO: These constants should be defined in a single place.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zafer-esen Please advice on how to go forward here.

subres: Seq[IExpression]
): IExpression = {
t update subres match {
// SSSOWO TODO: Why does this need special handling? "emptyHeap" is
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zafer-esen Do you have any comment on this?

@@ -225,6 +226,9 @@ object ValSetReader {
extends CollectingVisitor[Unit, ValSet]
with ExpressionUtils {

// SSSOWO: The de Bruijn version disregards disjunctions,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zafer-esen To mee this looks really weird. The deBruijn version and the "invariant" version treat disjunctions differently. I actually think the deBruijn version is correct and that this implementation may cause some to the problems discussed in issue #15. But I think we need to have a closer look on what to do with disjunctions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant