As for being not expressive enough for specifications, isn't the code itself a form of specification? :)
Good question. This is the holy grail. This is what everyone in PL research would love. This is where we want to get to.
Turns out a language as “simple” as C has sufficiently complicated semantics as to limit rigorous analysis to the basics. One example is loop analysis: it’s very useful to know that a loop will terminate eventually; if a loop is modifying some state and—worse—if the iteration variable gets modified—kiss your analysis goodbye because mechanically synthesizing strong pre- and post-conditions becomes insurmountable. It’s not an engineering challenge. It’s a math/pure CS theory challenge.
I assume if you were to develop such a system for C, C++, or Rust you'd similarly expect the user to do this.
(Any experts on formal verification please correct any inaccuracies in what I say here.)
The upshot of it is that C, C++, and Rust permit too much behavior that isn’t capturable in the type system. Thus, the properties that you’re interested in are semantic (as opposed to syntactic; type systems turn semantic properties into syntactic ones) so Rice’s theorem applies and there’s no computable way to do the analysis right.
Yes, dependent types can encode nice constraints, but so can asserts and assumes.
I am not seeing the fundamental difference in yeeting these constraints to a solver. Dafny seems to do the same thing with Z3.
I'd have assumed, by virtue of being Turing complete, you could express any invariant in almost any language?
For example a NonNegativeInteger type in most languages would just have a constructor that raises an exception if provided with a negative number. But in languages with proofs, the compiler can prevent you from constructing values of this type at all unless you have a corresponding proof that the value can't be negative (for example, the value is a result of squaring a real number).
I use C and C++ model checkers, like cbmc and its variants (esbmc) successfully, but you need to adjust your tests and loops a bit. Like #ifdef __VERIFIER__ or #ifdef __CPROVER__ https://diffblue.github.io/cbmc/cprover-manual/index.html
Dafny can compile to and interface with a few languages, including C#.
Are there benchmarks showing dafny is faster than other inefficient options ?
I'm not sure about benchmarks comparing languages, but Dafny goes through a lot of tweaking to make the process faster.