r/Compilers • u/Pattinathar • Aug 17 '26
Velaris: effect checking, Z3 contract proofs, and an LLVM JIT in one readable Python file
I built a language where the signature carries the guarantees, and I wanted to share the implementation choices since this crowd cares about the how.
Pipeline: lexer → parser → loader → effect checker → type checker → Z3 proof pass → LLVM JIT (llvmlite) → interpreter, all in one file in pipeline order.
Three things that might interest you:
- The proof pass explores paths symbolically and checks requires/ensures/loop invariants in Z3, with modular call summaries (a callee's contract is assumed at the call site rather than inlining its body). Lists use the theory of arrays, records get per-field symbolic values, and all_of/any_of become real quantifiers with the predicate body inlined under the For All.
- Floats are proven in Z3's genuine IEEE-754 theory, not modelled as reals — so the prover refutes x + 0.1 + 0.1 == x + 0.2 and returns the exact double. FP queries get a bigger solver budget (30s vs 3s) since bit-blasting is slow; integer proofs stay instant.
- The JIT covers pure Int/Float/Bool functions with typed codegen. Division and modulo are deliberately left interpreted in both modes —native fdiv by zero gives infinity while the language promises a clean error, and I'd rather lose the optimization than have the two engines disagree. Every native change ships with a differential test: same program, both engines, diff must be empty.
One soundness lesson: when I added quantifiers, the first test run produced a false counterexample. Turned out untranslatable `requires` premises had been silently dropped since an early version — harmless for "proven" claims, but capable of manufacturing false alarms. Now an untranslatable premise aborts the proof entirely and falls back to runtime checks.
Repo: https://github.com/gowrishankar-infra/velaris-lang
Playground (Pyodide, real compiler in-browser):
https://gowrishankar-infra.github.io/velaris-lang/playground.html
Disclosure: built pair-programming with an AI across 40+ releases; design decisions mine, commit history is the honest record. Beginner here, so tear the implementation apart — especially the prover.
5
u/Helpful-Primary2427 Aug 17 '26
AI slop post
2
u/antonation Aug 17 '26
Would be cool if you could share this to r/AIProgrammingLanguage and r/VibeCodedLanguages
2
u/ha9unaka Aug 17 '26
If you're a beginner, then stop slopping out code and do it yourself.
2
u/[deleted] Aug 17 '26
[removed] — view removed comment