Skip to content

migrate: a definition's function-pointer parameter is Option by evidence, as a corpus fixed point (D107, #2240) - #2243

Merged
ehartford merged 5 commits into
mainfrom
nullable-evidence
Oct 7, 2026
Merged

ehartford merged 5 commits into
mainfrom
nullable-evidence

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Implements D107 (c35685b): CiProject records per corpus definition the body's NULL tests (continuing vs aborting), corpus callers passing NULL, and the sinks a parameter flows to; resolve_fn_ptr_nullability is the least fixed point (Option as the safe default on cycles, unresolved dependencies and unanalyzable bodies); every verdict prints its reason. The bridge no longer wraps parameters by declaration site; ci_migrated_param_type is the one place a verdict reaches a rendered type (header, body copy, prototypes, call coercion); a NULL comparison on a non-null function pointer folds to its constant. Fixture bs_check_migrate_nullable_by_evidence (five cases + reasons). The four corpora re-promoted — migrate_diff shows exactly the callbacks that lost Option and their .unwrap()s; every corpus suite green; drift check green. System-header prototypes keep D102.

Fixes #2240. Draft until its battery is green.

Eric Hartford added 2 commits October 6, 2026 22:43
…nce, as a corpus fixed point (D107, #2240)

CiProject records, per corpus definition and parameter, what the body and
the corpus say: a NULL test whose NULL branch continues (`p == NULL`,
`!p`, `if (p)`, `p ? :`), a test whose NULL branch aborts (assert, abort,
exit, trap: evidence of non-null), a corpus caller passing NULL, and the
sinks the parameter flows to (a corpus callee's parameter, a record field,
a global). `resolve_fn_ptr_nullability` is the least fixed point: Option
from body test, NULL caller, field or global store, a forward to an Option
parameter, or a forward to a corpus function with no definition here; a
cycle of forwards with no other evidence is Option for every member; an
unanalyzable body is Option. The verdict is a function of the corpus,
never of unit order, and every verdict prints its reason once
(`migrate: f param N: Option: caller g passes NULL`).

The bridge no longer wraps a parameter by declaration site;
`ci_migrated_param_type` is the one place the verdict reaches a rendered
type (the definition header, the body copy, prototypes, call-argument
coercion), so every unit presents the same parameter. A non-null
parameter's body copy is Option only when the body assigns to it; a NULL
comparison on a non-null function pointer folds to its constant
(`assert(cb != NULL)` holds by the type). A lone unit is its own corpus.
System-header prototypes keep D102.

Fixture `bs_check_migrate_nullable_by_evidence`: handled test, assert,
NULL caller, field store, forward, the reasons, the signatures, `Some`
only at Option callees, and the output checks. `WITH_DEBUG_MIGRATE_NULLABLE=1`
traces the verdict each render site reads.
… is seen through __builtin_expect

pcre2, zlib, tommyds and c_algorithms re-migrated and promoted: callbacks
a body calls unconditionally with no NULL caller (inflateBack's in/out,
pcre2_jit_stack_assign's callback, list_sort's compare, arraylist's
callbacks, run_test's test) are non-null and call through without
`.unwrap()`; those with a NULL caller (pcre2_set_callout) keep `Option`.
migrate_diff names the touched functions in each corpus; corpus-drift-check
green; every corpus test suite green on promote. The condition walker sees
assert's test through `__builtin_expect(test, 0)`, so an assert reads as
the aborting test it is ("the NULL branch aborts (a contract)").
Eric Hartford added 2 commits October 6, 2026 23:47
…ration-only; std drops a Some; the drift harness passes a function

The NULL-comparison fold on a non-null function pointer applies in
migration sessions only — a c_import session keeps D102, where a facade
may present the parameter nullable and the inline body may test it — and
in a bool context it yields a bool. The body copy of a function-pointer
parameter stays Option in c_import sessions (D102); in a migration it is
Option only when the body assigns to it. hash_index drops the `Some`
around hash_slot_compare now that tommy_hashdyn_search's parameter is
non-null (D107); the pcre2 wo-drift harness hands pcre2_jit_stack_assign
a function (its callback has no corpus NULL caller). The silent facade
over an unrendered static inline this exposed is #2244.
@ehartford
ehartford added this pull request to stack #2246 October 7, 2026 07:15
…cre2 checks read the migrated tree; one std module, one source

The third battery's pcre2-wo-drift found that NULL passed inside a
static definition was not recorded as caller evidence, so three
callbacks stayed non-null while the harness passed NULL
(record_call_evidence in the migrate scan's static branch). Re-promoting
under that fix found the checks that had stayed silent:

- build/pcre2.w's cohesive check and pcre2-build compiled the harness
  through the Workspace API, so the compiler's embedded std.re interface
  answered every `use std.re.X` and the migrated siblings were never
  read (a syntax error appended to one still passed). Both now run the
  release compiler with `--bundle-corpus std/re --no-prelude`, the form
  corpus_check_every_module and the bundle build use; the compiler is
  threaded through verify_generated and the promote/build targets.
- With the prelude on, the prelude's std.regex resolved std.re.* to the
  checkout's lib/std/re while the harness resolved to its tree: one
  source loaded as two module instances, two sets of globals, and
  pcre2test panicked in test 24. Zcu.add_imported_path now records each
  std identity's file and the frontend refuses "module 'std.re.defs' is
  loaded from two files in one compilation" once the root's imports are
  in (a tree file beside its embedded spelling is one module, as a
  stage compiler resolves its std). WITH_DEBUG_IMPORTS=1 prints every
  registered module with its key and identity.
- Every --dump-*/--trace-* flag ignored --bundle-corpus (only `check`
  set it): cli_check_compilation sets it, and tools/migrate_diff.w
  dumps the corpus on its source without the prelude.
- c-migrator-pcre2-prep-tests was red on main (verified on
  2166323): the compile-builds fixture called an unsafe fn outside
  unsafe, and the jit case guarded a module-private surface that the
  migrator exports since #662; it builds and runs the jit-unsupported
  contract again. New case: std-module-two-sources.

Corpora re-promoted under the caller evidence (pcre2_set_callout_8,
pcre2_jit_stack_assign_8, pcre2_set_recursion_memory_management_8 take
Option callbacks); drift and prep tests green under the seed driver.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on the stack top 990d183 (comptime-infer, D107 #2243 under it): gate 67s, uat 25s, battery-checks 352s. Driven by the pinned seed; logs in out/battery/.

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.

migrate: nullable-by-evidence function-pointer parameters as a corpus fixed point (D107); the migrator is NON-COMPLIANT until this lands

1 participant