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: remove repetitive folds in Z3Context #3006

Merged
merged 9 commits into from
Oct 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -767,26 +767,17 @@ class Z3SolverContext(val config: SolverConfig) extends SolverContext with LazyL
case OperEx(ApalacheInternalOper.distinct, args @ _*) =>
val (es, ns) = (args.map(toExpr)).unzip
val distinct = z3context.mkDistinct(es: _*)
(distinct.asInstanceOf[ExprSort],
ns.foldLeft(1L) {
_ + _
})
(distinct.asInstanceOf[ExprSort], sumExprCount(ns))
konnov marked this conversation as resolved.
Show resolved Hide resolved

case OperEx(TlaBoolOper.and, args @ _*) =>
val (es, ns) = (args.map(toExpr)).unzip
val and = z3context.mkAnd(es.map(_.asInstanceOf[BoolExpr]): _*)
(and.asInstanceOf[ExprSort],
ns.foldLeft(1L) {
_ + _
})
(and.asInstanceOf[ExprSort], sumExprCount(ns))

case OperEx(TlaBoolOper.or, args @ _*) =>
val (es, ns) = (args.map(toExpr)).unzip
val or = z3context.mkOr(es.map(_.asInstanceOf[BoolExpr]): _*)
(or.asInstanceOf[ExprSort],
ns.foldLeft(1L) {
_ + _
})
(or.asInstanceOf[ExprSort], sumExprCount(ns))

case OperEx(TlaBoolOper.implies, lhs, rhs) =>
val (lhsZ3, ln) = toExpr(lhs)
Expand Down Expand Up @@ -1079,6 +1070,11 @@ class Z3SolverContext(val config: SolverConfig) extends SolverContext with LazyL
})
logger.info(entries.mkString(",") + "\n")
}

// sum up the number of expressions in the children, add 1 for self
private def sumExprCount(nexprInChildren: Seq[Long]): Long = {
nexprInChildren.foldLeft(1L) { _ + _ }
}
}

object Z3SolverContext {
Expand Down
Loading