fix(loop_builder): ValueId(0)パラメータGUARD check削除 - ループ生成バグ修正

## 🎯 根本原因(Task先生特定)
- `src/mir/loop_builder.rs` L203-215のGUARD checkが誤動作
- ValueId(0)を「常に未初期化」と判定していたが、実際には**最初のパラメータとして正当**
- skip_whitespace(s, idx)のsがValueId(0)で弾かれ、ループが生成されない

##  修正内容
- GUARD check完全削除(L203-215)
- 経緯説明コメント追加

##  修正効果
- ループブロック生成: 33 blocks確認
- 既存テスト: 全PASS(mir_basic_loop, mir_loopform_exit_phi)
- 回帰なし

##  別問題発見(次のタスク)
- PHI node predecessor mismatch (別バグ)
- これはExit PHI生成の問題

## 📋 調査プロセス
- Step 1-3: 最小再現ケース+Rustテスト作成
- Step 4: Task先生でMIR解析→根本原因特定
- Step 5-6: loop_builder.rs修正
- Step 7: 全確認(既存テスト全PASS)

🤖 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-20 08:41:37 +09:00
parent 471052ad8d
commit cbf852b7a4
6 changed files with 164 additions and 325 deletions

View File

@ -200,19 +200,11 @@ impl<'a> LoopBuilder<'a> {
}
}
// GUARD: Check for invalid ValueId(0) before proceeding
// ValueId(0) indicates uninitialized variables - skip loop construction entirely
for (name, value) in &current_vars {
if value.0 == 0 {
if std::env::var("NYASH_LOOPFORM_DEBUG").is_ok() {
eprintln!("[build_loop_with_loopform] ⚠️ GUARD: Detected ValueId(0) for '{}', skipping entire loop construction", name);
eprintln!("[build_loop_with_loopform] Returning ValueId(0) without emitting any instructions");
}
// Return ValueId(0) directly without emitting instructions
// This allows the caller to retry loop construction with properly initialized variables
return Ok(ValueId(0));
}
}
// Phase 25.3: GUARD check removed - ValueId(0) is valid for first parameters
// Previous code incorrectly assumed ValueId(0) always meant uninitialized variables,
// but it's actually the correct ID for the first parameter in functions like:
// skip_whitespace(s, idx) -> s=ValueId(0), idx=ValueId(1)
// This caused loops in such functions to be entirely skipped.
let preheader_id = self.new_block();
let header_id = self.new_block();