hn.today

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

s.conao3.com12 points0 comments
Screenshot of I checked Clojure's core with Lean and found 17 unreported bugs

A systematic check of Clojure 1.12.7’s Java-based core used Lean 4 to verify small arithmetic routines and differential testing to compare collections with Java’s standard equivalents. Lean modeled Java integer operations as fixed-width bit vectors, letting it find counterexamples that could then be reproduced in Clojure; larger data structures were tested with randomized sequences of operations. The investigation found 17 bugs with no matching reports in Clojure’s issue tracker or support forum. The results also distinguish bugs from areas that held up: persistent hash maps and sets matched Java maps across three million operations, and tested vector and tree-map behavior showed no discrepancies.

The most serious findings include a `vector-of` reduction that loops forever at 65,505 elements because an incorrect bit mask resets the next chunk’s index to zero, and a persistent hash-map deletion bug that can leave a collision node with a stale hash, making a surviving key visible when printed but inaccessible by lookup. Java interop also behaves differently for `removeIf` depending on whether the compiler knows the receiver’s type. Other examples include integer overflow causing `drop` on a string sequence to throw, and `assoc` with a negative index on a subvector overwriting an element outside that view. The remaining bugs concern numeric conversions, metadata, array and sequence methods, and related edge cases; twelve have comparatively smaller effects.

Read on s.conao3.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

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

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

Lean formal checks and differential testing of Clojure 1.12.7 uncovered 17 previously unreported bugs, including issues in `vector-of`, HAMT hash collisions, and Java functional-interface calls without type hints. Three million HAMT operations and vector boundary tests found no errors in the core tree structures; the bugs appeared in surrounding code and interactions such as equality and hashing. (s.conao3.com)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.