feat(phase21.5): selfhost-first bring-up infrastructure

## Task 1: Child Process stderr Capture 
- Fix: Child process now captures stderr (2>&1 instead of 2>/dev/null)
- Added: Detailed failure logs with last 80 lines on error
- Tags: [builder/selfhost-first:fail:child:rc=N] and [fail:no-ok-marker]
- Location: tools/hakorune_emit_mir.sh:try_selfhost_builder()

## Task 2: Builder Box Parameterization + Min Fallback 
- Added: HAKO_MIR_BUILDER_BOX env var (default: hako.mir.builder)
- Added: HAKO_SELFHOST_TRY_MIN=1 for automatic min builder fallback
- Location: tools/hakorune_emit_mir.sh
- Benefit: Isolate using resolution vs implementation issues

## Task 3: Loop Minimal Semantics Verification 
- Verified: PHI/increment/backedge implementation is correct
- Structure: entry(0) → loop(1) → body(2) → exit(3)
- PHI: i = {i0, entry} | {i_next, body}
- Location: lang/src/mir/builder/internal/loop_opts_adapter_box.hako

## Task 4: Using Resolution Diagnostics 
- Added: [mirbuilder/entry:build] debug tag at builder entry
- Added: HAKO_MIR_BUILDER_TRACE propagation
- Location: lang/src/mir/builder/MirBuilderBox.hako
- Benefit: Pinpoint whether using resolution succeeds

## Task 5: EXE Canary Strict Validation 
- Changed: Now requires exact rc=10 (loop limit value)
- Added: LLVM IR dump on failure (first 120 lines)
- Location: tools/smokes/v2/profiles/quick/core/phase2100/stageb_loop_jsonfrag_crate_exe_canary_vm.sh

## Environment Variables
New:
- HAKO_MIR_BUILDER_BOX (default: hako.mir.builder)
- HAKO_SELFHOST_TRY_MIN (default: 0)

Enhanced:
- HAKO_SELFHOST_TRACE → HAKO_MIR_BUILDER_TRACE propagation
- HAKO_SELFHOST_NO_DELEGATE → Better diagnostics

## Implementation Principles
- 既定挙動不変 (Default unchanged)
- Dev toggle guarded (all new features)
- Minimal diff, surgical changes
- Fail-fast with clear diagnostics
- Easy rollback via env vars

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-11 09:54:27 +09:00
parent 2299da7663
commit edb3ace102
5 changed files with 53 additions and 8 deletions

View File

@ -29,6 +29,12 @@ static box MirBuilderBox {
// Main entry
method emit_from_program_json_v0(program_json, opts) {
// Debug tag (dev toggle only)
using "hako.mir.builder.internal.builder_config" as BuilderConfigBox
if BuilderConfigBox.trace_enabled() == 1 {
print("[mirbuilder/entry:build]")
}
if program_json == null {
print("[mirbuilder/input/null] program_json is null")
return null

View File

@ -30,6 +30,7 @@ static box BuilderConfigBox {
// Loop/JsonFrag related
loop_jsonfrag_on() { return self._is_on("HAKO_MIR_BUILDER_LOOP_JSONFRAG") }
loop_force_jsonfrag_on() { return self._is_on("HAKO_MIR_BUILDER_LOOP_FORCE_JSONFRAG") }
jsonfrag_normalize_on() { return self._is_on("HAKO_MIR_BUILDER_JSONFRAG_NORMALIZE") }
skip_loops_on() { return self._is_on("HAKO_MIR_BUILDER_SKIP_LOOPS") }

View File

@ -27,6 +27,7 @@ static box LoopOptsBox {
// Block 2 (body): i_next = i+1, jump back to loop
// Block 3 (exit): ret i (final loop variable value)
// Value IDs: r1=i0(0), r2=limit(N), r3=phi(i), r4=cmp, r5=i_next, r10=const(1)
// PHI semantics: r3 receives r1 from block 0 (entry), r5 from block 2 (backedge)
local mir = "{\"functions\":[{\"name\":\"main\",\"params\":[],\"locals\":[],\"blocks\":[" +
"{\"id\":0,\"instructions\":[" +
"{\"op\":\"const\",\"dst\":1,\"value\":{\"type\":\"i64\",\"value\":0}}," +