diff --git a/docs/development/current/main/phases/phase-100/README.md b/docs/development/current/main/phases/phase-100/README.md index c7139336..5c3ba112 100644 --- a/docs/development/current/main/phases/phase-100/README.md +++ b/docs/development/current/main/phases/phase-100/README.md @@ -81,3 +81,31 @@ loop(i < 1) { - **Fixture**: `apps/tests/phase100_pinned_local_receiver_min.hako` - **Smoke Test**: `tools/smokes/v2/profiles/integration/apps/phase100_pinned_local_receiver_vm.sh` - **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)