Phase 33-11 Quick Wins - Task 2
Clarified that Pattern 4 (continue statements) is intentionally
not implemented, with explicit error message and migration guide.
Changes:
1. Added clear STUB IMPLEMENTATION header to module docs
2. Updated lower() to return explicit error (not silent stub)
3. Added #[doc(hidden)] and #[allow(dead_code)] annotations
4. Created comprehensive migration guide (phase-195-pattern4.md)
Status:
- Not implemented: Pattern 4 (continue)
- Use instead: Pattern 1-3 (simple/break/if+phi)
- Reason: Continue requires complex PHI analysis, lower priority
- Build: ✅ Success (no errors, no new warnings)
Migration path:
- Pattern 1: Simple while loops (no break/continue)
- Pattern 2: Loops with break
- Pattern 3: Loops with if + PHI (workaround for continue)
- Pattern 4: (FUTURE) Loops with continue statements
2.5 KiB
2.5 KiB
Phase 195: Pattern 4 (Loop with Continue) Implementation Plan
Status: Deferred (not yet implemented)
Overview
Pattern 4 handles loops with continue statements that skip to the next iteration. This is the most complex loop pattern due to additional control flow requirements.
Why Deferred?
-
Continue semantics require additional PHI and control flow analysis
- Continue creates an additional edge to the loop header
- Requires phi nodes for both continue and normal paths
- More complex than break (which exits the loop)
-
Pattern 3 covers most practical cases
- Pattern 1: Simple while loops
- Pattern 2: Loops with break
- Pattern 3: Loops with if + PHI (most common complex pattern)
- Pattern 4: Loops with continue (less common in practice)
-
Lower priority than break/if patterns
- Break patterns (Pattern 2) are more common
- If + PHI patterns (Pattern 3) handle complex control flow
- Continue can often be refactored using if statements
Example Use Case
local i = 0
local sum = 0
loop(i < 10) {
i = i + 1
if (i % 2 == 0) {
continue // Skip even numbers
}
sum = sum + i
}
// sum = 25 (1+3+5+7+9)
Implementation Requirements
When implemented, Pattern 4 lowering will need to:
- Detect continue statements in the loop body
- Generate PHI nodes for continue target (loop header)
- Handle carrier variables (i, sum) across continue boundaries
- Generate exit PHI nodes for final values after loop
Control Flow Diagram
header
|
v
body
|
/----+----\
/ \
v v
continue normal
| |
\-----+-------/
|
v
latch
|
/---+---\
/ \
v v
loop exit
Workaround
Until Pattern 4 is implemented, use Pattern 3 (if + PHI) instead:
local i = 0
local sum = 0
loop(i < 10) {
i = i + 1
if (not (i % 2 == 0)) { // Invert condition
sum = sum + i
}
}
Migration Path
- Pattern 1: Simple while loops (no break/continue)
- Pattern 2: Loops with break
- Pattern 3: Loops with if + PHI
- Pattern 4: (FUTURE) Loops with continue statements
Related Files
src/mir/builder/control_flow/joinir/patterns/pattern4_with_continue.rs- Stub implementationsrc/mir/join_ir/lowering/loop_with_continue_minimal.rs- Lowering logic (TODO)
Timeline
- Phase 195+: Implementation planned but deferred
- Priority: Lower than Pattern 1-3
- Complexity: High (additional control flow edges)