## Summary Root cause: ConditionLoweringBox was bypassing ConditionContext.alloc_value (SSOT allocator), causing ValueId collisions between JoinIR condition params and lowered instructions. ## Changes 1. **ConditionLoweringBox (expr_lowerer.rs)**: Must use ConditionContext.alloc_value - Pass &mut ConditionContext to lower_condition (SSOT allocator) - Eliminates internal counter usage 2. **Allocator unification (condition_lowerer.rs, method_call_lowerer.rs)**: - Accept &mut dyn FnMut() -> ValueId as allocator parameter - Ensures all lowering paths use same SSOT allocator 3. **Boundary Copy deduplication (joinir_inline_boundary_injector.rs)**: - Deduplicate condition_bindings by dst - Fail-Fast if different sources target same dst (MIR SSA violation) 4. **Trim pattern fixes (trim_loop_lowering.rs, trim_pattern_validator.rs, stmts.rs)**: - Use builder.next_value_id() instead of value_gen.next() in function context - Ensures function-level ValueId allocation respects reserved PHI dsts ## Acceptance ✅ ./target/release/hakorune --verify apps/tests/phase133_json_skip_whitespace_min.hako ✅ Smoke: phase135_trim_mir_verify.sh - MIR SSA validation PASS ✅ Regression: phase132_exit_phi_parity.sh - 3/3 PASS ✅ Regression: phase133_json_skip_whitespace_llvm_exe.sh - compile-only PASS 🤖 Generated with Claude Code Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
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 側の束縛寿命とは問題が違うので混ぜない。
- MIR(SSA/束縛寿命):
src/mir/builder/vars/*が{...}のレキシカルスコープとlocalのシャドウイングを管理する。 - JoinIR lowering(この層):
ScopeManagerがConditionEnv/LoopBodyLocalEnv/CapturedEnv/CarrierInfoを束ねて解決順序を固定する。 - 解析箱:
LoopConditionScopeBoxは「条件が参照して良いスコープか」を判定する箱で、名前解決そのものはしない。
詳しい境界ルールは docs/development/current/main/phase238-exprlowerer-scope-boundaries.md を参照してね。***