Skip to content

P1: implement real Zig FFI matching the Idris2 ABI#39

Merged
hyperpolymath merged 1 commit into
mainfrom
claude/new-session-1fphit
Jun 26, 2026
Merged

P1: implement real Zig FFI matching the Idris2 ABI#39
hyperpolymath merged 1 commit into
mainfrom
claude/new-session-1fphit

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

What & why

The Zig FFI (src/interface/ffi/src/main.zig) was an unrendered scaffold: it still contained literal {{project}} template tokens, so it could not compile, and its generic functions/result codes bore no relation to alloyiser's domain ABI. Nobody had ever compiled the Zig side or checked it against the Idris2 ABI (kickoff P1).

Change

Rewrote the FFI as a self-contained reference implementing exactly the 17 C-ABI functions declared in src/interface/abi/Alloyiser/ABI/Foreign.idr — model lifecycle, sig/field/fact/assertion construction, analyze, counterexample retrieval, .als/JSON serialisation, and version/build-info/error helpers — with the 8-code Result enum matching Alloyiser.ABI.Types.resultToInt exactly (ok=0counterexample_found=7).

The Idris2 ABI is the source of truth: every C symbol name, arity, and result-code value derives from it.

Verification

  • zig test src/main.zig -lc → 2/2 tests pass under Zig 0.14.0.
  • Symbol/result-code cross-check: fns 17 → MATCH, rc VALUES-MATCH.
  • idris2 --build alloyiser-abi.ipkg → still type-checks clean.

Assertion solving (the JVM/Alloy Analyzer bridge) remains future work — analyze reports no counterexamples. First of the P1 wave (unrendered-template FFIs).

CI note

The rust-ci / Hypatia / governance checks are pre-existing estate-infra reds unrelated to this change (Zig FFI only).

🤖 Generated with Claude Code

https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH


Generated by Claude Code

The Zig FFI was an unrendered scaffold — it still contained literal
`{{project}}` template tokens (so it could not compile) and its generic
functions/result codes bore no relation to alloyiser's domain ABI.

Rewrite src/interface/ffi/src/main.zig as a self-contained reference that
implements exactly the 17 C-ABI functions declared in
src/interface/abi/Alloyiser/ABI/Foreign.idr (model lifecycle, sig/field/
fact/assertion construction, analyze, counterexample retrieval, .als/JSON
serialisation, version/build-info/error helpers), with the 8-code Result
enum matching Alloyiser.ABI.Types.resultToInt exactly (0..7). The Idris2
ABI is the source of truth; symbol names, arity, and result-code encodings
all derive from it.

Builds and tests clean under Zig 0.14.0 (zig test src/main.zig -lc); the
Idris2 ABI still type-checks. Assertion solving (the JVM/Alloy Analyzer
bridge) remains future work — analyze reports no counterexamples.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH
@hyperpolymath hyperpolymath marked this pull request as ready for review June 26, 2026 22:01
@hyperpolymath hyperpolymath merged commit ec9c6a9 into main Jun 26, 2026
20 of 22 checks passed
@hyperpolymath hyperpolymath deleted the claude/new-session-1fphit branch June 26, 2026 22:01
hyperpolymath added a commit that referenced this pull request Jun 26, 2026
)

## What & why

The FFI implementation PR (#39) inadvertently committed
`src/interface/ffi/.zig-cache/` build artifacts — a `git add -A` was run
after a local `zig test`. That includes a ~3.5 MB compiled test binary
that does not belong in version control.

## Change

- `git rm --cached` the three tracked `.zig-cache/` files (removed from
the repo; ~7 MB of binaries gone).
- Add `.zig-cache/` (and `**/.zig-cache/`) to `.gitignore` so transient
Zig build output is never committed again.

No source changes; the FFI code from #39 is untouched.

## CI note
The `rust-ci` / `Hypatia` / governance checks are pre-existing
estate-infra reds unrelated to this change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH

---
_Generated by [Claude
Code](https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH)_

Co-authored-by: Claude <noreply@anthropic.com>
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.

2 participants