Specifying Options¶
Stainless’s command line options have the form --option or --option=value.
To enable a flag option, use --option=true or on or yes,
or just --option. To disable a flag option, use --option=false.
Additionally, if you need to pass options to the scalac frontend of Stainless,
you can do it by using a single dash -. For example, try -Ybrowse:typer.
The rest of this section presents some of the command-line options that Stainless recognizes.
For a short (but always up-to-date) summary, you can also invoke stainless --help.
Choosing which Stainless feature to use¶
The first group of options determines which feature of Stainless will be used.
By default, --verification is chosen.
--verificationProves or disproves function contracts, as explained in the Verification conditions section.
--evalEvaluate parameterless functions and report their body’s value and whether or not their postcondition holds.
--gencConvert stainless code to C (implies –batched, default: false). See documentation section for generating C code.
--coqTransform the program into a Coq program, and let Coq generate subgoals automatically
--type-checkerUse type checker inspired by System FR to generate verification conditions. Default is
trueand is strongly recommended; usingfalsereverts to an old verification-condition generator.--infer-measures=[yes|no|only] (default: yes)Infers measures for recursive functions which do not already have one.
--check-measures=[true|false] (default: true)Check termination of functions with measures, ie. whether measures decrease between recursive calls.
--testgenProves or disproves function contracts (like
--verification) and attempts to create Scala test cases from reported counter-examples.--genc-testgenLike
--testgen, but generates C test cases using GenC.--helpPrints a helpful message, then exits.
Additional top-level options¶
These options are available to all Stainless components:
--watchRe-run the selected analysis components upon file changes, making the program analysis interactive and significantly more efficient than restarting stainless manually.
--no-colorsDisable colored output and non-ascii characters (consider this option for better support in IDEs)
--compactReduces the components’ summaries to only the invalid elements (e.g. invalid VC).
--debug=d1,d2,...Enables printing detailed messages for the components d1,d2,… . Available components include:
solver(SMT solvers and their wrappers)termination(Termination analysis)timers(Timers, timer pools)trees(Manipulation of trees)verification(Verification)full-vc(Display VCs before and after simplification)type-checker(Type checking of the final program for VC generation)type-checker-vcs(Generation of VCs by the type-checker)derivation(Dump typing derivations)
--functions=f1,f2,...Only consider functions f1, f2, … . This applies to all functionalities where Stainless manipulates the input in a per-function basis.
Stainless will match against suffixes of qualified names. For instance:
--functions=List.sizewill match the methodstainless.collection.List.size, while--functions=sizewill match all methods and functions namedsize. This option supports_as wildcard:--functions=List._will match allListmethods.--solvers=s1,s2,...Use solvers s1, s2,… . If more than one solver is chosen, all chosen solvers will be used in parallel, and the best result will be presented. By default, the
nativez3solver is picked.Some solvers are specialized in proving verification conditions and will have a hard time finding a counterexample in the case of an invalid verification condition, whereas some are specialized in finding counterexamples, and some provide a compromise between the two. Also, some solvers do not as of now support higher-order functions.
Available solvers include:
nativez3Native Z3 with z3-templates for unfolding recursive functions (default).
smt-cvc5cvc5 through SMT-LIB. An algorithm within Stainless takes up the unfolding of recursive functions, handling of lambdas etc. To use this or any of the following cvc5-based solvers, you need to have the
cvc5executable in your system path (the latest unstable version is recommended).smt-z3Z3 through SMT-LIB. To use this or the next solver, you need to have the
z3executable in your program path (the latest stable version is recommended). Inductive reasoning happens on the Stainless side (similarly tosmt-cvc5).unrollz3Native Z3, but inductive reasoning happens within Stainless (similarly to
smt-z3).princessPrincess solver through its native interface (uses princess-templates) during unfolding. This is a full-stack JVM solver and enables Stainless to run without external solver dependencies.
--timeout=tSet a timeout for each attempt to prove one verification condition/ repair one function (in sec.) When using the
--evalcomponent, one should use--max-callsinstead.--z3-rlimit=n,--cvc4-rlimit=nand--cvc5-rlimit=nSet a resource limit for the solvers that run on z3 (
nativez3, the default,smt-z3,unrollz3and their variants), resp. forsmt-cvc4andsmt-cvc5, as a deterministic alternative to--timeout: unlike a wall-clock timeout, the outcome does not depend on the machine or its load. The limitnis given in millions of solver resource units (--z3-rlimit=2passesrlimit=2000000to z3), and0(the default) means no limit. z3 accepts at most--z3-rlimit=4294; larger values are capped. A verification condition that exceeds the limit is reported asresource limit reached.The limit applies to each solver query separately, not to a whole verification condition: Stainless typically issues many queries per verification condition while unfolding recursive functions, and the condition is given up as soon as a single query exceeds the limit. How long a given limit takes therefore depends on the program, so it should be calibrated for the programs at hand.
Since only individual queries are bounded, a verification condition whose queries all stay below the limit may in principle run forever (in practice, queries usually grow with each unfolding until one exceeds the limit). To bound the total work, combine the resource limit with
--unroll-bound=n, which caps the number of unfolding steps and keeps the outcome deterministic; a verification condition that reaches the bound is reported asunroll bound reached. Alternatively, add--timeoutas a wall-clock safety net.To help choose a limit, the verification summary has a
resources (M)column, after the time. To check one verification condition, Stainless sends several queries to the solver while unfolding; the column shows the resources used by the most expensive of these queries, in millions of units (rounded up). This is the same unit as the limit, so the value shown can be given as the limit.Resources are only shown for the solvers that run on z3 (
nativez3,smt-z3,unrollz3and their variants) and forsmt-cvc5. Nothing else is counted: the cell is empty for the other solvers (eval,princess,smt-cvc4, …), for the conditions that need no solver (trivial, or found in the cache), and when no solver of a portfolio answered. With a portfolio, the value is that of the solver that answered.A condition that reached the limit shows that limit (cvc5 may show slightly more, as it does not stop at once). The JSON report (
--json) has the same value in units (resourceUsage), and the usage of each query (resources).--cacheUse persistent cache on disk to save the state of the verification and/or termination analyses.
--cache-dir=<directory>Specify in which directory the cache files generated by
--cacheand other options should be stored. Defaults to.stainless-cache/.--json=<file>Export the verification and/or termination analyses to the given file.
--classpath=<classpath>Add the given directories and JARs to the classpath of the program, separated by
:(;on Windows). Stainless reads the definitions that the program uses from the TASTy files of these dependencies, so a library written for Stainless can be used as a JAR, for instance one fetched withcs fetch.
Additional Options (by component)¶
The following options relate to specific components in Stainless.
Verification¶
--strict-aritmeticCheck arithmetic operations for unintended behaviour and overflows. Note that reasoning about fixed-width integers (signed or unsigned) is sound even if this option is false, but in that case no warnings are generated for overflows and underflows because these have well-defined semantics in Scala.
--vc-cacheUse a persistent cache mechanism to speed up verification; on by default. The cache, in the directory given by
--cache-dir(.stainless-cache/by default), has two files:vccachehash.binholds the VCs proven valid, which later runs report as “valid from cache”;vccachehash-unknown.binholds the VCs on which the solvers timed out or reached their resource limit, which later runs report as, for instance, “timeout (from cache)” without sending them to the solvers again. When iterating on a proof, these slow VCs then fail fast if they didn’t change. Other inconclusive results (unknown, unroll bound reached) are not cached, as they are usually fast. Such a VC is checked again when it changes, and when the options that decide how hard the solvers try change:--solvers,--timeout,--z3-rlimit,--cvc5-rlimit,--unroll-bound,--unroll-factor,--feeling-lucky,--check-modelsand--function-equality.
Invalid VCs are never cached. With
--binary-cache, the files arevccachebin.binandvccachebin-unknown.bin.--recheck-unknown-vcsEmpty the cache of the VCs that timed out or reached the resource limit (see
--vc-cache) before verifying, so that all of them are sent to the solvers again. The VCs that time out again are cached again. With--watch, the cache is emptied once, at the start.--fail-earlyAborts verification as soon as a VC cannot be proven to be correct.
--fail-invalidAborts verification as soon as an invalid VC is found.
--sat-precond=[none|all|annotated] (default: none)Check that the preconditions of functions are satisfiable, so that their postconditions don’t hold only vacuously: Stainless generates an additional verification condition, of kind “precondition satisfiability”, which is invalid when the precondition is unsatisfiable. With
all, it checks the preconditions of all functions; withannotated, only those of the functions annotated with@checkSatPrecondition.--sat-precondalone means--sat-precond=all. A witness given withrequireWitnessreplaces this check, see Verification conditions.
Termination¶
--ignore-postsIgnore postconditions during termination verification.
Unrolling Solver¶
--check-modelsDouble-check counterexamples with the evaluator.
--feeling-luckyUse evaluator to find counterexamples early.
--unroll-assumptionsUse unsat-assumptions to drive unrolling while remaining fair.
--silent-errorsDon’t crash on errors, simply return
Unknown.--unroll-factor=nSpeeds up unrolling by a factor
n.--model-finding=nBoosts model-finding capabilities by a factor
n. This may come at the cost of proof construction.--no-simplificationsDisables program simplification heuristics.
cvc5 Solver¶
--solver:cvc5=<cvc5-opt>Pass extra command-line arguments to cvc5.
Evaluators¶
--codegenUse compiled evaluator instead of an interpreter.
--small-arraysAssume all arrays can fit into memory during compiled evaluation.
--instrumentInstrument ADT field access during code generation.
--max-calls=nBounds the total number of function call evaluations (before crashing).
--ignore-contractsIgnores function contracts during evaluation.
Tests generation¶
testgen-file=<file>Specifies the output file for the generated tests.
genc-testgen-includes=header1.h,header2,...Only applies for
--genc-testgen. Indicates the headers to#includein the generated test file.
Configuration File¶
Stainless supports setting default values for command line options configuration files.
To specify configuration file you can use the option `--config-file=FILE. The default is
stainless.conf or .stainless.conf. The file should be a valid HOCON file.
For example, consider the config file containin the following lines:
vc-cache = false
debug = [verification, trees]
timeout = 5
check-models = true
print-ids = true
The file will translate to the following command line options:
--vc-cache=false --debug=verification,trees --timeout=5 --print-ids
Stainless searches for a configuration file recursively
starting from the current directory and walking up the
directory hierarchy. For example, if one runs stainless
from /a/b/c and there is a config file in any of c,
b or a, the first of those is going to be loaded.
Library Files¶
Purpose of library files¶
Stainless contains library source Scala files that define types and functions that are meant to be always available
via import statements such as import stainless.lang._, import stainless.annotation._,
import stainless.collection._, and so on. Many of these types have special treatment inside the extraction
pipeline and will map directly to mathematical data types of the underlying SMT solvers.
At build time, the build.sbt script computes the list of these files by traversing the frontends/library/ directory.
Changing the list of library files¶
To support further customization, if at run time stainless finds
a file libfiles.txt in the current directory, it replaces the list of library files files with the list contained
in this file, one file per line, with paths relative to the directory frontends/library/. For example, libfiles.txt
may contain:
stainless/util/Random.scala
stainless/lang/Option.scala
stainless/lang/StaticChecks.scala
stainless/lang/Real.scala
stainless/lang/Either.scala
stainless/lang/Set.scala
stainless/lang/MutableMap.scala
stainless/lang/package.scala
stainless/lang/Bag.scala
stainless/lang/Map.scala
stainless/collection/List.scala
stainless/math/Nat.scala
stainless/math/Unsigned.scala
stainless/math/package.scala
stainless/io/StdIn.scala
stainless/io/package.scala
stainless/annotation/annotations.scala
stainless/annotation/isabelle.scala
stainless/annotation/cCode.scala
stainless/proof/Internal.scala
stainless/proof/package.scala
Shortening this list may reduce the startup time, but also cause Stainless to not work propertly, so
using the --watch and --functions options is the first option to try.
For further customization by advanced users, please examine the build.sbt file.