Skip to content

Migrator contracts, step 2 (D159, #2615): a proved function is printed as a method of its record - #2623

Merged
ehartford merged 6 commits into
mainfrom
migrator-contracts-2
Oct 25, 2026
Merged

ehartford merged 6 commits into
mainfrom
migrator-contracts-2

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

D159 step 2 (#2615): the migrator prints a proved function as a method of its record.

  • A function whose first parameter is a mutated corpus record, with every other pointer parameter a proved out-parameter, is pub mut fn <m> in an impl R: block at the end of its unit; the out-parameter is the return (T, or (status, T)), a returned receiver is -> &R from self; the body prints in a safe context with its raw operations carrying their own unsafe. Corpus calls print as method calls, an out-argument assigned from the return. A function with an unproved pointer keeps its raw signature under a // contract: line.
  • Refusals the corpora forced: a handle the body accepts as NULL (or a caller passes NULL) is no receiver; ret-from on a path that returns NULL is unproved; a unit-local static, a header no single unit owns, a variadic, a method-name collision keep the raw form; a header-owned inline definition (STC templates) is a method. Pointer arithmetic now carries its pointer type.
  • Lane defect fixed: the pcre2 cohesive check and build lanes placed the fresh units under lib/std/re, where their imports fell back to the promoted corpus; they use the import path's layout now.
  • Every corpus lane green on fresh migrations: STC 176 methods (stc_word_stack has push/pop/reserve), pcre2 15, zlib 19, TommyDS 19, c-algorithms 18, M*LIB 26; pcre2test passes upstream RunTest. Plan status in docs/proposals/migrator-contracts-plan.md.

Battery: seed-driven, posted below when green.

Eric Hartford added 6 commits October 25, 2026 00:33
…d as a method of its record

A function whose first parameter is a mutated corpus record (receiver-mut) and whose other pointer parameters are proved out-parameters is emitted as `pub mut fn <m>` in an `impl R:` block at the end of its unit: the out-parameter is the return (`T`, or `(status, T)`), a return of the receiver itself is `-> &R from self`, and the body is printed in a safe context with its raw operations carrying their own unsafe. Corpus calls to one print as method calls, an out-argument assigned from the return. A function with an unproved pointer keeps its raw signature under a `// contract:` line. The view verdict now refuses a NULL return path and is drawn beside receiver-mut. The basic test covers each shape and type-checks the output.
A static definition (a unit's own or a header's inline one) keeps its raw signature in the printer, so it takes no method shape either (the calls were being rewritten to methods that were never printed). Pointer arithmetic carries its pointer type, so a field read through it prints with the unsafe a safe method body needs (M*LIB). A typedef that renames a record is an alias, not a record an impl can attach to. A handle the body accepts as NULL, or a corpus caller passes NULL, is no receiver: pcre2's `pcre2_set_optimize(NULL, …)` returns an error, a method's self is never NULL.
…n the check tree, where their imports find them

They were copied under lib/std/re, so `use std.engines.pcre2.X` found no sibling there and fell back to the checkout's promoted corpus: the fresh harness was checked against the old library and a signature change in the fresh one could not be seen (D159 step 2's methods were "unknown" for that reason). The generic corpus_check_every_module already uses the import path's layout.
…hod too

The unit that publishes a header's static inline definition prints it `pub`, so the shape applies to it as to any published function; only a unit's own static, and a header no single unit owns (a private copy per includer), keep the raw signature. STC's word shapes (stack.h instantiated in facade_shapes.c) are the case: push, pop and reserve are now methods of stc_word_stack.
…the ruling; no explicit Unit on the setters

behav_migrate_anon_union_field and behav_migrate_no_redundant_unsafe migrated a `bump(struct S *)` and called it as a free unsafe function; under D159 it is a method of the record, called safely as `s.bump(…)`, and the raw-function assertions hold for the functions that stay raw. The two new setters drop their written `-> Unit` (unit-return-review).
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery green on a02f7e3, seed-driven under nightly-20261025-local-1-c88f3eeff0bc (tools/battery.w: gate, uat, battery-checks). corpus-migrator-gate green on the fresh migrations of every corpus (pcre2test passes upstream RunTest).

@ehartford
ehartford marked this pull request as ready for review October 25, 2026 05:40
@ehartford
ehartford merged commit c841754 into main Oct 25, 2026
@ehartford
ehartford deleted the migrator-contracts-2 branch October 25, 2026 05:40
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