Skip to content

Let a documentation block build on an earlier one on the same page (#584) - #601

Merged
godofecht merged 1 commit into
mainfrom
doc-same-page-context
Aug 19, 2026
Merged

godofecht merged 1 commit into
mainfrom
doc-same-page-context

Conversation

@godofecht

@godofecht godofecht commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #584.

The problem

A chapter builds a program up in pieces. Every fence is compiled alone, so every later block failed:

docs/book/06-pipelines-and-results.md:80   Undefined function 'Err' / ResultI32
docs/book/06-pipelines-and-results.md:152  Undefined function 'parse_port'

The fix cannot be to repeat struct ResultI32 above every fence. That is worse prose than the page has now, and the issue says so.

The mechanism

```flow id=result-type
struct ResultI32 { ok: bool, value: i32 }
function parse_port(raw: i32) -> ResultI32 { ... }
function configure(raw: i32) -> ResultI32 { ... }

**Named rather than implicit.** The issue asked for something explicit and deterministic that does not silently concatenate arbitrary earlier code, and that is the reason: concatenating whatever came before would verify a program the page never shows.

Ids are **page-scoped and resolve backwards only**, so the context a block compiles against is exactly what it names, and forward references are impossible by construction.

A `uses=` naming a block that was renamed or moved **fails the build**:

uses='gone' names no earlier block on this page; add id=gone to the block it depends on


That is the property that makes this safe to spread across the corpus: it cannot rot into quietly verifying the wrong thing.

## Relationship to preamble=

`preamble=` stays. It carries context that is not on the page at all, such as the unit declarations behind the VISION examples. `uses=` is for context the page **does** show, where duplicating it into the fence would damage the prose.

## Applied

Three blocks in `docs/book/06-pipelines-and-results.md`, taking the chapter from 8 unverified to 7 and moving the last one's failure from `parse_port` to its next real dependency. The rest of that chapter uses placeholder names (`f`, `double`, `clamp`) and is illustrative rather than progressive.

Spreading this across the remaining corpus is #583's job. This PR lands the mechanism and one worked example.

## Verification

| Check | Result |
|---|---|
| `pytest tests/` | 1701 passed, 6 skipped |
| `check_doc_examples.py --check-ledger` | no new unverified, 221 → 220 |
| `check_doc_links.py` | all links and fragments resolve |

Five new tests: resolution, ordering across several ids, the loud failure when an id is missing, that a block cannot use one defined later, and that a block without `uses=` gets no context.

)

A chapter builds a program up in pieces: the struct is shown once, then the
functions over it. Every one of those later blocks failed, because each fence
is compiled alone. docs/book/06-pipelines-and-results.md could not verify
parse_port without repeating struct ResultI32 above it, which is worse prose
than the page has now.

    ```flow id=result-type
    struct ResultI32 { ok: bool, value: i32 }
    ```

    ```flow uses=result-type id=parse-port
    function parse_port(raw: i32) -> ResultI32 { ... }
    ```

    ```flow uses=result-type,parse-port
    function configure(raw: i32) -> ResultI32 { ... }
    ```

Named rather than implicit, because silently concatenating whatever came
before would verify a program the page never shows. Ids are page-scoped and
resolve backwards only, so the context a block compiles against is exactly
what it names, and a `uses=` pointing at a block that was renamed or moved
fails the build instead of quietly verifying something else.

preamble= already existed and stays: it carries context that is not on the
page at all. This is for context the page does show.

Closes #584

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@godofecht
godofecht merged commit ec03a32 into main Aug 19, 2026
22 checks passed
@godofecht
godofecht deleted the doc-same-page-context branch August 19, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs verifier needs same-page context for progressive Flow snippets

1 participant