This is an interesting idea. At its core, IRs tend to be smaller and have better defined semantics. Of course, you'd have to use something other than the IR itself as the metalanguage (not a problem, though). Perhaps the reason this hasn't been attempted as often (I read the sibling Sel4 discussion about refinements) is twofold:
1. The mechanical effort required to show that the IR satisfies some abstract specification. Sel4 requires several refinement proofs (I am trusting the sibling comment on this), which suggests a great deal of effort. Perhaps LLMs (taken as "smart heuristics for proof code generation") can be of use here.
2. IR serves a secondary purpose as a target for compiler transformations. I've written myself about formally verifying compiler analyses[1] and I've proven a rudimentary LICM optimization in Lean based on these analyses (I haven't had a chance to write that one up), but it took a great deal of effort. We may then be forced either not to optimize or to trust something like LLVM (but...here be dragons? :P ).
So there is a tension between "simple core language" and "mutable substrate for optimization". And that doesn't even bring into question MLIR dialects and progressive lowering!
true. I should have been more careful. it does depend on the nature of the IR, modern languages have many layers of IRs. For example, I have made some progress interpreting Zig's "AIR" which is in the sweet spot where it doesn't yet launch into an LLVM-level "mutable substrate for optimization". Now, what I have is currently entirely heuristic, but I'm considering patching a theorem prover in to it.
I agree with you in part, as I have lightly alluded to in my article. There's a lot to love! Lean's typeclasses + inference, metaprogramming, custom notation, "X implemented as Y" support, and much more are fantastic.
It's not clear to me, however, that the space is completely filled. I find it hard to imagine using Lean for software that deeply interacts with the OS or hardware, or even just "doesn't refcount". Am I unaware of progress in this area? In a similar vein, in terms of practical software success, I think we've seen the most with model checking, yet Lean is not particularly amenable to this. It remains to be seen whether tactics and proofs (+ some sort of repair) will beat out the incumbent.
Great article BTW, I think it was incredibly detailed and well written
> I find it hard to imagine using Lean for software that deeply interacts with the OS or hardware, or even just "doesn't refcount".
This is true: my thought is that the path to using Lean for "practical software" looks like delegating a lot of stuff like I/O to Rust libs. Lean will soon be able to compile to LLVM IR instead of just C and IMO it makes more sense to think about how to fill the gaps with the smartest cross-lang approaches rather than to rebuild a lot of basic stuff as pure Lean
> my thought is that the path to using Lean for "practical software" looks like delegating a lot of stuff like I/O to Rust libs. Lean will soon be able to compile to LLVM IR instead of just C and IMO it makes more sense to think about how to fill the gaps with the smartest cross-lang approaches rather than to rebuild a lot of basic stuff as pure Lean
I think this is the sort of approach we should pursue to make progress towards verification as an industry. But every time I write low-level code, and have to think through complicated cases, I feel that it is there that I need the most help. That's when I dream of a tool that can meet me at my level of abstraction and help me lean on rigor and verification. This is part of why mainstream verifiable languages have been on my mind personally, and I admit this implicit bias may affect the focus of the article and original claims.
Apologies if you've already heard of it, but have you ever looked into the metamath0 project, specifically metamath C[1]? It's not super active, but the design tries to allow for low-level programming (goto, structs, etc) while still allowing for the full MM0 proof environment to prove program properties.
I really liked your article, and I haven't read or absorbed all of it yet but I agreed with your points on this topic.
I think Lean could perhaps serve in most server application use cases (and many others - roughly any use case where you could use Haskell), and Aeneas or something like it could leverage Lean only for verification. https://lean-lang.org/use-cases/aeneas/
Absolutely. Libraries like servant in Haskell, too, relied on extensions to the language (was it data kinds and GADTs?) to make for some very, very sleek abstractions. Lean comes with these language features, but in a single unified type system, and it has even more goodies!
What was surprising to me is that (at least some) Lean code is easier to understand than the machinery behind Servant, since you are just using normal code to operate on types.
This to me is the single most mindblowing part of Lean that has not been fully taken advantage of yet: that types themselves are first class and fully programmable in a way indistinct from normal code
And it compounds with Lean's dependent type system and the ability for proofs to be "bundled" into said dependent types and then erase at elab time
I think one aspect that real software cares a lot more but hard to formally verify is performance. Basic big-O is in the realm of mathematics and doable, but important details like cache locality, SoA versus AoS, compiler-guaranteed tailcalls and compiler-guaranteed strength reduction are all aspects that need to be tackled before we can formally verify software.
It definitely isn't bad choice, it reads a lot like Haskell. I've been exploring this myself too, haven't tried performance, but there are some Postgres / HTTP libraries for it.
Its macro capabilities make it very nice for SQL driven apps. I've been working one small invocing schema, and you can derive the Insert, Patch etc types with just macros with `deriving Patch` at the end of your type.
Also, one of my reasoning is that if these AI LLMs are tuned to work with millions of lines of Lean, it probably is very efficient for it.
I was aware of SPARK but not particularly familiar, and dropped it from my enumeration of relevant technologies unintentionally (though, the purpose of the post was not specifically to enumerate relevant tech). I really should read up on SPARK!
Say more! I'm familiar with expression graphs, and I know languages that are built on this, but it's not clear to me how this applies to formal proofs. Do you have more details?
Any single proof can first be thought of as proving an assertion about the graph. "There exists a path from A to C that traverses g." From there, the proof is bog standard graph maths.
In the abstract, all expressions of logic are graphs, like...statements of graph state, mutation, comparison, relation, differentiation, etc. An expression of language can be an incomplete expression of a graph, and other expressions can fill in the missing pieces or assert things about it. The language can express both the computation and the logic we use to reason about that computation.
In a sense, proof languages typically operate this way. They build a graph, assert something about it, and prove it in the mathy-graphy-sense. Mainstream programming languages have not yet put the graph structures front-and-center in the language design, and in the gap between the two we feel friction.
Nice, I'm also doing this to a degree with the language I've been building over the last year, proving as many facts as I can about the structure of the code, but my goal is to empower the compiler while allowing for terse, ergonomic code. Formal verification is in the back of my mind, but it isn't a language goal at this time. Instead, I'm focusing on more narrow validation, adopting Rust's "if it compiles it probably runs" ethos.
Yup, and this is my age range.
I guess I should have specified, knowing the average age on HN is... just a little higher to say the least.
But to a progressively lower extent it applies to older generations as well.
1. The mechanical effort required to show that the IR satisfies some abstract specification. Sel4 requires several refinement proofs (I am trusting the sibling comment on this), which suggests a great deal of effort. Perhaps LLMs (taken as "smart heuristics for proof code generation") can be of use here.
2. IR serves a secondary purpose as a target for compiler transformations. I've written myself about formally verifying compiler analyses[1] and I've proven a rudimentary LICM optimization in Lean based on these analyses (I haven't had a chance to write that one up), but it took a great deal of effort. We may then be forced either not to optimize or to trust something like LLVM (but...here be dragons? :P ).
So there is a tension between "simple core language" and "mutable substrate for optimization". And that doesn't even bring into question MLIR dialects and progressive lowering!
[1]: https://danilafe.com/series/static-program-analysis-in-agda/
reply