feat(joinir): Phase 185-187 body-local infrastructure + string design

Phase 185: Body-local Pattern2/4 integration skeleton
- Added collect_body_local_variables() helper
- Integrated UpdateEnv usage in loop_with_break_minimal
- Test files created (blocked by init lowering)

Phase 186: Body-local init lowering infrastructure
- Created LoopBodyLocalInitLowerer box (378 lines)
- Supports BinOp (+/-/*//) + Const + Variable
- Fail-Fast for method calls/string operations
- 3 unit tests passing

Phase 187: String UpdateLowering design (doc-only)
- Defined UpdateKind whitelist (6 categories)
- StringAppendChar/Literal patterns identified
- 3-layer architecture documented
- No code changes

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-09 00:59:38 +09:00
parent b6e31cf8ca
commit d4231f5d3a
13 changed files with 2472 additions and 11 deletions

View File

@ -195,6 +195,7 @@ JoinIR ラインで守るべきルールを先に書いておくよ:
- 責務:
- ループで更新される変数carrierを検出し、UpdateExpr を保持。
- Pattern 4 では実際に更新されるキャリアだけを残す。
- **Phase 187設計**: String 更新は UpdateKind ベースのホワイトリストで扱う方針StringAppendChar/Literal は Phase 188+ で実装予定)。
- **ExitMeta / JoinFragmentMeta**
- ファイル: `carrier_info.rs`
@ -326,9 +327,33 @@ Phase 181 で JsonParserBox 内の 11 ループを棚卸しした結果、
- 5 つの unit test で変数検出ロジックを検証
- **テスト**: `apps/tests/phase183_body_only_loopbodylocal.hako` で動作確認
- `[TrimLoopLowerer] No LoopBodyLocal detected` トレース出力で body-only 判定成功
- **次の課題**: body-local 変数の MIR lowering 対応(`local temp` in loop body
- **次の課題→Phase 184 で対応)**: body-local 変数の MIR lowering 対応(`local temp` in loop body
- Phase 183 では "Trim promotion しない" 判定まで完了
- 実際の MIR 生成は Phase 184+対応予定
- 実際の MIR 生成インフラは Phase 184 で実装済みPattern2/4 への統合は次フェーズ)
### 4.2 Body-local 変数の MIR lowering 基盤Phase 184
Phase 184 では、「条件には出てこない LoopBodyLocal 変数」を安全に JoinIR→MIR に落とすためのインフラ箱だけを追加したよ。
- **LoopBodyLocalEnv**
- 責務: ループ本体内で `local` 定義された変数の「JoinIR 側 ValueId のみ」を管理する。
- 入力: ループ本体 AST / JoinIR ビルダー。
- 出力: `name -> join_value_id` のマップ。
- 特徴: host 側との対応は持たない。ConditionEnv とは完全に分離された「本体専用ローカル環境」。
- **UpdateEnv**
- 責務: UpdateExpr lowering 時の変数解決順序をカプセル化する。
- 仕様: `ConditionEnv`(条件・キャリア)と `LoopBodyLocalEnv`(本体ローカル)を中で束ねて、
`resolve(name)` で「条件→ローカル」の順に ValueId を返す。
- 利用箇所: CarrierUpdateEmitter / CarrierUpdateLowerer が、変数名ベースで UpdateExpr を JoinIR に落とす時に利用。
- **CarrierUpdateEmitter 拡張**
- 責務: `LoopUpdateSummary`UpdateKindに応じて、int 系キャリア更新を JoinIR 命令に変換する。
- 変更点: 直接 `variable_map` を読むのではなく、`UpdateEnv` 経由で名前解決するように変更。
- 効果: 本体専用の LoopBodyLocal 変数(`temp`を、Pattern2/4 から安全に扱える土台が整った。
このフェーズではあくまで「ストレージ・名前解決・emit の箱」までで止めてあり、
Pattern2/4 への統合(実際に Body-local 更新を使うループを JoinIR 経路に載せるは次フェーズPhase 185 以降)の仕事として分離している。
- 構造的に P1P4 で対応可能(代表例):
- `_parse_number` / `_atoi`P2 Break- Phase 182 でブロッカー特定済み
- `_match_literal`P1 Simple while- Phase 182 で動作確認済み ✅