Repository navigation
Modeled C stage 12: the SQLite facade against the real header (ruling §66) - #1619
Merged
Merged
Conversation
added 2 commits
September 24, 2026 09:35
… §66) lib/facades/sqlite3.w: the first complete facade written under the ruling, against the sqlite3.h c_import resolves on the host, covering every §66 item: Database over *mut sqlite3 (sqlite3_open out param 1, ok SQLITE_OK, drop sqlite3_close, destroys sqlite3_close_v2, thread creator), Statement as a dependent child (sqlite3_prepare_v2 out param 3, borrows param 0, drop sqlite3_finalize), errmsg and column_text as borrowed text (Option[CStr]), step/reset invalidating column views with `preserves` where sqlite3.h guarantees it (each sentence quoted), sqlite3_exec's callback with typed userdata, sqlite3_create_function_v2 consuming pApp destroyed_by xDestroy and retaining xFunc/xStep/xFinal, presentation (Database.open, db.exec, stmt.column_text) with `rename prepare` as the explicit override. Location derived from spec §16.2b.1 and §18.5: project source space under lib/facades, not lib/std (the toolchain publishes no facade beyond libc's); it moves into c.sqlite3 when the package can carry it. What the real header exposed in the facade language, fixed here: - `returns borrow CStr` refused `const unsigned char *` (*const u8), sqlite3_column_text's spelling of the same bytes (SemaFacade). - A facade's rendered surface is now `pub` (FacadeRender), so a facade module exports its resources; a c_import type in a pub signature is not the module's private type (SemaDecl module_private_type). - A `null` argument takes its pointer type from the parameter through methods and generic fns as through plain calls (SemaCheck null_arg_expected_type): `db.prepare(sql, -1, null)`. - A statement produced through the parent's presented method (`db.prepare`) escaped its database's scope: the receiver method's signature is found by qualified text (SemaFacade facade_producer_sigs). - A C parameter named `N` rendered as a pattern; facade parameter names are escaped as the c_import wrappers escape them (p_N).
…stroy-once under the debug allocator behav_sqlite_facade_end_to_end.w runs every §66 item against the real library with no unsafe; err_sqlite_facade_* pin the column view used after step, the statement outliving its database, and capturing closures as exec's and create_function_v2's callbacks; err_c_facade_child_outlives_parent_via_receiver.w pins the receiver form the dependency summary missed; da_sqlite_facade_destroy_once.w witnesses xDestroy running exactly once on every path.
ehartford
force-pushed
the
modeled-c-stage12
branch
from
September 24, 2026 13:35
9de5731 to
5295cc0
Compare
Contributor
Author
|
Battery green — stack #1616 (main → #1614 stage 10 → #1615 stage 13 → #1619 stage 12), top 5295cc0 on main 2c7ed44, pinned seed, cold c_import cache, audits included: Also in this stack (stage 13 layer): the Ready to merge: |
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.
D51 stage 12 — the gate for every example rewrite (§66: "The SQLite facade must compile and typecheck before … are rewritten against the new surface").
lib/facades/sqlite3.wis written against the realsqlite3.handbehav_sqlite_facade_end_to_end.wruns every §66 item against the real library with nounsafe. Nothing underbuild/release_uat_fixtures/,examples/or docs is touched; those rewrites are the next PR.§66 item by item
sqlite3owned pointer resourceresource Database wraps *mut sqlite3sqlite3_openout-parameter productionfrom sqlite3_open(out param 1)SQLITE_OKok SQLITE_OK→Result[Database, DatabaseError]DatabaseError.FailedWithResource(status, FailedDatabase); closed when the error drops (doc sentence quoted in the facade)sqlite3_close/sqlite3_close_v2drop/destroys(db.close_v2()consuming)sqlite3_stmtdependent childresource Statement … borrows param 0sqlite3_prepare_v2/sqlite3_finalizefrom …(out param 3)/dropsqlite3_errmsgreturns borrow CStr from param 0→Option[CStr]view of the connectionsqlite3_column_textNone(fixture asserts both)step/reset/column_intstate nothing (invalidate);preserves param 0oncolumn_count,column_type,column_byteswith the sqlite3.h sentences quoted; pinned byerr_sqlite_facade_column_text_after_step.wsqlite3_exec:callback param 2 userdata param 3sqlite3_create_function_v2:consumes param 4 destroyed_by param 8(da_sqlite_facade_destroy_once.w: xDestroy runs exactly once on every path)retains param 5/6/7 by param 0; capturing closures refused (err_sqlite_facade_*_captures.w)thread creatoron both, with the reasonsend/shareare not granted (the mode is a build/open-time choice the header does not prove)Database.open,db.exec,db.errmsg(),db.prepare,stmt.step(),stmt.column_text()…rename prepare(plusrenameon the statement ops, see #1610)Left raw (findings, filed)
sqlite3_context/sqlite3_valueare callback-scope handles (§44) the language has no form for, sosqlite3_result_*,sqlite3_value_*,sqlite3_user_dataneedunsafe. The fixture's function sets no result.sqlite3_errmsgon a failed open'sFailedDatabase: no clause marks an operation valid on the failure state (§16.2b.4 names the notion, the language has no spelling).sqlite3_execwith no callback: the pairing cannot mark the callback optional.sqlite3_mprintf: out of scope (ruling pending).What the real header exposed, fixed here
*const u8C strings; a facade's rendered surface ispub(so the facade is its own module) and a c_import type in a pub signature is not private;nullas a method / generic-fn argument takes its parameter's type; a statement produced throughdb.prepare(…)escaped its database's scope (the receiver method's signature was not found when the dependency summary was applied —err_c_facade_child_outlives_parent_via_receiver.w);Nas a C parameter name. Also filed: #1609 (bare fn →extern "C" fnthrough a generic parameter; the fixture uses a typed local), #1610 (library-prefix presentation), #1617 (pre-existing static-fn-through-instance codegen failure, found while probing).Derived decision
Facade location:
lib/facades/sqlite3.w— project source space per §16.2b.1/§18.5 (toolchain publishes no facade beyond libc's;c.sqlite3is Conan and ships none), reachable from every fixture asuse facades.sqlite3through thelib/module root; notlib/std, which the compiler embeds.Verification
with build :devgreen;with-stage1 checkon the facade and every fixture; the new behavior fixture runs against the system sqlite3 and matches; compile_errors sweep over allerr_c_facade_*+ new: 121/121 + 5/5;run --debug-allocon the new lane fixture:leak count=0. No:fixpoint/:test/audits (battery by the coordinator). Under this facadebuild/release_uat_fixtures/sqlite3_main.wneeds 0 of its current 11unsafe(every op it uses is modeled; itsexec(…, null, null, null)becomes a no-op callback until #1618).