Skip to content

P1: align Zig FFI symbol names to the Idris2 ABI#39

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

P1: align Zig FFI symbol names to the Idris2 ABI#39
hyperpolymath merged 1 commit into
mainfrom
claude/new-session-1fphit

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Problem: ABI ↔ FFI symbol-name drift

The Idris2 ABI in src/interface/abi/Chapeliser/ABI/Foreign.idr is the source of truth for the C-ABI contract. It declares 12 foreign symbols via %foreign "C:c_*, libchapeliser_ffi":

c_init, c_shutdown, c_get_total_items, c_load_item, c_store_result, c_process_item, c_process_chunk, c_reduce, c_is_match, c_key_hash, c_checkpoint_save, c_checkpoint_load

The Zig FFI reference implementation in src/interface/ffi/src/main.zig instead exported these as chapeliser_ref_<stem>. The functions correspond 1:1 by stem and the Result codes already matched, but the symbol names diverged, so the ABI and FFI would not link — every c_* import the ABI declares would resolve to an undefined symbol.

Fix (Zig-only; ABI unchanged because it is the source of truth)

  • Renamed the 12 ABI-declared exports from chapeliser_ref_<stem> to exactly c_<stem> in src/interface/ffi/src/main.zig.
  • The two extra utility functions (version, build_info) are not part of the ABI, so they are namespaced as chapeliser_version / chapeliser_build_info rather than given c_ names.
  • Updated all internal call sites in main.zig tests and the extern fn declarations in src/interface/ffi/test/integration_test.zig to match.

No behaviour or result-code values changed. Only files under src/interface/ffi/ were touched.

Verification

  • zig build test (main.zig unit tests, 7/7): pass
  • zig build test-integration (links the shared lib, so the test's extern decls resolve against the renamed exports): pass
  • idris2 --build chapeliser-abi.ipkg: exit 0
  • Cross-check: every C:c_<name> in Foreign.idr now has a matching export fn c_<name> in main.zig; no chapeliser_ref_ references remain.

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

🤖 Generated with Claude Code

https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH


Generated by Claude Code

The Idris2 ABI in src/interface/abi/Chapeliser/ABI/Foreign.idr is the
source of truth for the C-ABI contract. It declares 12 foreign symbols
via `%foreign "C:c_*, libchapeliser_ffi"`:

  c_init, c_shutdown, c_get_total_items, c_load_item, c_store_result,
  c_process_item, c_process_chunk, c_reduce, c_is_match, c_key_hash,
  c_checkpoint_save, c_checkpoint_load

The Zig FFI reference implementation exported these as
`chapeliser_ref_<stem>` instead. The functions correspond 1:1 by stem
and the Result codes already match, but the symbol names diverged, so
the ABI and FFI would not link (every `c_*` import would be undefined).

Fix (Zig-only, ABI unchanged because it is the source of truth):
  - Rename the 12 ABI-declared exports from `chapeliser_ref_<stem>` to
    exactly `c_<stem>` in src/interface/ffi/src/main.zig.
  - The two extra utility functions (`version`, `build_info`) are NOT
    part of the ABI, so they are namespaced as `chapeliser_version` and
    `chapeliser_build_info` rather than given `c_` names.
  - Update all internal call sites in main.zig tests and the
    `extern fn` declarations in test/integration_test.zig accordingly.

No behaviour or result-code values changed.

Verification:
  - `zig build test` (main.zig unit tests): pass
  - `zig build test-integration` (links the lib, resolves externs): pass
  - `idris2 --build chapeliser-abi.ipkg`: exit 0
  - Every `C:c_<name>` in Foreign.idr now has a matching
    `export fn c_<name>` in main.zig.

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 095e38a into main Jun 26, 2026
28 of 30 checks passed
@hyperpolymath hyperpolymath deleted the claude/new-session-1fphit branch June 26, 2026 22:08
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