You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Facade: calls through function-pointer fields (allocator hooks, dispatch tables) are the largest raw cluster: 1648 functions in 14 libraries #3206
Part of #3115. From the survey on main 4cf358b (docs/spec/toolchain/facade-coverage.md): the largest cluster of raw verdicts is 'retains a parameter, passed through a function pointer field no unit decides': 1648 functions in 14 libraries, plus the return side ('returns what the function pointer field X returns', #3172).
Until #3172/#3174 these read as proofs by coincidence of names: a struct field named free was taken for libc's free (pcre2's memctl->free, libssh2's session->free), a field named like a function for that function (SDL's jump_table.SDL_X, glfw's _glfw.platform.setWindowTitle). Law 4 forbids that, so pcre2 went 6 → 0 presented, libssh2 10 → 3, yyjson 9 → 1, sdl 549 → 493, cjson stays 0 of 79.
Two shapes, with different answers:
1. Dispatch tables the package fills itself (SDL dynapi's jump_table, glfw's _glfw.platform, libuv/libevent backends). Every store to the field in the corpus is a named function of the package (a static initializer or an assignment). That is provable without a name: the callee is one of a closed set, and the verdict is the join over the set (retains if any retains; returns owned only if all do). No grammar needed. The open question is soundness of the closed-world reading: a store the corpus does not show (a memcpy of the table, a cast, a platform file this host does not configure) would make the join wrong. Needs Eric's ruling (safety): is 'every store to this field in the package's units names a package function, and the field's address never escapes' evidence enough?
2. Allocator and hook fields the user may replace (pcre2 memctl, yyjson alc, cJSON_Hooks, libpng malloc_fn, libssh2 alloc/free, libxml2's xmlMalloc globals already handled as aliases). The default is libc's malloc/free but a parameter can replace it, so no proof exists. This needs a stated fact: either the library's own annotation (libpng's PNG_ALLOCATED now proves its producers, #3205), or a registry/facade clause that says 'field F of record R is this library's allocator / deallocator' (#3150, #3151). Needs Eric's ruling on the clause (facade grammar, §16.2b).
Shape 1 is implementable today behind the ruling; shape 2 decides whether pcre2, yyjson, cjson and libssh2 can present anything at all.
Decision brief for Eric (no spec words proposed; draft only)
The gap. 1648 functions in 14 libraries are raw because a parameter is passed to, or a value returned from, a call through a function-pointer field. Until #3172/#3174 these read as proofs by coincidence of names.
Two facts first (D110/D111). What the callee does with the argument is unknown at the call: the callee is whatever the field holds. So the question is who can be in the field. Two shapes:
A. A table the package fills itself (SDL's jump_table, glfw's _glfw.platform, libuv/libevent backends). Every store to the field in the package's units names a package function.
B. A hook the user may replace (pcre2 memctl->malloc/free, yyjson alc, cJSON_Hooks, libssh2 session->alloc/free, libpng malloc_fn/error_fn). The default is libc's; a parameter can install anything.
1. What the others do (verified in .reference/). Go's cgo does not call C function pointers at all (cmd/cgo/doc.go: "Calling C function pointers is currently not supported"). Swift, Zig and Rust's bindgen import the field as a function-pointer value and prove nothing about it. None reads the C bodies, so none faces this question: it arises because With proves ownership from source (§16.2b.15).
2. What the spec says. §16.2b.15 item 1: the toolchain "proves facts without names". Item 2 lists the annotations a library ships (__attribute__((malloc)), …). Item 3: the registry, "for what neither proof nor annotations settle". §16.2b.2 orders them: clause, proof, annotations, registry, profile, default. §16.2b.9 models callbacks With hands to C; nothing models a function pointer the library calls through its own struct. The existing allocator rule is narrow: a global initialized to an allocator is one (D121, libxml2's xmlFree = free).
3. Mission fit. Law 4: retention, destruction and ownership are never inferred from a name; a proof or a stated fact only. Shape A is a proof question (is a closed-world reading of the stores sound?). Shape B has no proof by construction, so it is a stated-fact question (which form states it?).
4. Prediction (one, committed).
A: accept the closed-world proof, with two conditions. The verdict is the join over every function stored to that field in the package's units (retains if any does; owned return only if all are). Conditions: every store names a package function, and the field's address never escapes. A unit this host could not read makes the field unproven, and the report says which. This is the D121 global-alias rule extended from "a global initialized to an allocator" to "a field only ever assigned known functions". 70%. The risk you would weigh: a store the corpus does not show (a memcpy of the table, a platform file not configured) makes the join wrong, and wrong here is unsafe.
B: a registry fact, not a new inference. One line per library in registry/c/<lib>/facts.w states that a named field of a named record is that library's allocator or deallocator, with the upstream citation; the proofs then treat calls through it as allocation and free. The library's own annotation already proves the common case where it exists (libpng's PNG_ALLOCATED, Facade evidence: attributes are also read from Clang's AST; a package function annotated malloc is an allocator call #3205). No default from the field's name, ever. 80%. This needs a clause in the facts grammar, so the words are yours.
Error handlers and progress callbacks (libpng's error_fn, xz's progress): the argument is handed to the user's callback. I predict you treat that as §16.2b.9 territory (the callback's contract decides), not as either shape above. 60%; this is the part I am least sure of.
Nothing here is delegable (C interop, safety). Shape A is implementable in the drafter once ruled; shape B unblocks pcre2, yyjson, cjson and libssh2, which present almost nothing without it.
Ruled by Eric, 2026-11-09 (D198, #3211). Shape A: the closed-world proof is refused; a function-pointer field's callee set is proven only when the field is written in exactly one place, that place is a constant initializer or a single assignment of a named package function, and the containing struct is never passed by address to a function outside the set the drafter can read. Anything else is a registry fact (glfw's static platform table proves; SDL's dynamically filled jump table is a facts line). Shape B: granted; the facts grammar gets field alloc of Record is allocator / is deallocator, cited, and a hook's setter is marked as mutating the library's state domain so borrows from allocations under the old hooks are invalidated (spec words still to be written). Error/progress callbacks: §16.2b.9 as written; a C library invoking a user hook inside an API call makes that call reentrant with respect to the hook's captures. Implementing shape A's narrowed proof now.
Draft wording for blessing (D198, shape B; nothing below is implemented or merged)
§16.2b.15, the facts file (item 3), draft addition:
A facts file may state that a function-pointer field is the library's allocator or deallocator:
field malloc of pcre2_memctl is allocator // cite: pcre2api(3), "MEMORY MANAGEMENT"
field free of pcre2_memctl is deallocator
A call through an allocator field returns a fresh allocation the caller owns; a call through a deallocator field destroys its argument. The fact is never drawn from the field's name. A function that sets such a field (a hook setter) is a mutation of the library's state domain (§16.2b.7): every borrow that depends on an allocation made before the call is invalidated by it. The draft marks the setters it can prove (a function whose body assigns the field from a parameter); a setter it cannot prove is stated in the facts file.
§16.2b.9, one sentence: a library that invokes a registered callback from inside one of its operations makes that operation reentrant with respect to the callback's captures.
Open point: whether one line may state both (fields malloc, free of R are allocator, deallocator), and whether the per-record context pointer the hooks take (memory_data) needs stating.
Shape A is implemented (#3212, main 0210440) and measured. No field in the 22 drafted libraries meets the ruled conditions, so the totals are unchanged (7863 functions, 1748 presented). The reports now name the condition that failed, which is what a facts line has to state:
why the field's callee is unproven
functions
libraries
the record is passed to a function the proofs cannot read (memset, an indirect call)
1462 (+50 on the return side)
11
an initializer or a field's address the proofs cannot map
85
3
written in several places (glfw's Cocoa and null tables, libarchive's formats)
74 (+10)
9
its one write is not a named function
58
4
a pointer to the record is converted to another type
43
5
a unit of the package could not be read
43
2
the package never writes it (the caller's value)
3
1
The first row is dominated by records the library zeroes with memset before filling. If you want that case provable, the rule would need 'memset of the whole record before the one write' as an enumerated exception; as ruled it is an escape. Everything else waits on shape B's facts clause (draft wording above).
Words blessed by Eric and landed as spec v7.43 (D198's amendment). The draft above is superseded: keep the clause words (reads / fills / updates param N); resource R in T is dropped (the in-place form already exists); fills beside a status follows §16.2b.4 (Result[T, E] with ok, (status, T) without); nothing is made non-movable; one field per facts line; the hooks' context pointer is stated (field F of R is context). The compiler is NON-COMPLIANT until it implements them; implementation starts now.
Needs Eric: shape 1 (dispatch tables the package fills itself) is the brief on #3174, with the measured split (1138 functions wait on 'a record passed to a call through a field whose callee set is closed', 84 on 'several writers'). Shape 2 (allocator hooks) is ruled. Nothing here moves until that ruling.
Shape 1 is ruled on #3174 (both extensions, gated on a measuring build; holds deferred). Nothing separate to answer here; this waits on #3174's implementation.
Activity
#3174: a call through an explicitly dereferenced function-pointer fie…
#3174: a call through an explicitly dereferenced function-pointer fie…
ehartford commentedon Nov 10, 2026
Decision brief for Eric (no spec words proposed; draft only)
The gap. 1648 functions in 14 libraries are raw because a parameter is passed to, or a value returned from, a call through a function-pointer field. Until #3172/#3174 these read as proofs by coincidence of names.
Two facts first (D110/D111). What the callee does with the argument is unknown at the call: the callee is whatever the field holds. So the question is who can be in the field. Two shapes:
jump_table, glfw's_glfw.platform, libuv/libevent backends). Every store to the field in the package's units names a package function.memctl->malloc/free, yyjsonalc, cJSON_Hooks, libssh2session->alloc/free, libpngmalloc_fn/error_fn). The default is libc's; a parameter can install anything.1. What the others do (verified in
.reference/). Go's cgo does not call C function pointers at all (cmd/cgo/doc.go: "Calling C function pointers is currently not supported"). Swift, Zig and Rust's bindgen import the field as a function-pointer value and prove nothing about it. None reads the C bodies, so none faces this question: it arises because With proves ownership from source (§16.2b.15).2. What the spec says. §16.2b.15 item 1: the toolchain "proves facts without names". Item 2 lists the annotations a library ships (
__attribute__((malloc)), …). Item 3: the registry, "for what neither proof nor annotations settle". §16.2b.2 orders them: clause, proof, annotations, registry, profile, default. §16.2b.9 models callbacks With hands to C; nothing models a function pointer the library calls through its own struct. The existing allocator rule is narrow: a global initialized to an allocator is one (D121, libxml2'sxmlFree = free).3. Mission fit. Law 4: retention, destruction and ownership are never inferred from a name; a proof or a stated fact only. Shape A is a proof question (is a closed-world reading of the stores sound?). Shape B has no proof by construction, so it is a stated-fact question (which form states it?).
4. Prediction (one, committed).
memcpyof the table, a platform file not configured) makes the join wrong, and wrong here is unsafe.registry/c/<lib>/facts.wstates that a named field of a named record is that library's allocator or deallocator, with the upstream citation; the proofs then treat calls through it as allocation and free. The library's own annotation already proves the common case where it exists (libpng's PNG_ALLOCATED, Facade evidence: attributes are also read from Clang's AST; a package function annotated malloc is an allocator call #3205). No default from the field's name, ever. 80%. This needs a clause in the facts grammar, so the words are yours.error_fn, xz's progress): the argument is handed to the user's callback. I predict you treat that as §16.2b.9 territory (the callback's contract decides), not as either shape above. 60%; this is the part I am least sure of.Nothing here is delegable (C interop, safety). Shape A is implementable in the drafter once ruled; shape B unblocks pcre2, yyjson, cjson and libssh2, which present almost nothing without it.
D198: a proof about C is accepted only when the drafter can enumerate…
ehartford commentedon Nov 10, 2026
Ruled by Eric, 2026-11-09 (D198, #3211). Shape A: the closed-world proof is refused; a function-pointer field's callee set is proven only when the field is written in exactly one place, that place is a constant initializer or a single assignment of a named package function, and the containing struct is never passed by address to a function outside the set the drafter can read. Anything else is a registry fact (glfw's static platform table proves; SDL's dynamically filled jump table is a facts line). Shape B: granted; the facts grammar gets
field alloc of Record is allocator/is deallocator, cited, and a hook's setter is marked as mutating the library's state domain so borrows from allocations under the old hooks are invalidated (spec words still to be written). Error/progress callbacks: §16.2b.9 as written; a C library invoking a user hook inside an API call makes that call reentrant with respect to the hook's captures. Implementing shape A's narrowed proof now.D198 (#3206): a function-pointer field's callee is proven only when t…
ehartford commentedon Nov 10, 2026
Draft wording for blessing (D198, shape B; nothing below is implemented or merged)
§16.2b.15, the facts file (item 3), draft addition:
§16.2b.9, one sentence: a library that invokes a registered callback from inside one of its operations makes that operation reentrant with respect to the callback's captures.
Open point: whether one line may state both (
fields malloc, free of R are allocator, deallocator), and whether the per-record context pointer the hooks take (memory_data) needs stating.D198 (#3206): a function-pointer field's callee is proven only when t…
ehartford commentedon Nov 10, 2026
Shape A is implemented (#3212, main 0210440) and measured. No field in the 22 drafted libraries meets the ruled conditions, so the totals are unchanged (7863 functions, 1748 presented). The reports now name the condition that failed, which is what a facts line has to state:
memset, an indirect call)The first row is dominated by records the library zeroes with
memsetbefore filling. If you want that case provable, the rule would need 'memset of the whole record before the one write' as an enumerated exception; as ruled it is an escape. Everything else waits on shape B's facts clause (draft wording above).ehartford commentedon Nov 10, 2026
Words blessed by Eric and landed as spec v7.43 (D198's amendment). The draft above is superseded: keep the clause words (
reads/fills/updates param N);resource R in Tis dropped (the in-place form already exists);fillsbeside a status follows §16.2b.4 (Result[T, E]withok,(status, T)without); nothing is made non-movable; one field per facts line; the hooks' context pointer is stated (field F of R is context). The compiler is NON-COMPLIANT until it implements them; implementation starts now.ehartford commentedon Nov 18, 2026
Needs Eric: shape 1 (dispatch tables the package fills itself) is the brief on #3174, with the measured split (1138 functions wait on 'a record passed to a call through a field whose callee set is closed', 84 on 'several writers'). Shape 2 (allocator hooks) is ruled. Nothing here moves until that ruling.
Contract report names destroyers for unproduced records; survey reads…
A call through a constant table of named functions reaches exactly th…
A null store writes no function: one table leaving a field NULL no lo…
ehartford commentedon Nov 25, 2026
Ruled by Eric, 2026-11-25 (answers to briefs.md).
Shape 1 is ruled on #3174 (both extensions, gated on a measuring build;
holdsdeferred). Nothing separate to answer here; this waits on #3174's implementation.