gdp-wired 0.46.0 → 0.48.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 +18 -5
- package/dist/core/carry.d.ts +15 -0
- package/dist/core/carry.js +651 -0
- package/dist/core/cli.d.ts +4 -1
- package/dist/core/cli.js +31 -11
- package/dist/core/count-cases.d.ts +24 -0
- package/dist/core/count-cases.js +320 -0
- package/dist/core/count-cert-grow.d.ts +4 -0
- package/dist/core/count-cert-grow.js +37 -0
- package/dist/core/count-cert-transport.d.ts +3 -0
- package/dist/core/count-cert-transport.js +58 -0
- package/dist/core/count-completion.d.ts +9 -0
- package/dist/core/count-completion.js +27 -0
- package/dist/core/count-cubes.d.ts +8 -0
- package/dist/core/count-cubes.js +69 -0
- package/dist/core/count-demand.d.ts +37 -0
- package/dist/core/count-demand.js +361 -0
- package/dist/core/count-facts.d.ts +52 -0
- package/dist/core/count-facts.js +247 -0
- package/dist/core/count-focus-proof.d.ts +8 -0
- package/dist/core/count-focus-proof.js +140 -0
- package/dist/core/count-focused.d.ts +22 -0
- package/dist/core/count-focused.js +676 -0
- package/dist/core/count-ranges.d.ts +5 -0
- package/dist/core/count-ranges.js +65 -0
- package/dist/core/count-recovery/action-guard.d.ts +5 -0
- package/dist/core/count-recovery/action-guard.js +51 -0
- package/dist/core/count-recovery/boolean-core.d.ts +16 -0
- package/dist/core/count-recovery/boolean-core.js +258 -0
- package/dist/core/count-recovery/carried-case.d.ts +2 -0
- package/dist/core/count-recovery/carried-case.js +24 -0
- package/dist/core/count-recovery/conditional-check-cache.d.ts +23 -0
- package/dist/core/count-recovery/conditional-check-cache.js +130 -0
- package/dist/core/count-recovery/conditional-cuts.d.ts +6 -0
- package/dist/core/count-recovery/conditional-cuts.js +318 -0
- package/dist/core/count-recovery/conditional-proof.d.ts +19 -0
- package/dist/core/count-recovery/conditional-proof.js +306 -0
- package/dist/core/count-recovery/derivability-closure.d.ts +14 -0
- package/dist/core/count-recovery/derivability-closure.js +533 -0
- package/dist/core/count-recovery/empty-count-source.d.ts +2 -0
- package/dist/core/count-recovery/empty-count-source.js +40 -0
- package/dist/core/count-recovery/field-bound-lemmas.d.ts +23 -0
- package/dist/core/count-recovery/field-bound-lemmas.js +640 -0
- package/dist/core/count-recovery/field-case.d.ts +5 -0
- package/dist/core/count-recovery/field-case.js +89 -0
- package/dist/core/count-recovery/field-demand.d.ts +46 -0
- package/dist/core/count-recovery/field-demand.js +47 -0
- package/dist/core/count-recovery/field-only.d.ts +3 -0
- package/dist/core/count-recovery/field-only.js +18 -0
- package/dist/core/count-recovery/fold-path.d.ts +6 -0
- package/dist/core/count-recovery/fold-path.js +35 -0
- package/dist/core/count-recovery/frame-lemmas.d.ts +9 -0
- package/dist/core/count-recovery/frame-lemmas.js +120 -0
- package/dist/core/count-recovery/guard-cases.d.ts +12 -0
- package/dist/core/count-recovery/guard-cases.js +138 -0
- package/dist/core/count-recovery/key-closure.d.ts +14 -0
- package/dist/core/count-recovery/key-closure.js +62 -0
- package/dist/core/count-recovery/leaf-allowance.d.ts +4 -0
- package/dist/core/count-recovery/leaf-allowance.js +7 -0
- package/dist/core/count-recovery/lift-count-proxies.d.ts +6 -0
- package/dist/core/count-recovery/lift-count-proxies.js +175 -0
- package/dist/core/count-recovery/live-dependencies.d.ts +6 -0
- package/dist/core/count-recovery/live-dependencies.js +76 -0
- package/dist/core/count-recovery/member-inclusions.d.ts +11 -0
- package/dist/core/count-recovery/member-inclusions.js +168 -0
- package/dist/core/count-recovery/member-premises.d.ts +29 -0
- package/dist/core/count-recovery/member-premises.js +114 -0
- package/dist/core/count-recovery/natural-cases.d.ts +6 -0
- package/dist/core/count-recovery/natural-cases.js +59 -0
- package/dist/core/count-recovery/ops.d.ts +6 -0
- package/dist/core/count-recovery/ops.js +8 -0
- package/dist/core/count-recovery/pre-state-source.d.ts +8 -0
- package/dist/core/count-recovery/pre-state-source.js +18 -0
- package/dist/core/count-recovery/rebase-path.d.ts +9 -0
- package/dist/core/count-recovery/rebase-path.js +70 -0
- package/dist/core/count-recovery/rename-proof.d.ts +2 -0
- package/dist/core/count-recovery/rename-proof.js +102 -0
- package/dist/core/count-recovery/row-cases.d.ts +16 -0
- package/dist/core/count-recovery/row-cases.js +291 -0
- package/dist/core/count-recovery/scalar-guards.d.ts +7 -0
- package/dist/core/count-recovery/scalar-guards.js +291 -0
- package/dist/core/count-recovery/source-memo.d.ts +12 -0
- package/dist/core/count-recovery/source-memo.js +67 -0
- package/dist/core/count-select.d.ts +16 -0
- package/dist/core/count-select.js +24 -0
- package/dist/core/count-support.d.ts +598 -0
- package/dist/core/count-support.js +2080 -0
- package/dist/core/count-unions.d.ts +2 -0
- package/dist/core/count-unions.js +139 -0
- package/dist/core/count-witness-flags.d.ts +9 -0
- package/dist/core/count-witness-flags.js +37 -0
- package/dist/core/count-write-frames.d.ts +12 -0
- package/dist/core/count-write-frames.js +206 -0
- package/dist/core/counts.d.ts +20 -2
- package/dist/core/counts.js +807 -156
- package/dist/core/dsl.d.ts +50 -6
- package/dist/core/dsl.js +307 -65
- package/dist/core/effect-schema.d.ts +90 -0
- package/dist/core/effect-schema.js +500 -0
- package/dist/core/effect.d.ts +3 -7
- package/dist/core/effect.js +10 -65
- package/dist/core/exists.d.ts +1 -1
- package/dist/core/exists.js +80 -15
- package/dist/core/extract-check.d.ts +7 -1
- package/dist/core/extract-check.js +161 -19
- package/dist/core/extract-go-check.js +24 -4
- package/dist/core/extract-go.d.ts +7 -0
- package/dist/core/extract-go.js +29 -2
- package/dist/core/extract-read.d.ts +31 -9
- package/dist/core/extract-read.js +36 -11
- package/dist/core/extract-rs.js +58 -14
- package/dist/core/extract-shapes.d.ts +1 -0
- package/dist/core/extract-shapes.js +190 -27
- package/dist/core/extract-standalone.d.ts +3 -0
- package/dist/core/extract-standalone.js +265 -0
- package/dist/core/extract.d.ts +1 -0
- package/dist/core/extract.js +25 -5
- package/dist/core/field-laws.d.ts +2 -0
- package/dist/core/field-laws.js +100 -0
- package/dist/core/finite-frontiers.d.ts +5 -0
- package/dist/core/finite-frontiers.js +116 -0
- package/dist/core/finite-houdini.d.ts +52 -0
- package/dist/core/finite-houdini.js +460 -0
- package/dist/core/finite-model.d.ts +13 -0
- package/dist/core/finite-model.js +68 -0
- package/dist/core/finite-tiny.d.ts +72 -0
- package/dist/core/finite-tiny.js +1052 -0
- package/dist/core/infer.d.ts +1 -1
- package/dist/core/infer.js +32 -9
- package/dist/core/laws.d.ts +2 -1
- package/dist/core/laws.js +76 -19
- package/dist/core/lemma-cuts.d.ts +38 -0
- package/dist/core/lemma-cuts.js +365 -0
- package/dist/core/machine.d.ts +39 -2
- package/dist/core/machine.js +240 -35
- package/dist/core/mutate.d.ts +55 -0
- package/dist/core/mutate.js +210 -0
- package/dist/core/native-domain.d.ts +6 -0
- package/dist/core/native-domain.js +114 -0
- package/dist/core/native-law.d.ts +3 -0
- package/dist/core/native-law.js +174 -0
- package/dist/core/quorum-laws.d.ts +5 -0
- package/dist/core/quorum-laws.js +239 -0
- package/dist/core/relational.js +10 -2
- package/dist/core/relevance.d.ts +4 -0
- package/dist/core/relevance.js +79 -0
- package/dist/core/rs/Cargo.toml +1 -1
- package/dist/core/rs/src/main.rs +458 -9
- package/dist/core/runtime-wall.d.ts +3 -0
- package/dist/core/runtime-wall.js +4 -0
- package/dist/core/sample-step.d.ts +16 -0
- package/dist/core/sample-step.js +28 -0
- package/dist/core/source-check.d.ts +44 -0
- package/dist/core/source-check.js +126 -0
- package/dist/core/source-diagnostic.d.ts +1 -0
- package/dist/core/source-diagnostic.js +34 -0
- package/dist/core/support-budget.d.ts +2 -0
- package/dist/core/support-budget.js +6 -0
- package/dist/core/system.js +2 -0
- package/dist/core/wall.d.ts +6 -0
- package/dist/core/wall.js +23 -0
- package/dist/core/watch.js +4 -0
- package/dist/kernel/cdcl.d.ts +4 -0
- package/dist/kernel/cdcl.js +20 -5
- package/dist/kernel/kernel.d.ts +10 -0
- package/dist/kernel/kernel.js +56 -3
- package/dist/kernel/model-sequence.d.ts +2 -2
- package/dist/kernel/model-sequence.js +4 -3
- package/dist/kernel/model-values.d.ts +2 -0
- package/dist/kernel/model-values.js +60 -0
- package/dist/kernel/prove.d.ts +10 -0
- package/dist/kernel/prove.js +56 -8
- package/dist/kernel/prover-rows.d.ts +29 -0
- package/dist/kernel/prover-rows.js +114 -0
- package/dist/lean-kernel/emit.d.ts +39 -2
- package/dist/lean-kernel/emit.js +136 -24
- package/dist/lean-kernel/lean-terms.d.ts +1 -0
- package/dist/lean-kernel/lean-terms.js +13 -5
- package/dist/lean-kernel/library.js +4 -0
- package/dist/lean-kernel/qalpha.d.ts +7 -0
- package/dist/lean-kernel/qalpha.js +40 -0
- package/package.json +5 -1
|
@@ -86,6 +86,7 @@ export type GX = {
|
|
|
86
86
|
v: GX;
|
|
87
87
|
}[];
|
|
88
88
|
i?: GX;
|
|
89
|
+
end?: string;
|
|
89
90
|
};
|
|
90
91
|
export type GS = {
|
|
91
92
|
s: string;
|
|
@@ -191,7 +192,13 @@ export type GoOptions = {
|
|
|
191
192
|
answers?: Record<string, string>;
|
|
192
193
|
skip?: string[];
|
|
193
194
|
};
|
|
195
|
+
export type GoClock = {
|
|
196
|
+
p: string;
|
|
197
|
+
end: string;
|
|
198
|
+
callee: string;
|
|
199
|
+
};
|
|
194
200
|
export type GoRead = {
|
|
201
|
+
clocks?: GoClock[];
|
|
195
202
|
answers?: (Answer & {
|
|
196
203
|
range?: [number, number];
|
|
197
204
|
})[];
|
package/dist/core/extract-go.js
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
//
|
|
10
10
|
// The subset: a named struct of the package and the methods given (pointer or value receivers), the object starting
|
|
11
11
|
// at Go's zero value; fields of integer types (every width, signed and unsigned, named ones such as time.Duration),
|
|
12
|
-
// bool, string,
|
|
12
|
+
// bool, string, direct time.Now().UnixMilli()/Unix() projections (one millisecond request tick; the check replaces
|
|
13
|
+
// only Now, not the native projection), *big.Int (an unbounded integer, nil a state of its own), nested structs, maps from
|
|
13
14
|
// integers or strings to integers, booleans or structs of them, and slices of integers or booleans as lists; locals,
|
|
14
15
|
// assignments (=, :=, op=, ++, --, tuples), if, switch (with a tag or without, fallthrough, break), early returns,
|
|
15
16
|
// calls of the package's functions and methods (inlined), pointers to the state's objects (an interior pointer &x.f
|
|
@@ -47,6 +48,7 @@ class Go {
|
|
|
47
48
|
opts;
|
|
48
49
|
g;
|
|
49
50
|
leaves = [];
|
|
51
|
+
clocks = new Map();
|
|
50
52
|
funcs = {};
|
|
51
53
|
constructor(pkg, opts, inf) {
|
|
52
54
|
this.pkg = pkg;
|
|
@@ -283,6 +285,17 @@ class Go {
|
|
|
283
285
|
if (f.e === 'sel' && f.k === 'qual')
|
|
284
286
|
return this.std(x);
|
|
285
287
|
if (f.e === 'sel' && f.k === 'method') {
|
|
288
|
+
// Keep Time opaque: only a direct Now projection is a scalar. Preserve
|
|
289
|
+
// the native projection in the check; substitute just its clock source.
|
|
290
|
+
const now = f.x;
|
|
291
|
+
if ((!this.pkg.lang || this.pkg.lang === 'go') && f.mpkg === 'time' && (f.n === 'Unix' || f.n === 'UnixMilli') && !a.length &&
|
|
292
|
+
now?.e === 'call' && !now.a?.length && now.f?.e === 'sel' && now.f.k === 'qual' && now.f.pkg === 'time' && now.f.n === 'Now') {
|
|
293
|
+
if (!now.end)
|
|
294
|
+
return this.no(x, 'time.Now(): the reader did not provide a clock source span');
|
|
295
|
+
this.clocks.set(now.p, { p: now.p, end: now.end, callee: now.f.text });
|
|
296
|
+
const clock = { e: 'clock', ...at };
|
|
297
|
+
return f.n === 'UnixMilli' ? clock : { e: 'bin', ...at, op: '//', x: clock, y: { e: 'int', p: x.p, v: 1000 } };
|
|
298
|
+
}
|
|
286
299
|
// A method promoted from an embedded field: its receiver is that field (through the embedded fields on the way).
|
|
287
300
|
let rt = this.T(f.x.t), base = rt.k === 'ptr' ? rt.elem : f.x.t, emb;
|
|
288
301
|
if ((f.path ?? []).length > 1) {
|
|
@@ -868,6 +881,18 @@ function readGo1(pkg, o, go) {
|
|
|
868
881
|
if (answers.length)
|
|
869
882
|
for (const e of events)
|
|
870
883
|
e.args.push({ k: 'rec', fields: answers.flatMap(a => [a.inputs.name, ...(a.inputs.none ? [a.inputs.none] : [])]).map(n => [n, { k: 'input', name: n }]) });
|
|
884
|
+
// An answered outer call must not swallow a clock substitution or reuse its offsets.
|
|
885
|
+
for (const clock of go.clocks.values())
|
|
886
|
+
for (const answer of answers)
|
|
887
|
+
for (const site of answer.at ?? []) {
|
|
888
|
+
const c = /^(.*):(\d+):(\d+)$/.exec(clock.p), a = /^(.*):(\d+):(\d+)$/.exec(site.p);
|
|
889
|
+
if (!c || !a || c[1] !== a[1] || !site.end)
|
|
890
|
+
continue;
|
|
891
|
+
const cs = c.slice(2).map(Number), as = a.slice(2).map(Number), ce = clock.end.split(':').map(Number), ae = site.end.split(':').map(Number);
|
|
892
|
+
const before = (x, y) => x[0] < y[0] || (x[0] === y[0] && x[1] < y[1]);
|
|
893
|
+
if (before(cs, ae) && before(as, ce))
|
|
894
|
+
refuse(clock.p, 'a clock read inside an answered call (overlapping source substitutions)');
|
|
895
|
+
}
|
|
871
896
|
// (and the harness's: it makes the struct with the fields read)
|
|
872
897
|
for (const mt of methods)
|
|
873
898
|
mt.params = mt.params.map(pa => ({ ...pa, arg: recOf(pa.arg) }));
|
|
@@ -977,6 +1002,8 @@ function readGo1(pkg, o, go) {
|
|
|
977
1002
|
for (const d of maps)
|
|
978
1003
|
laws.push(`r.law(${JSON.stringify(`${d.name}: a nil map holds no key`)}, ({${d.name}, ${d.name}_nil}) => forall(k => any(${d.name}_nil.not(), ${d.name}.at(k).has.not())))`);
|
|
979
1004
|
const layout = { k: 'rec', fields: state.filter(v => !outputs.includes(v.name)).map(v => [v.name, { k: 'scalar', name: v.name }]) };
|
|
1005
|
+
if (g.now)
|
|
1006
|
+
g.notes.add('Go wall clock: UnixMilli and Unix projections use one millisecond request tick; multiple reads assume the step stays within that tick. General time.Time values and finer projections remain outside the subset.');
|
|
980
1007
|
const model = {
|
|
981
1008
|
name: opts.entry, shape: 'class', file: pkg.files[0]?.name ?? 'go', entry: opts.entry,
|
|
982
1009
|
params: cparams, inputs: g.inputs, state, maps, init, writes, mapWrites, outputs, ...(lists.length ? { lists, listWrites } : {}),
|
|
@@ -985,7 +1012,7 @@ function readGo1(pkg, o, go) {
|
|
|
985
1012
|
// Unsigned inputs are naturals (the input's kind); a state variable's sort is the printer's to decide (a natural where
|
|
986
1013
|
// every write is proven one: a wrap by cases may not be, though it stays within the type, which its law says).
|
|
987
1014
|
const unsigned = [...g.ints].filter(([n, ty]) => { const [lo, hi] = rangeOf(ty); return lo === 0 && hi > 0 && (g.inputs.some(v => v.name === n) || cparams.some(v => v.name === n)); }).map(([n]) => n);
|
|
988
|
-
return { ...(pkg.ctor ? { ctor: ctorArgs } : {}), ...(g.leftOut.size ? { leftOut: [...g.leftOut] } : {}), model, edges: g.edges, unsigned, leaves: go.leaves.filter(l => l.kind === 'frame' || state.some(v => v.name === l.name) || maps.some(d => d.name === l.name) || lists.some(d => d.name === l.name)), spans: [...g.spans.values()], entry: opts.entry, methods, ...(answers.length ? { answers } : {}) };
|
|
1015
|
+
return { ...(g.now ? { clocks: [...go.clocks.values()] } : {}), ...(pkg.ctor ? { ctor: ctorArgs } : {}), ...(g.leftOut.size ? { leftOut: [...g.leftOut] } : {}), model, edges: g.edges, unsigned, leaves: go.leaves.filter(l => l.kind === 'frame' || state.some(v => v.name === l.name) || maps.some(d => d.name === l.name) || lists.some(d => d.name === l.name)), spans: [...g.spans.values()], entry: opts.entry, methods, ...(answers.length ? { answers } : {}) };
|
|
989
1016
|
}
|
|
990
1017
|
function termOf(v, at) {
|
|
991
1018
|
// (none: a path that ends without the value, which a reader of malformed source may join in)
|
|
@@ -90,9 +90,30 @@ export type Term = {
|
|
|
90
90
|
s: 'str';
|
|
91
91
|
e: K;
|
|
92
92
|
};
|
|
93
|
+
export type LazyRoot = readonly [scope: string, argument: number];
|
|
94
|
+
export type LazyField = {
|
|
95
|
+
prefix: string;
|
|
96
|
+
root?: LazyRoot;
|
|
97
|
+
field: string;
|
|
98
|
+
};
|
|
99
|
+
export declare const lazyKey: (record: {
|
|
100
|
+
prefix: string;
|
|
101
|
+
root?: LazyRoot;
|
|
102
|
+
}, field: string) => string;
|
|
103
|
+
export declare const sameLazyRoot: (a: {
|
|
104
|
+
prefix: string;
|
|
105
|
+
root?: LazyRoot;
|
|
106
|
+
} | undefined, b: {
|
|
107
|
+
prefix: string;
|
|
108
|
+
root?: LazyRoot;
|
|
109
|
+
}) => boolean;
|
|
93
110
|
export type Arg = {
|
|
94
111
|
k: 'input';
|
|
95
112
|
name: string;
|
|
113
|
+
} | {
|
|
114
|
+
k: 'maybe-bool';
|
|
115
|
+
name: string;
|
|
116
|
+
missing: string;
|
|
96
117
|
} | {
|
|
97
118
|
k: 'lit';
|
|
98
119
|
value: string;
|
|
@@ -104,6 +125,7 @@ export type Arg = {
|
|
|
104
125
|
} | {
|
|
105
126
|
k: 'lazy';
|
|
106
127
|
prefix: string;
|
|
128
|
+
root?: LazyRoot;
|
|
107
129
|
};
|
|
108
130
|
export type Event = {
|
|
109
131
|
select: Record<string, string>;
|
|
@@ -150,6 +172,9 @@ export type Model = {
|
|
|
150
172
|
shape: 'reducer' | 'functions' | 'class';
|
|
151
173
|
file: string;
|
|
152
174
|
entry: string;
|
|
175
|
+
standalone?: true;
|
|
176
|
+
standaloneDomains?: Record<string, number[]>;
|
|
177
|
+
standaloneBindings?: string[];
|
|
153
178
|
params: Var[];
|
|
154
179
|
inputs: Var[];
|
|
155
180
|
state: Var[];
|
|
@@ -168,10 +193,7 @@ export type Model = {
|
|
|
168
193
|
notes: string[];
|
|
169
194
|
hints: WeakMap<object, string>;
|
|
170
195
|
ctorArgs?: string[];
|
|
171
|
-
lazy?: Map<string,
|
|
172
|
-
prefix: string;
|
|
173
|
-
field: string;
|
|
174
|
-
}>;
|
|
196
|
+
lazy?: Map<string, LazyField>;
|
|
175
197
|
initSource?: string;
|
|
176
198
|
spans?: [number, number][];
|
|
177
199
|
factory?: {
|
|
@@ -279,6 +301,7 @@ type Rec = {
|
|
|
279
301
|
origin: 'fresh' | 'input' | 'this' | 'shared';
|
|
280
302
|
lazy?: {
|
|
281
303
|
prefix: string;
|
|
304
|
+
root?: LazyRoot;
|
|
282
305
|
};
|
|
283
306
|
};
|
|
284
307
|
type MapObj = {
|
|
@@ -372,10 +395,8 @@ export type Setup = {
|
|
|
372
395
|
nowRole: 'input' | 'param';
|
|
373
396
|
hints: WeakMap<object, string>;
|
|
374
397
|
notes: Set<string>;
|
|
375
|
-
lazy: Map<string,
|
|
376
|
-
|
|
377
|
-
field: string;
|
|
378
|
-
}>;
|
|
398
|
+
lazy: Map<string, LazyField>;
|
|
399
|
+
lazySelections?: Set<string>;
|
|
379
400
|
ctor?: boolean;
|
|
380
401
|
ours: (sf: ts.SourceFile) => boolean;
|
|
381
402
|
spans?: [number, number][];
|
|
@@ -398,12 +419,13 @@ export type Setup = {
|
|
|
398
419
|
};
|
|
399
420
|
export declare class Exec {
|
|
400
421
|
readonly s: Setup;
|
|
422
|
+
private readonly standalone;
|
|
401
423
|
throws: {
|
|
402
424
|
pc: B[];
|
|
403
425
|
}[];
|
|
404
426
|
private depth;
|
|
405
427
|
private ids;
|
|
406
|
-
constructor(s: Setup);
|
|
428
|
+
constructor(s: Setup, standalone?: boolean);
|
|
407
429
|
fresh(base: string): string;
|
|
408
430
|
newVar(base: string, sort: Sort, role: Var['role'], note?: string): Var;
|
|
409
431
|
id(prefix: string): string;
|
|
@@ -26,6 +26,13 @@ export class Retype extends Error {
|
|
|
26
26
|
this.sort = sort;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
export const lazyKey = (record, field) => JSON.stringify([record.root ?? [record.prefix, 0], [field]]);
|
|
30
|
+
export const sameLazyRoot = (a, b) => {
|
|
31
|
+
if (!a)
|
|
32
|
+
return false;
|
|
33
|
+
const x = a.root ?? [a.prefix, 0], y = b.root ?? [b.prefix, 0];
|
|
34
|
+
return x[0] === y[0] && x[1] === y[1];
|
|
35
|
+
};
|
|
29
36
|
export const unparen = (x) => (ts.isParenthesizedExpression(x) ? unparen(x.expression) : x);
|
|
30
37
|
// An expression without its parentheses, casts and `!` (what it is, as the front ends read it).
|
|
31
38
|
export const bare = (x) => (ts.isParenthesizedExpression(x) || ts.isAsExpression(x) || ts.isSatisfiesExpression(x) || ts.isNonNullExpression(x) ? bare(x.expression) : x);
|
|
@@ -208,11 +215,13 @@ export function shapeOf(t, checker, at, inner) {
|
|
|
208
215
|
const keySort = (s, at) => (s.k === 'num' ? 'num' : s.k === 'str' || s.k === 'choice' ? 'str' : refuse(at, 'a map keyed by other than numbers or strings'));
|
|
209
216
|
export class Exec {
|
|
210
217
|
s;
|
|
218
|
+
standalone;
|
|
211
219
|
throws = [];
|
|
212
220
|
depth = 0;
|
|
213
221
|
ids = 0;
|
|
214
|
-
constructor(s) {
|
|
222
|
+
constructor(s, standalone = false) {
|
|
215
223
|
this.s = s;
|
|
224
|
+
this.standalone = standalone;
|
|
216
225
|
}
|
|
217
226
|
fresh(base) {
|
|
218
227
|
const clean = base.replace(/^#/, '').replace(/[^A-Za-z0-9_]/g, '_').replace(/^(\d)/, '_$1') || 'x';
|
|
@@ -390,8 +399,11 @@ export class Exec {
|
|
|
390
399
|
return { has: { op: 'cell', map: m.name, key, field: 'has' }, vals: new Map(m.fields.map(f => [f.name, Exec.cellOf(m, key, f)])) };
|
|
391
400
|
}
|
|
392
401
|
asChoice(v, values, at) {
|
|
393
|
-
if (v.t === 'choice')
|
|
402
|
+
if (v.t === 'choice') {
|
|
403
|
+
if (v.values.length !== values.length || v.values.some((value, i) => value !== values[i]))
|
|
404
|
+
return refuse(at, 'a join or assignment between different ordered choice domains');
|
|
394
405
|
return v.e;
|
|
406
|
+
}
|
|
395
407
|
if (v.t === 'str' && v.e.op === 'slit') {
|
|
396
408
|
if (!values.includes(v.e.value))
|
|
397
409
|
return refuse(at, `'${v.e.value}' is not one of ${values.map(x => `'${x}'`).join(', ')}`);
|
|
@@ -526,13 +538,16 @@ export class Exec {
|
|
|
526
538
|
// where it is there.
|
|
527
539
|
narrow(e, pt, pe) {
|
|
528
540
|
const strip = (x) => (ts.isParenthesizedExpression(x) ? strip(x.expression) : x);
|
|
529
|
-
let x = strip(e), present = true;
|
|
541
|
+
let x = strip(e), present = true, absenceTest = false, comparedNull = false, loose = false;
|
|
530
542
|
if (ts.isPrefixUnaryExpression(x) && x.operator === ts.SyntaxKind.ExclamationToken) {
|
|
531
543
|
x = strip(x.operand);
|
|
532
544
|
present = false;
|
|
533
545
|
}
|
|
534
546
|
else if (ts.isBinaryExpression(x) && (x.right.kind === ts.SyntaxKind.UndefinedKeyword || (ts.isIdentifier(x.right) && x.right.text === 'undefined') || x.right.kind === ts.SyntaxKind.NullKeyword)) {
|
|
535
547
|
const op = x.operatorToken.kind;
|
|
548
|
+
absenceTest = true;
|
|
549
|
+
comparedNull = x.right.kind === ts.SyntaxKind.NullKeyword;
|
|
550
|
+
loose = op === ts.SyntaxKind.EqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken;
|
|
536
551
|
if (op === ts.SyntaxKind.EqualsEqualsEqualsToken || op === ts.SyntaxKind.EqualsEqualsToken)
|
|
537
552
|
present = false;
|
|
538
553
|
else if (op !== ts.SyntaxKind.ExclamationEqualsEqualsToken && op !== ts.SyntaxKind.ExclamationEqualsToken)
|
|
@@ -544,7 +559,15 @@ export class Exec {
|
|
|
544
559
|
const v = pt.locals.get(x.text);
|
|
545
560
|
if (v?.t !== 'opt')
|
|
546
561
|
return [pt, pe];
|
|
547
|
-
|
|
562
|
+
// A strict comparison to the other absence kind is constant, not a presence test.
|
|
563
|
+
if (absenceTest && !loose && !!v.null !== comparedNull)
|
|
564
|
+
return [pt, pe];
|
|
565
|
+
const absent = { t: 'undef', ...(v.null ? { null: true } : {}) };
|
|
566
|
+
const set = (p, there) => ({ ...p, locals: new Map(p.locals).set(x.text, there ? v.v : absent) });
|
|
567
|
+
// A falsy optional scalar can be present (false or 0), not just absent.
|
|
568
|
+
// Preserve the opt value on that arm; only an explicit absence comparison narrows both arms.
|
|
569
|
+
if (!absenceTest)
|
|
570
|
+
return present ? [set(pt, true), pe] : [pt, set(pe, true)];
|
|
548
571
|
return present ? [set(pt, true), set(pe, false)] : [set(pt, false), set(pe, true)];
|
|
549
572
|
}
|
|
550
573
|
bind(name, v, p) {
|
|
@@ -619,6 +642,10 @@ export class Exec {
|
|
|
619
642
|
return I.cmp('=', a.e, b.e);
|
|
620
643
|
if (a.t === 'bool' && b.t === 'bool')
|
|
621
644
|
return I.or(I.and(a.e, b.e), I.and(I.not(a.e), I.not(b.e)));
|
|
645
|
+
// Choices are encoded by position. Standalone arguments may have different
|
|
646
|
+
// domains or orders, so comparing their indices would equate different strings.
|
|
647
|
+
if (this.standalone && a.t === 'choice' && b.t === 'choice')
|
|
648
|
+
return I.or(...a.values.filter(x => b.values.includes(x)).map(x => I.and(I.is(a.e, x), I.is(b.e, x))));
|
|
622
649
|
if (a.t === 'choice' && (b.t === 'choice' || b.t === 'str'))
|
|
623
650
|
return I.leq(a.e, b.t === 'str' && b.e.op === 'slit' && !a.values.includes(b.e.value) ? I.llit(b.e.value, [...a.values, b.e.value]) : this.asChoice(b, a.values, at));
|
|
624
651
|
if (b.t === 'choice' && a.t === 'str')
|
|
@@ -986,8 +1013,6 @@ export class Exec {
|
|
|
986
1013
|
return { t: 'num', e: I.nite(c, x.e, y.e) };
|
|
987
1014
|
if (x.t === 'bool' && y.t === 'bool')
|
|
988
1015
|
return { t: 'bool', e: I.bite(c, x.e, y.e) };
|
|
989
|
-
if (x.t === 'choice' && y.t === 'choice')
|
|
990
|
-
return { t: 'choice', e: I.lite(c, x.e, y.e), values: x.values };
|
|
991
1016
|
if ((x.t === 'choice' || x.t === 'str') && (y.t === 'choice' || y.t === 'str')) {
|
|
992
1017
|
if (x.t === 'str' && y.t === 'str')
|
|
993
1018
|
return { t: 'str', e: I.kite(c, x.e, y.e) };
|
|
@@ -1073,11 +1098,11 @@ export class Exec {
|
|
|
1073
1098
|
})();
|
|
1074
1099
|
if (opaque)
|
|
1075
1100
|
return [{ t: 'opaque', what: opaque }, p];
|
|
1076
|
-
const
|
|
1077
|
-
//
|
|
1078
|
-
const seen = [...this.s.lazy].find(([, l]) => l
|
|
1079
|
-
const nvar = seen ? this.s.vars.get(seen) : this.newVar(
|
|
1080
|
-
this.s.lazy.set(nvar.name, {
|
|
1101
|
+
const key = lazyKey(o.lazy, f), sort = this.s.lazySorts.get(key) ?? typed ?? { k: 'num' };
|
|
1102
|
+
// Repeated reads share one input, independently of its readable scalar name.
|
|
1103
|
+
const seen = [...this.s.lazy].find(([, l]) => lazyKey(l, l.field) === key)?.[0];
|
|
1104
|
+
const nvar = seen ? this.s.vars.get(seen) : this.newVar(`${o.lazy.prefix}${f}`, sort, 'input'), nv = Exec.valueOf(nvar);
|
|
1105
|
+
this.s.lazy.set(nvar.name, { ...o.lazy, field: f });
|
|
1081
1106
|
const fields = new Map(o.fields).set(f, nv);
|
|
1082
1107
|
return [nv, { ...p, heap: new Map(p.heap).set(v.id, { ...o, fields }) }];
|
|
1083
1108
|
}
|
package/dist/core/extract-rs.js
CHANGED
|
@@ -129,7 +129,7 @@ function toJson(t, x) {
|
|
|
129
129
|
return `json!(match ${x} { ${t.values.map(v => `${t.enum}::${v} => ${JSON.stringify(v)}`).join(', ')} })`;
|
|
130
130
|
return 'json!(null)';
|
|
131
131
|
}
|
|
132
|
-
function harnessCode(mod, read, cls) {
|
|
132
|
+
function harnessCode(mod, read, cls, name) {
|
|
133
133
|
const leaves = read.leaves.filter(l => l.kind !== 'frame' && l.kind !== 'map');
|
|
134
134
|
if (read.leaves.some(l => l.kind === 'map'))
|
|
135
135
|
throw new Refusal(mod.file, 'a map in the state: the Rust harness reads none yet');
|
|
@@ -162,17 +162,15 @@ function harnessCode(mod, read, cls) {
|
|
|
162
162
|
const f = cls ? fn(cls.methods[m]) : fn(m);
|
|
163
163
|
const ps = f.params.filter(p => !p.self);
|
|
164
164
|
const args = ps.map((p, i) => { const rs = p.rs ?? ''; const v = fromJson(p.t, `(&a[${i}][1])`, mod); return /^&\s*mut/.test(rs) ? `&mut ${v}` : rs.startsWith('&') ? `&${v}` : v; });
|
|
165
|
-
const target = cls ? `o.${m}(${args.join(', ')})` :
|
|
165
|
+
const target = cls ? `o.${m}(${args.join(', ')})` : `super::${m}(${args.join(', ')})`;
|
|
166
166
|
const ret = f.ret;
|
|
167
167
|
const out = ret.k === 'res' ? `match r { Ok(v) => { let _ = &v; Ok(${ret.of.k === 'none' ? 'json!(null)' : tagged(ret.of, 'v')}) } Err(_) => Err("an Err".to_string()) }` : ret.k === 'opt' ? `Ok(match r { Some(v) => ${tagged(ret.of, 'v')}, None => json!(null) })` : ret.k === 'none' ? 'Ok(json!(null))' : `Ok(${tagged(ret, 'r')})`;
|
|
168
168
|
return `${JSON.stringify(m)} => { let r = ${target}; ${out} }`;
|
|
169
169
|
});
|
|
170
|
-
const clsMod = cls?.module ?? 'crate';
|
|
171
|
-
void clsMod;
|
|
172
170
|
return `
|
|
173
171
|
#[cfg(test)]
|
|
174
172
|
#[allow(unused, clippy::all)]
|
|
175
|
-
pub(crate) mod
|
|
173
|
+
pub(crate) mod ${name} {
|
|
176
174
|
use super::*;
|
|
177
175
|
use serde_json::{json, Value};
|
|
178
176
|
use std::io::{BufRead, Write};
|
|
@@ -260,25 +258,59 @@ function harnessFor(dir, mod, read, opts) {
|
|
|
260
258
|
if (!/\[dev-dependencies(\.serde_json)?\][^[]*serde_json/s.test(toml))
|
|
261
259
|
toml += '\n[dev-dependencies.serde_json]\nversion = "1"\n';
|
|
262
260
|
fs.writeFileSync(`${work}/Cargo.toml`, toml);
|
|
263
|
-
const file = cls ? String(cls.file) :
|
|
261
|
+
const file = cls ? String(cls.file) : mod.path.slice(mod.root.length + 1);
|
|
264
262
|
const modPath = cls?.module ?? mod.fmods?.[Object.keys(read.args)[0]] ?? 'crate';
|
|
263
|
+
if (!cls && Object.keys(read.args).some(id => mod.fmods?.[id] !== modPath || mod.funcs[id]?.span?.[0] !== file)) {
|
|
264
|
+
throw new Refusal(mod.file, 'Rust native replay requires function entries in one known file/module');
|
|
265
|
+
}
|
|
265
266
|
// The clock: Instant::now() read through the harness (the request's time), the code's own calls rewritten first.
|
|
266
267
|
const lib = fs.existsSync(`${work}/src/lib.rs`) ? 'src/lib.rs' : 'src/main.rs';
|
|
267
268
|
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}`] : []; });
|
|
269
|
+
// Allocate bridges once on the unmodified Rust copy, before the chosen names
|
|
270
|
+
// become references in rewritten calls. Placement is still queried afterwards.
|
|
271
|
+
const bridges = JSON.parse(cp.execFileSync(rsReader(opts.cargo), [JSON.stringify({ root: work, harness_bridges: { file: lib } })], { encoding: 'utf8', maxBuffer: 1 << 20, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() }));
|
|
272
|
+
if (bridges.error)
|
|
273
|
+
throw new Refusal(mod.file, bridges.error);
|
|
274
|
+
const { now: nowName, answer: answerName } = bridges;
|
|
275
|
+
if (typeof nowName !== 'string' || !/^__gdp_now(?:_[1-9][0-9]*)?$/.test(nowName) ||
|
|
276
|
+
typeof answerName !== 'string' || !/^__gdp_answer(?:_[1-9][0-9]*)?$/.test(answerName)) {
|
|
277
|
+
throw new Refusal(mod.file, 'Rust native replay has no validated root bridge names');
|
|
278
|
+
}
|
|
268
279
|
// (each answered call rewritten to the harness's answer, from the crate's own text, before the clock's; the call
|
|
269
280
|
// kept in a branch never taken, so the answer is of the type the call is, which a binding needn't write)
|
|
270
|
-
for (const [f, t] of stubbed(read, f => fs.readFileSync(`${dir}/${f}`, 'utf8'), (a, _, call) => `(if false { ${call} } else { crate
|
|
281
|
+
for (const [f, t] of stubbed(read, f => fs.readFileSync(`${dir}/${f}`, 'utf8'), (a, _, call) => `(if false { ${call} } else { crate::${answerName}(${JSON.stringify(a.key)}) })`))
|
|
271
282
|
fs.writeFileSync(`${work}/${f}`, t);
|
|
272
283
|
for (const f of walk(`${work}/src`)) {
|
|
273
284
|
const s = fs.readFileSync(f, 'utf8');
|
|
274
|
-
const t = s.replace(/\b(?:std::time::)?Instant::now\(\)/g,
|
|
285
|
+
const t = s.replace(/\b(?:std::time::)?Instant::now\(\)/g, `crate::${nowName}()`);
|
|
275
286
|
if (t !== s)
|
|
276
287
|
fs.writeFileSync(f, t);
|
|
277
288
|
}
|
|
278
|
-
//
|
|
289
|
+
// Query the parser after rewrites: original offsets are stale after stubs
|
|
290
|
+
// or clock substitutions. Append for file modules; insert before the exact
|
|
291
|
+
// closing brace for inline modules, keeping private-field access in scope.
|
|
279
292
|
const own = new Map([file, lib].map(f => [f, fs.readFileSync(`${work}/${f}`, 'utf8').split('\n').length]));
|
|
280
|
-
|
|
281
|
-
|
|
293
|
+
const site = JSON.parse(cp.execFileSync(rsReader(opts.cargo), [JSON.stringify({ root: work, harness_scope: { file, module: modPath } })], { encoding: 'utf8', maxBuffer: 1 << 20, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() }));
|
|
294
|
+
if (site.error || site.inline_end === undefined)
|
|
295
|
+
throw new Refusal(mod.file, site.error ?? 'Rust native replay has no placement metadata');
|
|
296
|
+
const harnessName = site.harness_name;
|
|
297
|
+
if (typeof harnessName !== 'string' || !/^__gdp_harness(?:_[1-9][0-9]*)?$/.test(harnessName)) {
|
|
298
|
+
throw new Refusal(mod.file, 'Rust native replay has no validated helper module name');
|
|
299
|
+
}
|
|
300
|
+
const source = fs.readFileSync(`${work}/${file}`, 'utf8');
|
|
301
|
+
let prefix = source, suffix = '';
|
|
302
|
+
if (site.inline_end !== null) {
|
|
303
|
+
const bytes = new TextEncoder().encode(source), at = site.inline_end;
|
|
304
|
+
if (!Number.isSafeInteger(at) || at < 0 || at >= bytes.length || bytes[at] !== 125 || source.startsWith('\uFEFF') || /^#![^[]/.test(source)) {
|
|
305
|
+
throw new Refusal(mod.file, 'Rust native replay has an unsupported inline-module byte position');
|
|
306
|
+
}
|
|
307
|
+
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
308
|
+
prefix = decoder.decode(bytes.slice(0, at));
|
|
309
|
+
suffix = decoder.decode(bytes.slice(at));
|
|
310
|
+
}
|
|
311
|
+
const code = harnessCode(mod, read, cls, harnessName), insertedAt = prefix.split('\n').length, addedLines = code.split('\n').length - 1;
|
|
312
|
+
fs.writeFileSync(`${work}/${file}`, prefix + code + suffix);
|
|
313
|
+
fs.writeFileSync(`${work}/${lib}`, `${fs.readFileSync(`${work}/${lib}`, 'utf8')}\n#[cfg(test)]\n#[allow(unused)]\npub(crate) fn ${nowName}() -> std::time::Instant { ${modPath}::${harnessName}::now() }\n#[cfg(test)]\n#[allow(unused)]\npub(crate) fn ${answerName}<T: ${modPath}::${harnessName}::GdpAns>(k: &str) -> T { ${modPath}::${harnessName}::answer(k) }\n`);
|
|
282
314
|
const target = `${os.tmpdir()}/gdp-rscheck-target`;
|
|
283
315
|
const built = buildCheck('cargo', () => cp.execFileSync(opts.cargo ?? 'cargo', ['test', '--lib', '--no-run', '--message-format=json', '--target-dir', target], { cwd: work, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 28, env: { ...proc?.env }, timeout: compileLimit(), killSignal: 'SIGKILL' }), e => String(e.stdout ?? '').split('\n').flatMap(l => { try {
|
|
284
316
|
const j = JSON.parse(l);
|
|
@@ -286,8 +318,20 @@ function harnessFor(dir, mod, read, opts) {
|
|
|
286
318
|
}
|
|
287
319
|
catch {
|
|
288
320
|
return [];
|
|
289
|
-
} }), l => {
|
|
290
|
-
|
|
321
|
+
} }), l => {
|
|
322
|
+
const m = /--> ([^\s:]+\.rs):(\d+):\d+/.exec(l);
|
|
323
|
+
if (!m)
|
|
324
|
+
return false;
|
|
325
|
+
let line = Number(m[2]);
|
|
326
|
+
if (m[1] === file) {
|
|
327
|
+
if (line > insertedAt && line < insertedAt + addedLines)
|
|
328
|
+
return false;
|
|
329
|
+
if (line >= insertedAt + addedLines)
|
|
330
|
+
line -= addedLines;
|
|
331
|
+
}
|
|
332
|
+
const n = own.get(m[1]);
|
|
333
|
+
return n === undefined || line <= n;
|
|
334
|
+
});
|
|
291
335
|
if (!('ok' in built))
|
|
292
336
|
return { cmd: 'false', args: [], hello: {}, error: built.why, kind: built.kind };
|
|
293
337
|
const msgs = built.ok;
|
|
@@ -302,7 +346,7 @@ function harnessFor(dir, mod, read, opts) {
|
|
|
302
346
|
return { cmd: 'false', args: [], hello: {}, error: 'the test build gave no executable', kind: 'harness' };
|
|
303
347
|
read.model.notes.push('Rust: the code is checked in a debug build (overflow checks on); its branch arms are not counted (no instrumentation yet)');
|
|
304
348
|
read.arms.length = 0;
|
|
305
|
-
const test = `${modPath === 'crate' ? '' : `${modPath.replace(/^crate::/, '')}::`}
|
|
349
|
+
const test = `${modPath === 'crate' ? '' : `${modPath.replace(/^crate::/, '')}::`}${harnessName}::__gdp_harness_main`;
|
|
306
350
|
return { cmd: exe, args: [test, '--exact', '--nocapture', '--test-threads=1'], hello: {} };
|
|
307
351
|
}
|
|
308
352
|
catch (e) {
|
|
@@ -10,6 +10,7 @@ export type ReadOptions = {
|
|
|
10
10
|
init?: unknown;
|
|
11
11
|
};
|
|
12
12
|
export declare function setupOf(code: string, file: string, typed?: Record<string, Sort>, files?: Record<string, string>): Setup;
|
|
13
|
+
export declare function readStandalone(code: string, file: string, opts: ReadOptions): Model;
|
|
13
14
|
export declare function readFunctions(code: string, file: string, opts: ReadOptions): Model;
|
|
14
15
|
export declare function readClass(code: string, file: string, opts: ReadOptions): Model;
|
|
15
16
|
export type Result = {
|