Skip to content

Commit 6d88377

Browse files
hyperpolymathclaude
andcommitted
docs(abi): honest marker for generated/abi/ gap
generated/abi/ is reserved for an Idris2 -> C header pipeline that does not exist yet. The Zig FFI at ffi/zig/src/main.zig is hand-maintained in parallel with the Idris2 ABI; this commit makes that fact legible rather than aspirational: - generated/abi/README.adoc: RESERVED marker + gap analysis + plan. - ffi/zig/src/main.zig: header comment no longer cites non-existent src/abi/Foreign.idr / src/abi/Types.idr; now names the actual .idr modules the FFI mirrors and points at generated/abi/README.adoc. Closes the "ABI/header pipeline" Track B investigation. The pipeline itself is deferred — it is a multi-session undertaking either as a reflection-based Idris2 tool or a dedicated codegen plugin. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f295131 commit 6d88377

2 files changed

Lines changed: 77 additions & 2 deletions

File tree

ffi/zig/src/main.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// TYPED_WASM FFI Implementation
22
//
3-
// This module implements the C-compatible FFI declared in src/abi/Foreign.idr
4-
// All types and layouts must match the Idris2 ABI definitions.
3+
// This module is the C-compatible Zig FFI surface. Types and result codes
4+
// are hand-maintained in parallel with the Idris2 ABI spread across
5+
// src/abi/{Region,TypedAccess,Pointer,Effects,Lifetime,Linear,
6+
// MultiModule}.idr and src/abi/Layout/*.idr. There is no automated
7+
// Idris2 -> C header pipeline yet; see generated/abi/README.adoc for the
8+
// gap analysis and the plan for closing it.
59
//
610
// SPDX-License-Identifier: PMPL-1.0-or-later
711

generated/abi/README.adoc

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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

Comments
 (0)