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

Review async KSMT solver methods usage in suspending context #91

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Changes from all 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 @@ -716,7 +716,7 @@ class KSMTSolver(
ef.buildConstClassAxioms().asAxiom() as KExpr<KBoolSort>,
ef.ctx.mkConstDecl("ClassAxioms", ef.ctx.boolSort)
)
solver.push()
solver.pushAsync()

return queries.map { (hardConstraints, softConstraints, ctx) ->
solver.assertAndTrackAsync(
Expand All @@ -725,10 +725,10 @@ class KSMTSolver(
)
val softConstraintsMap = when {
softConstraints.isNotEmpty() -> {
solver.push()
solver.pushAsync()
softConstraints.withIndex().associate { (index, softConstraint) ->
val expr = ef.ctx.mkConstDecl("SoftConstraint$index", ef.ctx.boolSort)
solver.assertAndTrack(softConstraint.asAxiom() as KExpr<KBoolSort>, expr)
solver.assertAndTrackAsync(softConstraint.asAxiom() as KExpr<KBoolSort>, expr)
(expr as KConstDecl<KBoolSort>) to softConstraint.asAxiom() as KExpr<KBoolSort>
}
}
Expand Down Expand Up @@ -763,19 +763,19 @@ class KSMTSolver(
result to reason
}
}.also {
solver.pop()
solver.popAsync(1u)
if (softConstraints.isNotEmpty()) {
solver.pop()
solver.popAsync(1u)
}
solver.push()
solver.pushAsync()
}.with(ctx)
}
}

private suspend fun KPortfolioSolver.checkAndMinimize(
softConstraintsMap: Map<KConstDecl<KBoolSort>, KExpr<KBoolSort>>
): KSolverStatus {
var result = this.check()
var result = this.checkAsync(timeout.seconds)
return when (result) {
KSolverStatus.UNSAT -> {
while (result == KSolverStatus.UNSAT && softConstraintsMap.isNotEmpty()) {
Expand All @@ -785,8 +785,8 @@ class KSMTSolver(
val core = tryOrNull { this.unsatCoreAsync().toSet() } ?: return result
if (core.any { exprToDeclMappings[it] !in softCopies }) break
else {
this.pop()
this.push()
this.popAsync(1u)
this.pushAsync()
for (key in core) softCopies.remove(exprToDeclMappings[key])
for ((expr, softConstraint) in softCopies) {
this.assertAndTrackAsync(softConstraint, expr)
Expand Down
Loading