tla-ts 0.0.3-dev.bfd303f → 0.0.3-dev.c8c988d
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/index.d.cts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/run-cli.cjs +5 -3
- package/dist/run-cli.js +20 -18
- package/dist/transfer.cjs +22 -17
- package/dist/transfer.js +22 -17
- package/package.json +1 -1
- package/src/ast.ts +6 -1
- package/src/builtins.ts +9 -3
- package/src/check.ts +234 -53
- package/src/config.ts +224 -170
- package/src/environment.ts +32 -6
- package/src/errors.ts +52 -1
- package/src/evaluate.ts +131 -13
- package/src/fingerprints.ts +2 -1
- package/src/instances.ts +1 -1
- package/src/levels.ts +166 -36
- package/src/live-check.ts +3 -1
- package/src/liveness.ts +5 -1
- package/src/parser.ts +60 -17
- package/src/resolve.ts +108 -29
- package/src/run-cli.ts +56 -9
- package/src/spec-description.ts +1 -2
- package/src/standard-modules.ts +52 -38
- package/src/substitution-levels.ts +35 -11
- package/src/successors.ts +87 -17
- package/src/value-sources.ts +29 -0
- package/src/values.ts +122 -42
package/dist/index.d.cts
CHANGED
|
@@ -46,6 +46,7 @@ interface ApplyExpression {
|
|
|
46
46
|
operator: string;
|
|
47
47
|
args: Expression[];
|
|
48
48
|
argumentCounts?: number[];
|
|
49
|
+
argumentsRange?: SourceRange;
|
|
49
50
|
location: SourceLocation;
|
|
50
51
|
resolution?: LocalResolution;
|
|
51
52
|
}
|
|
@@ -175,6 +176,7 @@ interface FunctionSetExpression {
|
|
|
175
176
|
interface RecordField {
|
|
176
177
|
name: string;
|
|
177
178
|
value: Expression;
|
|
179
|
+
location: SourceLocation;
|
|
178
180
|
}
|
|
179
181
|
interface RecordExpression {
|
|
180
182
|
kind: "Record" | "RecordSet";
|
|
@@ -395,6 +397,7 @@ interface ProofStep {
|
|
|
395
397
|
token: string;
|
|
396
398
|
body: StepBody;
|
|
397
399
|
head: SourceRange;
|
|
400
|
+
statement: SourceRange;
|
|
398
401
|
proof: Proof | undefined;
|
|
399
402
|
location: SourceLocation;
|
|
400
403
|
}
|
|
@@ -589,9 +592,18 @@ interface SyntaxFailure {
|
|
|
589
592
|
column: number;
|
|
590
593
|
isEnd: boolean;
|
|
591
594
|
}
|
|
595
|
+
interface SanyError {
|
|
596
|
+
location: string;
|
|
597
|
+
message: string;
|
|
598
|
+
}
|
|
599
|
+
interface SanyReport {
|
|
600
|
+
errors: SanyError[];
|
|
601
|
+
isFatal: boolean;
|
|
602
|
+
}
|
|
592
603
|
export declare class TlaSyntaxError extends TlaError {
|
|
593
604
|
failure: SyntaxFailure | undefined;
|
|
594
|
-
|
|
605
|
+
sany: SanyReport | undefined;
|
|
606
|
+
constructor(message: string, cause?: unknown, failure?: SyntaxFailure, sany?: SanyReport);
|
|
595
607
|
}
|
|
596
608
|
export declare class TlaConfigError extends TlaError {
|
|
597
609
|
constructor(message: string, cause?: unknown);
|
|
@@ -649,6 +661,18 @@ interface EvaluationFailure {
|
|
|
649
661
|
trace: TraceStep[];
|
|
650
662
|
initialState: Record<string, Value> | undefined;
|
|
651
663
|
exitCode: number;
|
|
664
|
+
replay?: Replay;
|
|
665
|
+
isWithoutStatistics?: boolean;
|
|
666
|
+
}
|
|
667
|
+
interface Replay {
|
|
668
|
+
output: string[];
|
|
669
|
+
callStack: string[] | undefined;
|
|
670
|
+
fingerprint?: Fingerprint;
|
|
671
|
+
isBeforeError?: boolean;
|
|
672
|
+
}
|
|
673
|
+
interface Fingerprint {
|
|
674
|
+
sources: string[];
|
|
675
|
+
reason: string;
|
|
652
676
|
}
|
|
653
677
|
interface CheckResult {
|
|
654
678
|
status: CheckStatus;
|
package/dist/index.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ interface ApplyExpression {
|
|
|
46
46
|
operator: string;
|
|
47
47
|
args: Expression[];
|
|
48
48
|
argumentCounts?: number[];
|
|
49
|
+
argumentsRange?: SourceRange;
|
|
49
50
|
location: SourceLocation;
|
|
50
51
|
resolution?: LocalResolution;
|
|
51
52
|
}
|
|
@@ -175,6 +176,7 @@ interface FunctionSetExpression {
|
|
|
175
176
|
interface RecordField {
|
|
176
177
|
name: string;
|
|
177
178
|
value: Expression;
|
|
179
|
+
location: SourceLocation;
|
|
178
180
|
}
|
|
179
181
|
interface RecordExpression {
|
|
180
182
|
kind: "Record" | "RecordSet";
|
|
@@ -395,6 +397,7 @@ interface ProofStep {
|
|
|
395
397
|
token: string;
|
|
396
398
|
body: StepBody;
|
|
397
399
|
head: SourceRange;
|
|
400
|
+
statement: SourceRange;
|
|
398
401
|
proof: Proof | undefined;
|
|
399
402
|
location: SourceLocation;
|
|
400
403
|
}
|
|
@@ -589,9 +592,18 @@ interface SyntaxFailure {
|
|
|
589
592
|
column: number;
|
|
590
593
|
isEnd: boolean;
|
|
591
594
|
}
|
|
595
|
+
interface SanyError {
|
|
596
|
+
location: string;
|
|
597
|
+
message: string;
|
|
598
|
+
}
|
|
599
|
+
interface SanyReport {
|
|
600
|
+
errors: SanyError[];
|
|
601
|
+
isFatal: boolean;
|
|
602
|
+
}
|
|
592
603
|
export declare class TlaSyntaxError extends TlaError {
|
|
593
604
|
failure: SyntaxFailure | undefined;
|
|
594
|
-
|
|
605
|
+
sany: SanyReport | undefined;
|
|
606
|
+
constructor(message: string, cause?: unknown, failure?: SyntaxFailure, sany?: SanyReport);
|
|
595
607
|
}
|
|
596
608
|
export declare class TlaConfigError extends TlaError {
|
|
597
609
|
constructor(message: string, cause?: unknown);
|
|
@@ -649,6 +661,18 @@ interface EvaluationFailure {
|
|
|
649
661
|
trace: TraceStep[];
|
|
650
662
|
initialState: Record<string, Value> | undefined;
|
|
651
663
|
exitCode: number;
|
|
664
|
+
replay?: Replay;
|
|
665
|
+
isWithoutStatistics?: boolean;
|
|
666
|
+
}
|
|
667
|
+
interface Replay {
|
|
668
|
+
output: string[];
|
|
669
|
+
callStack: string[] | undefined;
|
|
670
|
+
fingerprint?: Fingerprint;
|
|
671
|
+
isBeforeError?: boolean;
|
|
672
|
+
}
|
|
673
|
+
interface Fingerprint {
|
|
674
|
+
sources: string[];
|
|
675
|
+
reason: string;
|
|
652
676
|
}
|
|
653
677
|
interface CheckResult {
|
|
654
678
|
status: CheckStatus;
|
package/dist/run-cli.cjs
CHANGED
|
@@ -23,7 +23,9 @@ PROVE %a@]`,i)]};return{printSequent:p,printExpr:r}},Nt=(e,t)=>Mt(e).printExpr(
|
|
|
23
23
|
`).length,c=o-t.lastIndexOf(`
|
|
24
24
|
`,o-1),l=n.findLast(e=>e.kind!==`End`&&(e.line<s||e.line===s&&e.column<c));return{offset:o,line:s,column:c,end:{reason:Lr,line:l?.line??s,column:l?l.endColumn+1:c,isEnd:!0}}},Br=t=>{try{return t()}catch(t){if(!(t instanceof e.I)||!t.failure)throw t;return t.failure}},Vr=e=>typeof e==`object`&&!!e&&`reason`in e,Hr=t=>{let n=Br(()=>zr(t));if(Vr(n))return[n];let r=Br(()=>e.x(n?t.slice(0,n.offset):t));return n&&(!Vr(r)||r.isEnd)?[{reason:`Unexpected TAB character. TLAPS does not handle TAB characters in source files.`,line:n.line,column:n.column,isEnd:!1},Vr(r)&&r.reason===Lr?r:n.end]:Vr(r)?[r]:r},Ur=(t,n,r,i,a)=>{if(!Ir.test(t.source))throw new e.F(`No tokens in file`);let o=Hr(t.source);if(Array.isArray(o)){o.forEach(e=>{let n=`File ${JSON.stringify(t.file)}, line ${e.line}, character ${e.column}\n${e.reason}`;i({text:n,channel:`stderr`}),i({text:`${n}\n`,channel:`toolboxOnly`})});let n=`Could not parse ${JSON.stringify(t.file)} successfully.`;throw i({text:`${a}Error: ${n}`,channel:`stderr`}),new e.F(n,{failure:`Module.Parser.parse_file`})}let s=Pr(t.file,t.source,n,r).convertModule(o),c=t.file.slice(t.file.lastIndexOf(`/`)+1),l=c.replace(/\.tla$/,``);return s.name===l?s:(i({text:`${f(s.location)}Warning: module name ${JSON.stringify(s.name)} does not match file name ${JSON.stringify(c)}.`,channel:`toolbox`}),{...s,name:l})},Wr=t=>{let n=new Map([...t].map(([e,t])=>[e,Un(t).dependencies])),r=/* @__PURE__ */ new Set,i=[],a=o=>{if(r.has(o))return;r.add(o);let s=t.get(o);if(!s)throw new e.F(`Module "${o}" not found`);(n.get(o)??[]).forEach(a),i.push(s)};return[...t.keys()].sort(Gn).forEach(a),i},Gr=(e,t,n)=>t.length===0?[]:[` ${e}_proofs_count = ${t.length}`,...t.map((t,r)=>` ${e}_proof_${n+r+1} at ${c(t)}`)],Kr=(e,t,n)=>{let r=e.location;return[` ---- incomplete proof of theorem at ${r?c({...r,endLine:r.startLine,endColumn:r.startColumn}):`<unknown location>`} ----`,...Gr(`missing`,e.absent,t),...Gr(`omitted`,e.omitted,n),` ====`]},qr=e=>{let t=e.summary,n=t.theorems.reduce((e,t)=>t.absent.length+t.omitted.length===0?e:{lines:[...e.lines,...Kr(t,e.missing,e.omitted)],missing:e.missing+t.absent.length,omitted:e.omitted+t.omitted.length},{lines:[],missing:0,omitted:0});return[`---- summary of module ${JSON.stringify(e.name)} ----`,` obligations_count = ${t.total}`,...t.absent.length>0?[` missing_proofs_count = ${t.absent.length}`]:[],...t.omitted.length>0?[` omitted_proofs_count = ${t.omitted.length}`]:[],...n.lines,`====`].join(`
|
|
25
25
|
`)},Jr=(t,n,r={})=>{let i=r.lines??Fr,a=r.onWarning??(()=>{}),o={value:0},s=new Map(Ln);t.forEach(e=>{let t={...Ur(e,o,!0,a,`File "<unknown>":
|
|
26
|
-
`),isImportant:!0};s.set(t.name,t)});let c=[...s.values()].sort((e,t)=>Gn(e.name,t.name)),l=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Set;for(let e=0;e<c.length;e++){let t=Un(c[e]);t.submodules.forEach((e,t)=>{f.add(t),s.has(t)||s.set(t,e)});for(let e of t.dependencies){if(s.has(e)&&!Ln.has(e))continue;let r=n(e);if(!r){!s.has(e)&&!l.has(e)&&l.set(e,t.locations.get(e));continue}let i=Ur(r,o,!1,a,u(t.locations.get(e)));s.set(e,i),c.push(i)}}let p=[...l.keys()].filter(e=>!f.has(e)).sort(Gn);if(p.forEach(e=>a(d(l.get(e),`Unknown module ${JSON.stringify(e)}`))),p.length>0)throw new e.F(`Unknown module ${JSON.stringify(p[0])}`,{failure:`Module.Parser.load_module`});let m={anonymizer:Be(o,(e,t)=>ar(m,e,t),a),generator:an(o,new Set(t.map(e=>e.file)),i,a),salts:{value:0},latestModules:/* @__PURE__ */ new Map,onWarning:a},h=Wr(s).map(e=>e.isStandard?e:Hn(s,e,/* @__PURE__ */ new Set)),g=new Map(h.map(e=>[e.name,e]));return h.flatMap(e=>{if(e.isStandard)return[];let t=or(m,g,void 0,e);if(!e.isImportant)return[];let n=sr(m,[],t),r=n.obligations.flatMap((e,t)=>{let n=e.location;if(e.kind.kind===`Omitted`||n&&(n.startLine<i.start||n.endLine>i.end))return[];let r=e.kind.kind===`Error`?e.kind.message:`${Pt(e.sequent)}\n`;return[{id:t+1,location:Rr(n),text:r}]});return[{name:e.name,location:e.location,obligations:r,summary:n.summary}]})},Yr={success:e.
|
|
27
|
-
`),$r=/[*?[{]/,ei=e=>e.flatMap(e=>$r.test(e)?(0,n.globSync)(e).sort().map(e=>({path:e,isGlobbed:!0})):[{path:e,isGlobbed:!1}]),ti=e=>/^[+-]?\d+$/.test(e)&&BigInt.asIntN(64,BigInt(e))===BigInt(e),ni=e=>e?e[0]===`auto`?(0,a.availableParallelism)():Math.max(1,Number.parseInt(e[0],10)||1):1,ri=t=>console.log(e.E(t)),ii=[`constrained`,`stuttering`,`strict`],ai=(e,t)=>e.endsWith(t)?e:`${e}${t}`,oi=e=>{if(e.length===1)return{path:ai(e[0],`.dump`)};let t=e[0].toLowerCase();return{path:ai(e[1],`.dot`),dot:!0,colorize:t.includes(`colorize`),actionLabels:t.includes(`actionlabels`),snapshot:t.includes(`snapshot`)}},si=(e,t=`Error: The behavior up to this point is:`)=>{e.length>0&&console.log(t),e.forEach((e,t)=>{console.log(`State ${t+1}: <${e.label??e.action??`Initial predicate`}>`),ri(e.state)})},ci=e=>e.length===1?`Error: Temporal property ${e[0]} was violated.\n`:`Error: Temporal properties ${e.slice(0,-1).join(`, `)}${e.length>2?`,`:``} and ${e[e.length-1]} were violated.\n`,li=
|
|
26
|
+
`),isImportant:!0};s.set(t.name,t)});let c=[...s.values()].sort((e,t)=>Gn(e.name,t.name)),l=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Set;for(let e=0;e<c.length;e++){let t=Un(c[e]);t.submodules.forEach((e,t)=>{f.add(t),s.has(t)||s.set(t,e)});for(let e of t.dependencies){if(s.has(e)&&!Ln.has(e))continue;let r=n(e);if(!r){!s.has(e)&&!l.has(e)&&l.set(e,t.locations.get(e));continue}let i=Ur(r,o,!1,a,u(t.locations.get(e)));s.set(e,i),c.push(i)}}let p=[...l.keys()].filter(e=>!f.has(e)).sort(Gn);if(p.forEach(e=>a(d(l.get(e),`Unknown module ${JSON.stringify(e)}`))),p.length>0)throw new e.F(`Unknown module ${JSON.stringify(p[0])}`,{failure:`Module.Parser.load_module`});let m={anonymizer:Be(o,(e,t)=>ar(m,e,t),a),generator:an(o,new Set(t.map(e=>e.file)),i,a),salts:{value:0},latestModules:/* @__PURE__ */ new Map,onWarning:a},h=Wr(s).map(e=>e.isStandard?e:Hn(s,e,/* @__PURE__ */ new Set)),g=new Map(h.map(e=>[e.name,e]));return h.flatMap(e=>{if(e.isStandard)return[];let t=or(m,g,void 0,e);if(!e.isImportant)return[];let n=sr(m,[],t),r=n.obligations.flatMap((e,t)=>{let n=e.location;if(e.kind.kind===`Omitted`||n&&(n.startLine<i.start||n.endLine>i.end))return[];let r=e.kind.kind===`Error`?e.kind.message:`${Pt(e.sequent)}\n`;return[{id:t+1,location:Rr(n),text:r}]});return[{name:e.name,location:e.location,obligations:r,summary:n.summary}]})},Yr={success:e.V.success,"assumption-violation":e.V.assumptionViolation,deadlock:e.V.deadlock,"invariant-violation":e.V.safetyViolation,"property-violation":e.V.safetyViolation,"liveness-violation":e.V.livenessViolation,"postcondition-violation":e.V.assumptionViolation,error:e.V.error},Xr=s(`tla-ts <Spec.tla|Spec.cfg|glob>... {options}`,[{flag:`-config <Spec.cfg>`},{flag:`-deadlock`},{flag:`-dump [<format>] <file>`,getArity:e=>e.length>1&&e[0].startsWith(`dot`)?2:1},{flag:`-lncheck <final|default>`},{flag:`-seed <num>`},{flag:`-workers <count|auto>`}]),Zr=s(`tla-ts prove {options} <Module.tla|glob>...`,[{flag:`-N`,isRequired:!0},{flag:`--toolbox <start> <end>`},{flag:`--line <num>`},{flag:`--printallobs`},{flag:`--summary`},{flag:`--strict`},{flag:`-I <directory>`,isRepeatable:!0}]),Qr=[`Usage: ${Xr.usage}`,` ${Zr.usage}`,` tla-ts prove [<tlapm option>]... <Module.tla|glob>...`].join(`
|
|
27
|
+
`),$r=/[*?[{]/,ei=e=>e.flatMap(e=>$r.test(e)?(0,n.globSync)(e).sort().map(e=>({path:e,isGlobbed:!0})):[{path:e,isGlobbed:!1}]),ti=e=>/^[+-]?\d+$/.test(e)&&BigInt.asIntN(64,BigInt(e))===BigInt(e),ni=e=>e?e[0]===`auto`?(0,a.availableParallelism)():Math.max(1,Number.parseInt(e[0],10)||1):1,ri=t=>console.log(e.E(t)),ii=[`constrained`,`stuttering`,`strict`],ai=(e,t)=>e.endsWith(t)?e:`${e}${t}`,oi=e=>{if(e.length===1)return{path:ai(e[0],`.dump`)};let t=e[0].toLowerCase();return{path:ai(e[1],`.dot`),dot:!0,colorize:t.includes(`colorize`),actionLabels:t.includes(`actionlabels`),snapshot:t.includes(`snapshot`)}},si=(e,t=`Error: The behavior up to this point is:`)=>{e.length>0&&console.log(t),e.forEach((e,t)=>{console.log(`State ${t+1}: <${e.label??e.action??`Initial predicate`}>`),ri(e.state)})},ci=e=>e.length===1?`Error: Temporal property ${e[0]} was violated.\n`:`Error: Temporal properties ${e.slice(0,-1).join(`, `)}${e.length>2?`,`:``} and ${e[e.length-1]} were violated.\n`,li=e=>e.map((e,t)=>`${t}. ${e}\n`).join(``),ui=e=>console.log(`Error: The error occurred when TLC was evaluating the nested\nexpressions at the following positions:\n${e?`${e}\n`:` The error call stack is empty.
|
|
28
|
+
`}`),di=e=>{e.output.forEach(e=>console.log(e));let t=li(e.callStack??[]),n=e.fingerprint;if(e.isBeforeError)t&&ui(t);else if(e.callStack&&n){let e=n.sources.map(e=>`${e}\n`).join(``);console.log(`Error: TLC was unable to fingerprint.\n\nFingerprint Stack Trace:\n${t?`${t}\n`:e}\nReason:\n${n.reason}`)}else e.callStack&&ui(t)},fi=t=>{if(t.failure){let e=t.failure.replay;if(e?.isBeforeError&&di(e),console.log(`Error: ${t.failure.message}`),t.failure.initialState&&(console.log(`While working on the initial state:`),ri(t.failure.initialState)),si(t.failure.trace),e&&!e.isBeforeError&&di(e),t.failure.isWithoutStatistics)return}else if(t.violation){let e=t.violation,n=e.name,r=e.loopStart,i=r===void 0&&e.trace.length===1&&(t.status===`invariant-violation`||t.status===`liveness-violation`),a={success:``,error:``,"assumption-violation":e.message?`Error: Evaluating assumption ${n} failed.\n${e.message}`:`Error: Assumption ${n} is false.`,deadlock:`Error: Deadlock reached.`,"invariant-violation":i?`Error: Invariant ${n} is violated by the initial state:`:`Error: Invariant ${n} is violated.`,"property-violation":ci(e.properties??[n]),"liveness-violation":r===void 0?i?`Error: Property ${n} is violated by the initial state:`:`Error: Action property ${n} is violated.`:ci(e.properties??[n]),"postcondition-violation":`Error: ${e.message??`Postcondition ${n} is false.`}`}[t.status];if(e.counts&&console.log(e.counts),console.log(a),i)ri(e.trace[0].state);else if(t.status===`property-violation`)si(e.trace,`Error: The following behavior constitutes a counter-example:
|
|
28
29
|
`);else if(r===void 0)si(e.trace);else{si(e.trace,`Error: The following behavior constitutes a counter-example:
|
|
29
|
-
`);let t=r===e.trace.length-1;console.log(t?`State ${r+2}: Stuttering`:`Back to state ${r+1}${e.loopLabel?`: <${e.loopLabel}>\n`:``}`)}let o=e.unwitnessed;if(o?.counts&&console.log(o.counts),o&&console.log(`Error: ${o.message}`),i||t.status===`assumption-violation`)return}else{let n=e.h(t.distinctStates,t.generatedStates);if(console.log(`Model checking completed. No error has been found.`),console.log(` Estimates of the probability that TLC did not check all reachable states`),console.log(` because two distinct states had the same fingerprint:`),console.log(` calculated (optimistic): val = ${e.f(n)}`),t.fingerprintDistance!==void 0){let n=e.p(t.fingerprintDistance);console.log(` based on the actual fingerprints: val = ${e.f(n)}`)}}console.log(`${t.generatedStates} states generated, ${t.distinctStates} distinct states found, ${t.queuedStates} states left on queue.`),console.log(`The depth of the complete state graph search is ${t.depth}.`);let n=t.outDegrees&&e.g(t.outDegrees);n&&console.log(n)},
|
|
30
|
+
`);let t=r===e.trace.length-1;console.log(t?`State ${r+2}: Stuttering`:`Back to state ${r+1}${e.loopLabel?`: <${e.loopLabel}>\n`:``}`)}let o=e.unwitnessed;if(o?.counts&&console.log(o.counts),o&&console.log(`Error: ${o.message}`),i||t.status===`assumption-violation`)return}else{let n=e.h(t.distinctStates,t.generatedStates);if(console.log(`Model checking completed. No error has been found.`),console.log(` Estimates of the probability that TLC did not check all reachable states`),console.log(` because two distinct states had the same fingerprint:`),console.log(` calculated (optimistic): val = ${e.f(n)}`),t.fingerprintDistance!==void 0){let n=e.p(t.fingerprintDistance);console.log(` based on the actual fingerprints: val = ${e.f(n)}`)}}console.log(`${t.generatedStates} states generated, ${t.distinctStates} distinct states found, ${t.queuedStates} states left on queue.`),console.log(`The depth of the complete state graph search is ${t.depth}.`);let n=t.outDegrees&&e.g(t.outDegrees);n&&console.log(n)},pi=async(r,a)=>{if(!(0,n.existsSync)(r))return console.error(`Cannot find the specification file ${r}`),e.V.configParseError;let o=(0,n.readFileSync)(r,`utf8`),s=(0,i.basename)(r,`.tla`),c=e.b(o).name;if(c!==s)throw e.z([{location:`Unknown location`,message:`File name '${s}' does not match the name '${c}' of the top level module it contains.`}],!0);let l=a.get(`-config`)?.[0]??(a.has(`-config`)?void 0:r.replace(/\.tla$/,`.cfg`));if(!l||!(0,n.existsSync)(l))return console.error(`Cannot find the configuration file ${l??``}`),e.V.configParseError;let u=e.A((0,n.readFileSync)(l,`utf8`));a.has(`-deadlock`)&&(u.checkDeadlock=!1);let d=a.has(`-seed`)?a.get(`-seed`)?.[0]:`0`;if(d===void 0)return console.error(`Error: seed required.`),1;if(!ti(d))return console.error(`Error: An integer for seed required. But encountered ${d}`),1;let f=a.has(`-lncheck`)?a.get(`-lncheck`)?.[0]?.toLowerCase():`default`;if(f===void 0)return console.error(`Error: expect a strategy such as final for -lncheck option.`),1;let p=a.get(`-dump`);if(p?.length===0)return console.error(`Error: A file name for dumping states required.`),1;let m=p?.length===2&&ii.find(e=>p[0].toLowerCase().includes(e));if(m)return console.error(`Error: tla-ts does not support the -dump format ${m}.`),1;let h=(0,i.dirname)(r);console.log(`Checking ${(0,i.basename)(r)} with ${(0,i.basename)(l)}`);let g=await t.t({workers:ni(a.get(`-workers`)),livenessCheck:[`final`,`seqfinal`,`off`].includes(f)?`final`:`default`,seed:BigInt(d),dump:p&&oi(p),source:o,config:u,onPause:()=>(0,n.readSync)(0,Buffer.alloc(1)),loadModule:e=>{let t=(0,i.join)(h,`${e}.tla`);return(0,n.existsSync)(t)?(0,n.readFileSync)(t,`utf8`):void 0},loadClass:e=>{let t=(0,i.join)(h,`${e}.class`);return(0,n.existsSync)(t)?(0,n.readFileSync)(t):void 0},readFile:e=>(0,n.existsSync)(e)?(0,n.readFileSync)(e,`utf8`):void 0,writeFile:(e,t)=>{(0,n.mkdirSync)((0,i.dirname)((0,i.resolve)(e)),{recursive:!0}),(0,n.writeFileSync)(e,t)}});return fi(g),g.failure?.exitCode??Yr[g.status]},mi=e=>`*** Errors: ${e.errors.length}\n\n${e.errors.map(e=>`${e.location}\n\n${e.message}\n\n`).join(`
|
|
31
|
+
`)}`,hi=(t,n)=>{if(t instanceof e.M||t instanceof e.P)return console.log(`Error: ${t.message}`);let r=t instanceof e.I?t.sany:void 0;if(!r||n===void 0)return console.error(`${t.name}: ${t.message}`);console.log(r.isFatal?`\nFatal errors while parsing TLA+ spec in file ${(0,i.basename)(n,`.tla`)}\n\n${r.errors.map(e=>`${e.location}\n\n${e.message}\n`).join(``)}${mi(r)}\n`:`Semantic errors:\n\n${mi(r)}`),console.log(`Error: Parsing or semantic analysis failed.`)},gi=async(t,n)=>{try{return await t()}catch(t){if(!(t instanceof e.N))throw t;return hi(t,n),e.B(t)}},_i=async(t,n)=>{let r=[];for(let[e,i]of t.entries())e>0&&console.log(``),r.push(await gi(()=>n(i),i));return r.find(t=>t!==e.V.success)??e.V.success},vi=()=>(process.env.PATH??``).split(i.delimiter).map(e=>(0,i.join)(e,`tlapm`)).filter(e=>(0,n.existsSync)(e)),yi=()=>vi().map(e=>(0,i.join)((0,i.dirname)((0,i.dirname)((0,n.realpathSync)(e))),`lib/tlapm/stdlib`)).find(e=>(0,n.existsSync)(e)),bi=e=>e.flatMap(e=>$r.test(e)?(0,n.globSync)(e).sort():[e]),xi=e=>{let t=vi()[0];return t===void 0?(console.error(`Error: tla-ts prove runs tlapm to prove obligations, but tlapm isn't on your PATH. Install tlapm, or pass -N to only generate the obligations.`),1):(0,r.spawnSync)(t,bi(e),{stdio:`inherit`}).status??1},Si=e=>(0,n.existsSync)(e)?{file:e,source:(0,n.readFileSync)(e,`utf8`)}:void 0,Ci=e=>console.error(`@!!BEGIN\n${e.map(e=>`@!!${e}\n`).join(``)}@!!END\n`),wi=e=>/^[+,\-./0-9:=@A-Z_a-z]+$/.test(e)?e:`'${e.replaceAll(`'`,`'\\''`)}'`,Ti=e=>{let t=/* @__PURE__ */ new Date,n=e=>String(e).padStart(2,`0`),r=`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}`,i=`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`;console.log(`\n\\* TLAPM version 5f5037f\n\\* launched at ${r} ${i} with command line:\n\\* ${[`tla-ts`,`prove`,...e].map(wi).join(` `)}\n`)},Ei={incomplete:11,emptyTarget:12},Di=(e,t,n)=>{let r=e.summary;n||(r.absent.forEach(e=>console.error(`Missing proof at ${l(e)}`)),r.omitted.forEach(e=>console.error(`Omitted proof at ${l(e)}`)));let i=r.absent.length+r.omitted.length>0;i&&console.error(`${u(e.location)}[ERROR]: Proof incomplete in module ${JSON.stringify(e.name)}: ${r.absent.length} missing, ${r.omitted.length} omitted proof step(s).`);let a=t&&e.obligations.length===0;return a&&console.error(`${u(e.location)}[ERROR]: No proof obligation found for the selected target.`),[...i?[Ei.incomplete]:[],...a?[Ei.emptyTarget]:[]]},Oi=t=>{try{return t()}catch(t){if(!(t instanceof e.F))throw t;console.error(` tlapm ending abnormally with ${t.exception}\n`);return}},ki=t=>{if(!t.includes(`-N`)&&!t.includes(`--summary`))return xi(t);let r=Zr.parse(t),a=r.unknown[0];if(a!==void 0)return console.error(`Error: tla-ts prove does not support the tlapm option ${a}.`),1;if(r.incomplete)return console.error(`Error: option '${r.incomplete.name}' needs an argument.`),1;let o=r.options.find(e=>e.name!==`-I`&&e.values.some(e=>!/^-?\d+$/.test(e)));if(o)return console.error(`Error: option '${o.name}' expects an integer.`),1;let s=bi(r.positionals),c=s.map(e=>e.endsWith(`.tla`)?e:`${e}.tla`);if(c.length===0)return console.error(Qr),1;let l=r.has(`--toolbox`)||r.has(`--line`);l&&Ti(t);let u=r.options.reduce((e,t)=>{let[n,r]=t.values.map(Number);return t.name===`--toolbox`?{start:n,end:r===0?1/0:r}:t.name===`--line`?n===0?Fr:{start:n,end:n}:e},Fr),d=yi(),f=r.options.flatMap(e=>e.name===`-I`?e.values:[]),p=c.reduce((e,t)=>e.includes((0,i.dirname)(t))?e:[(0,i.dirname)(t),...e],[`.`,...d?[d]:[],...f.toReversed()]),m=Oi(()=>{let t=c.findIndex(e=>!(0,n.existsSync)(e));if(t!==-1){let n=s[t];throw console.error(`File "<unknown>":\nError: File ${JSON.stringify(n)} not found`),new e.F(`File ${n} not found`,{failure:`Module.Parser.parse_file`})}return Jr(c.map(e=>({file:`./${e}`,source:(0,n.readFileSync)(e,`utf8`)})),e=>p.map(t=>Si(`${t}/${e}.tla`)).find(Boolean),{lines:u,onWarning:e=>{if(e.channel===`stdout`)return console.log(e.text);let t=e.channel===`toolbox`||e.channel===`toolboxOnly`;if(l&&t)return Ci([`type:warning`,`msg:${e.text}`]);e.channel!==`toolboxOnly`&&console.error(e.text)}})});if(!m)return 3;let h=m.flatMap(e=>(r.has(`--summary`)&&console.log(qr(e)),l&&(e.obligations.forEach(e=>Ci([`type:obligation`,`id:${e.id}`,`loc:${e.location}`,`status:to be proved`,...r.has(`--printallobs`)?[`obl:${e.text}`]:[]])),Ci([`type:obligationsnumber`,`count:${e.obligations.length}`])),r.has(`--strict`)?Di(e,u.start>0||u.end<1/0,r.has(`--summary`)):[]));return h.includes(Ei.incomplete)?Ei.incomplete:h[0]??e.V.success},Ai=async e=>{if(e[0]===`prove`)return gi(()=>ki(e.slice(1)));let t=Xr.parse(e),r=ei(t.positionals),i=t.has(`-config`),a=r.map(e=>({...e,path:e.path.replace(/\.cfg$/,`.tla`)})).filter(e=>e.path.endsWith(`.tla`)&&(!e.isGlobbed||i||(0,n.existsSync)(e.path.replace(/\.tla$/,`.cfg`)))).map(e=>e.path);return a.length===0?(console.error(Qr),1):i&&a.length>1?(console.error(`Error: -config applies to one specification, but several were given.`),1):_i([...new Set(a)],e=>pi(e,t))},ji=async()=>{process.exitCode=await Ai(process.argv.slice(2))};exports.runCli=ji;
|