Commit 55c3f365

55c3f365d345Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 5 files · ~5 modified

Description

compiler: convert the ffi_func registry from parallel arrays to an FfiFunc struct

The ffi_func declaration registry was a struct-of-arrays: five parallel arrays (mods/names/ret/args/nargs) grown in lockstep with five reallocs, indexed as ffi_func_names[i] at ~22 sites. Adding a field meant touching the struct, the grow block, and every access. Fold them into a single FfiFunc struct array: the grow is one realloc, accesses read ffi_funcs[i].name, and a new field is one struct member.

First of the six FFI registries (const/buf/reader/lib/cflag to follow). Pure internal refactor -- generated C is byte-for-byte identical across optcarrot, all benchmark/test inputs, and the FFI test programs.

Gates: 950 tests pass, optcarrot checksum 59662.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
55c3f365d345
Parent
e711be5c57f0

src/analyze_infer.cmodifiedView file

@@ -611,7 +611,7 @@
611611 rcmod = nt_str(nt, recv, "name");
612612 if (rcmod) {
613613 int fi = ffi_find_func(c, rcmod, name);
614- if (fi >= 0) return ffi_spec_to_ty(c->ffi_func_ret[fi]);
614+ if (fi >= 0) return ffi_spec_to_ty(c->ffi_funcs[fi].ret);
615615 /* ffi_buffer: Module.buf_name returns the static char* (ptr type -> TY_POLY) */
616616 if (ffi_find_buf(c, rcmod, name) >= 0) return TY_POLY;
617617 /* ffi_read_*: Module.reader_name(buf) returns int or ptr */