e30116f53d
feat(joinir): Phase 171-fix ConditionEnv/ConditionBinding architecture
...
Proper HOST↔JoinIR ValueId separation for condition variables:
- Add ConditionEnv struct (name → JoinIR-local ValueId mapping)
- Add ConditionBinding struct (HOST/JoinIR ValueId pairs)
- Modify condition_to_joinir to use ConditionEnv instead of builder.variable_map
- Update Pattern2 lowerer to build ConditionEnv and ConditionBindings
- Extend JoinInlineBoundary with condition_bindings field
- Update BoundaryInjector to inject Copy instructions for condition variables
This fixes the undefined ValueId errors where HOST ValueIds were being
used directly in JoinIR instructions. Programs now execute (RC: 0),
though loop variable exit values still need Phase 172 work.
Key invariants established:
1. JoinIR uses ONLY JoinIR-local ValueIds
2. HOST↔JoinIR bridging is ONLY through JoinInlineBoundary
3. condition_to_joinir NEVER accesses builder.variable_map
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-07 01:45:03 +09:00
caf38dba19
feat(joinir): Phase 190 - LoopExitBinding boxification
...
Formalize exit PHI → variable_map reconnection with explicit LoopExitBinding
structure. Eliminates hardcoded variable names and prepares for Pattern 4+
multi-carrier support.
Key changes:
1. **New LoopExitBinding struct**:
- carrier_name: String (e.g., "sum", "count")
- join_exit_value: ValueId (JoinIR exit value)
- host_slot: ValueId (variable_map destination)
Makes it explicit: WHICH variable, FROM where, TO where.
2. **Updated JoinInlineBoundary**:
- Replaced implicit host_outputs: Vec<ValueId>
- With explicit exit_bindings: Vec<LoopExitBinding>
- Old APIs marked #[deprecated] for backward compatibility
3. **Pattern 3 now uses explicit bindings**:
Before: boundary.host_outputs = vec![sum_var_id] // implicit
After: boundary.exit_bindings = vec![LoopExitBinding {
carrier_name: "sum".to_string(),
join_exit_value: ValueId(18),
host_slot: sum_var_id,
}]
4. **merge_joinir_mir_blocks() updated**:
- Consumes exit_bindings instead of bare ValueIds
- Enhanced debug output shows carrier names
- Validates carrier name matches variable_map expectations
Benefits:
- Self-documenting code: bindings explain themselves
- Multi-carrier ready: Pattern 4+ just extend the vec![]
- Type-safe: No implicit semantics
- Debuggable: Explicit carrier name in logs
Test status:
- Build: ✅ SUCCESS (0 errors, 47 warnings)
- Pattern 3: ✅ PASS (no regressions)
- Backward compatibility: ✅ Maintained via #[deprecated]
Prepare for Phase 191: Pattern Router Table and Phase 192: JoinLoopTrace
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: ChatGPT <noreply@openai.com >
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-05 19:59:40 +09:00
0397df5240
refactor(joinir): Phase 189 - Remove hardcoded 'sum' variable, generalize exit PHI connection
...
Key improvements:
1. **Eliminate hardcoded variable name**: Replace hardcoded "sum" with generic
ValueId-based variable_map updates. Add new JoinInlineBoundary constructor
`new_with_input_and_host_outputs()` for Pattern 3.
2. **Generalize output slot mapping**: Exit PHI result now updates all host_outputs
entries in variable_map, not just hardcoded "sum". Prepares for future
multi-carrier patterns.
3. **PHI preservation in blocks**: Fix block finalization to preserve existing
PHI instructions (from handle_select) instead of overwriting them.
4. **Stable function name→ValueId mapping**: Ensure consistent ValueId
assignment for tail call detection across multi-function merges.
5. **Enhanced debugging**: Add detailed logging in block converter and meta
analysis for PHI verification.
Files modified:
- src/mir/builder/control_flow.rs: Remove hardcoded "sum", use boundary outputs
- src/mir/join_ir/lowering/inline_boundary.rs: Add new constructor
- src/mir/join_ir_vm_bridge/joinir_block_converter.rs: Stable mappings, PHI preservation
- src/mir/join_ir_vm_bridge/meta.rs: Debug output for PHI tracking
- src/mir/builder/joinir_id_remapper.rs: PHI value remapping
- src/mir/builder/joinir_inline_boundary_injector.rs: Span preservation
Test status: Pattern 3 (loop_if_phi.hako) still produces correct result (sum=9, RC=9)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: ChatGPT <noreply@openai.com >
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-05 19:39:54 +09:00
d303d24b43
feat(joinir): Phase 188 JoinInlineBoundary + Pattern 1 working! 🎉
...
Major milestone: loop_min_while.hako outputs "0 1 2" correctly!
## JoinInlineBoundary (Option D from ChatGPT Pro design review)
- New struct for clean SSA boundary between JoinIR and host function
- JoinIR uses local ValueIds (0,1,2...) - no host ValueId dependency
- Copy injection at entry block connects host → JoinIR values
## Pattern 1 Simple While Loop
- Refactored to use pure local ValueIds
- Removed Pattern1Context dependency on host ValueIds
- Clean separation: lowerer generates, merger connects
## Key Design Principles (Box Theory)
- Box A: JoinIR Frontend (host-agnostic)
- Box B: Join→MIR Bridge (independent functions)
- Box C: JoinInlineBoundary (boundary info only)
- Box D: JoinMirInlineMerger (Copy injection)
## Files Changed
- NEW: inline_boundary.rs - JoinInlineBoundary struct
- control_flow.rs - merge with boundary, void return fix
- simple_while_minimal.rs - pure local ValueIds
- mod.rs - module export
Test: NYASH_DISABLE_PLUGINS=1 ./target/release/hakorune apps/tests/loop_min_while.hako
Output: 0\n1\n2 ✅
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-05 13:46:44 +09:00