tla-ts 0.0.3-dev.5e6ab4d → 0.0.3-dev.6a30eee
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +3 -2
- package/dist/run-cli.js +3 -2
- package/dist/transfer.cjs +18 -14
- package/dist/transfer.js +18 -14
- package/package.json +1 -1
- package/src/check.ts +70 -28
- package/src/errors.ts +5 -0
- package/src/evaluate.ts +41 -12
- package/src/exit-codes.ts +20 -30
- package/src/live-check.ts +710 -0
- package/src/liveness.ts +4 -521
- package/src/parallel.ts +15 -2
- package/src/run-cli.ts +9 -2
- package/src/runtime.ts +1 -1
- package/src/successors.ts +10 -6
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/parallel.cjs
CHANGED
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
const e=require("./transfer.cjs"),t=async e=>{if(typeof Worker==`function`){let t=new Worker(new URL(`./parallel-worker.js`,require("url").pathToFileURL(__filename).href),{type:`module`});return t.addEventListener(`message`,t=>e(t.data)),t.addEventListener(`error`,()=>e({type:`abort`})),t}let t=new(await(import(
|
|
10
10
|
/* @vite-ignore */
|
|
11
11
|
/* webpackIgnore: true */
|
|
12
|
-
`node:worker_threads`))).Worker(new URL(`./parallel-worker.js`,require("url").pathToFileURL(__filename).href));return t.on(`message`,e),t.on(`error`,()=>e({type:`abort`})),{postMessage:(e,n)=>t.postMessage(e,n),terminate:()=>void t.terminate()}},n=async n=>{let r=typeof n.config==`string`?e.A(n.config):n.config,i=()=>e.l({...n,config:r}),
|
|
12
|
+
`node:worker_threads`))).Worker(new URL(`./parallel-worker.js`,require("url").pathToFileURL(__filename).href));return t.on(`message`,e),t.on(`error`,()=>e({type:`abort`})),{postMessage:(e,n)=>t.postMessage(e,n),terminate:()=>void t.terminate()}},n=async n=>{let r=typeof n.config==`string`?e.A(n.config):n.config,i=n.onPrint??console.log,a={count:0},o=()=>{let t={count:a.count};return e.l({...n,config:r,onPrint:e=>t.count-->0?void 0:i(e)})},s=n.workers??1;if(s<2||typeof SharedArrayBuffer!=`function`||r.view!==void 0||r.postconditions.length>0||r.possible.length>0)return o();let c=/* @__PURE__ */ new Map,l=e=>{let t=n.loadModule?.(e);return c.set(e,t),t},u=/* @__PURE__ */ new Map,d=e=>{let t=n.loadClass?.(e);return u.set(e,t),t};e.O(e._(n.source,r,l));let f=e.D(),p=e.y(r,{source:n.source,loadModule:l,loadClass:d,print:e=>{a.count++,i(e)},files:{readFile:n.readFile,writeFile:n.writeFile}}),m=p.environment,h=e.u(r,m,()=>e.v(n.source,l));if(e.d(p.assumptions,m)||!h||h.spec.init===void 0||h.spec.next===void 0||h.properties.liveness.length>0||e.S(m))return o();let g=e.T(),_={fingerprints:e.i()},v=/* @__PURE__ */ new Int32Array(2),y=Array.from({length:s},e.n),b={generatedStates:0,distinctStates:0,queuedStates:0,depth:0,outDegrees:Array.from({length:32},()=>0)},x=[],S=()=>({status:`success`,violation:void 0,failure:void 0,...b,fingerprintDistance:e.m(b.distinctStates,b.generatedStates,()=>{let e=new BigInt64Array(b.distinctStates);return x.reduce((t,n)=>(e.set(n,t),t+n.length),0),e})}),C=t=>{let n=[];for(let r of e.C(t,m,h.spec.scope))if(g(r),b.generatedStates++,e.c(h.getFingerprintState(r),v),e.s(_.fingerprints)&&(_.fingerprints=e.a(_.fingerprints)),e.o(_.fingerprints,v[0],v[1])){if(h.findViolatedInvariant(r)||h.findFailedInitialPredicate(r))return!1;if(h.satisfiesConstraints(r)){if(!y[n.length%s].encode(r))return!1;n.push(r),b.distinctStates++}}return x.push(BigInt64Array.from(n,e=>m.runtime.getFingerprint(e))),!0};try{if(!C(h.spec.init))return o()}catch(t){if(!(t instanceof e.P))throw t;return o()}if(e.D()!==f)return o();if(b.depth=b.generatedStates===0?0:1,b.distinctStates===0)return S();let w=[],T={count:s,resolve:e=>{}},E=e=>{w.push(e),(e.type===`abort`||w.length===T.count)&&T.resolve(w.splice(0))},D=e=>new Promise(t=>{T.count=e,T.resolve=t}),O=D(s),k=new Int32Array(new SharedArrayBuffer(s*4)),A=new Int32Array(new SharedArrayBuffer(s*4)),j=await Promise.all(Array.from({length:s},()=>t(E))),M=()=>j.forEach(e=>e.terminate()),N=/* @__PURE__ */ new Map,P=(e,t)=>{let n=e<t?`${e}:${t}`:`${t}:${e}`,r=N.get(n)??new MessageChannel;return N.set(n,r),e<t?r.port1:r.port2};j.forEach((e,t)=>{let i=Array.from({length:s},(e,n)=>n===t?void 0:P(t,n)),a=y[t].finish(),o={type:`start`,source:n.source,config:r,modules:[...c],classes:[...u],index:t,ports:i,seed:a,fingerprints:_.fingerprints,requests:k,remaining:A};e.postMessage(o,[...i.filter(e=>e!==void 0),a.words.buffer])});let F=e=>e.some(e=>e.type===`abort`),I=e=>j.forEach(t=>t.postMessage(e)),L=async t=>{let n=t.filter(e=>e.type===`paused`).length;if(n===0||F(t))return t;_.fingerprints=e.a(_.fingerprints);let r=D(n);return I({type:`resize`,fingerprints:_.fingerprints}),[...t.filter(e=>e.type!==`paused`),...await L(await r)]};if(F(await O))return M(),o();for(let e=1;;e++){let t=D(s);k.forEach((e,t)=>Atomics.store(k,t,0)),I({type:`level`,level:e});let n=await L(await t);if(F(n))return M(),o();let r=n.flatMap(e=>e.type===`level`?[e]:[]),i=r.reduce((e,t)=>e+t.added,0);if(b.generatedStates+=r.reduce((e,t)=>e+t.generated,0),b.distinctStates+=i,r.forEach(e=>{e.outDegrees.forEach((e,t)=>b.outDegrees[t]+=e),x.push(e.fingerprints)}),i===0)return M(),S();b.depth++}};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return n}});
|
package/dist/parallel.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
import{A as e,C as t,D as n,O as r,P as i,S as
|
|
9
|
+
import{A as e,C as t,D as n,O as r,P as i,S as a,T as o,_ as s,a as c,c as l,d as ee,i as te,l as u,m as d,n as f,o as ne,s as p,u as m,v as h,y as g}from"./transfer.js";const _=async e=>{if(typeof Worker==`function`){let t=new Worker(new URL(`./parallel-worker.js`,import.meta.url),{type:`module`});return t.addEventListener(`message`,t=>e(t.data)),t.addEventListener(`error`,()=>e({type:`abort`})),t}let t=new(await(import(
|
|
10
10
|
/* @vite-ignore */
|
|
11
11
|
/* webpackIgnore: true */
|
|
12
|
-
`node:worker_threads`))).Worker(new URL(`./parallel-worker.js`,import.meta.url));return t.on(`message`,e),t.on(`error`,()=>e({type:`abort`})),{postMessage:(e,n)=>t.postMessage(e,n),terminate:()=>void t.terminate()}},
|
|
12
|
+
`node:worker_threads`))).Worker(new URL(`./parallel-worker.js`,import.meta.url));return t.on(`message`,e),t.on(`error`,()=>e({type:`abort`})),{postMessage:(e,n)=>t.postMessage(e,n),terminate:()=>void t.terminate()}},v=async v=>{let y=typeof v.config==`string`?e(v.config):v.config,b=v.onPrint??console.log,x={count:0},S=()=>{let e={count:x.count};return u({...v,config:y,onPrint:t=>e.count-->0?void 0:b(t)})},C=v.workers??1;if(C<2||typeof SharedArrayBuffer!=`function`||y.view!==void 0||y.postconditions.length>0||y.possible.length>0)return S();let w=/* @__PURE__ */ new Map,T=e=>{let t=v.loadModule?.(e);return w.set(e,t),t},E=/* @__PURE__ */ new Map,D=e=>{let t=v.loadClass?.(e);return E.set(e,t),t};r(s(v.source,y,T));let O=n(),k=g(y,{source:v.source,loadModule:T,loadClass:D,print:e=>{x.count++,b(e)},files:{readFile:v.readFile,writeFile:v.writeFile}}),A=k.environment,j=m(y,A,()=>h(v.source,T));if(ee(k.assumptions,A)||!j||j.spec.init===void 0||j.spec.next===void 0||j.properties.liveness.length>0||a(A))return S();let M=o(),N={fingerprints:te()},P=/* @__PURE__ */ new Int32Array(2),F=Array.from({length:C},f),I={generatedStates:0,distinctStates:0,queuedStates:0,depth:0,outDegrees:Array.from({length:32},()=>0)},L=[],R=()=>({status:`success`,violation:void 0,failure:void 0,...I,fingerprintDistance:d(I.distinctStates,I.generatedStates,()=>{let e=new BigInt64Array(I.distinctStates);return L.reduce((t,n)=>(e.set(n,t),t+n.length),0),e})}),z=e=>{let n=[];for(let r of t(e,A,j.spec.scope))if(M(r),I.generatedStates++,l(j.getFingerprintState(r),P),p(N.fingerprints)&&(N.fingerprints=c(N.fingerprints)),ne(N.fingerprints,P[0],P[1])){if(j.findViolatedInvariant(r)||j.findFailedInitialPredicate(r))return!1;if(j.satisfiesConstraints(r)){if(!F[n.length%C].encode(r))return!1;n.push(r),I.distinctStates++}}return L.push(BigInt64Array.from(n,e=>A.runtime.getFingerprint(e))),!0};try{if(!z(j.spec.init))return S()}catch(e){if(!(e instanceof i))throw e;return S()}if(n()!==O)return S();if(I.depth=I.generatedStates===0?0:1,I.distinctStates===0)return R();let B=[],V={count:C,resolve:e=>{}},H=e=>{B.push(e),(e.type===`abort`||B.length===V.count)&&V.resolve(B.splice(0))},U=e=>new Promise(t=>{V.count=e,V.resolve=t}),W=U(C),G=new Int32Array(new SharedArrayBuffer(C*4)),K=new Int32Array(new SharedArrayBuffer(C*4)),q=await Promise.all(Array.from({length:C},()=>_(H))),J=()=>q.forEach(e=>e.terminate()),Y=/* @__PURE__ */ new Map,X=(e,t)=>{let n=e<t?`${e}:${t}`:`${t}:${e}`,r=Y.get(n)??new MessageChannel;return Y.set(n,r),e<t?r.port1:r.port2};q.forEach((e,t)=>{let n=Array.from({length:C},(e,n)=>n===t?void 0:X(t,n)),r=F[t].finish(),i={type:`start`,source:v.source,config:y,modules:[...w],classes:[...E],index:t,ports:n,seed:r,fingerprints:N.fingerprints,requests:G,remaining:K};e.postMessage(i,[...n.filter(e=>e!==void 0),r.words.buffer])});let Z=e=>e.some(e=>e.type===`abort`),Q=e=>q.forEach(t=>t.postMessage(e)),$=async e=>{let t=e.filter(e=>e.type===`paused`).length;if(t===0||Z(e))return e;N.fingerprints=c(N.fingerprints);let n=U(t);return Q({type:`resize`,fingerprints:N.fingerprints}),[...e.filter(e=>e.type!==`paused`),...await $(await n)]};if(Z(await W))return J(),S();for(let e=1;;e++){let t=U(C);G.forEach((e,t)=>Atomics.store(G,t,0)),Q({type:`level`,level:e});let n=await $(await t);if(Z(n))return J(),S();let r=n.flatMap(e=>e.type===`level`?[e]:[]),i=r.reduce((e,t)=>e+t.added,0);if(I.generatedStates+=r.reduce((e,t)=>e+t.generated,0),I.distinctStates+=i,r.forEach(e=>{e.outDegrees.forEach((e,t)=>I.outDegrees[t]+=e),L.push(e.fingerprints)}),i===0)return J(),R();I.depth++}};export{v as t};
|
package/dist/run-cli.cjs
CHANGED
|
@@ -24,5 +24,6 @@ PROVE %a@]`,i)]};return{printSequent:p,printExpr:r}},Mt=(e,t)=>jt(e).printExpr(
|
|
|
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,Hn(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(Wn).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(In);t.forEach(e=>{let t={...Ur(e,o,!0,a,`File "<unknown>":
|
|
26
26
|
`),isImportant:!0};s.set(t.name,t)});let c=[...s.values()].sort((e,t)=>Wn(e.name,t.name)),l=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Set;for(let e=0;e<c.length;e++){let t=Hn(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)&&!In.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(Wn);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:ze(o,(e,t)=>ar(m,e,t),a),generator:rn(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:Vn(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:`${Nt(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.B.success,"assumption-violation":e.B.assumptionViolation,deadlock:e.B.deadlock,"invariant-violation":e.B.safetyViolation,"property-violation":e.B.safetyViolation,"liveness-violation":e.B.livenessViolation,"postcondition-violation":e.B.assumptionViolation,error:e.B.error},Xr=s(`tla-ts <Spec.tla|Spec.cfg|glob>... {options}`,[{flag:`-config <Spec.cfg>`},{flag:`-deadlock`},{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=>{let n=Object.entries(t);n.forEach(([t,r])=>console.log(`${n.length===1?``:`/\\ `}${t} = ${e.k(e.E(r))}`)),console.log(``)},ii=(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)})},ai=t=>{if(t.failure)console.log(`Error: ${t.failure.message}`),t.failure.initialState&&(console.log(`While working on the initial state:`),ri(t.failure.initialState)),ii(t.failure.trace);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"
|
|
28
|
-
`);
|
|
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=>{let n=Object.entries(t);n.forEach(([t,r])=>console.log(`${n.length===1?``:`/\\ `}${t} = ${e.k(e.E(r))}`)),console.log(``)},ii=(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)})},ai=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`,oi=t=>{if(t.failure)console.log(`Error: ${t.failure.message}`),t.failure.initialState&&(console.log(`While working on the initial state:`),ri(t.failure.initialState)),ii(t.failure.trace);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":ai(e.properties??[n]),"liveness-violation":r===void 0?i?`Error: Property ${n} is violated by the initial state:`:`Error: Action property ${n} is violated.`:ai(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`)ii(e.trace,`Error: The following behavior constitutes a counter-example:
|
|
28
|
+
`);else if(r===void 0)ii(e.trace);else{ii(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)},si=async(r,a)=>{if(!(0,n.existsSync)(r))return console.error(`Cannot find the specification file ${r}`),e.B.configParseError;let o=a.get(`-config`)?.[0]??(a.has(`-config`)?void 0:r.replace(/\.tla$/,`.cfg`));if(!o||!(0,n.existsSync)(o))return console.error(`Cannot find the configuration file ${o??``}`),e.B.configParseError;let s=e.A((0,n.readFileSync)(o,`utf8`));a.has(`-deadlock`)&&(s.checkDeadlock=!1);let c=a.has(`-seed`)?a.get(`-seed`)?.[0]:`0`;if(c===void 0)return console.error(`Error: seed required.`),1;if(!ti(c))return console.error(`Error: An integer for seed required. But encountered ${c}`),1;let l=a.has(`-lncheck`)?a.get(`-lncheck`)?.[0]?.toLowerCase():`default`;if(l===void 0)return console.error(`Error: expect a strategy such as final for -lncheck option.`),1;let u=(0,i.dirname)(r);console.log(`Checking ${(0,i.basename)(r)} with ${(0,i.basename)(o)}`);let d=await t.t({workers:ni(a.get(`-workers`)),livenessCheck:[`final`,`seqfinal`,`off`].includes(l)?`final`:`default`,seed:BigInt(c),source:(0,n.readFileSync)(r,`utf8`),config:s,onPause:()=>(0,n.readSync)(0,Buffer.alloc(1)),loadModule:e=>{let t=(0,i.join)(u,`${e}.tla`);return(0,n.existsSync)(t)?(0,n.readFileSync)(t,`utf8`):void 0},loadClass:e=>{let t=(0,i.join)(u,`${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 oi(d),d.failure?.exitCode??Yr[d.status]},ci=t=>{if(t instanceof e.M||t instanceof e.P)return console.log(`Error: ${t.message}`);console.error(`${t.name}: ${t.message}`)},li=async t=>{try{return await t()}catch(t){if(!(t instanceof e.N))throw t;return ci(t),e.z(t)}},ui=async(t,n)=>{let r=[];for(let[e,i]of t.entries())e>0&&console.log(``),r.push(await li(()=>n(i)));return r.find(t=>t!==e.B.success)??e.B.success},di=()=>(process.env.PATH??``).split(i.delimiter).map(e=>(0,i.join)(e,`tlapm`)).filter(e=>(0,n.existsSync)(e)),fi=()=>di().map(e=>(0,i.join)((0,i.dirname)((0,i.dirname)((0,n.realpathSync)(e))),`lib/tlapm/stdlib`)).find(e=>(0,n.existsSync)(e)),pi=e=>e.flatMap(e=>$r.test(e)?(0,n.globSync)(e).sort():[e]),mi=e=>{let t=di()[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,pi(e),{stdio:`inherit`}).status??1},hi=e=>(0,n.existsSync)(e)?{file:e,source:(0,n.readFileSync)(e,`utf8`)}:void 0,gi=e=>console.error(`@!!BEGIN\n${e.map(e=>`@!!${e}\n`).join(``)}@!!END\n`),_i=e=>/^[+,\-./0-9:=@A-Z_a-z]+$/.test(e)?e:`'${e.replaceAll(`'`,`'\\''`)}'`,vi=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(_i).join(` `)}\n`)},yi={incomplete:11,emptyTarget:12},bi=(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?[yi.incomplete]:[],...a?[yi.emptyTarget]:[]]},xi=t=>{try{return t()}catch(t){if(!(t instanceof e.F))throw t;console.error(` tlapm ending abnormally with ${t.exception}\n`);return}},Si=t=>{if(!t.includes(`-N`)&&!t.includes(`--summary`))return mi(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=pi(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&&vi(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=fi(),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=xi(()=>{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=>hi(`${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 gi([`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=>gi([`type:obligation`,`id:${e.id}`,`loc:${e.location}`,`status:to be proved`,...r.has(`--printallobs`)?[`obl:${e.text}`]:[]])),gi([`type:obligationsnumber`,`count:${e.obligations.length}`])),r.has(`--strict`)?bi(e,u.start>0||u.end<1/0,r.has(`--summary`)):[]));return h.includes(yi.incomplete)?yi.incomplete:h[0]??e.B.success},Ci=async e=>{if(e[0]===`prove`)return li(()=>Si(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):ui([...new Set(a)],e=>si(e,t))},wi=async()=>{process.exitCode=await Ci(process.argv.slice(2))};exports.runCli=wi;
|
package/dist/run-cli.js
CHANGED
|
@@ -24,5 +24,6 @@ PROVE %a@]`,i)]};return{printSequent:p,printExpr:n}},on=(e,t)=>an(e).printExpr(
|
|
|
24
24
|
`,a-1),c=t.findLast(e=>e.kind!==`End`&&(e.line<o||e.line===o&&e.column<s));return{offset:a,line:o,column:s,end:{reason:ui,line:c?.line??o,column:c?c.endColumn+1:s,isEnd:!0}}},pi=e=>{try{return e()}catch(e){if(!(e instanceof i)||!e.failure)throw e;return e.failure}},mi=e=>typeof e==`object`&&!!e&&`reason`in e,hi=e=>{let t=pi(()=>fi(e));if(mi(t))return[t];let n=pi(()=>g(t?e.slice(0,t.offset):e));return t&&(!mi(n)||n.isEnd)?[{reason:`Unexpected TAB character. TLAPS does not handle TAB characters in source files.`,line:t.line,column:t.column,isEnd:!1},mi(n)&&n.reason===ui?n:t.end]:mi(n)?[n]:n},gi=(e,t,n,i,a)=>{if(!li.test(e.source))throw new r(`No tokens in file`);let o=hi(e.source);if(Array.isArray(o)){o.forEach(t=>{let n=`File ${JSON.stringify(e.file)}, line ${t.line}, character ${t.column}\n${t.reason}`;i({text:n,channel:`stderr`}),i({text:`${n}\n`,channel:`toolboxOnly`})});let t=`Could not parse ${JSON.stringify(e.file)} successfully.`;throw i({text:`${a}Error: ${t}`,channel:`stderr`}),new r(t,{failure:`Module.Parser.parse_file`})}let s=si(e.file,e.source,t,n).convertModule(o),c=e.file.slice(e.file.lastIndexOf(`/`)+1),l=c.replace(/\.tla$/,``);return s.name===l?s:(i({text:`${de(s.location)}Warning: module name ${JSON.stringify(s.name)} does not match file name ${JSON.stringify(c)}.`,channel:`toolbox`}),{...s,name:l})},_i=e=>{let t=new Map([...e].map(([e,t])=>[e,hr(t).dependencies])),n=/* @__PURE__ */ new Set,i=[],a=o=>{if(n.has(o))return;n.add(o);let s=e.get(o);if(!s)throw new r(`Module "${o}" not found`);(t.get(o)??[]).forEach(a),i.push(s)};return[...e.keys()].sort(_r).forEach(a),i},vi=(e,t,n)=>t.length===0?[]:[` ${e}_proofs_count = ${t.length}`,...t.map((t,r)=>` ${e}_proof_${n+r+1} at ${ce(t)}`)],yi=(e,t,n)=>{let r=e.location;return[` ---- incomplete proof of theorem at ${r?ce({...r,endLine:r.startLine,endColumn:r.startColumn}):`<unknown location>`} ----`,...vi(`missing`,e.absent,t),...vi(`omitted`,e.omitted,n),` ====`]},bi=e=>{let t=e.summary,n=t.theorems.reduce((e,t)=>t.absent.length+t.omitted.length===0?e:{lines:[...e.lines,...yi(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
|
`)},xi=(e,t,n={})=>{let i=n.lines??ci,a=n.onWarning??(()=>{}),o={value:0},s=new Map(lr);e.forEach(e=>{let t={...gi(e,o,!0,a,`File "<unknown>":
|
|
26
26
|
`),isImportant:!0};s.set(t.name,t)});let c=[...s.values()].sort((e,t)=>_r(e.name,t.name)),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Set;for(let e=0;e<c.length;e++){let n=hr(c[e]);n.submodules.forEach((e,t)=>{u.add(t),s.has(t)||s.set(t,e)});for(let e of n.dependencies){if(s.has(e)&&!lr.has(e))continue;let r=t(e);if(!r){!s.has(e)&&!l.has(e)&&l.set(e,n.locations.get(e));continue}let i=gi(r,o,!1,a,ue(n.locations.get(e)));s.set(e,i),c.push(i)}}let d=[...l.keys()].filter(e=>!u.has(e)).sort(_r);if(d.forEach(e=>a(D(l.get(e),`Unknown module ${JSON.stringify(e)}`))),d.length>0)throw new r(`Unknown module ${JSON.stringify(d[0])}`,{failure:`Module.Parser.load_module`});let f={anonymizer:dt(o,(e,t)=>Mr(f,e,t),a),generator:jn(o,new Set(e.map(e=>e.file)),i,a),salts:{value:0},latestModules:/* @__PURE__ */ new Map,onWarning:a},p=_i(s).map(e=>e.isStandard?e:mr(s,e,/* @__PURE__ */ new Set)),m=new Map(p.map(e=>[e.name,e]));return p.flatMap(e=>{if(e.isStandard)return[];let t=Nr(f,m,void 0,e);if(!e.isImportant)return[];let n=Pr(f,[],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:`${sn(e.sequent)}\n`;return[{id:t+1,location:di(n),text:r}]});return[{name:e.name,location:e.location,obligations:r,summary:n.summary}]})},Si={success:t.success,"assumption-violation":t.assumptionViolation,deadlock:t.deadlock,"invariant-violation":t.safetyViolation,"property-violation":t.safetyViolation,"liveness-violation":t.livenessViolation,"postcondition-violation":t.assumptionViolation,error:t.error},Ci=se(`tla-ts <Spec.tla|Spec.cfg|glob>... {options}`,[{flag:`-config <Spec.cfg>`},{flag:`-deadlock`},{flag:`-lncheck <final|default>`},{flag:`-seed <num>`},{flag:`-workers <count|auto>`}]),wi=se(`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}]),Ti=[`Usage: ${Ci.usage}`,` ${wi.usage}`,` tla-ts prove [<tlapm option>]... <Module.tla|glob>...`].join(`
|
|
27
|
-
`),Ei=/[*?[{]/,Di=e=>e.flatMap(e=>Ei.test(e)?ee(e).sort().map(e=>({path:e,isGlobbed:!0})):[{path:e,isGlobbed:!1}]),Oi=e=>/^[+-]?\d+$/.test(e)&&BigInt.asIntN(64,BigInt(e))===BigInt(e),ki=e=>e?e[0]===`auto`?ae():Math.max(1,Number.parseInt(e[0],10)||1):1,Ai=e=>{let t=Object.entries(e);t.forEach(([e,r])=>console.log(`${t.length===1?``:`/\\ `}${e} = ${m(n(r))}`)),console.log(``)},ji=(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`}>`),Ai(e.state)})},Mi=e=>{if(e.failure)console.log(`Error: ${e.failure.message}`),e.failure.initialState&&(console.log(`While working on the initial state:`),Ai(e.failure.initialState)),ji(e.failure.trace);else if(e.violation){let t=e.violation,n=t.name,r=t.loopStart,i=r===void 0&&t.trace.length===1&&(e.status===`invariant-violation`||e.status===`liveness-violation`),a={success:``,error:``,"assumption-violation":t.message?`Error: Evaluating assumption ${n} failed.\n${t.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"
|
|
28
|
-
`);
|
|
27
|
+
`),Ei=/[*?[{]/,Di=e=>e.flatMap(e=>Ei.test(e)?ee(e).sort().map(e=>({path:e,isGlobbed:!0})):[{path:e,isGlobbed:!1}]),Oi=e=>/^[+-]?\d+$/.test(e)&&BigInt.asIntN(64,BigInt(e))===BigInt(e),ki=e=>e?e[0]===`auto`?ae():Math.max(1,Number.parseInt(e[0],10)||1):1,Ai=e=>{let t=Object.entries(e);t.forEach(([e,r])=>console.log(`${t.length===1?``:`/\\ `}${e} = ${m(n(r))}`)),console.log(``)},ji=(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`}>`),Ai(e.state)})},Mi=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`,Ni=e=>{if(e.failure)console.log(`Error: ${e.failure.message}`),e.failure.initialState&&(console.log(`While working on the initial state:`),Ai(e.failure.initialState)),ji(e.failure.trace);else if(e.violation){let t=e.violation,n=t.name,r=t.loopStart,i=r===void 0&&t.trace.length===1&&(e.status===`invariant-violation`||e.status===`liveness-violation`),a={success:``,error:``,"assumption-violation":t.message?`Error: Evaluating assumption ${n} failed.\n${t.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":Mi(t.properties??[n]),"liveness-violation":r===void 0?i?`Error: Property ${n} is violated by the initial state:`:`Error: Action property ${n} is violated.`:Mi(t.properties??[n]),"postcondition-violation":`Error: ${t.message??`Postcondition ${n} is false.`}`}[e.status];if(t.counts&&console.log(t.counts),console.log(a),i)Ai(t.trace[0].state);else if(e.status===`property-violation`)ji(t.trace,`Error: The following behavior constitutes a counter-example:
|
|
28
|
+
`);else if(r===void 0)ji(t.trace);else{ji(t.trace,`Error: The following behavior constitutes a counter-example:
|
|
29
|
+
`);let e=r===t.trace.length-1;console.log(e?`State ${r+2}: Stuttering`:`Back to state ${r+1}${t.loopLabel?`: <${t.loopLabel}>\n`:``}`)}let o=t.unwitnessed;if(o?.counts&&console.log(o.counts),o&&console.log(`Error: ${o.message}`),i||e.status===`assumption-violation`)return}else{let t=f(e.distinctStates,e.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 = ${u(t)}`),e.fingerprintDistance!==void 0){let t=h(e.fingerprintDistance);console.log(` based on the actual fingerprints: val = ${u(t)}`)}}console.log(`${e.generatedStates} states generated, ${e.distinctStates} distinct states found, ${e.queuedStates} states left on queue.`),console.log(`The depth of the complete state graph search is ${e.depth}.`);let t=e.outDegrees&&d(e.outDegrees);t&&console.log(t)},Pi=async(n,r)=>{if(!y(n))return console.error(`Cannot find the specification file ${n}`),t.configParseError;let i=r.get(`-config`)?.[0]??(r.has(`-config`)?void 0:n.replace(/\.tla$/,`.cfg`));if(!i||!y(i))return console.error(`Cannot find the configuration file ${i??``}`),t.configParseError;let a=e(x(i,`utf8`));r.has(`-deadlock`)&&(a.checkDeadlock=!1);let o=r.has(`-seed`)?r.get(`-seed`)?.[0]:`0`;if(o===void 0)return console.error(`Error: seed required.`),1;if(!Oi(o))return console.error(`Error: An integer for seed required. But encountered ${o}`),1;let s=r.has(`-lncheck`)?r.get(`-lncheck`)?.[0]?.toLowerCase():`default`;if(s===void 0)return console.error(`Error: expect a strategy such as final for -lncheck option.`),1;let c=E(n);console.log(`Checking ${w(n)} with ${w(i)}`);let l=await v({workers:ki(r.get(`-workers`)),livenessCheck:[`final`,`seqfinal`,`off`].includes(s)?`final`:`default`,seed:BigInt(o),source:x(n,`utf8`),config:a,onPause:()=>S(0,Buffer.alloc(1)),loadModule:e=>{let t=re(c,`${e}.tla`);return y(t)?x(t,`utf8`):void 0},loadClass:e=>{let t=re(c,`${e}.class`);return y(t)?x(t):void 0},readFile:e=>y(e)?x(e,`utf8`):void 0,writeFile:(e,t)=>{b(E(ie(e)),{recursive:!0}),te(e,t)}});return Ni(l),l.failure?.exitCode??Si[l.status]},Fi=e=>{if(e instanceof o||e instanceof c)return console.log(`Error: ${e.message}`);console.error(`${e.name}: ${e.message}`)},Ii=async e=>{try{return await e()}catch(e){if(!(e instanceof s))throw e;return Fi(e),_(e)}},Li=async(e,n)=>{let r=[];for(let[t,i]of e.entries())t>0&&console.log(``),r.push(await Ii(()=>n(i)));return r.find(e=>e!==t.success)??t.success},Ri=()=>(process.env.PATH??``).split(T).map(e=>re(e,`tlapm`)).filter(e=>y(e)),zi=()=>Ri().map(e=>re(E(E(C(e))),`lib/tlapm/stdlib`)).find(e=>y(e)),Bi=e=>e.flatMap(e=>Ei.test(e)?ee(e).sort():[e]),Vi=e=>{let t=Ri()[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):ne(t,Bi(e),{stdio:`inherit`}).status??1},Hi=e=>y(e)?{file:e,source:x(e,`utf8`)}:void 0,Ui=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(`'`,`'\\''`)}'`,Gi=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`)},Ki={incomplete:11,emptyTarget:12},qi=(e,t,n)=>{let r=e.summary;n||(r.absent.forEach(e=>console.error(`Missing proof at ${le(e)}`)),r.omitted.forEach(e=>console.error(`Omitted proof at ${le(e)}`)));let i=r.absent.length+r.omitted.length>0;i&&console.error(`${ue(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(`${ue(e.location)}[ERROR]: No proof obligation found for the selected target.`),[...i?[Ki.incomplete]:[],...a?[Ki.emptyTarget]:[]]},Ji=e=>{try{return e()}catch(e){if(!(e instanceof r))throw e;console.error(` tlapm ending abnormally with ${e.exception}\n`);return}},Yi=e=>{if(!e.includes(`-N`)&&!e.includes(`--summary`))return Vi(e);let n=wi.parse(e),i=n.unknown[0];if(i!==void 0)return console.error(`Error: tla-ts prove does not support the tlapm option ${i}.`),1;if(n.incomplete)return console.error(`Error: option '${n.incomplete.name}' needs an argument.`),1;let a=n.options.find(e=>e.name!==`-I`&&e.values.some(e=>!/^-?\d+$/.test(e)));if(a)return console.error(`Error: option '${a.name}' expects an integer.`),1;let o=Bi(n.positionals),s=o.map(e=>e.endsWith(`.tla`)?e:`${e}.tla`);if(s.length===0)return console.error(Ti),1;let c=n.has(`--toolbox`)||n.has(`--line`);c&&Gi(e);let l=n.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?ci:{start:n,end:n}:e},ci),u=zi(),d=n.options.flatMap(e=>e.name===`-I`?e.values:[]),f=s.reduce((e,t)=>e.includes(E(t))?e:[E(t),...e],[`.`,...u?[u]:[],...d.toReversed()]),p=Ji(()=>{let e=s.findIndex(e=>!y(e));if(e!==-1){let t=o[e];throw console.error(`File "<unknown>":\nError: File ${JSON.stringify(t)} not found`),new r(`File ${t} not found`,{failure:`Module.Parser.parse_file`})}return xi(s.map(e=>({file:`./${e}`,source:x(e,`utf8`)})),e=>f.map(t=>Hi(`${t}/${e}.tla`)).find(Boolean),{lines:l,onWarning:e=>{if(e.channel===`stdout`)return console.log(e.text);let t=e.channel===`toolbox`||e.channel===`toolboxOnly`;if(c&&t)return Ui([`type:warning`,`msg:${e.text}`]);e.channel!==`toolboxOnly`&&console.error(e.text)}})});if(!p)return 3;let m=p.flatMap(e=>(n.has(`--summary`)&&console.log(bi(e)),c&&(e.obligations.forEach(e=>Ui([`type:obligation`,`id:${e.id}`,`loc:${e.location}`,`status:to be proved`,...n.has(`--printallobs`)?[`obl:${e.text}`]:[]])),Ui([`type:obligationsnumber`,`count:${e.obligations.length}`])),n.has(`--strict`)?qi(e,l.start>0||l.end<1/0,n.has(`--summary`)):[]));return m.includes(Ki.incomplete)?Ki.incomplete:m[0]??t.success},Xi=async e=>{if(e[0]===`prove`)return Ii(()=>Yi(e.slice(1)));let t=Ci.parse(e),n=Di(t.positionals),r=t.has(`-config`),i=n.map(e=>({...e,path:e.path.replace(/\.cfg$/,`.tla`)})).filter(e=>e.path.endsWith(`.tla`)&&(!e.isGlobbed||r||y(e.path.replace(/\.tla$/,`.cfg`)))).map(e=>e.path);return i.length===0?(console.error(Ti),1):r&&i.length>1?(console.error(`Error: -config applies to one specification, but several were given.`),1):Li([...new Set(i)],e=>Pi(e,t))},Zi=async()=>{process.exitCode=await Xi(process.argv.slice(2))};export{Zi as runCli};
|