tla-ts 0.0.10-dev.1ebc153bd → 0.0.10-dev.22f7435d3
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/deciders.cjs +31 -31
- package/dist/deciders.js +30 -30
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +68 -68
- package/dist/prove.js +61 -61
- package/dist/run.cjs +42 -42
- package/dist/run.js +44 -44
- package/dist/transfer.cjs +38 -38
- package/dist/transfer.js +29 -29
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/bags.ts +5 -2
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +9 -6
- package/src/check-trace.ts +116 -64
- package/src/check.ts +343 -166
- package/src/cli/tlc-output.ts +1 -0
- package/src/cli/tlc.ts +3 -2
- package/src/codegen.ts +23 -8
- package/src/dependencies.ts +5 -4
- package/src/dfid.ts +13 -8
- package/src/environment.ts +1 -0
- package/src/evaluate.ts +58 -23
- package/src/exit-codes.ts +27 -13
- package/src/java-hash.ts +14 -0
- package/src/liveness-checker.ts +131 -81
- package/src/liveness.ts +48 -10
- package/src/parser.ts +6 -1
- package/src/prover/smt/solver/arith-rewriter.ts +11 -3
- package/src/prover/smt/solver/array-rewriter.ts +12 -2
- package/src/prover/smt/solver/asserted-formulas.ts +109 -63
- package/src/prover/smt/solver/ast.ts +5 -3
- package/src/prover/smt/solver/auf-solver.ts +23 -12
- package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
- package/src/prover/smt/solver/bound-simplifier.ts +10 -11
- package/src/prover/smt/solver/card2bv.ts +34 -15
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -23
- package/src/prover/smt/solver/context.ts +44 -11
- package/src/prover/smt/solver/dependent-expr-state.ts +19 -13
- package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
- package/src/prover/smt/solver/elim-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +1 -1
- package/src/prover/smt/solver/fd-solver.ts +146 -39
- package/src/prover/smt/solver/internalizer.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +4 -0
- package/src/prover/smt/solver/maxcore.ts +2 -1
- package/src/prover/smt/solver/maxsmt-base.ts +1 -0
- package/src/prover/smt/solver/model-checker.ts +1 -1
- package/src/prover/smt/solver/model-evaluator.ts +2 -0
- package/src/prover/smt/solver/model-generator.ts +82 -42
- package/src/prover/smt/solver/muz/dl-context.ts +12 -40
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
- package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
- package/src/prover/smt/solver/muz/hnf.ts +2 -2
- package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
- package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
- package/src/prover/smt/solver/opt-context.ts +12 -4
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-solver.ts +4 -3
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/poly-rewriter.ts +1 -0
- package/src/prover/smt/solver/proto-model.ts +4 -2
- package/src/prover/smt/solver/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qsat.ts +23 -8
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/rewriter.ts +31 -25
- package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +56 -28
- package/src/prover/smt/solver/sat/sat-tactic.ts +13 -4
- package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
- package/src/prover/smt/solver/smt-consequences.ts +1 -1
- package/src/prover/smt/solver/smt-kernel.ts +39 -4
- package/src/prover/smt/solver/smt-setup.ts +28 -4
- package/src/prover/smt/solver/smtlib-parser.ts +31 -4
- package/src/prover/smt/solver/smtlib-script.ts +219 -82
- package/src/prover/smt/solver/solve-eqs.ts +24 -17
- package/src/prover/smt/solver/solver.ts +18 -3
- package/src/prover/smt/solver/tactic.ts +132 -78
- package/src/prover/smt/solver/theory-bv.ts +11 -1
- package/src/prover/smt/solver/theory-fpa.ts +1 -1
- package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +7 -1
- package/src/prover/smt/solver/theory-lra.ts +1 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
- package/src/resolve.ts +446 -167
- package/src/runtime.ts +4 -0
- package/src/search.ts +161 -92
- package/src/simulate.ts +165 -102
- package/src/spec-description.ts +3 -4
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +168 -49
- package/src/successors.ts +6 -3
- package/src/symmetry.ts +1 -0
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +22 -14
- package/src/tlc/tlc-operators.ts +7 -7
- package/src/tlc/tlcext-operators.ts +26 -10
- package/src/tlc/trace-spec.ts +6 -20
- package/src/typed-tier.ts +9 -4
- package/src/values.ts +95 -57
package/src/cli/tlc-output.ts
CHANGED
|
@@ -548,6 +548,7 @@ export const printResult = (result: CheckResult, printer: MessagePrinter, timing
|
|
|
548
548
|
printTrace(printer, failure.trace, "error-trace");
|
|
549
549
|
const traceFailure = failure.traceFailure;
|
|
550
550
|
if (traceFailure) {
|
|
551
|
+
printTraceOutput(printer, traceFailure.output);
|
|
551
552
|
print(
|
|
552
553
|
traceFailure.code,
|
|
553
554
|
MESSAGE_LEVEL.error,
|
package/src/cli/tlc.ts
CHANGED
|
@@ -280,8 +280,9 @@ const checkSpec = async (
|
|
|
280
280
|
} else {
|
|
281
281
|
printError(error, printer);
|
|
282
282
|
}
|
|
283
|
-
|
|
284
|
-
|
|
283
|
+
const exitCode = getTopLevelExitCode(error);
|
|
284
|
+
if (exitCode !== EXIT_STATUS.abort) printFinished();
|
|
285
|
+
return exitCode;
|
|
285
286
|
};
|
|
286
287
|
const config = (() => {
|
|
287
288
|
try {
|
package/src/codegen.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
getFunctionBuilder,
|
|
15
15
|
getLazyFilter,
|
|
16
16
|
isKeptLazy,
|
|
17
|
+
isUniformPredicate,
|
|
17
18
|
getDomainOperator,
|
|
18
19
|
getSubsetOperator,
|
|
19
20
|
getEvaluator,
|
|
@@ -165,9 +166,16 @@ const getFreeNames = (expression: Expression, names = new Set<string>()) => {
|
|
|
165
166
|
return names;
|
|
166
167
|
};
|
|
167
168
|
|
|
168
|
-
const getDelegateContext = (
|
|
169
|
+
const getDelegateContext = (
|
|
170
|
+
generator: Generator,
|
|
171
|
+
expression: Expression,
|
|
172
|
+
frame: Frame,
|
|
173
|
+
isEveryLocalCaptured = false,
|
|
174
|
+
) => {
|
|
169
175
|
const freeNames = getFreeNames(expression);
|
|
170
|
-
const captured = [...frame.locals].filter(
|
|
176
|
+
const captured = [...frame.locals].filter(
|
|
177
|
+
(entry) => isEveryLocalCaptured || freeNames.has(entry[0]),
|
|
178
|
+
);
|
|
171
179
|
if (captured.length === 0) return frame.context;
|
|
172
180
|
const names = addReference(
|
|
173
181
|
generator,
|
|
@@ -176,8 +184,13 @@ const getDelegateContext = (generator: Generator, expression: Expression, frame:
|
|
|
176
184
|
return `extend(${frame.context}, ${names}, [${captured.map((entry) => entry[1]).join(", ")}])`;
|
|
177
185
|
};
|
|
178
186
|
|
|
179
|
-
const generateDelegate = (
|
|
180
|
-
|
|
187
|
+
const generateDelegate = (
|
|
188
|
+
generator: Generator,
|
|
189
|
+
expression: Expression,
|
|
190
|
+
frame: Frame,
|
|
191
|
+
isEveryLocalCaptured = false,
|
|
192
|
+
) =>
|
|
193
|
+
`${addReference(generator, getEvaluator(expression, generator.environment))}(${getDelegateContext(generator, expression, frame, isEveryLocalCaptured)})`;
|
|
181
194
|
|
|
182
195
|
const generateHelper = (
|
|
183
196
|
generator: Generator,
|
|
@@ -267,7 +280,8 @@ const generateSetFilter = (
|
|
|
267
280
|
const lazy = `if (!isReducible(${base})) return ${filterLazily}(${base}, ${getDelegateContext(generator, expression, bodyFrame)});`;
|
|
268
281
|
const set = generateExpression(generator, expression.bound.set, bodyFrame);
|
|
269
282
|
bodyFrame.locals.set(name, element);
|
|
270
|
-
const
|
|
283
|
+
const stop = isUniformPredicate(expression, generator.environment) ? " else break;" : "";
|
|
284
|
+
const test = `if (filterPredicate(${generateExpression(generator, expression.predicate, bodyFrame)}, ${node})) addBounded(${kept}, ${element});${stop}`;
|
|
271
285
|
return `const ${base} = ${set}; ${lazy} const ${list} = ${base}.kind === "Interval" ? ${base} : finiteElements(${base}); const ${kept} = []; ${generateLoop(generator, list, element, test)} return normalizedSet(${kept});`;
|
|
272
286
|
});
|
|
273
287
|
|
|
@@ -318,9 +332,10 @@ const generateApply = (
|
|
|
318
332
|
const domain = addReference(generator, getDomainOperator(expression));
|
|
319
333
|
return `${domain}(${generateExpression(generator, args[0], frame)})`;
|
|
320
334
|
}
|
|
321
|
-
|
|
322
|
-
if (builtin.name === "
|
|
323
|
-
|
|
335
|
+
// TLC caches a constant TLCEval only where no name is bound, so the delegate sees every local.
|
|
336
|
+
if (builtin.name === "TLCEval") return generateDelegate(generator, expression, frame, true);
|
|
337
|
+
if (builtin.name === "\\subseteq" && builtin.evaluateBinary && args.length === 2) {
|
|
338
|
+
const subset = addReference(generator, getSubsetOperator(expression, builtin.evaluateBinary));
|
|
324
339
|
return `${subset}(${generateExpression(generator, args[0], frame)}, ${generateExpression(generator, args[1], frame)})`;
|
|
325
340
|
}
|
|
326
341
|
const environment = generator.environment;
|
package/src/dependencies.ts
CHANGED
|
@@ -156,11 +156,11 @@ const collectLocalFacts = (
|
|
|
156
156
|
definition.params.length > 0),
|
|
157
157
|
});
|
|
158
158
|
} else {
|
|
159
|
-
if (isImpureBuiltin(
|
|
160
|
-
row[0] |= IMPURE | (
|
|
159
|
+
if (isImpureBuiltin(target, environment)) {
|
|
160
|
+
row[0] |= IMPURE | (target === "Assert" ? 0 : REPEATED_EFFECT);
|
|
161
161
|
}
|
|
162
|
-
if (STREAMED_BUILTINS.has(
|
|
163
|
-
if (RANDOM_BUILTINS.has(
|
|
162
|
+
if (STREAMED_BUILTINS.has(target)) row[0] |= STREAMED;
|
|
163
|
+
if (RANDOM_BUILTINS.has(target)) row[0] |= RANDOM;
|
|
164
164
|
if (!isOverridden && isImpureBuiltin(target, environment)) row[0] |= READS_IMPURE;
|
|
165
165
|
const builtin = environment.builtins.get(target);
|
|
166
166
|
if (
|
|
@@ -348,6 +348,7 @@ const EFFECT_FLAGS = {
|
|
|
348
348
|
streamed: STREAMED,
|
|
349
349
|
// What a second evaluation shows: output again, or other random draws.
|
|
350
350
|
replayed: REPEATED_EFFECT | RANDOM,
|
|
351
|
+
varying: IMPURE | RANDOM,
|
|
351
352
|
};
|
|
352
353
|
|
|
353
354
|
export const isExpressionImpure = (
|
package/src/dfid.ts
CHANGED
|
@@ -131,7 +131,7 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
131
131
|
withUnexpectedException(() =>
|
|
132
132
|
createLivenessChecker(temporalProperties, search.spec.temporals, environment, {
|
|
133
133
|
getFingerprint: () => 0,
|
|
134
|
-
|
|
134
|
+
forEachActionSuccessors: () => {},
|
|
135
135
|
}),
|
|
136
136
|
),
|
|
137
137
|
)?.branches;
|
|
@@ -268,16 +268,21 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
268
268
|
config.alias === undefined
|
|
269
269
|
? search.toRecord(state)
|
|
270
270
|
: search.evaluateAlias(config.alias, state, state, isTool);
|
|
271
|
-
const
|
|
272
|
-
? search.getViolatedInvariants(state)
|
|
273
|
-
: [search.findViolatedInvariant(state)].filter((invariant) => invariant !== undefined);
|
|
274
|
-
for (const invariant of violated) {
|
|
271
|
+
const reportInvariant = (name: string) =>
|
|
275
272
|
message(
|
|
276
273
|
MESSAGE_CODE.invariantViolatedInitial,
|
|
277
|
-
`Invariant ${
|
|
274
|
+
`Invariant ${name} is violated by the initial state:\n${formatState(alias())}`,
|
|
278
275
|
);
|
|
279
|
-
|
|
280
|
-
|
|
276
|
+
if (isContinued) {
|
|
277
|
+
search.forEachViolatedInvariant(state, (invariant) => {
|
|
278
|
+
reportInvariant(invariant.name);
|
|
279
|
+
checker.continuedCode = MESSAGE_CODE.invariantViolatedInitial;
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
const violated = isContinued ? undefined : search.findViolatedInvariant(state);
|
|
283
|
+
if (violated) {
|
|
284
|
+
reportInvariant(violated.name);
|
|
285
|
+
return MESSAGE_CODE.invariantViolatedInitial;
|
|
281
286
|
}
|
|
282
287
|
const predicate = search.findFailedInitialPredicate(state);
|
|
283
288
|
if (predicate) {
|
package/src/environment.ts
CHANGED
|
@@ -1131,6 +1131,7 @@ export const createEnvironment = (
|
|
|
1131
1131
|
variableIndex,
|
|
1132
1132
|
facts,
|
|
1133
1133
|
startupValues: Array.from({ length: facts.ids.size }, (): Value | undefined => undefined),
|
|
1134
|
+
tlcEvalValues: new WeakMap(),
|
|
1134
1135
|
substitutedDefinitions,
|
|
1135
1136
|
instanceParams,
|
|
1136
1137
|
evaluators: new WeakMap(),
|
package/src/evaluate.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { MESSAGE_CODE } from "./tlc/messages";
|
|
|
27
27
|
import type { CheckerRuntime } from "./runtime";
|
|
28
28
|
import {
|
|
29
29
|
isEvaluatedAtStartup,
|
|
30
|
+
isExpressionImpure,
|
|
30
31
|
isImpureDefinition,
|
|
31
32
|
isNonconstant,
|
|
32
33
|
type DefinitionFacts,
|
|
@@ -152,6 +153,7 @@ export interface Environment {
|
|
|
152
153
|
variableIndex: Map<string, number>;
|
|
153
154
|
facts: DefinitionFacts;
|
|
154
155
|
startupValues: (Value | undefined)[];
|
|
156
|
+
tlcEvalValues: WeakMap<Expression, Value>;
|
|
155
157
|
substitutedDefinitions: Set<Definition>;
|
|
156
158
|
instanceParams: Set<OperatorParam>;
|
|
157
159
|
evaluators: WeakMap<Expression, Evaluator>;
|
|
@@ -320,15 +322,14 @@ export const getDomainOperator = (expression: Expression) => (value: Value) => {
|
|
|
320
322
|
};
|
|
321
323
|
|
|
322
324
|
export const getSubsetOperator =
|
|
323
|
-
(expression: Expression,
|
|
325
|
+
(expression: Expression, subset: (left: Value, right: Value) => Value) =>
|
|
326
|
+
(left: Value, right: Value) => {
|
|
324
327
|
if (!isSetValue(left) || isOverriddenSet(left)) {
|
|
325
328
|
throw new TlaEvaluationError(
|
|
326
329
|
`Attempted to evaluate an expression of form S \\subseteq T, but S was not enumerable.\n${describeRange(expression)}`,
|
|
327
330
|
);
|
|
328
331
|
}
|
|
329
|
-
return
|
|
330
|
-
? builtin.evaluateBinary(left, right)
|
|
331
|
-
: builtin.evaluate([left, right]);
|
|
332
|
+
return subset(left, right);
|
|
332
333
|
};
|
|
333
334
|
|
|
334
335
|
export const createRealNumberError = (expression: DecimalExpression) =>
|
|
@@ -523,10 +524,13 @@ const someElement = (
|
|
|
523
524
|
return false;
|
|
524
525
|
};
|
|
525
526
|
|
|
526
|
-
export const mapBoundSets = <Result>(
|
|
527
|
+
export const mapBoundSets = <Result>(
|
|
528
|
+
bounds: Bound[],
|
|
529
|
+
map: (set: Expression, index: number) => Result,
|
|
530
|
+
) =>
|
|
527
531
|
bounds.reduce<Result[]>((results, bound, index) => {
|
|
528
532
|
results.push(
|
|
529
|
-
index > 0 && bounds[index - 1].set === bound.set ? results[index - 1] : map(bound.set),
|
|
533
|
+
index > 0 && bounds[index - 1].set === bound.set ? results[index - 1] : map(bound.set, index),
|
|
530
534
|
);
|
|
531
535
|
return results;
|
|
532
536
|
}, []);
|
|
@@ -1323,7 +1327,6 @@ const headFingerprint = (callStack: CallStack, source: Expression, error: unknow
|
|
|
1323
1327
|
|
|
1324
1328
|
export const createTracingEnvironment = (environment: Environment): Environment => ({
|
|
1325
1329
|
...environment,
|
|
1326
|
-
coverage: undefined,
|
|
1327
1330
|
evaluators: new WeakMap(),
|
|
1328
1331
|
entryEvaluators: new WeakMap(),
|
|
1329
1332
|
definitionEvaluators: new WeakMap(),
|
|
@@ -1592,16 +1595,27 @@ const compileApply = (
|
|
|
1592
1595
|
// Deviation from TLC: TLCEval#tlcEval evaluates an argument SANY takes for constant, such as Print(v, TRUE), in an empty state.
|
|
1593
1596
|
const isCached =
|
|
1594
1597
|
!contextualApplications.has(expression) && !isNonconstant(args[0], environment);
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1598
|
+
const tlcEvalValues = environment.tlcEvalValues;
|
|
1599
|
+
return (context) => {
|
|
1600
|
+
if (!isCached || context.scope !== undefined) {
|
|
1601
|
+
return global.evaluate(getLazyArguments(args, context), context);
|
|
1602
|
+
}
|
|
1603
|
+
const cached = tlcEvalValues.get(expression);
|
|
1604
|
+
if (cached !== undefined) return cached;
|
|
1605
|
+
const value = global.evaluate(getLazyArguments(args, context), undefined);
|
|
1606
|
+
tlcEvalValues.set(expression, value);
|
|
1607
|
+
return value;
|
|
1608
|
+
};
|
|
1600
1609
|
}
|
|
1601
|
-
if (
|
|
1610
|
+
if (
|
|
1611
|
+
global?.kind === "Builtin" &&
|
|
1612
|
+
global.name === "\\subseteq" &&
|
|
1613
|
+
global.evaluateBinary &&
|
|
1614
|
+
args.length === 2
|
|
1615
|
+
) {
|
|
1602
1616
|
const left = getEvaluator(args[0], environment);
|
|
1603
1617
|
const right = getEvaluator(args[1], environment);
|
|
1604
|
-
const subset = getSubsetOperator(expression, global);
|
|
1618
|
+
const subset = getSubsetOperator(expression, global.evaluateBinary);
|
|
1605
1619
|
return (context) => subset(left(context), right(context));
|
|
1606
1620
|
}
|
|
1607
1621
|
if (global?.kind === "Builtin") return compileBuiltinCall(global, args, environment);
|
|
@@ -1760,8 +1774,14 @@ export const getFunctionBuilder = (
|
|
|
1760
1774
|
return markLambdaFunction(functionValue);
|
|
1761
1775
|
}
|
|
1762
1776
|
const pairs: [Value, Value][] = [];
|
|
1763
|
-
const sets = mapBoundSets(bounds, (set) =>
|
|
1764
|
-
getNormalizedElements(
|
|
1777
|
+
const sets = mapBoundSets(bounds, (set, index) =>
|
|
1778
|
+
getNormalizedElements(
|
|
1779
|
+
bounds.length > 1 && typeof domain === "object" && domain.kind === "ProductSet"
|
|
1780
|
+
? domain.factors[index]
|
|
1781
|
+
: domain,
|
|
1782
|
+
set,
|
|
1783
|
+
context.environment.runtime.version,
|
|
1784
|
+
),
|
|
1765
1785
|
);
|
|
1766
1786
|
forEachBoundElement(bounds, sets, context.scope, (scope) => {
|
|
1767
1787
|
const key =
|
|
@@ -1960,6 +1980,20 @@ export const getLazyFilter = (
|
|
|
1960
1980
|
createFiltered(base, context, predicate, node);
|
|
1961
1981
|
};
|
|
1962
1982
|
|
|
1983
|
+
const hasLocalName = (expression: Expression): boolean =>
|
|
1984
|
+
isLocallyResolved(expression) ||
|
|
1985
|
+
expression.kind === "OperatorReference" ||
|
|
1986
|
+
getChildren(expression).some(hasLocalName);
|
|
1987
|
+
|
|
1988
|
+
export const isUniformPredicate = (
|
|
1989
|
+
expression: Expression & { kind: "SetFilter" },
|
|
1990
|
+
environment: Environment,
|
|
1991
|
+
) =>
|
|
1992
|
+
expression.bound.pattern.kind === "Name" &&
|
|
1993
|
+
!environment.coverage &&
|
|
1994
|
+
!hasLocalName(expression.predicate) &&
|
|
1995
|
+
!isExpressionImpure([expression.predicate], environment, "varying");
|
|
1996
|
+
|
|
1963
1997
|
export const expectFilterPredicate = (
|
|
1964
1998
|
value: Value,
|
|
1965
1999
|
expression: Expression & { kind: "SetFilter" },
|
|
@@ -2002,20 +2036,21 @@ const compileSetComprehension = (
|
|
|
2002
2036
|
const filterLazily = getLazyFilter(expression, environment);
|
|
2003
2037
|
const pattern = expression.bound.pattern;
|
|
2004
2038
|
const coverage = environment.coverage;
|
|
2039
|
+
const isUniform = isUniformPredicate(expression, environment);
|
|
2005
2040
|
return (context) => {
|
|
2006
2041
|
const base = set(context);
|
|
2007
2042
|
if (!isReducibleSet(base)) return filterLazily(base, context, coverage?.current);
|
|
2008
2043
|
const kept: Value[] = [];
|
|
2009
|
-
const
|
|
2044
|
+
const elements = base.kind === "Interval" ? base : toFiniteSet(base).elements;
|
|
2045
|
+
const size = Array.isArray(elements) ? elements.length : elements.high - elements.low + 1;
|
|
2046
|
+
for (let position = 0; position < size; position++) {
|
|
2047
|
+
const element = Array.isArray(elements) ? elements[position] : elements.low + position;
|
|
2010
2048
|
const value = predicate(withScope(context, bindPattern(context.scope, pattern, element)));
|
|
2011
2049
|
if (expectFilterPredicate(value, expression)) addBoundedElement(kept, element);
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
forEachElement(elements, visit);
|
|
2050
|
+
else if (isUniform) break;
|
|
2051
|
+
}
|
|
2015
2052
|
if (coverage && coverage.current !== -1) {
|
|
2016
|
-
coverage.secondary[coverage.current] +=
|
|
2017
|
-
(Array.isArray(elements) ? elements.length : elements.high - elements.low + 1) +
|
|
2018
|
-
kept.length;
|
|
2053
|
+
coverage.secondary[coverage.current] += size + kept.length;
|
|
2019
2054
|
}
|
|
2020
2055
|
return createNormalizedSet(kept);
|
|
2021
2056
|
};
|
package/src/exit-codes.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { LivenessChecker } from "./liveness-checker";
|
|
1
|
+
import type { LivenessChecker, LivenessChecks } from "./liveness-checker";
|
|
2
2
|
|
|
3
3
|
export const EXIT_STATUS = {
|
|
4
4
|
success: 0,
|
|
5
|
+
abort: 1,
|
|
5
6
|
assumptionViolation: 10,
|
|
6
7
|
deadlock: 11,
|
|
7
8
|
safetyViolation: 12,
|
|
@@ -69,23 +70,36 @@ const withErrorExitCode = <Result>(run: () => Result) => {
|
|
|
69
70
|
}
|
|
70
71
|
};
|
|
71
72
|
|
|
73
|
+
const withCheckerExitCode = (checker: LivenessChecker): LivenessChecker => ({
|
|
74
|
+
branches: checker.branches,
|
|
75
|
+
solutions: checker.solutions,
|
|
76
|
+
addInitialState: (index, state, tracing) =>
|
|
77
|
+
withErrorExitCode(() => checker.addInitialState(index, state, tracing)),
|
|
78
|
+
addState: (index, state, successors, tracing) =>
|
|
79
|
+
withErrorExitCode(() => checker.addState(index, state, successors, tracing)),
|
|
80
|
+
storeState: checker.storeState,
|
|
81
|
+
getStateCounts: checker.getStateCounts,
|
|
82
|
+
findViolation: () => withErrorExitCode(() => checker.findViolation()),
|
|
83
|
+
getViolatedProperties: (path, cycleStart) =>
|
|
84
|
+
withErrorExitCode(() => checker.getViolatedProperties(path, cycleStart)),
|
|
85
|
+
});
|
|
86
|
+
|
|
72
87
|
export const withLivenessExitCode = (
|
|
73
88
|
create: () => LivenessChecker | undefined,
|
|
74
89
|
): LivenessChecker | undefined => {
|
|
75
90
|
const checker = withErrorExitCode(create);
|
|
91
|
+
return checker && withCheckerExitCode(checker);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const withLivenessChecksExitCode = (
|
|
95
|
+
create: () => LivenessChecks | undefined,
|
|
96
|
+
): LivenessChecks | undefined => {
|
|
97
|
+
const checks = withErrorExitCode(create);
|
|
76
98
|
return (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
withErrorExitCode(() => checker.addInitialState(index, state, tracing)),
|
|
82
|
-
addState: (index, state, successors, tracing) =>
|
|
83
|
-
withErrorExitCode(() => checker.addState(index, state, successors, tracing)),
|
|
84
|
-
storeState: checker.storeState,
|
|
85
|
-
getStateCounts: checker.getStateCounts,
|
|
86
|
-
findViolation: () => withErrorExitCode(() => checker.findViolation()),
|
|
87
|
-
getViolatedProperties: (path, cycleStart) =>
|
|
88
|
-
withErrorExitCode(() => checker.getViolatedProperties(path, cycleStart)),
|
|
99
|
+
checks && {
|
|
100
|
+
solutions: checks.solutions,
|
|
101
|
+
createChecker: (search, solutions) =>
|
|
102
|
+
withCheckerExitCode(checks.createChecker(search, solutions)),
|
|
89
103
|
}
|
|
90
104
|
);
|
|
91
105
|
};
|
package/src/java-hash.ts
CHANGED
|
@@ -5,3 +5,17 @@ export const getJavaHashCode = (text: string): number => {
|
|
|
5
5
|
}
|
|
6
6
|
return hash;
|
|
7
7
|
};
|
|
8
|
+
|
|
9
|
+
const getHashMapHash = (text: string) => {
|
|
10
|
+
const hash = getJavaHashCode(text);
|
|
11
|
+
return hash ^ (hash >>> 16);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const getHashMapOrder = (names: string[]) => {
|
|
15
|
+
const unique = [...new Set(names)];
|
|
16
|
+
const capacity = 2 ** Math.max(4, Math.ceil(Math.log2(unique.length / 0.75)));
|
|
17
|
+
return unique
|
|
18
|
+
.map((name, index) => ({ name, index, bucket: getHashMapHash(name) & (capacity - 1) }))
|
|
19
|
+
.sort((left, right) => left.bucket - right.bucket || left.index - right.index)
|
|
20
|
+
.map((entry) => entry.name);
|
|
21
|
+
};
|