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.
- package/dist/deciders.cjs +31 -31
- package/dist/deciders.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -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 +64 -64
- package/dist/prove.js +76 -76
- package/dist/run.cjs +42 -42
- package/dist/run.js +44 -44
- package/dist/transfer.cjs +37 -35
- package/dist/transfer.js +43 -41
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +10 -1
- package/src/check-failure.ts +12 -10
- package/src/check-trace.ts +36 -23
- package/src/check.ts +182 -135
- package/src/cli/tlc-output.ts +17 -2
- package/src/cli/tlc.ts +2 -2
- package/src/codegen.ts +15 -19
- package/src/coverage.ts +190 -1
- package/src/dependencies.ts +19 -6
- package/src/dfid.ts +80 -27
- package/src/environment.ts +30 -1
- package/src/evaluate.ts +254 -59
- package/src/exit-codes.ts +25 -13
- package/src/instances.ts +11 -1
- package/src/levels.ts +48 -7
- package/src/liveness-checker.ts +98 -27
- package/src/liveness.ts +4 -1
- package/src/obligations/source.ts +2 -0
- package/src/parser.ts +3 -0
- package/src/prover/smt/solver/card2bv.ts +7 -4
- package/src/prover/smt/solver/context.ts +20 -4
- package/src/prover/smt/solver/dependent-expr-state.ts +18 -12
- package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
- package/src/prover/smt/solver/fd-solver.ts +146 -39
- 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/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 +1 -0
- package/src/prover/smt/solver/opt-solver.ts +1 -1
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/qsat.ts +7 -2
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +45 -26
- package/src/prover/smt/solver/sat/sat-tactic.ts +4 -2
- 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 +9 -2
- package/src/prover/smt/solver/smtlib-parser.ts +6 -2
- package/src/prover/smt/solver/smtlib-script.ts +197 -73
- package/src/prover/smt/solver/tactic.ts +64 -37
- package/src/resolve.ts +143 -39
- package/src/sany/generator-expressions.ts +2 -0
- package/src/sany/generator-proofs.ts +1 -0
- package/src/search.ts +156 -37
- package/src/simulate.ts +143 -150
- package/src/spec-description.ts +3 -0
- package/src/standard-modules.ts +41 -16
- package/src/subexpressions.ts +168 -63
- package/src/successors.ts +33 -11
- package/src/symmetry.ts +1 -0
- package/src/tlc/replay.ts +64 -41
- package/src/trace-liveness.ts +529 -0
- package/src/typed-tier.ts +20 -6
- package/src/values.ts +15 -1
|
@@ -53,7 +53,7 @@ import { isMbqiByFeatures, isMbqiByLogic } from "./smt-setup";
|
|
|
53
53
|
import { isSupportedLogic, logicHasSeq } from "./smt-logics";
|
|
54
54
|
import { getVerdict, solveAssertions, solveAssuming } from "./solver";
|
|
55
55
|
import { getConsequences } from "./smt-consequences";
|
|
56
|
-
import { getFdConsequences } from "./fd-solver";
|
|
56
|
+
import { checkFdSolver, getFdConsequences } from "./fd-solver";
|
|
57
57
|
import { SmtKernel } from "./smt-kernel";
|
|
58
58
|
import { RefVector } from "./ref-vector";
|
|
59
59
|
import { IncSatSolver } from "./sat/inc-sat-solver";
|
|
@@ -109,7 +109,6 @@ const UNPORTED_COMMANDS = new Set([
|
|
|
109
109
|
"get-interpolant",
|
|
110
110
|
"get-proof",
|
|
111
111
|
"get-proof-graph",
|
|
112
|
-
"get-unsat-assumptions",
|
|
113
112
|
"get-user-tactics",
|
|
114
113
|
"help",
|
|
115
114
|
"help-simplifier",
|
|
@@ -267,6 +266,17 @@ const getSimplifyParams = (items: SExpr[]) => {
|
|
|
267
266
|
return params;
|
|
268
267
|
};
|
|
269
268
|
|
|
269
|
+
const GET_INFO_KEYWORDS = [
|
|
270
|
+
":reason-unknown",
|
|
271
|
+
":status",
|
|
272
|
+
":version",
|
|
273
|
+
":authors",
|
|
274
|
+
":error-behavior",
|
|
275
|
+
":parameters",
|
|
276
|
+
":rlimit",
|
|
277
|
+
":assertion-stack-levels",
|
|
278
|
+
];
|
|
279
|
+
|
|
270
280
|
const APPLY_PARAMETERS = new Map([
|
|
271
281
|
["print", true],
|
|
272
282
|
["print_model_converter", true],
|
|
@@ -344,6 +354,7 @@ interface Scope {
|
|
|
344
354
|
assertions: number;
|
|
345
355
|
objectives: number;
|
|
346
356
|
softTrail: number;
|
|
357
|
+
rlimit: number;
|
|
347
358
|
}
|
|
348
359
|
|
|
349
360
|
interface CheckResult {
|
|
@@ -414,6 +425,7 @@ export const runSmtlibScript = (
|
|
|
414
425
|
isPrintingSuccess: false,
|
|
415
426
|
isProducingModels: true,
|
|
416
427
|
isProducingUnsatCores: false,
|
|
428
|
+
isProducingUnsatAssumptions: false,
|
|
417
429
|
isProducingProofs: false,
|
|
418
430
|
isExitingOnError: false,
|
|
419
431
|
isInteractive: false,
|
|
@@ -550,13 +562,15 @@ export const runSmtlibScript = (
|
|
|
550
562
|
return false;
|
|
551
563
|
}
|
|
552
564
|
if (error instanceof SmtDefaultError) {
|
|
553
|
-
setCheck(L_UNDEF, { isFromTactic: true, reasonUnknown:
|
|
565
|
+
setCheck(L_UNDEF, { isFromTactic: true, reasonUnknown: optimizer.getReasonUnknown() });
|
|
554
566
|
throw new SmtParseError(error.message, end);
|
|
555
567
|
}
|
|
556
568
|
if (!(error instanceof SmtCanceledError || isStackOverflow(error))) throw error;
|
|
557
569
|
const reasonUnknown = optimizer.getReasonUnknown();
|
|
558
570
|
optimizer.release();
|
|
559
571
|
setCheck(L_UNDEF, { isOptimizing: true, reasonUnknown });
|
|
572
|
+
if (error instanceof SmtCanceledError)
|
|
573
|
+
throw new SmtParseError(manager.limit.getCancelMessage(), end);
|
|
560
574
|
print("unknown");
|
|
561
575
|
return true;
|
|
562
576
|
} finally {
|
|
@@ -570,21 +584,22 @@ export const runSmtlibScript = (
|
|
|
570
584
|
};
|
|
571
585
|
// The port keeps answering with the smt kernel where it lacks a piece of the logic's strategy.
|
|
572
586
|
const solveWithStrategy = () => {
|
|
573
|
-
const goal = getGoal();
|
|
574
|
-
const strategy =
|
|
575
|
-
settings.parameters.get("tactic.default_tactic") ??
|
|
576
|
-
getLogicStrategy(state.logic, goal.isProofsEnabled);
|
|
577
587
|
try {
|
|
588
|
+
if (isUsingFdSolver())
|
|
589
|
+
return {
|
|
590
|
+
...checkFdSolver(state.manager, getSatParams(settings.parameters), state.assertions),
|
|
591
|
+
context: undefined,
|
|
592
|
+
};
|
|
593
|
+
const goal = getGoal();
|
|
594
|
+
const strategy =
|
|
595
|
+
settings.parameters.get("tactic.default_tactic") ??
|
|
596
|
+
getLogicStrategy(state.logic, goal.isProofsEnabled);
|
|
578
597
|
const checked = checkSatUsing(compileInternalTactic(getTacticEnvironment(), strategy), goal);
|
|
579
598
|
return {
|
|
580
599
|
result: checked.status,
|
|
581
600
|
context: undefined,
|
|
582
601
|
model: checked.model,
|
|
583
|
-
|
|
584
|
-
reasonUnknown:
|
|
585
|
-
isUsingFdSolver() && checked.status !== L_UNDEF
|
|
586
|
-
? "no reason given"
|
|
587
|
-
: checked.reasonUnknown,
|
|
602
|
+
reasonUnknown: checked.reasonUnknown,
|
|
588
603
|
};
|
|
589
604
|
} catch (error) {
|
|
590
605
|
if (!(error instanceof SmtUnsupportedError)) throw error;
|
|
@@ -663,11 +678,12 @@ export const runSmtlibScript = (
|
|
|
663
678
|
setCheck(solved.result, {
|
|
664
679
|
context: solved.context,
|
|
665
680
|
isOptimizing,
|
|
666
|
-
isFromTactic
|
|
681
|
+
isFromTactic,
|
|
667
682
|
model: solved.model,
|
|
668
683
|
core: solved.core ?? solved.context?.unsatCore ?? [],
|
|
669
684
|
reasonUnknown: getReasonUnknown(solved, deadline),
|
|
670
685
|
});
|
|
686
|
+
if (isFromTactic && isUsingFdSolver()) solved.model?.decRef();
|
|
671
687
|
print(getVerdict(solved.result));
|
|
672
688
|
} catch (error) {
|
|
673
689
|
if (
|
|
@@ -679,13 +695,14 @@ export const runSmtlibScript = (
|
|
|
679
695
|
)
|
|
680
696
|
throw error;
|
|
681
697
|
const context = isKernelChecking ? state.kernel?.context : undefined;
|
|
698
|
+
const reasonUnknown = isKernelChecking ? state.satSolver?.reasonUnknown : undefined;
|
|
682
699
|
setCheck(L_UNDEF, {
|
|
683
700
|
isOptimizing,
|
|
684
|
-
isFromTactic: !isKernelChecking
|
|
701
|
+
isFromTactic: !isKernelChecking,
|
|
685
702
|
reasonUnknown:
|
|
686
703
|
error instanceof SmtDefaultError
|
|
687
704
|
? error.message
|
|
688
|
-
: getReasonUnknown({ result: L_UNDEF, context, reasonUnknown
|
|
705
|
+
: getReasonUnknown({ result: L_UNDEF, context, reasonUnknown }, deadline),
|
|
689
706
|
});
|
|
690
707
|
print("unknown");
|
|
691
708
|
} finally {
|
|
@@ -703,7 +720,9 @@ export const runSmtlibScript = (
|
|
|
703
720
|
throw check.isFromTactic
|
|
704
721
|
? new SmtParseError("model is not available", list.end)
|
|
705
722
|
: new SmtUnsupportedError("the model of a canceled search");
|
|
706
|
-
const
|
|
723
|
+
const context = check.context;
|
|
724
|
+
const model = context === undefined ? new ProtoModel(state.manager) : context.getModel();
|
|
725
|
+
if (model === undefined) throw new SmtParseError("model is not available", list.end);
|
|
707
726
|
model.incRef();
|
|
708
727
|
check.model = model;
|
|
709
728
|
return model;
|
|
@@ -755,6 +774,13 @@ export const runSmtlibScript = (
|
|
|
755
774
|
useSatSolver((solver) => solver.push());
|
|
756
775
|
}
|
|
757
776
|
};
|
|
777
|
+
const initManager = () => {
|
|
778
|
+
if (state.isProofsEnabled !== undefined) return;
|
|
779
|
+
state.isProofsEnabled = settings.parameters.get("proof") === "true";
|
|
780
|
+
if (state.logic === undefined || logicHasSeq(state.logic)) state.manager.initSeqPlugin();
|
|
781
|
+
if (state.logic === undefined) state.reader.registerList();
|
|
782
|
+
resetKernel();
|
|
783
|
+
};
|
|
758
784
|
// The parts of inc_sat_solver that are not ported leave its answers to the smt kernel.
|
|
759
785
|
const useSatSolver = <Result>(action: (solver: IncSatSolver) => Result) => {
|
|
760
786
|
const solver = state.satSolver;
|
|
@@ -989,10 +1015,15 @@ export const runSmtlibScript = (
|
|
|
989
1015
|
`Invalid function name. Expecting sort list starting with '(' to disambiguate function name got ${domain.lastId}`,
|
|
990
1016
|
domain,
|
|
991
1017
|
);
|
|
992
|
-
const sorts = domain.items.map((sort) =>
|
|
1018
|
+
const sorts = domain.items.map((sort) =>
|
|
1019
|
+
state.reader.parseSort(
|
|
1020
|
+
sort,
|
|
1021
|
+
"Invalid function name. Expecting sort list starting with '(' to disambiguate function name",
|
|
1022
|
+
),
|
|
1023
|
+
);
|
|
993
1024
|
if (reference.items[2] === undefined)
|
|
994
1025
|
throw new SmtParseError("Invalid function name invalid sort, unexpected ')'", reference.end);
|
|
995
|
-
const range = state.reader.parseSort(reference.items[2]);
|
|
1026
|
+
const range = state.reader.parseSort(reference.items[2], "Invalid function name");
|
|
996
1027
|
const follower = reference.items[3] ?? reference.end;
|
|
997
1028
|
const found = state.reader.getFuncs(name.text).find((decl) => {
|
|
998
1029
|
const funcDecl = state.manager.funcDecls[decl];
|
|
@@ -1011,6 +1042,76 @@ export const runSmtlibScript = (
|
|
|
1011
1042
|
throw new SmtUnsupportedError("a function declaration reference with trailing terms");
|
|
1012
1043
|
return found;
|
|
1013
1044
|
};
|
|
1045
|
+
// get_info_cmd prints in set_next_arg, before the parser checks the rest of the command.
|
|
1046
|
+
const printInfo = (list: SmtList, keyword: string) => {
|
|
1047
|
+
if (keyword === ":reason-unknown") {
|
|
1048
|
+
const check = state.check;
|
|
1049
|
+
const reasonUnknown =
|
|
1050
|
+
check === undefined
|
|
1051
|
+
? "state of the most recent check-sat command is not known"
|
|
1052
|
+
: check.reasonUnknown;
|
|
1053
|
+
if (reasonUnknown === undefined)
|
|
1054
|
+
throw new SmtUnsupportedError("the information :reason-unknown");
|
|
1055
|
+
print(`(:reason-unknown "${reasonUnknown.replaceAll('"', '\\"')}")`);
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
if (keyword === ":rlimit") {
|
|
1059
|
+
initManager();
|
|
1060
|
+
print(`(:rlimit ${state.manager.limit.count})`);
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
if (keyword === ":error-behavior") {
|
|
1064
|
+
print(
|
|
1065
|
+
`(:error-behavior ${settings.isExitingOnError ? "immediate-exit" : "continued-execution"})`,
|
|
1066
|
+
);
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
if (keyword === ":name") {
|
|
1070
|
+
print('(:name "Z3")');
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
if (keyword === ":authors") {
|
|
1074
|
+
print(
|
|
1075
|
+
'(:authors "Leonardo de Moura, Nikolaj Bjorner, Lev Nachmanson and Christoph Wintersteiger")',
|
|
1076
|
+
);
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
if (keyword === ":version") {
|
|
1080
|
+
print('(:version "5.3.2")');
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
if (keyword === ":status") {
|
|
1084
|
+
print(`(:status ${getVerdict(settings.status)})`);
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
if (keyword === ":assertion-stack-levels") {
|
|
1088
|
+
print(`(:assertion-stack-levels ${state.scopes.length})`);
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
if (keyword === ":all-statistics" || keyword === ":parameters")
|
|
1092
|
+
throw new SmtUnsupportedError(`the information ${keyword}`);
|
|
1093
|
+
if (keyword !== ":?") {
|
|
1094
|
+
print("unsupported");
|
|
1095
|
+
printDiagnostic(`; ${keyword} line: ${list.line} position: ${list.column}`);
|
|
1096
|
+
}
|
|
1097
|
+
print("; Suppported get-info parameters:");
|
|
1098
|
+
for (const supported of GET_INFO_KEYWORDS) print(`; (get-info ${supported})`);
|
|
1099
|
+
};
|
|
1100
|
+
const printCore = () => {
|
|
1101
|
+
const check = state.check;
|
|
1102
|
+
if (check?.core === undefined)
|
|
1103
|
+
throw new SmtUnsupportedError("the unsat core of a tactic that drops dependencies");
|
|
1104
|
+
const kernel = state.kernel;
|
|
1105
|
+
if (kernel === undefined || check.context !== kernel.context) {
|
|
1106
|
+
print(`(${check.core.map(format).join(" ")})`);
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
1110
|
+
const core = new RefVector(state.manager);
|
|
1111
|
+
kernel.getUnsatCore(core);
|
|
1112
|
+
print(`(${core.items.map(format).join(" ")})`);
|
|
1113
|
+
core.reset();
|
|
1114
|
+
};
|
|
1014
1115
|
const runCommand = new Map<string, (list: SmtList) => void>([
|
|
1015
1116
|
[
|
|
1016
1117
|
"assert",
|
|
@@ -1062,7 +1163,9 @@ export const runSmtlibScript = (
|
|
|
1062
1163
|
throw new SmtParseError("at least 2 arguments expected", list.end);
|
|
1063
1164
|
const decl = state.manager.mkFuncDecl(
|
|
1064
1165
|
name.text,
|
|
1065
|
-
domain.items.map((sort) =>
|
|
1166
|
+
domain.items.map((sort) =>
|
|
1167
|
+
state.reader.parseSort(sort, "expecting sort list starting with '('"),
|
|
1168
|
+
),
|
|
1066
1169
|
SORT_BOOL,
|
|
1067
1170
|
);
|
|
1068
1171
|
state.reader.insertFunc(decl, list.end);
|
|
@@ -1080,7 +1183,7 @@ export const runSmtlibScript = (
|
|
|
1080
1183
|
list.end,
|
|
1081
1184
|
);
|
|
1082
1185
|
const manager = state.manager;
|
|
1083
|
-
const range = state.reader.parseSort(sort);
|
|
1186
|
+
const range = state.reader.parseSort(sort, "invalid command argument, sort expected");
|
|
1084
1187
|
const decl = manager.mkFuncDecl(name.text, [], range);
|
|
1085
1188
|
state.reader.insertFunc(decl, list.end);
|
|
1086
1189
|
getDatalog().registerVariable(manager.mkApp(decl, [], range));
|
|
@@ -1094,7 +1197,7 @@ export const runSmtlibScript = (
|
|
|
1094
1197
|
const name = list.items[2];
|
|
1095
1198
|
getDatalog().addRule(
|
|
1096
1199
|
state.reader.parseFormula(rule, rule),
|
|
1097
|
-
isSymbol(name) ? name.text :
|
|
1200
|
+
isSymbol(name) ? name.text : undefined,
|
|
1098
1201
|
);
|
|
1099
1202
|
},
|
|
1100
1203
|
],
|
|
@@ -1146,6 +1249,7 @@ export const runSmtlibScript = (
|
|
|
1146
1249
|
state.manager.limit.push(settings.rlimit);
|
|
1147
1250
|
try {
|
|
1148
1251
|
const checked = checkSatUsing(tactic, goal);
|
|
1252
|
+
const reasonUnknown = checked.reasonUnknown ?? getCancelMessage(deadline);
|
|
1149
1253
|
setCheck(checked.status, {
|
|
1150
1254
|
isFromTactic: true,
|
|
1151
1255
|
model: checked.model,
|
|
@@ -1153,14 +1257,13 @@ export const runSmtlibScript = (
|
|
|
1153
1257
|
builder.isTrackingDependencies || !hasNames()
|
|
1154
1258
|
? getDependencyValues(checked.core)
|
|
1155
1259
|
: undefined,
|
|
1156
|
-
reasonUnknown
|
|
1260
|
+
reasonUnknown,
|
|
1157
1261
|
});
|
|
1158
|
-
print(
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
print(`(error "tactic failed: ${message}")`);
|
|
1262
|
+
print(
|
|
1263
|
+
checked.isConversionCanceled
|
|
1264
|
+
? `(error "tactic failed: ${reasonUnknown}")`
|
|
1265
|
+
: getVerdict(checked.status),
|
|
1266
|
+
);
|
|
1164
1267
|
} finally {
|
|
1165
1268
|
state.manager.limit.pop();
|
|
1166
1269
|
}
|
|
@@ -1286,11 +1389,21 @@ export const runSmtlibScript = (
|
|
|
1286
1389
|
assertions: state.assertions.length,
|
|
1287
1390
|
objectives: state.objectives.length,
|
|
1288
1391
|
softTrail: state.softTrail.length,
|
|
1392
|
+
rlimit: settings.rlimit,
|
|
1289
1393
|
});
|
|
1290
1394
|
state.reader.push();
|
|
1291
1395
|
state.isIncremental = true;
|
|
1292
|
-
state.
|
|
1293
|
-
|
|
1396
|
+
const limit = state.manager.limit;
|
|
1397
|
+
limit.push(settings.rlimit);
|
|
1398
|
+
try {
|
|
1399
|
+
state.kernel?.push();
|
|
1400
|
+
useSatSolver((solver) => solver.push());
|
|
1401
|
+
} catch (error) {
|
|
1402
|
+
if (!(error instanceof SmtCanceledError)) throw error;
|
|
1403
|
+
throw new SmtParseError(limit.getCancelMessage(), list.end);
|
|
1404
|
+
} finally {
|
|
1405
|
+
limit.pop();
|
|
1406
|
+
}
|
|
1294
1407
|
}
|
|
1295
1408
|
if (list.items[2] !== undefined)
|
|
1296
1409
|
throw new SmtParseError("invalid push command, ')' expected", list.items[2]);
|
|
@@ -1314,6 +1427,7 @@ export const runSmtlibScript = (
|
|
|
1314
1427
|
useSatSolver((solver) => solver.pop(count));
|
|
1315
1428
|
state.reader.pop(count);
|
|
1316
1429
|
restoreAssertions(scope.assertions);
|
|
1430
|
+
settings.rlimit = scope.rlimit;
|
|
1317
1431
|
resetOptimizer();
|
|
1318
1432
|
releaseObjectives(scope.objectives, scope.softTrail);
|
|
1319
1433
|
state.scopes.length -= count;
|
|
@@ -1339,7 +1453,12 @@ export const runSmtlibScript = (
|
|
|
1339
1453
|
restoreAssertions(0);
|
|
1340
1454
|
resetOptimizer();
|
|
1341
1455
|
releaseObjectives(0, 0);
|
|
1342
|
-
state.scopes = state.scopes.map(() => ({
|
|
1456
|
+
state.scopes = state.scopes.map((scope) => ({
|
|
1457
|
+
...scope,
|
|
1458
|
+
assertions: 0,
|
|
1459
|
+
objectives: 0,
|
|
1460
|
+
softTrail: 0,
|
|
1461
|
+
}));
|
|
1343
1462
|
if (state.isProofsEnabled !== undefined) resetKernel();
|
|
1344
1463
|
state.isIncremental = state.scopes.length > 0;
|
|
1345
1464
|
state.hasChecked = false;
|
|
@@ -1422,6 +1541,7 @@ export const runSmtlibScript = (
|
|
|
1422
1541
|
if (isPrintingDependencies && !builder.isTrackingDependencies && hasNames())
|
|
1423
1542
|
throw new SmtUnsupportedError("the dependencies of a tactic that drops dependencies");
|
|
1424
1543
|
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
1544
|
+
state.manager.limit.push(settings.rlimit);
|
|
1425
1545
|
const goals = (() => {
|
|
1426
1546
|
try {
|
|
1427
1547
|
return applyTactic(tactic, input);
|
|
@@ -1429,6 +1549,8 @@ export const runSmtlibScript = (
|
|
|
1429
1549
|
if (!(error instanceof SmtTacticError)) throw error;
|
|
1430
1550
|
print(`(error "tactic failed: ${error.message}")`);
|
|
1431
1551
|
return undefined;
|
|
1552
|
+
} finally {
|
|
1553
|
+
state.manager.limit.pop();
|
|
1432
1554
|
}
|
|
1433
1555
|
})();
|
|
1434
1556
|
// apply_tactic_cmd releases the result goals and then the input goal.
|
|
@@ -1545,21 +1667,23 @@ export const runSmtlibScript = (
|
|
|
1545
1667
|
"unsat core construction is not enabled, use command (set-option :produce-unsat-cores true)",
|
|
1546
1668
|
list.end,
|
|
1547
1669
|
);
|
|
1548
|
-
|
|
1549
|
-
if (check === undefined || check.status !== L_FALSE)
|
|
1670
|
+
if (state.check?.status !== L_FALSE)
|
|
1550
1671
|
throw new SmtParseError("unsat core is not available", list.end);
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1672
|
+
printCore();
|
|
1673
|
+
},
|
|
1674
|
+
],
|
|
1675
|
+
[
|
|
1676
|
+
"get-unsat-assumptions",
|
|
1677
|
+
(list) => {
|
|
1678
|
+
checkArgumentCount(list, 0);
|
|
1679
|
+
if (!settings.isProducingUnsatAssumptions)
|
|
1680
|
+
throw new SmtParseError(
|
|
1681
|
+
"unsat assumptions construction is not enabled, use command (set-option :produce-unsat-assumptions true)",
|
|
1682
|
+
list.end,
|
|
1683
|
+
);
|
|
1684
|
+
if (state.check?.status !== L_FALSE)
|
|
1685
|
+
throw new SmtParseError("unsat assumptions is not available", list.end);
|
|
1686
|
+
printCore();
|
|
1563
1687
|
},
|
|
1564
1688
|
],
|
|
1565
1689
|
[
|
|
@@ -1578,8 +1702,9 @@ export const runSmtlibScript = (
|
|
|
1578
1702
|
const evaluator = new ModelEvaluator(manager, model);
|
|
1579
1703
|
const value = evaluator.rewrite(term);
|
|
1580
1704
|
display(value);
|
|
1581
|
-
|
|
1705
|
+
// eval_cmd frees its model_evaluator before the value, and the parser frees the term last.
|
|
1582
1706
|
evaluator.release();
|
|
1707
|
+
manager.decRef(value);
|
|
1583
1708
|
manager.decRef(term);
|
|
1584
1709
|
},
|
|
1585
1710
|
],
|
|
@@ -1708,7 +1833,13 @@ export const runSmtlibScript = (
|
|
|
1708
1833
|
"dbg-some-value",
|
|
1709
1834
|
(list) => {
|
|
1710
1835
|
display(
|
|
1711
|
-
getManagerSomeValue(
|
|
1836
|
+
getManagerSomeValue(
|
|
1837
|
+
state.manager,
|
|
1838
|
+
state.reader.parseSort(
|
|
1839
|
+
list.items[1] ?? list.end,
|
|
1840
|
+
"invalid command argument, sort expected",
|
|
1841
|
+
),
|
|
1842
|
+
),
|
|
1712
1843
|
);
|
|
1713
1844
|
},
|
|
1714
1845
|
],
|
|
@@ -1759,8 +1890,19 @@ export const runSmtlibScript = (
|
|
|
1759
1890
|
const optionName = `:${getParameterName(keyword)}`;
|
|
1760
1891
|
const value = list.items[2];
|
|
1761
1892
|
const isTrue = isSymbol(value, "true");
|
|
1893
|
+
if (
|
|
1894
|
+
(keyword === ":produce-proofs" ||
|
|
1895
|
+
keyword === ":produce-unsat-cores" ||
|
|
1896
|
+
keyword === ":produce-unsat-assumptions") &&
|
|
1897
|
+
state.assertions.length > 0
|
|
1898
|
+
)
|
|
1899
|
+
throw new SmtParseError(
|
|
1900
|
+
`error setting '${keyword}', option value cannot be modified after assertions have been added`,
|
|
1901
|
+
value ?? list.end,
|
|
1902
|
+
);
|
|
1762
1903
|
if (keyword === ":produce-models") settings.isProducingModels = isTrue;
|
|
1763
1904
|
if (keyword === ":produce-unsat-cores") settings.isProducingUnsatCores = isTrue;
|
|
1905
|
+
if (keyword === ":produce-unsat-assumptions") settings.isProducingUnsatAssumptions = isTrue;
|
|
1764
1906
|
if (keyword === ":produce-proofs") settings.isProducingProofs = isTrue;
|
|
1765
1907
|
if (keyword === ":interactive-mode" || keyword === ":produce-assertions") {
|
|
1766
1908
|
if (state.isProofsEnabled !== undefined)
|
|
@@ -1837,6 +1979,7 @@ export const runSmtlibScript = (
|
|
|
1837
1979
|
[":print-success", settings.isPrintingSuccess],
|
|
1838
1980
|
[":produce-models", settings.isProducingModels],
|
|
1839
1981
|
[":produce-unsat-cores", settings.isProducingUnsatCores],
|
|
1982
|
+
[":produce-unsat-assumptions", settings.isProducingUnsatAssumptions],
|
|
1840
1983
|
[":interactive-mode", settings.isInteractive],
|
|
1841
1984
|
[":produce-assertions", settings.isInteractive],
|
|
1842
1985
|
[":int-real-coercions", true],
|
|
@@ -1856,26 +1999,12 @@ export const runSmtlibScript = (
|
|
|
1856
1999
|
"get-info",
|
|
1857
2000
|
(list) => {
|
|
1858
2001
|
const info = list.items[1];
|
|
1859
|
-
if (info
|
|
1860
|
-
throw new SmtParseError("invalid command argument
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
: check.reasonUnknown;
|
|
1866
|
-
if (info.text === ":reason-unknown" && reasonUnknown !== undefined) {
|
|
1867
|
-
print(`(:reason-unknown "${reasonUnknown.replaceAll('"', '\\"')}")`);
|
|
1868
|
-
return;
|
|
1869
|
-
}
|
|
1870
|
-
if (info.text === ":rlimit") {
|
|
1871
|
-
print(`(:rlimit ${state.manager.limit.count})`);
|
|
1872
|
-
return;
|
|
1873
|
-
}
|
|
1874
|
-
if (info.text !== ":error-behavior")
|
|
1875
|
-
throw new SmtUnsupportedError(`the information ${info.text}`);
|
|
1876
|
-
print(
|
|
1877
|
-
`(:error-behavior ${settings.isExitingOnError ? "immediate-exit" : "continued-execution"})`,
|
|
1878
|
-
);
|
|
2002
|
+
if (info === undefined)
|
|
2003
|
+
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
2004
|
+
if (info.kind !== "keyword")
|
|
2005
|
+
throw new SmtParseError("invalid command argument, keyword expected", info);
|
|
2006
|
+
printInfo(list, info.text);
|
|
2007
|
+
checkArgumentCount(list, 1);
|
|
1879
2008
|
},
|
|
1880
2009
|
],
|
|
1881
2010
|
[
|
|
@@ -1950,12 +2079,7 @@ export const runSmtlibScript = (
|
|
|
1950
2079
|
}
|
|
1951
2080
|
// Z3's scoped_timer ends with the command that set it, so a command starts without one.
|
|
1952
2081
|
state.manager.limit.restart(Infinity);
|
|
1953
|
-
if (!MANAGERLESS_COMMANDS.has(head.text)
|
|
1954
|
-
state.isProofsEnabled = settings.parameters.get("proof") === "true";
|
|
1955
|
-
if (state.logic === undefined || logicHasSeq(state.logic)) state.manager.initSeqPlugin();
|
|
1956
|
-
if (state.logic === undefined) state.reader.registerList();
|
|
1957
|
-
resetKernel();
|
|
1958
|
-
}
|
|
2082
|
+
if (!MANAGERLESS_COMMANDS.has(head.text)) initManager();
|
|
1959
2083
|
try {
|
|
1960
2084
|
command(list);
|
|
1961
2085
|
} catch (error) {
|
|
@@ -1984,13 +1984,14 @@ interface TacticCheck {
|
|
|
1984
1984
|
model: ProtoModel | undefined;
|
|
1985
1985
|
core: Dependency | undefined;
|
|
1986
1986
|
reasonUnknown: string | undefined;
|
|
1987
|
+
isConversionCanceled: boolean;
|
|
1987
1988
|
}
|
|
1988
1989
|
|
|
1989
1990
|
// The port's declarations of division by zero leave out their domain; Z3's have two arguments.
|
|
1990
1991
|
const DIVISION_BY_ZERO_DECLS = new Set([OP_DIV0, OP_IDIV0, OP_MOD0, OP_POWER0]);
|
|
1991
1992
|
|
|
1992
1993
|
// A constant of an uninterpreted sort the model lacks puts its value in that sort's universe.
|
|
1993
|
-
const applyDefinitions = (definitions: Definition[], model: ProtoModel) => {
|
|
1994
|
+
export const applyDefinitions = (definitions: readonly Definition[], model: ProtoModel) => {
|
|
1994
1995
|
const manager = model.manager;
|
|
1995
1996
|
const universe: number[] = [];
|
|
1996
1997
|
let evaluator = new ModelEvaluator(manager, model);
|
|
@@ -2042,61 +2043,87 @@ const applyDefinitions = (definitions: Definition[], model: ProtoModel) => {
|
|
|
2042
2043
|
return model;
|
|
2043
2044
|
};
|
|
2044
2045
|
|
|
2046
|
+
const applyConverter = (entry: Goal["converters"][number], model: ProtoModel) => {
|
|
2047
|
+
if ("convert" in entry) return entry.convert(model);
|
|
2048
|
+
if ("definitions" in entry) return applyDefinitions(entry.definitions, model);
|
|
2049
|
+
model.unregisterDecl(entry.decl);
|
|
2050
|
+
return model;
|
|
2051
|
+
};
|
|
2052
|
+
|
|
2045
2053
|
export const convertModel = (goal: Goal, model: ProtoModel) =>
|
|
2046
|
-
goal.converters.reduceRight((converted, entry) =>
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
}, model);
|
|
2052
|
-
|
|
2053
|
-
const getConvertedModel = (goal: Goal) =>
|
|
2054
|
-
convertModel(goal, goal.model?.copy() ?? new ProtoModel(goal.manager).mkModel());
|
|
2055
|
-
|
|
2056
|
-
export const checkSatUsing = (tactic: Tactic, goal: Goal): TacticCheck => {
|
|
2057
|
-
const undecided = { status: L_UNDEF, model: undefined, core: undefined };
|
|
2058
|
-
const goals = (() => {
|
|
2054
|
+
goal.converters.reduceRight((converted, entry) => applyConverter(entry, converted), model);
|
|
2055
|
+
|
|
2056
|
+
const getConvertedModel = (goal: Goal) => {
|
|
2057
|
+
let model = goal.model?.copy() ?? new ProtoModel(goal.manager).mkModel();
|
|
2058
|
+
for (let index = goal.converters.length - 1; index >= 0; index--) {
|
|
2059
2059
|
try {
|
|
2060
|
-
|
|
2060
|
+
model = applyConverter(goal.converters[index], model);
|
|
2061
2061
|
} catch (error) {
|
|
2062
|
-
if (error instanceof
|
|
2063
|
-
|
|
2064
|
-
throw error;
|
|
2062
|
+
if (!(error instanceof SmtCanceledError)) throw error;
|
|
2063
|
+
return { model, isCanceled: true };
|
|
2065
2064
|
}
|
|
2066
|
-
}
|
|
2065
|
+
}
|
|
2066
|
+
return { model, isCanceled: false };
|
|
2067
|
+
};
|
|
2068
|
+
|
|
2069
|
+
const getTacticCheck = (goal: Goal, goals: Goal[] | string | undefined): TacticCheck => {
|
|
2070
|
+
const undecided = {
|
|
2071
|
+
status: L_UNDEF,
|
|
2072
|
+
model: undefined,
|
|
2073
|
+
core: undefined,
|
|
2074
|
+
isConversionCanceled: false,
|
|
2075
|
+
};
|
|
2067
2076
|
if (goals === undefined) return { ...undecided, reasonUnknown: undefined };
|
|
2068
2077
|
if (typeof goals === "string") return { ...undecided, reasonUnknown: goals };
|
|
2069
|
-
if (
|
|
2070
|
-
|
|
2078
|
+
if (isDecidedUnsat(goals))
|
|
2079
|
+
return { ...undecided, status: L_FALSE, core: goals[0].getDependency(0), reasonUnknown: "" };
|
|
2080
|
+
const isSat = isDecidedSat(goals);
|
|
2081
|
+
const converted =
|
|
2082
|
+
isSat ||
|
|
2083
|
+
(goal.isModelsEnabled &&
|
|
2084
|
+
goals.length > 0 &&
|
|
2085
|
+
(goals[0].model !== undefined || goals[0].converters.length > 0))
|
|
2086
|
+
? getConvertedModel(goals[0])
|
|
2087
|
+
: undefined;
|
|
2088
|
+
const model = converted?.model;
|
|
2089
|
+
if (converted?.isCanceled === true)
|
|
2090
|
+
return { ...undecided, model, reasonUnknown: undefined, isConversionCanceled: true };
|
|
2091
|
+
if (isSat)
|
|
2071
2092
|
return goal.manager.limit.inc()
|
|
2072
|
-
? { status: L_TRUE, model,
|
|
2093
|
+
? { ...undecided, status: L_TRUE, model, reasonUnknown: "" }
|
|
2073
2094
|
: { ...undecided, model, reasonUnknown: "canceled" };
|
|
2074
|
-
}
|
|
2075
|
-
if (isDecidedUnsat(goals))
|
|
2076
|
-
return {
|
|
2077
|
-
status: L_FALSE,
|
|
2078
|
-
model: undefined,
|
|
2079
|
-
core: goals[0].getDependency(0),
|
|
2080
|
-
reasonUnknown: "",
|
|
2081
|
-
};
|
|
2082
2095
|
return {
|
|
2083
2096
|
...undecided,
|
|
2084
|
-
model
|
|
2085
|
-
goal.isModelsEnabled &&
|
|
2086
|
-
goals.length > 0 &&
|
|
2087
|
-
(goals[0].model !== undefined || goals[0].converters.length > 0)
|
|
2088
|
-
? getConvertedModel(goals[0])
|
|
2089
|
-
: undefined,
|
|
2097
|
+
model,
|
|
2090
2098
|
reasonUnknown:
|
|
2091
2099
|
goals.length === 1 && goals[0].reasonUnknown !== "" ? goals[0].reasonUnknown : "unknown",
|
|
2092
2100
|
};
|
|
2093
2101
|
};
|
|
2094
2102
|
|
|
2103
|
+
export const checkSatUsing = (tactic: Tactic, goal: Goal) => {
|
|
2104
|
+
const goals = (() => {
|
|
2105
|
+
try {
|
|
2106
|
+
return tactic(goal);
|
|
2107
|
+
} catch (error) {
|
|
2108
|
+
if (error instanceof SmtTacticError || error instanceof SmtDefaultError) return error.message;
|
|
2109
|
+
if (error instanceof SmtCanceledError) return undefined;
|
|
2110
|
+
throw error;
|
|
2111
|
+
}
|
|
2112
|
+
})();
|
|
2113
|
+
try {
|
|
2114
|
+
return getTacticCheck(goal, goals);
|
|
2115
|
+
} finally {
|
|
2116
|
+
goal.reset();
|
|
2117
|
+
if (Array.isArray(goals)) for (const result of goals) result.reset();
|
|
2118
|
+
}
|
|
2119
|
+
};
|
|
2120
|
+
|
|
2095
2121
|
export const applyTactic = (tactic: Tactic, goal: Goal) => {
|
|
2096
2122
|
try {
|
|
2097
2123
|
return tactic(goal);
|
|
2098
2124
|
} catch (error) {
|
|
2099
|
-
if (error instanceof SmtCanceledError)
|
|
2125
|
+
if (error instanceof SmtCanceledError)
|
|
2126
|
+
throw new SmtTacticError(goal.manager.limit.getCancelMessage());
|
|
2100
2127
|
throw error;
|
|
2101
2128
|
}
|
|
2102
2129
|
};
|