tla-ts 0.0.10-dev.a17d6d9fa → 0.0.10-dev.a5705bfbf

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.
Files changed (78) hide show
  1. package/dist/deciders.cjs +31 -31
  2. package/dist/deciders.js +2 -2
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.cts +12 -2
  5. package/dist/index.d.ts +12 -2
  6. package/dist/index.js +1 -1
  7. package/dist/parallel-worker.cjs +1 -1
  8. package/dist/parallel-worker.js +1 -1
  9. package/dist/prove.cjs +64 -64
  10. package/dist/prove.js +76 -76
  11. package/dist/run.cjs +42 -42
  12. package/dist/run.js +44 -44
  13. package/dist/transfer.cjs +37 -35
  14. package/dist/transfer.js +43 -41
  15. package/dist/worker.cjs +7 -7
  16. package/dist/worker.js +7 -7
  17. package/package.json +1 -1
  18. package/src/ast.ts +10 -1
  19. package/src/check-failure.ts +12 -10
  20. package/src/check-trace.ts +36 -23
  21. package/src/check.ts +182 -135
  22. package/src/cli/tlc-output.ts +17 -2
  23. package/src/cli/tlc.ts +2 -2
  24. package/src/codegen.ts +15 -19
  25. package/src/coverage.ts +190 -1
  26. package/src/dependencies.ts +19 -6
  27. package/src/dfid.ts +80 -27
  28. package/src/environment.ts +30 -1
  29. package/src/evaluate.ts +254 -59
  30. package/src/exit-codes.ts +25 -13
  31. package/src/instances.ts +11 -1
  32. package/src/levels.ts +48 -7
  33. package/src/liveness-checker.ts +98 -27
  34. package/src/liveness.ts +4 -1
  35. package/src/obligations/source.ts +2 -0
  36. package/src/parser.ts +3 -0
  37. package/src/prover/smt/solver/card2bv.ts +7 -4
  38. package/src/prover/smt/solver/context.ts +20 -4
  39. package/src/prover/smt/solver/dependent-expr-state.ts +18 -12
  40. package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
  41. package/src/prover/smt/solver/fd-solver.ts +146 -39
  42. package/src/prover/smt/solver/maxcore.ts +2 -1
  43. package/src/prover/smt/solver/maxsmt-base.ts +1 -0
  44. package/src/prover/smt/solver/model-checker.ts +1 -1
  45. package/src/prover/smt/solver/muz/dl-context.ts +12 -40
  46. package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
  47. package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
  48. package/src/prover/smt/solver/muz/hnf.ts +2 -2
  49. package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
  50. package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
  51. package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
  52. package/src/prover/smt/solver/opt-context.ts +1 -0
  53. package/src/prover/smt/solver/opt-solver.ts +1 -1
  54. package/src/prover/smt/solver/parallel-tactic.ts +1 -1
  55. package/src/prover/smt/solver/qsat.ts +7 -2
  56. package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
  57. package/src/prover/smt/solver/sat/inc-sat-solver.ts +45 -26
  58. package/src/prover/smt/solver/sat/sat-tactic.ts +4 -2
  59. package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
  60. package/src/prover/smt/solver/smt-consequences.ts +1 -1
  61. package/src/prover/smt/solver/smt-kernel.ts +9 -2
  62. package/src/prover/smt/solver/smtlib-parser.ts +6 -2
  63. package/src/prover/smt/solver/smtlib-script.ts +197 -73
  64. package/src/prover/smt/solver/tactic.ts +64 -37
  65. package/src/resolve.ts +143 -39
  66. package/src/sany/generator-expressions.ts +2 -0
  67. package/src/sany/generator-proofs.ts +1 -0
  68. package/src/search.ts +156 -37
  69. package/src/simulate.ts +143 -150
  70. package/src/spec-description.ts +3 -0
  71. package/src/standard-modules.ts +41 -16
  72. package/src/subexpressions.ts +168 -63
  73. package/src/successors.ts +33 -11
  74. package/src/symmetry.ts +1 -0
  75. package/src/tlc/replay.ts +64 -41
  76. package/src/trace-liveness.ts +529 -0
  77. package/src/typed-tier.ts +20 -6
  78. package/src/values.ts +15 -1
