Bare Metal Clojure with clojure.Spec
summary
A compiler uses clojure.spec generators to feed sample inputs and statically specialize pure numeric Clojure into C (and Java) by inlining, unboxing and stripping branches, producing unboxed native integers and near-handwritten C output. Benchmarks show plus compiles from scratch in about a minute and a fully inlined Fibonacci build takes ~15 minutes, and combining inlining with memoization yields an O(log n) Fibonacci via inlining+memoize. It works but compilation is slow and correctness is probabilistic unless specs exhaust edge cases.
AI-written summary · about
chapters (12)
- 0:00Introduction to the compiler
- 0:55Motivation and architecture
- 3:42Why Clojure for this project
- 6:49Clojure spec and generators
- 8:30Basic translation process
- 10:45Compiler optimization strategy
- 13:22Deep dive: optimizing plus
- 17:38Refining the optimization output
- 22:32Higher-order optimizations
- 27:22Advantages of this approach
- 30:24Challenges and limitations
- 34:37Q&A session
related talks
24mBuilding Intelligible Systems
46mSpectrum, a library for statically "typing" clojure.spec
56mWrite Fast Code Like a Native
36mSpecification-Guided Component-Based Synthesis from Effectful Libraries
01h 03mBenchmarking and optimizing the Carbon compiler
01h 02mFastware
40mClojure At Scale
30mModularity, Code Specialization, and Zero-Cost Abstractions for Program Verifica...
