Add associative map constraints and range refinement

This commit is contained in:
2026-08-14 06:26:15 +09:00
parent 8198b615a8
commit cc6ab40807
52 changed files with 8951 additions and 6918 deletions
@@ -1,6 +1,6 @@
# Composition and Materialization
`&``//``default`、materialize は、runtime value の variant に基づいて処理する。
`&``//``as``default`、materialize は、runtime value の variant に基づいて処理する。
## `&`
@@ -89,7 +89,24 @@ patch(a: RuntimeValue, b: RuntimeValue) -> RuntimeValue
- 配列、scalar、function は右辺置換とする。
`//` は制約を保持するための演算子ではない。
制約を満たす具体化に`&` を使う。
対称な制約合成には `&` を使い、左辺が右辺より狭いことを確認しながら合成する場合`as` を使う。
## `as`
`as` は narrower と wider の向きを固定した範囲包含確認と合成である。
```text
apply_as(narrower: RuntimeValue, wider: RuntimeValue)
-> RuntimeValue | Diagnostic
```
abstract / abstract では、左辺 constraints が右辺 constraints を包含することを確認し、左辺を結果にする。
concrete / abstract では、concrete value が右辺 constraints を満たすことを確認する。
object / object では右辺を field domain とする。左辺にしかない field は診断し、両側にある field は再帰的に `apply_as` し、右辺にしかない field は thunk を force せずそのまま結果へ残す。
この扱いは default の有無に依存しない。default は包含判定の根拠でも `as` の補完値でもなく、後の materialize だけが選択する。
`ArrayItems(wider)` は concrete array の全要素を、`MapValues(wider)` は concrete object の全 field value を同じ関数で絞り込む。
## materialize