gdp-wired 0.31.1 → 0.32.0
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/README.md +82 -6
- package/dist/core/c/reader.d.ts +86 -0
- package/dist/core/c/reader.js +860 -0
- package/dist/core/cli.d.ts +66 -0
- package/dist/core/cli.js +582 -0
- package/dist/core/dsl.d.ts +4 -2
- package/dist/core/dsl.js +22 -12
- package/dist/core/effect.d.ts +6 -4
- package/dist/core/effect.js +48 -10
- package/dist/core/ex/harness.exs +177 -0
- package/dist/core/ex/json.exs +46 -0
- package/dist/core/ex/reader.exs +462 -0
- package/dist/core/exists.d.ts +3 -0
- package/dist/core/exists.js +3 -1
- package/dist/core/extract-c.d.ts +35 -0
- package/dist/core/extract-c.js +424 -0
- package/dist/core/extract-check.js +27 -6
- package/dist/core/extract-ex.d.ts +16 -0
- package/dist/core/extract-ex.js +33 -0
- package/dist/core/extract-go-check.d.ts +28 -0
- package/dist/core/extract-go-check.js +639 -0
- package/dist/core/extract-go.d.ts +231 -0
- package/dist/core/extract-go.js +1166 -0
- package/dist/core/extract-jvm.d.ts +23 -0
- package/dist/core/extract-jvm.js +220 -0
- package/dist/core/extract-print.js +17 -7
- package/dist/core/extract-py.d.ts +15 -0
- package/dist/core/extract-py.js +31 -0
- package/dist/core/extract-rb.d.ts +17 -0
- package/dist/core/extract-rb.js +31 -0
- package/dist/core/extract-read.d.ts +20 -0
- package/dist/core/extract-read.js +46 -6
- package/dist/core/extract-rs.d.ts +12 -0
- package/dist/core/extract-rs.js +306 -0
- package/dist/core/extract-shapes.d.ts +2 -0
- package/dist/core/extract-shapes.js +6 -5
- package/dist/core/extract-step.d.ts +806 -0
- package/dist/core/extract-step.js +4141 -0
- package/dist/core/extract-swift.d.ts +27 -0
- package/dist/core/extract-swift.js +484 -0
- package/dist/core/extract-xstate.d.ts +10 -3
- package/dist/core/extract-xstate.js +50 -4
- package/dist/core/extract.d.ts +22 -3
- package/dist/core/extract.js +107 -18
- package/dist/core/go/go.mod +3 -0
- package/dist/core/go/reader.go +901 -0
- package/dist/core/infer.js +1770 -52
- package/dist/core/jvm/Harness.java +361 -0
- package/dist/core/jvm/JavaReader.java +825 -0
- package/dist/core/jvm/Jvm.java +332 -0
- package/dist/core/jvm/KtReader.java +960 -0
- package/dist/core/jvm/Rt.java +10 -0
- package/dist/core/laws.d.ts +66 -0
- package/dist/core/laws.js +522 -0
- package/dist/core/py/harness.py +328 -0
- package/dist/core/py/reader.py +447 -0
- package/dist/core/rb/harness.rb +233 -0
- package/dist/core/rb/reader.rb +375 -0
- package/dist/core/rs/Cargo.lock +108 -0
- package/dist/core/rs/Cargo.toml +14 -0
- package/dist/core/rs/src/main.rs +681 -0
- package/dist/core/swift/Harness.swift +124 -0
- package/dist/core/swift/Main.swift +34 -0
- package/dist/core/swift/Package.swift +13 -0
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +1341 -0
- package/dist/kernel/epr.d.ts +35 -0
- package/dist/kernel/epr.js +1676 -0
- package/dist/kernel/prove.d.ts +44 -0
- package/dist/kernel/prove.js +657 -50
- package/dist/lean-kernel/emit.d.ts +1 -0
- package/dist/lean-kernel/emit.js +21 -4
- package/package.json +53 -2
package/README.md
CHANGED
|
@@ -9,6 +9,10 @@ An automatic prover for stateful rules: budgets, caps, rate limits, workflows, a
|
|
|
9
9
|
the laws it must keep. gdp-wired proves them with no proof to write, shows a real run that breaks a law when it's false
|
|
10
10
|
(found by searching on the GPU), has every proof checked again by Lean, and ships the rule as JavaScript.
|
|
11
11
|
|
|
12
|
+
[](https://gdpwired.dev/#explainer)
|
|
13
|
+
|
|
14
|
+
How it works, in 14 minutes: what a certificate is, why the kernel is small, and the frontier. [Watch it on gdpwired.dev](https://gdpwired.dev/#explainer), with captions.
|
|
15
|
+
|
|
12
16
|
```sh
|
|
13
17
|
npm install gdp-wired # or bun add gdp-wired; plain JavaScript with types, Node 20+, Bun or a browser
|
|
14
18
|
```
|
|
@@ -38,6 +42,78 @@ protocols, commerce, supply chains, games, education, healthcare, energy, networ
|
|
|
38
42
|
governance, insurance, bookings, safety and IoT, mobility, media), each checked three ways: the kernel proves every law
|
|
39
43
|
and refutes every broken variant, random runs of both runtimes agree, and Lean checks the trees.
|
|
40
44
|
|
|
45
|
+
## First proof in your language
|
|
46
|
+
|
|
47
|
+
The rules already in your code (Python, Ruby, Elixir, Java, Kotlin, Go, Rust, Swift, C, C++, TypeScript, Effect,
|
|
48
|
+
XState) are read with nothing to write: the language, the class or functions, and what other code is answered or left
|
|
49
|
+
out are inferred.
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
npx gdp-wired-cli check src/limiter.py # or .rb .ex .java .kt .go .rs .swift .c .cpp .ts (Effect, XState), a Go package, a crate, a Swift package
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
It prints the rule in the code's names, checks it against the code by running both, and proposes laws from the rule's
|
|
56
|
+
own comparisons, each proven, broken (with the run, as calls of your code) or unknown, with the comment that states it.
|
|
57
|
+
State a law with one comment over the code's names; on the line above a method it is a law of that method's step:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
class Limiter:
|
|
61
|
+
def __init__(self, limit: int):
|
|
62
|
+
self.limit, self.used = limit, 0
|
|
63
|
+
|
|
64
|
+
# gdp: law a counted hit adds its cost: result implies used == old(used) + cost
|
|
65
|
+
# gdp: law used never passes the limit: used <= limit
|
|
66
|
+
def hit(self, cost: int) -> bool:
|
|
67
|
+
if cost <= 0 or self.used + cost > self.limit:
|
|
68
|
+
return False
|
|
69
|
+
self.used += cost
|
|
70
|
+
return True
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
limiter.py: Limiter (Python)
|
|
75
|
+
checked against the code: 2154 requests from the start, 400 from drawn states, 2 from the prover's witnesses, 3 of 3 branch arms
|
|
76
|
+
the entry inferred: Limiter, the class whose public methods write its state (hit; the others read it)
|
|
77
|
+
names (the code's, then the rule's):
|
|
78
|
+
limit state limit_
|
|
79
|
+
used state used
|
|
80
|
+
limit made with limit
|
|
81
|
+
hit(cost) request cost
|
|
82
|
+
hit() result result hit_result
|
|
83
|
+
laws stated in the code:
|
|
84
|
+
proven a counted hit adds its cost (limiter.py:5)
|
|
85
|
+
broken used never passes the limit (limiter.py:6)
|
|
86
|
+
used <= limit
|
|
87
|
+
run: made with limit = -3
|
|
88
|
+
hit(cost=-3)
|
|
89
|
+
laws proposed (nothing written; state one with the comment under it):
|
|
90
|
+
proven used is never negative
|
|
91
|
+
# gdp: law used is never negative: used >= 0
|
|
92
|
+
...
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
From code, the same in every language: one import, the file (a path or a URL; a Go package or a Rust crate by any file
|
|
96
|
+
of it), a law. The class, service or machine is inferred (`{entry}` names one), and Effect and XState run on the
|
|
97
|
+
packages the file's own project has:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import {extractEffect, proveRule} from 'gdp-wired/effect' // or extractPython from 'gdp-wired/extract-py', extract, ...
|
|
101
|
+
const x = extractEffect('./limiter.ts')
|
|
102
|
+
proveRule(x.rule!, [...x.invariants ?? [], x.rule!.law('never below zero', ({tokens}) => tokens.atLeast(0))])
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`//` in Go, Rust, C, C++, Java, Kotlin and TypeScript (an Effect service's laws above its make effect, an XState
|
|
106
|
+
machine's over its context, `value` and `event`); `@GdpLaw("<name>: <expr>")` on a Java or Kotlin method (with
|
|
107
|
+
the annotation declared in your code), `@gdp_law("...")` in Python, `@gdp_law "..."` in Elixir, `#[doc = "gdp: law
|
|
108
|
+
..."]` in Rust. The expression: comparisons, `+ - * k`, `and or not implies`, the state after the step by its fields
|
|
109
|
+
(`self.`, `this.`, `@` or bare; `after.x`), `old(x)` or `before.x` before it, the request's arguments by name,
|
|
110
|
+
`result`, `failed`, a call of other code answered by the request as `f(...)`, `x is None`, maps as the code reads them
|
|
111
|
+
(`counts[user]`, `user in counts`, `cache["rl:" + user]`), `forall k in m: ...`, a choice by its value (`mode ==
|
|
112
|
+
"closed"`). Anything else is refused with why, never dropped. Modelling choices a rule needs (`failures = "kept"` for
|
|
113
|
+
laws about when it raises, a store's attributes, an untyped result) go in a `gdp.toml` beside the code (or `[tool.gdp]`
|
|
114
|
+
in pyproject.toml, `"gdp"` in package.json), per rule under `[rules.<name>]`. The exit code is 1 when a stated law is
|
|
115
|
+
broken, 2 when one couldn't be checked: `uses: monotykamary/gdp-wired@main` with `paths:` runs it in CI.
|
|
116
|
+
|
|
41
117
|
## Where it fits
|
|
42
118
|
|
|
43
119
|
<img src="https://raw.githubusercontent.com/monotykamary/gdp-wired/main/static/venn.svg" alt="What Lean, Bend and gdp-wired each cover, and where they overlap" width="640" />
|
|
@@ -73,21 +149,21 @@ All of these are proven automatically, and each proof is also a Lean theorem:
|
|
|
73
149
|
firing are events from outside, taken only where they can come (each once a visit; one timer at a time), and
|
|
74
150
|
eventless transitions and entry and exit actions that write the context are read into each transition as XState's
|
|
75
151
|
macrostep.
|
|
76
|
-
- **Rules read from the code** (`gdp-wired/extract`): `extract(
|
|
152
|
+
- **Rules read from the code** (`gdp-wired/extract`): `extract('./bucket.ts')` reads a reducer, `useReducer`'s, functions
|
|
77
153
|
over one record, a class whose methods write its fields (with the classes it extends), or the object of functions a
|
|
78
154
|
factory returns, and returns the rule that steps the same way, as a builder value and as source to keep
|
|
79
|
-
(`toSource`); `extractXState` reads an XState machine, or a function that makes one, its guards and
|
|
80
|
-
inline,
|
|
155
|
+
(`toSource`); `extractXState('./machine.ts')` reads an XState machine, or a function that makes one, its guards and
|
|
156
|
+
actions named or inline, into a chart and its rule (xstate the one the file's project has). The extractor is untrusted: each rule is run beside the code it was read from (requests
|
|
81
157
|
from the start, steps from drawn states and from the prover's counterexamples, every state, cell, list, result and
|
|
82
158
|
refusal compared, the code's branches counted), and a difference refuses it. Its subset (integers, booleans, strings
|
|
83
159
|
and string-literal unions, values that may be null, records, Map and Record keyed state, arrays as lists, Dates as
|
|
84
160
|
their time, branches and early returns, throws as refusals, `Date.now()` as an input) and what it refuses, each with
|
|
85
161
|
the place and the reason, are in `core/extract.ts`.
|
|
86
|
-
- **Effect services** (`gdp-wired/effect`, `effect` 3.x or 4.x): `extractEffect(
|
|
162
|
+
- **Effect services** (`gdp-wired/effect`, `effect` 3.x or 4.x): `extractEffect('./limiter.ts')` reads a service
|
|
87
163
|
whose make effect creates Refs (Ref, SynchronizedRef, SubscriptionRef, 4.x's TxRef) and returns an object of methods
|
|
88
164
|
(`Effect.fn` bodies, arrows returning an effect), with typed failures as its refusals and `Clock.currentTimeMillis` as
|
|
89
|
-
an input; the rule is checked by running the service on Effect's runtime (`
|
|
90
|
-
each request's time), every Ref, result and failure compared. `conforms(rule, service)` runs a rule written by hand
|
|
165
|
+
an input; the rule is checked by running the service on Effect's runtime (the `effect` the file's project has,
|
|
166
|
+
`Effect.runSyncExit`, the clock fixed at each request's time), every Ref, result and failure compared. `conforms(rule, service)` runs a rule written by hand
|
|
91
167
|
beside a running service (Effect's own Semaphore, a store), and `fromSchema(schema)` is a Schema's kind
|
|
92
168
|
(`examples/effect.ts`; what is read and refused, with what Effect projects write, in `research/effect/README.md`).
|
|
93
169
|
- **What nobody stated, looked for when the prover alone stops**: where `proveRule` or `proveSteps` doesn't prove the laws
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { GoPkg } from '../extract-go.js';
|
|
2
|
+
type CN = {
|
|
3
|
+
id?: string;
|
|
4
|
+
kind: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
inner?: CN[];
|
|
7
|
+
type?: {
|
|
8
|
+
qualType: string;
|
|
9
|
+
desugaredQualType?: string;
|
|
10
|
+
};
|
|
11
|
+
value?: string;
|
|
12
|
+
opcode?: string;
|
|
13
|
+
castKind?: string;
|
|
14
|
+
isArrow?: boolean;
|
|
15
|
+
isPostfix?: boolean;
|
|
16
|
+
referencedDecl?: {
|
|
17
|
+
id: string;
|
|
18
|
+
kind: string;
|
|
19
|
+
name: string;
|
|
20
|
+
type?: {
|
|
21
|
+
qualType: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
referencedMemberDecl?: string;
|
|
25
|
+
storageClass?: string;
|
|
26
|
+
isImplicit?: boolean;
|
|
27
|
+
completeDefinition?: boolean;
|
|
28
|
+
tagUsed?: string;
|
|
29
|
+
hasElse?: boolean;
|
|
30
|
+
computeLHSType?: {
|
|
31
|
+
qualType: string;
|
|
32
|
+
desugaredQualType?: string;
|
|
33
|
+
};
|
|
34
|
+
init?: string;
|
|
35
|
+
decl?: {
|
|
36
|
+
id: string;
|
|
37
|
+
kind: string;
|
|
38
|
+
};
|
|
39
|
+
loc?: L;
|
|
40
|
+
range?: {
|
|
41
|
+
begin: L;
|
|
42
|
+
end: L;
|
|
43
|
+
};
|
|
44
|
+
$at?: At;
|
|
45
|
+
$b?: At;
|
|
46
|
+
$e?: At;
|
|
47
|
+
[k: string]: unknown;
|
|
48
|
+
};
|
|
49
|
+
type L = {
|
|
50
|
+
offset?: number;
|
|
51
|
+
file?: string;
|
|
52
|
+
line?: number;
|
|
53
|
+
col?: number;
|
|
54
|
+
tokLen?: number;
|
|
55
|
+
spellingLoc?: L;
|
|
56
|
+
expansionLoc?: L;
|
|
57
|
+
includedFrom?: unknown;
|
|
58
|
+
};
|
|
59
|
+
type At = {
|
|
60
|
+
file: string;
|
|
61
|
+
line: number;
|
|
62
|
+
col: number;
|
|
63
|
+
off: number;
|
|
64
|
+
tok: number;
|
|
65
|
+
};
|
|
66
|
+
export type CTarget = {
|
|
67
|
+
int: number;
|
|
68
|
+
long: number;
|
|
69
|
+
short: number;
|
|
70
|
+
llong: number;
|
|
71
|
+
charUnsigned: boolean;
|
|
72
|
+
};
|
|
73
|
+
export type CRead = {
|
|
74
|
+
pkg: GoPkg;
|
|
75
|
+
methods: string[];
|
|
76
|
+
entry: string;
|
|
77
|
+
cname: string;
|
|
78
|
+
};
|
|
79
|
+
export declare const node: <T>(id: string) => T;
|
|
80
|
+
export declare function clangDump(file: string, flags: string[], clang?: string, cpp?: boolean, filter?: string): {
|
|
81
|
+
tu: CN;
|
|
82
|
+
target: CTarget;
|
|
83
|
+
};
|
|
84
|
+
export declare function flagsFor(file: string, compileCommands?: string): string[];
|
|
85
|
+
export declare function readC(file: string, entry: string, tu: CN, target: CTarget, cpp?: boolean, root?: string, picks?: Record<string, number>): CRead;
|
|
86
|
+
export {};
|