Repository navigation
Codegen never emits a placeholder for a body it could not lower: one loud BUG naming the function and location (#2006) - #2010
Merged
Merged
Conversation
…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
marked this pull request as ready for review
October 3, 2026 07:37
This was referenced Oct 3, 2026
with check accepts method calls with the wrong argument count; fails late at LLVM verification
#1973
Closed
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.