You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sema audit gap: garbage generic-inst slot reads were invisible to audit:all; add a typed-expr well-formedness audit #692
Found during #682-inc1 bring-up. The prelude-prefix reordering exposed a latent bug: get_generic_inst_base/arg/arg_count read d-slots/type_extra from NON-inst types, returning garbage that depended on type-table layout. Under the new layout the garbage was u7 (the bitpacked sub-byte primitive), so an unannotated Vec.new() receiver typed push(100)'s literal as u7 — wrong inference, wrong codegen (get(0) read -28), and a runtime abort in the disjoint-slice spec test.
The gap:analyze audit:all reported violations=0 on the affected programs — nothing validates that typed-expr types are well-formed for their context. A program whose int literal is typed as a bitpacked u7 outside any bitpacked-struct context should be an audit violation; so should a TY_GENERIC_INST accessor consult on a non-inst type (now impossible — the accessors are kind-guarded as of the #682-inc1 commit — but the audit class generalizes: d-slot reads interpreted under the wrong kind).
Every typed_expr_types entry's type is spellable in its context: sub-byte int types only inside bitpacked layouts; no TY_ALIAS leaks post-resolve; no error-type propagation into MIR.
Generic-inst arg vectors: d2 == extra count, args are valid type ids.
The kind-guards fix the concrete bug; this issue is the instrument so the class self-identifies next time a layout shift changes which garbage gets read.
Triage 2026-10-25, with v0.15.3.0 (main a261b65): still open. The root bug is fixed (Sema.get_generic_inst_base returns 0 for a non-instance type), but the audit gap remains: analyze has no typed-expression well-formedness audit (the audit:* list in src/Analysis.w: calls, effects, storage, pool, methods, phase, mir, returns, receivers, receiver-surface, pool-views, contract, resolution, codegen, trait-tables). audit:resolution checks that MIR agrees with Sema, which a wrong Sema type passes.
#3390 adds the range checks to audit:storage (and audit:all): the type table's columns are parallel, every generic instance's argument vector lies inside type_extra and names type ids, and every typed expression names a type id. Clean on the compiler's own source (1,560,278 facts). Test: test/internals/analysis_type_table_test.w.
Left open here: the context rule (a sub-byte integer type only where a bit-packed layout or a bitfield setter demands one; no TY_ALIAS after resolution; no error type reaching MIR). Each needs the expression's context or a decision about what is legitimate (a bitfield setter takes u3, D147), so they are separate cells.
#3422 adds one more cell to audit:mir: a MIR local's type is a type of the table (the error type, or a slot that is no type id, in a lowered body is a violation). Running the audit over the compiler's own source for it turned up two violations on main, both fixed in the same PR: a drop-state false positive (a field assigned whole after a sub-field was dropped) and a move of a Copy field out of a global (D52). audit:mir on src/main.w is clean now.
Still open here: the context rules (a sub-byte integer type only where a bit-packed layout or a bitfield setter demands one; no alias after resolution). Each needs a statement of what is legitimate.
Closing: the instrument exists, and the two remaining 'context rules' turn out not to be invariants. Measured with a counting build of audit:storage (not landed):
'No alias after resolution' is not true of correct programs. The compiler's own source has 18,966 alias-typed expressions out of 1,446,568, with audit:all clean. An expression typed by an alias is normal; consumers resolve it.
'A sub-byte integer only inside a bit-packed layout' is not true either.u1..u7 are ordinary types (§4): fn low(x: u4) -> u4: x with let x: u4 = 3 compiles and runs. A bit-packed test has 11 sub-byte-typed expressions, all legitimate (field reads and the literals compared with them); the compiler's source has none. 'Spelled somewhere in the program' cannot be a rule, since the standard library is part of every compilation.
the generic-instance accessors are kind-guarded (the original bug);
audit:storage checks every generic instance's argument vector stays inside type_extra and every argument is a type id, and every typed expression's type is a type id;
Activity
Frontend: prelude closure expands to a deterministic prefix before us…
ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): still open. The root bug is fixed (Sema.get_generic_inst_basereturns 0 for a non-instance type), but the audit gap remains:analyzehas no typed-expression well-formedness audit (theaudit:*list insrc/Analysis.w: calls, effects, storage, pool, methods, phase, mir, returns, receivers, receiver-surface, pool-views, contract, resolution, codegen, trait-tables).audit:resolutionchecks that MIR agrees with Sema, which a wrong Sema type passes.post-release: analysis tooling.
audit:storage checks the type table: a generic instance's argument ve…
ehartford commentedon Nov 17, 2026
#3390 adds the range checks to
audit:storage(andaudit:all): the type table's columns are parallel, every generic instance's argument vector lies insidetype_extraand names type ids, and every typed expression names a type id. Clean on the compiler's own source (1,560,278 facts). Test:test/internals/analysis_type_table_test.w.Left open here: the context rule (a sub-byte integer type only where a bit-packed layout or a bitfield setter demands one; no
TY_ALIASafter resolution; no error type reaching MIR). Each needs the expression's context or a decision about what is legitimate (a bitfield setter takesu3, D147), so they are separate cells.audit:mir is clean on the compiler's own source. Three things: a MIR …
ehartford commentedon Nov 18, 2026
#3422 adds one more cell to
audit:mir: a MIR local's type is a type of the table (the error type, or a slot that is no type id, in a lowered body is a violation). Running the audit over the compiler's own source for it turned up two violations on main, both fixed in the same PR: a drop-state false positive (a field assigned whole after a sub-field was dropped) and amoveof a Copy field out of a global (D52).audit:mironsrc/main.wis clean now.Still open here: the context rules (a sub-byte integer type only where a bit-packed layout or a bitfield setter demands one; no alias after resolution). Each needs a statement of what is legitimate.
ehartford commentedon Nov 18, 2026
Closing: the instrument exists, and the two remaining 'context rules' turn out not to be invariants. Measured with a counting build of
audit:storage(not landed):audit:allclean. An expression typed by an alias is normal; consumers resolve it.u1..u7are ordinary types (§4):fn low(x: u4) -> u4: xwithlet x: u4 = 3compiles and runs. A bit-packed test has 11 sub-byte-typed expressions, all legitimate (field reads and the literals compared with them); the compiler's source has none. 'Spelled somewhere in the program' cannot be a rule, since the standard library is part of every compilation.What guards the class that bit #682 now:
audit:storagechecks every generic instance's argument vector stays insidetype_extraand every argument is a type id, and every typed expression's type is a type id;audit:mirchecks every MIR local's type is a type of the table, with no error type (audit:mir is clean on the compiler's own source (#692) #3422);audit:resolutionchecks each lowered operand has the type Sema gave it, and counts lowered expressions with no record (The typed-expression table's contract, and a count of unrecorded expressions (#767) #3428);audit:allon the compiler's own source (audit:all is clean on the compiler's own source, and the battery keeps it there (#3423) #3427).A layout shift that makes an accessor read garbage now shows as one of those.