From b45035597d8475a23f469c47511938058bf816cc Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Wed, 17 Dec 2025 06:10:26 +0900 Subject: [PATCH] docs: Phase 100 P2 mutable accumulator contract MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .../current/main/phases/phase-100/README.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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)