Skip to content

Cathedral sweep: audit each compiler file for per-path logic that should be a single source of truth #651

Open

Description

@ehartford

Motivation

The share-place work re-established one cathedral — compute_fn_abi(sig) as the single ABI descriptor (FnAbi / PassMode), read by both the callee prologue and every call site, so caller/callee/path divergence is impossible (see docs/decisions.md D6, docs/fn_abi_descriptor_design.md). That divergence — a per-path "value vs address vs byval" decision reinvented in several places — was the exact bug that produced the transparent T*/T** mismatch.

The lesson generalizes: anywhere the compiler makes the same semantic decision in more than one place, it's a bazaar and a latent divergence bug. We should sweep the compiler for these and cathedralize them.

Task

Go through the compiler one file at a time (src/*.w, src/compiler/*.w) and, for each, identify logic that should be centralized into a single source of truth. Look for:

  • The same classification/decision computed per-path instead of once (like the pre-D6 ABI decision). Examples of the shape to hunt: "is this passed by value or by address", "does this place need a drop", "is this receiver a borrow or owned", "how is a ref-arg's address materialized", "which types are Copy", "how a constant is read from an operand".
  • Parallel if/else ladders over the same kinds that drift out of sync.
  • Helpers that reimplement a query that already exists elsewhere (e.g. drop-schedule lookups, receiver-mode detection, effect classification).
  • Places that read a derived fact by re-deriving it rather than reading the canonical descriptor.

For each finding: note the file, the duplicated decision, where the canonical source of truth is (or should be), and the risk it poses (what divergence bug it could cause). Propose the cathedral (the one function/descriptor to compute it) and the read sites that should consume it.

Method

  • One file per pass; produce a short report per file (findings + proposed cathedral), not a blanket refactor.
  • Prioritize the hot correctness paths first: MIR lowering (MirLower.w), codegen (Codegen.w, CodegenDispatch.w), sema ownership/effects (Sema.w, SemaCheck.w, SemaDecl.w).
  • Each cathedralization lands as its own change with the full gate (with build && :fixpoint && :test) green.

References

  • docs/decisions.md D6 (FnAbi single ABI source of truth), D5 (share-place).
  • docs/fn_abi_descriptor_design.md.
  • Architecture issue, not a spec gap — no docs/with-specification.md section applies.

Activity

  1. ehartford commented on Jul 17, 2026

    @ehartford
    ContributorAuthor

    Cathedral-sweep candidate found during #668: src/CCodegen.w has the place-projection walk duplicated four times — the text renderer (place_text's projection loop) plus three near-identical tid walkers (place_tid, place_ref_target_tid, place_tid_no_infer). The #668 fix had to patch PK_TUPLE_INDEX into all four; before that, the renderer knew projections the tid walkers didn't, which produced the classic divergence bug (tuple field rendered correctly but typed as unknown → str == emitted as raw C ==). One projection-walk source of truth (walk once, yield text+tid together, or share the kind dispatch) would make that class impossible.

  2. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): still open. The candidate the last comment names is still there: src/CCodegen.w has the three tid walkers (place_tid, place_ref_target_tid, place_tid_no_infer) beside the text renderer.

    post-release: an open-ended audit.

  3. added this to the post-v0.16.0 milestone on Oct 28, 2026
  4. added a commit that references this issue on Nov 28, 2026
  5. ehartford commented on Nov 28, 2026

    @ehartford
    ContributorAuthor

    Cathedralized src/CCodegen.with in PR #3673: replaced the four duplicated place-projection walkers (place_tid, place_ref_target_tid, place_tid_no_infer, place_text) named in the earlier comments with one canonical walk_place_projections returning CcPlaceWalk (+156 / -373 lines net). Verified across all 47 test/emit_c/*.with fixtures and full seed-driven battery (emit-c-smoke green).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions