Skip to content
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b0c3aed
Add ControlFlowType enum, ControlFlowMarker class, and RuntimeControl…
fglock Nov 6, 2025
e7b78e9
Modify EmitControlFlow to return marked RuntimeList for non-local con…
fglock Nov 6, 2025
48d5cd5
Add control flow check infrastructure (disabled) - WIP Phase 3
fglock Nov 6, 2025
10f631b
Phase 2 complete: Non-local control flow via tagged returns (99.8%)
fglock Nov 6, 2025
937c0b3
Fix plan: Skip Phase 3 (call-site checks), renumber to make straightf…
fglock Nov 6, 2025
86daaee
Phase 3 partial: Add TAILCALL trampoline at returnLabel (99.8% mainta…
fglock Nov 6, 2025
c03f76f
Phase 3: Tail call trampoline working, call-site checks deferred
fglock Nov 6, 2025
28f39a0
feat: Add feature flags and Phase 3 loop handler infrastructure
fglock Nov 6, 2025
0d1cccb
feat: Implement Phase 4 (Top-Level Safety)
fglock Nov 6, 2025
4a8a369
feat: Propagate isMainProgram flag to code generation
fglock Nov 6, 2025
1f5bc8b
feat: Add source location tracking to control flow markers
fglock Nov 6, 2025
5544bbc
feat: Pass source location to RuntimeControlFlowList
fglock Nov 6, 2025
065bc87
docs: Streamline design doc to action-oriented plan
fglock Nov 6, 2025
c4db263
feat: Dynamic slot allocation for control flow temp storage
fglock Nov 6, 2025
a183087
docs: Update plan with ASM frame computation findings
fglock Nov 6, 2025
e8c5a85
docs: Add critical decision document for control flow architecture
fglock Nov 6, 2025
e3bcbad
docs: Document existing SKIP workarounds to be removed
fglock Nov 6, 2025
b9ec4d0
fix: Remove top-level safety check - restored 99.8% pass rate
fglock Nov 6, 2025
0405780
docs: Update plan - Phases 5 & 6 complete (99.9% pass rate)
fglock Nov 6, 2025
c5c895d
test: Add comprehensive control flow unit tests
fglock Nov 6, 2025
fe226a3
Fix goto __SUB__ tail call by detecting it in handleGotoLabel
fglock Nov 6, 2025
326a856
Update MILESTONES.md: goto __SUB__ is now working
fglock Nov 6, 2025
bb0e5fe
Update design document: Phase 7 (Tail Call Trampoline) COMPLETE
fglock Nov 6, 2025
8c674dd
Add comprehensive comments explaining disabled features and next steps
fglock Nov 6, 2025
d5477dd
Update MILESTONES.md: Mark Phase 7 (Non-local control flow) as COMPLETE
fglock Nov 6, 2025
84084ac
Update FEATURE_MATRIX.md: Add tail call features, simplify control fl…
fglock Nov 6, 2025
055630b
docs
fglock Nov 6, 2025
cb28263
fix: Prevent RuntimeControlFlowList from being corrupted as data
fglock Nov 6, 2025
7cc0bf1
docs: Document RuntimeControlFlowList data corruption fix
fglock Nov 6, 2025
2d03783
docs: Comprehensive analysis of ASM frame computation blocker
fglock Nov 6, 2025
ee4cb82
feat: Implement runtime control flow registry for 'last SKIP' support
fglock Nov 6, 2025
b2e23ef
docs: Add comprehensive documentation for control flow registry solution
fglock Nov 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: Add critical decision document for control flow architecture
Pass rate regression: 99.8% → 30.4%
Cause: Tagged returns not being processed (call-site checks broken)

Three options presented:
1. Fix ASM frame computation (high effort, uncertain)
2. Hybrid approach - GOTO + exceptions (recommended)
3. Pure exceptions (safe fallback)

Recommendation: Option 2 (Hybrid) - fast GOTO for local, exceptions for non-local
  • Loading branch information
fglock committed Nov 6, 2025
commit e8c5a85222afcc1677a21ebd15f27401c0491943
117 changes: 117 additions & 0 deletions dev/design/CRITICAL_DECISION_NEEDED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# CRITICAL DECISION: Control Flow Architecture

## Current Status

**Pass Rate:** 30.4% (massive regression from 99.8% baseline)

**Root Cause:** Tagged return values are created but never processed, causing ALL non-local control flow to error:
- `uni/variables.t`: "Label not found for 'last SKIP'" (66833 tests blocked)
- `op/list.t`: StackOverflowError (3 tests blocked)
- `op/hash.t`: 5 failures

## The Problem

Tagged return control flow requires **call-site checks** to work:
1. Subroutine call returns marked `RuntimeControlFlowList`
2. **Call site must check** and dispatch to loop handler
3. Loop handler processes control flow (LAST/NEXT/REDO/GOTO)

**BUT:** Call-site checks cause `ArrayIndexOutOfBoundsException` in ASM frame computation.
- Tried: Fixed slot → Dynamic slot → Simplified pattern
- All fail with ASM frame merge errors
- Root cause: `DUP → branch → stack manipulation` breaks ASM's COMPUTE_FRAMES

## Three Options

### Option 1: Fix ASM Frame Computation (High Effort, Uncertain Success)

**Approach:** Manually provide frame hints at every branch point
- Call `mv.visitFrame(F_FULL, ...)` with exact local types and stack types
- Track all local variable types throughout method
- Update frames whenever bytecode changes

**Pros:**
- Pure tagged return solution (no exceptions)
- Clean architecture

**Cons:**
- **Very high effort** - must track types for every local variable
- **Fragile** - breaks if bytecode generation changes
- **Error-prone** - wrong frame = VerifyError
- **No guarantee it will work** - ASM may still reject complex patterns

**Estimated Time:** 20-40 hours of work, 50% chance of success

### Option 2: Hybrid Approach (Recommended)

**Approach:** Use exceptions ONLY for non-local control flow
- **Local** last/next/redo (same loop): Fast GOTO (current, works ✓)
- **Non-local** last/next/redo (crosses subroutine): Exception-based
- Detect at compile-time: if label not in current method, throw exception

**Pros:**
- **Proven to work** (old approach was at 99.8%)
- No ASM frame issues
- Fast path for common case (local control flow)
- Can implement immediately

**Cons:**
- Uses exceptions (performance cost for non-local flow)
- Mixed architecture (goto + exceptions)

**Implementation:**
1. Add back exception classes (`LastException`, `NextException`, etc.)
2. In `EmitControlFlow`: if label not found → throw exception instead of returning marked list
3. Keep fast GOTO for local control flow
4. Remove `RuntimeControlFlowList` creation for non-local flow

**Estimated Time:** 4-8 hours

### Option 3: Pure Exception-Based (Fallback)

**Approach:** Revert to pure exception-based control flow
- All last/next/redo/goto throw exceptions
- Try-catch blocks around loops
- Stack cleanup before throwing

**Pros:**
- **Proven architecture** (was working before)
- No ASM frame issues
- Simple to understand

**Cons:**
- Higher bytecode size (try-catch blocks)
- "Method too large" errors possible
- Exception overhead even for local flow

**Estimated Time:** 2-4 hours (mostly revert)

## Recommendation

**Option 2 (Hybrid)** is the best path forward:
- Balances performance (fast local, slower non-local)
- Proven to work (exceptions work, local GOTO works)
- Reasonable implementation time
- Avoids ASM frame computation issues entirely

## Test Case That Must Work

```perl
# From uni/variables.t (66833 tests depend on this!)
SKIP: {
sub { last SKIP }->(); # Non-local last
}

# From op/for.t
OUTER: for (1..3) {
sub { last OUTER }->(); # Non-local last
}
```

## Question for User

Which option should we pursue?
1. Option 1 (Fix ASM) - High risk, high effort
2. Option 2 (Hybrid) - **Recommended**
3. Option 3 (Pure exceptions) - Safe fallback