Repository navigation
Modeled C: retained variadic callback pairs — abandon, setter status contract, pair setters, MIR pair-state flow (D66, #1652) - #1679
Merged
Conversation
ehartford
force-pushed
the
modeled-c-retained-variadic
branch
from
September 25, 2026 17:34
a57c64f to
278e0da
Compare
ehartford
force-pushed
the
modeled-c-retained-variadic
branch
from
September 25, 2026 17:38
278e0da to
aa7eba4
Compare
ehartford
changed the base branch from
modeled-c-element-buffers
to
public-return-foundation
September 25, 2026 17:41
ehartford
changed the base branch from
public-return-foundation
to
josh/float-round-trip
September 25, 2026 18:06
ehartford
changed the base branch from
josh/float-round-trip
to
public-return-foundation
September 25, 2026 18:06
ehartford
force-pushed
the
modeled-c-retained-variadic
branch
2 times, most recently
from
September 25, 2026 19:07
abd3ff5 to
4821959
Compare
ehartford
force-pushed
the
modeled-c-retained-variadic
branch
from
September 25, 2026 19:08
4821959 to
0dc4b32
Compare
added 4 commits
September 25, 2026 17:49
Specification 9.1 and D43 do not exempt public functions from inference. Remove the unsupported visibility-based parser rejection and replace its negative test with public value/Unit/method/generic/import regressions. Keep a mixed-tail rejection test and correct the formatter plan's claim. The callback-state helpers do not need public method visibility; remove the redundant Unit annotations added to accommodate the parser error. Root-cause proof: out/public-return-parser-proof.log, LLDB stopped in Parser.parse_fn_decl at Parser.w:1318 with is_pub=1 and ret_type=0. The missing annotation took the unconditional public-only diagnostic. Validation: pinned-seed source check and :dev pass. The four targeted public-return tests pass with rebuilt stage1; foreign-pair place tests also pass with inferred helper returns. Full stack battery is pending.
added 3 commits
September 25, 2026 18:36
…atus contract, pair setters, and the MIR pair-state flow (D66, #1652) Implements the 2026-09-25 ruling (spec §16.2b.5, §16.2b.9; #1688). - `abandon <fn>` on a resource: the safe abandonment of partial callback setup. Sema verifies it is the resource's own operation, takes only the representation and is itself `callbacks none`; the rendered Drop runs it before the destroyer on every drop path. - `ok CONST` on a variadic operation is the status contract of its listed cases (presentation unchanged); MIR reads `status == OK` / `!= OK`, through a binding or a copy, as the setter's success or failure edge. - A callback case (`callback param N as T userdata param CONST retains by param 0`) renders `mut fn <base>__<CB>[U](…, value: <T with &U>)` and the implied userdata setter `mut fn <base>__<UD>[U](…, value: &U)`; retention is stated, never inferred (a case without it is refused). A callback-only setter binds `U` from the callback's own signature, and a named fn is checked against its own signature as a C function pointer (§12.4). - Sema registers every operation of a resource with a pair under the concrete signature MIR records on the call (FacadePairOp): setters per specialization with a canonical `U` (a closure literal's per-literal fn type is interned structurally), the abandon op as the reset, destroyers, and every other operation as callback-capable unless `callbacks none`. - MirForeignPairs.w runs the ForeignPairState.w place flow over each lowered body's CFG: setters and their status edges, borrows (a projection through a reference local is that local), moves, resource births at call results, drops, escapes into the return place or an aggregate, and unmodeled helper calls (checked, then unknown until a reset). Findings are reported in the body's own file: an operation that may invoke an unproven pair, a retained userdata that dies or moves while held (at the setter that retained it), a retaining resource that escapes. WITH_DUMP_PAIR_FLOW=1 prints every fact the flow ran on. - ForeignPairState.w gains the unknown-operation transfer and the escape check the adapter needs. The pass collects findings through a report record rather than moving them between Vecs with into_iter: #1689 (a returned Vec of a three-str record yields its last element at every position under into_iter).
…the UAT transfers a file through it (D66, #1652) `curl_easy_setopt` states `callbacks none` and `ok CURLE_OK`, and lists `case CURLOPT_WRITEFUNCTION: callback param 2 as curl_write_callback userdata param CURLOPT_WRITEDATA retains by param 0`; `curl_easy_reset` is the handle's `abandon` path, `callbacks none` bounded to the modeled option set (the MIME freefunc path is documented); `curl_easy_cleanup` stays callback-capable. Every clause quotes its manual page. The release UAT program follows the spec change (§66; the D66 amendment of 2026-09-25): it transfers a local file through the modeled pair — `file://`, no network, no `unsafe` — counting the bytes the callback receives, with the sink declared before the handle so it outlives it.
…on notes (#1652) Runtime, against the real library: the pair over a file:// transfer, and the ruling's required acceptance case (first setter succeeds, second fails with the real variadic ABI, the function returns an error, Drop resets then cleans up). Check-only: the accepted shapes. Compile errors: an incomplete pair, an unhandled setter failure, a userdata dying while held, a retaining resource returned, a helper leaving the pair unknown, `abandon` naming a callback-capable operation, a callback case without retention. The unlisted-option fixture moves to CURLOPT_READDATA, since the pairing now implies CURLOPT_WRITEDATA.
ehartford
force-pushed
the
modeled-c-retained-variadic
branch
from
September 25, 2026 22:36
0dc4b32 to
93ddd18
Compare
…#1652) The contract audit now states each operation's callback capability with its provenance (`callbacks none`, or the conservative default); the three contract-view expectations gain that row.
Contributor
Author
|
Battery verdict — green. Driven by the pinned seed
The first run was red on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements Eric's 2026-09-25 ruling on retained variadic callback pairs (D66 amendment, spec §16.2b.5 and §16.2b.9, landed in #1688) — #1652.
What lands
abandon <op>on a resource: the safe abandonment path. Sema verifies it is the resource's own operation, takes only the representation, and is itselfcallbacks none; the rendered Drop runs it before the destroyer on every drop path (a spurious reset costs one call, a missed one is unsafe).ok CONSTon a variadic operation: the status contract of its listed cases, presentation unchanged; MIR reads a comparison of the returned code against it (through a binding or a copy) as the setter's success/failure edge.case CONST: callback param N as T userdata param CONST2 retains by param 0rendersmut fn <base>__<CONST>[U](…, value: <T with its void * as &U>), and the paired userdata settermut fn <base>__<CONST2>[U](…, value: &U)is implied by the pairing (no secondcaseline). Retention is stated, never inferred: a callback case withoutretains byis refused. A callback-only setter bindsUfrom the callback's own signature; a named fn coerces to theextern "C"type (§12.4).FacadePairOp): setters per specialization with their canonicalU(a closure literal's per-literal fn type is interned structurally), the abandon op as the reset, destroyers, and every other operation as callback-capable unlesscallbacks none— including the other cases of the same setter, so two-call setup requirescallbacks noneon the setter (§16.2b.9).MirForeignPairs.w: after lowering, before codegen, theForeignPairState.wplace flow runs over each body's real CFG — setters and their status edges, borrows (including projections through a reference local), moves, resource births at call results, drops, returns/stores as escapes, and unmodeled helper calls (checked as callback-capable, then unknown until a reset). Violations are diagnostics in the body's own file: an operation that may invoke an unproven pair; a retained userdata that dies or moves while held (reported at the setter that retained it); a retaining resource returned or stored.WITH_DUMP_PAIR_FLOW=1prints every fact the flow ran on.lib/facades/libcurl.w:abandon curl_easy_reset,callbacks noneandok CURLE_OKoncurl_easy_setopt,callbacks noneoncurl_easy_reset(bounded to the modeled option set; the MIMEfreefuncpath is documented), and theCURLOPT_WRITEFUNCTION/CURLOPT_WRITEDATAcase. The release UAT program transfers a local file through the modeled pair (no network, nounsafe), under the D66 amendment (§66: the facade first, then the validation artifact).Evidence (branch stage1, this worktree)
test/behavior/behav_libcurl_facade_callback_pair.wagainst the real library:written: true / fetched: true / ok,--debug-allocleak count 0.test/behavior/behav_libcurl_facade_callback_pair_failure.w— the ruling's required acceptance case with the real variadic ABI: first setter succeeds, second fails (test facade pairs the callback withCURLOPT_LASTENTRY), the function returns an error, Drop resets then cleans up:first: true / second: false / configured: false / ok, leak count 0.test/behavior/behav_c_facade_variadic_callback_pair_check.w(check-only): either setup order, a reset between runs, a helper handed a proven pair, a sink read between the setter and the run, early returns after a first successful setter — accepted.abandonnaming a callback-capable op, a callback case without retention, the unlisted-option refusal moved toCURLOPT_READDATA(the pairing now impliesCURLOPT_WRITEDATA).behav_libcurl_facade_setopt,behav_c_facade_retained_callback,_callback_scope,_free_callback,_variadic_free,_callbacks_none) unchanged and passing.Not modeled (refused conservatively, documented in
docs/modeled-c-pair-state-plan.md): interprocedural pair summaries for helpers; closure literals as the callback (pass a named fn); the retained pointer case (CURLOPT_POSTFIELDS); reading a chunk's bytes inside a write callback (itschar *stays raw until a callback buffer clause is ruled — counts are safe today).Status: draft until the pinned-seed battery is green and posted here.