Skip to content

analyze: audit:resolution phase 1 — every MIR callee agrees with Sema's resolution (D65, #1647); validate-all rejects a signature-less const-fn callee (#1639) - #1662

Merged
ehartford merged 6 commits into
modeled-c-d66-curlfrom
analyze-audit-resolution
Sep 25, 2026
Merged

ehartford merged 6 commits into
modeled-c-d66-curlfrom
analyze-audit-resolution

Conversation

@ehartford

@ehartford ehartford commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Adds with analyze <file> audit:resolution to audit:all (D65, #1647). Each MIR call is checked against Sema's recorded callee and argument count; resolved calls inside lowered bodies must be accounted for. Violations identify the body, source location, and disagreeing facts. --validate-all also rejects a signature-less const-fn callee outside Sema's callable snapshot (#1639).

Sema produces callable, intrinsic, and generic facts; MIR propagates them to the validator. The audit reads those facts, including callable arguments of desugared combinators, Drop-impl calls materialized as drops, and calls MIR explicitly records as elided. It does not introduce a callee-name allow-list.

Planted MIR/Sema fixtures cover unknown and invented callees, direct and indirect arity mismatches, node/signature disagreements, and missing generic/intrinsic dispatch marks. A no-prelude regression covers the no-MIR diagnostic, one indirect callback body, and two declaration spans.

The first stack battery passed build, fixpoint, drop-audit, and move-audit, but found a singleton-input panic in the resolution audit. LLDB proved resolution_sorted_by_key initialized root to -1 for one span and entered the order[child] bounds-panic branch. The sorter now returns immediately for fewer than two entries; audit checks remain intact. The new regression fails on the previous release binary with that panic.

Part 3 of the GitHub stack: #1656 → #1661 → #1662. #1661 contains the temporary source accommodation needed to build with the pinned seed, which still carries the field-path packing bug. Remove that accommodation after the next seed cut.

Validation at 974c8ba: full seed-driven build, fixpoint (16 units), drop audit (213 cells), move audit (105 cells), full test suite, test-green, and last-green all passed. The suite includes 1,273 behavior files and all 36 internal-test files. The final verdict table is posted below. Earlier iterate checks and the 1,218-fixture resolution sweep also passed.

@ehartford
ehartford force-pushed the analyze-audit-resolution branch 2 times, most recently from 9ec7b68 to 3ff4208 Compare September 24, 2026 22:39
@ehartford

Copy link
Copy Markdown
Contributor Author

Full test/behavior sweep, audit:resolution with the branch's stage1 (head 3ff4208, built with #1656's stage1 as the seed): 1269 fixtures. 1218 analyze and every one is violations=0 ok. The other 51 report analysis compilation failed; each of them also fails check under #1656's stage1 (no audit code), i.e. they are expected-error fixtures, not findings.

Findings the sweep surfaced along the way, each resolved by a producer stating its fact (no exclusion, no name list): for x in v.iter() / a comprehension over it (index loop, .iter() peeled — elided_call_nodes), a typed BTreeMap.new() / BTreeSet.new() (aggregate in place of the resolved specialization — same table), a static HashMap.new() (MAP_NEW now carries its call node), s.track(t) / Atomic.new (machinery-dispatch mark), opt.map(f) (the callable-typed argument), arena.drop() (the Drop-impl facts). Fixtures that were red before those: behav_comprehension_view_to_fn, behav_d61_debug_rows, behav_for_binding_disjoint_mutation, behav_for_iter_mut_self, behav_for_veciter, behav_intoiter_vec, behav_iter_pipeline_local, behav_iter_view_to_fn, behav_veciter_generic, behav_veciter_iter_sum, behav_veciter_iter_trait, issue64_borrowed_vec_methods, issue64_unwrap_chain_receivers, behav_arena_region, behav_arena_vec, behav_c_facade_getenv_twice, the async-scope set, atomic_store_element_view — all violations=0 on the head.

Eric Hartford added 5 commits September 24, 2026 19:18
…nt agrees with Sema's resolution of the call it lowers (D65, #1647)

