Skip to content

Commit

Permalink
Not collecting axioms and declarations unless necessary, and resettin…
Browse files Browse the repository at this point in the history
…g properly
  • Loading branch information
marcoeilers committed Aug 27, 2024
1 parent 2151ff6 commit 63d1716
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/main/scala/decider/ProverStdIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ abstract class ProverStdIO(uniqueId: String,
Runtime.getRuntime.removeShutdownHook(proverShutdownHook)
proverShutdownHook = null
}
allDecls = Seq()
allEmits = Seq()
}
}

Expand All @@ -196,7 +198,9 @@ abstract class ProverStdIO(uniqueId: String,
}

def emit(content: String): Unit = {
allEmits :+= content
if (debugMode) {
allEmits :+= content
}
writeLine(content)
readSuccess()
}
Expand Down Expand Up @@ -403,7 +407,8 @@ abstract class ProverStdIO(uniqueId: String,

def declare(decl: Decl): Unit = {
val str = termConverter.convert(decl)
allDecls = allDecls :+ decl
if (debugMode)
allDecls = allDecls :+ decl
emit(str)
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/decider/Z3ProverAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class Z3ProverAPI(uniqueId: String,
val emittedFuncs = mutable.LinkedHashSet[FuncDecl]()
val emittedFuncSymbols = mutable.Queue[Symbol]()
var allDecls: Seq[Decl] = Seq()
var allEmits: Seq[String] = Seq()

// If true, we do not define macros on the Z3 level, but perform macro expansion ourselves on Silicon Terms.
// Otherwise, we define a function on the Z3 level and axiomatize it according to the macro definition.
Expand Down Expand Up @@ -186,6 +185,7 @@ class Z3ProverAPI(uniqueId: String,
emittedSorts.clear()
emittedFuncSymbols.clear()
emittedSortSymbols.clear()
allDecls = Seq()
}

def reset(): Unit = {
Expand All @@ -196,6 +196,7 @@ class Z3ProverAPI(uniqueId: String,

def stop(): Unit = {
emittedPreambleString.clear()
allDecls = Seq()
preamblePhaseOver = false
emittedFuncs.clear()
emittedSorts.clear()
Expand Down Expand Up @@ -232,19 +233,17 @@ class Z3ProverAPI(uniqueId: String,
if (preamblePhaseOver) {
sys.error("emitting phase over")
}
allEmits :+= content
emittedPreambleString.append(content)
}

override def emit(contents: Iterable[String]): Unit = {
if (preamblePhaseOver) {
sys.error("emitting phase over")
}
allEmits ++= contents
emittedPreambleString.appendAll(contents)
}

def getAllEmits(): Seq[String] = allEmits
def getAllEmits(): Seq[String] = emittedPreambleString.toSeq

override def emitSettings(contents: Iterable[String]): Unit = {
// we ignore this, don't know any better solution atm.
Expand Down Expand Up @@ -448,7 +447,8 @@ class Z3ProverAPI(uniqueId: String,
// current state) and record it in out collection(s) of emmitted declarations.
// Special handling for macro declarations if expandMacros is true; in that case,
// nothing is declared on the Z3 level, and we simply remember the definition ourselves.
allDecls = allDecls :+ decl
if (debugMode)
allDecls = allDecls :+ decl
decl match {
case SortDecl(s) =>
val convertedSort = termConverter.convertSort(s)
Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/interfaces/decider/Prover.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import viper.silicon.common.config.Version
import viper.silver.components.StatefulComponent
import viper.silicon.{Config, Map}
import viper.silicon.state.terms._
import viper.silicon.verifier.Verifier
import viper.silver.verifier.Model

sealed abstract class Result
Expand All @@ -21,12 +22,14 @@ object Unknown extends Result

/* TODO: Should be generic, not hardcoded to Strings */
trait ProverLike {
protected val debugMode = Verifier.config.enableDebugging()
var preambleAssumptions: Seq[DebugAxiom] = Seq()
def emit(content: String): Unit
def emit(contents: Iterable[String]): Unit = { contents foreach emit }
def emitSettings(contents: Iterable[String]): Unit
def assumeAxioms(terms: InsertionOrderedSet[Term], description: String): Unit = {
preambleAssumptions :+= new DebugAxiom(description, terms)
if (debugMode)
preambleAssumptions :+= new DebugAxiom(description, terms)
terms foreach assume
}
def setOption(name: String, value: String): String
Expand Down

0 comments on commit 63d1716

Please sign in to comment.