Skip to content

docs(core): generate the foldability inventory instead of hand-maintaining it #1062

Closed

Description

@lex00

The "what folds and what doesn't" inventory is hand-maintained prose over a code-defined subset. It went stale within an hour of the merge it describes (#1020 / a0e7ffe9), and the fix for that instance is PR #1061. This issue is about not needing that fix again.

The problem: four sources, none reconciled

source holds enforced?
packages/core/src/fold/subset.ts which shapes fold (the real definition) it IS the definition
per-lexicon IntrinsicDef registrations which intrinsics fold no
EXPECTED_FOLD in examples/fold-differential.test.ts the empirical per-entry list yes — the only one CI checks
docs/.../concepts/typescript-as-data.mdx the prose a reader actually sees no

Nothing makes them agree. The doc is a hand-copied restatement of the first two, and it silently diverges every time either changes.

Concretely, on the day of filing, the page simultaneously claimed cross-file resolution was "the largest remaining gap" (shipped) and that a function call as a value is "never fold-representable, full stop" (deliberately reversed by #1044). Both wrong, both invisible until someone read it.

This will get worse, not better: #1044 introduces per-intrinsic, per-lexicon foldability. That is a matrix across 11 lexicons that no one will maintain by hand correctly.

The precedent already exists in this repo

Two mechanisms are already here and just aren't applied to foldability:

  • packages/core/src/codegen/docs-sections.ts generates lexicon documentation from code.
  • packages/core/src/codegen/post-synth-barrel-guards.test.ts asserts a generated artifact is current and fails with a "run npm run generate" message when it drifts.

Scope

  1. Generate the subset table — the list of foldable expression forms — from fold/subset.ts rather than restating it in prose. If full generation is impractical because the subset is expressed as control flow rather than data, then at minimum add a guard test that fails when the documented list and the code diverge, in the shape of the post-synth barrel guard.
  2. Generate the per-lexicon intrinsic foldability matrix from IntrinsicDef registrations: intrinsic, tagged-template or plain call, folds yes/no. This becomes materially more valuable with feat(core): fold registered plain-call intrinsics (per-intrinsic opt-in) — DECIDED: yes #1044 and should land alongside or after it.
  3. Publish the live coverage number. Today it is 21 fold / 77 run-fallback across the 98-entry corpus, and it exists only inside a test file. See the note below on why this one matters most.
  4. Guard all of it in CI so divergence fails the build rather than misinforming a reader.

Why the coverage number specifically

The "left of the line by construction" claim is the central technical assertion about chant's evaluation model. Right now a reader has to take it on trust, and the number that would let them check it — how much of the corpus actually folds — lives in a test file.

Publishing it converts an assertion into a verifiable fact, and it moves every time this work advances (15/98 → 21/98 in one PR). It is also the honest counterweight to the claim: fold is opt-in and covers a minority of real source today, and a reader discovering that themselves after being told otherwise is worse than being told up front.

Acceptance

  • The foldable/not-foldable inventory in the docs is generated from code, or guarded by a test that fails on divergence.
  • A per-lexicon intrinsic foldability matrix exists and is generated, not hand-written.
  • The live fold coverage count is published in the docs and refreshed by the same mechanism.
  • Divergence between subset.ts, the intrinsic registrations, and the published inventory fails CI.
  • cd docs && npm run build passes and the link check stays green.

Non-goals

  • Changing what folds. This is about describing it accurately.
  • Replacing EXPECTED_FOLD. That gate stays; this issue makes the human-readable side agree with it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions