Skip to content

Facade presentation: trailing raw arguments the C contract makes optional (prepare(sql, -1, null), exec(…, null)) stay on the presented method — ceremony the facade should remove #1624

Closed

Description

@ehartford

Found by the ruling §66 example rewrite (build/release_uat_fixtures/sqlite3_main.w, docs/with_for_ai.md). What the application writes today:

let Ok(stmt) = db.prepare("SELECT value FROM t", -1, null) else: …
db.exec("CREATE TABLE …", None, null)        // #1618 for the callback
  • sqlite3_prepare_v2(db, zSql, nByte, ppStmt, pzTail): the presented prepare takes nByte (-1 = "read up to the first NUL" — the facade already passes a NUL-terminated &str, so the compiler knows the length) and pzTail: *mut *mut i8 ("If pzTail is not NULL then *pzTail is made to point to the first byte past the end of the first SQL statement") — a raw out slot the program declines with null.
  • sqlite3_exec(…, char **errmsg): "If errmsg is not NULL then any error message is written into memory obtained from sqlite3_malloc()" — the same raw out slot, declined with null.

Both are spellings the compiler already knows (the length of the text it marshals; that the program did not ask for the tail/errmsg), so per the mission they are ceremony. Proposal: an fn-item clause for a declinable raw out slot (e.g. optional param 4 → omitted from the presented method, NULL passed; a program wanting the tail spells the raw call), and nByte-style length parameters derived from the marshalled text (length param 2 of param 1). Related: #1500 (the raw out slot exposed on the lend rendering), #1618 (nullable callback).

Activity

  1. ehartford commented on Sep 24, 2026

    @ehartford
    ContributorAuthor

    Ruled (Eric 2026-09-24; §16.2b.11 "Fixed arguments" / D64): param N fixed <literal> binds a C parameter to a literal and removes it from the presented signature; the raw operation stays available. Not default — it is not an optional argument. Implementation in the next modeled-C batch.

  2. ehartford commented on Sep 24, 2026

    @ehartford
    ContributorAuthor

    Another instance from examples/c-interop (PR #1640): sqlite3_bind_text(stmt, i, text, -1, SQLITE_TRANSIENT). With fn sqlite3_bind_text / lend in the project's facade the method renders as stmt.bind_text(1, "abc", -1, <destructor>), but the sentinel cannot be passed: SQLITE_TRANSIENT ((sqlite3_destructor_type)-1, imported as a global of type extern "C" fn(*mut c_void) -> Unit) is refused with wrong argument type in call to 'Statement.bind_text' … parameter 'p4' expects extern "C" fn(*mut c_void) -> Unit / actual type: extern "C" fn(*mut c_void) -> Unit (the same types, so this is the #1609 coercion class on the rendered method), and let transient: extern "C" fn(*mut c_void) -> Unit = SQLITE_TRANSIENT is type mismatch in binding. Only a typed local of a real fn compiles — which would be the wrong contract (SQLITE_STATIC/a no-op destructor keeps the borrowed str pointer past the call).

    The honest facade spelling is D64's param 4 fixed SQLITE_TRANSIENT — the only safe value under a lend of the text — and it is not implemented on the modeled-c stack yet (unknown facade clause 'param'). Until it lands the example binds an integer and its README says why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions