tla 0.0.10-dev.a2d447617 → 0.0.10-dev.a43e3a937

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
@@ -23,7 +23,7 @@ operator name or before an operator name.`)}else if(r===void 0||t.yn(r))return e
23
23
  in module being instantiated.`,Wn=(e,n,r,i,a,o,s=e.currentModule)=>(t.yn(i)&&e.addError(o,n===`SubstIn`?Un:`Substitution error, probably due to error in module being instantiated.`),{...H(e.getId()),kind:n,substs:r,body:i,instantiatingModule:s,instantiatedModule:a,location:o}),Gn=(e,t,n,r,i)=>{if(n)return Wn(e,`SubstIn`,t,n,r,i);e.addError(i,Un)},Kn=(e,t,n)=>{U(e,t),t.params=n},qn=(e,n,r,i)=>{let a=In(e.file,n),o=t.Jn(e.file,a),s=t.Kn(e.file,a.start),c=n.name??``,l=t.un(),u=n.isLocal?a.start+1:a.start;n.params.length>0&&e.contexts.push(l);let d=Fn(e,n,{start:u,end:a.end},n.params.length>0),f=Yt(e,n.module),p=f.context,m=Hn(e,n,p,o);n.params.length>0&&e.contexts.pop();for(let i of t.hn(p.table)){if(i.kind!==`OpDef`||i.isLocal||i.defKind!==`UserDefined`&&i.defKind!==`ModuleInstance`)continue;let t=[...d,...i.params??[]],a=`${c}!${i.name}`,l=i.defKind===`UserDefined`?Zt(e,{name:a,params:t,body:m.length>0?Gn(e,m,i.body,f,o):i.body,isLocal:n.isLocal,location:o,source:i.source??i,preComments:s,labels:i.labels}):Zt(e,{defKind:`ModuleInstance`,name:a,params:t,isLocal:n.isLocal,location:o,module:i.module,source:i.source??i,preComments:s});U(e,l),i.defKind===`UserDefined`&&Qt(e,l),(r??e.currentModule.definitions).push(l)}for(let i of t.hn(p.table)){if(i.kind!==`ThmOrAssumpDef`||i.isLocal)continue;let t=m.length>0?Wn(e,`APSubstIn`,m,i.body,f,o):i.body,a={...H(e.getId()),kind:`ThmOrAssumpDef`,name:`${c}!${i.name}`,isTheorem:i.isTheorem,body:t,params:[],isLocal:n.isLocal,location:o,module:e.currentModule,source:i.source??i,labels:i.labels,isLeibnizArg:[],isLeibniz:!1,opLevelCond:[],maxLevels:[],weights:[],minMaxLevel:[]};Kn(e,a,[...d,...i.params]),(r??e.currentModule.definitions).push(a)}let h={...H(e.getId()),kind:`Instance`,name:c,isLocal:n.isLocal,params:d,module:f,substs:m,location:o};(i??e.currentModule.topLevel).push(h);let g=Zt(e,{defKind:`ModuleInstance`,name:c,params:d,isLocal:n.isLocal,location:o,preComments:s});U(e,g),e.version!==`1.7.4`&&r?.push(g)},Jn=(e,t)=>(U(e,t),t),Yn=(e,n,r=!0,i)=>{let a=In(e.file,n),o=i??t.Jn(e.file,a),s=t.Kn(e.file,a.start),c=Yt(e,n.module),l=c.context,u=Hn(e,n,l,o),d=n.isLocal,f=Vt(c);for(let n of t.hn(l.table)){if(n.kind!==`OpDef`||n.defKind!==`UserDefined`||n.isLocal)continue;let t=(t,r)=>{let i=Zt(e,{name:n.name,params:n.params,body:r,isLocal:d,location:o,module:t,source:n.source??n,preComments:s,labels:n.labels});return U(e,i),i},r=n.module===void 0||Vt(n.module),i=f||r?d?t(n.module,n.body):Jn(e,n):t(e.currentModule,Gn(e,u,n.body,c,o));e.currentModule.definitions.push(i),i!==n&&Qt(e,i)}for(let n of t.hn(l.table)){if(n.kind!==`ThmOrAssumpDef`||n.isLocal)continue;let t=(t,r)=>{let i={...n,...H(e.getId()),body:r,isLocal:d,location:o,module:t,source:n.source??n,params:[]};return Kn(e,i,n.params),i},i=f?d?t(n.module,n.body):Jn(e,n):Vt(n.module)?d?t(e.currentModule,n.body):n:t(e.currentModule,Wn(e,`APSubstIn`,u,n.body,c,o));r&&e.currentModule.definitions.push(i)}let p={...H(e.getId()),kind:`Instance`,name:void 0,isLocal:d,params:[],module:c,substs:u,location:o};return r&&e.currentModule.topLevel.push(p),p},Xn=(e,n,r)=>r===0?{start:n,end:n}:t.Qn(e,n,`_`)?{start:n,end:t.Qn(e,n+2,`_`)?n+2:n+1}:t.Qn(e,n+1,`(`)?{start:n,end:t.Wn(e,n+1)}:{start:n,end:t.Qn(e,n+1,`_`)?n+1:n},Zn=(e,t)=>Xn(e,Kt(e,t.location).start,t.arity),Qn=(e,n,r)=>{let i=Zn(e.file,n),a={...H(e.getId()),levelChecked:1,level:+(r===3),kind:`OpDecl`,name:t.Ln(n.name),arity:n.arity,declKind:r,location:t.Jn(e.file,i),module:e.currentModule};return r===2&&(a.levelParams.add(a),a.allParams.add(a)),U(e,a),a},$n=(e,t,n)=>{e.recursion.unresolvedSum<=0||e.addError(qt(e.file,t),`${n} may not appear within a recursive definition section.`)},er=(e,n)=>{let r=[...n.definitions.map(t=>({unit:{kind:`Definition`,definition:t},span:In(e,t)})),...(n.instances??[]).map(t=>({unit:{kind:`Instance`,instance:t},span:In(e,t)}))],i=t.Un(e,n).start,a=t.Rn(e,n.body).start,o=[];for(let n=i+1;n<a;n++){let i=r.some(e=>e.span.start<=n&&n<=e.span.end);t.Qn(e,n,`RECURSIVE`)&&!i&&o.push(n)}let s=o.map((r,i)=>{let s=o[i+1]??a;return{unit:{kind:`Recursive`,declarations:(n.recursive??[]).filter(n=>{let i=t.Yn(e,n.location);return r<i&&i<s})},span:{start:r,end:r}}});return[...r,...s].toSorted((e,t)=>e.span.start-t.span.start).map(e=>e.unit)},tr=(e,n)=>{let r=t.un();return W(e,r,()=>{e.curLevel++,e.recursion.unresolvedCount[e.curLevel]=0;let t=[],i=[];for(let r of er(e.file,n))r.kind===`Recursive`?Bn(e,r.declarations):r.kind===`Instance`?qn(e,r.instance,t,i):r.definition.kind===`Function`?zn(e,r.definition,t):Ln(e,r.definition,t);Vn(e),e.curLevel=Math.max(e.curLevel-1,0);let a=q(e,n.body);return{...H(e.getId()),kind:`LetIn`,opDefs:t,instances:i,body:a,context:r,location:Gt(e.file,n)}})},nr={Constant:{declKind:24,level:0},Variable:{declKind:25,level:1},State:{declKind:26,level:1},Action:{declKind:27,level:2},Temporal:{declKind:28,level:3}},rr=(e,n)=>{let r=Jt(e,n.name)??(n.name===e.currentModule.name?e.currentModule:void 0);return r===void 0?(e.addError(t.Xn(e.file,t.Yn(e.file,n.location)+1),`Module \`${n.name}' used without being extended or instantiated.`),[]):[r]},ir=(t,n)=>n.flatMap(n=>{if(n.kind===`ModuleFact`)return rr(t,n);let r=n.kind===`ExceptAt`?{kind:`Identifier`,name:`@`,location:n.location}:n,i=Ot(r);if(i===void 0||!kt(i))return[q(t,n)];let a=fn(t,r,0,!0,!1);if(a.kind===`ThmOrAssumpDef`)throw new e.et(`Expected a fact`);return[a]}),ar=(e,n)=>n.defs.flatMap((r,i)=>{if(r.kind===`ModuleFact`)return rr(e,r);let a=n.defErrors?.get(i)??[];for(let t of a)e.addError(t.location,t.message);if(a.length>0)return[];let o=Gt(e.file,r),s=fn(e,t.En(r)??(r.kind===`OperatorReference`?{kind:`Identifier`,name:r.operator,location:r.location}:r),-1,!1,!0,o);return s.kind===`OpDef`||s.kind===`ThmOrAssumpDef`&&!s.name.startsWith(`<`)?[s]:(e.addError(o,`DEF clause entry should describe a defined operator.`),[])}),or=(e,t,n)=>{t.isOnly||t.facts.length+t.defs.length>0||e.addError(n,`Empty BY, USE, or HIDE`)},sr=(e,t)=>{let n=qt(e.file,t.location);or(e,t,n);let r=ir(e,t.facts),i=ar(e,t);if(r.length+i.length===0&&e.addError(n,`Empty USE or HIDE statement.`),t.kind===`Hide`)for(let t of r.filter(e=>e.kind===`OpAppl`&&e.operator.kind!==`ThmOrAssumpDef`))e.addError(t.location,`The only expression allowed as a fact in a HIDE is
24
24
  the name of a theorem, assumption, or step.`);return{...H(e.getId()),kind:`UseOrHide`,facts:r,defs:i,isOnly:t.isOnly,isHide:t.kind===`Hide`,location:n}},cr=(e,n)=>{let r=Kt(e.file,n.location),i=n.set&&q(e,n.set),a=On(e.file,r.start,n.name),o=nr[n.level],s={...H(e.getId()),levelChecked:1,level:o.level,kind:`OpDecl`,name:t.Ln(n.name),arity:n.arity,declKind:o.declKind,location:t.Jn(e.file,Xn(e.file,a,n.arity)),module:e.currentModule};return U(e,s),{...H(e.getId()),kind:`NewSymb`,declaration:s,set:i,location:t.Jn(e.file,r)}},lr=(e,n,r,i)=>{let a=Kt(e.file,n.location),o=n.isBoxed===!0,s=t.Jn(e.file,{start:a.start,end:o?a.start+1:a.start});o!==(n.isProveBoxed===!0)&&e.addError(s,o?`[]ASSUME matched by PROVE instead of []PROVE`:`ASSUME matched by []PROVE instead of PROVE`);let c=e.getId();r>1&&e.contexts.push(t.un()),o&&e.contexts.some(t=>e.assumeContexts.has(t))&&e.addError(s,`[]ASSUME used within the scope of an ordinary ASSUME's assumptions`),o||e.assumeContexts.add(Lt(e.contexts));let l={isDeclaredBefore:[!1],hasGoal:i!==void 0,isSuffices:i?.isSuffices??!1,isInProof:!0};e.assumeProveState.depth=r,e.assumeProveState.isDeclared[r]=!1,r===1&&(e.assumeProveState.goal=i&&l,e.assumeProveState.goalClause=0);let u=n.assumptions.map((t,n)=>{let i=t.kind===`NewSymbol`,a=t.kind===`AssumeProve`&&t.label?Pn(e,t.label.name,qt(e.file,t.label.location),()=>lr(e,t,r+1)):t.kind===`AssumeProve`?lr(e,t,r+1):i?cr(e,t):q(e,t);return e.assumeProveState.depth=r,i&&(e.assumeProveState.isDeclared[r]=!0),l.isDeclaredBefore.push(l.isDeclaredBefore[n]||i),r===1&&e.assumeProveState.goalClause++,a}),d=q(e,n.conclusion);r>1&&e.contexts.pop(),e.assumeProveState.depth=r-1,r===1&&(e.assumeProveState.goal=void 0);let f={...H(c),kind:`AssumeProve`,assumptions:u,goal:d,isSuffices:l.isSuffices,isBoxed:o,location:t.Jn(e.file,a)};return e.assumeProveScopes.set(f,l),f},ur=(e,t,n,r,i,a,o=!0)=>({...H(t),kind:`ThmOrAssumpDef`,name:n,isTheorem:o,body:r,params:[],isLocal:!1,location:i,module:e.currentModule,source:void 0,labels:a,isLeibnizArg:[],isLeibniz:!1,opLevelCond:[],maxLevels:[],weights:[],minMaxLevel:[]}),dr=(e,t)=>{let n=qt(e.file,t.location);t.kind===`By`&&or(e,t,n);let r=t.kind===`By`?ir(e,t.facts):[],i=t.kind===`By`?ar(e,t):[];return t.kind===`By`&&e.getId(),t.kind===`By`&&r.length+i.length===0&&e.addError(n,`Empty BY`),{...H(e.getId()),kind:`LeafProof`,facts:r,defs:i,isOmitted:t.kind===`Omitted`,isOnly:t.kind===`By`&&t.isOnly,location:n}},fr=(e,n,r)=>{let i=t.Jn(e.file,r);switch(n.kind){case`Have`:return K(e,`$Have`,[q(e,n.expression)],i);case`Case`:return K(e,`$Pfcase`,[q(e,n.expression)],i);case`Witness`:return K(e,`$Witness`,n.expressions.map(t=>q(e,t)),i);case`Qed`:return K(e,`$Qed`,[],i);case`Take`:case`Pick`:{let a=n.kind===`Pick`,o=a?`$Pick`:`$Take`;a&&e.contexts.push(t.un());let s=t=>n.kind===`Pick`?[_n(e,t,n.body)]:[];if(n.bounds.length>0){let t=gn(e,n.bounds,r.start),a=s(t.bounded.flat());return K(e,o,a,i,t)}let c=t.Bn(e.file,r.start,r.end+1,n.names),l=n.names.map((n,r)=>Xt(e,n,0,t.Xn(e.file,c[r]),!0)),u=s(l);return K(e,o,u,i,{unbounded:l})}}},pr=(n,r)=>{if(r.kind!==`Steps`)return dr(n,r);let i=t.un();n.contexts.push(i);let a=[],o=[],s=t.Tn(r.steps),c,l=(r,i,o)=>{if(r.kind===`Define`){let i=r.definitions.map(t=>{let r=[];t.kind===`Instance`?qn(n,t,r,a):t.kind===`Function`?zn(n,t,r):Ln(n,t,r);let i=r[t.kind===`Instance`?r.length-1:0];if(i?.kind!==`OpDef`)throw new e.et(`A DEFINE step defines no operator`);return i});return{...H(n.getId()),kind:`DefStep`,defs:i,location:t.Jn(n.file,o)}}if(r.kind===`Use`||r.kind===`Hide`)return{...sr(n,r),location:t.Jn(n.file,i)};if(r.kind===`Instance`)return Yn(n,r,!1,t.Jn(n.file,o))},u=r.steps.map(r=>{let i=Kt(n.file,r.location),a=t.qn(n.file,r.head),u={start:a.start+1,end:a.end},d=r.body;r.name!==void 0&&/^<[*+]>/.test(r.token)&&n.addError(t.Xn(n.file,i.start),`<*> and <+> cannot be used for a named step.`),r.name!==void 0&&Ht(n);let f=r.name===void 0?void 0:n.getId();d.kind!==`Assert`&&(c=void 0);let p=l(d,i,u);if(p!==void 0)return r.name!==void 0&&U(n,Zt(n,{defKind:`NumberedProofStep`,name:r.name,location:t.Jn(n.file,i),labels:Ut(n),step:p})),p;let m=d.kind===`Assert`&&d.statement.kind===`AssumeProve`;m&&(c=void 0);let h=d.kind===`Assert`&&d.isSuffices,g=t.un(),_=d.kind===`Assert`?(e=>{if(e.kind===`AssumeProve`){let t=W(n,g,()=>lr(n,e,1,r.name===void 0?void 0:{isSuffices:h}));return t.isSuffices=h,t}if(h){let r=q(n,e);return K(n,`$Suffices`,[r],t.Jn(n.file,u))}let i=s.get(r),a=i!==void 0&&c!==void 0,o=a?q(n,i.right):void 0,l=a?$t(n,rn(n,i.operator,Gt(n.file,e)),[K(n,`$Nop`,[c],Gt(n.file,i.at)),o],Gt(n.file,e)):q(n,e);return c=l.kind===`OpAppl`?l.operands[1]:void 0,l})(d.statement):fr(n,d,u);if(_===void 0)throw new e.et(`Unexpected proof step ${d.kind}`);let v=d.kind===`Pick`?n.contexts.pop():void 0,y=r.name===void 0||f===void 0?void 0:ur(n,f,r.name,_,t.Xn(n.file,t.Yn(n.file,r.location)),Ut(n));y&&U(n,y);let b=m&&!h;b&&n.contexts.push(g);let x=r.proof&&pr(n,r.proof);b&&n.contexts.pop(),Wt(n,_),m&&h&&(o.push(g),n.contexts.push(g));for(let e of v?.symbols??[])U(n,e);return{...H(n.getId()),kind:`Theorem`,definition:y,body:_,proof:x,isSuffices:h,location:t.Jn(n.file,i)}});for(let e of o)for(let e of n.contexts.pop()?.symbols??[])t.ln(i,e);return n.contexts.pop(),{...H(n.getId()),kind:`NonLeafProof`,steps:u,instances:a,proofLevel:r.level,location:qt(n.file,r.location)}},mr=(e,n)=>{let r=qt(e.file,n.location),i=n.statement,a=t.un();n.name!==void 0&&Ht(e);let o=n.name===void 0?void 0:e.getId();i.kind===`AssumeProve`&&e.contexts.push(a);let s=i.kind===`AssumeProve`?lr(e,i,1,n.name===void 0?void 0:{isSuffices:!1}):q(e,i),c=n.name===void 0||o===void 0?void 0:ur(e,o,n.name,s,r,Ut(e));c&&(i.kind===`AssumeProve`&&e.contexts.pop(),U(e,c),e.currentModule.definitions.push(c),i.kind===`AssumeProve`&&e.contexts.push(a));let l=n.proof&&pr(e,n.proof);i.kind===`AssumeProve`&&e.contexts.pop(),Wt(e,s);let u={...H(e.getId()),kind:`Theorem`,definition:c,body:s,proof:l,isSuffices:!1,location:r};e.currentModule.topLevel.push(u)},hr=(e,t)=>{let n=qt(e.file,t.location);t.name!==void 0&&Ht(e);let r=q(e,t.expression),i=t.name===void 0?void 0:ur(e,e.getId(),t.name,r,n,Ut(e),!1);i&&(U(e,i),e.currentModule.definitions.push(i));let a={...H(e.getId()),kind:`Assume`,definition:i,body:r,location:n};e.currentModule.topLevel.push(a)},gr=e=>e.kind===`OpDef`||e.kind===`FormalParam`?`definition`:`declaration`,_r=(e,t)=>{e.push(t);for(let n of t.substitutions)J(e,n.expression)},J=(e,n)=>{if(n.kind===`Let`){for(let r of[...n.definitions,...n.instances??[]].sort((e,n)=>t.kt(e.location,n.location)))vr(e,r);return J(e,n.body)}let r=t.ar(n);for(let t=0;t<r.length;t++)J(e,r[t])},vr=(e,n)=>{if(n.kind===`Instance`)return _r(e,n);for(let r of t.or(n))J(e,r)},yr=(e,t)=>{let n=t=>{t.kind!==`ModuleFact`&&J(e,t)};for(let e of t.facts)n(e);for(let e of t.defs)n(e)},br=(e,t)=>{if(t.kind===`NewSymbol`)t.set&&J(e,t.set);else{if(t.kind!==`AssumeProve`)return J(e,t);for(let n of t.assumptions)br(e,n);br(e,t.conclusion)}},xr=(e,t)=>{switch(t.kind){case`Use`:case`Hide`:return yr(e,t);case`Instance`:return _r(e,t);case`Define`:for(let n of t.definitions)vr(e,n);return;case`Have`:case`Case`:return J(e,t.expression);case`Witness`:for(let n of t.expressions)J(e,n);return;case`Take`:for(let n of t.bounds)J(e,n.set);return;case`Pick`:for(let n of t.bounds)J(e,n.set);return J(e,t.body);case`Assert`:return br(e,t.statement);case`Qed`:return}},Sr=(e,t)=>{if(t?.kind===`By`)return yr(e,t);if(t?.kind===`Steps`)for(let n of t.steps)xr(e,n.body),Sr(e,n.proof)},Cr=(e,n)=>{let r=/* @__PURE__ */ new Set;for(let t of e.units)if(t.kind===`Module`&&r.add(t.module.name),t.kind===`Instance`&&t.instance.module===n.module)return r.has(n.module);return e.modules.some(e=>e.name===n.module&&t.Gt(e.location,n.location))},wr=e=>{let t=[],n=[],r=/* @__PURE__ */ new Map,i=(e,a)=>{let o=(t,n)=>{for(let i of t)n.push(i),r.has(i)||r.set(i,e.name)},s=e=>!a.has(e);o(e.extends.filter(s),t);let c=[];for(let t of e.units)t.kind===`Instance`?_r(c,t.instance):t.kind===`Definition`?vr(c,t.definition):t.kind===`Theorem`?(br(c,t.theorem.statement),Sr(c,t.theorem.proof)):t.kind===`Assumption`?J(c,t.assumption.expression):t.kind===`Use`&&yr(c,t.use);o(c.filter(t=>s(t.module)&&!Cr(e,t)).map(e=>e.module),n);let l=new Map(a);for(let t of e.modules){let e=new Map(l),n=/* @__PURE__ */ new Set,r=t=>{if(!n.has(t)){n.add(t);for(let n of t.extends){let t=e.get(n);if(t!==void 0){for(let n of t.modules)e.has(n.name)||e.set(n.name,n);r(t)}}}};r(t),i(t,e),l.set(t.name,t)}};return i(e,/* @__PURE__ */ new Map),{extendees:t,instancees:n,importers:r}},Tr=(n,r,i={})=>{let a=[],o=(e,n)=>t.cn(a,{location:e,text:n,isWarning:!1}),s=(e,n)=>t.cn(a,{location:e,text:n,isWarning:!0}),c=i.version===`1.7.4`?-1:0,l=()=>++c,u=0;i.version!==`1.7.4`&&Tt(l);let d=Tt(l);l();let f=new Map(d.map(e=>[e.name,e])),p=/* @__PURE__ */ new Map,m=/* @__PURE__ */ new Map,h=(n,r)=>{let a=n===i.rootFileName&&i.rootFilePath||`${n}.tla`,o=t=>new e.K(`Could not parse module ${n} from file ${a}`,n,t),s=i.version===`1.7.4`?t.gr(r):void 0;if(s!==void 0)throw o(s);let c=i.parsedSources?.get(n);if(c?.text===r)return c;try{let e=t.tr(r);return{module:t.jn(r,e),tokens:e}}catch(n){throw n instanceof e.et?o(t.Pn(r)??`***Parse Error***\n${n.message}`):n}},g=(n,r,a)=>{let o=m.get(n);if(o)return o;if(r===void 0)throw new e.V(n,a,i.version!==`1.7.4`);i.onParse?.(n);let s=h(n,r),c=s.module;if(c.name!==n)throw new e.K(`File name '${n}' does not match the name '${c.name}' of the top level module it contains.`,void 0);let l={file:t.zn(c.name,r,s.tokens),text:r,tokens:s.tokens,module:c,dependencies:E(n,c)};return m.set(n,l),l},_=[],v=/* @__PURE__ */ new Set,y=[],b=(t,n,i)=>{let a=y.indexOf(t);if(a!==-1)throw new e.K(`Circular dependency among .tla files; dependency cycle is:\n\n ${[...y.slice(a),t].map(e=>`${e}.tla`).join(` --> `)}`,void 0);if(v.has(t))return;v.add(t),y.push(t);let o=g(t,n,i).dependencies;for(let e of[...o.extendees,...o.instancees])b(e,r(e),t);y.pop(),_.push(t)},x=/* @__PURE__ */ new Set,S=(e,t)=>x.has(`${e} ${t}`),C=(e,t,n)=>{let r=m.get(e);if(!r||n.has(e))return;n.add(e);let i=r.dependencies,a=i[t].find(t=>!S(e,t));if(a!==void 0)return{name:a,importer:e,namingModule:i.importers.get(a)??e};for(let r of[...i.extendees,...i.instancees]){let i=S(e,r)?C(r,t,n):void 0;if(i)return i}},w=e=>{g(e,n);let t=()=>C(e,`extendees`,/* @__PURE__ */ new Set)??C(e,`instancees`,/* @__PURE__ */ new Set);for(let e=t();e!==void 0;e=t())m.has(e.name)||g(e.name,r(e.name),e.namingModule),x.add(`${e.importer} ${e.name}`)},T=i.rootFileName??h(``,n).module.name,E=(e,t)=>{let n=wr(t);if(e!==T||i.rootExtendees===void 0)return n;n.extendees.splice(t.extends.length,0,...i.rootExtendees);for(let t of i.rootExtendees)n.importers.has(t)||n.importers.set(t,e);return n};w(T),b(T,n);let D=/* @__PURE__ */ new WeakMap,O=/* @__PURE__ */ new WeakMap,k=(e,n,r,a,c={sectionCount:0,unresolvedCount:[0],unresolvedSum:0})=>{let d={kind:`Module`,id:l(),name:e.name,location:qt(n,e.location),extendees:[],context:Lt(a),constantDecls:void 0,variableDecls:void 0,opDefs:void 0,thmOrAssDefs:void 0,topLevel:[],definitions:[],opDefsInRecursiveSection:[],isLevelChecked:!1,levelCorrect:!0,argLevelParams:/* @__PURE__ */ new Map,levelConstraints:/* @__PURE__ */ new Map,argLevelConstraints:/* @__PURE__ */ new Map,records:[]};r&&r.definitions.push(d);let m={version:i.version,addError:o,addWarning:s,getId:l,builtinsByName:f,externalModules:p,nullApplicationId:u,file:n,contexts:a,currentModule:d,curLevel:0,recursion:c,functions:[],exceptStack:[],exceptSpecStack:[],labelScopes:[],assumeContexts:/* @__PURE__ */ new WeakSet,assumeProveState:{depth:0,isDeclared:[],goal:void 0,goalClause:0},assumeProveScopes:D,labelGoals:O,recursiveDeclarations:[],generateLet:e=>tr(m,e),selectorToNode:It({version:i.version,resolveSymbol:e=>Rt(a,e),resolveSynonym:t.Ln,generateExpression:e=>q(m,e),generateArgument:(e,t,n,r)=>Cn(m,e,t,n,r),createOpAppl:(e,t,n)=>{let r=$t(m,e,t,n);return an(m,e,t,n),r},createOpArg:(e,t)=>nn(m,e,t),createFormalParam:(e,t,n)=>Xt(m,e,t,n,!1),createLambda:(e,r,i)=>Zt(m,{name:`LAMBDA`,params:e,body:r,location:i,preComments:t.Kn(n,t.Yn(n,{line:i.beginLine,column:i.beginColumn}))}),copySubstIn:(e,t)=>Wn(m,`SubstIn`,e.substs,t,e.instantiatedModule,e.location,e.instantiatingModule),getBuiltin:e=>en(m,e),addError:(e,t)=>(o(e,t),G(m)),isOutOfLabelScope:e=>{let t=m.labelGoals.get(e);return t!==void 0&&t.scope.isDeclaredBefore[t.clause]&&t.scope.isSuffices===t.scope.isInProof},isOutOfClauseScope:(e,t)=>{let n=m.assumeProveScopes.get(e);return n!==void 0&&n.isDeclaredBefore[t-1]&&(!n.hasGoal||n.isSuffices===n.isInProof)}})};for(let n of e.extends){let e=Yt(m,n);d.extendees.push(e);let r=Lt(a);for(let n of e.context.symbols){if(n.kind!==`Module`&&n.kind!==`FormalParam`&&n.kind!==`OpDecl`&&n.isLocal)continue;let e=n.kind===`Module`?t.fn(r,n.name):t.pn(r,n.name);e===void 0?t.ln(r,n):e!==n&&e.kind!==n.kind?o(n.location,`The ${gr(n)} of '${n.name}' conflicts with \nits ${gr(e)} at ${t.dn(e.location)}.`):e!==n&&!Bt(e,n)&&s(n.location,`Warning: the ${gr(e)} of '${n.name}' conflicts with \nits ${gr(e)} at ${t.dn(e.location)}.`)}for(let t of e.topLevel)d.topLevel.push(t)}for(let r of e.units)switch(r.kind){case`Variables`:$n(m,r.location,`A VARIABLE declaration`);for(let e of r.declarations)Qn(m,e,3);break;case`Constants`:$n(m,r.location,`A declaration`);for(let e of r.declarations)Qn(m,e,2);break;case`Recursive`:Bn(m,r.declarations);break;case`Definition`:r.definition.kind===`Function`?zn(m,r.definition,void 0):Ln(m,r.definition,void 0);break;case`Instance`:r.instance.name===void 0?Yn(m,r.instance):qn(m,r.instance,void 0,void 0);break;case`Assumption`:$n(m,r.assumption.location,`An ASSUME`),hr(m,r.assumption);break;case`Theorem`:$n(m,r.theorem.location,`A THEOREM`),mr(m,r.theorem);break;case`Use`:$n(m,r.use.location,`A USE or HIDE`),d.topLevel.push(sr(m,r.use));break;case`Module`:{$n(m,r.module.location,`A MODULE `);let e=k(r.module,n,d,[...a,t.un()],m.recursion);for(let t of e.opDefsInRecursiveSection)d.opDefsInRecursiveSection.push(t);let i=Jt(m,e.name);i===void 0?t.ln(Lt(a),e):i!==e&&o(e.location,`Multiply-defined module '${e.name}': this definition or declaration conflicts \nwith the one at ${t.dn(i.location)}.`);break}}return Vn(m),d};return{sources:_.map(e=>g(e,void 0)),generate:()=>{let e=_.map(e=>{i.onAnalyze?.(e),u=Array.from({length:4},l)[1];let n=g(e,void 0),r=t.un();for(let e of d.toReversed())t.ln(r,e);let o=k(n.module,n.file,void 0,[r]);return p.set(e,o),i.onModule?.(o,a),o});return{root:e[e.length-1],modules:e,messages:a}}}},Y=(e,n,r,i)=>t.cn(e.messages,{location:n,text:r,isWarning:!1,...i!==void 0&&!e.isTlc174&&{code:i}}),X=(e,t)=>{for(let n of t)e.add(n)},Er=(e,t,n)=>`${e.id}:${t}:${n.id}`,Dr=(e,t,n,r)=>{e.set(Er(t,n,r),{op:t,index:n,param:r})},Or=(e,t,n=()=>!0)=>{for(let[r,i]of t)n(i)&&e.set(r,i)},kr=(e,t,n)=>{e.set(t,Math.min(n,e.get(t)??3))},Ar=(e,t,n=()=>!0)=>{for(let[r,i]of t)n(r)&&kr(e,r,i)},jr=(e,t)=>`${e.id}:${t}`,Mr=(e,t,n,r)=>{let i=jr(t,n),a=e.get(i)?.level??0;e.set(i,{param:t,position:n,level:Math.max(r,a)})},Nr=(e,t,n=()=>!0)=>{for(let r of t.values())n(r)&&Mr(e,r.param,r.position,r.level)},Pr=(e,t)=>{let n;for(let r of t){let t=jr(r.param,r.position);(n??e.requiredLeibnizArgs).has(t)||(n??=new Map(e.requiredLeibnizArgs),n.set(t,r))}n&&(e.requiredLeibnizArgs=n)},Fr=(e,t)=>{e.levelParams=t.levelParams,e.allParams=t.allParams,e.appliedParams=t.appliedParams,e.requiredLeibnizArgs=t.requiredLeibnizArgs,e.levelConstraints=t.levelConstraints,e.argLevelConstraints=t.argLevelConstraints,e.argLevelParams=t.argLevelParams},Ir=(e,t)=>{X(e.levelParams,t.levelParams),X(e.allParams,t.allParams),Ar(e.levelConstraints,t.levelConstraints),Nr(e.argLevelConstraints,t.argLevelConstraints),Or(e.argLevelParams,t.argLevelParams)},Lr=(e,t)=>t.includes(e.op)||t.includes(e.param),Rr=e=>e.kind===`OpDecl`||e.kind===`FormalParam`,zr=e=>e.kind!==`Module`,Br=e=>e.kind===`OpDef`||e.kind===`ThmOrAssumpDef`,Vr=(e,t)=>e.kind===`OpDef`&&e.arity<0?0:t,Hr=(e,t)=>e.weights[Vr(e,t)]??0,Ur=(e,t)=>e.maxLevels[Vr(e,t)]??3,Wr=(e,t,n)=>e.minMaxLevel?.[t]?.[n]??0,Gr=(e,t)=>e.kind===`OpDef`?e.isLeibnizArg?.[Vr(e,t)]??!0:e.isLeibnizArg[t]??!0,Kr=(e,t)=>{let n=e.params?.[Vr(e,t)];return n===void 0||e.appliedParams===void 0?Hr(e,t)===1:e.appliedParams.has(n)},qr=(e,t)=>(e.appliedParams??e.levelParams).has(t),Jr=e=>e.appliedParams!==void 0,Yr=e=>{let t=e.operator,n=[...e.ranges];for(let[r,i]of e.operands.entries())i!==void 0&&(!Br(t)||Kr(t,r))&&n.push(i);if(!n.some(Jr)&&!(Br(t)&&Jr(t))){e.appliedParams=void 0;return}let r=/* @__PURE__ */ new Set;if(Br(t)){let e=t.params??[];for(let n of t.appliedParams??t.levelParams)e.includes(n)||r.add(n)}else e.levelParams.has(t)&&r.add(t);for(let e of n)X(r,e.appliedParams??e.levelParams);for(let t of ni(e))r.delete(t);e.appliedParams=r},Xr=e=>{let t=e.body;if(!Jr(t)&&!e.substs.some(e=>Jr(e.expr)))return;let n=/* @__PURE__ */ new Set;for(let r of t.appliedParams??t.levelParams)ri(r,e.substs)===void 0&&n.add(r);for(let r of e.substs)qr(t,r.op)&&X(n,r.expr.appliedParams??r.expr.levelParams);return n},Zr=e=>e.kind===`FormalParam`||e.kind===`OpDecl`||e.kind===`OpDef`&&e.defKind===`BuiltIn`,Qr=e=>{switch(e.kind){case`Numeral`:case`String`:case`Decimal`:case`At`:return!0;case`Label`:return Qr(e.body);case`OpArg`:return Zr(e.op);case`OpAppl`:return Zr(e.operator)&&e.operands.every(e=>e===void 0||Qr(e))&&e.ranges.every(Qr);default:return!1}},$r=e=>{let t=e.flatMap(e=>[...e.allParams]);for(let n of e){let e=n.body;e!==void 0&&(n.appliedParams=new Set(Qr(e)?e.appliedParams??e.levelParams:[...n.params??[],...t]))}},ei=(e,t)=>e.kind===`OpArg`&&t&&e.op.kind!==`Module`?e.op.nonLeibnizParams:e.nonLeibnizParams,ti=(e,t,n,r)=>e.opLevelCond?.[t]?.[n]?.[r]??!1,ni=e=>[...e.unbounded??[],...(e.bounded??[]).flat()],ri=(e,t)=>t.find(t=>t.op===e)?.expr,ii=(e,t,n)=>{X(e.nonLeibnizParams,ei(n.expr,qr(t,n.op))),e.nonLeibnizParams.has(n.op)&&(e.nonLeibnizParams.delete(n.op),X(e.nonLeibnizParams,n.expr.allParams))},ai=(e,t)=>{if(t.op.arity<=0||t.expr.kind!==`OpArg`)return[];let n=t.expr.op,r={module:e.name,constant:t.op.name};if(Rr(n))return Array.from({length:n.arity},(e,t)=>({...r,param:n,position:t}));if(!Br(n))return[];let i=n.params??[];return[...n.argLevelParams.values()].flatMap(e=>i.includes(e.param)&&Rr(e.op)?[{...r,param:e.op,position:e.index}]:[])},oi=(e,t,n)=>{let r=ri(e,t);return r===void 0?/* @__PURE__ */ new Set([e]):n?r.allParams:r.levelParams},si=(e,t)=>{let n=/* @__PURE__ */ new Map;for(let[r,i]of e){let e=ri(i.op,t);if(e===void 0){n.set(r,i);continue}if(e.kind!==`OpArg`||!Rr(e.op))continue;let a=e.op;for(let e of oi(i.param,t,!1))Dr(n,a,i.index,e)}return n},ci=(e,t,n,r,i)=>{let a=/* @__PURE__ */ new Map;for(let[r,i]of e.levelConstraints){let e=n||r.kind!==`OpDecl`?i:r.declKind===2?0:r.declKind===3?1:i;for(let n of oi(r,t,!1))kr(a,n,e)}for(let n of e.argLevelParams.values()){let e=ri(n.op,t);if(e?.kind!==`OpArg`||e.op.kind!==`OpDef`)continue;Z(e.op,r,i);let o=Ur(e.op,n.index);for(let e of oi(n.param,t,!1))kr(a,e,o)}return a},li=(e,t,n,r)=>{let i=/* @__PURE__ */ new Map;for(let n of e.argLevelConstraints.values()){let e=ri(n.param,t);e===void 0?Mr(i,n.param,n.position,n.level):e.kind===`OpArg`&&Rr(e.op)&&Mr(i,e.op,n.position,n.level)}for(let a of e.argLevelParams.values()){let e=ri(a.param,t);if(e===void 0)continue;let o=ri(a.op,t),s=o===void 0?a.op:o.kind===`OpArg`?o.op:void 0;s!==void 0&&Rr(s)&&(Z(e,n,r),Mr(i,s,a.index,e.level))}return i},ui=(e,n)=>t.mn(e,3).length>0||(bi(e,n),t.gn(e).some(e=>(e.body?.level??0)!==0))?!1:e.topLevel.every(e=>e.kind!==`Theorem`||e.level===0),di=(e,t,n)=>{e.minMaxLevel=t.map(e=>Array.from({length:e.arity},(t,r)=>n.argLevelConstraints.get(jr(e,r))?.level??0)),e.opLevelCond=t.map(e=>t.map(t=>Array.from({length:e.arity},(r,i)=>n.argLevelParams.has(Er(e,i,t))))),X(e.levelParams,n.levelParams),X(e.allParams,n.allParams),X(e.nonLeibnizParams,n.nonLeibnizParams),e.appliedParams=e.kind===`OpDef`&&e.recursiveSection>=0?void 0:n.appliedParams;for(let n=0;n<t.length;n++){let r=t[n];e.levelParams.delete(r),e.allParams.delete(r),e.nonLeibnizParams.has(r)&&(e.nonLeibnizParams.delete(r),e.isLeibnizArg&&(e.isLeibnizArg[n]=!1),e.isLeibniz=!1)}Pr(e,n.requiredLeibnizArgs.values()),e.levelConstraints=new Map(n.levelConstraints);for(let n of t)e.levelConstraints.delete(n);e.argLevelConstraints=new Map(n.argLevelConstraints);for(let n of t)for(let t=0;t<n.arity;t++)e.argLevelConstraints.delete(jr(n,t));Or(e.argLevelParams,n.argLevelParams,e=>!t.some(t=>t===e.op)||!t.some(t=>t===e.param))},fi=(e,n,r,i,a)=>{for(let[o,s]of e.operands.entries()){if(s===void 0||(s.level>Ur(n,o)&&(r&&Z(s,i,a)&&Y(a,e.location,`Level error in applying operator ${n.name}:\nThe level of argument ${o+1} exceeds the maximum level allowed by the operator.`),e.levelCorrect=!1),s.kind!==`OpArg`||!Br(s.op)))continue;let c=s.op;Z(c,i,a);let l=t._n(c);for(let t=0;t<l;t++){let l=Wr(n,o,t);Ur(c,t)>=l||(r&&Z(s,i,a)&&Y(a,e.location,`Level error in applying operator ${n.name}:\nThe permitted level of argument ${t+1} of the operator argument ${o+1} \nmust be at least ${l}.`),e.levelCorrect=!1)}for(let[t,r]of e.operands.entries())for(let u=0;u<l;u++)r===void 0||!ti(n,o,t,u)||r.level<=Ur(c,u)||(Z(s,i,a)&&Z(r,i,a)&&Y(a,e.location,`Level error in applying operator ${n.name}:\nThe level of argument ${t+1} exceeds the maximum level allowed by the operator.`,`HIGHER_ORDER_OPERATOR_COPARAMETER_LEVEL_CONSTRAINTS_EXCEEDED`),e.levelCorrect=!1)}for(let[r,o]of e.ranges.entries()){let s=Z(o,i,a);o.level<=2||(s&&Y(a,e.location,`Level error in applying operator ${n.name}:\nThe level of the range for the bounded variable ${t.dn(e.bounded?.[r]?.[0]?.location)} \nexceeds the maximum level allowed by the operator.`),e.levelCorrect=!1)}},pi=(e,n,r,i,a)=>{let o=n.params??[],s=t=>e.operands.find((e,n)=>o[n]===t);Ar(e.levelConstraints,n.levelConstraints);for(let t of e.operands)t!==void 0&&Ar(e.levelConstraints,t.levelConstraints,e=>!r.has(e));for(let t of e.ranges)Ar(e.levelConstraints,t.levelConstraints);for(let[t,r]of e.operands.entries()){let i=Ur(n,t);for(let t of r?.levelParams??[])kr(e.levelConstraints,t,i)}for(let[r,o]of e.operands.entries()){if(o?.kind!==`OpArg`||!Br(o.op))continue;let s=o.op;Z(s,i,a);let c=t._n(s);for(let[t,i]of e.operands.entries())for(let a=0;a<c;a++){if(!ti(n,r,t,a))continue;let o=Ur(s,a);for(let t of i?.levelParams??[])kr(e.levelConstraints,t,o);!s.isLeibniz&&!Gr(s,a)&&i&&X(e.nonLeibnizParams,i.allParams)}}for(let t of n.argLevelParams.values()){let n=s(t.op);n?.kind===`OpArg`&&Br(n.op)&&(Z(n.op,i,a),kr(e.levelConstraints,t.param,Ur(n.op,t.index)))}Nr(e.argLevelConstraints,n.argLevelConstraints);for(let t of e.operands)t&&Nr(e.argLevelConstraints,t.argLevelConstraints);for(let t of e.ranges)Nr(e.argLevelConstraints,t.argLevelConstraints);for(let[t,r]of e.operands.entries()){if(r?.kind!==`OpArg`||!Rr(r.op))continue;let i=r.op;for(let r=0;r<i.arity;r++)Mr(e.argLevelConstraints,i,r,Wr(n,t,r));for(let[r,a]of e.operands.entries())for(let o=0;o<i.arity;o++)a!==void 0&&ti(n,t,r,o)&&Mr(e.argLevelConstraints,i,o,a.level)}for(let t of n.argLevelParams.values()){let n=s(t.param);n!==void 0&&(Z(n,i,a),Mr(e.argLevelConstraints,t.op,t.index,n.level))}for(let t of e.operands)t!==void 0&&Or(e.argLevelParams,t.argLevelParams,e=>!r.has(e.param));for(let t of e.ranges)Or(e.argLevelParams,t.argLevelParams);for(let[t,r]of n.argLevelParams){let n=s(r.op);if(n===void 0){let n=s(r.param);if(n===void 0)e.argLevelParams.set(t,r);else{Z(n,i,a);for(let t of n.levelParams)Dr(e.argLevelParams,r.op,r.index,t)}}else n.kind===`OpArg`&&Rr(n.op)&&Dr(e.argLevelParams,n.op,r.index,r.param)}for(let[t,r]of e.operands.entries()){if(r?.kind!==`OpArg`||!Rr(r.op))continue;let i=r.op;for(let[r,a]of e.operands.entries())for(let o=0;o<i.arity;o++)if(a!==void 0&&ti(n,t,r,o))for(let t of a.levelParams)Dr(e.argLevelParams,i,o,t)}},mi=(e,t,n)=>{let r=t.params??[];for(let i of t.requiredLeibnizArgs.values()){let t=r.indexOf(i.param);if(t===-1){Pr(e,[i]);continue}let a=e.operands[t];if(a?.kind!==`OpArg`)continue;let o=a.op;if(Rr(o)){Pr(e,[{...i,param:o}]);continue}if(!Br(o))continue;if(!Gr(o,i.position)){Y(n,e.location,`Error in instantiating module '${i.module}':\n A non-Leibniz operator substituted for '${i.constant}'.`);continue}let s=o.params?.[i.position];for(let t of o.argLevelParams.values())t.param===s&&Rr(t.op)&&Pr(e,[{...i,param:t.op,position:t.index}])}for(let t of e.operands)t&&Pr(e,t.requiredLeibnizArgs.values());for(let t of e.ranges)Pr(e,t.requiredLeibnizArgs.values())},hi=/* @__PURE__ */ new Map([[`\\land`,`\\land`],[`\\lor`,`\\lor`],[`=>`,`=>`],[`\\equiv`,`\\equiv`],[`$ConjList`,`Conjunction list`],[`$DisjList`,`Disjunction list`]]),gi=(e,t)=>{let n=(n,r)=>{Y(t,n,r),t.isTlc174||(e.levelCorrect=!1)},r=e.operator.name,i=e.operands[0];if((r===`[]`||r===`<>`)&&i?.level===2&&i.kind===`OpAppl`){let t=r===`[]`;i.operator.name!==(t?`$SquareAct`:`$AngleAct`)&&n(e.location,t?`[] followed by action not of form [A]_v.`:`<> followed by action not of form <<A>>_v.`)}r!==`~>`&&r!==`-+->`||i?.level!==2&&e.operands[1]?.level!==2||n(e.location,`Action used where only temporal formula or state predicate allowed.`);let a=hi.get(r);if(a!==void 0&&e.operands.some(e=>e?.level===3)&&e.operands.some(e=>e?.level===2)&&n(e.location,`${a} has both temporal formula and action as arguments.`),e.level===3&&(r===`$BoundedExists`||r===`$BoundedForall`))for(let t of e.ranges)t.level===2&&n(t.location,`Action-level bound of quantified temporal formula.`)},_i=(e,t,n)=>{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t,e.levelCorrect=!0;let r=e.operands.filter(e=>e!==void 0);for(let i of r)Z(i,t,n)||(e.levelCorrect=!1);for(let r of e.ranges)Z(r,t,n)||(e.levelCorrect=!1);let i=e.operator;if(Br(i)){let r=Z(i,t,n);fi(e,i,r,t,n),e.level=e.operands.reduce((e,t,n)=>t!==void 0&&Hr(i,n)===1?Math.max(e,t.level):e,i.level);for(let t of e.ranges)e.level=Math.max(e.level,t.level);X(e.levelParams,i.levelParams),X(e.allParams,i.allParams),X(e.nonLeibnizParams,i.nonLeibnizParams);for(let[t,n]of e.operands.entries())n!==void 0&&(Hr(i,t)===1&&X(e.levelParams,n.levelParams),X(e.allParams,n.allParams),X(e.nonLeibnizParams,ei(n,Kr(i,t))),Gr(i,t)||X(e.nonLeibnizParams,n.allParams));for(let t of e.ranges)X(e.levelParams,t.levelParams),X(e.allParams,t.allParams),X(e.nonLeibnizParams,t.nonLeibnizParams);let a=new Set(ni(e));for(let t of a)e.levelParams.delete(t),e.allParams.delete(t),e.nonLeibnizParams.delete(t);pi(e,i,a,t,n),mi(e,i,n)}else{Z(i,t,n),e.level=r.reduce((e,t)=>Math.max(e,t.level),i.kind===`Module`?0:i.level),e.levelParams=/* @__PURE__ */ new Set([i]),e.allParams.add(i);for(let t=0;t<r.length;t++){let n=r[t];X(e.levelParams,n.levelParams),X(e.allParams,n.allParams),X(e.nonLeibnizParams,n.nonLeibnizParams),Pr(e,n.requiredLeibnizArgs.values()),Ar(e.levelConstraints,n.levelConstraints),Mr(e.argLevelConstraints,i,t,n.level),Nr(e.argLevelConstraints,n.argLevelConstraints);for(let r of n.levelParams)Dr(e.argLevelParams,i,t,r);Or(e.argLevelParams,n.argLevelParams)}}return Yr(e),gi(e,n),e.levelCorrect},vi=(e,t,n)=>{if(e.levelChecked>=t||!e.inRecursiveSection&&e.levelChecked>0)return e.levelCorrect;e.levelChecked=t;let r=e.body;if(r===void 0)return e.levelCorrect=e.step===void 0||Z(e.step,t,n),e.levelCorrect;e.levelCorrect=Z(r,t,n),e.level=Math.max(e.level,r.level);let i=e.params??[];for(let t=0;t<i.length;t++){let n=i[t],a=r.levelConstraints.get(n);a!==void 0&&(e.maxLevels[t]=Math.min(e.maxLevels[t],a)),r.levelParams.has(n)&&(e.weights[t]=Math.max(e.weights[t],1))}return di(e,i,r),e.levelCorrect},yi=(e,t,n)=>{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t,e.maxLevels=e.params.map(()=>3),e.weights=e.params.map(()=>0),e.isLeibnizArg=e.params.map((t,n)=>n===e.params.length-1),e.params.length>0&&(e.isLeibniz=!0),e.levelCorrect=Z(e.body,t,n),e.level=e.body.level;for(let[t,n]of e.params.entries()){let r=e.body.levelConstraints.get(n);r!==void 0&&(e.maxLevels[t]=r),e.body.levelParams.has(n)&&(e.weights[t]=1)}return di(e,e.params,e.body),e.levelCorrect},bi=(e,n)=>{if(e.isLevelChecked)return e.levelCorrect;e.isLevelChecked=!0;let r=e.opDefsInRecursiveSection,i=0;for(;i<r.length;){let e=r[i].recursiveSection,t=i;for(;t<r.length&&r[t].recursiveSection===e;){let e=r[t];e.inRecursive?(e.levelChecked=1,e.maxLevels=e.maxLevels.map(()=>2),e.weights=e.weights.map(()=>1)):e.levelChecked=0,t++}let a=r.slice(i,t),o=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Set,c=0;for(let e of a)if(e.inRecursive&&(e.levelChecked=0),vi(e,1,n),e.inRecursive){for(let[t,r]of e.maxLevels.entries())r>=2||Y(n,e.location,`Argument ${t+1} of recursive operator ${e.name} is primed`);c=Math.max(c,e.level),X(o,e.levelParams),X(s,e.allParams)}for(let e of a)e.inRecursive&&(e.levelChecked=2),e.level=Math.max(e.level,c),X(e.levelParams,o),X(e.allParams,s);for(let e of a)e.inRecursive&&(e.levelChecked=1),vi(e,2,n);$r(a),i=t}e.levelCorrect=!0;let a=t=>{t||(e.levelCorrect=!1)};for(let t of e.definitions.filter(e=>e.kind===`Module`))a(bi(t,n));let o=t.gn(e);for(let e of o)a(vi(e,1,n));for(let r of t.vn(e))a(yi(r,1,n));for(let t of e.topLevel)a(Z(t,1,n));if(!ui(e,n))for(let n of t.mn(e,2))kr(e.levelConstraints,n,0);for(let t of o)Ar(e.levelConstraints,t.levelConstraints),Nr(e.argLevelConstraints,t.argLevelConstraints),Or(e.argLevelParams,t.argLevelParams,e=>!Lr(e,t.params??[]));for(let t of e.topLevel)Ar(e.levelConstraints,t.levelConstraints),Nr(e.argLevelConstraints,t.argLevelConstraints),Or(e.argLevelParams,t.argLevelParams);return e.levelCorrect},xi=(e,t,n,r)=>{if(e.levelChecked>=n)return e.levelCorrect;e.levelChecked=n;for(let i of t)zr(i)&&(i.kind!==`OpDef`||i.defKind!==`ModuleInstance`)&&(e.levelCorrect=Z(i,n,r)&&e.levelCorrect,e.level=Math.max(e.level,i.level),Ir(e,i),X(e.nonLeibnizParams,i.nonLeibnizParams));return e.levelCorrect},Si=(e,t)=>{if(e?.kind===`NonLeafProof`)for(let n of e.steps){if(n.kind!==`Theorem`||n.body.kind!==`OpAppl`)continue;let e=n.body.operator.name;e===`$Take`||e===`$Witness`||e===`$Have`?n.body.level!==0&&Y(t,n.body.location,`Non-constant TAKE, WITNESS, or HAVE for temporal goal.`):e===`$Pfcase`?(n.body.level!==0&&Y(t,n.body.location,`Non-constant CASE for temporal goal.`),Si(n.proof,t)):e===`$Qed`&&Si(n.proof,t)}},Ci=(e,t,n)=>{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t,e.levelParams=/* @__PURE__ */ new Set,e.levelCorrect=!0;let r=e.module;bi(r,n)||(e.levelCorrect=!1);for(let r of e.substs)Z(r.expr,t,n)||(e.levelCorrect=!1);let i=ui(r,n);for(let a of e.substs)!i&&a.expr.level>a.op.level&&(Z(a.expr,t,n)&&Y(n,e.location,`Level error in instantiating module '${r.name}':\nThe level of the expression or operator substituted for '${a.op.name}' \nmust be at most ${a.op.level}.`),e.levelCorrect=!1),a.expr.kind!==`OpArg`||(a.expr.op.kind!==`OpDef`||a.expr.op.defKind!==`UserDefined`&&a.expr.op.defKind!==`BuiltIn`)&&a.expr.op.kind!==`ThmOrAssumpDef`||a.expr.op.isLeibniz||Y(n,e.location,`Error in instantiating module '${r.name}':\n A non-Leibniz operator substituted for '${a.op.name}'.`);for(let i of e.substs){let a=r.levelConstraints.get(i.op);if(a!==void 0&&i.expr.level>a&&(Z(i.expr,t,n)&&Y(n,e.location,`Level error in instantiating module '${r.name}':\nThe level of the expression or operator substituted for '${i.op.name}' \nmust be at most ${a}.`),e.levelCorrect=!1),i.op.arity<=0||i.expr.kind!==`OpArg`||i.expr.op.kind!==`OpDef`)continue;let o=i.expr.op,s=Z(o,t,n);for(let t=0;t<i.op.arity;t++){let a=r.argLevelConstraints.get(jr(i.op,t))?.level;a===void 0||Ur(o,t)>=a||(s&&Y(n,e.location,`Level error in instantiating module '${r.name}':\nThe level of the argument ${t+1} of the operator ${o.name} \nmust be at least ${a}.`),e.levelCorrect=!1)}}for(let i of r.argLevelParams.values())for(let a of e.substs)for(let o of e.substs){if(i.op!==a.op||i.param!==o.op||a.expr.kind!==`OpArg`)continue;let s=a.expr.op,c=Z(s,t,n);if(s.kind!==`OpDef`)continue;let l=Ur(s,i.index);o.expr.level<=l||(c&&Z(o.expr,t,n)&&Y(n,e.location,`Level error when instantiating module '${r.name}':\nThe level of the argument ${i.index} of the operator ${a.op.name}' \nmust be at most ${l}.`),e.levelCorrect=!1)}let a=t=>!e.params.some(e=>e===t);Ar(e.levelConstraints,ci(r,e.substs,i,t,n),a);for(let t of e.substs)Ar(e.levelConstraints,t.expr.levelConstraints,a);Nr(e.argLevelConstraints,li(r,e.substs,t,n),e=>a(e.param));for(let t of e.substs)Nr(e.argLevelConstraints,t.expr.argLevelConstraints,e=>a(e.param));Or(e.argLevelParams,si(r.argLevelParams,e.substs),t=>!Lr(t,e.params));for(let t of e.substs)Or(e.argLevelParams,t.expr.argLevelParams,t=>!Lr(t,e.params));return e.levelCorrect},Z=(e,t,n)=>{if(!zr(e))return bi(e,n);switch(e.kind){case`OpAppl`:return _i(e,t,n);case`OpDef`:return vi(e,t,n);case`ThmOrAssumpDef`:return yi(e,t,n);case`FormalParam`:return e.levelChecked===0&&(e.levelChecked=t,e.levelParams.add(e),e.allParams.add(e)),!0;case`OpDecl`:return!0;case`Numeral`:case`String`:case`Decimal`:return e.levelChecked<t&&(e.levelChecked=t),!0;case`OpArg`:{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t;let r=e.op;return e.levelCorrect=Z(r,t,n),r.kind===`Module`||(e.level=r.level,Fr(e,r)),e.levelCorrect}case`LetIn`:{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t,e.levelCorrect=!0;let r=e.opDefs.filter(e=>e.kind!==`OpDef`||e.defKind!==`ModuleInstance`);for(let i of r)Z(i,t,n)||(e.levelCorrect=!1);Z(e.body,t,n)||(e.levelCorrect=!1);for(let r of e.instances)Z(r,t,n)||(e.levelCorrect=!1);e.level=e.body.level,e.levelParams=new Set(e.body.levelParams),e.allParams=new Set(e.body.allParams),e.appliedParams=e.body.appliedParams,e.nonLeibnizParams=new Set(e.body.nonLeibnizParams),Pr(e,e.body.requiredLeibnizArgs.values());for(let t of r){let n=t.params??[];Pr(e,[...t.requiredLeibnizArgs.values()].filter(e=>!n.includes(e.param)))}Ar(e.levelConstraints,e.body.levelConstraints);for(let t of r)Ar(e.levelConstraints,t.levelConstraints);Nr(e.argLevelConstraints,e.body.argLevelConstraints);for(let t of r)Nr(e.argLevelConstraints,t.argLevelConstraints);Or(e.argLevelParams,e.body.argLevelParams);for(let t of r){let n=t.kind===`OpDef`?t.params??[]:[];Or(e.argLevelParams,t.argLevelParams,e=>!Lr(e,n))}for(let t of e.instances)Or(e.argLevelParams,t.argLevelParams);return e.levelCorrect}case`Label`:{if(e.levelChecked>=t)return!0;e.levelChecked=t;for(let r of e.params)Z(r,t,n);let r=Z(e.body,t,n);return e.level=e.body.level,Fr(e,e.body),e.nonLeibnizParams=e.body.nonLeibnizParams,r}case`At`:{if(e.levelChecked>=t)return!0;e.levelChecked=t;let r=e.except.operands,i=r[0];if(i===void 0)return!0;Z(i,t,n),e.level=i.level;let a=[i];for(let i=1;i<r.length;i++){let o=r[i];if(o!==void 0){if(Z(o,t,n),o===e.component)break;e.level=Math.max(e.level,o.level),a.push(o)}}for(let t of a)Ir(e,t);return!0}case`SubstIn`:case`APSubstIn`:{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t,e.levelCorrect=!0;let r=e.body;Z(r,t,n)||(e.levelCorrect=!1);for(let r of e.substs)Z(r.expr,t,n)||(e.levelCorrect=!1);e.level=e.substs.reduce((e,t)=>r.levelParams.has(t.op)?Math.max(e,t.expr.level):e,r.level);for(let t of r.levelParams)X(e.levelParams,oi(t,e.substs,!1));if(e.appliedParams=Xr(e),e.kind===`APSubstIn`){for(let t of r.allParams)X(e.allParams,oi(t,e.substs,!0));e.nonLeibnizParams=new Set(r.nonLeibnizParams);for(let t of e.substs)r.allParams.has(t.op)&&ii(e,r,t)}else{e.allParams=new Set(r.allParams),e.nonLeibnizParams=new Set(r.nonLeibnizParams);for(let t of e.substs)e.allParams.has(t.op)&&(e.allParams.delete(t.op),X(e.allParams,t.expr.allParams),ii(e,r,t))}Pr(e,[...r.requiredLeibnizArgs.values()].filter(t=>ri(t.param,e.substs)===void 0));for(let t of e.substs)Pr(e,t.expr.requiredLeibnizArgs.values()),Pr(e,ai(e.instantiatedModule,t));let i=ui(e.instantiatedModule,n);return e.levelConstraints=ci(r,e.substs,i,t,n),e.argLevelConstraints=li(r,e.substs,t,n),e.argLevelParams=si(r.argLevelParams,e.substs),e.levelCorrect}case`Instance`:return Ci(e,t,n);case`Assume`:{if(e.levelChecked>=t)return!0;e.levelChecked=t;let r=Z(e.body,t,n),i=!e.definition||Z(e.definition,t,n);return e.level=e.body.level,Fr(e,e.body),e.level!==0&&Y(n,e.location,`Level error: assumptions must be level 0 (Constant), \nbut this one has level ${e.level}.`),r&&i}case`Theorem`:{if(e.levelChecked>=t)return!0;let r=xi(e,[e.definition??e.body,...e.proof?[e.proof]:[]],t,n),i=e.body;if(i.kind===`OpAppl`&&i.operator.name===`$Pick`&&i.level===3)for(let e of i.ranges)e.level!==0&&Y(n,e.location,`Non-constant bound of temporal PICK.`);return i.level===3&&Si(e.proof,n),r}case`LeafProof`:case`UseOrHide`:return xi(e,e.facts,t,n);case`NonLeafProof`:return xi(e,[...e.steps,...e.instances],t,n);case`DefStep`:return xi(e,e.defs,t,n);case`NewSymb`:return e.levelChecked>=t||(e.levelChecked=t,e.level=e.declaration.level,e.set===void 0)||(e.levelCorrect=Z(e.set,t,n),e.level=Math.max(e.level,e.set.level),e.level===3&&(e.levelCorrect=!1,Y(n,e.location,`Level error:
25
25
  Temporal formula used as set.`)),Fr(e,e.set),e.nonLeibnizParams=e.set.nonLeibnizParams),e.levelCorrect;case`AssumeProve`:{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t,e.levelCorrect=!0;for(let r of e.assumptions)Z(r,t,n)||(e.levelCorrect=!1);Z(e.goal,t,n),e.level=e.assumptions.reduce((e,t)=>Math.max(e,t.level),e.goal.level);let r=[e.goal,...e.assumptions];for(let t of r)Ir(e,t),X(e.nonLeibnizParams,t.nonLeibnizParams);if(r.some(Jr)){let t=/* @__PURE__ */ new Set;for(let e of r)X(t,e.appliedParams??e.levelParams);e.appliedParams=t}if(e.levelCorrect)for(let t of e.levelParams)t.kind===`OpDecl`&&t.declKind===2&&kr(e.levelConstraints,t,2);return e.levelCorrect}}},wi=e=>{switch(e.kind){case`OpAppl`:return[...e.ranges,...e.operands];case`OpDef`:case`ThmOrAssumpDef`:case`Label`:return[e.body];case`LetIn`:return[...e.opDefs,...e.instances,e.body];case`SubstIn`:case`APSubstIn`:return[e.body,...e.substs.map(e=>e.expr)];case`Instance`:return e.substs.map(e=>e.expr);case`AssumeProve`:return[...e.assumptions,e.goal];case`NewSymb`:return[e.set];default:return[]}},Ti=/* @__PURE__ */ new Map([[`Integers`,`Int`],[`Naturals`,`Nat`],[`Reals`,`Reals`]]),Ei=e=>{let t=/* @__PURE__ */ new Set,n=e=>{if(e===void 0||t.has(e))return!1;if(t.add(e),e.kind===`OpAppl`){let t=e.operator;if(t.kind===`OpDecl`||t.kind===`FormalParam`)return!0;if(t.kind===`OpDef`){if(t.name===`BOOLEAN`)return!0;let e=t.module?.name;if(e!==void 0&&Ti.get(e)===t.name||n(t))return!0}}return wi(e).some(n)};return n(e)},Di=e=>e.operands.filter(e=>e?.kind===`OpAppl`),Oi=e=>{let t=e.operands[0];return t?.kind===`String`?t:void 0},ki=e=>JSON.stringify([e.operands.length,...Di(e).map(e=>Oi(e)?.value).sort()]),Ai=(e,t=/* @__PURE__ */ new Set)=>{for(let n of e.extendees)t.has(n)||(t.add(n),Ai(n,t));return t},ji=e=>{let n=e.records.map(n=>({domain:ki(n),warnings:Di(n).flatMap(n=>{let r=Oi(n),i=r&&t.pn(e.context,r.value);return r===void 0||i===void 0?[]:[{location:r.location,text:`The field name "${r.value}" in the record constructor is identical to the existing definition or declaration\nnamed ${r.value}, located at ${t.dn(i.location)}.\nThe field in the record will not take the value of the ${r.value} definition or declaration.\nIn TLA+, field names in records are strings, regardless of any similarly named declarations or definitions.\nTherefore, DOMAIN [${r.value} |-> ...] = {"${r.value}"} holds true.`,isWarning:!0}]})})),r=new Set(n.flatMap(e=>e.warnings.length>0?[e.domain]:[])),i=/* @__PURE__ */ new Set;for(let t of[...[...Ai(e)].flatMap(e=>e.records),...e.records]){let e=ki(t);r.has(e)&&!i.has(e)&&Di(t).some(Ei)&&i.add(e)}return n.flatMap(e=>i.has(e.domain)?[]:e.warnings)},Mi=e=>[...e.constants.map(e=>e.name),...e.variables.map(e=>e.name),...e.definitions.map(e=>e.name),...e.instances.flatMap(e=>e.name??[]),...e.assumptions.flatMap(e=>e.name??[]),...e.theorems.flatMap(e=>e.name??[]),...e.units.flatMap(e=>e.kind===`Recursive`?e.declarations.map(e=>e.name):[]),...e.modules.flatMap(e=>[e.name,...Mi(e)])],Ni=e=>[...e.recordFields,...e.modules.flatMap(Ni)],Pi=e=>`kind`in e&&(e.kind===`Record`||e.kind===`RecordSet`)&&`fields`in e,Fi=e=>`kind`in e&&(e.kind===`Operator`||e.kind===`Function`)&&`name`in e&&typeof e.name==`string`,Ii=e=>{let n=[],r=[],i=[],a=[],o=e=>{for(let t of e){t.name!==void 0&&i.push(t.name);for(let e of t.substitutions)a.push(e.expression)}},s=e=>{for(let n of e)r.push(n),i.push(n.name),a.push(...t.or(n))},c=[];for(let t of e.units)t.kind===`Definition`&&s([t.definition]),t.kind===`Instance`&&o([t.instance]),t.kind===`Assumption`&&a.push(t.assumption.expression),(t.kind===`Theorem`||t.kind===`Use`)&&c.push(t);let l=/* @__PURE__ */ new Set;for(;c.length>0;){let e=c.pop();typeof e==`object`&&e&&!l.has(e)&&(l.add(e),Pi(e)&&n.push(e),Fi(e)&&(r.push(e),i.push(e.name)),`kind`in e&&e.kind===`Instance`&&`name`in e&&typeof e.name==`string`&&i.push(e.name),c.push(...Object.values(e)))}for(;a.length>0;){let e=a.pop();e!==void 0&&((e.kind===`Record`||e.kind===`RecordSet`)&&n.push(e),e.kind===`Let`?(s(e.definitions),o(e.instances??[]),a.push(e.body)):a.push(...t.ar(e)))}return{records:n,definitions:r,names:i}},Li=e=>JSON.stringify([e.fields.length,...e.fields.map(e=>e.name).sort()]),Ri=(e,n)=>{let r=e.map(e=>({module:e.module,dependencies:[...e.dependencies.extendees,...e.dependencies.instancees],imports:[...e.module.extends,...e.module.instances.flatMap(e=>e.name===void 0?[e.module]:[])],names:Mi(e.module)})),i=new Map(r.map(e=>[e.module.name,e])),a=(e,t)=>{let n=/* @__PURE__ */ new Set([e]);for(let e of n)for(let r of t(e)){let e=i.get(r);e!==void 0&&n.add(e)}return[...n]},o=Ct.map(e=>e[0]);return r.every(e=>{if(!n.has(e.module.name))return!0;let r=Ni(e.module);if(r.length===0)return!0;let i=a(e,e=>e.dependencies),s=/* @__PURE__ */ new Set([...o,...i.flatMap(e=>e.names)]);if(!r.some(e=>s.has(e)))return!0;let c=Ii(e.module),l=new Set(c.records.flatMap(e=>e.fields.some(e=>s.has(e.name))?[Li(e)]:[]));if(l.size===0)return!0;for(let e of c.names)s.add(e);let u=new Set(a(e,e=>e.module.extends).flatMap(e=>[...e.module.constants,...e.module.variables].map(e=>e.name))),d=a(e,e=>e.imports),f=/* @__PURE__ */ new Map;for(let e of[...d.flatMap(e=>e.module.definitions),...c.definitions]){let t=f.get(e.name);f.set(e.name,f.has(e.name)&&t!==e?void 0:e)}let p=new Set(d.flatMap(e=>e.module.definitions.filter(t=>Ti.get(e.module.name)===t.name))),m=e=>{let n=/* @__PURE__ */ new Set,r=[e];for(;r.length>0;){let e=r.pop();if(e!==void 0&&e.kind!==`Lambda`&&e.kind!==`OperatorReference`&&e.kind!==`Subexpression`&&e.kind!==`Selection`){if(e.kind===`Let`){for(let t of e.definitions)s.add(t.name);for(let t of e.instances??[])t.name!==void 0&&s.add(t.name)}if(e.kind===`Identifier`||e.kind===`Apply`){let i=e.kind===`Identifier`?e.name:e.operator;if(i===`BOOLEAN`||u.has(i)||!s.has(i)&&/^\w+$/.test(i))return!0;let a=f.get(i);if(a!==void 0&&p.has(a))return!0;a!==void 0&&!n.has(a)&&(n.add(a),r.push(...t.or(a)))}r.push(...t.ar(e))}}return!1};return[...l].every(e=>c.records.some(t=>Li(t)===e&&t.fields.some(e=>m(e.value))))})},zi=e=>`${t.dn(e.location)}\n\n${e.text}`,Bi=e=>{let t=e.filter(e=>!e.isWarning),n=e.filter(e=>e.isWarning);return[t.length>0?`*** Errors: ${t.length}\n\n`:``,...t.map(e=>`${zi(e)}\n\n\n`),n.length>0?`*** Warnings: ${n.length}\n\n`:``,...n.map(e=>`${zi(e)}\n\n\n`)].join(``)},Vi=4802,Hi=/* @__PURE__ */ new Set([`FiniteSets`,`Sequences`,`Bags`,`Naturals`,`Integers`,`Reals`,`RealTime`,`Randomization`,`TLC`]),Ui=e=>{let t=/* @__PURE__ */ new Set,n=[],r=e=>{t.add(e.name),n.push(...e.extends);for(let t of e.modules)r(t)};return r(e),n.filter(e=>!t.has(e))},Wi=n=>{try{let e=t.tr(n);return{text:n,module:t.jn(n,e),tokens:e}}catch(t){if(t instanceof e.et)return;throw t}},Gi=(e,n)=>n===`1.7.4`&&t.gr(e)!==void 0?void 0:Wi(e)?.module.name,Ki=(n,i,a={})=>{let s=(0,c.basename)(n,`.tla`),l=r.i(a.version),u=a.fileName??s,d=a.rootSource!==void 0||o.t.existsSync(n),f=a.rootSource??(o.t.existsSync(n)?o.t.readFileSync(n,`utf8`):l.get(s)),p=[],m=e=>{p.push(e),a.onPrint?.(e)},h=e=>m(`${e}\n`),g=a.version===`1.7.4`,_=g&&a.isXmlExport,v=e=>{a.isXmlExport||h(e)},y=a.describeFile,x=/* @__PURE__ */ new Map([[s,d?`file`:`standard`]]),S=!1,C=[],w=!1,T=!1,E=Te(b(),h),D=/* @__PURE__ */ new Map,O=[],k=()=>{for(let e of O.splice(0))e.isError?a.onPrintError?.(`${e.text}\n`):h(e.text)},A=e=>{let t=D.get(e),n=t?.module.location.range;if(t===void 0||n===void 0)return;let r=t.text.split(/\r\n|\r|\n/),i=St(E,r.slice(n.start.line-1,n.end.line),a.version),o=i.has(`TLA_DIVERGENCE_EXISTS`),s=i.has(`PCAL_DIVERGENCE_EXISTS`),c=o===s?void 0:`The ${o?`TLA+ translation`:`PlusCal algorithm`} in module ${e} has changed since its last translation.`;if(g){let t=o&&s?`The PlusCal algorithm and its TLA+ translation in module ${e} filename since the last translation.`:c;t===void 0?i.has(`ERROR_ENCOUNTERED`)&&O.push({text:`A unexpected problem was encountered attempting to validate the specification for ${e}`,isError:!0}):O.push({text:`!! WARNING: ${t}`,isError:!1});return}let l=o&&s?`Both the PlusCal algorithm and its TLA+ translation in module ${e} have changed since the last translation.`:c??(i.has(`ERROR_ENCOUNTERED`)?`An unexpected problem was encountered attempting to validate the specification for ${e}`:void 0);if(l===void 0)return;let u=!i.has(`ERROR_ENCOUNTERED`)||o||s;C.some(e=>e.text===l)||C.push({location:e,text:l,isWarning:u})},j=(e,t)=>{if(a.isXmlExport||D.has(e))return;let n=Wi(t);if(n===void 0||n.module.name!==e)return;let r=[...D.values()].filter(t=>Ui(t.module).includes(e));D.set(e,n);for(let t of r)A(e);for(let t of Ui(n.module).filter(t=>t!==e&&D.has(t)))A(t)},ee=()=>{if(k(),w)return;w=!0;let e=C.filter(e=>e.isWarning);if(e.length>0){v(`Warnings (${e.length}) during syntax parsing of ${u}:\n\n`);for(let t of e)v(`${zi(t)}\n\n\n`)}e.length!==C.length&&(h(Bi(C)),S=!0,T=!0)},te=e=>{let n=l.get(e),r=i(e),a=r===void 0&&n===void 0&&f!==void 0&&!g?t.wn(f,e):void 0,o=r??a;return x.set(e,r===void 0?a===void 0?`standard`:`root file`:`file`),o!==void 0&&j(e,o),o??n},ne=t=>{if(S=!0,t instanceof e.l){h(`\nFatal errors while parsing TLA+ spec in file ${u}\n`),h(t.message),h(Bi(C));return}if(!(t instanceof e.K))throw t;let n={location:t.location,text:t.message,isWarning:!1},r=g&&t.parseError?.includes(` and token "" `);t.parseError!==void 0&&!r&&!_&&h(t.parseError),h(`\nFatal errors while parsing TLA+ spec in file ${u}\n`),r?h(`java.lang.NullPointerException: Cannot invoke "String.length()" because "str" is null`):g?(h(`tla2sany.semantic.AbortException`),m(`*** Abort messages: 1\n\n${zi(n)}\n\n\n`)):(h(zi(n)),h(Bi(w?[n]:[...C,n])))},re=e=>{ee(),(y||_)&&!T&&h(`Semantic processing of module ${e}`)},M=(()=>{try{if(f===void 0)throw new e.K(`Cannot find source file for module ${u}`,void 0);return j(s,f),Tr(f,te,{rootFileName:s,rootFilePath:a.isXmlExport?`${u.replace(/\.tla$/,``)}.tla`:void 0,version:a.version,rootExtendees:a.rootExtendees,parsedSources:D,onParse:e=>{y&&h(`Parsing file ${y(e,x.get(e)??`file`)}`),e===s&&A(s),k()},onAnalyze:re,onModule:(e,t)=>{if(T||(t.every(e=>e.isWarning)&&bi(e,{messages:t,isTlc174:g}),t.length===0))return;if(t.some(e=>!e.isWarning)&&(S=!0),g)return h(`Semantic errors:\n\n${Bi(t)}`);let n=t.filter(e=>e.isWarning);if(n.length>0){v(`*** Warnings: ${n.length}\n`);for(let e of n)v(`${zi(e)}\n\n\n`)}let r=t.filter(e=>!e.isWarning);if(r.length!==0){h(`Semantic errors:\n\n*** Errors: ${r.length}\n`);for(let e of r)h(`${zi(e)}\n\n`)}}})}catch(e){ne(e);return}})(),ie=()=>M?.sources.flatMap(e=>Hi.has(e.module.name)?[]:[e.module.name])??[],N=!1;return{isAcceptable:M!==void 0&&!S&&!a.isXmlExport&&!g&&C.every(e=>e.isWarning)&&Ri(M.sources,new Set(ie())),analyze:()=>{if(N)for(let e of M?.sources??[])e.module=t.jn(e.text,e.tokens);let e=(()=>{try{return M?.generate()}catch(e){ne(e);return}})();if(e!==void 0&&ee(),e!==void 0&&!S&&!a.isXmlExport&&!g){let t=e.modules.filter(e=>!Hi.has(e.name));if(y)for(let e of t)h(`Linting of module ${e.name}`);let n=a.suppressedCodes?.includes(Vi)?[]:t.flatMap(ji),r=a.errorCodes?.includes(Vi)?`Warning treated as error: `:``;for(let e of n)h(`${r}${zi(e)}\n\n\n`);r&&n.length>0&&(S=!0)}return{text:p.join(``),isFailed:S,specification:T?void 0:e}},accept:()=>{for(let e of M?.sources??[])re(e.module.name);if(ee(),y)for(let e of ie())h(`Linting of module ${e}`)},shareModules:()=>(N=!0,new Map(M?.sources.map(e=>[e.text,e])))}},qi=e=>e.kind===`OpDef`&&e.defKind!==`BuiltIn`&&e.defKind!==`ModuleInstance`,Ji=(e,t)=>e.context.symbols.find(e=>qi(e)&&e.name===t),Yi=t=>e.Ft(new e.D(`Parsing or semantic analysis failed.Parsing or semantic analysis failed.${t}`),e.Et.specParseError),Xi=(n,r,i,a,o,s)=>{let c=e=>Yi(`Unknown location\n\n${e} while parsing breakpoint expression "${a}"`);try{t.kn(n)}catch(t){throw t instanceof e.et?Yi(`Syntax error while parsing breakpoint expression "${a}"`):t}let l=!1,u=!1,d=(()=>{try{return Tr(n,o,{version:s,onModule:(e,t)=>{let n=()=>t.every(e=>e.isWarning);if(!n())return;let i=bi(e,{messages:t,isTlc174:s===`1.7.4`});e.name===r&&(l=!0,u=i&&n())}}).generate()}catch(t){throw t instanceof e.et?c(`Semantic error`):t}})();if(!l)throw c(`Semantic error`);if(!u)throw c(`Level-checking error`);let f=Ji(d.root,i)?.level??0;if(f===3)throw Yi(`Unknown location\n\nDebug expressions must be action-level or below; actual level: ${f} (Temporal)`)},Zi=(e,t,n,r,i)=>{let a=n=>n===t.name?e:r(n),o=Date.now();return n.map((e,n)=>{if(Ji(t,e.expression))return{name:e.expression,module:void 0,source:void 0};let r=`__DebuggerModule__${o+n}`,s=`__DebuggerExpr__${o+n}`,c=`---- MODULE ${r} ----\nEXTENDS ${t.name}\n\n${s} == ${e.expression}\n====`;return Xi(c,r,s,e.expression,a,i),{name:s,module:r,source:c}})},Qi=(1n<<63n)-1n,$i=[[-123456,-123456],[-1,0],[1e3,1003],[1005,1005],[1101,1102],[2e3,2001],[2100,2149],[2154,2274],[2279,2287],[2300,2301],[2400,2405],[2501,2502],[2772,2780],[3e3,3002],[3100,3114],[4e3,4002],[5001,5007],[7e3,7010],[2e4,2e4]],ea=[[4003,4005],[4200,4206],[4220,4224],[4240,4247],[4260,4262],[4270,4275],[4290,4294],[4310,4315],[4330,4337],[4350,4357]],ta=/* @__PURE__ */ new Map([[4800,`EXTENDED_MODULES_SYMBOL_UNIFICATION_AMBIGUITY`],[4801,`INSTANCED_MODULES_SYMBOL_UNIFICATION_AMBIGUITY`],[4802,`RECORD_CONSTRUCTOR_FIELD_NAME_CLASH`],[4803,`PLUSCAL_ALGORITHM_AND_TRANSLATION_CHANGED_SINCE_LAST_TRANSLATION`],[4804,`PLUSCAL_ALGORITHM_CHANGED_SINCE_LAST_TRANSLATION`],[4805,`PLUSCAL_TRANSLATION_CHANGED_SINCE_LAST_TRANSLATION`]]),na=(e,t,n,r)=>({module:e,constant:n,operators:[{kind:`postcondition`,operator:t}],communityModule:r}),ra={json:na(`_JsonTrace`,`_JsonTrace`,`_JsonTraceFile`,void 0),tla:na(`_TLAPlusCounterExample`,`_TLAPlusCounterExample`,`_TLAPlusCounterExampleFile`,`IOUtils`),tlc:na(`_TLCTrace`,`_TLCTrace`,`_TLCTraceFile`,void 0),tlcplain:na(`_TLCTracePlain`,`_TLCTrace`,`_TLCTraceFile`,`IOUtils`),tlcTESpec:na(`_TLCTESpec`,`_TLCTrace`,`_TLCTraceFile`,`IOUtils`),tlcaction:na(`_TLCActionTrace`,`_TLCTrace`,`_TLCTraceFile`,`IOUtils`),dot:na(`_DotTrace`,`_DotTrace`,`_DotTraceFile`,`GraphViz`),cbor:na(`_CBORTrace`,`_CBORTrace`,`_CBORTraceFile`,`CBOR`)},ia=(e,t)=>({module:e,constant:`${t}InputFile`,operators:[{kind:`constraint`,operator:`${t}Constraint`},{kind:`view`,operator:`${t}View`}],communityModule:void 0}),aa={tlc:ia(`_TLCTrace`,`_TLCTrace`),json:ia(`_JsonTrace`,`_JsonTrace`)},oa=(e,t)=>e.some(e=>t>=e[0]&&t<=e[1]),sa=(e,t)=>{if(e===``)return[e];let n=e.split(t);for(;n.at(-1)===``;)n.pop();return n},ca=(e,t)=>[...new Set(e.filter(e=>t.includes(e)))].sort((e,t)=>e-t),la=/\p{Nd}/u,ua=e=>{let t=0;for(;la.test(String.fromCharCode(e-t-1));)t++;return t%10},da=(e,t)=>{let n=e.replace(/\p{Nd}/gu,e=>e.length===1?String(ua(e.charCodeAt(0))):e);if(!/^[+-]?\d+$/.test(n))return;let r=BigInt(n);return BigInt.asIntN(t,r)===r?r:void 0},fa=()=>({specs:[],configPath:void 0,seed:void 0,aril:0n,workers:void 0,coverage:void 0,livenessCheck:`default`,dump:void 0,fingerprintIndex:void 0,maxSetSize:void 0,isLazyValueExpanded:!0,isViewPrinted:!1,isFramePrinted:!1,isShared:!1,metadir:void 0,recoverDirectory:void 0,isCheckpointRequested:!1,mode:`model-check`,dfidDepth:void 0,traceDepth:100,traceCount:void 0,scheduler:`random`,actionStatistics:void 0,behaviorFile:void 0,isTool:!1,isContinued:!1,isDeadlockChecked:!0,isWarningEnabled:!0,isTraceSpecForced:!1,isTraceSpecDisabled:!1,isTraceBinaryDisabled:!1,traceSpecPath:void 0,isDiffTrace:!1,suppressedCodes:[],errorCodes:[],userFile:void 0,invariants:[],moduleOperators:[],communityTraceModules:[]}),pa={"-modelcheck":()=>{},"-difftrace":e=>{e.isDiffTrace=!0},"-deadlock":e=>{e.isDeadlockChecked=!1},"-cleanup":()=>{},"-frame":e=>{e.isFramePrinted=!0},"-shared":e=>{e.isShared=!0},"-nowarning":e=>{e.isWarningEnabled=!1},"-gzip":()=>{},"-terse":e=>{e.isLazyValueExpanded=!1},"-continue":e=>{e.isContinued=!0},"-view":e=>{e.isViewPrinted=!0},"-debug":()=>{},"-tool":e=>{e.isTool=!0}},ma=(e,t,n)=>(r,i)=>{let a=da(i,e);return a===void 0?`${t} But encountered ${i}`:n(r,a,i)},ha=(e,t,n,r)=>({missing:t,apply:ma(32,n,(t,n)=>{let i=BigInt.asIntN(32,n*60000n);if(i<0n)return`Error: expect a nonnegative integer for -${e} option.`;r(t,Number(i)/6e4)})}),ga={"-teSpecOutDir":{missing:`Error: expected a path for -teSpecOutDir option.`,apply:(e,t)=>{e.traceSpecPath=t}},"-userFile":{missing:`Error: need to specify the full qualified file.`,apply:(t,n)=>{try{o.t.closeSync(o.t.openSync(n,`w`))}catch(t){if(e.vt(t)===void 0)throw t;return`Error: Failed to create user output log file.`}t.userFile=n}},"-lncheck":{missing:`Error: expect a strategy such as final for -lncheck option.`,apply:(e,t)=>{e.livenessCheck=t.toLowerCase()}},"-config":{missing:`Error: expect a file name for -config option.`,apply:(e,t)=>{let n=t.replace(/\.cfg$/,``);e.configPath=n.endsWith(`.tla`)?n:`${n}.cfg`}},"-coverage":ha(`coverage`,`Error: coverage report interval required.`,`Error: An integer for coverage report interval required.`,(e,t)=>{e.coverage=t}),"-checkpoint":ha(`checkpoint`,`Error: checkpoint interval required.`,`Error: An integer for checkpoint interval is required.`,(e,t)=>{e.isCheckpointRequested=t>0}),"-depth":{missing:`Error: trace length required.`,apply:ma(32,`Error: An integer for trace length required.`,(e,t)=>{e.traceDepth=Number(t)})},"-seed":{missing:`Error: seed required.`,apply:ma(64,`Error: An integer for seed required.`,(e,t)=>{e.seed=t})},"-aril":{missing:`Error: aril required.`,apply:ma(64,`Error: An integer for aril required.`,(e,t)=>{e.aril=t})},"-maxSetSize":{missing:`Error: maxSetSize required.`,apply:ma(32,`Error: An integer for maxSetSize required.`,(e,t,r)=>{if(t<1n)return`Error: Value in interval [0, ${n.on}] for maxSetSize required. But encountered ${r}`;e.maxSetSize=Number(t)})},"-recover":{missing:`Error: need to specify the metadata directory for recovery.`,apply:(e,t)=>{e.recoverDirectory=t}},"-metadir":{missing:`Error: need to specify the metadata directory.`,apply:(e,t)=>{e.metadir=t}},"-workers":{missing:`Error: expect an integer or 'auto' for -workers option.`,apply:(e,t)=>{let n=t.trim().toLowerCase()===`auto`?BigInt((0,u.availableParallelism)()):da(t,32);if(n===void 0)return`Error: worker number or 'auto' required. But encountered ${t}`;if(n<1n)return`Error: at least one worker required.`;e.workers=Number(n)}},"-dfid":{missing:`Error: expect a nonnegative integer for -dfid option.`,apply:ma(32,`Error: expect a nonnegative integer for -dfid option.`,(e,t)=>{if(t<0n)return`Error: expect a nonnegative integer for -dfid option.`;e.dfidDepth=Number(t)})},"-fp":{missing:`Error: expect an integer for -fp option.`,apply:ma(32,`Error: A number for -fp is required.`,(e,t)=>{if(t<0n||t>=131)return`Error: The number for -fp must be between 0 and 130 (inclusive).`;e.fingerprintIndex=Number(t)})},"-fpmem":{missing:`Error: fpset memory size required.`,apply:(e,n)=>{let r=t.o(n);if(r===void 0||r<0||Number.isNaN(r))return`Error: An positive integer or a fraction for fpset memory size/percentage required. But encountered ${n}`;r>1&&process.stdout.write(`Using -fpmem with an abolute memory value has been deprecated. Please allocate memory for the TLC process via the JVM mechanisms and use -fpmem to set the fraction to be used for fingerprint storage.
26
- `)}},"-fpbits":{missing:`Error: fpbits required.`,apply:ma(32,`Error: An integer for fpbits required.`,(e,t,n)=>t<0n||t>30n?`Error: Value in interval [0, 30] for fpbits required. But encountered ${n}`:void 0)}},_a={"-loadtrace":{name:`-loadTrace`,missing:`Error: A format and a file name for loading traces required.`,formats:aa},"-dumptrace":{name:`-dumpTrace`,missing:`Error: A format and a file name for dumping traces required.`,formats:ra}},va=e=>{let t=fa(),n=0,r=e=>({kind:`command-line`,error:e,isTool:t.isTool}),i=()=>({kind:`uncaught`,error:`java.lang.ArrayIndexOutOfBoundsException: Index ${e.length} out of bounds for length ${e.length}`,isTool:t.isTool}),a={tlc:[],sany:[]},o={tlc:[],sany:[]},s=()=>e[n],c=()=>e[n++];for(;n<e.length;){let l=c();if(Object.hasOwn(pa,l))pa[l](t);else if(Object.hasOwn(ga,l)){let e=c();if(e===void 0)return r(ga[l].missing);let n=ga[l].apply(t,e);if(n!==void 0)return r(n)}else if(l===`-simulate`||l===`-generate`){t.mode=l===`-generate`?`generate`:`simulate`;let e=s();if(e===void 0||![`stats=`,`file=`,`num=`,`sched`].some(t=>e.includes(t)))continue;n++;let i=e.split(`,`),a=i.findLast(e=>e.startsWith(`file=`));a!==void 0&&(t.behaviorFile=a.replaceAll(`file=`,``)),i.includes(`sched=rl`)?t.scheduler=`rl`:i.includes(`sched=rlaction`)&&t.scheduler!==`rl`&&(t.scheduler=`rlaction`);let o=i.findLast(e=>e===`stats=basic`||e===`stats=full`);o!==void 0&&(t.actionStatistics=o===`stats=basic`?`basic`:`full`);for(let e of i.filter(e=>e.startsWith(`num=`))){let n=e.replaceAll(`num=`,``);if(t.traceCount=da(n,64),t.traceCount===void 0)return{kind:`uncaught`,error:`java.lang.NumberFormatException: For input string: "${n}"`,isTool:t.isTool}}if((t.traceCount??Qi)===Qi&&t.behaviorFile!==void 0)return r(`Error: You need to specify a 'num' argument when using the 'file' argument, for example: '"num=5,file=test.txt"'.`)}else if(l===`-suppressMessages`||l===`-messagesAsErrors`){let e=c();if(e===void 0)return r(`Error: ${l} requires a comma-separated list of message codes.`);let t=l===`-suppressMessages`?a:o;for(let n of sa(e,`,`)){let e=n.replace(/^[^!-\uffff]+|[^!-\uffff]+$/g,``),i=da(e,32);if(i===void 0)return r(`Error: For input string: "${e}"`);let o=Number(i);if(oa($i,o))t.tlc.push(o);else{if(!ta.has(o)&&!oa(ea,o))return r(`Error: unknown message code: ${o}`);if(t===a&&!ta.has(o))return r(`Error: code ${o} is an error and cannot be suppressed.`);t.sany.push(o)}}}else if(l===`-inv`){let e=c();if(e===void 0)return i();t.invariants.push({modules:[...new Set([...e.matchAll(/INSTANCE\s+(\w+)/g)].map(e=>e[1]))],expression:e})}else if(l===`-invlevel`){let e=c();if(e===void 0)return i();if(da(e,32)===void 0)return r(`Error: An integer for -invlevel required. But encountered ${e}`);t.invariants.push({modules:[`TLC`,`Naturals`],expression:`LET _T == INSTANCE TLC _N == INSTANCE Naturals IN _N!<(_T!TLCGet("level"), ${e})`})}else if(l===`-debugger`){let e=s();e!==void 0&&[`port=`,`nosuspend`,`nohalt`,`suspend`,`halt`].some(t=>e.includes(t))&&n++}else if(l===`-generateSpecTE`)t.isTraceSpecForced=!0,s()===`nomonolith`&&n++;else if(l===`-noGenerateSpecTE`||l.toLowerCase()===`-note`)t.isTraceSpecDisabled=!0;else if(l===`-noGenerateSpecTEBin`||l.toLowerCase()===`-notebin`)t.isTraceBinaryDisabled=!0;else{if(l===`-help`||l===`-h`)return`usage`;if(l===`-dump`){let i=s();if(i?.startsWith(`class,`))return r(`Trying to instantiate a custom IStateWriter implementation ${i.replaceAll(`class,`,``)}.`);let a=i?.startsWith(`dot`)&&n+1<e.length?2:1;if(t.dump=e.slice(n,n+a),n+=a,t.dump.length===0)return r(`Error: A file name for dumping states required.`)}else if(Object.hasOwn(_a,l.toLowerCase())){let i=_a[l.toLowerCase()];if(n+1>=e.length)return r(i.missing);let a=c(),o=c(),s=Object.keys(i.formats).find(e=>e.toLowerCase()===a.toLowerCase());if(s===void 0)return r(`Error: Unknown format ${a} given to ${i.name}.`);let u=i.formats[s];u.communityModule!==void 0&&t.communityTraceModules.push({format:s,module:u.communityModule}),t.moduleOperators.push(...u.operators.map(e=>({...e,module:u.module,constants:{[u.constant]:o}})))}else if(l.toLowerCase()===`-postcondition`){let e=c();if(e===void 0)return r(`Error: Module!Operator for postCondition required.`);if(!e.includes(`!`))return r(`Module!Operator for postCondition required. Encountered: ${e}`);let n=sa(e,`!`);if(n.length!==2)return r(`Module!Operator for postCondition must be of the form module!operator. Encountered: ${e}`);if(n[0]===``)return r(`Module name for postCondition required. Encountered: ${e}`);if(n[0].includes(`.`))return r(`Module name for postCondition must not contain a dot. Encountered: ${n[0]}`);if(n[1].includes(`.`))return r(`Operator name for postCondition must not contain a dot. Encountered: ${n[1]}`);t.moduleOperators.push({kind:`postcondition`,module:n[0],operator:n[1]})}else{if(l.startsWith(`-`))return r(`Error: unrecognized option: ${l}`);t.specs.push(l)}}}if(!t.isWarningEnabled&&a.tlc.length+a.sany.length>0)return r(`Error: -nowarning already suppresses all warnings, making -suppressMessages redundant. Remove -nowarning to suppress only the specified messages, or remove -suppressMessages to suppress all warnings.`);let l=ca(a.tlc,o.tlc),u=l.length>0?l.map(String):ca(a.sany,o.sany).map(e=>ta.get(e)??String(e));return u.length>0?r(`Error: The following codes were set to both -suppressMessages and -messagesAsErrors: [${u.join(`, `)}]`):(t.suppressedCodes=[...a.tlc,...a.sany],t.errorCodes=[...o.tlc,...o.sany],t)},ya=()=>BigInt(Math.floor(Math.random()*2**32)),ba=(e,t)=>({...e,workers:e.workers??t,fingerprintIndex:e.fingerprintIndex??Math.floor(Math.random()*131),seed:e.seed??BigInt.asIntN(64,ya()<<32n|ya()),aril:e.seed===void 0?0n:e.aril});var xa=`0.0.10-dev.a2d447617`;const Sa=(e,t)=>e.print(r.a.computingInitProgress,r.o.none,`Computed ${t} initial states...`),Ca=(e,t)=>e===`invariant-violation`?{code:r.a.invariantViolatedInitial,text:`Invariant ${t} is violated by the initial state:`}:{code:r.a.propertyViolatedInitial,text:`Property ${t} is violated by the initial state:`},Q=(e,t)=>{for(let i of t??[]){if(typeof i==`string`){e.printOutput(i);continue}if(i.kind===`initial-states-progress`){Sa(e,i.count);continue}if(i.kind===`warning`){e.print(i.code,r.o.warning,i.text);continue}if(i.kind===`violation`){Va(i.status,i.violation,e);continue}let t=Ca(i.status,i.name);e.print(t.code,r.o.error,`${t.text}\n${n.Sn(i.state)}`)}},wa={code:r.a.behaviorUpToThisPoint,text:`The behavior up to this point is:`},Ta={code:r.a.counterExample,text:`The following behavior constitutes a counter-example:
26
+ `)}},"-fpbits":{missing:`Error: fpbits required.`,apply:ma(32,`Error: An integer for fpbits required.`,(e,t,n)=>t<0n||t>30n?`Error: Value in interval [0, 30] for fpbits required. But encountered ${n}`:void 0)}},_a={"-loadtrace":{name:`-loadTrace`,missing:`Error: A format and a file name for loading traces required.`,formats:aa},"-dumptrace":{name:`-dumpTrace`,missing:`Error: A format and a file name for dumping traces required.`,formats:ra}},va=e=>{let t=fa(),n=0,r=e=>({kind:`command-line`,error:e,isTool:t.isTool}),i=()=>({kind:`uncaught`,error:`java.lang.ArrayIndexOutOfBoundsException: Index ${e.length} out of bounds for length ${e.length}`,isTool:t.isTool}),a={tlc:[],sany:[]},o={tlc:[],sany:[]},s=()=>e[n],c=()=>e[n++];for(;n<e.length;){let l=c();if(Object.hasOwn(pa,l))pa[l](t);else if(Object.hasOwn(ga,l)){let e=c();if(e===void 0)return r(ga[l].missing);let n=ga[l].apply(t,e);if(n!==void 0)return r(n)}else if(l===`-simulate`||l===`-generate`){t.mode=l===`-generate`?`generate`:`simulate`;let e=s();if(e===void 0||![`stats=`,`file=`,`num=`,`sched`].some(t=>e.includes(t)))continue;n++;let i=e.split(`,`),a=i.findLast(e=>e.startsWith(`file=`));a!==void 0&&(t.behaviorFile=a.replaceAll(`file=`,``)),i.includes(`sched=rl`)?t.scheduler=`rl`:i.includes(`sched=rlaction`)&&t.scheduler!==`rl`&&(t.scheduler=`rlaction`);let o=i.findLast(e=>e===`stats=basic`||e===`stats=full`);o!==void 0&&(t.actionStatistics=o===`stats=basic`?`basic`:`full`);for(let e of i.filter(e=>e.startsWith(`num=`))){let n=e.replaceAll(`num=`,``);if(t.traceCount=da(n,64),t.traceCount===void 0)return{kind:`uncaught`,error:`java.lang.NumberFormatException: For input string: "${n}"`,isTool:t.isTool}}if((t.traceCount??Qi)===Qi&&t.behaviorFile!==void 0)return r(`Error: You need to specify a 'num' argument when using the 'file' argument, for example: '"num=5,file=test.txt"'.`)}else if(l===`-suppressMessages`||l===`-messagesAsErrors`){let e=c();if(e===void 0)return r(`Error: ${l} requires a comma-separated list of message codes.`);let t=l===`-suppressMessages`?a:o;for(let n of sa(e,`,`)){let e=n.replace(/^[^!-\uffff]+|[^!-\uffff]+$/g,``),i=da(e,32);if(i===void 0)return r(`Error: For input string: "${e}"`);let o=Number(i);if(oa($i,o))t.tlc.push(o);else{if(!ta.has(o)&&!oa(ea,o))return r(`Error: unknown message code: ${o}`);if(t===a&&!ta.has(o))return r(`Error: code ${o} is an error and cannot be suppressed.`);t.sany.push(o)}}}else if(l===`-inv`){let e=c();if(e===void 0)return i();t.invariants.push({modules:[...new Set([...e.matchAll(/INSTANCE\s+(\w+)/g)].map(e=>e[1]))],expression:e})}else if(l===`-invlevel`){let e=c();if(e===void 0)return i();if(da(e,32)===void 0)return r(`Error: An integer for -invlevel required. But encountered ${e}`);t.invariants.push({modules:[`TLC`,`Naturals`],expression:`LET _T == INSTANCE TLC _N == INSTANCE Naturals IN _N!<(_T!TLCGet("level"), ${e})`})}else if(l===`-debugger`){let e=s();e!==void 0&&[`port=`,`nosuspend`,`nohalt`,`suspend`,`halt`].some(t=>e.includes(t))&&n++}else if(l===`-generateSpecTE`)t.isTraceSpecForced=!0,s()===`nomonolith`&&n++;else if(l===`-noGenerateSpecTE`||l.toLowerCase()===`-note`)t.isTraceSpecDisabled=!0;else if(l===`-noGenerateSpecTEBin`||l.toLowerCase()===`-notebin`)t.isTraceBinaryDisabled=!0;else{if(l===`-help`||l===`-h`)return`usage`;if(l===`-dump`){let i=s();if(i?.startsWith(`class,`))return r(`Trying to instantiate a custom IStateWriter implementation ${i.replaceAll(`class,`,``)}.`);let a=i?.startsWith(`dot`)&&n+1<e.length?2:1;if(t.dump=e.slice(n,n+a),n+=a,t.dump.length===0)return r(`Error: A file name for dumping states required.`)}else if(Object.hasOwn(_a,l.toLowerCase())){let i=_a[l.toLowerCase()];if(n+1>=e.length)return r(i.missing);let a=c(),o=c(),s=Object.keys(i.formats).find(e=>e.toLowerCase()===a.toLowerCase());if(s===void 0)return r(`Error: Unknown format ${a} given to ${i.name}.`);let u=i.formats[s];u.communityModule!==void 0&&t.communityTraceModules.push({format:s,module:u.communityModule}),t.moduleOperators.push(...u.operators.map(e=>({...e,module:u.module,constants:{[u.constant]:o}})))}else if(l.toLowerCase()===`-postcondition`){let e=c();if(e===void 0)return r(`Error: Module!Operator for postCondition required.`);if(!e.includes(`!`))return r(`Module!Operator for postCondition required. Encountered: ${e}`);let n=sa(e,`!`);if(n.length!==2)return r(`Module!Operator for postCondition must be of the form module!operator. Encountered: ${e}`);if(n[0]===``)return r(`Module name for postCondition required. Encountered: ${e}`);if(n[0].includes(`.`))return r(`Module name for postCondition must not contain a dot. Encountered: ${n[0]}`);if(n[1].includes(`.`))return r(`Operator name for postCondition must not contain a dot. Encountered: ${n[1]}`);t.moduleOperators.push({kind:`postcondition`,module:n[0],operator:n[1]})}else{if(l.startsWith(`-`))return r(`Error: unrecognized option: ${l}`);t.specs.push(l)}}}if(!t.isWarningEnabled&&a.tlc.length+a.sany.length>0)return r(`Error: -nowarning already suppresses all warnings, making -suppressMessages redundant. Remove -nowarning to suppress only the specified messages, or remove -suppressMessages to suppress all warnings.`);let l=ca(a.tlc,o.tlc),u=l.length>0?l.map(String):ca(a.sany,o.sany).map(e=>ta.get(e)??String(e));return u.length>0?r(`Error: The following codes were set to both -suppressMessages and -messagesAsErrors: [${u.join(`, `)}]`):(t.suppressedCodes=[...a.tlc,...a.sany],t.errorCodes=[...o.tlc,...o.sany],t)},ya=()=>BigInt(Math.floor(Math.random()*2**32)),ba=(e,t)=>({...e,workers:e.workers??t,fingerprintIndex:e.fingerprintIndex??Math.floor(Math.random()*131),seed:e.seed??BigInt.asIntN(64,ya()<<32n|ya()),aril:e.seed===void 0?0n:e.aril});var xa=`0.0.10-dev.a43e3a937`;const Sa=(e,t)=>e.print(r.a.computingInitProgress,r.o.none,`Computed ${t} initial states...`),Ca=(e,t)=>e===`invariant-violation`?{code:r.a.invariantViolatedInitial,text:`Invariant ${t} is violated by the initial state:`}:{code:r.a.propertyViolatedInitial,text:`Property ${t} is violated by the initial state:`},Q=(e,t)=>{for(let i of t??[]){if(typeof i==`string`){e.printOutput(i);continue}if(i.kind===`initial-states-progress`){Sa(e,i.count);continue}if(i.kind===`warning`){e.print(i.code,r.o.warning,i.text);continue}if(i.kind===`violation`){Va(i.status,i.violation,e);continue}let t=Ca(i.status,i.name);e.print(t.code,r.o.error,`${t.text}\n${n.Sn(i.state)}`)}},wa={code:r.a.behaviorUpToThisPoint,text:`The behavior up to this point is:`},Ta={code:r.a.counterExample,text:`The following behavior constitutes a counter-example:
27
27
  `},Ea={"error-trace":{heading:wa,isLastDiffed:!1},"counter-example":{heading:Ta,isLastDiffed:!0}},Da=(e,t,n,i)=>e.print(r.a.statePrint2,r.o.state,`${t}: <${n.label??n.action??`Initial predicate`}>\n${i}`),Oa=(t,i,a)=>{let o=Ea[a].heading,s=a===`counter-example`&&t.version===`1.7.4`;i.length>0&&t.print(o.code,r.o.error,o.text);try{for(let e=0;e<i.length;e++){let r=i[e];(e>0||s)&&Q(t,r.output),Q(t,r.aliasOutput);let o=t.isDiffTrace&&e>0&&(Ea[a].isLastDiffed||e<i.length-1);Da(t,e+1,r,n.Sn(r.state,o?n.Tn(r.state,i[e-1].state):void 0))}}catch(n){t.print(r.a.general,r.o.error,e.bt(n))}},ka=(e,t)=>t===`1.7.4`||e.length===0?`Temporal properties were violated.
28
28
  `:e.length===1?`Temporal property ${e[0]} was violated.\n`:`Temporal properties ${e.slice(0,-1).join(`, `)}${e.length>2?`,`:``} and ${e[e.length-1]} were violated.\n`,Aa=e=>e.filter((t,n)=>t!==e[n-1]).map((e,t)=>`${t}) ${n.or(e)}\n`).toReversed().join(``),ja=e=>{if(e.length===0)return` The error call stack is empty.
29
29
  `;let t=[];for(let n=0;n<e.length;n++){let r=e[n],i=r.location.range;r!==e[n-1]&&i&&t.push(`${t.length}. Line ${i.start.line}, column ${i.start.column} to line ${i.end.line}, column ${i.end.column} in ${i.module}\n`)}return`${t.join(``)}\n`},Ma=(e,t)=>{let n=t.generated,i=t.distinct,a=r.m(/* @__PURE__ */ new Date);n===i?e.print(r.a.initGenerated1,r.o.none,`Finished computing initial states: ${i} distinct state${i===1?``:`s`} generated at ${a}.`):e.print(r.a.initGenerated2,r.o.none,`Finished computing initial states: ${n} state${n===1?``:`s`} generated, with ${i} of them distinct at ${a}.`)},Na=(e,t,n)=>{let i=e=>String(e).replace(/\B(?=(?:\d{3})+$)/g,`,`),a=(e,t)=>e===void 0?``:` (${i(e)} ${t}/min)`;e.print(r.a.progress,r.o.none,`Progress(${Math.max(t.depth,1)}) at ${r.m(/* @__PURE__ */ new Date)}: ${i(t.generatedStates)} states generated${a(n?.[0],`s`)}, ${i(t.distinctStates)} distinct states found${a(n?.[1],`ds`)}, ${i(t.queuedStates)} states left on queue.`)},Pa={init:r.a.coverageInit,next:r.a.coverageNext,invariant:r.a.coverageProperty,implied:r.a.coverageProperty,constraint:r.a.coverageConstraint},Fa=(e,t,n)=>{let i=(t,n)=>e.print(t,r.o.none,n);i(r.a.coverageStart,`The coverage statistics at ${r.m(/* @__PURE__ */ new Date)} (see https://explain.tlapl.us/module-coverage-statistics for how to interpret the following statistics).`);for(let e of t.variables)i(r.a.coverageVariable,`<${e.label}>: ${e.distinct}`);for(let e of t.relations){let t=Pa[e.kind];i(t,t===r.a.coverageProperty?`<${e.label}>`:`<${e.label}>: ${e.distinct}:${e.generated}`);for(let t of e.expressions){let e=` ${`|`.repeat(t.depth)}${t.location}`;t.cost>0?i(r.a.coverageValueCost,`${e}: ${t.count}:${t.cost}`):i(r.a.coverageValue,`${e}: ${t.count}`)}}Date.now()-n>3e5?i(r.a.coverageEndOverhead,`End of statistics (please note that for performance reasons large models
package/dist/run.js CHANGED
@@ -23,7 +23,7 @@ operator name or before an operator name.`)}else if(n===void 0||Oe(n))return e.a
23
23
  in module being instantiated.`,Ji=(e,t,n,r,i,a,o=e.currentModule)=>(Oe(r)&&e.addError(a,t===`SubstIn`?qi:`Substitution error, probably due to error in module being instantiated.`),{...q(e.getId()),kind:t,substs:n,body:r,instantiatingModule:o,instantiatedModule:i,location:a}),Yi=(e,t,n,r,i)=>{if(n)return Ji(e,`SubstIn`,t,n,r,i);e.addError(i,qi)},Xi=(e,t,n)=>{J(e,t),t.params=n},Zi=(e,t,n,r)=>{let i=Bi(e.file,t),a=A(e.file,i),o=j(e.file,i.start),s=t.name??``,c=z(),l=t.isLocal?i.start+1:i.start;t.params.length>0&&e.contexts.push(c);let u=zi(e,t,{start:l,end:i.end},t.params.length>0),d=Qr(e,t.module),f=d.context,p=Ki(e,t,f,a);t.params.length>0&&e.contexts.pop();for(let r of fe(f.table)){if(r.kind!==`OpDef`||r.isLocal||r.defKind!==`UserDefined`&&r.defKind!==`ModuleInstance`)continue;let i=[...u,...r.params??[]],c=`${s}!${r.name}`,l=r.defKind===`UserDefined`?ti(e,{name:c,params:i,body:p.length>0?Yi(e,p,r.body,d,a):r.body,isLocal:t.isLocal,location:a,source:r.source??r,preComments:o,labels:r.labels}):ti(e,{defKind:`ModuleInstance`,name:c,params:i,isLocal:t.isLocal,location:a,module:r.module,source:r.source??r,preComments:o});J(e,l),r.defKind===`UserDefined`&&ni(e,l),(n??e.currentModule.definitions).push(l)}for(let r of fe(f.table)){if(r.kind!==`ThmOrAssumpDef`||r.isLocal)continue;let i=p.length>0?Ji(e,`APSubstIn`,p,r.body,d,a):r.body,o={...q(e.getId()),kind:`ThmOrAssumpDef`,name:`${s}!${r.name}`,isTheorem:r.isTheorem,body:i,params:[],isLocal:t.isLocal,location:a,module:e.currentModule,source:r.source??r,labels:r.labels,isLeibnizArg:[],isLeibniz:!1,opLevelCond:[],maxLevels:[],weights:[],minMaxLevel:[]};Xi(e,o,[...u,...r.params]),(n??e.currentModule.definitions).push(o)}let m={...q(e.getId()),kind:`Instance`,name:s,isLocal:t.isLocal,params:u,module:d,substs:p,location:a};(r??e.currentModule.topLevel).push(m);let h=ti(e,{defKind:`ModuleInstance`,name:s,params:u,isLocal:t.isLocal,location:a,preComments:o});J(e,h),e.version!==`1.7.4`&&n?.push(h)},Qi=(e,t)=>(J(e,t),t),$i=(e,t,n=!0,r)=>{let i=Bi(e.file,t),a=r??A(e.file,i),o=j(e.file,i.start),s=Qr(e,t.module),c=s.context,l=Ki(e,t,c,a),u=t.isLocal,d=Wr(s);for(let t of fe(c.table)){if(t.kind!==`OpDef`||t.defKind!==`UserDefined`||t.isLocal)continue;let n=(n,r)=>{let i=ti(e,{name:t.name,params:t.params,body:r,isLocal:u,location:a,module:n,source:t.source??t,preComments:o,labels:t.labels});return J(e,i),i},r=t.module===void 0||Wr(t.module),i=d||r?u?n(t.module,t.body):Qi(e,t):n(e.currentModule,Yi(e,l,t.body,s,a));e.currentModule.definitions.push(i),i!==t&&ni(e,i)}for(let t of fe(c.table)){if(t.kind!==`ThmOrAssumpDef`||t.isLocal)continue;let r=(n,r)=>{let i={...t,...q(e.getId()),body:r,isLocal:u,location:a,module:n,source:t.source??t,params:[]};return Xi(e,i,t.params),i},i=d?u?r(t.module,t.body):Qi(e,t):Wr(t.module)?u?r(e.currentModule,t.body):t:r(e.currentModule,Ji(e,`APSubstIn`,l,t.body,s,a));n&&e.currentModule.definitions.push(i)}let f={...q(e.getId()),kind:`Instance`,name:void 0,isLocal:u,params:[],module:s,substs:l,location:a};return n&&e.currentModule.topLevel.push(f),f},ea=(e,t,n)=>n===0?{start:t,end:t}:N(e,t,`_`)?{start:t,end:N(e,t+2,`_`)?t+2:t+1}:N(e,t+1,`(`)?{start:t,end:ae(e,t+1)}:{start:t,end:N(e,t+1,`_`)?t+1:t},ta=(e,t)=>ea(e,Yr(e,t.location).start,t.arity),na=(e,t,n)=>{let r=ta(e.file,t),i={...q(e.getId()),levelChecked:1,level:+(n===3),kind:`OpDecl`,name:M(t.name),arity:t.arity,declKind:n,location:A(e.file,r),module:e.currentModule};return n===2&&(i.levelParams.add(i),i.allParams.add(i)),J(e,i),i},ra=(e,t,n)=>{e.recursion.unresolvedSum<=0||e.addError(Xr(e.file,t),`${n} may not appear within a recursive definition section.`)},ia=(e,t)=>{let n=[...t.definitions.map(t=>({unit:{kind:`Definition`,definition:t},span:Bi(e,t)})),...(t.instances??[]).map(t=>({unit:{kind:`Instance`,instance:t},span:Bi(e,t)}))],r=P(e,t).start,i=ne(e,t.body).start,a=[];for(let t=r+1;t<i;t++){let r=n.some(e=>e.span.start<=t&&t<=e.span.end);N(e,t,`RECURSIVE`)&&!r&&a.push(t)}let o=a.map((n,r)=>{let o=a[r+1]??i;return{unit:{kind:`Recursive`,declarations:(t.recursive??[]).filter(t=>{let r=I(e,t.location);return n<r&&r<o})},span:{start:n,end:n}}});return[...n,...o].toSorted((e,t)=>e.span.start-t.span.start).map(e=>e.unit)},aa=(e,t)=>{let n=z();return $r(e,n,()=>{e.curLevel++,e.recursion.unresolvedCount[e.curLevel]=0;let r=[],i=[];for(let n of ia(e.file,t))n.kind===`Recursive`?Wi(e,n.declarations):n.kind===`Instance`?Zi(e,n.instance,r,i):n.definition.kind===`Function`?Ui(e,n.definition,r):Vi(e,n.definition,r);Gi(e),e.curLevel=Math.max(e.curLevel-1,0);let a=X(e,t.body);return{...q(e.getId()),kind:`LetIn`,opDefs:r,instances:i,body:a,context:n,location:Jr(e.file,t)}})},oa={Constant:{declKind:24,level:0},Variable:{declKind:25,level:1},State:{declKind:26,level:1},Action:{declKind:27,level:2},Temporal:{declKind:28,level:3}},sa=(e,t)=>{let n=Zr(e,t.name)??(t.name===e.currentModule.name?e.currentModule:void 0);return n===void 0?(e.addError(F(e.file,I(e.file,t.location)+1),`Module \`${t.name}' used without being extended or instantiated.`),[]):[n]},ca=(e,t)=>t.flatMap(t=>{if(t.kind===`ModuleFact`)return sa(e,t);let n=t.kind===`ExceptAt`?{kind:`Identifier`,name:`@`,location:t.location}:t,r=jr(n);if(r===void 0||!Mr(r))return[X(e,t)];let i=gi(e,n,0,!0,!1);if(i.kind===`ThmOrAssumpDef`)throw new _(`Expected a fact`);return[i]}),la=(e,t)=>t.defs.flatMap((n,r)=>{if(n.kind===`ModuleFact`)return sa(e,n);let i=t.defErrors?.get(r)??[];for(let t of i)e.addError(t.location,t.message);if(i.length>0)return[];let a=Jr(e.file,n),o=gi(e,D(n)??(n.kind===`OperatorReference`?{kind:`Identifier`,name:n.operator,location:n.location}:n),-1,!1,!0,a);return o.kind===`OpDef`||o.kind===`ThmOrAssumpDef`&&!o.name.startsWith(`<`)?[o]:(e.addError(a,`DEF clause entry should describe a defined operator.`),[])}),ua=(e,t,n)=>{t.isOnly||t.facts.length+t.defs.length>0||e.addError(n,`Empty BY, USE, or HIDE`)},da=(e,t)=>{let n=Xr(e.file,t.location);ua(e,t,n);let r=ca(e,t.facts),i=la(e,t);if(r.length+i.length===0&&e.addError(n,`Empty USE or HIDE statement.`),t.kind===`Hide`)for(let t of r.filter(e=>e.kind===`OpAppl`&&e.operator.kind!==`ThmOrAssumpDef`))e.addError(t.location,`The only expression allowed as a fact in a HIDE is
24
24
  the name of a theorem, assumption, or step.`);return{...q(e.getId()),kind:`UseOrHide`,facts:r,defs:i,isOnly:t.isOnly,isHide:t.kind===`Hide`,location:n}},fa=(e,t)=>{let n=Yr(e.file,t.location),r=t.set&&X(e,t.set),i=Mi(e.file,n.start,t.name),a=oa[t.level],o={...q(e.getId()),levelChecked:1,level:a.level,kind:`OpDecl`,name:M(t.name),arity:t.arity,declKind:a.declKind,location:A(e.file,ea(e.file,i,t.arity)),module:e.currentModule};return J(e,o),{...q(e.getId()),kind:`NewSymb`,declaration:o,set:r,location:A(e.file,n)}},pa=(e,t,n,r)=>{let i=Yr(e.file,t.location),a=t.isBoxed===!0,o=A(e.file,{start:i.start,end:a?i.start+1:i.start});a!==(t.isProveBoxed===!0)&&e.addError(o,a?`[]ASSUME matched by PROVE instead of []PROVE`:`ASSUME matched by []PROVE instead of PROVE`);let s=e.getId();n>1&&e.contexts.push(z()),a&&e.contexts.some(t=>e.assumeContexts.has(t))&&e.addError(o,`[]ASSUME used within the scope of an ordinary ASSUME's assumptions`),a||e.assumeContexts.add(Br(e.contexts));let c={isDeclaredBefore:[!1],hasGoal:r!==void 0,isSuffices:r?.isSuffices??!1,isInProof:!0};e.assumeProveState.depth=n,e.assumeProveState.isDeclared[n]=!1,n===1&&(e.assumeProveState.goal=r&&c,e.assumeProveState.goalClause=0);let l=t.assumptions.map((t,r)=>{let i=t.kind===`NewSymbol`,a=t.kind===`AssumeProve`&&t.label?Ri(e,t.label.name,Xr(e.file,t.label.location),()=>pa(e,t,n+1)):t.kind===`AssumeProve`?pa(e,t,n+1):i?fa(e,t):X(e,t);return e.assumeProveState.depth=n,i&&(e.assumeProveState.isDeclared[n]=!0),c.isDeclaredBefore.push(c.isDeclaredBefore[r]||i),n===1&&e.assumeProveState.goalClause++,a}),u=X(e,t.conclusion);n>1&&e.contexts.pop(),e.assumeProveState.depth=n-1,n===1&&(e.assumeProveState.goal=void 0);let d={...q(s),kind:`AssumeProve`,assumptions:l,goal:u,isSuffices:c.isSuffices,isBoxed:a,location:A(e.file,i)};return e.assumeProveScopes.set(d,c),d},ma=(e,t,n,r,i,a,o=!0)=>({...q(t),kind:`ThmOrAssumpDef`,name:n,isTheorem:o,body:r,params:[],isLocal:!1,location:i,module:e.currentModule,source:void 0,labels:a,isLeibnizArg:[],isLeibniz:!1,opLevelCond:[],maxLevels:[],weights:[],minMaxLevel:[]}),ha=(e,t)=>{let n=Xr(e.file,t.location);t.kind===`By`&&ua(e,t,n);let r=t.kind===`By`?ca(e,t.facts):[],i=t.kind===`By`?la(e,t):[];return t.kind===`By`&&e.getId(),t.kind===`By`&&r.length+i.length===0&&e.addError(n,`Empty BY`),{...q(e.getId()),kind:`LeafProof`,facts:r,defs:i,isOmitted:t.kind===`Omitted`,isOnly:t.kind===`By`&&t.isOnly,location:n}},ga=(e,t,n)=>{let r=A(e.file,n);switch(t.kind){case`Have`:return Y(e,`$Have`,[X(e,t.expression)],r);case`Case`:return Y(e,`$Pfcase`,[X(e,t.expression)],r);case`Witness`:return Y(e,`$Witness`,t.expressions.map(t=>X(e,t)),r);case`Qed`:return Y(e,`$Qed`,[],r);case`Take`:case`Pick`:{let i=t.kind===`Pick`,a=i?`$Pick`:`$Take`;i&&e.contexts.push(z());let o=n=>t.kind===`Pick`?[xi(e,n,t.body)]:[];if(t.bounds.length>0){let i=bi(e,t.bounds,n.start),s=o(i.bounded.flat());return Y(e,a,s,r,i)}let s=T(e.file,n.start,n.end+1,t.names),c=t.names.map((t,n)=>ei(e,t,0,F(e.file,s[n]),!0)),l=o(c);return Y(e,a,l,r,{unbounded:c})}}},_a=(e,t)=>{if(t.kind!==`Steps`)return ha(e,t);let n=z();e.contexts.push(n);let r=[],i=[],a=re(t.steps),o,s=(t,n,i)=>{if(t.kind===`Define`){let n=t.definitions.map(t=>{let n=[];t.kind===`Instance`?Zi(e,t,n,r):t.kind===`Function`?Ui(e,t,n):Vi(e,t,n);let i=n[t.kind===`Instance`?n.length-1:0];if(i?.kind!==`OpDef`)throw new _(`A DEFINE step defines no operator`);return i});return{...q(e.getId()),kind:`DefStep`,defs:n,location:A(e.file,i)}}if(t.kind===`Use`||t.kind===`Hide`)return{...da(e,t),location:A(e.file,n)};if(t.kind===`Instance`)return $i(e,t,!1,A(e.file,i))},c=t.steps.map(t=>{let n=Yr(e.file,t.location),r=Se(e.file,t.head),c={start:r.start+1,end:r.end},l=t.body;t.name!==void 0&&/^<[*+]>/.test(t.token)&&e.addError(F(e.file,n.start),`<*> and <+> cannot be used for a named step.`),t.name!==void 0&&Gr(e);let u=t.name===void 0?void 0:e.getId();l.kind!==`Assert`&&(o=void 0);let d=s(l,n,c);if(d!==void 0)return t.name!==void 0&&J(e,ti(e,{defKind:`NumberedProofStep`,name:t.name,location:A(e.file,n),labels:Kr(e),step:d})),d;let f=l.kind===`Assert`&&l.statement.kind===`AssumeProve`;f&&(o=void 0);let p=l.kind===`Assert`&&l.isSuffices,m=z(),h=l.kind===`Assert`?(n=>{if(n.kind===`AssumeProve`){let r=$r(e,m,()=>pa(e,n,1,t.name===void 0?void 0:{isSuffices:p}));return r.isSuffices=p,r}if(p){let t=X(e,n);return Y(e,`$Suffices`,[t],A(e.file,c))}let r=a.get(t),i=r!==void 0&&o!==void 0,s=i?X(e,r.right):void 0,l=i?ri(e,ci(e,r.operator,Jr(e.file,n)),[Y(e,`$Nop`,[o],Jr(e.file,r.at)),s],Jr(e.file,n)):X(e,n);return o=l.kind===`OpAppl`?l.operands[1]:void 0,l})(l.statement):ga(e,l,c);if(h===void 0)throw new _(`Unexpected proof step ${l.kind}`);let g=l.kind===`Pick`?e.contexts.pop():void 0,v=t.name===void 0||u===void 0?void 0:ma(e,u,t.name,h,F(e.file,I(e.file,t.location)),Kr(e));v&&J(e,v);let y=f&&!p;y&&e.contexts.push(m);let b=t.proof&&_a(e,t.proof);y&&e.contexts.pop(),qr(e,h),f&&p&&(i.push(m),e.contexts.push(m));for(let t of g?.symbols??[])J(e,t);return{...q(e.getId()),kind:`Theorem`,definition:v,body:h,proof:b,isSuffices:p,location:A(e.file,n)}});for(let t of i)for(let t of e.contexts.pop()?.symbols??[])_e(n,t);return e.contexts.pop(),{...q(e.getId()),kind:`NonLeafProof`,steps:c,instances:r,proofLevel:t.level,location:Xr(e.file,t.location)}},va=(e,t)=>{let n=Xr(e.file,t.location),r=t.statement,i=z();t.name!==void 0&&Gr(e);let a=t.name===void 0?void 0:e.getId();r.kind===`AssumeProve`&&e.contexts.push(i);let o=r.kind===`AssumeProve`?pa(e,r,1,t.name===void 0?void 0:{isSuffices:!1}):X(e,r),s=t.name===void 0||a===void 0?void 0:ma(e,a,t.name,o,n,Kr(e));s&&(r.kind===`AssumeProve`&&e.contexts.pop(),J(e,s),e.currentModule.definitions.push(s),r.kind===`AssumeProve`&&e.contexts.push(i));let c=t.proof&&_a(e,t.proof);r.kind===`AssumeProve`&&e.contexts.pop(),qr(e,o);let l={...q(e.getId()),kind:`Theorem`,definition:s,body:o,proof:c,isSuffices:!1,location:n};e.currentModule.topLevel.push(l)},ya=(e,t)=>{let n=Xr(e.file,t.location);t.name!==void 0&&Gr(e);let r=X(e,t.expression),i=t.name===void 0?void 0:ma(e,e.getId(),t.name,r,n,Kr(e),!1);i&&(J(e,i),e.currentModule.definitions.push(i));let a={...q(e.getId()),kind:`Assume`,definition:i,body:r,location:n};e.currentModule.topLevel.push(a)},ba=e=>e.kind===`OpDef`||e.kind===`FormalParam`?`definition`:`declaration`,xa=(e,t)=>{e.push(t);for(let n of t.substitutions)Sa(e,n.expression)},Sa=(e,t)=>{if(t.kind===`Let`){for(let n of[...t.definitions,...t.instances??[]].sort((e,t)=>ge(e.location,t.location)))Ca(e,n);return Sa(e,t.body)}let n=oe(t);for(let t=0;t<n.length;t++)Sa(e,n[t])},Ca=(e,t)=>{if(t.kind===`Instance`)return xa(e,t);for(let n of be(t))Sa(e,n)},wa=(e,t)=>{let n=t=>{t.kind!==`ModuleFact`&&Sa(e,t)};for(let e of t.facts)n(e);for(let e of t.defs)n(e)},Ta=(e,t)=>{if(t.kind===`NewSymbol`)t.set&&Sa(e,t.set);else{if(t.kind!==`AssumeProve`)return Sa(e,t);for(let n of t.assumptions)Ta(e,n);Ta(e,t.conclusion)}},Ea=(e,t)=>{switch(t.kind){case`Use`:case`Hide`:return wa(e,t);case`Instance`:return xa(e,t);case`Define`:for(let n of t.definitions)Ca(e,n);return;case`Have`:case`Case`:return Sa(e,t.expression);case`Witness`:for(let n of t.expressions)Sa(e,n);return;case`Take`:for(let n of t.bounds)Sa(e,n.set);return;case`Pick`:for(let n of t.bounds)Sa(e,n.set);return Sa(e,t.body);case`Assert`:return Ta(e,t.statement);case`Qed`:return}},Da=(e,t)=>{if(t?.kind===`By`)return wa(e,t);if(t?.kind===`Steps`)for(let n of t.steps)Ea(e,n.body),Da(e,n.proof)},Oa=(e,t)=>{let n=/* @__PURE__ */ new Set;for(let r of e.units)if(r.kind===`Module`&&n.add(r.module.name),r.kind===`Instance`&&r.instance.module===t.module)return n.has(t.module);return e.modules.some(e=>e.name===t.module&&O(e.location,t.location))},ka=e=>{let t=[],n=[],r=/* @__PURE__ */ new Map,i=(e,a)=>{let o=(t,n)=>{for(let i of t)n.push(i),r.has(i)||r.set(i,e.name)},s=e=>!a.has(e);o(e.extends.filter(s),t);let c=[];for(let t of e.units)t.kind===`Instance`?xa(c,t.instance):t.kind===`Definition`?Ca(c,t.definition):t.kind===`Theorem`?(Ta(c,t.theorem.statement),Da(c,t.theorem.proof)):t.kind===`Assumption`?Sa(c,t.assumption.expression):t.kind===`Use`&&wa(c,t.use);o(c.filter(t=>s(t.module)&&!Oa(e,t)).map(e=>e.module),n);let l=new Map(a);for(let t of e.modules){let e=new Map(l),n=/* @__PURE__ */ new Set,r=t=>{if(!n.has(t)){n.add(t);for(let n of t.extends){let t=e.get(n);if(t!==void 0){for(let n of t.modules)e.has(n.name)||e.set(n.name,n);r(t)}}}};r(t),i(t,e),l.set(t.name,t)}};return i(e,/* @__PURE__ */ new Map),{extendees:t,instancees:n,importers:r}},Aa=(e,t,n={})=>{let r=[],i=(e,t)=>se(r,{location:e,text:t,isWarning:!1}),a=(e,t)=>se(r,{location:e,text:t,isWarning:!0}),o=n.version===`1.7.4`?-1:0,c=()=>++o,l=0;n.version!==`1.7.4`&&Or(c);let u=Or(c);c();let f=new Map(u.map(e=>[e.name,e])),p=/* @__PURE__ */ new Map,m=/* @__PURE__ */ new Map,h=(e,t)=>{let r=e===n.rootFileName&&n.rootFilePath||`${e}.tla`,i=t=>new s(`Could not parse module ${e} from file ${r}`,e,t),a=n.version===`1.7.4`?de(t):void 0;if(a!==void 0)throw i(a);let o=n.parsedSources?.get(e);if(o?.text===t)return o;try{let e=Te(t);return{module:me(t,e),tokens:e}}catch(e){throw e instanceof _?i(te(t)??`***Parse Error***\n${e.message}`):e}},g=(e,t,r)=>{let i=m.get(e);if(i)return i;if(t===void 0)throw new d(e,r,n.version!==`1.7.4`);n.onParse?.(e);let a=h(e,t),o=a.module;if(o.name!==e)throw new s(`File name '${e}' does not match the name '${o.name}' of the top level module it contains.`,void 0);let c={file:ke(o.name,t,a.tokens),text:t,tokens:a.tokens,module:o,dependencies:D(e,o)};return m.set(e,c),c},v=[],y=/* @__PURE__ */ new Set,b=[],x=(e,n,r)=>{let i=b.indexOf(e);if(i!==-1)throw new s(`Circular dependency among .tla files; dependency cycle is:\n\n ${[...b.slice(i),e].map(e=>`${e}.tla`).join(` --> `)}`,void 0);if(y.has(e))return;y.add(e),b.push(e);let a=g(e,n,r).dependencies;for(let n of[...a.extendees,...a.instancees])x(n,t(n),e);b.pop(),v.push(e)},S=/* @__PURE__ */ new Set,C=(e,t)=>S.has(`${e} ${t}`),w=(e,t,n)=>{let r=m.get(e);if(!r||n.has(e))return;n.add(e);let i=r.dependencies,a=i[t].find(t=>!C(e,t));if(a!==void 0)return{name:a,importer:e,namingModule:i.importers.get(a)??e};for(let r of[...i.extendees,...i.instancees]){let i=C(e,r)?w(r,t,n):void 0;if(i)return i}},T=n=>{g(n,e);let r=()=>w(n,`extendees`,/* @__PURE__ */ new Set)??w(n,`instancees`,/* @__PURE__ */ new Set);for(let e=r();e!==void 0;e=r())m.has(e.name)||g(e.name,t(e.name),e.namingModule),S.add(`${e.importer} ${e.name}`)},E=n.rootFileName??h(``,e).module.name,D=(e,t)=>{let r=ka(t);if(e!==E||n.rootExtendees===void 0)return r;r.extendees.splice(t.extends.length,0,...n.rootExtendees);for(let t of n.rootExtendees)r.importers.has(t)||r.importers.set(t,e);return r};T(E),x(E,e);let ee=/* @__PURE__ */ new WeakMap,O=/* @__PURE__ */ new WeakMap,k=(e,t,r,o,s={sectionCount:0,unresolvedCount:[0],unresolvedSum:0})=>{let u={kind:`Module`,id:c(),name:e.name,location:Xr(t,e.location),extendees:[],context:Br(o),constantDecls:void 0,variableDecls:void 0,opDefs:void 0,thmOrAssDefs:void 0,topLevel:[],definitions:[],opDefsInRecursiveSection:[],isLevelChecked:!1,levelCorrect:!0,argLevelParams:/* @__PURE__ */ new Map,levelConstraints:/* @__PURE__ */ new Map,argLevelConstraints:/* @__PURE__ */ new Map,records:[]};r&&r.definitions.push(u);let d={version:n.version,addError:i,addWarning:a,getId:c,builtinsByName:f,externalModules:p,nullApplicationId:l,file:t,contexts:o,currentModule:u,curLevel:0,recursion:s,functions:[],exceptStack:[],exceptSpecStack:[],labelScopes:[],assumeContexts:/* @__PURE__ */ new WeakSet,assumeProveState:{depth:0,isDeclared:[],goal:void 0,goalClause:0},assumeProveScopes:ee,labelGoals:O,recursiveDeclarations:[],generateLet:e=>aa(d,e),selectorToNode:zr({version:n.version,resolveSymbol:e=>Vr(o,e),resolveSynonym:M,generateExpression:e=>X(d,e),generateArgument:(e,t,n,r)=>Di(d,e,t,n,r),createOpAppl:(e,t,n)=>{let r=ri(d,e,t,n);return li(d,e,t,n),r},createOpArg:(e,t)=>si(d,e,t),createFormalParam:(e,t,n)=>ei(d,e,t,n,!1),createLambda:(e,n,r)=>ti(d,{name:`LAMBDA`,params:e,body:n,location:r,preComments:j(t,I(t,{line:r.beginLine,column:r.beginColumn}))}),copySubstIn:(e,t)=>Ji(d,`SubstIn`,e.substs,t,e.instantiatedModule,e.location,e.instantiatingModule),getBuiltin:e=>ai(d,e),addError:(e,t)=>(i(e,t),ii(d)),isOutOfLabelScope:e=>{let t=d.labelGoals.get(e);return t!==void 0&&t.scope.isDeclaredBefore[t.clause]&&t.scope.isSuffices===t.scope.isInProof},isOutOfClauseScope:(e,t)=>{let n=d.assumeProveScopes.get(e);return n!==void 0&&n.isDeclaredBefore[t-1]&&(!n.hasGoal||n.isSuffices===n.isInProof)}})};for(let t of e.extends){let e=Qr(d,t);u.extendees.push(e);let n=Br(o);for(let t of e.context.symbols){if(t.kind!==`Module`&&t.kind!==`FormalParam`&&t.kind!==`OpDecl`&&t.isLocal)continue;let e=t.kind===`Module`?le(n,t.name):xe(n,t.name);e===void 0?_e(n,t):e!==t&&e.kind!==t.kind?i(t.location,`The ${ba(t)} of '${t.name}' conflicts with \nits ${ba(e)} at ${ce(e.location)}.`):e!==t&&!Ur(e,t)&&a(t.location,`Warning: the ${ba(e)} of '${t.name}' conflicts with \nits ${ba(e)} at ${ce(e.location)}.`)}for(let t of e.topLevel)u.topLevel.push(t)}for(let n of e.units)switch(n.kind){case`Variables`:ra(d,n.location,`A VARIABLE declaration`);for(let e of n.declarations)na(d,e,3);break;case`Constants`:ra(d,n.location,`A declaration`);for(let e of n.declarations)na(d,e,2);break;case`Recursive`:Wi(d,n.declarations);break;case`Definition`:n.definition.kind===`Function`?Ui(d,n.definition,void 0):Vi(d,n.definition,void 0);break;case`Instance`:n.instance.name===void 0?$i(d,n.instance):Zi(d,n.instance,void 0,void 0);break;case`Assumption`:ra(d,n.assumption.location,`An ASSUME`),ya(d,n.assumption);break;case`Theorem`:ra(d,n.theorem.location,`A THEOREM`),va(d,n.theorem);break;case`Use`:ra(d,n.use.location,`A USE or HIDE`),u.topLevel.push(da(d,n.use));break;case`Module`:{ra(d,n.module.location,`A MODULE `);let e=k(n.module,t,u,[...o,z()],d.recursion);for(let t of e.opDefsInRecursiveSection)u.opDefsInRecursiveSection.push(t);let r=Zr(d,e.name);r===void 0?_e(Br(o),e):r!==e&&i(e.location,`Multiply-defined module '${e.name}': this definition or declaration conflicts \nwith the one at ${ce(r.location)}.`);break}}return Gi(d),u};return{sources:v.map(e=>g(e,void 0)),generate:()=>{let e=v.map(e=>{n.onAnalyze?.(e),l=Array.from({length:4},c)[1];let t=g(e,void 0),i=z();for(let e of u.toReversed())_e(i,e);let a=k(t.module,t.file,void 0,[i]);return p.set(e,a),n.onModule?.(a,r),a});return{root:e[e.length-1],modules:e,messages:r}}}},Z=(e,t,n,r)=>se(e.messages,{location:t,text:n,isWarning:!1,...r!==void 0&&!e.isTlc174&&{code:r}}),Q=(e,t)=>{for(let n of t)e.add(n)},ja=(e,t,n)=>`${e.id}:${t}:${n.id}`,Ma=(e,t,n,r)=>{e.set(ja(t,n,r),{op:t,index:n,param:r})},Na=(e,t,n=()=>!0)=>{for(let[r,i]of t)n(i)&&e.set(r,i)},Pa=(e,t,n)=>{e.set(t,Math.min(n,e.get(t)??3))},Fa=(e,t,n=()=>!0)=>{for(let[r,i]of t)n(r)&&Pa(e,r,i)},Ia=(e,t)=>`${e.id}:${t}`,La=(e,t,n,r)=>{let i=Ia(t,n),a=e.get(i)?.level??0;e.set(i,{param:t,position:n,level:Math.max(r,a)})},Ra=(e,t,n=()=>!0)=>{for(let r of t.values())n(r)&&La(e,r.param,r.position,r.level)},za=(e,t)=>{let n;for(let r of t){let t=Ia(r.param,r.position);(n??e.requiredLeibnizArgs).has(t)||(n??=new Map(e.requiredLeibnizArgs),n.set(t,r))}n&&(e.requiredLeibnizArgs=n)},Ba=(e,t)=>{e.levelParams=t.levelParams,e.allParams=t.allParams,e.appliedParams=t.appliedParams,e.requiredLeibnizArgs=t.requiredLeibnizArgs,e.levelConstraints=t.levelConstraints,e.argLevelConstraints=t.argLevelConstraints,e.argLevelParams=t.argLevelParams},Va=(e,t)=>{Q(e.levelParams,t.levelParams),Q(e.allParams,t.allParams),Fa(e.levelConstraints,t.levelConstraints),Ra(e.argLevelConstraints,t.argLevelConstraints),Na(e.argLevelParams,t.argLevelParams)},Ha=(e,t)=>t.includes(e.op)||t.includes(e.param),Ua=e=>e.kind===`OpDecl`||e.kind===`FormalParam`,Wa=e=>e.kind!==`Module`,Ga=e=>e.kind===`OpDef`||e.kind===`ThmOrAssumpDef`,Ka=(e,t)=>e.kind===`OpDef`&&e.arity<0?0:t,qa=(e,t)=>e.weights[Ka(e,t)]??0,Ja=(e,t)=>e.maxLevels[Ka(e,t)]??3,Ya=(e,t,n)=>e.minMaxLevel?.[t]?.[n]??0,Xa=(e,t)=>e.kind===`OpDef`?e.isLeibnizArg?.[Ka(e,t)]??!0:e.isLeibnizArg[t]??!0,Za=(e,t)=>{let n=e.params?.[Ka(e,t)];return n===void 0||e.appliedParams===void 0?qa(e,t)===1:e.appliedParams.has(n)},Qa=(e,t)=>(e.appliedParams??e.levelParams).has(t),$a=e=>e.appliedParams!==void 0,eo=e=>{let t=e.operator,n=[...e.ranges];for(let[r,i]of e.operands.entries())i!==void 0&&(!Ga(t)||Za(t,r))&&n.push(i);if(!n.some($a)&&!(Ga(t)&&$a(t))){e.appliedParams=void 0;return}let r=/* @__PURE__ */ new Set;if(Ga(t)){let e=t.params??[];for(let n of t.appliedParams??t.levelParams)e.includes(n)||r.add(n)}else e.levelParams.has(t)&&r.add(t);for(let e of n)Q(r,e.appliedParams??e.levelParams);for(let t of so(e))r.delete(t);e.appliedParams=r},to=e=>{let t=e.body;if(!$a(t)&&!e.substs.some(e=>$a(e.expr)))return;let n=/* @__PURE__ */ new Set;for(let r of t.appliedParams??t.levelParams)co(r,e.substs)===void 0&&n.add(r);for(let r of e.substs)Qa(t,r.op)&&Q(n,r.expr.appliedParams??r.expr.levelParams);return n},no=e=>e.kind===`FormalParam`||e.kind===`OpDecl`||e.kind===`OpDef`&&e.defKind===`BuiltIn`,ro=e=>{switch(e.kind){case`Numeral`:case`String`:case`Decimal`:case`At`:return!0;case`Label`:return ro(e.body);case`OpArg`:return no(e.op);case`OpAppl`:return no(e.operator)&&e.operands.every(e=>e===void 0||ro(e))&&e.ranges.every(ro);default:return!1}},io=e=>{let t=e.flatMap(e=>[...e.allParams]);for(let n of e){let e=n.body;e!==void 0&&(n.appliedParams=new Set(ro(e)?e.appliedParams??e.levelParams:[...n.params??[],...t]))}},ao=(e,t)=>e.kind===`OpArg`&&t&&e.op.kind!==`Module`?e.op.nonLeibnizParams:e.nonLeibnizParams,oo=(e,t,n,r)=>e.opLevelCond?.[t]?.[n]?.[r]??!1,so=e=>[...e.unbounded??[],...(e.bounded??[]).flat()],co=(e,t)=>t.find(t=>t.op===e)?.expr,lo=(e,t,n)=>{Q(e.nonLeibnizParams,ao(n.expr,Qa(t,n.op))),e.nonLeibnizParams.has(n.op)&&(e.nonLeibnizParams.delete(n.op),Q(e.nonLeibnizParams,n.expr.allParams))},uo=(e,t)=>{if(t.op.arity<=0||t.expr.kind!==`OpArg`)return[];let n=t.expr.op,r={module:e.name,constant:t.op.name};if(Ua(n))return Array.from({length:n.arity},(e,t)=>({...r,param:n,position:t}));if(!Ga(n))return[];let i=n.params??[];return[...n.argLevelParams.values()].flatMap(e=>i.includes(e.param)&&Ua(e.op)?[{...r,param:e.op,position:e.index}]:[])},fo=(e,t,n)=>{let r=co(e,t);return r===void 0?/* @__PURE__ */ new Set([e]):n?r.allParams:r.levelParams},po=(e,t)=>{let n=/* @__PURE__ */ new Map;for(let[r,i]of e){let e=co(i.op,t);if(e===void 0){n.set(r,i);continue}if(e.kind!==`OpArg`||!Ua(e.op))continue;let a=e.op;for(let e of fo(i.param,t,!1))Ma(n,a,i.index,e)}return n},mo=(e,t,n,r,i)=>{let a=/* @__PURE__ */ new Map;for(let[r,i]of e.levelConstraints){let e=n||r.kind!==`OpDecl`?i:r.declKind===2?0:r.declKind===3?1:i;for(let n of fo(r,t,!1))Pa(a,n,e)}for(let n of e.argLevelParams.values()){let e=co(n.op,t);if(e?.kind!==`OpArg`||e.op.kind!==`OpDef`)continue;$(e.op,r,i);let o=Ja(e.op,n.index);for(let e of fo(n.param,t,!1))Pa(a,e,o)}return a},ho=(e,t,n,r)=>{let i=/* @__PURE__ */ new Map;for(let n of e.argLevelConstraints.values()){let e=co(n.param,t);e===void 0?La(i,n.param,n.position,n.level):e.kind===`OpArg`&&Ua(e.op)&&La(i,e.op,n.position,n.level)}for(let a of e.argLevelParams.values()){let e=co(a.param,t);if(e===void 0)continue;let o=co(a.op,t),s=o===void 0?a.op:o.kind===`OpArg`?o.op:void 0;s!==void 0&&Ua(s)&&($(e,n,r),La(i,s,a.index,e.level))}return i},go=(e,t)=>ve(e,3).length>0||(Eo(e,t),ue(e).some(e=>(e.body?.level??0)!==0))?!1:e.topLevel.every(e=>e.kind!==`Theorem`||e.level===0),_o=(e,t,n)=>{e.minMaxLevel=t.map(e=>Array.from({length:e.arity},(t,r)=>n.argLevelConstraints.get(Ia(e,r))?.level??0)),e.opLevelCond=t.map(e=>t.map(t=>Array.from({length:e.arity},(r,i)=>n.argLevelParams.has(ja(e,i,t))))),Q(e.levelParams,n.levelParams),Q(e.allParams,n.allParams),Q(e.nonLeibnizParams,n.nonLeibnizParams),e.appliedParams=e.kind===`OpDef`&&e.recursiveSection>=0?void 0:n.appliedParams;for(let n=0;n<t.length;n++){let r=t[n];e.levelParams.delete(r),e.allParams.delete(r),e.nonLeibnizParams.has(r)&&(e.nonLeibnizParams.delete(r),e.isLeibnizArg&&(e.isLeibnizArg[n]=!1),e.isLeibniz=!1)}za(e,n.requiredLeibnizArgs.values()),e.levelConstraints=new Map(n.levelConstraints);for(let n of t)e.levelConstraints.delete(n);e.argLevelConstraints=new Map(n.argLevelConstraints);for(let n of t)for(let t=0;t<n.arity;t++)e.argLevelConstraints.delete(Ia(n,t));Na(e.argLevelParams,n.argLevelParams,e=>!t.some(t=>t===e.op)||!t.some(t=>t===e.param))},vo=(e,t,n,r,i)=>{for(let[a,o]of e.operands.entries()){if(o===void 0||(o.level>Ja(t,a)&&(n&&$(o,r,i)&&Z(i,e.location,`Level error in applying operator ${t.name}:\nThe level of argument ${a+1} exceeds the maximum level allowed by the operator.`),e.levelCorrect=!1),o.kind!==`OpArg`||!Ga(o.op)))continue;let s=o.op;$(s,r,i);let c=R(s);for(let l=0;l<c;l++){let c=Ya(t,a,l);Ja(s,l)>=c||(n&&$(o,r,i)&&Z(i,e.location,`Level error in applying operator ${t.name}:\nThe permitted level of argument ${l+1} of the operator argument ${a+1} \nmust be at least ${c}.`),e.levelCorrect=!1)}for(let[n,l]of e.operands.entries())for(let u=0;u<c;u++)l===void 0||!oo(t,a,n,u)||l.level<=Ja(s,u)||($(o,r,i)&&$(l,r,i)&&Z(i,e.location,`Level error in applying operator ${t.name}:\nThe level of argument ${n+1} exceeds the maximum level allowed by the operator.`,`HIGHER_ORDER_OPERATOR_COPARAMETER_LEVEL_CONSTRAINTS_EXCEEDED`),e.levelCorrect=!1)}for(let[n,a]of e.ranges.entries()){let o=$(a,r,i);a.level<=2||(o&&Z(i,e.location,`Level error in applying operator ${t.name}:\nThe level of the range for the bounded variable ${ce(e.bounded?.[n]?.[0]?.location)} \nexceeds the maximum level allowed by the operator.`),e.levelCorrect=!1)}},yo=(e,t,n,r,i)=>{let a=t.params??[],o=t=>e.operands.find((e,n)=>a[n]===t);Fa(e.levelConstraints,t.levelConstraints);for(let t of e.operands)t!==void 0&&Fa(e.levelConstraints,t.levelConstraints,e=>!n.has(e));for(let t of e.ranges)Fa(e.levelConstraints,t.levelConstraints);for(let[n,r]of e.operands.entries()){let i=Ja(t,n);for(let t of r?.levelParams??[])Pa(e.levelConstraints,t,i)}for(let[n,a]of e.operands.entries()){if(a?.kind!==`OpArg`||!Ga(a.op))continue;let o=a.op;$(o,r,i);let s=R(o);for(let[r,i]of e.operands.entries())for(let a=0;a<s;a++){if(!oo(t,n,r,a))continue;let s=Ja(o,a);for(let t of i?.levelParams??[])Pa(e.levelConstraints,t,s);!o.isLeibniz&&!Xa(o,a)&&i&&Q(e.nonLeibnizParams,i.allParams)}}for(let n of t.argLevelParams.values()){let t=o(n.op);t?.kind===`OpArg`&&Ga(t.op)&&($(t.op,r,i),Pa(e.levelConstraints,n.param,Ja(t.op,n.index)))}Ra(e.argLevelConstraints,t.argLevelConstraints);for(let t of e.operands)t&&Ra(e.argLevelConstraints,t.argLevelConstraints);for(let t of e.ranges)Ra(e.argLevelConstraints,t.argLevelConstraints);for(let[n,r]of e.operands.entries()){if(r?.kind!==`OpArg`||!Ua(r.op))continue;let i=r.op;for(let r=0;r<i.arity;r++)La(e.argLevelConstraints,i,r,Ya(t,n,r));for(let[r,a]of e.operands.entries())for(let o=0;o<i.arity;o++)a!==void 0&&oo(t,n,r,o)&&La(e.argLevelConstraints,i,o,a.level)}for(let n of t.argLevelParams.values()){let t=o(n.param);t!==void 0&&($(t,r,i),La(e.argLevelConstraints,n.op,n.index,t.level))}for(let t of e.operands)t!==void 0&&Na(e.argLevelParams,t.argLevelParams,e=>!n.has(e.param));for(let t of e.ranges)Na(e.argLevelParams,t.argLevelParams);for(let[n,a]of t.argLevelParams){let t=o(a.op);if(t===void 0){let t=o(a.param);if(t===void 0)e.argLevelParams.set(n,a);else{$(t,r,i);for(let n of t.levelParams)Ma(e.argLevelParams,a.op,a.index,n)}}else t.kind===`OpArg`&&Ua(t.op)&&Ma(e.argLevelParams,t.op,a.index,a.param)}for(let[n,r]of e.operands.entries()){if(r?.kind!==`OpArg`||!Ua(r.op))continue;let i=r.op;for(let[r,a]of e.operands.entries())for(let o=0;o<i.arity;o++)if(a!==void 0&&oo(t,n,r,o))for(let t of a.levelParams)Ma(e.argLevelParams,i,o,t)}},bo=(e,t,n)=>{let r=t.params??[];for(let i of t.requiredLeibnizArgs.values()){let t=r.indexOf(i.param);if(t===-1){za(e,[i]);continue}let a=e.operands[t];if(a?.kind!==`OpArg`)continue;let o=a.op;if(Ua(o)){za(e,[{...i,param:o}]);continue}if(!Ga(o))continue;if(!Xa(o,i.position)){Z(n,e.location,`Error in instantiating module '${i.module}':\n A non-Leibniz operator substituted for '${i.constant}'.`);continue}let s=o.params?.[i.position];for(let t of o.argLevelParams.values())t.param===s&&Ua(t.op)&&za(e,[{...i,param:t.op,position:t.index}])}for(let t of e.operands)t&&za(e,t.requiredLeibnizArgs.values());for(let t of e.ranges)za(e,t.requiredLeibnizArgs.values())},xo=/* @__PURE__ */ new Map([[`\\land`,`\\land`],[`\\lor`,`\\lor`],[`=>`,`=>`],[`\\equiv`,`\\equiv`],[`$ConjList`,`Conjunction list`],[`$DisjList`,`Disjunction list`]]),So=(e,t)=>{let n=(n,r)=>{Z(t,n,r),t.isTlc174||(e.levelCorrect=!1)},r=e.operator.name,i=e.operands[0];if((r===`[]`||r===`<>`)&&i?.level===2&&i.kind===`OpAppl`){let t=r===`[]`;i.operator.name!==(t?`$SquareAct`:`$AngleAct`)&&n(e.location,t?`[] followed by action not of form [A]_v.`:`<> followed by action not of form <<A>>_v.`)}r!==`~>`&&r!==`-+->`||i?.level!==2&&e.operands[1]?.level!==2||n(e.location,`Action used where only temporal formula or state predicate allowed.`);let a=xo.get(r);if(a!==void 0&&e.operands.some(e=>e?.level===3)&&e.operands.some(e=>e?.level===2)&&n(e.location,`${a} has both temporal formula and action as arguments.`),e.level===3&&(r===`$BoundedExists`||r===`$BoundedForall`))for(let t of e.ranges)t.level===2&&n(t.location,`Action-level bound of quantified temporal formula.`)},Co=(e,t,n)=>{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t,e.levelCorrect=!0;let r=e.operands.filter(e=>e!==void 0);for(let i of r)$(i,t,n)||(e.levelCorrect=!1);for(let r of e.ranges)$(r,t,n)||(e.levelCorrect=!1);let i=e.operator;if(Ga(i)){let r=$(i,t,n);vo(e,i,r,t,n),e.level=e.operands.reduce((e,t,n)=>t!==void 0&&qa(i,n)===1?Math.max(e,t.level):e,i.level);for(let t of e.ranges)e.level=Math.max(e.level,t.level);Q(e.levelParams,i.levelParams),Q(e.allParams,i.allParams),Q(e.nonLeibnizParams,i.nonLeibnizParams);for(let[t,n]of e.operands.entries())n!==void 0&&(qa(i,t)===1&&Q(e.levelParams,n.levelParams),Q(e.allParams,n.allParams),Q(e.nonLeibnizParams,ao(n,Za(i,t))),Xa(i,t)||Q(e.nonLeibnizParams,n.allParams));for(let t of e.ranges)Q(e.levelParams,t.levelParams),Q(e.allParams,t.allParams),Q(e.nonLeibnizParams,t.nonLeibnizParams);let a=new Set(so(e));for(let t of a)e.levelParams.delete(t),e.allParams.delete(t),e.nonLeibnizParams.delete(t);yo(e,i,a,t,n),bo(e,i,n)}else{$(i,t,n),e.level=r.reduce((e,t)=>Math.max(e,t.level),i.kind===`Module`?0:i.level),e.levelParams=/* @__PURE__ */ new Set([i]),e.allParams.add(i);for(let t=0;t<r.length;t++){let n=r[t];Q(e.levelParams,n.levelParams),Q(e.allParams,n.allParams),Q(e.nonLeibnizParams,n.nonLeibnizParams),za(e,n.requiredLeibnizArgs.values()),Fa(e.levelConstraints,n.levelConstraints),La(e.argLevelConstraints,i,t,n.level),Ra(e.argLevelConstraints,n.argLevelConstraints);for(let r of n.levelParams)Ma(e.argLevelParams,i,t,r);Na(e.argLevelParams,n.argLevelParams)}}return eo(e),So(e,n),e.levelCorrect},wo=(e,t,n)=>{if(e.levelChecked>=t||!e.inRecursiveSection&&e.levelChecked>0)return e.levelCorrect;e.levelChecked=t;let r=e.body;if(r===void 0)return e.levelCorrect=e.step===void 0||$(e.step,t,n),e.levelCorrect;e.levelCorrect=$(r,t,n),e.level=Math.max(e.level,r.level);let i=e.params??[];for(let t=0;t<i.length;t++){let n=i[t],a=r.levelConstraints.get(n);a!==void 0&&(e.maxLevels[t]=Math.min(e.maxLevels[t],a)),r.levelParams.has(n)&&(e.weights[t]=Math.max(e.weights[t],1))}return _o(e,i,r),e.levelCorrect},To=(e,t,n)=>{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t,e.maxLevels=e.params.map(()=>3),e.weights=e.params.map(()=>0),e.isLeibnizArg=e.params.map((t,n)=>n===e.params.length-1),e.params.length>0&&(e.isLeibniz=!0),e.levelCorrect=$(e.body,t,n),e.level=e.body.level;for(let[t,n]of e.params.entries()){let r=e.body.levelConstraints.get(n);r!==void 0&&(e.maxLevels[t]=r),e.body.levelParams.has(n)&&(e.weights[t]=1)}return _o(e,e.params,e.body),e.levelCorrect},Eo=(e,t)=>{if(e.isLevelChecked)return e.levelCorrect;e.isLevelChecked=!0;let n=e.opDefsInRecursiveSection,r=0;for(;r<n.length;){let e=n[r].recursiveSection,i=r;for(;i<n.length&&n[i].recursiveSection===e;){let e=n[i];e.inRecursive?(e.levelChecked=1,e.maxLevels=e.maxLevels.map(()=>2),e.weights=e.weights.map(()=>1)):e.levelChecked=0,i++}let a=n.slice(r,i),o=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Set,c=0;for(let e of a)if(e.inRecursive&&(e.levelChecked=0),wo(e,1,t),e.inRecursive){for(let[n,r]of e.maxLevels.entries())r>=2||Z(t,e.location,`Argument ${n+1} of recursive operator ${e.name} is primed`);c=Math.max(c,e.level),Q(o,e.levelParams),Q(s,e.allParams)}for(let e of a)e.inRecursive&&(e.levelChecked=2),e.level=Math.max(e.level,c),Q(e.levelParams,o),Q(e.allParams,s);for(let e of a)e.inRecursive&&(e.levelChecked=1),wo(e,2,t);io(a),r=i}e.levelCorrect=!0;let i=t=>{t||(e.levelCorrect=!1)};for(let n of e.definitions.filter(e=>e.kind===`Module`))i(Eo(n,t));let a=ue(e);for(let e of a)i(wo(e,1,t));for(let n of Ee(e))i(To(n,1,t));for(let n of e.topLevel)i($(n,1,t));if(!go(e,t))for(let t of ve(e,2))Pa(e.levelConstraints,t,0);for(let t of a)Fa(e.levelConstraints,t.levelConstraints),Ra(e.argLevelConstraints,t.argLevelConstraints),Na(e.argLevelParams,t.argLevelParams,e=>!Ha(e,t.params??[]));for(let t of e.topLevel)Fa(e.levelConstraints,t.levelConstraints),Ra(e.argLevelConstraints,t.argLevelConstraints),Na(e.argLevelParams,t.argLevelParams);return e.levelCorrect},Do=(e,t,n,r)=>{if(e.levelChecked>=n)return e.levelCorrect;e.levelChecked=n;for(let i of t)Wa(i)&&(i.kind!==`OpDef`||i.defKind!==`ModuleInstance`)&&(e.levelCorrect=$(i,n,r)&&e.levelCorrect,e.level=Math.max(e.level,i.level),Va(e,i),Q(e.nonLeibnizParams,i.nonLeibnizParams));return e.levelCorrect},Oo=(e,t)=>{if(e?.kind===`NonLeafProof`)for(let n of e.steps){if(n.kind!==`Theorem`||n.body.kind!==`OpAppl`)continue;let e=n.body.operator.name;e===`$Take`||e===`$Witness`||e===`$Have`?n.body.level!==0&&Z(t,n.body.location,`Non-constant TAKE, WITNESS, or HAVE for temporal goal.`):e===`$Pfcase`?(n.body.level!==0&&Z(t,n.body.location,`Non-constant CASE for temporal goal.`),Oo(n.proof,t)):e===`$Qed`&&Oo(n.proof,t)}},ko=(e,t,n)=>{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t,e.levelParams=/* @__PURE__ */ new Set,e.levelCorrect=!0;let r=e.module;Eo(r,n)||(e.levelCorrect=!1);for(let r of e.substs)$(r.expr,t,n)||(e.levelCorrect=!1);let i=go(r,n);for(let a of e.substs)!i&&a.expr.level>a.op.level&&($(a.expr,t,n)&&Z(n,e.location,`Level error in instantiating module '${r.name}':\nThe level of the expression or operator substituted for '${a.op.name}' \nmust be at most ${a.op.level}.`),e.levelCorrect=!1),a.expr.kind!==`OpArg`||(a.expr.op.kind!==`OpDef`||a.expr.op.defKind!==`UserDefined`&&a.expr.op.defKind!==`BuiltIn`)&&a.expr.op.kind!==`ThmOrAssumpDef`||a.expr.op.isLeibniz||Z(n,e.location,`Error in instantiating module '${r.name}':\n A non-Leibniz operator substituted for '${a.op.name}'.`);for(let i of e.substs){let a=r.levelConstraints.get(i.op);if(a!==void 0&&i.expr.level>a&&($(i.expr,t,n)&&Z(n,e.location,`Level error in instantiating module '${r.name}':\nThe level of the expression or operator substituted for '${i.op.name}' \nmust be at most ${a}.`),e.levelCorrect=!1),i.op.arity<=0||i.expr.kind!==`OpArg`||i.expr.op.kind!==`OpDef`)continue;let o=i.expr.op,s=$(o,t,n);for(let t=0;t<i.op.arity;t++){let a=r.argLevelConstraints.get(Ia(i.op,t))?.level;a===void 0||Ja(o,t)>=a||(s&&Z(n,e.location,`Level error in instantiating module '${r.name}':\nThe level of the argument ${t+1} of the operator ${o.name} \nmust be at least ${a}.`),e.levelCorrect=!1)}}for(let i of r.argLevelParams.values())for(let a of e.substs)for(let o of e.substs){if(i.op!==a.op||i.param!==o.op||a.expr.kind!==`OpArg`)continue;let s=a.expr.op,c=$(s,t,n);if(s.kind!==`OpDef`)continue;let l=Ja(s,i.index);o.expr.level<=l||(c&&$(o.expr,t,n)&&Z(n,e.location,`Level error when instantiating module '${r.name}':\nThe level of the argument ${i.index} of the operator ${a.op.name}' \nmust be at most ${l}.`),e.levelCorrect=!1)}let a=t=>!e.params.some(e=>e===t);Fa(e.levelConstraints,mo(r,e.substs,i,t,n),a);for(let t of e.substs)Fa(e.levelConstraints,t.expr.levelConstraints,a);Ra(e.argLevelConstraints,ho(r,e.substs,t,n),e=>a(e.param));for(let t of e.substs)Ra(e.argLevelConstraints,t.expr.argLevelConstraints,e=>a(e.param));Na(e.argLevelParams,po(r.argLevelParams,e.substs),t=>!Ha(t,e.params));for(let t of e.substs)Na(e.argLevelParams,t.expr.argLevelParams,t=>!Ha(t,e.params));return e.levelCorrect},$=(e,t,n)=>{if(!Wa(e))return Eo(e,n);switch(e.kind){case`OpAppl`:return Co(e,t,n);case`OpDef`:return wo(e,t,n);case`ThmOrAssumpDef`:return To(e,t,n);case`FormalParam`:return e.levelChecked===0&&(e.levelChecked=t,e.levelParams.add(e),e.allParams.add(e)),!0;case`OpDecl`:return!0;case`Numeral`:case`String`:case`Decimal`:return e.levelChecked<t&&(e.levelChecked=t),!0;case`OpArg`:{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t;let r=e.op;return e.levelCorrect=$(r,t,n),r.kind===`Module`||(e.level=r.level,Ba(e,r)),e.levelCorrect}case`LetIn`:{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t,e.levelCorrect=!0;let r=e.opDefs.filter(e=>e.kind!==`OpDef`||e.defKind!==`ModuleInstance`);for(let i of r)$(i,t,n)||(e.levelCorrect=!1);$(e.body,t,n)||(e.levelCorrect=!1);for(let r of e.instances)$(r,t,n)||(e.levelCorrect=!1);e.level=e.body.level,e.levelParams=new Set(e.body.levelParams),e.allParams=new Set(e.body.allParams),e.appliedParams=e.body.appliedParams,e.nonLeibnizParams=new Set(e.body.nonLeibnizParams),za(e,e.body.requiredLeibnizArgs.values());for(let t of r){let n=t.params??[];za(e,[...t.requiredLeibnizArgs.values()].filter(e=>!n.includes(e.param)))}Fa(e.levelConstraints,e.body.levelConstraints);for(let t of r)Fa(e.levelConstraints,t.levelConstraints);Ra(e.argLevelConstraints,e.body.argLevelConstraints);for(let t of r)Ra(e.argLevelConstraints,t.argLevelConstraints);Na(e.argLevelParams,e.body.argLevelParams);for(let t of r){let n=t.kind===`OpDef`?t.params??[]:[];Na(e.argLevelParams,t.argLevelParams,e=>!Ha(e,n))}for(let t of e.instances)Na(e.argLevelParams,t.argLevelParams);return e.levelCorrect}case`Label`:{if(e.levelChecked>=t)return!0;e.levelChecked=t;for(let r of e.params)$(r,t,n);let r=$(e.body,t,n);return e.level=e.body.level,Ba(e,e.body),e.nonLeibnizParams=e.body.nonLeibnizParams,r}case`At`:{if(e.levelChecked>=t)return!0;e.levelChecked=t;let r=e.except.operands,i=r[0];if(i===void 0)return!0;$(i,t,n),e.level=i.level;let a=[i];for(let i=1;i<r.length;i++){let o=r[i];if(o!==void 0){if($(o,t,n),o===e.component)break;e.level=Math.max(e.level,o.level),a.push(o)}}for(let t of a)Va(e,t);return!0}case`SubstIn`:case`APSubstIn`:{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t,e.levelCorrect=!0;let r=e.body;$(r,t,n)||(e.levelCorrect=!1);for(let r of e.substs)$(r.expr,t,n)||(e.levelCorrect=!1);e.level=e.substs.reduce((e,t)=>r.levelParams.has(t.op)?Math.max(e,t.expr.level):e,r.level);for(let t of r.levelParams)Q(e.levelParams,fo(t,e.substs,!1));if(e.appliedParams=to(e),e.kind===`APSubstIn`){for(let t of r.allParams)Q(e.allParams,fo(t,e.substs,!0));e.nonLeibnizParams=new Set(r.nonLeibnizParams);for(let t of e.substs)r.allParams.has(t.op)&&lo(e,r,t)}else{e.allParams=new Set(r.allParams),e.nonLeibnizParams=new Set(r.nonLeibnizParams);for(let t of e.substs)e.allParams.has(t.op)&&(e.allParams.delete(t.op),Q(e.allParams,t.expr.allParams),lo(e,r,t))}za(e,[...r.requiredLeibnizArgs.values()].filter(t=>co(t.param,e.substs)===void 0));for(let t of e.substs)za(e,t.expr.requiredLeibnizArgs.values()),za(e,uo(e.instantiatedModule,t));let i=go(e.instantiatedModule,n);return e.levelConstraints=mo(r,e.substs,i,t,n),e.argLevelConstraints=ho(r,e.substs,t,n),e.argLevelParams=po(r.argLevelParams,e.substs),e.levelCorrect}case`Instance`:return ko(e,t,n);case`Assume`:{if(e.levelChecked>=t)return!0;e.levelChecked=t;let r=$(e.body,t,n),i=!e.definition||$(e.definition,t,n);return e.level=e.body.level,Ba(e,e.body),e.level!==0&&Z(n,e.location,`Level error: assumptions must be level 0 (Constant), \nbut this one has level ${e.level}.`),r&&i}case`Theorem`:{if(e.levelChecked>=t)return!0;let r=Do(e,[e.definition??e.body,...e.proof?[e.proof]:[]],t,n),i=e.body;if(i.kind===`OpAppl`&&i.operator.name===`$Pick`&&i.level===3)for(let e of i.ranges)e.level!==0&&Z(n,e.location,`Non-constant bound of temporal PICK.`);return i.level===3&&Oo(e.proof,n),r}case`LeafProof`:case`UseOrHide`:return Do(e,e.facts,t,n);case`NonLeafProof`:return Do(e,[...e.steps,...e.instances],t,n);case`DefStep`:return Do(e,e.defs,t,n);case`NewSymb`:return e.levelChecked>=t||(e.levelChecked=t,e.level=e.declaration.level,e.set===void 0)||(e.levelCorrect=$(e.set,t,n),e.level=Math.max(e.level,e.set.level),e.level===3&&(e.levelCorrect=!1,Z(n,e.location,`Level error:
25
25
  Temporal formula used as set.`)),Ba(e,e.set),e.nonLeibnizParams=e.set.nonLeibnizParams),e.levelCorrect;case`AssumeProve`:{if(e.levelChecked>=t)return e.levelCorrect;e.levelChecked=t,e.levelCorrect=!0;for(let r of e.assumptions)$(r,t,n)||(e.levelCorrect=!1);$(e.goal,t,n),e.level=e.assumptions.reduce((e,t)=>Math.max(e,t.level),e.goal.level);let r=[e.goal,...e.assumptions];for(let t of r)Va(e,t),Q(e.nonLeibnizParams,t.nonLeibnizParams);if(r.some($a)){let t=/* @__PURE__ */ new Set;for(let e of r)Q(t,e.appliedParams??e.levelParams);e.appliedParams=t}if(e.levelCorrect)for(let t of e.levelParams)t.kind===`OpDecl`&&t.declKind===2&&Pa(e.levelConstraints,t,2);return e.levelCorrect}}},Ao=e=>{switch(e.kind){case`OpAppl`:return[...e.ranges,...e.operands];case`OpDef`:case`ThmOrAssumpDef`:case`Label`:return[e.body];case`LetIn`:return[...e.opDefs,...e.instances,e.body];case`SubstIn`:case`APSubstIn`:return[e.body,...e.substs.map(e=>e.expr)];case`Instance`:return e.substs.map(e=>e.expr);case`AssumeProve`:return[...e.assumptions,e.goal];case`NewSymb`:return[e.set];default:return[]}},jo=/* @__PURE__ */ new Map([[`Integers`,`Int`],[`Naturals`,`Nat`],[`Reals`,`Reals`]]),Mo=e=>{let t=/* @__PURE__ */ new Set,n=e=>{if(e===void 0||t.has(e))return!1;if(t.add(e),e.kind===`OpAppl`){let t=e.operator;if(t.kind===`OpDecl`||t.kind===`FormalParam`)return!0;if(t.kind===`OpDef`){if(t.name===`BOOLEAN`)return!0;let e=t.module?.name;if(e!==void 0&&jo.get(e)===t.name||n(t))return!0}}return Ao(e).some(n)};return n(e)},No=e=>e.operands.filter(e=>e?.kind===`OpAppl`),Po=e=>{let t=e.operands[0];return t?.kind===`String`?t:void 0},Fo=e=>JSON.stringify([e.operands.length,...No(e).map(e=>Po(e)?.value).sort()]),Io=(e,t=/* @__PURE__ */ new Set)=>{for(let n of e.extendees)t.has(n)||(t.add(n),Io(n,t));return t},Lo=e=>{let t=e.records.map(t=>({domain:Fo(t),warnings:No(t).flatMap(t=>{let n=Po(t),r=n&&xe(e.context,n.value);return n===void 0||r===void 0?[]:[{location:n.location,text:`The field name "${n.value}" in the record constructor is identical to the existing definition or declaration\nnamed ${n.value}, located at ${ce(r.location)}.\nThe field in the record will not take the value of the ${n.value} definition or declaration.\nIn TLA+, field names in records are strings, regardless of any similarly named declarations or definitions.\nTherefore, DOMAIN [${n.value} |-> ...] = {"${n.value}"} holds true.`,isWarning:!0}]})})),n=new Set(t.flatMap(e=>e.warnings.length>0?[e.domain]:[])),r=/* @__PURE__ */ new Set;for(let t of[...[...Io(e)].flatMap(e=>e.records),...e.records]){let e=Fo(t);n.has(e)&&!r.has(e)&&No(t).some(Mo)&&r.add(e)}return t.flatMap(e=>r.has(e.domain)?[]:e.warnings)},Ro=e=>[...e.constants.map(e=>e.name),...e.variables.map(e=>e.name),...e.definitions.map(e=>e.name),...e.instances.flatMap(e=>e.name??[]),...e.assumptions.flatMap(e=>e.name??[]),...e.theorems.flatMap(e=>e.name??[]),...e.units.flatMap(e=>e.kind===`Recursive`?e.declarations.map(e=>e.name):[]),...e.modules.flatMap(e=>[e.name,...Ro(e)])],zo=e=>[...e.recordFields,...e.modules.flatMap(zo)],Bo=e=>`kind`in e&&(e.kind===`Record`||e.kind===`RecordSet`)&&`fields`in e,Vo=e=>`kind`in e&&(e.kind===`Operator`||e.kind===`Function`)&&`name`in e&&typeof e.name==`string`,Ho=e=>{let t=[],n=[],r=[],i=[],a=e=>{for(let t of e){t.name!==void 0&&r.push(t.name);for(let e of t.substitutions)i.push(e.expression)}},o=e=>{for(let t of e)n.push(t),r.push(t.name),i.push(...be(t))},s=[];for(let t of e.units)t.kind===`Definition`&&o([t.definition]),t.kind===`Instance`&&a([t.instance]),t.kind===`Assumption`&&i.push(t.assumption.expression),(t.kind===`Theorem`||t.kind===`Use`)&&s.push(t);let c=/* @__PURE__ */ new Set;for(;s.length>0;){let e=s.pop();typeof e==`object`&&e&&!c.has(e)&&(c.add(e),Bo(e)&&t.push(e),Vo(e)&&(n.push(e),r.push(e.name)),`kind`in e&&e.kind===`Instance`&&`name`in e&&typeof e.name==`string`&&r.push(e.name),s.push(...Object.values(e)))}for(;i.length>0;){let e=i.pop();e!==void 0&&((e.kind===`Record`||e.kind===`RecordSet`)&&t.push(e),e.kind===`Let`?(o(e.definitions),a(e.instances??[]),i.push(e.body)):i.push(...oe(e)))}return{records:t,definitions:n,names:r}},Uo=e=>JSON.stringify([e.fields.length,...e.fields.map(e=>e.name).sort()]),Wo=(e,t)=>{let n=e.map(e=>({module:e.module,dependencies:[...e.dependencies.extendees,...e.dependencies.instancees],imports:[...e.module.extends,...e.module.instances.flatMap(e=>e.name===void 0?[e.module]:[])],names:Ro(e.module)})),r=new Map(n.map(e=>[e.module.name,e])),i=(e,t)=>{let n=/* @__PURE__ */ new Set([e]);for(let e of n)for(let i of t(e)){let e=r.get(i);e!==void 0&&n.add(e)}return[...n]},a=Er.map(e=>e[0]);return n.every(e=>{if(!t.has(e.module.name))return!0;let n=zo(e.module);if(n.length===0)return!0;let r=i(e,e=>e.dependencies),o=/* @__PURE__ */ new Set([...a,...r.flatMap(e=>e.names)]);if(!n.some(e=>o.has(e)))return!0;let s=Ho(e.module),c=new Set(s.records.flatMap(e=>e.fields.some(e=>o.has(e.name))?[Uo(e)]:[]));if(c.size===0)return!0;for(let e of s.names)o.add(e);let l=new Set(i(e,e=>e.module.extends).flatMap(e=>[...e.module.constants,...e.module.variables].map(e=>e.name))),u=i(e,e=>e.imports),d=/* @__PURE__ */ new Map;for(let e of[...u.flatMap(e=>e.module.definitions),...s.definitions]){let t=d.get(e.name);d.set(e.name,d.has(e.name)&&t!==e?void 0:e)}let f=new Set(u.flatMap(e=>e.module.definitions.filter(t=>jo.get(e.module.name)===t.name))),p=e=>{let t=/* @__PURE__ */ new Set,n=[e];for(;n.length>0;){let e=n.pop();if(e!==void 0&&e.kind!==`Lambda`&&e.kind!==`OperatorReference`&&e.kind!==`Subexpression`&&e.kind!==`Selection`){if(e.kind===`Let`){for(let t of e.definitions)o.add(t.name);for(let t of e.instances??[])t.name!==void 0&&o.add(t.name)}if(e.kind===`Identifier`||e.kind===`Apply`){let r=e.kind===`Identifier`?e.name:e.operator;if(r===`BOOLEAN`||l.has(r)||!o.has(r)&&/^\w+$/.test(r))return!0;let i=d.get(r);if(i!==void 0&&f.has(i))return!0;i!==void 0&&!t.has(i)&&(t.add(i),n.push(...be(i)))}n.push(...oe(e))}}return!1};return[...c].every(e=>s.records.some(t=>Uo(t)===e&&t.fields.some(e=>p(e.value))))})},Go=e=>`${ce(e.location)}\n\n${e.text}`,Ko=e=>{let t=e.filter(e=>!e.isWarning),n=e.filter(e=>e.isWarning);return[t.length>0?`*** Errors: ${t.length}\n\n`:``,...t.map(e=>`${Go(e)}\n\n\n`),n.length>0?`*** Warnings: ${n.length}\n\n`:``,...n.map(e=>`${Go(e)}\n\n\n`)].join(``)},qo=4802,Jo=/* @__PURE__ */ new Set([`FiniteSets`,`Sequences`,`Bags`,`Naturals`,`Integers`,`Reals`,`RealTime`,`Randomization`,`TLC`]),Yo=e=>{let t=/* @__PURE__ */ new Set,n=[],r=e=>{t.add(e.name),n.push(...e.extends);for(let t of e.modules)r(t)};return r(e),n.filter(e=>!t.has(e))},Xo=e=>{try{let t=Te(e);return{text:e,module:me(e,t),tokens:t}}catch(e){if(e instanceof _)return;throw e}},Zo=(e,t)=>t===`1.7.4`&&de(e)!==void 0?void 0:Xo(e)?.module.name,Qo=(e,t,n={})=>{let r=ht(e,`.tla`),i=Ve(n.version),a=n.fileName??r,o=n.rootSource!==void 0||H.existsSync(e),c=n.rootSource??(H.existsSync(e)?H.readFileSync(e,`utf8`):i.get(r)),l=[],u=e=>{l.push(e),n.onPrint?.(e)},d=e=>u(`${e}\n`),f=n.version===`1.7.4`,p=f&&n.isXmlExport,m=e=>{n.isXmlExport||d(e)},h=n.describeFile,g=/* @__PURE__ */ new Map([[r,o?`file`:`standard`]]),_=!1,v=[],y=!1,x=!1,S=En(Rt(),d),C=/* @__PURE__ */ new Map,w=[],T=()=>{for(let e of w.splice(0))e.isError?n.onPrintError?.(`${e.text}\n`):d(e.text)},E=e=>{let t=C.get(e),r=t?.module.location.range;if(t===void 0||r===void 0)return;let i=t.text.split(/\r\n|\r|\n/),a=Tr(S,i.slice(r.start.line-1,r.end.line),n.version),o=a.has(`TLA_DIVERGENCE_EXISTS`),s=a.has(`PCAL_DIVERGENCE_EXISTS`),c=o===s?void 0:`The ${o?`TLA+ translation`:`PlusCal algorithm`} in module ${e} has changed since its last translation.`;if(f){let t=o&&s?`The PlusCal algorithm and its TLA+ translation in module ${e} filename since the last translation.`:c;t===void 0?a.has(`ERROR_ENCOUNTERED`)&&w.push({text:`A unexpected problem was encountered attempting to validate the specification for ${e}`,isError:!0}):w.push({text:`!! WARNING: ${t}`,isError:!1});return}let l=o&&s?`Both the PlusCal algorithm and its TLA+ translation in module ${e} have changed since the last translation.`:c??(a.has(`ERROR_ENCOUNTERED`)?`An unexpected problem was encountered attempting to validate the specification for ${e}`:void 0);if(l===void 0)return;let u=!a.has(`ERROR_ENCOUNTERED`)||o||s;v.some(e=>e.text===l)||v.push({location:e,text:l,isWarning:u})},D=(e,t)=>{if(n.isXmlExport||C.has(e))return;let r=Xo(t);if(r===void 0||r.module.name!==e)return;let i=[...C.values()].filter(t=>Yo(t.module).includes(e));C.set(e,r);for(let t of i)E(e);for(let t of Yo(r.module).filter(t=>t!==e&&C.has(t)))E(t)},ee=()=>{if(T(),y)return;y=!0;let e=v.filter(e=>e.isWarning);if(e.length>0){m(`Warnings (${e.length}) during syntax parsing of ${a}:\n\n`);for(let t of e)m(`${Go(t)}\n\n\n`)}e.length!==v.length&&(d(Ko(v)),_=!0,x=!0)},O=e=>{let n=i.get(e),r=t(e),a=r===void 0&&n===void 0&&c!==void 0&&!f?De(c,e):void 0,o=r??a;return g.set(e,r===void 0?a===void 0?`standard`:`root file`:`file`),o!==void 0&&D(e,o),o??n},k=e=>{if(_=!0,e instanceof b){d(`\nFatal errors while parsing TLA+ spec in file ${a}\n`),d(e.message),d(Ko(v));return}if(!(e instanceof s))throw e;let t={location:e.location,text:e.message,isWarning:!1},n=f&&e.parseError?.includes(` and token "" `);e.parseError!==void 0&&!n&&!p&&d(e.parseError),d(`\nFatal errors while parsing TLA+ spec in file ${a}\n`),n?d(`java.lang.NullPointerException: Cannot invoke "String.length()" because "str" is null`):f?(d(`tla2sany.semantic.AbortException`),u(`*** Abort messages: 1\n\n${Go(t)}\n\n\n`)):(d(Go(t)),d(Ko(y?[t]:[...v,t])))},A=e=>{ee(),(h||p)&&!x&&d(`Semantic processing of module ${e}`)},j=(()=>{try{if(c===void 0)throw new s(`Cannot find source file for module ${a}`,void 0);return D(r,c),Aa(c,O,{rootFileName:r,rootFilePath:n.isXmlExport?`${a.replace(/\.tla$/,``)}.tla`:void 0,version:n.version,rootExtendees:n.rootExtendees,parsedSources:C,onParse:e=>{h&&d(`Parsing file ${h(e,g.get(e)??`file`)}`),e===r&&E(r),T()},onAnalyze:A,onModule:(e,t)=>{if(x||(t.every(e=>e.isWarning)&&Eo(e,{messages:t,isTlc174:f}),t.length===0))return;if(t.some(e=>!e.isWarning)&&(_=!0),f)return d(`Semantic errors:\n\n${Ko(t)}`);let n=t.filter(e=>e.isWarning);if(n.length>0){m(`*** Warnings: ${n.length}\n`);for(let e of n)m(`${Go(e)}\n\n\n`)}let r=t.filter(e=>!e.isWarning);if(r.length!==0){d(`Semantic errors:\n\n*** Errors: ${r.length}\n`);for(let e of r)d(`${Go(e)}\n\n`)}}})}catch(e){k(e);return}})(),M=()=>j?.sources.flatMap(e=>Jo.has(e.module.name)?[]:[e.module.name])??[],te=!1;return{isAcceptable:j!==void 0&&!_&&!n.isXmlExport&&!f&&v.every(e=>e.isWarning)&&Wo(j.sources,new Set(M())),analyze:()=>{if(te)for(let e of j?.sources??[])e.module=me(e.text,e.tokens);let e=(()=>{try{return j?.generate()}catch(e){k(e);return}})();if(e!==void 0&&ee(),e!==void 0&&!_&&!n.isXmlExport&&!f){let t=e.modules.filter(e=>!Jo.has(e.name));if(h)for(let e of t)d(`Linting of module ${e.name}`);let r=n.suppressedCodes?.includes(qo)?[]:t.flatMap(Lo),i=n.errorCodes?.includes(qo)?`Warning treated as error: `:``;for(let e of r)d(`${i}${Go(e)}\n\n\n`);i&&r.length>0&&(_=!0)}return{text:l.join(``),isFailed:_,specification:x?void 0:e}},accept:()=>{for(let e of j?.sources??[])A(e.module.name);if(ee(),h)for(let e of M())d(`Linting of module ${e}`)},shareModules:()=>(te=!0,new Map(j?.sources.map(e=>[e.text,e])))}},$o=e=>e.kind===`OpDef`&&e.defKind!==`BuiltIn`&&e.defKind!==`ModuleInstance`,es=(e,t)=>e.context.symbols.find(e=>$o(e)&&e.name===t),ts=e=>o(new r(`Parsing or semantic analysis failed.Parsing or semantic analysis failed.${e}`),a.specParseError),ns=(e,t,n,r,i,a)=>{let o=e=>ts(`Unknown location\n\n${e} while parsing breakpoint expression "${r}"`);try{he(e)}catch(e){throw e instanceof _?ts(`Syntax error while parsing breakpoint expression "${r}"`):e}let s=!1,c=!1,l=(()=>{try{return Aa(e,i,{version:a,onModule:(e,n)=>{let r=()=>n.every(e=>e.isWarning);if(!r())return;let i=Eo(e,{messages:n,isTlc174:a===`1.7.4`});e.name===t&&(s=!0,c=i&&r())}}).generate()}catch(e){throw e instanceof _?o(`Semantic error`):e}})();if(!s)throw o(`Semantic error`);if(!c)throw o(`Level-checking error`);let u=es(l.root,n)?.level??0;if(u===3)throw ts(`Unknown location\n\nDebug expressions must be action-level or below; actual level: ${u} (Temporal)`)},rs=(e,t,n,r,i)=>{let a=n=>n===t.name?e:r(n),o=Date.now();return n.map((e,n)=>{if(es(t,e.expression))return{name:e.expression,module:void 0,source:void 0};let r=`__DebuggerModule__${o+n}`,s=`__DebuggerExpr__${o+n}`,c=`---- MODULE ${r} ----\nEXTENDS ${t.name}\n\n${s} == ${e.expression}\n====`;return ns(c,r,s,e.expression,a,i),{name:s,module:r,source:c}})},is=(1n<<63n)-1n,as=[[-123456,-123456],[-1,0],[1e3,1003],[1005,1005],[1101,1102],[2e3,2001],[2100,2149],[2154,2274],[2279,2287],[2300,2301],[2400,2405],[2501,2502],[2772,2780],[3e3,3002],[3100,3114],[4e3,4002],[5001,5007],[7e3,7010],[2e4,2e4]],os=[[4003,4005],[4200,4206],[4220,4224],[4240,4247],[4260,4262],[4270,4275],[4290,4294],[4310,4315],[4330,4337],[4350,4357]],ss=/* @__PURE__ */ new Map([[4800,`EXTENDED_MODULES_SYMBOL_UNIFICATION_AMBIGUITY`],[4801,`INSTANCED_MODULES_SYMBOL_UNIFICATION_AMBIGUITY`],[4802,`RECORD_CONSTRUCTOR_FIELD_NAME_CLASH`],[4803,`PLUSCAL_ALGORITHM_AND_TRANSLATION_CHANGED_SINCE_LAST_TRANSLATION`],[4804,`PLUSCAL_ALGORITHM_CHANGED_SINCE_LAST_TRANSLATION`],[4805,`PLUSCAL_TRANSLATION_CHANGED_SINCE_LAST_TRANSLATION`]]),cs=(e,t,n,r)=>({module:e,constant:n,operators:[{kind:`postcondition`,operator:t}],communityModule:r}),ls={json:cs(`_JsonTrace`,`_JsonTrace`,`_JsonTraceFile`,void 0),tla:cs(`_TLAPlusCounterExample`,`_TLAPlusCounterExample`,`_TLAPlusCounterExampleFile`,`IOUtils`),tlc:cs(`_TLCTrace`,`_TLCTrace`,`_TLCTraceFile`,void 0),tlcplain:cs(`_TLCTracePlain`,`_TLCTrace`,`_TLCTraceFile`,`IOUtils`),tlcTESpec:cs(`_TLCTESpec`,`_TLCTrace`,`_TLCTraceFile`,`IOUtils`),tlcaction:cs(`_TLCActionTrace`,`_TLCTrace`,`_TLCTraceFile`,`IOUtils`),dot:cs(`_DotTrace`,`_DotTrace`,`_DotTraceFile`,`GraphViz`),cbor:cs(`_CBORTrace`,`_CBORTrace`,`_CBORTraceFile`,`CBOR`)},us=(e,t)=>({module:e,constant:`${t}InputFile`,operators:[{kind:`constraint`,operator:`${t}Constraint`},{kind:`view`,operator:`${t}View`}],communityModule:void 0}),ds={tlc:us(`_TLCTrace`,`_TLCTrace`),json:us(`_JsonTrace`,`_JsonTrace`)},fs=(e,t)=>e.some(e=>t>=e[0]&&t<=e[1]),ps=(e,t)=>{if(e===``)return[e];let n=e.split(t);for(;n.at(-1)===``;)n.pop();return n},ms=(e,t)=>[...new Set(e.filter(e=>t.includes(e)))].sort((e,t)=>e-t),hs=/\p{Nd}/u,gs=e=>{let t=0;for(;hs.test(String.fromCharCode(e-t-1));)t++;return t%10},_s=(e,t)=>{let n=e.replace(/\p{Nd}/gu,e=>e.length===1?String(gs(e.charCodeAt(0))):e);if(!/^[+-]?\d+$/.test(n))return;let r=BigInt(n);return BigInt.asIntN(t,r)===r?r:void 0},vs=()=>({specs:[],configPath:void 0,seed:void 0,aril:0n,workers:void 0,coverage:void 0,livenessCheck:`default`,dump:void 0,fingerprintIndex:void 0,maxSetSize:void 0,isLazyValueExpanded:!0,isViewPrinted:!1,isFramePrinted:!1,isShared:!1,metadir:void 0,recoverDirectory:void 0,isCheckpointRequested:!1,mode:`model-check`,dfidDepth:void 0,traceDepth:100,traceCount:void 0,scheduler:`random`,actionStatistics:void 0,behaviorFile:void 0,isTool:!1,isContinued:!1,isDeadlockChecked:!0,isWarningEnabled:!0,isTraceSpecForced:!1,isTraceSpecDisabled:!1,isTraceBinaryDisabled:!1,traceSpecPath:void 0,isDiffTrace:!1,suppressedCodes:[],errorCodes:[],userFile:void 0,invariants:[],moduleOperators:[],communityTraceModules:[]}),ys={"-modelcheck":()=>{},"-difftrace":e=>{e.isDiffTrace=!0},"-deadlock":e=>{e.isDeadlockChecked=!1},"-cleanup":()=>{},"-frame":e=>{e.isFramePrinted=!0},"-shared":e=>{e.isShared=!0},"-nowarning":e=>{e.isWarningEnabled=!1},"-gzip":()=>{},"-terse":e=>{e.isLazyValueExpanded=!1},"-continue":e=>{e.isContinued=!0},"-view":e=>{e.isViewPrinted=!0},"-debug":()=>{},"-tool":e=>{e.isTool=!0}},bs=(e,t,n)=>(r,i)=>{let a=_s(i,e);return a===void 0?`${t} But encountered ${i}`:n(r,a,i)},xs=(e,t,n,r)=>({missing:t,apply:bs(32,n,(t,n)=>{let i=BigInt.asIntN(32,n*60000n);if(i<0n)return`Error: expect a nonnegative integer for -${e} option.`;r(t,Number(i)/6e4)})}),Ss={"-teSpecOutDir":{missing:`Error: expected a path for -teSpecOutDir option.`,apply:(e,t)=>{e.traceSpecPath=t}},"-userFile":{missing:`Error: need to specify the full qualified file.`,apply:(e,t)=>{try{H.closeSync(H.openSync(t,`w`))}catch(e){if(S(e)===void 0)throw e;return`Error: Failed to create user output log file.`}e.userFile=t}},"-lncheck":{missing:`Error: expect a strategy such as final for -lncheck option.`,apply:(e,t)=>{e.livenessCheck=t.toLowerCase()}},"-config":{missing:`Error: expect a file name for -config option.`,apply:(e,t)=>{let n=t.replace(/\.cfg$/,``);e.configPath=n.endsWith(`.tla`)?n:`${n}.cfg`}},"-coverage":xs(`coverage`,`Error: coverage report interval required.`,`Error: An integer for coverage report interval required.`,(e,t)=>{e.coverage=t}),"-checkpoint":xs(`checkpoint`,`Error: checkpoint interval required.`,`Error: An integer for checkpoint interval is required.`,(e,t)=>{e.isCheckpointRequested=t>0}),"-depth":{missing:`Error: trace length required.`,apply:bs(32,`Error: An integer for trace length required.`,(e,t)=>{e.traceDepth=Number(t)})},"-seed":{missing:`Error: seed required.`,apply:bs(64,`Error: An integer for seed required.`,(e,t)=>{e.seed=t})},"-aril":{missing:`Error: aril required.`,apply:bs(64,`Error: An integer for aril required.`,(e,t)=>{e.aril=t})},"-maxSetSize":{missing:`Error: maxSetSize required.`,apply:bs(32,`Error: An integer for maxSetSize required.`,(e,t,n)=>{if(t<1n)return`Error: Value in interval [0, ${Pe}] for maxSetSize required. But encountered ${n}`;e.maxSetSize=Number(t)})},"-recover":{missing:`Error: need to specify the metadata directory for recovery.`,apply:(e,t)=>{e.recoverDirectory=t}},"-metadir":{missing:`Error: need to specify the metadata directory.`,apply:(e,t)=>{e.metadir=t}},"-workers":{missing:`Error: expect an integer or 'auto' for -workers option.`,apply:(e,t)=>{let n=t.trim().toLowerCase()===`auto`?BigInt(Tt()):_s(t,32);if(n===void 0)return`Error: worker number or 'auto' required. But encountered ${t}`;if(n<1n)return`Error: at least one worker required.`;e.workers=Number(n)}},"-dfid":{missing:`Error: expect a nonnegative integer for -dfid option.`,apply:bs(32,`Error: expect a nonnegative integer for -dfid option.`,(e,t)=>{if(t<0n)return`Error: expect a nonnegative integer for -dfid option.`;e.dfidDepth=Number(t)})},"-fp":{missing:`Error: expect an integer for -fp option.`,apply:bs(32,`Error: A number for -fp is required.`,(e,t)=>{if(t<0n||t>=131)return`Error: The number for -fp must be between 0 and 130 (inclusive).`;e.fingerprintIndex=Number(t)})},"-fpmem":{missing:`Error: fpset memory size required.`,apply:(e,t)=>{let n=ye(t);if(n===void 0||n<0||Number.isNaN(n))return`Error: An positive integer or a fraction for fpset memory size/percentage required. But encountered ${t}`;n>1&&process.stdout.write(`Using -fpmem with an abolute memory value has been deprecated. Please allocate memory for the TLC process via the JVM mechanisms and use -fpmem to set the fraction to be used for fingerprint storage.
26
- `)}},"-fpbits":{missing:`Error: fpbits required.`,apply:bs(32,`Error: An integer for fpbits required.`,(e,t,n)=>t<0n||t>30n?`Error: Value in interval [0, 30] for fpbits required. But encountered ${n}`:void 0)}},Cs={"-loadtrace":{name:`-loadTrace`,missing:`Error: A format and a file name for loading traces required.`,formats:ds},"-dumptrace":{name:`-dumpTrace`,missing:`Error: A format and a file name for dumping traces required.`,formats:ls}},ws=e=>{let t=vs(),n=0,r=e=>({kind:`command-line`,error:e,isTool:t.isTool}),i=()=>({kind:`uncaught`,error:`java.lang.ArrayIndexOutOfBoundsException: Index ${e.length} out of bounds for length ${e.length}`,isTool:t.isTool}),a={tlc:[],sany:[]},o={tlc:[],sany:[]},s=()=>e[n],c=()=>e[n++];for(;n<e.length;){let l=c();if(Object.hasOwn(ys,l))ys[l](t);else if(Object.hasOwn(Ss,l)){let e=c();if(e===void 0)return r(Ss[l].missing);let n=Ss[l].apply(t,e);if(n!==void 0)return r(n)}else if(l===`-simulate`||l===`-generate`){t.mode=l===`-generate`?`generate`:`simulate`;let e=s();if(e===void 0||![`stats=`,`file=`,`num=`,`sched`].some(t=>e.includes(t)))continue;n++;let i=e.split(`,`),a=i.findLast(e=>e.startsWith(`file=`));a!==void 0&&(t.behaviorFile=a.replaceAll(`file=`,``)),i.includes(`sched=rl`)?t.scheduler=`rl`:i.includes(`sched=rlaction`)&&t.scheduler!==`rl`&&(t.scheduler=`rlaction`);let o=i.findLast(e=>e===`stats=basic`||e===`stats=full`);o!==void 0&&(t.actionStatistics=o===`stats=basic`?`basic`:`full`);for(let e of i.filter(e=>e.startsWith(`num=`))){let n=e.replaceAll(`num=`,``);if(t.traceCount=_s(n,64),t.traceCount===void 0)return{kind:`uncaught`,error:`java.lang.NumberFormatException: For input string: "${n}"`,isTool:t.isTool}}if((t.traceCount??is)===is&&t.behaviorFile!==void 0)return r(`Error: You need to specify a 'num' argument when using the 'file' argument, for example: '"num=5,file=test.txt"'.`)}else if(l===`-suppressMessages`||l===`-messagesAsErrors`){let e=c();if(e===void 0)return r(`Error: ${l} requires a comma-separated list of message codes.`);let t=l===`-suppressMessages`?a:o;for(let n of ps(e,`,`)){let e=n.replace(/^[^!-\uffff]+|[^!-\uffff]+$/g,``),i=_s(e,32);if(i===void 0)return r(`Error: For input string: "${e}"`);let o=Number(i);if(fs(as,o))t.tlc.push(o);else{if(!ss.has(o)&&!fs(os,o))return r(`Error: unknown message code: ${o}`);if(t===a&&!ss.has(o))return r(`Error: code ${o} is an error and cannot be suppressed.`);t.sany.push(o)}}}else if(l===`-inv`){let e=c();if(e===void 0)return i();t.invariants.push({modules:[...new Set([...e.matchAll(/INSTANCE\s+(\w+)/g)].map(e=>e[1]))],expression:e})}else if(l===`-invlevel`){let e=c();if(e===void 0)return i();if(_s(e,32)===void 0)return r(`Error: An integer for -invlevel required. But encountered ${e}`);t.invariants.push({modules:[`TLC`,`Naturals`],expression:`LET _T == INSTANCE TLC _N == INSTANCE Naturals IN _N!<(_T!TLCGet("level"), ${e})`})}else if(l===`-debugger`){let e=s();e!==void 0&&[`port=`,`nosuspend`,`nohalt`,`suspend`,`halt`].some(t=>e.includes(t))&&n++}else if(l===`-generateSpecTE`)t.isTraceSpecForced=!0,s()===`nomonolith`&&n++;else if(l===`-noGenerateSpecTE`||l.toLowerCase()===`-note`)t.isTraceSpecDisabled=!0;else if(l===`-noGenerateSpecTEBin`||l.toLowerCase()===`-notebin`)t.isTraceBinaryDisabled=!0;else{if(l===`-help`||l===`-h`)return`usage`;if(l===`-dump`){let i=s();if(i?.startsWith(`class,`))return r(`Trying to instantiate a custom IStateWriter implementation ${i.replaceAll(`class,`,``)}.`);let a=i?.startsWith(`dot`)&&n+1<e.length?2:1;if(t.dump=e.slice(n,n+a),n+=a,t.dump.length===0)return r(`Error: A file name for dumping states required.`)}else if(Object.hasOwn(Cs,l.toLowerCase())){let i=Cs[l.toLowerCase()];if(n+1>=e.length)return r(i.missing);let a=c(),o=c(),s=Object.keys(i.formats).find(e=>e.toLowerCase()===a.toLowerCase());if(s===void 0)return r(`Error: Unknown format ${a} given to ${i.name}.`);let u=i.formats[s];u.communityModule!==void 0&&t.communityTraceModules.push({format:s,module:u.communityModule}),t.moduleOperators.push(...u.operators.map(e=>({...e,module:u.module,constants:{[u.constant]:o}})))}else if(l.toLowerCase()===`-postcondition`){let e=c();if(e===void 0)return r(`Error: Module!Operator for postCondition required.`);if(!e.includes(`!`))return r(`Module!Operator for postCondition required. Encountered: ${e}`);let n=ps(e,`!`);if(n.length!==2)return r(`Module!Operator for postCondition must be of the form module!operator. Encountered: ${e}`);if(n[0]===``)return r(`Module name for postCondition required. Encountered: ${e}`);if(n[0].includes(`.`))return r(`Module name for postCondition must not contain a dot. Encountered: ${n[0]}`);if(n[1].includes(`.`))return r(`Operator name for postCondition must not contain a dot. Encountered: ${n[1]}`);t.moduleOperators.push({kind:`postcondition`,module:n[0],operator:n[1]})}else{if(l.startsWith(`-`))return r(`Error: unrecognized option: ${l}`);t.specs.push(l)}}}if(!t.isWarningEnabled&&a.tlc.length+a.sany.length>0)return r(`Error: -nowarning already suppresses all warnings, making -suppressMessages redundant. Remove -nowarning to suppress only the specified messages, or remove -suppressMessages to suppress all warnings.`);let l=ms(a.tlc,o.tlc),u=l.length>0?l.map(String):ms(a.sany,o.sany).map(e=>ss.get(e)??String(e));return u.length>0?r(`Error: The following codes were set to both -suppressMessages and -messagesAsErrors: [${u.join(`, `)}]`):(t.suppressedCodes=[...a.tlc,...a.sany],t.errorCodes=[...o.tlc,...o.sany],t)},Ts=()=>BigInt(Math.floor(Math.random()*2**32)),Es=(e,t)=>({...e,workers:e.workers??t,fingerprintIndex:e.fingerprintIndex??Math.floor(Math.random()*131),seed:e.seed??BigInt.asIntN(64,Ts()<<32n|Ts()),aril:e.seed===void 0?0n:e.aril});var Ds=`0.0.10-dev.a2d447617`;const Os=(e,t)=>e.print(B.computingInitProgress,V.none,`Computed ${t} initial states...`),ks=(e,t)=>e===`invariant-violation`?{code:B.invariantViolatedInitial,text:`Invariant ${t} is violated by the initial state:`}:{code:B.propertyViolatedInitial,text:`Property ${t} is violated by the initial state:`},As=(e,t)=>{for(let n of t??[]){if(typeof n==`string`){e.printOutput(n);continue}if(n.kind===`initial-states-progress`){Os(e,n.count);continue}if(n.kind===`warning`){e.print(n.code,V.warning,n.text);continue}if(n.kind===`violation`){Js(n.status,n.violation,e);continue}let t=ks(n.status,n.name);e.print(t.code,V.error,`${t.text}\n${Ae(n.state)}`)}},js={code:B.behaviorUpToThisPoint,text:`The behavior up to this point is:`},Ms={code:B.counterExample,text:`The following behavior constitutes a counter-example:
26
+ `)}},"-fpbits":{missing:`Error: fpbits required.`,apply:bs(32,`Error: An integer for fpbits required.`,(e,t,n)=>t<0n||t>30n?`Error: Value in interval [0, 30] for fpbits required. But encountered ${n}`:void 0)}},Cs={"-loadtrace":{name:`-loadTrace`,missing:`Error: A format and a file name for loading traces required.`,formats:ds},"-dumptrace":{name:`-dumpTrace`,missing:`Error: A format and a file name for dumping traces required.`,formats:ls}},ws=e=>{let t=vs(),n=0,r=e=>({kind:`command-line`,error:e,isTool:t.isTool}),i=()=>({kind:`uncaught`,error:`java.lang.ArrayIndexOutOfBoundsException: Index ${e.length} out of bounds for length ${e.length}`,isTool:t.isTool}),a={tlc:[],sany:[]},o={tlc:[],sany:[]},s=()=>e[n],c=()=>e[n++];for(;n<e.length;){let l=c();if(Object.hasOwn(ys,l))ys[l](t);else if(Object.hasOwn(Ss,l)){let e=c();if(e===void 0)return r(Ss[l].missing);let n=Ss[l].apply(t,e);if(n!==void 0)return r(n)}else if(l===`-simulate`||l===`-generate`){t.mode=l===`-generate`?`generate`:`simulate`;let e=s();if(e===void 0||![`stats=`,`file=`,`num=`,`sched`].some(t=>e.includes(t)))continue;n++;let i=e.split(`,`),a=i.findLast(e=>e.startsWith(`file=`));a!==void 0&&(t.behaviorFile=a.replaceAll(`file=`,``)),i.includes(`sched=rl`)?t.scheduler=`rl`:i.includes(`sched=rlaction`)&&t.scheduler!==`rl`&&(t.scheduler=`rlaction`);let o=i.findLast(e=>e===`stats=basic`||e===`stats=full`);o!==void 0&&(t.actionStatistics=o===`stats=basic`?`basic`:`full`);for(let e of i.filter(e=>e.startsWith(`num=`))){let n=e.replaceAll(`num=`,``);if(t.traceCount=_s(n,64),t.traceCount===void 0)return{kind:`uncaught`,error:`java.lang.NumberFormatException: For input string: "${n}"`,isTool:t.isTool}}if((t.traceCount??is)===is&&t.behaviorFile!==void 0)return r(`Error: You need to specify a 'num' argument when using the 'file' argument, for example: '"num=5,file=test.txt"'.`)}else if(l===`-suppressMessages`||l===`-messagesAsErrors`){let e=c();if(e===void 0)return r(`Error: ${l} requires a comma-separated list of message codes.`);let t=l===`-suppressMessages`?a:o;for(let n of ps(e,`,`)){let e=n.replace(/^[^!-\uffff]+|[^!-\uffff]+$/g,``),i=_s(e,32);if(i===void 0)return r(`Error: For input string: "${e}"`);let o=Number(i);if(fs(as,o))t.tlc.push(o);else{if(!ss.has(o)&&!fs(os,o))return r(`Error: unknown message code: ${o}`);if(t===a&&!ss.has(o))return r(`Error: code ${o} is an error and cannot be suppressed.`);t.sany.push(o)}}}else if(l===`-inv`){let e=c();if(e===void 0)return i();t.invariants.push({modules:[...new Set([...e.matchAll(/INSTANCE\s+(\w+)/g)].map(e=>e[1]))],expression:e})}else if(l===`-invlevel`){let e=c();if(e===void 0)return i();if(_s(e,32)===void 0)return r(`Error: An integer for -invlevel required. But encountered ${e}`);t.invariants.push({modules:[`TLC`,`Naturals`],expression:`LET _T == INSTANCE TLC _N == INSTANCE Naturals IN _N!<(_T!TLCGet("level"), ${e})`})}else if(l===`-debugger`){let e=s();e!==void 0&&[`port=`,`nosuspend`,`nohalt`,`suspend`,`halt`].some(t=>e.includes(t))&&n++}else if(l===`-generateSpecTE`)t.isTraceSpecForced=!0,s()===`nomonolith`&&n++;else if(l===`-noGenerateSpecTE`||l.toLowerCase()===`-note`)t.isTraceSpecDisabled=!0;else if(l===`-noGenerateSpecTEBin`||l.toLowerCase()===`-notebin`)t.isTraceBinaryDisabled=!0;else{if(l===`-help`||l===`-h`)return`usage`;if(l===`-dump`){let i=s();if(i?.startsWith(`class,`))return r(`Trying to instantiate a custom IStateWriter implementation ${i.replaceAll(`class,`,``)}.`);let a=i?.startsWith(`dot`)&&n+1<e.length?2:1;if(t.dump=e.slice(n,n+a),n+=a,t.dump.length===0)return r(`Error: A file name for dumping states required.`)}else if(Object.hasOwn(Cs,l.toLowerCase())){let i=Cs[l.toLowerCase()];if(n+1>=e.length)return r(i.missing);let a=c(),o=c(),s=Object.keys(i.formats).find(e=>e.toLowerCase()===a.toLowerCase());if(s===void 0)return r(`Error: Unknown format ${a} given to ${i.name}.`);let u=i.formats[s];u.communityModule!==void 0&&t.communityTraceModules.push({format:s,module:u.communityModule}),t.moduleOperators.push(...u.operators.map(e=>({...e,module:u.module,constants:{[u.constant]:o}})))}else if(l.toLowerCase()===`-postcondition`){let e=c();if(e===void 0)return r(`Error: Module!Operator for postCondition required.`);if(!e.includes(`!`))return r(`Module!Operator for postCondition required. Encountered: ${e}`);let n=ps(e,`!`);if(n.length!==2)return r(`Module!Operator for postCondition must be of the form module!operator. Encountered: ${e}`);if(n[0]===``)return r(`Module name for postCondition required. Encountered: ${e}`);if(n[0].includes(`.`))return r(`Module name for postCondition must not contain a dot. Encountered: ${n[0]}`);if(n[1].includes(`.`))return r(`Operator name for postCondition must not contain a dot. Encountered: ${n[1]}`);t.moduleOperators.push({kind:`postcondition`,module:n[0],operator:n[1]})}else{if(l.startsWith(`-`))return r(`Error: unrecognized option: ${l}`);t.specs.push(l)}}}if(!t.isWarningEnabled&&a.tlc.length+a.sany.length>0)return r(`Error: -nowarning already suppresses all warnings, making -suppressMessages redundant. Remove -nowarning to suppress only the specified messages, or remove -suppressMessages to suppress all warnings.`);let l=ms(a.tlc,o.tlc),u=l.length>0?l.map(String):ms(a.sany,o.sany).map(e=>ss.get(e)??String(e));return u.length>0?r(`Error: The following codes were set to both -suppressMessages and -messagesAsErrors: [${u.join(`, `)}]`):(t.suppressedCodes=[...a.tlc,...a.sany],t.errorCodes=[...o.tlc,...o.sany],t)},Ts=()=>BigInt(Math.floor(Math.random()*2**32)),Es=(e,t)=>({...e,workers:e.workers??t,fingerprintIndex:e.fingerprintIndex??Math.floor(Math.random()*131),seed:e.seed??BigInt.asIntN(64,Ts()<<32n|Ts()),aril:e.seed===void 0?0n:e.aril});var Ds=`0.0.10-dev.a43e3a937`;const Os=(e,t)=>e.print(B.computingInitProgress,V.none,`Computed ${t} initial states...`),ks=(e,t)=>e===`invariant-violation`?{code:B.invariantViolatedInitial,text:`Invariant ${t} is violated by the initial state:`}:{code:B.propertyViolatedInitial,text:`Property ${t} is violated by the initial state:`},As=(e,t)=>{for(let n of t??[]){if(typeof n==`string`){e.printOutput(n);continue}if(n.kind===`initial-states-progress`){Os(e,n.count);continue}if(n.kind===`warning`){e.print(n.code,V.warning,n.text);continue}if(n.kind===`violation`){Js(n.status,n.violation,e);continue}let t=ks(n.status,n.name);e.print(t.code,V.error,`${t.text}\n${Ae(n.state)}`)}},js={code:B.behaviorUpToThisPoint,text:`The behavior up to this point is:`},Ms={code:B.counterExample,text:`The following behavior constitutes a counter-example:
27
27
  `},Ns={"error-trace":{heading:js,isLastDiffed:!1},"counter-example":{heading:Ms,isLastDiffed:!0}},Ps=(e,t,n,r)=>e.print(B.statePrint2,V.state,`${t}: <${n.label??n.action??`Initial predicate`}>\n${r}`),Fs=(e,t,n)=>{let r=Ns[n].heading,i=n===`counter-example`&&e.version===`1.7.4`;t.length>0&&e.print(r.code,V.error,r.text);try{for(let r=0;r<t.length;r++){let a=t[r];(r>0||i)&&As(e,a.output),As(e,a.aliasOutput);let o=e.isDiffTrace&&r>0&&(Ns[n].isLastDiffed||r<t.length-1);Ps(e,r+1,a,Ae(a.state,o?je(a.state,t[r-1].state):void 0))}}catch(t){e.print(B.general,V.error,h(t))}},Is=(e,t)=>t===`1.7.4`||e.length===0?`Temporal properties were violated.
28
28
  `:e.length===1?`Temporal property ${e[0]} was violated.\n`:`Temporal properties ${e.slice(0,-1).join(`, `)}${e.length>2?`,`:``} and ${e[e.length-1]} were violated.\n`,Ls=e=>e.filter((t,n)=>t!==e[n-1]).map((e,t)=>`${t}) ${Fe(e)}\n`).toReversed().join(``),Rs=e=>{if(e.length===0)return` The error call stack is empty.
29
29
  `;let t=[];for(let n=0;n<e.length;n++){let r=e[n],i=r.location.range;r!==e[n-1]&&i&&t.push(`${t.length}. Line ${i.start.line}, column ${i.start.column} to line ${i.end.line}, column ${i.end.column} in ${i.module}\n`)}return`${t.join(``)}\n`},zs=(e,t)=>{let n=t.generated,r=t.distinct,i=He(/* @__PURE__ */ new Date);n===r?e.print(B.initGenerated1,V.none,`Finished computing initial states: ${r} distinct state${r===1?``:`s`} generated at ${i}.`):e.print(B.initGenerated2,V.none,`Finished computing initial states: ${n} state${n===1?``:`s`} generated, with ${r} of them distinct at ${i}.`)},Bs=(e,t,n)=>{let r=e=>String(e).replace(/\B(?=(?:\d{3})+$)/g,`,`),i=(e,t)=>e===void 0?``:` (${r(e)} ${t}/min)`;e.print(B.progress,V.none,`Progress(${Math.max(t.depth,1)}) at ${He(/* @__PURE__ */ new Date)}: ${r(t.generatedStates)} states generated${i(n?.[0],`s`)}, ${r(t.distinctStates)} distinct states found${i(n?.[1],`ds`)}, ${r(t.queuedStates)} states left on queue.`)},Vs={init:B.coverageInit,next:B.coverageNext,invariant:B.coverageProperty,implied:B.coverageProperty,constraint:B.coverageConstraint},Hs=(e,t,n)=>{let r=(t,n)=>e.print(t,V.none,n);r(B.coverageStart,`The coverage statistics at ${He(/* @__PURE__ */ new Date)} (see https://explain.tlapl.us/module-coverage-statistics for how to interpret the following statistics).`);for(let e of t.variables)r(B.coverageVariable,`<${e.label}>: ${e.distinct}`);for(let e of t.relations){let t=Vs[e.kind];r(t,t===B.coverageProperty?`<${e.label}>`:`<${e.label}>: ${e.distinct}:${e.generated}`);for(let t of e.expressions){let e=` ${`|`.repeat(t.depth)}${t.location}`;t.cost>0?r(B.coverageValueCost,`${e}: ${t.count}:${t.cost}`):r(B.coverageValue,`${e}: ${t.count}`)}}Date.now()-n>3e5?r(B.coverageEndOverhead,`End of statistics (please note that for performance reasons large models
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tla",
3
- "version": "0.0.10-dev.a2d447617",
3
+ "version": "0.0.10-dev.a43e3a937",
4
4
  "description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
5
5
  "keywords": [
6
6
  "formal verification",