Commit 382de76
committed
P1: fix Zig FFI to build and match the Idris2 ABI
The Zig FFI in src/interface/ffi/src/main.zig failed `zig test src/main.zig
-lc` under Zig 0.14.0 and one test asserted behaviour the ABI contract does
not provide.
Errors found:
1. Compile error: `array_list.ArrayListAligned` no longer exposes
`popOrNull`. `oblibeniser_undo_pop` called `h.undo_stack.popOrNull()`,
which does not exist in Zig 0.14.0.
2. Test failure: the "compute and verify inverse" test finalised the
operation with a null (0) post-snapshot pointer, so `post_snapshot`
stayed null and `oblibeniser_compute_inverse` correctly returned
`not_reversible` (per its contract: an inverse needs both pre- and
post-state snapshots). The test asserted `ok`, so it failed.
Fixes:
1. Replaced `popOrNull()` with `pop()`, which in Zig 0.14.0 already returns
an optional (`?T`); the `orelse` empty-stack handling is unchanged.
2. Updated the test to record with a real pre-state snapshot and finalise
with a real post-state snapshot, then assert `ok` for compute_inverse and
additionally verify_inverse. This exercises the documented contract
instead of weakening the FFI logic.
The Idris2 ABI (src/interface/abi/Oblibeniser/ABI/Foreign.idr + Types.idr)
remains the source of truth: every `C:<name>` symbol still has a matching
`export fn`, and the Result enum integer values (Ok=0 .. InverseProofFailed=7)
are unchanged and match resultToInt.
Verification:
- `zig test src/main.zig -lc` -> all 7 tests pass, zero errors/warnings.
- `idris2 --build oblibeniser-abi.ipkg` -> exit 0.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH1 parent 74d25e3 commit 382de76
1 file changed
Lines changed: 17 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
447 | | - | |
| 447 | + | |
448 | 448 | | |
449 | 449 | | |
450 | 450 | | |
| |||
601 | 601 | | |
602 | 602 | | |
603 | 603 | | |
604 | | - | |
605 | | - | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
606 | 617 | | |
607 | 618 | | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
608 | 622 | | |
609 | 623 | | |
610 | 624 | | |
| |||
0 commit comments