|
| 1 | +// SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | +// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> |
| 3 | += generated/abi/ — Auto-generated C headers (reserved) |
| 4 | + |
| 5 | +:status: RESERVED — not yet populated |
| 6 | +:last-reviewed: 2026-04-18 |
| 7 | + |
| 8 | +== Intent |
| 9 | + |
| 10 | +Per the hyperpolymath ABI/FFI standard (see `~/.claude/CLAUDE.md`): |
| 11 | + |
| 12 | +[cols="1,1,3"] |
| 13 | +|=== |
| 14 | +| Layer | Language | Purpose |
| 15 | + |
| 16 | +| ABI | Idris2 | Interface definitions with formal proofs |
| 17 | +| FFI | Zig | C-compatible implementation |
| 18 | +| Headers | C (generated) | Bridge between ABI and FFI |
| 19 | +|=== |
| 20 | + |
| 21 | +`generated/abi/` is the standard home for the C headers the Idris2 ABI |
| 22 | +should emit and the Zig FFI should consume. When the pipeline is live, |
| 23 | +`zig build` in `ffi/zig/` will depend on a fresh generation step that |
| 24 | +walks `src/abi/**/*.idr` and emits matching `.h` files here. |
| 25 | + |
| 26 | +== Current state (2026-04-18) |
| 27 | + |
| 28 | +**No pipeline exists yet.** The 21 Idris2 `.idr` modules in `src/abi/` |
| 29 | +define types, predicates, and theorems but do not emit C headers. |
| 30 | +`ffi/zig/src/main.zig` is hand-maintained in parallel with the Idris2 |
| 31 | +definitions; the comment at `main.zig:3` citing `src/abi/Foreign.idr` |
| 32 | +and `src/abi/Types.idr` points at files that do not exist — the real |
| 33 | +ABI is spread across `Region.idr`, `TypedAccess.idr`, `Pointer.idr`, |
| 34 | +`Effects.idr`, `Lifetime.idr`, `Linear.idr`, `MultiModule.idr`, and |
| 35 | +the `Layout/*.idr` aggregate. |
| 36 | + |
| 37 | +== Why it is a gap worth closing |
| 38 | + |
| 39 | +Until the pipeline is live, every change to an Idris2 type must be |
| 40 | +manually mirrored in Zig. That divergence is the single most common |
| 41 | +source of FFI bugs in the estate — the hand-written Zig side drifts |
| 42 | +from the proven Idris2 side. A real generator would: |
| 43 | + |
| 44 | +. Walk each `src/abi/**/*.idr` module declaring foreign-visible types |
| 45 | +. Emit a matching `generated/abi/<Module>.h` with |
| 46 | + `struct`/`enum`/`typedef` definitions |
| 47 | +. Be reproducible (byte-for-byte identical across runs) |
| 48 | +. Fail the Zig build when `generated/abi/` is stale relative to `src/abi/` |
| 49 | + |
| 50 | +== Why it is deferred |
| 51 | + |
| 52 | +Idris2's built-in C backend (`idris2 --cg rts`) produces implementation |
| 53 | +bodies rather than header surfaces. A real header generator would need |
| 54 | +either: |
| 55 | + |
| 56 | +* a small reflection-based tool that pattern-matches on top-level |
| 57 | + `data` and `record` declarations and emits matching C, or |
| 58 | +* a dedicated Idris2 codegen plugin that targets `.h` output only. |
| 59 | + |
| 60 | +Both options are multi-session undertakings. The first is the lighter |
| 61 | +option and is the recommended starting point when the pipeline is next |
| 62 | +prioritised. |
| 63 | + |
| 64 | +== Tracking |
| 65 | + |
| 66 | +* `AI-WORK-todo.md` §2 Track B lists "ABI/header pipeline" as an open |
| 67 | + item — it remains open as of this file's creation. |
| 68 | +* `PROOF-NEEDS.md` carries the verification-side story; the header |
| 69 | + pipeline is the runtime/FFI counterpart. |
| 70 | +* Nothing currently imports from `generated/abi/`, so marking this |
| 71 | + directory `RESERVED` does not break any build. |
0 commit comments