Skip to content

TCB: dispatch each function's implementations in the order its file lists them - #4685

Merged
alex merged 1 commit into
mainfrom
claude/vg-dispatch-by-api
Nov 8, 2026
Merged

alex merged 1 commit into
mainfrom
claude/vg-dispatch-by-api

Conversation

@alex

@alex alex commented Nov 8, 2026

Copy link
Copy Markdown
Member

Part of #4548. This PR changes trusted code. It only removes trusted machinery or makes it stricter: no ISA model, contract or Verified changes. It is stacked on #4682, which orders every list and registration file best first.

Trusted changes

TCB/Registration.lean:

  • Adds Artifact.base: the name of the function an artifact implements, which is its Api's name. Api.artifact sets it. An artifact built directly defaults to its own name, so it is a function of its own, as before.

TCB/Rust.lean:

  • Grouping: a function's implementations are the artifacts with its base (groupsOf). They are no longer found by the name prefix _<suffix> together with an equal signature and documentation. Every implementation must have its base's signature and documentation, otherwise the emitter fails (checkGroups).
  • Order: a dispatcher tries the implementations in the order the artifacts list them. Tables of functions likewise: fnTables no longer sorts tables by name. Deleted: Rank, Ranking, rankOf, partsOf, lexLe, checkRanks, the ranking parameter of files and of the dispatcher builders, and Dispatch.lean.
  • Unreachable implementations: one the dispatcher would never choose, because it needs every feature of one tried before it, now fails the emitter (armsOf). It used to be dropped silently.
  • Aliases deleted: alias, sameKey and aliasKey are gone, along with the alias check in checkFnTables. Every artifact is now emitted as its own function. Variants and registrations list their implementations best first #4682 removed the only duplicates.

TCB/Emit.lean:

  • Discovery deleted: the emitter no longer looks for variants and generic files (variantDir, genericDir, groupOf, grouped, variantOf, interfacesOf, genericGroups, allOf, varName, instances). Since Variants are lists; generic callers are ordinary registration files #4654, registration files apply generic callers to lists of variants themselves.
  • Driver: it lists each registration module's artifacts with the module's name. run checks that all the implementations of a function are in one registration file (checkSources), so their order there is the order the dispatcher tries them in.
  • qualifiedName stays as a naming helper; its uniqueness is checked by checkUnique.

Untrusted changes:

  • lean/Emit.lean and EmitOne.lean no longer pass groups of variants or generic files.
  • The golden tests (VerifiedGarbageTest/Dispatch.lean and Emit.lean) now check the list order, the never-chosen error, the signature and documentation check, checkSources, and table groups in list order.
  • The variant lists' documentation, CLAUDE.md, lean/README.md and the adding-a-primitive skill are updated.

Generated crates

Every dispatcher's documentation now says it tries its implementations "in the order its registration file lists them". Otherwise, what the dispatchers call is unchanged, except for five dispatchers on x86-64. Each of those chooses among implementations built from two variant lists, and now tries them by the first list, then the second:

Dispatchers Lists combined Order change Why no real CPU is affected
Ed25519's three functions SHA-512 × field arithmetic _shani is now tried before _avx2_ifma Every CPU with the SHA512 extensions has ADX, so it chooses _shani_adx first either way
AES-GCM's two streaming functions CTR × GHASH _vaes (VAES without VPCLMULQDQ) is now tried before _aesni_vpclmul No CPU has one of VAES and VPCLMULQDQ without the other

I compared every dispatcher with the base branch's; these five are the only differences. They choose the same implementation on every real CPU.

Checks

  • lake build, including the golden tests, passes.
  • Emit.lean passes, with every audit.
  • Every step of the Static checks job passes.
  • check_lean_public_imports.py passes.
  • cargo clippy --all-targets -- -D warnings, cargo fmt --check and cargo test pass.

Generated by Claude Code

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

This pull request has conflicts with main, found after 38dc6d8 landed on main: rebase it to resolve them. Before rebasing, see CLAUDE.md on checking how much Lean main changed, and on restacking a stacked pull request.

Posted by .github/workflows/conflicts.yml, once per push to a conflicting pull request.

…ists them

A dispatcher's implementations were the artifacts of a module whose names
extend the base's with `_<suffix>`, with its signature and documentation
(`Rust.groupsOf`), tried in the order the untrusted `Dispatch.lean` ranked
their suffixes, a suffix of several parts parsed back into ranked parts
(`partsOf`, `lexLe`). The emitter found the generic callers and variants
whose instances made those suffixes by their files' paths. Now:

* `Artifact.base` is the name of the function an artifact implements, its
  `Api`'s (`Api.artifact`; by default its own name), and a function's
  implementations are the artifacts of its base (`groupsOf`), each with
  the `Api`'s signature and documentation (`checkGroups`);
* its dispatcher tries them in the order its registration file lists
  them: every implementation of a function is in one registration file
  (`Emit.checkSources`, from the driver's list of each module's
  artifacts), and the tables of functions in the order the artifacts list
  them (`fnTables`, no longer sorted by name);
* one it would never choose (it needs every feature of one before it, or
  more) fails the emitter, rather than being left out (`armsOf`);
* the emitter no longer finds variants and generic files
  (`Emit.grouped`, `genericGroups`, `instances`, `allOf`: the
  registration files apply generic callers to lists of variants
  themselves), nor ranks suffixes (`Rank`, `rankOf`, `partsOf`, `lexLe`,
  `checkRanks` and `Dispatch.lean` are gone), nor emits an artifact as
  another name of one with the same code (`alias`, `sameKey`).

What the dispatchers call is unchanged but for five on x86-64, whose
implementations come from two lists (a caller of two variants' functions:
Ed25519's three functions, by SHA-512 and field arithmetic, and AES-GCM's
two streaming ones, by CTR and GHASH): they now try them by the first
list, then the second, which differs from the old order only between
implementations whose features no CPU tells apart (SHA-512's extensions
without ADX, VAES without VPCLMULQDQ). Every dispatcher's documentation
now says it tries them in the order its registration file lists them.

Part of #4548.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFjAR7Byf513R4zuFy
@alex
alex force-pushed the claude/vg-dispatch-by-api branch from c4cdac8 to abf6ffa Compare November 8, 2026 20:43
@alex
alex enabled auto-merge November 8, 2026 20:47
@alex
alex added this pull request to the merge queue Nov 8, 2026
Merged via the queue into main with commit e4c4e66 Nov 8, 2026
51 checks passed
@alex
alex deleted the claude/vg-dispatch-by-api branch November 8, 2026 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants