Skip to content

Facade: an fn item describing a producer also renders a safe lend method that exposes the raw out slot (Database.sqlite3_prepare_v2(…, ppStmt: *mut *mut sqlite3_stmt, …)) #1500

Closed

Description

@ehartford

Spec: §16.2b.3/§16.2b.4 (a resource's producer is its constructor), §16.2b.5 (a lend method borrows the resource), ruling §9 (never half-model).

Repro (modeled-C stage 6 branch, real sqlite3.h via with get c.sqlite3):

c facade sqlite:
    resource Database wraps *mut sqlite3
        from sqlite3_open(out param 1)
        drop sqlite3_close
        ok SQLITE_OK
    resource Statement wraps *mut sqlite3_stmt
        from sqlite3_prepare_v2(out param 3)
        drop sqlite3_finalize
        borrows param 0
    fn sqlite3_prepare_v2
        lend

The fn sqlite3_prepare_v2 / lend item is needed: without it the producer is "still a raw call after the facade covers its out parameter" (pzTail: const char ** is an undescribed raw pointer). With it, besides the constructor Statement.sqlite3_prepare_v2(db: &Database, zSql: str, nByte: c_int, pzTail: *mut *const i8) -> (c_int, Option[Statement]), the stage-4 lend renderer also emits a safe method on the parent:

fn Database.sqlite3_prepare_v2(zSql: str, nByte: c_int, ppStmt: *mut *mut sqlite3_stmt, pzTail: *mut *const i8) -> c_int

(with check --dump-typed). It hands C the caller's own out slot, so the statement it produces is an unowned raw handle that nothing finalizes: a second call surface for the producer that bypasses the resource (§16.2b.4: "one call surface per production form", D59) and leaks.

Expected: an fn item that describes a resource's producer (a from/init of any resource) is not also presented as a lend method; its lend (and preserves, etc.) describes the parameters of the constructor only. Or the facade needs a way to describe pzTail without lend — a ruling question for presentation (stage 8).

Found while implementing modeled-C stage 6; not fixed there (lend-method presentation is stage 4/8).

Activity

  1. ehartford commented on Sep 26, 2026

    @ehartford
    ContributorAuthor

    Already fixed on main by #1601 (modeled-C stage 8: facade_render_lend_item skips a producer that from covers, via facade_render_is_resource_op). Verified: the issue's facade renders the constructor only. A regression test pinning it is on the ruled-fixes stack layer.

  2. added 6 commits that reference this issue on Sep 27, 2026
    2323977
    45cb5a6
    07852b3
    b792f31
    9081ea8
    682b77a
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