Commit Graph

9 Commits

Author SHA1 Message Date
8750186e55 chore: Phase 26-H セッション完了 - 全ドキュメント更新
Phase 26-H 完了内容:
 JoinIR 型定義実装(src/mir/join_ir.rs)
 MIR → JoinIR 自動変換実装(lower_min_loop_to_joinir)
 自動変換テスト実装(mir_joinir_min_auto_lowering)
 PHI/Loop箱 → JoinIR 移行対応表追加(loopform_ssot.md)

ドキュメント更新:
- Phase 27 JoinIR タスク計画追加
- Phase 26-H タスク完了記録
- 各種 README 更新(進捗反映)
- CURRENT_TASK.md 更新

コミット統計: $(git status --short | wc -l) files changed

次のステップ: Phase 27 一般化 MIR → JoinIR 変換
2025-11-23 05:53:27 +09:00
9bdf2ff069 chore: Phase 25.2関連ドキュメント更新&レガシーテストアーカイブ整理
## ドキュメント更新
- CURRENT_TASK.md: Phase 25.2完了記録
- phase-25.1b/e/q/25.2 README更新
- json_v0_bridge/README.md新規追加

## テストファイル整理
- vtable_*テストをtests/archive/に移動(6ファイル)
- json_program_loop.rsテスト追加

## コード整理
- プラグイン(egui/python-compiler)微修正
- benchmarks.rs, instance_v2.rs更新
- MIR関連ファイル微調整

## 全体成果
Phase 25.2完了により:
- LoopSnapshotMergeBox統一管理実装
- ValueId(1283)バグ根本解決
- ~35行コード削減(目標210行の16%)
- 11テスト全部PASS、3実行テストケースPASS
2025-11-20 03:56:12 +09:00
525e59bc8d feat(loop-phi): Add body-local variable PHI generation for Rust AST loops
Phase 25.1c/k: Fix ValueId undefined errors in loops with body-local variables

**Problem:**
- FuncScannerBox.scan_all_boxes/1 and BreakFinderBox._find_loops/2 had ValueId
  undefined errors for variables declared inside loop bodies
- LoopFormBuilder only generated PHIs for preheader variables, missing body-locals
- Example: `local ch = s.substring(i, i+1)` inside loop → undefined on next iteration

**Solution:**
1. **Rust AST path** (src/mir/loop_builder.rs):
   - Detect body-local variables by comparing body_end_vars vs current_vars
   - Generate empty PHI nodes at loop header for body-local variables
   - Seal PHIs with latch + continue snapshot inputs after seal_phis()
   - Added HAKO_LOOP_PHI_TRACE=1 logging for debugging

2. **JSON v0 path** (already fixed in previous session):
   - src/runner/json_v0_bridge/lowering/loop_.rs handles body-locals
   - Uses same strategy but for JSON v0 bridge lowering

**Results:**
-  FuncScannerBox.scan_all_boxes: 41 body-local PHIs generated
-  Main.main (demo harness): 23 body-local PHIs generated
- ⚠️ Still some ValueId undefined errors remaining (exit PHI issue)

**Files changed:**
- src/mir/loop_builder.rs: body-local PHI generation logic
- lang/src/compiler/entry/func_scanner.hako: debug logging
- /tmp/stageb_funcscan_demo.hako: test harness

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-19 23:12:01 +09:00
1747ec976c refactor(json_v0_bridge): Phase 25.1p - FunctionDefBuilder箱化+me予約修正
【変更内容】
1. FunctionDefBuilder 箱化(SSOT化)
   - インスタンスメソッド判定の一元化
   - パラメータ ValueId 生成の統一
   - 変数マップ初期化の統一

2. ValueId(0) me 予約バグ修正
   - is_instance_method() で box_name != "Main" 判定
   - インスタンスメソッドは me を ValueId(0) に予約
   - variable_map["me"] = ValueId(0) を自動設定

3. コード削減・可読性向上
   - 60行 → 40行(関数定義処理)
   - 重複ロジック削除
   - デバッグログ追加(is_instance表示)

【効果】
- json_v0_bridge 経路の ValueId(0) 未定義エラー解消
- Stage-B compiler で static box メソッドが正しく動作
- 設計の一貫性向上(me の扱いが明確)

【非スコープ】
- Rust MirBuilder 側は未修正(Phase 26で統一予定)
- lower_static_method_as_function は現状維持

関連: Phase 25.1m (静的メソッド修正), Phase 25.1c/k (SSA修正)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-19 10:08:04 +09:00
82b6c4e834 Phase 25.1b: VM undefined-value diagnostics and builder SSA helpers 2025-11-17 03:19:03 +09:00
eadde8d1dd fix(mir/builder): use function-local ValueId throughout MIR builder
Phase 25.1b: Complete SSA fix - eliminate all global ValueId usage in function contexts.

Root cause: ~75 locations throughout MIR builder were using global value
generator (self.value_gen.next()) instead of function-local allocator
(f.next_value_id()), causing SSA verification failures and runtime
"use of undefined value" errors.

