Skip to content

P1: fix Zig FFI to compile and match the Idris2 ABI#39

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

P1: fix Zig FFI to compile and match the Idris2 ABI#39
hyperpolymath merged 1 commit into
mainfrom
claude/new-session-1fphit

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Summary

src/interface/ffi/src/main.zig did not compile under Zig 0.14.0. This PR fixes it with two minimal, FFI-only changes. The Idris2 ABI (src/interface/abi/Anvomidaviser/ABI/Foreign.idr + Types.idr) is the source of truth and is unchanged.

Fixes

  1. Syntax error (expected statement, found ';', ~line 288): the if (!h.initialized) { ... } block at the end of anvomidaviser_get_string was terminated with a stray ;. An if used as a statement takes no trailing semicolon, so the }; after the block body was parsed as an empty statement. Removed the spurious semicolon.

  2. Handle was a Zig opaque {} with fields: it was declared pub const Handle = opaque { allocator, initialized } but then instantiated (handle.* = .{...}) and field-accessed (h.allocator, h.initialized). Zig opaque types are unsized and cannot hold or expose fields, so this could never compile once the parser passed the syntax error. Changed Handle to a concrete struct, matching the house idiom in alloyiser's exemplar (its Model struct). It is still only ever handed to C as a pointer, so it remains opaque across the C ABI.

ABI alignment (preserved)

  • Every C:anvomidaviser_* symbol in Foreign.idr has a matching export fn (19/19).
  • Result enum integer values match Types.idr's resultToInt exactly: ok=0, error=1, invalid_param=2, out_of_memory=3, null_pointer=4, rule_violation=5.
  • No exported symbol names or result codes were changed.

Verification

  • cd src/interface/ffi && zig test src/main.zig -lc → all 3 tests pass, 0 errors/warnings.
  • cd src/interface/abi && idris2 --build anvomidaviser-abi.ipkg → exit 0 (build dir removed afterward).

Note: any rust-ci / Hypatia / governance red checks are pre-existing estate-infrastructure issues unrelated to this Zig-only change.

🤖 Generated with Claude Code

https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH


Generated by Claude Code

The Zig FFI reference implementation (src/interface/ffi/src/main.zig)
failed to compile under Zig 0.14.0. Two fixes, both confined to the FFI
layer; the Idris2 ABI remains the source of truth.

1. Syntax error (the reported `expected statement, found ';'`): the
   `if (!h.initialized) { ... }` block at the end of
   anvomidaviser_get_string was terminated with a stray `;`. An `if`
   used as a statement takes no trailing semicolon, so the `};`
   following the block body was parsed as an empty statement. Removed
   the spurious semicolon.

2. `Handle` was declared as a Zig `opaque {}` type but given fields
   (`allocator`, `initialized`) and instantiated with `handle.* = .{...}`
   plus field access (`h.allocator`, `h.initialized`). Zig `opaque`
   types are unsized and cannot hold or expose fields, so this could
   never compile once the parser advanced past the syntax error.
   Changed `Handle` to a concrete `struct`, matching the house idiom
   in alloyiser's exemplar (its `Model` struct). It is still only ever
   handed to C as a pointer, so it stays opaque across the C ABI.

No exported C symbol names changed and no Result codes changed: every
`C:anvomidaviser_*` symbol in Foreign.idr still has a matching
`export fn`, and the Result enum integer values (ok=0, error=1,
invalid_param=2, out_of_memory=3, null_pointer=4, rule_violation=5)
match Types.idr's resultToInt exactly.

Verification:
- zig test src/main.zig -lc  -> all 3 tests pass, 0 errors/warnings
- idris2 --build anvomidaviser-abi.ipkg  -> exit 0

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:08
@hyperpolymath hyperpolymath merged commit d7b0fa0 into main Jun 26, 2026
20 of 22 checks passed
@hyperpolymath hyperpolymath deleted the claude/new-session-1fphit branch June 26, 2026 22:09
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