@e4779/pi-fabric 0.92.42-fork.7 → 0.96.4-fork.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LAWS.bend +502 -0
- package/PROOF.bend +452 -0
- package/README.md +5 -1
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/dist/agents/handoff.d.ts +2 -1
- package/dist/agents/handoff.d.ts.map +1 -1
- package/dist/agents/manager.d.ts +2 -0
- package/dist/agents/manager.d.ts.map +1 -1
- package/dist/agents.js +6 -5
- package/dist/agents.js.map +1 -1
- package/dist/chunks/{chunk-3TXOQ5MG.js → chunk-3CJETB4S.js} +828 -204
- package/dist/chunks/chunk-3CJETB4S.js.map +7 -0
- package/dist/chunks/{chunk-IUCVOZRX.js → chunk-3SIXBW6A.js} +2 -2
- package/dist/chunks/chunk-4E63LJDD.js +468 -0
- package/dist/chunks/chunk-4E63LJDD.js.map +7 -0
- package/dist/chunks/{chunk-AAHHYDTO.js → chunk-4NF3S3NM.js} +1 -1
- package/dist/chunks/{chunk-AAHHYDTO.js.map → chunk-4NF3S3NM.js.map} +2 -2
- package/dist/chunks/{chunk-2SWRVIYJ.js → chunk-754HA6KO.js} +2 -2
- package/dist/chunks/{chunk-K6DHXXF5.js → chunk-B2IVWASP.js} +2 -2
- package/dist/chunks/{chunk-ZDNGXLEC.js → chunk-B4HECUJI.js} +2 -2
- package/dist/chunks/{chunk-H6DDV6E2.js → chunk-CSJSHBAT.js} +5 -5
- package/dist/chunks/{chunk-MW5VI7IW.js → chunk-D4B4CCTA.js} +2 -2
- package/dist/chunks/{chunk-EDL4JDW7.js → chunk-EBWMC3OO.js} +2 -2
- package/dist/chunks/{chunk-4NUTVNS2.js → chunk-F72MAIQY.js} +31 -368
- package/dist/chunks/chunk-F72MAIQY.js.map +7 -0
- package/dist/chunks/{chunk-W3FRE4VI.js → chunk-FDIEQEXS.js} +2 -2
- package/dist/chunks/{chunk-7A6NVHB5.js → chunk-FJSHRHOR.js} +7 -4
- package/dist/chunks/chunk-FJSHRHOR.js.map +7 -0
- package/dist/chunks/{chunk-PSNXUZMY.js → chunk-G2F2RDZI.js} +5 -47
- package/dist/chunks/chunk-G2F2RDZI.js.map +7 -0
- package/dist/chunks/{chunk-3WIGAX56.js → chunk-JCV54SSP.js} +2 -2
- package/dist/chunks/chunk-KS44WKJJ.js +51 -0
- package/dist/chunks/chunk-KS44WKJJ.js.map +7 -0
- package/dist/chunks/{chunk-3H7SDWZI.js → chunk-LNLQ2LX3.js} +22 -1
- package/dist/chunks/chunk-LNLQ2LX3.js.map +7 -0
- package/dist/chunks/{chunk-G4LADAYY.js → chunk-OINADFEF.js} +8 -3
- package/dist/chunks/chunk-OINADFEF.js.map +7 -0
- package/dist/chunks/{chunk-UQ4LTUH4.js → chunk-OUAC6O5C.js} +36 -9
- package/dist/chunks/chunk-OUAC6O5C.js.map +7 -0
- package/dist/chunks/{chunk-MQG5QKGI.js → chunk-Q5BMTL6A.js} +217 -95
- package/dist/chunks/chunk-Q5BMTL6A.js.map +7 -0
- package/dist/chunks/{chunk-IK6PPFWG.js → chunk-QFKHAAZA.js} +11 -11
- package/dist/chunks/chunk-QFKHAAZA.js.map +7 -0
- package/dist/chunks/{chunk-RTXZHKMS.js → chunk-QNMQJNXE.js} +7 -3
- package/dist/chunks/chunk-QNMQJNXE.js.map +7 -0
- package/dist/chunks/{chunk-U5FYOMG5.js → chunk-UBPFGMDQ.js} +6 -2
- package/dist/chunks/chunk-UBPFGMDQ.js.map +7 -0
- package/dist/chunks/{chunk-FLKGJPCN.js → chunk-ULQFHZJE.js} +4 -1
- package/dist/chunks/chunk-ULQFHZJE.js.map +7 -0
- package/dist/chunks/{chunk-7VAZ4N43.js → chunk-V3PIO7QL.js} +2 -2
- package/dist/chunks/{chunk-MGDLRV2R.js → chunk-VQGO4P7C.js} +2 -2
- package/dist/chunks/{chunk-XT4346N7.js → chunk-WXSELMFV.js} +9 -3
- package/dist/chunks/chunk-WXSELMFV.js.map +7 -0
- package/dist/chunks/{chunk-D5WKZONW.js → chunk-X3IRR7CV.js} +2 -2
- package/dist/chunks/{chunk-IJL3QK3J.js → chunk-Y57UHPIK.js} +1 -1
- package/dist/chunks/{chunk-IJL3QK3J.js.map → chunk-Y57UHPIK.js.map} +1 -1
- package/dist/chunks/{chunk-RKRVOBVO.js → chunk-YC3QQDZ3.js} +2 -2
- package/dist/chunks/{chunk-Q4XJ4PYL.js → chunk-ZRI433JP.js} +299 -83
- package/dist/chunks/chunk-ZRI433JP.js.map +7 -0
- package/dist/chunks/{chunk-36B4AIRT.js → chunk-ZTXZ6JDO.js} +2 -2
- package/dist/commands/fabric.d.ts.map +1 -1
- package/dist/compaction/bounds.d.ts +4 -0
- package/dist/compaction/bounds.d.ts.map +1 -1
- package/dist/compaction/branch-summary.d.ts.map +1 -1
- package/dist/compaction/dialogue.d.ts +24 -0
- package/dist/compaction/dialogue.d.ts.map +1 -0
- package/dist/compaction/hook.d.ts +6 -2
- package/dist/compaction/hook.d.ts.map +1 -1
- package/dist/compaction/hook.js +6 -5
- package/dist/compaction/instructions.d.ts +1 -0
- package/dist/compaction/instructions.d.ts.map +1 -1
- package/dist/compaction/projections.d.ts +3 -3
- package/dist/compaction/projections.d.ts.map +1 -1
- package/dist/compaction/qa.d.ts.map +1 -1
- package/dist/compaction/render.d.ts +11 -0
- package/dist/compaction/render.d.ts.map +1 -1
- package/dist/components/configuration.js +2 -3
- package/dist/components/effect-policy.d.ts +2 -0
- package/dist/components/effect-policy.d.ts.map +1 -1
- package/dist/components/effect-scope.d.ts.map +1 -1
- package/dist/components/supervisor.d.ts +1 -1
- package/dist/components/supervisor.d.ts.map +1 -1
- package/dist/core/action-registry.d.ts +14 -2
- package/dist/core/action-registry.d.ts.map +1 -1
- package/dist/core/action-registry.js +7 -5
- package/dist/core/provider-bindings.d.ts +8 -2
- package/dist/core/provider-bindings.d.ts.map +1 -1
- package/dist/core/provider-operations.d.ts +28 -0
- package/dist/core/provider-operations.d.ts.map +1 -0
- package/dist/core/provider-operations.js +201 -0
- package/dist/core/provider-operations.js.map +7 -0
- package/dist/core/shell-inbox.d.ts +13 -0
- package/dist/core/shell-inbox.d.ts.map +1 -0
- package/dist/core/shell-jobs.d.ts +51 -7
- package/dist/core/shell-jobs.d.ts.map +1 -1
- package/dist/core/shell-limits.d.ts +3 -0
- package/dist/core/shell-limits.d.ts.map +1 -0
- package/dist/core/shell-monitor.d.ts +51 -0
- package/dist/core/shell-monitor.d.ts.map +1 -0
- package/dist/entropy/index.js +8 -7
- package/dist/entropy/normal-form.d.ts.map +1 -1
- package/dist/execution-service.d.ts +1 -1
- package/dist/execution-service.d.ts.map +1 -1
- package/dist/fabric-runtime-state.d.ts +1 -1
- package/dist/fabric-runtime-state.d.ts.map +1 -1
- package/dist/fabric-runtime-state.js +1124 -325
- package/dist/fabric-runtime-state.js.map +4 -4
- package/dist/index.js +155 -44
- package/dist/index.js.map +3 -3
- package/dist/jev/observation.js +5 -3
- package/dist/jev.d.ts +0 -1
- package/dist/jev.d.ts.map +1 -1
- package/dist/jev.js +9 -13
- package/dist/memory/digest.d.ts.map +1 -1
- package/dist/memory/digest.js +2 -1
- package/dist/memory/discovery.js +6 -5
- package/dist/memory/expand-service.d.ts.map +1 -1
- package/dist/memory/file-worker.js +9 -8
- package/dist/memory/file-worker.js.map +1 -1
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/normalize.d.ts.map +1 -1
- package/dist/memory/normalize.js +5 -4
- package/dist/memory/search.js +7 -6
- package/dist/memory/worker-provider.js +10 -9
- package/dist/memory.js +9 -8
- package/dist/memory.js.map +1 -1
- package/dist/mesh/store.d.ts.map +1 -1
- package/dist/prewalk/handoff.d.ts +1 -1
- package/dist/prewalk/handoff.d.ts.map +1 -1
- package/dist/protocol.d.ts +2 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +1 -1
- package/dist/providers/jev-provider.d.ts +1 -1
- package/dist/providers/jev-provider.d.ts.map +1 -1
- package/dist/providers/jev-provider.js +9 -7
- package/dist/providers/memory-provider.js +9 -8
- package/dist/providers/pi-tools-provider.d.ts.map +1 -1
- package/dist/providers/tasks-provider.d.ts +12 -0
- package/dist/providers/tasks-provider.d.ts.map +1 -0
- package/dist/residency/host.js +10 -9
- package/dist/residency/pi-entry.js +10 -9
- package/dist/residency/pi-entry.js.map +1 -1
- package/dist/runtime/core-override-guest-types.js +2 -2
- package/dist/runtime/guest-types.d.ts +1 -1
- package/dist/runtime/guest-types.d.ts.map +1 -1
- package/dist/runtime/guest-types.js +1 -1
- package/dist/runtime/monty-runtime.js +1 -2
- package/dist/runtime/monty-runtime.js.map +1 -1
- package/dist/runtime/typescript-kernel.js +2 -2
- package/dist/runtime-state-builtins.d.ts +1 -1
- package/dist/runtime-state-builtins.d.ts.map +1 -1
- package/dist/schema/controller.d.ts.map +1 -1
- package/dist/state/store.d.ts.map +1 -1
- package/dist/ui/controller.d.ts +1 -0
- package/dist/ui/controller.d.ts.map +1 -1
- package/dist/ui/conversation-targets.js +2 -2
- package/dist/ui/conversation.js +7 -7
- package/dist/ui/dashboard.js +9 -9
- package/dist/ui/highlight.d.ts.map +1 -1
- package/dist/ui/languages/bend.d.ts +4 -0
- package/dist/ui/languages/bend.d.ts.map +1 -0
- package/dist/ui/languages/bend.js +73 -0
- package/dist/ui/languages/bend.js.map +7 -0
- package/dist/ui/settings.js +1 -2
- package/dist/ui/settings.js.map +1 -1
- package/dist/ui/shell-hang-keys.d.ts.map +1 -1
- package/dist/ui/shell-tasks.d.ts +22 -0
- package/dist/ui/shell-tasks.d.ts.map +1 -0
- package/dist/ui/shell-tasks.js +161 -0
- package/dist/ui/shell-tasks.js.map +7 -0
- package/dist/ui/shiki-catalog.d.ts +2 -1
- package/dist/ui/shiki-catalog.d.ts.map +1 -1
- package/dist/ui/snapshot.d.ts.map +1 -1
- package/dist/ui/types.d.ts +1 -0
- package/dist/ui/types.d.ts.map +1 -1
- package/dist/ui/widget.d.ts.map +1 -1
- package/dist/verified/authority.d.ts +17 -0
- package/dist/verified/authority.d.ts.map +1 -0
- package/dist/verified/generated/authority-kernel.d.ts +10 -0
- package/dist/verified/generated/authority-kernel.js +116 -0
- package/dist/verified/generated/kernel.d.ts +31 -0
- package/dist/verified/generated/kernel.js +351 -0
- package/dist/verified/generated/lifecycle-kernel.d.ts +7 -0
- package/dist/verified/generated/lifecycle-kernel.js +155 -0
- package/dist/verified/generated/manifest.json +54 -0
- package/dist/verified/generated/provider-kernel.d.ts +9 -0
- package/dist/verified/generated/provider-kernel.js +80 -0
- package/dist/verified/generated/storage-kernel.d.ts +11 -0
- package/dist/verified/generated/storage-kernel.js +98 -0
- package/dist/verified/memory.d.ts +11 -0
- package/dist/verified/memory.d.ts.map +1 -0
- package/dist/verified/nat.d.ts +2 -0
- package/dist/verified/nat.d.ts.map +1 -0
- package/dist/verified/policy.d.ts +37 -0
- package/dist/verified/policy.d.ts.map +1 -0
- package/dist/verified/resources.d.ts +14 -0
- package/dist/verified/resources.d.ts.map +1 -0
- package/dist/verified/storage.d.ts +32 -0
- package/dist/verified/storage.d.ts.map +1 -0
- package/dist/worker/recovery-watchdog.d.ts +12 -0
- package/dist/worker/recovery-watchdog.d.ts.map +1 -0
- package/dist/worker/recovery-watchdog.js +41 -0
- package/dist/worker/recovery-watchdog.js.map +7 -0
- package/dist/worker.js +70 -20
- package/dist/worker.js.map +2 -2
- package/docs/agents.md +20 -14
- package/docs/architecture.md +1 -1
- package/docs/background-tasks.md +140 -0
- package/docs/compaction.md +91 -28
- package/docs/components.md +5 -1
- package/docs/configuration.md +6 -6
- package/docs/foreman.md +4 -4
- package/docs/harnesses.md +95 -0
- package/docs/interface.md +7 -0
- package/docs/jev.md +59 -52
- package/docs/kernels.md +2 -2
- package/docs/licenses/bend-apache-2.0.txt +202 -0
- package/docs/memory-recall.md +1 -1
- package/docs/programmatic-compaction.md +13 -2
- package/docs/provider-capabilities.md +197 -0
- package/docs/shell-middleware.md +3 -3
- package/docs/skills.md +1 -1
- package/docs/verified-kernels.md +278 -0
- package/package.json +14 -4
- package/proofs/abi.json +308 -0
- package/proofs/authority-abi.json +7 -0
- package/proofs/authority-kernel.bend +23 -0
- package/proofs/authority-proof.bend +74 -0
- package/proofs/authority-spec.bend +30 -0
- package/proofs/authority-state.bend +43 -0
- package/proofs/authority-types.d.ts +3 -0
- package/proofs/kernel.bend +139 -0
- package/proofs/lifecycle-abi.json +3 -0
- package/proofs/lifecycle-kernel.bend +11 -0
- package/proofs/lifecycle-proof.bend +249 -0
- package/proofs/lifecycle-spec.bend +261 -0
- package/proofs/lifecycle-types.d.ts +4 -0
- package/proofs/lifecycle.bend +119 -0
- package/proofs/provider-abi.json +4 -0
- package/proofs/provider-kernel.bend +14 -0
- package/proofs/provider-plans.bend +28 -0
- package/proofs/provider-spec.bend +14 -0
- package/proofs/provider-types.d.ts +5 -0
- package/proofs/resource-proof.bend +633 -0
- package/proofs/resource-spec.bend +133 -0
- package/proofs/resources.bend +160 -0
- package/proofs/state-kernel.bend +17 -0
- package/proofs/state-plans.bend +40 -0
- package/proofs/state-proof.bend +42 -0
- package/proofs/state-spec.bend +26 -0
- package/proofs/storage-abi.json +3 -0
- package/proofs/storage-kernel.bend +11 -0
- package/proofs/storage-plans.bend +100 -0
- package/proofs/storage-proof.bend +176 -0
- package/proofs/storage-spec.bend +70 -0
- package/proofs/storage-types.d.ts +8 -0
- package/proofs/types.d.ts +7 -0
- package/scripts/test-verified-kernels.mjs +107 -0
- package/scripts/verified-kernels.mjs +136 -0
- package/skillsets/python/fabric-jev/SKILL.md +13 -9
- package/skillsets/typescript/fabric-exec/SKILL.md +4 -2
- package/skillsets/typescript/fabric-jev/SKILL.md +13 -9
- package/dist/chunks/chunk-3H7SDWZI.js.map +0 -7
- package/dist/chunks/chunk-3TXOQ5MG.js.map +0 -7
- package/dist/chunks/chunk-4NUTVNS2.js.map +0 -7
- package/dist/chunks/chunk-77PDIBK2.js +0 -129
- package/dist/chunks/chunk-77PDIBK2.js.map +0 -7
- package/dist/chunks/chunk-7A6NVHB5.js.map +0 -7
- package/dist/chunks/chunk-FLKGJPCN.js.map +0 -7
- package/dist/chunks/chunk-G4LADAYY.js.map +0 -7
- package/dist/chunks/chunk-IK6PPFWG.js.map +0 -7
- package/dist/chunks/chunk-MQG5QKGI.js.map +0 -7
- package/dist/chunks/chunk-PSNXUZMY.js.map +0 -7
- package/dist/chunks/chunk-Q4XJ4PYL.js.map +0 -7
- package/dist/chunks/chunk-RTXZHKMS.js.map +0 -7
- package/dist/chunks/chunk-U5FYOMG5.js.map +0 -7
- package/dist/chunks/chunk-UQ4LTUH4.js.map +0 -7
- package/dist/chunks/chunk-XT4346N7.js.map +0 -7
- package/dist/jev/browser.d.ts +0 -37
- package/dist/jev/browser.d.ts.map +0 -1
- package/dist/jev/browser.js +0 -13
- package/dist/jev/browser.js.map +0 -7
- /package/dist/chunks/{chunk-IUCVOZRX.js.map → chunk-3SIXBW6A.js.map} +0 -0
- /package/dist/chunks/{chunk-2SWRVIYJ.js.map → chunk-754HA6KO.js.map} +0 -0
- /package/dist/chunks/{chunk-K6DHXXF5.js.map → chunk-B2IVWASP.js.map} +0 -0
- /package/dist/chunks/{chunk-ZDNGXLEC.js.map → chunk-B4HECUJI.js.map} +0 -0
- /package/dist/chunks/{chunk-H6DDV6E2.js.map → chunk-CSJSHBAT.js.map} +0 -0
- /package/dist/chunks/{chunk-MW5VI7IW.js.map → chunk-D4B4CCTA.js.map} +0 -0
- /package/dist/chunks/{chunk-EDL4JDW7.js.map → chunk-EBWMC3OO.js.map} +0 -0
- /package/dist/chunks/{chunk-W3FRE4VI.js.map → chunk-FDIEQEXS.js.map} +0 -0
- /package/dist/chunks/{chunk-3WIGAX56.js.map → chunk-JCV54SSP.js.map} +0 -0
- /package/dist/chunks/{chunk-7VAZ4N43.js.map → chunk-V3PIO7QL.js.map} +0 -0
- /package/dist/chunks/{chunk-MGDLRV2R.js.map → chunk-VQGO4P7C.js.map} +0 -0
- /package/dist/chunks/{chunk-D5WKZONW.js.map → chunk-X3IRR7CV.js.map} +0 -0
- /package/dist/chunks/{chunk-RKRVOBVO.js.map → chunk-YC3QQDZ3.js.map} +0 -0
- /package/dist/chunks/{chunk-36B4AIRT.js.map → chunk-ZTXZ6JDO.js.map} +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import Base
|
|
2
|
+
import ./resources.bend as R
|
|
3
|
+
|
|
4
|
+
# Independent, proof-relevant set semantics, not the executable Boolean checker.
|
|
5
|
+
def Member(+name: +List<Nat>, xs: +List<+List<Nat>>) -> Type:
|
|
6
|
+
match xs:
|
|
7
|
+
case Nil{}:
|
|
8
|
+
Empty
|
|
9
|
+
case Con{h, t}:
|
|
10
|
+
{name == h : +List<Nat>} | Member(name, t)
|
|
11
|
+
|
|
12
|
+
def Subset(xs: +List<+List<Nat>>, +ys: +List<+List<Nat>>) -> Type:
|
|
13
|
+
match xs:
|
|
14
|
+
case Nil{}:
|
|
15
|
+
Unit
|
|
16
|
+
case Con{h, t}:
|
|
17
|
+
Member(h, ys) & Subset(t, ys)
|
|
18
|
+
|
|
19
|
+
def AtMost(xs: +List<+List<Nat>>, limit: Nat) -> Type:
|
|
20
|
+
match xs limit:
|
|
21
|
+
case Nil{} _:
|
|
22
|
+
Unit
|
|
23
|
+
case Con{h, t} 0n:
|
|
24
|
+
Empty
|
|
25
|
+
case Con{h, t} 1n+p:
|
|
26
|
+
AtMost(t, p)
|
|
27
|
+
|
|
28
|
+
def Nonempty(xs: +List<+List<Nat>>) -> Type:
|
|
29
|
+
match xs:
|
|
30
|
+
case Nil{}:
|
|
31
|
+
Empty
|
|
32
|
+
case Con{h, t}:
|
|
33
|
+
Unit
|
|
34
|
+
|
|
35
|
+
def NameNonempty(name: +List<Nat>) -> Type:
|
|
36
|
+
match name:
|
|
37
|
+
case Nil{}:
|
|
38
|
+
Empty
|
|
39
|
+
case Con{h, t}:
|
|
40
|
+
Unit
|
|
41
|
+
|
|
42
|
+
def NameAtMost(name: +List<Nat>, limit: Nat) -> Type:
|
|
43
|
+
match name limit:
|
|
44
|
+
case Nil{} _:
|
|
45
|
+
Unit
|
|
46
|
+
case Con{h, t} 0n:
|
|
47
|
+
Empty
|
|
48
|
+
case Con{h, t} 1n+p:
|
|
49
|
+
NameAtMost(t, p)
|
|
50
|
+
|
|
51
|
+
def NameValid(+name: +List<Nat>) -> Type:
|
|
52
|
+
NameNonempty(name) & (NameAtMost(name, 256n) & {name != [42n] : +List<Nat>})
|
|
53
|
+
|
|
54
|
+
def NamesValid(xs: +List<+List<Nat>>) -> Type:
|
|
55
|
+
match xs:
|
|
56
|
+
case Nil{}:
|
|
57
|
+
Unit
|
|
58
|
+
case Con{h, t}:
|
|
59
|
+
NameValid(h) & NamesValid(t)
|
|
60
|
+
|
|
61
|
+
def Quality(+names: +List<+List<Nat>>) -> Type:
|
|
62
|
+
Nonempty(names) & (AtMost(names, 64n) & NamesValid(names))
|
|
63
|
+
|
|
64
|
+
def OutputValid(scope: R.Scope) -> Type:
|
|
65
|
+
match scope:
|
|
66
|
+
case R.Unknown{}:
|
|
67
|
+
Unit
|
|
68
|
+
case R.Exact{names}:
|
|
69
|
+
Quality(names)
|
|
70
|
+
|
|
71
|
+
def Refines(original: R.Scope, normalized: R.Scope) -> Type:
|
|
72
|
+
match original normalized:
|
|
73
|
+
case R.Unknown{} R.Exact{ys}:
|
|
74
|
+
Empty
|
|
75
|
+
case R.Exact{xs} R.Exact{ys}:
|
|
76
|
+
Subset(xs, ys) & Subset(ys, xs)
|
|
77
|
+
case _ R.Unknown{}:
|
|
78
|
+
Unit
|
|
79
|
+
|
|
80
|
+
def Shared(+xs: +List<+List<Nat>>, +ys: +List<+List<Nat>>) -> Type:
|
|
81
|
+
&name: +List<Nat> -> Member(name, xs) & Member(name, ys)
|
|
82
|
+
|
|
83
|
+
def Overlap(left: R.Scope, right: R.Scope) -> Type:
|
|
84
|
+
match left right:
|
|
85
|
+
case R.Unknown{} _:
|
|
86
|
+
Unit
|
|
87
|
+
case R.Exact{xs} R.Unknown{}:
|
|
88
|
+
Unit
|
|
89
|
+
case R.Exact{xs} R.Exact{ys}:
|
|
90
|
+
Shared(xs, ys)
|
|
91
|
+
|
|
92
|
+
def Conflicts(+left: R.Scope, +right: R.Scope, lo: Bool, ro: Bool) -> Type:
|
|
93
|
+
({lo == True{} : Bool} | {ro == True{} : Bool}) & Overlap(left, right)
|
|
94
|
+
|
|
95
|
+
def Against(ys: +List<R.Effect>, +left: R.Effect) -> Bool:
|
|
96
|
+
match ys:
|
|
97
|
+
case Nil{}:
|
|
98
|
+
False{}
|
|
99
|
+
case Con{h, t}:
|
|
100
|
+
R.pairConflict(left, h) || Against(t, left)
|
|
101
|
+
|
|
102
|
+
def Groups(xs: +List<R.Effect>, +ys: +List<R.Effect>) -> Bool:
|
|
103
|
+
match xs:
|
|
104
|
+
case Nil{}:
|
|
105
|
+
False{}
|
|
106
|
+
case Con{h, t}:
|
|
107
|
+
Against(ys, h) || Groups(t, ys)
|
|
108
|
+
|
|
109
|
+
def IdentityValid(+name: +List<Nat>) -> Type:
|
|
110
|
+
NameNonempty(name) & {name != [42n] : +List<Nat>}
|
|
111
|
+
|
|
112
|
+
def IdentitiesValid(xs: +List<+List<Nat>>) -> Type:
|
|
113
|
+
match xs:
|
|
114
|
+
case Nil{}:
|
|
115
|
+
Unit
|
|
116
|
+
case Con{h, t}:
|
|
117
|
+
IdentityValid(h) & IdentitiesValid(t)
|
|
118
|
+
|
|
119
|
+
def SourceValid(scope: R.Scope) -> Type:
|
|
120
|
+
match scope:
|
|
121
|
+
case R.Unknown{}:
|
|
122
|
+
Unit
|
|
123
|
+
case R.Exact{names}:
|
|
124
|
+
Nonempty(names) & IdentitiesValid(names)
|
|
125
|
+
|
|
126
|
+
def EffectConflicts(left: R.Effect, right: R.Effect) -> Type:
|
|
127
|
+
match left right:
|
|
128
|
+
case R.Quiet{} _:
|
|
129
|
+
Empty
|
|
130
|
+
case R.Effect{lo, ls} R.Quiet{}:
|
|
131
|
+
Empty
|
|
132
|
+
case R.Effect{lo, ls} R.Effect{ro, rs}:
|
|
133
|
+
Conflicts(ls, rs, lo, ro)
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import Base
|
|
2
|
+
|
|
3
|
+
# Names are complete UTF-16 code-unit lists. Empty names also encode malformed
|
|
4
|
+
# non-string resources. Neither serialization nor this checker truncates input.
|
|
5
|
+
type Scope is Data:
|
|
6
|
+
Unknown{}
|
|
7
|
+
Exact{names: +List<+List<Nat>>}
|
|
8
|
+
|
|
9
|
+
type Effect is Data:
|
|
10
|
+
Quiet{}
|
|
11
|
+
Effect{ordered: Bool, scope: Scope}
|
|
12
|
+
|
|
13
|
+
def nameEqual(xs: +List<Nat>, ys: +List<Nat>, equal: Bool) -> Bool:
|
|
14
|
+
match xs ys:
|
|
15
|
+
case Nil{} Nil{}:
|
|
16
|
+
equal
|
|
17
|
+
case Nil{} Con{h, t}:
|
|
18
|
+
False{}
|
|
19
|
+
case Con{h, t} Nil{}:
|
|
20
|
+
False{}
|
|
21
|
+
case Con{a, at} Con{b, bt}:
|
|
22
|
+
nameEqual(at, bt, equal && Nat.is_eq(a, b))
|
|
23
|
+
|
|
24
|
+
def nameNonempty(name: +List<Nat>) -> Bool:
|
|
25
|
+
match name:
|
|
26
|
+
case Nil{}:
|
|
27
|
+
False{}
|
|
28
|
+
case Con{h, t}:
|
|
29
|
+
True{}
|
|
30
|
+
|
|
31
|
+
def nameBounded(name: +List<Nat>, remaining: Nat) -> Bool:
|
|
32
|
+
match name remaining:
|
|
33
|
+
case Nil{} _:
|
|
34
|
+
True{}
|
|
35
|
+
case Con{h, t} 0n:
|
|
36
|
+
False{}
|
|
37
|
+
case Con{h, t} 1n+p:
|
|
38
|
+
nameBounded(t, p)
|
|
39
|
+
|
|
40
|
+
def identityValid(+name: +List<Nat>) -> Bool:
|
|
41
|
+
nameNonempty(name) && Bool.not(nameEqual(name, [42n], True{}))
|
|
42
|
+
|
|
43
|
+
def nameValid(+name: +List<Nat>) -> Bool:
|
|
44
|
+
nameNonempty(name) && (nameBounded(name, 256n) && Bool.not(nameEqual(name, [42n], True{})))
|
|
45
|
+
|
|
46
|
+
def member(xs: +List<+List<Nat>>, +name: +List<Nat>, found: Bool) -> Bool:
|
|
47
|
+
match xs:
|
|
48
|
+
case Nil{}:
|
|
49
|
+
found
|
|
50
|
+
case Con{h, t}:
|
|
51
|
+
member(t, name, found || nameEqual(name, h, True{}))
|
|
52
|
+
|
|
53
|
+
def covered(xs: +List<+List<Nat>>, +ys: +List<+List<Nat>>, good: Bool) -> Bool:
|
|
54
|
+
match xs:
|
|
55
|
+
case Nil{}:
|
|
56
|
+
good
|
|
57
|
+
case Con{h, t}:
|
|
58
|
+
covered(t, ys, good && member(ys, h, False{}))
|
|
59
|
+
|
|
60
|
+
def bounded(xs: +List<+List<Nat>>, remaining: Nat) -> Bool:
|
|
61
|
+
match xs remaining:
|
|
62
|
+
case Nil{} _:
|
|
63
|
+
True{}
|
|
64
|
+
case Con{h, t} 0n:
|
|
65
|
+
False{}
|
|
66
|
+
case Con{h, t} 1n+p:
|
|
67
|
+
bounded(t, p)
|
|
68
|
+
|
|
69
|
+
def namesValid(xs: +List<+List<Nat>>, good: Bool) -> Bool:
|
|
70
|
+
match xs:
|
|
71
|
+
case Nil{}:
|
|
72
|
+
good
|
|
73
|
+
case Con{h, t}:
|
|
74
|
+
namesValid(t, good && nameValid(h))
|
|
75
|
+
|
|
76
|
+
def identitiesValid(xs: +List<+List<Nat>>, good: Bool) -> Bool:
|
|
77
|
+
match xs:
|
|
78
|
+
case Nil{}:
|
|
79
|
+
good
|
|
80
|
+
case Con{h, t}:
|
|
81
|
+
identitiesValid(t, good && identityValid(h))
|
|
82
|
+
|
|
83
|
+
def nonempty(xs: +List<+List<Nat>>) -> Bool:
|
|
84
|
+
match xs:
|
|
85
|
+
case Nil{}:
|
|
86
|
+
False{}
|
|
87
|
+
case Con{h, t}:
|
|
88
|
+
True{}
|
|
89
|
+
|
|
90
|
+
def select(accepted: Bool, candidate: +List<+List<Nat>>) -> Scope:
|
|
91
|
+
match accepted:
|
|
92
|
+
case False{}:
|
|
93
|
+
Unknown{}
|
|
94
|
+
case True{}:
|
|
95
|
+
Exact{candidate}
|
|
96
|
+
|
|
97
|
+
def source(+names: +List<+List<Nat>>) -> Scope:
|
|
98
|
+
select(nonempty(names) && identitiesValid(names, True{}), names)
|
|
99
|
+
|
|
100
|
+
def quality(+candidate: +List<+List<Nat>>) -> Bool:
|
|
101
|
+
nonempty(candidate) && (bounded(candidate, 64n) && namesValid(candidate, True{}))
|
|
102
|
+
|
|
103
|
+
def whenQuality(ok: Bool, +original: +List<+List<Nat>>, +candidate: +List<+List<Nat>>) -> Bool:
|
|
104
|
+
match ok:
|
|
105
|
+
case False{}:
|
|
106
|
+
False{}
|
|
107
|
+
case True{}:
|
|
108
|
+
covered(original, candidate, True{}) && covered(candidate, original, True{})
|
|
109
|
+
|
|
110
|
+
def accepted(original: +List<+List<Nat>>, +candidate: +List<+List<Nat>>) -> Bool:
|
|
111
|
+
whenQuality(quality(candidate), original, candidate)
|
|
112
|
+
|
|
113
|
+
def normalize(original: Scope, +candidate: +List<+List<Nat>>) -> Scope:
|
|
114
|
+
match original:
|
|
115
|
+
case Unknown{}:
|
|
116
|
+
Unknown{}
|
|
117
|
+
case Exact{names}:
|
|
118
|
+
select(accepted(names, candidate), candidate)
|
|
119
|
+
|
|
120
|
+
def overlapNames(xs: +List<+List<Nat>>, +ys: +List<+List<Nat>>, found: Bool) -> Bool:
|
|
121
|
+
match xs:
|
|
122
|
+
case Nil{}:
|
|
123
|
+
found
|
|
124
|
+
case Con{h, t}:
|
|
125
|
+
overlapNames(t, ys, found || member(ys, h, False{}))
|
|
126
|
+
|
|
127
|
+
def overlap(left: Scope, right: Scope) -> Bool:
|
|
128
|
+
match left right:
|
|
129
|
+
case Unknown{} _:
|
|
130
|
+
True{}
|
|
131
|
+
case Exact{xs} Unknown{}:
|
|
132
|
+
True{}
|
|
133
|
+
case Exact{xs} Exact{ys}:
|
|
134
|
+
overlapNames(xs, ys, False{})
|
|
135
|
+
|
|
136
|
+
def conflict(left: Scope, right: Scope, lo: Bool, ro: Bool) -> Bool:
|
|
137
|
+
(lo || ro) && overlap(left, right)
|
|
138
|
+
|
|
139
|
+
def pairConflict(left: Effect, right: Effect) -> Bool:
|
|
140
|
+
match left right:
|
|
141
|
+
case Quiet{} _:
|
|
142
|
+
False{}
|
|
143
|
+
case Effect{lo, ls} Quiet{}:
|
|
144
|
+
False{}
|
|
145
|
+
case Effect{lo, ls} Effect{ro, rs}:
|
|
146
|
+
conflict(ls, rs, lo, ro)
|
|
147
|
+
|
|
148
|
+
def against(ys: +List<Effect>, +left: Effect, found: Bool) -> Bool:
|
|
149
|
+
match ys:
|
|
150
|
+
case Nil{}:
|
|
151
|
+
found
|
|
152
|
+
case Con{h, t}:
|
|
153
|
+
against(t, left, found || pairConflict(left, h))
|
|
154
|
+
|
|
155
|
+
def groups(xs: +List<Effect>, +ys: +List<Effect>, found: Bool) -> Bool:
|
|
156
|
+
match xs:
|
|
157
|
+
case Nil{}:
|
|
158
|
+
found
|
|
159
|
+
case Con{h, t}:
|
|
160
|
+
groups(t, ys, found || against(ys, h, False{}))
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Base
|
|
2
|
+
import ./state-plans.bend as C
|
|
3
|
+
|
|
4
|
+
def stateRead(grant: C.Grant, key: +List<Nat>, stopped: Bool) -> C.Plan:
|
|
5
|
+
C.readPlan(grant, key, stopped)
|
|
6
|
+
|
|
7
|
+
def stateWrite(grant: C.Grant, key: +List<Nat>, expected: +List<Nat>, observed: +List<Nat>, value: +List<Nat>, stopped: Bool) -> C.Plan:
|
|
8
|
+
C.writePlan(grant, key, expected, observed, value, stopped)
|
|
9
|
+
|
|
10
|
+
def stateRevoke(grant: C.Grant) -> C.Grant:
|
|
11
|
+
C.revoke(grant)
|
|
12
|
+
|
|
13
|
+
type StateKernel is Type:
|
|
14
|
+
StateKernel{read: C.Grant -> +List<Nat> -> Bool -> C.Plan, write: C.Grant -> +List<Nat> -> +List<Nat> -> +List<Nat> -> +List<Nat> -> Bool -> C.Plan, revoke: C.Grant -> C.Grant}
|
|
15
|
+
|
|
16
|
+
def main() -> IO(StateKernel):
|
|
17
|
+
IO.pure(StateKernel, StateKernel{stateRead, stateWrite, stateRevoke})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import Base
|
|
2
|
+
import ./resources.bend as R
|
|
3
|
+
|
|
4
|
+
type Grant is Data:
|
|
5
|
+
Grant{active: Bool, key: +List<Nat>}
|
|
6
|
+
|
|
7
|
+
type Plan is Data:
|
|
8
|
+
Denied{}
|
|
9
|
+
Read{key: +List<Nat>}
|
|
10
|
+
Write{key: +List<Nat>, expected: +List<Nat>, value: +List<Nat>}
|
|
11
|
+
|
|
12
|
+
def allowed(grant: Grant, key: +List<Nat>, stopped: Bool) -> Bool:
|
|
13
|
+
match grant:
|
|
14
|
+
case Grant{active, granted}:
|
|
15
|
+
active && (Bool.not(stopped) && R.nameEqual(granted, key, True{}))
|
|
16
|
+
|
|
17
|
+
def selectRead(good: Bool, key: +List<Nat>) -> Plan:
|
|
18
|
+
match good:
|
|
19
|
+
case False{}:
|
|
20
|
+
Denied{}
|
|
21
|
+
case True{}:
|
|
22
|
+
Read{key}
|
|
23
|
+
|
|
24
|
+
def selectWrite(good: Bool, key: +List<Nat>, expected: +List<Nat>, value: +List<Nat>) -> Plan:
|
|
25
|
+
match good:
|
|
26
|
+
case False{}:
|
|
27
|
+
Denied{}
|
|
28
|
+
case True{}:
|
|
29
|
+
Write{key, expected, value}
|
|
30
|
+
|
|
31
|
+
def readPlan(grant: Grant, +key: +List<Nat>, stopped: Bool) -> Plan:
|
|
32
|
+
selectRead(allowed(grant, key, stopped), key)
|
|
33
|
+
|
|
34
|
+
def writePlan(grant: Grant, +key: +List<Nat>, +expected: +List<Nat>, observed: +List<Nat>, value: +List<Nat>, stopped: Bool) -> Plan:
|
|
35
|
+
selectWrite(allowed(grant, key, stopped) && R.nameEqual(expected, observed, True{}), key, expected, value)
|
|
36
|
+
|
|
37
|
+
def revoke(grant: Grant) -> Grant:
|
|
38
|
+
match grant:
|
|
39
|
+
case Grant{active, key}:
|
|
40
|
+
Grant{False{}, key}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import Base
|
|
2
|
+
import ./state-plans.bend as C
|
|
3
|
+
import ./state-spec.bend as S
|
|
4
|
+
import ./resources.bend as R
|
|
5
|
+
import ./resource-proof.bend as P
|
|
6
|
+
|
|
7
|
+
def notTrue(+b: Bool, p: {Bool.not(b) == True{} : Bool}) -> {b == False{} : Bool}:
|
|
8
|
+
match b:
|
|
9
|
+
case False{}:
|
|
10
|
+
{==}
|
|
11
|
+
case True{}:
|
|
12
|
+
Empty.absurd({True{} == False{} : Bool}, P.falseTrue(p))
|
|
13
|
+
|
|
14
|
+
def authority(+grant: C.Grant, +key: +List<Nat>, +stopped: Bool, p: {C.allowed(grant, key, stopped) == True{} : Bool}) -> S.Authority(grant, key, stopped):
|
|
15
|
+
match grant:
|
|
16
|
+
case C.Grant{active, granted}:
|
|
17
|
+
P.andUse(S.Authority(grant, key, stopped), active, Bool.not(stopped) && R.nameEqual(granted, key, True{}), p, ap => rest =>
|
|
18
|
+
P.andUse(S.Authority(grant, key, stopped), Bool.not(stopped), R.nameEqual(granted, key, True{}), rest, np => kp =>
|
|
19
|
+
(ap, (notTrue(stopped, np), P.nameExact(granted, key, kp)))))
|
|
20
|
+
|
|
21
|
+
def readSelected(+grant: C.Grant, +key: +List<Nat>, +stopped: Bool, +good: Bool, p: {C.allowed(grant, key, stopped) == good : Bool}) -> S.ReadSafe(grant, key, stopped, C.selectRead(good, key)):
|
|
22
|
+
match good:
|
|
23
|
+
case False{}:
|
|
24
|
+
Unit{}
|
|
25
|
+
case True{}:
|
|
26
|
+
(authority(grant, key, stopped, p), {==})
|
|
27
|
+
|
|
28
|
+
def writeSelected(+grant: C.Grant, +key: +List<Nat>, +expected: +List<Nat>, +observed: +List<Nat>, +value: +List<Nat>, +stopped: Bool, +good: Bool, p: {C.allowed(grant, key, stopped) && R.nameEqual(expected, observed, True{}) == good : Bool}) -> S.WriteSafe(grant, key, expected, observed, value, stopped, C.selectWrite(good, key, expected, value)):
|
|
29
|
+
match good:
|
|
30
|
+
case False{}:
|
|
31
|
+
Unit{}
|
|
32
|
+
case True{}:
|
|
33
|
+
P.andUse(S.WriteSafe(grant, key, expected, observed, value, stopped, C.Write{key, expected, value}), C.allowed(grant, key, stopped), R.nameEqual(expected, observed, True{}), p, ap => ep =>
|
|
34
|
+
(authority(grant, key, stopped, ap), (P.nameExact(expected, observed, ep), ({==}, ({==}, {==})))))
|
|
35
|
+
|
|
36
|
+
def staleSelected(+grant: C.Grant, +key: +List<Nat>, +expected: +List<Nat>, +observed: +List<Nat>, +value: +List<Nat>, +stopped: Bool, +good: Bool, p: {C.allowed(grant, key, stopped) && R.nameEqual(expected, observed, True{}) == good : Bool}, different: {expected != observed : +List<Nat>}) -> {C.selectWrite(good, key, expected, value) == C.Denied{} : C.Plan}:
|
|
37
|
+
match good:
|
|
38
|
+
case False{}:
|
|
39
|
+
{==}
|
|
40
|
+
case True{}:
|
|
41
|
+
P.andUse({C.Write{key, expected, value} == C.Denied{} : C.Plan}, C.allowed(grant, key, stopped), R.nameEqual(expected, observed, True{}), p, ap => ep =>
|
|
42
|
+
Empty.absurd({C.Write{key, expected, value} == C.Denied{} : C.Plan}, different(P.nameExact(expected, observed, ep))))
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Base
|
|
2
|
+
import ./state-plans.bend as C
|
|
3
|
+
|
|
4
|
+
# Independent propositions: no calls to implementation predicates.
|
|
5
|
+
def Authority(grant: C.Grant, key: +List<Nat>, stopped: Bool) -> Type:
|
|
6
|
+
match grant:
|
|
7
|
+
case C.Grant{active, granted}:
|
|
8
|
+
{active == True{} : Bool} & ({stopped == False{} : Bool} & {granted == key : +List<Nat>})
|
|
9
|
+
|
|
10
|
+
def ReadSafe(grant: C.Grant, +key: +List<Nat>, stopped: Bool, plan: C.Plan) -> Type:
|
|
11
|
+
match plan:
|
|
12
|
+
case C.Denied{}:
|
|
13
|
+
Unit
|
|
14
|
+
case C.Read{actual}:
|
|
15
|
+
Authority(grant, key, stopped) & {actual == key : +List<Nat>}
|
|
16
|
+
case C.Write{k, e, v}:
|
|
17
|
+
Empty
|
|
18
|
+
|
|
19
|
+
def WriteSafe(grant: C.Grant, +key: +List<Nat>, +expected: +List<Nat>, observed: +List<Nat>, value: +List<Nat>, stopped: Bool, plan: C.Plan) -> Type:
|
|
20
|
+
match plan:
|
|
21
|
+
case C.Denied{}:
|
|
22
|
+
Unit
|
|
23
|
+
case C.Read{k}:
|
|
24
|
+
Empty
|
|
25
|
+
case C.Write{actual, revision, payload}:
|
|
26
|
+
Authority(grant, key, stopped) & ({expected == observed : +List<Nat>} & ({actual == key : +List<Nat>} & ({revision == expected : +List<Nat>} & {payload == value : +List<Nat>})))
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Base
|
|
2
|
+
import ./storage-plans.bend as C
|
|
3
|
+
|
|
4
|
+
def storageTransition(request: C.Request, slot: C.Slot) -> C.Plan:
|
|
5
|
+
C.reduce(request, slot)
|
|
6
|
+
|
|
7
|
+
type StorageKernel is Type:
|
|
8
|
+
StorageKernel{transition: C.Request -> C.Slot -> C.Plan}
|
|
9
|
+
|
|
10
|
+
def main() -> IO(StorageKernel):
|
|
11
|
+
IO.pure(StorageKernel, StorageKernel{storageTransition})
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import Base
|
|
2
|
+
|
|
3
|
+
# Canonical radix-2^32 limbs keep arithmetic below Bend's 48-bit Nat runtime cap.
|
|
4
|
+
# The host encodes only safe JS revisions; room also rejects noncanonical limbs.
|
|
5
|
+
type Revision is Data:
|
|
6
|
+
Revision{high: Nat, low: Nat}
|
|
7
|
+
|
|
8
|
+
type Expectation is Data:
|
|
9
|
+
Any{}
|
|
10
|
+
At{version: Revision}
|
|
11
|
+
|
|
12
|
+
type Change is Data:
|
|
13
|
+
Put{value: +List<Nat>, identity: +List<Nat>}
|
|
14
|
+
Delete{}
|
|
15
|
+
|
|
16
|
+
type Request is Data:
|
|
17
|
+
Request{key: +List<Nat>, expected: Expectation, change: Change}
|
|
18
|
+
|
|
19
|
+
type Slot is Data:
|
|
20
|
+
Slot{present: Bool, version: Revision, highWater: Revision}
|
|
21
|
+
|
|
22
|
+
type Plan is Data:
|
|
23
|
+
Conflict{}
|
|
24
|
+
Exhausted{}
|
|
25
|
+
Unchanged{}
|
|
26
|
+
PutNext{key: +List<Nat>, value: +List<Nat>, identity: +List<Nat>, version: Revision, highWater: Revision}
|
|
27
|
+
DeleteNext{key: +List<Nat>, version: Revision, highWater: Revision}
|
|
28
|
+
|
|
29
|
+
def equal(left: Revision, right: Revision) -> Bool:
|
|
30
|
+
match left right:
|
|
31
|
+
case Revision{ah, al} Revision{bh, bl}:
|
|
32
|
+
Nat.is_eq(ah, bh) && Nat.is_eq(al, bl)
|
|
33
|
+
|
|
34
|
+
def matches(expected: Expectation, actual: Revision) -> Bool:
|
|
35
|
+
match expected:
|
|
36
|
+
case Any{}:
|
|
37
|
+
True{}
|
|
38
|
+
case At{version}:
|
|
39
|
+
equal(version, actual)
|
|
40
|
+
|
|
41
|
+
def room(+version: Revision) -> Bool:
|
|
42
|
+
match version:
|
|
43
|
+
case Revision{high, low}:
|
|
44
|
+
(Nat.is_le(high, 2097151n) && Nat.is_le(low, 4294967295n)) && (Nat.is_lt(high, 2097151n) || Nat.is_lt(low, 4294967295n))
|
|
45
|
+
|
|
46
|
+
def carry(full: Bool, high: Nat, low: Nat) -> Revision:
|
|
47
|
+
match full:
|
|
48
|
+
case False{}:
|
|
49
|
+
Revision{high, 1n+low}
|
|
50
|
+
case True{}:
|
|
51
|
+
Revision{1n+high, 0n}
|
|
52
|
+
|
|
53
|
+
def next(+version: Revision) -> Revision:
|
|
54
|
+
match version:
|
|
55
|
+
case Revision{high, low}:
|
|
56
|
+
carry(Nat.is_eq(low, 4294967295n), high, low)
|
|
57
|
+
|
|
58
|
+
# Live revisions remain +1 for existing certificate consumers. An absent key
|
|
59
|
+
# allocates above the persistent store-wide clock, even after tombstone eviction.
|
|
60
|
+
def base(present: Bool, version: Revision, highWater: Revision) -> Revision:
|
|
61
|
+
match present:
|
|
62
|
+
case False{}:
|
|
63
|
+
highWater
|
|
64
|
+
case True{}:
|
|
65
|
+
version
|
|
66
|
+
|
|
67
|
+
def canGrow(version: Revision, highWater: Revision) -> Bool:
|
|
68
|
+
room(version) && room(highWater)
|
|
69
|
+
|
|
70
|
+
def grow(available: Bool, key: +List<Nat>, change: Change, version: Revision, highWater: Revision) -> Plan:
|
|
71
|
+
match available:
|
|
72
|
+
case False{}:
|
|
73
|
+
Exhausted{}
|
|
74
|
+
case True{}:
|
|
75
|
+
match change:
|
|
76
|
+
case Put{value, identity}:
|
|
77
|
+
PutNext{key, value, identity, next(version), next(highWater)}
|
|
78
|
+
case Delete{}:
|
|
79
|
+
DeleteNext{key, next(version), next(highWater)}
|
|
80
|
+
|
|
81
|
+
def apply(key: +List<Nat>, change: Change, +present: Bool, +version: Revision, +highWater: Revision) -> Plan:
|
|
82
|
+
match change present:
|
|
83
|
+
case Delete{} False{}:
|
|
84
|
+
Unchanged{}
|
|
85
|
+
case Delete{} True{}:
|
|
86
|
+
grow(canGrow(version, highWater), key, Delete{}, version, highWater)
|
|
87
|
+
case Put{value, identity} _:
|
|
88
|
+
grow(canGrow(base(present, version, highWater), highWater), key, Put{value, identity}, base(present, version, highWater), highWater)
|
|
89
|
+
|
|
90
|
+
def admit(ok: Bool, key: +List<Nat>, change: Change, present: Bool, version: Revision, highWater: Revision) -> Plan:
|
|
91
|
+
match ok:
|
|
92
|
+
case False{}:
|
|
93
|
+
Conflict{}
|
|
94
|
+
case True{}:
|
|
95
|
+
apply(key, change, present, version, highWater)
|
|
96
|
+
|
|
97
|
+
def reduce(request: Request, +slot: Slot) -> Plan:
|
|
98
|
+
match request slot:
|
|
99
|
+
case Request{key, expected, change} Slot{present, version, highWater}:
|
|
100
|
+
admit(matches(expected, version), key, change, present, version, highWater)
|