## Overview Analyzed 34 loops across selfhost codebase to identify JoinIR coverage gaps. Current readiness: 47% (16/30 loops). Next frontier: Pattern P5b (Escape Handling). ## Current Status - Phase 91 planning document: Complete - Loop inventory across 6 key files - Priority ranking: P5b (escape) > P5 (guard) > P6 (nested) - Effort estimates and ROI analysis - Pattern P5b Design: Complete - Problem statement (variable-step carriers) - Pattern definition with Skeleton layout - Recognition algorithm (8-step detection) - Capability taxonomy (P5b-specific guards) - Lowering strategy (Phase 92 preview) - Test fixture: Created - Minimal escape sequence parser - JSON string with backslash escape - Loop Canonicalizer extended - Capability table updated with P5b entries - Fail-Fast criteria documented - Implementation checklist added ## Key Findings ### Loop Readiness Matrix | Category | Count | JoinIR Status | |----------|-------|--------------| | Pattern 1 (simple bounded) | 16 | ✅ Ready | | Pattern 2 (with break) | 1 | ⚠️ Partial | | **Pattern P5b (escape seq)** | ~3 | ❌ NEW | | Pattern P5 (guard-bounded) | ~2 | ❌ Deferred | | Pattern P6 (nested loops) | ~8 | ❌ Deferred | ### Top Candidates 1. **P5b**: json_loader.hako:30 (8 lines, high reuse) - Effort: 2-3 days (recognition) - Impact: Unlocks all escape parsers 2. **P5**: mini_vm_core.hako:541 (204 lines, monolithic) - Effort: 1-2 weeks - Impact: Major JSON optimization 3. **P6**: seam_inspector.hako:76 (7+ nesting) - Effort: 2-3 weeks - Impact: Demonstrates nested composition ## Phase 91 Strategy **Recognition-only phase** (no lowering in P1): - Step 1: Design & planning ✅ - Step 2: Canonicalizer implementation (detect_escape_pattern) - Step 3: Unit tests + parity verification - Step 4: Lowering deferred to Phase 92 ## Files Added - docs/development/current/main/phases/phase-91/README.md - Full analysis & planning - docs/development/current/main/design/pattern-p5b-escape-design.md - Technical design - tools/selfhost/test_pattern5b_escape_minimal.hako - Test fixture ## Files Modified - docs/development/current/main/design/loop-canonicalizer.md - Capability table extended with P5b entries - Pattern P5b full section added - Implementation checklist updated ## Acceptance Criteria (Phase 91 Step 1) - ✅ Loop inventory complete (34 loops across 6 files) - ✅ Pattern P5b design document ready - ✅ Test fixture created - ✅ Capability taxonomy extended - ⏳ Implementation deferred (Step 2+) ## References - JoinIR Architecture: joinir-architecture-overview.md - Phase 91 Plan: phases/phase-91/README.md - P5b Design: design/pattern-p5b-escape-design.md Next: Implement detect_escape_pattern() recognition in Phase 91 Step 2 🤖 Generated with Claude Code Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
60 lines
1.7 KiB
Plaintext
60 lines
1.7 KiB
Plaintext
// Minimal Pattern P5b (Escape Handling) Test Fixture
|
|
// Purpose: Verify JoinIR Canonicalizer recognition of escape sequence patterns
|
|
//
|
|
// Pattern: loop(i < n) with conditional increment on escape character
|
|
// Carriers: i (position), out (accumulator)
|
|
// Exit: break on quote character
|
|
//
|
|
// This pattern is common in string parsing:
|
|
// - JSON string readers
|
|
// - CSV parsers
|
|
// - Template engines
|
|
// - Escape sequence handlers
|
|
|
|
static box Main {
|
|
console: ConsoleBox
|
|
|
|
main() {
|
|
me.console = new ConsoleBox()
|
|
|
|
// Test data: string with escape sequence
|
|
// Original: "hello\" world"
|
|
// After parsing: hello" world
|
|
local s = "hello\\\" world"
|
|
local n = s.length()
|
|
local i = 0
|
|
local out = ""
|
|
|
|
// Pattern P5b: Escape sequence handling loop
|
|
// - Header: loop(i < n)
|
|
// - Escape check: if ch == "\\" { i = i + 1 }
|
|
// - Process: out = out + ch
|
|
// - Update: i = i + 1
|
|
loop(i < n) {
|
|
local ch = s.substring(i, i + 1)
|
|
|
|
// Break on quote (string boundary)
|
|
if ch == "\"" {
|
|
break
|
|
}
|
|
|
|
// Handle escape sequence: skip the escape char itself
|
|
if ch == "\\" {
|
|
i = i + 1 // Skip escape character (i increments by +2 total with final i++)
|
|
if i < n {
|
|
ch = s.substring(i, i + 1)
|
|
}
|
|
}
|
|
|
|
// Accumulate processed character
|
|
out = out + ch
|
|
i = i + 1 // Standard increment
|
|
}
|
|
|
|
// Expected output: hello" world (escape removed)
|
|
me.console.log(out)
|
|
|
|
return "OK"
|
|
}
|
|
}
|