Commit Graph

8 Commits

Author SHA1 Message Date
0dc8510daf debug(stageb): センチネル追加でVMバグ特定 - using経由static box内loop不実行
## 🔍 調査結果
###  確認事項
- **本物の実装が呼ばれている**: SENTINEL出力で確認済み
  - 🔥 SENTINEL_SKIP_WS_CALLED!!!
  - 🎯 SENTINEL_KW_BOUNDARY_BEFORE_CALLED!!!
  - 🎯 SENTINEL_KW_BOUNDARY_AFTER_CALLED!!!
  - 🔤 SENTINEL_IS_IDENT_CHAR_CALLED!!!

### 🐛 重大バグ発見
**症状**: `FuncScannerBox.skip_whitespace` 内の `loop(1 == 1)` が実行されない

**証拠**:
```
[skip_ws] START idx=10 s.length()=173
[skip_ws] i=10 n=173
[skip_ws] RETURN i=10  ← ループボディが実行されず即座にreturn
```
- `[skip_ws] LOOP-TOP i=10` が**一度も出力されない**
- loop(1 == 1) の無限ループすら実行されない

**影響範囲**:
- box_name抽出失敗(空文字列)
- defs生成失敗(defs_len=0)
- canary テスト失敗

**問題の本質**:
- using 経由で読み込まれたモジュールの static box 内
- 静的メソッド呼び出し (`FuncScannerBox.skip_whitespace(...)`)
- loop 構文が VM/MIR レベルで実行されない

## 🔧 修正内容
1. **センチネル追加**: 4箇所に明確な出力追加
   - skip_whitespace, kw_boundary_before, kw_boundary_after, is_ident_char
2. **呼び出し修正**: `me.scan_all_boxes` → `StageBFuncScannerBox.scan_all_boxes`

## 📊 次のステップ
VM/MIR レイヤーでの loop 構文実装確認が必要

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 08:03:05 +09:00
54b2735f13 refactor(stageb): FuncScannerBox完全静的化 - new()撤廃でSSOT確立
## 構造改善
-  `new FuncScannerBox()` 完全撤廃(8箇所削除)
-  FuncScannerBox を純粋静的ヘルパー箱化
-  StageBFuncScannerBox を薄いデリゲートファサードに
-  全 `me.*` 呼び出しを `FuncScannerBox.*` 静的呼び出しに変換

## エラー解決
-  "Unknown method on InstanceBox" エラー根絶
-  "Type error: unsupported compare Lt on String" エラー解決
-  VM実行時の全エラー解消

## SSOT構造
FuncScannerBox (SSOT)
  ├─ 公開メソッド: skip_whitespace, find_matching_brace, 等
  ├─ 静的ヘルパーエイリアス: _parse_params, _strip_comments, 等
  └─ 内部実装: すべて FuncScannerBox.* 静的呼び出し

StageBFuncScannerBox (薄いファサード)
  └─ 全メソッドが FuncScannerBox への静的委譲のみ

## 未解決問題
- ⚠️ box_name 抽出が空文字列を返す(box検出は成功、名前抽出が失敗)
- ⚠️ defs_len=0 のまま(box_name='' のため _scan_methods が呼ばれない)

次のステップ: box_name抽出ロジックのデバッグ

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 07:45:28 +09:00
e809d3a79b refactor(stageb): Phase 25.3 FuncScanner boxification完了
- FuncScannerBox helper SSOT確立(8個のhelperに詳細コメント追加)
- StageBFuncScannerBox → FuncScannerBox完全委譲(約380行削減)
- scan_all_boxes状態フラグ整理(4つの状態遷移を明確化)
- 常時出力print削除(dev専用ログのみ保持)
- SSAテスト全pass(mir_funcscanner_scan_methods/fib_min)

Phase 25.3-B完了、次はfib defs canary緑化へ

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 07:01:21 +09:00
3a82633924 refactor(funcscanner): Region+next_i パターン統一 & SSA テスト追加
**FuncScanner .hako 側改善**:
- scan_all_boxes を Region + next_i 形式に統一(continue 多発による SSA/PHI 複雑さ削減)
- インデント修正(タブ→スペース統一)
- デバッグ print 削除

**SSA テスト追加**:
- lang/src/compiler/tests/funcscanner_scan_methods_min.hako
- src/tests/mir_funcscanner_ssa.rs (scan_methods & fib_min SSA デバッグテスト)

**Phase 25.3 ドキュメント**:
- docs/development/roadmap/phases/phase-25.3-funcscanner/ 追加

**関連**: Phase 25.3 FuncScanner 箱化準備作業

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 06:38:43 +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
80f8a7bc8c 🔧 Hotfix 7 (Enhanced): ValueId receiver alias tracking for nested loops
- Problem: Pinned receiver variables in loops cause undefined ValueId errors
- Enhanced fix: Update all receiver aliases (me + all __pin$N$@recv levels)
- Handles nested loops by updating previous pin levels
- Test status: Partial improvement, ValueId(50) → ValueId(40)
- Further investigation needed for complete fix

Files modified:
- src/mir/phi_core/loopform_builder.rs (emit_header_phis)
2025-11-19 00:02:41 +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
9e2fa1e36e Phase 21.6 solidification: chain green (return/binop/loop/call); add Phase 21.7 normalization plan (methodize static boxes). Update CURRENT_TASK.md and docs. 2025-11-11 22:35:45 +09:00