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

Refactor Z3SolverContext cellCache #1703

Merged
merged 3 commits into from
May 3, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.apache.commons.io.output.NullOutputStream
import java.io.PrintWriter
import java.util.concurrent.atomic.AtomicLong
import scala.collection.mutable
import scala.collection.mutable.ListBuffer

/**
* <p> An implementation of a SolverContext using Z3. Note that this class overrides the global z3 settings
Expand Down Expand Up @@ -78,8 +79,8 @@ class Z3SolverContext(val config: SolverConfig) extends SolverContext {
* representing sets, the cache stores a list of constants. The list is required to support incremental solving, since
* different context levels can have different SSA arrays.
*/
private val cellCache: mutable.Map[Int, List[(ExprSort, CellT, Int)]] =
new mutable.HashMap[Int, List[(ExprSort, CellT, Int)]]
private val cellCache: mutable.Map[Int, ListBuffer[(ExprSort, CellT, Int)]] =
new mutable.HashMap[Int, ListBuffer[(ExprSort, CellT, Int)]]

/**
* A cache for the in-relation between a set and its potential element.
Expand Down Expand Up @@ -144,7 +145,7 @@ class Z3SolverContext(val config: SolverConfig) extends SolverContext {
log(s"(declare-const $cell $cellSort)")
val cellName = cell.toString
val const = z3context.mkConst(cellName, cellSort)
cellCache += (cell.id -> List((const, cell.cellType, level)))
cellCache += (cell.id -> ListBuffer((const, cell.cellType, level)))

// If arrays are used, they are initialized here.
if (cellSort.isInstanceOf[ArraySort[_, _]] && !cell.isUnconstrained) {
Expand Down Expand Up @@ -273,7 +274,7 @@ class Z3SolverContext(val config: SolverConfig) extends SolverContext {
val arraySort = getOrMkCellSort(arrayT)
log(s"(declare-const $updatedArrayName $arraySort)")
val updatedArray = z3context.mkConst(updatedArrayName, arraySort)
cellCache += (arrayId -> ((updatedArray, arrayT, level) :: cellCache(arrayId)))
cellCache += (arrayId -> cellCache(arrayId).prepend((updatedArray, arrayT, level)))
_metrics = _metrics.addNConsts(1)
updatedArray.asInstanceOf[ExprSort]
}
Expand Down Expand Up @@ -420,8 +421,8 @@ class Z3SolverContext(val config: SolverConfig) extends SolverContext {
// clean the caches
cellSorts.filterInPlace((_, value) => value._2 <= level)
funDecls.filterInPlace((_, value) => value._2 <= level)
cellCache.foreach(entry => cellCache += entry.copy(_2 = entry._2.filter(_._3 <= level)))
cellCache.filterInPlace((_, value) => value.nonEmpty)
cellCache.foreachEntry((_, valueList) => valueList.filterInPlace(value => value._3 <= level))
cellCache.filterInPlace((_, valueList) => valueList.nonEmpty)
inCache.filterInPlace((_, value) => value._2 <= level)
constantArrayCache.filterInPlace((_, value) => value._2 <= level)
cellDefaults.filterInPlace((_, value) => value._2 <= level)
Expand All @@ -438,8 +439,8 @@ class Z3SolverContext(val config: SolverConfig) extends SolverContext {
// clean the caches
cellSorts.filterInPlace((_, value) => value._2 <= level)
funDecls.filterInPlace((_, value) => value._2 <= level)
cellCache.foreach(entry => cellCache += entry.copy(_2 = entry._2.filter(_._3 <= level)))
cellCache.filterInPlace((_, value) => value.nonEmpty)
cellCache.foreachEntry((_, valueList) => valueList.filterInPlace(value => value._3 <= level))
cellCache.filterInPlace((_, valueList) => valueList.nonEmpty)
inCache.filterInPlace((_, value) => value._2 <= level)
constantArrayCache.filterInPlace((_, value) => value._2 <= level)
cellDefaults.filterInPlace((_, value) => value._2 <= level)
Expand Down