r/Clojure • • 2d ago

Checked Clojure's core with Lean and differential testing and found unreported bugs in HAMT and vector-of

https://s.conao3.com/blog/2026/e4f733
75 Upvotes

6 comments sorted by

6

u/alexdmiller 1d ago

Very useful work, I'm working through these and filing bugs/patches as I go. I would not classify everything here as bugs, some fall into "undefined behavior" territory.

1

u/agumonkey 1d ago

people on HN also reviewed the article

https://news.ycombinator.com/item?id=50642939

they noted some potential mistakes in the methodology, it might be worth your while (in case you didn't read it already)

3

u/alexdmiller 1d ago

Not sure anything there was very helpful, but thanks

16

u/steloflute 2d ago

Automated program analysis can be used to create better programs.

8

u/J_M_B 2d ago

I've been using ACL2 to verify a Clojure I wrote on top of Fortran. Lean didn't seem like the best tool to me because I wasn't just proving things that are mathematical as I am formalizing a programming language. I admit I just might not have been able to figure out how to leverage lean.

The road to a formally proven Clojure using acl2 books is a long one though. I had to stop because it was taking forever and also because I was afraid of having a system that would be too brittle. I have managed to get large parts of the system formally verified, including the garbage collector, heap and threads. I also generate my fortran source code by translating the acl2 models directly into code with a proven generator. Not all parts are covered and I am giving myself more flexibility for the parts of the language that will be more static.

The harness consists of the following: cross-referencing gfortran and flang compiler outputs and the respective behavior of their outputs, clojure spec fuzzing and acl2 formal proofs. Fuzzing on the whole finds a lot of bugs. ACL2 books helped me verify the language is working as intended.

1

u/deaddyfreddy 1d ago edited 1d ago

byte-array and short-array reject an initial value

They don't:

(byte-array 2 (byte 7))

(short-array 2 (short 7))

(float ##NaN) is ##NaN

Is it a bug?