Skip to content

Commit 26cc85c

Browse files
authored
Add implementation of setTimeout for CVC5 (#933)
1 parent cc9bdc0 commit 26cc85c

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

src/main/scala/Config.scala

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ class Config(args: Seq[String]) extends SilFrontendConfig(args, "Silicon") {
213213
)
214214

215215
val assertTimeout: ScallopOption[Int] = opt[Int]("assertTimeout",
216-
descr = ("Timeout (in ms) per SMT solver assertion (default: 0, i.e. no timeout). "
217-
+ s"Ignored when using the ${Cvc5ProverStdIO.name} prover."),
216+
descr = ("Timeout (in ms) per SMT solver assertion (default: 0, i.e. no timeout). "),
218217
default = None,
219218
noshort = true
220219
)
@@ -225,8 +224,7 @@ class Config(args: Seq[String]) extends SilFrontendConfig(args, "Silicon") {
225224
+ "check doesn't, at least not directly. However, failing checks might result in "
226225
+ "performance degradation, e.g. when a dead program path is nevertheless explored, "
227226
+ "and indirectly in verification failures due to incompletenesses, e.g. when "
228-
+ "the held permission amount is too coarsely underapproximated (default: 10). "
229-
+ s"Ignored when using the ${Cvc5ProverStdIO.name} prover."),
227+
+ "the held permission amount is too coarsely underapproximated (default: 10). "),
230228
default = Some(10),
231229
noshort = true
232230
)
@@ -239,17 +237,13 @@ class Config(args: Seq[String]) extends SilFrontendConfig(args, "Silicon") {
239237

240238
private val rawProverSaturationTimeout = opt[Int]("proverSaturationTimeout",
241239
descr = ( "Timeout (in ms) used for the prover's state saturation calls (default: 100). "
242-
+ "A timeout of 0 disables all saturation checks."
243-
+ s"Note that for the ${Cvc5ProverStdIO.name} prover, state saturation calls can "
244-
+ "either be disabled (weights or base timeout of 0) or forced with no timeout "
245-
+ "(positive weight and base timeout)."),
240+
+ "A timeout of 0 disables all saturation checks."),
246241
default = Some(100),
247242
noshort = true
248243
)
249244

250245
val pushTimeout: ScallopOption[Int] = opt[Int]("pushTimeout",
251-
descr = ( "Timeout (in ms) per push operation in the SMT solver. (default: 0, i.e. no timeout). "
252-
+ s"Ignored when using the ${Cvc5ProverStdIO.name} prover."),
246+
descr = ( "Timeout (in ms) per push operation in the SMT solver. (default: 0, i.e. no timeout). "),
253247
default = Some(0),
254248
noshort = true
255249
)
@@ -302,10 +296,7 @@ class Config(args: Seq[String]) extends SilFrontendConfig(args, "Silicon") {
302296
+ s" after inhale: ${defaultProverSaturationTimeoutWeights.afterInhale}\n"
303297
+ s" before repeated prover queries: ${defaultProverSaturationTimeoutWeights.beforeRepetition}\n"
304298
+ "Weights must be non-negative, a weight of 0 disables the corresponding saturation "
305-
+ "call and a minimal timeout of 10ms is enforced."
306-
+ s"Note that for the ${Cvc5ProverStdIO.name} prover, state saturation calls can "
307-
+ "either be disabled (weights or base timeout of 0) or forced with no timeout "
308-
+ "(positive weight and base timeout)."),
299+
+ "call and a minimal timeout of 10ms is enforced."),
309300
default = Some(defaultProverSaturationTimeoutWeights),
310301
noshort = true
311302
)(saturationTimeoutWeightsConverter)
@@ -404,7 +395,7 @@ class Config(args: Seq[String]) extends SilFrontendConfig(args, "Silicon") {
404395
lazy val proverResourcesPerMillisecond: Int = {
405396
if (rawZ3ResourcesPerMillisecond.isSupplied) rawZ3ResourcesPerMillisecond()
406397
else rawProverResourcesPerMillisecond()
407-
}
398+
}
408399

409400
val rawProverRandomizeSeeds: ScallopOption[Boolean] = opt[Boolean]("proverRandomizeSeeds",
410401
descr = "Set various random seeds of the prover to random values",
@@ -795,7 +786,7 @@ class Config(args: Seq[String]) extends SilFrontendConfig(args, "Silicon") {
795786
)
796787

797788
val conditionalizePermissions: ScallopOption[Boolean] = opt[Boolean]("conditionalizePermissions",
798-
descr = "Potentially reduces the number of symbolic execution paths, by conditionalising " +
789+
descr = "Potentially reduces the number of symbolic execution paths, by conditionalising " +
799790
"permission expressions. E.g. rewrite \"b ==> acc(x.f, p)\" to \"acc(x.f, b ? p : none)\"." +
800791
"This is an experimental feature; report problems if you observe any.",
801792
default = Some(false),

src/main/scala/decider/CVC5ProverStdIO.scala

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Cvc5ProverStdIO(uniqueId: String,
2929
identifierFactory: IdentifierFactory,
3030
reporter: Reporter)
3131
extends ProverStdIO(uniqueId, termConverter, identifierFactory, reporter) {
32-
32+
3333
val name: String = Cvc5ProverStdIO.name
3434
val minVersion: Version = Cvc5ProverStdIO.minVersion
3535
val maxVersion: Option[Version] = Cvc5ProverStdIO.maxVersion
@@ -39,8 +39,20 @@ class Cvc5ProverStdIO(uniqueId: String,
3939
val startUpArgs: Seq[String] = Cvc5ProverStdIO.startUpArgs
4040
val randomizeSeedsOptions: Seq[String] = Cvc5ProverStdIO.randomizeSeedsOptions
4141

42-
// cvc5 does not support per-check timeouts after instantiation.
43-
protected def setTimeout(timeout: Option[Int]): Unit = {}
42+
protected def setTimeout(timeout: Option[Int]): Unit = {
43+
val effectiveTimeout = timeout.getOrElse(Verifier.config.proverTimeout)
44+
45+
if (lastTimeout != effectiveTimeout) {
46+
lastTimeout = effectiveTimeout
47+
48+
if (Verifier.config.proverEnableResourceBounds) {
49+
writeLine(s"(set-option :reproducible-resource-limit ${effectiveTimeout * Verifier.config.proverResourcesPerMillisecond})")
50+
} else {
51+
writeLine(s"(set-option :tlimit-per $effectiveTimeout)")
52+
}
53+
readSuccess()
54+
}
55+
}
4456

4557
protected def getProverPath: Path = {
4658
Paths.get(Verifier.config.cvc5Exe)

0 commit comments

Comments
 (0)