lawspec 0.31.0 → 0.31.3

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.
Files changed (437) hide show
  1. package/CHANGELOG.md +116 -1
  2. package/README.md +86 -4
  3. package/api.mjs +14 -9
  4. package/authoring.mjs +899 -0
  5. package/beam-coverage.mjs +190 -65
  6. package/beam-doctor.mjs +343 -124
  7. package/bin/lawspec.mjs +1955 -657
  8. package/build.json +135 -129
  9. package/component-packages.mjs +662 -176
  10. package/component.d.ts +82 -20
  11. package/component.mjs +317 -94
  12. package/core.wasm +2 -2
  13. package/core_jsffi.js +5 -5
  14. package/doctor.mjs +558 -299
  15. package/examples-command.mjs +44 -23
  16. package/failure-database.mjs +60 -17
  17. package/files.mjs +122 -62
  18. package/index.d.ts +585 -312
  19. package/input-files.mjs +90 -25
  20. package/launcher.mjs +72 -31
  21. package/learn/adapters.mjs +226 -0
  22. package/learn/app.mjs +1279 -0
  23. package/learn/assert.mjs +33 -0
  24. package/learn/assets.mjs +15 -0
  25. package/learn/browser-runtime.mjs +58 -0
  26. package/learn/bundle.mjs +118 -0
  27. package/learn/compile-worker.mjs +106 -0
  28. package/learn/compiler.mjs +230 -0
  29. package/learn/coverage.json +8259 -0
  30. package/learn/curriculum.json +2955 -0
  31. package/learn/fantomas-worker.mjs +25 -0
  32. package/learn/format-worker.mjs +148 -0
  33. package/learn/fsharp.mjs +83 -0
  34. package/learn/harness-host.mjs +22 -0
  35. package/learn/index.html +326 -0
  36. package/learn/lawspec-core.mjs +223 -0
  37. package/learn/lawspec-language.mjs +69 -0
  38. package/learn/node-test.mjs +11 -0
  39. package/learn/presentation.mjs +73 -0
  40. package/learn/runner.mjs +72 -0
  41. package/learn/sandbox-frame.html +34 -0
  42. package/learn/sandbox.mjs +91 -0
  43. package/learn/store.mjs +141 -0
  44. package/learn/story.mjs +42 -0
  45. package/learn/style-options.json +16 -0
  46. package/learn/style.css +1023 -0
  47. package/learn/theme.js +77 -0
  48. package/learn/typescript.mjs +53 -0
  49. package/learn/vendor/@fontsource-atkinson-hyperlegible-LICENSE.txt +93 -0
  50. package/learn/vendor/@fontsource-atkinson-hyperlegible-mono-LICENSE.txt +93 -0
  51. package/learn/vendor/@fontsource-overpass-LICENSE.txt +93 -0
  52. package/learn/vendor/assemblies.json +1 -0
  53. package/learn/vendor/editor-worker.js +30 -0
  54. package/learn/vendor/editor.css +1 -0
  55. package/learn/vendor/editor.mjs +931 -0
  56. package/learn/vendor/esbuild-wasm-LICENSE.txt +21 -0
  57. package/learn/vendor/esbuild.mjs +2683 -0
  58. package/learn/vendor/esbuild.wasm +0 -0
  59. package/learn/vendor/fable-library/Array.js +1347 -0
  60. package/learn/vendor/fable-library/Async.js +134 -0
  61. package/learn/vendor/fable-library/AsyncBuilder.js +183 -0
  62. package/learn/vendor/fable-library/BigInt.js +306 -0
  63. package/learn/vendor/fable-library/BitConverter.js +138 -0
  64. package/learn/vendor/fable-library/Boolean.js +22 -0
  65. package/learn/vendor/fable-library/CHANGELOG.md +242 -0
  66. package/learn/vendor/fable-library/Char.js +202 -0
  67. package/learn/vendor/fable-library/Choice.js +184 -0
  68. package/learn/vendor/fable-library/CollectionUtil.js +182 -0
  69. package/learn/vendor/fable-library/ConditionalWeakTable.js +21 -0
  70. package/learn/vendor/fable-library/Date.js +841 -0
  71. package/learn/vendor/fable-library/DateOffset.js +261 -0
  72. package/learn/vendor/fable-library/DateOnly.js +124 -0
  73. package/learn/vendor/fable-library/Decimal.js +238 -0
  74. package/learn/vendor/fable-library/Double.js +47 -0
  75. package/learn/vendor/fable-library/Encoding.js +185 -0
  76. package/learn/vendor/fable-library/Event.js +93 -0
  77. package/learn/vendor/fable-library/FSharp.Collections.js +45 -0
  78. package/learn/vendor/fable-library/FSharp.Core.CompilerServices.js +27 -0
  79. package/learn/vendor/fable-library/FSharp.Core.js +156 -0
  80. package/learn/vendor/fable-library/Global.js +29 -0
  81. package/learn/vendor/fable-library/Guid.js +161 -0
  82. package/learn/vendor/fable-library/Int32.js +135 -0
  83. package/learn/vendor/fable-library/List.js +1323 -0
  84. package/learn/vendor/fable-library/Long.js +47 -0
  85. package/learn/vendor/fable-library/MailboxProcessor.js +94 -0
  86. package/learn/vendor/fable-library/Map.js +1396 -0
  87. package/learn/vendor/fable-library/MapUtil.js +130 -0
  88. package/learn/vendor/fable-library/MutableMap.js +339 -0
  89. package/learn/vendor/fable-library/MutableSet.js +233 -0
  90. package/learn/vendor/fable-library/Native.js +14 -0
  91. package/learn/vendor/fable-library/Numeric.js +75 -0
  92. package/learn/vendor/fable-library/Observable.js +113 -0
  93. package/learn/vendor/fable-library/Option.js +104 -0
  94. package/learn/vendor/fable-library/README.md +3 -0
  95. package/learn/vendor/fable-library/Random.js +172 -0
  96. package/learn/vendor/fable-library/Range.js +45 -0
  97. package/learn/vendor/fable-library/Reflection.js +479 -0
  98. package/learn/vendor/fable-library/RegExp.js +141 -0
  99. package/learn/vendor/fable-library/Result.js +165 -0
  100. package/learn/vendor/fable-library/Seq.js +1417 -0
  101. package/learn/vendor/fable-library/Seq2.js +111 -0
  102. package/learn/vendor/fable-library/Set.js +1816 -0
  103. package/learn/vendor/fable-library/String.js +674 -0
  104. package/learn/vendor/fable-library/System.Collections.Generic.js +333 -0
  105. package/learn/vendor/fable-library/System.Text.js +200 -0
  106. package/learn/vendor/fable-library/System.js +289 -0
  107. package/learn/vendor/fable-library/TimeOnly.js +122 -0
  108. package/learn/vendor/fable-library/TimeSpan.js +180 -0
  109. package/learn/vendor/fable-library/Timer.js +67 -0
  110. package/learn/vendor/fable-library/Types.js +198 -0
  111. package/learn/vendor/fable-library/Unicode.13.0.0.js +4 -0
  112. package/learn/vendor/fable-library/Uri.js +165 -0
  113. package/learn/vendor/fable-library/Util.js +796 -0
  114. package/learn/vendor/fable-library/big.d.ts +338 -0
  115. package/learn/vendor/fable-library/lib/big.js +825 -0
  116. package/learn/vendor/fable-library/package.json +24 -0
  117. package/learn/vendor/fable-library/quotation.js +618 -0
  118. package/learn/vendor/fable.js +430 -0
  119. package/learn/vendor/fantomas/FSharp.Core.uawo19tl4c.wasm +0 -0
  120. package/learn/vendor/fantomas/Fantomas.Core.stnanlnpyw.wasm +0 -0
  121. package/learn/vendor/fantomas/Fantomas.FCS.lqohfu5o9y.wasm +0 -0
  122. package/learn/vendor/fantomas/LawSpec.Learn.Formatter.poiijdbsl9.wasm +0 -0
  123. package/learn/vendor/fantomas/Microsoft.CSharp.mp8lhr6rez.wasm +0 -0
  124. package/learn/vendor/fantomas/Microsoft.VisualBasic.0e5fchkecn.wasm +0 -0
  125. package/learn/vendor/fantomas/Microsoft.VisualBasic.Core.17wn27qal2.wasm +0 -0
  126. package/learn/vendor/fantomas/Microsoft.Win32.Primitives.9d566sle9e.wasm +0 -0
  127. package/learn/vendor/fantomas/Microsoft.Win32.Registry.52dy96yk8i.wasm +0 -0
  128. package/learn/vendor/fantomas/System.AppContext.jwujeh069z.wasm +0 -0
  129. package/learn/vendor/fantomas/System.Buffers.y0isk1x97h.wasm +0 -0
  130. package/learn/vendor/fantomas/System.Collections.Concurrent.x5koi7bzem.wasm +0 -0
  131. package/learn/vendor/fantomas/System.Collections.Immutable.diwg7advch.wasm +0 -0
  132. package/learn/vendor/fantomas/System.Collections.NonGeneric.4089xs440e.wasm +0 -0
  133. package/learn/vendor/fantomas/System.Collections.Specialized.hj81u7zblb.wasm +0 -0
  134. package/learn/vendor/fantomas/System.Collections.nvrdeoknr1.wasm +0 -0
  135. package/learn/vendor/fantomas/System.ComponentModel.Annotations.yatcnfjeuk.wasm +0 -0
  136. package/learn/vendor/fantomas/System.ComponentModel.DataAnnotations.led9l5awu3.wasm +0 -0
  137. package/learn/vendor/fantomas/System.ComponentModel.EventBasedAsync.hpvp6cf4de.wasm +0 -0
  138. package/learn/vendor/fantomas/System.ComponentModel.Primitives.v7cajwpaqo.wasm +0 -0
  139. package/learn/vendor/fantomas/System.ComponentModel.TypeConverter.xk1hnyt762.wasm +0 -0
  140. package/learn/vendor/fantomas/System.ComponentModel.rrnda1lucx.wasm +0 -0
  141. package/learn/vendor/fantomas/System.Configuration.bn9vghjcq8.wasm +0 -0
  142. package/learn/vendor/fantomas/System.Console.09ajpiafhz.wasm +0 -0
  143. package/learn/vendor/fantomas/System.Core.wc649o5mw9.wasm +0 -0
  144. package/learn/vendor/fantomas/System.Data.Common.s4cowzd9a9.wasm +0 -0
  145. package/learn/vendor/fantomas/System.Data.DataSetExtensions.5fm360ikxl.wasm +0 -0
  146. package/learn/vendor/fantomas/System.Data.fsu4j4t4jw.wasm +0 -0
  147. package/learn/vendor/fantomas/System.Diagnostics.Contracts.p74re5oxzn.wasm +0 -0
  148. package/learn/vendor/fantomas/System.Diagnostics.Debug.622sixg49n.wasm +0 -0
  149. package/learn/vendor/fantomas/System.Diagnostics.DiagnosticSource.2j35bc2g2b.wasm +0 -0
  150. package/learn/vendor/fantomas/System.Diagnostics.FileVersionInfo.7n0wdvltaa.wasm +0 -0
  151. package/learn/vendor/fantomas/System.Diagnostics.Process.8iffh49mew.wasm +0 -0
  152. package/learn/vendor/fantomas/System.Diagnostics.StackTrace.1yz88vico8.wasm +0 -0
  153. package/learn/vendor/fantomas/System.Diagnostics.TextWriterTraceListener.ua8iuh2vhj.wasm +0 -0
  154. package/learn/vendor/fantomas/System.Diagnostics.Tools.roy5445ugj.wasm +0 -0
  155. package/learn/vendor/fantomas/System.Diagnostics.TraceSource.6qx1ldzz7g.wasm +0 -0
  156. package/learn/vendor/fantomas/System.Diagnostics.Tracing.b4799zpaas.wasm +0 -0
  157. package/learn/vendor/fantomas/System.Drawing.8gcjjqj0pu.wasm +0 -0
  158. package/learn/vendor/fantomas/System.Drawing.Primitives.y2uveru2yk.wasm +0 -0
  159. package/learn/vendor/fantomas/System.Dynamic.Runtime.023zrvzh9x.wasm +0 -0
  160. package/learn/vendor/fantomas/System.Formats.Asn1.znpklkbgqv.wasm +0 -0
  161. package/learn/vendor/fantomas/System.Formats.Tar.5yybjepfi2.wasm +0 -0
  162. package/learn/vendor/fantomas/System.Globalization.Calendars.10g6hyjy3k.wasm +0 -0
  163. package/learn/vendor/fantomas/System.Globalization.Extensions.hrinfrismg.wasm +0 -0
  164. package/learn/vendor/fantomas/System.Globalization.uvs4rah8fk.wasm +0 -0
  165. package/learn/vendor/fantomas/System.IO.4j645gw40d.wasm +0 -0
  166. package/learn/vendor/fantomas/System.IO.Compression.2z7vdt6tfb.wasm +0 -0
  167. package/learn/vendor/fantomas/System.IO.Compression.Brotli.fv80xs79j3.wasm +0 -0
  168. package/learn/vendor/fantomas/System.IO.Compression.FileSystem.88jdddz3sw.wasm +0 -0
  169. package/learn/vendor/fantomas/System.IO.Compression.ZipFile.jkn9avr4vo.wasm +0 -0
  170. package/learn/vendor/fantomas/System.IO.FileSystem.AccessControl.yme0uhbu37.wasm +0 -0
  171. package/learn/vendor/fantomas/System.IO.FileSystem.DriveInfo.qas7wf73rs.wasm +0 -0
  172. package/learn/vendor/fantomas/System.IO.FileSystem.Primitives.d1jmhkzu0e.wasm +0 -0
  173. package/learn/vendor/fantomas/System.IO.FileSystem.Watcher.z570derp0d.wasm +0 -0
  174. package/learn/vendor/fantomas/System.IO.FileSystem.o6jtz51fup.wasm +0 -0
  175. package/learn/vendor/fantomas/System.IO.IsolatedStorage.hqyeyb5ipe.wasm +0 -0
  176. package/learn/vendor/fantomas/System.IO.MemoryMappedFiles.zhamjnusxd.wasm +0 -0
  177. package/learn/vendor/fantomas/System.IO.Pipelines.wrmw5vws31.wasm +0 -0
  178. package/learn/vendor/fantomas/System.IO.Pipes.AccessControl.qcancj8gj2.wasm +0 -0
  179. package/learn/vendor/fantomas/System.IO.Pipes.zhcyguvwkr.wasm +0 -0
  180. package/learn/vendor/fantomas/System.IO.UnmanagedMemoryStream.o8cpjnlard.wasm +0 -0
  181. package/learn/vendor/fantomas/System.Linq.AsyncEnumerable.hyc0b7okjw.wasm +0 -0
  182. package/learn/vendor/fantomas/System.Linq.Expressions.ldibvm0efj.wasm +0 -0
  183. package/learn/vendor/fantomas/System.Linq.Parallel.2buevezvch.wasm +0 -0
  184. package/learn/vendor/fantomas/System.Linq.Queryable.cvq43g1awj.wasm +0 -0
  185. package/learn/vendor/fantomas/System.Linq.lz6mvi0hm2.wasm +0 -0
  186. package/learn/vendor/fantomas/System.Memory.3jekerw0ga.wasm +0 -0
  187. package/learn/vendor/fantomas/System.Net.Http.Json.8k237kkwec.wasm +0 -0
  188. package/learn/vendor/fantomas/System.Net.Http.cityx2bvcl.wasm +0 -0
  189. package/learn/vendor/fantomas/System.Net.HttpListener.s1jreclykx.wasm +0 -0
  190. package/learn/vendor/fantomas/System.Net.Mail.cmlj4c0gto.wasm +0 -0
  191. package/learn/vendor/fantomas/System.Net.NameResolution.q3gf18q13l.wasm +0 -0
  192. package/learn/vendor/fantomas/System.Net.NetworkInformation.xaz5tjw7d0.wasm +0 -0
  193. package/learn/vendor/fantomas/System.Net.Ping.a40atim1h0.wasm +0 -0
  194. package/learn/vendor/fantomas/System.Net.Primitives.i88i20r8sr.wasm +0 -0
  195. package/learn/vendor/fantomas/System.Net.Quic.hx06eo5xkj.wasm +0 -0
  196. package/learn/vendor/fantomas/System.Net.Requests.hkjxlfe5f5.wasm +0 -0
  197. package/learn/vendor/fantomas/System.Net.Security.ch34yya69o.wasm +0 -0
  198. package/learn/vendor/fantomas/System.Net.ServerSentEvents.0u7o0jk3p1.wasm +0 -0
  199. package/learn/vendor/fantomas/System.Net.ServicePoint.xbhxnytx4l.wasm +0 -0
  200. package/learn/vendor/fantomas/System.Net.Sockets.hzgzlvkc9l.wasm +0 -0
  201. package/learn/vendor/fantomas/System.Net.WebClient.84i8nwzbgu.wasm +0 -0
  202. package/learn/vendor/fantomas/System.Net.WebHeaderCollection.326nl7s9g3.wasm +0 -0
  203. package/learn/vendor/fantomas/System.Net.WebProxy.oq3mgkkqef.wasm +0 -0
  204. package/learn/vendor/fantomas/System.Net.WebSockets.2cx1v74vg8.wasm +0 -0
  205. package/learn/vendor/fantomas/System.Net.WebSockets.Client.rafzkktw8j.wasm +0 -0
  206. package/learn/vendor/fantomas/System.Net.w1hpj3bo6r.wasm +0 -0
  207. package/learn/vendor/fantomas/System.Numerics.Vectors.oyv7biw9ux.wasm +0 -0
  208. package/learn/vendor/fantomas/System.Numerics.lyu36wqn19.wasm +0 -0
  209. package/learn/vendor/fantomas/System.ObjectModel.kxu80demuu.wasm +0 -0
  210. package/learn/vendor/fantomas/System.Private.CoreLib.1vy46s12u6.wasm +0 -0
  211. package/learn/vendor/fantomas/System.Private.DataContractSerialization.ao8k9iu77a.wasm +0 -0
  212. package/learn/vendor/fantomas/System.Private.Uri.itn0n2zjd0.wasm +0 -0
  213. package/learn/vendor/fantomas/System.Private.Xml.19nzpxrx8w.wasm +0 -0
  214. package/learn/vendor/fantomas/System.Private.Xml.Linq.tw5eq1hjvo.wasm +0 -0
  215. package/learn/vendor/fantomas/System.Reflection.DispatchProxy.7lajnj8s8c.wasm +0 -0
  216. package/learn/vendor/fantomas/System.Reflection.Emit.7liz9zln06.wasm +0 -0
  217. package/learn/vendor/fantomas/System.Reflection.Emit.ILGeneration.1ut3qgacw8.wasm +0 -0
  218. package/learn/vendor/fantomas/System.Reflection.Emit.Lightweight.d0gvllb1jj.wasm +0 -0
  219. package/learn/vendor/fantomas/System.Reflection.Extensions.zr5bhwfczd.wasm +0 -0
  220. package/learn/vendor/fantomas/System.Reflection.Metadata.ff6np6mz2j.wasm +0 -0
  221. package/learn/vendor/fantomas/System.Reflection.Primitives.igpmvwv78c.wasm +0 -0
  222. package/learn/vendor/fantomas/System.Reflection.TypeExtensions.qouojzlnp9.wasm +0 -0
  223. package/learn/vendor/fantomas/System.Reflection.mk3jyxvh13.wasm +0 -0
  224. package/learn/vendor/fantomas/System.Resources.Reader.41ppfyz2vc.wasm +0 -0
  225. package/learn/vendor/fantomas/System.Resources.ResourceManager.sfwvfmw1ea.wasm +0 -0
  226. package/learn/vendor/fantomas/System.Resources.Writer.3uvs9tp38z.wasm +0 -0
  227. package/learn/vendor/fantomas/System.Runtime.CompilerServices.Unsafe.puz1xm53oc.wasm +0 -0
  228. package/learn/vendor/fantomas/System.Runtime.CompilerServices.VisualC.9qdau315py.wasm +0 -0
  229. package/learn/vendor/fantomas/System.Runtime.Extensions.i7gntui96b.wasm +0 -0
  230. package/learn/vendor/fantomas/System.Runtime.Handles.00oxj4o6ov.wasm +0 -0
  231. package/learn/vendor/fantomas/System.Runtime.InteropServices.JavaScript.9kq1vofond.wasm +0 -0
  232. package/learn/vendor/fantomas/System.Runtime.InteropServices.RuntimeInformation.my7qeqbhfh.wasm +0 -0
  233. package/learn/vendor/fantomas/System.Runtime.InteropServices.vqp80tnwc7.wasm +0 -0
  234. package/learn/vendor/fantomas/System.Runtime.Intrinsics.u0samjybfo.wasm +0 -0
  235. package/learn/vendor/fantomas/System.Runtime.Loader.n6zxw1b98a.wasm +0 -0
  236. package/learn/vendor/fantomas/System.Runtime.Numerics.o40sjhz59x.wasm +0 -0
  237. package/learn/vendor/fantomas/System.Runtime.Serialization.Formatters.1esvva4te3.wasm +0 -0
  238. package/learn/vendor/fantomas/System.Runtime.Serialization.Json.4n7u09advh.wasm +0 -0
  239. package/learn/vendor/fantomas/System.Runtime.Serialization.Primitives.xs2bo91wvk.wasm +0 -0
  240. package/learn/vendor/fantomas/System.Runtime.Serialization.Xml.ny21jmziti.wasm +0 -0
  241. package/learn/vendor/fantomas/System.Runtime.Serialization.qcxaur5wqs.wasm +0 -0
  242. package/learn/vendor/fantomas/System.Runtime.odq454d6j9.wasm +0 -0
  243. package/learn/vendor/fantomas/System.Security.AccessControl.8yfnzmqzaq.wasm +0 -0
  244. package/learn/vendor/fantomas/System.Security.Claims.8ogy0860de.wasm +0 -0
  245. package/learn/vendor/fantomas/System.Security.Cryptography.Algorithms.8zijp1svfw.wasm +0 -0
  246. package/learn/vendor/fantomas/System.Security.Cryptography.Cng.yxagtt77no.wasm +0 -0
  247. package/learn/vendor/fantomas/System.Security.Cryptography.Csp.uhfbvvau84.wasm +0 -0
  248. package/learn/vendor/fantomas/System.Security.Cryptography.Encoding.2ywrusvy8q.wasm +0 -0
  249. package/learn/vendor/fantomas/System.Security.Cryptography.OpenSsl.oa268u7i92.wasm +0 -0
  250. package/learn/vendor/fantomas/System.Security.Cryptography.Primitives.5uhvqe8puk.wasm +0 -0
  251. package/learn/vendor/fantomas/System.Security.Cryptography.X509Certificates.6i7pxilopt.wasm +0 -0
  252. package/learn/vendor/fantomas/System.Security.Cryptography.d0quqk1iyr.wasm +0 -0
  253. package/learn/vendor/fantomas/System.Security.Principal.Windows.gpqua4rz29.wasm +0 -0
  254. package/learn/vendor/fantomas/System.Security.Principal.i20kfklf3g.wasm +0 -0
  255. package/learn/vendor/fantomas/System.Security.SecureString.x2y8tzci3c.wasm +0 -0
  256. package/learn/vendor/fantomas/System.Security.e83vvh6sl2.wasm +0 -0
  257. package/learn/vendor/fantomas/System.ServiceModel.Web.poglliv2no.wasm +0 -0
  258. package/learn/vendor/fantomas/System.ServiceProcess.yro5uj2opo.wasm +0 -0
  259. package/learn/vendor/fantomas/System.Text.Encoding.CodePages.2wchx40i7z.wasm +0 -0
  260. package/learn/vendor/fantomas/System.Text.Encoding.Extensions.8utaw61kn5.wasm +0 -0
  261. package/learn/vendor/fantomas/System.Text.Encoding.cxdyfepnpj.wasm +0 -0
  262. package/learn/vendor/fantomas/System.Text.Encodings.Web.37ehbi7cye.wasm +0 -0
  263. package/learn/vendor/fantomas/System.Text.Json.ixiaa8hd3h.wasm +0 -0
  264. package/learn/vendor/fantomas/System.Text.RegularExpressions.2fhfmkk6vf.wasm +0 -0
  265. package/learn/vendor/fantomas/System.Threading.6pry74a050.wasm +0 -0
  266. package/learn/vendor/fantomas/System.Threading.AccessControl.76zfdfy8go.wasm +0 -0
  267. package/learn/vendor/fantomas/System.Threading.Channels.gpxnr01lmp.wasm +0 -0
  268. package/learn/vendor/fantomas/System.Threading.Overlapped.aqpl8tzdyc.wasm +0 -0
  269. package/learn/vendor/fantomas/System.Threading.Tasks.Dataflow.ytwttt7fzh.wasm +0 -0
  270. package/learn/vendor/fantomas/System.Threading.Tasks.Extensions.0deavcb00v.wasm +0 -0
  271. package/learn/vendor/fantomas/System.Threading.Tasks.Parallel.tjwtxugso0.wasm +0 -0
  272. package/learn/vendor/fantomas/System.Threading.Tasks.fu4qd5h3qy.wasm +0 -0
  273. package/learn/vendor/fantomas/System.Threading.Thread.klaua2by9m.wasm +0 -0
  274. package/learn/vendor/fantomas/System.Threading.ThreadPool.mkzm212njz.wasm +0 -0
  275. package/learn/vendor/fantomas/System.Threading.Timer.yp49llu5h2.wasm +0 -0
  276. package/learn/vendor/fantomas/System.Transactions.Local.vz6cgeh4w7.wasm +0 -0
  277. package/learn/vendor/fantomas/System.Transactions.ipwm3rsy66.wasm +0 -0
  278. package/learn/vendor/fantomas/System.ValueTuple.7ol6ljuhx8.wasm +0 -0
  279. package/learn/vendor/fantomas/System.Web.HttpUtility.itlvncjd96.wasm +0 -0
  280. package/learn/vendor/fantomas/System.Web.np8uzzakvl.wasm +0 -0
  281. package/learn/vendor/fantomas/System.Windows.18nzio44t3.wasm +0 -0
  282. package/learn/vendor/fantomas/System.Xml.45jprtg1pa.wasm +0 -0
  283. package/learn/vendor/fantomas/System.Xml.Linq.v9v8udncm1.wasm +0 -0
  284. package/learn/vendor/fantomas/System.Xml.ReaderWriter.a9mr08uzci.wasm +0 -0
  285. package/learn/vendor/fantomas/System.Xml.Serialization.03juoguwgc.wasm +0 -0
  286. package/learn/vendor/fantomas/System.Xml.XDocument.c9dhjnzqjb.wasm +0 -0
  287. package/learn/vendor/fantomas/System.Xml.XPath.XDocument.138b12i1pm.wasm +0 -0
  288. package/learn/vendor/fantomas/System.Xml.XPath.pvxm9341ce.wasm +0 -0
  289. package/learn/vendor/fantomas/System.Xml.XmlDocument.450wsyxvl0.wasm +0 -0
  290. package/learn/vendor/fantomas/System.Xml.XmlSerializer.y3t2n0tce7.wasm +0 -0
  291. package/learn/vendor/fantomas/System.gjriafnqmz.wasm +0 -0
  292. package/learn/vendor/fantomas/WindowsBase.8zsce9qxfb.wasm +0 -0
  293. package/learn/vendor/fantomas/cs/FSharp.Core.resources.9ehmavdel7.wasm +0 -0
  294. package/learn/vendor/fantomas/de/FSharp.Core.resources.2ofmxloa01.wasm +0 -0
  295. package/learn/vendor/fantomas/dotnet.js +1233 -0
  296. package/learn/vendor/fantomas/dotnet.native.b6l13xorvf.js +16 -0
  297. package/learn/vendor/fantomas/dotnet.native.rw4kynp763.wasm +0 -0
  298. package/learn/vendor/fantomas/dotnet.runtime.v06hirbjsv.js +4 -0
  299. package/learn/vendor/fantomas/es/FSharp.Core.resources.hkr5ggb4tr.wasm +0 -0
  300. package/learn/vendor/fantomas/fr/FSharp.Core.resources.43soen28ow.wasm +0 -0
  301. package/learn/vendor/fantomas/icudt_CJK.tjcz0u77k5.dat +0 -0
  302. package/learn/vendor/fantomas/icudt_EFIGS.tptq2av103.dat +0 -0
  303. package/learn/vendor/fantomas/icudt_no_CJK.lfu7j35m59.dat +0 -0
  304. package/learn/vendor/fantomas/it/FSharp.Core.resources.m60n5ls7oq.wasm +0 -0
  305. package/learn/vendor/fantomas/ja/FSharp.Core.resources.o6oof69v14.wasm +0 -0
  306. package/learn/vendor/fantomas/ko/FSharp.Core.resources.q6l4snlu9o.wasm +0 -0
  307. package/learn/vendor/fantomas/mscorlib.8ptuc08eli.wasm +0 -0
  308. package/learn/vendor/fantomas/netstandard.eymp85mooh.wasm +0 -0
  309. package/learn/vendor/fantomas/pl/FSharp.Core.resources.8bni0w6j8b.wasm +0 -0
  310. package/learn/vendor/fantomas/pt-BR/FSharp.Core.resources.k849vqm41u.wasm +0 -0
  311. package/learn/vendor/fantomas/ru/FSharp.Core.resources.jz9rhhtsla.wasm +0 -0
  312. package/learn/vendor/fantomas/tr/FSharp.Core.resources.wn6vbvjm1u.wasm +0 -0
  313. package/learn/vendor/fantomas/zh-Hans/FSharp.Core.resources.z7zzbso094.wasm +0 -0
  314. package/learn/vendor/fantomas/zh-Hant/FSharp.Core.resources.iammfsi7ls.wasm +0 -0
  315. package/learn/vendor/fast-check-LICENSE.txt +21 -0
  316. package/learn/vendor/fast-check.mjs +37 -0
  317. package/learn/vendor/fonts/atkinson-hyperlegible-latin-400-normal.woff2 +0 -0
  318. package/learn/vendor/fonts/atkinson-hyperlegible-latin-700-normal.woff2 +0 -0
  319. package/learn/vendor/fonts/atkinson-hyperlegible-mono-latin-400-normal.woff2 +0 -0
  320. package/learn/vendor/fonts/overpass-latin-600-normal.woff2 +0 -0
  321. package/learn/vendor/fonts/overpass-latin-700-normal.woff2 +0 -0
  322. package/learn/vendor/formatter-licenses/DotNet-LICENSE.txt +23 -0
  323. package/learn/vendor/formatter-licenses/DotNet-THIRD-PARTY-NOTICES.txt +1418 -0
  324. package/learn/vendor/formatter-licenses/FSharp-LICENSE.txt +23 -0
  325. package/learn/vendor/formatter-licenses/Fantomas-LICENSE.txt +202 -0
  326. package/learn/vendor/formatter-licenses/README.md +12 -0
  327. package/learn/vendor/manifest.json +1354 -0
  328. package/learn/vendor/metadata/Browser.Blob.dll +0 -0
  329. package/learn/vendor/metadata/Browser.Dom.dll +0 -0
  330. package/learn/vendor/metadata/Browser.Event.dll +0 -0
  331. package/learn/vendor/metadata/Browser.Gamepad.dll +0 -0
  332. package/learn/vendor/metadata/Browser.WebGL.dll +0 -0
  333. package/learn/vendor/metadata/Browser.WebStorage.dll +0 -0
  334. package/learn/vendor/metadata/FSharp.Core.dll +0 -0
  335. package/learn/vendor/metadata/Fable.Core.dll +0 -0
  336. package/learn/vendor/metadata/Fable.Repl.Lib.dll +0 -0
  337. package/learn/vendor/metadata/System.Collections.Concurrent.dll +0 -0
  338. package/learn/vendor/metadata/System.Collections.dll +0 -0
  339. package/learn/vendor/metadata/System.ComponentModel.Primitives.dll +0 -0
  340. package/learn/vendor/metadata/System.ComponentModel.TypeConverter.dll +0 -0
  341. package/learn/vendor/metadata/System.ComponentModel.dll +0 -0
  342. package/learn/vendor/metadata/System.Console.dll +0 -0
  343. package/learn/vendor/metadata/System.Core.dll +0 -0
  344. package/learn/vendor/metadata/System.Diagnostics.Debug.dll +0 -0
  345. package/learn/vendor/metadata/System.Diagnostics.Tools.dll +0 -0
  346. package/learn/vendor/metadata/System.Diagnostics.Tracing.dll +0 -0
  347. package/learn/vendor/metadata/System.Globalization.dll +0 -0
  348. package/learn/vendor/metadata/System.IO.dll +0 -0
  349. package/learn/vendor/metadata/System.Net.Requests.dll +0 -0
  350. package/learn/vendor/metadata/System.Net.WebClient.dll +0 -0
  351. package/learn/vendor/metadata/System.Numerics.dll +0 -0
  352. package/learn/vendor/metadata/System.Reflection.Extensions.dll +0 -0
  353. package/learn/vendor/metadata/System.Reflection.Metadata.dll +0 -0
  354. package/learn/vendor/metadata/System.Reflection.Primitives.dll +0 -0
  355. package/learn/vendor/metadata/System.Reflection.TypeExtensions.dll +0 -0
  356. package/learn/vendor/metadata/System.Reflection.dll +0 -0
  357. package/learn/vendor/metadata/System.Runtime.Extensions.dll +0 -0
  358. package/learn/vendor/metadata/System.Runtime.InteropServices.dll +0 -0
  359. package/learn/vendor/metadata/System.Runtime.Numerics.dll +0 -0
  360. package/learn/vendor/metadata/System.Runtime.dll +0 -0
  361. package/learn/vendor/metadata/System.Text.Encoding.Extensions.dll +0 -0
  362. package/learn/vendor/metadata/System.Text.Encoding.dll +0 -0
  363. package/learn/vendor/metadata/System.Text.RegularExpressions.dll +0 -0
  364. package/learn/vendor/metadata/System.Threading.Tasks.dll +0 -0
  365. package/learn/vendor/metadata/System.Threading.Thread.dll +0 -0
  366. package/learn/vendor/metadata/System.Threading.dll +0 -0
  367. package/learn/vendor/metadata/System.ValueTuple.dll +0 -0
  368. package/learn/vendor/metadata/System.dll +0 -0
  369. package/learn/vendor/metadata/mscorlib.dll +0 -0
  370. package/learn/vendor/metadata/netstandard.dll +0 -0
  371. package/learn/vendor/monaco-editor-LICENSE.txt +21 -0
  372. package/learn/vendor/prettier/babel.mjs +16 -0
  373. package/learn/vendor/prettier/brace-style.mjs +376 -0
  374. package/learn/vendor/prettier/estree.mjs +44 -0
  375. package/learn/vendor/prettier/standalone.mjs +29 -0
  376. package/learn/vendor/prettier/typescript.mjs +22 -0
  377. package/learn/vendor/prettier-LICENSE.txt +7 -0
  378. package/learn/vendor/prettier-plugin-brace-style-LICENSE.txt +21 -0
  379. package/learn/vendor/typescript-LICENSE.txt +55 -0
  380. package/learn/vendor/typescript-libs.json +1 -0
  381. package/learn/vendor/typescript.mjs +451 -0
  382. package/learn/vendor/zod-LICENSE.txt +21 -0
  383. package/learn/web-format.mjs +8 -0
  384. package/learn.mjs +126 -0
  385. package/lsp.mjs +444 -133
  386. package/mcp.mjs +250 -0
  387. package/native-evidence.mjs +668 -182
  388. package/native-examples.mjs +56 -19
  389. package/native-host.mjs +136 -42
  390. package/native-parsers/clojure.LICENSE +121 -0
  391. package/native-parsers/clojure.wasm +0 -0
  392. package/native-parsers/csharp.LICENSE +21 -0
  393. package/native-parsers/csharp.wasm +0 -0
  394. package/native-parsers/elixir.LICENSE +176 -0
  395. package/native-parsers/elixir.wasm +0 -0
  396. package/native-parsers/erlang.LICENSE +201 -0
  397. package/native-parsers/erlang.wasm +0 -0
  398. package/native-parsers/fsharp.LICENSE +21 -0
  399. package/native-parsers/fsharp.wasm +0 -0
  400. package/native-parsers/gleam.LICENSE +202 -0
  401. package/native-parsers/gleam.wasm +0 -0
  402. package/native-parsers/go.LICENSE +21 -0
  403. package/native-parsers/go.wasm +0 -0
  404. package/native-parsers/groovy.LICENSE +21 -0
  405. package/native-parsers/groovy.wasm +0 -0
  406. package/native-parsers/haskell.LICENSE +21 -0
  407. package/native-parsers/haskell.wasm +0 -0
  408. package/native-parsers/java.LICENSE +21 -0
  409. package/native-parsers/java.wasm +0 -0
  410. package/native-parsers/javascript.LICENSE +21 -0
  411. package/native-parsers/javascript.wasm +0 -0
  412. package/native-parsers/kotlin.LICENSE +9 -0
  413. package/native-parsers/kotlin.wasm +0 -0
  414. package/native-parsers/lock.json +114 -0
  415. package/native-parsers/prolog.LICENSE +21 -0
  416. package/native-parsers/prolog.wasm +0 -0
  417. package/native-parsers/python.LICENSE +21 -0
  418. package/native-parsers/python.wasm +0 -0
  419. package/native-parsers/rust.LICENSE +21 -0
  420. package/native-parsers/rust.wasm +0 -0
  421. package/native-parsers/scala.LICENSE +21 -0
  422. package/native-parsers/scala.wasm +0 -0
  423. package/native-parsers/swift.LICENSE +21 -0
  424. package/native-parsers/swift.wasm +0 -0
  425. package/native-parsers/typescript.LICENSE +21 -0
  426. package/native-parsers/typescript.wasm +0 -0
  427. package/node-events-reporter.mjs +41 -17
  428. package/package.json +5 -3
  429. package/project.mjs +338 -0
  430. package/proof.d.ts +93 -19
  431. package/proof.mjs +1538 -447
  432. package/read-only-hpack.mjs +6 -5
  433. package/scala-build-state.mjs +131 -41
  434. package/scala-coverage.mjs +57 -34
  435. package/scalars.mjs +23 -8
  436. package/templates.mjs +566 -617
  437. package/test-command.mjs +1671 -521
