tla-ts 0.0.9-dev.2813db5 → 0.0.9-dev.4ce0657
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/README.md +21 -0
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +15 -15
- package/dist/deciders.js +48 -48
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/prove.cjs +16 -16
- package/dist/prove.js +20 -20
- package/dist/run.cjs +28 -28
- package/dist/run.js +31 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +1 -1
- package/dist/transfer.cjs +18 -18
- package/dist/transfer.js +26 -26
- package/dist/worker.cjs +4 -4
- package/dist/worker.js +4 -4
- package/package.json +3 -1
- package/src/check.ts +44 -31
- package/src/cli/options.ts +1 -1
- package/src/cli/tlc.ts +17 -8
- package/src/cli/typescript.ts +26 -0
- package/src/environment.ts +4 -0
- package/src/errors.ts +15 -0
- package/src/evaluate.ts +65 -10
- package/src/instances.ts +67 -6
- package/src/liveness-checker.ts +6 -3
- package/src/liveness.ts +7 -3
- package/src/prover/smt/solver/solver.ts +31 -27
- package/src/successors.ts +3 -3
- package/src/typescript/actions.ts +494 -0
- package/src/typescript/collections.ts +615 -0
- package/src/typescript/compile.ts +70 -0
- package/src/typescript/context.ts +106 -0
- package/src/typescript/emit.ts +122 -0
- package/src/typescript/expressions.ts +508 -0
- package/src/typescript/formula.ts +160 -0
- package/src/typescript/functions.ts +295 -0
- package/src/typescript/model.ts +164 -0
- package/src/typescript/names.ts +116 -0
- package/src/typescript/program.ts +51 -0
- package/src/typescript/properties.ts +141 -0
- package/src/typescript/scope.ts +117 -0
- package/src/typescript/steps.ts +175 -0
- package/src/typescript/types.ts +178 -0
- package/src/values.ts +11 -9
package/dist/worker.cjs
CHANGED
|
@@ -12,13 +12,13 @@ const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenes
|
|
|
12
12
|
`)}`,_=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,v=(e,t)=>m([{location:_(t),message:e}]);var y=class extends u{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},b=class extends u{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const x=`This was a Java StackOverflowError. It was probably the result
|
|
13
13
|
of an incorrect recursive function definition that caused TLC to enter
|
|
14
14
|
an infinite loop when trying to compute the function or its application
|
|
15
|
-
to an element in its putative domain.`;var S=class extends b{constructor(){super(x)}};const C=()=>n(new S,e.error);var w=class extends b{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},T=class extends b{variable;constructor(e,t){super(e),this.variable=t}},E=class extends b{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},D=class extends b{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},O=class extends u{failure;exception;constructor(e,t={}){super(e),this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},k=class extends O{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},A=class extends u{constructor(e,t){super(e,t),this.name=`TlaProverError`}},j=class extends u{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},M=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},N=class extends u{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},P=class extends u{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},F=class extends u{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},I=class extends u{constructor(e){super(e),this.name=`SmtInvariantError`}},L=class extends u{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},R=class extends u{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},z=class extends u{constructor(e,t){super(e,t),this.name=`SmtParseError`}},B=class extends N{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const V=t=>r(t)??(t instanceof d?e.specParseError:t instanceof y?e.configParseError:t instanceof b?e.specEvaluationFailure:e.error);var H=class extends u{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},U=class extends u{constructor(e){super(e),this.name=`PcalRuntimeError`}},W=class extends u{constructor(e){super(`You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${e}.`),this.name=`PcalBugError`}};const
|
|
15
|
+
to an element in its putative domain.`;var S=class extends b{constructor(){super(x)}};const C=()=>n(new S,e.error);var w=class extends b{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},T=class extends b{variable;constructor(e,t){super(e),this.variable=t}},E=class extends b{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},D=class extends b{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},O=class extends u{failure;exception;constructor(e,t={}){super(e),this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},k=class extends O{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},A=class extends u{constructor(e,t){super(e,t),this.name=`TlaProverError`}},j=class extends u{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},M=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},N=class extends u{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},P=class extends u{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},F=class extends u{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},I=class extends u{constructor(e){super(e),this.name=`SmtInvariantError`}},L=class extends u{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},R=class extends u{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},z=class extends u{constructor(e,t){super(e,t),this.name=`SmtParseError`}},B=class extends N{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const V=t=>r(t)??(t instanceof d?e.specParseError:t instanceof y?e.configParseError:t instanceof b?e.specEvaluationFailure:e.error);var H=class extends u{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},U=class extends u{constructor(e){super(e),this.name=`PcalRuntimeError`}},W=class extends u{constructor(e){super(`You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${e}.`),this.name=`PcalBugError`}},G=class extends u{constructor(e,t){let n=t?.getSourceFile(),r=n?.getLineAndCharacterOfPosition(t?.getStart()??0);super(n===void 0||r===void 0?e:`${n.fileName}:${r.line+1}:${r.character+1} ${e}`),this.name=`TlaTypeScriptError`}};const K=`node:worker_threads`,q=()=>typeof Worker==`function`||typeof process<`u`&&process.versions?.node!==void 0,J=async(e,t,n)=>{if(typeof Worker==`function`){let r=new Worker(e,{type:`module`});return r.addEventListener(`message`,e=>t(e.data)),r.addEventListener(`error`,n),r}let r=new(await(import(
|
|
16
16
|
/* @vite-ignore */
|
|
17
17
|
/* webpackIgnore: true */
|
|
18
|
-
|
|
18
|
+
K))).Worker(e);return r.on(`message`,t),r.on(`error`,n),{postMessage:(e,t)=>r.postMessage(e,t),terminate:()=>void r.terminate()}},Y=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
|
|
19
19
|
/* @vite-ignore */
|
|
20
20
|
/* webpackIgnore: true */
|
|
21
|
-
|
|
21
|
+
K)).parentPort,X=()=>{let e=`Bun`in globalThis?import(
|
|
22
22
|
/* @vite-ignore */
|
|
23
23
|
/* webpackIgnore: true */
|
|
24
|
-
`bun:jsc`):void 0;return async()=>{(await e)?.edenGC(),await new Promise(e=>typeof setImmediate==`function`?setImmediate(e):setTimeout(e,0))}};Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return
|
|
24
|
+
`bun:jsc`):void 0;return async()=>{(await e)?.edenGC(),await new Promise(e=>typeof setImmediate==`function`?setImmediate(e):setTimeout(e,0))}};Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"J",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return C}});
|
package/dist/worker.js
CHANGED
|
@@ -12,13 +12,13 @@ const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenes
|
|
|
12
12
|
`)}`,_=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,v=(e,t)=>m([{location:_(t),message:e}]);var y=class extends u{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},b=class extends u{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const x=`This was a Java StackOverflowError. It was probably the result
|
|
13
13
|
of an incorrect recursive function definition that caused TLC to enter
|
|
14
14
|
an infinite loop when trying to compute the function or its application
|
|
15
|
-
to an element in its putative domain.`;var S=class extends b{constructor(){super(x)}};const C=()=>n(new S,e.error);var w=class extends b{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},T=class extends b{variable;constructor(e,t){super(e),this.variable=t}},E=class extends b{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},D=class extends b{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},O=class extends u{failure;exception;constructor(e,t={}){super(e),this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},k=class extends O{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},A=class extends u{constructor(e,t){super(e,t),this.name=`TlaProverError`}},j=class extends u{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},M=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},N=class extends u{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},P=class extends u{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},F=class extends u{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},I=class extends u{constructor(e){super(e),this.name=`SmtInvariantError`}},L=class extends u{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},R=class extends u{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},z=class extends u{constructor(e,t){super(e,t),this.name=`SmtParseError`}},B=class extends N{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const V=t=>r(t)??(t instanceof d?e.specParseError:t instanceof y?e.configParseError:t instanceof b?e.specEvaluationFailure:e.error);var H=class extends u{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},U=class extends u{constructor(e){super(e),this.name=`PcalRuntimeError`}},W=class extends u{constructor(e){super(`You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${e}.`),this.name=`PcalBugError`}};const
|
|
15
|
+
to an element in its putative domain.`;var S=class extends b{constructor(){super(x)}};const C=()=>n(new S,e.error);var w=class extends b{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},T=class extends b{variable;constructor(e,t){super(e),this.variable=t}},E=class extends b{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},D=class extends b{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},O=class extends u{failure;exception;constructor(e,t={}){super(e),this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},k=class extends O{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},A=class extends u{constructor(e,t){super(e,t),this.name=`TlaProverError`}},j=class extends u{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},M=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},N=class extends u{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},P=class extends u{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},F=class extends u{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},I=class extends u{constructor(e){super(e),this.name=`SmtInvariantError`}},L=class extends u{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},R=class extends u{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},z=class extends u{constructor(e,t){super(e,t),this.name=`SmtParseError`}},B=class extends N{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const V=t=>r(t)??(t instanceof d?e.specParseError:t instanceof y?e.configParseError:t instanceof b?e.specEvaluationFailure:e.error);var H=class extends u{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},U=class extends u{constructor(e){super(e),this.name=`PcalRuntimeError`}},W=class extends u{constructor(e){super(`You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${e}.`),this.name=`PcalBugError`}},G=class extends u{constructor(e,t){let n=t?.getSourceFile(),r=n?.getLineAndCharacterOfPosition(t?.getStart()??0);super(n===void 0||r===void 0?e:`${n.fileName}:${r.line+1}:${r.character+1} ${e}`),this.name=`TlaTypeScriptError`}};const K=`node:worker_threads`,q=()=>typeof Worker==`function`||typeof process<`u`&&process.versions?.node!==void 0,J=async(e,t,n)=>{if(typeof Worker==`function`){let r=new Worker(e,{type:`module`});return r.addEventListener(`message`,e=>t(e.data)),r.addEventListener(`error`,n),r}let r=new(await(import(
|
|
16
16
|
/* @vite-ignore */
|
|
17
17
|
/* webpackIgnore: true */
|
|
18
|
-
|
|
18
|
+
K))).Worker(e);return r.on(`message`,t),r.on(`error`,n),{postMessage:(e,t)=>r.postMessage(e,t),terminate:()=>void r.terminate()}},Y=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
|
|
19
19
|
/* @vite-ignore */
|
|
20
20
|
/* webpackIgnore: true */
|
|
21
|
-
|
|
21
|
+
K)).parentPort,X=()=>{let e=`Bun`in globalThis?import(
|
|
22
22
|
/* @vite-ignore */
|
|
23
23
|
/* webpackIgnore: true */
|
|
24
|
-
`bun:jsc`):void 0;return async()=>{(await e)?.edenGC(),await new Promise(e=>typeof setImmediate==`function`?setImmediate(e):setTimeout(e,0))}};export{
|
|
24
|
+
`bun:jsc`):void 0;return async()=>{(await e)?.edenGC(),await new Promise(e=>typeof setImmediate==`function`?setImmediate(e):setTimeout(e,0))}};export{T as A,_ as B,E as C,S as D,f as E,s as F,e as G,V as H,h as I,a as J,r as K,m as L,j as M,k as N,d as O,c as P,v as R,p as S,A as T,o as U,g as V,l as W,b as _,L as a,M as b,U as c,F as d,I as f,u as g,y as h,J as i,N as j,G as k,R as l,P as m,Y as n,W as o,z as p,n as q,q as r,H as s,X as t,x as u,D as v,O as w,B as x,w as y,C as z};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tla-ts",
|
|
3
|
-
"version": "0.0.9-dev.
|
|
3
|
+
"version": "0.0.9-dev.4ce0657",
|
|
4
4
|
"description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"formal verification",
|
|
@@ -55,9 +55,11 @@
|
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
+
"@typescript/typescript6": "6.0.2",
|
|
58
59
|
"fflate": "^0.8.3"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
62
|
+
"@engine262/engine262": "0.0.1-d553e7b52501fbc47eae981c8d0fa7a5c26d0171",
|
|
61
63
|
"@types/node": "^22",
|
|
62
64
|
"publint": "^0.3.0",
|
|
63
65
|
"typescript": "^7.0.2",
|
package/src/check.ts
CHANGED
|
@@ -720,24 +720,27 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
720
720
|
// explored it.
|
|
721
721
|
const livenessSource = current.livenessSource;
|
|
722
722
|
current.livenessSource = source;
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
723
|
+
try {
|
|
724
|
+
forEachSuccessor(
|
|
725
|
+
spec.next,
|
|
726
|
+
state,
|
|
727
|
+
environment,
|
|
728
|
+
(successor) => {
|
|
729
|
+
canonicalizeState(successor.state);
|
|
730
|
+
const isInModel =
|
|
731
|
+
search.satisfiesConstraints(successor.state, state) &&
|
|
732
|
+
search.satisfiesActionConstraints(state, successor.state);
|
|
733
|
+
if (!isInModel) return false;
|
|
734
|
+
const fingerprintState = getFingerprintState(successor.state);
|
|
735
|
+
const index = findStateIndex(getStateHash(fingerprintState), fingerprintState);
|
|
736
|
+
successors.push({ index, state: successor.state });
|
|
737
|
+
return false;
|
|
738
|
+
},
|
|
739
|
+
spec.scope,
|
|
740
|
+
);
|
|
741
|
+
} finally {
|
|
742
|
+
current.livenessSource = livenessSource;
|
|
743
|
+
}
|
|
741
744
|
return successors;
|
|
742
745
|
},
|
|
743
746
|
}),
|
|
@@ -767,14 +770,22 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
767
770
|
position: number,
|
|
768
771
|
loopStart: number | undefined,
|
|
769
772
|
) => {
|
|
770
|
-
// TLC evaluates TLCGet("level") and Trace in an alias at the state's position in the trace.
|
|
773
|
+
// TLC evaluates TLCGet("level") and Trace in an alias at the state's position in the trace. The
|
|
774
|
+
// search reads them again once the alias is evaluated, as it goes on with -continue.
|
|
775
|
+
const searchLevel = runtime.getLevel;
|
|
776
|
+
const searchBehavior = runtime.getBehavior;
|
|
771
777
|
runtime.getLevel = () => position + 1;
|
|
772
778
|
runtime.getBehavior = () => steps.slice(0, position + 1).map((step) => step.state);
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
779
|
+
try {
|
|
780
|
+
return evaluateAlias(
|
|
781
|
+
alias,
|
|
782
|
+
steps[position].state,
|
|
783
|
+
(steps[position + 1] ?? steps[loopStart ?? position]).state,
|
|
784
|
+
);
|
|
785
|
+
} finally {
|
|
786
|
+
runtime.getLevel = searchLevel;
|
|
787
|
+
runtime.getBehavior = searchBehavior;
|
|
788
|
+
}
|
|
778
789
|
};
|
|
779
790
|
const evaluateAlias = (alias: string, state: Value[], next: Value[] | undefined) => {
|
|
780
791
|
try {
|
|
@@ -798,13 +809,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
798
809
|
Object.assign(current, { index, isExpanding: true, candidate: undefined });
|
|
799
810
|
const getKey = isHeld ? (values: Value[]) => values : getFingerprintState;
|
|
800
811
|
const key = getKey(state);
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
812
|
+
try {
|
|
813
|
+
return actions.find((item) =>
|
|
814
|
+
getSuccessors(item.expression, previous, environment, item.scope).some((successor) =>
|
|
815
|
+
isSameState(getKey(successor.state), key),
|
|
816
|
+
),
|
|
817
|
+
);
|
|
818
|
+
} finally {
|
|
819
|
+
Object.assign(current, expanding);
|
|
820
|
+
}
|
|
808
821
|
};
|
|
809
822
|
// Before TLC prints a trace, it rebuilds from the initial predicate the states it does not keep,
|
|
810
823
|
// all but the last `known` ones. As it prints each later step, it finds the action that takes
|
package/src/cli/options.ts
CHANGED
|
@@ -63,7 +63,7 @@ export const defineCommand = (usage: string, specs: OptionSpec[]) => {
|
|
|
63
63
|
};
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
export const CHECK_COMMAND = defineCommand("tla-ts <Spec.tla|Spec.cfg|glob>... {options}", [
|
|
66
|
+
export const CHECK_COMMAND = defineCommand("tla-ts <Spec.tla|Spec.cfg|spec.ts|glob>... {options}", [
|
|
67
67
|
{ flag: "-config <Spec.cfg>" },
|
|
68
68
|
{ flag: "-continue" },
|
|
69
69
|
{ flag: "-deadlock" },
|
package/src/cli/tlc.ts
CHANGED
|
@@ -75,6 +75,7 @@ import {
|
|
|
75
75
|
toLibraryPath,
|
|
76
76
|
type JavaProperties,
|
|
77
77
|
} from "./shared";
|
|
78
|
+
import { writeTypeScriptSpec } from "./typescript";
|
|
78
79
|
|
|
79
80
|
const EXIT_CODES: Record<CheckStatus, number> = {
|
|
80
81
|
success: EXIT_STATUS.success,
|
|
@@ -882,19 +883,21 @@ export const checkSpecs = async (args: string[], java: JavaProperties) => {
|
|
|
882
883
|
const inputs = getInputPaths(parsed.positionals);
|
|
883
884
|
const isConfigured = parsed.has("-config");
|
|
884
885
|
// Like TLC, a spec named without an extension is the .tla file of that name. A glob also matches
|
|
885
|
-
// modules that only other specs import, which have no configuration.
|
|
886
|
+
// modules that only other specs import, which have no configuration. A TypeScript file compiles
|
|
887
|
+
// to a spec.
|
|
886
888
|
const specPaths = inputs
|
|
887
889
|
.map((input) => ({
|
|
888
890
|
...input,
|
|
889
891
|
path:
|
|
890
|
-
input.isGlobbed || /\.(tla|cfg)$/.test(input.path)
|
|
892
|
+
input.isGlobbed || /\.(tla|cfg|ts)$/.test(input.path)
|
|
891
893
|
? input.path.replace(/\.cfg$/, ".tla")
|
|
892
894
|
: `${input.path}.tla`,
|
|
893
895
|
}))
|
|
894
896
|
.filter(
|
|
895
897
|
(input) =>
|
|
896
|
-
input.path.endsWith(".
|
|
897
|
-
(
|
|
898
|
+
input.path.endsWith(".ts") ||
|
|
899
|
+
(input.path.endsWith(".tla") &&
|
|
900
|
+
(!input.isGlobbed || isConfigured || existsSync(input.path.replace(/\.tla$/, ".cfg")))),
|
|
898
901
|
)
|
|
899
902
|
.map((input) => input.path);
|
|
900
903
|
if (specPaths.length === 0) {
|
|
@@ -916,15 +919,21 @@ export const checkSpecs = async (args: string[], java: JavaProperties) => {
|
|
|
916
919
|
const exitCodes: number[] = [];
|
|
917
920
|
for (const [index, path] of paths.entries()) {
|
|
918
921
|
if (index > 0) console.log("");
|
|
919
|
-
// TLC checks one spec, so tla-ts names each of several it checks.
|
|
920
|
-
if (paths.length > 1)
|
|
921
|
-
console.log(`Checking ${basename(path)} with ${basename(path, ".tla")}.cfg`);
|
|
922
922
|
const printer = createMessagePrinter(
|
|
923
923
|
parsed.has("-tool"),
|
|
924
924
|
!parsed.has("-nowarning"),
|
|
925
925
|
java.tlcVersion ?? "master",
|
|
926
926
|
);
|
|
927
|
-
exitCodes.push(
|
|
927
|
+
exitCodes.push(
|
|
928
|
+
await reportErrors(async () => {
|
|
929
|
+
const specPath = path.endsWith(".ts") ? await writeTypeScriptSpec(path) : path;
|
|
930
|
+
// TLC checks one spec, so tla-ts names each of several it checks.
|
|
931
|
+
if (paths.length > 1) {
|
|
932
|
+
console.log(`Checking ${basename(specPath)} with ${basename(specPath, ".tla")}.cfg`);
|
|
933
|
+
}
|
|
934
|
+
return checkSpec(specPath, parsed, java, printer);
|
|
935
|
+
}, printer),
|
|
936
|
+
);
|
|
928
937
|
}
|
|
929
938
|
return exitCodes.find((exitCode) => exitCode !== EXIT_STATUS.success) ?? EXIT_STATUS.success;
|
|
930
939
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
3
|
+
import { TlaTypeScriptError } from "../errors";
|
|
4
|
+
|
|
5
|
+
// Compiles a TypeScript file to the TLA+ spec and config of its module, beside it, and returns the
|
|
6
|
+
// spec's path. A file there that tla-ts didn't generate is left alone.
|
|
7
|
+
export const writeTypeScriptSpec = async (path: string) => {
|
|
8
|
+
// The TypeScript compiler takes a while to load, so only a TypeScript input loads it.
|
|
9
|
+
const compiled = (await import("../typescript/compile")).compile(
|
|
10
|
+
readFileSync(path, "utf8"),
|
|
11
|
+
path,
|
|
12
|
+
);
|
|
13
|
+
const header = `\\* Generated by tla-ts from ${basename(path)}. Edit ${basename(path)} instead.`;
|
|
14
|
+
const specPath = join(dirname(path), `${compiled.name}.tla`);
|
|
15
|
+
const configPath = join(dirname(path), `${compiled.name}.cfg`);
|
|
16
|
+
for (const outputPath of [specPath, configPath]) {
|
|
17
|
+
if (existsSync(outputPath) && !readFileSync(outputPath, "utf8").startsWith(header)) {
|
|
18
|
+
throw new TlaTypeScriptError(
|
|
19
|
+
`${outputPath} already exists, and tla-ts didn't generate it from ${path}`,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
writeFileSync(specPath, `${header}\n${compiled.source}\n`);
|
|
24
|
+
writeFileSync(configPath, `${header}\n${compiled.config}\n`);
|
|
25
|
+
return specPath;
|
|
26
|
+
};
|
package/src/environment.ts
CHANGED
|
@@ -531,6 +531,8 @@ export const createEnvironment = (
|
|
|
531
531
|
),
|
|
532
532
|
variables: new Set(linked.variables),
|
|
533
533
|
getDefinition: (key) => definitions.get(key),
|
|
534
|
+
getOuterDefinition: (name) =>
|
|
535
|
+
module.definitions.find((definition) => definition.name === name),
|
|
534
536
|
isParameterized: (key) => parameterized.get(key) === true,
|
|
535
537
|
addDefinition: (source, name, create) => {
|
|
536
538
|
const key = createName(`${name}@${module.name}`);
|
|
@@ -742,6 +744,8 @@ export const createEnvironment = (
|
|
|
742
744
|
),
|
|
743
745
|
variables: new Set(linked.variables),
|
|
744
746
|
getDefinition: (key) => definitions.get(key),
|
|
747
|
+
// Each substitution is a local definition, which the copies read by name.
|
|
748
|
+
getOuterDefinition: () => undefined,
|
|
745
749
|
isParameterized: (key) => parameterized.get(key) === true,
|
|
746
750
|
addDefinition: (_source, name, create) => {
|
|
747
751
|
const key = `${name}${KEY_SEPARATOR}${instance.module}${suffix}.${copies.length}`;
|
package/src/errors.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type ts from "@typescript/typescript6";
|
|
1
2
|
import type { SourceRange } from "./ast";
|
|
2
3
|
import { EXIT_STATUS, getExitCode, setExitCode } from "./exit-codes";
|
|
3
4
|
import type { PcalNode } from "./pcal/ast";
|
|
@@ -373,3 +374,17 @@ export class PcalBugError extends TlaError {
|
|
|
373
374
|
this.name = "PcalBugError";
|
|
374
375
|
}
|
|
375
376
|
}
|
|
377
|
+
|
|
378
|
+
// TypeScript that tla-ts can't compile to TLA+, at the file, line and column of the construct.
|
|
379
|
+
export class TlaTypeScriptError extends TlaError {
|
|
380
|
+
constructor(message: string, node?: ts.Node) {
|
|
381
|
+
const sourceFile = node?.getSourceFile();
|
|
382
|
+
const position = sourceFile?.getLineAndCharacterOfPosition(node?.getStart() ?? 0);
|
|
383
|
+
super(
|
|
384
|
+
sourceFile === undefined || position === undefined
|
|
385
|
+
? message
|
|
386
|
+
: `${sourceFile.fileName}:${position.line + 1}:${position.character + 1} ${message}`,
|
|
387
|
+
);
|
|
388
|
+
this.name = "TlaTypeScriptError";
|
|
389
|
+
}
|
|
390
|
+
}
|
package/src/evaluate.ts
CHANGED
|
@@ -119,6 +119,8 @@ export interface Thunk {
|
|
|
119
119
|
// Whether the expression may build a set that streams until TLC caches it, so that the thunk
|
|
120
120
|
// caches only a settled value.
|
|
121
121
|
isStreamed: boolean;
|
|
122
|
+
// Whether the thunk dropped its scope after caching a value that holds in every state.
|
|
123
|
+
isReleased?: boolean;
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
type Binding = { kind: "Value"; value: Value } | Thunk | { kind: "Operator"; operator: Operator };
|
|
@@ -818,9 +820,15 @@ export const evaluateStartupDefinitions = (definitions: Definition[], environmen
|
|
|
818
820
|
|
|
819
821
|
const forceThunk = (thunk: Thunk, context: Context) => {
|
|
820
822
|
const isSameState = thunk.state === context.state && thunk.next === context.next;
|
|
821
|
-
if (
|
|
823
|
+
if (thunk.cache !== undefined && (isSameState || thunk.isReleased)) return thunk.cache;
|
|
822
824
|
const value = evaluate(thunk.expression, withScope(context, thunk.scope));
|
|
823
825
|
if (isSameState && (!thunk.isStreamed || isSettledValue(value))) thunk.cache = value;
|
|
826
|
+
// A value a thunk cached with no state read no variable, so it holds in every state. Releasing
|
|
827
|
+
// its scope frees the evaluations the scope's bindings cached, which a long script keeps alive.
|
|
828
|
+
if (thunk.cache !== undefined && thunk.state === undefined && thunk.next === undefined) {
|
|
829
|
+
thunk.scope = undefined;
|
|
830
|
+
thunk.isReleased = true;
|
|
831
|
+
}
|
|
824
832
|
return value;
|
|
825
833
|
};
|
|
826
834
|
|
|
@@ -1026,6 +1034,24 @@ interface ReevaluatedDefinitions {
|
|
|
1026
1034
|
streamed: ReadonlySet<Definition>;
|
|
1027
1035
|
}
|
|
1028
1036
|
|
|
1037
|
+
// A LET's function definition has one function constructor, as in SANY, so its code compiles once
|
|
1038
|
+
// however often the LET is evaluated.
|
|
1039
|
+
const letFunctionConstructions = new WeakMap<FunctionDefinition, Expression>();
|
|
1040
|
+
|
|
1041
|
+
const getLetFunctionConstruction = (definition: FunctionDefinition): Expression => {
|
|
1042
|
+
const known = letFunctionConstructions.get(definition);
|
|
1043
|
+
if (known) return known;
|
|
1044
|
+
const construction: Expression = {
|
|
1045
|
+
kind: "FunctionConstruction",
|
|
1046
|
+
bounds: definition.bounds,
|
|
1047
|
+
body: definition.body,
|
|
1048
|
+
location: definition.location,
|
|
1049
|
+
isRecursive: true,
|
|
1050
|
+
};
|
|
1051
|
+
letFunctionConstructions.set(definition, construction);
|
|
1052
|
+
return construction;
|
|
1053
|
+
};
|
|
1054
|
+
|
|
1029
1055
|
export const bindDefinitions = (
|
|
1030
1056
|
definitions: Definition[],
|
|
1031
1057
|
context: Context,
|
|
@@ -1040,13 +1066,7 @@ export const bindDefinitions = (
|
|
|
1040
1066
|
if (definition.kind === "Function") {
|
|
1041
1067
|
node.binding = {
|
|
1042
1068
|
kind: "Thunk",
|
|
1043
|
-
expression:
|
|
1044
|
-
kind: "FunctionConstruction",
|
|
1045
|
-
bounds: definition.bounds,
|
|
1046
|
-
body: definition.body,
|
|
1047
|
-
location: definition.location,
|
|
1048
|
-
isRecursive: true,
|
|
1049
|
-
},
|
|
1069
|
+
expression: getLetFunctionConstruction(definition),
|
|
1050
1070
|
scope: node,
|
|
1051
1071
|
state: context.state,
|
|
1052
1072
|
next: context.next,
|
|
@@ -1529,6 +1549,39 @@ export const keepLazy = (expression: Expression) => {
|
|
|
1529
1549
|
}
|
|
1530
1550
|
};
|
|
1531
1551
|
|
|
1552
|
+
// The names an expression may look up in its scope, or undefined when a subexpression selector may
|
|
1553
|
+
// look up others.
|
|
1554
|
+
const scopeNames = new WeakMap<Expression, string[] | undefined>();
|
|
1555
|
+
|
|
1556
|
+
const getScopeNames = (expression: Expression) => {
|
|
1557
|
+
if (scopeNames.has(expression)) return scopeNames.get(expression);
|
|
1558
|
+
const names = new Set<string>();
|
|
1559
|
+
const visit = (node: Expression): boolean => {
|
|
1560
|
+
if (node.kind === "Subexpression") return false;
|
|
1561
|
+
if (node.kind === "Identifier") names.add(node.name);
|
|
1562
|
+
if (node.kind === "Apply" || node.kind === "OperatorReference") names.add(node.operator);
|
|
1563
|
+
if (node.kind === "ExceptAt") names.add(EXCEPT_AT);
|
|
1564
|
+
return getChildren(node).every(visit);
|
|
1565
|
+
};
|
|
1566
|
+
const result = visit(expression) ? [...names] : undefined;
|
|
1567
|
+
scopeNames.set(expression, result);
|
|
1568
|
+
return result;
|
|
1569
|
+
};
|
|
1570
|
+
|
|
1571
|
+
// The bindings of a scope that names look up, so that a lazy function keeps only those alive and
|
|
1572
|
+
// not the values its other bindings cached. An unnamed node ends the chain, since a TLCEval in the
|
|
1573
|
+
// body sorts its value only where no context binds a name.
|
|
1574
|
+
const trimScope = (scope: Scope | undefined, names: string[] | undefined) =>
|
|
1575
|
+
names === undefined || scope === undefined
|
|
1576
|
+
? scope
|
|
1577
|
+
: names.reduce<Scope>(
|
|
1578
|
+
(trimmed, name) => {
|
|
1579
|
+
const binding = lookupScope(scope, name);
|
|
1580
|
+
return binding ? { name, binding, parent: trimmed } : trimmed;
|
|
1581
|
+
},
|
|
1582
|
+
{ name: "", binding: { kind: "Value", value: false }, parent: undefined },
|
|
1583
|
+
);
|
|
1584
|
+
|
|
1532
1585
|
const compileFunctionConstruction = (
|
|
1533
1586
|
expression: Expression & { kind: "FunctionConstruction" },
|
|
1534
1587
|
environment: Environment,
|
|
@@ -1569,12 +1622,14 @@ const compileFunctionConstruction = (
|
|
|
1569
1622
|
return createFunction(pairs);
|
|
1570
1623
|
};
|
|
1571
1624
|
const template = getLazyFunctionTemplate(bounds, expression.body);
|
|
1625
|
+
const bodyNames = getScopeNames(expression.body);
|
|
1572
1626
|
const createLazy = (domain: Value, context: Context) => {
|
|
1573
|
-
const scope = context.scope;
|
|
1627
|
+
const scope = trimScope(context.scope, bodyNames);
|
|
1628
|
+
const lambdaContext = withScope(context, scope);
|
|
1574
1629
|
const functionValue = keepLambda({
|
|
1575
1630
|
value: createLazyFunction(
|
|
1576
1631
|
domain,
|
|
1577
|
-
(argument) => body(withScope(
|
|
1632
|
+
(argument) => body(withScope(lambdaContext, bindArgument(bounds, scope, argument))),
|
|
1578
1633
|
getLazyFunctionSource(template, bounds, domain),
|
|
1579
1634
|
),
|
|
1580
1635
|
bounds,
|
package/src/instances.ts
CHANGED
|
@@ -14,8 +14,6 @@ import {
|
|
|
14
14
|
import { TlaSyntaxError } from "./errors";
|
|
15
15
|
import { getArity, getBoundNames, getPatternNames, isBefore, LOCAL_RESOLUTION } from "./resolve";
|
|
16
16
|
|
|
17
|
-
export const substitutedExpressions = new WeakSet<Expression>();
|
|
18
|
-
|
|
19
17
|
// Applications inside an instance with substitutions or parameters, which TLC evaluates in a
|
|
20
18
|
// context that binds them.
|
|
21
19
|
export const contextualApplications = new WeakSet<Expression>();
|
|
@@ -224,6 +222,8 @@ interface Instantiation {
|
|
|
224
222
|
substitutions: Map<string, Expression>;
|
|
225
223
|
variables: Set<string>;
|
|
226
224
|
getDefinition: (key: string) => Definition | undefined;
|
|
225
|
+
// A definition of the instantiating module that a substitution names.
|
|
226
|
+
getOuterDefinition: (name: string) => Definition | undefined;
|
|
227
227
|
isParameterized: (key: string) => boolean;
|
|
228
228
|
addDefinition: (source: string, name: string, create: (key: string) => Definition) => string;
|
|
229
229
|
createName: (name: string) => string;
|
|
@@ -240,8 +240,40 @@ interface Rewrite {
|
|
|
240
240
|
copies: Map<string, string>;
|
|
241
241
|
mode: RewriteMode;
|
|
242
242
|
modes: Map<RewriteMode, Rewrite>;
|
|
243
|
+
// The substitutions an operator's copy reads, which it binds once, as TLC binds each to a lazy
|
|
244
|
+
// value when it evaluates the operator's body.
|
|
245
|
+
bindings?: Map<string, Expression>;
|
|
243
246
|
}
|
|
244
247
|
|
|
248
|
+
const getSubstitutionName = (name: string) => `${name}@SUBSTITUTION`;
|
|
249
|
+
|
|
250
|
+
const isVariableAlias = (expression: Expression): boolean =>
|
|
251
|
+
expression.kind === "Identifier" ||
|
|
252
|
+
(expression.kind === "Tuple" && expression.elements.every(isVariableAlias));
|
|
253
|
+
|
|
254
|
+
// A name, or a tuple of names, stays in place, so a step can assign it or leave it unchanged as
|
|
255
|
+
// TLC does through its lazy value. An operator or a literal costs nothing to evaluate again. A name
|
|
256
|
+
// of a definition that isn't such an alias is bound once.
|
|
257
|
+
const isBoundOnce = (replacement: Expression, instantiation: Instantiation) => {
|
|
258
|
+
if (replacement.kind !== "Identifier") {
|
|
259
|
+
return (
|
|
260
|
+
!isVariableAlias(replacement) &&
|
|
261
|
+
replacement.kind !== "OperatorReference" &&
|
|
262
|
+
replacement.kind !== "Lambda" &&
|
|
263
|
+
replacement.kind !== "Number" &&
|
|
264
|
+
replacement.kind !== "String"
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
const definition = isLocallyResolved(replacement)
|
|
268
|
+
? undefined
|
|
269
|
+
: instantiation.getOuterDefinition(replacement.name);
|
|
270
|
+
return (
|
|
271
|
+
definition?.kind === "Operator" &&
|
|
272
|
+
definition.params.length === 0 &&
|
|
273
|
+
!isVariableAlias(definition.body)
|
|
274
|
+
);
|
|
275
|
+
};
|
|
276
|
+
|
|
245
277
|
const getFreeNames = (expression: Expression, bound = new Set<string>()): string[] => {
|
|
246
278
|
const name =
|
|
247
279
|
expression.kind === "Identifier"
|
|
@@ -515,10 +547,15 @@ const substitute = (
|
|
|
515
547
|
if (enabled) return enabled;
|
|
516
548
|
if (expression.kind === "Identifier" && isFree(expression.name)) {
|
|
517
549
|
const replacement = instantiation.substitutions.get(expression.name);
|
|
518
|
-
|
|
519
|
-
|
|
550
|
+
const bindings = rewrite.bindings;
|
|
551
|
+
if (replacement && (bindings === undefined || !isBoundOnce(replacement, instantiation))) {
|
|
520
552
|
return replacement;
|
|
521
553
|
}
|
|
554
|
+
if (replacement && bindings) {
|
|
555
|
+
const name = getSubstitutionName(expression.name);
|
|
556
|
+
bindings.set(name, replacement);
|
|
557
|
+
return createLocalIdentifier(name, expression.location);
|
|
558
|
+
}
|
|
522
559
|
const copy = getCopy(rewrite, expression.name);
|
|
523
560
|
if (copy === undefined) return expression;
|
|
524
561
|
if (params.length === 0) return { ...expression, name: copy };
|
|
@@ -649,13 +686,37 @@ const copyDefinition = (rewrite: Rewrite, key: string): string => {
|
|
|
649
686
|
return instantiation.addDefinition(key, definition.name, (copyKey) => {
|
|
650
687
|
rewrite.copies.set(key, copyKey);
|
|
651
688
|
const rename = createRenamer(rewrite);
|
|
689
|
+
const bindings = new Map<string, Expression>();
|
|
690
|
+
const bodyRewrite =
|
|
691
|
+
definition.kind === "Operator" && rewrite.mode === "Normal"
|
|
692
|
+
? { ...rewrite, bindings }
|
|
693
|
+
: rewrite;
|
|
652
694
|
const mapped = renameParams(
|
|
653
695
|
mapDefinition(definition, (child, bound) =>
|
|
654
|
-
substitute(child,
|
|
696
|
+
substitute(child, bodyRewrite, bindNames(new Map(), bound, rename)),
|
|
655
697
|
),
|
|
656
698
|
rename,
|
|
657
699
|
);
|
|
658
|
-
|
|
700
|
+
if (mapped.kind !== "Operator" || bindings.size === 0) {
|
|
701
|
+
return withInstanceParams(mapped, instantiation.params, definition.location);
|
|
702
|
+
}
|
|
703
|
+
const definitions = [...bindings].map(([name, replacement]): Definition => ({
|
|
704
|
+
kind: "Operator",
|
|
705
|
+
name,
|
|
706
|
+
params: [],
|
|
707
|
+
body: replacement,
|
|
708
|
+
isLocal: true,
|
|
709
|
+
isRecursive: false,
|
|
710
|
+
location: replacement.location,
|
|
711
|
+
}));
|
|
712
|
+
return withInstanceParams(
|
|
713
|
+
{
|
|
714
|
+
...mapped,
|
|
715
|
+
body: { kind: "Let", definitions, body: mapped.body, location: mapped.body.location },
|
|
716
|
+
},
|
|
717
|
+
instantiation.params,
|
|
718
|
+
definition.location,
|
|
719
|
+
);
|
|
659
720
|
});
|
|
660
721
|
};
|
|
661
722
|
|
package/src/liveness-checker.ts
CHANGED
|
@@ -268,11 +268,14 @@ export const createLivenessChecker = (
|
|
|
268
268
|
return cache;
|
|
269
269
|
};
|
|
270
270
|
// TLCGet("level") reads the level of the state whose successors the checks run on.
|
|
271
|
+
// A check that fails leaves no source, so the failure's trace reads the levels of the search.
|
|
271
272
|
const evaluateFrom = <Result>(source: number | undefined, evaluate: () => Result) => {
|
|
272
273
|
environment.runtime.setLivenessSource(source);
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
274
|
+
try {
|
|
275
|
+
return evaluate();
|
|
276
|
+
} finally {
|
|
277
|
+
environment.runtime.setLivenessSource(undefined);
|
|
278
|
+
}
|
|
276
279
|
};
|
|
277
280
|
const evaluateState = (predicate: LiveExpression, state: Value[]) =>
|
|
278
281
|
evaluateLive(
|
package/src/liveness.ts
CHANGED
|
@@ -92,7 +92,11 @@ export const getLevel = (
|
|
|
92
92
|
const binding = lookupScope(scope, name);
|
|
93
93
|
if (!binding) return undefined;
|
|
94
94
|
if (binding.kind === "Value") return CONSTANT_LEVEL;
|
|
95
|
-
if (binding.kind === "Thunk")
|
|
95
|
+
if (binding.kind === "Thunk") {
|
|
96
|
+
return binding.isReleased
|
|
97
|
+
? CONSTANT_LEVEL
|
|
98
|
+
: getLevel(binding.expression, binding.scope, environment);
|
|
99
|
+
}
|
|
96
100
|
const operator = binding.operator;
|
|
97
101
|
return operator.kind === "Closure"
|
|
98
102
|
? getLevel(operator.body, operator.scope, environment)
|
|
@@ -210,7 +214,7 @@ export const expandTemporal = (
|
|
|
210
214
|
}
|
|
211
215
|
if (expression.kind === "Identifier") {
|
|
212
216
|
const binding = isLocallyResolved(expression) ? lookupScope(scope, expression.name) : undefined;
|
|
213
|
-
if (binding?.kind === "Thunk") {
|
|
217
|
+
if (binding?.kind === "Thunk" && !binding.isReleased) {
|
|
214
218
|
return expand(binding.expression, binding.scope);
|
|
215
219
|
}
|
|
216
220
|
const definition = environment.constants.has(expression.name)
|
|
@@ -345,7 +349,7 @@ export const toLiveExpression = (
|
|
|
345
349
|
isLocallyResolved(expression) || getDefinition(name, environment) === undefined
|
|
346
350
|
? lookupScope(scope, name)
|
|
347
351
|
: undefined;
|
|
348
|
-
if (binding?.kind === "Thunk" && definitionThunks.has(binding)) {
|
|
352
|
+
if (binding?.kind === "Thunk" && !binding.isReleased && definitionThunks.has(binding)) {
|
|
349
353
|
return expandCall(expression, () =>
|
|
350
354
|
expand(binding.expression, binding.scope, expression, scope),
|
|
351
355
|
);
|