Skip to content

D65: methods and trait impls of same-named types are their declaration's own (#1457); codegen takes passing modes from FnAbi (#1647 ph2); MIR places/bindings/call transfers audited against Sema (#1647 ph3–4); frozen Sema stays frozen in emit-c (#1983); generic-instance field types from Sema (#1984) - #2012

Merged
ehartford merged 9 commits into
mainfrom
wave-d65
Oct 3, 2026

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Campaign wave. One commit per item, rebased on main da08b14. audit:all over src/main.w: 13 violations on 9307016 → 0. #1457: a method/impl/vtable of a type two files declare is keyed by that declaration (Item$m$<path hash>); codegen no longer splits the symbol at '.' (lldb watchpoint on had_error found the silent failure); the 'not supported yet (#1457)' error is deleted; the issue's program prints a 5 6/a 6 5. #1647 phase 2: 8 sites deciding a passing mode/place category from an LLVM type now read FnAbi's PassMode or Sema's category (audit:codegen red at all 8 → 0). Phases 3–4: MIR field places / let alias-or-owner choices and call-argument transfers judged against Sema (70239 places, 9174 bindings, 27433 arguments, 0 violations; planted cases prove each lane fires). #1983: 8 → 0. #1984: 5 → 0. :dev, drop-audit 254/0, deep-debug-tool-tests, fixpoint (16 units), gate green. Remaining unconverted D65 sites (listed in the hardening plan) continue in a follow-up.

