Repository navigation
docs: measure whether the documented examples compile - #540
Merged
Merged
Conversation
First step of the wiki work: build the instrument before changing any content, so every later claim about coverage is measured. There are 775 ```flow blocks across the tracked markdown. None of them was checked by anything. `scripts/check_doc_examples.py` compiles all of them in about half a second, in process, and writes a ledger to docs/generated/example-status.json. The baseline is 569 verified (73%) and 206 unverified. Most documented examples are fragments by design, so the checker tries a short ladder of wrappers and records which rung each block needed. A block that only passes under the loosest wrapper stays visible in the ledger rather than disappearing into a green count. The ladder needs a guard. Flow reads `state angle` as two bare variable expressions and `angle evolves as velocity` as a variable followed by a cast of `evolves` to type `velocity`. Both parse once wrapped in a main, and neither means anything like what the surrounding prose says. Without a check for no-op statements the tool reported 581 verified; 12 of those were prose. All 12 are in VISION.md, describing syntax the language does not have yet, which is what the ignore= tag is for. Extraction moves into scripts/docs_blocks.py. build_wiki.py and verify_browser_interp.py each carried a copy of the same regex and the same "function main" filter, kept in sync by a comment, and had already diverged: only one derived a section heading. The regex also mispaired fences, since with DOTALL and a non-greedy body it can start at a closing fence and run to the next opening one, capturing prose as code. The replacement walks lines and applies the CommonMark fence rule. Tutorial extraction is byte-identical before and after: 257 lessons, same ids, sections and bodies. Per-block metadata goes in the info string, which markdown offers and nothing was using: expect-error, ignore="reason", host=, preamble=, from=, flow-body. Unknown words are rejected, so a typo fails loudly instead of quietly verifying a block the author meant to exempt. Reporting only. No CI gate yet. Unit 1426 passed, ruff clean, doc-links and wiki-links clean. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A stress test of the first version found it was overstating. It reported
569 of 775 verified; compiling those through transpile and clang showed
that a fifth of them do not build. On the first 120 alone, 52 failed.
The cause was the fast tier. It ran the type checker with strict=False,
and in lenient mode names are not resolved, so undefined identifiers
survived to clang and the checker never looked. Three fixes, each one
because leaving it out produced green on documentation that does not work:
- Strict type checking, then C generation, then clang. Batching clang at
150 translation units per process keeps the whole run near six seconds,
so there is no reason to stop early.
- Route source through the field and dynamics expanders the way
module_resolver does. Without them `dsys plant { ... }` and
`field T: f64[32] on Line` were reported as syntax errors, which is the
opposite mistake: correct documentation called broken.
- Reject blocks that compile to an empty translation unit. `theorem`
declarations and unused generics are erased before codegen, so clang was
being asked to approve an empty file. 42 blocks were passing this way,
including the theorem example on the page whose subject is that theorems
are checked, and a block under the heading "What gets rejected" whose
body is entirely commented out.
Two harness rungs are removed after measuring that both rescue zero blocks.
`flow-body` cannot work: _validate_flow rejects a flow with no state and
limits members to f32/f64, while the docs write `state angle : Angle`.
`decl-wrap` was worse than useless; a translation unit needs no entry point
to compile, so all it ever did was hand an empty `main` to otherwise empty
blocks and defeat the vacuity check.
The no-op guard now recurses, so a bare identifier inside an `if` is caught
the same as one at the top level.
`host=`, `preamble=` and `from=` are removed from the accepted info string
until something honours them. They parsed and did nothing, which is worse
than absent: an author writes preamble= and gets a green that means nothing.
Ledger rows are keyed by content hash rather than line number. Inserting a
paragraph at the top of VISION.md moves all 30 of its blocks; across recent
history 178 of 813 commits would have renumbered rows, up to 223 at once.
That is a standing merge conflict that trains reviewers to resolve it
blindly. A content key changes exactly when the block does.
Honest baseline: 399 of 774 verified (52%). Unverified stops at parse 258,
types 62, vacuous 42, clang 13.
Unit 1444 passed, ruff clean.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
godofecht
force-pushed
the
docs/verify-example-blocks
branch
from
August 18, 2026 08:55
51df55e to
e7166c4
Compare
This was referenced Aug 18, 2026
This was referenced Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First of the wiki series. Builds the instrument before touching content, so every later claim about coverage is a measured one.
The baseline
774
```flowblocks across the tracked markdown. Nothing checked any of them.Every block goes through the front end a real build uses: the field and dynamics source expanders, the parser, the strict type checker, the C generator, and clang. The whole run is about six seconds, with clang batched at 150 translation units per process.
The first version of this was wrong, and that shaped the design
I wrote a fast tier first: parse plus type check, in process, 0.4 seconds, 569 of 775 verified. Then I compiled those 569 through transpile and clang. A fifth of them do not build. On the first 120, 52 failed.
The cause was
checker.strict = False. In lenient mode the type checker does not resolve names, so undefined identifiers sail through to clang and nothing ever looks. Three consequences, each now fixed because leaving it out produced green on documentation that does not work:Strict checking, then codegen, then clang. Not a cheaper approximation of it.
Route through the source expanders.
module_resolverexpands the field and dynamics DSLs before parsing; the checker did not. Sodsys plant { ... }andfield T: f64[32] on Linewere reported as syntax errors, which is the more damaging mistake: it pushes an author to rewrite documentation that is already correct.Reject blocks that compile to nothing.
theoremdeclarations and unused generics are erased before codegen, so clang was being handed an empty file and approving it. 42 blocks were passing this way. Two are worth naming: thetheorem nat_zero_addexample on the page whose entire subject is that theorems get checked, and a block under the heading## Part 2: What gets rejectedwhose body is 100% commented out.Two harness rungs, designed and then measured out
The harness exists because most documented examples are fragments by design: a page about struct syntax shows a struct, not a program wrapped around one. But two of the rungs I planned rescue zero blocks repo-wide:
flow-body(wrap inflow Demo { ... }) cannot work.flow_blocks._validate_flowrejects a flow that declares no state and restricts members to f32/f64, while the documentation writesstate angle : Angle,input voltage : Voltage. Every dimensioned example is structurally excluded. Its intended cases are either aspirational syntax or already-completeflowblocks, where wrapping replaces a useful diagnostic (nested flow member 'angle' has type 'Angle', which is not a flow in this file) with a worse one.decl-wrap(append amain) was worse than useless. A Flow translation unit needs no entry point to parse, type-check or generate C, so blocks with real declarations already pass standalone. All it ever did was hand an emptymainto otherwise-empty blocks, which is exactly how 42 vacuous blocks were passing.What survives is
standaloneandstmt-wrap, and the ledger records which one each block needed.The no-op guard
Flow parses
state angleas two bare variable expressions, andangle evolves as velocityas a variable followed by a cast ofevolvesto typevelocity:Both parse once wrapped in a
main, and neither means anything like what the prose says. The guard rejects any harness result containing no-op statements, and recurses, so a bare identifier inside anifis caught the same as one at the top level. Checked in both directions: it rejects exactly the blocks that are genuinely not statements, with no false negatives.Deduplicating the extractor
build_wiki.py:554andverify_browser_interp.py:44each held a copy of the same regex and the same"function main" in codefilter, kept in sync by a comment saying so. They had already diverged: onlybuild_wikiderived a section heading.The shared regex was also wrong. With
re.DOTALLand a non-greedy body,```flow\n(.*?)```can start at the closing fence of one block and run to the opening fence of the next, capturing the prose between as code.scripts/docs_blocks.pywalks lines under the CommonMark fence rule instead. Tutorial extraction is byte-identical across the change, verified by running the old logic side by side: 257 lessons, same ids, titles, sections and bodies.Info strings
host=,preamble=andfrom=are designed but deliberately not shipped. They parsed and did nothing, which is worse than absent: an author writespreamble=docs/_preambles/gfx.flow, the block is checked without it, and a pass means nothing. They return when something honours them.Unknown words raise, so
expect_errorfails loudly rather than quietly verifying a block the author meant to exempt.Ledger keyed by content, not line
Rows are keyed
path#sha256(code)[:12]. Inserting one paragraph at the top ofVISION.mdshifts all 30 of its blocks; across recent history 178 of 813 commits would have renumbered at least one row, up to 223 at once. A line-keyed 160 KB JSON in that traffic is a standing merge conflict that trains reviewers to resolve it blindly, which silently un-ratchets. A content key changes exactly when the block does, which is also when it genuinely needs re-verifying.Scope
Reporting only. No CI gate, no content changed. The gate arrives later in the series once the count is down, using the ledger as a ratchet. The 375 unverified are not one population; they split into docs using syntax the language never had, aspirational
VISION.mdvocabulary, cross-block context, and compiler backend bugs. Each wants a different fix and a separate PR.Validation
ruff check srcclean; new and touched scripts cleancheck_doc_links.pyandcheck_wiki_links.pycleanbuild_wiki.pyrebuilds and still emits 257 lessons, byte-identical