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

Add flag to require triggers in all quantifiers #679

Merged
merged 2 commits into from
Sep 24, 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
16 changes: 15 additions & 1 deletion src/main/scala/viper/gobra/frontend/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ object ConfigDefaults {
lazy val DefaultNoVerify: Boolean = false
lazy val DefaultNoStreamErrors: Boolean = false
lazy val DefaultParseAndTypeCheckMode: TaskManagerMode = TaskManagerMode.Parallel
lazy val DefaultRequireTriggers: Boolean = false
}

// More-complete exhale modes
Expand Down Expand Up @@ -134,6 +135,8 @@ case class Config(
noVerify: Boolean = ConfigDefaults.DefaultNoVerify,
noStreamErrors: Boolean = ConfigDefaults.DefaultNoStreamErrors,
parseAndTypeCheckMode: TaskManagerMode = ConfigDefaults.DefaultParseAndTypeCheckMode,
// when enabled, all quantifiers without triggers are rejected
requireTriggers: Boolean = ConfigDefaults.DefaultRequireTriggers,
) {

def merge(other: Config): Config = {
Expand Down Expand Up @@ -181,7 +184,8 @@ case class Config(
enableLazyImports = enableLazyImports || other.enableLazyImports,
noVerify = noVerify || other.noVerify,
noStreamErrors = noStreamErrors || other.noStreamErrors,
parseAndTypeCheckMode = parseAndTypeCheckMode
parseAndTypeCheckMode = parseAndTypeCheckMode,
requireTriggers = requireTriggers || other.requireTriggers
)
}

Expand Down Expand Up @@ -234,6 +238,7 @@ case class BaseConfig(gobraDirectory: Path = ConfigDefaults.DefaultGobraDirector
noVerify: Boolean = ConfigDefaults.DefaultNoVerify,
noStreamErrors: Boolean = ConfigDefaults.DefaultNoStreamErrors,
parseAndTypeCheckMode: TaskManagerMode = ConfigDefaults.DefaultParseAndTypeCheckMode,
requireTriggers: Boolean = ConfigDefaults.DefaultRequireTriggers,
) {
def shouldParse: Boolean = true
def shouldTypeCheck: Boolean = !shouldParseOnly
Expand Down Expand Up @@ -290,6 +295,7 @@ trait RawConfig {
noVerify = baseConfig.noVerify,
noStreamErrors = baseConfig.noStreamErrors,
parseAndTypeCheckMode = baseConfig.parseAndTypeCheckMode,
requireTriggers = baseConfig.requireTriggers,
)
}

Expand Down Expand Up @@ -665,6 +671,13 @@ class ScallopGobraConfig(arguments: Seq[String], isInputOptional: Boolean = fals
noshort = true,
)

val requireTriggers: ScallopOption[Boolean] = opt[Boolean](
name = "requireTriggers",
descr = s"Enforces that all quantifiers have a user-provided trigger.",
default = Some(ConfigDefaults.DefaultRequireTriggers),
noshort = true,
)

val noVerify: ScallopOption[Boolean] = opt[Boolean](
name = "noVerify",
descr = s"Skip the verification step performed after encoding the Gobra program into Viper.",
Expand Down Expand Up @@ -849,5 +862,6 @@ class ScallopGobraConfig(arguments: Seq[String], isInputOptional: Boolean = fals
noVerify = noVerify(),
noStreamErrors = noStreamErrors(),
parseAndTypeCheckMode = parseAndTypeCheckMode(),
requireTriggers = requireTriggers(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,21 @@ trait GhostExprTyping extends BaseTyping { this: TypeInfoImpl =>
// check that `thn` and `els` have a common type
mergeableTypes.errors(exprType(thn), exprType(els))(expr)

case PForall(vars, triggers, body) =>
case n@PForall(vars, triggers, body) =>
// check whether all triggers are valid and consistent
validTriggers(vars, triggers) ++
// check that the quantifier `body` is either Boolean or an assertion
assignableToSpec(body)
assignableToSpec(body) ++
// check that the user provided triggers when running with --requireTriggers
error(n, "found a quantifier without triggers.", config.requireTriggers && triggers.isEmpty)

case PExists(vars, triggers, body) =>
case n@PExists(vars, triggers, body) =>
// check whether all triggers are valid and consistent
validTriggers(vars, triggers) ++
// check that the quantifier `body` is Boolean
assignableToSpec(body) ++ assignableTo.errors(exprType(body), BooleanT)(expr)
assignableToSpec(body) ++ assignableTo.errors(exprType(body), BooleanT)(expr) ++
// check that the user provided triggers when running with --requireTriggers
error(n, "found a quantifier without triggers.", config.requireTriggers && triggers.isEmpty)

case n: PImplication =>
isExpr(n.left).out ++ isExpr(n.right).out ++
Expand Down