docs(phase93): Phase 93 P0完了記録 & ドキュメント整理
## 追加 - docs/development/current/main/phases/phase-93/README.md - Phase 93 P0 (ConditionOnly Derived Slot) 完了記録 - 実装内容・テスト結果の詳細 ## 更新 - CURRENT_TASK.md: Phase 93 P0完了に伴う更新 - 10-Now.md: 現在の進捗状況更新 - 30-Backlog.md: Phase 92/93関連タスク整理 - phase-91/92関連ドキュメント: historical化・要約化 ## 削減 - 735行削減(historical化により詳細をREADMEに集約) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -9,13 +9,14 @@
|
||||
|
||||
## Executive Summary
|
||||
|
||||
**Current JoinIR Readiness**: 47% (16/30 loops in selfhost code)
|
||||
**Inventory snapshot**: 47% (16/30 loops in selfhost code)
|
||||
この数値は Phase 91 開始時点の棚卸しメモで、Phase 91 自体では「P5b の認識(canonicalizer)まで」を完了した。
|
||||
|
||||
| Category | Count | Status | Effort |
|
||||
|----------|-------|--------|--------|
|
||||
| Pattern 1 (simple bounded) | 16 | ✅ Ready | None |
|
||||
| Pattern 2 (with break) | 1 | ⚠️ Partial | Low |
|
||||
| Pattern P5b (escape handling) | ~3 | ❌ Blocked | Medium |
|
||||
| Pattern P5b (escape handling) | ~3 | ✅ Recognized (canonicalizer) | Medium |
|
||||
| Pattern P5 (guard-bounded) | ~2 | ❌ Blocked | High |
|
||||
| Pattern P6 (nested loops) | ~8 | ❌ Blocked | Very High |
|
||||
|
||||
@ -32,7 +33,7 @@
|
||||
|
||||
#### File: `apps/selfhost-vm/json_loader.hako` (3 loops)
|
||||
- Lines 16-22: ✅ Pattern 1 (simple bounded)
|
||||
- **Lines 30-37**: ❌ Pattern P5b **CANDIDATE** (escape sequence handling)
|
||||
- **Lines 30-37**: ✅ Pattern P5b (escape skip; canonicalizer recognizes)
|
||||
- Lines 43-48: ✅ Pattern 1 (simple bounded)
|
||||
|
||||
#### File: `apps/selfhost-vm/boxes/mini_vm_core.hako` (9 loops)
|
||||
@ -222,197 +223,12 @@ This would make each sub-loop Pattern 1-compatible immediately.
|
||||
|
||||
## Design: Pattern P5b (Escape Sequence Handling)
|
||||
|
||||
### Motivation
|
||||
Pattern P5b の詳細設計は重複を避けるため、設計 SSOT に集約する。
|
||||
|
||||
String parsing commonly requires escape sequence handling:
|
||||
- Double quotes: `"text with \" escaped quote"`
|
||||
- Backslashes: `"path\\with\\backslashes"`
|
||||
- Newlines: `"text with \n newline"`
|
||||
- **設計 SSOT**: `docs/development/current/main/design/pattern-p5b-escape-design.md`
|
||||
- **Canonicalizer SSOT(語彙/境界)**: `docs/development/current/main/design/loop-canonicalizer.md`
|
||||
|
||||
Current loops handle this with conditional increment:
|
||||
```rust
|
||||
if ch == "\\" {
|
||||
i = i + 1 // Skip escape character itself
|
||||
ch = next_char
|
||||
}
|
||||
i = i + 1 // Always advance
|
||||
```
|
||||
|
||||
This variable-step pattern is **not JoinIR-compatible** because:
|
||||
- Loop increment is conditional (sometimes +1, sometimes +2)
|
||||
- Canonicalizer expects constant-delta carriers
|
||||
- Lowering expects uniform update rules
|
||||
|
||||
### Solution: Pattern P5b Definition
|
||||
|
||||
#### Header Requirement
|
||||
```
|
||||
loop(i < n) // Bounded loop on string length
|
||||
```
|
||||
|
||||
#### Escape Check Requirement
|
||||
```
|
||||
if ch == "\\" {
|
||||
i = i + delta_skip // Skip character (typically +1, +2, or variable)
|
||||
// Optional: consume escape character
|
||||
ch = s.substring(i, i+1)
|
||||
}
|
||||
```
|
||||
|
||||
#### After-Escape Requirement
|
||||
```
|
||||
// Standard character processing
|
||||
out = out + ch
|
||||
i = i + delta_normal // Standard increment (typically +1)
|
||||
```
|
||||
|
||||
#### Skeleton Structure
|
||||
```
|
||||
LoopSkeleton {
|
||||
steps: [
|
||||
HeaderCond(i < n),
|
||||
Body(escape_check_stmts),
|
||||
Body(process_char_stmts),
|
||||
Update(i = i + normal_delta, maybe(i = i + skip_delta))
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### Carrier Configuration
|
||||
- **Primary Carrier**: Loop variable (`i`)
|
||||
- `delta_normal`: +1 (standard case)
|
||||
- `delta_escape`: +1 or +2 (skip escape)
|
||||
- **Secondary Carrier**: Accumulator (`out`)
|
||||
- Pattern: `out = out + value`
|
||||
|
||||
#### ExitContract
|
||||
```
|
||||
ExitContract {
|
||||
has_break: true, // Break on quote detection
|
||||
has_continue: false,
|
||||
has_return: false,
|
||||
carriers: vec![
|
||||
CarrierInfo { name: "i", deltas: [+1, +2] },
|
||||
CarrierInfo { name: "out", pattern: Append }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### Routing Decision
|
||||
```
|
||||
RoutingDecision {
|
||||
chosen: Pattern5bEscape,
|
||||
structure_notes: ["escape_handling", "variable_step"],
|
||||
missing_caps: [] // All required capabilities present
|
||||
}
|
||||
```
|
||||
|
||||
### Recognition Algorithm
|
||||
|
||||
#### AST Inspection Steps
|
||||
|
||||
1. **Find escape check**:
|
||||
- Pattern: `if ch == "\\" { ... }`
|
||||
- Extract: Escape character constant
|
||||
- Extract: Increment inside if block
|
||||
|
||||
2. **Extract skip delta**:
|
||||
- Pattern: `i = i + <const>`
|
||||
- Calculate: `skip_delta = <const>`
|
||||
|
||||
3. **Find normal increment**:
|
||||
- Pattern: `i = i + <const>` (after escape if block)
|
||||
- Calculate: `normal_delta = <const>`
|
||||
|
||||
4. **Validate break condition**:
|
||||
- Pattern: `if <char> == "<quote>" { break }`
|
||||
- Required for string boundary detection
|
||||
|
||||
5. **Build LoopSkeleton**:
|
||||
- Carriers: `[{name: "i", deltas: [normal, skip]}, ...]`
|
||||
- ExitContract: `has_break=true`
|
||||
- RoutingDecision: `chosen=Pattern5bEscape`
|
||||
|
||||
### Implementation Plan
|
||||
|
||||
#### Canonicalizer Extension (`src/mir/loop_canonicalizer/canonicalizer.rs`)
|
||||
|
||||
Add `detect_escape_pattern()` recognition:
|
||||
```rust
|
||||
fn detect_escape_pattern(
|
||||
loop_expr: &Expr,
|
||||
carriers: &[String]
|
||||
) -> Option<EscapePatternInfo> {
|
||||
// Step 1-5 as above
|
||||
// Return: { escape_char, skip_delta, normal_delta, carrier_name }
|
||||
}
|
||||
```
|
||||
|
||||
Priority: Call before `detect_skip_whitespace_pattern()` (more specific pattern first)
|
||||
|
||||
#### Pattern Recognizer Wrapper (`src/mir/loop_canonicalizer/pattern_recognizer.rs`)
|
||||
|
||||
Expose `detect_escape_pattern()`:
|
||||
```rust
|
||||
pub fn try_extract_escape_pattern(
|
||||
loop_expr: &Expr
|
||||
) -> Option<(String, i64, i64)> { // (carrier, normal_delta, skip_delta)
|
||||
// Delegate to canonicalizer detection
|
||||
}
|
||||
```
|
||||
|
||||
#### Test Fixture (`tools/selfhost/test_pattern5b_escape_minimal.hako`)
|
||||
|
||||
Minimal reproducible example:
|
||||
```nyash
|
||||
// Minimal escape sequence parser
|
||||
local s = "\\"hello\\" world"
|
||||
local n = s.length()
|
||||
local i = 0
|
||||
local out = ""
|
||||
|
||||
loop(i < n) {
|
||||
local ch = s.substring(i, i+1)
|
||||
|
||||
if ch == "\"" {
|
||||
break
|
||||
}
|
||||
|
||||
if ch == "\\" {
|
||||
i = i + 1 // Skip escape character
|
||||
if i < n {
|
||||
ch = s.substring(i, i+1)
|
||||
}
|
||||
}
|
||||
|
||||
out = out + ch
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
print(out) // Should print: hello" world
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Files to Modify (Phase 91)
|
||||
|
||||
### New Files
|
||||
1. `docs/development/current/main/phases/phase-91/README.md` ← You are here
|
||||
2. `docs/development/current/main/design/pattern-p5b-escape-design.md` (new - detailed design)
|
||||
3. `tools/selfhost/test_pattern5b_escape_minimal.hako` (new - test fixture)
|
||||
|
||||
### Modified Files
|
||||
1. `docs/development/current/main/design/loop-canonicalizer.md`
|
||||
- Add Pattern P5b to capability matrix
|
||||
- Add recognition algorithm
|
||||
- Add routing decision table
|
||||
|
||||
2. (Phase 91 Step 2+) `src/mir/loop_canonicalizer/canonicalizer.rs`
|
||||
- Add `detect_escape_pattern()` function
|
||||
- Extend `canonicalize_loop_expr()` to check for escape patterns
|
||||
|
||||
3. (Phase 91 Step 2+) `src/mir/loop_canonicalizer/pattern_recognizer.rs`
|
||||
- Add `try_extract_escape_pattern()` wrapper
|
||||
この Phase 91 README は「在庫分析 + 実装完了の記録」に徹し、アルゴリズム本文や疑似コードは上記 SSOT を参照する。
|
||||
|
||||
---
|
||||
|
||||
@ -438,9 +254,8 @@ print(out) // Should print: hello" world
|
||||
## Next Steps (Future Sessions)
|
||||
|
||||
### Phase 92: Lowering
|
||||
- Implement Pattern5bEscape lowerer in JoinIR
|
||||
- Handle ConditionalStep carrier updates with PHI composition
|
||||
- E2E test with `test_pattern5b_escape_minimal.hako`
|
||||
- 進捗は Phase 92 で実施済み(ConditionalStep lowering + body-local 条件式サポート + 最小E2E smoke)。
|
||||
- 入口: `docs/development/current/main/phases/phase-92/README.md`
|
||||
|
||||
### Phase 93: Pattern P5 (Guard-Bounded)
|
||||
- Implement Pattern5 for `mini_vm_core.hako:541`
|
||||
@ -466,7 +281,7 @@ print(out) // Should print: hello" world
|
||||
**Phase 91** establishes the next frontier of JoinIR coverage: **Pattern P5b (Escape Handling)**.
|
||||
|
||||
This pattern unlocks:
|
||||
- ✅ All string escape parsing loops
|
||||
- ✅ escape skip を含む “条件付き増分” 系ループの取り込み足場(recognizer + contract)
|
||||
- ✅ Foundation for Pattern P5 (guard-bounded)
|
||||
- ✅ Preparation for Pattern P6 (nested loops)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user