tla-ts 0.0.10-dev.5ffc55ce5 → 0.0.10-dev.6232a1403

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/run.cjs 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
- const e=require("./worker.cjs"),t=require("./transfer.cjs"),n=require("./prove.cjs"),r=require("./tlapm.cjs");let i=require("node:path"),a=require("node:fs"),o=require("node:url"),s=require("node:child_process"),c=require("node:os"),l=require("node:v8");const u=`META-INF/MANIFEST.MF`,d=async e=>{if(e===void 0||!(0,a.existsSync)(e))return`master`;let t=await import(`fflate`),n=t.unzipSync((0,a.readFileSync)(e),{filter:e=>e.name===u})[u];return(n&&/^X-Git-Tag: *(\S*)/m.exec(t.strFromU8(n))?.[1])===`v1.7.4`?`1.7.4`:`master`},f=/[*?[{]/,p=e=>e.flatMap(e=>f.test(e)?(0,a.globSync)(e).sort().map(e=>({path:e,isGlobbed:!0})):[{path:e,isGlobbed:!1}]),m=(e,t)=>e.map(e=>(0,i.join)(e,`${t}.tla`)).find(a.existsSync),h=e=>t=>{let n=m(e,t);return n===void 0?void 0:(0,a.readFileSync)(n,`utf8`)},g=(e,t,n)=>console.error(`File does not exist: ${e}/${t} while looking in these directories: ${e}, ${n.join(`, `)}, classpath:/tla2sany/StandardModules, classpath:/`),_=e=>`jar:file:${(0,o.pathToFileURL)((0,i.resolve)(e)).pathname}!/tla2sany/StandardModules/`,v=t=>t instanceof e.V?e.it(t.code):e.Q(t),y=(n,r)=>{if(n instanceof e._||n instanceof e.b){let i=t.sn(n.message),a=n instanceof e.V?n.code:i&&!i.isEvalException?i.code:t.en.general;return r.print(a,t.tn.error,t.rn(a,n.message,r.isTool))}console.error(`${n.name}: ${n.message}`)},b=async(n,r=t.nn({isTool:!1}))=>{try{return await n()}catch(t){if(!(t instanceof e.y))throw t;return y(t,r),v(t)}},x=(e,t,n)=>console.error(`File does not exist: ${(0,i.isAbsolute)(e)?e:`${process.cwd()}/${e}`} while looking in these directories: ${[...t,...n===void 0?[]:[_(n)]].join(`, `)}`),S=e=>e.endsWith(`/`)?e:`${e}/`,C=(e,n)=>r=>{let i=e(r);return i===void 0&&!t.ct.has(r)&&n(`${r}.tla`),i},w=e=>e.classPath?.split(i.delimiter).find(e=>e.endsWith(`.jar`));var T=`0.0.10-dev.5ffc55ce5`;const E=2224400062,D={int8:0,int16:1,int32:2,shared8:4,shared16:5,shared32:6,block32:8,string8:9,string32:10,doubleLittle:12},O={smallInt:64,smallString:32,smallBlock:128},k=(e,...t)=>({tag:e,fields:t}),A=e=>typeof e==`object`&&`tag`in e,ee=(t,n)=>{let r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(t.length<n+20||r.getUint32(n)!==E)throw new e.A(`corrupted fingerprint file`);let i=n+20+r.getUint32(n+4),a=[],o=n+20,s=t=>{let n=o;if(o+=t,o>i)throw new e.A(`corrupted fingerprint file`);return n},c=new TextDecoder,l=e=>{let n=s(e),r=c.decode(t.subarray(n,n+e));return a.push(r),r},u=(e,t)=>{let n=k(e);t>0&&a.push(n);for(let e=0;e<t;e++)n.fields.push(f());return n},d=e=>a[a.length-e],f=()=>{let n=t[s(1)];if(n>=O.smallBlock)return u(n&15,n>>4&7);if(n>=O.smallInt)return n&63;if(n>=O.smallString)return l(n&31);switch(n){case D.int8:return r.getInt8(s(1));case D.int16:return r.getInt16(s(2));case D.int32:return r.getInt32(s(4));case D.shared8:return d(r.getUint8(s(1)));case D.shared16:return d(r.getUint16(s(2)));case D.shared32:return d(r.getUint32(s(4)));case D.block32:{let e=r.getUint32(s(4));return u(e&255,e>>>10)}case D.string8:return l(r.getUint8(s(1)));case D.string32:return l(r.getUint32(s(4)));case D.doubleLittle:{let e={float:r.getFloat64(s(8),!0)};return a.push(e),e}}throw new e.A(`corrupted fingerprint file`)};return{value:f(),next:i}},te=e=>{let t=[],n=0,r=0,i=0,a=(e,n)=>{for(let r=(n-1)*8;r>=0;r-=8)t.push(e>>>r&255)},o=new TextEncoder,s=e=>{if(typeof e==`number`)return e>=0&&e<64?t.push(O.smallInt+e):e>=-128&&e<128?t.push(D.int8,e&255):e>=-32768&&e<32768?(t.push(D.int16),a(e,2)):(t.push(D.int32),a(e,4));if(n++,typeof e==`string`){let n=o.encode(e);n.length<32?t.push(O.smallString+n.length):n.length<256?t.push(D.string8,n.length):(t.push(D.string32),a(n.length,4)),t.push(...n),r+=1+Math.floor((n.length+4)/4),i+=1+Math.floor((n.length+8)/8);return}if(!A(e)){let n=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));n.setFloat64(0,e.float,!0),t.push(D.doubleLittle,...new Uint8Array(n.buffer)),r+=3,i+=2;return}let c=e.fields.length;c===0?n--:(r+=1+c,i+=1+c),e.tag<16&&c<8?t.push(O.smallBlock+e.tag+(c<<4)):(t.push(D.block32),a(c*1024+e.tag,4)),e.fields.forEach(s)};s(e);let c=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(20));return[E,t.length,n,r,i].forEach((e,t)=>c.setUint32(t*4,e)),new Uint8Array([...new Uint8Array(c.buffer),...t])},ne=20210223,j=[...n.c,`cooper`,`expandenabled`,`expandcdot`,`lambdify`,`enabledaxioms`,`levelcomparison`],M={zenon:{field:1,tag:1},isabelle:{field:2,tag:0},cooper:{field:4,tag:3,isConstant:!0},smt:{field:10,tag:8},z3:{field:11,tag:9},ls4:{field:17,tag:16},expandenabled:{field:18,tag:6,isConstant:!0},expandcdot:{field:19,tag:8,isConstant:!0},lambdify:{field:20,tag:9,isConstant:!0},enabledaxioms:{field:21,tag:10,isConstant:!0},levelcomparison:{field:22,tag:11,isConstant:!0}},re=[`false`,`timeout`],ie=`tla-ts ${T}`,ae=/* @__PURE__ */ new Map([[M.zenon.field,3],[M.isabelle.field,4]]),N=(e,t)=>e!==void 0&&A(e)?e.fields[t]:void 0,oe=e=>e!==void 0&&typeof e==`object`&&`float`in e?e.float:1/0,P=e=>{let t=new TextEncoder().encode(e),n=(e,t)=>e<<t|e>>>32-t,r=Array.from({length:Math.ceil(t.length/4)},(e,n)=>t[n*4]|t[n*4+1]<<8|t[n*4+2]<<16|t[n*4+3]<<24).reduce((e,t)=>{let r=Math.imul(n(Math.imul(t,3432918353),15),461845907);return Math.imul(n(e^r,13),5)+3864292196|0},0),i=Math.imul(r^t.length^(r^t.length)>>>16,2246822507),a=Math.imul(i^i>>>13,3266489909);return(a^a>>>16)&1073741823},se=e=>e!==void 0&&A(e)?[[e.fields[0],e.fields[1]],...se(e.fields[2])]:[],F=(t,n,r)=>{let i=(0,a.readFileSync)(n),o=ee(i,0),s=ee(i,o.next).value;if(o.value!==ne||!A(s)||s.tag!==0)throw new e.A(`corrupted fingerprint file`);let c=N(N(s,0),1),l=(e,t)=>{let n=ae.get(t);return!r||n===void 0||N(N(e,0),n)===ie};t.clear(),(c!==void 0&&A(c)?c.fields:[]).flatMap(e=>se(e).toReversed()).forEach(([n,r])=>{if(typeof n!=`string`||!A(r))throw new e.A(`corrupted fingerprint file`);t.set(n,r.fields.map((e,t)=>l(e,t)?e:0))})},ce=(e,t)=>{let n=N(t,0),r=N(n,0),i=N(N(n,1),0);if(r===void 0||r===1)return;let a=oe(N(e===`isabelle`?N(i,0):i,0)),o=e===`isabelle`?N(i,1):void 0,s=N(N(r,0),0);return{kind:`stored`,method:{prover:e,timeLimitMs:a*1e3,...typeof o==`string`&&{tactic:o}},isProved:r===0,...s!==void 0&&{reason:typeof s==`number`?re[s]:String(N(s,0))}}},le=(e,t)=>{let r=/* @__PURE__ */ new Date,i=t.method,a={float:n.u(i)},o=e===`zenon`?k(0,a,5):e===`isabelle`?k(0,k(0,a),i.tactic??`auto`):k(0,a),s=n.i(t),c=re.indexOf(s??``),l=s===void 0?0:k(0,c===-1?k(0,s):c);return k(0,k(0,k(0,n.a(t)?0:k(0,l),M[e].isConstant?M[e].tag:k(M[e].tag,o)),k(0,r.getFullYear(),r.getMonth(),r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds()),ie,ie,ie))},ue=e=>{let t=2**Math.max(9,Math.ceil(Math.log2(e.size/2))),n=Array.from({length:t},()=>0);return e.forEach((e,r)=>{let i=P(r)&t-1;n[i]=k(0,r,k(0,...e),n[i])}),k(0,k(0,e.size,k(0,...n),0,512))},de=e=>String(e).padStart(2,`0`),fe=(e,t)=>{let n=/* @__PURE__ */ new Date,r=`${e}.history`,o=(0,i.join)(r,`${n.getFullYear()}-${de(n.getMonth()+1)}-${de(n.getDate())}_${de(n.getHours())}_${de(n.getMinutes())}_${de(n.getSeconds())}`);(0,a.mkdirSync)(o,{recursive:!0}),[e,...t].filter(e=>(0,a.existsSync)(e)).forEach(e=>(0,a.cpSync)(e,(0,i.join)(o,(0,i.basename)(e)),{preserveTimestamps:!0})),(0,a.readdirSync)(r).map(e=>(0,i.join)(r,e)).sort((e,t)=>(0,a.statSync)(t).mtimeMs-(0,a.statSync)(e).mtimeMs).slice(10).forEach(e=>(0,a.rmSync)(e,{recursive:!0,force:!0}))},pe=e=>{let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map,r=new Map([...e].map(([e,r])=>{let i=new Map(j.flatMap(e=>{let n=r[M[e].field],i=ce(e,N(n,0));return i?(t.set(i,n),[[e,i]]):[]}));return n.set(i,r),[e,i]}));return{results:r,save:i=>{e.clear(),r.forEach((r,i)=>{let a=[...n.get(r)??Array(23).fill(0)];j.forEach(e=>{let n=r.get(e);n&&(a[M[e].field]=t.get(n)??le(e,n))}),e.set(i,a)}),(0,a.writeFileSync)(`${i}.tmp`,Buffer.concat([te(ne),te(ue(e))])),(0,a.renameSync)(`${i}.tmp`,i)}}},me=((e,t)=>{let n=new Map(t.map(e=>{let[t,...n]=e.flag.split(` `);return[t,n.length]}));return{usage:e.replace(`{options}`,t.map(e=>`[${e.flag}]${e.isRepeatable?`...`:``}`).join(` `)),parse:e=>{let t=[],r=[],i=[];for(let a=0;a<e.length;a++){let o=n.get(e[a]);o===void 0?(e[a].startsWith(`-`)?i:r).push(e[a]):(t.push({name:e[a],values:e.slice(a+1,a+1+o)}),a+=o)}return{options:t,positionals:r,unknown:i,incomplete:t.find(e=>e.values.length<(n.get(e.name)??0)),has:e=>t.some(t=>t.name===e),get:e=>t.findLast(t=>t.name===e)?.values}}}})(`tla-ts tlapm {options} <Module.tla|glob>...`,[{flag:`-N`},{flag:`--summary`},{flag:`--strict`},{flag:`--toolbox <start> <end>`},{flag:`--line <num>`},{flag:`--printallobs`},{flag:`--threads <num>`},{flag:`--version`},{flag:`-I <directory>`,isRepeatable:!0},{flag:`-k`},{flag:`--noproving`},{flag:`--nofp`},{flag:`--nofpl <start> <end>`},{flag:`--safefp`},{flag:`--cleanfp`},{flag:`--usefp <file>`},{flag:`--cache-dir <directory>`},{flag:`--debug <flags>`,isRepeatable:!0},{flag:`--method <methods>`},{flag:`--solver <command>`},{flag:`--smt-logic <logic>`},{flag:`--stretch <factor>`},{flag:`--noflatten`}]),he=[`Usage: tla-ts <Spec.tla|Spec.cfg|spec.ts|glob>... [-config <Spec.cfg>] [-continue] [-deadlock] [-dump [<format>] <file>] [-fp <num>] [-lncheck <final|default|off>] [-maxSetSize <num>] [-metadir <directory>] [-nowarning] [-seed <num>] [-terse] [-tool] [-view] [-workers <count|auto>]`,` ${me.usage}`,` tla-ts [<JVM option>]... tlc2.TLC <TLC option>... <Spec>`,` (-cp tla2tools.jar or -Dtla-ts.tlc=1.7.4 picks the TLC to reproduce)`,` tla-ts [<JVM option>]... tla2sany.xml.XMLExporter [-I <directory>]... [-o] [-t] [-r] [-u] <Module.tla>`].join(`
9
+ const e=require("./worker.cjs"),t=require("./transfer.cjs"),n=require("./prove.cjs"),r=require("./tlapm.cjs");let i=require("node:path"),a=require("node:fs"),o=require("node:url"),s=require("node:child_process"),c=require("node:os"),l=require("node:v8");const u=`META-INF/MANIFEST.MF`,d=async e=>{if(e===void 0||!(0,a.existsSync)(e))return`master`;let t=await import(`fflate`),n=t.unzipSync((0,a.readFileSync)(e),{filter:e=>e.name===u})[u];return(n&&/^X-Git-Tag: *(\S*)/m.exec(t.strFromU8(n))?.[1])===`v1.7.4`?`1.7.4`:`master`},f=/[*?[{]/,p=e=>e.flatMap(e=>f.test(e)?(0,a.globSync)(e).sort().map(e=>({path:e,isGlobbed:!0})):[{path:e,isGlobbed:!1}]),m=(e,t)=>e.map(e=>(0,i.join)(e,`${t}.tla`)).find(a.existsSync),h=e=>t=>{let n=m(e,t);return n===void 0?void 0:(0,a.readFileSync)(n,`utf8`)},g=(e,t,n)=>console.error(`File does not exist: ${e}/${t} while looking in these directories: ${e}, ${n.join(`, `)}, classpath:/tla2sany/StandardModules, classpath:/`),_=e=>`jar:file:${(0,o.pathToFileURL)((0,i.resolve)(e)).pathname}!/tla2sany/StandardModules/`,v=t=>t instanceof e.V?e.it(t.code):e.Q(t),y=(n,r)=>{if(n instanceof e._||n instanceof e.b){let i=t.sn(n.message),a=n instanceof e.V?n.code:i&&!i.isEvalException?i.code:t.en.general;return r.print(a,t.tn.error,t.rn(a,n.message,r.isTool))}console.error(`${n.name}: ${n.message}`)},b=async(n,r=t.nn({isTool:!1}))=>{try{return await n()}catch(t){if(!(t instanceof e.y))throw t;return y(t,r),v(t)}},x=(e,t,n)=>console.error(`File does not exist: ${(0,i.isAbsolute)(e)?e:`${process.cwd()}/${e}`} while looking in these directories: ${[...t,...n===void 0?[]:[_(n)]].join(`, `)}`),S=e=>e.endsWith(`/`)?e:`${e}/`,C=(e,n)=>r=>{let i=e(r);return i===void 0&&!t.ct.has(r)&&n(`${r}.tla`),i},w=e=>e.classPath?.split(i.delimiter).find(e=>e.endsWith(`.jar`));var T=`0.0.10-dev.6232a1403`;const E=2224400062,D={int8:0,int16:1,int32:2,shared8:4,shared16:5,shared32:6,block32:8,string8:9,string32:10,doubleLittle:12},O={smallInt:64,smallString:32,smallBlock:128},k=(e,...t)=>({tag:e,fields:t}),A=e=>typeof e==`object`&&`tag`in e,ee=(t,n)=>{let r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(t.length<n+20||r.getUint32(n)!==E)throw new e.A(`corrupted fingerprint file`);let i=n+20+r.getUint32(n+4),a=[],o=n+20,s=t=>{let n=o;if(o+=t,o>i)throw new e.A(`corrupted fingerprint file`);return n},c=new TextDecoder,l=e=>{let n=s(e),r=c.decode(t.subarray(n,n+e));return a.push(r),r},u=(e,t)=>{let n=k(e);t>0&&a.push(n);for(let e=0;e<t;e++)n.fields.push(f());return n},d=e=>a[a.length-e],f=()=>{let n=t[s(1)];if(n>=O.smallBlock)return u(n&15,n>>4&7);if(n>=O.smallInt)return n&63;if(n>=O.smallString)return l(n&31);switch(n){case D.int8:return r.getInt8(s(1));case D.int16:return r.getInt16(s(2));case D.int32:return r.getInt32(s(4));case D.shared8:return d(r.getUint8(s(1)));case D.shared16:return d(r.getUint16(s(2)));case D.shared32:return d(r.getUint32(s(4)));case D.block32:{let e=r.getUint32(s(4));return u(e&255,e>>>10)}case D.string8:return l(r.getUint8(s(1)));case D.string32:return l(r.getUint32(s(4)));case D.doubleLittle:{let e={float:r.getFloat64(s(8),!0)};return a.push(e),e}}throw new e.A(`corrupted fingerprint file`)};return{value:f(),next:i}},te=e=>{let t=[],n=0,r=0,i=0,a=(e,n)=>{for(let r=(n-1)*8;r>=0;r-=8)t.push(e>>>r&255)},o=new TextEncoder,s=e=>{if(typeof e==`number`)return e>=0&&e<64?t.push(O.smallInt+e):e>=-128&&e<128?t.push(D.int8,e&255):e>=-32768&&e<32768?(t.push(D.int16),a(e,2)):(t.push(D.int32),a(e,4));if(n++,typeof e==`string`){let n=o.encode(e);n.length<32?t.push(O.smallString+n.length):n.length<256?t.push(D.string8,n.length):(t.push(D.string32),a(n.length,4)),t.push(...n),r+=1+Math.floor((n.length+4)/4),i+=1+Math.floor((n.length+8)/8);return}if(!A(e)){let n=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));n.setFloat64(0,e.float,!0),t.push(D.doubleLittle,...new Uint8Array(n.buffer)),r+=3,i+=2;return}let c=e.fields.length;c===0?n--:(r+=1+c,i+=1+c),e.tag<16&&c<8?t.push(O.smallBlock+e.tag+(c<<4)):(t.push(D.block32),a(c*1024+e.tag,4)),e.fields.forEach(s)};s(e);let c=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(20));return[E,t.length,n,r,i].forEach((e,t)=>c.setUint32(t*4,e)),new Uint8Array([...new Uint8Array(c.buffer),...t])},ne=20210223,j=[...n.c,`cooper`,`expandenabled`,`expandcdot`,`lambdify`,`enabledaxioms`,`levelcomparison`],M={zenon:{field:1,tag:1},isabelle:{field:2,tag:0},cooper:{field:4,tag:3,isConstant:!0},smt:{field:10,tag:8},z3:{field:11,tag:9},ls4:{field:17,tag:16},expandenabled:{field:18,tag:6,isConstant:!0},expandcdot:{field:19,tag:8,isConstant:!0},lambdify:{field:20,tag:9,isConstant:!0},enabledaxioms:{field:21,tag:10,isConstant:!0},levelcomparison:{field:22,tag:11,isConstant:!0}},re=[`false`,`timeout`],ie=`tla-ts ${T}`,ae=/* @__PURE__ */ new Map([[M.zenon.field,3],[M.isabelle.field,4]]),N=(e,t)=>e!==void 0&&A(e)?e.fields[t]:void 0,oe=e=>e!==void 0&&typeof e==`object`&&`float`in e?e.float:1/0,P=e=>{let t=new TextEncoder().encode(e),n=(e,t)=>e<<t|e>>>32-t,r=Array.from({length:Math.ceil(t.length/4)},(e,n)=>t[n*4]|t[n*4+1]<<8|t[n*4+2]<<16|t[n*4+3]<<24).reduce((e,t)=>{let r=Math.imul(n(Math.imul(t,3432918353),15),461845907);return Math.imul(n(e^r,13),5)+3864292196|0},0),i=Math.imul(r^t.length^(r^t.length)>>>16,2246822507),a=Math.imul(i^i>>>13,3266489909);return(a^a>>>16)&1073741823},se=e=>e!==void 0&&A(e)?[[e.fields[0],e.fields[1]],...se(e.fields[2])]:[],F=(t,n,r)=>{let i=(0,a.readFileSync)(n),o=ee(i,0),s=ee(i,o.next).value;if(o.value!==ne||!A(s)||s.tag!==0)throw new e.A(`corrupted fingerprint file`);let c=N(N(s,0),1),l=(e,t)=>{let n=ae.get(t);return!r||n===void 0||N(N(e,0),n)===ie};t.clear(),(c!==void 0&&A(c)?c.fields:[]).flatMap(e=>se(e).toReversed()).forEach(([n,r])=>{if(typeof n!=`string`||!A(r))throw new e.A(`corrupted fingerprint file`);t.set(n,r.fields.map((e,t)=>l(e,t)?e:0))})},ce=(e,t)=>{let n=N(t,0),r=N(n,0),i=N(N(n,1),0);if(r===void 0||r===1)return;let a=oe(N(e===`isabelle`?N(i,0):i,0)),o=e===`isabelle`?N(i,1):void 0,s=N(N(r,0),0);return{kind:`stored`,method:{prover:e,timeLimitMs:a*1e3,...typeof o==`string`&&{tactic:o}},isProved:r===0,...s!==void 0&&{reason:typeof s==`number`?re[s]:String(N(s,0))}}},le=(e,t)=>{let r=/* @__PURE__ */ new Date,i=t.method,a={float:n.u(i)},o=e===`zenon`?k(0,a,5):e===`isabelle`?k(0,k(0,a),i.tactic??`auto`):k(0,a),s=n.i(t),c=re.indexOf(s??``),l=s===void 0?0:k(0,c===-1?k(0,s):c);return k(0,k(0,k(0,n.a(t)?0:k(0,l),M[e].isConstant?M[e].tag:k(M[e].tag,o)),k(0,r.getFullYear(),r.getMonth(),r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds()),ie,ie,ie))},ue=e=>{let t=2**Math.max(9,Math.ceil(Math.log2(e.size/2))),n=Array.from({length:t},()=>0);return e.forEach((e,r)=>{let i=P(r)&t-1;n[i]=k(0,r,k(0,...e),n[i])}),k(0,k(0,e.size,k(0,...n),0,512))},de=e=>String(e).padStart(2,`0`),fe=(e,t)=>{let n=/* @__PURE__ */ new Date,r=`${e}.history`,o=(0,i.join)(r,`${n.getFullYear()}-${de(n.getMonth()+1)}-${de(n.getDate())}_${de(n.getHours())}_${de(n.getMinutes())}_${de(n.getSeconds())}`);(0,a.mkdirSync)(o,{recursive:!0}),[e,...t].filter(e=>(0,a.existsSync)(e)).forEach(e=>(0,a.cpSync)(e,(0,i.join)(o,(0,i.basename)(e)),{preserveTimestamps:!0})),(0,a.readdirSync)(r).map(e=>(0,i.join)(r,e)).sort((e,t)=>(0,a.statSync)(t).mtimeMs-(0,a.statSync)(e).mtimeMs).slice(10).forEach(e=>(0,a.rmSync)(e,{recursive:!0,force:!0}))},pe=e=>{let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map,r=new Map([...e].map(([e,r])=>{let i=new Map(j.flatMap(e=>{let n=r[M[e].field],i=ce(e,N(n,0));return i?(t.set(i,n),[[e,i]]):[]}));return n.set(i,r),[e,i]}));return{results:r,save:i=>{e.clear(),r.forEach((r,i)=>{let a=[...n.get(r)??Array(23).fill(0)];j.forEach(e=>{let n=r.get(e);n&&(a[M[e].field]=t.get(n)??le(e,n))}),e.set(i,a)}),(0,a.writeFileSync)(`${i}.tmp`,Buffer.concat([te(ne),te(ue(e))])),(0,a.renameSync)(`${i}.tmp`,i)}}},me=((e,t)=>{let n=new Map(t.map(e=>{let[t,...n]=e.flag.split(` `);return[t,n.length]}));return{usage:e.replace(`{options}`,t.map(e=>`[${e.flag}]${e.isRepeatable?`...`:``}`).join(` `)),parse:e=>{let t=[],r=[],i=[];for(let a=0;a<e.length;a++){let o=n.get(e[a]);o===void 0?(e[a].startsWith(`-`)?i:r).push(e[a]):(t.push({name:e[a],values:e.slice(a+1,a+1+o)}),a+=o)}return{options:t,positionals:r,unknown:i,incomplete:t.find(e=>e.values.length<(n.get(e.name)??0)),has:e=>t.some(t=>t.name===e),get:e=>t.findLast(t=>t.name===e)?.values}}}})(`tla-ts tlapm {options} <Module.tla|glob>...`,[{flag:`-N`},{flag:`--summary`},{flag:`--strict`},{flag:`--toolbox <start> <end>`},{flag:`--line <num>`},{flag:`--printallobs`},{flag:`--threads <num>`},{flag:`--version`},{flag:`-I <directory>`,isRepeatable:!0},{flag:`-k`},{flag:`--noproving`},{flag:`--nofp`},{flag:`--nofpl <start> <end>`},{flag:`--safefp`},{flag:`--cleanfp`},{flag:`--usefp <file>`},{flag:`--cache-dir <directory>`},{flag:`--debug <flags>`,isRepeatable:!0},{flag:`--method <methods>`},{flag:`--solver <command>`},{flag:`--smt-logic <logic>`},{flag:`--stretch <factor>`},{flag:`--noflatten`}]),he=[`Usage: tla-ts <Spec.tla|Spec.cfg|spec.ts|glob>... [-config <Spec.cfg>] [-continue] [-deadlock] [-dump [<format>] <file>] [-fp <num>] [-lncheck <final|default|off>] [-maxSetSize <num>] [-metadir <directory>] [-nowarning] [-seed <num>] [-terse] [-tool] [-view] [-workers <count|auto>]`,` ${me.usage}`,` tla-ts [<JVM option>]... tlc2.TLC <TLC option>... <Spec>`,` (-cp tla2tools.jar or -Dtla-ts.tlc=1.7.4 picks the TLC to reproduce)`,` tla-ts [<JVM option>]... tla2sany.xml.XMLExporter [-I <directory>]... [-o] [-t] [-r] [-u] <Module.tla>`].join(`
10
10
  `),ge={name:``,values:[],doc:` `},_e=[ge,{name:`(basic options)`,values:[],doc:` `},ge,{name:`--help`,values:[],doc:` show this help message and exit`},{name:`-help`,values:[],doc:` (same as --help)`},{name:`--version`,values:[],doc:` show version number and exit`},{name:`--verbose`,values:[],doc:` produce verbose messages`},{name:`-v`,values:[],doc:` (same as --verbose)`},ge,{name:`--where`,values:[],doc:` show location of standard library and exit`},{name:`--config`,values:[],doc:` show configuration and exit`},{name:`--summary`,values:[],doc:` show summary of theorems (implies -N and not -C)`},{name:`--strict`,values:[],doc:` report incomplete proofs, empty proof targets and failed obligations as errors and exit with a non-zero status`},{name:`--timing`,values:[],doc:` show runtime statistics`},ge,{name:`-I`,values:[`string`],doc:`<dir> add <dir> to search path`},{name:`-d`,values:[`string`],doc:``},ge,{name:`-k`,values:[],doc:` keep going on backend failures`},{name:`-N`,values:[],doc:` do not run any backend verifiers`},{name:`-C`,values:[],doc:` check proofs in Isabelle/TLA+`},ge,{name:`--threads`,values:[`int`],doc:`<int> set number of worker threads to <int>`},{name:`--method`,values:[`string`],doc:`<meth> set default method to <meth> (try --method help)`},{name:`--solver`,values:[`string`],doc:`<solver> set SMT solver to <solver>`},{name:`--smt-logic`,values:[`string`],doc:`<logic> set SMT logic to <logic>`},{name:`--stretch`,values:[`float`],doc:`<f> multiply all timeouts by <f>`},{name:`--fast-isabelle`,values:[],doc:``},ge,{name:`(advanced options)`,values:[],doc:` `},ge,{name:`--noflatten`,values:[],doc:` do not flatten obligations`},{name:`--nonormal`,values:[],doc:` do not normalize obligations before printing`},{name:`--debug`,values:[`string`],doc:`{[-]<flag>} enable/disable debugging flags`},{name:`--paranoid`,values:[],doc:``},{name:`--isaprove`,values:[],doc:``},ge,{name:`--toolbox`,values:[`int`,`int`],doc:`<int><int> toolbox mode`},{name:`--toolbox-vsn`,values:[`int`],doc:`<int> Toolbox protocol version, 1|2, 1 by default.`},{name:`--line`,values:[`int`],doc:`<int> line to prove`},{name:`--wait`,values:[`int`],doc:`<time> wait for <time> before printing obligations in progress`},{name:`--stdin`,values:[],doc:` read the tla file from stdin instead of file system. Only applies if single tla file is provided as input.`},{name:`--prefer-stdlib`,values:[],doc:` prefer built-in standard modules if the module search path contains files with the same names as modules in stdlib.`},{name:`--parser`,values:[`string`],doc:` Set parser backend to use: TLAPM (default) or SANY.`},{name:`--module-jar`,values:[`string`],doc:` Add a path to a .jar file containing additional TLA+ modules, such
11
11
  as the community modules. Multiple .jar files can be added by using
12
12
  this option multiple times.`},{name:`--noproving`,values:[],doc:` do not prove, report fingerprinted results only`},ge,{name:`--printallobs`,values:[],doc:` print obligations in all toolbox messages`},ge,{name:`--fpdir`,values:[`string`],doc:``},{name:`--safefp`,values:[],doc:` check tlapm, zenon, Isabelle versions for fingerprints`},{name:`--nofp`,values:[],doc:` do not use existing fingerprints, but overwrite any preexisting fingerprints associated with the current proof obligations, using the newly computed fingerprints and results`},{name:`--nofpl`,values:[`int`,`int`],doc:`<int><int> disable fingerprint use between given lines`},{name:`--cleanfp`,values:[],doc:` erase fingerprint file before starting`},ge,{name:`--erasefp`,values:[`string`,`string`],doc:`<f><back> erase from file <f> all results of backend <back>`},{name:`--printfp`,values:[`string`],doc:`<f> print the fingerprints stored in file <f> and quit`},{name:`--usefp`,values:[`string`],doc:`<f> load fingerprints from file <f> (save as usual)`},{name:`--fpp`,values:[],doc:` print the fingerprints of obligations in toolbox messages`},{name:`--cache-dir`,values:[`string`],doc:'<directory> save auxiliary and temporary files under <directory>. Alternatively, this directory can be defined via the variable `TLAPM_CACHE_DIR` of the runtime environment. The command-line parameter takes precedence over the environment variable. If neither is specified, the default value is ".tlacache".'}],ve=e=>/^[^ ]* */.exec(e)?.[0].length??0,ye=()=>{let e=Math.max(..._e.map(e=>e.name.length+ve(e.doc)));return`Usage: tla-ts tlapm <options> FILE ...\noptions are:\n${_e.filter(e=>e.doc!==``).map(t=>{let n=ve(t.doc);return` ${t.name} ${t.doc.slice(0,n)}${` `.repeat(e-t.name.length-n)}${t.doc.slice(n)}\n`}).join(``)}`},be=t=>{for(let r=0;r<t.length;r++){let i=t[r];if(i===`--version`)return;if(!i.startsWith(`-`))continue;let a=_e.find(e=>e.name===i);if(!a)return`unknown option '${i}'`;for(let e of a.values){if(r++,r===t.length)return`option '${i}' needs an argument`;let a=t[r];if(e===`int`&&n.p(a)===void 0)return`wrong argument '${a}'; option '${i}' expects an integer`;if(e===`float`&&n.f(a)===void 0)return`wrong argument '${a}'; option '${i}' expects a float`}let o=t[r];if(i===`--threads`&&(n.p(o)??0)<0)return`--threads requires a positive argument`;if(i===`--debug`&&o.split(`,`).includes(`oldsmt`))return`--debug oldsmt: the old SMT encoding has been removed`;if(i===`--method`)try{n.d(o)}catch(t){if(!(t instanceof e.j))throw t;return t.message}}},xe=e=>[`.`,...r.t().map(e=>(0,i.join)((0,i.dirname)((0,i.dirname)((0,a.realpathSync)(e))),`lib/tlapm/stdlib`)).filter(a.existsSync).slice(0,1),...e.options.flatMap(e=>e.name===`-I`?e.values:[]).toReversed()],Se=e=>console.error(`@!!BEGIN\n${e.map(e=>`@!!${e}\n`).join(``)}@!!END\n`),Ce=(e,t,n)=>Se([`type:obligation`,`id:${e.id}`,`loc:${e.location}`,`status:${t}`,...n]),we=e=>/^[+,\-./0-9:=@A-Z_a-z]+$/.test(e)?e:`'${e.replaceAll(`'`,`'\\''`)}'`,Te={failed:10,incomplete:11,emptyTarget:12},Ee=(e,t,r)=>{let i=e.summary;r||(i.absent.forEach(e=>console.error(`Missing proof at ${n.x(e)}`)),i.omitted.forEach(e=>console.error(`Omitted proof at ${n.x(e)}`)));let a=i.absent.length+i.omitted.length>0;a&&console.error(`${n.b(e.location)}[ERROR]: Proof incomplete in module ${JSON.stringify(e.name)}: ${i.absent.length} missing, ${i.omitted.length} omitted proof step(s).`);let o=t&&e.obligations.length===0;return o&&console.error(`${n.b(e.location)}[ERROR]: No proof obligation found for the selected target.`),[...a?[Te.incomplete]:[],...o?[Te.emptyTarget]:[]]},De=(e,t,n)=>{console.error(` tlapm ending abnormally with ${e.exception}\n`),n&&Se(t.message===``?[`type:error`,`url:http://tla.msr-inria.inria.fr/bugs`,`msg:Oops, this seems to be a bug in TLAPM.\nPlease give feedback to developers.\n\n\n ${e.exception}\n`]:[`type:warning`,`msg:${t.location===void 0?``:`${t.location}\n\n`}${t.message}`])},Oe=t=>{if(!(t instanceof e.A))throw t;return{kind:`aborted`,error:t}},ke=e=>{try{return{kind:`done`,value:e()}}catch(e){return Oe(e)}},Ae=(e,t,r)=>{let i=t.method.timeLimitMs,a=t.kind===`decided`?`; time-used: ${(t.timeUsedMs/1e3).toFixed(1)} (${Math.round(100*t.timeUsedMs/i)}%)`:``,o=i===0?``:`time-limit: ${i===1/0?`inf`:Number((i/1e3).toPrecision(6))}${a}`,s=[t.method.tactic,o].filter(Boolean).join(`; `),c=n.i(t),l=n.a(t),u=t.kind===`reused`,d=t.kind===`decided`?t.note:t.kind===`refused`?`${t.reason}\nObligation:\n\n`:t.kind===`unavailable`?`\n\\* ${t.warning}\n`:void 0,f=t.kind===`unavailable`||u?t.shipped:void 0;Ce(e,l?`proved`:`failed`,[`prover:${t.method.prover}`,...s===``?[]:[`meth:${s}`],...c===void 0?[]:[`reason:${c}`],`already:${u}`,...l?[]:[`obl:${u?``:d??`
package/dist/run.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{t as e}from"./tlapm.js";import{$ as t,A as n,B as r,C as i,D as a,F as o,G as s,I as c,L as l,M as u,O as d,P as f,Q as p,T as m,V as h,W as g,_,at as v,b as y,c as b,g as x,it as S,j as C,k as w,nt as T,o as E,ot as ee,s as D,tt as O,x as k,y as A}from"./worker.js";import{$ as te,At as ne,E as re,Ft as ie,G as ae,K as oe,M as se,O as ce,Pt as le,Q as ue,S as de,Vt as j,Zt as fe,_n as pe,an as me,b as he,bn as ge,cn as _e,ct as ve,dn as ye,dt as be,en as M,fn as xe,gn as Se,h as Ce,hn as we,ht as Te,i as Ee,in as De,kt as Oe,lt as ke,m as Ae,mn as je,mt as Me,nn as N,o as Ne,on as P,ot as Pe,p as Fe,pn as Ie,pt as Le,qt as Re,r as ze,rn as Be,s as Ve,sn as He,tn as F,tt as Ue,un as We,ut as Ge,vn as Ke,vt as qe,w as Je,x as Ye,yn as Xe}from"./transfer.js";import{S as Ze,_ as Qe,a as $e,b as et,c as tt,d as nt,f as rt,g as it,h as at,i as ot,l as st,m as ct,n as lt,p as ut,r as dt,s as ft,t as pt,u as mt,v as ht,x as gt,y as _t}from"./prove.js";import{basename as vt,delimiter as yt,dirname as bt,isAbsolute as xt,join as St,resolve as Ct}from"node:path";import{appendFileSync as wt,closeSync as Tt,cpSync as Et,existsSync as I,globSync as Dt,mkdirSync as Ot,openSync as kt,readFileSync as At,readSync as jt,readdirSync as Mt,realpathSync as Nt,renameSync as Pt,rmSync as Ft,statSync as It,writeFileSync as Lt}from"node:fs";import{pathToFileURL as Rt}from"node:url";import{spawnSync as zt}from"node:child_process";import{arch as Bt,availableParallelism as Vt,release as Ht,tmpdir as Ut,type as Wt}from"node:os";import{getHeapStatistics as Gt}from"node:v8";const Kt=`META-INF/MANIFEST.MF`,qt=async e=>{if(e===void 0||!I(e))return`master`;let t=await import(`fflate`),n=t.unzipSync(At(e),{filter:e=>e.name===Kt})[Kt];return(n&&/^X-Git-Tag: *(\S*)/m.exec(t.strFromU8(n))?.[1])===`v1.7.4`?`1.7.4`:`master`},Jt=/[*?[{]/,Yt=e=>e.flatMap(e=>Jt.test(e)?Dt(e).sort().map(e=>({path:e,isGlobbed:!0})):[{path:e,isGlobbed:!1}]),Xt=(e,t)=>e.map(e=>St(e,`${t}.tla`)).find(I),Zt=e=>t=>{let n=Xt(e,t);return n===void 0?void 0:At(n,`utf8`)},Qt=(e,t,n)=>console.error(`File does not exist: ${e}/${t} while looking in these directories: ${e}, ${n.join(`, `)}, classpath:/tla2sany/StandardModules, classpath:/`),$t=e=>`jar:file:${Rt(Ct(e)).pathname}!/tla2sany/StandardModules/`,en=e=>e instanceof h?S(e.code):p(e),tn=(e,t)=>{if(e instanceof _||e instanceof y){let n=He(e.message),r=e instanceof h?e.code:n&&!n.isEvalException?n.code:M.general;return t.print(r,F.error,Be(r,e.message,t.isTool))}console.error(`${e.name}: ${e.message}`)},nn=async(e,t=N({isTool:!1}))=>{try{return await e()}catch(e){if(!(e instanceof A))throw e;return tn(e,t),en(e)}},rn=(e,t,n)=>console.error(`File does not exist: ${xt(e)?e:`${process.cwd()}/${e}`} while looking in these directories: ${[...t,...n===void 0?[]:[$t(n)]].join(`, `)}`),an=e=>e.endsWith(`/`)?e:`${e}/`,on=(e,t)=>n=>{let r=e(n);return r===void 0&&!ve.has(n)&&t(`${n}.tla`),r},sn=e=>e.classPath?.split(yt).find(e=>e.endsWith(`.jar`));var cn=`0.0.10-dev.5ffc55ce5`;const ln=2224400062,un={int8:0,int16:1,int32:2,shared8:4,shared16:5,shared32:6,block32:8,string8:9,string32:10,doubleLittle:12},dn={smallInt:64,smallString:32,smallBlock:128},L=(e,...t)=>({tag:e,fields:t}),fn=e=>typeof e==`object`&&`tag`in e,pn=(e,t)=>{let r=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.length<t+20||r.getUint32(t)!==ln)throw new n(`corrupted fingerprint file`);let i=t+20+r.getUint32(t+4),a=[],o=t+20,s=e=>{let t=o;if(o+=e,o>i)throw new n(`corrupted fingerprint file`);return t},c=new TextDecoder,l=t=>{let n=s(t),r=c.decode(e.subarray(n,n+t));return a.push(r),r},u=(e,t)=>{let n=L(e);t>0&&a.push(n);for(let e=0;e<t;e++)n.fields.push(f());return n},d=e=>a[a.length-e],f=()=>{let t=e[s(1)];if(t>=dn.smallBlock)return u(t&15,t>>4&7);if(t>=dn.smallInt)return t&63;if(t>=dn.smallString)return l(t&31);switch(t){case un.int8:return r.getInt8(s(1));case un.int16:return r.getInt16(s(2));case un.int32:return r.getInt32(s(4));case un.shared8:return d(r.getUint8(s(1)));case un.shared16:return d(r.getUint16(s(2)));case un.shared32:return d(r.getUint32(s(4)));case un.block32:{let e=r.getUint32(s(4));return u(e&255,e>>>10)}case un.string8:return l(r.getUint8(s(1)));case un.string32:return l(r.getUint32(s(4)));case un.doubleLittle:{let e={float:r.getFloat64(s(8),!0)};return a.push(e),e}}throw new n(`corrupted fingerprint file`)};return{value:f(),next:i}},mn=e=>{let t=[],n=0,r=0,i=0,a=(e,n)=>{for(let r=(n-1)*8;r>=0;r-=8)t.push(e>>>r&255)},o=new TextEncoder,s=e=>{if(typeof e==`number`)return e>=0&&e<64?t.push(dn.smallInt+e):e>=-128&&e<128?t.push(un.int8,e&255):e>=-32768&&e<32768?(t.push(un.int16),a(e,2)):(t.push(un.int32),a(e,4));if(n++,typeof e==`string`){let n=o.encode(e);n.length<32?t.push(dn.smallString+n.length):n.length<256?t.push(un.string8,n.length):(t.push(un.string32),a(n.length,4)),t.push(...n),r+=1+Math.floor((n.length+4)/4),i+=1+Math.floor((n.length+8)/8);return}if(!fn(e)){let n=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));n.setFloat64(0,e.float,!0),t.push(un.doubleLittle,...new Uint8Array(n.buffer)),r+=3,i+=2;return}let c=e.fields.length;c===0?n--:(r+=1+c,i+=1+c),e.tag<16&&c<8?t.push(dn.smallBlock+e.tag+(c<<4)):(t.push(un.block32),a(c*1024+e.tag,4)),e.fields.forEach(s)};s(e);let c=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(20));return[ln,t.length,n,r,i].forEach((e,t)=>c.setUint32(t*4,e)),new Uint8Array([...new Uint8Array(c.buffer),...t])},hn=20210223,gn=[...tt,`cooper`,`expandenabled`,`expandcdot`,`lambdify`,`enabledaxioms`,`levelcomparison`],_n={zenon:{field:1,tag:1},isabelle:{field:2,tag:0},cooper:{field:4,tag:3,isConstant:!0},smt:{field:10,tag:8},z3:{field:11,tag:9},ls4:{field:17,tag:16},expandenabled:{field:18,tag:6,isConstant:!0},expandcdot:{field:19,tag:8,isConstant:!0},lambdify:{field:20,tag:9,isConstant:!0},enabledaxioms:{field:21,tag:10,isConstant:!0},levelcomparison:{field:22,tag:11,isConstant:!0}},vn=[`false`,`timeout`],yn=`tla-ts ${cn}`,bn=/* @__PURE__ */ new Map([[_n.zenon.field,3],[_n.isabelle.field,4]]),xn=(e,t)=>e!==void 0&&fn(e)?e.fields[t]:void 0,Sn=e=>e!==void 0&&typeof e==`object`&&`float`in e?e.float:1/0,Cn=e=>{let t=new TextEncoder().encode(e),n=(e,t)=>e<<t|e>>>32-t,r=Array.from({length:Math.ceil(t.length/4)},(e,n)=>t[n*4]|t[n*4+1]<<8|t[n*4+2]<<16|t[n*4+3]<<24).reduce((e,t)=>{let r=Math.imul(n(Math.imul(t,3432918353),15),461845907);return Math.imul(n(e^r,13),5)+3864292196|0},0),i=Math.imul(r^t.length^(r^t.length)>>>16,2246822507),a=Math.imul(i^i>>>13,3266489909);return(a^a>>>16)&1073741823},wn=e=>e!==void 0&&fn(e)?[[e.fields[0],e.fields[1]],...wn(e.fields[2])]:[],Tn=(e,t,r)=>{let i=At(t),a=pn(i,0),o=pn(i,a.next).value;if(a.value!==hn||!fn(o)||o.tag!==0)throw new n(`corrupted fingerprint file`);let s=xn(xn(o,0),1),c=(e,t)=>{let n=bn.get(t);return!r||n===void 0||xn(xn(e,0),n)===yn};e.clear(),(s!==void 0&&fn(s)?s.fields:[]).flatMap(e=>wn(e).toReversed()).forEach(([t,r])=>{if(typeof t!=`string`||!fn(r))throw new n(`corrupted fingerprint file`);e.set(t,r.fields.map((e,t)=>c(e,t)?e:0))})},En=(e,t)=>{let n=xn(t,0),r=xn(n,0),i=xn(xn(n,1),0);if(r===void 0||r===1)return;let a=Sn(xn(e===`isabelle`?xn(i,0):i,0)),o=e===`isabelle`?xn(i,1):void 0,s=xn(xn(r,0),0);return{kind:`stored`,method:{prover:e,timeLimitMs:a*1e3,...typeof o==`string`&&{tactic:o}},isProved:r===0,...s!==void 0&&{reason:typeof s==`number`?vn[s]:String(xn(s,0))}}},Dn=(e,t)=>{let n=/* @__PURE__ */ new Date,r=t.method,i={float:mt(r)},a=e===`zenon`?L(0,i,5):e===`isabelle`?L(0,L(0,i),r.tactic??`auto`):L(0,i),o=ot(t),s=vn.indexOf(o??``),c=o===void 0?0:L(0,s===-1?L(0,o):s);return L(0,L(0,L(0,$e(t)?0:L(0,c),_n[e].isConstant?_n[e].tag:L(_n[e].tag,a)),L(0,n.getFullYear(),n.getMonth(),n.getDate(),n.getHours(),n.getMinutes(),n.getSeconds()),yn,yn,yn))},On=e=>{let t=2**Math.max(9,Math.ceil(Math.log2(e.size/2))),n=Array.from({length:t},()=>0);return e.forEach((e,r)=>{let i=Cn(r)&t-1;n[i]=L(0,r,L(0,...e),n[i])}),L(0,L(0,e.size,L(0,...n),0,512))},kn=e=>String(e).padStart(2,`0`),An=(e,t)=>{let n=/* @__PURE__ */ new Date,r=`${e}.history`,i=St(r,`${n.getFullYear()}-${kn(n.getMonth()+1)}-${kn(n.getDate())}_${kn(n.getHours())}_${kn(n.getMinutes())}_${kn(n.getSeconds())}`);Ot(i,{recursive:!0}),[e,...t].filter(e=>I(e)).forEach(e=>Et(e,St(i,vt(e)),{preserveTimestamps:!0})),Mt(r).map(e=>St(r,e)).sort((e,t)=>It(t).mtimeMs-It(e).mtimeMs).slice(10).forEach(e=>Ft(e,{recursive:!0,force:!0}))},jn=e=>{let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map,r=new Map([...e].map(([e,r])=>{let i=new Map(gn.flatMap(e=>{let n=r[_n[e].field],i=En(e,xn(n,0));return i?(t.set(i,n),[[e,i]]):[]}));return n.set(i,r),[e,i]}));return{results:r,save:i=>{e.clear(),r.forEach((r,i)=>{let a=[...n.get(r)??Array(23).fill(0)];gn.forEach(e=>{let n=r.get(e);n&&(a[_n[e].field]=t.get(n)??Dn(e,n))}),e.set(i,a)}),Lt(`${i}.tmp`,Buffer.concat([mn(hn),mn(On(e))])),Pt(`${i}.tmp`,i)}}},Mn=((e,t)=>{let n=new Map(t.map(e=>{let[t,...n]=e.flag.split(` `);return[t,n.length]}));return{usage:e.replace(`{options}`,t.map(e=>`[${e.flag}]${e.isRepeatable?`...`:``}`).join(` `)),parse:e=>{let t=[],r=[],i=[];for(let a=0;a<e.length;a++){let o=n.get(e[a]);o===void 0?(e[a].startsWith(`-`)?i:r).push(e[a]):(t.push({name:e[a],values:e.slice(a+1,a+1+o)}),a+=o)}return{options:t,positionals:r,unknown:i,incomplete:t.find(e=>e.values.length<(n.get(e.name)??0)),has:e=>t.some(t=>t.name===e),get:e=>t.findLast(t=>t.name===e)?.values}}}})(`tla-ts tlapm {options} <Module.tla|glob>...`,[{flag:`-N`},{flag:`--summary`},{flag:`--strict`},{flag:`--toolbox <start> <end>`},{flag:`--line <num>`},{flag:`--printallobs`},{flag:`--threads <num>`},{flag:`--version`},{flag:`-I <directory>`,isRepeatable:!0},{flag:`-k`},{flag:`--noproving`},{flag:`--nofp`},{flag:`--nofpl <start> <end>`},{flag:`--safefp`},{flag:`--cleanfp`},{flag:`--usefp <file>`},{flag:`--cache-dir <directory>`},{flag:`--debug <flags>`,isRepeatable:!0},{flag:`--method <methods>`},{flag:`--solver <command>`},{flag:`--smt-logic <logic>`},{flag:`--stretch <factor>`},{flag:`--noflatten`}]),Nn=[`Usage: tla-ts <Spec.tla|Spec.cfg|spec.ts|glob>... [-config <Spec.cfg>] [-continue] [-deadlock] [-dump [<format>] <file>] [-fp <num>] [-lncheck <final|default|off>] [-maxSetSize <num>] [-metadir <directory>] [-nowarning] [-seed <num>] [-terse] [-tool] [-view] [-workers <count|auto>]`,` ${Mn.usage}`,` tla-ts [<JVM option>]... tlc2.TLC <TLC option>... <Spec>`,` (-cp tla2tools.jar or -Dtla-ts.tlc=1.7.4 picks the TLC to reproduce)`,` tla-ts [<JVM option>]... tla2sany.xml.XMLExporter [-I <directory>]... [-o] [-t] [-r] [-u] <Module.tla>`].join(`
9
+ import{t as e}from"./tlapm.js";import{$ as t,A as n,B as r,C as i,D as a,F as o,G as s,I as c,L as l,M as u,O as d,P as f,Q as p,T as m,V as h,W as g,_,at as v,b as y,c as b,g as x,it as S,j as C,k as w,nt as T,o as E,ot as ee,s as D,tt as O,x as k,y as A}from"./worker.js";import{$ as te,At as ne,E as re,Ft as ie,G as ae,K as oe,M as se,O as ce,Pt as le,Q as ue,S as de,Vt as j,Zt as fe,_n as pe,an as me,b as he,bn as ge,cn as _e,ct as ve,dn as ye,dt as be,en as M,fn as xe,gn as Se,h as Ce,hn as we,ht as Te,i as Ee,in as De,kt as Oe,lt as ke,m as Ae,mn as je,mt as Me,nn as N,o as Ne,on as P,ot as Pe,p as Fe,pn as Ie,pt as Le,qt as Re,r as ze,rn as Be,s as Ve,sn as He,tn as F,tt as Ue,un as We,ut as Ge,vn as Ke,vt as qe,w as Je,x as Ye,yn as Xe}from"./transfer.js";import{S as Ze,_ as Qe,a as $e,b as et,c as tt,d as nt,f as rt,g as it,h as at,i as ot,l as st,m as ct,n as lt,p as ut,r as dt,s as ft,t as pt,u as mt,v as ht,x as gt,y as _t}from"./prove.js";import{basename as vt,delimiter as yt,dirname as bt,isAbsolute as xt,join as St,resolve as Ct}from"node:path";import{appendFileSync as wt,closeSync as Tt,cpSync as Et,existsSync as I,globSync as Dt,mkdirSync as Ot,openSync as kt,readFileSync as At,readSync as jt,readdirSync as Mt,realpathSync as Nt,renameSync as Pt,rmSync as Ft,statSync as It,writeFileSync as Lt}from"node:fs";import{pathToFileURL as Rt}from"node:url";import{spawnSync as zt}from"node:child_process";import{arch as Bt,availableParallelism as Vt,release as Ht,tmpdir as Ut,type as Wt}from"node:os";import{getHeapStatistics as Gt}from"node:v8";const Kt=`META-INF/MANIFEST.MF`,qt=async e=>{if(e===void 0||!I(e))return`master`;let t=await import(`fflate`),n=t.unzipSync(At(e),{filter:e=>e.name===Kt})[Kt];return(n&&/^X-Git-Tag: *(\S*)/m.exec(t.strFromU8(n))?.[1])===`v1.7.4`?`1.7.4`:`master`},Jt=/[*?[{]/,Yt=e=>e.flatMap(e=>Jt.test(e)?Dt(e).sort().map(e=>({path:e,isGlobbed:!0})):[{path:e,isGlobbed:!1}]),Xt=(e,t)=>e.map(e=>St(e,`${t}.tla`)).find(I),Zt=e=>t=>{let n=Xt(e,t);return n===void 0?void 0:At(n,`utf8`)},Qt=(e,t,n)=>console.error(`File does not exist: ${e}/${t} while looking in these directories: ${e}, ${n.join(`, `)}, classpath:/tla2sany/StandardModules, classpath:/`),$t=e=>`jar:file:${Rt(Ct(e)).pathname}!/tla2sany/StandardModules/`,en=e=>e instanceof h?S(e.code):p(e),tn=(e,t)=>{if(e instanceof _||e instanceof y){let n=He(e.message),r=e instanceof h?e.code:n&&!n.isEvalException?n.code:M.general;return t.print(r,F.error,Be(r,e.message,t.isTool))}console.error(`${e.name}: ${e.message}`)},nn=async(e,t=N({isTool:!1}))=>{try{return await e()}catch(e){if(!(e instanceof A))throw e;return tn(e,t),en(e)}},rn=(e,t,n)=>console.error(`File does not exist: ${xt(e)?e:`${process.cwd()}/${e}`} while looking in these directories: ${[...t,...n===void 0?[]:[$t(n)]].join(`, `)}`),an=e=>e.endsWith(`/`)?e:`${e}/`,on=(e,t)=>n=>{let r=e(n);return r===void 0&&!ve.has(n)&&t(`${n}.tla`),r},sn=e=>e.classPath?.split(yt).find(e=>e.endsWith(`.jar`));var cn=`0.0.10-dev.6232a1403`;const ln=2224400062,un={int8:0,int16:1,int32:2,shared8:4,shared16:5,shared32:6,block32:8,string8:9,string32:10,doubleLittle:12},dn={smallInt:64,smallString:32,smallBlock:128},L=(e,...t)=>({tag:e,fields:t}),fn=e=>typeof e==`object`&&`tag`in e,pn=(e,t)=>{let r=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.length<t+20||r.getUint32(t)!==ln)throw new n(`corrupted fingerprint file`);let i=t+20+r.getUint32(t+4),a=[],o=t+20,s=e=>{let t=o;if(o+=e,o>i)throw new n(`corrupted fingerprint file`);return t},c=new TextDecoder,l=t=>{let n=s(t),r=c.decode(e.subarray(n,n+t));return a.push(r),r},u=(e,t)=>{let n=L(e);t>0&&a.push(n);for(let e=0;e<t;e++)n.fields.push(f());return n},d=e=>a[a.length-e],f=()=>{let t=e[s(1)];if(t>=dn.smallBlock)return u(t&15,t>>4&7);if(t>=dn.smallInt)return t&63;if(t>=dn.smallString)return l(t&31);switch(t){case un.int8:return r.getInt8(s(1));case un.int16:return r.getInt16(s(2));case un.int32:return r.getInt32(s(4));case un.shared8:return d(r.getUint8(s(1)));case un.shared16:return d(r.getUint16(s(2)));case un.shared32:return d(r.getUint32(s(4)));case un.block32:{let e=r.getUint32(s(4));return u(e&255,e>>>10)}case un.string8:return l(r.getUint8(s(1)));case un.string32:return l(r.getUint32(s(4)));case un.doubleLittle:{let e={float:r.getFloat64(s(8),!0)};return a.push(e),e}}throw new n(`corrupted fingerprint file`)};return{value:f(),next:i}},mn=e=>{let t=[],n=0,r=0,i=0,a=(e,n)=>{for(let r=(n-1)*8;r>=0;r-=8)t.push(e>>>r&255)},o=new TextEncoder,s=e=>{if(typeof e==`number`)return e>=0&&e<64?t.push(dn.smallInt+e):e>=-128&&e<128?t.push(un.int8,e&255):e>=-32768&&e<32768?(t.push(un.int16),a(e,2)):(t.push(un.int32),a(e,4));if(n++,typeof e==`string`){let n=o.encode(e);n.length<32?t.push(dn.smallString+n.length):n.length<256?t.push(un.string8,n.length):(t.push(un.string32),a(n.length,4)),t.push(...n),r+=1+Math.floor((n.length+4)/4),i+=1+Math.floor((n.length+8)/8);return}if(!fn(e)){let n=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));n.setFloat64(0,e.float,!0),t.push(un.doubleLittle,...new Uint8Array(n.buffer)),r+=3,i+=2;return}let c=e.fields.length;c===0?n--:(r+=1+c,i+=1+c),e.tag<16&&c<8?t.push(dn.smallBlock+e.tag+(c<<4)):(t.push(un.block32),a(c*1024+e.tag,4)),e.fields.forEach(s)};s(e);let c=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(20));return[ln,t.length,n,r,i].forEach((e,t)=>c.setUint32(t*4,e)),new Uint8Array([...new Uint8Array(c.buffer),...t])},hn=20210223,gn=[...tt,`cooper`,`expandenabled`,`expandcdot`,`lambdify`,`enabledaxioms`,`levelcomparison`],_n={zenon:{field:1,tag:1},isabelle:{field:2,tag:0},cooper:{field:4,tag:3,isConstant:!0},smt:{field:10,tag:8},z3:{field:11,tag:9},ls4:{field:17,tag:16},expandenabled:{field:18,tag:6,isConstant:!0},expandcdot:{field:19,tag:8,isConstant:!0},lambdify:{field:20,tag:9,isConstant:!0},enabledaxioms:{field:21,tag:10,isConstant:!0},levelcomparison:{field:22,tag:11,isConstant:!0}},vn=[`false`,`timeout`],yn=`tla-ts ${cn}`,bn=/* @__PURE__ */ new Map([[_n.zenon.field,3],[_n.isabelle.field,4]]),xn=(e,t)=>e!==void 0&&fn(e)?e.fields[t]:void 0,Sn=e=>e!==void 0&&typeof e==`object`&&`float`in e?e.float:1/0,Cn=e=>{let t=new TextEncoder().encode(e),n=(e,t)=>e<<t|e>>>32-t,r=Array.from({length:Math.ceil(t.length/4)},(e,n)=>t[n*4]|t[n*4+1]<<8|t[n*4+2]<<16|t[n*4+3]<<24).reduce((e,t)=>{let r=Math.imul(n(Math.imul(t,3432918353),15),461845907);return Math.imul(n(e^r,13),5)+3864292196|0},0),i=Math.imul(r^t.length^(r^t.length)>>>16,2246822507),a=Math.imul(i^i>>>13,3266489909);return(a^a>>>16)&1073741823},wn=e=>e!==void 0&&fn(e)?[[e.fields[0],e.fields[1]],...wn(e.fields[2])]:[],Tn=(e,t,r)=>{let i=At(t),a=pn(i,0),o=pn(i,a.next).value;if(a.value!==hn||!fn(o)||o.tag!==0)throw new n(`corrupted fingerprint file`);let s=xn(xn(o,0),1),c=(e,t)=>{let n=bn.get(t);return!r||n===void 0||xn(xn(e,0),n)===yn};e.clear(),(s!==void 0&&fn(s)?s.fields:[]).flatMap(e=>wn(e).toReversed()).forEach(([t,r])=>{if(typeof t!=`string`||!fn(r))throw new n(`corrupted fingerprint file`);e.set(t,r.fields.map((e,t)=>c(e,t)?e:0))})},En=(e,t)=>{let n=xn(t,0),r=xn(n,0),i=xn(xn(n,1),0);if(r===void 0||r===1)return;let a=Sn(xn(e===`isabelle`?xn(i,0):i,0)),o=e===`isabelle`?xn(i,1):void 0,s=xn(xn(r,0),0);return{kind:`stored`,method:{prover:e,timeLimitMs:a*1e3,...typeof o==`string`&&{tactic:o}},isProved:r===0,...s!==void 0&&{reason:typeof s==`number`?vn[s]:String(xn(s,0))}}},Dn=(e,t)=>{let n=/* @__PURE__ */ new Date,r=t.method,i={float:mt(r)},a=e===`zenon`?L(0,i,5):e===`isabelle`?L(0,L(0,i),r.tactic??`auto`):L(0,i),o=ot(t),s=vn.indexOf(o??``),c=o===void 0?0:L(0,s===-1?L(0,o):s);return L(0,L(0,L(0,$e(t)?0:L(0,c),_n[e].isConstant?_n[e].tag:L(_n[e].tag,a)),L(0,n.getFullYear(),n.getMonth(),n.getDate(),n.getHours(),n.getMinutes(),n.getSeconds()),yn,yn,yn))},On=e=>{let t=2**Math.max(9,Math.ceil(Math.log2(e.size/2))),n=Array.from({length:t},()=>0);return e.forEach((e,r)=>{let i=Cn(r)&t-1;n[i]=L(0,r,L(0,...e),n[i])}),L(0,L(0,e.size,L(0,...n),0,512))},kn=e=>String(e).padStart(2,`0`),An=(e,t)=>{let n=/* @__PURE__ */ new Date,r=`${e}.history`,i=St(r,`${n.getFullYear()}-${kn(n.getMonth()+1)}-${kn(n.getDate())}_${kn(n.getHours())}_${kn(n.getMinutes())}_${kn(n.getSeconds())}`);Ot(i,{recursive:!0}),[e,...t].filter(e=>I(e)).forEach(e=>Et(e,St(i,vt(e)),{preserveTimestamps:!0})),Mt(r).map(e=>St(r,e)).sort((e,t)=>It(t).mtimeMs-It(e).mtimeMs).slice(10).forEach(e=>Ft(e,{recursive:!0,force:!0}))},jn=e=>{let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map,r=new Map([...e].map(([e,r])=>{let i=new Map(gn.flatMap(e=>{let n=r[_n[e].field],i=En(e,xn(n,0));return i?(t.set(i,n),[[e,i]]):[]}));return n.set(i,r),[e,i]}));return{results:r,save:i=>{e.clear(),r.forEach((r,i)=>{let a=[...n.get(r)??Array(23).fill(0)];gn.forEach(e=>{let n=r.get(e);n&&(a[_n[e].field]=t.get(n)??Dn(e,n))}),e.set(i,a)}),Lt(`${i}.tmp`,Buffer.concat([mn(hn),mn(On(e))])),Pt(`${i}.tmp`,i)}}},Mn=((e,t)=>{let n=new Map(t.map(e=>{let[t,...n]=e.flag.split(` `);return[t,n.length]}));return{usage:e.replace(`{options}`,t.map(e=>`[${e.flag}]${e.isRepeatable?`...`:``}`).join(` `)),parse:e=>{let t=[],r=[],i=[];for(let a=0;a<e.length;a++){let o=n.get(e[a]);o===void 0?(e[a].startsWith(`-`)?i:r).push(e[a]):(t.push({name:e[a],values:e.slice(a+1,a+1+o)}),a+=o)}return{options:t,positionals:r,unknown:i,incomplete:t.find(e=>e.values.length<(n.get(e.name)??0)),has:e=>t.some(t=>t.name===e),get:e=>t.findLast(t=>t.name===e)?.values}}}})(`tla-ts tlapm {options} <Module.tla|glob>...`,[{flag:`-N`},{flag:`--summary`},{flag:`--strict`},{flag:`--toolbox <start> <end>`},{flag:`--line <num>`},{flag:`--printallobs`},{flag:`--threads <num>`},{flag:`--version`},{flag:`-I <directory>`,isRepeatable:!0},{flag:`-k`},{flag:`--noproving`},{flag:`--nofp`},{flag:`--nofpl <start> <end>`},{flag:`--safefp`},{flag:`--cleanfp`},{flag:`--usefp <file>`},{flag:`--cache-dir <directory>`},{flag:`--debug <flags>`,isRepeatable:!0},{flag:`--method <methods>`},{flag:`--solver <command>`},{flag:`--smt-logic <logic>`},{flag:`--stretch <factor>`},{flag:`--noflatten`}]),Nn=[`Usage: tla-ts <Spec.tla|Spec.cfg|spec.ts|glob>... [-config <Spec.cfg>] [-continue] [-deadlock] [-dump [<format>] <file>] [-fp <num>] [-lncheck <final|default|off>] [-maxSetSize <num>] [-metadir <directory>] [-nowarning] [-seed <num>] [-terse] [-tool] [-view] [-workers <count|auto>]`,` ${Mn.usage}`,` tla-ts [<JVM option>]... tlc2.TLC <TLC option>... <Spec>`,` (-cp tla2tools.jar or -Dtla-ts.tlc=1.7.4 picks the TLC to reproduce)`,` tla-ts [<JVM option>]... tla2sany.xml.XMLExporter [-I <directory>]... [-o] [-t] [-r] [-u] <Module.tla>`].join(`
10
10
  `),Pn={name:``,values:[],doc:` `},Fn=[Pn,{name:`(basic options)`,values:[],doc:` `},Pn,{name:`--help`,values:[],doc:` show this help message and exit`},{name:`-help`,values:[],doc:` (same as --help)`},{name:`--version`,values:[],doc:` show version number and exit`},{name:`--verbose`,values:[],doc:` produce verbose messages`},{name:`-v`,values:[],doc:` (same as --verbose)`},Pn,{name:`--where`,values:[],doc:` show location of standard library and exit`},{name:`--config`,values:[],doc:` show configuration and exit`},{name:`--summary`,values:[],doc:` show summary of theorems (implies -N and not -C)`},{name:`--strict`,values:[],doc:` report incomplete proofs, empty proof targets and failed obligations as errors and exit with a non-zero status`},{name:`--timing`,values:[],doc:` show runtime statistics`},Pn,{name:`-I`,values:[`string`],doc:`<dir> add <dir> to search path`},{name:`-d`,values:[`string`],doc:``},Pn,{name:`-k`,values:[],doc:` keep going on backend failures`},{name:`-N`,values:[],doc:` do not run any backend verifiers`},{name:`-C`,values:[],doc:` check proofs in Isabelle/TLA+`},Pn,{name:`--threads`,values:[`int`],doc:`<int> set number of worker threads to <int>`},{name:`--method`,values:[`string`],doc:`<meth> set default method to <meth> (try --method help)`},{name:`--solver`,values:[`string`],doc:`<solver> set SMT solver to <solver>`},{name:`--smt-logic`,values:[`string`],doc:`<logic> set SMT logic to <logic>`},{name:`--stretch`,values:[`float`],doc:`<f> multiply all timeouts by <f>`},{name:`--fast-isabelle`,values:[],doc:``},Pn,{name:`(advanced options)`,values:[],doc:` `},Pn,{name:`--noflatten`,values:[],doc:` do not flatten obligations`},{name:`--nonormal`,values:[],doc:` do not normalize obligations before printing`},{name:`--debug`,values:[`string`],doc:`{[-]<flag>} enable/disable debugging flags`},{name:`--paranoid`,values:[],doc:``},{name:`--isaprove`,values:[],doc:``},Pn,{name:`--toolbox`,values:[`int`,`int`],doc:`<int><int> toolbox mode`},{name:`--toolbox-vsn`,values:[`int`],doc:`<int> Toolbox protocol version, 1|2, 1 by default.`},{name:`--line`,values:[`int`],doc:`<int> line to prove`},{name:`--wait`,values:[`int`],doc:`<time> wait for <time> before printing obligations in progress`},{name:`--stdin`,values:[],doc:` read the tla file from stdin instead of file system. Only applies if single tla file is provided as input.`},{name:`--prefer-stdlib`,values:[],doc:` prefer built-in standard modules if the module search path contains files with the same names as modules in stdlib.`},{name:`--parser`,values:[`string`],doc:` Set parser backend to use: TLAPM (default) or SANY.`},{name:`--module-jar`,values:[`string`],doc:` Add a path to a .jar file containing additional TLA+ modules, such
11
11
  as the community modules. Multiple .jar files can be added by using
12
12
  this option multiple times.`},{name:`--noproving`,values:[],doc:` do not prove, report fingerprinted results only`},Pn,{name:`--printallobs`,values:[],doc:` print obligations in all toolbox messages`},Pn,{name:`--fpdir`,values:[`string`],doc:``},{name:`--safefp`,values:[],doc:` check tlapm, zenon, Isabelle versions for fingerprints`},{name:`--nofp`,values:[],doc:` do not use existing fingerprints, but overwrite any preexisting fingerprints associated with the current proof obligations, using the newly computed fingerprints and results`},{name:`--nofpl`,values:[`int`,`int`],doc:`<int><int> disable fingerprint use between given lines`},{name:`--cleanfp`,values:[],doc:` erase fingerprint file before starting`},Pn,{name:`--erasefp`,values:[`string`,`string`],doc:`<f><back> erase from file <f> all results of backend <back>`},{name:`--printfp`,values:[`string`],doc:`<f> print the fingerprints stored in file <f> and quit`},{name:`--usefp`,values:[`string`],doc:`<f> load fingerprints from file <f> (save as usual)`},{name:`--fpp`,values:[],doc:` print the fingerprints of obligations in toolbox messages`},{name:`--cache-dir`,values:[`string`],doc:'<directory> save auxiliary and temporary files under <directory>. Alternatively, this directory can be defined via the variable `TLAPM_CACHE_DIR` of the runtime environment. The command-line parameter takes precedence over the environment variable. If neither is specified, the default value is ".tlacache".'}],In=e=>/^[^ ]* */.exec(e)?.[0].length??0,Ln=()=>{let e=Math.max(...Fn.map(e=>e.name.length+In(e.doc)));return`Usage: tla-ts tlapm <options> FILE ...\noptions are:\n${Fn.filter(e=>e.doc!==``).map(t=>{let n=In(t.doc);return` ${t.name} ${t.doc.slice(0,n)}${` `.repeat(e-t.name.length-n)}${t.doc.slice(n)}\n`}).join(``)}`},Rn=e=>{for(let t=0;t<e.length;t++){let n=e[t];if(n===`--version`)return;if(!n.startsWith(`-`))continue;let r=Fn.find(e=>e.name===n);if(!r)return`unknown option '${n}'`;for(let i of r.values){if(t++,t===e.length)return`option '${n}' needs an argument`;let r=e[t];if(i===`int`&&ut(r)===void 0)return`wrong argument '${r}'; option '${n}' expects an integer`;if(i===`float`&&rt(r)===void 0)return`wrong argument '${r}'; option '${n}' expects a float`}let i=e[t];if(n===`--threads`&&(ut(i)??0)<0)return`--threads requires a positive argument`;if(n===`--debug`&&i.split(`,`).includes(`oldsmt`))return`--debug oldsmt: the old SMT encoding has been removed`;if(n===`--method`)try{nt(i)}catch(e){if(!(e instanceof C))throw e;return e.message}}},zn=t=>[`.`,...e().map(e=>St(bt(bt(Nt(e))),`lib/tlapm/stdlib`)).filter(I).slice(0,1),...t.options.flatMap(e=>e.name===`-I`?e.values:[]).toReversed()],Bn=e=>console.error(`@!!BEGIN\n${e.map(e=>`@!!${e}\n`).join(``)}@!!END\n`),Vn=(e,t,n)=>Bn([`type:obligation`,`id:${e.id}`,`loc:${e.location}`,`status:${t}`,...n]),Hn=e=>/^[+,\-./0-9:=@A-Z_a-z]+$/.test(e)?e:`'${e.replaceAll(`'`,`'\\''`)}'`,Un={failed:10,incomplete:11,emptyTarget:12},Wn=(e,t,n)=>{let r=e.summary;n||(r.absent.forEach(e=>console.error(`Missing proof at ${gt(e)}`)),r.omitted.forEach(e=>console.error(`Omitted proof at ${gt(e)}`)));let i=r.absent.length+r.omitted.length>0;i&&console.error(`${et(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(`${et(e.location)}[ERROR]: No proof obligation found for the selected target.`),[...i?[Un.incomplete]:[],...a?[Un.emptyTarget]:[]]},Gn=(e,t,n)=>{console.error(` tlapm ending abnormally with ${e.exception}\n`),n&&Bn(t.message===``?[`type:error`,`url:http://tla.msr-inria.inria.fr/bugs`,`msg:Oops, this seems to be a bug in TLAPM.\nPlease give feedback to developers.\n\n\n ${e.exception}\n`]:[`type:warning`,`msg:${t.location===void 0?``:`${t.location}\n\n`}${t.message}`])},Kn=e=>{if(!(e instanceof n))throw e;return{kind:`aborted`,error:e}},qn=e=>{try{return{kind:`done`,value:e()}}catch(e){return Kn(e)}},Jn=(e,t,n)=>{let r=t.method.timeLimitMs,i=t.kind===`decided`?`; time-used: ${(t.timeUsedMs/1e3).toFixed(1)} (${Math.round(100*t.timeUsedMs/r)}%)`:``,a=r===0?``:`time-limit: ${r===1/0?`inf`:Number((r/1e3).toPrecision(6))}${i}`,o=[t.method.tactic,a].filter(Boolean).join(`; `),s=ot(t),c=$e(t),l=t.kind===`reused`,u=t.kind===`decided`?t.note:t.kind===`refused`?`${t.reason}\nObligation:\n\n`:t.kind===`unavailable`?`\n\\* ${t.warning}\n`:void 0,d=t.kind===`unavailable`||l?t.shipped:void 0;Vn(e,c?`proved`:`failed`,[`prover:${t.method.prover}`,...o===``?[]:[`meth:${o}`],...s===void 0?[]:[`reason:${s}`],`already:${l}`,...c?[]:[`obl:${l?``:u??`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tla-ts",
3
- "version": "0.0.10-dev.5ffc55ce5",
3
+ "version": "0.0.10-dev.6232a1403",
4
4
  "description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
5
5
  "keywords": [
6
6
  "formal verification",
@@ -2051,7 +2051,7 @@ export class AstManager {
2051
2051
  }
2052
2052
 
2053
2053
  get am() {
2054
- this.algebraicManager ??= new AlgebraicManager(this.limit);
2054
+ this.algebraicManager ??= new AlgebraicManager();
2055
2055
  return this.algebraicManager;
2056
2056
  }
2057
2057
 
@@ -12,227 +12,105 @@ import {
12
12
  SORT_INT,
13
13
  SORT_REAL,
14
14
  } from "./ast";
15
- import {
16
- type Polynomial,
17
- type PolynomialManager,
18
- PolynomialRef,
19
- PolynomialRefVector,
20
- } from "./nlsat/polynomial";
15
+ import type { Polynomial, PolynomialManager } from "./nlsat/polynomial";
21
16
  import { getLcm, Rational } from "./rational";
22
17
  import { RefVector } from "./ref-vector";
23
18
 
24
- interface Frame {
25
- term: number;
26
- index: number;
19
+ export interface PolynomialResult {
20
+ polynomial: Polynomial;
21
+ denominator: bigint;
27
22
  }
28
23
 
29
- export class Expr2Polynomial {
30
- private cache = new Map<number, number>();
31
- private cachedDomain: RefVector;
32
- private cachedPolynomials: PolynomialRefVector;
33
- private cachedDenominators: bigint[] = [];
34
- private frames: Frame[] = [];
35
- private presult: PolynomialRefVector;
36
- private dresult: bigint[] = [];
37
- private var2expr: RefVector;
38
-
39
- constructor(
40
- private manager: AstManager,
41
- readonly pm: PolynomialManager,
42
- private t2x: Map<number, number>,
43
- private mkVar: (isInt: boolean) => number,
44
- ) {
45
- this.cachedDomain = new RefVector(manager);
46
- this.cachedPolynomials = new PolynomialRefVector(pm);
47
- this.presult = new PolynomialRefVector(pm);
48
- this.var2expr = new RefVector(manager);
49
- }
50
-
51
- private reset() {
52
- this.frames.length = 0;
53
- this.presult.reset();
54
- this.dresult.length = 0;
55
- }
56
-
57
- private cacheResult(term: number) {
58
- if (this.manager.getRefCount(term) <= 1) return;
59
- this.cache.set(term, this.cachedPolynomials.size);
60
- this.cachedDomain.push(term);
61
- this.cachedPolynomials.push(this.presult.get(this.presult.size - 1));
62
- this.cachedDenominators.push(this.dresult[this.dresult.length - 1]);
63
- }
64
-
65
- private storeResult(term: number, polynomial: Polynomial, denominator: bigint) {
66
- this.presult.push(polynomial);
67
- this.dresult.push(denominator);
68
- this.cacheResult(term);
69
- }
70
-
71
- private storeVarPoly(term: number) {
72
- let variable = this.t2x.get(term);
73
- if (variable === undefined) {
74
- variable = this.mkVar(this.manager.sorts[term] === SORT_INT);
75
- this.t2x.set(term, variable);
76
- if (variable >= this.var2expr.size) this.var2expr.resize(variable + 1);
77
- this.var2expr.set(variable, term);
78
- }
79
- this.storeResult(term, this.pm.mkVar(variable), 1n);
80
- }
81
-
82
- private visitArithApp(term: number) {
83
- const manager = this.manager;
84
- switch (manager.getOp(term)) {
24
+ export const toPolynomial = (
25
+ manager: AstManager,
26
+ pm: PolynomialManager,
27
+ term: number,
28
+ mkVar: (term: number) => number,
29
+ ): PolynomialResult => {
30
+ const convert = (expr: number): PolynomialResult => {
31
+ if (manager.kinds[expr] !== KIND_APP || manager.getFamily(expr) !== FAMILY_ARITH)
32
+ return { polynomial: pm.mkVar(mkVar(expr)), denominator: 1n };
33
+ const op = manager.getOp(expr);
34
+ switch (op) {
85
35
  case OP_NUM: {
86
- const value = manager.getRationalValue(term);
87
- this.storeResult(term, this.pm.mkConst(value.num), value.den);
88
- return true;
36
+ const value = manager.getRationalValue(expr);
37
+ return { polynomial: pm.mkConst(value.num), denominator: value.den };
89
38
  }
90
39
  case OP_ADD:
91
- case OP_SUB:
92
- case OP_MUL:
93
- case OP_UMINUS:
40
+ case OP_SUB: {
41
+ const args = manager.getArgs(expr).map(convert);
42
+ const denominator = args.reduce((lcm, arg) => getLcm(lcm, arg.denominator), 1n);
43
+ let polynomial = pm.zero;
44
+ for (const [index, arg] of args.entries()) {
45
+ const scaled = pm.mulConst(denominator / arg.denominator, arg.polynomial);
46
+ polynomial =
47
+ index === 0
48
+ ? scaled
49
+ : op === OP_ADD
50
+ ? pm.add(polynomial, scaled)
51
+ : pm.sub(polynomial, scaled);
52
+ }
53
+ return { polynomial, denominator };
54
+ }
55
+ case OP_MUL: {
56
+ let polynomial = pm.one;
57
+ let denominator = 1n;
58
+ for (const arg of manager.getArgs(expr).map(convert)) {
59
+ polynomial = pm.mul(polynomial, arg.polynomial);
60
+ denominator *= arg.denominator;
61
+ }
62
+ return { polynomial, denominator };
63
+ }
64
+ case OP_UMINUS: {
65
+ const arg = convert(manager.getArg(expr, 0));
66
+ return { polynomial: pm.neg(arg.polynomial), denominator: arg.denominator };
67
+ }
94
68
  case OP_TO_REAL:
95
- this.frames.push({ term, index: 0 });
96
- return false;
69
+ return convert(manager.getArg(expr, 0));
97
70
  case OP_POWER: {
98
- const exponent = manager.getArg(term, 1);
71
+ const exponent = manager.getArg(expr, 1);
99
72
  const value = manager.isNumeral(exponent) ? manager.getRationalValue(exponent) : undefined;
100
- if (value === undefined || !value.isInt() || value.num <= 0n || value.num > 0xffffffffn) {
101
- this.storeVarPoly(term);
102
- return true;
103
- }
104
- this.frames.push({ term, index: 0 });
105
- return false;
73
+ if (value === undefined || !value.isInt() || value.num <= 0n || value.num > 0xffffffffn)
74
+ return { polynomial: pm.mkVar(mkVar(expr)), denominator: 1n };
75
+ const base = convert(manager.getArg(expr, 0));
76
+ return {
77
+ polynomial: pm.pw(base.polynomial, Number(value.num)),
78
+ denominator: base.denominator ** value.num,
79
+ };
106
80
  }
107
81
  default:
108
- this.storeVarPoly(term);
109
- return true;
82
+ return { polynomial: pm.mkVar(mkVar(expr)), denominator: 1n };
110
83
  }
111
- }
84
+ };
85
+ return convert(term);
86
+ };
112
87
 
113
- private visit(term: number) {
114
- const manager = this.manager;
115
- const cached = manager.getRefCount(term) > 1 ? this.cache.get(term) : undefined;
116
- if (cached !== undefined) {
117
- this.presult.push(this.cachedPolynomials.get(cached));
118
- this.dresult.push(this.cachedDenominators[cached]);
119
- return true;
120
- }
121
- if (manager.kinds[term] !== KIND_APP || manager.getFamily(term) !== FAMILY_ARITH) {
122
- this.storeVarPoly(term);
123
- return true;
124
- }
125
- return this.visitArithApp(term);
126
- }
127
-
128
- private pop(numArgs: number) {
129
- this.presult.shrink(this.presult.size - numArgs);
130
- this.dresult.length -= numArgs;
131
- }
132
-
133
- private processAddSub(term: number, numArgs: number, isAdd: boolean) {
134
- const pm = this.pm;
135
- const first = this.presult.size - numArgs;
136
- const p = new PolynomialRef(pm);
137
- const pAux = new PolynomialRef(pm);
138
- let denominator = 1n;
139
- for (let index = 0; index < numArgs; index++)
140
- denominator = getLcm(denominator, this.dresult[first + index]);
141
- p.set(pm.zero);
142
- for (let index = 0; index < numArgs; index++) {
143
- pAux.set(
144
- pm.mulConst(denominator / this.dresult[first + index], this.presult.get(first + index)),
145
- );
146
- if (index === 0) p.copy(pAux);
147
- else p.set(isAdd ? pm.add(p.get(), pAux.get()) : pm.sub(p.get(), pAux.get()));
148
- }
149
- this.pop(numArgs);
150
- this.storeResult(term, p.get(), denominator);
151
- pAux.reset();
152
- p.reset();
153
- }
154
-
155
- private processMul(term: number, numArgs: number) {
156
- const first = this.presult.size - numArgs;
157
- const p = new PolynomialRef(this.pm);
158
- let denominator = 1n;
159
- p.set(this.pm.one);
160
- for (let index = 0; index < numArgs; index++) {
161
- p.set(this.pm.mul(p.get(), this.presult.get(first + index)));
162
- denominator *= this.dresult[first + index];
163
- }
164
- this.pop(numArgs);
165
- this.storeResult(term, p.get(), denominator);
166
- p.reset();
167
- }
168
-
169
- private processUminus(term: number) {
170
- const negP = new PolynomialRef(this.pm);
171
- negP.set(this.pm.neg(this.presult.get(this.presult.size - 1)));
172
- this.presult.shrink(this.presult.size - 1);
173
- this.presult.push(negP.get());
174
- this.cacheResult(term);
175
- negP.reset();
176
- }
88
+ export class Expr2Polynomial {
89
+ private termToVar = new Map<number, number>();
90
+ private varToTerm: RefVector;
177
91
 
178
- private processPower(term: number, numArgs: number) {
179
- const first = this.presult.size - numArgs;
180
- const k = Number(this.manager.getRationalValue(this.manager.getArg(term, 1)).num);
181
- const p = new PolynomialRef(this.pm);
182
- this.pm.pw(this.presult.get(first), k, p);
183
- const denominator = this.dresult[first] ** BigInt(k);
184
- this.pop(numArgs);
185
- this.storeResult(term, p.get(), denominator);
186
- p.reset();
92
+ constructor(
93
+ private manager: AstManager,
94
+ readonly pm: PolynomialManager,
95
+ ) {
96
+ this.varToTerm = new RefVector(manager);
187
97
  }
188
98
 
189
- private processApp(term: number) {
190
- const numArgs = this.manager.getNumArgs(term);
191
- switch (this.manager.getOp(term)) {
192
- case OP_ADD:
193
- return this.processAddSub(term, numArgs, true);
194
- case OP_SUB:
195
- return this.processAddSub(term, numArgs, false);
196
- case OP_MUL:
197
- return this.processMul(term, numArgs);
198
- case OP_POWER:
199
- return this.processPower(term, numArgs);
200
- case OP_UMINUS:
201
- return this.processUminus(term);
202
- default:
203
- return this.cacheResult(term);
204
- }
99
+ private getVar(term: number) {
100
+ const existing = this.termToVar.get(term);
101
+ if (existing !== undefined) return existing;
102
+ const variable = this.varToTerm.size;
103
+ this.termToVar.set(term, variable);
104
+ this.varToTerm.push(term);
105
+ return variable;
205
106
  }
206
107
 
207
- toPolynomial(term: number, p: PolynomialRef) {
208
- this.reset();
209
- if (!this.visit(term)) {
210
- const frames = this.frames;
211
- while (frames.length > 0) {
212
- const frame = frames[frames.length - 1];
213
- const numArgs = this.manager.getNumArgs(frame.term);
214
- let isPushed = false;
215
- while (frame.index < numArgs) {
216
- const arg = this.manager.getArg(frame.term, frame.index);
217
- frame.index++;
218
- if (!this.visit(arg)) {
219
- isPushed = true;
220
- break;
221
- }
222
- }
223
- if (isPushed) continue;
224
- this.processApp(frame.term);
225
- frames.pop();
226
- }
227
- }
228
- p.set(this.presult.get(this.presult.size - 1));
229
- const denominator = this.dresult[this.dresult.length - 1];
230
- this.reset();
231
- return denominator;
108
+ private isIntVar(variable: number) {
109
+ return this.manager.sorts[this.varToTerm.items[variable]] === SORT_INT;
232
110
  }
233
111
 
234
- private isIntVar(variable: number) {
235
- return this.manager.sorts[this.var2expr.items[variable]] === SORT_INT;
112
+ toPolynomial(term: number) {
113
+ return toPolynomial(this.manager, this.pm, term, (expr) => this.getVar(expr));
236
114
  }
237
115
 
238
116
  toExpr(polynomial: Polynomial, isUsingPower: boolean) {
@@ -247,7 +125,7 @@ export class Expr2Polynomial {
247
125
  const coeff = polynomial.as[index];
248
126
  if (coeff !== 1n) factors.push(mkNumeral(coeff));
249
127
  for (const [position, variable] of monomial.vars.entries()) {
250
- const term = this.var2expr.items[variable];
128
+ const term = this.varToTerm.items[variable];
251
129
  const base =
252
130
  this.isIntVar(variable) && !isInt ? manager.mkApp(OP_TO_REAL, [term], SORT_REAL) : term;
253
131
  const degree = monomial.degrees[position];
@@ -263,9 +141,6 @@ export class Expr2Polynomial {
263
141
  }
264
142
 
265
143
  release() {
266
- this.presult.reset();
267
- this.cachedPolynomials.reset();
268
- this.cachedDomain.reset();
269
- this.var2expr.reset();
144
+ this.varToTerm.reset();
270
145
  }
271
146
  }
@@ -18,7 +18,7 @@ import { runSimplifier } from "./dependent-expr-state";
18
18
  import { Expr2Polynomial } from "./expr2polynomial";
19
19
  import type { Goal } from "./goal";
20
20
  import { getLcm, Rational } from "./rational";
21
- import { Factors, type Polynomial, PolynomialManager, PolynomialRef } from "./nlsat/polynomial";
21
+ import { PolynomialManager } from "./nlsat/polynomial";
22
22
  import type { Rewrite } from "./rewriter-tpl";
23
23
  import { RewriterTpl } from "./rewriter-tpl";
24
24
 
@@ -37,13 +37,7 @@ class FactorRewriter extends RewriterTpl {
37
37
  private isSplittingFactors: boolean,
38
38
  ) {
39
39
  super(manager);
40
- let variableCount = 0;
41
- this.expr2poly = new Expr2Polynomial(
42
- manager,
43
- new PolynomialManager(manager.limit),
44
- new Map(),
45
- () => variableCount++,
46
- );
40
+ this.expr2poly = new Expr2Polynomial(manager, new PolynomialManager());
47
41
  }
48
42
 
49
43
  private mkZeroFor(expr: number) {
@@ -57,36 +51,20 @@ class FactorRewriter extends RewriterTpl {
57
51
  : this.manager.mkApp(OP_MUL, args, this.manager.sorts[args[0]]);
58
52
  }
59
53
 
60
- private factor(op: number, lhs: number, rhs: number) {
54
+ private factor(op: number, lhs: number, rhs: number): number {
55
+ const manager = this.manager;
61
56
  const pm = this.expr2poly.pm;
62
- const first = new PolynomialRef(pm);
63
- const second = new PolynomialRef(pm);
64
- const p = new PolynomialRef(pm);
65
- const firstDenominator = this.expr2poly.toPolynomial(lhs, first);
66
- const secondDenominator = this.expr2poly.toPolynomial(rhs, second);
67
- const lcm = getLcm(firstDenominator, secondDenominator);
68
- p.set(
69
- pm.addmulTerms(
70
- lcm / firstDenominator,
71
- pm.unit,
72
- first.get(),
73
- -(lcm / secondDenominator),
74
- pm.unit,
75
- second.get(),
76
- ),
57
+ const first = this.expr2poly.toPolynomial(lhs);
58
+ const second = this.expr2poly.toPolynomial(rhs);
59
+ const lcm = getLcm(first.denominator, second.denominator);
60
+ const polynomial = pm.addmul(
61
+ lcm / first.denominator,
62
+ first.polynomial,
63
+ -(lcm / second.denominator),
64
+ second.polynomial,
77
65
  );
78
- const factors = new Factors(pm);
79
- const result = pm.isConst(p.get()) ? -1 : this.factorPolynomial(op, p.get(), factors);
80
- factors.reset();
81
- p.reset();
82
- second.reset();
83
- first.reset();
84
- return result;
85
- }
86
-
87
- private factorPolynomial(op: number, polynomial: Polynomial, factors: Factors): number {
88
- const manager = this.manager;
89
- this.expr2poly.pm.factor(polynomial, factors);
66
+ if (pm.isConst(polynomial)) return -1;
67
+ const factors = pm.factor(polynomial);
90
68
  if (factors.factors.length === 1 && factors.degrees[0] === 1) return -1;
91
69
  const terms = factors.factors.map((factor) => this.expr2poly.toExpr(factor, true));
92
70
  if (op === OP_EQ) {