feat(joinir): Phase 225 - MethodCall init meta-driven lowering

- Remove hardcoded method whitelist from loop_body_local_init.rs
- Remove hardcoded box name matching
- Delegate to MethodCallLowerer for all MethodCall handling
- CoreMethodId metadata is now SSOT for init method validation
- substring now works in body-local init (-82 net lines)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-10 19:08:18 +09:00
parent 4e00edcea5
commit 0243de871f
7 changed files with 765 additions and 172 deletions

View File

@ -296,20 +296,22 @@ Local Region (1000+):
- PatternPipelineContext.is_if_sum_pattern() で条件複雑度をチェック。
- P3 if-sum mode は単純比較のみ受理、複雑条件は PoC lowerer へフォールバック。
- **MethodCallLowererPhase 224-B 実装完了)**
- **MethodCallLowererPhase 224-B / 224-C / 225 実装完了)**
- ファイル: `src/mir/join_ir/lowering/method_call_lowerer.rs`
- 責務:
- AST MethodCall ノードを JoinIR BoxCall に loweringメタデータ駆動
- CoreMethodId の `is_pure()`, `allowed_in_condition()`, `allowed_in_init()` でホワイトリスト判定。
- Phase 224-B P0: 引数なしメソッドのみ対応(`s.length()`, `arr.length()` 等)。
- CoreMethodId の `is_pure()`, `allowed_in_condition()`, `allowed_in_init()` などのメタでホワイトリスト判定。
- Phase 224-B: 引数なしメソッド`length()` 等)対応
- Phase 224-C: 引数付きメソッド(`substring(i,j)`, `indexOf(ch)` 等)対応。
- Phase 225: body-local init 用の MethodCall lowering も完全に CoreMethodId メタ駆動に統一(メソッド名ハードコード/Box 名ハードコードを削除)。
- 設計原則:
- **メソッド名ハードコード禁止**: CoreMethodId メタデータのみ参照。
- **Fail-Fast**: ホワイトリストにないメソッドは即座にエラー。
- **Box-First**: 単一責任("このMethodCallをJoinIRにできるか")だけを担当。
- 使用箇所:
- `condition_lowerer.rs` の `lower_value_expression()` から呼び出し。
- Pattern 2/3/4 のループ条件式で `s.length()` 等をサポート可能
- 次ステップ: Phase 224-C で引数付きメソッド(`substring(i, i+1)`, `indexOf(ch)`対応予定
- `loop_body_local_init.rs` の init lowering からも呼び出され、bodylocal init での substring/indexOf などを lowering
- Pattern 2/3/4 のループ条件式や bodylocal init で `s.length()`, `s.substring(...)`, `digits.indexOf(ch)` 等をサポート可能(メタ条件を満たす範囲で)。
- **LoopBodyCarrierPromoterPhase 171-C-2 実装済み)**
- ファイル: `src/mir/loop_pattern_detection/loop_body_carrier_promoter.rs`
@ -855,10 +857,17 @@ JoinIR は Rust 側だけでなく、将来的に .hako selfhost コンパイラ
- テスト: phase192_normalization_demo.hako → 123 ✅
- 制約: MethodCall を含む init 式は Phase 193 で対応予定
3. **✅ MethodCall を含む init 式の対応** → Phase 193 完了
3. **✅ MethodCall を含む init 式の対応** → Phase 193 完了、Phase 225 でメタ駆動化
- `local digit = digits.indexOf(ch)` のような MethodCall init の lowering 完了
- LoopBodyLocalInitLowerer 拡張BoxCall emission
- メソッド whitelist: indexOf, get, toString 対応
- **Phase 193**: ハードコードされた whitelist: indexOf, get, toString 対応
- **Phase 225**: CoreMethodId メタ駆動化によりハードコード完全削除 ✅
- `SUPPORTED_INIT_METHODS` 定数削除(メソッド名 whitelist
- Box 名の match 文削除(`indexOf → StringBox` 等のハードコード)
- MethodCallLowerer への委譲により単一責任原則達成
- `allowed_in_init()` メタデータで whitelist 管理
- **substring メソッド追加**: Phase 225 で substring が body-local init で使用可能に
- **コード削減**: -82 行158削除 - 76追加
- 制約: body-local init のみ対応、condition 内の MethodCall は Phase 200+
4. **✅ JsonParser 実戦投入P1/P2/P5 検証)** → Phase 194 完了