@toiroakr/chisel 0.1.0 → 0.3.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 +354 -21
- package/dist/absence.d.ts +28 -0
- package/dist/absence.js +266 -0
- package/dist/absence.js.map +1 -0
- package/dist/behavior.d.ts +26 -19
- package/dist/behavior.js +193 -203
- package/dist/behavior.js.map +1 -1
- package/dist/beside.d.ts +5 -0
- package/dist/beside.js +10 -0
- package/dist/beside.js.map +1 -1
- package/dist/border.d.ts +7 -8
- package/dist/border.js +88 -36
- package/dist/border.js.map +1 -1
- package/dist/bounds.d.ts +1 -0
- package/dist/bounds.js +27 -0
- package/dist/bounds.js.map +1 -0
- package/dist/changes.d.ts +23 -0
- package/dist/changes.js +355 -0
- package/dist/changes.js.map +1 -0
- package/dist/checks.d.ts +1 -0
- package/dist/checks.js +295 -0
- package/dist/checks.js.map +1 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +351 -14
- package/dist/cli.js.map +1 -1
- package/dist/codec.js +16 -7
- package/dist/codec.js.map +1 -1
- package/dist/codegen.js +6 -8
- package/dist/codegen.js.map +1 -1
- package/dist/composition.d.ts +3 -3
- package/dist/composition.js +9 -8
- package/dist/composition.js.map +1 -1
- package/dist/conformance.d.ts +24 -0
- package/dist/conformance.js +44 -0
- package/dist/conformance.js.map +1 -0
- package/dist/data.d.ts +3 -2
- package/dist/data.js +7 -3
- package/dist/data.js.map +1 -1
- package/dist/decimal-js.d.ts +2 -0
- package/dist/decimal-js.js +5 -0
- package/dist/decimal-js.js.map +1 -0
- package/dist/decimal.d.ts +2 -0
- package/dist/decimal.js +3 -0
- package/dist/decimal.js.map +1 -0
- package/dist/dependency.d.ts +9 -6
- package/dist/dependency.js +23 -17
- package/dist/dependency.js.map +1 -1
- package/dist/domain.d.ts +6 -2
- package/dist/domain.js +65 -25
- package/dist/domain.js.map +1 -1
- package/dist/ensures.js +3 -3
- package/dist/ensures.js.map +1 -1
- package/dist/equal.d.ts +1 -0
- package/dist/equal.js +135 -0
- package/dist/equal.js.map +1 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +25 -0
- package/dist/errors.js.map +1 -0
- package/dist/exact.d.ts +13 -1
- package/dist/exact.js +52 -3
- package/dist/exact.js.map +1 -1
- package/dist/feasibility.d.ts +5 -3
- package/dist/feasibility.js +309 -53
- package/dist/feasibility.js.map +1 -1
- package/dist/guard-borders.d.ts +14 -5
- package/dist/guard-borders.js +229 -190
- package/dist/guard-borders.js.map +1 -1
- package/dist/guard-scope.d.ts +65 -0
- package/dist/guard-scope.js +384 -0
- package/dist/guard-scope.js.map +1 -0
- package/dist/hooks.d.ts +22 -0
- package/dist/hooks.js +2 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +30 -8
- package/dist/index.js +18 -5
- package/dist/index.js.map +1 -1
- package/dist/interleave.d.ts +31 -0
- package/dist/interleave.js +202 -0
- package/dist/interleave.js.map +1 -0
- package/dist/interval.d.ts +8 -0
- package/dist/interval.js +213 -23
- package/dist/interval.js.map +1 -1
- package/dist/isolated.d.ts +7 -1
- package/dist/isolated.js +53 -5
- package/dist/isolated.js.map +1 -1
- package/dist/kinds/decimal.d.ts +1 -0
- package/dist/kinds/decimal.js +16 -0
- package/dist/kinds/decimal.js.map +1 -0
- package/dist/kinds/rational.d.ts +1 -0
- package/dist/kinds/rational.js +13 -0
- package/dist/kinds/rational.js.map +1 -0
- package/dist/kinds/temporal.d.ts +1 -0
- package/dist/kinds/temporal.js +15 -0
- package/dist/kinds/temporal.js.map +1 -0
- package/dist/lean/behavior.d.ts +29 -0
- package/dist/lean/behavior.js +76 -0
- package/dist/lean/behavior.js.map +1 -0
- package/dist/lean/given.d.ts +10 -0
- package/dist/lean/given.js +15 -0
- package/dist/lean/given.js.map +1 -0
- package/dist/lean/index.d.ts +11 -0
- package/dist/lean/index.js +8 -0
- package/dist/lean/index.js.map +1 -0
- package/dist/lean/model.d.ts +20 -0
- package/dist/lean/model.js +133 -0
- package/dist/lean/model.js.map +1 -0
- package/dist/lean/protocol.d.ts +14 -0
- package/dist/lean/protocol.js +34 -0
- package/dist/lean/protocol.js.map +1 -0
- package/dist/lean/rule.d.ts +54 -0
- package/dist/lean/rule.js +149 -0
- package/dist/lean/rule.js.map +1 -0
- package/dist/lean/schema.d.ts +46 -0
- package/dist/lean/schema.js +155 -0
- package/dist/lean/schema.js.map +1 -0
- package/dist/machine-check.d.ts +73 -0
- package/dist/machine-check.js +215 -0
- package/dist/machine-check.js.map +1 -0
- package/dist/machine.d.ts +122 -0
- package/dist/machine.js +271 -0
- package/dist/machine.js.map +1 -0
- package/dist/model.d.ts +110 -11
- package/dist/model.js +724 -80
- package/dist/model.js.map +1 -1
- package/dist/off-grid.d.ts +4 -0
- package/dist/off-grid.js +92 -0
- package/dist/off-grid.js.map +1 -0
- package/dist/outcomes.d.ts +15 -0
- package/dist/outcomes.js +120 -0
- package/dist/outcomes.js.map +1 -0
- package/dist/pairs.js +14 -5
- package/dist/pairs.js.map +1 -1
- package/dist/partition.d.ts +1 -0
- package/dist/partition.js +101 -19
- package/dist/partition.js.map +1 -1
- package/dist/placeholders.d.ts +3 -0
- package/dist/placeholders.js +44 -0
- package/dist/placeholders.js.map +1 -0
- package/dist/proof.d.ts +6 -0
- package/dist/proof.js +282 -56
- package/dist/proof.js.map +1 -1
- package/dist/protocol.d.ts +22 -0
- package/dist/protocol.js +12 -0
- package/dist/protocol.js.map +1 -0
- package/dist/relations.d.ts +30 -0
- package/dist/relations.js +235 -0
- package/dist/relations.js.map +1 -0
- package/dist/replay.d.ts +45 -0
- package/dist/replay.js +157 -0
- package/dist/replay.js.map +1 -0
- package/dist/rewrites.d.ts +41 -0
- package/dist/rewrites.js +180 -0
- package/dist/rewrites.js.map +1 -0
- package/dist/rule.d.ts +74 -11
- package/dist/rule.js +429 -22
- package/dist/rule.js.map +1 -1
- package/dist/runtime.d.ts +12 -0
- package/dist/runtime.js +8 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema.d.ts +44 -28
- package/dist/schema.js +50 -113
- package/dist/schema.js.map +1 -1
- package/dist/specification.d.ts +23 -3
- package/dist/specification.js +1001 -96
- package/dist/specification.js.map +1 -1
- package/dist/stops.d.ts +20 -0
- package/dist/stops.js +221 -0
- package/dist/stops.js.map +1 -0
- package/dist/temporal-global.d.ts +4 -0
- package/dist/temporal-global.js +11 -0
- package/dist/temporal-global.js.map +1 -0
- package/dist/temporal.d.ts +22 -0
- package/dist/temporal.js +113 -0
- package/dist/temporal.js.map +1 -0
- package/dist/tla-validate.d.ts +31 -0
- package/dist/tla-validate.js +151 -0
- package/dist/tla-validate.js.map +1 -0
- package/dist/tla.d.ts +61 -0
- package/dist/tla.js +722 -0
- package/dist/tla.js.map +1 -0
- package/dist/verification.d.ts +9 -0
- package/dist/verification.js +7 -0
- package/dist/verification.js.map +1 -0
- package/dist/ways.d.ts +11 -5
- package/dist/ways.js +51 -45
- package/dist/ways.js.map +1 -1
- package/dist/world.d.ts +98 -0
- package/dist/world.js +463 -0
- package/dist/world.js.map +1 -0
- package/package.json +49 -10
- package/schema/report.schema.json +169 -1
package/dist/feasibility.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { compatibleBound } from "./interval.js";
|
|
2
|
+
import { deepEqual } from "./equal.js";
|
|
2
3
|
import { integerCarrier, normalize, numberCarrier } from "./border.js";
|
|
3
|
-
import { inheritedAt } from "./guard-
|
|
4
|
+
import { inheritedAt } from "./guard-scope.js";
|
|
4
5
|
import { carrierOf } from "./partition.js";
|
|
5
|
-
import { DEPS, boundTermPath, conjuncts, describeRule, differenceOf, holds, isTerm, positionData, positionOf, readOperand, termData, termPaths } from "./rule.js";
|
|
6
|
+
import { DEPS, boundTermPath, conjuncts, describeRule, differenceOf, holds, isTerm, positionData, positionOf, readOperand, termData, termPaths, counts, partsOfMeasure, positionTerm } from "./rule.js";
|
|
6
7
|
import { isVariantsSchema, schemaAtPath } from "./schema.js";
|
|
8
|
+
import { relationsVerdict } from "./relations.js";
|
|
7
9
|
const negated = {
|
|
8
10
|
"<": ">=",
|
|
9
11
|
"<=": ">",
|
|
@@ -36,7 +38,16 @@ export function feasibilityOf(way, scope, placement, combinations = FEASIBILITY_
|
|
|
36
38
|
const groups = new Map();
|
|
37
39
|
const relations = [];
|
|
38
40
|
const opaque = [];
|
|
41
|
+
const relationSteps = [];
|
|
42
|
+
// `==`/`!=` between two finite positions, settled with them by the joint search, and between two
|
|
43
|
+
// strings free of invariants, settled by which values the way makes equal.
|
|
44
|
+
const finiteEqualities = [];
|
|
45
|
+
const stringEqualities = [];
|
|
39
46
|
const outcomes = new Map();
|
|
47
|
+
// What the way holds of quantified conditions, each written with its negation pushed in, so a
|
|
48
|
+
// condition and the same one written negated (`any(xs, x => all(ys, y => y != x))` failing and
|
|
49
|
+
// `all(xs, x => any(ys, y => y == x))` failing) are told to contradict each other.
|
|
50
|
+
const quantified = new Set();
|
|
40
51
|
const groupFor = (path, measure) => {
|
|
41
52
|
const key = JSON.stringify([path, measure]);
|
|
42
53
|
if (!groups.has(key)) {
|
|
@@ -93,7 +104,7 @@ export function feasibilityOf(way, scope, placement, combinations = FEASIBILITY_
|
|
|
93
104
|
const identity = stepIdentity(step);
|
|
94
105
|
const key = step.distinction.kind === "match" ? JSON.stringify(["match", positionData(step.distinction.on)?.path]) : describeRule(step.distinction);
|
|
95
106
|
const bucket = outcomes.get(key) ?? [];
|
|
96
|
-
const seen = bucket.find(previous =>
|
|
107
|
+
const seen = bucket.find(previous => deepEqual(previous.identity, identity));
|
|
97
108
|
if (seen !== undefined) {
|
|
98
109
|
if (seen.outcome !== step.outcome) {
|
|
99
110
|
return { kind: "infeasible", reason: contradicts };
|
|
@@ -102,16 +113,25 @@ export function feasibilityOf(way, scope, placement, combinations = FEASIBILITY_
|
|
|
102
113
|
}
|
|
103
114
|
bucket.push({ identity, outcome: step.outcome });
|
|
104
115
|
outcomes.set(key, bucket);
|
|
105
|
-
const placed = placedConstraintOf(step);
|
|
116
|
+
const placed = placedConstraintOf(step, scope);
|
|
106
117
|
if (placed !== undefined) {
|
|
107
|
-
groups.get(groupFor(placed.path, placed.measure)).constraints.push(placed.
|
|
118
|
+
groups.get(groupFor(placed.path, placed.measure)).constraints.push(...placed.constraints);
|
|
108
119
|
continue;
|
|
109
120
|
}
|
|
110
121
|
const { distinction, outcome } = step;
|
|
111
122
|
if (distinction.kind === "all" || distinction.kind === "any") {
|
|
123
|
+
const held = identityKey(outcome === true ? distinction : negatedRule(distinction));
|
|
124
|
+
const refused = identityKey(outcome === true ? negatedRule(distinction) : distinction);
|
|
125
|
+
if (quantified.has(refused))
|
|
126
|
+
return { kind: "infeasible", reason: contradicts };
|
|
127
|
+
quantified.add(held);
|
|
112
128
|
opaque.push(termPaths(distinction));
|
|
113
129
|
continue;
|
|
114
130
|
}
|
|
131
|
+
if (distinction.kind === "relation") {
|
|
132
|
+
relationSteps.push({ rule: distinction, outcome: outcome === true });
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
115
135
|
if (distinction.kind !== "compare") {
|
|
116
136
|
continue;
|
|
117
137
|
}
|
|
@@ -121,6 +141,13 @@ export function feasibilityOf(way, scope, placement, combinations = FEASIBILITY_
|
|
|
121
141
|
constrainForm(form, operator, 0);
|
|
122
142
|
continue;
|
|
123
143
|
}
|
|
144
|
+
const equality = equalityOf(distinction, operator, scope);
|
|
145
|
+
if (equality !== undefined) {
|
|
146
|
+
groupFor(equality.left, "value");
|
|
147
|
+
groupFor(equality.right, "value");
|
|
148
|
+
(equality.finite ? finiteEqualities : stringEqualities).push(equality);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
124
151
|
const relation = relationOf(distinction, operator, groupFor);
|
|
125
152
|
if (relation === undefined) {
|
|
126
153
|
opaque.push(termPaths(distinction));
|
|
@@ -139,8 +166,26 @@ export function feasibilityOf(way, scope, placement, combinations = FEASIBILITY_
|
|
|
139
166
|
constrainForm(form, rule.operator, 0, true);
|
|
140
167
|
}
|
|
141
168
|
}
|
|
142
|
-
|
|
169
|
+
// Relations on a place no other step reads are settled among themselves; one
|
|
170
|
+
// whose place another step reads too is read with it as an opaque step.
|
|
143
171
|
let unsettled = false;
|
|
172
|
+
// A place relations settled among themselves is still read: an opaque step
|
|
173
|
+
// on it (another relation read through a transform, an all/any, a
|
|
174
|
+
// comparison not read) leaves the way undecided.
|
|
175
|
+
const relationReads = [];
|
|
176
|
+
for (const verdict of relationsVerdict(relationSteps, scope)) {
|
|
177
|
+
if (verdict.kind === "infeasible")
|
|
178
|
+
return { kind: "infeasible", reason: contradicts };
|
|
179
|
+
const shared = verdict.paths.some(path => [...groups.values()].some(group => sharesValue(path, group.path)) || opaque.flat().some(other => sharesValue(path, other)));
|
|
180
|
+
if (verdict.kind === "unknown" || shared)
|
|
181
|
+
opaque.push(verdict.paths);
|
|
182
|
+
else
|
|
183
|
+
relationReads.push(...verdict.paths);
|
|
184
|
+
// An unknown verdict is no settled way, searched or not: a transformed or quantified subject was never read, so an invariant of its place may refuse it.
|
|
185
|
+
if (verdict.kind === "unknown")
|
|
186
|
+
unsettled = true;
|
|
187
|
+
}
|
|
188
|
+
const intervals = new Map();
|
|
144
189
|
for (const [key, group] of groups) {
|
|
145
190
|
const settled = settle(group, scope);
|
|
146
191
|
if (settled === false) {
|
|
@@ -149,7 +194,14 @@ export function feasibilityOf(way, scope, placement, combinations = FEASIBILITY_
|
|
|
149
194
|
intervals.set(key, typeof settled === "object" ? settled : undefined);
|
|
150
195
|
unsettled ||= settled === undefined && group.constraints.length > 1;
|
|
151
196
|
}
|
|
152
|
-
|
|
197
|
+
if (stringEqualities.length > 0) {
|
|
198
|
+
const verdict = equalitiesHold(stringEqualities, groups);
|
|
199
|
+
if (verdict === false)
|
|
200
|
+
return { kind: "infeasible", reason: contradicts };
|
|
201
|
+
if (verdict === undefined)
|
|
202
|
+
unsettled = true;
|
|
203
|
+
}
|
|
204
|
+
const joint = jointAssignment([...groups.values()], scope, combinations, undefined, finiteEqualities);
|
|
153
205
|
if (joint === "none") {
|
|
154
206
|
return { kind: "infeasible", reason: contradicts };
|
|
155
207
|
}
|
|
@@ -208,17 +260,17 @@ export function feasibilityOf(way, scope, placement, combinations = FEASIBILITY_
|
|
|
208
260
|
return { kind: "infeasible", reason: contradicts };
|
|
209
261
|
}
|
|
210
262
|
}
|
|
211
|
-
const readPaths = [...groups.values()].map(group => group.path);
|
|
263
|
+
const readPaths = [...[...groups.values()].map(group => group.path), ...relationReads];
|
|
212
264
|
const overlaps = opaque.some((paths, index) => paths.some(path => [...readPaths, ...opaque.filter((_, other) => other !== index).flat()].some(other => sharesValue(path, other))));
|
|
213
265
|
return overlaps || unsettled
|
|
214
266
|
? { kind: "undecided", reason: unreadable }
|
|
215
267
|
: { kind: "feasible" };
|
|
216
268
|
}
|
|
217
|
-
// The
|
|
218
|
-
function placedConstraintOf(step) {
|
|
269
|
+
// The constraints a step puts on one coordinate: a match, or a comparison with a constant.
|
|
270
|
+
function placedConstraintOf(step, scope) {
|
|
219
271
|
const { distinction, outcome } = step;
|
|
220
272
|
if (distinction.kind === "match") {
|
|
221
|
-
return { path: positionOf(distinction.on).path, measure: "value",
|
|
273
|
+
return { path: positionOf(distinction.on).path, measure: "value", constraints: [{ operator: "==", bound: outcome }] };
|
|
222
274
|
}
|
|
223
275
|
if (distinction.kind !== "compare") {
|
|
224
276
|
return undefined;
|
|
@@ -227,25 +279,41 @@ function placedConstraintOf(step) {
|
|
|
227
279
|
if (normalized === undefined) {
|
|
228
280
|
return undefined;
|
|
229
281
|
}
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
constraint: {
|
|
235
|
-
operator: outcome === true ? normalized.operator : negated[normalized.operator],
|
|
236
|
-
bound: normalized.bound,
|
|
237
|
-
},
|
|
282
|
+
const path = positionOf((isTerm(distinction.left) ? distinction.left : distinction.right)).path;
|
|
283
|
+
const constraint = {
|
|
284
|
+
operator: outcome === true ? normalized.operator : negated[normalized.operator],
|
|
285
|
+
bound: normalized.bound,
|
|
238
286
|
};
|
|
287
|
+
// A transformed read of a finite position, `lowercase($.level)` of an enum,
|
|
288
|
+
// is read off each of its values: the step refuses the values whose reading
|
|
289
|
+
// the constraint does not keep, so it is settled with the value's own steps.
|
|
290
|
+
const { transforms, reading } = partsOfMeasure(normalized.measure);
|
|
291
|
+
const domain = transforms.length > 0 && reading === "value" ? finiteDomainAt(scope, path) : undefined;
|
|
292
|
+
if (domain !== undefined) {
|
|
293
|
+
const kept = { kind: "compare", left: positionTerm([], normalized.measure), operator: constraint.operator, right: constraint.bound };
|
|
294
|
+
return {
|
|
295
|
+
path,
|
|
296
|
+
measure: "value",
|
|
297
|
+
constraints: domain.filter(value => !holds(kept, value)).map(value => ({ operator: "!=", bound: value })),
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
return { path, measure: normalized.measure, constraints: [constraint] };
|
|
239
301
|
}
|
|
240
302
|
function stepIdentity(step) {
|
|
241
303
|
return step.distinction.kind === "match"
|
|
242
304
|
? ["match", termData(step.distinction.on)]
|
|
243
305
|
: ruleIdentity(step.distinction);
|
|
244
306
|
}
|
|
307
|
+
// The identity of a rule as one string, told apart by the paths it reads rather than by how it is
|
|
308
|
+
// written, since the key "a.b" is written as the path a.b is.
|
|
309
|
+
function identityKey(rule) {
|
|
310
|
+
return JSON.stringify(ruleIdentity(rule), (_, value) => typeof value === "bigint" ? `${value}n` : value);
|
|
311
|
+
}
|
|
245
312
|
function ruleIdentity(rule) {
|
|
246
313
|
const operand = (value) => isTerm(value) ? ["term", termData(value)] : ["constant", value];
|
|
247
314
|
switch (rule.kind) {
|
|
248
315
|
case "compare": return [rule.kind, rule.operator, operand(rule.left), operand(rule.right)];
|
|
316
|
+
case "relation": return [rule.kind, rule.relation, operand(rule.subject), operand(rule.other)];
|
|
249
317
|
case "all":
|
|
250
318
|
case "any": return [rule.kind, operand(rule.of), rule.element, ruleIdentity(rule.each)];
|
|
251
319
|
case "not": return [rule.kind, ruleIdentity(rule.rule)];
|
|
@@ -258,7 +326,7 @@ function ruleIdentity(rule) {
|
|
|
258
326
|
function rangeOf(form, intervals, carrier) {
|
|
259
327
|
const whole = (edge, direction) => edge === undefined || edge.inclusive || carrier !== integerCarrier
|
|
260
328
|
? edge
|
|
261
|
-
: { value: edge.value + direction, inclusive: true };
|
|
329
|
+
: { value: Number(edge.value) + direction, inclusive: true };
|
|
262
330
|
const end = (side) => form.parts.reduce((total, { key, coefficient }) => {
|
|
263
331
|
const interval = intervals.get(key);
|
|
264
332
|
const taken = (coefficient > 0) === (side === "lower") ? "lower" : "upper";
|
|
@@ -266,7 +334,7 @@ function rangeOf(form, intervals, carrier) {
|
|
|
266
334
|
return total === undefined || edge === undefined
|
|
267
335
|
? undefined
|
|
268
336
|
: {
|
|
269
|
-
value: total.value + coefficient * edge.value,
|
|
337
|
+
value: total.value + coefficient * Number(edge.value),
|
|
270
338
|
inclusive: total.inclusive && edge.inclusive,
|
|
271
339
|
};
|
|
272
340
|
}, { value: 0, inclusive: true });
|
|
@@ -293,7 +361,7 @@ function numericFormOf(rule, scope, prefix) {
|
|
|
293
361
|
const parts = form.parts.map(part => ({ ...part, path: [...prefix, ...part.path] }));
|
|
294
362
|
const kept = parts.every(part => part.measure === "value" &&
|
|
295
363
|
!leftOutAlong(scope, part.path) &&
|
|
296
|
-
["integer", "number"].includes(
|
|
364
|
+
["integer", "number"].includes(schemaThrough(scope, part.path)?.kind ?? ""));
|
|
297
365
|
return parts.length >= 2 && kept && typeof form.constant === "number" ? { ...form, parts } : undefined;
|
|
298
366
|
}
|
|
299
367
|
function leftOutAlong(scope, path) {
|
|
@@ -310,7 +378,7 @@ function readableFormOf(rule, scope) {
|
|
|
310
378
|
return undefined;
|
|
311
379
|
}
|
|
312
380
|
const form = differenceOf(rule);
|
|
313
|
-
const kinds = form.parts.map(part => part.measure
|
|
381
|
+
const kinds = form.parts.map(part => counts(part.measure) ? "integer" : schemaThrough(scope, part.path)?.kind);
|
|
314
382
|
// A part that may be left out is not one: the comparison holds without it.
|
|
315
383
|
return typeof form.constant === "number" &&
|
|
316
384
|
kinds.every(kind => kind === "integer" || kind === "number") &&
|
|
@@ -318,6 +386,105 @@ function readableFormOf(rule, scope) {
|
|
|
318
386
|
? form
|
|
319
387
|
: undefined;
|
|
320
388
|
}
|
|
389
|
+
// The rule with its negation pushed in through quantifiers and connectives, which every way of
|
|
390
|
+
// reading it the analyses use agrees with: what a way reads is never absent, since a comparison
|
|
391
|
+
// reading a value that may be left out is refused where it is written.
|
|
392
|
+
function negatedRule(rule) {
|
|
393
|
+
switch (rule.kind) {
|
|
394
|
+
case "compare": return { ...rule, operator: negated[rule.operator] };
|
|
395
|
+
case "all": return { kind: "any", of: rule.of, element: rule.element, each: negatedRule(rule.each) };
|
|
396
|
+
case "any": return { kind: "all", of: rule.of, element: rule.element, each: negatedRule(rule.each) };
|
|
397
|
+
case "and": return { kind: "or", rules: rule.rules.map(negatedRule) };
|
|
398
|
+
case "or": return { kind: "and", rules: rule.rules.map(negatedRule) };
|
|
399
|
+
case "not": return rule.rule;
|
|
400
|
+
case "relation": return { kind: "not", rule };
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
// A comparison by `==` or `!=` of two values settled without an order: two finite positions, or
|
|
404
|
+
// two strings no invariant of their own narrows.
|
|
405
|
+
function equalityOf(rule, operator, scope) {
|
|
406
|
+
if (operator !== "==" && operator !== "!=")
|
|
407
|
+
return undefined;
|
|
408
|
+
if (!isTerm(rule.left) || !isTerm(rule.right))
|
|
409
|
+
return undefined;
|
|
410
|
+
const left = positionData(rule.left), right = positionData(rule.right);
|
|
411
|
+
if (left === undefined || right === undefined || left.measure !== "value" || right.measure !== "value")
|
|
412
|
+
return undefined;
|
|
413
|
+
const equal = operator === "==";
|
|
414
|
+
if (finiteDomainThrough(scope, left.path) !== undefined && finiteDomainThrough(scope, right.path) !== undefined)
|
|
415
|
+
return { left: left.path, right: right.path, equal, finite: true };
|
|
416
|
+
const free = (path) => {
|
|
417
|
+
const schemas = declaredAt(scope, path);
|
|
418
|
+
return schemas.length > 0 && schemas.every(schema => schema.kind === "string" && schema.invariants.length === 0);
|
|
419
|
+
};
|
|
420
|
+
return free(left.path) && free(right.path) ? { left: left.path, right: right.path, equal, finite: false } : undefined;
|
|
421
|
+
}
|
|
422
|
+
// The schema at a path, or, inside a case of a sum field, the one schema every case declaring the
|
|
423
|
+
// path gives it. A way reads such a field only where an earlier step settled the case (a read of
|
|
424
|
+
// one that may be left out is refused where it is written), so it is read as present.
|
|
425
|
+
function schemaThrough(scope, path) {
|
|
426
|
+
const direct = schemaAtPath(scope, path);
|
|
427
|
+
if (direct !== undefined)
|
|
428
|
+
return direct;
|
|
429
|
+
const declared = declaredAt(scope, path);
|
|
430
|
+
return declared.length > 0 && declared.every(schema => schema === declared[0]) ? declared[0] : undefined;
|
|
431
|
+
}
|
|
432
|
+
// The schemas a path reaches through every case of a sum that declares its next key; none where a
|
|
433
|
+
// key is declared nowhere, or the path passes an optional, whose absence no comparison settles.
|
|
434
|
+
function declaredAt(schema, path) {
|
|
435
|
+
const [key, ...rest] = path;
|
|
436
|
+
if (key === undefined)
|
|
437
|
+
return [schema];
|
|
438
|
+
if (isVariantsSchema(schema)) {
|
|
439
|
+
return Object.values(schema.variants)
|
|
440
|
+
.filter(variant => Object.hasOwn(variant.shape, key))
|
|
441
|
+
.flatMap(variant => declaredAt(variant.shape[key], rest));
|
|
442
|
+
}
|
|
443
|
+
if (schema.kind !== "object")
|
|
444
|
+
return [];
|
|
445
|
+
const { shape } = schema;
|
|
446
|
+
return Object.hasOwn(shape, key) ? declaredAt(shape[key], rest) : [];
|
|
447
|
+
}
|
|
448
|
+
// Whether strings, each any value but the constants the way pins it to or keeps it from, can be
|
|
449
|
+
// equal and unequal as the way asks: those it makes equal are one value, pinned to at most one
|
|
450
|
+
// constant; two it makes unequal are neither one value nor pinned to one constant. A string has
|
|
451
|
+
// values to spare, so nothing else can refute it. Undefined where a string is also ordered.
|
|
452
|
+
function equalitiesHold(equalities, groups) {
|
|
453
|
+
const parent = new Map();
|
|
454
|
+
const find = (key) => { const up = parent.get(key) ?? key; if (up === key)
|
|
455
|
+
return key; const root = find(up); parent.set(key, root); return root; };
|
|
456
|
+
const keyOf = (path) => JSON.stringify([path, "value"]);
|
|
457
|
+
for (const { left, right, equal } of equalities)
|
|
458
|
+
if (equal)
|
|
459
|
+
parent.set(find(keyOf(left)), find(keyOf(right)));
|
|
460
|
+
const pinned = new Map();
|
|
461
|
+
const excluded = new Map();
|
|
462
|
+
for (const { left, right } of equalities)
|
|
463
|
+
for (const key of [keyOf(left), keyOf(right)]) {
|
|
464
|
+
for (const constraint of groups.get(key)?.constraints ?? []) {
|
|
465
|
+
if ((constraint.operator !== "==" && constraint.operator !== "!=") || typeof constraint.bound !== "string")
|
|
466
|
+
return undefined;
|
|
467
|
+
const into = constraint.operator === "==" ? pinned : excluded;
|
|
468
|
+
const root = find(key);
|
|
469
|
+
into.set(root, (into.get(root) ?? new Set()).add(constraint.bound.normalize("NFC")));
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
for (const [root, values] of pinned) {
|
|
473
|
+
if (values.size > 1 || [...values].some(value => excluded.get(root)?.has(value)))
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
for (const { left, right, equal } of equalities) {
|
|
477
|
+
if (equal)
|
|
478
|
+
continue;
|
|
479
|
+
const [a, b] = [find(keyOf(left)), find(keyOf(right))];
|
|
480
|
+
if (a === b)
|
|
481
|
+
return false;
|
|
482
|
+
const [x, y] = [pinned.get(a), pinned.get(b)];
|
|
483
|
+
if (x?.size === 1 && y?.size === 1 && [...x][0] === [...y][0])
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
321
488
|
function relationOf(rule, operator, groupFor) {
|
|
322
489
|
if (!isTerm(rule.left) || !isTerm(rule.right)) {
|
|
323
490
|
return undefined;
|
|
@@ -337,8 +504,9 @@ function relationOf(rule, operator, groupFor) {
|
|
|
337
504
|
// two decimals or two instants differ in units their readers convert to, which
|
|
338
505
|
// the steps of a way do not carry.
|
|
339
506
|
function differenceCarrierOf(sides, scope) {
|
|
340
|
-
const kinds = sides.map(side => side.measure
|
|
341
|
-
|
|
507
|
+
const kinds = sides.map(side => counts(side.measure) ? "integer" : schemaThrough(scope, side.path)?.kind);
|
|
508
|
+
// A Date is a whole number of milliseconds, so two of them differ by one, as two integers do.
|
|
509
|
+
if (kinds.every(kind => kind === "integer") || kinds.every(kind => kind === "jsDate")) {
|
|
342
510
|
return integerCarrier;
|
|
343
511
|
}
|
|
344
512
|
return kinds.every(kind => kind === "integer" || kind === "number") ? numberCarrier : undefined;
|
|
@@ -353,7 +521,7 @@ function settle(group, scope) {
|
|
|
353
521
|
if (domain !== undefined) {
|
|
354
522
|
return finite(domain, group.constraints);
|
|
355
523
|
}
|
|
356
|
-
const schema =
|
|
524
|
+
const schema = schemaThrough(scope, path);
|
|
357
525
|
if (schema === undefined) {
|
|
358
526
|
return undefined;
|
|
359
527
|
}
|
|
@@ -372,7 +540,10 @@ function settle(group, scope) {
|
|
|
372
540
|
? []
|
|
373
541
|
: [{ operator: normalized.operator, bound: normalized.bound }];
|
|
374
542
|
});
|
|
375
|
-
|
|
543
|
+
const constraints = [...group.constraints, ...invariants];
|
|
544
|
+
if (constraints.some(item => !compatibleBound(item.bound, counts(measure) ? "number" : schema.kind)))
|
|
545
|
+
return undefined;
|
|
546
|
+
return ordered(constraints, carrier);
|
|
376
547
|
}
|
|
377
548
|
// The values of a finite domain the position's own invariants keep, the way its
|
|
378
549
|
// classes leave out the ones an invariant refuses.
|
|
@@ -383,7 +554,7 @@ function admittedBy(domain, schema, scope, path) {
|
|
|
383
554
|
return domain.filter(value => own.every(rule => holds(rule, value)));
|
|
384
555
|
}
|
|
385
556
|
function sumOwning(scope, path) {
|
|
386
|
-
const owner =
|
|
557
|
+
const owner = schemaThrough(scope, path.slice(0, -1));
|
|
387
558
|
return owner !== undefined && isVariantsSchema(owner) && owner.discriminant === path[path.length - 1]
|
|
388
559
|
? owner
|
|
389
560
|
: undefined;
|
|
@@ -394,6 +565,32 @@ function finite(domain, constraints) {
|
|
|
394
565
|
}
|
|
395
566
|
return domain.some(value => constraints.every(item => (value === item.bound) === (item.operator === "==")));
|
|
396
567
|
}
|
|
568
|
+
// Strings lying between two bounds, nearest the lower first: the lower bound with
|
|
569
|
+
// the lowest code point after it ("a" to "a!" holds "a\u0000"), and the bounds'
|
|
570
|
+
// common prefix followed by each code point between theirs where they part ("Z"
|
|
571
|
+
// to "a" holds "[" and "_"), so a range holding a transformed value is found.
|
|
572
|
+
const BETWEEN_LIMIT = 256;
|
|
573
|
+
function stringsBetween(lower, upper) {
|
|
574
|
+
if (typeof lower !== "string" || typeof upper !== "string") {
|
|
575
|
+
return [];
|
|
576
|
+
}
|
|
577
|
+
const low = [...lower.normalize("NFC")];
|
|
578
|
+
const high = [...upper.normalize("NFC")];
|
|
579
|
+
let common = 0;
|
|
580
|
+
while (common < Math.min(low.length, high.length) && low[common] === high[common]) {
|
|
581
|
+
common += 1;
|
|
582
|
+
}
|
|
583
|
+
const prefix = low.slice(0, common).join("");
|
|
584
|
+
const from = common < low.length ? low[common].codePointAt(0) + 1 : 0;
|
|
585
|
+
const to = common < high.length ? high[common].codePointAt(0) : 0;
|
|
586
|
+
const parted = [];
|
|
587
|
+
for (let point = from; point < Math.min(to, from + BETWEEN_LIMIT); point += 1) {
|
|
588
|
+
if (point < 0xd800 || point > 0xdfff) {
|
|
589
|
+
parted.push(prefix + String.fromCodePoint(point));
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return [`${lower}\u0000`, ...parted];
|
|
593
|
+
}
|
|
397
594
|
function ordered(constraints, carrier) {
|
|
398
595
|
let lower = carrier.floor === undefined ? undefined : { value: carrier.floor.value, inclusive: true };
|
|
399
596
|
let upper = carrier.ceiling === undefined ? undefined : { value: carrier.ceiling.value, inclusive: true };
|
|
@@ -414,7 +611,9 @@ function ordered(constraints, carrier) {
|
|
|
414
611
|
unequal.push(bound);
|
|
415
612
|
}
|
|
416
613
|
}
|
|
417
|
-
|
|
614
|
+
// A value nothing reads as is never held: lowercase($) == "ABC" never holds.
|
|
615
|
+
const within = (value) => carrier.produces?.(value) !== false &&
|
|
616
|
+
above(value, lower, carrier) &&
|
|
418
617
|
below(value, upper, carrier) &&
|
|
419
618
|
unequal.every(refused => carrier.compare(value, refused) !== 0);
|
|
420
619
|
if (equal.length > 0) {
|
|
@@ -430,7 +629,23 @@ function ordered(constraints, carrier) {
|
|
|
430
629
|
const { step } = carrier;
|
|
431
630
|
if (step === undefined) {
|
|
432
631
|
const order = carrier.compare(lower.value, upper.value);
|
|
433
|
-
|
|
632
|
+
if (!(order < 0 || (order === 0 && within(lower.value)))) {
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
if (carrier.produces === undefined) {
|
|
636
|
+
return interval;
|
|
637
|
+
}
|
|
638
|
+
// A transformed string reads only as what its transforms give back, and a
|
|
639
|
+
// range may hold none of them (no lowercased string lies from "A" to "Z"):
|
|
640
|
+
// it is settled only where a value is found in it.
|
|
641
|
+
const found = [
|
|
642
|
+
lower.inclusive ? lower.value : undefined,
|
|
643
|
+
carrier.past?.(lower.value, 1),
|
|
644
|
+
upper.inclusive ? upper.value : undefined,
|
|
645
|
+
carrier.past?.(upper.value, -1),
|
|
646
|
+
...stringsBetween(lower.value, upper.value),
|
|
647
|
+
].some(value => value !== undefined && within(value));
|
|
648
|
+
return found ? interval : undefined;
|
|
434
649
|
}
|
|
435
650
|
let candidate = lower.inclusive ? lower.value : step(lower.value, 1);
|
|
436
651
|
for (let tried = 0; tried <= unequal.length; tried += 1) {
|
|
@@ -518,14 +733,16 @@ export function witnessesOf(way, scope, inputCase, combinations = FEASIBILITY_CO
|
|
|
518
733
|
groups.get(key).constraints.push(constraint);
|
|
519
734
|
};
|
|
520
735
|
for (const step of way.steps) {
|
|
521
|
-
const placed = placedConstraintOf(step);
|
|
736
|
+
const placed = placedConstraintOf(step, scope);
|
|
522
737
|
if (placed === undefined ||
|
|
523
738
|
placed.measure !== "value" ||
|
|
524
|
-
|
|
739
|
+
placed.constraints.some(constraint => constraint.operator !== "==" && constraint.operator !== "!=") ||
|
|
525
740
|
finiteDomainAt(scope, placed.path) === undefined) {
|
|
526
741
|
return undefined;
|
|
527
742
|
}
|
|
528
|
-
|
|
743
|
+
for (const constraint of placed.constraints) {
|
|
744
|
+
constrain(placed.path, constraint);
|
|
745
|
+
}
|
|
529
746
|
}
|
|
530
747
|
if (inputCase !== undefined && groups.has(JSON.stringify([inputCase.discriminant]))) {
|
|
531
748
|
constrain([inputCase.discriminant], { operator: "==", bound: inputCase.tag });
|
|
@@ -540,6 +757,25 @@ export function witnessesOf(way, scope, inputCase, combinations = FEASIBILITY_CO
|
|
|
540
757
|
}
|
|
541
758
|
})();
|
|
542
759
|
}
|
|
760
|
+
// What finiteDomainAt answers, or, for a position inside a case of a sum field, the values it takes
|
|
761
|
+
// in the one schema every case declaring it gives it.
|
|
762
|
+
function finiteDomainThrough(scope, path) {
|
|
763
|
+
const direct = finiteDomainAt(scope, path);
|
|
764
|
+
if (direct !== undefined)
|
|
765
|
+
return direct;
|
|
766
|
+
const owners = declaredAt(scope, path.slice(0, -1));
|
|
767
|
+
const key = path[path.length - 1];
|
|
768
|
+
if (owners.length === 0 || key === undefined)
|
|
769
|
+
return undefined;
|
|
770
|
+
if (owners.every(owner => isVariantsSchema(owner) && owner.discriminant === key)) {
|
|
771
|
+
return [...new Set(owners.flatMap(owner => owner.variantTags))];
|
|
772
|
+
}
|
|
773
|
+
const leaves = declaredAt(scope, path);
|
|
774
|
+
if (leaves.length === 0 || leaves.some(leaf => leaf !== leaves[0] || leaf.invariants.length > 0))
|
|
775
|
+
return undefined;
|
|
776
|
+
const leaf = leaves[0];
|
|
777
|
+
return leaf.kind === "boolean" ? [true, false] : leaf.kind === "enum" ? leaf.values : undefined;
|
|
778
|
+
}
|
|
543
779
|
function finiteDomainAt(scope, path) {
|
|
544
780
|
const discriminated = sumOwning(scope, path);
|
|
545
781
|
if (discriminated !== undefined) {
|
|
@@ -547,20 +783,24 @@ function finiteDomainAt(scope, path) {
|
|
|
547
783
|
const discriminant = path[path.length - 1];
|
|
548
784
|
const refusing = [...discriminated.invariants, ...inheritedAt(scope, path.slice(0, -1))]
|
|
549
785
|
.flatMap(conjuncts)
|
|
550
|
-
.filter(rule =>
|
|
786
|
+
.filter(rule => deepEqual(boundTermPath(rule), [discriminant]));
|
|
551
787
|
return discriminated.variantTags.filter(tag => refusing.every(rule => holds(rule, { [discriminant]: tag })));
|
|
552
788
|
}
|
|
553
|
-
const schema =
|
|
789
|
+
const schema = schemaThrough(scope, path);
|
|
554
790
|
if (schema?.kind === "boolean") {
|
|
555
791
|
return admittedBy([true, false], schema, scope, path);
|
|
556
792
|
}
|
|
557
793
|
if (schema?.kind === "enum") {
|
|
558
794
|
return admittedBy(schema.values, schema, scope, path);
|
|
559
795
|
}
|
|
796
|
+
// A sum's discriminant read where the way settled its case is that case's tag alone.
|
|
797
|
+
if (schema?.kind === "literal") {
|
|
798
|
+
return admittedBy([schema.value], schema, scope, path);
|
|
799
|
+
}
|
|
560
800
|
return undefined;
|
|
561
801
|
}
|
|
562
|
-
// A rule over finite positions: each comparison reads one of them
|
|
563
|
-
// constant with == or !=, combined with and/or/not. Its positions, or
|
|
802
|
+
// A rule over finite positions: each comparison reads one of them, or what
|
|
803
|
+
// its transforms make of it, against a constant with == or !=, combined with and/or/not. Its positions, or
|
|
564
804
|
// undefined when any part of it reads something else.
|
|
565
805
|
function finitePathsOf(rule, scope, prefix) {
|
|
566
806
|
switch (rule.kind) {
|
|
@@ -572,13 +812,15 @@ function finitePathsOf(rule, scope, prefix) {
|
|
|
572
812
|
}
|
|
573
813
|
const paths = sides.map(side => [...prefix, ...side.path]);
|
|
574
814
|
return (rule.operator === "==" || rule.operator === "!=") &&
|
|
575
|
-
sides.every(side => side.measure
|
|
815
|
+
sides.every(side => !counts(side.measure)) &&
|
|
576
816
|
paths.every(path => finiteDomainAt(scope, path) !== undefined)
|
|
577
817
|
? paths
|
|
578
818
|
: undefined;
|
|
579
819
|
}
|
|
580
820
|
const normalized = normalize(rule);
|
|
581
|
-
|
|
821
|
+
// A transformed value, `lowercase($.level)`, is read off each value the
|
|
822
|
+
// combinations try, as the invariant is held with `holds`.
|
|
823
|
+
if (normalized === undefined || counts(normalized.measure)) {
|
|
582
824
|
return undefined;
|
|
583
825
|
}
|
|
584
826
|
if (normalized.operator !== "==" && normalized.operator !== "!=") {
|
|
@@ -605,10 +847,17 @@ function finitePathsOf(rule, scope, prefix) {
|
|
|
605
847
|
// many" when there are more combinations to try than the limit. Unless
|
|
606
848
|
// `whole`, positions no such invariant reaches are left out, and nothing is
|
|
607
849
|
// tried when there are none.
|
|
608
|
-
function jointAssignments(groups, scope, combinations, prefer = () => undefined, whole = false) {
|
|
609
|
-
const joint = jointInvariantsOf(scope)
|
|
850
|
+
function jointAssignments(groups, scope, combinations, prefer = () => undefined, whole = false, equalities = []) {
|
|
851
|
+
const joint = [...jointInvariantsOf(scope), ...equalities.map((equality) => ({
|
|
852
|
+
prefix: [],
|
|
853
|
+
paths: [equality.left, equality.right],
|
|
854
|
+
rule: { kind: "compare", operator: equality.equal ? "==" : "!=", left: positionTerm(equality.left, "value"), right: positionTerm(equality.right, "value") },
|
|
855
|
+
}))];
|
|
610
856
|
const constrained = groups.filter(group => group.measure === "value" && finiteDomainAt(scope, group.path) !== undefined);
|
|
611
857
|
const component = new Map(constrained.map(group => [JSON.stringify(group.path), group.path]));
|
|
858
|
+
for (const equality of equalities)
|
|
859
|
+
for (const path of [equality.left, equality.right])
|
|
860
|
+
component.set(JSON.stringify(path), path);
|
|
612
861
|
const involved = [];
|
|
613
862
|
for (let grew = true; grew;) {
|
|
614
863
|
grew = false;
|
|
@@ -629,7 +878,7 @@ function jointAssignments(groups, scope, combinations, prefer = () => undefined,
|
|
|
629
878
|
}
|
|
630
879
|
const domains = positions.map(path => {
|
|
631
880
|
const keeps = constrained.filter(group => JSON.stringify(group.path) === JSON.stringify(path));
|
|
632
|
-
const kept =
|
|
881
|
+
const kept = finiteDomainThrough(scope, path).filter(value => keeps.every(group => group.constraints.every(item => holds({ kind: "compare", operator: item.operator, left: positionTerm([], "value"), right: item.bound }, value))));
|
|
633
882
|
const preferred = prefer(path);
|
|
634
883
|
return kept.includes(preferred) ? [preferred, ...kept.filter(value => value !== preferred)] : kept;
|
|
635
884
|
});
|
|
@@ -651,8 +900,8 @@ function jointAssignments(groups, scope, combinations, prefer = () => undefined,
|
|
|
651
900
|
return from(0, []);
|
|
652
901
|
}
|
|
653
902
|
// The first of the combinations jointAssignments tries, or "none".
|
|
654
|
-
function jointAssignment(groups, scope, combinations, prefer) {
|
|
655
|
-
const tried = jointAssignments(groups, scope, combinations, prefer);
|
|
903
|
+
function jointAssignment(groups, scope, combinations, prefer, equalities = []) {
|
|
904
|
+
const tried = jointAssignments(groups, scope, combinations, prefer, false, equalities);
|
|
656
905
|
if (tried === "too many") {
|
|
657
906
|
return "too many";
|
|
658
907
|
}
|
|
@@ -696,7 +945,7 @@ export function keepingInvariants(scope, before, after, combinations = FEASIBILI
|
|
|
696
945
|
const groups = related.map((path) => ({
|
|
697
946
|
path,
|
|
698
947
|
measure: "value",
|
|
699
|
-
constraints:
|
|
948
|
+
constraints: deepEqual(readAt(before, path), readAt(after, path))
|
|
700
949
|
? []
|
|
701
950
|
: [{ operator: "==", bound: readAt(after, path) }],
|
|
702
951
|
}));
|
|
@@ -728,7 +977,7 @@ export function keepingOrderings(scope, before, after) {
|
|
|
728
977
|
}
|
|
729
978
|
const form = differenceOf(rule);
|
|
730
979
|
const parts = form.parts.map(part => ({ ...part, path: [...prefix, ...part.path] }));
|
|
731
|
-
const numeric = parts.every(part => part.measure === "value" && ["integer", "number"].includes(
|
|
980
|
+
const numeric = parts.every(part => part.measure === "value" && ["integer", "number"].includes(schemaThrough(scope, part.path)?.kind ?? ""));
|
|
732
981
|
return parts.length >= 2 && numeric && typeof form.constant === "number"
|
|
733
982
|
? [{ rule: rule, parts, constant: form.constant }]
|
|
734
983
|
: [];
|
|
@@ -748,7 +997,7 @@ export function keepingOrderings(scope, before, after) {
|
|
|
748
997
|
}
|
|
749
998
|
const moving = broken.parts.find(part => Math.abs(part.coefficient) === 1 &&
|
|
750
999
|
!moved.has(JSON.stringify(part.path)) &&
|
|
751
|
-
|
|
1000
|
+
deepEqual(readAt(before, part.path), readAt(after, part.path)));
|
|
752
1001
|
if (moving === undefined) {
|
|
753
1002
|
return undefined;
|
|
754
1003
|
}
|
|
@@ -795,9 +1044,13 @@ function nearestKeeping(scope, path, operator, bound) {
|
|
|
795
1044
|
// Whether no combination the invariants relating finite positions keep gives
|
|
796
1045
|
// the position at `path` this value.
|
|
797
1046
|
export function refusedJointly(scope, path, value, combinations = FEASIBILITY_COMBINATION_LIMIT) {
|
|
798
|
-
return (
|
|
799
|
-
|
|
800
|
-
|
|
1047
|
+
return refusedTogether(scope, [{ path, value }], combinations);
|
|
1048
|
+
}
|
|
1049
|
+
// No combination the invariants relating finite positions keep gives every
|
|
1050
|
+
// one of these finite positions its value.
|
|
1051
|
+
export function refusedTogether(scope, coordinates, combinations = FEASIBILITY_COMBINATION_LIMIT) {
|
|
1052
|
+
return (coordinates.every(({ path }) => finiteDomainAt(scope, path) !== undefined) &&
|
|
1053
|
+
jointAssignment(coordinates.map(({ path, value }) => ({ path, measure: "value", constraints: [{ operator: "==", bound: value }] })), scope, combinations) === "none");
|
|
801
1054
|
}
|
|
802
1055
|
// The invariants the scope holds that relate two or more finite positions,
|
|
803
1056
|
// each with the positions it reads.
|
|
@@ -825,7 +1078,7 @@ export function finiteReach(decision, scope, combinations, fixed = []) {
|
|
|
825
1078
|
}
|
|
826
1079
|
const positions = [...distinctPaths([...read, ...fixed])];
|
|
827
1080
|
const invariants = fieldInvariants(scope, []);
|
|
828
|
-
const has = (path) => positions.some(other =>
|
|
1081
|
+
const has = (path) => positions.some(other => deepEqual(other, path));
|
|
829
1082
|
for (let grew = true; grew;) {
|
|
830
1083
|
grew = false;
|
|
831
1084
|
for (const { prefix, rule } of invariants) {
|
|
@@ -902,7 +1155,10 @@ function decisionPaths(decision) {
|
|
|
902
1155
|
return false;
|
|
903
1156
|
}
|
|
904
1157
|
paths.push(data.path);
|
|
905
|
-
|
|
1158
|
+
// A transformed value is read off each value of the domain as the guard
|
|
1159
|
+
// reads it (`lowercase($.level)` of each case of an enum); a string
|
|
1160
|
+
// has no domain, so its transformed read stays out of the plan.
|
|
1161
|
+
return !counts(data.measure);
|
|
906
1162
|
});
|
|
907
1163
|
case "not":
|
|
908
1164
|
return collect(rule.rule);
|