r/Clojure • • 6d 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
79 Upvotes

8 comments sorted by

7

u/alexdmiller 5d 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 5d 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)

4

u/alexdmiller 5d ago

Not sure anything there was very helpful, but thanks

16

u/steloflute 6d ago

Automated program analysis can be used to create better programs.

8

u/J_M_B 6d 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/pooyamo 1d ago

Is formal prove methods your specialty or do you have academic training in it? I ask cause I have no idea what sort of background is needed for a similar endeavor as you described and I've been interested in a similar thing too.

It looks like one needs to know about programming language type theory too for this task.

1

u/J_M_B 18h ago

Very limited. I worked through the NAND to Tetris course and I've always been into PL theory so I've picked up things along the way. I say just dive in and do it and learn along the way.

1

u/deaddyfreddy 5d ago edited 5d 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?