package/proof.mjs CHANGED
@@ -2,110 +2,248 @@
2
2
  // Host execution of compiler-produced tasks. The browser/WASM compiler stays
3
3
  // pure; this Node host invokes Z3's SMT-LIB interface without a shell.
4
4
  import {spawn} from 'node:child_process';
5
- import {createHash,randomUUID} from 'node:crypto';
6
- import {access,mkdir,readFile,realpath,rename,rm,writeFile} from 'node:fs/promises';
5
+ import {createHash, randomUUID} from 'node:crypto';
6
+ import {
7
+ access,
8
+ mkdir,
9
+ readFile,
10
+ realpath,
11
+ rename,
12
+ rm,
13
+ writeFile,
14
+ } from 'node:fs/promises';
7
15
  import {constants} from 'node:fs';
8
16
  import path from 'node:path';
9
17
 
10
- const hash=value=>createHash('sha256').update(value).digest('hex');
11
- const frame=value=>Buffer.byteLength(value,'utf8')+':'+value;
12
- const fingerprint=values=>hash(values.map(frame).join(''));
18
+ const hash = value => createHash('sha256').update(value).digest('hex');
19
+ const frame = value => Buffer.byteLength(value, 'utf8') + ':' + value;
20
+ const fingerprint = values => hash(values.map(frame).join(''));
13
21
  // A task names its encoding; tasks that need later features are v2.
