gdp-wired 0.42.0 → 0.44.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 +14 -3
- package/dist/core/cli.d.ts +8 -1
- package/dist/core/cli.js +271 -30
- package/dist/core/counts.d.ts +8 -1
- package/dist/core/counts.js +171 -302
- package/dist/core/data.js +2 -2
- package/dist/core/dsl.js +26 -30
- package/dist/core/effect-prims.d.ts +60 -0
- package/dist/core/effect-prims.js +625 -0
- package/dist/core/effect-schedule.d.ts +103 -0
- package/dist/core/effect-schedule.js +817 -0
- package/dist/core/effect.d.ts +36 -1
- package/dist/core/effect.js +656 -29
- package/dist/core/ex/harness.exs +2 -0
- package/dist/core/exists.d.ts +5 -0
- package/dist/core/exists.js +98 -34
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +5 -3
- package/dist/core/extract-check.d.ts +2 -0
- package/dist/core/extract-check.js +45 -4
- package/dist/core/extract-ex.js +2 -2
- package/dist/core/extract-go-check.js +4 -6
- package/dist/core/extract-go.d.ts +3 -0
- package/dist/core/extract-go.js +4 -4
- package/dist/core/extract-jvm.js +6 -3
- package/dist/core/extract-print.js +9 -2
- package/dist/core/extract-py.js +2 -2
- package/dist/core/extract-rb.js +2 -2
- package/dist/core/extract-read.js +2 -1
- package/dist/core/extract-rs.js +12 -7
- package/dist/core/extract-sol.js +4 -4
- package/dist/core/extract-step.d.ts +18 -0
- package/dist/core/extract-step.js +135 -31
- package/dist/core/extract-swift.js +3 -3
- package/dist/core/extract.d.ts +8 -0
- package/dist/core/extract.js +13 -1
- package/dist/core/infer.d.ts +1 -0
- package/dist/core/infer.js +10 -7
- package/dist/core/jvm/Harness.java +8 -1
- package/dist/core/jvm/Jvm.java +1 -1
- package/dist/core/jvm/KtReader.java +3 -0
- package/dist/core/laws.d.ts +4 -0
- package/dist/core/laws.js +176 -9
- package/dist/core/machine.d.ts +3 -0
- package/dist/core/machine.js +17 -3
- package/dist/core/py/harness.py +64 -19
- package/dist/core/py/reader.py +51 -1
- package/dist/core/sol/Replay.sol +52 -0
- package/dist/core/sol/harness.py +508 -0
- package/dist/core/system.d.ts +44 -0
- package/dist/core/system.js +435 -0
- package/dist/interchange/check.d.ts +18 -1
- package/dist/interchange/check.js +9 -2
- package/dist/interchange/cli.d.ts +2 -0
- package/dist/interchange/cli.js +45 -0
- package/dist/interchange/format.d.ts +1 -1
- package/dist/interchange/format.js +15 -7
- package/dist/kernel/cdcl.js +32 -12
- package/dist/kernel/kernel.js +3 -2
- package/dist/kernel/prove.d.ts +1 -0
- package/dist/kernel/prove.js +69 -8
- package/dist/kernel/reader.js +3 -2
- package/dist/lean-kernel/emit.js +3 -3
- package/dist/lean-kernel/lean-terms.d.ts +1 -0
- package/dist/lean-kernel/lean-terms.js +8 -4
- package/package.json +12 -3
package/dist/core/extract-rs.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Refusal, pathOf } from "./extract-read.js";
|
|
2
|
-
import { entryNames, extractStep, node, stubbed } from "./extract-step.js";
|
|
2
|
+
import { asset, entryNames, extractStep, node, stubbed } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
4
|
const proc = globalThis.process;
|
|
5
5
|
// The reader, built once per version of its source (into the system's temporary directory).
|
|
6
6
|
export function rsReader(cargo = 'cargo') {
|
|
7
7
|
const fs = node('node:fs'), cp = node('node:child_process'), os = node('node:os'), crypto = node('node:crypto');
|
|
8
|
-
const dir =
|
|
8
|
+
const dir = asset('rs/');
|
|
9
9
|
const h = crypto.createHash('sha256').update(fs.readFileSync(`${dir}src/main.rs`, 'utf8') + fs.readFileSync(`${dir}Cargo.toml`, 'utf8')).digest('hex').slice(0, 12);
|
|
10
10
|
const target = `${os.tmpdir()}/gdp-rsreader-${h}`, bin = `${target}/release/gdp-rsreader`;
|
|
11
11
|
if (!fs.existsSync(bin))
|
|
@@ -177,12 +177,15 @@ pub(crate) mod __gdp_harness {
|
|
|
177
177
|
// An answered call's value: the request's input for it (each answered call rewritten to crate::__gdp_answer).
|
|
178
178
|
static ANS: std::sync::Mutex<Option<Value>> = std::sync::Mutex::new(None);
|
|
179
179
|
pub(crate) trait GdpAns { fn of(v: &Value) -> Self; }
|
|
180
|
-
|
|
180
|
+
// (an answer outside the call's type, a type stated wider than the code's: a request the code can't be given)
|
|
181
|
+
pub(crate) struct GdpOutside(pub(crate) String);
|
|
182
|
+
macro_rules! gdp_int { ($($t:ty),*) => { $(impl GdpAns for $t { fn of(v: &Value) -> Self { match int(val(v)) { Ok(n) => <$t>::try_from(n).unwrap_or_else(|_| std::panic::panic_any(GdpOutside(format!("{} outside {}", n, stringify!($t))))), Err(_) => Default::default() } } })* } }
|
|
181
183
|
gdp_int!(i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize);
|
|
182
184
|
impl GdpAns for bool { fn of(v: &Value) -> Self { val(v).as_bool().unwrap_or(false) } }
|
|
183
185
|
impl GdpAns for String { fn of(v: &Value) -> Self { val(v).as_str().unwrap_or("").to_string() } }
|
|
184
186
|
impl<T: GdpAns> GdpAns for Option<T> { fn of(v: &Value) -> Self { if v.get("none").and_then(|x| x.as_bool()) == Some(true) { None } else { Some(T::of(v)) } } }
|
|
185
|
-
|
|
187
|
+
// (the value taken out of the lock first: an answer outside its type panics, which must leave the lock usable)
|
|
188
|
+
pub(crate) fn answer<T: GdpAns>(k: &str) -> T { let v = ANS.lock().unwrap_or_else(|e| e.into_inner()).as_ref().and_then(|a| a.get(k).cloned()).unwrap_or(Value::Null); T::of(&v) }
|
|
186
189
|
fn base() -> std::time::Instant { *BASE.get_or_init(|| std::time::Instant::now() + std::time::Duration::from_secs(1u64 << 31)) }
|
|
187
190
|
pub(crate) fn now() -> std::time::Instant { inst(NOW.load(std::sync::atomic::Ordering::SeqCst) as i128) }
|
|
188
191
|
fn inst(n: i128) -> std::time::Instant { if n >= 0 { base() + std::time::Duration::from_nanos(n as u64) } else { base() - std::time::Duration::from_nanos((-n) as u64) } }
|
|
@@ -216,7 +219,7 @@ pub(crate) mod __gdp_harness {
|
|
|
216
219
|
"call" => {
|
|
217
220
|
let i = req["id"].as_u64().unwrap() as usize - 1;
|
|
218
221
|
NOW.store(int(&req["now"]).unwrap_or(0) as i64, std::sync::atomic::Ordering::SeqCst);
|
|
219
|
-
*ANS.lock().
|
|
222
|
+
*ANS.lock().unwrap_or_else(|e| e.into_inner()) = Some(req["answers"].clone());
|
|
220
223
|
let m = req["m"].as_str().unwrap().to_string();
|
|
221
224
|
let a = req["a"].clone();
|
|
222
225
|
let o = &mut objs[i];
|
|
@@ -224,6 +227,7 @@ pub(crate) mod __gdp_harness {
|
|
|
224
227
|
Ok(Ok(Ok(v))) => json!({"out": v}),
|
|
225
228
|
Ok(Ok(Err(e))) => json!({"out": null, "err": e}),
|
|
226
229
|
Ok(Err(bad)) => json!({"out": null, "bad": bad}),
|
|
230
|
+
Err(p) if p.downcast_ref::<GdpOutside>().is_some() => json!({"out": null, "outside": p.downcast_ref::<GdpOutside>().unwrap().0}),
|
|
227
231
|
Err(p) => json!({"out": null, "err": format!("panic: {}", p.downcast_ref::<String>().cloned().or_else(|| p.downcast_ref::<&str>().map(|s| s.to_string())).unwrap_or_default())}),
|
|
228
232
|
}
|
|
229
233
|
}
|
|
@@ -257,8 +261,9 @@ function harnessFor(dir, mod, read, opts) {
|
|
|
257
261
|
// The clock: Instant::now() read through the harness (the request's time), the code's own calls rewritten first.
|
|
258
262
|
const lib = fs.existsSync(`${work}/src/lib.rs`) ? 'src/lib.rs' : 'src/main.rs';
|
|
259
263
|
const walk = (d) => fs.readdirSync(d, { withFileTypes: true }).flatMap((e) => { const x = e; return x.isDirectory() ? walk(`${d}/${x.name}`) : x.name.endsWith('.rs') ? [`${d}/${x.name}`] : []; });
|
|
260
|
-
// (each answered call rewritten to the harness's answer, from the crate's own text, before the clock's
|
|
261
|
-
|
|
264
|
+
// (each answered call rewritten to the harness's answer, from the crate's own text, before the clock's; the call
|
|
265
|
+
// kept in a branch never taken, so the answer is of the type the call is, which a binding needn't write)
|
|
266
|
+
for (const [f, t] of stubbed(read, f => fs.readFileSync(`${dir}/${f}`, 'utf8'), (a, _, call) => `(if false { ${call} } else { crate::__gdp_answer(${JSON.stringify(a.key)}) })`))
|
|
262
267
|
fs.writeFileSync(`${work}/${f}`, t);
|
|
263
268
|
for (const f of walk(`${work}/src`)) {
|
|
264
269
|
const s = fs.readFileSync(f, 'utf8');
|
package/dist/core/extract-sol.js
CHANGED
|
@@ -29,7 +29,7 @@ import { allowed, watch } from "./watch.js";
|
|
|
29
29
|
import { kindOfVar } from "./extract-check.js";
|
|
30
30
|
import { Refusal, pathOf } from "./extract-read.js";
|
|
31
31
|
const refuse = (where, what) => { throw new Refusal(where, what); };
|
|
32
|
-
import { checkStep, node, readStep, stepNames } from "./extract-step.js";
|
|
32
|
+
import { asset, checkStep, node, readStep, stepNames } from "./extract-step.js";
|
|
33
33
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
34
34
|
export const MOD = 'W256$';
|
|
35
35
|
// (the width the check runs the rule at: past 2^256's half the code's values are the rule's near W)
|
|
@@ -815,7 +815,7 @@ export function extractSolidity(at, opts = {}) {
|
|
|
815
815
|
const slots = Object.fromEntries(out.storageLayout.storage.map(s => [s.label, { slot: s.slot, offset: s.offset, bytes: Number(types[s.type]?.numberOfBytes ?? 32), map: types[s.type]?.encoding === 'mapping', nested: meta.nested.includes(s.label), type: s.type }]));
|
|
816
816
|
const kinds = Object.fromEntries(meta.fields.map(f => [f.name, kindOf(f.t, f.sol)]));
|
|
817
817
|
const mapKeys = Object.fromEntries(meta.fields.filter(f => f.sol.startsWith('mapping(')).map(f => [f.name, keyKinds(f.sol)]));
|
|
818
|
-
return { cmd: opts.python ?? 'python3', args: [
|
|
818
|
+
return { cmd: opts.python ?? 'python3', args: [asset('sol/harness.py')], env: { ...(opts.anvil ? { GDP_ANVIL: opts.anvil } : {}) },
|
|
819
819
|
hello: { sol: { creation: out.evm.bytecode.object, abi: out.abi, ids: out.evm.methodIdentifiers, slots, kinds, mapKeys, havoc: meta.nested, havocBy: havocBy(mod), mod: MOD, minW: meta.minW, addrBits: meta.addrBits, entries: meta.entries, ctor: meta.ctor, ether: meta.ether } } };
|
|
820
820
|
};
|
|
821
821
|
// (methods: the external functions that may write the state, unless named)
|
|
@@ -895,7 +895,7 @@ export function extractSolidity(at, opts = {}) {
|
|
|
895
895
|
return { ...rx, read: rread, names: stepNames(rread), quiet: 'pending$', ...(replays ? { replay: (run, law) => replays(run, law) } : {}) };
|
|
896
896
|
}
|
|
897
897
|
function compileReplay(o) {
|
|
898
|
-
const c = compile(
|
|
898
|
+
const c = compile(asset('sol/Replay.sol'), { ...o, root: asset('sol/') });
|
|
899
899
|
const k = c.contracts[c.paths.get(c.main)];
|
|
900
900
|
return { agent: k.Agent.evm.deployedBytecode.object, director: k.Director.evm.deployedBytecode.object };
|
|
901
901
|
}
|
|
@@ -1013,7 +1013,7 @@ function replayer(c) {
|
|
|
1013
1013
|
let out;
|
|
1014
1014
|
try {
|
|
1015
1015
|
fs.writeFileSync(`${dir}/run.json`, JSON.stringify({ sol: c.hello, leaves: c.leaves, ctorSpec: c.ctor, ctor: ctorArgs, agent: c.replay.agent, director: c.replay.director, groups }));
|
|
1016
|
-
out = JSON.parse(cp.execFileSync(c.opts.python ?? 'python3', [
|
|
1016
|
+
out = JSON.parse(cp.execFileSync(c.opts.python ?? 'python3', [asset('sol/harness.py'), '--replay', `${dir}/run.json`], { encoding: 'utf8', maxBuffer: 1 << 26, stdio: ['ignore', 'pipe', 'pipe'], env: { ...env(), ...(c.opts.anvil ? { GDP_ANVIL: c.opts.anvil } : {}) } }));
|
|
1017
1017
|
}
|
|
1018
1018
|
catch (e) {
|
|
1019
1019
|
return no(`the replay didn't run (${String(e.message).slice(0, 300)})`);
|
|
@@ -18,6 +18,7 @@ export type SType = {
|
|
|
18
18
|
k: 'float' | 'bool' | 'str' | 'none' | 'any' | 'lock';
|
|
19
19
|
atomic?: string;
|
|
20
20
|
lock?: string;
|
|
21
|
+
bytes?: boolean;
|
|
21
22
|
} | {
|
|
22
23
|
k: 'choice';
|
|
23
24
|
values: string[];
|
|
@@ -37,6 +38,7 @@ export type SType = {
|
|
|
37
38
|
k: 'map';
|
|
38
39
|
key: SType;
|
|
39
40
|
val: SType;
|
|
41
|
+
set?: boolean;
|
|
40
42
|
} | {
|
|
41
43
|
k: 'list';
|
|
42
44
|
of: SType;
|
|
@@ -113,6 +115,7 @@ export type SModule = {
|
|
|
113
115
|
path: string;
|
|
114
116
|
module: string;
|
|
115
117
|
root: string;
|
|
118
|
+
consts?: Record<string, number | string | boolean>;
|
|
116
119
|
entries: ({
|
|
117
120
|
k: 'class';
|
|
118
121
|
rec: string;
|
|
@@ -193,6 +196,7 @@ export type StepOptions = {
|
|
|
193
196
|
failures?: 'refuse' | 'kept';
|
|
194
197
|
onError?: 'refuse' | 'discard';
|
|
195
198
|
domains?: Record<string, 'nat' | 'int'>;
|
|
199
|
+
keep?: string[];
|
|
196
200
|
defaults?: string[];
|
|
197
201
|
fields?: Record<string, null | boolean | number | string>;
|
|
198
202
|
share?: boolean;
|
|
@@ -422,6 +426,7 @@ export type Leaf = {
|
|
|
422
426
|
path: string[];
|
|
423
427
|
kind: 'num' | 'bool' | 'str' | 'choice' | 'none' | 'map' | 'frame';
|
|
424
428
|
float?: boolean;
|
|
429
|
+
set?: boolean;
|
|
425
430
|
cls?: string;
|
|
426
431
|
fields?: {
|
|
427
432
|
name: string;
|
|
@@ -440,6 +445,7 @@ export type PArg = {
|
|
|
440
445
|
name: string;
|
|
441
446
|
float?: boolean;
|
|
442
447
|
sym?: boolean;
|
|
448
|
+
bytes?: boolean;
|
|
443
449
|
z?: Raw;
|
|
444
450
|
} | {
|
|
445
451
|
k: 'opt';
|
|
@@ -585,6 +591,8 @@ export declare class Stepper {
|
|
|
585
591
|
p: string;
|
|
586
592
|
}, p: Path, role?: Var['role']): [V, PArg];
|
|
587
593
|
intTy(t: SType): IntTy | undefined;
|
|
594
|
+
bytesVars: Set<string>;
|
|
595
|
+
kept: Set<string>;
|
|
588
596
|
typed(v: Var, t: SType | IntTy, role: Var['role'], sel?: I.B): void;
|
|
589
597
|
sel: B;
|
|
590
598
|
shared: Map<string, [V, PArg]>;
|
|
@@ -771,6 +779,7 @@ export declare class Stepper {
|
|
|
771
779
|
answer(key: string, names: string[], patch: Patch | undefined, at: SX, p: Path, awaited: boolean, type?: string | SType, how?: string): [V, Path];
|
|
772
780
|
passing(key: string, name: string, patch: Patch | undefined, at: SX, p: Path, awaited: boolean): Path;
|
|
773
781
|
readonly pend: Map<string, Pend>;
|
|
782
|
+
readonly leftOut: Set<string>;
|
|
774
783
|
readonly returnedBy: Map<string, {
|
|
775
784
|
id: string;
|
|
776
785
|
roots: string[];
|
|
@@ -812,6 +821,7 @@ export declare class Stepper {
|
|
|
812
821
|
argsRead(x: SX, p: Path): Path;
|
|
813
822
|
evArgs<T>(x: SX, p: Path, k: (args: V[], kw: [string, V][], p: Path) => T): T;
|
|
814
823
|
dictCall(m: V, name: string, x: SX, p: Path): [V, Path];
|
|
824
|
+
setCall(m: V, name: string, x: SX, p: Path): [V, Path];
|
|
815
825
|
construct(rec: string, args: V[], kw: [string, V][], x: SX, p: Path): [V, Path];
|
|
816
826
|
builtin(n: string, x: SX, p: Path): [V, Path];
|
|
817
827
|
quotient(d: SX, p: Path, round: 'floor' | 'ceil' | 'trunc' | 'even'): [V, Path];
|
|
@@ -959,6 +969,14 @@ export declare const varTerm: (v: Var) => Term;
|
|
|
959
969
|
export declare function iteTerm(c: B, a: Term, b: Term): Term;
|
|
960
970
|
type Raw = number | boolean | string;
|
|
961
971
|
export declare const node: <T>(id: string) => T;
|
|
972
|
+
export declare function asset(rel: string): string;
|
|
973
|
+
export declare function openHarness(work: string, cmd: string, args: string[], o: Record<string, unknown>): {
|
|
974
|
+
child: {
|
|
975
|
+
kill: () => void;
|
|
976
|
+
};
|
|
977
|
+
wi: number;
|
|
978
|
+
ro: number;
|
|
979
|
+
};
|
|
962
980
|
export type Harness = {
|
|
963
981
|
cmd: string;
|
|
964
982
|
args: string[];
|
|
@@ -29,6 +29,10 @@ import { Refusal, mergeOps, mergeWrites } from "./extract-read.js";
|
|
|
29
29
|
import { fromModel } from "./extract.js";
|
|
30
30
|
import { nonneg } from "./extract-print.js";
|
|
31
31
|
import { Outside, constantsOf, draw, drive } from "./extract-check.js";
|
|
32
|
+
// A string that is one of a choice's literals on every path (a literal, or literals by a condition): the choice's.
|
|
33
|
+
const asChoice = (k, vs) => { if (k.op === 'slit')
|
|
34
|
+
return vs.includes(k.value) ? I.llit(k.value, vs) : undefined; if (k.op !== 'kite')
|
|
35
|
+
return undefined; const a = asChoice(k.a, vs), b = asChoice(k.b, vs); return a && b ? I.lite(k.c, a, b) : undefined; };
|
|
32
36
|
const where = (x) => x.p || '?';
|
|
33
37
|
const refuse = (x, what) => { throw new Refusal(typeof x === 'string' ? x : where(x), what); };
|
|
34
38
|
const RESERVED = new Set(['rule', 'nat', 'int', 'bool', 'when', 'min', 'max', 'all', 'any', 'not', 'yes', 'no', 'lit', 'str', 'record', 'oneOf', 'intern', 'Int', 'forall']);
|
|
@@ -155,7 +159,7 @@ export class Stepper {
|
|
|
155
159
|
if (t.k === 'list')
|
|
156
160
|
return 'a list (lists are outside the Python subset)';
|
|
157
161
|
if (t.k === 'map')
|
|
158
|
-
return 'a dict';
|
|
162
|
+
return t.set ? 'a set' : 'a dict';
|
|
159
163
|
return t.k;
|
|
160
164
|
}
|
|
161
165
|
// An input of a type: its variables, the value, and how the harness makes it.
|
|
@@ -164,7 +168,7 @@ export class Stepper {
|
|
|
164
168
|
if (s) {
|
|
165
169
|
const v = this.newVar(name, s, role);
|
|
166
170
|
this.typed(v, t, role);
|
|
167
|
-
return [this.valueOf(v), { k: 'in', name: v.name, z: zeroRaw(s), ...(t.k === 'float' ? { float: true } : {}), ...(t.k === 'choice' && t.sym ? { sym: true } : {}) }];
|
|
171
|
+
return [this.valueOf(v), { k: 'in', name: v.name, z: zeroRaw(s), ...(t.k === 'float' ? { float: true } : {}), ...(t.k === 'choice' && t.sym ? { sym: true } : {}), ...(t.k === 'str' && t.bytes ? { bytes: true } : {}) }];
|
|
168
172
|
}
|
|
169
173
|
if (t.k === 'opt') {
|
|
170
174
|
if (t.of.k === 'rec') {
|
|
@@ -177,7 +181,7 @@ export class Stepper {
|
|
|
177
181
|
return refuse(at, `${name}: an optional ${this.why(t.of)}`);
|
|
178
182
|
const v = this.newVar(name, inner, role, `0 where ${name} is None`), none = this.newVar(`${name}_none`, { k: 'bool' }, role, `whether ${name} is None`);
|
|
179
183
|
this.typed(v, t.of, role);
|
|
180
|
-
return [{ t: 'opt', has: I.not(I.bvar(none.name)), v: this.valueOf(v) }, { k: 'opt', none: none.name, v: { k: 'in', name: v.name, z: zeroRaw(inner), ...(t.of.k === 'float' ? { float: true } : {}) } }];
|
|
184
|
+
return [{ t: 'opt', has: I.not(I.bvar(none.name)), v: this.valueOf(v) }, { k: 'opt', none: none.name, v: { k: 'in', name: v.name, z: zeroRaw(inner), ...(t.of.k === 'float' ? { float: true } : {}), ...(t.of.k === 'str' && t.of.bytes ? { bytes: true } : {}) } }];
|
|
181
185
|
}
|
|
182
186
|
if (t.k === 'none')
|
|
183
187
|
return [{ t: 'none' }, { k: 'dflt' }];
|
|
@@ -207,7 +211,13 @@ export class Stepper {
|
|
|
207
211
|
// A fixed-width integer variable: its type, and (for a request) a value outside it refused: the claim is for the
|
|
208
212
|
// type's values.
|
|
209
213
|
intTy(t) { return t.k === 'int' && t.bits !== undefined ? { bits: t.bits, signed: t.signed ?? true, ...(t.mod ? { mod: t.mod } : {}) } : undefined; }
|
|
214
|
+
// (bytes: a string of the rule's that is never equal to a str, as Python's b"x" != "x")
|
|
215
|
+
bytesVars = new Set();
|
|
216
|
+
// (the request's arguments kept though no term reads them: opts.keep)
|
|
217
|
+
kept = new Set();
|
|
210
218
|
typed(v, t, role, sel = this.sel) {
|
|
219
|
+
if ('k' in t && t.k === 'str' && t.bytes)
|
|
220
|
+
this.bytesVars.add(v.name);
|
|
211
221
|
const ty = 'k' in t ? this.intTy(t) : t;
|
|
212
222
|
if (!ty)
|
|
213
223
|
return;
|
|
@@ -949,7 +959,10 @@ export class Stepper {
|
|
|
949
959
|
this.frames.pop();
|
|
950
960
|
this.frameLocals.pop();
|
|
951
961
|
}
|
|
952
|
-
|
|
962
|
+
// (a literal returned where the function declares a choice of literals, `-> Literal["a", "b"]`: the choice's)
|
|
963
|
+
const rt = f.ret?.k === 'opt' ? f.ret.of : f.ret;
|
|
964
|
+
const asDeclared = (v) => { const l = rt?.k === 'choice' && v.t === 'str' ? asChoice(v.e, rt.values) : undefined; return l ? { t: 'choice', e: l } : v; };
|
|
965
|
+
const rets = [...flow.rets, ...(flow.live ? [[flow.live, { t: 'none' }]] : [])].map(([r, v]) => [r, asDeclared(v)]);
|
|
953
966
|
if (!rets.length)
|
|
954
967
|
return [{ t: 'none' }, { ...q, pc: [...q.pc, I.F], locals: saved }];
|
|
955
968
|
const joined = this.join(rets.map(([r, v]) => ({ ...r, locals: new Map([['$ret', v]]) })), at), out = joined.locals.get('$ret');
|
|
@@ -1256,8 +1269,11 @@ export class Stepper {
|
|
|
1256
1269
|
this.declared.set(`${o.id}.${f}`, t);
|
|
1257
1270
|
// (a literal written to a field of a choice is the choice's)
|
|
1258
1271
|
const ft = this.declared.get(`${o.id}.${f}`) ?? this.mod.recs[obj.ty]?.fields.find(x => x.name === f)?.t, ct = ft?.k === 'opt' ? ft.of : ft;
|
|
1259
|
-
if (ct?.k === 'choice' && v.t === 'str'
|
|
1260
|
-
|
|
1272
|
+
if (ct?.k === 'choice' && v.t === 'str') {
|
|
1273
|
+
const l = asChoice(v.e, ct.values);
|
|
1274
|
+
if (l)
|
|
1275
|
+
v = { t: 'choice', e: l };
|
|
1276
|
+
}
|
|
1261
1277
|
const heap = new Map(p.heap).set(o.id, { ...obj, f: new Map(obj.f).set(f, v) });
|
|
1262
1278
|
return { ...p, heap };
|
|
1263
1279
|
}
|
|
@@ -1271,10 +1287,7 @@ export class Stepper {
|
|
|
1271
1287
|
}
|
|
1272
1288
|
// (a string that is a literal of the choice on every path)
|
|
1273
1289
|
if (f.sort.k === 'choice' && v.t === 'str') {
|
|
1274
|
-
const
|
|
1275
|
-
return vs.includes(k.value) ? I.llit(k.value, vs) : undefined; if (k.op !== 'kite')
|
|
1276
|
-
return undefined; const a = conv(k.a), b = conv(k.b); return a && b ? I.lite(k.c, a, b) : undefined; };
|
|
1277
|
-
const l = conv(v.e);
|
|
1290
|
+
const l = asChoice(v.e, f.sort.values);
|
|
1278
1291
|
if (l)
|
|
1279
1292
|
return { t: 'choice', e: l };
|
|
1280
1293
|
}
|
|
@@ -1372,7 +1385,12 @@ export class Stepper {
|
|
|
1372
1385
|
this.notes.add(`${r.short}.${f.name}: a string the module only sets to ${vs.map(x => JSON.stringify(x)).join(' or ')} (read as a choice of those)`);
|
|
1373
1386
|
return { k: 'choice', values: vs };
|
|
1374
1387
|
};
|
|
1375
|
-
|
|
1388
|
+
// (a set: its keys alone, a cell held or not, as the TypeScript front end's Set)
|
|
1389
|
+
if (t.set) {
|
|
1390
|
+
fields = [];
|
|
1391
|
+
scalar = false;
|
|
1392
|
+
}
|
|
1393
|
+
else if (t.val.k === 'rec') {
|
|
1376
1394
|
const r = this.rec(t.val.name, at);
|
|
1377
1395
|
fields = r.fields.map(f => cell(f.name, lits(r, f)));
|
|
1378
1396
|
scalar = false;
|
|
@@ -1380,7 +1398,7 @@ export class Stepper {
|
|
|
1380
1398
|
else
|
|
1381
1399
|
fields = [cell('value', t.val)];
|
|
1382
1400
|
const v = this.newVar(name, { k: 'num' }, 'state');
|
|
1383
|
-
const d = { name: v.name, key, fields, scalar, js: 'Map' };
|
|
1401
|
+
const d = { name: v.name, key, fields, scalar, js: t.set ? 'Set' : 'Map' };
|
|
1384
1402
|
this.maps.push(d);
|
|
1385
1403
|
return d;
|
|
1386
1404
|
}
|
|
@@ -1646,8 +1664,12 @@ export class Stepper {
|
|
|
1646
1664
|
if (!pa.inject && (this.scalar(t) || ['lock', 'none', 'map', 'list'].includes(t.k) || (t.k === 'rec' && this.mod.recs[t.name]?.own && !this.mod.recs[t.name].kinds.includes('protocol')) || (pa.dflt && !(pa.t.k === 'opt' && pa.dflt.e === 'none'))))
|
|
1647
1665
|
return undefined;
|
|
1648
1666
|
const fields = [];
|
|
1649
|
-
|
|
1650
|
-
|
|
1667
|
+
// (self.f = arg, or one place of a tuple's, self.a, self.f = a, arg)
|
|
1668
|
+
const pairs = (to, v) => (to?.e === 'tuple' && v?.e === 'tuple' && to.xs.length === v.xs.length ? to.xs.flatMap((t, i) => pairs(t, v.xs[i])) : [[to, v]]);
|
|
1669
|
+
deep(init.body, st => { if (st.s === 'set')
|
|
1670
|
+
for (const [to, v] of pairs(st.to, st.x))
|
|
1671
|
+
if (to?.e === 'get' && to.x.e === 'var' && to.x.n === 'self' && v?.e === 'var' && v.n === pa.name)
|
|
1672
|
+
fields.push(String(to.f)); });
|
|
1651
1673
|
const ms = this.callsOn(r, fields);
|
|
1652
1674
|
if (!pa.inject && !ms.length)
|
|
1653
1675
|
return undefined;
|
|
@@ -1741,7 +1763,13 @@ export class Stepper {
|
|
|
1741
1763
|
}
|
|
1742
1764
|
continue;
|
|
1743
1765
|
}
|
|
1744
|
-
|
|
1766
|
+
// (another option given a constant, None or a flag, as a tracing span or which tier to use: the store is read as
|
|
1767
|
+
// one map whatever it says, the check's too, and the note says so; one given a value of the request is refused)
|
|
1768
|
+
if (v.t === 'none' || (v.t === 'bool' && v.e.op === 'const') || (v.t === 'num' && v.e.op === 'const') || (v.t === 'str' && v.e.op === 'slit')) {
|
|
1769
|
+
this.notes.add(`${store}.${m}: its ${n} (${v.t === 'none' ? 'None' : v.t === 'str' ? JSON.stringify(v.e.value) : String(v.e.v)}) left out: the store read as one map whatever it says`);
|
|
1770
|
+
continue;
|
|
1771
|
+
}
|
|
1772
|
+
return refuse(at, `${at.text}: the store's ${m} given ${n}, a value the request decides (the subset reads a key, a value, nx, xx, the expiry and options given a constant)`);
|
|
1745
1773
|
}
|
|
1746
1774
|
given(all.filter(v => v !== keyV && v !== valV));
|
|
1747
1775
|
if (args.length > (kind === 'set' ? 2 : 1))
|
|
@@ -2027,6 +2055,8 @@ export class Stepper {
|
|
|
2027
2055
|
// other code may change it: refused unless the caller states it. Its value read (a run refused where it is): the next
|
|
2028
2056
|
// run answers it by the request, over its declared type; else it is left out, kept only where nothing reads it.
|
|
2029
2057
|
pend = new Map();
|
|
2058
|
+
// (the calls of other code left out, by the callee's names: a check that can't run them, C's, makes them no-ops)
|
|
2059
|
+
leftOut = new Set();
|
|
2030
2060
|
returnedBy = new Map();
|
|
2031
2061
|
entryIds = new Set();
|
|
2032
2062
|
boundary(x, b, p, awaited) {
|
|
@@ -2043,6 +2073,7 @@ export class Stepper {
|
|
|
2043
2073
|
return this.answer(b.key, [b.name], b.patch, x, q, awaited, t, tag ? 'tagged' : 'inferred');
|
|
2044
2074
|
const why = `${x.text ?? b.name}: the value of ${b.name}, other code left out`;
|
|
2045
2075
|
this.pend.set(why, { ...b, why, at: x.p, ...(x.end ? { end: x.end } : {}) });
|
|
2076
|
+
this.leftOut.add(b.name).add(b.key);
|
|
2046
2077
|
this.notes.add(`${b.name} (${x.p}): left out (${tag ? 'tagged: gdp: skip' : 'inferred: nothing the rule keeps reads its value'}), run as it is by the check`);
|
|
2047
2078
|
return [{ t: 'opaque', why, ask: b.key }, this.passing(b.key, b.name, b.patch, x, q, awaited)];
|
|
2048
2079
|
}
|
|
@@ -2362,6 +2393,8 @@ export class Stepper {
|
|
|
2362
2393
|
if (ans)
|
|
2363
2394
|
return this.answer(ans, names, patch, x, x.args ? this.argsRead(x, p) : p, false);
|
|
2364
2395
|
if (this.skipped(names)) {
|
|
2396
|
+
for (const n of names)
|
|
2397
|
+
this.leftOut.add(n);
|
|
2365
2398
|
this.notes.add(`${names[0]} (${x.p}): left out (stated: skip), run as it is by the check`);
|
|
2366
2399
|
return [{ t: 'opaque', why: `${names[0]}: the value of a call left out (skip)` }, this.passing(names[0], names[0], patch, x, x.args ? this.argsRead(x, p) : p, false)];
|
|
2367
2400
|
}
|
|
@@ -3009,8 +3042,10 @@ export class Stepper {
|
|
|
3009
3042
|
return I.cmp('=', a.e, b.e);
|
|
3010
3043
|
if (a.t === 'bool' && b.t === 'bool')
|
|
3011
3044
|
return I.bite(a.e, b.e, I.not(b.e));
|
|
3012
|
-
if (a.t === 'str' && b.t === 'str')
|
|
3013
|
-
|
|
3045
|
+
if (a.t === 'str' && b.t === 'str') {
|
|
3046
|
+
const isB = (k) => (k.op === 'svar' ? this.bytesVars.has(k.name) : k.op === 'slit' ? false : undefined), x = isB(a.e), y = isB(b.e);
|
|
3047
|
+
return x !== undefined && y !== undefined && x !== y ? I.F : I.keq(a.e, b.e);
|
|
3048
|
+
}
|
|
3014
3049
|
if (a.t === 'choice' && b.t === 'choice')
|
|
3015
3050
|
return I.leq(a.e, b.e);
|
|
3016
3051
|
if (a.t === 'choice' && b.t === 'str' && b.e.op === 'slit')
|
|
@@ -3117,6 +3152,9 @@ export class Stepper {
|
|
|
3117
3152
|
const r = this.rec(obj.ty, x);
|
|
3118
3153
|
patch = { mod: r.module, path: [r.short, String(fx.f)] };
|
|
3119
3154
|
}
|
|
3155
|
+
// (a method of a store or an injected dependency: stubbed on the one the check gives)
|
|
3156
|
+
else if (obj?.k === 'store')
|
|
3157
|
+
patch = { store: obj.name, path: [String(fx.f)] };
|
|
3120
3158
|
else {
|
|
3121
3159
|
const [v] = this.ev(fx, p);
|
|
3122
3160
|
if (v.t === 'ext' || v.t === 'cls')
|
|
@@ -3130,6 +3168,8 @@ export class Stepper {
|
|
|
3130
3168
|
}
|
|
3131
3169
|
if (ans)
|
|
3132
3170
|
return this.answer(ans, names, patch, x, this.argsRead(x, p), awaited);
|
|
3171
|
+
for (const n of names)
|
|
3172
|
+
this.leftOut.add(n);
|
|
3133
3173
|
this.notes.add(`${names[0]} (${x.p}): left out (stated: skip), run as it is by the check`);
|
|
3134
3174
|
return [{ t: 'opaque', why: `${x.text}: the value of a call left out (skip)` }, this.passing(names[0], names[0], patch, x, this.argsRead(x, p), awaited)];
|
|
3135
3175
|
}
|
|
@@ -3236,6 +3276,8 @@ export class Stepper {
|
|
|
3236
3276
|
return k(args, kw, q);
|
|
3237
3277
|
}
|
|
3238
3278
|
dictCall(m, name, x, p) {
|
|
3279
|
+
if (this.mapObj(m, x, p)[1].decl.js === 'Set')
|
|
3280
|
+
return this.setCall(m, name, x, p);
|
|
3239
3281
|
return this.evArgs(x, p, (args, kw, q) => {
|
|
3240
3282
|
if (kw.length)
|
|
3241
3283
|
return refuse(x, `${x.text}: a dict's method given keywords`);
|
|
@@ -3266,6 +3308,19 @@ export class Stepper {
|
|
|
3266
3308
|
return refuse(x, `${x.text}: dict.${name} (the subset reads get, pop, [k], in and del)`);
|
|
3267
3309
|
});
|
|
3268
3310
|
}
|
|
3311
|
+
// A set's methods: add, discard and remove (a KeyError where the key isn't held), each a write of one key.
|
|
3312
|
+
setCall(m, name, x, p) {
|
|
3313
|
+
return this.evArgs(x, p, (args, kw, q) => {
|
|
3314
|
+
if (kw.length || args.length !== 1)
|
|
3315
|
+
return refuse(x, `${x.text}: a set's method given other than one key`);
|
|
3316
|
+
const [id, o] = this.mapObj(m, x, q), k = this.keyOf(args[0], x.args[0]);
|
|
3317
|
+
if (name === 'add')
|
|
3318
|
+
return [{ t: 'none' }, this.writeCell(id, o, k, I.T, new Map(), x, q)];
|
|
3319
|
+
if (name === 'discard' || name === 'remove')
|
|
3320
|
+
return [{ t: 'none' }, this.mapDel(m, k, x, q, name === 'remove')];
|
|
3321
|
+
return refuse(x, `${x.text}: set.${name} (the subset reads add, discard, remove and in)`);
|
|
3322
|
+
});
|
|
3323
|
+
}
|
|
3269
3324
|
construct(rec, args, kw, x, p) {
|
|
3270
3325
|
const r = this.rec(rec, x);
|
|
3271
3326
|
// (a plain class of the repository whose __init__ the reader read: made by running it on a fresh object)
|
|
@@ -3313,6 +3368,9 @@ export class Stepper {
|
|
|
3313
3368
|
const [c, q] = this.truth(a0, p);
|
|
3314
3369
|
return [{ t: 'bool', e: c }, q];
|
|
3315
3370
|
}
|
|
3371
|
+
// (set(), dict(), list(): an empty collection, as {} and [] are, a collection only where a field declares its type)
|
|
3372
|
+
if ((n === 'set' || n === 'frozenset' || n === 'dict' || n === 'list') && !x.args.length && !x.kw.length)
|
|
3373
|
+
return [{ t: 'opaque', why: n === 'list' ? `${n}() [] (an empty list, a collection only where a field declares its type)` : `${n}() {} (an empty ${n === 'dict' ? 'dict' : 'set'}, a collection only where a field declares its type)` }, p];
|
|
3316
3374
|
return this.evArgs(x, p, (args, kw, q) => {
|
|
3317
3375
|
if (kw.length)
|
|
3318
3376
|
return refuse(x, `${x.text}: ${n} given keywords`);
|
|
@@ -4558,9 +4616,13 @@ function readOnce(mod, opts, g) {
|
|
|
4558
4616
|
continue;
|
|
4559
4617
|
}
|
|
4560
4618
|
const [v, a] = g.input(pa.name, pa.t, fn, p, 'param');
|
|
4619
|
+
// (an argument of no kind the rule holds, a dict of no stated types say: the constructor and the methods may
|
|
4620
|
+
// keep it, and are refused wherever the rule would read it, as a method's argument of that type is; the check
|
|
4621
|
+
// gives an inert one)
|
|
4561
4622
|
if (a.k === 'inert')
|
|
4562
|
-
|
|
4563
|
-
|
|
4623
|
+
g.notes.add(`${r.short}(${pa.name}): ${g.why(pa.t)}, read nowhere the rule keeps (the check gives an inert one)`);
|
|
4624
|
+
// (where the rule would read it, refused there, saying how: a store, or a default)
|
|
4625
|
+
give(pa, a.k === 'inert' && v.t === 'opaque' ? { ...v, why: `${v.why} (a constructor argument: state it as a store, or give it a default)` } : v);
|
|
4564
4626
|
ctor.push([pa.name, a]);
|
|
4565
4627
|
}
|
|
4566
4628
|
const [, p2] = g.callFunc(fn, { t: 'ref', id: 'this' }, args, kw, { e: 'call', p: fn.p, text: `${r.short}()` }, p, false);
|
|
@@ -4706,11 +4768,14 @@ function readOnce(mod, opts, g) {
|
|
|
4706
4768
|
g.notes.add(`${path.join('.')}: a list, read as its items in order (each item's place a key that only grows as items are added)`);
|
|
4707
4769
|
return;
|
|
4708
4770
|
}
|
|
4709
|
-
|
|
4771
|
+
// (a dict whose cells the rule can hold: keyed by integers or strings, of sets' keys, records, or numbers, booleans
|
|
4772
|
+
// and literals; another, of threading.Event say, is a field outside the subset, left out like any other)
|
|
4773
|
+
const cellable = (t) => (t.key.k === 'int' || t.key.k === 'str') && (!!t.set || t.val.k === 'rec' || (!!g.scalar(t.val) && g.scalar(t.val).k !== 'str'));
|
|
4774
|
+
if (v.t === 'opaque' && decl?.k === 'map' && /\{\}/.test(v.why) && !!decl.set === /^(set|frozenset)\(\)/.test(v.why) && cellable(decl)) {
|
|
4710
4775
|
const d = g.mapDeclOf(name, decl, at), id = `state:${path.join('.')}`;
|
|
4711
4776
|
const vt = decl.val;
|
|
4712
4777
|
heap.set(id, { k: 'map', decl: d, val: vt, origin: 'state' });
|
|
4713
|
-
leaves.push({ name: d.name, path, kind: 'map', key: d.key, ...(vt.k === 'rec' ? { cls: vt.name, fields: d.fields.map(x => ({ name: x.name, ...(g.mod.recs[vt.name].fields.find(y => y.name === x.name)?.t.k === 'float' ? { float: true } : {}), ...(x.sort.k === 'choice' ? { choice: true } : {}) })) } : vt.k === 'float' ? { float: true } : {}) });
|
|
4778
|
+
leaves.push({ name: d.name, path, kind: 'map', key: d.key, ...(decl.set ? { set: true } : {}), ...(vt.k === 'rec' ? { cls: vt.name, fields: d.fields.map(x => ({ name: x.name, ...(g.mod.recs[vt.name].fields.find(y => y.name === x.name)?.t.k === 'float' ? { float: true } : {}), ...(x.sort.k === 'choice' ? { choice: true } : {}) })) } : vt.k === 'float' ? { float: true } : {}) });
|
|
4714
4779
|
into.set(f, { t: 'ref', id });
|
|
4715
4780
|
return;
|
|
4716
4781
|
}
|
|
@@ -4744,7 +4809,8 @@ function readOnce(mod, opts, g) {
|
|
|
4744
4809
|
// --- the requests: each method (or function) one -------------------------------------------------------------------
|
|
4745
4810
|
const r = cls ? g.rec(cls, at) : undefined;
|
|
4746
4811
|
const chosen = cls
|
|
4747
|
-
|
|
4812
|
+
// (by default its public methods but the one it is made by, Rust's new, which takes no object)
|
|
4813
|
+
? (opts.methods ?? writing ?? Object.keys(r.methods).filter(m => !m.startsWith('_') && r.methods[m] && !(mod.lang === 'rust' && m === 'new'))).map(m => (r.methods[m] ? g.func(r.methods[m], at) : refuse(at, `no method ${r.short}.${m} in ${mod.file}`)))
|
|
4748
4814
|
: entries.map(e => g.func(e.id, at));
|
|
4749
4815
|
if (!chosen.length)
|
|
4750
4816
|
refuse(at, `${cls ? r.short : 'the entry'} has no methods to read`);
|
|
@@ -4784,6 +4850,15 @@ function readOnce(mod, opts, g) {
|
|
|
4784
4850
|
continue;
|
|
4785
4851
|
}
|
|
4786
4852
|
const [v, a] = g.input(nm, pa.t, fn, p);
|
|
4853
|
+
if (opts.keep?.includes(pa.name)) {
|
|
4854
|
+
const keepOf = (x) => { if (x.k === 'in')
|
|
4855
|
+
g.kept.add(x.name);
|
|
4856
|
+
else if (x.k === 'opt') {
|
|
4857
|
+
g.kept.add(x.none);
|
|
4858
|
+
keepOf(x.v);
|
|
4859
|
+
} };
|
|
4860
|
+
keepOf(a);
|
|
4861
|
+
}
|
|
4787
4862
|
if (at)
|
|
4788
4863
|
g.shared.set(`${ty} ${k}`, [v, a]);
|
|
4789
4864
|
args.push(v);
|
|
@@ -4905,7 +4980,18 @@ function readOnce(mod, opts, g) {
|
|
|
4905
4980
|
const pd = asked?.ask ? [...g.pend.values()].find(x => x.why === asked.why) : undefined;
|
|
4906
4981
|
if (asked?.ask && (pd?.ret?.k !== 'rec' || g.cuttable(asked.why)))
|
|
4907
4982
|
refuse(fn, `${fn.name} returns ${asked.why} (a result the rule keeps)`);
|
|
4908
|
-
|
|
4983
|
+
// (a string result that is one of the method's literals on every path, `return "adopt"` / `return "stop"`: a choice
|
|
4984
|
+
// of them, as a Literal result is; a string kept by cases is otherwise of two strings the rule holds)
|
|
4985
|
+
const strLits = (k) => (k.op === 'slit' ? [k.value] : k.op === 'kite' ? ((a, b) => (a && b ? [...new Set([...a, ...b])] : undefined))(strLits(k.a), strLits(k.b)) : undefined);
|
|
4986
|
+
const lits = out.t === 'str' && out.e.op === 'kite' ? strLits(out.e) : undefined;
|
|
4987
|
+
if (lits) {
|
|
4988
|
+
const l = asChoice(out.e, lits);
|
|
4989
|
+
f.out = { t: 'choice', e: l };
|
|
4990
|
+
g.notes.add(`${fn.name} returns ${lits.map(x => JSON.stringify(x)).join(' or ')}: kept as a choice of them`);
|
|
4991
|
+
}
|
|
4992
|
+
const out1 = f.out;
|
|
4993
|
+
if (out1.t === 'num' || out1.t === 'bool' || out1.t === 'str' || out1.t === 'choice' || out1.t === 'opt') {
|
|
4994
|
+
const out = out1;
|
|
4909
4995
|
const inner = out.t === 'opt' ? out.v : out;
|
|
4910
4996
|
if (inner.t === 'num' || inner.t === 'bool' || inner.t === 'str' || inner.t === 'choice') {
|
|
4911
4997
|
const sort = inner.t === 'num' ? { k: 'num' } : inner.t === 'bool' ? { k: 'bool' } : inner.t === 'str' ? { k: 'str' } : { k: 'choice', values: lvalues(inner.e) };
|
|
@@ -5044,7 +5130,7 @@ function readOnce(mod, opts, g) {
|
|
|
5044
5130
|
for (const fd of g.folds)
|
|
5045
5131
|
for (const t of [...Object.values(fd.init), ...Object.values(fd.step)])
|
|
5046
5132
|
mention(t.e);
|
|
5047
|
-
const unread = g.inputs.filter(v => !read.has(v.name) && v.name !== ev?.name);
|
|
5133
|
+
const unread = g.inputs.filter(v => !read.has(v.name) && v.name !== ev?.name && !g.kept.has(v.name));
|
|
5048
5134
|
if (unread.length)
|
|
5049
5135
|
g.notes.add(`read by the code but by no term of the rule (given their sort's zero, or None, by the check): ${unread.map(v => v.name).join(', ')}`);
|
|
5050
5136
|
const inputs = g.inputs.filter(v => !unread.includes(v));
|
|
@@ -5158,19 +5244,35 @@ export function iteTerm(c, a, b) {
|
|
|
5158
5244
|
const proc = globalThis.process;
|
|
5159
5245
|
export const node = (id) => { const m = proc?.getBuiltinModule?.(id); if (!m)
|
|
5160
5246
|
throw new Error(`the extractor runs the code's toolchain through ${id} (Node 20.16 or later, or Bun)`); return m; };
|
|
5247
|
+
// A file gdp-wired runs beside its modules (a front end's reader or harness, core/<lang>/...): its path, or a clear
|
|
5248
|
+
// error when the install lacks it.
|
|
5249
|
+
export function asset(rel) {
|
|
5250
|
+
const p = node('node:url').fileURLToPath(new URL(`./${rel}`, import.meta.url));
|
|
5251
|
+
if (!node('node:fs').existsSync(p))
|
|
5252
|
+
throw new Error(`gdp-wired's ${rel} is missing from its install (${p}): reinstall gdp-wired`);
|
|
5253
|
+
return p;
|
|
5254
|
+
}
|
|
5255
|
+
// A harness started on the two named pipes in `work` and both opened. It runs under sh, which, if the harness exits
|
|
5256
|
+
// before it answered (it couldn't start: a file missing, an interpreter absent, the code not loading), opens the
|
|
5257
|
+
// pipes itself and answers the first request with the error, so nothing here waits on a harness that is gone.
|
|
5258
|
+
const GUARD = 'i=$1 o=$2; shift 2; trap \'kill $p 2>/dev/null; exit 143\' TERM; "$@" "$i" "$o" & p=$!; wait $p; e=$?; [ "$e" = 0 ] && exit 0; trap - TERM; exec 3<"$i" 4>"$o"; read -r _ <&3; printf \'{"error": "the harness exited (status %s) before it answered"}\\n\' "$e" >&4';
|
|
5259
|
+
export function openHarness(work, cmd, args, o) {
|
|
5260
|
+
const fs = node('node:fs'), cp = node('node:child_process');
|
|
5261
|
+
cp.execFileSync('mkfifo', [`${work}/in`, `${work}/out`], {});
|
|
5262
|
+
const child = cp.spawn('sh', ['-c', GUARD, 'gdp-harness', `${work}/in`, `${work}/out`, cmd, ...args], o);
|
|
5263
|
+
const wi = fs.openSync(`${work}/in`, 'w'), ro = fs.openSync(`${work}/out`, 'r');
|
|
5264
|
+
return { child, wi, ro };
|
|
5265
|
+
}
|
|
5161
5266
|
export function checkStep(h, read, r, sorts, opts) {
|
|
5162
5267
|
const o = opts.check ?? {}, m = read.model, bound = o.bound ?? 12;
|
|
5163
|
-
const fs = node('node:fs'),
|
|
5268
|
+
const fs = node('node:fs'), os = node('node:os');
|
|
5164
5269
|
const work = fs.mkdtempSync(`${os.tmpdir()}/gdp-stepcheck-`);
|
|
5165
5270
|
let child, wi = -1, ro = -1;
|
|
5166
5271
|
const empty = { runs: 0, requests: 0, fromStates: 0, probes: { conditions: 0, witnesses: 0, steps: 0 }, refusedBoth: 0, outside: 0, edge: 0, compiledAgreed: 0, coverage: { arms: 0, hit: 0, missed: [] }, ms: 0, runMs: 0 };
|
|
5167
5272
|
try {
|
|
5168
5273
|
if (h.error)
|
|
5169
5274
|
return { ...empty, mismatch: h.error };
|
|
5170
|
-
|
|
5171
|
-
child = cp.spawn(h.cmd, [...h.args, `${work}/in`, `${work}/out`], { stdio: ['ignore', 'ignore', 'inherit'], env: { ...proc?.env, ...h.env } });
|
|
5172
|
-
wi = fs.openSync(`${work}/in`, 'w');
|
|
5173
|
-
ro = fs.openSync(`${work}/out`, 'r');
|
|
5275
|
+
({ child, wi, ro } = openHarness(work, h.cmd, h.args, { stdio: ['ignore', 'ignore', 'inherit'], env: { ...proc?.env, ...h.env } }));
|
|
5174
5276
|
const buf = new Uint8Array(1 << 20), dec = new TextDecoder();
|
|
5175
5277
|
let pend = '';
|
|
5176
5278
|
const line = () => {
|
|
@@ -5210,7 +5312,7 @@ export function checkStep(h, read, r, sorts, opts) {
|
|
|
5210
5312
|
};
|
|
5211
5313
|
const j = (x) => (typeof x === 'number' ? String(x) : x);
|
|
5212
5314
|
const snapJson = (s) => ({ ...Object.fromEntries(Object.entries(s.leaves).map(([k, v]) => [k, j(v)])), ...Object.fromEntries(Object.entries(s.maps).map(([k, cells]) => [k, Object.fromEntries(Object.entries(cells).map(([key, c]) => [key, Object.fromEntries(Object.entries(c).map(([f, x]) => [f, j(x)]))]))])) });
|
|
5213
|
-
const build = (a, inputs) => (a.k === 'in' ? { in: inputs[a.name] ?? a.z ?? 0, ...(a.float ? { float: true } : {}), ...(a.sym ? { sym: true } : {}) } : a.k === 'opt' ? (inputs[a.none] === true ? { none: true } : build(a.v, inputs)) : a.k === 'rec' ? (a.f.length ? { rec: a.cls, f: Object.fromEntries(a.f.map(([f, x]) => [f, build(x, inputs)])) } : { inert: true }) : a.k === 'inert' ? { inert: true, ...(a.dict ? { dict: true } : {}) } : a.k === 'store' ? { store: a.name }
|
|
5315
|
+
const build = (a, inputs) => (a.k === 'in' ? { in: inputs[a.name] ?? a.z ?? 0, ...(a.float ? { float: true } : {}), ...(a.sym ? { sym: true } : {}), ...(a.bytes ? { bytes: true } : {}) } : a.k === 'opt' ? (inputs[a.none] === true ? { none: true } : build(a.v, inputs)) : a.k === 'rec' ? (a.f.length ? { rec: a.cls, f: Object.fromEntries(a.f.map(([f, x]) => [f, build(x, inputs)])) } : { inert: true }) : a.k === 'inert' ? { inert: true, ...(a.dict ? { dict: true } : {}) } : a.k === 'store' ? { store: a.name }
|
|
5214
5316
|
: a.k === 'list' ? { list: (inputs[a.name] ?? []).map(it => build(a.item, it)) } : { dflt: true });
|
|
5215
5317
|
const ctorArgs = (params) => read.ctor.map(([n, a]) => [n, build(a, params)]);
|
|
5216
5318
|
let now = 0, inputsNow = {};
|
|
@@ -5235,6 +5337,8 @@ export function checkStep(h, read, r, sorts, opts) {
|
|
|
5235
5337
|
throw new Error(JSON.stringify(res.error)); return toSnap(res.state); },
|
|
5236
5338
|
call: (self, e, args) => {
|
|
5237
5339
|
const res = ask({ op: 'call', id: self, m: e.call, a: args, now, answers: answersOf(e.call) });
|
|
5340
|
+
if (res.outside !== undefined)
|
|
5341
|
+
return { ok: false, outside: true, error: res.outside };
|
|
5238
5342
|
if (res.frame)
|
|
5239
5343
|
throw new Error(`the code changes ${res.frame}, a field the rule leaves out`);
|
|
5240
5344
|
if (res.bad !== undefined)
|
|
@@ -5360,7 +5464,7 @@ export function extractStep(mod, h, opts) {
|
|
|
5360
5464
|
}
|
|
5361
5465
|
const unsigned = Object.fromEntries([...read.model.inputs, ...read.model.params].filter(v => read.ints[v.name] && !read.ints[v.name].signed).map(v => [v.name, 'nat']));
|
|
5362
5466
|
const x = fromModel(read.model, mod.file, { ...unsigned, ...opts.domains }, notes, (rule, sorts) => checkStep(h(read), read, rule, sorts, opts));
|
|
5363
|
-
return { ...x, read, names: stepNames(read) };
|
|
5467
|
+
return { ...x, read, names: stepNames(read), ...(mod.consts ? { consts: mod.consts } : {}) };
|
|
5364
5468
|
}
|
|
5365
5469
|
// The names of a reading: each leaf of the state by its path, the constructor's and each method's arguments (an object
|
|
5366
5470
|
// the caller gives by its fields), each answer by its callee's qualified name, each method's result, the failure.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Refusal, pathOf } from "./extract-read.js";
|
|
2
|
-
import { entryNames, extractStep, node, stubbed } from "./extract-step.js";
|
|
2
|
+
import { asset, entryNames, extractStep, node, stubbed } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
4
|
const env = () => globalThis.process?.env ?? {};
|
|
5
5
|
const errText = (e) => { const ls = `${e.stdout ?? ''}\n${e.stderr ?? ''}`.split('\n'); return (ls.filter(l => /\berror:/.test(l)).length ? ls.filter(l => /\berror:/.test(l)) : ls.filter(l => /error|fatal/i.test(l))).slice(0, 4).join(' | ').slice(0, 900) || String(e.message).slice(0, 300); };
|
|
@@ -10,7 +10,7 @@ const swiftOf = (o) => o.swift ?? env().GDP_SWIFT ?? 'swift';
|
|
|
10
10
|
// Else the reader's package, swift-syntax pinned, built by SwiftPM: minutes, once.
|
|
11
11
|
export function swiftReader(o = {}) {
|
|
12
12
|
const fs = node('node:fs'), cp = node('node:child_process'), os = node('node:os'), path = node('node:path');
|
|
13
|
-
const dir =
|
|
13
|
+
const dir = asset('swift/'), main = `${dir}Sources/gdp-swiftreader/main.swift`;
|
|
14
14
|
let version;
|
|
15
15
|
try {
|
|
16
16
|
version = cp.execFileSync(swiftOf(o), ['--version'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
@@ -130,7 +130,7 @@ export function extractSwift(where, opts = {}) {
|
|
|
130
130
|
}
|
|
131
131
|
// --- the harness: Swift beside the code, generated per reading ----------------------------------------------------------
|
|
132
132
|
// (its fixed parts, Swift files shipped beside the reader)
|
|
133
|
-
const resource = (f) => node('node:fs').readFileSync(
|
|
133
|
+
const resource = (f) => node('node:fs').readFileSync(asset(`swift/${f}`), 'utf8');
|
|
134
134
|
// The Swift name of an integer type, and of an answer's type.
|
|
135
135
|
const intName = (t) => { const x = t; return x.sw ?? (x.bits === 64 || !x.bits ? (x.signed === false ? 'UInt' : 'Int') : `${x.signed === false ? 'UInt' : 'Int'}${x.bits}`); };
|
|
136
136
|
function answerType(a, read) {
|
package/dist/core/extract.d.ts
CHANGED
|
@@ -36,6 +36,14 @@ export type Extraction = {
|
|
|
36
36
|
evidence?: Evidence;
|
|
37
37
|
notes: string[];
|
|
38
38
|
names?: Name[];
|
|
39
|
+
schedule?: unknown;
|
|
40
|
+
schedules?: unknown[];
|
|
41
|
+
fibers?: {
|
|
42
|
+
name: string;
|
|
43
|
+
steps: number;
|
|
44
|
+
base: number;
|
|
45
|
+
}[];
|
|
46
|
+
consts?: Record<string, number | string | boolean>;
|
|
39
47
|
};
|
|
40
48
|
export type Name = {
|
|
41
49
|
code: string;
|