feat(joinir): Phase 135 P0 - ConditionLoweringBox allocator SSOT (ValueId collision fix)

## 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>
This commit is contained in:
nyash-codex
2025-12-15 18:49:08 +09:00
parent e8e4779942
commit d82c332a40
15 changed files with 186 additions and 70 deletions

View File

@ -363,7 +363,8 @@ impl TrimLoopLowerer {
use crate::mir::instruction::MirInstruction;
use crate::mir::types::BinaryOp;
let one = emit_integer(builder, 1);
let start_plus_1 = builder.value_gen.next();
// Phase 135 P0: Use function-level ValueId (SSOT)
let start_plus_1 = builder.next_value_id();
builder.emit_instruction(MirInstruction::BinOp {
dst: start_plus_1,
op: BinaryOp::Add,
@ -372,7 +373,8 @@ impl TrimLoopLowerer {
})?;
// Generate: ch0 = s.substring(start, start+1)
let ch0 = builder.value_gen.next();
// Phase 135 P0: Use function-level ValueId (SSOT)
let ch0 = builder.next_value_id();
builder.emit_method_call(
Some(ch0),
s_id,

View File

@ -47,12 +47,14 @@ impl TrimPatternValidator {
let ws_const = emit_string(builder, ws_char.clone());
// eq_check = ch == ws_const
let eq_dst = builder.value_gen.next();
// Phase 135 P0: Use function-level ValueId (SSOT)
let eq_dst = builder.next_value_id();
emit_eq_to(builder, eq_dst, ch_value, ws_const)?;
result_opt = Some(if let Some(prev_result) = result_opt {
// result = prev_result || eq_check
let dst = builder.value_gen.next();
// Phase 135 P0: Use function-level ValueId (SSOT)
let dst = builder.next_value_id();
builder.emit_instruction(MirInstruction::BinOp {
dst,
op: BinaryOp::Or,