gdp-wired 0.44.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/dist/core/c/reader.js +22 -7
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +1 -0
- package/dist/core/cli.js +136 -6
- 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.js +2 -2
- 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.js +19 -12
- package/dist/core/extract-check.d.ts +6 -0
- package/dist/core/extract-check.js +49 -3
- package/dist/core/extract-ex.js +3 -3
- package/dist/core/extract-go-check.js +19 -12
- package/dist/core/extract-go.js +20 -5
- package/dist/core/extract-jvm.js +63 -14
- package/dist/core/extract-print.js +3 -0
- package/dist/core/extract-py.js +3 -3
- package/dist/core/extract-rb.js +3 -3
- package/dist/core/extract-read.d.ts +8 -0
- package/dist/core/extract-read.js +55 -0
- package/dist/core/extract-rs.js +17 -19
- package/dist/core/extract-shapes.js +20 -0
- package/dist/core/extract-sol.js +19 -8
- package/dist/core/extract-step.d.ts +50 -3
- package/dist/core/extract-step.js +289 -58
- package/dist/core/extract-swift.js +20 -13
- 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 +115 -42
- package/dist/core/jvm/JavaReader.java +10 -2
- package/dist/core/jvm/Jvm.java +17 -1
- package/dist/core/jvm/KtReader.java +57 -5
- package/dist/core/machine.d.ts +1 -2
- package/dist/core/machine.js +27 -15
- package/dist/core/py/harness.py +77 -11
- 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/harness.py +6 -3
- package/dist/core/solver.js +5 -4
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +262 -3
- package/dist/core/transfer.js +17 -0
- package/dist/core/watch.js +1 -1
- package/dist/interchange/check.js +10 -10
- package/dist/interchange/format.d.ts +4 -0
- package/dist/interchange/format.js +13 -5
- package/dist/kernel/cdcl.js +33 -2
- 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/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 +2 -2
package/dist/core/dsl.d.ts
CHANGED
|
@@ -518,6 +518,7 @@ type Update<S extends Obj, M extends Obj> = Partial<{
|
|
|
518
518
|
}>;
|
|
519
519
|
type Spec = {
|
|
520
520
|
name: string;
|
|
521
|
+
ghost?: (m: Machine) => Machine;
|
|
521
522
|
params: [string, Kind<unknown>][];
|
|
522
523
|
inputs: [string, Kind<unknown>][];
|
|
523
524
|
state: [string, number | ((p: never) => TermLike)][];
|
|
@@ -672,6 +673,7 @@ export declare class Rule<P extends Obj = {}, I extends Obj = {}, S extends Obj
|
|
|
672
673
|
private whatIs;
|
|
673
674
|
private distinct;
|
|
674
675
|
get machine(): Machine;
|
|
676
|
+
withGhosts(ghost: (m: Machine) => Machine): this;
|
|
675
677
|
crossCheck(laws: Law[], stepLaws?: StepLaw[], opts?: {
|
|
676
678
|
trials?: number;
|
|
677
679
|
depth?: number;
|
package/dist/core/dsl.js
CHANGED
|
@@ -19,8 +19,8 @@ import { candidates, cone, searchCounted } from "./counts.js";
|
|
|
19
19
|
import { env as knobs } from "./solver.js";
|
|
20
20
|
import { argsKey, machineTerms, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, withArithmetic } from "./machine.js";
|
|
21
21
|
import { allowed, keysOf, requestEnv, watch, watchWork } from "./watch.js";
|
|
22
|
-
import { ghostOf, proveSome, someHolds, substVars, substVarsE } from "./exists.js";
|
|
23
|
-
import { check, checkRecur, foldObligations, loopObligations, substC, sumMachine } from "../kernel/kernel.js";
|
|
22
|
+
import { ghostOf, proveSome, skolemOf, someHolds, substVars, substVarsE } from "./exists.js";
|
|
23
|
+
import { check, checkRecur, foldObligations, ghostedMachine, loopObligations, someOfGhostsOk, substC, sumMachine } from "../kernel/kernel.js";
|
|
24
24
|
import { certLoop, clock, counted, factsFor, fullRate, grow, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withDeadline, withWall } from "../kernel/prove.js";
|
|
25
25
|
import { certCyclic, certOn, crossCyclic, cyclicOn, foldNodes, proveCyclic, quietly, recurNodes, translatedProof, uncovered } from "./cyclic.js";
|
|
26
26
|
import { discover } from "./discover.js";
|
|
@@ -2315,8 +2315,11 @@ export class Rule {
|
|
|
2315
2315
|
}
|
|
2316
2316
|
// (each sum a state variable from 0 the step never sets: sumMachine sets it, exact)
|
|
2317
2317
|
const sums = sumsIn(machineTerms(m), s.sumsRead ?? []);
|
|
2318
|
-
|
|
2318
|
+
const out = withArithmetic(sums ? { ...m, state: { ...m.state, ...Object.fromEntries(Object.keys(sums).map(n => [n, { op: 'const', value: 0 }])) }, sums } : m, [], s.arith ?? []);
|
|
2319
|
+
return s.ghost ? s.ghost(out) : out;
|
|
2319
2320
|
}
|
|
2321
|
+
// The same rule with ghosts its machine gains (the search's, over a law with "there exists" made plain: skolemOf).
|
|
2322
|
+
withGhosts(ghost) { return this.with({ ghost }); }
|
|
2320
2323
|
// --- the builders checked ------------------------------------------------------------------------------------------
|
|
2321
2324
|
// The builders against what they built, on concrete runs: random params and requests by their kinds (`pre` and
|
|
2322
2325
|
// `assume` met), and at every state each law's callback, each step law's, every flag and the step itself run again
|
|
@@ -2937,7 +2940,11 @@ export function proveRule(r, laws, opts = {}) {
|
|
|
2937
2940
|
// (with a search budget, the laws as given within it on the wall: a step goal of hundreds of hypotheses has a second
|
|
2938
2941
|
// each by its own budget, so the search would never start)
|
|
2939
2942
|
const ms = typeof opts.search === 'object' ? opts.search.ms : undefined, given = () => (opts.fast ? proveSetFast : proveLaws)(r.machine, withKinds(r, laws));
|
|
2940
|
-
|
|
2943
|
+
// (a law with "there exists" about every key: half of it, as the plain search over its ghosts takes the law too; one
|
|
2944
|
+
// step goal of no_lost_keys' laws as given took 57 s of 60 choosing a witness term)
|
|
2945
|
+
// (an eighth where such a law binds several names: proveSome gives a ghost map to one bound name alone)
|
|
2946
|
+
const share = laws.some(l => (l.some?.length ?? 0) > 1 && l.forall) ? 8 : laws.some(l => l.some?.length && l.forall) ? 2 : 1;
|
|
2947
|
+
const out = ms === undefined ? given() : withWall(performance.now() + ms / share, given);
|
|
2941
2948
|
const v = { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) };
|
|
2942
2949
|
return searched(r, laws, [], v, opts);
|
|
2943
2950
|
}
|
|
@@ -2998,6 +3005,16 @@ function searched(r, laws, stepLaws, v, opts) {
|
|
|
2998
3005
|
// (the search's end on the wall too: kernel/prove.ts's withWall, past which every goal is unknown)
|
|
2999
3006
|
return withWall(performance.now() + Math.max(0, until - clock()), () => searchedUntil(r, laws, stepLaws, v, opts, until));
|
|
3000
3007
|
}
|
|
3008
|
+
// Two machines alike up to the names of the keys their quantified flags and writes at every key bind (the rule builds
|
|
3009
|
+
// fresh ones each time it is read): each bound name by its place of first binding.
|
|
3010
|
+
const sameMachine = (a, b) => {
|
|
3011
|
+
const canon = (m) => {
|
|
3012
|
+
const t = JSON.stringify(m), bs = [...new Set([...t.matchAll(/"(?:each|key)":"([^"]+)"|"keys":\[([^\]]*)\]/g)].flatMap(x => (x[1] ? [x[1]] : [...x[2].matchAll(/"([^"]+)"/g)].map(y => y[1]))))];
|
|
3013
|
+
const at = new Map(bs.map((x, i) => [x, `$b${i}`]));
|
|
3014
|
+
return t.replace(/"(name|each|key)":"([^"]+)"/g, (all, f, x) => (at.has(x) ? `"${f}":"${at.get(x)}"` : all)).replace(/"keys":\[([^\]]*)\]/g, (_all, xs) => `"keys":[${xs.replace(/"([^"]+)"/g, (a2, x) => (at.has(x) ? `"${at.get(x)}"` : a2))}]`);
|
|
3015
|
+
};
|
|
3016
|
+
return canon(a) === canon(b);
|
|
3017
|
+
};
|
|
3001
3018
|
function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
3002
3019
|
const any = opts.from === 'any';
|
|
3003
3020
|
// Bounded runs (core/bmc.ts): a law broken k steps from the start, a model of the kernel's k-step goal, the run taken
|
|
@@ -3049,7 +3066,8 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3049
3066
|
const fm = rule.machine, share = (until - clock() - tail) / 10;
|
|
3050
3067
|
fresh = withDeadline(clock() + share, () => freshLaws(fm, rule.kindLaws(), { params: (rand, bound) => rule.randomParams(rand, bound), input: (rand, bound, ps) => rule.randomInput(rand, bound, ps) }, { ms: share }));
|
|
3051
3068
|
if (fresh.length) {
|
|
3052
|
-
|
|
3069
|
+
// (counted, as the laws' own search: the same verdict on any machine)
|
|
3070
|
+
const given = [...withKinds(rule, laws), ...fresh.map(f => f.law)], out = counted(fullRate, () => withDeadline(clock() + share, () => (stepLaws.length ? proveStepLaws(fm, given, stepLaws) : proveLaws(fm, given))), true);
|
|
3053
3071
|
if (out.proven && out.checked)
|
|
3054
3072
|
return { proven: true, checked: true, found: { laws: fresh, ...(lemmas ? { lemmas } : {}) }, assumes: reachableBy(fresh) };
|
|
3055
3073
|
}
|
|
@@ -3074,17 +3092,74 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3074
3092
|
}
|
|
3075
3093
|
// (the search's own wall ends where the tail begins: the last bounded runs keep it)
|
|
3076
3094
|
const tailAt = () => performance.now() + Math.max(0, until - tail - clock());
|
|
3077
|
-
|
|
3095
|
+
// (a law about every key with "there exists": the search over its plain form, the value at its ghost map's cell, the
|
|
3096
|
+
// ghosts' own laws beside it, on the rule with the ghosts (exists.ts's skolemOf), its verdict `back`'s; no join, whose
|
|
3097
|
+
// convex forms can't state a cell read at a key a ghost holds: the engine alone (the join's first whole-set query on
|
|
3098
|
+
// db_ae's plain laws took 234 counted s, past the budget, before the engine)
|
|
3099
|
+
const sk = !stepLaws.length && laws.some(l => l.some?.length && l.forall) ? skolemOf(rule.machine, laws) : undefined;
|
|
3100
|
+
const target = sk ? rule.withGhosts(sk.ghost) : rule, sought = sk?.laws ?? laws;
|
|
3101
|
+
// (the set the search proved, as it proved it, over the rule with the ghosts (its goals settled again where they stand),
|
|
3102
|
+
// the ghosts checked to be the original's (kernel.ts's ghostedOk): each law with "there exists" holds, its value at its
|
|
3103
|
+
// ghost map's cell (GhostMap.lean's forall_some_of_ghostmap); else proveSome's own proof of the laws as stated)
|
|
3104
|
+
// (the trees of the search's verdict are the ghosted machine's: no part of the ∃ verdict)
|
|
3105
|
+
const back = (over, found, fast = true) => {
|
|
3106
|
+
if (!sk)
|
|
3107
|
+
return {};
|
|
3108
|
+
// (a machine with sums or a history takes no ghost map (GhostMap.lean's SGhostedM is over SMachine): proveSome there)
|
|
3109
|
+
const ls = [...fresh.map(f => f.law), ...sought, ...found.map(f => f.law)], pm = over.withSumsOf(ls).machine;
|
|
3110
|
+
const plain = over === target && !pm.history && !Object.keys(pm.sums ?? {}).length ? proveRule(over, ls, { search: false, fast }) : undefined;
|
|
3111
|
+
// (the kernel's ∃ reading, GhostMap.lean's forall_some_of_ghostsubst: the plain laws proven of the original with all
|
|
3112
|
+
// the ghosts, each ∃ law's body with its witness term in place, the very law object proven (its keys with it: terra's
|
|
3113
|
+
// review, a law alike in name and body but about no key would prove less))
|
|
3114
|
+
const G = { orig: rule.machine, vars: {}, maps: sk.maps };
|
|
3115
|
+
if (knobs.GDP_EXISTS_LOG === '1')
|
|
3116
|
+
console.error(`exists: back: plain ${plain ? `${plain.proven} ${plain.checked}` : 'none'}, machine ${sameMachine(over.machine, ghostedMachine(G))}`);
|
|
3117
|
+
if (plain?.proven && plain.checked && sameMachine(over.machine, ghostedMachine(G))
|
|
3118
|
+
&& laws.filter(l => l.some?.length).every(l => { const q = sk.plains[l.name]; return !!q && ls.includes(q.plain) && someOfGhostsOk(G, l, q.plain, q.sub); }))
|
|
3119
|
+
return { proven: true, checked: true, witnesses: sk.witnesses };
|
|
3120
|
+
// (proveSome over the original: the found laws that read no ghost map)
|
|
3121
|
+
const own = found.filter(f => Object.keys(sk.maps).every(mp => !JSON.stringify(f.law.holds).includes(`"map":${JSON.stringify(mp)}`)));
|
|
3122
|
+
const out = proveSome(rule.machine, [...withKinds(rule, laws), ...fresh.map(f => f.law), ...own.map(f => f.law)], { mapMs: Math.max(5_000, (until - clock()) / 2) });
|
|
3123
|
+
return { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) };
|
|
3124
|
+
};
|
|
3125
|
+
// (the plain law's candidate supports, exists.ts's ghostSupports: Houdini within half of what is left, each with the
|
|
3126
|
+
// rest assumed, the failing dropped, until none fails; then the set through `back`, the ∃ verdict as the search's)
|
|
3127
|
+
if (sk?.cands.length) {
|
|
3128
|
+
const tm = target.machine, hUntil = clock() + (until - clock()) / 2;
|
|
3129
|
+
let keep = [...sk.cands];
|
|
3130
|
+
for (let round = 0; round < 8 && clock() < hUntil; round++) {
|
|
3131
|
+
const ls = withKinds(target, [...fresh.map(f => f.law), ...sought, ...keep]);
|
|
3132
|
+
const drop = keep.filter(c => clock() >= hUntil || !withDeadline(Math.min(hUntil, clock() + 3_000), () => proveLaw(tm, ls, ls.indexOf(c))).proven);
|
|
3133
|
+
if (clock() >= hUntil)
|
|
3134
|
+
break;
|
|
3135
|
+
if (knobs.GDP_EXISTS_LOG === '1')
|
|
3136
|
+
console.error(`exists: ghost supports round ${round}: ${keep.length} kept, ${drop.length} dropped: ${keep.map(c => c.name).join('; ').slice(0, 1500)}`);
|
|
3137
|
+
if (!drop.length) {
|
|
3138
|
+
const b = back(target, keep.map(law => ({ law })), false);
|
|
3139
|
+
if (knobs.GDP_EXISTS_LOG === '1')
|
|
3140
|
+
console.error(`exists: ghost supports set: ${b.proven ? 'proven' : `${b.goal} ${b.stuck} ${b.why ?? ''}`}`);
|
|
3141
|
+
if (b.proven && b.checked) {
|
|
3142
|
+
const found = keep.map(law => ({ law, text: law.name }));
|
|
3143
|
+
return { ...b, proven: true, checked: true, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
|
|
3144
|
+
}
|
|
3145
|
+
break;
|
|
3146
|
+
}
|
|
3147
|
+
keep = keep.filter(c => !drop.includes(c));
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
const inf = withWall(tailAt(), () => inferLaws(target, [...fresh.map(f => f.law), ...sought], stepLaws, { ms, ...((rule === r && !fresh.length) || sk ? { first: v } : {}), ...(sk ? { join: 0 } : {}) }));
|
|
3078
3151
|
if (!(inf.proven && inf.checked)) {
|
|
3079
3152
|
// The sum of each map the step writes (withMapSums): the search again over the rule with them, within half of what
|
|
3080
3153
|
// is left (at most 20 s), where a law of cells against a total needs one (no ERC20 balance past the supply).
|
|
3081
|
-
const summed =
|
|
3154
|
+
const summed = target.withMapSums();
|
|
3082
3155
|
if (summed && until - clock() - tail > 1000) {
|
|
3083
|
-
const inf2 = withWall(tailAt(), () => inferLaws(summed, [...fresh.map(f => f.law), ...
|
|
3156
|
+
const inf2 = withWall(tailAt(), () => inferLaws(summed, [...fresh.map(f => f.law), ...sought], stepLaws, { ms: Math.min(20_000, (until - clock() - tail) / 2) }));
|
|
3084
3157
|
if (inf2.proven && inf2.checked) {
|
|
3085
3158
|
const { found, stats: _s2, ...verdict } = inf2;
|
|
3086
3159
|
void _s2;
|
|
3087
|
-
|
|
3160
|
+
const b = back(summed, found);
|
|
3161
|
+
if (!sk || (b.proven && b.checked))
|
|
3162
|
+
return { ...(sk ? {} : verdict), ...b, proven: true, checked: true, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
|
|
3088
3163
|
}
|
|
3089
3164
|
}
|
|
3090
3165
|
// (a step law's ghost: at most 10 s of it, as its goals cost more than the laws')
|
|
@@ -3095,7 +3170,10 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3095
3170
|
}
|
|
3096
3171
|
const { found, stats: _stats, ...verdict } = inf;
|
|
3097
3172
|
void _stats;
|
|
3098
|
-
|
|
3173
|
+
const b = back(target, found);
|
|
3174
|
+
if (sk && !(b.proven && b.checked))
|
|
3175
|
+
return { ...v, ...b, why: [v.why, 'the set found over the ghost maps is not proven with the laws as stated'].filter(Boolean).join('; ') };
|
|
3176
|
+
return { ...(sk ? { proven: true, checked: true } : verdict), ...b, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
|
|
3099
3177
|
}
|
|
3100
3178
|
// A law with "there exists" about no key, which the join can't take as its goal: its witness core/exists.ts's ghostOf;
|
|
3101
3179
|
// then core/counts.ts's pipeline: the candidates, the engine's template two keys at the bound value's places, framed by
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// use (a semaphore never released past what was taken) as a law to prove of it.
|
|
19
19
|
import ts from 'typescript';
|
|
20
20
|
import * as dsl from "./dsl.js";
|
|
21
|
-
import { interpret,
|
|
21
|
+
import { interpret, seeded } from "./machine.js";
|
|
22
22
|
import { allowed } from "./watch.js";
|
|
23
23
|
import { bare as strip, memberName, refuse, text } from "./extract-read.js";
|
|
24
24
|
import { extractEffect } from "./effect.js";
|
|
@@ -500,7 +500,7 @@ export async function primitiveConforms(spec, effect, opts = {}) {
|
|
|
500
500
|
const E = effect, v4 = 'TxRef' in E, x = opts.x ?? primitiveRule(spec, E, opts.file ? { file: opts.file } : {});
|
|
501
501
|
if (!x.ok || !x.rule)
|
|
502
502
|
return { checked: 0, waited: 0, blocked: 0, interrupted: 0, failure: `the rule: ${x.refusals.map(f => f.what).join('; ')}` };
|
|
503
|
-
const r = x.rule, g = r.compiled(), interp = interpret(r.machine), rand =
|
|
503
|
+
const r = x.rule, g = r.compiled(), interp = interpret(r.machine), rand = seeded(opts.seed ?? 1);
|
|
504
504
|
const inputs = r.parts.inputs.map(([n]) => n).filter(n => n !== 'method');
|
|
505
505
|
const ops = spec.kind === 'queue' ? QUEUE_OPS(v4) : SEM_OPS;
|
|
506
506
|
const tick = () => new Promise(res => setTimeout(res, 0));
|
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;
|