Hi everyone,
I've been dabbling around in using model checkers and specification languages over the last few months. After talking to @Luke Boswell yesterday, I tried out using some of these on the Roc compiler yesterday.
Disclosure: I let Opus write the spec, then ran that through the model checker to guide the search.
I'm happy to share more on this if anyone is interested.
I filed a first issue that was found: https://github.com/roc-lang/roc/issues/13401
This is right up my alley.
I find that spending some efforts finding the right tools is high leverage. AI knows the tools/ how to use them and can help you decide the best tool for the job when asked to do so, but it won't always suggest them by default, so it is good to familiarize yourself with the formal spec ecosystem in the domain you are working in.
TLA+/Quint and related are good for temporal properties of distributed systems
Maude/K are very good with language semantics.
Lean obviously very general purpose
many tools are very domain specific. For example there are crypto spec languages, contract languages, etc... It's a good idea to check for specific tools before defaulting to just lean/tla+ which is what most people seem to do.
After the meetup and your comments @Jack Scully and then a good chat with @Ulf Bissbort I've been researching various techniques and how these might like for pure Roc code.
I've made a PR with my concept for how to provide a set of useful tools to enable correctness. Would love any thoughts on that -- it hasn't had a lot of road testing yet, I'm still testing it.
I have to say this builds upon the work of @Matthieu Pizenberg with his SAT solver. :heart:
https://github.com/lukewilliamboswell/roc-fuzz/pull/112
roc-fuzz is a Roc platform for testing pure Roc code past the examples you
write. Fuzz targets check properties over typed inputs with coverage-guided
search; goals, trace rules and allocation measurements check what a passing
campaign exercised;Modelsearches and fuzzes a stateful component described
as a state machine; andSolveproves or refutes claims about fixed-width
integer arithmetic. Each target builds into one self-contained executable that
checks declared examples, explores, and keeps findings for inspection, replay,
retention and minimization.
I might need to rethink the name at some point... it's not just a fuzzer any more. Though the idea of "fuzzy" is kind of growing on me as I have been growing to think of these tools as lenses to peer into a very opaque space from different perspectives.
I would probably try TLA+/Apalache for that specific case because TLA+ is fundamentally state machine based. Quint/Ivy are others in that family
Apalache basically takes a TLA spec and converts it to a sat problem
I used a system that is similar to TLA+ semantically and what it can represent. I also quite like Alloy and Allium for other use cases and often found myself now having to keep many different specs in sync.
After doing that for too many cases and also I ended up writing a small transpiler from a program spec expressed as plain data (Kind of Clojure philosophy like, but with types) to a SMT solver. This allows me to combine the favourite parts of the various languages
One of my goals here, is to try and bring these tools into familiar Roc syntax if I can.
One syntax to rule them all!
Not quite like that :grinning_face_with_smiling_eyes: ... I hope that it helps reduce the friction for people who have the Roc toolchain installed and are comfortable with that.
I think it's a worthy goal to have uniform syntax here. As much as many people claim that they don't care about the syntax of a language, my practical experience has been the opposite.
@Luke Boswell would you like me to create a PR that fixes https://github.com/roc-lang/roc/issues/13401 ?
Richard is already working on it by the look of things. You could add a comment to the Issue with your patches, that might help?
I have to say this builds upon the work of Matthieu Pizenberg with his SAT solver.
Happy it was helpful. I suppose this means it compiled with RC1 without needing big changes? (I haven’t had the time to check)
Only minor changes.. and then I made a few minor perf related tweaks
Diff here https://github.com/mpizenberg/rocsat/compare/main...lukewilliamboswell:rocsat:main
I added some fuzz targets to help me test it / measure allocations etc
At the risk of hijacking this thread even further from the compiler and talking about pure Roc... I just wanted to share an experience report.
I published roc-fuzz 0.8 with the Model and Sovle features. I pretended I had a mature methodology for using model checkers for spec driven development (see Hillel Wayne's article thank you @Ulf Bissbort) -- and assigned an army of Agents to pour through the PDF 2.0 spec and systematically build smaller models and proofs against my implementation.
So far, we've found at least 7 pretty significant or exotic bugs/correctness issues that I think I would never have found before.
By never here, I mean these would have first appeared in a GH issue from some bug found in production
For reference, this is the PR where the PDF work is https://github.com/lukewilliamboswell/roc-pdf/pull/106; I've also had the same task running on roc-time, roc-font, and roc-docx...
I've been reading the PR's over my morning coffee... and I'm really impressed, I don't think I've never seen anything like it before.
The Agents have been able to pull out details from the PDF standards etc and encode that really cleanly into models, or what I've been calling "correctness oracles".
I'm only using Sol 6.2 medium here, with around 4-5 concurrent agents working for a few hours.
I think the models read well and are easy to follow with Roc syntax.
How would you categorize this kind of test infrastructure? It's not unit testing.. I'm not really sure what to call it.
Claude calls all my similar things "oracles" as well. In some cases it maps to stuff I've done earlier in my career, and we called the matching artifacts "gold files".
There are different "tools" we can mix and match to encode our invariants in a single target. I imagine these sitting in the toolbox and we tailor the approach for each problem, specific for that sub-system we want to test.
This is from the first line in the docs;
Model searches and fuzzes a stateful component described as a state machine; and Solve proves or refutes claims about fixed-width integer arithmetic.I thought "Golden X" referred to static data that should not change over time. If we follow that, maybe this could be thought of as a "Golden Model" maybe?
The idea being that this is like an independent model or specification for the system. It's not in written or textual form, but I guess it could be really useful to support a requirement spec or standard.
"Model" feels really overloaded though, so I don't love it
I don't follow everything exactly, but to me the "gold files" concept is a bit more mundane. A gold file is used to prove that two independent oracles or two versions of the same oracle produce identical results. The former is a proof that at least two different implementations agree (strong but not conclusive). The latter is basic regression testing.
So I think you want something stronger for anything going through a state machine. Not really sure though.
My roc-markdown processor has a pretty interesting chain of proof. The first version was golang, and it was in the first generation of my chat program. My friend and I, who both worked for Zulip, used the golang dialect of markdown for a couple months and found no surprising behavior. The golang version did NOT have a hand-written parser; it just extended the best golang tool out there. Then I ported the markdown processor to zig with a complete handwritten parser from Claude. We used gold files based on a corpus of about 10,000 real messages from our chat (tuples of markdown and HTML). And then I ported it again to Roc, still using the original 10,000 real-world tuples. And then I eventually retired the corpus in favor of all the other correctness tests. Also, along the whole chain, we were pinning our compliance with a third-party CommonMark corpus. We had deliberate places where we violated the spec, but we never allow the code to regress from matching all the gold files where we agreed on the behavior.
I could have some details wrong there--there were also messages mined from Zulip itself. But anyway, the whole chain of proof is only as strong as the original assumptions.
just something to throw in here: I am interested in exploring (just exploring, no concrete plans!) potentially incorporating some form of proof checking features into Roc itself.
the basic idea is that it fits our "batteries included tooling" philosophy, it's theoretically a good fit for a language with functional semantics, it could let package authors advertise stronger guarantees, etc.
I know very little about this space, but I want to learn more about it in 2027 and see if it could be a good fit, and if so, how.
I've been thinking that roc-fuzz may be replaced in the long term. Roc will have built in fuzzing some day etc.
I'm using it as a bit of a test bed to explore ideas like this model checking and formal proofs. Will be awesome to have features like this built into the tooling if they prove to be useful.
yeah besides "batteries included," incorporating things into the compiler itself has performance benefits because all the info the tool needs is already right there in memory from having just built the Roc code base, and no work needs to be redone.
Don’t know much either, but considering pure and effectful roc code is clearly identified, I’m sure there are plenty of interesting properties that could be derived. For example equivalence of implementations (for performance reasons), or things like codecs rounds, etc. Exciting :)
What sorts of things are you thinking would be proven in Roc?
Like invariants of the roc program?
yeah - the example that came into my mind was roc-deflate having a proof that for all bytes and all compression levels:
decompress(compress(bytes, level))
== Ok(bytes)
having this as a proof would mean that even if someone compromised the package, not only could you be confident they aren't sneaking in malicious side effects (already true today), but also you can be confident that they aren't special-casing some recognized inputs to decompress into malicious outputs
an attack like that would be hard to catch with property-based tests because you'd have to get lucky and have a seed that generated the exact special-cased input
but with a proof being something you could diff when upgrading (e.g. so you could detect automatically that something which was proven true in previous releases had been dropped) you could have a package where the worst a supply-chain attack could do is like...I don't even know, slow it down?
that would be a really big benefit for 1 line of API code (and presumably a gigantic proof behind the scenes)
Are you thinking of having a formally verified proof (e.g. in lean) for this property of the compress and decompress functions? Similar to e.g. the seL4 operating system kernel, which has been formally verified?
yeah except in Roc instead of Lean :smile:
that would be the idea of giving Roc the ability to do that
haha, you guys are ambitious. Love it.
it's just an idea at the moment, but I do think it's worth exploring the idea!
That would be extremely useful of course. But, from my limited experience, I would recommend of thinking of these model checking and formal verification tools to be part of a toolset: from individual different ways to formulate specifications of parts of your program that can be checked all the way to full correctness proofs on the extreme end.
One of the core tradeoffs being that
a) model checking time can just explode
b) imposing fully checkable code severely limits being able to write pragmatic and "regular" code
In other words: don't let the perfect be the enemy of the good
But I don't mean to be pessimistic. I've already told Luke that from my experience over the last few months using different model checking and formal method approaches, I believe Roc is in an unusually strong position to integrate these ideas
My mental model is a logarithmic relationship here, where you can get a rapid lift up the curve just by sprinkling some of these methods around in core places and combing a few different approaches in a targeted way.
But as you move up the curve and get closer to optimal it get harder and harder, or more expensive... the gains start levelling off and you have to really squeeze for more coverage.
Based on that I tried to cherry pick some obvious wins as a starting point for roc-fuzz to test out... but I would love to explore deeper capabilities someday.
I'm currently having too much fun just exploring these new tools.
yeah, I like that description and it agrees with how I think about using these methods by "sprinkling them on"
For an easy start, I can recommend even just trying out "Allium", which started off as just a set of md notes to give to your LLM. They have added some basic model checking for dangling references and a few other properties since. It takes about 3 min to get going with the downside being that I used npm to install the checker.
There's an overview of the ideas here by the creator: https://youtu.be/43lsrgkhJ8c?t=4561
I think the most important proofs we need in Roc aren't correctness proofs. I'm already confident that Roc is correct in most places. I want performance proofs. Prove to me that Roc can generate code that runs stuff in linear time.
The reason I think that Roc is a particularly good fit to combine with model checking is from my personal experience how I have evolved in writing code after using these methods for a few months now. As Luke was saying, one already gets quite far by just sprinkling these methods onto existing code. But for complicated code that has a lot of IO and interaction with the outside world I have found that using the TigerBeetle or FoundationDB approach of writing side effectful code in the explicit syntactic form of a state machine takes the applicability of these methods to a whole new level.
Separating side-effectful code from pure functions and expressing it in that form allows writing specifications and protocols that are amenable to a form where model checking languages and SAT solvers can hook into and explore the state space much effectively than random sampling.
Ulf Bissbort said:
I have found that using the TigerBeetle or FoundationDB approach of writing side effectful code in the explicit syntactic form of a state machine takes the applicability of these methods to a whole new level.
I'll go back to Luke's question with my own framing. Is there a name for these types of techniques?
If there's already a name for them, then we can do research. If these are particularly innovative, we should coin a name.
I propose "Roc Style"
Luke Boswell said:
I propose "Roc Style"
haha it's not unique to Roc
We need a website :rock_on: https://tigerstyle.dev
i've read the NASA powers of ten before. So useful. Tigerbeetle folks get it.
https://tigerstyle.dev/#nasas-power-of-ten-rules
https://spinroot.com/gerard/pdf/P10.pdf
A lot of the methods sit at the interface of two existing fields:
a) formal methods is a decades old field in academia where the goal is to specify precisely what a system should do and then prove (or at least exhaustively check) that it does. This ranges from full correctness proofs in Lean/Rocq/Isabelle (seL4,CompCert) to the more lightweight side with model checkers like TLA+ and Alloy, which check a model of your design rather than the code itself.
b) software testing, which has traditionally been much more pragmatic and industry driven: you run the actual code and compare what it does against some oracle. Property based testing, fuzzing, differential testing against an independent implementation (Steve's gold files) and Jepsen style testing, where you record a history of events from the outside and check it against a consistency model, all fall into this bucket.
I kinda brought up "gold files" as a counterexample to the main theme of this thread, which I interpret as a lean toward more academic-style rigor in the language. I think Roc already pretty much nails (b), which I call basic industry standards.
I support the lean.
I consider gold files table stakes. :slight_smile: And the Roc compiler tests have a bunch of them.
We don't have to go full-on Haskell or anything, but a certain level of rigor is gonna help in the agentic era. If your language can enforce things that others can't, it's gonna win over other languages that embrace things like mainstream syntax or familiarity.
Interesting. For me personally, it is more of a red flag if languages market themselves to lean harder on the formal side. It often correlates with academics publishing papers, rather than coming from an angle where people try to write actual real world software
I think Dafny strikes a reasonable middle ground and has ideas of how this could integrate into Roc: https://whileydave.com/2023/06/27/programming-languages-going-above-and-beyond/
See my #show and tell > a riff on Cook-Levin thread. It's gonna be very academic and theoretical when I really get Cooking. But the theorem is literally about performance. That's what I care about. Performance, performance, performance.
Claude can pretty quickly diagnose bad code that leads to quadratic behavior when it should be linear or whatever. But Claude's not smart enough to write it correctly the first time sometimes. I want the compiler to enforce guarantees. And type systems are proofs in and of themselves.
I've road tested RocStyle :rock_on: on a few different repositories now, and with each iteration I've been refining the approach.
This is the latest version (the link is at a commit not yet merged)... it's not very long, but makes the discussion above a little more concrete I think.
https://github.com/roc-lang/unicode/blob/f187ef2cad84795918f4324457a1ae33200a4eb6/docs/testing.md
see also #beginners > roc style guide
Some of my style guide centers around basic aesthetics and following conventions. But it's also about writing good code. I have a lot of Roc code that actually enforces the styles.
(shale + Roc)
https://github.com/showell/roc-apps/blob/master/docs/roc-style.md
https://github.com/showell/roc-apps/blob/master/docs/roc-style.md#effects-and-purity "Pure decisions live outside effects." My agents read that before every session and write better Roc code.
it is more of a red flag if languages market themselves to lean harder on the formal side. It often correlates with academics publishing papers, rather than coming from an angle where people try to write actual real world software.
In the past it was rarely worth the time investment to do formal verification but now it seems practically feasible with AI assistance.
I've road tested RocStyle :rock_on: on a few different repositories now
I propose we write it as :rock_on:-style :smile:
In the past it was rarely worth the time investment to do formal verification but now it seems practically feasible with AI assistance.
Now that I have traced the thought, I think @Jack Scully also said this at the last meetup :)
It's worth repeating! More broadly, it was rarely worth the time investment to do X but now X seems practically feasible with AI assistance. For many X.
A lot of tropes about software development go out the window.
WIthout AI bloated test suites can bring a codebase to a screeching halt. You end up with codebases that never regress, but they never move forward either, because every developer is too busy fixing tests.
WIth AI you let your agent do all the analysis on breaking tests. You still pay time to RUN the tests, of course, so nothing's free. Performance, performance, performance becomes premium.
check out the gospel system for Ocaml. It seems like a promising direction:
https://ocaml-gospel.github.io/gospel/walkthroughs/fibonacci
I would hesitate to try to make Roc a theorem proving language. I know for example that lean takes advantage of dependent types. it also has mathlib...
Ada (1980) has preconditions and postconditions: https://learn.adacore.com/courses/intro-to-ada/chapters/contracts.html
I love the "ghost" branding, because the contracts are clearly opt-in.
Last updated: Nov 26 2026 at 20:35 UTC