Skip to content

Modeled C stage 10: with analyze contract view (ruling §63) - #1614

Merged
ehartford merged 3 commits into
mainfrom
modeled-c-stage10
Sep 24, 2026
Merged

ehartford merged 3 commits into
mainfrom
modeled-c-stage10

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Stage 10 of the modeled-C campaign (docs/modeled-c-implementation-plan.md "Stage 10"; ruling §63, §2.3; spec §16.2b.2, §18.5). Based on main, not on stage 9 (#1606).

What lands

  • ForeignContract fact kind (AnalysisFactKind.ForeignContract = 25, foreign-contract) and a collector in analysis_collect_sema (src/AnalysisContract.w). One subject row per resource, fn item, domain, callback parameter and use convention; under it one row per effective fact: production and initialization state, status convention, automatic and alternate destroyers, dependency/independence, thread capabilities, the views borrowed from a resource and the operations that invalidate or preserve them; per fn item each parameter's effect (lend, consumes [+ destroyed_by], retains-by, destroys, out-slot, callback-scope borrow), the result's origin (borrow from param/domain, static, raw), invalidation and preservation, presentation (of, rename, the presented method); per callback its role (scope borrow, retained by, destroy path), thread and reentrancy; per domain its scope, library, views and invalidators. Every row ends [clause:<name>@<path>:<line>] or [default:<rule>]; subject rows carry facade:<name>@<path> (§16.2b.2 facade identity).
  • audit:contract (in audit:all): producer with no destroy path; destroying operation presented as a lend; retained parameter/callback with no lifetime owner; illegal thread combination (send without drop_any_thread; creator with send/share); and the ruling's advisory — a name segment (close, free, destroy, release, finalize, unref, …) plus a signature taking a resource's representation, exposed with nothing stronger than the described-fn lend — printed in the ruling's four-line form and silenced by an explicit lend. Each violation names the clause, its line and the clause that resolves it.
  • with analyze file.w contract: the rows in order (subject rows as headings, fact rows indented) followed by the audit's notes, violations and a verdict without the fact count, so a snapshot of it does not move with the prelude.
  • contract and audit:contract are semantic-snapshot requests (Compilation.w): they read last_sema when Sema refused a clause, so bad_no_destroy_path.w (a §16.2b.3 compile error) is still named by the audit.
  • Tests: test/contract/ and the contract-view-tests action (in :test). ok_sqlite_shaped.w — a facaded SQLite-shaped header (out-parameter production, SQLITE_OK, close/close_v2, dependent Statement, borrowed errmsg/column_text, db_handle borrowed resource, consume-with-destroy-callback, retained trace callback + userdata, thread capabilities, rename/of presentation, an errno domain, static libversion) with its contract view checked in byte for byte; one bad_*.w per suspicious configuration, each stating the audit lines it expects (//! expect-contract: / -not:), red under audit:contract; ok_ fixtures must be green under audit:all too.
  • Docs: docs/deep-debugging-tools.md, CLAUDE.md's request list, and the plan's stage 10 paragraph (spelling settled).

Derived decisions (ruling silent; each at worst removes capability)

  1. CLI spelling contract — the plan's proposal, adopted; audit:contract for the checks alone.
  2. Advisory is a report.violations entry, not a note. §63: "advisory only … must not change the effective contract, classify the function as destroying, remove the operation, or grant/revoke safety capability." A red audit verdict is none of those — the compiler's verdicts are untouched — and it is the only channel that makes a tool say "review this". The text says so in the ruling's own words. An explicit lend "records that the facade author deliberately reviewed the operation" and silences it.
  3. creator + send/share is flagged as illegal. §48: thread creator means operations, destruction and ownership stay on the creating thread; §49-§50 make send/share capabilities beyond that. Stating both is a contradiction the compiler does not yet refuse; flagging it removes nothing.
  4. Snapshot = the contract view, not the full facts TSV. The TSV is stable in format, but its id/node/symbol/type columns are pool- and prelude-relative and would churn with every stdlib change; the view carries the same row text (detail) with paths and lines, and the audit needles pin the violations.
  5. Provenance identity is facade:<name>@<path>. §16.2b B.8's facade:<package>@<version> needs a package-shipped facade, which Sema does not model yet (no package/version on a facade block); the block's file path identifies it honestly today and the @<version> form follows when packages ship facades.
  6. Compiler runtime seams are counted, not listed, in "invalidated by" (with_*, which no user program calls); every library operation is named.
  7. Profile checks (ambiguous match; profile fact shadowed) are documented stubs: no profile fact exists in Sema until stage 11, so they examine nothing and cannot fire; the audit notes it when a use convention is present.

Stage 9 tolerance

Stage 9's callback param N userdata param M records and its new Sema errors (retains … by a non-resource, consumed-and-retained userdata) are not on main. The collector reads only fields that exist on main; bad_retained_no_owner.w compiles on main and becomes a compile error once #1606 lands — the audit still names it, because both requests read Sema's snapshot. Nothing here needs rebasing on #1606.

Verification

  • with-stage1 check src/main.w green; with build :dev green; with build :spec-inventory-check green (no new CLI command: contract is an analyze request, and the spec already describes the view).
  • analyze … contract / audit:contract / audit:all on every test/contract fixture; audit:all green on the stage 5-8 fixtures child_drop_order, domain_errno, presentation_methods, text_view, facts_verify, presentation_ambiguous, dependent_ok. behav_c_facade_resource_in_place_pinned.w is red under audit:all on main and the installed compiler too (receiver-audit and codegen-marshalling rows, not the contract audit): filed as analyze audit:all red on behav_c_facade_resource_in_place_pinned.w: receiver-audit sig mismatch and a with_free call with no Codegen marshalling fact #1613.
  • with build :contract-view-tests and :deep-debug-tool-tests: see the battery comment below.

Draft until the seed-driven battery is green (D56).

@ehartford

Copy link
Copy Markdown
Contributor Author

Iterate-tier evidence (stage1 driver in the worktree, SDKROOT=CLT 15.4):

  • with build :dev green; with-stage1 check src/main.w ok; with build :spec-inventory-check green.
  • with build :contract-view-tests: contract-view-tests: 6 fixtures; every audit verdict, needle and snapshot agreed (wall 274.6s incl. the release build).
  • with build :deep-debug-tool-tests green (24.6s).
    No battery yet; draft until it is posted.

Eric Hartford added 3 commits September 24, 2026 06:14
…ance (D51 stage 10, ruling §63)

A `foreign-contract` AnalysisFactKind and a collector over Sema's facade
records (resources, fn items, domains, callback parameters, `use
convention`): one subject row each and one row per effective fact —
production, status, destroy paths, dependency, thread capabilities, views
and their invalidators; parameter effects, result origin, preservation,
presentation; callback role, thread and reentrancy — each ending in its
provenance, the facade clause with file and line or the conservative
default that supplied it (§16.2b.2). Read-only: nothing here changes a
verdict (ruling §2.3). `audit:contract` (in `audit:all`) is the ruling's
suspicious-configuration list — producer with no destroy path, destroyer
presented as a lend, retained parameter with no lifetime owner, illegal
thread combination, and the advisory destroyer-shaped borrow that an
explicit `lend` silences; the profile checks wait for stage 11. `with
analyze file.w contract` prints the rows in order with the verdict, and
both requests read Sema's snapshot so a refused clause is still named.
…res for the contract view (stage 10)

test/contract/ok_sqlite_shaped.w is a facaded SQLite-shaped header with its
`contract` view checked in (ok_sqlite_shaped.expected); each bad_*.w plants
one of the ruling's suspicious configurations and states the audit lines it
expects. The action analyzes fixtures by project-relative path so the
snapshot's paths are stable, requires bad_ fixtures red and ok_ fixtures
green under audit:contract and audit:all, and compares the view byte for
byte. In :test.
@ehartford
ehartford marked this pull request as ready for review September 24, 2026 14:12
@ehartford
ehartford merged commit 50a478b into main Sep 24, 2026
@ehartford
ehartford deleted the modeled-c-stage10 branch September 24, 2026 16:57
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