Files
hakorune/src/mir/join_ir/lowering
tomoaki bfbc9b26bf fix(joinir): Phase 283 P0 - Pattern3 Undefined ValueId Bug Fix
- Fix: extract_if_condition() moved after local_cond_env construction
  (loop_with_if_phi_if_sum.rs:175)
  - Root cause: condition extraction before i_param/sum_param creation
  - Result: i % 2 referenced caller's ConditionEnv with unmapped ValueId
- Fail-Fast: Add condition_bindings validation in merge (mod.rs)
- Fixture: Update loop_if_phi.hako for C2 compatibility (sum.toString())
- Verified: VM execution outputs sum=9 

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-23 08:14:27 +09:00
..

JoinIR Lowering (ExprLowerer / ScopeManager / Envs)

このディレクトリは JoinIR lowering の中でも、条件式や環境まわりの箱ExprLowerer, ScopeManager, ConditionEnv, LoopBodyLocalEnv, UpdateEnv など)を扱う層だよ。コードを触るときは、以下の最小ルールを守ってね。

  • ExprLowerer は ScopeManager 経由のみ で名前解決する。ConditionEnv / LoopBodyLocalEnv / CapturedEnv / CarrierInfo に直接触らない。
  • 条件式から UpdateEnv を参照しない。UpdateEnv はキャリア更新専用で、header/break/continue 条件は ScopeManager→ConditionEnv で完結させる。
  • ConditionEnv は「条件で参照する JoinIR ValueId だけ」を持つ。body-local を直接入れず、必要なら昇格ScopeManager に解決を任せる。
  • Fail-Fast 原則: Unsupported/NotFound は明示エラーにして、by-name ヒューリスティックや静かなフォールバックは禁止。

名前解決の境界SSOT

このディレクトリの ScopeManager は「JoinIR lowering の中で」名前を ValueId に解決するための箱だよ。 同じ “名前” でも、MIR 側の束縛寿命とは問題が違うので混ぜない。

  • MIRSSA/束縛寿命): src/mir/builder/vars/*{...} のレキシカルスコープと local のシャドウイングを管理する。
  • JoinIR loweringこの層: ScopeManagerConditionEnv/LoopBodyLocalEnv/CapturedEnv/CarrierInfo を束ねて解決順序を固定する。
  • 解析箱: LoopConditionScopeBox は「条件が参照して良いスコープか」を判定する箱で、名前解決そのものはしない。

詳しい境界ルールは docs/development/current/main/phase238-exprlowerer-scope-boundaries.md を参照してね。***