Skip to content

Migrator stage: emit safe signatures where a migrated function's body proves its contract (D159) #2615

Closed

Description

@ehartford

Ruled D159 (2026-10-24, docs/meetings/2026-10-24-D159-*.md). The migrator gains a stage, after translation and before emission, that emits a safe signature for a migrated function when its body proves the contract:

  • (a) a pointer parameter the body mutates in place is a mut receiver / inout;
  • (b) a pointer argument the body stores into the engine's own storage is an ownership transfer ONLY when a destroyer in the same corpus frees it along that path; store alone is "stored, ownership unknown" and the function stays unsafe (Eric's first condition: TommyDS intrusive links and user-data pointers are stored but not owned);
  • (c) a returned pointer derived from a parameter is a view with that parameter's origin (-> &T from <param>).

An unproved point keeps pub unsafe fn with the unproved point named in the generated comment. Contracts are emitted into the generated source, never hand-edited.

Second condition: the inferred contracts are body-derived facts, so the drift lane (wo-drift) diffs them as their own artifact and a contract change is red until a human has looked (the §3.4 origin-inference lesson).

This is a migrator generation bump: under D112 promoted corpora are not re-promoted until their pin or a ruling moves them; new corpora and re-promotions get contracts. The STC facades (lib/std/collections/*.w) drop their engine-call unsafe at the STC corpus's next re-promotion (18–39 sites per facade today, after #2614's slot API).

Acceptance: the proof reads the C AST the migrator already has; c-migrator-basic-tests cases for each inference and each refusal; a contract diff in the drift lane; a facade calling a proved engine function without unsafe compiles under :user-programs-safe-style scrutiny; D51's test holds for every inference (a wrong one can at worst reject a valid program).

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    D159 amended (Eric, 2026-10-24): inference (a) uses only the spec's spellings, no new parameter mode. Receiver (mut self) when the engine handle is the first parameter and the body mutates through it; a second pointer parameter the body writes on EVERY returning path is an out-parameter presented as a returned value, T or (status, T) (the modeled-C out param N / ok pattern), sound only when the written record is plain data (Copy, or a copy class rt_core can produce); a record holding an owned pointer falls under inference (b)'s stored-and-freed rule; a conditional write (partial fill, write guarded by the status) stays unsafe fn with "out-parameter written conditionally"; everything else (a second pointer read and written in place, an input/output pointer, a mutated array) is unproved. STC's _insert result record is the motivating out-parameter case.

  2. added a commit that references this issue on Oct 25, 2026
  3. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Step 1 landed: #2619, main d88b39f. with migrate --emit-contracts FILE; every corpus promotion now carries contracts.tsv and the drift report prints changed contract lines. STC fresh (775 functions): 277 receiver-mut, 1 out-parameter, 9 ret-from, 0 owned (slot pushes are stored-unknown: STC's i_keydrop is a no-op, the facade owns the slot), 427 unproved, mostly read-only handles (not in the ruling). Next: step 2 (emission), then the generation bump and the STC re-promotion (step 3), then the contract diff as a gate (step 4). Follow-up brief candidates recorded in the plan: a &self receiver for read-only handles, a consumed receiver for destroyers, owned-through-a-local-alias (TommyDS/STC free via a walked local).

  4. added 3 commits that reference this issue on Oct 25, 2026
  5. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Done, in four steps on main:

    Left as briefs for a ruling (docs/proposals/migrator-contracts-plan.md): a &self receiver for the read-only surface (343 STC rows; the facades' remaining 93 read calls), and an owned parameter stored into a record ((b) emission, a representation change).

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