docs: Phase 100 P2 mutable accumulator contract

- Add P2 section to phases/phase-100/README.md
- Document allowed form: s = s + x (x must be read-only)
- List Fail-Fast cases (reversed ops, complex RHS, multiple updates)
- Add example with numeric output

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-17 06:10:26 +09:00
parent 682fc11f7c
commit b45035597d

View File

@ -81,3 +81,31 @@ loop(i < 1) {
- **Fixture**: `apps/tests/phase100_pinned_local_receiver_min.hako` - **Fixture**: `apps/tests/phase100_pinned_local_receiver_min.hako`
- **Smoke Test**: `tools/smokes/v2/profiles/integration/apps/phase100_pinned_local_receiver_vm.sh` - **Smoke Test**: `tools/smokes/v2/profiles/integration/apps/phase100_pinned_local_receiver_vm.sh`
- **Regression**: Phase 96 and Phase 94 smoke tests pass - **Regression**: Phase 96 and Phase 94 smoke tests pass
## P2: Mutable Accumulators (s = s + x form only)
**Constraint**: Mutable variables are LIMITED to accumulator pattern.
**Allowed form**:
- `s = s + x` where x ∈ {Const, BodyLocal, Captured, Pinned, Carrier}
**Fail-Fast (未対応)**:
- Any other mutation: `s = f(...)` / `s = x + s` / `s += x` / multiple updates / conditional updates
- Reason: Shape explosion prevention, safe accumulator support (JSON/CSV building)
**Example** (now works):
```hako
local out = ""
loop(i < 2) {
local ch = "a"
out = out + ch # Accumulator form → LoopState carrier
i = i + 1
}
print(out.length()) # Output: 2
```
**Implementation**:
- **P2-1**: MutableAccumulatorAnalyzer (AST shape detection only)
- **P2-2**: Pattern2 wiring (ScopeManager delegates read-only check)
- **P2-3**: Lowering (carrier update emission)
- **P2-4**: Integration test (fixture + smoke, length-based validation)