## Summary
Refactored loop-internal If statement handling into a boxified module
structure, achieving 154-line reduction (40%) from stmt_handlers.rs
with zero regression.
## Implementation
- Created if_in_loop/ module (9 files, ~480 lines)
- pattern.rs: IfInLoopPattern enum (5 variants)
- lowering/{empty,single_var_then,single_var_both,conditional_effect,unsupported}.rs
- Replaced lower_if_stmt_in_loop() (154 lines) with lower_if_stmt_in_loop_boxified()
- Made StatementEffect pub(crate) for module visibility
## Pattern Classification
1. Empty: condition-only check (no side effects)
2. SingleVarThen: if { x = a } → x = cond ? a : x
3. SingleVarBoth: if { x = a } else { x = b } → x = cond ? a : b
4. ConditionalEffect: if pred(v) { acc.push(v) } (filter pattern)
5. Unsupported: complex cases (Phase 54+)
## Test Results
✅ 56 JoinIR tests PASSED (0 failed, 0 regression)
✅ Build successful (1m 02s)
✅ Improved maintainability (easier to add new patterns)
## Files Changed
- src/mir/join_ir/frontend/ast_lowerer/
- if_in_loop/ (9 new files)
- mod.rs (+2 lines: module + pub use)
- stmt_handlers.rs (-154 lines: 40% reduction)
- CURRENT_TASK.md (+5 lines: Phase P1 記録)
- docs/development/refactoring/p1-if-handler-boxification-plan.md (new)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
AST/CFG → JoinIR frontend lowering layer
Scope:
- Normalize tiny AST/CFG patterns into JoinIR instructions without touching MIR or runtime concerns.
- Keep pattern-specific lowering isolated (if/return, loop variants, nested-if, read_quoted_from).
- Centralize expression/value extraction and small analysis helpers (if-in-loop var tracking).
Boundaries:
- No code generation beyond JoinIR; MIR/VM concerns belong to the bridge layer.
- Dev-flagged paths stay opt-in (HAKO_JOINIR_NESTED_IF, HAKO_JOINIR_READ_QUOTED*).
- Avoid hard-coded semantics; prefer structural pattern detection and reusable helpers.
Layout:
mod.rs: public surface + entry dispatch + shared counterscontext.rs:ExtractCtx(var ids) helpersexpr.rs: expression-to-JoinIR value extractionif_return.rs: simple if→Select loweringloop_patterns.rs: loop variants (simple/break/continue)read_quoted.rs: read_quoted_from loweringnested_if.rs: NestedIfMerge lowering/detectionanalysis.rs: loop if-var analysis + metadata helperstests.rs: frontend lowering tests gated by dev flags