tla-ts 0.0.3-dev.3504663 → 0.0.3-dev.3539317

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 CHANGED
@@ -49,6 +49,7 @@ interface ApplyExpression {
49
49
  argumentCounts?: number[];
50
50
  argumentsRange?: SourceRange;
51
51
  selectorRanges?: SourceRange[];
52
+ argumentRanges?: (SourceRange | undefined)[];
52
53
  location: SourceLocation;
53
54
  resolution?: LocalResolution;
54
55
  }
@@ -60,6 +61,7 @@ interface OperatorReferenceExpression {
60
61
  interface LambdaExpression {
61
62
  kind: "Lambda";
62
63
  params: string[];
64
+ paramRanges?: SourceRange[];
63
65
  body: Expression;
64
66
  location: SourceLocation;
65
67
  }
@@ -111,9 +113,11 @@ interface LetExpression {
111
113
  type BoundPattern = {
112
114
  kind: "Name";
113
115
  name: string;
116
+ ranges?: SourceRange[];
114
117
  } | {
115
118
  kind: "Tuple";
116
119
  names: string[];
120
+ ranges?: SourceRange[];
117
121
  };
118
122
  interface Bound {
119
123
  pattern: BoundPattern;
@@ -129,6 +133,7 @@ interface UnboundedQuantifierExpression {
129
133
  kind: "UnboundedQuantifier";
130
134
  quantifier: "Forall" | "Exists";
131
135
  names: string[];
136
+ nameRanges?: SourceRange[];
132
137
  isTemporal?: boolean;
133
138
  body: Expression;
134
139
  location: SourceLocation;
@@ -245,6 +250,7 @@ interface LabelExpression {
245
250
  kind: "Label";
246
251
  name: string;
247
252
  params: string[];
253
+ paramRanges?: SourceRange[];
248
254
  body: Expression;
249
255
  location: SourceLocation;
250
256
  }
@@ -267,6 +273,7 @@ interface SubexpressionExpression {
267
273
  kind: "Subexpression";
268
274
  selectors: Selector[];
269
275
  selectorRanges?: SourceRange[];
276
+ argumentRanges?: (SourceRange | undefined)[];
270
277
  location: SourceLocation;
271
278
  }
272
279
  type Expression = NumberExpression | DecimalExpression | StringExpression | IdentifierExpression | ApplyExpression | OperatorReferenceExpression | LambdaExpression | JunctionExpression | PrimeExpression | UnchangedExpression | EnabledExpression | IfExpression | CaseExpression | LetExpression | QuantifierExpression | UnboundedQuantifierExpression | ChooseExpression | SetEnumerationExpression | SetFilterExpression | SetMapExpression | TupleExpression | FunctionConstructionExpression | FunctionSetExpression | RecordExpression | ExceptExpression | ExceptAtExpression | FunctionApplicationExpression | FieldAccessExpression | ProductExpression | TemporalExpression | ActionExpression | FairnessExpression | LabelExpression | SubexpressionExpression;
@@ -308,6 +315,7 @@ interface Assumption {
308
315
  }
309
316
  interface InstanceSubstitution {
310
317
  name: string;
318
+ nameRange: SourceRange;
311
319
  expression: Expression;
312
320
  }
313
321
  interface Instance {
@@ -327,6 +335,7 @@ interface NewSymbol {
327
335
  arity: number;
328
336
  level: "Constant" | "Variable" | "State" | "Action" | "Temporal";
329
337
  set: Expression | undefined;
338
+ nameRange?: SourceRange;
330
339
  location: SourceLocation;
331
340
  }
332
341
  interface AssumeProve {
@@ -376,6 +385,7 @@ type StepBody = UseOrHide | Instance | DefineStep | {
376
385
  } | {
377
386
  kind: "Take";
378
387
  names: string[];
388
+ nameRanges?: SourceRange[];
379
389
  bounds: Bound[];
380
390
  } | {
381
391
  kind: "Witness";
@@ -383,6 +393,7 @@ type StepBody = UseOrHide | Instance | DefineStep | {
383
393
  } | {
384
394
  kind: "Pick";
385
395
  names: string[];
396
+ nameRanges?: SourceRange[];
386
397
  bounds: Bound[];
387
398
  body: Expression;
388
399
  } | {
@@ -601,6 +612,7 @@ interface SanyError {
601
612
  }
602
613
  interface SanyReport {
603
614
  errors: SanyError[];
615
+ warnings: SanyError[];
604
616
  isFatal: boolean;
605
617
  parseError?: string;
606
618
  }
package/dist/index.d.ts CHANGED
@@ -49,6 +49,7 @@ interface ApplyExpression {
49
49
  argumentCounts?: number[];
50
50
  argumentsRange?: SourceRange;
51
51
  selectorRanges?: SourceRange[];
52
+ argumentRanges?: (SourceRange | undefined)[];
52
53
  location: SourceLocation;
53
54
  resolution?: LocalResolution;
54
55
  }
@@ -60,6 +61,7 @@ interface OperatorReferenceExpression {
60
61
  interface LambdaExpression {
61
62
  kind: "Lambda";
62
63
  params: string[];
64
+ paramRanges?: SourceRange[];
63
65
  body: Expression;
64
66
  location: SourceLocation;
65
67
  }
@@ -111,9 +113,11 @@ interface LetExpression {
111
113
  type BoundPattern = {
112
114
  kind: "Name";
113
115
  name: string;
116
+ ranges?: SourceRange[];
114
117
  } | {
115
118
  kind: "Tuple";
116
119
  names: string[];
120
+ ranges?: SourceRange[];
117
121
  };
118
122
  interface Bound {
119
123
  pattern: BoundPattern;
@@ -129,6 +133,7 @@ interface UnboundedQuantifierExpression {
129
133
  kind: "UnboundedQuantifier";
130
134
  quantifier: "Forall" | "Exists";
131
135
  names: string[];
136
+ nameRanges?: SourceRange[];
132
137
  isTemporal?: boolean;
133
138
  body: Expression;
134
139
  location: SourceLocation;
@@ -245,6 +250,7 @@ interface LabelExpression {
245
250
  kind: "Label";
246
251
  name: string;
247
252
  params: string[];
253
+ paramRanges?: SourceRange[];
248
254
  body: Expression;
249
255
  location: SourceLocation;
250
256
  }
@@ -267,6 +273,7 @@ interface SubexpressionExpression {
267
273
  kind: "Subexpression";
268
274
  selectors: Selector[];
269
275
  selectorRanges?: SourceRange[];
276
+ argumentRanges?: (SourceRange | undefined)[];
270
277
  location: SourceLocation;
271
278
  }
272
279
  type Expression = NumberExpression | DecimalExpression | StringExpression | IdentifierExpression | ApplyExpression | OperatorReferenceExpression | LambdaExpression | JunctionExpression | PrimeExpression | UnchangedExpression | EnabledExpression | IfExpression | CaseExpression | LetExpression | QuantifierExpression | UnboundedQuantifierExpression | ChooseExpression | SetEnumerationExpression | SetFilterExpression | SetMapExpression | TupleExpression | FunctionConstructionExpression | FunctionSetExpression | RecordExpression | ExceptExpression | ExceptAtExpression | FunctionApplicationExpression | FieldAccessExpression | ProductExpression | TemporalExpression | ActionExpression | FairnessExpression | LabelExpression | SubexpressionExpression;
@@ -308,6 +315,7 @@ interface Assumption {
308
315
  }
309
316
  interface InstanceSubstitution {
310
317
  name: string;
318
+ nameRange: SourceRange;
311
319
  expression: Expression;
312
320
  }
313
321
  interface Instance {
@@ -327,6 +335,7 @@ interface NewSymbol {
327
335
  arity: number;
328
336
  level: "Constant" | "Variable" | "State" | "Action" | "Temporal";
329
337
  set: Expression | undefined;
338
+ nameRange?: SourceRange;
330
339
  location: SourceLocation;
331
340
  }
332
341
  interface AssumeProve {
@@ -376,6 +385,7 @@ type StepBody = UseOrHide | Instance | DefineStep | {
376
385
  } | {
377
386
  kind: "Take";
378
387
  names: string[];
388
+ nameRanges?: SourceRange[];
379
389
  bounds: Bound[];
380
390
  } | {
381
391
  kind: "Witness";
@@ -383,6 +393,7 @@ type StepBody = UseOrHide | Instance | DefineStep | {
383
393
  } | {
384
394
  kind: "Pick";
385
395
  names: string[];
396
+ nameRanges?: SourceRange[];
386
397
  bounds: Bound[];
387
398
  body: Expression;
388
399
  } | {
@@ -601,6 +612,7 @@ interface SanyError {
601
612
  }
602
613
  interface SanyReport {
603
614
  errors: SanyError[];
615
+ warnings: SanyError[];
604
616
  isFatal: boolean;
605
617
  parseError?: string;
606
618
  }
package/dist/run-cli.cjs CHANGED
@@ -23,9 +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.L)||!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.S(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.I(`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.I(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.I(`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.I(`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.H.success,"assumption-violation":e.H.assumptionViolation,deadlock:e.H.deadlock,"invariant-violation":e.H.safetyViolation,"property-violation":e.H.safetyViolation,"liveness-violation":e.H.livenessViolation,"postcondition-violation":e.H.assumptionViolation,error:e.H.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(`
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.I(`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.U.success,"assumption-violation":e.U.assumptionViolation,deadlock:e.U.deadlock,"invariant-violation":e.U.safetyViolation,"property-violation":e.U.safetyViolation,"liveness-violation":e.U.livenessViolation,"postcondition-violation":e.U.assumptionViolation,error:e.U.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
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.D(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
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:
29
29
  `);else if(r===void 0)si(e.trace);else{si(e.trace,`Error: The following behavior constitutes a counter-example:
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.H.configParseError;let o=(0,n.readFileSync)(r,`utf8`),s=(0,i.basename)(r,`.tla`),c=e.b(o,s).name;if(c!==s)throw e.B([{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.H.configParseError;let u=e.j((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.N||t instanceof e.F)return console.log(`Error: ${t.message}`);let r=t instanceof e.L?t.sany:void 0;if(!r||n===void 0)return console.error(`${t.name}: ${t.message}`);r.parseError!==void 0&&console.log(r.parseError),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.P))throw t;return hi(t,n),e.V(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.H.success)??e.H.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.I))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.I(`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.H.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;
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.U.configParseError;let o=(0,n.readFileSync)(r,`utf8`),s=(0,i.basename)(r,`.tla`),c=e.b(o,s).name;if(c!==s)throw e.B([{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.U.configParseError;let u=e.j((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.N||t instanceof e.F)return console.log(`Error: ${t.message}`);let r=t instanceof e.L?t.sany:void 0;if(!r||n===void 0)return console.error(`${t.name}: ${t.message}`);r.parseError!==void 0&&console.log(r.parseError),r.warnings.length>0&&console.log(e.V(r.warnings)),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.P))throw t;return hi(t,n),e.H(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.U.success)??e.U.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.I))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.I(`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.U.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;