@@ -1,4 +1,4 @@
1
- import { SmtTacticError, SmtUnsupportedError } from "../../../../errors";
1
+ import { SmtCanceledError, SmtTacticError, SmtUnsupportedError } from "../../../../errors";
2
2
  import { type AstManager, OP_AND, OP_EQ, OP_IMPLIES, OP_NOT, OP_OR, SORT_BOOL } from "../ast";
3
3
  import { mkNot } from "../ast-util";
4
4
  import { BitBlasterRewriter } from "../bit-blast-tactic";
@@ -7,11 +7,16 @@ import { L_FALSE, L_TRUE, L_UNDEF } from "../lbool";
7
7
  import { ProtoModel } from "../proto-model";
8
8
  import { RefVector } from "../ref-vector";
9
9
  import type { ThSolverFactory } from "../euf/euf-solver";
10
- import { convertModel, mkIncSatEufPreprocess, mkIncSatPreprocess } from "../tactic";
10
+ import {
11
+ applyDefinitions,
12
+ convertModel,
13
+ mkIncSatEufPreprocess,
14
+ mkIncSatPreprocess,
15
+ } from "../tactic";
11
16
  import type { SatParams } from "./config";
12
17
  import { Goal2Sat } from "./goal2sat";
13
18
  import { getConsequences } from "./consequences";
14
- import { isLiteral, sat2goal } from "./sat2goal";
19
+ import { isLiteral, Sat2GoalConverter, sat2goal } from "./sat2goal";
15
20
  import { Solver } from "./solver";
16
21
 
