Skip to content

Modeled C D66: discriminated variadic contracts, borrowed record views, and safe libcurl UAT - #1661

Merged
ehartford merged 5 commits into
sema-field-move-pathfrom
modeled-c-d66-curl
Sep 25, 2026
Merged

ehartford merged 5 commits into
sema-field-move-pathfrom
modeled-c-d66-curl

Conversation

@ehartford

@ehartford ehartford commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Implements D66 discriminated variadic contracts and borrowed record views, adds lib/facades/libcurl.w against the real curl header, and rewrites the libcurl release UAT under that ruling from eight unsafe blocks to zero.

Variadic clauses require a compile-time selector and explicitly listed integer or string cases. Sema selects the case and MIR materializes that decision; the generated bridge preserves the C variadic ABI. String cases use a call-scoped NUL-terminated temporary. Unlisted, runtime, pointer, and callback cases without the necessary contracts fail with diagnostics.

Borrowed record returns become Option[&T], with parameter or domain origins propagated through existing lifetime and invalidation checks. Pointer fields remain raw until field-level contracts are defined; static record returns remain rejected. typedef void H is translated as a c_void alias so opaque C handles match their resource representation.

The libcurl facade models Easy ownership, nine setopt cases, borrowed version records, and static version/error strings. Callback and retained variadic options remain tracked in #1652. The four release UAT fixtures contain no unsafe; the full user-programs-safe gate is still red on the recovered tally example, pending free-function callbacks (#1644) and element-count buffers (#1643). This PR does not rewrite that example to bypass the gate.

Part 2 of the GitHub stack: #1656 → #1661 → #1662. The field-path record fix belongs to #1656. This layer retains one marked copy of actual_options.output_path so the pinned seed can compile the stack; remove it after a seed cut containing #1656.

Iterate verification passed the D66/libcurl behavior, compile-error, and allocator fixtures, resolution audits, specification inventory, and the libcurl UAT. The corrected stack at 974c8ba passed the full seed-driven build, fixpoint (16 units), drop audit (213 cells), move audit (105 cells), full test suite, test-green, and last-green. The singleton-sort panic found by the first battery is fixed in #1662; its final verdict table is posted there.

Other findings remain tracked: #1653 header translation, #1654 build input freshness, and #1655 view invalidation on returning branches.

@ehartford

Copy link
Copy Markdown
Contributor Author

Facade fixture sweep with this branch's seed-built stage1 (out/bootstrap/bin/with-stage1 test <explicit file list>; --filter does not narrow the walk, see the wall-clock note):

Battery (:fixpoint, :test, audits) not run per the brief; draft until it is posted.

Eric Hartford added 5 commits September 24, 2026 19:17
…cade's `resource Easy wraps *mut CURL` must name the type the translated declarations spell

ci_translate_typedef rendered a void typedef as an alias of Unit while every
`H *` parameter and return in the same translation is `*mut c_void`, so
`*mut CURL` (the header's own spelling) never matched curl_easy_init's
return or curl_easy_setopt's first parameter: "producer 'h_new' returns
*mut c_void, not the representation". The alias is c_void — an incomplete
object type C uses only through pointers — and FacadeRender's alias chasing
follows a true c_void alias (it stopped at any target rendering as c_void,
a guard meant for `= opaque`, which is its own declaration kind and never
in the alias loop). Exercised by behav_libcurl_facade_setopt.w and the
libcurl UAT (D66).
…ted by param P:` with `case CONST: <type>`) and borrowed record views (`returns borrow T from domain D | from param N`)

Spec §16.2b.5 "Discriminated variadic contracts" and §16.2b.6 "Borrowed
record views" (D66). Parser: the variadic clause with its indented cases; a
callback case and a retained case are refused naming #1652. Sema: the fn
must be variadic, N its variadic position, P an earlier integer or enum
parameter, each case an imported integer constant with a distinct value and
an integer C type or `str` (a pointer case is refused with the two
contracts it lacks); a call's selector must be a compile-time constant (an
integer literal or an imported constant no local shadows) naming a listed
case — otherwise the refusal names the case to add and the raw variadic
function, which stays raw and available under `unsafe`. Render: one method
or function per case, `<name>__<CONST>`, calling the declaration — still
variadic to the backend — with the case's argument typed as the case
states (`str` as a call-scoped NUL-terminated copy, §16.3c); Sema
retargets the presented call to the case its selector picks (check_call
chooses, lower_method_call/lower_call materialize; D65). Record views:
`returns borrow T` for a c_import struct T, from a resource parameter or a
declared domain, renders `Option[&T]` — a lend method with the declared
view summary, or a free bridge reached under the C name — whose scalar
fields are readable, whose pointer fields stay raw, and which the origin's
invalidating operations end; `static` stays CStr-only. Bridges of free
operations now carry the raw operation's call effects (domains touched,
domain borrowed).

Fixtures: ulimit's UL_SETFSIZE long crossing a real variadic ABI and read
back; every refusal; localeconv's record from a domain and a resource-backed
record view, its invalidation by domain and by lend, outliving its origin,
a pointer field used as text needing unsafe.
…h — Easy (init/cleanup), setopt case by case, the version record as a borrowed view of the version_info domain, curl_version and curl_easy_strerror static text (D66)

Every clause cites the manual sentence it relies on. The callback pairing
(CURLOPT_WRITEFUNCTION/WRITEDATA) and the retained CURLOPT_POSTFIELDS are
left out (#1652): raw under unsafe until the pairing is modeled.
curl_easy_perform presents its CURLcode (`ok` projects a producer or a
copied-back length, not a plain operation). Threads are not granted (the
manual spells `send` but not drop-any-thread). Fixtures: the UAT surface
plus every case kind against the host library without a transfer; an
unlisted option refused with the case to add; the version view invalidated
by curl_global_cleanup; handles cleaned up once under the debug allocator.
…e` to 0 (ruling §66); the release UAT copies lib/facades/libcurl.w into the project as the other three do

Same observable output ("libcurl UAT passed"): global init, an Easy handle
scoped to configure_handle so it is cleaned up before curl_global_cleanup,
CURLOPT_NOSIGNAL through the variadic contract, the version number read
through the borrowed record's scalar field, the version text through
curl_version().
…he pinned seed carries the 16-bit field-path bug (#1631) that #1656 fixes, and must still compile this tree; retire with the next seed cut
@ehartford
ehartford changed the base branch from main to sema-field-move-path September 24, 2026 23:18
@ehartford
ehartford added this pull request to stack #1664 September 24, 2026 23:18
@ehartford ehartford changed the title Modeled C D66: discriminated variadic contracts, borrowed record views; libcurl facade; libcurl UAT at zero unsafe — user-programs-safe green Modeled C D66: discriminated variadic contracts, borrowed record views, and safe libcurl UAT Sep 25, 2026
@ehartford
ehartford marked this pull request as ready for review September 25, 2026 01:42
@ehartford
ehartford merged commit d71f6e2 into main Sep 25, 2026
@ehartford
ehartford deleted the modeled-c-d66-curl branch September 25, 2026 03:32
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