gdp-wired 0.43.0 → 0.45.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 +8 -3
- package/dist/core/c/reader.js +22 -7
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +7 -0
- package/dist/core/cli.js +184 -12
- package/dist/core/counts.d.ts +1 -1
- package/dist/core/counts.js +30 -12
- package/dist/core/data.d.ts +6 -1
- package/dist/core/data.js +894 -152
- package/dist/core/dsl.d.ts +2 -0
- package/dist/core/dsl.js +88 -10
- package/dist/core/effect-prims.d.ts +60 -0
- package/dist/core/effect-prims.js +625 -0
- package/dist/core/effect.d.ts +17 -1
- package/dist/core/effect.js +108 -4
- package/dist/core/ex/harness.exs +2 -0
- package/dist/core/ex/reader.exs +17 -1
- package/dist/core/exists.d.ts +15 -1
- package/dist/core/exists.js +263 -41
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +22 -13
- package/dist/core/extract-check.d.ts +7 -0
- package/dist/core/extract-check.js +57 -4
- package/dist/core/extract-ex.js +5 -5
- package/dist/core/extract-go-check.js +22 -17
- package/dist/core/extract-go.d.ts +3 -0
- package/dist/core/extract-go.js +24 -9
- package/dist/core/extract-jvm.js +68 -16
- package/dist/core/extract-print.js +3 -0
- package/dist/core/extract-py.js +5 -5
- package/dist/core/extract-rb.js +5 -5
- package/dist/core/extract-read.d.ts +8 -0
- package/dist/core/extract-read.js +55 -0
- package/dist/core/extract-rs.js +28 -25
- package/dist/core/extract-shapes.js +20 -0
- package/dist/core/extract-sol.js +23 -12
- package/dist/core/extract-step.d.ts +59 -3
- package/dist/core/extract-step.js +334 -64
- package/dist/core/extract-swift.js +22 -15
- package/dist/core/extract.d.ts +1 -0
- package/dist/core/extract.js +27 -2
- package/dist/core/fresh.d.ts +2 -2
- package/dist/core/fresh.js +7 -3
- package/dist/core/go/reader.go +7 -1
- package/dist/core/infer.js +113 -40
- package/dist/core/jvm/Harness.java +8 -1
- package/dist/core/jvm/JavaReader.java +10 -2
- package/dist/core/jvm/Jvm.java +18 -2
- package/dist/core/jvm/KtReader.java +60 -5
- package/dist/core/machine.d.ts +2 -0
- package/dist/core/machine.js +32 -6
- package/dist/core/py/harness.py +128 -24
- package/dist/core/py/reader.py +50 -5
- package/dist/core/rb/reader.rb +52 -5
- package/dist/core/rs/src/main.rs +10 -0
- package/dist/core/sol/Replay.sol +52 -0
- package/dist/core/sol/harness.py +511 -0
- package/dist/core/solver.js +5 -4
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +274 -6
- package/dist/core/transfer.js +17 -0
- package/dist/core/watch.js +1 -1
- package/dist/interchange/check.d.ts +18 -1
- package/dist/interchange/check.js +19 -12
- package/dist/interchange/cli.d.ts +2 -0
- package/dist/interchange/cli.js +45 -0
- package/dist/interchange/format.d.ts +5 -1
- package/dist/interchange/format.js +25 -9
- package/dist/kernel/cdcl.js +65 -14
- package/dist/kernel/epr.js +35 -5
- package/dist/kernel/kernel.d.ts +2 -0
- package/dist/kernel/kernel.js +67 -40
- package/dist/kernel/prove.d.ts +22 -0
- package/dist/kernel/prove.js +156 -7
- package/dist/kernel/reader.js +3 -2
- package/dist/lean-kernel/emit.d.ts +9 -3
- package/dist/lean-kernel/emit.js +170 -29
- package/dist/lean-kernel/library.js +1 -1
- package/package.json +12 -3
package/dist/core/effect.d.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import type { Kind, Rule } from './dsl.js';
|
|
2
|
-
import { type Rand } from './machine.js';
|
|
2
|
+
import { type Law, type Rand } from './machine.js';
|
|
3
3
|
import { type Source } from './extract-read.js';
|
|
4
4
|
import { type ExtractOptions, type Extraction } from './extract.js';
|
|
5
5
|
import { type ScheduleRule } from './effect-schedule.js';
|
|
6
|
+
import { type Prim } from './effect-prims.js';
|
|
6
7
|
export { proveRule, proveSteps } from './dsl.js';
|
|
7
8
|
export { jitterRun, replaySchedule, scheduleConforms, stepper } from './effect-schedule.js';
|
|
9
|
+
export { primitiveConforms, primitiveLaws, primitiveRule } from './effect-prims.js';
|
|
8
10
|
type Mod = Record<string, any>;
|
|
9
11
|
export type EffectOptions = Omit<ExtractOptions, 'entry'> & {
|
|
10
12
|
entry?: string;
|
|
11
13
|
effect?: Mod;
|
|
12
14
|
modules?: Record<string, unknown>;
|
|
13
15
|
fibers?: boolean;
|
|
16
|
+
perFiber?: string[];
|
|
17
|
+
capacityParam?: boolean;
|
|
14
18
|
};
|
|
15
19
|
export type MethodSchedule = {
|
|
16
20
|
at: string;
|
|
@@ -32,6 +36,18 @@ export type Runner = {
|
|
|
32
36
|
};
|
|
33
37
|
export declare function runner(E: Mod): Runner;
|
|
34
38
|
export declare function extractEffect(at: Source, opts?: EffectOptions): Extraction;
|
|
39
|
+
export type Primitive = Prim & {
|
|
40
|
+
invariants: Law[];
|
|
41
|
+
laws: Law[];
|
|
42
|
+
lemmas?: Law[];
|
|
43
|
+
};
|
|
44
|
+
export declare function withLemmas(x: Extraction, opts?: {
|
|
45
|
+
ms?: number;
|
|
46
|
+
}): {
|
|
47
|
+
x: Extraction;
|
|
48
|
+
proven: string[];
|
|
49
|
+
unproven: string[];
|
|
50
|
+
};
|
|
35
51
|
export declare function fiberRun(x: Extraction, run: {
|
|
36
52
|
params: Record<string, number>;
|
|
37
53
|
trace: Record<string, unknown>[];
|
package/dist/core/effect.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// a Schema's kind.
|
|
17
17
|
import ts from 'typescript';
|
|
18
18
|
import * as dsl from "./dsl.js";
|
|
19
|
-
import { interpret, seeded } from "./machine.js";
|
|
19
|
+
import { interpret, lcg, seeded } from "./machine.js";
|
|
20
20
|
import { allowed } from "./watch.js";
|
|
21
21
|
import * as I from "./extract-ir.js";
|
|
22
22
|
import { Refusal, bare as strip, beside, impure, memberName, normalize, placed, refuse, shapeOf, sourceOf, text, where } from "./extract-read.js";
|
|
@@ -25,9 +25,14 @@ import { fromModel, namesOf } from "./extract.js";
|
|
|
25
25
|
import { check, sandbox } from "./extract-check.js";
|
|
26
26
|
import { Parts, readSchedule, replaySchedule, scheduleConforms, scheduleRule } from "./effect-schedule.js";
|
|
27
27
|
import { asRule, lift } from "./system.js";
|
|
28
|
+
import { rewritePrims } from "./effect-prims.js";
|
|
28
29
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
29
30
|
export { jitterRun, replaySchedule, scheduleConforms, stepper } from "./effect-schedule.js";
|
|
31
|
+
export { primitiveConforms, primitiveLaws, primitiveRule } from "./effect-prims.js";
|
|
30
32
|
const REFS = new Set(['Ref', 'SynchronizedRef', 'SubscriptionRef', 'TxRef', 'TRef']), MAKES = ['make', 'makeUnsafe', 'unsafeMake'];
|
|
33
|
+
// (Effect's RateLimiter: 3.x's gives its permits back on a fiber of its own, forked into the make effect's scope, on
|
|
34
|
+
// timers; 4.x's (effect/persistence) keeps its counters in a store every user of it shares)
|
|
35
|
+
const RATE = 'a RateLimiter (not modelled: 3.x\'s gives its permits back on timers of a fiber forked into the scope, 4.x\'s keeps its counters in a store shared by its every user): write the window in Refs read with Clock.currentTimeMillis, or a rule by hand beside it (conforms)';
|
|
31
36
|
const STM = (api) => `${api} (of STM: gen, commit, succeed, sync, void, fail, die, check and retry are read)`, MATCH = (x) => `${x}: a matcher (write the dispatch as a switch on _tag, or ifs)`;
|
|
32
37
|
// The Effect line the file is read for (4.x unless the project's effect is 3.x), and the policies its methods retry or
|
|
33
38
|
// repeat with, each read into its schedule's rule.
|
|
@@ -171,6 +176,8 @@ function factoryOf(s, entry) {
|
|
|
171
176
|
}
|
|
172
177
|
if (m === 'STM')
|
|
173
178
|
return refuse(d, STM(api));
|
|
179
|
+
if (m === 'RateLimiter' || /\bRateLimiter\b/.test(call.getText()))
|
|
180
|
+
return refuse(d, RATE);
|
|
174
181
|
if (m === 'Semaphore' || /^Effect\.(unsafeM|m)akeSemaphore$/.test(api)) {
|
|
175
182
|
const n = call.arguments[0];
|
|
176
183
|
if (!n || !ts.isNumericLiteral(n) || n.text !== '1')
|
|
@@ -266,6 +273,8 @@ function hook(s, refs, locks, effects) {
|
|
|
266
273
|
return [eff(q => (q.heap.has(SLEPT) ? refuse(e, 'the clock read after a repeat that waits (the time has moved on by its delays)') : ex.now(e, q))), p];
|
|
267
274
|
if (api?.startsWith('Clock.'))
|
|
268
275
|
return refuse(e, `${api} (Clock.currentTimeMillis is read, as an input)`);
|
|
276
|
+
if (!api && ['_tag', 'value'].includes(memberName(e.name)) && /^Option<|^(Some|None)</.test(s.checker.typeToString(s.checker.getTypeAtLocation(e.expression))))
|
|
277
|
+
return refuse(e, `${text(e)}: an Option's ${memberName(e.name)} (Option.isSome, isNone, getOrElse and getOrUndefined are read)`);
|
|
269
278
|
if (api && /^(Random|DateTime|Crypto|Console|Config|FileSystem)\./.test(api) && ts.isYieldExpression(e.parent))
|
|
270
279
|
return refuse(e, `${api}: an answer from outside the Refs read (Clock.currentTimeMillis is the one read, as an input)`);
|
|
271
280
|
return undefined;
|
|
@@ -363,6 +372,12 @@ function hook(s, refs, locks, effects) {
|
|
|
363
372
|
}
|
|
364
373
|
if (m === 'Match')
|
|
365
374
|
return refuse(e, MATCH(api));
|
|
375
|
+
if (m === 'Option')
|
|
376
|
+
return option(ex, e, op, p);
|
|
377
|
+
if (m === 'RateLimiter')
|
|
378
|
+
return refuse(e, RATE);
|
|
379
|
+
if (m === 'Queue')
|
|
380
|
+
return refuse(e, `${api}: a Queue other than one the service's make effect makes (yield* Queue.bounded(n), dropping, sliding, unbounded or make, read as its model)`);
|
|
366
381
|
if (m === 'TRef')
|
|
367
382
|
return refuse(e, `${api} (a TRef the service's make effect makes is read: get, set, update, modify and their variants)`);
|
|
368
383
|
if (m === 'Semaphore')
|
|
@@ -411,7 +426,7 @@ function hook(s, refs, locks, effects) {
|
|
|
411
426
|
found.push({ at: where(at), use, source: sched ? sched.getText() : `{times: ${times}}`, rule: sr });
|
|
412
427
|
// The policy run as Effect drives it, each attempt taking no time: how many times it goes on (for every input it
|
|
413
428
|
// may be fed, drawn), and how long it waits in all.
|
|
414
|
-
const g = sr.rule.compiled(), ps = sr.rule.encodeParams({}), rand = (() => { let x = 7; return (n) => (x = (x
|
|
429
|
+
const g = sr.rule.compiled(), ps = sr.rule.encodeParams({}), rand = (() => { let x = 7; return (n) => (x = lcg(x)) % Math.max(1, n); })();
|
|
415
430
|
const runOnce = (draw) => {
|
|
416
431
|
let st = g.init(ps), n = 0, waited = 0;
|
|
417
432
|
for (; n < 1000; n++) {
|
|
@@ -474,6 +489,31 @@ function hook(s, refs, locks, effects) {
|
|
|
474
489
|
delete ex.now;
|
|
475
490
|
}
|
|
476
491
|
}
|
|
492
|
+
// Option's constructors and reads, over a value that may be missing (Queue.poll's answer): some, none, isSome, isNone,
|
|
493
|
+
// getOrElse (of a default written here) and getOrUndefined.
|
|
494
|
+
function option(ex, e, op, p) {
|
|
495
|
+
const [a, b] = e.arguments, has = (v) => (v.t === 'opt' ? v.has : v.t === 'undef' ? I.F : I.T), n = e.arguments.length;
|
|
496
|
+
if (op === 'none' && !n)
|
|
497
|
+
return [{ t: 'undef' }, p];
|
|
498
|
+
if (op === 'some' && n === 1) {
|
|
499
|
+
const [v, q] = ex.ev(a, p);
|
|
500
|
+
return [{ t: 'opt', has: I.T, v }, q];
|
|
501
|
+
}
|
|
502
|
+
if ((op === 'isSome' || op === 'isNone') && n === 1) {
|
|
503
|
+
const [v, q] = ex.ev(a, p);
|
|
504
|
+
return [{ t: 'bool', e: op === 'isSome' ? has(v) : I.not(has(v)) }, q];
|
|
505
|
+
}
|
|
506
|
+
if (op === 'getOrUndefined' && n === 1)
|
|
507
|
+
return ex.ev(a, p);
|
|
508
|
+
if (op === 'getOrElse' && n === 2) {
|
|
509
|
+
const f = fnOf(s, b);
|
|
510
|
+
if (!f || f.parameters.length || ts.isBlock(f.body) || impure(f.body))
|
|
511
|
+
return refuse(b, 'Option.getOrElse of other than () => a value written here');
|
|
512
|
+
const [v, q] = ex.ev(a, p), [d, q2] = ex.ev(f.body, q);
|
|
513
|
+
return [v.t === 'opt' ? ex.phiV(v.has, v.v, d, e) : v.t === 'undef' ? d : v, q2];
|
|
514
|
+
}
|
|
515
|
+
return refuse(e, `Option.${op} (some, none, isSome, isNone, getOrElse and getOrUndefined are read)`);
|
|
516
|
+
}
|
|
477
517
|
// Ref.op(ref, ...): the ref a Ref the service made (by its name), its value the state's field.
|
|
478
518
|
function refOp(ex, e, m, op, p) {
|
|
479
519
|
const r = e.arguments[0] && strip(e.arguments[0]), base = op.replace(/Effect$/, ''), answer = ANSWERS[base], f = e.arguments[1];
|
|
@@ -574,6 +614,9 @@ export function extractEffect(at, opts = {}) {
|
|
|
574
614
|
if (sch)
|
|
575
615
|
return fromScheduleEntry(code, file, sch, E, opts);
|
|
576
616
|
const entry = opts.entry ?? serviceOf(code, file, opts);
|
|
617
|
+
const pr = modelled(code, file, entry, E, opts);
|
|
618
|
+
if (pr)
|
|
619
|
+
return pr;
|
|
577
620
|
if (opts.fibers !== false) {
|
|
578
621
|
const f = fibered(code, file, entry, E, opts);
|
|
579
622
|
if (f)
|
|
@@ -594,6 +637,64 @@ export function extractEffect(at, opts = {}) {
|
|
|
594
637
|
const schedules = found;
|
|
595
638
|
return { ...fromModel(model, file, opts.domains, [], (rule, sorts) => check(code, file, model, rule, sorts, { ...opts.check, modules, ...(opts.files ? { files: opts.files } : {}), ...(opts.domains ? { given: opts.domains } : {}) })), names: namesOf(model), ...(schedules.length ? { schedules } : {}) };
|
|
596
639
|
}
|
|
640
|
+
function modelled(code, file, entry, E, opts) {
|
|
641
|
+
if (!/\b(Queue|Semaphore|makeSemaphore|unsafeMakeSemaphore)\b/.test(code))
|
|
642
|
+
return undefined;
|
|
643
|
+
const s = setupOf(code, placed(file), {}, opts.files), w = rewritePrims(s, factoryOf(s, entry), x => apiOf(s, x), V4, { params: !!opts.capacityParam });
|
|
644
|
+
if (!w)
|
|
645
|
+
return undefined;
|
|
646
|
+
const x = extractEffect(w.code, { ...opts, capacityParam: false, file: normalize(placed(file)), entry, effect: E, perFiber: w.prims.flatMap(p => (p.kind === 'semaphore' ? [`${p.name}_held`] : [])) });
|
|
647
|
+
if (!x.ok || !x.rule)
|
|
648
|
+
return { ...x, notes: [...w.notes, ...x.notes] };
|
|
649
|
+
const r = x.rule;
|
|
650
|
+
// (a field's value: under fibers an integer is the machine's two naturals, x and x$neg)
|
|
651
|
+
const maps = new Set(Object.keys(x.rule.machine.maps ?? {}));
|
|
652
|
+
const val = (st, n) => (st[n] instanceof dsl.Int ? st[n] : `${n}$neg` in st ? new dsl.Int(st[n], st[`${n}$neg`]) : dsl.Int.of(st[n]));
|
|
653
|
+
const prims = w.prims.map(p => {
|
|
654
|
+
const f = (n) => `${p.name}_${n}`;
|
|
655
|
+
if (p.kind === 'queue')
|
|
656
|
+
return { ...p, laws: [], invariants: [r.law(p.capacity === undefined ? `${p.name} never gives more than it was given` : `${p.name} holds at most ${p.capacity} items`, st => {
|
|
657
|
+
const h = val(st, f('head')), t = val(st, f('tail'));
|
|
658
|
+
return p.capacity === undefined ? h.atMost(t) : h.atMost(t).and(t.atMost(h.plus(typeof p.capacity === 'number' ? p.capacity : val(st, p.capacity))));
|
|
659
|
+
})] };
|
|
660
|
+
const total = (st) => (typeof p.permits === 'number' ? p.permits : val(st, p.permits));
|
|
661
|
+
// (what the fibers hold sums to what is taken: one fiber's own, or under many fibers the sum of each's)
|
|
662
|
+
const held = (st) => (maps.has(f('held')) ? new dsl.Int(st[f('held')].sum(), maps.has(`${f('held')}$neg`) ? st[`${f('held')}$neg`].sum() : dsl.lit(0)) : val(st, f('held')));
|
|
663
|
+
// (under many fibers, the lemmas the use law rests on where each fiber gives back only what it took, withPermits':
|
|
664
|
+
// no fiber's own below nothing, and so not their sum)
|
|
665
|
+
const neg = `${f('held')}$neg`, lemmas = maps.has(neg) ? [r.law(`${p.name}: no fiber gives back more permits than it took`, st => dsl.forall(k => st[neg].at(k).eq(0))),
|
|
666
|
+
r.law(`${p.name}: what its fibers hold is never below nothing`, st => st[neg].sum().eq(0))] : [];
|
|
667
|
+
return { ...p, invariants: [r.law(`${p.name} never has more permits taken than ${typeof p.permits === 'number' ? `its ${p.permits}` : p.permits}`, st => val(st, f('taken')).atMost(total(st))), r.law(`${p.name}'s permits taken are those its fibers hold`, st => val(st, f('taken')).eq(held(st)))],
|
|
668
|
+
laws: [r.law(`${p.name} is never released past what was taken`, st => val(st, f('taken')).atLeast(0))], lemmas };
|
|
669
|
+
});
|
|
670
|
+
const lemmas = prims.flatMap(p => p.lemmas ?? []);
|
|
671
|
+
return { ...x, invariants: [...x.invariants ?? [], ...prims.flatMap(p => p.invariants)], notes: [...w.notes, ...x.notes], primitives: prims, ...(lemmas.length ? { lemmas } : {}) };
|
|
672
|
+
}
|
|
673
|
+
// The extraction with its lemmas (laws that hold where the code uses its primitives as they are meant to be, a
|
|
674
|
+
// semaphore's permits given back by the fiber that took them) proven first, each with the invariants and those proven
|
|
675
|
+
// before it: the proven ones, with what their search found, join the invariants every law is proven beside; the others
|
|
676
|
+
// are left out (a lemma is no claim: the laws stated are).
|
|
677
|
+
export function withLemmas(x, opts = {}) {
|
|
678
|
+
const lemmas = x.lemmas ?? [], inv = [...x.invariants ?? []], proven = [], unproven = [];
|
|
679
|
+
if (!x.rule)
|
|
680
|
+
return { x, proven, unproven };
|
|
681
|
+
for (const l of lemmas) {
|
|
682
|
+
let v;
|
|
683
|
+
try {
|
|
684
|
+
v = dsl.proveRule(x.rule, [...inv, l], { search: { ms: opts.ms ?? 30_000 } });
|
|
685
|
+
}
|
|
686
|
+
catch {
|
|
687
|
+
v = undefined;
|
|
688
|
+
}
|
|
689
|
+
if (v?.proven && v.checked) {
|
|
690
|
+
inv.push(l, ...(v.found?.laws ?? []).map(f => f.law));
|
|
691
|
+
proven.push(l.name);
|
|
692
|
+
}
|
|
693
|
+
else
|
|
694
|
+
unproven.push(l.name);
|
|
695
|
+
}
|
|
696
|
+
return { x: { ...x, invariants: inv }, proven, unproven };
|
|
697
|
+
}
|
|
597
698
|
// --- many fibers: a method that is several steps ---------------------------------------------------------------------
|
|
598
699
|
// A method's atomic units: the statements of its body that run an effect on the service's state (a transaction, a Ref
|
|
599
700
|
// operation, a helper's), each a step another fiber's may come between. A failure, a log, a sleep or a wait runs no
|
|
@@ -788,7 +889,7 @@ function fibered(code, file, entry, E, opts) {
|
|
|
788
889
|
return { ...one, notes: [`read as one fiber's steps (${split.map(mt => `${mt.name}: ${mt.units.length}`).join(', ')}), the service written again:`, out, ...one.notes] };
|
|
789
890
|
const m0 = one.rule.machine, model = one.model;
|
|
790
891
|
// (an integer is two naturals, x and x$neg)
|
|
791
|
-
const local = (n0) => { const n = n0.replace(/\$neg$/, ''); return made.has(n) || model.outputs.some(o => n === o || n.startsWith(`${o}_`)) || n === 'failed'; };
|
|
892
|
+
const local = (n0) => { const n = n0.replace(/\$neg$/, ''); return made.has(n) || !!opts.perFiber?.includes(n) || model.outputs.some(o => n === o || n.startsWith(`${o}_`)) || n === 'failed'; };
|
|
792
893
|
const shared = Object.keys(m0.state).filter(n => !local(n));
|
|
793
894
|
if (m0.inputs.includes('fiber'))
|
|
794
895
|
return { ok: false, refusals: [{ where: file, what: 'a method takes an argument named fiber (the name the fibers are told apart by)' }], notes: [] };
|
|
@@ -796,7 +897,10 @@ function fibered(code, file, entry, E, opts) {
|
|
|
796
897
|
const parts = one.rule.parts;
|
|
797
898
|
// (the kinds of the requests' choices kept; an integer is its two naturals, x and x$neg, as the machine has it)
|
|
798
899
|
const named = new Set([...lifted.params, ...lifted.inputs]), whole = ([n]) => named.has(n) && !named.has(`${n}$neg`);
|
|
799
|
-
|
|
900
|
+
// (and the shared integers' kinds: a law reads an integer of the service's as it does where the rule is one fiber's)
|
|
901
|
+
const one2 = one.rule;
|
|
902
|
+
const ints = [...one2.kindsOfState().filter(([n]) => shared.includes(n) && shared.includes(`${n}$neg`)), ...one2.kindsOfCells().filter(([n, k]) => k.vars(n).every(p => !local(p)))];
|
|
903
|
+
const rule = asRule({ ...lifted, name: `${m0.name}, every fiber` }, Object.fromEntries([...parts.params, ...parts.inputs].filter(whole).concat(ints)));
|
|
800
904
|
const names = (one.names ?? []).filter(n => !(n.role === 'state' && local(n.rule)) && n.role !== 'result' && !made.has(n.code));
|
|
801
905
|
const inv = (one.invariants ?? []).filter(l => ![...JSON.stringify(l.holds).matchAll(/"name":"([^"]*)"/g)].some(m => local(m[1])));
|
|
802
906
|
const steps = split.map((mt, mi) => ({ name: mt.name, steps: mt.units.length, base: (mi + 1) * 100 }));
|
package/dist/core/ex/harness.exs
CHANGED
|
@@ -60,6 +60,8 @@ defmodule GdpHarness do
|
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
def arg(%{"none" => true}), do: nil
|
|
63
|
+
# (a value the rule never reads: any value, nil)
|
|
64
|
+
def arg(%{"inert" => true}), do: nil
|
|
63
65
|
def state_of(st) do
|
|
64
66
|
for l <- s("leaves"), l["kind"] not in ["frame", "map"], into: %{} do
|
|
65
67
|
v = Map.get(st, String.to_atom(hd(l["path"])))
|
package/dist/core/ex/reader.exs
CHANGED
|
@@ -22,6 +22,7 @@ defmodule GdpReader do
|
|
|
22
22
|
base = Path.basename(file)
|
|
23
23
|
Process.put(:base, base)
|
|
24
24
|
mods = modules(ast, [])
|
|
25
|
+
Process.put(:mods, mods)
|
|
25
26
|
# (no name: the file's one module, or its one GenServer or Agent: the entry inferred)
|
|
26
27
|
name = req["module"] || (case Enum.filter(mods, fn {_, b} -> length(mods) == 1 or Enum.any?(b, &match?({:use, _, [{:__aliases__, _, [k]} | _]} when k in [:GenServer, :Agent], &1)) end) do [{n, _}] -> n; _ -> "" end)
|
|
27
28
|
case Enum.find(mods, fn {n, _} -> n == name end) || Enum.find(mods, fn {n, _} -> String.ends_with?(n, "." <> name) end) do
|
|
@@ -105,6 +106,8 @@ defmodule GdpReader do
|
|
|
105
106
|
_ -> {struct_fields(kw), struct_init(kw)}
|
|
106
107
|
end
|
|
107
108
|
end
|
|
109
|
+
# (a plain module's state is its struct: with no defstruct, none the check can make)
|
|
110
|
+
defp state_of(:pure, nil, _), do: {[], fn q -> fn_of("#{q}.__init__", "new", [], [%{"s" => "no", "p" => "#{Process.get(:base)}:1:1", "why" => "#{q}: a plain module with no struct (defstruct) for its state"}]) end}
|
|
108
111
|
defp state_of(_, kw, _), do: {struct_fields(kw), struct_init(kw)}
|
|
109
112
|
defp struct_fields(nil), do: []
|
|
110
113
|
defp struct_fields(kw), do: Enum.map(kw, fn {k, v} -> {k, v}; k -> {k, nil} end)
|
|
@@ -310,7 +313,7 @@ defmodule GdpReader do
|
|
|
310
313
|
def expr({:-, m, [a]}), do: %{"e" => "neg", "x" => expr(a), "p" => p(m)}
|
|
311
314
|
def expr({:/, m, _} = x), do: %{"e" => "no", "why" => "#{text(x)}: a float division (the subset reads trunc(a / k), div and rem)", "p" => p(m)}
|
|
312
315
|
def expr({:if, m, [c, kw]}), do: %{"e" => "ite", "c" => expr(c), "a" => expr(single(kw[:do], m)), "b" => expr(single(kw[:else], m)), "p" => p(m)}
|
|
313
|
-
def expr({:%{}, m, [{:|, _, [s, kv]}]}), do: upd(expr(s), kv, m)
|
|
316
|
+
def expr({:%{}, m, [{:|, _, [s, kv]}]}), do: upd(expr(s), kv, m) |> Map.put("strict", true)
|
|
314
317
|
def expr({:%, m, [_, {:%{}, _, kv}]}), do: struct_new(kv, m)
|
|
315
318
|
def expr({:%{}, m, _} = x), do: %{"e" => "no", "why" => "#{text(x)}: a map literal (a state is updated: %{s | f: v})", "p" => p(m)}
|
|
316
319
|
def expr({{:., m, [v, f]}, km, []}) when is_atom(f) and not is_tuple(elem(v, 0)) and is_list(km), do: (if km[:no_parens], do: get(expr(v), f, m), else: call_expr(v, f, [], m))
|
|
@@ -345,12 +348,25 @@ defmodule GdpReader do
|
|
|
345
348
|
key == [:Map] and f == :put and match?([_, k, _] when is_atom(k), args) -> upd(expr(Enum.at(args, 0)), [{Enum.at(args, 1), Enum.at(args, 2)}], m)
|
|
346
349
|
key == [:Map] and f == :merge and match?([_, {:%{}, _, _}], args) -> upd(expr(Enum.at(args, 0)), elem(Enum.at(args, 1), 2), m)
|
|
347
350
|
key == [:Map] and f == :get and match?([_, k] when is_atom(k), args) -> get(expr(Enum.at(args, 0)), Enum.at(args, 1), m)
|
|
351
|
+
# (a module of the file, all of whose functions the reader sees, that defines no f of this arity: an UndefinedFunctionError)
|
|
352
|
+
is_list(key) and undefined?(Enum.map_join(key, ".", &to_string/1), f, length(args)) -> %{"e" => "no", "why" => "#{text(x)}: #{text(mod)} defines no #{f}/#{length(args)} (an UndefinedFunctionError where it runs)", "raises" => true, "p" => p(m)}
|
|
348
353
|
# (another module's code: at the boundary where it is inferred; its arguments are values, which it can't change)
|
|
349
354
|
is_atom(mod) or is_tuple(mod) and elem(mod, 0) == :__aliases__ -> %{"e" => "no", "why" => "#{text(x)}: another module's code", "p" => p(m), "ext" => "#{text(mod)}.#{f}", "names" => [], "patch" => %{"mod" => text(mod), "path" => [to_string(f)]}}
|
|
350
355
|
true -> %{"e" => "no", "why" => "#{text(x)}: a call outside the subset", "p" => p(m)}
|
|
351
356
|
end
|
|
352
357
|
end
|
|
353
358
|
|
|
359
|
+
defp undefined?(name, f, n) do
|
|
360
|
+
case List.keyfind(Process.get(:mods) || [], name, 0) do
|
|
361
|
+
{_, body} ->
|
|
362
|
+
# (only a module of plain definitions: use, defdelegate, a macro may define functions the reader doesn't see)
|
|
363
|
+
closed = Enum.all?(body, &match?({k, _, _} when k in [:def, :defp, :@, :defstruct, :defmodule, :alias, :require, :import, :defmacrop], &1))
|
|
364
|
+
arities = for {:def, _, [head | _]} <- body, {^f, args, _} <- [head_of(head)], do: {Enum.count(args, &(not match?({:\\, _, _}, &1))), length(args)}
|
|
365
|
+
closed and f not in [:module_info, :__info__, :__struct__] and not Enum.any?(arities, fn {lo, hi} -> n in lo..hi//1 end)
|
|
366
|
+
nil -> false
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
|
|
354
370
|
# --- types, inferred from the defaults and what the module puts in each field --------------------------------------
|
|
355
371
|
defp infer(fields, body) do
|
|
356
372
|
puts = collect(body, %{})
|
package/dist/core/exists.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type C, type E, type Law, type Machine, type SomeWitness, type State } from './machine.js';
|
|
2
2
|
import { type Report } from '../kernel/prove.js';
|
|
3
|
+
import { type Ghosted } from '../kernel/kernel.js';
|
|
3
4
|
type Env = Record<string, number>;
|
|
4
5
|
type Group = string[];
|
|
5
6
|
export declare const namesOf: (t: E | C) => string[];
|
|
@@ -14,10 +15,22 @@ export declare function smallOf(m: Machine): {
|
|
|
14
15
|
}[];
|
|
15
16
|
export declare function trueSmall(m: Machine, laws: Law[], ghosted?: Machine): boolean;
|
|
16
17
|
export declare function holdsAt(m: Machine, law: Law, p: Env, st: State, b: number): boolean;
|
|
17
|
-
export declare function someHolds(body: C, vars: string[], env: Env, st: State, m: Machine): {
|
|
18
|
+
export declare function someHolds(body: C, vars: string[], env: Env, st: State, m: Machine, quick?: boolean): {
|
|
18
19
|
holds: boolean;
|
|
19
20
|
witness?: Env;
|
|
20
21
|
} | undefined;
|
|
22
|
+
export declare function skolemOf(m: Machine, laws: Law[]): {
|
|
23
|
+
ghost: (m2: Machine) => Machine;
|
|
24
|
+
laws: Law[];
|
|
25
|
+
ok: (m2: Machine) => boolean;
|
|
26
|
+
witnesses: Record<string, string>;
|
|
27
|
+
maps: Ghosted['maps'];
|
|
28
|
+
plains: Record<string, {
|
|
29
|
+
plain: Law;
|
|
30
|
+
sub: Record<string, E>;
|
|
31
|
+
}>;
|
|
32
|
+
cands: Law[];
|
|
33
|
+
} | undefined;
|
|
21
34
|
export type SomeReport = Report & {
|
|
22
35
|
laws?: Law[];
|
|
23
36
|
machine?: Machine;
|
|
@@ -30,6 +43,7 @@ export declare function proveSome(m: Machine, laws: Law[], opts?: {
|
|
|
30
43
|
whole?: (m: Machine, laws: Law[]) => Report & {
|
|
31
44
|
laws?: Law[];
|
|
32
45
|
};
|
|
46
|
+
mapMs?: number;
|
|
33
47
|
}): SomeReport;
|
|
34
48
|
export declare function showE(e: E): string;
|
|
35
49
|
export declare function showC(c: C): string;
|