Due to its nature, this documentation section may not always be up to date; we welcome pull requests with carefully written and tested improvements to the information below.
Requirements:
- Java SE Development Kit 8 or Java SE Development Kit 7 for your platform
Instructions:
- Download the latest Stainless JAR from the Releases page on GitHub
- Paste the following code in a file named
test.scala:
import stainless.lang._
object test {
def ok = {
assert(true)
}
}- In a terminal, type the following command, substituting the proper path to the Stainless JAR previously downloaded:
$ java -jar /path/to/stainless/jar/file.jar test.scala- The output should read:
[Warning ] The Z3 native interface is not available. Falling back onto princess.
[ Info ] - Checking cache: 'body assertion' VC for ok @5:5...
[ Info ] Cache miss: 'body assertion' VC for ok @5:5...
[ Info ] - Now solving 'body assertion' VC for ok @5:5...
[ Info ] - Result for 'body assertion' VC for ok @5:5:
[ Info ] => VALID
[ Info ] ┌───────────────────┐
[ Info ] ╔═╡ stainless summary ╞══════════════════════════════════════════════════════════════════════╗
[ Info ] ║ └───────────────────┘ ║
[ Info ] ║ ok body assertion valid U:princess test.scala:5:5 0.931 ║
[ Info ] ╟┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄╢
[ Info ] ║ total: 1 valid: 1 (0 from cache) invalid: 0 unknown: 0 time: 0.931 ║
[ Info ] ╚════════════════════════════════════════════════════════════════════════════════════════════╝
[ Info ] Shutting down executor service.
If no external SMT solvers (such as Z3 or CVC4) are found, Stainless will instead use the bundled Scala-based Princess solver, which can sometime be quite slow.
To improve performance, one can install an external SMT solver, as described in section ":ref:`smt-solvers`".
Requirements:
- Java SE Development Kit 8 or Java SE Development Kit 7 for your platform
- sbt 0.13.x (Available from http://www.scala-sbt.org/)
- An external SMT solver (see Section ":ref:`smt-solvers`")
- Sphinx restructured text tool (for building local documentation)
Instructions:
Get the sources of Stainless by cloning the official Stainless repository:
$ git clone https://github.com/epfl-lara/stainless.git
Cloning into 'stainless'...
// ...
$ cd stainless
$ sbt clean universal:stage
// takes about 1 minuteThe compilation will automatically generate the following two bash scripts:
frontends/scalac/target/universal/stage/bin/stainless-scalacthat will use thescalaccompiler as frontend,frontends/stainless-dotty/target/universal/stage/bin/stainless-dottythat uses thedotccompiler as frontend (experimental).
You may want to introduce a soft-link from frontends/scalac/target/universal/stage/bin/stainless-scalac to stainless:
$ ln -s frontends/scalac/target/universal/stage/bin/stainless-scalac stainlessThese scripts work for all platforms and allow additional control over the execution, such as passing JVM arguments or system properties:
$ frontends/scalac/target/universal/stage/bin/stainless-scalac -Dscalaz3.debug.load=true -J-Xmx6G --helpNote that Stainless is organized as a structure of several
projects. The main project lives in core while the two available
frontends can be found in frontends/scalac and frontends/dotty.
From a user point of view, this should most of
the time be transparent and the build command should take
care of everything.
Get the sources of Stainless by cloning the official Stainless repository. You will need a Git shell for windows, e.g. Git for Windows.
$ git clone https://github.com/epfl-lara/stainless.git
Cloning into 'stainless'...
// ...
$ cd stainless
$ sbt clean universal:stage
// takes about 1 minutesCompilation will automatically generate the following two bash scripts:
frontends/scalac/target/universal/stage/bin/stainless-scalac.batthat will use thescalaccompiler as frontend,frontends/stainless-dotty/target/universal/stage/bin/stainless-dotty.batthat uses thedotccompiler as frontend (experimental).
Setting up an sbt build file to use Stainless is a simple 4-step procedure:
- Start by installing an external solver (see Section ":ref:`smt-solvers`").
- Add the
sbt-stainlessplugin together with the required resolver to yourproject/plugins.sbt
resolvers += Resolver.url(
"LARA sbt plugins releases",
url("https://dl.bintray.com/epfl-lara/sbt-plugins/")
)(Resolver.ivyStylePatterns)
addSbtPlugin("ch.epfl.lara" % "sbt-stainless" % "<insert-version>")Check the sbt-stainless bintray repository for the available versions.
- In your project's build file, enable the
StainlessPluginon the modules that should be verified by stainless. Below is an example:
// build.sbt
lazy val algorithm = (project in file("algorithm"))
.enablePlugins(StainlessPlugin) // <-- Enabling stainless verification on this module!
.settings(...)Note that if you are using .scala build files you need to use the fully qualified name ch.epfl.lara.sbt.stainless.StainlessPlugin. Also, because stainless accepts a subset of the Scala language, you may need to refactor your build a bit and code to successfully use stainless on a module.
- After modifying the build, type
reloadif inside the sbt interactive shell. From now on, when executingcompileon a module where theStainlessPluginis enabled, stainless will check your Scala code and report errors in the shell (just like any other error that would be reported during compilation).
That's all there is to it. However, the sbt-stainless plugin currently has the following limitations you should know about:
- No incremental compilation support. All sources (included the stainless-library sources) are recompiled at every
compileexecution. - The plugin only supports vanilla Scala. To track sbt support in dotty you can follow issue #178.
Also, note that the plugin offers a stainlessIsEnabled setting that can help experimenting with stainless. The stainlessIsEnabled setting is set to true by default, but you can flip the flag to false by typing set every stainlessIsEnabled := false while inside the sbt interactive shell.
Inox, the solving backend for Stainless, relies on SMT solvers for reasoning about quantifier-free formulas.
Inox ships with the JVM SMT solver Princess which should work out of the box on any system, but is quite slow.
It is recommended that you use one of the following external SMT solvers:
- CVC4 1.6, http://cvc4.cs.stanford.edu
- Z3 4.7.1, https://github.com/Z3Prover/z3
Solver binaries that you install should match your operating system and your architecture.
We recommend that you install these solvers as a binary and have their binaries available in the $PATH (as z3 or cvc4).
- Download Z3 4.7.1 from https://github.com/Z3Prover/z3/releases/tag/z3-4.7.1
- Unzip the downloaded archive
- Copy the
z3binary found in thebin/directory of the inflated archive to a directory in your$PATH, eg.,/usr/local/bin. - Make sure
z3can be found, by opening a new terminal window and typing:
$ z3 --version- The output should read:
Z3 version 4.7.1 - 64 bit`
- Download CVC4 1.6 from http://cvc4.cs.stanford.edu/downloads/builds/x86_64-linux-opt/
- Copy the downloaded binary as
cvc4to a directory in your$PATH, eg.,/usr/local/bin.
- Make sure
cvc4can be found, by opening a new terminal window and typing:
$ cvc4 --version- The output should begin with:
This is CVC4 version 1.6
- Install Homebrew
- Install CVC4 using the Homebrew tap at https://github.com/CVC4/homebrew-cvc4
- Make sure
cvc4can be found, by opening a new terminal window and typing:
$ cvc4 --version- The output should begin with:
This is CVC4 version 1.6
Stainless comes with a test suite. Use the following commands to invoke different test suites:
$ sbt test
$ sbt it:testIt's also possible to run tests in isolation, for example, the following command runs Extraction tests on all files in termination/looping:
$ sbt 'it:testOnly *ExtractionSuite* -- -z "in termination/looping"'To build this documentation locally, you will need Sphinx ( http://sphinx-doc.org/ ), a restructured text toolkit that was originally developed to support Python documentation.
After installing sphinx, run sbt previewSite. This will generate the documentation and open a browser.
The documentation resides in the core/src/sphinx/ directory and can also be built without sbt
using the provided Makefile. To do this, in a Linux shell go to the directory core/src/sphinx/,
type make html, and open in your web browser the generated top-level local HTML file, by default stored in
src/sphinx/_build/html/index.html. Also, you can open the *.rst documentation files in a text editor, since
they are human readable in their source form.
Untested!
You first need to tell sbt to globally include the Eclipse plugin in its known plugins. To do so type
$ echo "addSbtPlugin(\"com.typesafe.sbteclipse\" % \"sbteclipse-plugin\" % \"2.4.0\")" >> ~/.sbt/0.13/plugins/plugins.sbtIn your Stainless home folder, type: `sbt clean compile eclipse`
This should create all the necessary metadata to load Stainless as a project in Eclipse.
You should now be able to import the project into your Eclipse workspace. Don't forget to also import dependencies (the dotty and cafebabe projects, found somewhere in your ~/.sbt directory).
For each run configuration in Eclipse, you have to set the
ECLIPSE_HOME environment variable to point to the home
directory of your Eclipse installation. To do so, go to
Run -> Run Configuration
and then, after picking the configuration you want to run, set the variable in the Environment tab.
If you want to use ScalaTest from within Eclipse, download the ScalaTest plugin. For instructions, see Using ScalaTest with Eclipse. Do NOT declare your test packages as nested packages in separate lines, because ScalaTest will not see them for some reason. E.g. don't write
package stainless
package test
package myTestPackagebut instead
package stainless.test.myTestPackage