Skip to content

Commit 659af4a

Browse files
P1: fix Zig FFI to build and match the Idris2 ABI (#38)
`zig test src/main.zig -lc` failed to compile under Zig 0.14.0 with 9 "unused function parameter" errors. In Zig 0.14 an unused function parameter is a hard error; the leading-underscore naming convention does NOT exempt a parameter from the unused-parameter check. The affected stub functions were `futharkiser_compile`, `futharkiser_compile_file`, `futharkiser_execute`, and `futharkiser_transfer`. Fix (house idiom, per alloyiser exemplar): rename the underscore-prefixed parameters to plain names and discard them with `_ = name;` statements at the top of each function body. This keeps the not-yet-implemented stubs valid while preserving the exact C-ABI signatures. ABI conformance (Idris2 is the source of truth) is unchanged and verified: - All 14 `C:futharkiser_*` symbols in src/interface/abi/Futharkiser/ABI/Foreign.idr have a matching `export fn` (no missing, no extra). - The Result enum integer values (ok=0, error=1, invalid_param=2, out_of_memory=3, null_pointer=4, compilation_failed=5, backend_unavailable=6, shape_mismatch=7) match Types.idr `resultToInt` exactly. - Exported symbol names and arities are unchanged. Verification: - `zig test src/main.zig -lc` -> all 9 tests pass, 0 errors/warnings. - `idris2 --build futharkiser-abi.ipkg` -> exit 0. Only src/interface/ffi/src/main.zig was changed. Claude-Session: https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH Co-authored-by: Claude <noreply@anthropic.com>
1 parent 75388ef commit 659af4a

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

src/interface/ffi/src/main.zig

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,11 @@ export fn futharkiser_free(raw_handle: ?*anyopaque) void {
154154
/// Returns a kernel handle on success, or null on compilation failure.
155155
export fn futharkiser_compile(
156156
raw_handle: ?*anyopaque,
157-
_source: [*:0]const u8,
158-
_backend_id: u32,
157+
source: [*:0]const u8,
158+
backend_id: u32,
159159
) ?*anyopaque {
160+
_ = source;
161+
_ = backend_id;
160162
const handle: *FutharkiserHandle = @ptrCast(@alignCast(raw_handle orelse {
161163
setError("Null library handle");
162164
return null;
@@ -180,9 +182,11 @@ export fn futharkiser_compile(
180182
/// Compile a Futhark source file to a GPU kernel.
181183
export fn futharkiser_compile_file(
182184
raw_handle: ?*anyopaque,
183-
_file_path: [*:0]const u8,
184-
_backend_id: u32,
185+
file_path: [*:0]const u8,
186+
backend_id: u32,
185187
) ?*anyopaque {
188+
_ = file_path;
189+
_ = backend_id;
186190
const handle: *FutharkiserHandle = @ptrCast(@alignCast(raw_handle orelse {
187191
setError("Null library handle");
188192
return null;
@@ -205,9 +209,11 @@ export fn futharkiser_compile_file(
205209
/// Execute a compiled GPU kernel by entry-point name.
206210
export fn futharkiser_execute(
207211
raw_handle: ?*anyopaque,
208-
_kernel_handle: ?*anyopaque,
209-
_entry_point: [*:0]const u8,
212+
kernel_handle: ?*anyopaque,
213+
entry_point: [*:0]const u8,
210214
) Result {
215+
_ = kernel_handle;
216+
_ = entry_point;
211217
const handle: *FutharkiserHandle = @ptrCast(@alignCast(raw_handle orelse {
212218
setError("Null library handle");
213219
return .null_pointer;
@@ -302,10 +308,13 @@ export fn futharkiser_free_buffer(
302308
/// Transfer data between memory spaces (host <-> device).
303309
export fn futharkiser_transfer(
304310
raw_handle: ?*anyopaque,
305-
_src_handle: ?*anyopaque,
306-
_dst_handle: ?*anyopaque,
307-
_flags: u64,
311+
src_handle: ?*anyopaque,
312+
dst_handle: ?*anyopaque,
313+
flags: u64,
308314
) Result {
315+
_ = src_handle;
316+
_ = dst_handle;
317+
_ = flags;
309318
const handle: *FutharkiserHandle = @ptrCast(@alignCast(raw_handle orelse {
310319
setError("Null library handle");
311320
return .null_pointer;

0 commit comments

Comments
 (0)