@toiroakr/chisel 0.2.0 → 0.3.1
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 +114 -10
- package/dist/absence.d.ts +1 -0
- package/dist/absence.js +39 -1
- package/dist/absence.js.map +1 -1
- package/dist/behavior.d.ts +5 -10
- package/dist/behavior.js +48 -225
- 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 +3 -1
- package/dist/border.js +47 -3
- package/dist/border.js.map +1 -1
- package/dist/bounds.js +4 -3
- package/dist/bounds.js.map +1 -1
- 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 +2 -0
- package/dist/cli.js +80 -11
- package/dist/cli.js.map +1 -1
- package/dist/codec.js +9 -3
- package/dist/codec.js.map +1 -1
- package/dist/codegen.js +2 -0
- package/dist/codegen.js.map +1 -1
- package/dist/composition.js +5 -4
- 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 +2 -2
- package/dist/data.js +5 -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/domain.d.ts +2 -2
- package/dist/domain.js +59 -19
- package/dist/domain.js.map +1 -1
- package/dist/ensures.js +1 -1
- package/dist/ensures.js.map +1 -1
- 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.js +205 -18
- package/dist/feasibility.js.map +1 -1
- package/dist/guard-borders.d.ts +2 -0
- package/dist/guard-borders.js +112 -24
- package/dist/guard-borders.js.map +1 -1
- package/dist/guard-scope.d.ts +5 -1
- package/dist/guard-scope.js +26 -6
- package/dist/guard-scope.js.map +1 -1
- 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 +16 -5
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/dist/interval.d.ts +1 -0
- package/dist/interval.js +44 -4
- 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.d.ts +25 -0
- package/dist/machine.js +88 -17
- package/dist/machine.js.map +1 -1
- package/dist/model.d.ts +39 -5
- package/dist/model.js +268 -59
- 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 +9 -1
- package/dist/outcomes.js +92 -10
- package/dist/outcomes.js.map +1 -1
- package/dist/pairs.js +2 -1
- package/dist/pairs.js.map +1 -1
- package/dist/partition.js +12 -9
- 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.js +189 -37
- 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/rewrites.d.ts +41 -0
- package/dist/rewrites.js +180 -0
- package/dist/rewrites.js.map +1 -0
- package/dist/rule.d.ts +29 -6
- package/dist/rule.js +145 -5
- package/dist/rule.js.map +1 -1
- package/dist/runtime.d.ts +4 -4
- package/dist/runtime.js +3 -3
- package/dist/runtime.js.map +1 -1
- package/dist/schema.d.ts +44 -28
- package/dist/schema.js +42 -109
- package/dist/schema.js.map +1 -1
- package/dist/specification.d.ts +11 -1
- package/dist/specification.js +391 -26
- 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.js +5 -5
- package/dist/temporal.js.map +1 -1
- 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 +46 -6
- package/dist/tla.js +250 -49
- package/dist/tla.js.map +1 -1
- package/dist/verification.d.ts +2 -0
- package/dist/verification.js +2 -0
- package/dist/verification.js.map +1 -1
- package/dist/ways.d.ts +4 -1
- package/dist/ways.js +23 -8
- package/dist/ways.js.map +1 -1
- package/dist/world.d.ts +2 -2
- package/dist/world.js +13 -17
- package/dist/world.js.map +1 -1
- package/package.json +23 -7
- package/schema/report.schema.json +169 -1
package/dist/specification.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { placeholderForOf, placeholderOf } from "./placeholders.js";
|
|
2
|
+
import { answersOf, callsIn, childrenOf, fieldsTurnedOn, isIteration, iterationsOf, nodeOf, localRoots, localsOf, writtenArgument } from "./model.js";
|
|
2
3
|
import { rangeOf } from "./interval.js";
|
|
3
4
|
import { fractionOf } from "./exact.js";
|
|
4
5
|
import { selectedTag, taggedCase, verify } from "./proof.js";
|
|
@@ -6,15 +7,21 @@ import { constantsOf, domainOf } from "./domain.js";
|
|
|
6
7
|
import { pairCoverage, PAIR_LIMIT } from "./pairs.js";
|
|
7
8
|
import { deepEqual } from "./equal.js";
|
|
8
9
|
import { WAY_LIMIT, describeWay, eachWayOf, sameSteps } from "./ways.js";
|
|
10
|
+
import { changeOf } from "./changes.js";
|
|
11
|
+
import { isOutOfRoom } from "./exact.js";
|
|
12
|
+
import { foldsOf, runWalk, tells, tookSecond, walks as walkRewrites, walksOf } from "./rewrites.js";
|
|
13
|
+
import { stopsOf } from "./stops.js";
|
|
9
14
|
import { answerFrom, fakeIssuesOf, fakeWarningsOf } from "./dependency.js";
|
|
10
15
|
import { answerSchema } from "./guard-scope.js";
|
|
11
16
|
import { comparisonsNotReadOf, ensuresBordersOf, invariantContradictionsOf, mayBeLeftOut, invariantPairBordersOf, guardBordersOf, guardPartitionsOf, feasibilityScope, } from "./guard-borders.js";
|
|
17
|
+
import { brokenProtocol } from "./protocol.js";
|
|
12
18
|
import { SpecificationError, TodoDecision, brokenEnsures, comparisonsReached, isCaseOnly, isTodo, perform, runTraced, traceSync, } from "./behavior.js";
|
|
19
|
+
import { isDecimal } from "./rule.js";
|
|
13
20
|
import { DEPS, localLabel, describeRule, describeTerm, differenceOf, holds, withDeps, isTerm, positionData, positionOf, positionTerm, termData, termPaths, pathsRead } from "./rule.js";
|
|
14
21
|
import { emptiedBy, normalize } from "./border.js";
|
|
15
22
|
import { FEASIBILITY_COMBINATION_LIMIT, feasibilityOf, finiteReach, keepingInvariants, keepingOrderings, refusedJointly, tooManyWays, unreached, witnessesOf } from "./feasibility.js";
|
|
16
23
|
import { readEnsures } from "./ensures.js";
|
|
17
|
-
import { allOnOneSide, lineTheRowsAllow, partingsOf, spelled } from "./beside.js";
|
|
24
|
+
import { allOnOneSide, computationOf, lineTheRowsAllow, partingsOf, spelled } from "./beside.js";
|
|
18
25
|
import { coordinatesIn, excludedCases, positionsOf, writeExactly } from "./partition.js";
|
|
19
26
|
import { isVariantsSchema, object, schemaAtPath, tagOf } from "./schema.js";
|
|
20
27
|
async function runAndCompare(definition, name, given, expected, subject) {
|
|
@@ -85,6 +92,10 @@ export async function check(specification, options = {}) {
|
|
|
85
92
|
const combinations = positiveLimit("feasibility.combinations", options.feasibility?.combinations, FEASIBILITY_COMBINATION_LIMIT);
|
|
86
93
|
const definition = specification.examples.behavior;
|
|
87
94
|
const wayLimit = positiveLimit("feasibility.ways", options.feasibility?.ways, WAY_LIMIT);
|
|
95
|
+
const progress = (phase) => options.progress?.(`${definition.name}: ${phase}`);
|
|
96
|
+
progress("例の行を実行中");
|
|
97
|
+
const walkRows = [];
|
|
98
|
+
const stopRows = [];
|
|
88
99
|
const coveredInputs = new Set();
|
|
89
100
|
const coveredResults = new Set();
|
|
90
101
|
const coveredEffects = new Set();
|
|
@@ -203,6 +214,9 @@ export async function check(specification, options = {}) {
|
|
|
203
214
|
if (open !== undefined) {
|
|
204
215
|
incompleteness.push({ kind: "row not run", subject: row.name, reason: `判断が未定(${open})` });
|
|
205
216
|
}
|
|
217
|
+
else if (isOutOfRoom(error)) {
|
|
218
|
+
incompleteness.push({ kind: "out of room", subject: row.name, reason: error.message });
|
|
219
|
+
}
|
|
206
220
|
else {
|
|
207
221
|
const message = error instanceof Error ? error.message : String(error);
|
|
208
222
|
failures.push({ name: row.name, message });
|
|
@@ -240,6 +254,10 @@ export async function check(specification, options = {}) {
|
|
|
240
254
|
message: `Example breaks ensures ${broken.name}: ${describeRule(broken.rule, "")}`,
|
|
241
255
|
});
|
|
242
256
|
}
|
|
257
|
+
const expected = row.expect;
|
|
258
|
+
const unkept = brokenProtocol(definition.protocol, expected.effects.map(effect => (isVariantsSchema(definition.effects) ? tagOf(definition.effects, effect) : undefined) ?? ""), rule => holds(rule, { input: row.given, value: expected.result }));
|
|
259
|
+
if (unkept !== undefined)
|
|
260
|
+
failures.push({ name: row.name, message: `Example breaks protocol ${unkept.name}` });
|
|
243
261
|
const resultTag = caseOnly ?? (isVariantsSchema(definition.result) ? tagOf(definition.result, row.expect.result) : undefined);
|
|
244
262
|
if (resultTag !== undefined) {
|
|
245
263
|
coveredResults.add(resultTag);
|
|
@@ -260,6 +278,7 @@ export async function check(specification, options = {}) {
|
|
|
260
278
|
incompleteness.push({ kind: "row not run", subject: row.name, reason: unstood });
|
|
261
279
|
}
|
|
262
280
|
else if (implementation !== undefined) {
|
|
281
|
+
stopRows.push({ given: row.given, deps: standIns(row) });
|
|
263
282
|
const { actual, failure, error } = await runAndCompare(definition, row.name, row.given, row.expect, async (input) => {
|
|
264
283
|
const traced = await runTraced(implementation, input, standIns(row));
|
|
265
284
|
armsMet.push(...traced.arms);
|
|
@@ -288,6 +307,7 @@ export async function check(specification, options = {}) {
|
|
|
288
307
|
}
|
|
289
308
|
if (failure === undefined) {
|
|
290
309
|
verifiedInputs.add(inputTag);
|
|
310
|
+
walkRows.push({ name: row.name, given: row.given, deps: standIns(row), expected: row.expect });
|
|
291
311
|
const disregard = await disregardBroken(implementation, row, actual, standIns(row), limits);
|
|
292
312
|
if (disregard.kind === "broken") {
|
|
293
313
|
failures.push(disregard.failure);
|
|
@@ -301,6 +321,9 @@ export async function check(specification, options = {}) {
|
|
|
301
321
|
if (open !== undefined) {
|
|
302
322
|
incompleteness.push({ kind: "row not run", subject: row.name, reason: `判断が未定(${open})` });
|
|
303
323
|
}
|
|
324
|
+
else if (isOutOfRoom(error)) {
|
|
325
|
+
incompleteness.push({ kind: "out of room", subject: row.name, reason: error.message });
|
|
326
|
+
}
|
|
304
327
|
else if (failure !== undefined) {
|
|
305
328
|
failures.push(failure);
|
|
306
329
|
if (actual === undefined) {
|
|
@@ -402,7 +425,8 @@ export async function check(specification, options = {}) {
|
|
|
402
425
|
})),
|
|
403
426
|
};
|
|
404
427
|
}));
|
|
405
|
-
const
|
|
428
|
+
const guardDrawn = specification.implementation === undefined ? [] : guardBordersOf(specification.implementation);
|
|
429
|
+
const guardBorders = guardDrawn.map((drawn) => {
|
|
406
430
|
const reachedIt = reached.filter(item => item.comparison.rule === drawn.comparison && item.tag === drawn.origin?.tag);
|
|
407
431
|
const coordinates = reachedIt.map(item => drawn.coordinateOf(item.comparison));
|
|
408
432
|
const points = drawn.border.points.map(point => {
|
|
@@ -427,7 +451,7 @@ export async function check(specification, options = {}) {
|
|
|
427
451
|
...(beside === undefined ? {} : { beside }),
|
|
428
452
|
};
|
|
429
453
|
});
|
|
430
|
-
borders.push(...guardBorders);
|
|
454
|
+
borders.push(...toldOnce(guardBorders, guardDrawn));
|
|
431
455
|
// Not met by reaching a comparison, as a guard border is: what an ensures
|
|
432
456
|
// clause or an input invariant states holds of every input of the case.
|
|
433
457
|
const writtenCoverage = (drawn) => {
|
|
@@ -470,7 +494,11 @@ export async function check(specification, options = {}) {
|
|
|
470
494
|
partitions.every(partition => partition.kind !== "divided" || partition.missing.length === 0) &&
|
|
471
495
|
borders.every(border => border.points.every(point => point.status !== "gap")) &&
|
|
472
496
|
borders.every(border => border.beside?.status !== "not told");
|
|
497
|
+
progress("分岐と道筋を計測中");
|
|
473
498
|
const plans = plansOf(specification.implementation, combinations, wayLimit);
|
|
499
|
+
const toBeChangedFirst = changesFrom(specification.implementation, plans, wayLimit);
|
|
500
|
+
progress("foldの書き換えを確かめ中");
|
|
501
|
+
const walks = walksOf(specification.implementation, walkRows, (expected, actual) => answers(definition, expected, actual), given => tagOf(definition.input, given));
|
|
474
502
|
const arms = measureArms(specification.implementation, armsMet, armsOwed, combinations, plans, usableFakes);
|
|
475
503
|
const rulesMeasure = measureRules(specification.implementation, waysMet, waysOwed, combinations, plans, usableFakes);
|
|
476
504
|
const lines = [
|
|
@@ -486,14 +514,19 @@ export async function check(specification, options = {}) {
|
|
|
486
514
|
const comparisons = unreadComparisons.length === 0
|
|
487
515
|
? { status: "complete" }
|
|
488
516
|
: { status: "partial", notRead: unreadComparisons };
|
|
517
|
+
progress("構築を証明中");
|
|
489
518
|
const constructions = specification.implementation === undefined ? { status: "undetermined", decisions: [] } : verify(specification.implementation, { candidates: combinations, ways: wayLimit });
|
|
490
|
-
|
|
519
|
+
progress("停止を調べ中");
|
|
520
|
+
const stops = stopsOf(specification.implementation, stopRows, { candidates: combinations, proof: constructions });
|
|
521
|
+
const verdict = !adequate || armGap || constructions.status === "refuted" || walks.some(walk => walk.status === "not told") || stops.some(stop => stop.status === "may stop")
|
|
491
522
|
? "not_satisfied"
|
|
492
523
|
: constructions.status !== "verified" || comparisons.status === "partial" ||
|
|
493
524
|
pairAnalysis.measure.status === "partial" ||
|
|
494
525
|
armUndecided ||
|
|
526
|
+
walks.some(walk => walk.status === "undecided") ||
|
|
527
|
+
stops.some(stop => stop.status === "not resolved") ||
|
|
495
528
|
externals.length > 0 ||
|
|
496
|
-
incompleteness.some(item => item.kind === "disregards not checked")
|
|
529
|
+
incompleteness.some(item => item.kind === "disregards not checked" || item.kind === "out of room")
|
|
497
530
|
? "undetermined"
|
|
498
531
|
: arms.status === "complete" ||
|
|
499
532
|
(arms.status === "unavailable" && arms.reason === "not applicable")
|
|
@@ -518,6 +551,9 @@ export async function check(specification, options = {}) {
|
|
|
518
551
|
pairs: countPairs(pairablesOf(positions, guardPartitions), answeredGivens),
|
|
519
552
|
fakeIssues: fakeIssues.map(item => item.issue),
|
|
520
553
|
fakeWarnings: fakeWarningsOf(definition.dependencies, specification.fakes),
|
|
554
|
+
toBeChangedFirst,
|
|
555
|
+
walks,
|
|
556
|
+
stops,
|
|
521
557
|
evidence: {
|
|
522
558
|
input: definition.input.variantTags.filter(tag => !refusedInputs.includes(tag)).map(tag => ({
|
|
523
559
|
case: tag,
|
|
@@ -545,10 +581,31 @@ export async function check(specification, options = {}) {
|
|
|
545
581
|
verdict,
|
|
546
582
|
};
|
|
547
583
|
}
|
|
584
|
+
// What to change in the model before measuring it: the decisions `check`
|
|
585
|
+
// would leave unmeasured for having more ways than the limit, each with where
|
|
586
|
+
// its ways multiply and which part, declared as a behavior of its own, leaves
|
|
587
|
+
// the rest within the limit. Read off the shape of the model, without running
|
|
588
|
+
// a row, so it can be said before the measurement and is not changed by it.
|
|
589
|
+
export function modelChanges(specification, options = {}) {
|
|
590
|
+
const combinations = positiveLimit("feasibility.combinations", options.feasibility?.combinations, FEASIBILITY_COMBINATION_LIMIT);
|
|
591
|
+
const wayLimit = positiveLimit("feasibility.ways", options.feasibility?.ways, WAY_LIMIT);
|
|
592
|
+
return changesFrom(specification.implementation, plansOf(specification.implementation, combinations, wayLimit), wayLimit);
|
|
593
|
+
}
|
|
594
|
+
function changesFrom(implementation, plans, wayLimit) {
|
|
595
|
+
if (implementation === undefined || implementation.pipeline !== undefined || implementation.external !== undefined)
|
|
596
|
+
return [];
|
|
597
|
+
return decisionsWithCases(implementation).flatMap(([decision]) => {
|
|
598
|
+
if (decision.kind !== "rules" || plans.get(decision)?.kind !== "too many")
|
|
599
|
+
return [];
|
|
600
|
+
const change = changeOf(decision, wayLimit);
|
|
601
|
+
return change === undefined ? [] : [change];
|
|
602
|
+
});
|
|
603
|
+
}
|
|
548
604
|
export function generate(target, implementation, options = {}) {
|
|
549
605
|
const combinations = positiveLimit("feasibility.combinations", options.feasibility?.combinations, FEASIBILITY_COMBINATION_LIMIT);
|
|
550
606
|
const definition = target.kind === "behavior" ? target : target.behavior;
|
|
551
607
|
const wayLimit = positiveLimit("feasibility.ways", options.feasibility?.ways, WAY_LIMIT);
|
|
608
|
+
options.progress?.(`${definition.name}: 行を組み立て中`);
|
|
552
609
|
const rows = target.kind === "behavior" ? [] : target.rows.filter(row => definition.input.parse(row.given).success);
|
|
553
610
|
const existing = new Set(rows
|
|
554
611
|
.map(row => tagOf(definition.input, row.given))
|
|
@@ -557,7 +614,7 @@ export function generate(target, implementation, options = {}) {
|
|
|
557
614
|
const origins = answeredRows.map(row => row.given);
|
|
558
615
|
const standIns = Object.fromEntries(Object.entries(definition.dependencies)
|
|
559
616
|
.filter(([, declared]) => declared.takes === "nothing")
|
|
560
|
-
.map(([name, declared]) => [name, declared.output
|
|
617
|
+
.map(([name, declared]) => [name, placeholderOf(declared.output, name)]));
|
|
561
618
|
// Stand-ins a search ran a row it found with, which the row is offered with.
|
|
562
619
|
const searchedStandIns = new Map();
|
|
563
620
|
const withFrom = (origin) => {
|
|
@@ -569,7 +626,7 @@ export function generate(target, implementation, options = {}) {
|
|
|
569
626
|
return Object.keys(standing).length === 0 && written === undefined ? {} : { with: standing };
|
|
570
627
|
};
|
|
571
628
|
const originFor = (position) => origins.find(given => position.valuesIn(given).length > 0) ??
|
|
572
|
-
definition.input
|
|
629
|
+
placeholderOf(definition.input);
|
|
573
630
|
const fakeTables = new Map((options.fakes ?? [])
|
|
574
631
|
.filter(table => table.behavior === definition.name)
|
|
575
632
|
.filter(table => !fakeIssuesOf(definition.dependencies, definition.name, options.fakes ?? []).some(item => item.table.dependency === table.dependency))
|
|
@@ -636,7 +693,7 @@ export function generate(target, implementation, options = {}) {
|
|
|
636
693
|
const guardRead = guardReadSegmentsOf(implementation);
|
|
637
694
|
const refused = excludedCases(definition.input);
|
|
638
695
|
for (const tag of definition.input.variantTags.filter(tag => !existing.has(tag) && !refused.includes(tag))) {
|
|
639
|
-
const given = definition.input
|
|
696
|
+
const given = placeholderForOf(definition.input, tag);
|
|
640
697
|
offer({ name: `${definition.name}: ${tag}`, given, reason: `${tag}の期待結果を人間が決める必要があります`, ...withFrom(given) }, given);
|
|
641
698
|
}
|
|
642
699
|
for (const position of measuredPositionsOf(definition, guardDivided, guardRead, combinations)) {
|
|
@@ -683,7 +740,7 @@ export function generate(target, implementation, options = {}) {
|
|
|
683
740
|
}
|
|
684
741
|
}
|
|
685
742
|
}
|
|
686
|
-
const positionsByPath = new Map(positionsOf(definition.input).map(position => [trailKey(position.segments), position]));
|
|
743
|
+
const positionsByPath = new Map(positionsOf(definition.input, { containers: true }).map(position => [trailKey(position.segments), position]));
|
|
687
744
|
for (const drawn of implementation === undefined ? [] : guardPartitionsOf(implementation)) {
|
|
688
745
|
const position = positionsByPath.get(trailKey(drawn.segments));
|
|
689
746
|
if (position === undefined) {
|
|
@@ -691,7 +748,11 @@ export function generate(target, implementation, options = {}) {
|
|
|
691
748
|
}
|
|
692
749
|
for (const item of drawn.classes) {
|
|
693
750
|
const standsIn = [...rows, ...generated].some(row => position.valuesIn(row.given).some(value => value !== undefined && item.contains(value)));
|
|
694
|
-
if (!standsIn) {
|
|
751
|
+
if (!standsIn && item.witness === undefined) {
|
|
752
|
+
// Owed all the same: no law refutes it, though no value was found (ADR-0130).
|
|
753
|
+
notComposed.push(`${drawn.path} = ${item.name}: スキーマが受け付ける値が見つからない`);
|
|
754
|
+
}
|
|
755
|
+
else if (!standsIn) {
|
|
695
756
|
const origin = originFor(position);
|
|
696
757
|
offer({
|
|
697
758
|
name: `${definition.name}: ${drawn.path} = ${item.name}`,
|
|
@@ -702,10 +763,13 @@ export function generate(target, implementation, options = {}) {
|
|
|
702
763
|
}
|
|
703
764
|
}
|
|
704
765
|
}
|
|
766
|
+
const toldComputations = new Set();
|
|
767
|
+
const untold = [];
|
|
705
768
|
for (const drawn of implementation === undefined ? [] : guardBordersOf(implementation)) {
|
|
706
769
|
const reachedBy = (given, deps) => tagOf(definition.input, given) === drawn.origin?.tag
|
|
707
770
|
? comparisonsReached(implementation, given, tracedWith(deps)).filter(item => item.rule === drawn.comparison)
|
|
708
771
|
: [];
|
|
772
|
+
const searchNotes = new Map();
|
|
709
773
|
for (const point of drawn.border.points) {
|
|
710
774
|
if (point.status !== "owed" || point.witness === undefined) {
|
|
711
775
|
continue;
|
|
@@ -715,7 +779,7 @@ export function generate(target, implementation, options = {}) {
|
|
|
715
779
|
continue;
|
|
716
780
|
}
|
|
717
781
|
const origin = origins.find(given => reachedBy(given, withFrom(given).with).length > 0) ??
|
|
718
|
-
definition.input
|
|
782
|
+
placeholderOf(definition.input);
|
|
719
783
|
const candidates = sidesOf(drawn)
|
|
720
784
|
.map(side => drawn.compose(origin, point.witness, withFrom(origin).with, side))
|
|
721
785
|
.filter(candidate => candidate !== undefined);
|
|
@@ -728,22 +792,36 @@ export function generate(target, implementation, options = {}) {
|
|
|
728
792
|
return undefined;
|
|
729
793
|
const hit = searchedWays(implementation, drawn.origin.tag, drawn.origin.decision, combinations, usableFakes).witnessed
|
|
730
794
|
.find(item => item.comparison.rule === drawn.comparison && point.contains(drawn.coordinateOf(item.comparison)) && definition.input.parse(item.given).success);
|
|
731
|
-
if (hit
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
795
|
+
if (hit !== undefined) {
|
|
796
|
+
if (hit.with !== undefined)
|
|
797
|
+
searchedStandIns.set(hit.given, hit.with);
|
|
798
|
+
return hit.given;
|
|
799
|
+
}
|
|
800
|
+
// None reached the point: step from the runs nearest to it, one
|
|
801
|
+
// numeric field at a time, toward it (Souther 0.5.0's rows beside the
|
|
802
|
+
// nearest ones), and say what was tried where that reaches it neither.
|
|
803
|
+
const tried = searchedWays(implementation, drawn.origin.tag, drawn.origin.decision, combinations, usableFakes).witnessed
|
|
804
|
+
.filter(item => item.comparison.rule === drawn.comparison && definition.input.parse(item.given).success);
|
|
805
|
+
const stepped = besideTheNearest(definition, drawn, point, tried, (given, deps) => reachedBy(given, deps).map(item => drawn.coordinateOf(item)));
|
|
806
|
+
if (stepped.given !== undefined) {
|
|
807
|
+
if (stepped.with !== undefined)
|
|
808
|
+
searchedStandIns.set(stepped.given, stepped.with);
|
|
809
|
+
return stepped.given;
|
|
810
|
+
}
|
|
811
|
+
searchNotes.set(point, stepped.tried);
|
|
812
|
+
return undefined;
|
|
736
813
|
};
|
|
737
814
|
const given = candidates.find(candidate => definition.input.parse(candidate).success && reaches(candidate)) ??
|
|
738
815
|
askingFakes(drawn.origin?.tag ?? "", drawn.origin?.decision, [
|
|
739
816
|
...origins.filter(candidate => tagOf(definition.input, candidate) === drawn.origin?.tag),
|
|
740
|
-
...(drawn.origin === undefined ? [] : [definition.input
|
|
817
|
+
...(drawn.origin === undefined ? [] : [placeholderForOf(definition.input, drawn.origin.tag)]),
|
|
741
818
|
], reaches) ??
|
|
742
819
|
searchedPoint() ??
|
|
743
820
|
candidates.find(candidate => !definition.input.parse(candidate).success) ??
|
|
744
821
|
candidates.find(candidate => definition.input.parse(candidate).success);
|
|
745
822
|
if (given === undefined) {
|
|
746
|
-
|
|
823
|
+
const note = searchNotes.get(point);
|
|
824
|
+
notComposed.push(`${drawn.path} ${point.role} (${point.relation})${askedOf(drawn.segments.flatMap(segment => segment.startsWith(".#local:") ? [segment.slice(1)] : []))}${note === undefined ? "" : ` — ${note}`}`);
|
|
747
825
|
}
|
|
748
826
|
else {
|
|
749
827
|
offer({
|
|
@@ -763,9 +841,19 @@ export function generate(target, implementation, options = {}) {
|
|
|
763
841
|
const due = owed.some(standsAt) &&
|
|
764
842
|
owed.every(point => standsAt(point) || unmetStatus(pointFeasibility(drawn, point, implementation, combinations, wayLimit, usableFakes)).status === "no row owed");
|
|
765
843
|
const found = due ? besideOf(definition, implementation, drawn, items) : undefined;
|
|
844
|
+
const computation = computationOf(drawn.origin?.tag, drawn.form.parts);
|
|
845
|
+
if (found?.beside.status === "told")
|
|
846
|
+
toldComputations.add(computation);
|
|
766
847
|
if (found?.beside.status !== "not told") {
|
|
767
848
|
continue;
|
|
768
849
|
}
|
|
850
|
+
untold.push({ computation, drawn, found: found });
|
|
851
|
+
}
|
|
852
|
+
// A computation cut at several places owes its weights once (ADR-0124): no
|
|
853
|
+
// row is offered beside a border whose computation another border tells.
|
|
854
|
+
for (const { computation, drawn, found } of untold) {
|
|
855
|
+
if (toldComputations.has(computation))
|
|
856
|
+
continue;
|
|
769
857
|
const label = `${drawn.path} 隣の線 (${found.beside.another})`;
|
|
770
858
|
if (found.given === undefined) {
|
|
771
859
|
notComposed.push(label);
|
|
@@ -789,7 +877,7 @@ export function generate(target, implementation, options = {}) {
|
|
|
789
877
|
if (standsAt) {
|
|
790
878
|
continue;
|
|
791
879
|
}
|
|
792
|
-
const origin = origins.find(under) ?? definition.input
|
|
880
|
+
const origin = origins.find(under) ?? placeholderForOf(definition.input, drawn.segments[0].slice(1));
|
|
793
881
|
const candidates = sidesOf(drawn)
|
|
794
882
|
.map(side => drawn.compose(origin, point.witness, withFrom(origin).with, side))
|
|
795
883
|
.filter(candidate => candidate !== undefined);
|
|
@@ -846,7 +934,7 @@ export function generate(target, implementation, options = {}) {
|
|
|
846
934
|
};
|
|
847
935
|
const origins_ = [
|
|
848
936
|
...origins.filter(given => tagOf(definition.input, given) === tag),
|
|
849
|
-
definition.input
|
|
937
|
+
placeholderForOf(definition.input, tag),
|
|
850
938
|
];
|
|
851
939
|
const plan = plans.get(decision);
|
|
852
940
|
if (plan?.kind === "too many") {
|
|
@@ -893,7 +981,7 @@ export function generate(target, implementation, options = {}) {
|
|
|
893
981
|
// holds that one element, taken from what the rows hold or moved into each
|
|
894
982
|
// class of the element's positions.
|
|
895
983
|
function composeElement(way) {
|
|
896
|
-
const values = way.within
|
|
984
|
+
const values = isIteration(way.within) ? way.within.values : undefined;
|
|
897
985
|
const position = isTerm(values) ? positionData(values) : undefined;
|
|
898
986
|
if (position === undefined || position.measure !== "value" || position.path.some(key => key.startsWith("#")))
|
|
899
987
|
return undefined;
|
|
@@ -985,8 +1073,163 @@ export function generate(target, implementation, options = {}) {
|
|
|
985
1073
|
reason: "組み合わせの期待結果を人間が決める必要があります", ...withFrom(given) });
|
|
986
1074
|
}
|
|
987
1075
|
notComposed.push(...pairs.measure.notRead, ...pairs.measure.obligations.filter(pair => pair.status === "undecided").map(pair => `${pair.positions.join(" × ")}: ${pair.classes.join(" × ")} (${pair.reason})`));
|
|
1076
|
+
if (implementation !== undefined) {
|
|
1077
|
+
const walked = walkRowsFor(definition, implementation, answeredRows, row => tracedWith(withFrom(row.given).with), rows, generated);
|
|
1078
|
+
for (const { origin, ...row } of walked.rows)
|
|
1079
|
+
offer({ ...row, ...withFrom(origin) });
|
|
1080
|
+
notComposed.push(...walked.notComposed);
|
|
1081
|
+
for (const { origin, ...row } of suggestedRowsFor(definition, implementation, rows, [...rows.map(row => row.given), ...generated.map(row => row.given)])) {
|
|
1082
|
+
generated.push({ ...row, ...withFrom(origin) });
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
988
1085
|
return { rows: generated, notComposed };
|
|
989
1086
|
}
|
|
1087
|
+
// The inputs a called behavior's recorded rows were written with, asked in
|
|
1088
|
+
// its caller: each call of a dependency declared with its examples
|
|
1089
|
+
// (`dependency(checkStockExamples)`) has the argument a recorded row asks
|
|
1090
|
+
// written into a row of the case that makes the call. Such a row owes nothing
|
|
1091
|
+
// and is marked so; it is offered where no row asks it yet.
|
|
1092
|
+
function suggestedRowsFor(definition, implementation, rows, taken) {
|
|
1093
|
+
const suggested = [];
|
|
1094
|
+
const seen = [...taken];
|
|
1095
|
+
for (const [decision, tags] of decisionsWithCases(implementation)) {
|
|
1096
|
+
const expression = decision.kind === "rules" ? decision.expression : undefined;
|
|
1097
|
+
if (expression === undefined)
|
|
1098
|
+
continue;
|
|
1099
|
+
const origins = rows.filter(row => tags.includes(tagOf(definition.input, row.given) ?? ""));
|
|
1100
|
+
for (const call of callsIn(expression)) {
|
|
1101
|
+
const declared = definition.dependencies[call.dependency];
|
|
1102
|
+
for (const recorded of declared?.injected?.rows ?? []) {
|
|
1103
|
+
for (const origin of origins) {
|
|
1104
|
+
const given = writtenArgument(origin.given, call.input, recorded.given);
|
|
1105
|
+
if (given === undefined || !definition.input.parse(given).success || seen.some(other => deepEqual(other, given)))
|
|
1106
|
+
continue;
|
|
1107
|
+
seen.push(given);
|
|
1108
|
+
suggested.push({
|
|
1109
|
+
name: `${definition.name}: ${call.dependency}()の記録行「${recorded.name}」の入力を${describeArgument(call.input)}で尋ねる`,
|
|
1110
|
+
given,
|
|
1111
|
+
reason: "提案する入力(満たしていない義務はない)",
|
|
1112
|
+
suggested: true,
|
|
1113
|
+
origin: origin.given,
|
|
1114
|
+
});
|
|
1115
|
+
break;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
return suggested;
|
|
1121
|
+
}
|
|
1122
|
+
// A row of two or more elements for each fold whose rewrites (ADR-0126) no
|
|
1123
|
+
// answered row tells apart: the list a fold walks, where it is an input field,
|
|
1124
|
+
// grown by an element the rows hold, put last and then first, and the row kept
|
|
1125
|
+
// that tells the most rewrites apart from what the model answers on it.
|
|
1126
|
+
function walkRowsFor(definition, implementation, answeredRows, depsOf, rows, generated) {
|
|
1127
|
+
const offered = [];
|
|
1128
|
+
const notComposed = [];
|
|
1129
|
+
const tagOfGiven = (given) => tagOf(definition.input, given);
|
|
1130
|
+
for (const fold of foldsOf(implementation)) {
|
|
1131
|
+
if (fold.single)
|
|
1132
|
+
continue;
|
|
1133
|
+
const ofCase = answeredRows.filter(row => fold.tags.includes(tagOfGiven(row.given) ?? ""));
|
|
1134
|
+
const open = walkRewrites.filter(walk => !ofCase.some(row => {
|
|
1135
|
+
const deps = depsOf(row);
|
|
1136
|
+
const plain = runWalk(implementation, row.given, deps);
|
|
1137
|
+
if (plain.pending || plain.error !== undefined || !answers(definition, row.expect, plain.actual) || !tookSecond(plain, fold.node))
|
|
1138
|
+
return false;
|
|
1139
|
+
return tells(implementation, fold, walk, row.given, deps, actual => answers(definition, row.expect, actual)) === true;
|
|
1140
|
+
}));
|
|
1141
|
+
if (open.length === 0)
|
|
1142
|
+
continue;
|
|
1143
|
+
const label = `${fold.decision.id}: ${fold.label}`;
|
|
1144
|
+
if (fold.over === undefined) {
|
|
1145
|
+
notComposed.push(`${label}: 歩くリストが入力の欄ではないため、二つ以上の要素を歩く行を組み立てない`);
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1148
|
+
const path = fold.over;
|
|
1149
|
+
const read = (given) => path.reduce((value, key) => (value !== null && typeof value === "object" ? value[key] : undefined), given);
|
|
1150
|
+
const origins = [...ofCase, ...rows.filter(row => isTodo(row.expect) && fold.tags.includes(tagOfGiven(row.given) ?? ""))];
|
|
1151
|
+
const pool = [];
|
|
1152
|
+
for (const row of rows) {
|
|
1153
|
+
const list = read(row.given);
|
|
1154
|
+
if (Array.isArray(list))
|
|
1155
|
+
for (const element of list)
|
|
1156
|
+
if (!pool.some(other => deepEqual(other, element)))
|
|
1157
|
+
pool.push(element);
|
|
1158
|
+
}
|
|
1159
|
+
let best;
|
|
1160
|
+
search: for (const origin of origins) {
|
|
1161
|
+
const held = read(origin.given);
|
|
1162
|
+
if (!Array.isArray(held))
|
|
1163
|
+
continue;
|
|
1164
|
+
const list = held;
|
|
1165
|
+
// Made one at a time, in the order a list of two is reached, and no more
|
|
1166
|
+
// than 64 from each origin: a long list grows into long candidates.
|
|
1167
|
+
function* grown() {
|
|
1168
|
+
if (list.length === 0) {
|
|
1169
|
+
for (const first of pool)
|
|
1170
|
+
for (const second of pool)
|
|
1171
|
+
yield [first, second];
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
for (const element of pool) {
|
|
1175
|
+
yield [...list, element];
|
|
1176
|
+
yield [element, ...list];
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
let made = 0;
|
|
1180
|
+
for (const candidate of grown()) {
|
|
1181
|
+
if (++made > 64)
|
|
1182
|
+
break;
|
|
1183
|
+
const given = writtenAt(origin.given, path, candidate);
|
|
1184
|
+
if (!definition.input.parse(given).success)
|
|
1185
|
+
continue;
|
|
1186
|
+
const deps = depsOf(origin);
|
|
1187
|
+
const plain = runWalk(implementation, given, deps);
|
|
1188
|
+
if (plain.pending || plain.error !== undefined || !tookSecond(plain, fold.node))
|
|
1189
|
+
continue;
|
|
1190
|
+
const told = open.filter(walk => tells(implementation, fold, walk, given, deps, actual => answers(definition, plain.actual, actual)) === true).length;
|
|
1191
|
+
if (told > (best?.told ?? 0))
|
|
1192
|
+
best = { given, origin, told };
|
|
1193
|
+
if (told === open.length)
|
|
1194
|
+
break search;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
if (best === undefined) {
|
|
1198
|
+
notComposed.push(`${label}: 書き換え(${open.join("・")})を見分ける二つ以上の要素の行が見つからない`);
|
|
1199
|
+
continue;
|
|
1200
|
+
}
|
|
1201
|
+
if ([...generated, ...offered].some(row => deepEqual(row.given, best.given)))
|
|
1202
|
+
continue;
|
|
1203
|
+
offered.push({
|
|
1204
|
+
name: `${label} を二つ以上の要素で歩く`,
|
|
1205
|
+
given: best.given,
|
|
1206
|
+
reason: "foldの各段階が前の段階の答えを読むことを確かめる行の期待結果を人間が決める必要があります",
|
|
1207
|
+
origin: best.origin.given,
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
return { rows: offered, notComposed };
|
|
1211
|
+
}
|
|
1212
|
+
// The input a call's argument reads, as the report writes it, so two calls
|
|
1213
|
+
// of one dependency asking one recorded row are named apart.
|
|
1214
|
+
function describeArgument(argument) {
|
|
1215
|
+
const read = [];
|
|
1216
|
+
const walk = (value) => {
|
|
1217
|
+
if (isTerm(value))
|
|
1218
|
+
read.push(describeTerm(value));
|
|
1219
|
+
else if (value !== null && typeof value === "object")
|
|
1220
|
+
for (const child of Object.values(value))
|
|
1221
|
+
walk(child);
|
|
1222
|
+
};
|
|
1223
|
+
walk(argument);
|
|
1224
|
+
return read.length === 0 ? "定数" : read.join("・");
|
|
1225
|
+
}
|
|
1226
|
+
function writtenAt(given, path, value) {
|
|
1227
|
+
if (path.length === 0)
|
|
1228
|
+
return value;
|
|
1229
|
+
const [key, ...rest] = path;
|
|
1230
|
+
const record = (given ?? {});
|
|
1231
|
+
return { ...record, [key]: writtenAt(record[key], rest, value) };
|
|
1232
|
+
}
|
|
990
1233
|
export async function evaluate(exampleSet, name, subject) {
|
|
991
1234
|
const row = exampleSet.rows.find(row => row.name === name);
|
|
992
1235
|
if (row === undefined) {
|
|
@@ -1299,7 +1542,7 @@ function searchedWays(implementation, tag, decision, combinations, fakes = []) {
|
|
|
1299
1542
|
const projected = turned !== undefined && caseRules.every(rule => pathsRead(rule).every(path => path.length > 0 && turned.has(path[0])))
|
|
1300
1543
|
? object(Object.fromEntries(Object.entries(variant.shape).filter(([key]) => turned.has(key))))
|
|
1301
1544
|
: undefined;
|
|
1302
|
-
const placeholder = definition.input
|
|
1545
|
+
const placeholder = placeholderForOf(definition.input, tag);
|
|
1303
1546
|
const inputSchema = projected ?? definition.input;
|
|
1304
1547
|
const schema = values.length === 0
|
|
1305
1548
|
? inputSchema
|
|
@@ -1437,7 +1680,7 @@ function askingTogether(input, calls, askedBy) {
|
|
|
1437
1680
|
// A way through the body of an iteration over a field is taken only by an input
|
|
1438
1681
|
// whose array holds an element, so the way also asks for one.
|
|
1439
1682
|
function withEntry(way, entered = []) {
|
|
1440
|
-
const values = way.within
|
|
1683
|
+
const values = isIteration(way.within) ? way.within.values : undefined;
|
|
1441
1684
|
const position = isTerm(values) ? positionData(values) : undefined;
|
|
1442
1685
|
if (position === undefined || position.measure !== "value")
|
|
1443
1686
|
return entered.length === 0 ? way : { ...way, steps: [...way.steps, ...entered] };
|
|
@@ -1605,7 +1848,7 @@ function factoredWitness(way, implementation, tag, decision, combinations) {
|
|
|
1605
1848
|
const caseRules = [...variant.invariants, ...definition.input.invariants];
|
|
1606
1849
|
const separate = turned !== undefined && caseRules.every(rule => pathsRead(rule).every(path => path.length > 0 && turned.has(path[0])));
|
|
1607
1850
|
const rest = domainOf(object(others), combinations);
|
|
1608
|
-
const placeholder = definition.input
|
|
1851
|
+
const placeholder = placeholderForOf(definition.input, tag);
|
|
1609
1852
|
let tried = 0;
|
|
1610
1853
|
let refused = false;
|
|
1611
1854
|
for (const [a, b] of pairs) {
|
|
@@ -1647,6 +1890,101 @@ function unmetStatus(feasibilities) {
|
|
|
1647
1890
|
}
|
|
1648
1891
|
return { status: "no row owed", reason: feasibilities[0].reason };
|
|
1649
1892
|
}
|
|
1893
|
+
// The rows beside the runs nearest to a point on a computed value: from each
|
|
1894
|
+
// of the three runs whose value came nearest, one numeric field of the input
|
|
1895
|
+
// is moved by one, two, ten or a hundred either way, and the move that brings
|
|
1896
|
+
// the value nearest is kept, until the point is reached or no move brings it
|
|
1897
|
+
// nearer. Where none reaches it, what was tried is said: that is no proof the
|
|
1898
|
+
// point is unreachable.
|
|
1899
|
+
function besideTheNearest(definition, drawn, point, runs, coordinates) {
|
|
1900
|
+
const target = numeric(point.witness);
|
|
1901
|
+
if (target === undefined || runs.length === 0)
|
|
1902
|
+
return { tried: `${runs.length}件の実行を試したが、点に届く行は見つからない` };
|
|
1903
|
+
const distance = (given, deps) => {
|
|
1904
|
+
const values = coordinates(given, deps).map(numeric).filter((value) => value !== undefined);
|
|
1905
|
+
return values.length === 0 ? undefined : Math.min(...values.map(value => Math.abs(value - target)));
|
|
1906
|
+
};
|
|
1907
|
+
const variant = definition.input.variants[drawn.origin?.tag ?? ""];
|
|
1908
|
+
// Every integer, number and int64 leaf of the case, nested objects included.
|
|
1909
|
+
const fields = [];
|
|
1910
|
+
const numericLeaves = (schema, path) => {
|
|
1911
|
+
if (schema === undefined)
|
|
1912
|
+
return;
|
|
1913
|
+
if (schema.kind === "integer" || schema.kind === "number" || schema.kind === "int64")
|
|
1914
|
+
fields.push(path);
|
|
1915
|
+
else if (schema.kind === "object")
|
|
1916
|
+
for (const [key, field] of Object.entries(schema.shape))
|
|
1917
|
+
numericLeaves(field, [...path, key]);
|
|
1918
|
+
};
|
|
1919
|
+
numericLeaves(variant, []);
|
|
1920
|
+
const readAt = (given, path) => path.reduce((value, key) => (value !== null && typeof value === "object" ? value[key] : undefined), given);
|
|
1921
|
+
const scored = runs
|
|
1922
|
+
.map(run => ({ ...run, distance: distance(run.given, run.with) }))
|
|
1923
|
+
.filter((run) => run.distance !== undefined)
|
|
1924
|
+
.sort((a, b) => a.distance - b.distance);
|
|
1925
|
+
let nearest = scored[0]?.distance;
|
|
1926
|
+
let steps = 0;
|
|
1927
|
+
for (const start of scored.slice(0, 3)) {
|
|
1928
|
+
let current = start;
|
|
1929
|
+
for (let round = 0; round < 64 && current.distance > 0; round++) {
|
|
1930
|
+
let best;
|
|
1931
|
+
for (const field of fields) {
|
|
1932
|
+
for (const by of [1, -1, 2, -2, 10, -10, 100, -100]) {
|
|
1933
|
+
const value = readAt(current.given, field);
|
|
1934
|
+
if (typeof value !== "number" && typeof value !== "bigint")
|
|
1935
|
+
continue;
|
|
1936
|
+
const given = writtenAt(current.given, field, typeof value === "bigint" ? value + BigInt(by) : value + by);
|
|
1937
|
+
if (!definition.input.parse(given).success)
|
|
1938
|
+
continue;
|
|
1939
|
+
steps++;
|
|
1940
|
+
if (coordinates(given, current.with).some(reached => point.contains(reached))) {
|
|
1941
|
+
return { given, ...(current.with === undefined ? {} : { with: current.with }), tried: "" };
|
|
1942
|
+
}
|
|
1943
|
+
const moved = distance(given, current.with);
|
|
1944
|
+
if (moved !== undefined && moved < (best?.distance ?? current.distance))
|
|
1945
|
+
best = { ...current, given, distance: moved };
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
if (best === undefined)
|
|
1949
|
+
break;
|
|
1950
|
+
current = best;
|
|
1951
|
+
nearest = Math.min(nearest ?? current.distance, current.distance);
|
|
1952
|
+
}
|
|
1953
|
+
if (current.distance === 0 && coordinates(current.given, current.with).some(value => point.contains(value))) {
|
|
1954
|
+
return { given: current.given, ...(current.with === undefined ? {} : { with: current.with }), tried: "" };
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
return { tried: `${runs.length}件の実行と、近いものから${steps}件の隣の行を試したが、点に届く行は見つからない${nearest === undefined ? "" : `(最も近い差は${nearest})`}` };
|
|
1958
|
+
}
|
|
1959
|
+
function numeric(value) {
|
|
1960
|
+
if (typeof value === "number")
|
|
1961
|
+
return value;
|
|
1962
|
+
if (typeof value === "bigint")
|
|
1963
|
+
return Number(value);
|
|
1964
|
+
if (isDecimal(value))
|
|
1965
|
+
return value.toNumber();
|
|
1966
|
+
return undefined;
|
|
1967
|
+
}
|
|
1968
|
+
// A computation cut at several places owes its weights once (ADR-0124): a
|
|
1969
|
+
// border of it the rows tell from the lines beside it tells the computation's
|
|
1970
|
+
// weights, so another border of the same computation is told through it.
|
|
1971
|
+
function toldOnce(borders, drawn) {
|
|
1972
|
+
const keyOf = (index) => {
|
|
1973
|
+
const form = drawn[index].form;
|
|
1974
|
+
return form === undefined ? undefined : computationOf(drawn[index].origin?.tag, form.parts);
|
|
1975
|
+
};
|
|
1976
|
+
const told = new Map();
|
|
1977
|
+
borders.forEach((border, index) => {
|
|
1978
|
+
const key = keyOf(index);
|
|
1979
|
+
if (key !== undefined && border.beside?.status === "told" && border.beside.through === undefined && !told.has(key))
|
|
1980
|
+
told.set(key, border.rule);
|
|
1981
|
+
});
|
|
1982
|
+
return borders.map((border, index) => {
|
|
1983
|
+
const key = keyOf(index);
|
|
1984
|
+
const through = key === undefined ? undefined : told.get(key);
|
|
1985
|
+
return through !== undefined && border.beside?.status === "not told" ? { ...border, beside: { status: "told", through } } : border;
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1650
1988
|
function besideOf(definition, implementation, drawn, reachedIt) {
|
|
1651
1989
|
const parts = [...drawn.form.parts].sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
|
|
1652
1990
|
const rows = reachedIt.filter(item => drawn.coordinateOf(item.comparison) !== undefined).flatMap(item => {
|
|
@@ -1865,6 +2203,8 @@ function segmentsRead(rule, root, elements) {
|
|
|
1865
2203
|
switch (rule.kind) {
|
|
1866
2204
|
case "compare":
|
|
1867
2205
|
return [rule.left, rule.right].flatMap(trailsOf);
|
|
2206
|
+
case "relation":
|
|
2207
|
+
return [rule.subject, rule.other].flatMap(trailsOf);
|
|
1868
2208
|
case "all":
|
|
1869
2209
|
case "any": {
|
|
1870
2210
|
const of = trailOf(rule.of);
|
|
@@ -1900,7 +2240,7 @@ function namedSegments(position) {
|
|
|
1900
2240
|
// A disregarded position a guard reads is kept rather than dropped, since the
|
|
1901
2241
|
// guard's classes are attached to it; only what its type and invariants owe goes.
|
|
1902
2242
|
function measuredPositionsOf(definition, guardDivided = new Set(), guardRead = [], combinations = FEASIBILITY_COMBINATION_LIMIT) {
|
|
1903
|
-
return
|
|
2243
|
+
return withDividedContainers(definition.input, guardDivided).map(position => withJointExclusions(definition, position, combinations)).flatMap((position) => {
|
|
1904
2244
|
if (!isDisregarded(definition, position)) {
|
|
1905
2245
|
return [position];
|
|
1906
2246
|
}
|
|
@@ -1918,6 +2258,14 @@ function measuredPositionsOf(definition, guardDivided = new Set(), guardRead = [
|
|
|
1918
2258
|
];
|
|
1919
2259
|
});
|
|
1920
2260
|
}
|
|
2261
|
+
// The positions of an input, with a record or an array a guard's relation
|
|
2262
|
+
// divides as a container (ADR-0129), which is no position otherwise.
|
|
2263
|
+
function withDividedContainers(input, guardDivided) {
|
|
2264
|
+
const plain = positionsOf(input);
|
|
2265
|
+
const known = new Set(plain.map(position => trailKey(position.segments)));
|
|
2266
|
+
const containers = positionsOf(input, { containers: true }).filter(position => !known.has(trailKey(position.segments)) && guardDivided.has(trailKey(position.segments)));
|
|
2267
|
+
return [...plain, ...containers];
|
|
2268
|
+
}
|
|
1921
2269
|
const DISREGARD_COMBINATION_LIMIT = 255;
|
|
1922
2270
|
// Not the combinations alone: moves are tried before a combination is known to
|
|
1923
2271
|
// be one the input can hold, so the candidates tried that way are bounded too.
|
|
@@ -2086,7 +2434,24 @@ export function finiteCoordinateOf(definition, position, className) {
|
|
|
2086
2434
|
return undefined;
|
|
2087
2435
|
}
|
|
2088
2436
|
}
|
|
2437
|
+
// Planned once per implementation and limits: what to change is read off the
|
|
2438
|
+
// plans before the measurement and the measurement reads the same plans, so
|
|
2439
|
+
// `modelChanges` followed by `check` plans each decision once.
|
|
2440
|
+
const planned = new WeakMap();
|
|
2089
2441
|
function plansOf(implementation, combinations, wayLimit) {
|
|
2442
|
+
if (implementation === undefined)
|
|
2443
|
+
return new Map();
|
|
2444
|
+
const key = `${combinations}:${wayLimit}`;
|
|
2445
|
+
const cached = planned.get(implementation)?.get(key);
|
|
2446
|
+
if (cached !== undefined)
|
|
2447
|
+
return cached;
|
|
2448
|
+
const made = planFor(implementation, combinations, wayLimit);
|
|
2449
|
+
const byLimits = planned.get(implementation) ?? new Map();
|
|
2450
|
+
byLimits.set(key, made);
|
|
2451
|
+
planned.set(implementation, byLimits);
|
|
2452
|
+
return made;
|
|
2453
|
+
}
|
|
2454
|
+
function planFor(implementation, combinations, wayLimit) {
|
|
2090
2455
|
const plans = new Map();
|
|
2091
2456
|
for (const [decision, tags] of implementation === undefined ? [] : decisionsWithCases(implementation)) {
|
|
2092
2457
|
if (decision.kind !== "rules") {
|