Skip to content
Snippets Groups Projects
Commit a679d54b authored by Nicolas Voirol's avatar Nicolas Voirol
Browse files

Fixed funDef ordering in Strengthener

parent 9566dcff
No related branches found
No related tags found
No related merge requests found
...@@ -17,12 +17,22 @@ trait Strengthener { self : RelationComparator => ...@@ -17,12 +17,22 @@ trait Strengthener { self : RelationComparator =>
val checker: TerminationChecker val checker: TerminationChecker
implicit object CallGraphOrdering extends Ordering[FunDef] {
def compare(a: FunDef, b: FunDef): Int = {
val aCallsB = checker.program.callGraph.transitivelyCalls(a, b)
val bCallsA = checker.program.callGraph.transitivelyCalls(b, a)
if (aCallsB && !bCallsA) -1
else if (bCallsA && !aCallsB) 1
else 0
}
}
private val strengthenedPost : MutableSet[FunDef] = MutableSet.empty private val strengthenedPost : MutableSet[FunDef] = MutableSet.empty
def strengthenPostconditions(funDefs: Set[FunDef])(implicit solver: Processor with Solvable) { def strengthenPostconditions(funDefs: Set[FunDef])(implicit solver: Processor with Solvable) {
// Strengthen postconditions on all accessible functions by adding size constraints // Strengthen postconditions on all accessible functions by adding size constraints
val callees : Set[FunDef] = funDefs.flatMap(fd => checker.program.callGraph.transitiveCallees(fd)) val callees : Set[FunDef] = funDefs.flatMap(fd => checker.program.callGraph.transitiveCallees(fd))
val sortedCallees : Seq[FunDef] = callees.toSeq.sortWith((fd1, fd2) => checker.program.callGraph.transitivelyCalls(fd2, fd1)) val sortedCallees : Seq[FunDef] = callees.toSeq.sorted
for (funDef <- sortedCallees if !strengthenedPost(funDef) && funDef.hasBody && checker.terminates(funDef).isGuaranteed) { for (funDef <- sortedCallees if !strengthenedPost(funDef) && funDef.hasBody && checker.terminates(funDef).isGuaranteed) {
def strengthen(cmp: (Seq[Expr], Seq[Expr]) => Expr): Boolean = { def strengthen(cmp: (Seq[Expr], Seq[Expr]) => Expr): Boolean = {
...@@ -85,7 +95,7 @@ trait Strengthener { self : RelationComparator => ...@@ -85,7 +95,7 @@ trait Strengthener { self : RelationComparator =>
def strengthenApplications(funDefs: Set[FunDef])(implicit solver: Processor with Solvable) { def strengthenApplications(funDefs: Set[FunDef])(implicit solver: Processor with Solvable) {
val transitiveFunDefs = funDefs ++ funDefs.flatMap(checker.program.callGraph.transitiveCallees) val transitiveFunDefs = funDefs ++ funDefs.flatMap(checker.program.callGraph.transitiveCallees)
val sortedFunDefs = transitiveFunDefs.toSeq.sortWith((fd1, fd2) => checker.program.callGraph.transitivelyCalls(fd2, fd1)) val sortedFunDefs = transitiveFunDefs.toSeq.sorted
for (funDef <- sortedFunDefs if !strengthenedApp(funDef) && funDef.hasBody && checker.terminates(funDef).isGuaranteed) { for (funDef <- sortedFunDefs if !strengthenedApp(funDef) && funDef.hasBody && checker.terminates(funDef).isGuaranteed) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment