← All writing

Where does the proof stop?

The bracket stops before native codeA bracket binds the modeled LCNF and LNIR runs by their value and final heap. A separate native code chip sits beyond the bracket, outside the proof.Modeled runsOutside proofLCNFNative codeLNIRSame value and heapUnder the theorem’s conditions
The bracket stops before native codeUnder the theorem’s assumptions, a successful source run has a target run with the same value and final modeled heap. That comparison does not reach the native executable.

What my TurboLean fork taught me about proving a compiler pass, measuring its reach, and saying where the guarantee ends.

My commit: use one LCNF-to-LNIR lowerer

TurboLean Developer tools

At a glance

A compiler can translate a function without having a proof that the translation preserves its behavior. I wanted to know which functions the proof actually covered.

If a compiler gives me an executable, what would make me comfortable saying it preserves the program I wrote? A test can tell me the two programs agreed on the inputs I tried. A proof can tell me something more, but only about the translation it describes and under the conditions it names. I want both answers. I don't want either to stand in for the other.

That distinction shaped my work in the TurboLean fork. The project translates Lean programs through several representations before they run. I worked on one crossing in that chain: from Lean's LCNF representation to TurboLean's lower-level LNIR. The question was not how much of the compiler I could call verified. It was whether I could point to the exact translation, say what the theorem promises, and show where a particular function falls.

Make the theorem follow the code that runs.

The first problem was an implementation problem. It's easy to have a lowerer you can reason about and another version that the compiler actually calls. I removed the second, unproved route in my fork so the bridge and the proof could refer to one lowerer. That is what the first drawing follows: one translation, with the result it produces kept separate from what we can prove about that result.

Follow the program across the one translation the theorem talks about.

One path for the code and the proof.An outlined marker travels above a single path from LCNF input through the lowerer to LNIR output. The bracket marks the translation being discussed.One lowering pathLCNF inputLowererLNIR outputOne path for the caller and the theorem
One path for the code and the proof.

The compiler caller and the theorem refer to the same lowering from LCNF to LNIR.

An outlined marker travels above a single path from LCNF input through the lowerer to LNIR output. The bracket marks the translation being discussed.

Diagram key

The outlined marker follows the single translation discussed in the proof, from left to right.

LeftLCNF input
The Lean representation the source evaluator describes.
RightLNIR output
The lower-level representation the target evaluator describes.

I also split the evaluator for the incoming representation away from the lowerer. They still share definitions for the language they talk about, but the evaluator can describe how the source program runs without translating it first. That gave me a useful comparison in tests. If both sides go through the same translation just to tell me what the source means, it is much harder to know what that test has checked.

The split is not the theorem. It gives the theorem and the tests a cleaner object to talk about. And having one path is not an argument that every input to it is covered. The next question is what the theorem needs to know about the function it sees.

A function brings its callees with it.

Take a function that calls a helper, which in turn calls another helper. The first function might look simple. Its translation can still depend on what happens at the end of that chain. I changed the coverage check to follow those calls before counting the original function as proved.

Both examples start with a caller and a helper. Look at what happens at the far end of each chain.

The proof follows the calls.Two rows show Callers and Helpers. The first ends at a known Leaf, with solid links connecting the chain. The second ends at Unknown, with dashed links and no proof claim.Follow the whole call chainIn scope, if the chain qualifiesCallerHelperLeafOutside this proofCallerHelperUnknown
The proof follows the calls.

One illustrative chain can qualify. The other has an unaccounted-for callee and stays outside the proof.

Two rows show Callers and Helpers. The first ends at a known Leaf, with solid links connecting the chain. The second ends at Unknown, with dashed links and no proof claim.

Diagram key

Both rows begin alike. The full chain has to qualify under the theorem's conditions.

Top rowEligible chain
The calls remain in scope if each reachable declaration qualifies.
Bottom rowUnaccounted-for call
A missing callee record is not evidence that the call qualifies.

In the fork's local-call measurement, the whole reachable chain has to be accounted for. The declarations have to lower, the relevant names have to agree, and the call sites have to use arguments the theorem handles. This check is for non-recursive calls. An unaccounted-for callee or a cycle keeps the caller out of the proved count. Where the function did lower, it can still be recorded as translated without proof. That is information, not a verdict that the generated program is wrong.

This matters because a proof with a condition does not fail to be useful when the condition is narrow. My job was to stop the reporting code from erasing the condition. I wanted a reader to be able to explain why an entry moved into the proved column, and why the next entry didn't.

Stop the claim where the theorem stops.

The local-call theorem is a one-way result. If lowering succeeds, the environments and context agree, and the source evaluator successfully runs the function with the given fuel bound, the target evaluator returns the same value and final modeled heap. Fuel bounds the evaluation in the model. It isn't a measure of time. If source evaluation fails, or never finishes, this theorem doesn't tell me what the target does.

Watch where the comparison stops. The native executable is beyond the marked boundary.

The comparison ends at the model.A bracket highlights modeled source and target runs and their matching value and heap. A dashed vertical boundary separates the native code from the comparison.The proof stops at the modelCompared by the theoremOutside itSource runTarget runNative codeSame value and modeled heap
The comparison ends at the model.

Under the theorem's conditions, the modeled runs finish with the same value and heap. Native code is outside this result.

A bracket highlights modeled source and target runs and their matching value and heap. A dashed vertical boundary separates the native code from the comparison.

Diagram key

The bracket links only the source and target models; it never crosses the vertical boundary.

Left of the lineCompared
Successful modeled runs give the same value and final modeled heap under the assumptions.
Right of the lineNot compared
The executable and subsequent native stages are outside this theorem.

In the separate recursion work, I fixed a case that made the heap comparison matter. Both modeled runs returned zero. One freed an object and the other left it live. A test that checked only the return value would have missed it. That fix closed a specific gap, not the full recursive lowering result. And neither result proves the native binary correct. Code generation after LNIR, the rules for calling native functions, and what runs on the machine are outside the comparison.

There is a related mistake in code review. A theorem's statement can stay the same while its proof body changes. Some importing modules can observe that body during checking. In the fork I kept the edit classified as proof-only, but had the verifier recheck dependents when there were importers. That is more work than rechecking only the edited file. It is also a cost a reviewer can see and explain.

Tests make the same kind of claim. A regression test should prove it can object, on LinkedIn, opens in a new tab asks a check to show that it would notice the change it guards.

Put the denominator beside the claim.

The receipt changed how I would talk about coverage. In the pinned run, 880 of 902 declarations in the targeted C1 tests counted as proved. In the pinned Batteries library, 53 of 10,658 did. Neither number is a correction to the other. One set exercises the constructs the work was targeting. The other makes it harder to mistake that success for coverage of a larger body of Lean code.

Read the count beside each bar. The bars have equal length, but their denominators are different.

The proof depends on what you count.Three proportional bars separate proved, translated without proof, and rejected. Proved counts are 880 of 902 targeted, 48 of 1,805 Std/Init and C2, and 53 of 10,658 Batteries declarations.The pinned coverage receiptTargeted C1 tests880 / 902Std/Init + C248 / 1,805Pinned Batteries53 / 10,658ProvedNo proofRejectedBatteries count corrected: 59 to 53
The proof depends on what you count.

Each bar is one named input set in the pinned fork receipt. The small proved share of Batteries is not rounded up.

Same proof boundaryCorrected count

The Batteries count was corrected from 59 to 53 of 10,658. The intermediate 49 reflects reclassification, not another run. The modeled result and heap comparison still do not cover native execution.

Three proportional bars separate proved, translated without proof, and rejected. Proved counts are 880 of 902 targeted, 48 of 1,805 Std/Init and C2, and 53 of 10,658 Batteries declarations.

Diagram key

The bars show fractions of each named input set, with the proved count and its denominator printed above.

First solid segmentProved
The receipt counts the declaration as covered by the modeled proof.
Vertical stripesTranslated without proof
The measured path produced a translation outside the proof count.
Striped segmentRejected
The measured path rejected it. This is not a judgment about stock Lean.

The most useful result was a number that went down. On the same Batteries input set, the previous count was 59. When I fixed the classifier to see a helper call after a reference-count or set operation, ten of those entries no longer qualified as call-free. Applying the local-call rule admitted four. The result was 53. The intermediate 49 is a reclassification of the recorded facts, not another run. If I had optimized for the headline number, I would have missed the correction that made it worth publishing.

I want the receipt to travel with the result, so it records the measured source revision, Lean 4.35.0, the inputs, and digests of code used to produce the classification. It also records translated but unproved declarations separately from rejected ones. Compiler-generated auxiliaries were excluded from these denominators. A label that says a declaration was rejected is about this measurement path, not a claim that Lean cannot compile it.

The roadmap pull request I opened was closed as superseded. The maintainer credited the work and carried pieces into narrower changes. Later upstream work on bounded recursion is a separate result with its own conditions. The numbers shown here remain the measured fork snapshot, not measurements of upstream today.

Read every category in the pinned receipt
  1. Targeted C1 tests: 880 proved, 0 translated without proof, 22 rejected, out of 902 declarations.
  2. Std/Init + C2: 48 proved, 65 translated without proof, 1,692 rejected, out of 1,805 declarations.
  3. Pinned Batteries: 53 proved, 1,066 translated without proof, 9,539 rejected, out of 10,658 declarations.

The rejected-but-not-lowered count in the source is part of rejected, not a fourth category.

I first wrote about this habit for test coverage in The missing denominator, on LinkedIn, opens in a new tab: the first question in a coverage review is what the report counted.

For a closer technical look
  • The local-call coverage rule checks the reachable transitive set of declarations, including the call arguments and the naming conditions required by the proof.
  • The theorem preserves a successful result and the modeled heap, under its stated conditions. It is not a termination guarantee, a proof of failure behavior, or a theorem about an executable.
  • The receipt commit 33edb2d records measurements from source 0004587 with Lean 4.35.0. See the pinned record for the external input revision and classifier digests.

What I take from it

Before I repeat a claim about a verified compiler, I want to know which path it takes, which behaviors the theorem compares, and what the count leaves out. If I can't trace those answers back to the work, what exactly am I asking someone else to trust?