docs(specs): add Index Operator design; CURRENT_TASK: plan for Phase‑20.31 small-scope bring‑up

This commit is contained in:
nyash-codex
2025-10-31 19:35:47 +09:00
parent 8cc4654a7f
commit 86fd03afe8
2 changed files with 64 additions and 0 deletions

View File

@ -136,6 +136,29 @@ Plan — Next一本化の続きと段階導入
- 型注釈の最小拡張観測ベースで1〜2件 - 型注釈の最小拡張観測ベースで1〜2件
- phase15.7/README と Quick Reference に「内部正規化obj.m→Class.m」の注記を追記ユーザー向け説明を簡潔に - phase15.7/README と Quick Reference に「内部正規化obj.m→Class.m」の注記を追記ユーザー向け説明を簡潔に
Index Operator BringupPhase20.31 内の小粒対応)
目的
- `expr[index]` の最小サポートArray/Map の読み書き)。実行は NyRT dotted extern に正規化get/set
仕様Phase1
- 読み取り: `arr[i]`, `map[k]`
- 書き込み: `arr[i] = v`, `map[k] = v`
- 文字列 index/range は後続Phase2
- 未対応型は FailFast: "index operator is only supported for Array/Map"
実装計画
1) AST: IndexExpr と Assign(IndexExpr, …)Rust パーサー)
2) MIR Lowering: Array/Map の get/set に正規化
3) スモークquick: arr_read / arr_write / map_rw / negative_string
4) ドキュメント: docs/specs/language/index-operator.md
ロールアウト
- 必要なら dev フラグHAKO_INDEX_OPERATOR_DEV=1で段階導入dev=ON, prod=OFF
受け入れ基準
- 上記スモークが PASS。未対応型は安定診断で Fail。
Docs — Added Docs — Added
- Unified method resolution design note: docs/development/builder/unified-method-resolution.md - Unified method resolution design note: docs/development/builder/unified-method-resolution.md
- Pipeline, invariants, flags, rollout planP4 observe → dev optin → consider defaultを整理。 - Pipeline, invariants, flags, rollout planP4 observe → dev optin → consider defaultを整理。

View File

@ -0,0 +1,41 @@
Index Operator — Design (Phase20.31 scoped)
Scope (Phase1)
- Support bracket indexing for Array/Map:
- Read: expr[index]
- Write: expr[index] = value
- Semantics (lowering):
- Array
- Read → nyash.array.get_h(handle, idx)
- Write → nyash.array.set_h(handle, idx, val)
- Map
- Read → nyash.map.get_hh(handle, key_any)
- Write → nyash.map.set_hh(handle, key_any, val_any)
- Out of scope in Phase1: String indexing/ranges.
Parser/AST
- Add IndexExpr(target, index)
- Permit Assign(IndexExpr, value) on the LHS.
MIR Lowering (FailFast contract)
- If receiver is neither Array nor Map → error: "index operator is only supported for Array/Map".
- For Map keys/values:
- If arguments are SSA values (handles), pass as is; otherwise wrap primitive i64 as IntegerBox via available builder utilities.
Error Policy
- FailFast, no silent fallback.
- Stable diagnostics for unsupported types and malformed LHS.
Rollout / Flags
- Implement in Rust parser first; Ny parser later.
- If needed, guard with a dev flag for initial rollout (HAKO_INDEX_OPERATOR_DEV=1), default ON in dev profile, OFF in prod profiles.
Tests (canaries)
- arr_read: [1,2][0] == 1 → true
- arr_write: arr[1]=3; arr[1]==3 → true
- map_rw: m[10]=7; m[10]==7 → true
- negative: "hello"[0] (Phase1) → error
Notes
- This leverages existing NyRT dotted externs already implemented for Array/Map, minimizing surface area and risk.