This is a pre-release of Dafny 3.0.0. It is stable, but does not yet have all the features slated for version 3.0. It has a long list of improvements over Dafny 2.3.0, though some of those improvements are not backward compatible with 2.3.0 (see "Breaking change" remarks below).
Here are the major changes since Dafny 2.3.0:
Language
-
Allow
datatype,codatatype, andnewtypetypes to declare members (just like aclassand atraitcan declare members). -
Introduce
:-statements and expressions.
This new assignment operator extracts a successful value from the right-hand side (RHS) of the assignment, or propagates a failure if the evaluation of the RHS reports a failure. Some examples are inTest/exceptions/Exceptions1.dfyandTest/exceptions/Exceptions1Expressions.dfy. -
Introduce
expectstatements.
The statementexpect E, V;checks boolean expressionEat run time and halts execution if it evaluates tofalse. The optional argumentVis used in the error message produced. The verifier treats the statement asassume E;. -
Introduce
:- expect(a.k.a. assign-or-halt) statements.
This variation of the:-halts execution if the RHS reports a failure. Some examples are inTest/expectations/ExpectAndExceptions.dfy. -
Traits and classes that extend traits can now have type parameters.
All occurrences of a trait among the ancestor traits of a class (or trait) must have the same type-parameter instantiations. -
Traits can now extend other traits.
-
Order the
cases ofmatchstatements/expressions.
This allows overlaps betweencases, where an earliercasegets selected first. Acasecan now also be just a variable (or_), which in effect is an "else". (Note, this is a backward compatible change, since no overlaps among cases were allowed before.) A warning is generated if onecaseis already covered by the precedingcases. -
Patterns in
matchcases can now use simple literal expressions, such as2,3.14, andfalse. -
Add full verification support for body-less loops.
The loop targets of such a loop are the free mutable variables (including the heap) that occur in the guard,invariant, ordecreasesclause. If the loop has amodifiesclause--whatever themodifiesclause says--then the heap is counted as a loop target. -
Breaking change: In an
exportdeclarations, members of types are exported separately from exporting the type.- to export a member, the enclosing type must be provided or revealed
- class constructors and mutable fields can be exported only if the enclosing
class/traitis revealed - mutable fields can no longer be revealed, only provided
- datatype constructors, discriminators, and destructors are exported when the datatype is revealed, and can never be explicitly named in exports
- for an extreme predicate/lemma, the corresponding prefix predicate/lemma is exported, too
-
Breaking change: New rules for exporting classes.
To reveal a class or trait
Cwill export:- the fact that this is a reference type
- both types
CandC?, and the connection between these two - the anonymous constructor, if
Cis a class and has one
To provide a class or trait C will export:
- the name
C, as an opaque type - not type
C? - no constructor or mutable field, and it's an error to explicitly name these in exports
One breaking-change consequence of these rules is that constructor-less
newis no longer supported for imported classes. -
The syntactic form
import A.B.Cis now allowed, and it stands forimport C = A.B.C. -
import A.B.C`Xis now allowed. -
Introduce sequence construction expressions.
Some examples are inTest/dafny0/Comprehensions.dfy. -
constfields are not allowed in back-tick notation in frames -
Allow
import opened Awhere moduleAis in the same scope. -
Breaking change: Remove support for some deprecated syntax, and removed the keywords
array1andarray1?. -
Breaking change: Make
{:a token instead of two separate tokens. -
Breaking change: Disallow
modifystatements inforallstatements. -
Breaking change: Don't support map disjointness, that is,
a !! bis no longer supported whenaandbare maps.
Verifier
-
Improve representation of heap (as a map of map, rather than as 2-dimensional map).
-
Fix refinement checks for two-state predicates.
-
Don't re-verify code that comes from DLLs.
Compiler
-
Add compiler to Java (fully featured, except
iteratoris not supported). -
Add initial version of a compiler to C++.
-
Add support for
{:test}attribute (C# only for now), mapping it to[Xunit.Fact]. This allows xUnit-like unit testing from Dafny. -
Compile
forallstatement into simple loop when possible. -
Compile tail-recursive functions (not just tail-recursive methods) with tail calls. For functions, the compiler has an auto-accumulator feature that automatically detects cases when an added accumulator variable allows the function to be transformed into being tail-recursive. In such detected cases, the compiler introduces the accumulator variable automatically.
-
Enlarged support of
{:extern}declarations -
Allow the compilation of collection types that take traits as type parameters.
-
Compile methods with exactly one out-parameter to the usual result-type methods
-
Compile map comprehensions with multiple bound variables.
-
Support
{:nativeType XX}whereXXis a list of native types. They are considered in order and the first one supported by the compiler is picked. An error is generated if the type cannot be determined to fit in that native type. (See the/attrHelpmessage for details.) Also,numberis no longer supported outside JavaScript. -
The .NET immutable collections that used to be used with the
/optimizeflag are now always used. TheSystem.Collections.Immutable.dlllibrary is no longer part of the Dafny distribution, since it is part of .NET. Also,/optimizeflag is now permanently on, which causes/optimizeflag to be passed down to the C# compiler. -
Introduce branch-coverage profiling. See new
/coverageflag. -
Improved formatting of target code
-
Breaking change: A number of features are now represented different at run time. This may break any previous external code that depended on the old representations.
Documentation
-
Updates to the Dafny Language Reference Manual.
-
For Dafny contributors, added documentation of compilation of trait/class to C#/Java/JavaScript/Go.
IDE
- End support of the
DafnyExtension, which was the original Dafny IDE that plugged into Microsoft Visual Studio. (VS Code and Emacs plug-ins are still supported.)
Miscellaneous
- Various bug fixes throughout