r/ProgrammingLanguages • u/g1rlchild • Jul 24 '26
Discussion Languages with optional SMT Solver to allow for additional reliability?
So I've been tinkering with.the idea of a language that uses type checking and then an exhaustiveness checker as standard to ensure that all cases will get handled. And then on top of that, an optional system of invariants that are handled statically with a solver to allow for additional protections for programs that need it.
I'm nor familiar with any prior languages that have done this, but I don't have a very large base of knowledge for things like this yet. Has anyone worked with.something like this? Are there existing languages I should be looking at? I'd love to hear more about this kind of thing from folks with experience in this area.
17
u/aslakg Jul 24 '26
You should definitely look at Dafny
7
u/romac Jul 24 '26
For Scala there is Stainless: https://epfl-lara.github.io/stainless/intro.html
> Stainless can
> - verify statically that your program conforms to a given specification and that it cannot crash at run-time
> - provide useful counterexamples when an implementation does not satisfy its specification
> -verify that your program will terminate on all inputs
6
u/Karyo_Ten Jul 24 '26
https://nim-lang.org/docs/drnim.html
5
u/Royal_Pin_1971 Jul 24 '26
In the language I'm building (PFCL) the baseline layer is close to what you describe and needs no solver: pure functions only, static type checking, exhaustive case analysis and guaranteed termination. For the solver tier I've sketched a different placement than Dafny, SPARK or Liquid Haskell.
Solver would be a refutation CI gate outside the language rather than inside the type checker. Its queries would come from things the author writes anyway (dispatch guards, type signatures, declared invariants). It rejects only on proven contradiction always with a concrete counterexample. On timeout it degrades to a runtime check instead of blocking with the degradation recorded as a distinct assurance level. The author never writes toward the solver and never debugs it — more an admission gate than a proof system.
4
u/wk_end Jul 24 '26
F* does this through refinement types.
3
u/matthieum Jul 24 '26
I think one cool idea about pre-conditions, post-conditions, and invariants, is to be flexible.
That is, allow them to be either verified at compile-time, or at run-time.
And better yet, allow optimizing on the fact that they are verified, which can be done "relatively" trivially by following the scheme below:
The reason for the asymmetric placement, is to allow for better optimization due to visibility:
i < jbecausej = i + 1, making optimization of the pre-conditions easier.x * 2, ergo it's necessarily even, making optimization of the post-conditions easier.The remaining question is whether the compiler should automatically attempt to verify at compile-time, or not. Right now, I still think verification is too expensive to be attempted nilly-willy, so I'm leaning towards run-time verification by default, with opt-in compile-time verification via an annotation.
3
u/GunpowderGuy Jul 24 '26
Many languages with refinement types use SMT to automatically search for proof that the refinements hold, examples include:
Liquid haskell
Dafny
F*
I think languages with dependent types ( similar but not the same as refinement types ) can also use SMT to search proof that conditions in the refinement types, hold
2
u/echoes808 Jul 25 '26
I've seen couple language extensions, which use comments and feed it to the solver, check out:
OpenJML https://www.openjml.org/examples/merge-sort.html
Ocamleer (gospel is the syntax): https://ocaml-gospel.github.io/gospel/getting-started/first-spec
2
u/kohuept Jul 24 '26
SPARK? You can choose to apply SPARK_Mode to whichever Ada units you want to verify
28
u/[deleted] Jul 24 '26 edited Oct 05 '26
[removed] — view removed comment