14
- const encodings=['lawspec-smtlib-v1','lawspec-smtlib-v2'];
22
+ const encodings = ['lawspec-smtlib-v1', 'lawspec-smtlib-v2'];
15
23
 
16
- export function proofTaskFingerprint(task) {
17
- return fingerprint([task.encoding,task.lawFingerprint,String(task.machineBits),
18
- task.owner,task.declaration,task.script]);
24
+ export function proofTaskFingerprint(task)
25
+ {
26
+ return fingerprint([
27
+ task.encoding,
28
+ task.lawFingerprint,
29
+ String(task.machineBits),
30
+ task.owner,
31
+ task.declaration,
32
+ task.script,
33
+ ]);
19
34
  }
20
35
 
21
- function optionsWithDefaults(options) {
22
- const config={binary:options.binary??'z3',timeoutMs:options.timeoutMs??5000,
23
- memoryMb:options.memoryMb??512,resourceLimit:options.resourceLimit??0,
24
- seed:options.seed??0,maxOutputBytes:options.maxOutputBytes??1048576};
25
- for(const [key,maximum] of [['timeoutMs',600000],['memoryMb',65536],
26
- ['resourceLimit',2147483647],['seed',2147483647],['maxOutputBytes',16777216]]) {
27
- const minimum=['resourceLimit','seed'].includes(key)?0:1;
28
- if(!Number.isSafeInteger(config[key])||config[key]<minimum||config[key]>maximum)
36
+ function optionsWithDefaults(options)
37
+ {
38
+ const config = {
39
+ binary: options.binary ?? 'z3',
40
+ timeoutMs: options.timeoutMs ?? 5000,
41
+ memoryMb: options.memoryMb ?? 512,
42
+ resourceLimit: options.resourceLimit ?? 0,
43
+ seed: options.seed ?? 0,
44
+ maxOutputBytes: options.maxOutputBytes ?? 1048576,
45
+ };
46
+ for (const [key, maximum] of [
47
+ ['timeoutMs', 600000],
48
+ ['memoryMb', 65536],
49
+ ['resourceLimit', 2147483647],
50
+ ['seed', 2147483647],
51
+ ['maxOutputBytes', 16777216],
52
+ ])
53
+ {
54
+ const minimum = ['resourceLimit', 'seed'].includes(key) ? 0 : 1;
55
+ if (
56
+ !Number.isSafeInteger(config[key]) ||
57
+ config[key] < minimum ||
58
+ config[key] > maximum
59
+ )
29
60
  throw new TypeError(`Invalid Z3 ${key}`);
30
61
  }
31
- if(typeof config.binary!=='string'||!config.binary||config.binary.includes('\0'))
62
+ if (
63
+ typeof config.binary !== 'string' ||
64
+ !config.binary ||
65
+ config.binary.includes('\0')
66
+ )
32
67
  throw new TypeError('Invalid Z3 executable');
33
68
  return config;
34
69
  }
35
70
 
36
- async function executable(binary) {
37
- const candidates=path.isAbsolute(binary)||binary.includes('/')||binary.includes('\\')
38
- ?[path.resolve(binary)]
39
- :(process.env.PATH??'').split(path.delimiter).map(folder=>path.resolve(folder,binary));
40
- for(const candidate of candidates) {
41
- try {await access(candidate,constants.X_OK);return await realpath(candidate);}
42
- catch(error) {if(!['ENOENT','EACCES','ENOTDIR'].includes(error.code))throw error;}
71
+ async function executable(binary)
72
+ {
73
+ const candidates =
74
+ path.isAbsolute(binary) || binary.includes('/') || binary.includes('\\')
75
+ ? [path.resolve(binary)]
76
+ : (process.env.PATH ?? '')
77
+ .split(path.delimiter)
78
+ .map(folder => path.resolve(folder, binary));
79
+ for (const candidate of candidates)
80
+ {
81
+ try
82
+ {
83
+ await access(candidate, constants.X_OK);
84
+ return await realpath(candidate);
85
+ }
86
+ catch (error)
87
+ {
88
+ if (!['ENOENT', 'EACCES', 'ENOTDIR'].includes(error.code)) throw error;
89
+ }
43
90
  }
44
- throw Object.assign(new Error(`Z3 executable is unavailable: ${binary}`),{code:'ENOENT'});
91
+ throw Object.assign(new Error(`Z3 executable is unavailable: ${binary}`), {
92
+ code: 'ENOENT',
93
+ });
45
94
  }
46
95
 
47
96
  // Only the first response line is a protocol token. Models and unknown reasons
48
97
  // remain raw prover output; this host does not implement another SMT parser.
49
- const followUp=token=>token==='sat'?'(get-model)\n(exit)\n':
50
- token==='unknown'?'(get-info :reason-unknown)\n(exit)\n':'(exit)\n';
51
- function execute(binary,args,initial,config,interactive=false,finishFor=followUp) {
52
- return new Promise(resolve=>{
53
- const started=performance.now();
54
- const child=spawn(binary,args,{stdio:['pipe','pipe','pipe'],shell:false});
55
- child.stdout.setEncoding('utf8');child.stderr.setEncoding('utf8');
56
- let stdout='',stderr='',input=initial,bytes=0,outcome=null,error=null;
57
- let timeout=false,outputLimit=false,answered=false,closed=false;
58
- const timer=setTimeout(()=>{timeout=true;child.kill('SIGKILL');},config.timeoutMs);
59
- const append=(which,chunk)=>{
60
- bytes+=Buffer.byteLength(chunk,'utf8');
61
- if(bytes>config.maxOutputBytes){outputLimit=true;child.kill('SIGKILL');return;}
62
- if(which==='stdout')stdout+=chunk;else stderr+=chunk;
63
- if(interactive&&!answered&&stdout.includes('\n')) {
64
- answered=true;
65
- const token=stdout.slice(0,stdout.indexOf('\n')).trim();
66
- if(['sat','unsat','unknown'].includes(token))outcome=token;
67
- else error='unexpected Z3 protocol response';
68
- const finish=finishFor(token);
69
- input+=finish;
98
+ const followUp = token =>
99
+ token === 'sat'
100
+ ? '(get-model)\n(exit)\n'
101
+ : token === 'unknown'
102
+ ? '(get-info :reason-unknown)\n(exit)\n'
103
+ : '(exit)\n';
104
+ function execute(
105
+ binary,
106
+ args,
107
+ initial,
108
+ config,
109
+ interactive = false,
110
+ finishFor = followUp,
111
+ )
112
+ {
113
+ return new Promise(resolve =>
114
+ {
115
+ const started = performance.now();
116
+ const child = spawn(binary, args, {
117
+ stdio: ['pipe', 'pipe', 'pipe'],
118
+ shell: false,
119
+ });
120
+ child.stdout.setEncoding('utf8');
121
+ child.stderr.setEncoding('utf8');
122
+ let stdout = '',
123
+ stderr = '',
124
+ input = initial,
125
+ bytes = 0,
126
+ outcome = null,
127
+ error = null;
128
+ let timeout = false,
129
+ outputLimit = false,
130
+ answered = false,
131
+ closed = false;
132
+ const timer = setTimeout(() =>
133
+ {
134
+ timeout = true;
135
+ child.kill('SIGKILL');
136
+ }, config.timeoutMs);
137
+ const append = (which, chunk) =>
138
+ {
139
+ bytes += Buffer.byteLength(chunk, 'utf8');
140
+ if (bytes > config.maxOutputBytes)
141
+ {
142
+ outputLimit = true;
143
+ child.kill('SIGKILL');
144
+ return;
145
+ }
146
+ if (which === 'stdout') stdout += chunk;
147
+ else stderr += chunk;
148
+ if (interactive && !answered && stdout.includes('\n'))
149
+ {
150
+ answered = true;
151
+ const token = stdout.slice(0, stdout.indexOf('\n')).trim();
152
+ if (['sat', 'unsat', 'unknown'].includes(token)) outcome = token;
153
+ else error = 'unexpected Z3 protocol response';
154
+ const finish = finishFor(token);
155
+ input += finish;
70
156
  child.stdin.end(finish);
71
157
  }
72
158
  };
73
- child.stdout.on('data',chunk=>append('stdout',chunk));
74
- child.stderr.on('data',chunk=>append('stderr',chunk));
75
- child.stdin.on('error',problem=>{if(problem.code!=='EPIPE')error=problem.message;});
76
- child.on('error',problem=>{error=problem.message;});
77
- child.on('close',(exitCode,signal)=>{
78
- if(closed)return;
79
- closed=true;clearTimeout(timer);
80
- resolve({stdout,stderr,input,outcome,error,timeout,outputLimit,exitCode,signal,
81
- elapsedMs:performance.now()-started});
159
+ child.stdout.on('data', chunk => append('stdout', chunk));
160
+ child.stderr.on('data', chunk => append('stderr', chunk));
161
+ child.stdin.on('error', problem =>
162
+ {
163
+ if (problem.code !== 'EPIPE') error = problem.message;
164
+ });
165
+ child.on('error', problem =>
166
+ {
167
+ error = problem.message;
82
168
  });
83
- if(interactive)child.stdin.write(initial);else child.stdin.end(initial);
169
+ child.on('close', (exitCode, signal) =>
170
+ {
171
+ if (closed) return;
172
+ closed = true;
173
+ clearTimeout(timer);
174
+ resolve({
175
+ stdout,
176
+ stderr,
177
+ input,
178
+ outcome,
179
+ error,
180
+ timeout,
181
+ outputLimit,
182
+ exitCode,
183
+ signal,
184
+ elapsedMs: performance.now() - started,
185
+ });
186
+ });
187
+ if (interactive) child.stdin.write(initial);
188
+ else child.stdin.end(initial);
84
189
  });
85
190
  }
86
191
 
87
- const versionProbeMs=30000;
88
- async function prover(config) {
89
- const binary=await executable(config.binary);
90
- const binaryFingerprint=hash(await readFile(binary));
192
+ const versionProbeMs = 30000;
193
+ async function prover(config)
194
+ {
195
+ const binary = await executable(config.binary);
196
+ const binaryFingerprint = hash(await readFile(binary));
91
197
  // The identity probe has its own bound: the task limit is for a solver's
92
198
  // work on a task, and the probe does none.
93
- const versionRun=await execute(binary,['-version'],'',{...config,timeoutMs:versionProbeMs});
94
- const version=versionRun.stdout.trim();
95
- if(versionRun.exitCode!==0||versionRun.error||versionRun.timeout||versionRun.outputLimit||
96
- !/^Z3 version [0-9]+\.[0-9]+/.test(version))
97
- throw Object.assign(new Error('The selected executable did not return a successful Z3 version response'),
98
- {outcome:versionRun.timeout?'timeout':'failed'});
99
- const args=['-in','-smt2',`-t:${config.timeoutMs}`,`-memory:${config.memoryMb}`];
100
- const identity=fingerprint([binaryFingerprint,version,JSON.stringify(args),JSON.stringify(config)]);
101
- return {binary,binaryFingerprint,version,args,fingerprint:identity};
199
+ const versionRun = await execute(binary, ['-version'], '', {
200
+ ...config,
201
+ timeoutMs: versionProbeMs,
202
+ });
203
+ const version = versionRun.stdout.trim();
204
+ if (
205
+ versionRun.exitCode !== 0 ||
206
+ versionRun.error ||
207
+ versionRun.timeout ||
208
+ versionRun.outputLimit ||
209
+ !/^Z3 version [0-9]+\.[0-9]+/.test(version)
210
+ )
211
+ throw Object.assign(
212
+ new Error(
213
+ 'The selected executable did not return a successful Z3 version response',
214
+ ),
215
+ {outcome: versionRun.timeout ? 'timeout' : 'failed'},
216
+ );
217
+ const args = [
218
+ '-in',
219
+ '-smt2',
220
+ `-t:${config.timeoutMs}`,
221
+ `-memory:${config.memoryMb}`,
222
+ ];
223
+ const identity = fingerprint([
224
+ binaryFingerprint,
225
+ version,
226
+ JSON.stringify(args),
227
+ JSON.stringify(config),
228
+ ]);
229
+ return {binary, binaryFingerprint, version, args, fingerprint: identity};
102
230
  }
103
231
 
104
- function validTask(task) {
105
- return encodings.includes(task.encoding)&&[32,64].includes(task.machineBits)&&
106
- ['owner','declaration','lawFingerprint','script','taskFingerprint'].every(key=>typeof task[key]==='string')&&
107
- /^[0-9a-f]{64}$/.test(task.lawFingerprint)&&
108
- proofTaskFingerprint(task)===task.taskFingerprint;
232
+ function validTask(task)
233
+ {
234
+ return (
235
+ encodings.includes(task.encoding) &&
236
+ [32, 64].includes(task.machineBits) &&
237
+ [
238
+ 'owner',
239
+ 'declaration',
240
+ 'lawFingerprint',
241
+ 'script',
242
+ 'taskFingerprint',
243
+ ].every(key => typeof task[key] === 'string') &&
244
+ /^[0-9a-f]{64}$/.test(task.lawFingerprint) &&
245
+ proofTaskFingerprint(task) === task.taskFingerprint
246
+ );
109
247
  }
110
248
 
111
249
  // A semantic receipt may be reused after the compiler has admitted and
@@ -114,47 +252,127 @@ function validTask(task) {
114
252
  // cache has the same trust boundary as the compiler's other persisted memos.
115
253
  // Only completed unsat laws are reused. Counterexamples must be replayed by
116
254
  // the current evaluator, and unknown/unsupported/incomplete work is retried.
117
- async function receiptCache(request,selected) {
118
- if(typeof request.cacheDirectory!=='string'||!request.cacheDirectory||selected.error)return null;
119
- try {
120
- const build=await readFile(new URL('./build.json',import.meta.url));
121
- const host=await readFile(new URL('./proof.mjs',import.meta.url));
122
- return {folder:path.join(request.cacheDirectory,'solver-goals-v1'),
123
- identity:fingerprint(['lawspec.solver-cache.v1',hash(build),hash(host),selected.fingerprint])};
124
- } catch {return null;}
255
+ async function receiptCache(request, selected)
256
+ {
257
+ if (
258
+ typeof request.cacheDirectory !== 'string' ||
259
+ !request.cacheDirectory ||
260
+ selected.error
261
+ )
262
+ return null;
263
+ try
264
+ {
265
+ const build = await readFile(new URL('./build.json', import.meta.url));
266
+ const host = await readFile(new URL('./proof.mjs', import.meta.url));
267
+ return {
268
+ folder: path.join(request.cacheDirectory, 'solver-goals-v1'),
269
+ identity: fingerprint([
270
+ 'lawspec.solver-cache.v1',
271
+ hash(build),
272
+ hash(host),
273
+ selected.fingerprint,
274
+ ]),
275
+ };
276
+ }
277
+ catch
278
+ {
279
+ return null;
280
+ }
125
281
  }
126
282
 
127
- async function cachedSolve(task,selected,config,cache) {
128
- if(!cache||task.status!=='ready'||!validTask(task))return solve(task,selected,config);
129
- const key=fingerprint([cache.identity,task.encoding,task.lawFingerprint,String(task.machineBits)]);
130
- const filename=path.join(cache.folder,key+'.json');
131
- try {
132
- const saved=JSON.parse(await readFile(filename,'utf8'));
133
- const receipt=saved.receipt;
134
- const complete=saved.version===1&&saved.key===key&&validTask(saved.task)&&
135
- saved.task.lawFingerprint===task.lawFingerprint&&saved.task.encoding===task.encoding&&
136
- saved.task.machineBits===task.machineBits&&receipt?.status==='proved'&&receipt.outcome==='unsat'&&
137
- receipt.exitCode===0&&receipt.lawFingerprint===task.lawFingerprint&&
138
- /^[0-9a-f]{64}$/.test(receipt.runFingerprint??'')&&
139
- receipt.prover?.fingerprint===selected.fingerprint&&
140
- saved.digest===hash(JSON.stringify([saved.task,receipt]));
141
- if(complete&&hash(await readFile(selected.binary))===selected.binaryFingerprint)
142
- return {...receipt,owner:task.owner,declaration:task.declaration,at:task.at,
143
- currentTaskFingerprint:task.taskFingerprint,
144
- ...(receipt.induction&&task.induction?{currentInduction:{on:task.induction.on,using:task.induction.using}}:{}),
145
- reused:{key,owner:saved.task.owner,declaration:saved.task.declaration,
146
- taskFingerprint:receipt.taskFingerprint,runFingerprint:receipt.runFingerprint},
147
- reason:receipt.reason+'; reused a completed semantic proof receipt; no new solver task ran'};
148
- } catch {}
149
- const receipt=await solve(task,selected,config);
150
- if(receipt.status==='proved'&&receipt.outcome==='unsat'&&receipt.exitCode===0) {
151
- const temporary=filename+'.'+randomUUID()+'.tmp';
152
- try {
153
- await mkdir(cache.folder,{recursive:true});
154
- await writeFile(temporary,JSON.stringify({version:1,key,task,receipt,
155
- digest:hash(JSON.stringify([task,receipt]))})+'\n',{mode:0o600});
156
- await rename(temporary,filename);
157
- } catch {} finally {await rm(temporary,{force:true}).catch(()=>{});}
283
+ async function cachedSolve(task, selected, config, cache)
284
+ {
285
+ if (!cache || task.status !== 'ready' || !validTask(task))
286
+ return solve(task, selected, config);
287
+ const key = fingerprint([
288
+ cache.identity,
289
+ task.encoding,
290
+ task.lawFingerprint,
291
+ String(task.machineBits),
292
+ ]);
293
+ const filename = path.join(cache.folder, key + '.json');
294
+ try
295
+ {
296
+ const saved = JSON.parse(await readFile(filename, 'utf8'));
297
+ const receipt = saved.receipt;
298
+ const complete =
299
+ saved.version === 1 &&
300
+ saved.key === key &&
301
+ validTask(saved.task) &&
302
+ saved.task.lawFingerprint === task.lawFingerprint &&
303
+ saved.task.encoding === task.encoding &&
304
+ saved.task.machineBits === task.machineBits &&
305
+ receipt?.status === 'proved' &&
306
+ receipt.outcome === 'unsat' &&
307
+ receipt.exitCode === 0 &&
308
+ receipt.lawFingerprint === task.lawFingerprint &&
309
+ /^[0-9a-f]{64}$/.test(receipt.runFingerprint ?? '') &&
310
+ receipt.prover?.fingerprint === selected.fingerprint &&
311
+ saved.digest === hash(JSON.stringify([saved.task, receipt]));
312
+ if (
313
+ complete &&
314
+ hash(await readFile(selected.binary)) === selected.binaryFingerprint
315
+ )
316
+ return {
317
+ ...receipt,
318
+ owner: task.owner,
319
+ declaration: task.declaration,
320
+ at: task.at,
321
+ currentTaskFingerprint: task.taskFingerprint,
322
+ ...(receipt.induction && task.induction
323
+ ? {
324
+ currentInduction: {
325
+ on: task.induction.on,
326
+ using: task.induction.using,
327
+ },
328
+ }
329
+ : {}),
330
+ reused: {
331
+ key,
332
+ owner: saved.task.owner,
333
+ declaration: saved.task.declaration,
334
+ taskFingerprint: receipt.taskFingerprint,
335
+ runFingerprint: receipt.runFingerprint,
336
+ },
337
+ reason:
338
+ receipt.reason +
339
+ '; reused a completed semantic proof receipt; no new solver task ran',
340
+ };
341
+ }
342
+ catch
343
+ {}
344
+ const receipt = await solve(task, selected, config);
345
+ if (
346
+ receipt.status === 'proved' &&
347
+ receipt.outcome === 'unsat' &&
348
+ receipt.exitCode === 0
349
+ )
350
+ {
351
+ const temporary = filename + '.' + randomUUID() + '.tmp';
352
+ try
353
+ {
354
+ await mkdir(cache.folder, {recursive: true});
355
+ await writeFile(
356
+ temporary,
357
+ JSON.stringify({
358
+ version: 1,
359
+ key,
360
+ task,
361
+ receipt,
362
+ digest: hash(JSON.stringify([task, receipt])),
363
+ }) + '\n',
364
+ {mode: 0o600},
365
+ );
366
+ await rename(temporary, filename);
367
+ }
368
+ catch
369
+ {
370
+ }
371
+ finally
372
+ {
373
+ await rm(temporary, {force: true}).catch(() =>
374
+ {});
375
+ }
158
376
  }
159
377
  return receipt;
160
378
  }
@@ -164,53 +382,163 @@ async function cachedSolve(task,selected,config,cache) {
164
382
  // original ordered constant names, to the compiler for positional decoding
165
383
  // and full validation against the current binders/claim. The host never
166
384
  // rewrites solver/model text. Only compiler-confirmed outcomes are saved.
167
- function queryFingerprint(row,task) {
168
- return row.kind==='model'?hash(row.declaration+'\0'+task.kind+'\0'+task.script):fingerprint([row.declaration,row.stage,task.script]);
385
+ function queryFingerprint(row, task)
386
+ {
387
+ return row.kind === 'model'
388
+ ? hash(row.declaration + '\0' + task.kind + '\0' + task.script)
389
+ : fingerprint([row.declaration, row.stage, task.script]);
169
390
  }
170
- async function analysisQuery(cache,row,task,selected,executeQuery,fresh=false) {
171
- const eligible=cache&&/^[0-9a-f]{64}$/.test(task.semanticFingerprint??'')&&
172
- task.fingerprint===queryFingerprint(row,task);
173
- const key=eligible?fingerprint([cache.identity,row.kind==='model'?'model':'analysis',row.kind==='model'?'':row.stage,task.semanticFingerprint]):null;
174
- const filename=eligible?path.join(cache.folder,key+'.json'):null;
175
- if(eligible&&!fresh)try {
176
- const saved=JSON.parse(await readFile(filename,'utf8'));
177
- const record=saved.record;
178
- if(saved.version===1&&saved.key===key&&saved.digest===hash(JSON.stringify(record))&&
179
- record?.semanticFingerprint===task.semanticFingerprint&&record.solverFingerprint===selected.fingerprint&&
180
- ['sat','unsat'].includes(record.outcome)&&record.completed===true&&record.run?.exitCode===0&&
181
- record.taskFingerprint===queryFingerprint(record,{kind:record.taskKind,script:record.script})&&
182
- hash(await readFile(selected.binary))===selected.binaryFingerprint)
183
- return {...record,row,cacheFile:filename,
184
- reused:{key,owner:record.owner,declaration:record.declaration,
185
- taskFingerprint:record.taskFingerprint,runFingerprint:record.runFingerprint},
186
- rerun:()=>analysisQuery(cache,row,task,selected,executeQuery,true)};
187
- } catch {}
188
- const done=await executeQuery();
189
- return {...done,row,inputs:task.inputs,
190
- ...(eligible?{pendingCache:{filename,key,record:{kind:row.kind,taskKind:task.kind,owner:row.owner,declaration:row.declaration,stage:row.stage,
191
- taskFingerprint:task.fingerprint,semanticFingerprint:task.semanticFingerprint,script:task.script,
192
- solverFingerprint:selected.fingerprint,inputs:task.inputs,outcome:done.outcome,values:done.values,invariant:done.invariant,
193
- run:done.run,runFingerprint:done.runFingerprint,completed:true}}}:{})};
391
+ async function analysisQuery(
392
+ cache,
393
+ row,
394
+ task,
395
+ selected,
396
+ executeQuery,
397
+ fresh = false,
398
+ )
399
+ {
400
+ const eligible =
401
+ cache &&
402
+ /^[0-9a-f]{64}$/.test(task.semanticFingerprint ?? '') &&
403
+ task.fingerprint === queryFingerprint(row, task);
404
+ const key = eligible
405
+ ? fingerprint([
406
+ cache.identity,
407
+ row.kind === 'model' ? 'model' : 'analysis',
408
+ row.kind === 'model' ? '' : row.stage,
409
+ task.semanticFingerprint,
410
+ ])
411
+ : null;
412
+ const filename = eligible ? path.join(cache.folder, key + '.json') : null;
413
+ if (eligible && !fresh)
414
+ try
415
+ {
416
+ const saved = JSON.parse(await readFile(filename, 'utf8'));
417
+ const record = saved.record;
418
+ if (
419
+ saved.version === 1 &&
420
+ saved.key === key &&
421
+ saved.digest === hash(JSON.stringify(record)) &&
422
+ record?.semanticFingerprint === task.semanticFingerprint &&
423
+ record.solverFingerprint === selected.fingerprint &&
424
+ ['sat', 'unsat'].includes(record.outcome) &&
425
+ record.completed === true &&
426
+ record.run?.exitCode === 0 &&
427
+ record.taskFingerprint ===
428
+ queryFingerprint(record, {
429
+ kind: record.taskKind,
430
+ script: record.script,
431
+ }) &&
432
+ hash(await readFile(selected.binary)) === selected.binaryFingerprint
433
+ )
434
+ return {
435
+ ...record,
436
+ row,
437
+ cacheFile: filename,
438
+ reused: {
439
+ key,
440
+ owner: record.owner,
441
+ declaration: record.declaration,
442
+ taskFingerprint: record.taskFingerprint,
443
+ runFingerprint: record.runFingerprint,
444
+ },
445
+ rerun: () =>
446
+ analysisQuery(cache, row, task, selected, executeQuery, true),
447
+ };
448
+ }
449
+ catch
450
+ {}
451
+ const done = await executeQuery();
452
+ return {
453
+ ...done,
454
+ row,
455
+ inputs: task.inputs,
456
+ ...(eligible
457
+ ? {
458
+ pendingCache: {
459
+ filename,
460
+ key,
461
+ record: {
462
+ kind: row.kind,
463
+ taskKind: task.kind,
464
+ owner: row.owner,
465
+ declaration: row.declaration,
466
+ stage: row.stage,
467
+ taskFingerprint: task.fingerprint,
468
+ semanticFingerprint: task.semanticFingerprint,
469
+ script: task.script,
470
+ solverFingerprint: selected.fingerprint,
471
+ inputs: task.inputs,
472
+ outcome: done.outcome,
473
+ values: done.values,
474
+ invariant: done.invariant,
475
+ run: done.run,
476
+ runFingerprint: done.runFingerprint,
477
+ completed: true,
478
+ },
479
+ },
480
+ }
481
+ : {}),
482
+ };
194
483
  }
195
484
 
196
- async function saveQuery(done) {
197
- if(!done.pendingCache||!['sat','unsat'].includes(done.outcome)||done.run?.exitCode!==0)return;
198
- const {filename,key,record}=done.pendingCache;
199
- const temporary=filename+'.'+randomUUID()+'.tmp';
200
- try {
201
- await mkdir(path.dirname(filename),{recursive:true});
202
- await writeFile(temporary,JSON.stringify({version:1,key,record,digest:hash(JSON.stringify(record))})+'\n',{mode:0o600});
203
- await rename(temporary,filename);
204
- } catch {} finally {await rm(temporary,{force:true}).catch(()=>{});}
485
+ async function saveQuery(done)
486
+ {
487
+ if (
488
+ !done.pendingCache ||
489
+ !['sat', 'unsat'].includes(done.outcome) ||
490
+ done.run?.exitCode !== 0
491
+ )
492
+ return;
493
+ const {filename, key, record} = done.pendingCache;
494
+ const temporary = filename + '.' + randomUUID() + '.tmp';
495
+ try
496
+ {
497
+ await mkdir(path.dirname(filename), {recursive: true});
498
+ await writeFile(
499
+ temporary,
500
+ JSON.stringify({
501
+ version: 1,
502
+ key,
503
+ record,
504
+ digest: hash(JSON.stringify(record)),
505
+ }) + '\n',
506
+ {mode: 0o600},
507
+ );
508
+ await rename(temporary, filename);
509
+ }
510
+ catch
511
+ {
512
+ }
513
+ finally
514
+ {
515
+ await rm(temporary, {force: true}).catch(() =>
516
+ {});
517
+ }
205
518
  }
206
519
 
207
520
  // Law-set and model tasks need the same process and executable checks as
208
521
  // ordinary laws; a protocol token alone is not a completed solver run.
209
- async function verifiedOutcome(run,selected) {
210
- if(run.timeout)return 'timeout';
211
- let unchanged=false;
212
- try {unchanged=hash(await readFile(selected.binary))===selected.binaryFingerprint;} catch {}
213
- if(!unchanged||run.outputLimit||run.error||run.exitCode!==0||!run.outcome||run.stdout.includes('(error '))return 'failed';
522
+ async function verifiedOutcome(run, selected)
523
+ {
524
+ if (run.timeout) return 'timeout';
525
+ let unchanged = false;
526
+ try
527
+ {
528
+ unchanged =
529
+ hash(await readFile(selected.binary)) === selected.binaryFingerprint;
530
+ }
531
+ catch
532
+ {}
533
+ if (
534
+ !unchanged ||
535
+ run.outputLimit ||
536
+ run.error ||
537
+ run.exitCode !== 0 ||
538
+ !run.outcome ||
539
+ run.stdout.includes('(error ')
540
+ )
541
+ return 'failed';
214
542
  return run.outcome;
215
543
  }
216
544
 
@@ -222,369 +550,1132 @@ async function verifiedOutcome(run,selected) {
222
550
  // the same encodings, and the law is proved only when every case is. The
223
551
  // evidence records which encoding proved the law, and every attempt.
224
552
  // Programmers read plain words; the IR keeps the SMT names.
225
- const recursionName=recursion=>recursion?.encoding==='guarded-axioms'?`unfolding step by step up to ${recursion.fuel} times`:
226
- recursion?.encoding==='define-fun-rec'?'solver recursion':'';
227
- async function solve(task,selected,config) {
228
- const first=await attempt(task,task.script,task.taskFingerprint,selected,config);
229
- if(!task.recursion&&!task.induction)return first;
230
- if(first.status==='unsupported'||(first.status==='incomplete'&&first.outcome==='failed'&&!first.prover))return first;
231
- const tried=[{recursion:task.recursion,taskFingerprint:task.taskFingerprint,outcome:first.outcome,runFingerprint:first.runFingerprint,elapsedMs:first.elapsedMs}];
232
- if(first.outcome==='unsat')
233
- return {...first,recursion:task.recursion,attempts:tried,reason:first.reason+(task.recursion?'; by '+recursionName(task.recursion):'')};
234
- let best={...first,recursion:task.recursion,attempts:tried};
235
- const alternative=task.alternative;
236
- if(alternative&&!selected.error) {
237
- if(typeof alternative.script!=='string'||proofTaskFingerprint({...task,script:alternative.script})!==alternative.taskFingerprint)
238
- return {...best,reason:first.reason+'; the alternative encoding\'s binding is invalid'};
239
- const second=await attempt(task,alternative.script,alternative.taskFingerprint,selected,config);
240
- tried.push({recursion:alternative.recursion,taskFingerprint:alternative.taskFingerprint,outcome:second.outcome,
241
- runFingerprint:second.runFingerprint,elapsedMs:second.elapsedMs});
242
- if(second.outcome==='unsat')
243
- return {...second,taskFingerprint:alternative.taskFingerprint,recursion:alternative.recursion,attempts:tried,
244
- reason:second.reason+'; by '+recursionName(alternative.recursion)+' after '+recursionName(task.recursion)+' gave '+first.outcome};
245
- best={...best,reason:first.reason+'; '+recursionName(alternative.recursion)+' gave '+second.outcome};
553
+ const recursionName = recursion =>
554
+ recursion?.encoding === 'guarded-axioms'
555
+ ? `unfolding step by step up to ${recursion.fuel} times`
556
+ : recursion?.encoding === 'define-fun-rec'
557
+ ? 'solver recursion'
558
+ : '';
559
+ async function solve(task, selected, config)
560
+ {
561
+ const first = await attempt(
562
+ task,
563
+ task.script,
564
+ task.taskFingerprint,
565
+ selected,
566
+ config,
567
+ );
568
+ if (!task.recursion && !task.induction) return first;
569
+ if (
570
+ first.status === 'unsupported' ||
571
+ (first.status === 'incomplete' &&
572
+ first.outcome === 'failed' &&
573
+ !first.prover)
574
+ )
575
+ return first;
576
+ const tried = [
577
+ {
578
+ recursion: task.recursion,
579
+ taskFingerprint: task.taskFingerprint,
580
+ outcome: first.outcome,
581
+ runFingerprint: first.runFingerprint,
582
+ elapsedMs: first.elapsedMs,
583
+ },
584
+ ];
585
+ if (first.outcome === 'unsat')
586
+ return {
587
+ ...first,
588
+ recursion: task.recursion,
589
+ attempts: tried,
590
+ reason:
591
+ first.reason +
592
+ (task.recursion ? '; by ' + recursionName(task.recursion) : ''),
593
+ };
594
+ let best = {...first, recursion: task.recursion, attempts: tried};
595
+ const alternative = task.alternative;
596
+ if (alternative && !selected.error)
597
+ {
598
+ if (
599
+ typeof alternative.script !== 'string' ||
600
+ proofTaskFingerprint({...task, script: alternative.script}) !==
601
+ alternative.taskFingerprint
602
+ )
603
+ return {
604
+ ...best,
605
+ reason:
606
+ first.reason + "; the alternative encoding's binding is invalid",
607
+ };
608
+ const second = await attempt(
609
+ task,
610
+ alternative.script,
611
+ alternative.taskFingerprint,
612
+ selected,
613
+ config,
614
+ );
615
+ tried.push({
616
+ recursion: alternative.recursion,
617
+ taskFingerprint: alternative.taskFingerprint,
618
+ outcome: second.outcome,
619
+ runFingerprint: second.runFingerprint,
620
+ elapsedMs: second.elapsedMs,
621
+ });
622
+ if (second.outcome === 'unsat')
623
+ return {
624
+ ...second,
625
+ taskFingerprint: alternative.taskFingerprint,
626
+ recursion: alternative.recursion,
627
+ attempts: tried,
628
+ reason:
629
+ second.reason +
630
+ '; by ' +
631
+ recursionName(alternative.recursion) +
632
+ ' after ' +
633
+ recursionName(task.recursion) +
634
+ ' gave ' +
635
+ first.outcome,
636
+ };
637
+ best = {
638
+ ...best,
639
+ reason:
640
+ first.reason +
641
+ '; ' +
642
+ recursionName(alternative.recursion) +
643
+ ' gave ' +
644
+ second.outcome,
645
+ };
246
646
  }
247
- const induction=task.induction;
248
- if(!induction||selected.error)return best;
249
- if(induction.status!=='ready')
250
- return {...best,induction:{on:induction.on,using:induction.using,cases:[]},reason:best.reason+'; induction on '+induction.on+' is unsupported: '+induction.reason};
251
- const cases=[];
252
- for(const item of induction.cases) {
253
- const bound=caseTask=>proofTaskFingerprint({...task,script:caseTask.script})===caseTask.taskFingerprint;
254
- if(typeof item.script!=='string'||!bound(item)) {
255
- cases.push({case:item.case,outcome:'failed',reason:'the case\'s binding is invalid'});continue;
647
+ const induction = task.induction;
648
+ if (!induction || selected.error) return best;
649
+ if (induction.status !== 'ready')
650
+ return {
651
+ ...best,
652
+ induction: {on: induction.on, using: induction.using, cases: []},
653
+ reason:
654
+ best.reason +
655
+ '; induction on ' +
656
+ induction.on +
657
+ ' is unsupported: ' +
658
+ induction.reason,
659
+ };
660
+ const cases = [];
661
+ for (const item of induction.cases)
662
+ {
663
+ const bound = caseTask =>
664
+ proofTaskFingerprint({...task, script: caseTask.script}) ===
665
+ caseTask.taskFingerprint;
666
+ if (typeof item.script !== 'string' || !bound(item))
667
+ {
668
+ cases.push({
669
+ case: item.case,
670
+ outcome: 'failed',
671
+ reason: "the case's binding is invalid",
672
+ });
673
+ continue;
256
674
  }
257
- const runs=[{recursion:item.recursion,script:item.script,taskFingerprint:item.taskFingerprint},
258
- ...(item.alternative&&typeof item.alternative.script==='string'&&bound(item.alternative)?
259
- [{recursion:item.alternative.recursion,script:item.alternative.script,taskFingerprint:item.alternative.taskFingerprint}]:[])];
260
- const receipt={case:item.case,attempts:[]};
261
- for(const run of runs) {
262
- const done=await attempt(task,run.script,run.taskFingerprint,selected,config,item.inputs);
263
- receipt.attempts.push({recursion:run.recursion,taskFingerprint:run.taskFingerprint,outcome:done.outcome,
264
- runFingerprint:done.runFingerprint,elapsedMs:done.elapsedMs});
265
- Object.assign(receipt,{outcome:done.outcome,recursion:run.recursion,taskFingerprint:run.taskFingerprint,runFingerprint:done.runFingerprint});
266
- if(done.values&&!receipt.values)receipt.values=done.values;
267
- if(done.outcome==='unsat')break;
675
+ const runs = [
676
+ {
677
+ recursion: item.recursion,
678
+ script: item.script,
679
+ taskFingerprint: item.taskFingerprint,
680
+ },
681
+ ...(item.alternative &&
682
+ typeof item.alternative.script === 'string' &&
683
+ bound(item.alternative)
684
+ ? [
685
+ {
686
+ recursion: item.alternative.recursion,
687
+ script: item.alternative.script,
688
+ taskFingerprint: item.alternative.taskFingerprint,
689
+ },
690
+ ]
691
+ : []),
692
+ ];
693
+ const receipt = {case: item.case, attempts: []};
694
+ for (const run of runs)
695
+ {
696
+ const done = await attempt(
697
+ task,
698
+ run.script,
699
+ run.taskFingerprint,
700
+ selected,
701
+ config,
702
+ item.inputs,
703
+ );
704
+ receipt.attempts.push({
705
+ recursion: run.recursion,
706
+ taskFingerprint: run.taskFingerprint,
707
+ outcome: done.outcome,
708
+ runFingerprint: done.runFingerprint,
709
+ elapsedMs: done.elapsedMs,
710
+ });
711
+ Object.assign(receipt, {
712
+ outcome: done.outcome,
713
+ recursion: run.recursion,
714
+ taskFingerprint: run.taskFingerprint,
715
+ runFingerprint: done.runFingerprint,
716
+ });
717
+ if (done.values && !receipt.values) receipt.values = done.values;
718
+ if (done.outcome === 'unsat') break;
268
719
  }
269
720
  cases.push(receipt);
270
721
  }
271
- const record={on:induction.on,using:induction.using,asked:induction.asked,cases};
272
- if(cases.every(c=>c.outcome==='unsat'))
273
- return {...best,status:'proved',outcome:'unsat',induction:record,model:undefined,modelValidated:undefined,
274
- reason:'Z3 established this law by induction on '+induction.on+', every case: '+cases.map(c=>c.case+' by '+recursionName(c.recursion)).join(', ')+
275
- (induction.using.length?'; citing '+induction.using.map(law=>law.split('::law::').pop()).join(', '):'')+
276
- '; trusts the typed translation and selected solver, without a kernel-checked certificate'};
277
- const open=cases.filter(c=>c.outcome!=='unsat');
278
- return {...best,induction:record,reason:best.reason+'; induction on '+induction.on+': '+open.map(c=>'case '+c.case+' gave '+c.outcome).join(', ')};
722
+ const record = {
723
+ on: induction.on,
724
+ using: induction.using,
725
+ asked: induction.asked,
726
+ cases,
727
+ };
728
+ if (cases.every(c => c.outcome === 'unsat'))
729
+ return {
730
+ ...best,
731
+ status: 'proved',
732
+ outcome: 'unsat',
733
+ induction: record,
734
+ model: undefined,
735
+ modelValidated: undefined,
736
+ reason:
737
+ 'Z3 established this law by induction on ' +
738
+ induction.on +
739
+ ', every case: ' +
740
+ cases
741
+ .map(c => c.case + ' by ' + recursionName(c.recursion))
742
+ .join(', ') +
743
+ (induction.using.length
744
+ ? '; citing ' +
745
+ induction.using.map(law => law.split('::law::').pop()).join(', ')
746
+ : '') +
747
+ '; trusts the typed translation and selected solver, without a kernel-checked certificate',
748
+ };
749
+ const open = cases.filter(c => c.outcome !== 'unsat');
750
+ return {
751
+ ...best,
752
+ induction: record,
753
+ reason:
754
+ best.reason +
755
+ '; induction on ' +
756
+ induction.on +
757
+ ': ' +
758
+ open.map(c => 'case ' + c.case + ' gave ' + c.outcome).join(', '),
759
+ };
279
760
  }
280
761
 
281
- async function attempt(task,script,taskFingerprint,selected,config,names=null) {
282
- const common={owner:task.owner,declaration:task.declaration,at:task.at,
283
- lawFingerprint:task.lawFingerprint,taskFingerprint:task.taskFingerprint,
284
- encoding:task.encoding,machineBits:task.machineBits,configuration:config};
285
- if(task.status==='unsupported')return {...common,status:'unsupported',outcome:'unsupported',reason:task.reason};
286
- if(task.status!=='ready'||!validTask(task))
287
- return {...common,status:'incomplete',outcome:'failed',reason:'Compiler proof task binding is invalid'};
288
- if(selected.error)return {...common,status:'incomplete',outcome:selected.outcome,reason:selected.error};
289
- const input=`(set-option :print-success false)\n(set-option :produce-models true)\n`+
290
- `(set-option :random-seed ${config.seed})\n(set-option :rlimit ${config.resourceLimit})\n`+
291
- script+'(check-sat)\n';
762
+ async function attempt(
763
+ task,
764
+ script,
765
+ taskFingerprint,
766
+ selected,
767
+ config,
768
+ names = null,
769
+ )
770
+ {
771
+ const common = {
772
+ owner: task.owner,
773
+ declaration: task.declaration,
774
+ at: task.at,
775
+ lawFingerprint: task.lawFingerprint,
776
+ taskFingerprint: task.taskFingerprint,
777
+ encoding: task.encoding,
778
+ machineBits: task.machineBits,
779
+ configuration: config,
780
+ };
781
+ if (task.status === 'unsupported')
782
+ return {
783
+ ...common,
784
+ status: 'unsupported',
785
+ outcome: 'unsupported',
786
+ reason: task.reason,
787
+ };
788
+ if (task.status !== 'ready' || !validTask(task))
789
+ return {
790
+ ...common,
791
+ status: 'incomplete',
792
+ outcome: 'failed',
793
+ reason: 'Compiler proof task binding is invalid',
794
+ };
795
+ if (selected.error)
796
+ return {
797
+ ...common,
798
+ status: 'incomplete',
799
+ outcome: selected.outcome,
800
+ reason: selected.error,
801
+ };
802
+ const input =
803
+ `(set-option :print-success false)\n(set-option :produce-models true)\n` +
804
+ `(set-option :random-seed ${config.seed})\n(set-option :rlimit ${config.resourceLimit})\n` +
805
+ script +
806
+ '(check-sat)\n';
292
807
  // An induction case asks for the law's inputs, so its model can be
293
808
  // checked as the law's counterexample.
294
- const run=await execute(selected.binary,selected.args,input,config,true,names?.length?
295
- token=>token==='sat'?`(get-value (${names.join(' ')}))\n(exit)\n`:followUp(token):followUp);
296
- let unchanged=false;
297
- try {unchanged=hash(await readFile(selected.binary))===selected.binaryFingerprint;} catch {}
298
- const metadata={...common,prover:{name:'z3',version:selected.version,
299
- binary:selected.binary,binaryFingerprint:selected.binaryFingerprint,
300
- fingerprint:selected.fingerprint,arguments:selected.args},configuration:config,
301
- runFingerprint:fingerprint([taskFingerprint,selected.fingerprint,run.input]),
302
- elapsedMs:run.elapsedMs,exitCode:run.exitCode,signal:run.signal,
303
- stdout:run.stdout,stderr:run.stderr};
304
- let outcome=run.outcome,reason;
305
- if(!unchanged){outcome='failed';reason='Z3 executable changed during execution';}
306
- else if(run.timeout){outcome='timeout';reason='Z3 exceeded the host wall-clock limit';}
307
- else if(run.outputLimit){outcome='failed';reason='Z3 exceeded the output limit';}
308
- else if(run.exitCode!==0&&/out of memory|out_of_memory/i.test(run.stdout+'\n'+run.stderr)) {
309
- outcome='out-of-memory';reason='Z3 reported memory exhaustion';
310
- } else if(run.error||run.exitCode!==0||!outcome||run.stdout.includes('(error ')) {
311
- outcome='failed';reason=run.error??'Z3 did not complete the task protocol successfully';
312
- } else if(outcome==='unsat')reason='Z3 established this law, including required definedness; trusts the typed translation and selected solver, without a kernel-checked certificate';
313
- else if(outcome==='sat')reason='Z3 returned a satisfying model for the negated proof task; it has not been validated as a LawSpec counterexample';
314
- else {
315
- reason='Z3 could not decide this task: '+run.stdout.slice(run.stdout.indexOf('\n')+1).trim();
316
- if(/:reason-unknown\s+"timeout"/.test(run.stdout))outcome='timeout';
317
- else if(/:reason-unknown\s+"max\. resource limit exceeded"/.test(run.stdout))outcome='resource-limit';
809
+ const run = await execute(
810
+ selected.binary,
811
+ selected.args,
812
+ input,
813
+ config,
814
+ true,
815
+ names?.length
816
+ ? token =>
817
+ token === 'sat'
818
+ ? `(get-value (${names.join(' ')}))\n(exit)\n`
819
+ : followUp(token)
820
+ : followUp,
821
+ );
822
+ let unchanged = false;
823
+ try
824
+ {
825
+ unchanged =
826
+ hash(await readFile(selected.binary)) === selected.binaryFingerprint;
827
+ }
828
+ catch
829
+ {}
830
+ const metadata = {
831
+ ...common,
832
+ prover: {
833
+ name: 'z3',
834
+ version: selected.version,
835
+ binary: selected.binary,
836
+ binaryFingerprint: selected.binaryFingerprint,
837
+ fingerprint: selected.fingerprint,
838
+ arguments: selected.args,
839
+ },
840
+ configuration: config,
841
+ runFingerprint: fingerprint([
842
+ taskFingerprint,
843
+ selected.fingerprint,
844
+ run.input,
845
+ ]),
846
+ elapsedMs: run.elapsedMs,
847
+ exitCode: run.exitCode,
848
+ signal: run.signal,
849
+ stdout: run.stdout,
850
+ stderr: run.stderr,
851
+ };
852
+ let outcome = run.outcome,
853
+ reason;
854
+ if (!unchanged)
855
+ {
856
+ outcome = 'failed';
857
+ reason = 'Z3 executable changed during execution';
858
+ }
859
+ else if (run.timeout)
860
+ {
861
+ outcome = 'timeout';
862
+ reason = 'Z3 exceeded the host wall-clock limit';
863
+ }
864
+ else if (run.outputLimit)
865
+ {
866
+ outcome = 'failed';
867
+ reason = 'Z3 exceeded the output limit';
868
+ }
869
+ else if (
870
+ run.exitCode !== 0 &&
871
+ /out of memory|out_of_memory/i.test(run.stdout + '\n' + run.stderr)
872
+ )
873
+ {
874
+ outcome = 'out-of-memory';
875
+ reason = 'Z3 reported memory exhaustion';
876
+ }
877
+ else if (
878
+ run.error ||
879
+ run.exitCode !== 0 ||
880
+ !outcome ||
881
+ run.stdout.includes('(error ')
882
+ )
883
+ {
884
+ outcome = 'failed';
885
+ reason = run.error ?? 'Z3 did not complete the task protocol successfully';
886
+ }
887
+ else if (outcome === 'unsat')
888
+ reason =
889
+ 'Z3 established this law, including required definedness; trusts the typed translation and selected solver, without a kernel-checked certificate';
890
+ else if (outcome === 'sat')
891
+ reason =
892
+ 'Z3 returned a satisfying model for the negated proof task; it has not been validated as a LawSpec counterexample';
893
+ else
894
+ {
895
+ reason =
896
+ 'Z3 could not decide this task: ' +
897
+ run.stdout.slice(run.stdout.indexOf('\n') + 1).trim();
898
+ if (/:reason-unknown\s+"timeout"/.test(run.stdout)) outcome = 'timeout';
899
+ else if (
900
+ /:reason-unknown\s+"max\. resource limit exceeded"/.test(run.stdout)
901
+ )
902
+ outcome = 'resource-limit';
318
903
  }
319
- const model=run.outcome==='sat'?run.stdout.slice(run.stdout.indexOf('\n')+1).trim():null;
320
- return {...metadata,status:outcome==='unsat'?'proved':'incomplete',outcome,reason,
321
- ...(model!==null&&!names?.length?{model,modelValidated:false}:{}),...(model!==null&&names?.length?{values:model}:{})};
904
+ const model =
905
+ run.outcome === 'sat'
906
+ ? run.stdout.slice(run.stdout.indexOf('\n') + 1).trim()
907
+ : null;
908
+ return {
909
+ ...metadata,
910
+ status: outcome === 'unsat' ? 'proved' : 'incomplete',
911
+ outcome,
912
+ reason,
913
+ ...(model !== null && !names?.length ? {model, modelValidated: false} : {}),
914
+ ...(model !== null && names?.length ? {values: model} : {}),
915
+ };
322
916
  }
323
917
 
324
918
  // A satisfiable task's model is not a counterexample. Z3 runs the task's
325
919
  // counterexample query (lawspec-smtlib-v2) and gives the values of the law's
326
920
  // outer inputs; the compiler, not this host, reads them and re-checks the law
327
921
  // at them with its reference evaluator.
328
- async function counterexampleValues(task,selected,config) {
329
- const query=task.counterexample;
330
- if(!query||typeof query.script!=='string'||!Array.isArray(query.inputs))return null;
331
- if(fingerprint(['lawspec-smtlib-v2',task.lawFingerprint,String(task.machineBits),task.owner,task.declaration,
332
- query.script])!==query.fingerprint)return null;
333
- const names=query.inputs.map(input=>input.name);
922
+ async function counterexampleValues(task, selected, config)
923
+ {
924
+ const query = task.counterexample;
925
+ if (
926
+ !query ||
927
+ typeof query.script !== 'string' ||
928
+ !Array.isArray(query.inputs)
929
+ )
930
+ return null;
931
+ if (
932
+ fingerprint([
933
+ 'lawspec-smtlib-v2',
934
+ task.lawFingerprint,
935
+ String(task.machineBits),
936
+ task.owner,
937
+ task.declaration,
938
+ query.script,
939
+ ]) !== query.fingerprint
940
+ )
941
+ return null;
942
+ const names = query.inputs.map(input => input.name);
334
943
  // A law with no inputs needs no search: the evaluator decides it.
335
- if(!names.length)return {outcome:'sat',values:'()',fingerprint:query.fingerprint,runFingerprint:null};
336
- const input=`(set-option :print-success false)\n(set-option :produce-models true)\n`+
337
- `(set-option :random-seed ${config.seed})\n(set-option :rlimit ${config.resourceLimit})\n`+
338
- query.script+'(check-sat)\n';
339
- const run=await execute(selected.binary,selected.args,input,config,true,
340
- token=>token==='sat'&&names.length?`(get-value (${names.join(' ')}))\n(exit)\n`:'(exit)\n');
341
- if(run.outcome!=='sat'||run.timeout||run.outputLimit||run.error||run.exitCode!==0)
342
- return {outcome:run.outcome??'failed',stdout:run.stdout};
343
- return {outcome:'sat',values:names.length?run.stdout.slice(run.stdout.indexOf('\n')+1).trim():'()',
344
- fingerprint:query.fingerprint,runFingerprint:fingerprint([query.fingerprint,selected.fingerprint,run.input])};
944
+ if (!names.length)
945
+ return {
946
+ outcome: 'sat',
947
+ values: '()',
948
+ fingerprint: query.fingerprint,
949
+ runFingerprint: null,
950
+ };
951
+ const input =
952
+ `(set-option :print-success false)\n(set-option :produce-models true)\n` +
953
+ `(set-option :random-seed ${config.seed})\n(set-option :rlimit ${config.resourceLimit})\n` +
954
+ query.script +
955
+ '(check-sat)\n';
956
+ const run = await execute(
957
+ selected.binary,
958
+ selected.args,
959
+ input,
960
+ config,
961
+ true,
962
+ token =>
963
+ token === 'sat' && names.length
964
+ ? `(get-value (${names.join(' ')}))\n(exit)\n`
965
+ : '(exit)\n',
966
+ );
967
+ if (
968
+ run.outcome !== 'sat' ||
969
+ run.timeout ||
970
+ run.outputLimit ||
971
+ run.error ||
972
+ run.exitCode !== 0
973
+ )
974
+ return {outcome: run.outcome ?? 'failed', stdout: run.stdout};
975
+ return {
976
+ outcome: 'sat',
977
+ values: names.length
978
+ ? run.stdout.slice(run.stdout.indexOf('\n') + 1).trim()
979
+ : '()',
980
+ fingerprint: query.fingerprint,
981
+ runFingerprint: fingerprint([
982
+ query.fingerprint,
983
+ selected.fingerprint,
984
+ run.input,
985
+ ]),
986
+ };
345
987
  }
346
988
 
347
989
  // Tasks always come freshly from the compiler for the supplied source request.
348
990
  // An imported JSON solver report cannot upgrade a law's evidence through here.
349
- export async function proveWithZ3(compiler,request,options={}) {
350
- const config=optionsWithDefaults(options);
991
+ export async function proveWithZ3(compiler, request, options = {})
992
+ {
993
+ const config = optionsWithDefaults(options);
351
994
  // Settlement answers belong to this execution. A caller's imported
352
995
  // answers must never upgrade a law before the host invokes its solver.
353
- request={...request};
354
- for(const key of ['analysisResults','modelResults','proofCounterexamples'])delete request[key];
355
- const result=await compiler.proofTasks(request);
356
- if(result.diagnostics?.length)return {...result,solverEvidence:[]};
357
- const tasks=result.proofTasks??[];
358
- let selected={};
359
- const analysis=result.analysisTasks??[];
360
- const modelTasks=result.modelTasks??[];
361
- if(tasks.some(task=>task.status==='ready')||analysis.some(row=>row.status==='ready')||modelTasks.some(law=>law.tasks.length)) {
362
- try {selected=await prover(config);}
363
- catch(error){selected={error:error.message,outcome:error.code==='ENOENT'?'unavailable':error.outcome??'failed'};}
996
+ request = {...request};
997
+ for (const key of ['analysisResults', 'modelResults', 'proofCounterexamples'])
998
+ delete request[key];
999
+ const result = await compiler.proofTasks(request);
1000
+ if (result.diagnostics?.length) return {...result, solverEvidence: []};
1001
+ const tasks = result.proofTasks ?? [];
1002
+ let selected = {};
1003
+ const analysis = result.analysisTasks ?? [];
1004
+ const modelTasks = result.modelTasks ?? [];
1005
+ if (
1006
+ tasks.some(task => task.status === 'ready') ||
1007
+ analysis.some(row => row.status === 'ready') ||
1008
+ modelTasks.some(law => law.tasks.length)
1009
+ )
1010
+ {
1011
+ try
1012
+ {
1013
+ selected = await prover(config);
1014
+ }
1015
+ catch (error)
1016
+ {
1017
+ selected = {
1018
+ error: error.message,
1019
+ outcome:
1020
+ error.code === 'ENOENT' ? 'unavailable' : (error.outcome ?? 'failed'),
1021
+ };
1022
+ }
364
1023
  }
365
- const solverEvidence=[];
366
- const cache=await receiptCache(request,selected);
367
- for(const task of tasks)solverEvidence.push(await cachedSolve(task,selected,config,cache));
368
- const diagnostics=[...(result.diagnostics??[])];
1024
+ const solverEvidence = [];
1025
+ const cache = await receiptCache(request, selected);
1026
+ for (const task of tasks)
1027
+ solverEvidence.push(await cachedSolve(task, selected, config, cache));
1028
+ const diagnostics = [...(result.diagnostics ?? [])];
369
1029
  // Values to check as each unproved law's counterexample: the
370
1030
  // counterexample query's (run whenever a law's task was satisfiable, and
371
1031
  // for every unproved law over recursive definitions, since Z3 unfolds
372
1032
  // freely there), then each induction case's model.
373
- const searched=[];
374
- for(const [index,item] of solverEvidence.entries()) {
375
- const task=tasks[index];
376
- if(['proved','unsupported'].includes(item.status)||selected.error)continue;
377
- if(item.outcome==='sat'||task.recursion) {
378
- const found=await counterexampleValues(task,selected,config);
379
- if(found?.outcome==='sat')searched.push({index,found});
380
- else if(found&&item.outcome==='sat')solverEvidence[index]={...solverEvidence[index],reason:item.reason+'; the counterexample query gave no values ('+found.outcome+')'};
1033
+ const searched = [];
1034
+ for (const [index, item] of solverEvidence.entries())
1035
+ {
1036
+ const task = tasks[index];
1037
+ if (['proved', 'unsupported'].includes(item.status) || selected.error)
1038
+ continue;
1039
+ if (item.outcome === 'sat' || task.recursion)
1040
+ {
1041
+ const found = await counterexampleValues(task, selected, config);
1042
+ if (found?.outcome === 'sat') searched.push({index, found});
1043
+ else if (found && item.outcome === 'sat')
1044
+ solverEvidence[index] = {
1045
+ ...solverEvidence[index],
1046
+ reason:
1047
+ item.reason +
1048
+ '; the counterexample query gave no values (' +
1049
+ found.outcome +
1050
+ ')',
1051
+ };
381
1052
  }
382
- for(const c of item.induction?.cases??[])
383
- if(c.outcome==='sat'&&c.values)searched.push({index,found:{outcome:'sat',values:c.values,fingerprint:c.taskFingerprint,runFingerprint:c.runFingerprint},inductionCase:c.case});
1053
+ for (const c of item.induction?.cases ?? [])
1054
+ if (c.outcome === 'sat' && c.values)
1055
+ searched.push({
1056
+ index,
1057
+ found: {
1058
+ outcome: 'sat',
1059
+ values: c.values,
1060
+ fingerprint: c.taskFingerprint,
1061
+ runFingerprint: c.runFingerprint,
1062
+ },
1063
+ inductionCase: c.case,
1064
+ });
384
1065
  }
385
- if(searched.length) {
386
- const checked=await compiler.proofTasks({...request,proofCounterexamples:searched.map(({index,found})=>({
387
- owner:solverEvidence[index].owner,declaration:solverEvidence[index].declaration,
388
- taskFingerprint:tasks[index].taskFingerprint,values:found.values}))});
389
- const checks=checked.counterexampleChecks??[];
390
- searched.forEach(({index,found,inductionCase},position)=>{
391
- const item=solverEvidence[index],check=checks[position];
392
- if(!check||check.owner!==item.owner||check.declaration!==item.declaration||item.status==='refuted')return;
393
- const counterexample={inputs:check.inputs??[],values:found.values,fingerprint:found.fingerprint,
394
- runFingerprint:found.runFingerprint,check:check.status};
395
- if(check.status==='refuted') {
396
- const shown=(check.inputs??[]).map(input=>input.name+' = '+input.value).join(', ');
397
- solverEvidence[index]={...item,status:'refuted',modelValidated:true,counterexample,
398
- reason:(found.runFingerprint?'Z3 found ':'the law has no inputs; ')+(shown?'the input '+shown:'that the law fails')+
399
- (inductionCase?' in case '+inductionCase+' of the induction':'')+'; the reference evaluator confirms it: '+check.reason};
400
- } else if(inductionCase&&check.status==='model-not-confirmed') {
1066
+ if (searched.length)
1067
+ {
1068
+ const checked = await compiler.proofTasks({
1069
+ ...request,
1070
+ proofCounterexamples: searched.map(({index, found}) => ({
1071
+ owner: solverEvidence[index].owner,
1072
+ declaration: solverEvidence[index].declaration,
1073
+ taskFingerprint: tasks[index].taskFingerprint,
1074
+ values: found.values,
1075
+ })),
1076
+ });
1077
+ const checks = checked.counterexampleChecks ?? [];
1078
+ searched.forEach(({index, found, inductionCase}, position) =>
1079
+ {
1080
+ const item = solverEvidence[index],
1081
+ check = checks[position];
1082
+ if (
1083
+ !check ||
1084
+ check.owner !== item.owner ||
1085
+ check.declaration !== item.declaration ||
1086
+ item.status === 'refuted'
1087
+ )
1088
+ return;
1089
+ const counterexample = {
1090
+ inputs: check.inputs ?? [],
1091
+ values: found.values,
1092
+ fingerprint: found.fingerprint,
1093
+ runFingerprint: found.runFingerprint,
1094
+ check: check.status,
1095
+ };
1096
+ if (check.status === 'refuted')
1097
+ {
1098
+ const shown = (check.inputs ?? [])
1099
+ .map(input => input.name + ' = ' + input.value)
1100
+ .join(', ');
1101
+ solverEvidence[index] = {
1102
+ ...item,
1103
+ status: 'refuted',
1104
+ modelValidated: true,
1105
+ counterexample,
1106
+ reason:
1107
+ (found.runFingerprint ? 'Z3 found ' : 'the law has no inputs; ') +
1108
+ (shown ? 'the input ' + shown : 'that the law fails') +
1109
+ (inductionCase
1110
+ ? ' in case ' + inductionCase + ' of the induction'
1111
+ : '') +
1112
+ '; the reference evaluator confirms it: ' +
1113
+ check.reason,
1114
+ };
1115
+ }
1116
+ else if (inductionCase && check.status === 'model-not-confirmed')
1117
+ {
401
1118
  // Why3's SW: the case fails only under its hypothesis, not the law.
402
- solverEvidence[index]={...item,counterexample,
403
- reason:item.reason+'; in case '+inductionCase+' the induction hypothesis is too weak: the law holds at Z3\'s input, '+check.reason};
404
- } else if(check.status==='model-not-confirmed'&&(item.recursion||tasks[index].recursion)) {
1119
+ solverEvidence[index] = {
1120
+ ...item,
1121
+ counterexample,
1122
+ reason:
1123
+ item.reason +
1124
+ '; in case ' +
1125
+ inductionCase +
1126
+ " the induction hypothesis is too weak: the law holds at Z3's input, " +
1127
+ check.reason,
1128
+ };
1129
+ }
1130
+ else if (
1131
+ check.status === 'model-not-confirmed' &&
1132
+ (item.recursion || tasks[index].recursion)
1133
+ )
1134
+ {
405
1135
  // Unfolding may stop early, so such a model need not be one of the
406
1136
  // real definitions: incomplete, not a translation error.
407
- solverEvidence[index]={...item,counterexample,reason:item.reason+'; Z3 gave a model the reference evaluator does not confirm, after unfolding that may have stopped early: '+check.reason};
408
- } else if(check.status==='model-not-confirmed') {
409
- solverEvidence[index]={...item,counterexample,reason:'Z3 gave a model the reference evaluator does not confirm: '+check.reason};
410
- diagnostics.push({code:'proof-translation',message:`Z3's model for ${item.declaration} is not a counterexample: ${check.reason}`,at:item.at});
411
- } else if(item.outcome==='sat')solverEvidence[index]={...item,counterexample,reason:item.reason+'; '+check.reason};
1137
+ solverEvidence[index] = {
1138
+ ...item,
1139
+ counterexample,
1140
+ reason:
1141
+ item.reason +
1142
+ '; Z3 gave a model the reference evaluator does not confirm, after unfolding that may have stopped early: ' +
1143
+ check.reason,
1144
+ };
1145
+ }
1146
+ else if (check.status === 'model-not-confirmed')
1147
+ {
1148
+ solverEvidence[index] = {
1149
+ ...item,
1150
+ counterexample,
1151
+ reason:
1152
+ 'Z3 gave a model the reference evaluator does not confirm: ' +
1153
+ check.reason,
1154
+ };
1155
+ diagnostics.push({
1156
+ code: 'proof-translation',
1157
+ message: `Z3's model for ${item.declaration} is not a counterexample: ${check.reason}`,
1158
+ at: item.at,
1159
+ });
1160
+ }
1161
+ else if (item.outcome === 'sat')
1162
+ solverEvidence[index] = {
1163
+ ...item,
1164
+ counterexample,
1165
+ reason: item.reason + '; ' + check.reason,
1166
+ };
412
1167
  });
413
1168
  }
414
1169
  // A law proved by induction rests on the laws it cites: while one of them
415
1170
  // is not proved (or checked on every input), neither is the law.
416
- const current=new Map();
417
- for(const row of result.evidence??[])if(row.stage==='law')current.set(row.declaration,row.status);
418
- for(const item of solverEvidence)if(item.declaration&&!item.kind)current.set(item.declaration,item.status==='proved'?'proved':
419
- ['proved','exhaustively-checked'].includes(current.get(item.declaration))?current.get(item.declaration):item.status);
420
- let changed=true;
421
- while(changed) {
422
- changed=false;
423
- solverEvidence.forEach((item,index)=>{
424
- const cited=(item.currentInduction??item.induction)?.using??[];
425
- if(item.status!=='proved'||!cited.length)return;
426
- const open=cited.filter(law=>!['proved','exhaustively-checked'].includes(current.get(law)));
427
- if(!open.length)return;
428
- solverEvidence[index]={...item,status:'incomplete',reason:item.reason+'; it cites '+
429
- open.map(law=>law.split('::law::').pop()+', which is '+(current.get(law)??'not proved')).join(', ')};
430
- current.set(item.declaration,'incomplete');changed=true;
1171
+ const current = new Map();
1172
+ for (const row of result.evidence ?? [])
1173
+ if (row.stage === 'law') current.set(row.declaration, row.status);
1174
+ for (const item of solverEvidence)
1175
+ if (item.declaration && !item.kind)
1176
+ current.set(
1177
+ item.declaration,
1178
+ item.status === 'proved'
1179
+ ? 'proved'
1180
+ : ['proved', 'exhaustively-checked'].includes(
1181
+ current.get(item.declaration),
1182
+ )
1183
+ ? current.get(item.declaration)
1184
+ : item.status,
1185
+ );
1186
+ let changed = true;
1187
+ while (changed)
1188
+ {
1189
+ changed = false;
1190
+ solverEvidence.forEach((item, index) =>
1191
+ {
1192
+ const cited = (item.currentInduction ?? item.induction)?.using ?? [];
1193
+ if (item.status !== 'proved' || !cited.length) return;
1194
+ const open = cited.filter(
1195
+ law => !['proved', 'exhaustively-checked'].includes(current.get(law)),
1196
+ );
1197
+ if (!open.length) return;
1198
+ solverEvidence[index] = {
1199
+ ...item,
1200
+ status: 'incomplete',
1201
+ reason:
1202
+ item.reason +
1203
+ '; it cites ' +
1204
+ open
1205
+ .map(
1206
+ law =>
1207
+ law.split('::law::').pop() +
1208
+ ', which is ' +
1209
+ (current.get(law) ?? 'not proved'),
1210
+ )
1211
+ .join(', '),
1212
+ };
1213
+ current.set(item.declaration, 'incomplete');
1214
+ changed = true;
431
1215
  });
432
1216
  }
433
- const evidence=(result.evidence??[]).map(row=>{
434
- const found=solverEvidence.find(item=>item.owner===row.owner&&item.declaration===row.declaration);
435
- if(row.stage!=='law'||!found)return row;
436
- if(found.status!=='proved') {
437
- if(['proved','exhaustively-checked','known-discrepancy','skipped','flaky'].includes(row.status))return row;
438
- return {...row,status:found.status==='unsupported'?'unsupported':found.status==='refuted'?'refuted':'incomplete',reason:found.reason};
1217
+ const evidence = (result.evidence ?? []).map(row =>
1218
+ {
1219
+ const found = solverEvidence.find(
1220
+ item => item.owner === row.owner && item.declaration === row.declaration,
1221
+ );
1222
+ if (row.stage !== 'law' || !found) return row;
1223
+ if (found.status !== 'proved')
1224
+ {
1225
+ if (
1226
+ [
1227
+ 'proved',
1228
+ 'exhaustively-checked',
1229
+ 'known-discrepancy',
1230
+ 'skipped',
1231
+ 'flaky',
1232
+ ].includes(row.status)
1233
+ )
1234
+ return row;
1235
+ return {
1236
+ ...row,
1237
+ status:
1238
+ found.status === 'unsupported'
1239
+ ? 'unsupported'
1240
+ : found.status === 'refuted'
1241
+ ? 'refuted'
1242
+ : 'incomplete',
1243
+ reason: found.reason,
1244
+ };
439
1245
  }
440
- if(row.status==='known-discrepancy') {
441
- diagnostics.push({code:'harness',message:`Z3 proved ${row.declaration}; its harness cannot mark it as a known discrepancy`,at:found.at});
1246
+ if (row.status === 'known-discrepancy')
1247
+ {
1248
+ diagnostics.push({
1249
+ code: 'harness',
1250
+ message: `Z3 proved ${row.declaration}; its harness cannot mark it as a known discrepancy`,
1251
+ at: found.at,
1252
+ });
442
1253
  return row;
443
1254
  }
444
- return {...row,status:'proved',reason:found.reason+`; task ${found.taskFingerprint}`};
1255
+ return {
1256
+ ...row,
1257
+ status: 'proved',
1258
+ reason: found.reason + `; task ${found.taskFingerprint}`,
1259
+ };
445
1260
  });
446
1261
  // The law-set checks the compiler left undecided (completeness, overlap,
447
1262
  // conflict, vacuity): Z3 runs each task, and the compiler confirms every
448
1263
  // model with its reference evaluator before a check is refuted.
449
- let settled=evidence,found=diagnostics;
450
- if(analysis.length) {
451
- let answers=[];
452
- const ran=new Map();
453
- for(const row of analysis) {
454
- if(row.status!=='ready') {
455
- solverEvidence.push({owner:row.owner,declaration:row.declaration,stage:row.stage,kind:'analysis',
456
- encoding:'lawspec-smtlib-v2',status:'unsupported',outcome:'unsupported',reason:row.reason,configuration:config});
1264
+ let settled = evidence,
1265
+ found = diagnostics;
1266
+ if (analysis.length)
1267
+ {
1268
+ let answers = [];
1269
+ const ran = new Map();
1270
+ for (const row of analysis)
1271
+ {
1272
+ if (row.status !== 'ready')
1273
+ {
1274
+ solverEvidence.push({
1275
+ owner: row.owner,
1276
+ declaration: row.declaration,
1277
+ stage: row.stage,
1278
+ kind: 'analysis',
1279
+ encoding: 'lawspec-smtlib-v2',
1280
+ status: 'unsupported',
1281
+ outcome: 'unsupported',
1282
+ reason: row.reason,
1283
+ configuration: config,
1284
+ });
457
1285
  continue;
458
1286
  }
459
- for(const task of row.tasks) {
460
- if(selected.error) {ran.set(task.fingerprint,{row,outcome:selected.outcome,error:selected.error});continue;}
461
- const executeQuery=async()=>{
462
- const input=`(set-option :print-success false)\n(set-option :produce-models true)\n`+
463
- `(set-option :random-seed ${config.seed})\n(set-option :rlimit ${config.resourceLimit})\n`+task.script+'(check-sat)\n';
464
- const run=await execute(selected.binary,selected.args,input,config,true,
465
- token=>token==='sat'&&task.inputs.length?`(get-value (${task.inputs.join(' ')}))\n(exit)\n`:'(exit)\n');
466
- const outcome=await verifiedOutcome(run,selected);
467
- const values=outcome==='sat'&&task.inputs.length?run.stdout.slice(run.stdout.indexOf('\n')+1).trim():'';
468
- return {outcome,run,values,runFingerprint:fingerprint([task.fingerprint,selected.fingerprint,run.input])};
1287
+ for (const task of row.tasks)
1288
+ {
1289
+ if (selected.error)
1290
+ {
1291
+ ran.set(task.fingerprint, {
1292
+ row,
1293
+ outcome: selected.outcome,
1294
+ error: selected.error,
1295
+ });
1296
+ continue;
1297
+ }
1298
+ const executeQuery = async () =>
1299
+ {
1300
+ const input =
1301
+ `(set-option :print-success false)\n(set-option :produce-models true)\n` +
1302
+ `(set-option :random-seed ${config.seed})\n(set-option :rlimit ${config.resourceLimit})\n` +
1303
+ task.script +
1304
+ '(check-sat)\n';
1305
+ const run = await execute(
1306
+ selected.binary,
1307
+ selected.args,
1308
+ input,
1309
+ config,
1310
+ true,
1311
+ token =>
1312
+ token === 'sat' && task.inputs.length
1313
+ ? `(get-value (${task.inputs.join(' ')}))\n(exit)\n`
1314
+ : '(exit)\n',
1315
+ );
1316
+ const outcome = await verifiedOutcome(run, selected);
1317
+ const values =
1318
+ outcome === 'sat' && task.inputs.length
1319
+ ? run.stdout.slice(run.stdout.indexOf('\n') + 1).trim()
1320
+ : '';
1321
+ return {
1322
+ outcome,
1323
+ run,
1324
+ values,
1325
+ runFingerprint: fingerprint([
1326
+ task.fingerprint,
1327
+ selected.fingerprint,
1328
+ run.input,
1329
+ ]),
1330
+ };
469
1331
  };
470
- const done=await analysisQuery(cache,row,task,selected,executeQuery);
471
- ran.set(task.fingerprint,done);
472
- answers.push({fingerprint:task.fingerprint,outcome:done.outcome,values:done.values,inputs:done.inputs});
1332
+ const done = await analysisQuery(
1333
+ cache,
1334
+ row,
1335
+ task,
1336
+ selected,
1337
+ executeQuery,
1338
+ );
1339
+ ran.set(task.fingerprint, done);
1340
+ answers.push({
1341
+ fingerprint: task.fingerprint,
1342
+ outcome: done.outcome,
1343
+ values: done.values,
1344
+ inputs: done.inputs,
1345
+ });
473
1346
  }
474
1347
  }
475
- let checked=answers.length?await compiler.proofTasks({...request,analysisResults:answers}):{};
1348
+ let checked = answers.length
1349
+ ? await compiler.proofTasks({...request, analysisResults: answers})
1350
+ : {};
476
1351
  // A stored SAT model can stop decoding after a public constructor rename.
477
1352
  // Revalidation fails closed; retry that query once with the current names.
478
- let retried=false;
479
- for(const verdict of checked.analysisChecks??[]) {
480
- const done=ran.get(verdict.fingerprint);
481
- if(verdict.status==='incomplete'&&done?.reused&&done.rerun) {
482
- await rm(done.cacheFile,{force:true}).catch(()=>{});
483
- ran.set(verdict.fingerprint,await done.rerun());retried=true;
1353
+ let retried = false;
1354
+ for (const verdict of checked.analysisChecks ?? [])
1355
+ {
1356
+ const done = ran.get(verdict.fingerprint);
1357
+ if (verdict.status === 'incomplete' && done?.reused && done.rerun)
1358
+ {
1359
+ await rm(done.cacheFile, {force: true}).catch(() =>
1360
+ {});
1361
+ ran.set(verdict.fingerprint, await done.rerun());
1362
+ retried = true;
484
1363
  }
485
1364
  }
486
- if(retried) {
487
- answers=answers.map(answer=>{const done=ran.get(answer.fingerprint);return {...answer,
488
- outcome:done.outcome,values:done.values,inputs:done.inputs};});
489
- checked=await compiler.proofTasks({...request,analysisResults:answers});
1365
+ if (retried)
1366
+ {
1367
+ answers = answers.map(answer =>
1368
+ {
1369
+ const done = ran.get(answer.fingerprint);
1370
+ return {
1371
+ ...answer,
1372
+ outcome: done.outcome,
1373
+ values: done.values,
1374
+ inputs: done.inputs,
1375
+ };
1376
+ });
1377
+ checked = await compiler.proofTasks({
1378
+ ...request,
1379
+ analysisResults: answers,
1380
+ });
490
1381
  }
491
- const rows=new Map((checked.analysisEvidence??[]).map(row=>[row.declaration+'\u0000'+row.stage,row]));
492
- settled=evidence.map(row=>rows.get(row.declaration+'\u0000'+row.stage)??row);
493
- found=[...diagnostics,...(checked.diagnostics??[]).filter(row=>row.code==='refuted')];
494
- for(const verdict of checked.analysisChecks??[]) {
495
- const done=ran.get(verdict.fingerprint)??{};
496
- if(['proved','refuted','exempted'].includes(verdict.status))await saveQuery(done);
497
- solverEvidence.push({owner:verdict.owner,declaration:verdict.declaration,stage:verdict.stage,kind:'analysis',
498
- encoding:'lawspec-smtlib-v2',taskFingerprint:done.reused?.taskFingerprint??verdict.fingerprint,status:verdict.status,
499
- ...(done.reused?{currentTaskFingerprint:verdict.fingerprint,reused:done.reused}:{}),
500
- outcome:done.outcome??'failed',reason:verdict.reason+(done.reused?'; reused a completed query; model revalidated by the current evaluator':''),
501
- check:verdict.check,configuration:config,
502
- ...(done.run?{prover:{name:'z3',version:selected.version,binary:selected.binary,binaryFingerprint:selected.binaryFingerprint,
503
- fingerprint:selected.fingerprint,arguments:selected.args},runFingerprint:done.runFingerprint,
504
- elapsedMs:done.run.elapsedMs,exitCode:done.run.exitCode,stdout:done.run.stdout,stderr:done.run.stderr}:{})});
1382
+ const rows = new Map(
1383
+ (checked.analysisEvidence ?? []).map(row => [
1384
+ row.declaration + '\u0000' + row.stage,
1385
+ row,
1386
+ ]),
1387
+ );
1388
+ settled = evidence.map(
1389
+ row => rows.get(row.declaration + '\u0000' + row.stage) ?? row,
1390
+ );
1391
+ found = [
1392
+ ...diagnostics,
1393
+ ...(checked.diagnostics ?? []).filter(row => row.code === 'refuted'),
1394
+ ];
1395
+ for (const verdict of checked.analysisChecks ?? [])
1396
+ {
1397
+ const done = ran.get(verdict.fingerprint) ?? {};
1398
+ if (['proved', 'refuted', 'exempted'].includes(verdict.status))
1399
+ await saveQuery(done);
1400
+ solverEvidence.push({
1401
+ owner: verdict.owner,
1402
+ declaration: verdict.declaration,
1403
+ stage: verdict.stage,
1404
+ kind: 'analysis',
1405
+ encoding: 'lawspec-smtlib-v2',
1406
+ taskFingerprint: done.reused?.taskFingerprint ?? verdict.fingerprint,
1407
+ status: verdict.status,
1408
+ ...(done.reused
1409
+ ? {currentTaskFingerprint: verdict.fingerprint, reused: done.reused}
1410
+ : {}),
1411
+ outcome: done.outcome ?? 'failed',
1412
+ reason:
1413
+ verdict.reason +
1414
+ (done.reused
1415
+ ? '; reused a completed query; model revalidated by the current evaluator'
1416
+ : ''),
1417
+ check: verdict.check,
1418
+ configuration: config,
1419
+ ...(done.run
1420
+ ? {
1421
+ prover: {
1422
+ name: 'z3',
1423
+ version: selected.version,
1424
+ binary: selected.binary,
1425
+ binaryFingerprint: selected.binaryFingerprint,
1426
+ fingerprint: selected.fingerprint,
1427
+ arguments: selected.args,
1428
+ },
1429
+ runFingerprint: done.runFingerprint,
1430
+ elapsedMs: done.run.elapsedMs,
1431
+ exitCode: done.run.exitCode,
1432
+ stdout: done.run.stdout,
1433
+ stderr: done.run.stderr,
1434
+ }
1435
+ : {}),
1436
+ });
505
1437
  }
506
- for(const [fingerprintOf,done] of ran)if(done.error&&!(checked.analysisChecks??[]).some(v=>v.fingerprint===fingerprintOf))
507
- solverEvidence.push({kind:'analysis',owner:done.row.owner,declaration:done.row.declaration,stage:done.row.stage,
508
- taskFingerprint:fingerprintOf,encoding:'lawspec-smtlib-v2',status:'incomplete',
509
- outcome:done.outcome,reason:done.error,configuration:config});
1438
+ for (const [fingerprintOf, done] of ran)
1439
+ if (
1440
+ done.error &&
1441
+ !(checked.analysisChecks ?? []).some(
1442
+ v => v.fingerprint === fingerprintOf,
1443
+ )
1444
+ )
1445
+ solverEvidence.push({
1446
+ kind: 'analysis',
1447
+ owner: done.row.owner,
1448
+ declaration: done.row.declaration,
1449
+ stage: done.row.stage,
1450
+ taskFingerprint: fingerprintOf,
1451
+ encoding: 'lawspec-smtlib-v2',
1452
+ status: 'incomplete',
1453
+ outcome: done.outcome,
1454
+ reason: done.error,
1455
+ configuration: config,
1456
+ });
510
1457
  }
511
1458
  // Model laws the compiler's own search left open: induction, Spacer (its
512
1459
  // invariant goes back to the compiler, which asks for plain re-checks),
513
1460
  // and a bounded run search the compiler replays. Rounds repeat while the
514
1461
  // compiler asks for new tasks.
515
- if(modelTasks.length&&selected.error) {
516
- for(const law of modelTasks)for(const task of law.tasks)
517
- solverEvidence.push({kind:'model',owner:law.owner,declaration:law.declaration,task:task.kind,
518
- taskFingerprint:task.fingerprint,encoding:'lawspec-smtlib-v2',status:'incomplete',
519
- outcome:selected.outcome,reason:selected.error,configuration:config});
1462
+ if (modelTasks.length && selected.error)
1463
+ {
1464
+ for (const law of modelTasks)
1465
+ for (const task of law.tasks)
1466
+ solverEvidence.push({
1467
+ kind: 'model',
1468
+ owner: law.owner,
1469
+ declaration: law.declaration,
1470
+ task: task.kind,
1471
+ taskFingerprint: task.fingerprint,
1472
+ encoding: 'lawspec-smtlib-v2',
1473
+ status: 'incomplete',
1474
+ outcome: selected.outcome,
1475
+ reason: selected.error,
1476
+ configuration: config,
1477
+ });
520
1478
  }
521
- if(modelTasks.length&&!selected.error) {
522
- const answered=new Map(),modelAnswers=[],modelRows=new Map(),runs=new Map();
523
- let pending=modelTasks;
524
- for(let round=0;round<4;round++) {
525
- let fresh=0;
526
- for(const law of pending) for(const task of law.tasks) {
527
- if(answered.has(task.fingerprint))continue;
528
- fresh++;
529
- const executeQuery=async()=>{
530
- const input=`(set-option :print-success false)\n(set-option :produce-models true)\n`+
531
- `(set-option :random-seed ${config.seed})\n(set-option :rlimit ${config.resourceLimit})\n`+task.script+'(check-sat)\n';
532
- const run=await execute(selected.binary,selected.args,input,config,true,token=>token!=='sat'?'(exit)\n':
533
- task.kind==='spacer'?'(get-model)\n(exit)\n':task.inputs.length?`(get-value (${task.inputs.join(' ')}))\n(exit)\n`:'(exit)\n');
534
- const outcome=await verifiedOutcome(run,selected);
535
- const body=outcome==='sat'?run.stdout.slice(run.stdout.indexOf('\n')+1):'';
536
- let invariant='';
537
- if(task.kind==='spacer'&&outcome==='sat') {
538
- const at=body.indexOf('(define-fun Inv ');
539
- if(at>=0) {let depth=0;for(let i=at;i<body.length;i++){if(body[i]==='(')depth++;if(body[i]===')'){depth--;if(depth===0){invariant=body.slice(at,i+1);break;}}}}
540
- }
1479
+ if (modelTasks.length && !selected.error)
1480
+ {
1481
+ const answered = new Map(),
1482
+ modelAnswers = [],
1483
+ modelRows = new Map(),
1484
+ runs = new Map();
1485
+ let pending = modelTasks;
1486
+ for (let round = 0; round < 4; round++)
1487
+ {
1488
+ let fresh = 0;
1489
+ for (const law of pending)
1490
+ for (const task of law.tasks)
1491
+ {
1492
+ if (answered.has(task.fingerprint)) continue;
1493
+ fresh++;
1494
+ const executeQuery = async () =>
1495
+ {
1496
+ const input =
1497
+ `(set-option :print-success false)\n(set-option :produce-models true)\n` +
1498
+ `(set-option :random-seed ${config.seed})\n(set-option :rlimit ${config.resourceLimit})\n` +
1499
+ task.script +
1500
+ '(check-sat)\n';
1501
+ const run = await execute(
1502
+ selected.binary,
1503
+ selected.args,
1504
+ input,
1505
+ config,
1506
+ true,
1507
+ token =>
1508
+ token !== 'sat'
1509
+ ? '(exit)\n'
1510
+ : task.kind === 'spacer'
1511
+ ? '(get-model)\n(exit)\n'
1512
+ : task.inputs.length
1513
+ ? `(get-value (${task.inputs.join(' ')}))\n(exit)\n`
1514
+ : '(exit)\n',
1515
+ );
1516
+ const outcome = await verifiedOutcome(run, selected);
1517
+ const body =
1518
+ outcome === 'sat'
1519
+ ? run.stdout.slice(run.stdout.indexOf('\n') + 1)
1520
+ : '';
1521
+ let invariant = '';
1522
+ if (task.kind === 'spacer' && outcome === 'sat')
1523
+ {
1524
+ const at = body.indexOf('(define-fun Inv ');
1525
+ if (at >= 0)
1526
+ {
1527
+ let depth = 0;
1528
+ for (let i = at; i < body.length; i++)
1529
+ {
1530
+ if (body[i] === '(') depth++;
1531
+ if (body[i] === ')')
1532
+ {
1533
+ depth--;
1534
+ if (depth === 0)
1535
+ {
1536
+ invariant = body.slice(at, i + 1);
1537
+ break;
1538
+ }
1539
+ }
1540
+ }
1541
+ }
1542
+ }
541
1543
 
542
- return {run,outcome,values:task.kind==='spacer'?'':body.trim(),invariant,
543
- runFingerprint:fingerprint([task.fingerprint,selected.fingerprint,run.input])};
1544
+ return {
1545
+ run,
1546
+ outcome,
1547
+ values: task.kind === 'spacer' ? '' : body.trim(),
1548
+ invariant,
1549
+ runFingerprint: fingerprint([
1550
+ task.fingerprint,
1551
+ selected.fingerprint,
1552
+ run.input,
1553
+ ]),
1554
+ };
1555
+ };
1556
+ const row = {
1557
+ kind: 'model',
1558
+ owner: law.owner,
1559
+ declaration: law.declaration,
1560
+ stage: task.kind,
1561
+ };
1562
+ const done = await analysisQuery(
1563
+ cache,
1564
+ row,
1565
+ task,
1566
+ selected,
1567
+ executeQuery,
1568
+ );
1569
+ const answer = {
1570
+ fingerprint: task.fingerprint,
1571
+ outcome: done.outcome,
1572
+ values: done.values,
1573
+ invariant: done.invariant ?? '',
1574
+ inputs: done.inputs ?? task.inputs,
1575
+ };
1576
+ answered.set(task.fingerprint, answer);
1577
+ modelAnswers.push(answer);
1578
+ runs.set(task.fingerprint, {row, task, done});
1579
+ }
1580
+ if (!fresh) break;
1581
+ let checked = await compiler.proofTasks({
1582
+ ...request,
1583
+ modelResults: modelAnswers,
1584
+ });
1585
+ let retry = false;
1586
+ for (const check of checked.modelChecks ?? [])
1587
+ {
1588
+ const observation = runs.get(check.fingerprint);
1589
+ if (
1590
+ check.status !== 'model-not-confirmed' ||
1591
+ !observation?.done.reused ||
1592
+ !observation.done.rerun
1593
+ )
1594
+ continue;
1595
+ await rm(observation.done.cacheFile, {force: true}).catch(() =>
1596
+ {});
1597
+ observation.done = await observation.done.rerun();
1598
+ const {task, done} = observation;
1599
+ const answer = {
1600
+ fingerprint: task.fingerprint,
1601
+ outcome: done.outcome,
1602
+ values: done.values,
1603
+ invariant: done.invariant ?? '',
1604
+ inputs: done.inputs ?? task.inputs,
544
1605
  };
545
- const row={kind:'model',owner:law.owner,declaration:law.declaration,stage:task.kind};
546
- const done=await analysisQuery(cache,row,task,selected,executeQuery);
547
- const answer={fingerprint:task.fingerprint,outcome:done.outcome,values:done.values,invariant:done.invariant??'',inputs:done.inputs??task.inputs};
548
- answered.set(task.fingerprint,answer);modelAnswers.push(answer);
549
- runs.set(task.fingerprint,{row,task,done});
550
- }
551
- if(!fresh)break;
552
- let checked=await compiler.proofTasks({...request,modelResults:modelAnswers});
553
- let retry=false;
554
- for(const check of checked.modelChecks??[]){
555
- const observation=runs.get(check.fingerprint);
556
- if(check.status!=='model-not-confirmed'||!observation?.done.reused||!observation.done.rerun)continue;
557
- await rm(observation.done.cacheFile,{force:true}).catch(()=>{});
558
- observation.done=await observation.done.rerun();
559
- const {task,done}=observation;
560
- const answer={fingerprint:task.fingerprint,outcome:done.outcome,values:done.values,
561
- invariant:done.invariant??'',inputs:done.inputs??task.inputs};
562
- answered.set(task.fingerprint,answer);
563
- modelAnswers[modelAnswers.findIndex(value=>value.fingerprint===task.fingerprint)]=answer;
564
- retry=true;
1606
+ answered.set(task.fingerprint, answer);
1607
+ modelAnswers[
1608
+ modelAnswers.findIndex(
1609
+ value => value.fingerprint === task.fingerprint,
1610
+ )
1611
+ ] = answer;
1612
+ retry = true;
565
1613
  }
566
- if(retry)checked=await compiler.proofTasks({...request,modelResults:modelAnswers});
567
- for(const row of checked.modelEvidence??[])modelRows.set(row.declaration,row);
568
- for(const d of checked.diagnostics??[])if(d.code==='refuted'&&!found.some(e=>e.message===d.message))found=[...found,d];
569
- pending=checked.modelTasks??[];
1614
+ if (retry)
1615
+ checked = await compiler.proofTasks({
1616
+ ...request,
1617
+ modelResults: modelAnswers,
1618
+ });
1619
+ for (const row of checked.modelEvidence ?? [])
1620
+ modelRows.set(row.declaration, row);
1621
+ for (const d of checked.diagnostics ?? [])
1622
+ if (d.code === 'refuted' && !found.some(e => e.message === d.message))
1623
+ found = [...found, d];
1624
+ pending = checked.modelTasks ?? [];
570
1625
  }
571
- for(const {row,task,done} of runs.values()){
1626
+ for (const {row, task, done} of runs.values())
1627
+ {
572
1628
  // Current model settlement still checks every proof/replay obligation.
573
1629
  // A reused raw query never substitutes for that compiler decision.
574
- if(task.kind!=='bounded search'||done.outcome!=='sat'||modelRows.get(row.declaration)?.status==='refuted')
1630
+ if (
1631
+ task.kind !== 'bounded search' ||
1632
+ done.outcome !== 'sat' ||
1633
+ modelRows.get(row.declaration)?.status === 'refuted'
1634
+ )
575
1635
  await saveQuery(done);
576
- const run=done.run,outcome=done.outcome;
577
- solverEvidence.push({kind:'model',owner:row.owner,declaration:row.declaration,task:task.kind,
578
- taskFingerprint:done.reused?.taskFingerprint??task.fingerprint,
579
- ...(done.reused?{currentTaskFingerprint:task.fingerprint,reused:done.reused}:{}),
580
- encoding:'lawspec-smtlib-v2',status:outcome==='unsat'?'proved':'incomplete',outcome,reason:task.kind+': '+outcome+
581
- (done.reused?'; reused original solver query; current compiler rechecks the model evidence':''),
582
- prover:{name:'z3',version:selected.version,binary:selected.binary,binaryFingerprint:selected.binaryFingerprint,
583
- fingerprint:selected.fingerprint,arguments:selected.args},
584
- runFingerprint:done.runFingerprint,elapsedMs:run.elapsedMs,
585
- exitCode:run.exitCode,signal:run.signal,stdout:run.stdout,stderr:run.stderr,configuration:config});
1636
+ const run = done.run,
1637
+ outcome = done.outcome;
1638
+ solverEvidence.push({
1639
+ kind: 'model',
1640
+ owner: row.owner,
1641
+ declaration: row.declaration,
1642
+ task: task.kind,
1643
+ taskFingerprint: done.reused?.taskFingerprint ?? task.fingerprint,
1644
+ ...(done.reused
1645
+ ? {currentTaskFingerprint: task.fingerprint, reused: done.reused}
1646
+ : {}),
1647
+ encoding: 'lawspec-smtlib-v2',
1648
+ status: outcome === 'unsat' ? 'proved' : 'incomplete',
1649
+ outcome,
1650
+ reason:
1651
+ task.kind +
1652
+ ': ' +
1653
+ outcome +
1654
+ (done.reused
1655
+ ? '; reused original solver query; current compiler rechecks the model evidence'
1656
+ : ''),
1657
+ prover: {
1658
+ name: 'z3',
1659
+ version: selected.version,
1660
+ binary: selected.binary,
1661
+ binaryFingerprint: selected.binaryFingerprint,
1662
+ fingerprint: selected.fingerprint,
1663
+ arguments: selected.args,
1664
+ },
1665
+ runFingerprint: done.runFingerprint,
1666
+ elapsedMs: run.elapsedMs,
1667
+ exitCode: run.exitCode,
1668
+ signal: run.signal,
1669
+ stdout: run.stdout,
1670
+ stderr: run.stderr,
1671
+ configuration: config,
1672
+ });
586
1673
  }
587
- settled=settled.map(row=>row.stage==='law'&&modelRows.has(row.declaration)?{...row,...modelRows.get(row.declaration)}:row);
1674
+ settled = settled.map(row =>
1675
+ row.stage === 'law' && modelRows.has(row.declaration)
1676
+ ? {...row, ...modelRows.get(row.declaration)}
1677
+ : row,
1678
+ );
588
1679
  }
589
- return {...result,diagnostics:found,evidence:settled,solverEvidence};
1680
+ return {...result, diagnostics: found, evidence: settled, solverEvidence};
590
1681
  }