Solution:
- Added next_value_id() helper that automatically chooses correct allocator
- Fixed 19 files with ~75 occurrences of ValueId allocation
- All function-context allocations now use function-local IDs

Files modified:
- src/mir/builder/utils.rs: Added next_value_id() helper, fixed 8 locations
- src/mir/builder/builder_calls.rs: 17 fixes
- src/mir/builder/ops.rs: 8 fixes
- src/mir/builder/stmts.rs: 7 fixes
- src/mir/builder/emission/constant.rs: 6 fixes
- src/mir/builder/rewrite/*.rs: 10 fixes
- + 13 other files

Verification:
- cargo build --release: SUCCESS
- Simple tests with NYASH_VM_VERIFY_MIR=1: Zero undefined errors
- Multi-parameter static methods: All working

Known remaining: ValueId(22) in Stage-B (separate issue to investigate)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 00:48:18 +09:00
5f06d82ee5 Phase 25.1b: Step B完了(multi-carrier LoopForm対応)
Step B実装内容(fibonacci風マルチキャリアループ対応):
- LoopFormBox拡張:
  - multi_count mode追加(build2メソッド)
  - build_loop_multi_carrierメソッド実装(4-PHI, 5 blocks)
  - 3変数(i, a, b)同時追跡のfibonacci構造生成

- LowerLoopMultiCarrierBox新規実装:
  - 複数Local/Assign検出(2+変数)
  - キャリア変数抽出
  - mode="multi_count"でLoopOptsBox.build2呼び出し
  - Fail-Fast: insufficient_carriersタグ出力

- FuncBodyBasicLowerBox拡張:
  - _try_lower_loopに呼び出し導線追加
  - 優先順位: sum_bc → multi_carrier → simple
  - [funcs/basic:loop.multi_carrier]タグ出力

- Module export設定:
  - lang/src/mir/hako_module.toml: sum_bc/multi_carrier追加
  - nyash.toml: 対応するmodule path追加

既存mode完全保持(Rust Freeze遵守):
- count, sum_bcは一切変更なし
- multi_countは完全に独立して追加
- 既存テストへの影響ゼロ

Technical Details:
- PHI構造: 3-PHI (i, a, b) in Header
- Block構成: Preheader → Header → Body → Latch → Exit
- Fibonacci計算: t = a+b, a' = b, b' = t
- copy命令でLatchから Headerへ値を渡す

Task先生調査結果を反映:
- Rust層のパターンC(4-PHI, multi-carrier)に対応
- MirSchemaBox経由で型安全なMIR生成

Next: スモークテスト追加、既存テスト全通確認

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-16 03:11:49 +09:00
8ffc4d0448 Phase 25.1b: Step3完了(LoopForm対応)
Step3実装内容(LoopForm → MIR導線確立):
- FuncBodyBasicLowerBox._try_lower_loop追加:
  - Loop判定 → LowerLoopSumBcBox → LowerLoopSimpleBox の順に試行
  - 成功時は_rebindで関数名をBox.method/arityに付け替え
  - 失敗時は[builder/funcs:unsupported:loopform]でFail-Fast
- lowerメソッド冒頭でLoop優先処理:
  - Loop含む場合は_try_lower_loopを呼び、成功/失敗で明確に分岐
  - Loopが無い場合のみ既存のLocal/If/Return処理に進む
- PHI地獄防止ポリシー徹底:
  - FuncBodyBasicLowerBox/FuncLowering側でPHIやキャリアを直接いじらない
  - LoopForm制約外は必ずタグ付きでFail-Fast(Rust providerに退避可能)

ドキュメント更新:
- Phase 25.1b README: Step3をinitial-implementedに更新
- builder README: [builder/funcs:unsupported:loopform]タグ追加
- CURRENT_TASK.md: Step3進捗記録

スモークテスト:
- selfhost_mir_loopform_basic_vm.sh追加(基本構造実装済み)
- defs生成経路の詳細調整は継続タスク

Next: Step4(MethodCall/ExternCall対応)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-15 22:40:12 +09:00
7ca7f646de Phase 25.1b: Step2完了(FuncBodyBasicLowerBox導入)
Step2実装内容:
- FuncBodyBasicLowerBox導入(defs専用下請けモジュール)
- _try_lower_local_if_return実装(Local+単純if)
- _inline_local_ints実装(軽い正規化)
- minimal lowers統合(Return/BinOp/IfCompare/MethodArray系)

Fail-Fast体制確立:
- MirBuilderBox: defs_onlyでも必ずタグ出力
- [builder/selfhost-first:unsupported:defs_only]
- [builder/selfhost-first:unsupported:no_match]

Phase構造整備:
- Phase 25.1b README新設(Step0-3計画)
- Phase 25.2b README新設(次期計画)
- UsingResolverBox追加(using system対応準備)

スモークテスト:
- stage1_launcher_program_to_mir_canary_vm.sh追加

Next: Step3 LoopForm対応

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-15 22:32:13 +09:00