← Wed, Nov 25 digest

I checked Clojure's core with Lean and found unreported bugs

read article ↗ hn thread ↗

Using Lean 4 and differential testing, a developer found 17 unreported bugs in Clojure's core, including an infinite loop in vector-of and hash corruption in HAMT collections.

read it The detailed breakdown of real bugs found using Lean and differential testing offers fascinating technical depth for systems and language engineers.

summary

A developer modeled portions of Clojure's core in Lean 4 and ran differential testing against standard Java collections to uncover 17 unreported bugs in version 1.12.7. The findings include a bitmask error causing reduce on vector-of to infinite loop past 65,505 elements, and a hash corruption bug in HAMT collision nodes during dissoc. While a few minor points in the list sparked debate over dynamic typing semantics, the major findings represent genuine edge-case implementation flaws. The post details the reproduction and fixes for these issues.

key points

  1. Using Lean 4, the author modeled integer arithmetic and bit operations, while large persistent data structures were tested via differential testing against java.util collections.
  2. A long-standing bitmask error in vector-of causes reduce to loop infinitely on collections with 65,505 or more elements.
  3. HAMT collision nodes incorrectly preserve the query hash instead of the stored node hash during dissoc, breaking subsequent lookups for equal keys with different hashes.

who should read it

Clojure developers, language implementers, and engineers interested in formal verification and testing methodologies.

discussion positive

consensus

Commenters find the use of Lean fascinating for uncovering real bugs, though a few note that some minor items on the bug list are standard quirks of dynamic typing or user error.

pushback

A few commenters push back on whether certain items qualify as bugs, pointing out that dynamic languages permit key coercion and that passing incorrect types is expected to fail.

best comment by rvprasad ↗

While the effort is interesting, I found two issues in the list.

First, (.indexOf (seq (byte-array [1 2 3])) 2) fails because byte arrays store bytes and the argument 2 to `.indexOf` is a Long value. Simple type checking (via eyeballing) could have flagged the incorrect usage. I think such exercises can be more helpful if we can reduce the noise.

Second, (get "abc" 1.9) fails because `get` coerces the given key to integer in the context of string objects, which makes sense; specifically in the context of weakly typed language. That said, I believe that detailed documentation of the behavior …

It scrutinizes the bug list and points out that some listed issues stem from dynamic typing expectations or incorrect argument types rather than core implementation flaws.

Generated by an LLM from the article and thread. Check the sources before relying on it.