Skip to content

Codegen never emits a placeholder for a body it could not lower: one loud BUG naming the function and location (#2006) - #2010

Merged
ehartford merged 1 commit into
wave-sema2from
fix-2006
Oct 3, 2026
Merged

ehartford merged 1 commit into
wave-sema2from
fix-2006

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Fixes #2006 (CLAUDE.md No Silent Fallbacks). Codegen.mir_emit_failed replaces every fallback: error: BUG: codegen could not emit <the terminator of bbN | statement S in bbN | a body with no block> of '<fn>' at <file:line:col> + had_error (unreachable only so the verifier accepts the half-built fn). Converted: generate_default_trait_method_for_impl (ret 0), emit_module_runtime_init_fn (ret null; kept emitting into a terminated block), gen_closure (ret 0), gen_function_mir + mono twin (bare unreachable), gen_async_block (ignored statement results), four empty-body default returns, TK_RETURN's build_default_value on a missing return slot, and the global-initializer 'MIR is invalid' print that never set had_error. Reachability: the no-block and missing-return-slot paths are unreachable (MirBuilder.init creates the entry block; return slots precede the first block) — commented, the BUG fires if ever reached; an unemittable statement/terminator is reachable only through a codegen gap (post-Sema MIR must lower, D65), hit by nothing in the gate or 40 closure/async/global/trait-default fixtures. Shared loop mir_emit_block_or_report also fixes the default-method overflow-check terminator (overlaps stack #2007's 8aac1e66 — take this version on rebase). :dev, :deep-debug-tool-tests, gate green.

@ehartford
ehartford changed the base branch from main to wave-sema2 October 3, 2026 07:01
@ehartford
ehartford added this pull request to stack #2013 October 3, 2026 07:01
…ported BUG, never a placeholder return (#2006)

Every body emitter papered over a failed mir_emit_stmt / mir_emit_term and
the program compiled: the default trait method and closure emitters built
`ret 0`, the global-initializer emitter `ret null`, gen_function_mir and its
mono twin a bare `unreachable` (the closure and initializer emitters kept
emitting statements into the terminated block), and the async-block emitter
ignored a statement's result outright. A body with no block got a default
`ret` in four emitters, TK_RETURN returned build_default_value when the
return slot was missing, and the initializer emitter printed
"error: const initializer MIR is invalid" and went on to link.

Codegen.mir_emit_failed now names the function and the source location
(`error: BUG: codegen could not emit the terminator of bb3 of 'P.total' at
file.w:5:35`), sets had_error, and leaves `unreachable` only so the
half-built function stays well formed for the verifier. The three
synthesized-body emitters (default trait methods, global initializers,
async blocks) share mir_emit_block_or_report, which also places the
terminator where the builder stands: the default-trait-method loop tested
the MIR block's first LLVM block, so after a checked-arithmetic statement
(`arith.ok`) it skipped the terminator (the stack #1992 commit 8aac1e66
fixes the same line; the two resolve to this loop).

Reachability, per site:
- a body with no block (gen_function_mir, _mono, closure, async block,
  default trait method, initializer): unreachable — every body comes from
  MirBuilder.init, which creates the entry block, and the gen_function_mir
  callers already skip block_count() == 0 (CodegenDispatch dispatch,
  Codegen gen_owned bodies). A comment states it at each site; the BUG
  fires if it is ever reached.
- TK_RETURN without a return slot: unreachable — all six emitters insert
  mir_local_ptrs/mir_local_types[0] before their first block; mir_emit_term
  now returns false there, so the caller reports it.
- mir_emit_stmt / mir_emit_term returning false: post-Sema MIR must lower
  (D65), so only a codegen gap reaches them. None does in the gate (the
  release build compiles the compiler, selfcheck, examples-tests: zero
  BUG lines), nor in stage1 over 40 closure/async/global/trait-default behavior fixtures. A reaching test needs a
  codegen gap or a fault-injection hook, which do not exist.
@ehartford
ehartford marked this pull request as ready for review October 3, 2026 07:37
@ehartford
ehartford merged commit c884c1c into main Oct 3, 2026
@ehartford
ehartford deleted the fix-2006 branch October 3, 2026 07:38
ehartford added a commit that referenced this pull request Oct 3, 2026
…orkarounds (#2020)

* Seed: darwin nightly-20261003-local-1-c884c1c2a17c

Cut from main c884c1c (stack #2001/#2010 merged); builds main from a
fresh checkout to a stage2 == stage3 fixpoint. Workflow pins rewritten by
tools/bump_seed_pins.w.

* Sema: restore the FacadeCallEffect.param_sources comment the old seed forced onto one line

#2001 folded it so the c95ae12 seed's cross-file view-use scan would not
refuse src/main.w. The new seed carries #2001's own-file scan:
`src/main check src/main.w` is ok with the original text.

* ComptimeTransform: a user derive's source is moved out, not cloned (stale D32 seed workaround)

The clone stood in for `move` while the seed enforced the retired §2.4
Drop-owner condition. The new seed accepts `move evald.value.text` on a
`var` base (D82). Stage1 (:dev) runs spec_ss17_3_user_defined_derive and
every behav_derive_* / derive_* fixture to its expected output, and still
refuses err_user_derive_bad_output.

* wrap_diag_spans: the splice helper works around #2023, not a frozen seed

Inlining it under the new seed (and its stage1) fails codegen:
`wrong argument type actual=ptr expected=i64 fn=apply_edits` — the
str.slice call path passes a Vec element view where it takes i64. The
comment now names the real bug; the helper stays until #2023 is fixed.

* build: drop the legacy "armv8" arch spelling (stale seed workaround)

comp_arch_is_aarch64 said to delete its "armv8" branch after the next
reseed. Every pinned seed (darwin c884c1c, linux-x86_64 2e8defa,
linux-aarch64 v0.15.2.0, windows-x86_64 bd6e00d, windows-aarch64
v0.15.2.1) routes arch() through with_sysinfo_arch -> rt_sysinfo_arch, and
each of its rt/*_aarch64.w returns "aarch64"; none produces "armv8". So the
predicate and the separate Windows/Linux `armv8 or aarch64` checks in
build.w and build/*.w become plain `== "aarch64"`. build.w and
lib/std/build.w check ok under out/release/bin/with and the seed.

* Sema: loop_break_flat's comment states the design, not a seed limit

The flat Vec[i32] began as seed compatibility (#613, no Vec[Vec[i32]]);
the seed limit is gone (Sema.w already holds Vec[Vec[...]] fields), but the
layout stays: loop regions are strictly LIFO, and loop_entry_flat shares
each frame's offset into the same shape.

---------

Co-authored-by: Eric Hartford <[email protected]>
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.

Codegen silent fallbacks: when a default trait method, closure or global-initializer body can't place its terminator, the emitter returns a constant 0

1 participant