For each MIR call terminator the audit gathers Sema's answer for the
call's own AST node and compares it with what MIR resolved, re-deriving
nothing: a `const fn` callee must be a declared signature, a generic
template under its GENERIC_CALL mark, a builtin Sema classified, or a
body of the module; a place callee must be a call Sema resolved through
a callable value; the argument count must equal that same fact's
parameter count (a variadic signature or an extern fn type states none);
a call node Sema resolved to one signature must not lower to another;
and a call Sema resolved inside a lowered body must have a MIR call fact
carrying its node. Any other intrinsic mark is recognized by its kind.
Each violation names the body, the node's path:line:column, MIR's
answer, Sema's answer and the rule; the same rows are Invariant facts.

Facts Sema now emits (one owner per fact): `call_callable_types`, the
callable type an indirect call invokes, recorded once in check_call for
a callable binding, a callable field and any other callable-typed callee
(#1635's `let r = c.run; r(21)` is a Callable answer where MIR called a
function named `r` with the argument dropped); `intrinsic_fn_syms` /
`generic_builtin_syms`, the builtins is_intrinsic_fn_sym and the
type-argument predicates accept, enumerated; `call_callee_is_builtin`,
Sema's classification of a call node's callee. MirModule carries them
as `sema_callable_syms` (keyed by its own pool, carried by name) for the
validator that follows. `math_fn_count` exposes the math table's size.

A desugared combinator (`opt.map(f)`, `res.or_else(f)`, `filter`)
invokes an argument's value and carries the combinator call as its
node; the callable Sema typed that argument with is the callee's fact
(behav_c_facade_getenv_twice.w; the compiler never calls Option.map
with a closure, so only the fixture exercised it).

The comparison (mir_resolution_check_call, MirCore) takes Sema's answer
as a record, so a planted body and a planted answer exercise the rule
without a Sema. `audit:resolution` is in `audit:all`.

Two shapes MIR materializes without a call fact, judged from the facts
their producers already hold: a language-machinery GENERIC_CALL (a
Task/ScopedTask/channel/Atomic method, `track`, `spawn`, `join`) carries
the dispatch mark MirLower's one contract decision point
(require_generic_call_contract) now sets — codegen dispatches those by
name and receiver, and #1635's unresolved-bare-function branch never
sets it (phase 5 moves that classification into Sema and retires the
mark); an explicit `x.drop()` Sema resolved to the type's Drop impl is
the drop operation, recognized by the `drop` method symbol,
type_has_drop_impl on the receiver and no argument — the same facts
MirLower's drop-glue gate reads (behav_arena_region.w, behav_arena_vec.w).

Corpus: audit:resolution violations=0 on src/main.w, build.w, the
contract fixtures and every test/behavior fixture that analyzes;
audit:all violations=0 on the #1635 and getenv_twice fixtures.
… Sema knows and carries no intrinsic mark (#1639, D65)

#1635's MIR — a GENERIC_CALL to a symbol named after a callable binding,
the source argument dropped — passed every validator and died in
codegen. The typed-MIR validator now refuses a `const fn` callee that
is not in the module's `sema_callable_syms` snapshot (Sema's declared
signatures, generic templates and builtins, propagated at lowering),
has no body in the module and carries no intrinsic mark other than
GENERIC_CALL; a NONE-marked direct call to a template or builtin is
refused too, since the GENERIC_CALL mark carries its concrete contract.
No builtin is named here: the snapshot is Sema's fact.

The two planted bodies that called a bodiless symbol 2 through this
validator (#1180 Unit argument, #1443 missing borrow) declare it as a
signature, which is what they always meant.

A GENERIC_CALL that carries a recorded contract (sig or mono), or the
machinery-dispatch mark from require_generic_call_contract, is
accounted for: `s.track(t1)` and `Atomic.new` lower that way and the
first build of this rule refused every async-scope and Atomic program.
The planted matrix covers the mark: marked GENERIC_CALL ok, the same
MIR without it refused.
…-callee validator (#1647, #1639)

mir_test_resolution_callees: the comparison over a hand-built body and
a hand-built Sema answer — #1635's shape (a function invented from a
binding's name), a callee Sema knows nothing about, an argument count
that disagrees with the signature or the callable type (#1639's silent
case), a call node resolved to one signature and lowered to another, a
template or builtin without its GENERIC_CALL mark, and the clean cases.
mir_test_unknown_callee: the validator's matrix over intrinsic mark ×
snapshot class × body presence. The compiler no longer produces these
from source, so they are planted the way test/internals plants MIR.
…esolution joins to them (D65, #1647)

Rule 5 — a call Sema resolved inside a lowered body has a MIR call
fact — met three MIR-owned materializations that left no fact and
no trace: `for x in v.iter()` and a comprehension over it are the
index loop (`.iter()` is the implicit form, §13); a typed
`BTreeMap.new()` / `BTreeSet.new()` is the aggregate built in place of
its resolved specialization; a static `HashMap.new()` is MAP_NEW with
no node. MIR now states each: `MirBody.elided_call_nodes` records the
peeled `.iter()` (lower_for and the comprehension) and the btree `new`;
the intrinsic method emission carries its call node. The audit joins
Sema's resolved node to a call fact or a stated elision and reports the
counts; a call that vanished with neither is still red.

behav_comprehension_view_to_fn.w (4), behav_d61_debug_rows.w (2),
behav_for_iter_mut_self.w and behav_for_binding_disjoint_mutation.w
were the corpus findings; violations=0 on each, on src/main.w and on
build.w.
@ehartford
ehartford force-pushed the analyze-audit-resolution branch from 3ff4208 to d95194a Compare September 24, 2026 23:18
@ehartford
ehartford changed the base branch from sema-field-move-path to modeled-c-d66-curl September 24, 2026 23:18
@ehartford
ehartford added this pull request to stack #1664 September 24, 2026 23:18
LLDB on fold2 d95194a's release binary, analyzing the one-line indirect
c_va_list callback with audit:resolution --no-prelude, stops in
resolution_sorted_by_key: the input Vec header has len=1; at +356,
w20=1 (n), w10=w12=w13=0xffffffff (root, child, r), and w15=0xfffffffe.
Single-stepping tbnz w15,#31 enters the bounds-panic block at +1016.
The source is AnalysisResolution.w's keys[order[child]] comparison:
n / 2 - 1 initialized root to -1 before the unconditional sift loop.

Return the already ordered indices for n < 2. Keep the audit's verdict
checks intact. Add a no-prelude regression covering the no-MIR diagnostic,
the singleton indirect callback, and two declaration spans. The old
release compiler fails the singleton case with panic: index out of bounds.
@ehartford

Copy link
Copy Markdown
Contributor Author

Stack #1664 validation at 974c8bacd619ca53ec06b182af05ebbb60abc188, driven by the pinned seed nightly-20260925-local-1-fa33bda543c2 in fold2, with WITH_CIMPORT_CACHE_EPOCH=s1664-resolution-974c8bac and a regenerated stage embedded object.

Check Verdict
Full build PASS
Fixpoint PASS — all 16 compiler units agree
Drop audit PASS — 213 cells, 0 non-PASS, 0 regressions
Move audit PASS — 105 cells, 0 expected failures, 0 baseline differences
Full test suite PASS — including 1,273 behavior files, 1,121 compile-error files, 210 spec files, and all 36 internal-test files
test-green PASS — current evidence recorded
last-green PASS — verified seed archived and green published

The blocker was in the resolution audit's heap sort, not a prelude-sized Sema table. LLDB observed a one-element vector, root = child = -1, and the branch into the order[child] bounds panic. Commit 974c8ba returns immediately for fewer than two entries. The new no-prelude regression fails on the old release binary and passes on the new one. The original behav_c_va_list_target_abi.w also passes across its five target configurations; both planted resolution/unknown-callee tests pass.

Local logs: /Users/eric/.local/with-staging/fold2/out/logs-resolution-fix/.

The tested stack descends from 1814a14. Main has since advanced to aa978c6 with the UAT specification/inventory changes; run the required main battery after merge before installing or cutting the next seed. The seed accommodation in #1661 remains until that seed cut. The separate tally example safety gate remains tracked by #1644/#1643.

The existing three layers are ready. Eric has now prioritized #1665; that fix will be added as the next GitHub stack layer and receive combined verification before the merge.

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