Complete design for extending Normalized JoinIR to Pattern3 (if-sum) loops, reusing 90% of existing P2 infrastructure. Key insight: P3 already uses P2's Structured JoinIR foundation (Phase 220 ConditionEnv integration), so Normalized extension is straightforward. Design documents: - phase47-norm-p3-design.md: Complete P3 Normalized design - Infrastructure reuse analysis (ConditionEnv, CarrierInfo, ExitLine) - Representative loops identified (phase212_if_sum_min primary target) - StepScheduleBox extension (IfCond, ThenUpdates, ElseUpdates) - JpInst reuse (If instruction already exists) - Implementation strategy (dev-only → canonical) - File impact estimate (~365 lines, pure additive) - phase47-test-files-inventory.md: P3 test file catalog - 3 P3 test files analyzed - phase212_if_sum_min.hako: Single carrier (PRIMARY) - phase217_if_sum_multi_min.hako: Multi-carrier (sum + count) - phase218_json_if_sum_min.hako: Variable accumulation (sum + i) Architecture: - Unified Normalized for P1/P2/P3 (same pipeline) - Conditional updates only difference vs P2 - No P2 code changes needed (pure additive) Benefits: - 90% infrastructure reuse from P2 - Proven incremental rollout (dev → canonical) - Clear path to P4 (continue pattern) Implementation roadmap: - Phase 47-A: Minimal sum_count (dev-only) - Phase 47-B: array_filter (body-local + method calls) - Phase 47-C: Canonical promotion Updates: - joinir-architecture-overview.md: Added Phase 47 section - CURRENT_TASK.md: Updated Phase 47 entry (Design Complete) Status: Design phase complete, ready for implementation
4.9 KiB
Phase 47 Test Files Inventory
Date: 2025-12-12
P3 (If-Sum) Test Files Available
1. phase212_if_sum_min.hako ⭐ PRIMARY TARGET
Path: /home/tomoaki/git/hakorune-selfhost/apps/tests/phase212_if_sum_min.hako
Pattern: Simple if-sum with single carrier
local sum = 0
local i = 0
local len = 3
loop(i < len) {
if (i > 0) {
sum = sum + 1 // Conditional update
} else {
sum = sum + 0 // Else branch (no-op)
}
i = i + 1
}
Characteristics:
- ✅ Single carrier:
sum - ✅ Simple condition:
i > 0 - ✅ One loop param:
i - ✅ Explicit else branch
- ✅ Clean structure (no method calls, no body-local)
Expected output: sum = 2
Use case: Phase 47-A Minimal (first Normalized P3 implementation)
2. phase217_if_sum_multi_min.hako
Path: /home/tomoaki/git/hakorune-selfhost/apps/tests/phase217_if_sum_multi_min.hako
Pattern: Multi-carrier if-sum (2 accumulators)
local sum = 0
local count = 0
local i = 0
local len = 3
loop(i < len) {
if (i > 0) {
sum = sum + 1 // Conditional update 1
count = count + 1 // Conditional update 2
print(sum)
print(count)
} else {
print(0)
}
i = i + 1
}
Characteristics:
- ✅ Two carriers:
sum,count - ✅ Side effects:
print()calls - ✅ Multiple updates in then branch
- ⚠️ Slightly more complex than phase212
Expected output: sum = 2, count = 2
Use case: Phase 47-A Extended (multi-carrier test)
3. phase218_json_if_sum_min.hako
Path: /home/tomoaki/git/hakorune-selfhost/apps/tests/phase218_json_if_sum_min.hako
Pattern: JsonParser-style accumulation
local sum = 0
local i = 0
local len = 5
loop(i < len) {
if (i > 0) {
sum = sum + i // Variable accumulation (not constant)
print(sum)
} else {
print(0)
}
i = i + 1
}
Characteristics:
- ✅ Single carrier:
sum - ✅ Variable accumulation:
sum + i(notsum + 1) - ✅ Simulates JsonParser digit accumulation pattern
- ⚠️ More complex arithmetic
Expected output: sum = 10 (1+2+3+4)
Use case: Phase 47-A Extended (variable accumulation test)
Phase 47-A Implementation Priority
First Target: phase212_if_sum_min.hako
Why:
- ✅ Simplest structure - single carrier, simple condition
- ✅ Clean pattern - no side effects (no print), no method calls
- ✅ Direct P2 analogy - just adds if branching to P2 structure
- ✅ Best for proving concept - minimal complexity
Normalized components needed:
- EnvLayout:
{ i: int, sum: int }(same as P2) - StepSchedule:
[HeaderCond, IfCond, ThenUpdates, Updates, Tail] - JpInst: Reuse existing
Ifinstruction
Second Target: phase217_if_sum_multi_min.hako
Why:
- ✅ Multi-carrier test - proves P3 handles multiple accumulators
- ⚠️ Side effects (print) - tests that side effects work in then/else branches
- ✅ Still simple condition -
i > 0(same as phase212)
Additional Normalized components:
- EnvLayout:
{ i: int, sum: int, count: int }(multi-carrier) - Side effect handling in then/else branches
Third Target: phase218_json_if_sum_min.hako
Why:
- ✅ Variable accumulation -
sum + i(not constant) - ✅ JsonParser pattern - prepares for real JsonParser loops
- ⚠️ More complex arithmetic expression
Additional Normalized components:
- Expression lowering for
sum + i(already supported by ExprLowerer)
Phase 47-B Target (Future)
Candidate: JsonParser array_filter pattern (if exists in codebase)
local out = new ArrayBox()
local i = 0
loop(i < arr.length()) {
local v = arr.get(i)
if (predicate(v)) {
out.push(v)
}
i = i + 1
}
Complexity:
- ⚠️ Method calls:
arr.length(),arr.get(i),out.push(v) - ⚠️ Body-local:
v(used in if condition) - ⚠️ External predicate call
Status: Not yet verified if this exact pattern exists in codebase
Summary
Available P3 test files: 3
- ✅ phase212_if_sum_min.hako (PRIMARY)
- ✅ phase217_if_sum_multi_min.hako (SECONDARY)
- ✅ phase218_json_if_sum_min.hako (TERTIARY)
Phase 47-A roadmap:
- Start with phase212 (single carrier, simple)
- Extend to phase217 (multi-carrier)
- Extend to phase218 (variable accumulation)
- All dev-only (Normalized→MIR direct comparison tests)
Phase 47-B roadmap (future):
- Real JsonParser loops with method calls + body-local
- Requires body-local handling in EnvLayout (already exists for P2 DigitPos)
Phase 47-C roadmap (future):
- Canonical promotion of P3 minimal (like P2)
- Performance validation
References
- Phase 47 Design: phase47-norm-p3-design.md
- P2 Completion: PHASE_43_245B_NORMALIZED_COMPLETION.md
- Architecture: joinir-architecture-overview.md