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

Flag for non-linear integer arithmetic #709

Merged
merged 8 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/main/scala/viper/gobra/backend/ViperBackends.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ object ViperBackends {
if (config.z3APIMode) {
options = options ++ Vector(s"--prover=${Z3ProverAPI.name}")
}
if (config.disableNL) {
options = options ++ Vector(s"--disableNL")
}
val mceSiliconOpt = config.mceMode match {
case MCE.Disabled => "0"
case MCE.Enabled => "1"
Expand Down
22 changes: 22 additions & 0 deletions src/main/scala/viper/gobra/frontend/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ object ConfigDefaults {
lazy val DefaultParallelizeBranches: Boolean = false
lazy val DefaultConditionalizePermissions: Boolean = false
lazy val DefaultZ3APIMode: Boolean = false
lazy val DefaultDisableNL: Boolean = false
lazy val DefaultMCEMode: MCE.Mode = MCE.Enabled
lazy val DefaultEnableLazyImports: Boolean = false
lazy val DefaultNoVerify: Boolean = false
Expand Down Expand Up @@ -130,6 +131,7 @@ case class Config(
parallelizeBranches: Boolean = ConfigDefaults.DefaultParallelizeBranches,
conditionalizePermissions: Boolean = ConfigDefaults.DefaultConditionalizePermissions,
z3APIMode: Boolean = ConfigDefaults.DefaultZ3APIMode,
disableNL: Boolean = ConfigDefaults.DefaultDisableNL,
mceMode: MCE.Mode = ConfigDefaults.DefaultMCEMode,
enableLazyImports: Boolean = ConfigDefaults.DefaultEnableLazyImports,
noVerify: Boolean = ConfigDefaults.DefaultNoVerify,
Expand Down Expand Up @@ -180,6 +182,7 @@ case class Config(
parallelizeBranches = parallelizeBranches,
conditionalizePermissions = conditionalizePermissions,
z3APIMode = z3APIMode || other.z3APIMode,
disableNL = disableNL || other.disableNL,
mceMode = mceMode,
enableLazyImports = enableLazyImports || other.enableLazyImports,
noVerify = noVerify || other.noVerify,
Expand Down Expand Up @@ -233,6 +236,7 @@ case class BaseConfig(gobraDirectory: Path = ConfigDefaults.DefaultGobraDirector
parallelizeBranches: Boolean = ConfigDefaults.DefaultParallelizeBranches,
conditionalizePermissions: Boolean = ConfigDefaults.DefaultConditionalizePermissions,
z3APIMode: Boolean = ConfigDefaults.DefaultZ3APIMode,
disableNL: Boolean = ConfigDefaults.DefaultDisableNL,
mceMode: MCE.Mode = ConfigDefaults.DefaultMCEMode,
enableLazyImports: Boolean = ConfigDefaults.DefaultEnableLazyImports,
noVerify: Boolean = ConfigDefaults.DefaultNoVerify,
Expand Down Expand Up @@ -290,6 +294,7 @@ trait RawConfig {
parallelizeBranches = baseConfig.parallelizeBranches,
conditionalizePermissions = baseConfig.conditionalizePermissions,
z3APIMode = baseConfig.z3APIMode,
disableNL = baseConfig.disableNL,
mceMode = baseConfig.mceMode,
enableLazyImports = baseConfig.enableLazyImports,
noVerify = baseConfig.noVerify,
Expand Down Expand Up @@ -561,6 +566,7 @@ class ScallopGobraConfig(arguments: Seq[String], isInputOptional: Boolean = fals
default = None,
noshort = true
)

lazy val packageTimeoutDuration: Duration = packageTimeout.toOption match {
case Some(d) => Duration(d)
case _ => Duration.Inf
Expand Down Expand Up @@ -646,6 +652,13 @@ class ScallopGobraConfig(arguments: Seq[String], isInputOptional: Boolean = fals
noshort = true,
)

val disableNL: ScallopOption[Boolean] = opt[Boolean](
name = "disableNL",
descr = "Disable non-linear integer arithmetics. Non compatible with Carbon",
default = Some(ConfigDefaults.DefaultDisableNL),
noshort = true,
)

val mceMode: ScallopOption[MCE.Mode] = {
val on = "on"
val off = "off"
Expand Down Expand Up @@ -770,6 +783,14 @@ class ScallopGobraConfig(arguments: Seq[String], isInputOptional: Boolean = fals
}
}

addValidation {
if (!disableNL.toOption.contains(true) || isSiliconBasedBackend) {
Right(())
} else {
Left("--disableNL is not compatible with Carbon")
}
}


/** File Validation */
validateFilesExist(cutInput)
Expand Down Expand Up @@ -857,6 +878,7 @@ class ScallopGobraConfig(arguments: Seq[String], isInputOptional: Boolean = fals
parallelizeBranches = parallelizeBranches(),
conditionalizePermissions = conditionalizePermissions(),
z3APIMode = z3APIMode(),
disableNL = disableNL(),
mceMode = mceMode(),
enableLazyImports = enableLazyImports(),
noVerify = noVerify(),
Expand Down
13 changes: 13 additions & 0 deletions src/test/resources/regressions/examples/disableNL.gobra
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

// ##(--disableNL)
package pkg

requires 0 <= x && x <= 10
requires 0 <= y && y <= 10
//:: ExpectedOutput(postcondition_error:assertion_error)
ensures 0 <= res && res <= 100
func f(x, y int) (res int) {
return x * y
}
11 changes: 11 additions & 0 deletions src/test/resources/regressions/examples/disableNL_success.gobra
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

package pkg

requires 0 <= x && x <= 10
requires 0 <= y && y <= 10
ensures 0 <= res && res <= 100
func f(x, y int) (res int) {
return x * y
}
Loading