Skip to content

A function-pointer field the package fills: several writers join, and a record handed through a closed field stays proven (D211) - #3470

Merged
ehartford merged 5 commits into
mainfrom
d211-fnptr-fields
Nov 19, 2026
Merged

ehartford merged 5 commits into
mainfrom
d211-fnptr-fields

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Part of #3206 and #3174 (D211, ruled by Eric 2026-11-18). It does not close them: the field F of R holds f, g clause is new grammar and comes as a spec diff, and see the measurement below.

The ruling, implemented in the drafter (fd_draw_fnptr_verdicts) and the C evidence (ci_fnptr_field_evidence):

  • Several writers. A field written in several places, each with a named function of the package, holds that set. A parameter is retained if any member retains it (the report names the member); it is destroyed, and a return is owned, only if every member agrees.
  • A record handed to a call through such a field has not left the proofs once that field's set is closed. The verdicts are a fixed point: a record that leaves closes none of its fields, which can make another leave; the closed set only shrinks.
  • A whole-record assignment is a write to every function-pointer field. It is followed when its value is a package variable that is not a parameter, a choice between two such, or an initializer list; a record reached through a pointer, returned by a call or received as a parameter may hold what a caller wrote, and the record then leaves the proofs. (Before this, such an assignment was invisible, so a table copied from a caller's pointer read as proven.) memcpy already failed as an unreadable callee.

A fourth fix, found measuring glfw. A record named by a typedef before its struct is defined (typedef struct T T;) answered with that first, field-less declaration, so every designated initializer of it "mapped to no field". Fields are now read from the definition (with_ci_type_declaration).

Measured, with get --from-source over the sixteen libraries that build here, functions presented safely: glfw 30 → 31, raylib 459 → 473, the other fourteen unchanged. glfw's remaining 39 wait on something outside D211: the functions its platform table can hold are defined in Objective-C units on macOS, which the proofs do not read, so the set does not close on this target.

Tests. conan_facade_fnptr_field_proof_test gains five cases: two writers that both only read (now a lend), two writers one of which keeps its argument (retained, member named), a table handed through a closed field, a table assigned whole from a caller's pointer, and the typedef-before-struct table. tools/facade_coverage.w knows the new reasons.

Battery green on the branch tip; :release-checks green.

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.

1 participant