Repository navigation
Modeled C D64: buffer pairing and fixed arguments; zlib and bzip2 facades; their UAT fixtures at zero unsafe (#1621, #1624) - #1645
Merged
Conversation
ehartford
force-pushed
the
modeled-c-d64-buffers
branch
from
September 24, 2026 17:30
0a12cb2 to
c682c9e
Compare
ehartford
force-pushed
the
modeled-c-d64-buffers
branch
from
September 24, 2026 17:32
c682c9e to
0345089
Compare
ehartford
marked this pull request as ready for review
September 24, 2026 18:50
added 8 commits
September 24, 2026 14:51
…ut]`) and fixed arguments (`param N fixed <literal>`); the unpaired-pointer refusal; Vec/array coerce to slices in method calls (#1621, #1624) Spec §16.2b.8 "Buffers" and §16.2b.11 "Fixed arguments" (D64). Parser: the two clauses, `capacity` without `inout` and `len … inout` refused. Sema: the pointer must point at bytes, the length be an integer (inout: a mutable pointer to one), both distinct and paired once; a fixed literal must be a value of the C parameter's type; `ok CONST` on an fn item is the status contract a copied-back length is presented under (refused without an inout pairing; an inout pairing on a status-returning fn is refused without it); the ruling's refusal — a raw pointer parameter no clause pairs on a lend/presented item names the parameter and the clauses to add; a paired or fixed parameter never makes the raw call safe. Render: one `[]u8` / `[]mut u8` per pairing, the bridge `capacity = dest.len; C(dest.ptr, &capacity, …); check capacity <= dest.len; capacity as usize`, presented as `usize` (void) or `Result[usize, <Fn>Error]` (ok), the caller's slice untouched, a too-large length a panic naming the operation and the length. A hosted lend renders as before with the bridge; a free operation renders as `__with_facade_<name>` (or its `rename`) and a call to the C name is redirected to it where the rendering is visible (SemaCheck/MirLower), so the raw declaration stays what C declared and the bridge's own body calls it. Method calls gain the #604 Vec/array → []T/[]mut T coercion the free call path had (the hosted `n.read(buf)` needed it).
…lice; Sema accepted the cast and the validator refused it (D64: a str is the bytes a buffer pairing takes)
…lite3_exec fixes errmsg null (D64 §16.2b.11); db.prepare(sql) and db.exec(sql, cb, ud) in the fixtures
…/uncompress and BZ2_bzBuffToBuffCompress/Decompress as buffer pairs under ok Z_OK / ok BZ_OK, zlibVersion static text; roundtrip fixtures at zero unsafe
…e 3 -> 0 and 3 -> 0, same output; the UAT copies lib/facades/<lib>.w into the fresh project as src/facades/<lib>.w (ruling §66)
…s a resource's own operations and callback contracts to their renderings; a producer's fixed argument is the constructor's literal (not raw-beyond, not forwarded by the receiver method); WITH_DUMP_FACADE=1 prints the rendered text err_c_facade_uncovered_return_stays_raw now lends `db_count` on a `Db` resource: under D64 a `lend` on a bare `db *` no resource wraps is the refusal (err_c_facade_lend_unpaired_buffer), so the stage-3 fixture keeps its point (an undescribed pointer return stays raw) through a resource.
…rameters and names the D64 clauses; the D64 refusal covers the handle no resource wraps; `nullable` returns after collecting (the merge had dropped it) 12b's verify_facade_buffer_params names a caller-owned byte or scalar buffer (its fixture err_c_facade_lend_unpaired_buffer keeps that text); the D64 pass refuses the record handle no resource wraps under a presentation clause (err_c_facade_rename_unpaired_buffer). One parameter, one diagnostic.
…so it applies to c_import translations only — the runtime's own extern seams carry stage 13's domain rows (rt_libc_write, rt_libc_mmap, …) and render nothing
ehartford
force-pushed
the
modeled-c-d64-buffers
branch
from
September 24, 2026 18:51
b3e2e0f to
b50b5e4
Compare
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 D64 (spec §16.2b.8 "Buffers", §16.2b.11 "Fixed arguments"; #1621, #1624) on top of the modeled-C stack (base:
modeled-c-uat-rewrite).Compiler
buffer param P len param L,buffer param P capacity param L inout,param N fixed <literal>(capacitywithoutinoutandlen … inoutare parse errors; a fixed literal is an int,null,true/false).SemaFacade.w): P points at bytes (char/unsigned char/void/typedefs), L is an integer (inout: a mutable pointer to one), distinct, paired once, never also fixed; a fixed literal is a value of the C type (null↔pointer, int↔int, no negative into unsigned, never a resource-receiving param);ok CONSTon an fn item is the status contract of a copied-back length (refused without an inout pairing; an inout pairing on a status-returning fn is refused withoutok;returns …+ inout refused); generated<Fn>Errorname clash check. The refusal: 12b'sverify_facade_buffer_params(byte/scalar buffers) now skips paired/fixed parameters and its help names the D64 clauses; the D64 pass refuses a record handle no resource wraps under a presentation clause. A paired/fixed parameter never makes the raw C call safe (facade_covers_param).FacadeRender.w): one[]u8/[]mut u8per pairing; the bridge is exactly Eric's:capacity = dest.len; C(dest.ptr, &capacity, src.ptr, src.len); check capacity <= dest.len; capacity as usize— presented asusize(void C fn) orResult[usize, <Fn>Error](ok), on success only; the caller's slice is untouched; a too-large length is a panic naming the operation and the length. Hosted lends keep their&selfmethod; a free operation renders as__with_facade_<name>(or itsrename) and a call to the C name is redirected to it wherever the rendering is visible (SemaCheck.check_call→facade_bridge_redirect,MirLower.lower_call), so the raw declaration stays what C declared (the bridge's own body calls it; a module importing the header without the facade keeps the raw op).WITH_DUMP_FACADE=1prints the rendered facade text (a<facade NAME>:line:coldiagnostic points into it).[]T/[]mut Tcoercion in method calls ([]mut T stages 2–3: local bindings, returns, and split_at_mut #604 had only free calls);s as []u8validates in MIR (Sema accepted it, the validator refused).Facades
lib/facades/sqlite3.w:sqlite3_prepare_v2param nByte fixed -1/param pzTail fixed null;sqlite3_execparam errmsg fixed null. Resulting spellings:db.prepare(sql),db.exec(sql, None, None),db.exec(sql, Some(cb), Some(&ctx)).lib/facades/zlib.w(compress/uncompress as buffer pairs underok Z_OK,zlibVersionstatic text) andlib/facades/bzip2.w(BZ2_bzBuffToBuffCompress/Decompress underok BZ_OK), each clause citing the manual.UAT (ruling §66)
zlib_main.w3 unsafe → 0,bzip2_main.w3 → 0, same output; the release UAT copies the facade into the fresh project assrc/facades/<lib>.w(mirrors #1625).:user-programs-safenow lists onlylibcurl_main.w(8). libcurl needs:curl_easy_init/cleanupas a resource (from/drop),curl_easy_setopt(variadic — not modelable),curl_version_inforeturning a struct pointer whose fields are read (a borrowed record view — not ruled).Fixtures
5 behavior (input pair, inout+ok+rename+void, bounds panic, fixed int/null free+hosted, hosted lend pairs), 2 roundtrip twins of the UAT programs,
behav_method_slice_coercion, 22 compile_errors. Facade sweep on this stage1: 202 pass; the 4z_initfixtures (production_local_names,resource_in_place_{arming,drop_once,pinned}) fail identically on the stack head (Stream.z_initnow presents asStream.init) — not this layer.Verification
with check src/main.wok;:devgreen;:spec-inventory-checkgreen;analyze audit:allon the D64 fixtures: 0 violations. No:fixpoint/:test.Filed
#1632 (
v[..]on a Vec lowers to Unit), #1633 (str.as_bytes()missing;s as []u8is the route), #1634 (stage1 from main rejects src/main.w:2991), comment on #1137 (==on[]u8compares by address). Pre-existing: #1485 (memchr), the*_warnsfixtures need the pre_d_build runner.Derived decisions
__with_facade_<name>, not by shadowing (a facadepub fn compresswould hijack a header's inline helpers that callcompress, and a translated inline C function has no link symbol to alias).renamegives a distinct presented name.okon an fn item is accepted only with acapacity … inoutpairing (nothing else is ruled to present on success).