tla-ts 0.0.3-dev.949cce6 → 0.0.3-dev.9b15ea6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +146 -8
- package/dist/index.d.ts +146 -8
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +1351 -20
- package/dist/run-cli.js +1351 -20
- package/dist/transfer.cjs +86 -28
- package/dist/transfer.js +86 -28
- package/package.json +5 -1
- package/src/ast.ts +48 -6
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -11
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1352 -215
- package/src/cli.ts +8 -1
- package/src/codegen.ts +68 -18
- package/src/config.ts +252 -179
- package/src/environment.ts +451 -129
- package/src/errors.ts +217 -3
- package/src/evaluate.ts +724 -117
- package/src/exit-codes.ts +5 -4
- package/src/index.ts +1 -0
- package/src/instances.ts +4 -2
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +183 -37
- package/src/lexer.ts +14 -1
- package/src/live-check.ts +211 -89
- package/src/liveness.ts +192 -65
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +8 -3
- package/src/parallel.ts +56 -5
- package/src/parser.ts +423 -126
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +1363 -405
- package/src/run-cli.ts +1167 -155
- package/src/runtime.ts +16 -0
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3112 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +545 -0
- package/src/sany-linter.ts +122 -0
- package/src/sany-modules.ts +1398 -0
- package/src/sany-nodes.ts +463 -0
- package/src/sany-parse-error.ts +2161 -0
- package/src/sany-report.ts +354 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +26 -7
- package/src/standard-modules.ts +203 -146
- package/src/standard-ranges.ts +116 -0
- package/src/state-graph.ts +29 -6
- package/src/subexpressions.ts +221 -161
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +162 -114
- package/src/symmetry.ts +180 -52
- package/src/tableau.ts +4 -2
- package/src/tlc-ext.ts +13 -17
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +46 -18
- package/src/tlc-order.ts +56 -6
- package/src/tlc-random.ts +28 -3
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/value-sources.ts +29 -0
- package/src/values.ts +684 -204
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tla-ts",
|
|
3
|
-
"version": "0.0.3-dev.
|
|
3
|
+
"version": "0.0.3-dev.9b15ea6",
|
|
4
4
|
"description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"formal verification",
|
|
@@ -54,6 +54,9 @@
|
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"fflate": "^0.8.3"
|
|
59
|
+
},
|
|
57
60
|
"devDependencies": {
|
|
58
61
|
"@types/node": "^22",
|
|
59
62
|
"publint": "^0.3.0",
|
|
@@ -71,6 +74,7 @@
|
|
|
71
74
|
"conformance:sany": "tsx scripts/proof-conformance.ts",
|
|
72
75
|
"conformance:record": "tsx scripts/record-tlc.ts",
|
|
73
76
|
"conformance:record-sany": "tsx scripts/record-sany.ts",
|
|
77
|
+
"conformance:record-statechart": "tsx scripts/record-statechart.ts",
|
|
74
78
|
"conformance:record-tlapm": "tsx scripts/record-tlapm.ts",
|
|
75
79
|
"conformance:tlapm": "tsx scripts/tlapm-conformance.ts",
|
|
76
80
|
"publint": "publint",
|
package/src/ast.ts
CHANGED
|
@@ -33,9 +33,12 @@ export interface StringExpression {
|
|
|
33
33
|
location: SourceLocation;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// selectorRanges holds the range of each part of a name such as foo!lab, where SANY reports an
|
|
37
|
+
// error in selecting that part.
|
|
36
38
|
export interface IdentifierExpression {
|
|
37
39
|
kind: "Identifier";
|
|
38
40
|
name: string;
|
|
41
|
+
selectorRanges?: SourceRange[];
|
|
39
42
|
location: SourceLocation;
|
|
40
43
|
resolution?: LocalResolution;
|
|
41
44
|
}
|
|
@@ -47,6 +50,11 @@ export interface ApplyExpression {
|
|
|
47
50
|
// The number of args each part of a name like F(x)!l(y) takes, when a part before the last takes
|
|
48
51
|
// some.
|
|
49
52
|
argumentCounts?: number[];
|
|
53
|
+
// The range of the parenthesized arguments of a named operator, where SANY reports their count.
|
|
54
|
+
argumentsRange?: SourceRange;
|
|
55
|
+
selectorRanges?: SourceRange[];
|
|
56
|
+
// The range of the arguments of each part of a name like F(x)!l(y), for a part that takes some.
|
|
57
|
+
argumentRanges?: (SourceRange | undefined)[];
|
|
50
58
|
location: SourceLocation;
|
|
51
59
|
resolution?: LocalResolution;
|
|
52
60
|
}
|
|
@@ -60,6 +68,7 @@ export interface OperatorReferenceExpression {
|
|
|
60
68
|
export interface LambdaExpression {
|
|
61
69
|
kind: "Lambda";
|
|
62
70
|
params: string[];
|
|
71
|
+
paramRanges?: SourceRange[];
|
|
63
72
|
body: Expression;
|
|
64
73
|
location: SourceLocation;
|
|
65
74
|
}
|
|
@@ -68,6 +77,9 @@ export interface JunctionExpression {
|
|
|
68
77
|
kind: "And" | "Or";
|
|
69
78
|
operands: Expression[];
|
|
70
79
|
isBulleted?: boolean;
|
|
80
|
+
// SANY parses an infix chain such as A /\ B /\ C as (A /\ B) /\ C, whose node of each prefix of
|
|
81
|
+
// two or more operands ends after the parentheses of its last operand.
|
|
82
|
+
prefixEnds?: SourceLocation[];
|
|
71
83
|
location: SourceLocation;
|
|
72
84
|
}
|
|
73
85
|
|
|
@@ -117,7 +129,10 @@ export interface LetExpression {
|
|
|
117
129
|
location: SourceLocation;
|
|
118
130
|
}
|
|
119
131
|
|
|
120
|
-
|
|
132
|
+
// ranges holds the range of each name the pattern binds.
|
|
133
|
+
export type BoundPattern =
|
|
134
|
+
| { kind: "Name"; name: string; ranges?: SourceRange[] }
|
|
135
|
+
| { kind: "Tuple"; names: string[]; ranges?: SourceRange[] };
|
|
121
136
|
|
|
122
137
|
export interface Bound {
|
|
123
138
|
pattern: BoundPattern;
|
|
@@ -135,6 +150,7 @@ export interface UnboundedQuantifierExpression {
|
|
|
135
150
|
kind: "UnboundedQuantifier";
|
|
136
151
|
quantifier: "Forall" | "Exists";
|
|
137
152
|
names: string[];
|
|
153
|
+
nameRanges?: SourceRange[];
|
|
138
154
|
isTemporal?: boolean;
|
|
139
155
|
body: Expression;
|
|
140
156
|
location: SourceLocation;
|
|
@@ -192,6 +208,7 @@ export interface FunctionSetExpression {
|
|
|
192
208
|
export interface RecordField {
|
|
193
209
|
name: string;
|
|
194
210
|
value: Expression;
|
|
211
|
+
location: SourceLocation;
|
|
195
212
|
}
|
|
196
213
|
|
|
197
214
|
export interface RecordExpression {
|
|
@@ -228,6 +245,14 @@ export interface FunctionApplicationExpression {
|
|
|
228
245
|
location: SourceLocation;
|
|
229
246
|
}
|
|
230
247
|
|
|
248
|
+
// SANY parses [e1, ..., en] as a function application without the function, and its semantic
|
|
249
|
+
// checker rejects it.
|
|
250
|
+
export interface BracketExpression {
|
|
251
|
+
kind: "Bracket";
|
|
252
|
+
args: Expression[];
|
|
253
|
+
location: SourceLocation;
|
|
254
|
+
}
|
|
255
|
+
|
|
231
256
|
export interface FieldAccessExpression {
|
|
232
257
|
kind: "FieldAccess";
|
|
233
258
|
record: Expression;
|
|
@@ -266,6 +291,7 @@ export interface LabelExpression {
|
|
|
266
291
|
kind: "Label";
|
|
267
292
|
name: string;
|
|
268
293
|
params: string[];
|
|
294
|
+
paramRanges?: SourceRange[];
|
|
269
295
|
body: Expression;
|
|
270
296
|
location: SourceLocation;
|
|
271
297
|
}
|
|
@@ -280,6 +306,8 @@ export type Selector =
|
|
|
280
306
|
export interface SubexpressionExpression {
|
|
281
307
|
kind: "Subexpression";
|
|
282
308
|
selectors: Selector[];
|
|
309
|
+
selectorRanges?: SourceRange[];
|
|
310
|
+
argumentRanges?: (SourceRange | undefined)[];
|
|
283
311
|
location: SourceLocation;
|
|
284
312
|
}
|
|
285
313
|
|
|
@@ -311,6 +339,7 @@ export type Expression =
|
|
|
311
339
|
| ExceptExpression
|
|
312
340
|
| ExceptAtExpression
|
|
313
341
|
| FunctionApplicationExpression
|
|
342
|
+
| BracketExpression
|
|
314
343
|
| FieldAccessExpression
|
|
315
344
|
| ProductExpression
|
|
316
345
|
| TemporalExpression
|
|
@@ -343,6 +372,8 @@ export interface FunctionDefinition {
|
|
|
343
372
|
body: Expression;
|
|
344
373
|
isLocal: boolean;
|
|
345
374
|
isRecursive: boolean;
|
|
375
|
+
// Whether the body applies the function, which SANY makes a recursive function definition.
|
|
376
|
+
isSelfReferential?: boolean;
|
|
346
377
|
location: SourceLocation;
|
|
347
378
|
}
|
|
348
379
|
|
|
@@ -363,6 +394,7 @@ export interface Assumption {
|
|
|
363
394
|
|
|
364
395
|
export interface InstanceSubstitution {
|
|
365
396
|
name: string;
|
|
397
|
+
nameRange: SourceRange;
|
|
366
398
|
expression: Expression;
|
|
367
399
|
}
|
|
368
400
|
|
|
@@ -384,6 +416,7 @@ export interface NewSymbol {
|
|
|
384
416
|
arity: number;
|
|
385
417
|
level: "Constant" | "Variable" | "State" | "Action" | "Temporal";
|
|
386
418
|
set: Expression | undefined;
|
|
419
|
+
nameRange?: SourceRange;
|
|
387
420
|
location: SourceLocation;
|
|
388
421
|
}
|
|
389
422
|
|
|
@@ -435,19 +468,27 @@ export type StepBody =
|
|
|
435
468
|
| Instance
|
|
436
469
|
| DefineStep
|
|
437
470
|
| { kind: "Have"; expression: Expression }
|
|
438
|
-
| { kind: "Take"; names: string[]; bounds: Bound[] }
|
|
471
|
+
| { kind: "Take"; names: string[]; nameRanges?: SourceRange[]; bounds: Bound[] }
|
|
439
472
|
| { kind: "Witness"; expressions: Expression[] }
|
|
440
|
-
| {
|
|
473
|
+
| {
|
|
474
|
+
kind: "Pick";
|
|
475
|
+
names: string[];
|
|
476
|
+
nameRanges?: SourceRange[];
|
|
477
|
+
bounds: Bound[];
|
|
478
|
+
body: Expression;
|
|
479
|
+
}
|
|
441
480
|
| { kind: "Case"; expression: Expression }
|
|
442
481
|
| { kind: "Assert"; isSuffices: boolean; statement: Expression | AssumeProve }
|
|
443
482
|
| { kind: "Qed" };
|
|
444
483
|
|
|
445
|
-
// head is the range of the step number and its statement, without the proof
|
|
484
|
+
// head is the range of the step number and its statement, without the proof, and statement is the
|
|
485
|
+
// range of the statement alone.
|
|
446
486
|
export interface ProofStep {
|
|
447
487
|
name: string | undefined;
|
|
448
488
|
token: string;
|
|
449
489
|
body: StepBody;
|
|
450
490
|
head: SourceRange;
|
|
491
|
+
statement: SourceRange;
|
|
451
492
|
proof: Proof | undefined;
|
|
452
493
|
location: SourceLocation;
|
|
453
494
|
}
|
|
@@ -461,8 +502,7 @@ export interface Theorem {
|
|
|
461
502
|
|
|
462
503
|
// The units of a module in source order, for consumers that need the order across kinds.
|
|
463
504
|
export type ModuleUnit =
|
|
464
|
-
| { kind: "Constants"; declarations: Declaration[] }
|
|
465
|
-
| { kind: "Variables"; declarations: Declaration[] }
|
|
505
|
+
| { kind: "Constants" | "Variables"; declarations: Declaration[]; location: SourceLocation }
|
|
466
506
|
| { kind: "Recursive"; declarations: Declaration[] }
|
|
467
507
|
| { kind: "Definition"; definition: Definition }
|
|
468
508
|
| { kind: "Instance"; instance: Instance }
|
|
@@ -556,6 +596,8 @@ export const getChildren = (expression: Expression): Expression[] => {
|
|
|
556
596
|
];
|
|
557
597
|
case "FunctionApplication":
|
|
558
598
|
return [expression.function, ...expression.args];
|
|
599
|
+
case "Bracket":
|
|
600
|
+
return expression.args;
|
|
559
601
|
case "FieldAccess":
|
|
560
602
|
return [expression.record];
|
|
561
603
|
case "Product":
|
package/src/bags.ts
CHANGED
|
@@ -123,7 +123,8 @@ const mergeBags = (bags: FunctionValue[], method: string) =>
|
|
|
123
123
|
|
|
124
124
|
const EMPTY_BAG = createSortedFunction([], []);
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
// SubBag compares the counts with the >= of Naturals, which Integers replaces when TLC loads it.
|
|
127
|
+
export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Builtin[] => [
|
|
127
128
|
defineConstant("EmptyBag", EMPTY_BAG),
|
|
128
129
|
defineOperator("IsABag", 1, (args) => {
|
|
129
130
|
const functionValue = toFunction(getValue(args, 0, "IsABag"));
|
|
@@ -228,12 +229,8 @@ export const BAGS_OPERATORS: Builtin[] = [
|
|
|
228
229
|
const functionValue = toFiniteFunction(value);
|
|
229
230
|
const range = createSet(functionValue.range).elements;
|
|
230
231
|
const invalid = range.find((count) => typeof count !== "number");
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
throw new TlaEvaluationError(
|
|
234
|
-
`The ${isFirst ? "first" : "second"} argument of >= should be an integer, but instead it is:\n${formatValue(isFirst ? range[0] : invalid)}`,
|
|
235
|
-
);
|
|
236
|
-
}
|
|
232
|
+
// A count that isn't an integer fails the comparison.
|
|
233
|
+
if (invalid !== undefined) builtins.get(">=")?.evaluateBinary?.(range[0], invalid);
|
|
237
234
|
const counts = functionValue.range.filter((count) => typeof count === "number");
|
|
238
235
|
if (counts.some((count) => count < 1)) {
|
|
239
236
|
throw new TlaEvaluationError(
|
package/src/builtins.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { TlaEvaluationError, TlaModuleError } from "./errors";
|
|
|
2
2
|
import type { Builtin, BuiltinArgument, Context, OperatorValue } from "./evaluate";
|
|
3
3
|
import {
|
|
4
4
|
formatValue,
|
|
5
|
+
getFunctionClass,
|
|
5
6
|
getSequenceElements,
|
|
6
7
|
isEnumerable,
|
|
7
8
|
isFunctionValue,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
toFiniteFunction,
|
|
10
11
|
MAXIMUM_INTEGER,
|
|
11
12
|
MINIMUM_INTEGER,
|
|
13
|
+
setTrace,
|
|
12
14
|
toFiniteSet,
|
|
13
15
|
type Value,
|
|
14
16
|
} from "./values";
|
|
@@ -243,17 +245,20 @@ const KIND_STRINGS: Record<string, string> = {
|
|
|
243
245
|
UnionValue: "a set of the form UNION S",
|
|
244
246
|
};
|
|
245
247
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
+
const FUNCTION_CLASSES = {
|
|
249
|
+
lambda: "FcnLambdaValue",
|
|
250
|
+
tuple: "TupleValue",
|
|
251
|
+
record: "RecordValue",
|
|
252
|
+
};
|
|
253
|
+
|
|
248
254
|
export const getJavaClassName = (value: Value) => {
|
|
249
255
|
if (typeof value === "number") return "IntValue";
|
|
250
256
|
if (typeof value === "string") return "StringValue";
|
|
251
257
|
if (typeof value === "boolean") return "BoolValue";
|
|
252
258
|
if (value.kind === "SetOperation") return SET_OPERATION_CLASSES[value.operator];
|
|
253
259
|
if (value.kind !== "Function") return JAVA_CLASSES[value.kind];
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
return domain.every((key) => typeof key === "string") ? "RecordValue" : "FcnRcdValue";
|
|
260
|
+
const functionClass = getFunctionClass(value);
|
|
261
|
+
return functionClass === undefined ? "FcnRcdValue" : FUNCTION_CLASSES[functionClass];
|
|
257
262
|
};
|
|
258
263
|
|
|
259
264
|
export const getKindString = (value: Value) => KIND_STRINGS[getJavaClassName(value)];
|
|
@@ -270,13 +275,17 @@ export const overrideWithJava = (builtin: Builtin, signature: string): Builtin =
|
|
|
270
275
|
const guard =
|
|
271
276
|
<Arguments extends unknown[]>(compute: (...args: Arguments) => Value) =>
|
|
272
277
|
(...args: Arguments) => {
|
|
278
|
+
const depth = setTrace.sets?.length ?? 0;
|
|
273
279
|
try {
|
|
274
280
|
return compute(...args);
|
|
275
281
|
} catch (error) {
|
|
276
282
|
const isWrapped =
|
|
277
283
|
error instanceof TlaEvaluationError &&
|
|
278
284
|
(builtin.isLazy === true || !(error instanceof TlaModuleError));
|
|
279
|
-
|
|
285
|
+
if (!isWrapped) throw error;
|
|
286
|
+
// The wrapping error replaces a FingerprintException that a set with a source raised.
|
|
287
|
+
if (setTrace.sets) setTrace.sets.length = depth;
|
|
288
|
+
throw createJavaOverrideError(signature, error.message);
|
|
280
289
|
}
|
|
281
290
|
};
|
|
282
291
|
return {
|
|
@@ -297,15 +306,16 @@ export const getJavaInteger = (value: Value, signature: string) => {
|
|
|
297
306
|
return value;
|
|
298
307
|
};
|
|
299
308
|
|
|
300
|
-
export const
|
|
301
|
-
`public static tlc2.value.impl.${result} tlc2.module
|
|
309
|
+
export const getJavaSignature = (module: string, method: string, result: string, arity: number) =>
|
|
310
|
+
`public static tlc2.value.impl.${result} tlc2.module.${module}.${method}(${Array.from({ length: arity }, () => "tlc2.value.impl.IntValue").join(",")})`;
|
|
302
311
|
|
|
303
312
|
export const defineArithmetic = (
|
|
313
|
+
module: string,
|
|
304
314
|
name: string,
|
|
305
315
|
method: string,
|
|
306
316
|
compute: (left: number, right: number) => number,
|
|
307
317
|
) => {
|
|
308
|
-
const signature =
|
|
318
|
+
const signature = getJavaSignature(module, method, "IntValue", 2);
|
|
309
319
|
return defineBinary(name, (left, right) => {
|
|
310
320
|
const leftNumber = getJavaInteger(left, signature);
|
|
311
321
|
const rightNumber = getJavaInteger(right, signature);
|
|
@@ -324,9 +334,17 @@ const getIntegerArgument = (value: Value, position: string, name: string) => {
|
|
|
324
334
|
return value;
|
|
325
335
|
};
|
|
326
336
|
|
|
327
|
-
|
|
337
|
+
// The error of an argument that isn't an integer names the operator as TLC's method does.
|
|
338
|
+
export const defineComparison = (
|
|
339
|
+
name: string,
|
|
340
|
+
compare: (left: number, right: number) => boolean,
|
|
341
|
+
errorName = name,
|
|
342
|
+
) =>
|
|
328
343
|
defineBinary(name, (left, right) =>
|
|
329
|
-
compare(
|
|
344
|
+
compare(
|
|
345
|
+
getIntegerArgument(left, "first", errorName),
|
|
346
|
+
getIntegerArgument(right, "second", errorName),
|
|
347
|
+
),
|
|
330
348
|
);
|
|
331
349
|
|
|
332
350
|
export const defineLazyOperator = (
|
package/src/bundled-modules.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// TLC's Reals.tla, RealTime.tla, and Toolbox.tla, verbatim, so that errors inside them name the same
|
|
2
2
|
// lines as TLC's errors.
|
|
3
|
-
const REALS = `-------------------------------- MODULE Reals -------------------------------
|
|
3
|
+
export const REALS = `-------------------------------- MODULE Reals -------------------------------
|
|
4
4
|
(***************************************************************************)
|
|
5
5
|
(* This module provides dummy definitions of the operators that are *)
|
|
6
6
|
(* defined by the real Reals module. It is expected that any tool that *)
|
|
@@ -19,7 +19,7 @@ a / b == CHOOSE m \\in Real : m * b = a
|
|
|
19
19
|
Infinity == CHOOSE i : (i \\notin Real) /\\ (\\A r \\in Real : i > r)
|
|
20
20
|
=============================================================================`;
|
|
21
21
|
|
|
22
|
-
const REAL_TIME = `----------------------------- MODULE RealTime -------------------------------
|
|
22
|
+
export const REAL_TIME = `----------------------------- MODULE RealTime -------------------------------
|
|
23
23
|
(***************************************************************************)
|
|
24
24
|
(* This standard module is described in Chapter 9 of the book "Specifying *)
|
|
25
25
|
(* Systems". The type of specification described there cannot be handled *)
|
|
@@ -47,7 +47,7 @@ RTnow(v) == LET NowNext == /\\ now' \\in {r \\in Real : r > now}
|
|
|
47
47
|
/\\ \\A r \\in Real : WF_now(NowNext /\\ (now'>r))
|
|
48
48
|
=============================================================================`;
|
|
49
49
|
|
|
50
|
-
const TOOLBOX = `----------------------------- MODULE Toolbox --------------------------------
|
|
50
|
+
export const TOOLBOX = `----------------------------- MODULE Toolbox --------------------------------
|
|
51
51
|
(***************************************************************************)
|
|
52
52
|
(* *)
|
|
53
53
|
(***************************************************************************)
|
package/src/canonical.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getValueHash,
|
|
1
|
+
import { getValueHash, isInterchangeableValue, type Value } from "./values";
|
|
2
2
|
|
|
3
3
|
const canonicalizeElements = (elements: Value[], canonicalize: (value: Value) => Value) => {
|
|
4
4
|
for (let index = 0; index < elements.length; index++) {
|
|
@@ -15,11 +15,12 @@ export const createCanonicalizer = () => {
|
|
|
15
15
|
const hash = getValueHash(value);
|
|
16
16
|
const bucket = canonicalValues.get(hash);
|
|
17
17
|
if (bucket !== undefined && !Array.isArray(bucket)) {
|
|
18
|
-
if (bucket === value ||
|
|
18
|
+
if (bucket === value || isInterchangeableValue(bucket, value)) return bucket;
|
|
19
19
|
}
|
|
20
20
|
if (Array.isArray(bucket)) {
|
|
21
21
|
for (let index = 0; index < bucket.length; index++) {
|
|
22
|
-
if (bucket[index] === value ||
|
|
22
|
+
if (bucket[index] === value || isInterchangeableValue(bucket[index], value))
|
|
23
|
+
return bucket[index];
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
if (value.kind === "Set") canonicalizeElements(value.elements, canonicalize);
|