Commit Graph

5 Commits

Author SHA1 Message Date
79b9d2b32c fix(mir): edge-copy insertion before terminator - resolve ValueId undefined errors
【問題】
Stage-B(JSON v0 Bridge)で「use of undefined value ValueId(...)」エラー発生
- 原因: merge.rs:38-42でedge-copyを終端命令**後**に追加していた
- 結果: Copy命令が到達不能となり、ValueIdが未定義のまま参照される

【根本原因分析】
1. if_else.rs:34で`set_terminator(Jump)`を設定
2. if_else.rs:62で`merge_var_maps()`呼び出し
3. merge.rs:39で`add_instruction(Copy)` ← **ここで終端後に追加!**
4. BasicBlock構造上、terminator設定後のadd_instruction()は到達不能

【修正内容】
1. BasicBlock::add_instruction_before_terminator()メソッド追加
   - 終端命令の有無に関わらず、instructions vecに追加
   - terminator自体の追加は許可しない(panic)

2. merge_values()でedge-copy挿入方法を変更
   - add_instruction() → add_instruction_before_terminator()
   - これによりCopyが終端の**前**に配置される

【修正箇所】
- src/mir/basic_block.rs: add_instruction_before_terminator()追加(12行)
- src/runner/json_v0_bridge/lowering/merge.rs: 呼び出し変更(2行)

【テスト結果】
 if文PHIテスト: /tmp/phi_simple_if2.nyash → 出力 1
 loop文PHIテスト: /tmp/phi_loop_test.nyash → 出力 10
 userbox_*スモークテスト: 全6テストPASS
⚠️ Stage-B: namespace conflict未解決のため未確認
   (apps/selfhost.vm.* と lang/hakorune.vm.* の競合)

【影響範囲】
- JSON v0 Bridge経路のif/else合流処理
- edge-copy(PHI-off mode)の正しい配置保証
- Builder経路は元々正常動作(影響なし)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-01 14:37:54 +09:00
adbb0201a9 chore(fmt): add legacy stubs and strip trailing whitespace to unblock cargo fmt 2025-09-17 07:43:07 +09:00
840c1b85ef feat: Fix VM SSA loop execution with proper phi node handling
Fixed infinite loop issue in VM by addressing phi node caching problem.
The phi node was caching the initial value and returning it for all
subsequent iterations, preventing loop variable updates.

Changes:
- Created vm_phi.rs module to separate loop execution logic (similar to mir/loop_builder.rs)
- Disabled phi node caching to ensure correct value selection each iteration
- Added LoopExecutor to track block transitions and handle phi nodes properly
- Fixed VM to correctly track previous_block for phi input selection

The VM now correctly executes SSA-form loops with proper variable updates:
- Loop counter increments correctly
- Phi nodes select the right input based on control flow
- Test case now completes successfully (i=1,2,3,4)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-18 23:36:40 +09:00
ba568f7dfb Implement Local and TryCatch lowering in MirBuilder
Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
2025-08-13 07:13:53 +00:00
774e0bb241 🚀 MIR Stage 1 Basic Infrastructure Complete - 20 Instructions + SSA + Effects
Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
2025-08-12 11:33:48 +00:00