17
22
  const BIT_BLAST_PARAMS = {
@@ -42,6 +47,7 @@ export class IncSatSolver {
42
47
  private bitBlaster: BitBlasterRewriter | undefined;
43
48
  // m_mcs.back(), the model converters of the preprocessed goals.
44
49
  private readonly converters: Goal;
50
+ private readonly satConverter: Sat2GoalConverter;
45
51
  private isInternalizedConverted = false;
46
52
  private readonly internalized: RefVector;
47
53
  private hasUninterpreted = false;
@@ -69,6 +75,7 @@ export class IncSatSolver {
69
75
  this.names = new RefVector(manager);
70
76
  this.core = new RefVector(manager);
71
77
  this.converters = new Goal(manager);
78
+ this.satConverter = new Sat2GoalConverter(manager);
72
79
  this.internalized = new RefVector(manager);
73
80
  }
74
81
 
@@ -111,17 +118,20 @@ export class IncSatSolver {
111
118
  }
112
119
 
113
120
  push() {
114
- this.internalizeFormulas();
115
- this.goal2sat.push();
116
- this.solver.userPush();
117
- this.bitBlaster?.push();
118
- this.scopes.push({
119
- converters: this.converters.converters,
120
- fmlsSize: this.fmls.size,
121
- fmlsHead: this.fmlsHead,
122
- namesSize: this.names.size,
123
- hasUninterpreted: this.hasUninterpreted,
124
- });
121
+ try {
122
+ this.internalizeFormulas();
123
+ } finally {
124
+ this.goal2sat.push();
125
+ this.solver.userPush();
126
+ this.bitBlaster?.push();
127
+ this.scopes.push({
128
+ converters: this.converters.converters,
129
+ fmlsSize: this.fmls.size,
130
+ fmlsHead: this.fmlsHead,
131
+ namesSize: this.names.size,
132
+ hasUninterpreted: this.hasUninterpreted,
133
+ });
134
+ }
125
135
  }
126
136
 
127
137
  pop(numScopes: number) {
@@ -177,8 +187,10 @@ export class IncSatSolver {
177
187
  return goals;
178
188
  } catch (error) {
179
189
  this.releaseBitBlaster();
180
- if (!(error instanceof SmtTacticError)) throw error;
181
- this.reasonUnknown = error.message;
190
+ if (!(error instanceof SmtTacticError || error instanceof SmtCanceledError)) throw error;
191
+ // The tactics of the preprocessing report a limit that stops their rewriters as a tactic_exception.
192
+ this.reasonUnknown =
193
+ error instanceof SmtCanceledError ? this.manager.limit.getCancelMessage() : error.message;
182
194
  return undefined;
183
195
  }
184
196
  })();
@@ -239,7 +251,16 @@ export class IncSatSolver {
239
251
  this.internalizeAssumptions([...literals, ...this.names.items]);
240
252
  this.reasonUnknown = "no reason given";
241
253
  this.isInternalizedConverted = false;
242
- const result = this.solver.check(this.asms);
254
+ const result = (() => {
255
+ try {
256
+ return this.solver.check(this.asms);
257
+ } catch (error) {
258
+ if (!(error instanceof SmtCanceledError)) throw error;
259
+ // check_sat_core counts a step to see whether the limit stopped the search.
260
+ manager.limit.inc();
261
+ return L_UNDEF;
262
+ }
263
+ })();
243
264
  if (result === L_TRUE && this.hasUninterpreted) {
244
265
  this.reasonUnknown = "(sat.giveup has-uninterpreted)";
245
266
  return L_UNDEF;
@@ -337,18 +358,15 @@ export class IncSatSolver {
337
358
  const manager = this.manager;
338
359
  if (!this.solver.isModelCurrent || this.fmls.size > this.fmlsHead) return null;
339
360
  const euf = this.goal2sat.euf;
340
- // The euf solver fills a model rather than a proto_model, so its declarations keep their order.
341
- const model = euf === null ? new ProtoModel(manager) : new ProtoModel(manager).mkModel();
361
+ const model = new ProtoModel(manager).mkModel();
342
362
  for (const [expr, boolVar] of this.goal2sat.atoms) {
343
363
  if (!manager.isUninterpretedConst(expr)) continue;
344
364
  const value = this.solver.model[boolVar];
345
365
  if (value === L_TRUE) model.registerConst(manager.decls[expr], manager.trueExpr);
346
366
  else if (value === L_FALSE) model.registerConst(manager.decls[expr], manager.falseExpr);
347
367
  }
348
- const converted = convertModel(
349
- this.converters,
350
- euf === null ? model.mkModel() : euf.updateModel(model),
351
- );
368
+ if (this.satConverter.entries.length > 0) applyDefinitions(this.satConverter.entries, model);
369
+ const converted = convertModel(this.converters, euf === null ? model : euf.updateModel(model));
352
370
  converted.incRef();
353
371
  this.models.push(converted);
354
372
  return converted;
@@ -379,10 +397,9 @@ export class IncSatSolver {
379
397
  if (this.fmlsHead !== this.fmls.size) return this.fmls.items;
380
398
  if (this.isInternalizedConverted) return this.internalized.items;
381
399
  const goal = new Goal(this.manager);
382
- sat2goal(this.manager, this.solver, this.goal2sat.atoms, goal);
400
+ sat2goal(this.manager, this.solver, this.goal2sat.atoms, goal, this.satConverter);
383
401
  this.internalized.reset();
384
402
  for (const form of goal.forms.items) this.internalized.push(form);
385
- this.converters.converters = [...this.converters.converters, ...goal.converters];
386
403
  this.isInternalizedConverted = true;
387
404
  return this.internalized.items;
388
405
  }
@@ -391,7 +408,9 @@ export class IncSatSolver {
391
408
  // asserted formulas are internalized.
392
409
  getConverters(): Goal["converters"] {
393
410
  this.getAssertions();
394
- return this.isInternalizedConverted ? this.converters.converters : [];
411
+ return this.isInternalizedConverted
412
+ ? [...this.converters.converters, { definitions: this.satConverter.entries }]
413
+ : [];
395
414
  }
396
415
 
397
416
  release() {
@@ -6,7 +6,7 @@ import { L_FALSE, L_TRUE, L_UNDEF } from "../lbool";
6
6
  import { ProtoModel } from "../proto-model";
7
7
  import type { SatParams } from "./config";
8
8
  import { Goal2Sat } from "./goal2sat";
9
- import { sat2goal } from "./sat2goal";
9
+ import { Sat2GoalConverter, sat2goal } from "./sat2goal";
10
10
  import { Solver } from "./solver";
11
11
 
12
12
  // With a theory factory, the sat solver runs the euf solver of sat.euf as its extension.
@@ -43,7 +43,9 @@ export const createSatTactic =
43
43
  euf?.validateModel(goal.model);
44
44
  } else {
45
45
  solver.popToBaseLevel();
46
- sat2goal(manager, solver, goal2sat.atoms, goal);
46
+ const converter = new Sat2GoalConverter(manager);
47
+ sat2goal(manager, solver, goal2sat.atoms, goal, converter);
48
+ goal.addDefinitions(converter.entries);
47
49
  if (unhandledFuns.length > 0) goal.updatePrecision(OVER);
48
50
  }
49
51
  goal.depth++;
@@ -12,9 +12,9 @@ export const isLiteral = (manager: AstManager, expr: number) =>
12
12
  manager.isUninterpretedConst(expr) ||
13
13
  (manager.isNot(expr) && manager.isUninterpretedConst(manager.getArg(expr, 0)));
14
14
 
15
- class Sat2GoalConverter {
15
+ export class Sat2GoalConverter {
16
16
  readonly smc = new ModelConverter();
17
- var2expr: number[] = [];
17
+ readonly var2expr: number[] = [];
18
18
  readonly entries: Definition[] = [];
19
19
 
20
20
  constructor(private manager: AstManager) {}
@@ -22,17 +22,21 @@ class Sat2GoalConverter {
22
22
  private add(expr: number, def: number) {
23
23
  const manager = this.manager;
24
24
  manager.incRef(def);
25
+ manager.incDeclRef(manager.decls[expr]);
25
26
  this.entries.push({ decl: manager.decls[expr], def });
26
27
  }
27
28
 
28
29
  hide(expr: number) {
29
- this.entries.push({ decl: this.manager.decls[expr], def: -1 });
30
+ const manager = this.manager;
31
+ manager.incDeclRef(manager.decls[expr]);
32
+ this.entries.push({ decl: manager.decls[expr], def: -1 });
30
33
  }
31
34
 
32
35
  flushSmc(solver: Solver, atoms: Map<number, number>) {
33
36
  this.smc.flush(solver.mc);
34
- this.var2expr.length = solver.numVars();
35
- this.var2expr.fill(-1);
37
+ const numVars = solver.numVars();
38
+ while (this.var2expr.length < numVars) this.var2expr.push(-1);
39
+ this.var2expr.length = numVars;
36
40
  for (const [expr, boolVar] of atoms) this.var2expr[boolVar] = expr;
37
41
  this.flushGmc();
38
42
  }
@@ -106,12 +110,12 @@ export const sat2goal = (
106
110
  solver: Solver,
107
111
  atoms: Map<number, number>,
108
112
  goal: Goal,
113
+ converter: Sat2GoalConverter,
109
114
  ) => {
110
115
  if (solver.atBaseLvl() && solver.isInconsistent) {
111
116
  goal.assert(manager.falseExpr);
112
117
  return;
113
118
  }
114
- const converter = new Sat2GoalConverter(manager);
115
119
  converter.flushSmc(solver, atoms);
116
120
  const lit2expr = new Int32Array(2 * solver.numVars()).fill(-1);
117
121
  for (const [expr, boolVar] of atoms) {
@@ -161,5 +165,4 @@ export const sat2goal = (
161
165
  const formulas: number[] = [];
162
166
  solver.ext?.toFormulas(getExpr, formulas);
163
167
  for (const formula of formulas) goal.assert(formula);
164
- goal.addDefinitions(converter.entries);
165
168
  };
@@ -239,7 +239,7 @@ class ConsequenceFinder {
239
239
  const result = kernel.check(assumptions);
240
240
  if (result !== L_TRUE) return result;
241
241
  if (context.qmanager.hasQuantifiers()) return L_UNDEF;
242
- const model = context.getModel();
242
+ const model = context.getSatModel();
243
243
  for (const variable of vars) {
244
244
  const value = model.eval(variable, false);
245
245
  trail.pushOwned(value);
@@ -14,6 +14,7 @@ export class SmtKernel {
14
14
  isSetUp = false;
15
15
  private setup: SmtSetup | undefined;
16
16
  private isCoreMinimizing: boolean;
17
+ private scopeCount = 0;
17
18
 
18
19
  constructor(manager: AstManager, params: KernelParams) {
19
20
  this.asserted = new AssertedFormulas(manager, params.isFindingMacros);
@@ -50,7 +51,9 @@ export class SmtKernel {
50
51
  this.asserted.isPreprocessing = isPreprocessing;
51
52
  }
52
53
 
54
+ // context::assert_expr_core counts a step, and drops the formula once the limit is spent.
53
55
  assertExpr(expr: number) {
56
+ if (this.context.checkCanceled()) return;
54
57
  this.context.popToBaseLevel();
55
58
  this.asserted.assertExpr(expr);
56
59
  }
@@ -71,6 +74,7 @@ export class SmtKernel {
71
74
  limit.isSuspended = wasSuspended;
72
75
  context.push();
73
76
  this.asserted.push();
77
+ this.scopeCount++;
74
78
  }
75
79
 
76
80
  getAssertions() {
@@ -78,8 +82,11 @@ export class SmtKernel {
78
82
  }
79
83
 
80
84
  pop(numScopes: number) {
81
- this.context.pop(numScopes);
82
- for (let index = 0; index < numScopes; index++) this.asserted.pop();
85
+ const count = Math.min(numScopes, this.scopeCount);
86
+ if (count === 0) return;
87
+ this.context.pop(count);
88
+ for (let index = 0; index < count; index++) this.asserted.pop();
89
+ this.scopeCount -= count;
83
90
  }
84
91
 
85
92
  initAssumptions(assumptions: number[]) {
@@ -978,6 +978,7 @@ export const createSmtlibReader = (
978
978
  const macros = new Map<string, Macro>();
979
979
  // A pop empties the macros of a name but keeps the name in the dictionary.
980
980
  const macroNames: string[] = [];
981
+ const dictionaryNames = new Set<string>();
981
982
  const macroDictionary = new ObjMap<string>((index) => getSymbolHash(macroNames[index]));
982
983
  const lastNamed = { name: "", expr: -1 };
983
984
  const notifiedSorts = new Set<number>();
@@ -1016,7 +1017,10 @@ export const createSmtlibReader = (
1016
1017
  };
1017
1018
 
1018
1019
  const insertMacro = (name: string, macro: Macro) => {
1019
- if (!macroNames.includes(name)) macroDictionary.set(macroNames.push(name) - 1, name);
1020
+ if (!dictionaryNames.has(name)) {
1021
+ dictionaryNames.add(name);
1022
+ macroDictionary.set(macroNames.push(name) - 1, name);
1023
+ }
1020
1024
  declare(macros, name, macro);
1021
1025
  };
1022
1026
 
@@ -3554,7 +3558,7 @@ export const createSmtlibReader = (
3554
3558
  getFuncs: (name: string) => funcs.get(name) ?? [],
3555
3559
  hasDefinitions,
3556
3560
  parseTerm,
3557
- parseSort: (sexpr: SExpr) => parseSort(sexpr, ""),
3561
+ parseSort: (sexpr: SExpr, context: string) => parseSort(sexpr, context),
3558
3562
  parseFormula,
3559
3563
  parseAssertion,
3560
3564
  getLogicError: logicChecker.checkExpr,