Repository navigation
spec: retained variadic pairs — abandon, setter status contract, retained borrows (D66, #1652) - #1688
Merged
Merged
Conversation
… retained borrows, implied userdata setter (D66, #1652) Eric's ruling on the #1652 brief, landed as spec text: a resource names its safe abandonment path with `abandon <op>` (the op must be `callbacks none`; the compiler runs it before the destroyer on every drop path whose pair state is not proven callback-free); `ok CONST` on a variadic operation is the status contract of its listed cases, presentation unchanged; retained userdata is a borrow typed from the callback's own parameter mode, exclusive when the callback mutates it, held by the resource and ending at reset, destruction or the last callback-capable operation, with the resource ephemeral for that window; the paired userdata setter is implied by the callback case while `retains by param 0` stays explicit. The decision log records the two-model debt: the borrow is the target, stage 9's owned box is the legacy form.
ehartford
pushed a commit
that referenced
this pull request
Sep 25, 2026
…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).
ehartford
added a commit
that referenced
this pull request
Sep 26, 2026
…contract, pair setters, MIR pair-state flow (D66, #1652) (#1679) * Modeled C: callback state contracts and checked dataflow foundation (#1652) * Track callback pair state through distinct resource places and aliases * parser: honor return inference for public functions 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. * Propagate callback resource state and retained origins across control flow * Modeled C: retained variadic callback pairs — abandon path, setter status 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). * libcurl facade: the write callback pair and abandon curl_easy_reset; 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. * tests: retained variadic pair fixtures; docs: pair-state implementation 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. * tests: contract views carry the per-operation callbacks row (§16.2b.9, #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. --------- Co-authored-by: Eric Hartford <[email protected]>
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.
Docs-only; spec-inventory-check passed. Lands Eric's 2026-09-25 ruling on the #1652 brief (all four points approved, with the retained-borrow mode/window additions and the abandon-clause conditions) as §16.2b.5/§16.2b.9 text and a D66 amendment, plus the D65 debt note that the variadic borrow is the target model for retained userdata and stage 9's owned box is legacy. The compiler is NON-COMPLIANT until #1679 implements it.