P1: implement real Zig FFI matching the Idris2 ABI#39
Merged
Conversation
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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-codeResultenum matchingAlloyiser.ABI.Types.resultToIntexactly (ok=0…counterexample_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.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 —
analyzereports 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