Eric Hartford added 9 commits October 2, 2026 23:29
…od (#1457, inherent half)

Two modules each declaring `pub type Item` with a method `total` was a
located refusal ("a method name shared by same-named types in two
modules is not supported yet"): both methods minted the symbol
`Item.total` and the method tables keyed both under the name `Item`.

Sema now keys a method of a type whose name more than one file declares
by that declaration's identity symbol, `Name$m$<path hash>` (the way an
extension method's `$ext$` symbol already does): compute_method_origins
finds the colliding names from the decl table before any type is
registered; the declaring side (method_decl_base_symbol, the
registration keys) and the receiver side (method_owner_symbol_for_type,
from the receiver's TypeId through its registering candidate) read that
one answer. record_named_type_with_pub records which declaration each
identity symbol names.

Codegen took the method's owner by splitting the symbol text at '.'
(Codegen.w declare_function_at_inner, the two MIR prologues,
current_method_owner_from_name); with an identity owner that named no
type, `Self` failed to resolve and type_fallback set had_error with no
message (lldb: watch on Codegen.had_error, write at Codegen.w:1258 from
declare_function_at_inner:5223 for decl 3019, `Item$m$...twin_a`).
method_owner_cg_sym reads Sema's identity -> declaration fact and gives
that declaration's codegen symbol (its #1446 alias when it has one).

The method-registration audit keys by the same owner key instead of
rebuilding it from the name. The refusal and its helper
(method_decls_collide_across_types) are unreachable and removed.

Generic declarations keep the name key: a generic receiver keys by its
instantiation base. Trait impls on both types are the next commit.
…1457, trait half)

Two modules each declaring `Item` could not both implement one trait for
it: `impl Copy for Item` in each was "duplicate implementation of trait
for type" (on main as well), and a trait impl with methods met the
method-collision refusal. The impl registry keyed impls by the name, and
the trait paths named and keyed everything `Item.*`: default methods
(Sema register_trait_default_method_for_impl, CodegenTraits), vtables
(generate_trait_vtable_for_impl, `__vtable_Item_Trait`), the impl method
each vtable slot calls.

Sema: impl_owner_key_symbol(impl) is the method-declaration owner key
rule (owner_key_symbol_from) applied to an impl; default methods register
under it. A duplicate impl is per declaration: impl_identity_traits holds
(identity, trait) for a name more than one file declares; the name-keyed
record holds the trait once for the name.

Codegen: an impl's type symbol is the declaration Sema resolved its target
to (impl_decl_target_types through nominal_cg_sym_for_tid, the #1446 alias
the dyn coercion side already keys a vtable by), and a vtable slot's
function is the one Sema's registry holds for the impl's owner key, by
name only where the registry has no row.

Fixture: behav_1457_trait_impls_own_module_type.w (trait method, default
method, dyn dispatch and Copy on both `Item`s); it was E1102 before.
Generic owners keep the name key (find_impl_for_type_trait serves only
their mono bases).
…ot from LLVM types (#1647 phase 2, D65)

Ten codegen sites decided a passing mode or a place category from the LLVM
type of a value: the field and index walks of mir_place_projected_type and
mir_place_ptr ("the storage is a ptr, load through it"), the raw-pointer
index, the read of an indirect local, marshal_ref_addr's "already a
pointer" (the &fn crash), and the two MIR prologues' "the param is a ptr
and its value is not, so the slot holds an address" and share-place alias.

Each now calls Codegen.mode_decide(site, fact, llvm, fn, subject). The
decision is the owner's fact:
- FnAbi's PassMode: fn_abi_param_by_address (PM_INDIRECT,
  PM_INDIRECT_PLACE or a reference receiver); a receiver is the caller's
  receiver place whatever Sema types the local (D21); an ordinary
  parameter's slot holds an address only when Sema types its local as the
  value (mir_param_slot_holds_address: an explicit `&T` local IS the
  reference value, D6);
- Sema's category: mir_place_step_holds_address (a reference or raw
  pointer step, or the base of an indirect local), mir_sema_type_is_raw_
  pointer, and for marshalling mir_operand_is_fn_item (MIR's CK_FN item)
  and mir_sema_type_is_raw_pointer_or_ref.
The LLVM type is verification: audit_mode_provenance (audit:codegen, so
audit:all) reports decisions and disagreements per site, a disagreement
is a violation.

Evidence, `with-stage1 analyze src/main.w`:
- before (sites still deciding by LLVM type, instrumented): nine
  violations "N of N decisions taken from an LLVM type, not from <owner>",
  e.g. marshal_ref_addr 35107 of 35107, operand read of an indirect local
  638035 of 638035;
- after: every site disagree=0 (marshal_ref_addr 35104 decisions, prologue
  by-address 25362, ...). The 13 audit:all violations that remain are on
  base 9307016 too (#1983, #1984).
The first fact for by-address omitted the reference receiver (2670
disagreements, StringBuilder.len's self) and then over-counted explicit
`&T` parameters (debug_entry_before; 7 behavior fixtures red); lldb on
mir_param_slot_holds_address gave FnAbi=by-address and Sema local type
342 = &StringBuilder, which split receivers from ordinary parameters.

The two method-owner fallbacks of the field walks (a place's type taken
from the enclosing method's name) had no owning fact and fired 0 times
over src/main.w; they and current_method_owner_llvm_type are deleted.
The downcast sites and the null constant read the Option-of-pointer
niche, codegen-owned representation, and stay LLVM-typed.

Targeted: 349 behavior fixtures (refs, receivers, captures, closures,
&fn, indexing, raw pointers, Option, dyn): 2 fail, both identically on
base stage1 (behav_1874_simd_c_abi_darwin, behav_sema_raw_pointer_
effect_order). deep-debug-tool-tests gains the lane on behav_fn_abi_
callable.w. Not yet converted: mir_try_place_ptr_for_ref and
mir_operand_local_holds_pointer.
…a instead of re-resolving it under a pushed substitution (#1983)

`with analyze src/main.w audit:all` was red on main with eight frozen-phase
violations: CCodegen called Sema.push_specialization_subst /
pop_generic_subst (collect_used_struct_types, emit_closure_body,
emit_fn_body) and Sema.type_layout_size_of / align_of
(closure_env_kind_for), all `mut` Sema methods, after Sema froze.

The substitution served one fact: the type argument of a type-level
builtin call (`sizeof[PullCore[G]]()`, #1766), which CCodegen re-resolved
from the AST node under the instance's substitution. Sema already
resolves it while it checks that instance (check_call's sizeof/alignof
branch, under check_fn_body_concrete's substitution); it now records it,
keyed (mono symbol, type-argument node), with current_specialization_sym
naming the instance being checked (closures in it included).
type_level_arg_in_body(body, node) is the frozen query: the recorded fact
for a specialization, frozen resolution for any other body. CCodegen
reads it at both sites and pushes no substitution; the layout reads use
the frozen twins the LLVM backend already uses.

Evidence: audit:all over src/main.w, 13 violations before (8 of them
these, on base 9307016 too), 5 after (#1984). The 16 test/emit_c
fixtures emit C identical to base modulo symbol ids, generic_sizeof_mono
and gen_pull included.
…: one Sema type, one LLVM struct (#1984)

`with analyze src/main.w audit:all` reported five place-type violations
in LspDocument (src/Lsp.w): its `HashMap[str, Vec[str]]` fields projected
to %"HashMap__str__struct{ptr,i64,i64,i64}" while the MIR type lowered to
%__with.HashMap.str.__with.Vec.str.

declare_struct_type resolved each field's AST type node; for a generic
instance that is monomorphize_struct, which names the instance from its
arguments' LLVM layouts (llvm_type_mangle: `Vec[str]` became
`struct{ptr,i64,i64,i64}`) and even maps LLVM types back to Sema types.
Every MIR read of the field lowers Sema's type (sema_type_to_llvm, the
collection wrapper). Two derivations of one fact, LLVM type -> identity
(D65). A generic-instance field now takes the LLVM type of Sema's field
type (type_reflection_field_type_frozen of the struct's TypeId).

Evidence: audit:all over src/main.w, 5 violations after #1983, now
`violations=0 ok`. 301 behavior fixtures over structs, fields, Vec,
HashMap, Option, Box/Rc, generics and layout: green (behav_d44_map_
ownership timed out once under load; it compiles sub-programs and passes
on its own).
…g against Sema (#1647 phase 3, D65)

Phase 3 of docs/spec/implementation/mir-sema-hardening.md: a MIR place
lowered from a source expression must be the place Sema resolved for that
node, and a binding must be materialized in Sema's category.

MIR now states what it lowered: MirBody.field_place_* records each place
lower_field_access builds (node, place, base place), and let_binding_*
each `let` with its materialization (an alias of a place, or an owning
local). Sema persists the category it decided for a `let` it bound as a
view (view_bound_let_nodes: 1 a reference value, 2 a view of a place),
where it already set the scope's view flag.

audit:resolution (in audit:all) judges both with pure verdicts in MirCore:
- mir_field_place_verdict: the last projection is a field naming the
  node's field, the place's type is Sema's type for the node, and the base
  is the declaration Sema's base expression has after Sema's autoderef
  steps (the #1446/#1457 module-identity class);
- mir_let_binding_verdict: an immutable non-Copy `let` aliases a place iff
  Sema bound it as a view of a place (an owning local over a view is the
  #747 field move; an alias over an owner leaves a value nobody drops).
test/internals/analysis_resolution_test.w plants each disagreement.

Over src/main.w the compiler already agrees: field-places=70083
let-bindings=9155, violations=0 — so this lane has no red on the
pre-fix compiler to show; the planted cases are its evidence that it
fires. Not covered yet: view origins, index places, and the field
projection still names its field by symbol rather than Sema's index.
… ownership of the parameter (#1647 phase 4, D65)

Phase 4 of docs/spec/implementation/mir-sema-hardening.md: a MIR move or
copy of an argument must agree with Sema's effect for the parameter
(D5: the signature states the ownership mode).

For every MIR call with a signature, each argument that reads a named
binding's non-Copy place is judged by mir_call_arg_transfer_verdict
(MirCore): moving it into a parameter Sema borrows (share-place
value_ref_abi, or an extern bit-copy, extern_param_is_bit_copy) resets
a binding that still owns its value; copying it into a parameter Sema
consumes makes two owners. Statement temporaries are the forms that
exist to differ (`move x` into a borrowing parameter, a `copy x` clone)
and are not judged. test/internals/analysis_resolution_test.w plants each
disagreement.

Over src/main.w: call-arguments=180558, of which 27343 read a named owned
binding (18417 into borrowing parameters), violations=0; the phase-3
lanes report their populations too (let-bindings judged=9159 with
mir-aliases=32 = sema-place-views=32). The compiler already agrees, so
there is no red over src/main.w to show; the planted cases are the
evidence that the lane fires. Not covered yet: closure captures (D62/D63)
and lower_callable_expr's observe-vs-move choice.
…ecomes the program it refused (#1457)

err_1457_same_named_method_two_types.w pinned the located error that stood
in "until a method symbol carries its declaration" (its own words). 173e61c
made each method its declaration's own, so the program it refused now runs
and prints `1 2`; the fixture moves to test/behavior and pins that output.
The wave-d65 battery on e8a4453 was red on this fixture alone.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on 6644771 (seed-driven, with run tools/battery.w, on main da08b14): gate rc=0, battery-checks rc=0 — fixpoint, drop and move audits, every corpus. The prior run on e8a4453 was red only on err_1457_same_named_method_two_types.w, which pinned the interim collision error 'until a method symbol carries its declaration'; that program now runs and prints 1 2, so the fixture became a behavior test pinning it. Merged by the coordinator per Eric's standing direction. #1647 stays open for the remaining D65 sites (in progress).

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