I Asked My Compiler Which Code Can Run in Parallel. It Answered With Proof.

A compiler that analyzes a program ends up knowing a great deal about it: which statements depend on each other, which calls can panic, which values are captured where. Most of that knowledge stays inside the compiler, spent on optimization, and what reaches you is a binary and a few diagnostics.
Willow is an experimental language I'm building: statically typed, compiled to native code via Cranelift, with a generational GC and lightweight tasks for API servers. One design decision shaped a lot of the toolchain: what the compiler knows, you can ask.
The strangest example is parallelism. But first, the error that made me trust the checker.
The bug it catches before you ship it
This is a real bug pattern: a helper that waits on a channel, called while holding a lock. The task suspends, the lock stays held, and anything waiting on that lock — possibly including whoever was supposed to send on the channel — is stuck.
fn audit(ch: Channel<i64>) { let v = ch.recv(); // waits here println(v); } fn main() { let balance = Mutex::new(100); let ch = Channel<i64>::new(); lock balance as mut value { audit(ch); // called with the lock held value = value + 5; } } Willow rejects this at compile time:
$ willow check bad.wi error[E2604]: cannot call a waiting helper while holding a Willow lock --> bad.wi:12:9 | 4 | let v = ch.recv(); | ---- `Channel.recv` causes this transitive effect ... 12 | audit(ch); | ^^^^^ `audit` may suspend the task before returning | help: move the helper call outside the critical section; Rust calls here require a current reviewed nonblocking declaration Three things matter here. The checker sees through the helper — the wait is transitive, and the error shows the witness path. The help tells you the fix, not just the sin. And this is not a linter bolted on afterwards: the same effect information that powers this error is what the parallelism analysis below consumes. One semantic model, many surfaces.
The lock checker has siblings: inconsistent lock acquisition order across the program is E2605, and a task capturing a value it may not safely share is E2402/E2408 — the value either gets lent under strict rules, sent (transferring ownership), or rejected with the boundary named.
"Why can't this run in parallel?"
Here is a small function with a lock and a channel send — the kind of code where parallelizing by hand gets dangerous:
fn transfer(from: Mutex<i64>, to: Mutex<i64>, amount: i64, done: Channel<i64>) { lock from as mut debit, to as mut credit { let moved = net(amount); debit = debit - moved; credit = credit + moved; } done.send(amount); } Ask the compiler:
$ willow parallel transfer --source bank.wi parallel transfer: ok barrier bank.wi:11:5: effect.panic, memory.alias-unknown, progress.unknown, sync.lock sync.lock at bank.wi:11:5 (certainty=policy) barrier bank.wi:16:5: memory.alias-unknown, ownership.capture, sync.channel sync.channel at bank.wi:16:10 (certainty=unknown) Each statement it analyzes gets one of two answers: proven independent, or a barrier with named reasons — sync.lock, sync.channel, ownership.capture — each with a source location and a certainty level. When the compiler doesn't know, it says so (memory.alias-unknown), instead of guessing. A parallelism tool that bluffs is worse than none, so "unknown" stays in the output where it belongs.
Designed to refuse: the panic-ordering problem
Next I tried four independent calls in main, where the callee is loop-free arithmetic:
fn f(x: i64) -> i64 { return (x % 100) * (x % 100) + 3 * (x % 50) + 1; } let a = f(10); let b = f(20); let c = f(30); let d = f(40); The analysis said: independence: proven — rewrite: blocked.
The blocker was effect.panic. f does arithmetic, and arithmetic can panic on overflow. Sequentially, if f(20) panics, f(30) never runs. In parallel, that ordering guarantee disappears. Parallelizing would change which panic you observe first — a semantic change, not an optimization.
Panic ordering is a constraint I built into the analysis deliberately, as a rule. Having it fire on my own four-line example — and finding I couldn't argue with the reasoning — was the moment I knew the rule was doing real work, not just decoration.
With a loop inside f, the answer changes again: progress.unknown. The compiler can't prove the loop terminates, so it won't certify the call as a finite unit of work. Conservative? Absolutely. It refuses some code that is perfectly safe. That's the deliberate trade: unknown means unknown.
When it says yes
Make the callee finite and panic-free — comparisons and boolean logic only:
fn g(x: i64) -> bool { return x > 5 && x < 100 || x == 42; } let a = g(10); let b = g(20); let c = g(30); — and the answer flips:
$ willow suggest parallel main --source seq3.wi --explain ELIGIBLE seq3::main benefit=LIKELY_NOT_BENEFICIAL DISCHARGED PROVEN at seq3.wi:7:5: Checked disjoint private loans or immutable inputs, finite nonpanicking callees, source-order joins and compatible caller context. Two things I like about this output. First, the obligations are listed and discharged — you can see what was checked. Second, benefit=LIKELY_NOT_BENEFICIAL: the compiler thinks the rewrite is safe and probably not worth it for code this small. That estimate is a static heuristic — counted expression visits plus estimated transitive callee work, per the spec — not a measurement, and the spec itself warns that spawn/join overhead can dominate it. Safety and expected benefit are reported as separate judgments, which is exactly how it should be: merging them would hide which one is doing the work in any given answer.
Ask for the rewrite and you get a preview, not an edit:
$ willow suggest parallel --source seq3.wi --prepare <id> --revision <rev> - let a = g(10); - let b = g(20); + let __willow_parallel_task_0 = spawn g(10); + let __willow_parallel_task_1 = spawn g(20); + let a = __willow_parallel_task_0.join(); + let b = __willow_parallel_task_1.join(); The suggestion comes back as a transaction: a diff, the revision it was computed against, and a verification manifest with before/after hashes. Your file is not touched. And the check is not a one-off: the analysis runs again immediately before an edit is applied, and a previously validated suggestion on its own does not authorize the write — if the source moved, the transaction is stale and has to be re-earned. An editor — or an AI agent — can validate the revision, apply it, and know the result is exactly what the compiler checked.
Parallelizing by hand: the advisor is stricter than the language
Certification is a high bar, but it is not a gate on the language. Nothing stops you from spawning tasks yourself — the advisor simply won't vouch for code outside its proven class. Here is the loop-heavy version the advisor refuses to certify:
fn work(x: i64) -> i64 { let mut acc: i64 = 0; let mut i: i64 = 0; while i < 30000000 { acc = acc + (x + i) * (x + i) % 97; i = i + 1; } return acc; } Call it four times in sequence, or spawn all four and join them:
let ta = spawn work(10); let tb = spawn work(20); let tc = spawn work(30); let td = spawn work(40); let a = ta.join(); let b = tb.join(); let c = tc.join(); let d = td.join(); Measured with a release build (median of 3 runs, on a shared VM whose visible 4 vCPUs are CPU-capped, so treat the ratio as a floor, not a headline):
| Version | Wall time | Output |
|---|---|---|
| Sequential | 0.47s | total=5760000932 |
| Spawned ×4 | 0.35s | total=5760000932 |
Identical output, about 1.4x faster even in this constrained environment — Willow tasks really do run on multiple threads.
The same model, applied to cancellation
The checker is one application of the semantic model. Another is much more mundane — and it's the one that saves code every day. Racing three tasks and cancelling the losers in Willow:
let fast = spawn racer(1, 5); let mid = spawn racer(2, 30); let slow = spawn racer(3, 200); select { let v = fast.join() => { println(format("winner={}", v)); } let v = mid.join() => { println(format("winner={}", v)); } let v = slow.join() => { println(format("winner={}", v)); } sleep(1000) => { println("no winner in time"); } } mid.cancel(); slow.cancel(); Cancellation is a property of the task: cancel() requests it, is_cancelled() observes it. The equivalent Go program — I wrote both, and ran both ten times to make sure the outputs matched — needs context.WithCancel, a cooperative select on ctx.Done() inside every racer, a separate exit-notification channel, and manual bookkeeping to learn who actually stopped. Roughly twenty extra lines, and the cancellation contract lives in comments and discipline instead of the language. Go's model is flexible; it is also entirely opt-in, per goroutine, forever.
The compiler is an API
None of the commands above are special-purpose hacks. parallel and suggest parallel sit in a family — overview, refs, symbol, type, effects, impact, rename — that all read the same compiler-owned semantic evidence. They share the boring, important properties:
- JSON or NDJSON output, with an opt-in
--max-charsbudget, so a tool (or an agent with a context window) decides how much answer it can afford. -
--explainand--dry-runeverywhere: ask why, preview the change, then decide. - Edits as transactions, with revisions and content hashes, so an applied change is provably the change that was checked.
- A persistent query cache (experimental,
WILLOW_QUERY_CACHE=1), so repeated questions reuse checked results instead of re-analyzing the world. -
willow agent instructions— the toolchain explains itself to a coding agent, in the agent's own terms, for the agent frameworks it knows.
That last one is the thesis, if there is one. We are entering a period where a large share of new code is written by agents and reviewed — if at all — by tired humans. Concurrent code is where that arrangement fails first: races and deadlocks don't show up in a diff. A compiler that can be interrogated — about the specific properties it checks, and no further — that answers "what does this change affect?", "why can't this overlap?", "prove this rewrite is safe" with evidence instead of vibes, is a guardrail that scales with the agents instead of against them. It is not an oracle: it proves a bounded set of properties, under stated assumptions, and its most common honest answer is "unknown". That boundedness is what makes the answers worth trusting.
Limitations and losses
Willow is v0.1.14 and experimental. The standard library is small (I added map/filter/fold to it today), the ecosystem is effectively zero, and Go beats it on several channel-throughput benchmarks. The short version of the table (author-measured, Ryzen 7 7800X3D, vs Go 1.27):
| Benchmark | Result |
|---|---|
| Parked task memory | Willow: 757 B/task vs Go 2,743 B |
| Idle spawn | Willow ~2.06x faster |
| Wake fan-out | Go ~5.49x faster |
| Channel ping-pong | Go ~4.33x faster |
| Channel select fan-in | Go ~3.80x faster |
| Server simulation | Go ~2.57x faster |
The pattern is consistent: Willow's runtime is cheap at resting and starting — tasks are small and spawn is light — and slower at raw message throughput, where Go's scheduler has had a decade of tuning. If your workload is a million tiny messages, use Go. If it's a hundred thousand mostly-idle tasks with locks you don't want to misuse, that's the shape Willow is built for. The full methodology is in the README; the numbers above are mine, on my machine, and the losses are printed in the same table as the wins. Most real-world code I point suggest parallel at comes back blocked, because real code has loops, locks, and arithmetic that can panic.
But the direction feels right to me: a compiler that explains itself. Instead of stopping at "error at line 12", it shows what it proved, what it couldn't prove, and the exact statement where your lock makes the question unanswerable.
What would you ask a compiler, if it could answer?
A note on reproducibility: every command output in this article is real, produced by the v0.1.14 binary against the files as shown. The snippets are complete programs or complete functions — net in the transfer example is a one-line @effects(no_wait) identity helper, and the main functions that wire the examples together are omitted only where nothing in them affects the output.
Repo: https://github.com/lechatthecat/willow — criticism welcome, especially about where the analysis is too conservative.


