Highlights
Stainless is on Maven Central
The Stainless library and the compiler plugin are now published on Maven Central, under ch.epfl.lara (#1977). A Scala CLI or sbt project can use Stainless without installing it. The plugin verifies the program each time it is compiled, and the compiler then produces the class files, so the same build verifies and runs the program. The plugin includes the native Z3 interface, so no solver has to be installed on Linux x64 and ARM64, macOS ARM64 and Windows x64.
With Scala CLI 1.18.0 or later, the configuration is four directives, here at the top of the program:
//> using scalaOrganization ch.epfl.lara
//> using scala 3.10.1-RC1-bin-20260903-e1f9361-NIGHTLY
//> using dep ch.epfl.lara::stainless-library:0.11.0
//> using plugin ch.epfl.lara:::stainless-dotty-plugin:0.11.0
import stainless.annotation.*
import stainless.collection.*
import stainless.lang.*
object Example:
def sum(xs: List[BigInt]): BigInt = {
require(xs.forall(_ >= 0))
xs match
case Nil() => BigInt(0)
case Cons(h, t) => h + sum(t)
}.ensuring(_ >= 0)
@extern
def main(args: Array[String]): Unit =
println(sum(List[BigInt](1, 2, 3)))scala --power run Example.scala prints the verification summary, with the 7 conditions of sum valid, then 6. --power is needed for the scalaOrganization directive.
With sbt, the same configuration goes in build.sbt. sbt compile then verifies the program, and sbt run runs it:
scalaOrganization := "ch.epfl.lara"
scalaVersion := "3.10.1-RC1-bin-20260903-e1f9361-NIGHTLY"
libraryDependencies += "ch.epfl.lara" %% "stainless-library" % "0.11.0"
addCompilerPlugin(("ch.epfl.lara" % "stainless-dotty-plugin" % "0.11.0").cross(CrossVersion.full))- Both need Java 21 or later, and this exact Scala version: it is the compiler that Stainless is built with, published under
ch.epfl.lara. - Verification conditions that do not hold are reported as warnings. They do not fail the compilation, so check the summary before trusting a run.
- Ghost code is removed from the compiled program.
-P:stainless:verify:falseturns verification off, and-P:stainless:ghost-elim:falsekeeps the ghost code. - The release archives, their
stainlesscommand andsbt-stainlessare still available. Theexamplesdirectory has a project for each tool, and the documentation has the details.
??? no longer verifies (breaking)
??? throws at run time, but Stainless treated it as an unknown value that satisfies its specification (#1970). v0.10.5 verified this function:
import stainless.lang.*
object Todo:
def largerThan(x: BigInt): BigInt = {
??? : BigInt
}.ensuring(_ > x)??? is now an assert(false): v0.11.0 reports Missing implementation (???) is unreachable as invalid. @extern code is exempt. An abstract method that has a contract takes AbstractMethodBody as its body, where ??? was used before:
import stainless.lang.*
object Shapes:
abstract class Shape:
def area: BigInt = {
AbstractMethodBody[BigInt]()
}.ensuring(_ >= 0)
case class Square(side: BigInt) extends Shape:
require(side >= 0)
override def area: BigInt = side * sideLibrary lemmas return Unit, and holds is deprecated (breaking)
The lemmas of the library that were Boolean functions ending in .holds now return Unit and state their property in ensuring (#1973). A caller gets the property from the contract, without unfolding the proof. This concerns ListSpecs in stainless.collection and stainless.covcollection, and stainless.proof.BoundedQuantifiers. A proof that used such a lemma as a Boolean, as in because(ListSpecs.snocLast(l, x)), no longer compiles. It calls the lemma as a statement instead:
import stainless.collection.*
import stainless.lang.*
object Lemmas:
def lastOfSnoc(l: List[BigInt], x: BigInt): Unit = {
ListSpecs.snocLast(l, x)
}.ensuring(_ => (l :+ x).last == x)holds still works in user code, with a deprecation warning.
What's Changed
Maven Central
- Publish the Stainless library and the compiler plugin to Maven Central by @samuelchassot in #1977
Language and library
- Treat
???asassert(false)and addAbstractMethodBody()for abstract methods with contracts (also verifies the bodies of methods called throughsuperand the field initialisers of abstract classes and traits, which were skipped) by @samuelchassot in #1970 - Rewrite the library's
.holdslemmas asUnitlemmas withensuringand deprecateholdsby @samuelchassot in #1973 - Make the fields of @extern classes extern (an
@externclass can now wrap a Java object) by @samarion in #1969 - Extract super calls into a trait from a class with no other parent (fixes
Stainless does not support type Object & A) by @samarion in #1971
Performance
- Compute dependencies and class descendants once per symbol table (16 to 2 minutes on a program with 200 classes) by @samarion in #1962
- Call methods through their root declaration, and flatten dispatches (a call unfolds once to its implementations, not once per level of the hierarchy) by @samarion in #1961
- Don't refine the class fields of Object by their type tests (the type tests of a class hierarchy are no longer unrolled in conditions about the others) by @samarion in #1974
Reporting
- Keep the position of assert(false) by @samarion in #1972
- Warn only for the library functions that are requested for checking (no more
Forcing processing of ...warning for programs that override library methods) by @samarion in #1964
Inox
- Bump inox (50 Inox commits since v0.10.5) by @samuelchassot in #1982
Build and tests
- Support linked Git worktrees with newer sbt-git and JGit by @regb in #1979
- Keep invalid/Exceptions1 in reach of cvc5 and Princess by @samarion in #1975
- Skip ListMonoidLaws with Princess by @samarion in #1976
New Contributors
Full Changelog: v0.10.5...v0.11.0