@tsplc/compiler 0.5.13 → 0.5.15

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 (263) hide show
  1. package/README.md +33 -8
  2. package/dist/cli.js +794 -621
  3. package/dist/cli.js.map +19 -16
  4. package/dist/clock.js +5 -2
  5. package/dist/clock.js.map +5 -4
  6. package/dist/codesys.js +4162 -4157
  7. package/dist/codesys.js.map +43 -29
  8. package/dist/index.js +7852 -6549
  9. package/dist/index.js.map +53 -50
  10. package/dist/ir.js +2482 -2277
  11. package/dist/ir.js.map +28 -25
  12. package/dist/retain.js +3 -1
  13. package/dist/retain.js.map +3 -3
  14. package/dist/signals.js +115 -0
  15. package/dist/signals.js.map +10 -0
  16. package/dist/telemetry.js +25 -20
  17. package/dist/telemetry.js.map +6 -6
  18. package/package.json +19 -39
  19. package/src/codesys/config.ts +3 -3
  20. package/src/codesys/debug.ts +92 -108
  21. package/src/codesys/emit.ts +100 -88
  22. package/src/codesys/endpoints.ts +111 -0
  23. package/src/codesys/engineering.ts +30 -54
  24. package/src/codesys/explain/expressions.ts +445 -0
  25. package/src/codesys/explain/flags.ts +134 -0
  26. package/src/codesys/explain/parameters.ts +53 -0
  27. package/src/codesys/explain/rows.ts +182 -0
  28. package/src/codesys/explain/tables.ts +79 -0
  29. package/src/codesys/explain/tasks.ts +68 -0
  30. package/src/codesys/explain/writes.ts +497 -0
  31. package/src/codesys/explain.ts +85 -1401
  32. package/src/codesys/expressions.ts +41 -33
  33. package/src/codesys/global-lists.ts +114 -94
  34. package/src/codesys/global-names.ts +12 -14
  35. package/src/codesys/http.ts +428 -388
  36. package/src/codesys/instrumentation.ts +142 -148
  37. package/src/codesys/io-paths.ts +31 -23
  38. package/src/codesys/loops.ts +101 -0
  39. package/src/codesys/manifest.ts +269 -269
  40. package/src/codesys/names.ts +10 -33
  41. package/src/codesys/numeric.ts +89 -42
  42. package/src/codesys/plan.ts +202 -190
  43. package/src/codesys/programs.ts +23 -16
  44. package/src/codesys/publication.ts +13 -86
  45. package/src/codesys/required.ts +8 -0
  46. package/src/codesys/routines.ts +103 -489
  47. package/src/codesys/scheduling.ts +96 -0
  48. package/src/codesys/service-channels.ts +23 -0
  49. package/src/codesys/sources.ts +34 -28
  50. package/src/codesys/st-files.ts +112 -105
  51. package/src/codesys/statements.ts +409 -0
  52. package/src/codesys/storage.ts +41 -23
  53. package/src/codesys/symbols.ts +130 -119
  54. package/src/codesys/task-access.ts +65 -221
  55. package/src/codesys/telemetry-settings.ts +19 -0
  56. package/src/codesys/telemetry.ts +185 -148
  57. package/src/codesys/types.ts +69 -109
  58. package/src/codesys/vendor.ts +13 -50
  59. package/src/frontend/analyzer.ts +66 -111
  60. package/src/frontend/async.ts +316 -128
  61. package/src/frontend/blocks.ts +178 -154
  62. package/src/frontend/configuration.ts +49 -153
  63. package/src/frontend/const-functions.ts +50 -40
  64. package/src/frontend/control-flow.ts +164 -129
  65. package/src/frontend/cooperative.ts +17 -9
  66. package/src/frontend/coroutines.ts +539 -441
  67. package/src/frontend/dialect-names.ts +104 -0
  68. package/src/frontend/elaborate/array-searches.ts +77 -69
  69. package/src/frontend/elaborate/assignments.ts +68 -77
  70. package/src/frontend/elaborate/calls.ts +878 -512
  71. package/src/frontend/elaborate/capture-protocol.ts +118 -21
  72. package/src/frontend/elaborate/capture.ts +196 -109
  73. package/src/frontend/elaborate/declarations.ts +124 -0
  74. package/src/frontend/elaborate/dialect.ts +119 -46
  75. package/src/frontend/elaborate/expressions.ts +763 -442
  76. package/src/frontend/elaborate/filtered-arrays.ts +127 -91
  77. package/src/frontend/elaborate/frame.ts +50 -2
  78. package/src/frontend/elaborate/generics.ts +20 -34
  79. package/src/frontend/elaborate/graph.ts +13 -87
  80. package/src/frontend/elaborate/imports.ts +0 -5
  81. package/src/frontend/elaborate/index.ts +416 -169
  82. package/src/frontend/elaborate/initializers.ts +64 -42
  83. package/src/frontend/elaborate/iterators.ts +228 -364
  84. package/src/frontend/elaborate/layouts.ts +477 -116
  85. package/src/frontend/elaborate/model.ts +113 -55
  86. package/src/frontend/elaborate/references.ts +116 -138
  87. package/src/frontend/elaborate/retention.ts +137 -59
  88. package/src/frontend/elaborate/specialize.ts +617 -308
  89. package/src/frontend/elaborate/statements.ts +436 -247
  90. package/src/frontend/elaborate/storage.ts +280 -213
  91. package/src/frontend/elaborate/time-constructors.ts +34 -0
  92. package/src/frontend/elaborate/values.ts +77 -7
  93. package/src/frontend/elaborate/writes.ts +98 -84
  94. package/src/frontend/expressions.ts +149 -151
  95. package/src/frontend/generated-names.ts +3 -3
  96. package/src/frontend/intrinsics.ts +31 -17
  97. package/src/frontend/lowering-key.ts +23 -0
  98. package/src/frontend/module-graph.ts +105 -43
  99. package/src/frontend/positions.ts +43 -35
  100. package/src/frontend/promise-chains.ts +226 -266
  101. package/src/frontend/promises.ts +88 -67
  102. package/src/frontend/routines.ts +122 -65
  103. package/src/frontend/sdk.ts +104 -5
  104. package/src/frontend/services.ts +149 -102
  105. package/src/frontend/statements.ts +60 -64
  106. package/src/frontend/tasks.ts +151 -96
  107. package/src/frontend/telemetry.ts +1 -1
  108. package/src/frontend/types.ts +366 -181
  109. package/src/frontend/typescript.ts +239 -112
  110. package/src/index.ts +2 -1
  111. package/src/ir/aggregates.ts +90 -75
  112. package/src/ir/allocation.ts +29 -18
  113. package/src/ir/conditions.ts +38 -78
  114. package/src/ir/core-model.ts +128 -11
  115. package/src/ir/declarations.ts +18 -32
  116. package/src/ir/diagnostics.ts +25 -18
  117. package/src/ir/domains.ts +26 -23
  118. package/src/ir/fold.ts +55 -50
  119. package/src/ir/identity.ts +10 -0
  120. package/src/ir/index.ts +31 -7
  121. package/src/ir/job-errors.ts +30 -8
  122. package/src/ir/layouts.ts +63 -34
  123. package/src/ir/link.ts +11 -46
  124. package/src/ir/model.ts +25 -6
  125. package/src/ir/normalize.ts +3 -28
  126. package/src/ir/numeric.ts +45 -18
  127. package/src/ir/operands.ts +102 -0
  128. package/src/ir/ranges.ts +242 -67
  129. package/src/ir/routine.ts +126 -183
  130. package/src/ir/scalars.ts +29 -25
  131. package/src/ir/share.ts +323 -343
  132. package/src/ir/short-circuit.ts +140 -0
  133. package/src/ir/tables.ts +111 -0
  134. package/src/ir/temporaries.ts +15 -113
  135. package/src/ir/types.ts +32 -8
  136. package/src/project/artifacts.ts +143 -71
  137. package/src/project/cli.ts +104 -87
  138. package/src/project/debugger.ts +48 -34
  139. package/src/project/deployments.ts +12 -68
  140. package/src/project/flags.ts +14 -0
  141. package/src/project/plant.ts +293 -225
  142. package/src/project/project-commands.ts +254 -192
  143. package/src/project/project.ts +184 -141
  144. package/src/project/release.ts +22 -28
  145. package/src/project/server.ts +22 -26
  146. package/src/project/terminal.ts +13 -2
  147. package/src/runtime/async.ts +17 -13
  148. package/src/runtime/launch.ts +5 -2
  149. package/src/runtime/main.ts +8 -3
  150. package/src/runtime/missing-file.ts +3 -0
  151. package/src/runtime/process.ts +24 -19
  152. package/src/runtime/program.ts +20 -53
  153. package/src/runtime/retain.ts +18 -10
  154. package/src/runtime/runtime.ts +47 -60
  155. package/src/runtime/settings.ts +27 -0
  156. package/src/runtime/storage.ts +49 -74
  157. package/src/runtime/symbols.ts +19 -75
  158. package/src/runtime/telemetry.ts +37 -14
  159. package/src/runtime/transport.ts +26 -30
  160. package/stdlib/clock.ts +4 -2
  161. package/stdlib/plc-time.ts +2 -0
  162. package/stdlib/retain.ts +2 -0
  163. package/stdlib/signals.ts +142 -0
  164. package/stdlib/telemetry.ts +5 -12
  165. package/types/dialect.d.ts +49 -0
  166. package/types/globals.d.ts +2 -42
  167. package/types/index.d.ts +3 -1
  168. package/types/retain.d.ts +8 -2
  169. package/types/telemetry.d.ts +3 -0
  170. package/dist/bun-runtime.js +0 -1472
  171. package/dist/bun-runtime.js.map +0 -26
  172. package/dist/elaborate-capture.js +0 -304
  173. package/dist/elaborate-capture.js.map +0 -11
  174. package/dist/math.js +0 -24
  175. package/dist/math.js.map +0 -10
  176. package/dist/project.js +0 -626
  177. package/dist/project.js.map +0 -12
  178. package/dist/server-check.js +0 -59
  179. package/dist/server-check.js.map +0 -11
  180. package/src/frontend/exposure.ts +0 -181
  181. package/src/project/index.ts +0 -6
  182. package/src/runtime/.runtime-65O4JH/server/router.ts +0 -17
  183. package/src/runtime/.runtime-65O4JH/src/cell.ts +0 -45
  184. package/src/runtime/.runtime-65O4JH/src/controller.ts +0 -58
  185. package/src/runtime/.runtime-65O4JH/src/lane.ts +0 -6
  186. package/src/runtime/.runtime-65O4JH/src/main.ts +0 -11
  187. package/src/runtime/.runtime-65O4JH/src/services.ts +0 -8
  188. package/src/runtime/.runtime-65O4JH/tsconfig.json +0 -13
  189. package/src/runtime/.runtime-65O4JH/tsplc.config.ts +0 -31
  190. package/src/runtime/.runtime-Brw2kO/server/router.ts +0 -17
  191. package/src/runtime/.runtime-Brw2kO/src/cell.ts +0 -45
  192. package/src/runtime/.runtime-Brw2kO/src/controller.ts +0 -58
  193. package/src/runtime/.runtime-Brw2kO/src/lane.ts +0 -6
  194. package/src/runtime/.runtime-Brw2kO/src/main.ts +0 -11
  195. package/src/runtime/.runtime-Brw2kO/src/services.ts +0 -8
  196. package/src/runtime/.runtime-Brw2kO/tsconfig.json +0 -13
  197. package/src/runtime/.runtime-Brw2kO/tsplc.config.ts +0 -31
  198. package/src/runtime/.runtime-NHfu1D/server/router.ts +0 -17
  199. package/src/runtime/.runtime-NHfu1D/src/cell.ts +0 -45
  200. package/src/runtime/.runtime-NHfu1D/src/controller.ts +0 -58
  201. package/src/runtime/.runtime-NHfu1D/src/lane.ts +0 -6
  202. package/src/runtime/.runtime-NHfu1D/src/main.ts +0 -11
  203. package/src/runtime/.runtime-NHfu1D/src/services.ts +0 -8
  204. package/src/runtime/.runtime-NHfu1D/tsconfig.json +0 -13
  205. package/src/runtime/.runtime-NHfu1D/tsplc.config.ts +0 -31
  206. package/src/runtime/.runtime-VaUSOu/server/router.ts +0 -17
  207. package/src/runtime/.runtime-VaUSOu/src/cell.ts +0 -45
  208. package/src/runtime/.runtime-VaUSOu/src/controller.ts +0 -58
  209. package/src/runtime/.runtime-VaUSOu/src/lane.ts +0 -6
  210. package/src/runtime/.runtime-VaUSOu/src/main.ts +0 -11
  211. package/src/runtime/.runtime-VaUSOu/src/services.ts +0 -8
  212. package/src/runtime/.runtime-VaUSOu/tsconfig.json +0 -13
  213. package/src/runtime/.runtime-VaUSOu/tsplc.config.ts +0 -31
  214. package/src/runtime/.runtime-WbtNvR/server/router.ts +0 -17
  215. package/src/runtime/.runtime-WbtNvR/src/cell.ts +0 -45
  216. package/src/runtime/.runtime-WbtNvR/src/controller.ts +0 -58
  217. package/src/runtime/.runtime-WbtNvR/src/lane.ts +0 -6
  218. package/src/runtime/.runtime-WbtNvR/src/main.ts +0 -11
  219. package/src/runtime/.runtime-WbtNvR/src/services.ts +0 -8
  220. package/src/runtime/.runtime-WbtNvR/tsconfig.json +0 -13
  221. package/src/runtime/.runtime-WbtNvR/tsplc.config.ts +0 -31
  222. package/src/runtime/.runtime-opcua-GMPUt8/server/router.ts +0 -17
  223. package/src/runtime/.runtime-opcua-GMPUt8/src/cell.ts +0 -45
  224. package/src/runtime/.runtime-opcua-GMPUt8/src/controller.ts +0 -58
  225. package/src/runtime/.runtime-opcua-GMPUt8/src/lane.ts +0 -6
  226. package/src/runtime/.runtime-opcua-GMPUt8/src/main.ts +0 -11
  227. package/src/runtime/.runtime-opcua-GMPUt8/src/services.ts +0 -8
  228. package/src/runtime/.runtime-opcua-GMPUt8/tsconfig.json +0 -13
  229. package/src/runtime/.runtime-opcua-GMPUt8/tsplc.config.ts +0 -31
  230. package/src/runtime/.runtime-opcua-UwafxO/server/router.ts +0 -17
  231. package/src/runtime/.runtime-opcua-UwafxO/src/cell.ts +0 -45
  232. package/src/runtime/.runtime-opcua-UwafxO/src/controller.ts +0 -58
  233. package/src/runtime/.runtime-opcua-UwafxO/src/lane.ts +0 -6
  234. package/src/runtime/.runtime-opcua-UwafxO/src/main.ts +0 -11
  235. package/src/runtime/.runtime-opcua-UwafxO/src/services.ts +0 -8
  236. package/src/runtime/.runtime-opcua-UwafxO/tsconfig.json +0 -13
  237. package/src/runtime/.runtime-opcua-UwafxO/tsplc.config.ts +0 -31
  238. package/src/runtime/.runtime-opcua-ecaSee/server/router.ts +0 -17
  239. package/src/runtime/.runtime-opcua-ecaSee/src/cell.ts +0 -45
  240. package/src/runtime/.runtime-opcua-ecaSee/src/controller.ts +0 -58
  241. package/src/runtime/.runtime-opcua-ecaSee/src/lane.ts +0 -6
  242. package/src/runtime/.runtime-opcua-ecaSee/src/main.ts +0 -11
  243. package/src/runtime/.runtime-opcua-ecaSee/src/services.ts +0 -8
  244. package/src/runtime/.runtime-opcua-ecaSee/tsconfig.json +0 -13
  245. package/src/runtime/.runtime-opcua-ecaSee/tsplc.config.ts +0 -31
  246. package/src/runtime/.runtime-opcua-y91UCm/server/router.ts +0 -17
  247. package/src/runtime/.runtime-opcua-y91UCm/src/cell.ts +0 -45
  248. package/src/runtime/.runtime-opcua-y91UCm/src/controller.ts +0 -58
  249. package/src/runtime/.runtime-opcua-y91UCm/src/lane.ts +0 -6
  250. package/src/runtime/.runtime-opcua-y91UCm/src/main.ts +0 -11
  251. package/src/runtime/.runtime-opcua-y91UCm/src/services.ts +0 -8
  252. package/src/runtime/.runtime-opcua-y91UCm/tsconfig.json +0 -13
  253. package/src/runtime/.runtime-opcua-y91UCm/tsplc.config.ts +0 -31
  254. package/src/runtime/.runtime-ybIxYh/server/router.ts +0 -17
  255. package/src/runtime/.runtime-ybIxYh/src/cell.ts +0 -45
  256. package/src/runtime/.runtime-ybIxYh/src/controller.ts +0 -58
  257. package/src/runtime/.runtime-ybIxYh/src/lane.ts +0 -6
  258. package/src/runtime/.runtime-ybIxYh/src/main.ts +0 -11
  259. package/src/runtime/.runtime-ybIxYh/src/services.ts +0 -8
  260. package/src/runtime/.runtime-ybIxYh/tsconfig.json +0 -13
  261. package/src/runtime/.runtime-ybIxYh/tsplc.config.ts +0 -31
  262. package/stdlib/math.ts +0 -23
  263. package/types/plc.d.ts +0 -4
package/dist/ir.js.map CHANGED
@@ -1,32 +1,35 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/ir/domains.ts", "../src/ir/model.ts", "../src/ir/numeric.ts", "../src/ir/types.ts", "../src/ir/ranges.ts", "../src/ir/fold.ts", "../src/ir/scalars.ts", "../src/ir/aggregates.ts", "../src/ir/core-model.ts", "../src/ir/diagnostics.ts", "../src/ir/normalization-error.ts", "../src/ir/routine.ts", "../src/ir/conditions.ts", "../src/ir/identity.ts", "../src/ir/job-errors.ts", "../src/ir/layouts.ts", "../src/ir/allocation.ts", "../src/ir/declarations.ts", "../src/ir/link.ts", "../src/ir/normalize.ts", "../src/ir/operands.ts", "../src/ir/share.ts", "../src/ir/temporaries.ts"],
3
+ "sources": ["../src/ir/index.ts", "../src/ir/aggregates.ts", "../src/ir/domains.ts", "../src/ir/numeric.ts", "../src/ir/types.ts", "../src/ir/ranges.ts", "../src/ir/fold.ts", "../src/ir/model.ts", "../src/ir/scalars.ts", "../src/ir/core-model.ts", "../src/ir/tables.ts", "../src/ir/short-circuit.ts", "../src/ir/conditions.ts", "../src/ir/diagnostics.ts", "../src/ir/identity.ts", "../src/ir/job-errors.ts", "../src/ir/layouts.ts", "../src/ir/normalization-error.ts", "../src/ir/allocation.ts", "../src/ir/declarations.ts", "../src/ir/link.ts", "../src/ir/routine.ts", "../src/ir/normalize.ts", "../src/ir/operands.ts", "../src/ir/share.ts", "../src/ir/temporaries.ts"],
4
4
  "sourcesContent": [
5
- "import { elementaryType, integerRange } from \"@tsplc/iec\";\nimport { type Constant, comparisonOperators, type Expression } from \"./model\";\nimport { canonicalInteger, exactDecimal } from \"./numeric\";\nimport type { PlcType } from \"./types\";\n\nexport const nanosecondsPerMillisecond = 1_000_000n;\n\n// TIME stores unsigned milliseconds.\nconst [, latestMillisecond] = integerRange({\n\tbits: elementaryType(\"TIME\").bits,\n\tsigned: false,\n});\n\n// DATE and DATE_AND_TIME store unsigned seconds since 1970-01-01T00:00:00 UTC.\nconst [, latestSecond] = integerRange({\n\tbits: elementaryType(\"DATE_AND_TIME\").bits,\n\tsigned: false,\n});\nconst latestDateTime = new Date(Number(latestSecond) * 1000)\n\t.toISOString()\n\t.slice(0, \"YYYY-MM-DDTHH:mm:ss\".length);\nconst latestDate = latestDateTime.slice(0, \"YYYY-MM-DD\".length);\n\n/** Each calendar domain's zero value, which is also its earliest. */\nexport const calendarZero: Record<\n\tExtract<PlcType, { kind: \"calendar\" }>[\"domain\"],\n\tstring\n> = {\n\tdate: \"1970-01-01\",\n\ttimeOfDay: \"00:00:00.000\",\n\tdateTime: \"1970-01-01T00:00:00\",\n};\n\nexport function durationLiteral(\n\ttext: string,\n\tscaleNanoseconds: bigint,\n): Constant | undefined {\n\tconst clean = text\n\t\t.replaceAll(\"_\", \"\")\n\t\t.replace(/^(-?)\\./, (_, sign: string) => `${sign}0.`);\n\tconst value = exactDecimal(clean, scaleNanoseconds);\n\treturn typeof value === \"bigint\" && validDuration(value)\n\t\t? { kind: \"duration\", nanoseconds: String(value) }\n\t\t: undefined;\n}\nfunction validDuration(nanoseconds: bigint): boolean {\n\treturn (\n\t\tnanoseconds >= 0n &&\n\t\tnanoseconds <= latestMillisecond * nanosecondsPerMillisecond &&\n\t\tnanoseconds % nanosecondsPerMillisecond === 0n\n\t);\n}\nfunction validDate(text: string): boolean {\n\tconst match = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(text);\n\tif (!match) {\n\t\treturn false;\n\t}\n\tconst year = Number(match[1]);\n\tconst month = Number(match[2]);\n\tconst day = Number(match[3]);\n\tconst leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n\tconst length = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][\n\t\tmonth - 1\n\t];\n\treturn Boolean(\n\t\tlength &&\n\t\t\tday >= 1 &&\n\t\t\tday <= length &&\n\t\t\ttext >= calendarZero.date &&\n\t\t\ttext <= latestDate,\n\t);\n}\nfunction validClock(text: string, milliseconds: boolean): boolean {\n\tconst match = (\n\t\tmilliseconds\n\t\t\t? /^(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{3})$/\n\t\t\t: /^(\\d{2}):(\\d{2}):(\\d{2})$/\n\t).exec(text);\n\treturn Boolean(\n\t\tmatch &&\n\t\t\tNumber(match[1]) < 24 &&\n\t\t\tNumber(match[2]) < 60 &&\n\t\t\tNumber(match[3]) < 60,\n\t);\n}\nexport function calendarLiteral(\n\tdomain: Extract<PlcType, { kind: \"calendar\" }>[\"domain\"],\n\ttext: string,\n): Constant | undefined {\n\tif (domain === \"date\") {\n\t\treturn validDate(text) ? { kind: \"calendar\", value: text } : undefined;\n\t}\n\tif (domain === \"timeOfDay\") {\n\t\tconst canonical = /^\\d{2}:\\d{2}:\\d{2}$/.test(text) ? `${text}.000` : text;\n\t\treturn validClock(canonical, true)\n\t\t\t? { kind: \"calendar\", value: canonical }\n\t\t\t: undefined;\n\t}\n\treturn text.length === 19 &&\n\t\ttext[10] === \"T\" &&\n\t\tvalidDate(text.slice(0, 10)) &&\n\t\tvalidClock(text.slice(11), false) &&\n\t\ttext <= latestDateTime\n\t\t? { kind: \"calendar\", value: text }\n\t\t: undefined;\n}\nexport function domainConstantFits(value: Constant, type: PlcType): boolean {\n\tif (type.kind === \"duration\") {\n\t\treturn (\n\t\t\tvalue.kind === \"duration\" &&\n\t\t\tcanonicalInteger.test(value.nanoseconds) &&\n\t\t\tvalidDuration(BigInt(value.nanoseconds))\n\t\t);\n\t}\n\tif (type.kind === \"calendar\" && value.kind === \"calendar\") {\n\t\tconst parsed = calendarLiteral(type.domain, value.value);\n\t\treturn parsed?.kind === \"calendar\" && parsed.value === value.value;\n\t}\n\treturn false;\n}\nexport function domainIssue(\n\tvalue: Expression,\n\ttypes: ReadonlyMap<string, PlcType>,\n): string | undefined {\n\tconst type = types.get(value.type);\n\tif (value.kind === \"constant\") {\n\t\treturn type && domainConstantFits(value.value, type)\n\t\t\t? undefined\n\t\t\t: \"Invalid TIME/calendar constant.\";\n\t}\n\tif (\n\t\tvalue.kind === \"load\" ||\n\t\tvalue.kind === \"call\" ||\n\t\tvalue.kind === \"conditional\"\n\t) {\n\t\treturn undefined;\n\t}\n\tif (value.kind === \"binary\" && comparisonOperators.has(value.operator)) {\n\t\tconst left = types.get(value.left.type);\n\t\treturn value.type === \"BOOL\" &&\n\t\t\tleft &&\n\t\t\t[\"duration\", \"calendar\"].includes(left.kind) &&\n\t\t\tvalue.left.type === value.right.type\n\t\t\t? undefined\n\t\t\t: \"Time comparisons require matching domains.\";\n\t}\n\treturn \"TIME and calendar domains permit storage, typed copies and comparisons; implicit numeric arithmetic is unsupported.\";\n}\n",
6
- "import {\n\ttype BinaryOperator,\n\tcomparisonOperatorNames,\n\ttype UnaryOperator,\n} from \"@tsplc/iec/arithmetic\";\nimport type { Diagnostic, SourceSpan } from \"./diagnostics\";\nimport type { PlcType, SymbolId, TypeId } from \"./types\";\n\nexport type Constant =\n\t| { kind: \"bool\"; value: boolean }\n\t| { kind: \"integer\"; value: string }\n\t| { kind: \"float\"; value: number }\n\t| { kind: \"duration\"; nanoseconds: string }\n\t| { kind: \"calendar\"; value: string }\n\t| { kind: \"string\"; value: string }\n\t| { kind: \"array\"; items: readonly Constant[] }\n\t| { kind: \"record\"; fields: Readonly<Record<string, Constant>> };\n\nexport interface Variable {\n\tid: SymbolId;\n\tname: string;\n\ttype: TypeId;\n\tstorage:\n\t\t| \"module\"\n\t\t| \"local\"\n\t\t| \"parameter\"\n\t\t| \"input\"\n\t\t| \"output\"\n\t\t| \"field\"\n\t\t| \"instance\"\n\t\t| \"constant\"\n\t\t| \"blockOutput\";\n\tmutable: boolean;\n\tretain: boolean;\n\texported?: true;\n\texposure?: { name: string; version: string };\n\tmode?: \"inOut\";\n\tinitial?: Constant;\n\tspan: SourceSpan;\n}\n\nexport interface Place {\n\troot: SymbolId;\n\tpath: readonly (\n\t\t| { kind: \"field\"; name: string }\n\t\t| { kind: \"index\"; value: Expression }\n\t)[];\n}\n\nexport const comparisonOperators: ReadonlySet<BinaryOperator> = new Set(\n\tcomparisonOperatorNames,\n);\n\nexport type Expression = { type: TypeId; span: SourceSpan } & (\n\t| { kind: \"constant\"; value: Constant }\n\t| { kind: \"load\"; place: Place }\n\t| {\n\t\t\tkind: \"unary\";\n\t\t\toperator: UnaryOperator;\n\t\t\toperand: Expression;\n\t }\n\t| {\n\t\t\tkind: \"binary\";\n\t\t\toperator: BinaryOperator;\n\t\t\tleft: Expression;\n\t\t\tright: Expression;\n\t\t\tpolicy?: \"wrap\" | \"saturate\";\n\t }\n\t| {\n\t\t\tkind: \"call\";\n\t\t\tfunction: SymbolId;\n\t\t\tinstance?: SymbolId;\n\t\t\tindex?: Expression;\n\t\t\targuments: readonly Expression[];\n\t }\n\t| {\n\t\t\tkind: \"conditional\";\n\t\t\tcondition: Expression;\n\t\t\tthen: Expression;\n\t\t\telse: Expression;\n\t }\n\t| {\n\t\t\tkind: \"convert\";\n\t\t\toperand: Expression;\n\t\t\tpolicy: \"exact\" | \"wrap\" | \"saturate\";\n\t }\n\t| { kind: \"borrow\"; place: Place }\n\t| { kind: \"length\"; operand: Expression }\n\t| { kind: \"copy\"; operand: Expression }\n\t| { kind: \"record\"; fields: Readonly<Record<string, Expression>> }\n\t| { kind: \"array\"; items: readonly Expression[] }\n);\n\nexport type Statement = { span: SourceSpan } & (\n\t| { kind: \"assign\"; destination: Place; value: Expression }\n\t| {\n\t\t\tkind: \"if\";\n\t\t\tcondition: Expression;\n\t\t\tthen: readonly Statement[];\n\t\t\telse: readonly Statement[];\n\t }\n\t| {\n\t\t\tkind: \"switch\";\n\t\t\tvalue: Expression;\n\t\t\tcases: readonly {\n\t\t\t\tvalues: readonly Constant[];\n\t\t\t\tbody: readonly Statement[];\n\t\t\t}[];\n\t\t\tfallback: readonly Statement[];\n\t }\n\t| {\n\t\t\tkind: \"for\";\n\t\t\tcounter: SymbolId;\n\t\t\t/** Existing storage remains observable after the loop exits. */\n\t\t\tcounterScope?: \"existing\";\n\t\t\tstart: Expression;\n\t\t\tlimit: Expression;\n\t\t\tstep: string;\n\t\t\texclusive?: true;\n\t\t\tmaxIterations: number;\n\t\t\tbody: readonly Statement[];\n\t }\n\t| {\n\t\t\tkind: \"invoke\";\n\t\t\tfunction: SymbolId;\n\t\t\tinstance?: SymbolId;\n\t\t\tindex?: Expression;\n\t\t\targuments: readonly Expression[];\n\t\t\tdestination?: Place;\n\t }\n\t| {\n\t\t\tkind: \"blockUpdate\";\n\t\t\tinstance: SymbolId;\n\t\t\tindex?: Expression;\n\t\t\tinputs: Readonly<Record<string, Expression>>;\n\t }\n\t| { kind: \"return\"; value?: Expression }\n\t| { kind: \"break\" | \"continue\" }\n\t| ({ kind: \"telemetry\" } & TelemetryCall<Expression>)\n);\n\n/**\n * A `@tsplc/compiler/telemetry` call. `record` is what the record says besides its properties;\n * a property with a `length` is a byte array, borrowed, sent as text up to that length.\n */\nexport interface TelemetryCall<E> {\n\trecord:\n\t\t| { kind: \"event\"; event: string }\n\t\t| { kind: \"log\"; level: \"info\" | \"warn\" | \"error\"; message: string }\n\t\t| { kind: \"exception\"; code: E };\n\tproperties: readonly { name: string; value: E; length?: E }[];\n}\n\n/** Every value a telemetry call reads, in evaluation order. */\nexport const telemetryOperands = <E>({\n\trecord,\n\tproperties,\n}: TelemetryCall<E>): E[] => [\n\t...(record.kind === \"exception\" ? [record.code] : []),\n\t...properties.flatMap(({ value, length }) =>\n\t\tlength ? [value, length] : [value],\n\t),\n];\n\nexport interface MethodOwner {\n\tblock: SymbolId;\n\taccess: \"public\" | \"private\" | \"protected\";\n}\n\nexport interface PlcFunction {\n\towner?: MethodOwner;\n\tid: SymbolId;\n\tname: string;\n\tparameters: readonly Variable[];\n\tlocals: readonly Variable[];\n\tresult?: TypeId;\n\t/** A `@tsplc/compiler/math` helper, whose result range follows from its arguments' ranges. */\n\tbounds?: MathHelper;\n\t/** The source method this function was specialized from, as `Class.method`, and the TypeScript path of its `this`. */\n\torigin?: { name: string; instance?: string };\n\tbody: readonly Statement[];\n\tspan: SourceSpan;\n}\nexport type MathHelper = \"min\" | \"max\" | \"clamp\";\n\n// Native vendor blocks under their TypeScript names. Ports are [name, native name, type];\n// every output starts at its type's default, matching the vendor library blocks.\nconst timer = (input: string, output: string) =>\n\t({\n\t\tinputs: [\n\t\t\t[input, \"IN\", \"BOOL\"],\n\t\t\t[\"duration\", \"PT\", \"TIME\"],\n\t\t],\n\t\toutputs: [\n\t\t\t[output, \"Q\", \"BOOL\"],\n\t\t\t[\"elapsed\", \"ET\", \"TIME\"],\n\t\t],\n\t}) as const;\nexport const standardBlocks = {\n\tOnDelayTimer: { native: \"TON\", ...timer(\"enabled\", \"done\") },\n\tOffDelayTimer: { native: \"TOF\", ...timer(\"enabled\", \"active\") },\n\tPulseTimer: { native: \"TP\", ...timer(\"start\", \"active\") },\n\tRisingEdge: {\n\t\tnative: \"R_TRIG\",\n\t\tinputs: [[\"signal\", \"CLK\", \"BOOL\"]],\n\t\toutputs: [[\"rose\", \"Q\", \"BOOL\"]],\n\t},\n\tFallingEdge: {\n\t\tnative: \"F_TRIG\",\n\t\tinputs: [[\"signal\", \"CLK\", \"BOOL\"]],\n\t\toutputs: [[\"fell\", \"Q\", \"BOOL\"]],\n\t},\n\tUpCounter: {\n\t\tnative: \"CTU\",\n\t\tinputs: [\n\t\t\t[\"countUp\", \"CU\", \"BOOL\"],\n\t\t\t[\"reset\", \"RESET\", \"BOOL\"],\n\t\t\t[\"preset\", \"PV\", \"WORD\"],\n\t\t],\n\t\toutputs: [\n\t\t\t[\"reachedPreset\", \"Q\", \"BOOL\"],\n\t\t\t[\"value\", \"CV\", \"WORD\"],\n\t\t],\n\t},\n\tDownCounter: {\n\t\tnative: \"CTD\",\n\t\tinputs: [\n\t\t\t[\"countDown\", \"CD\", \"BOOL\"],\n\t\t\t[\"load\", \"LOAD\", \"BOOL\"],\n\t\t\t[\"preset\", \"PV\", \"WORD\"],\n\t\t],\n\t\toutputs: [\n\t\t\t[\"atZero\", \"Q\", \"BOOL\"],\n\t\t\t[\"value\", \"CV\", \"WORD\"],\n\t\t],\n\t},\n\tUpDownCounter: {\n\t\tnative: \"CTUD\",\n\t\tinputs: [\n\t\t\t[\"countUp\", \"CU\", \"BOOL\"],\n\t\t\t[\"countDown\", \"CD\", \"BOOL\"],\n\t\t\t[\"reset\", \"RESET\", \"BOOL\"],\n\t\t\t[\"load\", \"LOAD\", \"BOOL\"],\n\t\t\t[\"preset\", \"PV\", \"WORD\"],\n\t\t],\n\t\toutputs: [\n\t\t\t[\"reachedPreset\", \"QU\", \"BOOL\"],\n\t\t\t[\"atZero\", \"QD\", \"BOOL\"],\n\t\t\t[\"value\", \"CV\", \"WORD\"],\n\t\t],\n\t},\n\tBlinker: {\n\t\tnative: \"Util.BLINK\",\n\t\tinputs: [\n\t\t\t[\"enabled\", \"ENABLE\", \"BOOL\"],\n\t\t\t[\"offTime\", \"TIMELOW\", \"TIME\"],\n\t\t\t[\"onTime\", \"TIMEHIGH\", \"TIME\"],\n\t\t],\n\t\toutputs: [[\"on\", \"OUT\", \"BOOL\"]],\n\t},\n} as const;\nexport type StandardBlock = keyof typeof standardBlocks;\n\nexport interface FunctionBlock {\n\tid: SymbolId;\n\tname: string;\n\tinputs: readonly Variable[];\n\toutputs: readonly Variable[];\n\tstate: readonly Variable[];\n\tlocals: readonly Variable[];\n\tbody: readonly Statement[];\n\tresult?: TypeId;\n\tstandard?: StandardBlock;\n\truntime?:\n\t\t| { kind: \"mailbox\" }\n\t\t| { kind: \"backgroundHost\" }\n\t\t| { kind: \"rpc\"; path: string }\n\t\t| {\n\t\t\t\tkind: \"http\";\n\t\t\t\turl: string;\n\t\t\t\tmethod: \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\t\t\t\tjson: boolean;\n\t\t };\n\t/** The async function lowered to this block, and the source each `step` value stands for. */\n\tjob?: {\n\t\tname: string;\n\t\t/** The TypeScript path of `this`, for a method specialized to one instance. */\n\t\tinstance?: string;\n\t\tspan: SourceSpan;\n\t\tsteps: readonly {\n\t\t\tstep: number;\n\t\t\tkind: \"await\" | \"return\" | \"throw\" | \"statement\";\n\t\t\tspan: SourceSpan;\n\t\t\ttext: string;\n\t\t}[];\n\t};\n\tspan: SourceSpan;\n}\n\nexport interface PlcProgram {\n\tid: SymbolId;\n\tname: string;\n\tentry: SymbolId;\n\tcontinuation?: { instance: string; file: string };\n\tbackground?: {\n\t\tintervalNanoseconds: string;\n\t\tpriority: number;\n\t\tmailbox: string;\n\t\tworker: string;\n\t};\n}\n\nexport interface PlcModule {\n\t/**\n\t * Fields the elaborator folded into constants: no storage, but a known value at each TypeScript\n\t * path. `type` is the scalar's PLC type; strings, often enum members, have none.\n\t */\n\tfolded?: readonly {\n\t\tpath: string;\n\t\tvalue: Constant;\n\t\ttype?: TypeId;\n\t\tspan: SourceSpan;\n\t}[];\n\t/**\n\t * Object references: the module storage path of each object by the id a reference holds (−1 is\n\t * `undefined`), and the storage paths of the fields that hold a reference.\n\t */\n\treferences?: {\n\t\tobjects: readonly { id: number; path: string }[];\n\t\tfields: readonly string[];\n\t};\n\ttypes: readonly PlcType[];\n\tvariables: readonly Variable[];\n\tfunctions: readonly PlcFunction[];\n\tblocks: readonly FunctionBlock[];\n\tprograms: readonly PlcProgram[];\n}\n\nexport interface Task {\n\tname: string;\n\tintervalNanoseconds: string;\n\tpriority: number;\n\tprograms: readonly string[];\n}\n\nexport interface Deployment {\n\ttasks: readonly Task[];\n}\n\nexport interface Artifact {\n\tpath: string;\n\tcontent: string;\n}\n\nexport interface GeneratedObject {\n\tparent?: SymbolId;\n\tsourcePath?: string;\n\tid: SymbolId;\n\tkind:\n\t\t| \"program\"\n\t\t| \"function\"\n\t\t| \"functionBlock\"\n\t\t| \"method\"\n\t\t| \"globalList\"\n\t\t| \"dataType\";\n\tname: string;\n\tdeclaration: string;\n\timplementation?: string;\n}\n\nexport interface EmitResult {\n\tartifacts: readonly Artifact[];\n\tobjects: readonly GeneratedObject[];\n\tdiagnostics: readonly Diagnostic[];\n}\n",
7
- "// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.\nimport { roundFloat } from \"@tsplc/iec/arithmetic\";\nimport type { Constant } from \"./model\";\nimport { integerRange, type PlcType } from \"./types\";\n\ntype IntegerType = Extract<PlcType, { kind: \"integer\" | \"bits\" }>;\ntype FloatType = Extract<PlcType, { kind: \"float\" }>;\n\nexport type IntegerInterval = readonly [bigint, bigint];\n\nexport const lowest = (a: bigint, b: bigint): bigint => (a < b ? a : b);\nexport const highest = (a: bigint, b: bigint): bigint => (a > b ? a : b);\n\n/** Whether every value of `inner` lies in `outer`. */\nexport const within = (\n\tinner: IntegerInterval,\n\touter: IntegerInterval,\n): boolean => inner[0] >= outer[0] && inner[1] <= outer[1];\n\n/** Whether `interval` admits `value`, such as a divisor that may be zero. */\nexport const admits = (interval: IntegerInterval, value: bigint): boolean =>\n\tinterval[0] <= value && value <= interval[1];\n\n/** Integer constants are canonical decimal text: no leading zeros and no negative zero. */\nexport const canonicalInteger = /^(?:0|-?[1-9][0-9]*)$/;\n\nexport const integerType = (type: PlcType): type is IntegerType =>\n\ttype.kind === \"integer\" || type.kind === \"bits\";\n\n// The significand precision of REAL (IEEE 754 binary32) and LREAL (binary64), which bounds the\n// integers each format holds exactly.\nconst floatPrecision = { 32: 24, 64: 53 } as const;\n\n/** Every integer from minus this limit to this limit converts to the float type exactly. */\nexport const exactIntegerLimit = (type: FloatType): bigint =>\n\t1n << BigInt(floatPrecision[type.bits]);\n\ntype DecimalIssue = \"malformed\" | \"exponent\" | \"fraction\";\n\n/**\n * A signed decimal with an optional fraction and exponent, times `scale`, exactly; it must come\n * to a whole number. The exponent is capped so a literal cannot demand a vast power of ten.\n */\nexport const exactDecimal = (\n\ttext: string,\n\tscale: bigint,\n): bigint | DecimalIssue => {\n\tconst match = /^(-?\\d+)(?:\\.(\\d*))?(?:e([+-]?\\d+))?$/i.exec(text);\n\tif (!match) {\n\t\treturn \"malformed\";\n\t}\n\tconst [, whole, fraction = \"\", exponentText = \"0\"] = match;\n\tconst exponent = Number(exponentText) - fraction.length;\n\tif (!Number.isSafeInteger(exponent) || Math.abs(exponent) > 400) {\n\t\treturn \"exponent\";\n\t}\n\t// The pattern requires the whole digits, so the group always matched.\n\tconst digits = BigInt(whole! + fraction) * scale;\n\tif (exponent >= 0) {\n\t\treturn digits * 10n ** BigInt(exponent);\n\t}\n\tconst divisor = 10n ** BigInt(-exponent);\n\treturn digits % divisor ? \"fraction\" : digits / divisor;\n};\n\nconst integerLiteralIssues: Record<DecimalIssue, string> = {\n\tmalformed: \"Expected an exact integer literal.\",\n\texponent: \"Integer literal exponent is out of range.\",\n\tfraction: \"Integer literals cannot have a fractional part.\",\n};\n\nexport const parseInteger = (text: string): bigint => {\n\tconst clean = text.replaceAll(\"_\", \"\").replace(/n$/, \"\");\n\tif (/^-?0[xob]/i.test(clean)) {\n\t\treturn clean.startsWith(\"-\") ? -BigInt(clean.slice(1)) : BigInt(clean);\n\t}\n\tconst value = exactDecimal(clean, 1n);\n\tif (typeof value !== \"bigint\") {\n\t\tthrow new Error(integerLiteralIssues[value]);\n\t}\n\treturn value;\n};\n\nexport const constantFits = (value: Constant, type: PlcType): boolean => {\n\tif (type.kind === \"bool\") {\n\t\treturn value.kind === \"bool\" && typeof value.value === \"boolean\";\n\t}\n\tif (integerType(type)) {\n\t\treturn (\n\t\t\tvalue.kind === \"integer\" &&\n\t\t\tcanonicalInteger.test(value.value) &&\n\t\t\tadmits(integerRange(type), BigInt(value.value))\n\t\t);\n\t}\n\tif (type.kind === \"float\") {\n\t\treturn (\n\t\t\tvalue.kind === \"float\" &&\n\t\t\tNumber.isFinite(value.value) &&\n\t\t\tObject.is(roundFloat(value.value, type), value.value)\n\t\t);\n\t}\n\treturn false;\n};\n\nexport const canAssign = (\n\tsource: PlcType,\n\tdestination: PlcType,\n\tvalue?: Constant,\n): boolean => {\n\tif (value) {\n\t\treturn source.kind === destination.kind && constantFits(value, destination);\n\t}\n\tif (source.id === destination.id) {\n\t\treturn true;\n\t}\n\tif (source.kind === \"integer\" && destination.kind === \"integer\") {\n\t\treturn within(integerRange(source), integerRange(destination));\n\t}\n\treturn (\n\t\tsource.kind === \"float\" &&\n\t\tdestination.kind === \"float\" &&\n\t\tsource.bits <= destination.bits\n\t);\n};\n\n/** Plain integer +, - and * are native IEC arithmetic, which wraps on overflow as hand-written ST does. */\nexport const wrapsNatively = (expression: {\n\tkind: string;\n\toperator?: string;\n\tpolicy?: string;\n}): boolean =>\n\texpression.kind === \"binary\" &&\n\t!expression.policy &&\n\t(expression.operator === \"add\" ||\n\t\texpression.operator === \"subtract\" ||\n\t\texpression.operator === \"multiply\");\n",
8
- "import {\n\ttype ElementaryType,\n\tintegerRange as elementaryIntegerRange,\n\telementaryTypes,\n} from \"@tsplc/iec\";\n\nexport type TypeId = string;\nexport type SymbolId = string;\n\nexport interface Field {\n\tname: string;\n\ttype: TypeId;\n\treadonly: boolean;\n\tmode?: \"inOut\";\n}\n\nexport type PlcType =\n\t| { id: TypeId; kind: \"bool\" }\n\t| { id: TypeId; kind: \"integer\"; bits: 8 | 16 | 32 | 64; signed: boolean }\n\t| { id: TypeId; kind: \"bits\"; bits: 8 | 16 | 32 | 64 }\n\t| { id: TypeId; kind: \"float\"; bits: 32 | 64 }\n\t| { id: TypeId; kind: \"duration\" }\n\t| { id: TypeId; kind: \"calendar\"; domain: \"date\" | \"timeOfDay\" | \"dateTime\" }\n\t| { id: TypeId; kind: \"string\"; capacity: number; encoding: \"utf8\" | \"utf16\" }\n\t| {\n\t\t\tid: TypeId;\n\t\t\tkind: \"array\";\n\t\t\telement: TypeId;\n\t\t\tlength: number;\n\t\t\tlowerBound: number;\n\t\t\t/** `Record<Enum, T>`: the enum whose contiguous member values are the bounds and the only indexes. */\n\t\t\tindex?: TypeId;\n\t }\n\t| { id: TypeId; kind: \"record\"; fields: readonly Field[] }\n\t| {\n\t\t\tid: TypeId;\n\t\t\tkind: \"enum\";\n\t\t\tbase: TypeId;\n\t\t\t/** `text` is the string a plain TypeScript program's literal union member stands for. */\n\t\t\tmembers: readonly { name: string; value: string; text?: string }[];\n\t }\n\t| { id: TypeId; kind: \"block\"; block: SymbolId; output?: TypeId };\n\n/** The block allocated by a type: a block itself, or a fixed array of one. */\nexport const instancedBlock = (\n\tid: TypeId,\n\ttypes: ReadonlyMap<TypeId, PlcType>,\n): Extract<PlcType, { kind: \"block\" }> | undefined => {\n\tconst type = types.get(id);\n\tconst element = type?.kind === \"array\" ? types.get(type.element) : type;\n\treturn element?.kind === \"block\" ? element : undefined;\n};\n\nconst primitiveType = (type: ElementaryType): PlcType[] => {\n\tswitch (type.family) {\n\t\tcase \"bool\":\n\t\t\treturn [{ id: type.name, kind: \"bool\" }];\n\t\tcase \"integer\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: type.name,\n\t\t\t\t\tkind: \"integer\",\n\t\t\t\t\tbits: type.bits,\n\t\t\t\t\tsigned: type.signed,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"bits\":\n\t\t\treturn [{ id: type.name, kind: \"bits\", bits: type.bits }];\n\t\tcase \"real\":\n\t\t\treturn [{ id: type.name, kind: \"float\", bits: type.bits }];\n\t\tcase \"duration\":\n\t\t\treturn type.bits === 32 ? [{ id: type.name, kind: \"duration\" }] : [];\n\t\tcase \"date\":\n\t\tcase \"timeOfDay\":\n\t\tcase \"dateTime\":\n\t\t\treturn type.bits === 32\n\t\t\t\t? [{ id: type.name, kind: \"calendar\", domain: type.family }]\n\t\t\t\t: [];\n\t\tcase \"char\":\n\t\tcase \"string\":\n\t\t\treturn [];\n\t}\n};\n\ntype IntegerValued = Extract<PlcType, { kind: \"integer\" | \"bits\" }>;\n\nconst isIntegerValued = (type: PlcType): type is IntegerValued =>\n\ttype.kind === \"integer\" || type.kind === \"bits\";\n\nconst integerKindRank = (type: IntegerValued) => {\n\tif (type.kind === \"bits\") {\n\t\treturn 2;\n\t}\n\treturn type.signed ? 0 : 1;\n};\n\nconst elementaryPrimitives = elementaryTypes.flatMap(primitiveType);\n\n/**\n * The elementary types a program uses by name. Date and time types are the 32-bit ones;\n * strings are sized where they are declared, and characters are not modelled.\n *\n * Integers are grouped by width (signed, unsigned, bit string), because the debug manifest\n * lists types in this order and the build id written into the emitted ST hashes it.\n */\nexport const primitiveTypes: readonly PlcType[] = [\n\t...elementaryPrimitives.filter((type) => type.kind === \"bool\"),\n\t...elementaryPrimitives\n\t\t.filter(isIntegerValued)\n\t\t.sort(\n\t\t\t(left, right) =>\n\t\t\t\tleft.bits - right.bits ||\n\t\t\t\tintegerKindRank(left) - integerKindRank(right),\n\t\t),\n\t...elementaryPrimitives.filter(\n\t\t(type) => type.kind !== \"bool\" && !isIntegerValued(type),\n\t),\n];\n\nexport function integerRange(\n\ttype: Extract<PlcType, { kind: \"integer\" | \"bits\" }>,\n): readonly [bigint, bigint] {\n\treturn elementaryIntegerRange({\n\t\tbits: type.bits,\n\t\tsigned: type.kind === \"integer\" && type.signed,\n\t});\n}\n",
9
- "import { type BinaryOperator, loopIterations } from \"@tsplc/iec/arithmetic\";\nimport { fold } from \"./fold\";\nimport type { Expression, MathHelper, Variable } from \"./model\";\nimport {\n\tadmits,\n\thighest,\n\ttype IntegerInterval,\n\tintegerType,\n\tlowest,\n\twithin,\n} from \"./numeric\";\nimport { integerRange, type PlcType } from \"./types\";\n\nexport const interval = (\n\texpression: Expression,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tvariables: ReadonlyMap<string, Variable>,\n\tranges: ReadonlyMap<string, IntegerInterval> = new Map(),\n): IntegerInterval | undefined => {\n\tif (expression.kind === \"length\") {\n\t\tconst array = types.get(expression.operand.type);\n\t\tif (array?.kind === \"array\") {\n\t\t\treturn [BigInt(array.length), BigInt(array.length)];\n\t\t}\n\t}\n\tconst value = fold(expression, variables, types);\n\tif (value?.kind === \"integer\") {\n\t\treturn [BigInt(value.value), BigInt(value.value)];\n\t}\n\tconst type = types.get(expression.type);\n\tif (!type || !integerType(type)) {\n\t\treturn undefined;\n\t}\n\tif (expression.kind === \"load\") {\n\t\treturn ranges.get(expression.place.root) ?? integerRange(type);\n\t}\n\tif (expression.kind === \"convert\") {\n\t\treturn expression.policy === \"exact\"\n\t\t\t? interval(expression.operand, types, variables, ranges)\n\t\t\t: integerRange(type);\n\t}\n\tif (expression.kind === \"unary\" && expression.operator === \"negate\") {\n\t\tconst operand = interval(expression.operand, types, variables, ranges);\n\t\treturn operand && [-operand[1], -operand[0]];\n\t}\n\tif (expression.kind === \"binary\" && !expression.policy) {\n\t\tconst left = interval(expression.left, types, variables, ranges);\n\t\tconst right = interval(expression.right, types, variables, ranges);\n\t\treturn (\n\t\t\tleft &&\n\t\t\tright &&\n\t\t\tarithmeticInterval(expression.operator, left, right, integerRange(type))\n\t\t);\n\t}\n\treturn integerRange(type);\n};\n\n/** The range of `left operator right`; a result that may wrap spans its whole type. */\nconst arithmeticInterval = (\n\toperator: BinaryOperator,\n\tleft: IntegerInterval,\n\tright: IntegerInterval,\n\ttype: IntegerInterval,\n): IntegerInterval | undefined => {\n\tconst unwrapped = (result: IntegerInterval): IntegerInterval =>\n\t\twithin(result, type) ? result : type;\n\tconst corners = (combine: (a: bigint, b: bigint) => bigint) => [\n\t\tcombine(left[0], right[0]),\n\t\tcombine(left[0], right[1]),\n\t\tcombine(left[1], right[0]),\n\t\tcombine(left[1], right[1]),\n\t];\n\tswitch (operator) {\n\t\tcase \"add\":\n\t\t\treturn unwrapped([left[0] + right[0], left[1] + right[1]]);\n\t\tcase \"subtract\":\n\t\t\treturn unwrapped([left[0] - right[1], left[1] - right[0]]);\n\t\tcase \"multiply\": {\n\t\t\tconst products = corners((a, b) => a * b);\n\t\t\treturn unwrapped([products.reduce(lowest), products.reduce(highest)]);\n\t\t}\n\t\tcase \"divide\": {\n\t\t\tif (admits(right, 0n)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst quotients = corners((a, b) => a / b);\n\t\t\treturn [quotients.reduce(lowest), quotients.reduce(highest)];\n\t\t}\n\t\tcase \"remainder\": {\n\t\t\tif (admits(right, 0n)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst magnitude = (value: bigint) => (value < 0n ? -value : value);\n\t\t\tconst largest = highest(magnitude(right[0]), magnitude(right[1])) - 1n;\n\t\t\treturn [left[0] < 0n ? -largest : 0n, left[1] > 0n ? largest : 0n];\n\t\t}\n\t\tdefault:\n\t\t\treturn type;\n\t}\n};\n\n/** The most iterations a bounded loop may prove. */\nexport const maxLoopIterations = 1_000_000n;\n\nexport const loopBounds = (\n\tstart: IntegerInterval,\n\tlimit: IntegerInterval,\n\tstep: bigint,\n\texclusive = false,\n) => {\n\tconst excluded = exclusive ? 1n : 0n;\n\tconst first = step > 0n ? start[0] : start[1];\n\tconst last = step > 0n ? limit[1] - excluded : limit[0] + excluded;\n\tconst count = loopIterations(\n\t\tfirst,\n\t\tlimit[step > 0n ? 1 : 0],\n\t\texclusive,\n\t\tstep,\n\t);\n\tconst range: IntegerInterval = first <= last ? [first, last] : [last, first];\n\treturn { first, last, count, range };\n};\n\nconst negatedComparisons: Partial<Record<BinaryOperator, BinaryOperator>> = {\n\tless: \"greaterEqual\",\n\tlessEqual: \"greater\",\n\tgreater: \"lessEqual\",\n\tgreaterEqual: \"less\",\n};\n\nconst bounded = (\n\tcurrent: IntegerInterval,\n\toperator: BinaryOperator | undefined,\n\tvalue: bigint,\n): IntegerInterval => {\n\tconst [lower, upper] = current;\n\tswitch (operator) {\n\t\tcase \"less\":\n\t\t\treturn [lower, lowest(upper, value - 1n)];\n\t\tcase \"lessEqual\":\n\t\t\treturn [lower, lowest(upper, value)];\n\t\tcase \"greater\":\n\t\t\treturn [highest(lower, value + 1n), upper];\n\t\tcase \"greaterEqual\":\n\t\t\treturn [highest(lower, value), upper];\n\t\tdefault:\n\t\t\treturn current;\n\t}\n};\n\n// Only storage no statement can change carries branch refinements: loop counters,\n// by-value parameters and const locals, so the proof survives through the branch.\nexport const narrowRanges = (\n\tcondition: Expression,\n\ttruth: boolean,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tvariables: ReadonlyMap<string, Variable>,\n\tranges: ReadonlyMap<string, IntegerInterval>,\n): Map<string, IntegerInterval> => {\n\tconst narrowed = new Map(ranges);\n\tif (condition.kind !== \"binary\") {\n\t\treturn narrowed;\n\t}\n\tif (condition.operator === \"and\") {\n\t\treturn truth\n\t\t\t? narrowRanges(\n\t\t\t\t\tcondition.right,\n\t\t\t\t\ttruth,\n\t\t\t\t\ttypes,\n\t\t\t\t\tvariables,\n\t\t\t\t\tnarrowRanges(condition.left, truth, types, variables, ranges),\n\t\t\t\t)\n\t\t\t: narrowed;\n\t}\n\tif (condition.left.kind !== \"load\" || condition.left.place.path.length) {\n\t\treturn narrowed;\n\t}\n\tconst root = condition.left.place.root;\n\tconst variable = variables.get(root);\n\tconst type = types.get(condition.left.type);\n\tconst fixed =\n\t\tvariable &&\n\t\t((variable.storage === \"parameter\" && !variable.mode) ||\n\t\t\t(variable.storage === \"local\" && !variable.mutable));\n\tconst current =\n\t\tranges.get(root) ??\n\t\t(fixed && type && integerType(type) ? integerRange(type) : undefined);\n\tconst bound = interval(condition.right, types, variables, ranges);\n\tif (!current || !bound || bound[0] !== bound[1]) {\n\t\treturn narrowed;\n\t}\n\tconst [lower, upper] = bounded(\n\t\tcurrent,\n\t\ttruth ? condition.operator : negatedComparisons[condition.operator],\n\t\tbound[0],\n\t);\n\tif (lower <= upper) {\n\t\tnarrowed.set(root, [lower, upper]);\n\t}\n\treturn narrowed;\n};\n\n/** A value's proved integer range; a math helper's result follows from its arguments. */\nexport const valueRange = (\n\texpression: Expression,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tvariables: ReadonlyMap<string, Variable>,\n\tranges: ReadonlyMap<string, IntegerInterval>,\n\tfunctions: ReadonlyMap<string, { bounds?: MathHelper }>,\n): IntegerInterval | undefined => {\n\tif (expression.kind !== \"call\") {\n\t\treturn interval(expression, types, variables, ranges);\n\t}\n\tconst helper = functions.get(expression.function)?.bounds;\n\treturn (\n\t\thelper &&\n\t\tmathHelperRange(\n\t\t\thelper,\n\t\t\texpression.arguments.map((argument) =>\n\t\t\t\tvalueRange(argument, types, variables, ranges, functions),\n\t\t\t),\n\t\t)\n\t);\n};\n\nconst mathHelperRange = (\n\thelper: MathHelper,\n\t[first, second, third]: readonly (IntegerInterval | undefined)[],\n): IntegerInterval | undefined => {\n\tif (!first || !second) {\n\t\treturn undefined;\n\t}\n\tif (helper === \"min\") {\n\t\treturn [lowest(first[0], second[0]), lowest(first[1], second[1])];\n\t}\n\tif (helper === \"max\") {\n\t\treturn [highest(first[0], second[0]), highest(first[1], second[1])];\n\t}\n\t// clamp(value, lower, upper) returns one of its three arguments, never outside lower..upper,\n\t// and only lower or upper when the bounds are reversed.\n\tif (!third) {\n\t\treturn undefined;\n\t}\n\treturn [lowest(second[0], third[0]), highest(second[1], third[1])];\n};\n",
10
- "import {\n\tapplyIntegerPolicy,\n\tbooleanOperation,\n\tcompare,\n\telementaryValue,\n\tfloatArithmetic,\n\tintegerArithmetic,\n\tisElementary,\n\troundFloat,\n\tsaturateFloat,\n} from \"@tsplc/iec/arithmetic\";\nimport { nanosecondsPerMillisecond } from \"./domains\";\nimport type { Constant, Expression, Variable } from \"./model\";\nimport { integerType } from \"./numeric\";\nimport type { PlcType } from \"./types\";\n\ntype Types = ReadonlyMap<string, PlcType> | undefined;\n\nexport const fold = (\n\texpression: Expression,\n\tvariables: ReadonlyMap<string, Variable>,\n\ttypes?: ReadonlyMap<string, PlcType>,\n): Constant | undefined => {\n\tswitch (expression.kind) {\n\t\tcase \"constant\":\n\t\t\treturn expression.value;\n\t\tcase \"copy\":\n\t\t\treturn fold(expression.operand, variables, types);\n\t\tcase \"length\":\n\t\t\treturn foldLength(expression, variables, types);\n\t\tcase \"record\":\n\t\t\treturn foldRecord(expression, variables, types);\n\t\tcase \"array\": {\n\t\t\tconst items = expression.items.map((item) =>\n\t\t\t\tfold(item, variables, types),\n\t\t\t);\n\t\t\treturn items.every((item): item is Constant => item !== undefined)\n\t\t\t\t? { kind: \"array\", items }\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"load\": {\n\t\t\tif (expression.place.path.length) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst variable = variables.get(expression.place.root);\n\t\t\treturn variable?.storage === \"constant\" ? variable.initial : undefined;\n\t\t}\n\t\tcase \"convert\":\n\t\t\treturn foldConvert(\n\t\t\t\texpression,\n\t\t\t\tfold(expression.operand, variables, types),\n\t\t\t\ttypes?.get(expression.type),\n\t\t\t);\n\t\tcase \"unary\":\n\t\t\treturn foldUnary(\n\t\t\t\texpression,\n\t\t\t\tfold(expression.operand, variables, types),\n\t\t\t\ttypes?.get(expression.type),\n\t\t\t);\n\t\tcase \"binary\": {\n\t\t\tconst left = fold(expression.left, variables, types);\n\t\t\tconst right = fold(expression.right, variables, types);\n\t\t\treturn left && right\n\t\t\t\t? foldBinary(expression, left, right, types?.get(expression.type))\n\t\t\t\t: undefined;\n\t\t}\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n};\n\nconst foldLength = (\n\texpression: Extract<Expression, { kind: \"length\" }>,\n\tvariables: ReadonlyMap<string, Variable>,\n\ttypes: Types,\n): Constant | undefined => {\n\tconst type = types?.get(expression.operand.type);\n\tconst receiver =\n\t\texpression.operand.kind === \"load\"\n\t\t\t? variables.get(expression.operand.place.root)\n\t\t\t: undefined;\n\tconst pure =\n\t\texpression.operand.kind === \"load\" &&\n\t\texpression.operand.place.path.every(\n\t\t\t(segment) => segment.kind === \"field\",\n\t\t) &&\n\t\tBoolean(\n\t\t\treceiver?.initial ||\n\t\t\t\treceiver?.storage === \"input\" ||\n\t\t\t\treceiver?.storage === \"output\",\n\t\t);\n\tif (\n\t\ttype?.kind === \"array\" &&\n\t\t(pure || fold(expression.operand, variables, types))\n\t) {\n\t\treturn { kind: \"integer\", value: String(type.length) };\n\t}\n\treturn undefined;\n};\n\nconst foldRecord = (\n\texpression: Extract<Expression, { kind: \"record\" }>,\n\tvariables: ReadonlyMap<string, Variable>,\n\ttypes: Types,\n): Constant | undefined => {\n\tconst fields: Record<string, Constant> = Object.create(null);\n\tfor (const [name, operand] of Object.entries(expression.fields)) {\n\t\tconst value = fold(operand, variables, types);\n\t\tif (!value) {\n\t\t\treturn undefined;\n\t\t}\n\t\tfields[name] = value;\n\t}\n\treturn { kind: \"record\", fields };\n};\n\nconst foldConvert = (\n\texpression: Extract<Expression, { kind: \"convert\" }>,\n\tvalue: Constant | undefined,\n\ttarget: PlcType | undefined,\n): Constant | undefined => {\n\tif (value?.kind === \"integer\" && target && integerType(target)) {\n\t\tconst integer = BigInt(value.value);\n\t\treturn {\n\t\t\tkind: \"integer\",\n\t\t\tvalue: String(\n\t\t\t\texpression.policy === \"exact\"\n\t\t\t\t\t? integer\n\t\t\t\t\t: applyIntegerPolicy(integer, target, expression.policy),\n\t\t\t),\n\t\t};\n\t}\n\tif (value?.kind === \"integer\" && target?.kind === \"float\") {\n\t\treturn { kind: \"float\", value: roundFloat(Number(value.value), target) };\n\t}\n\tif (value?.kind === \"float\" && target?.kind === \"float\") {\n\t\treturn {\n\t\t\tkind: \"float\",\n\t\t\tvalue:\n\t\t\t\texpression.policy === \"saturate\"\n\t\t\t\t\t? saturateFloat(value.value, target)\n\t\t\t\t\t: roundFloat(value.value, target),\n\t\t};\n\t}\n\treturn undefined;\n};\n\nconst foldUnary = (\n\texpression: Extract<Expression, { kind: \"unary\" }>,\n\tvalue: Constant | undefined,\n\ttarget: PlcType | undefined,\n): Constant | undefined => {\n\tif (\n\t\tvalue?.kind === \"duration\" &&\n\t\texpression.operator === \"timeToMilliseconds\"\n\t) {\n\t\treturn {\n\t\t\tkind: \"integer\",\n\t\t\tvalue: String(BigInt(value.nanoseconds) / nanosecondsPerMillisecond),\n\t\t};\n\t}\n\tif (value?.kind === \"float\" && isElementary(expression.operator)) {\n\t\treturn finiteFloat(\n\t\t\telementaryValue[expression.operator](value.value),\n\t\t\ttarget,\n\t\t);\n\t}\n\tif (value?.kind === \"float\" && expression.operator === \"truncate\") {\n\t\treturn finiteFloat(Math.trunc(value.value), target);\n\t}\n\tif (value?.kind === \"bool\" && expression.operator === \"not\") {\n\t\treturn { kind: \"bool\", value: !value.value };\n\t}\n\tif (\n\t\tvalue?.kind === \"integer\" &&\n\t\texpression.operator === \"bitNot\" &&\n\t\ttarget?.kind === \"bits\"\n\t) {\n\t\treturn {\n\t\t\tkind: \"integer\",\n\t\t\tvalue: String(applyIntegerPolicy(~BigInt(value.value), target, \"wrap\")),\n\t\t};\n\t}\n\tif (value?.kind === \"integer\" && expression.operator === \"negate\") {\n\t\treturn { kind: \"integer\", value: String(-BigInt(value.value)) };\n\t}\n\tif (value?.kind === \"float\" && expression.operator === \"negate\") {\n\t\treturn { kind: \"float\", value: -value.value };\n\t}\n\treturn undefined;\n};\n\ntype Ordered = Exclude<Constant, { kind: \"bool\" | \"array\" | \"record\" }>;\n\nconst ordered = (value: Constant): value is Ordered =>\n\tvalue.kind !== \"bool\" && value.kind !== \"array\" && value.kind !== \"record\";\n\n/** The value two constants of one kind compare as; durations compare by nanoseconds. */\nconst comparable = (value: Ordered): bigint | number | string => {\n\tswitch (value.kind) {\n\t\tcase \"integer\":\n\t\t\treturn BigInt(value.value);\n\t\tcase \"duration\":\n\t\t\treturn BigInt(value.nanoseconds);\n\t\tdefault:\n\t\t\treturn value.value;\n\t}\n};\n\nconst foldBinary = (\n\texpression: Extract<Expression, { kind: \"binary\" }>,\n\tleft: Constant,\n\tright: Constant,\n\ttarget: PlcType | undefined,\n): Constant | undefined => {\n\tif (left.kind === \"bool\" && right.kind === \"bool\") {\n\t\tconst value = booleanOperation(\n\t\t\texpression.operator,\n\t\t\tleft.value,\n\t\t\tright.value,\n\t\t);\n\t\treturn value === undefined ? undefined : { kind: \"bool\", value };\n\t}\n\tif (left.kind !== right.kind || !ordered(left) || !ordered(right)) {\n\t\treturn undefined;\n\t}\n\tconst compared = compare(\n\t\texpression.operator,\n\t\tcomparable(left),\n\t\tcomparable(right),\n\t);\n\tif (compared !== undefined) {\n\t\treturn { kind: \"bool\", value: compared };\n\t}\n\tif (left.kind === \"integer\" && right.kind === \"integer\") {\n\t\tconst value = integerArithmetic(\n\t\t\texpression.operator,\n\t\t\tBigInt(left.value),\n\t\t\tBigInt(right.value),\n\t\t);\n\t\tif (value === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst wrapped =\n\t\t\ttarget &&\n\t\t\tintegerType(target) &&\n\t\t\t(expression.policy || target.kind === \"bits\")\n\t\t\t\t? applyIntegerPolicy(value, target, expression.policy ?? \"wrap\")\n\t\t\t\t: value;\n\t\treturn { kind: \"integer\", value: String(wrapped) };\n\t}\n\tif (left.kind === \"float\" && right.kind === \"float\") {\n\t\tconst value = floatArithmetic(expression.operator, left.value, right.value);\n\t\tif (value === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tkind: \"float\",\n\t\t\tvalue: target?.kind === \"float\" ? roundFloat(value, target) : value,\n\t\t};\n\t}\n\treturn undefined;\n};\n\n/** A float result as its type holds it, or nothing when it isn't finite, as NaN and infinities aren't constants. */\nconst finiteFloat = (\n\tvalue: number,\n\ttarget: PlcType | undefined,\n): Constant | undefined => {\n\tconst rounded = target?.kind === \"float\" ? roundFloat(value, target) : value;\n\treturn Number.isFinite(rounded)\n\t\t? { kind: \"float\", value: rounded }\n\t\t: undefined;\n};\n",
11
- "import {\n\ttype ElementaryFunction,\n\tfloatMaximum,\n\tisElementary,\n\troundFloat,\n} from \"@tsplc/iec/arithmetic\";\nimport { fold } from \"./fold\";\nimport {\n\ttype Constant,\n\tcomparisonOperators,\n\ttype Expression,\n\ttype Variable,\n} from \"./model\";\nimport {\n\tadmits,\n\tcanAssign,\n\tconstantFits,\n\texactIntegerLimit,\n\ttype IntegerInterval,\n\tintegerType,\n\twithin,\n\twrapsNatively,\n} from \"./numeric\";\nimport { interval } from \"./ranges\";\nimport { integerRange, type PlcType } from \"./types\";\n\n/** An operand's constant value and proved integer range, over the storage in scope. */\ninterface Proof {\n\tfold: (value: Expression) => Constant | undefined;\n\tinterval: (value: Expression) => IntegerInterval | undefined;\n}\n\nconst scalarKinds: ReadonlySet<PlcType[\"kind\"]> = new Set([\n\t\"bool\",\n\t\"integer\",\n\t\"bits\",\n\t\"float\",\n]);\n\nexport const scalarIssue = (\n\texpression: Expression,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tvariables: ReadonlyMap<string, Variable>,\n\tranges: ReadonlyMap<string, IntegerInterval> = new Map(),\n): string | undefined => {\n\tconst proof: Proof = {\n\t\tfold: (value) => fold(value, variables, types),\n\t\tinterval: (value) => interval(value, types, variables, ranges),\n\t};\n\tconst type = types.get(expression.type);\n\tif (!type || !scalarKinds.has(type.kind)) {\n\t\treturn \"Unknown scalar expression type.\";\n\t}\n\tif (expression.kind === \"constant\") {\n\t\treturn constantFits(expression.value, type)\n\t\t\t? undefined\n\t\t\t: \"Literal is outside its PLC type or has the wrong domain.\";\n\t}\n\tif (expression.kind === \"load\" || expression.kind === \"call\") {\n\t\treturn undefined;\n\t}\n\tif (expression.kind === \"convert\" || expression.kind === \"unary\") {\n\t\tconst source = types.get(expression.operand.type);\n\t\tif (!source) {\n\t\t\treturn \"Unknown operand type.\";\n\t\t}\n\t\treturn expression.kind === \"convert\"\n\t\t\t? conversionIssue(expression, source, type, proof)\n\t\t\t: unaryIssue(expression, source, type, proof);\n\t}\n\tif (expression.kind === \"binary\") {\n\t\tconst left = types.get(expression.left.type);\n\t\tconst right = types.get(expression.right.type);\n\t\tif (!left || !right) {\n\t\t\treturn \"Unknown operand type.\";\n\t\t}\n\t\treturn binaryIssue(expression, left, right, type, proof);\n\t}\n\tif (\"operand\" in expression && !types.has(expression.operand.type)) {\n\t\treturn \"Unknown operand type.\";\n\t}\n\treturn \"Expression has not been reduced to a scalar operation.\";\n};\n\nconst conversionIssue = (\n\texpression: Extract<Expression, { kind: \"convert\" }>,\n\tsource: PlcType,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tif (![\"exact\", \"wrap\", \"saturate\"].includes(expression.policy)) {\n\t\treturn \"Unknown numeric conversion policy.\";\n\t}\n\tif (source.kind === \"bool\" || type.kind === \"bool\") {\n\t\treturn \"Numeric conversions cannot use BOOL.\";\n\t}\n\tif (expression.policy === \"exact\") {\n\t\treturn exactConversionIssue(expression, source, type, proof);\n\t}\n\tif (\n\t\texpression.policy === \"saturate\" &&\n\t\tsource.kind === \"float\" &&\n\t\ttype.kind === \"float\"\n\t) {\n\t\treturn undefined;\n\t}\n\tif (integerType(source) && integerType(type)) {\n\t\treturn undefined;\n\t}\n\treturn expression.policy === \"saturate\"\n\t\t? \"Saturate conversions require two integer/bit-string operands or two floating operands.\"\n\t\t: \"Wrap conversions require integer or bit-string operands.\";\n};\n\nconst exactConversionIssue = (\n\texpression: Extract<Expression, { kind: \"convert\" }>,\n\tsource: PlcType,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tconst value = proof.fold(expression.operand);\n\tif (\n\t\tcanAssign(source, type, value) ||\n\t\t(value &&\n\t\t\tintegerType(source) &&\n\t\t\tintegerType(type) &&\n\t\t\tconstantFits(value, type))\n\t) {\n\t\treturn undefined;\n\t}\n\tif (!integerType(source)) {\n\t\treturn \"Exact conversion cannot be proved lossless.\";\n\t}\n\tif (type.kind === \"float\" && value?.kind === \"integer\") {\n\t\tconst converted = roundFloat(Number(value.value), type);\n\t\tif (\n\t\t\tNumber.isFinite(converted) &&\n\t\t\tNumber.isInteger(converted) &&\n\t\t\tBigInt(converted) === BigInt(value.value)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\tconst proved = proof.interval(expression.operand) ?? integerRange(source);\n\tif (type.kind === \"float\") {\n\t\tconst limit = exactIntegerLimit(type);\n\t\tif (within(proved, [-limit, limit])) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\tif (integerType(type) && within(proved, integerRange(type))) {\n\t\treturn undefined;\n\t}\n\treturn \"Exact conversion cannot be proved lossless.\";\n};\n\nconst unaryIssue = (\n\texpression: Extract<Expression, { kind: \"unary\" }>,\n\tsource: PlcType,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tif (isElementary(expression.operator)) {\n\t\tif (source.kind !== \"float\" || source.id !== type.id) {\n\t\t\treturn \"Elementary functions take and return one floating type.\";\n\t\t}\n\t\treturn domainIssue(expression.operator, expression.operand, type, proof);\n\t}\n\tswitch (expression.operator) {\n\t\tcase \"truncate\":\n\t\t\treturn source.kind === \"float\" && source.id === type.id\n\t\t\t\t? undefined\n\t\t\t\t: \"trunc takes and returns one floating type.\";\n\t\tcase \"clock\":\n\t\t\treturn type.id === \"DINT\"\n\t\t\t\t? undefined\n\t\t\t\t: \"now() returns DINT milliseconds.\";\n\t\tcase \"timeToMilliseconds\":\n\t\t\treturn source.id === \"TIME\" &&\n\t\t\t\tsource.kind === \"duration\" &&\n\t\t\t\ttype.id === \"UDINT\"\n\t\t\t\t? undefined\n\t\t\t\t: \"timeToMilliseconds requires TIME and returns UDINT.\";\n\t\tcase \"not\":\n\t\t\treturn type.kind === \"bool\" && source.kind === \"bool\"\n\t\t\t\t? undefined\n\t\t\t\t: \"Logical negation requires BOOL.\";\n\t\tcase \"bitNot\":\n\t\t\treturn type.kind === \"bits\" && source.id === type.id\n\t\t\t\t? undefined\n\t\t\t\t: \"Bitwise complement requires a bit string.\";\n\t\tcase \"negate\":\n\t\t\tif (\n\t\t\t\tsource.id !== type.id ||\n\t\t\t\t!(type.kind === \"integer\" || type.kind === \"float\")\n\t\t\t) {\n\t\t\t\treturn \"Numeric negation requires one arithmetic type.\";\n\t\t\t}\n\t\t\treturn resultIssue(expression, type, proof);\n\t}\n};\n\nconst binaryIssue = (\n\texpression: Extract<Expression, { kind: \"binary\" }>,\n\tleft: PlcType,\n\tright: PlcType,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tif (expression.operator === \"and\" || expression.operator === \"or\") {\n\t\treturn type.kind === \"bool\" && left.kind === \"bool\" && right.kind === \"bool\"\n\t\t\t? undefined\n\t\t\t: \"Logical operators require BOOL.\";\n\t}\n\tif (comparisonOperators.has(expression.operator)) {\n\t\treturn type.kind === \"bool\" &&\n\t\t\tleft.id === right.id &&\n\t\t\tscalarKinds.has(left.kind) &&\n\t\t\t(left.kind !== \"bool\" ||\n\t\t\t\t[\"equal\", \"notEqual\"].includes(expression.operator))\n\t\t\t? undefined\n\t\t\t: \"Comparison operands need the same PLC domain.\";\n\t}\n\tif (\n\t\t[\"bitAnd\", \"bitOr\", \"bitXor\", \"shiftLeft\", \"shiftRight\"].includes(\n\t\t\texpression.operator,\n\t\t)\n\t) {\n\t\tif (type.kind !== \"bits\" || left.id !== type.id) {\n\t\t\treturn \"Bitwise operators require bit strings.\";\n\t\t}\n\t\tif (\n\t\t\texpression.operator === \"shiftLeft\" ||\n\t\t\texpression.operator === \"shiftRight\"\n\t\t) {\n\t\t\tconst count = proof.fold(expression.right);\n\t\t\treturn count?.kind === \"integer\" &&\n\t\t\t\tBigInt(count.value) >= 0n &&\n\t\t\t\tBigInt(count.value) < BigInt(type.bits)\n\t\t\t\t? undefined\n\t\t\t\t: \"Shift count must be a compile-time integer within the bit width.\";\n\t\t}\n\t\treturn right.id === type.id ? undefined : \"Bit-string widths differ.\";\n\t}\n\tif (expression.operator === \"power\") {\n\t\tif (type.kind !== \"float\" || left.id !== type.id || right.id !== type.id) {\n\t\t\treturn \"A power takes and returns one floating type.\";\n\t\t}\n\t\treturn powerIssue(expression, type, proof);\n\t}\n\tif (\n\t\tleft.id !== type.id ||\n\t\tright.id !== type.id ||\n\t\t(type.kind !== \"integer\" && type.kind !== \"float\")\n\t) {\n\t\treturn \"Arithmetic operands need one integer or floating type.\";\n\t}\n\tif (expression.policy) {\n\t\treturn type.kind === \"integer\" &&\n\t\t\t[\"add\", \"subtract\", \"multiply\"].includes(expression.operator)\n\t\t\t? undefined\n\t\t\t: \"Explicit arithmetic policies require integer addition, subtraction or multiplication.\";\n\t}\n\tif (\n\t\t(expression.operator === \"divide\" || expression.operator === \"remainder\") &&\n\t\ttype.kind === \"integer\"\n\t) {\n\t\tconst divisor = proof.interval(expression.right);\n\t\tif (!divisor || admits(divisor, 0n)) {\n\t\t\treturn \"Division requires a proved nonzero divisor.\";\n\t\t}\n\t\tconst dividend = proof.interval(expression.left);\n\t\tconst [minimum] = integerRange(type);\n\t\tif (\n\t\t\ttype.signed &&\n\t\t\tdividend &&\n\t\t\tdividend[0] <= minimum &&\n\t\t\tadmits(divisor, -1n)\n\t\t) {\n\t\t\treturn \"Signed minimum divided by -1 cannot be represented.\";\n\t\t}\n\t}\n\treturn resultIssue(expression, type, proof);\n};\n\n/**\n * The bounds a floating operand is proved to keep: a constant's value, or the proved range of an\n * integer converted to it exactly. Other floating values have no proved bounds.\n */\nconst floatBounds = (\n\texpression: Expression,\n\tproof: Proof,\n): readonly [number, number] | undefined => {\n\tconst value = proof.fold(expression);\n\tif (value?.kind === \"float\") {\n\t\treturn [value.value, value.value];\n\t}\n\tif (value?.kind === \"integer\") {\n\t\treturn [Number(value.value), Number(value.value)];\n\t}\n\tif (expression.kind === \"convert\" && expression.policy === \"exact\") {\n\t\tconst proved = proof.interval(expression.operand);\n\t\treturn proved && [Number(proved[0]), Number(proved[1])];\n\t}\n\treturn undefined;\n};\n\n/** Where each elementary function's result is finite, and what to prove when its operand may leave there. */\nconst domains: Readonly<\n\tRecord<\n\t\tElementaryFunction,\n\t\t| {\n\t\t\t\tholds: (low: number, high: number, type: PlcType) => boolean;\n\t\t\t\tneeds: string;\n\t\t }\n\t\t| undefined\n\t>\n> = {\n\tsqrt: { holds: (low) => low >= 0, needs: \"not negative\" },\n\tln: { holds: (low) => low > 0, needs: \"greater than zero\" },\n\tlog10: { holds: (low) => low > 0, needs: \"greater than zero\" },\n\texp: {\n\t\tholds: (_, high, type) =>\n\t\t\ttype.kind === \"float\" &&\n\t\t\tNumber.isFinite(roundFloat(Math.exp(high), type)),\n\t\tneeds: \"small enough for a finite result\",\n\t},\n\tasin: {\n\t\tholds: (low, high) => low >= -1 && high <= 1,\n\t\tneeds: \"between -1 and 1\",\n\t},\n\tacos: {\n\t\tholds: (low, high) => low >= -1 && high <= 1,\n\t\tneeds: \"between -1 and 1\",\n\t},\n\tsin: undefined,\n\tcos: undefined,\n\ttan: undefined,\n\tatan: undefined,\n};\n\n/** A finite float operand keeps sine, cosine, tangent and arctangent finite; the others need their operand's domain proved. */\nconst domainIssue = (\n\toperator: ElementaryFunction,\n\toperand: Expression,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tconst domain = domains[operator];\n\tif (!domain) {\n\t\treturn undefined;\n\t}\n\tconst bounds = floatBounds(operand, proof);\n\tif (bounds && domain.holds(bounds[0], bounds[1], type)) {\n\t\treturn undefined;\n\t}\n\treturn `${operator} needs its operand proved ${domain.needs}, as a constant or an integer converted exactly is.`;\n};\n\n/** A power needs a constant exponent and a base whose proved bounds keep the result real and finite. */\nconst powerIssue = (\n\texpression: Extract<Expression, { kind: \"binary\" }>,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tconst folded = proof.fold(expression);\n\tif (folded) {\n\t\treturn constantFits(folded, type)\n\t\t\t? undefined\n\t\t\t: \"Floating result is not finite or representable.\";\n\t}\n\tconst exponent = proof.fold(expression.right);\n\tconst base = floatBounds(expression.left, proof);\n\tif (exponent?.kind !== \"float\" || !base || type.kind !== \"float\") {\n\t\treturn \"A power needs a constant exponent and a base proved within bounds, as a constant or an integer converted exactly is.\";\n\t}\n\tconst [low, high] = base;\n\tif (!Number.isInteger(exponent.value) && low < 0) {\n\t\treturn \"A fractional power needs its base proved not negative.\";\n\t}\n\tif (exponent.value < 0 && low <= 0 && high >= 0) {\n\t\treturn \"A negative power needs its base proved not zero.\";\n\t}\n\tconst magnitudes = [Math.abs(low), Math.abs(high)];\n\tconst largest =\n\t\texponent.value >= 0\n\t\t\t? Math.max(...magnitudes) ** exponent.value\n\t\t\t: Math.min(...magnitudes) ** exponent.value;\n\treturn Number.isFinite(roundFloat(largest, type))\n\t\t? undefined\n\t\t: \"The power may not be finite.\";\n};\n\n/** Whether an arithmetic result is proved to stay in its integer type, or finite in its float type. */\nconst resultIssue = (\n\texpression: Extract<Expression, { kind: \"unary\" | \"binary\" }>,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tif (integerType(type)) {\n\t\tconst result = proof.interval(expression);\n\t\tif (\n\t\t\t!(wrapsNatively(expression) && !proof.fold(expression)) &&\n\t\t\t(!result || !within(result, integerRange(type)))\n\t\t) {\n\t\t\treturn \"Arithmetic may overflow; widen the result or use an explicit wrap/saturate operation.\";\n\t\t}\n\t\treturn undefined;\n\t}\n\tif (type.kind !== \"float\") {\n\t\treturn undefined;\n\t}\n\tconst result = proof.fold(expression);\n\tif (result) {\n\t\treturn constantFits(result, type)\n\t\t\t? undefined\n\t\t\t: \"Floating result is not finite or representable.\";\n\t}\n\tif (expression.kind === \"unary\") {\n\t\treturn undefined;\n\t}\n\tconst lhs = proof.fold(expression.left);\n\tconst rhs = proof.fold(expression.right);\n\tif (\n\t\t[\"add\", \"subtract\"].includes(expression.operator) &&\n\t\t(lhs?.kind === \"float\" || rhs?.kind === \"float\")\n\t) {\n\t\t// Addition/subtraction and nearest rounding are monotone. Checking both\n\t\t// finite endpoints proves every finite input without changing its arithmetic.\n\t\tconst maximum = floatMaximum(type);\n\t\tconst finite = [-maximum, maximum].every((endpoint) => {\n\t\t\tconst a = lhs?.kind === \"float\" ? lhs.value : endpoint;\n\t\t\tconst b = rhs?.kind === \"float\" ? rhs.value : endpoint;\n\t\t\tconst value = expression.operator === \"add\" ? a + b : a - b;\n\t\t\treturn Number.isFinite(roundFloat(value, type));\n\t\t});\n\t\tif (finite) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\tif (\n\t\trhs?.kind === \"float\" &&\n\t\trhs.value === 1 &&\n\t\t[\"multiply\", \"divide\"].includes(expression.operator)\n\t) {\n\t\treturn undefined;\n\t}\n\treturn \"Floating arithmetic must prove a finite result.\";\n};\n",
12
- "// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.\nimport { calendarZero, domainConstantFits, domainIssue } from \"./domains\";\nimport {\n\ttype Constant,\n\tcomparisonOperators,\n\ttype Expression,\n\ttype Place,\n\ttype Variable,\n} from \"./model\";\nimport { constantFits, type IntegerInterval } from \"./numeric\";\nimport { interval } from \"./ranges\";\nimport { scalarIssue } from \"./scalars\";\nimport type { PlcType } from \"./types\";\n\nexport function aggregate(type: PlcType | undefined): boolean {\n\treturn type?.kind === \"record\" || type?.kind === \"array\";\n}\nexport function valueFits(\n\tvalue: Constant,\n\ttype: PlcType,\n\ttypes: ReadonlyMap<string, PlcType>,\n): boolean {\n\tif (type.kind === \"duration\" || type.kind === \"calendar\") {\n\t\treturn domainConstantFits(value, type);\n\t}\n\tif (type.kind === \"enum\") {\n\t\treturn (\n\t\t\tvalue.kind === \"integer\" &&\n\t\t\ttype.members.some((member) => member.value === value.value)\n\t\t);\n\t}\n\tif (type.kind === \"string\") {\n\t\treturn (\n\t\t\tvalue.kind === \"string\" &&\n\t\t\t!value.value.includes(\"\\0\") &&\n\t\t\t(type.encoding === \"utf8\"\n\t\t\t\t? new TextEncoder().encode(value.value).length <= type.capacity\n\t\t\t\t: value.value.length <= type.capacity)\n\t\t);\n\t}\n\tif (type.kind === \"array\") {\n\t\treturn (\n\t\t\tvalue.kind === \"array\" &&\n\t\t\tvalue.items.length === type.length &&\n\t\t\tvalue.items.every((item) =>\n\t\t\t\tvalueFits(item, types.get(type.element)!, types),\n\t\t\t)\n\t\t);\n\t}\n\tif (type.kind === \"record\") {\n\t\treturn (\n\t\t\tvalue.kind === \"record\" &&\n\t\t\tObject.keys(value.fields).length === type.fields.length &&\n\t\t\ttype.fields.every(\n\t\t\t\t(field) =>\n\t\t\t\t\tObject.hasOwn(value.fields, field.name) &&\n\t\t\t\t\tvalueFits(value.fields[field.name]!, types.get(field.type)!, types),\n\t\t\t)\n\t\t);\n\t}\n\treturn constantFits(value, type);\n}\nexport function defaultValue(\n\ttypeId: string,\n\ttypes: ReadonlyMap<string, PlcType>,\n): Constant {\n\tconst type = types.get(typeId);\n\tif (!type) {\n\t\tthrow new Error(\"Unknown default-value type\");\n\t}\n\tif (type.kind === \"bool\") {\n\t\treturn { kind: \"bool\", value: false };\n\t}\n\tif (type.kind === \"float\") {\n\t\treturn { kind: \"float\", value: 0 };\n\t}\n\tif (type.kind === \"string\") {\n\t\treturn { kind: \"string\", value: \"\" };\n\t}\n\tif (type.kind === \"enum\") {\n\t\treturn {\n\t\t\tkind: \"integer\",\n\t\t\tvalue:\n\t\t\t\ttype.members.find((member) => member.value === \"0\")?.value ??\n\t\t\t\ttype.members[0]!.value,\n\t\t};\n\t}\n\tif (type.kind === \"array\") {\n\t\treturn {\n\t\t\tkind: \"array\",\n\t\t\titems: Array.from({ length: type.length }, () =>\n\t\t\t\tdefaultValue(type.element, types),\n\t\t\t),\n\t\t};\n\t}\n\tif (type.kind === \"record\") {\n\t\treturn {\n\t\t\tkind: \"record\",\n\t\t\tfields: Object.fromEntries(\n\t\t\t\ttype.fields.map((field) => [\n\t\t\t\t\tfield.name,\n\t\t\t\t\tdefaultValue(field.type, types),\n\t\t\t\t]),\n\t\t\t),\n\t\t};\n\t}\n\tif (type.kind === \"duration\") {\n\t\treturn { kind: \"duration\", nanoseconds: \"0\" };\n\t}\n\tif (type.kind === \"calendar\") {\n\t\treturn { kind: \"calendar\", value: calendarZero[type.domain] };\n\t}\n\tif (type.kind === \"integer\" || type.kind === \"bits\") {\n\t\treturn { kind: \"integer\", value: \"0\" };\n\t}\n\tthrow new Error(\"Unsupported default-value type\");\n}\nexport function placeType(\n\tplace: Place,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tvariables: ReadonlyMap<string, Variable>,\n\tranges: ReadonlyMap<string, IntegerInterval> = new Map(),\n\twritable = false,\n): { type?: string; issue?: string } {\n\tconst root = variables.get(place.root);\n\tif (!root) {\n\t\treturn { issue: \"Unknown storage root.\" };\n\t}\n\tif (\n\t\twritable &&\n\t\t(root.storage === \"input\" ||\n\t\t\troot.storage === \"constant\" ||\n\t\t\troot.storage === \"blockOutput\" ||\n\t\t\t(root.storage === \"parameter\" && root.mode !== \"inOut\") ||\n\t\t\t(!place.path.length && !root.mutable))\n\t) {\n\t\treturn { issue: \"This storage is read-only.\" };\n\t}\n\tlet id = root.type;\n\tfor (const segment of place.path) {\n\t\tconst type = types.get(id);\n\t\tif (segment.kind === \"field\") {\n\t\t\tif (type?.kind === \"block\" && segment.name === \"out\" && type.output) {\n\t\t\t\tif (writable) {\n\t\t\t\t\treturn { issue: \"Function block output views are read-only.\" };\n\t\t\t\t}\n\t\t\t\tid = type.output;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (type?.kind !== \"record\") {\n\t\t\t\treturn { issue: \"Field access requires a record.\" };\n\t\t\t}\n\t\t\tconst field = type.fields.find((field) => field.name === segment.name);\n\t\t\tif (!field) {\n\t\t\t\treturn { issue: \"Unknown record field.\" };\n\t\t\t}\n\t\t\tif (writable && field.readonly) {\n\t\t\t\treturn { issue: \"This field is read-only.\" };\n\t\t\t}\n\t\t\tid = field.type;\n\t\t} else {\n\t\t\tif (type?.kind !== \"array\") {\n\t\t\t\treturn { issue: \"Index access requires a fixed array.\" };\n\t\t\t}\n\t\t\t// Enum values are closed, and the layout check below proves its members are the bounds.\n\t\t\t// An integer, such as a for…of counter, still needs its bounds proof.\n\t\t\tif (type.index && segment.value.type === type.index) {\n\t\t\t\tid = type.element;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst indexType = types.get(segment.value.type);\n\t\t\tconst bounds = interval(segment.value, types, variables, ranges);\n\t\t\tif (\n\t\t\t\tindexType?.kind !== \"integer\" ||\n\t\t\t\t!bounds ||\n\t\t\t\tbounds[0] < BigInt(type.lowerBound) ||\n\t\t\t\tbounds[1] >= BigInt(type.lowerBound + type.length)\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\tissue: \"Array index must be proved within the declared bounds.\",\n\t\t\t\t};\n\t\t\t}\n\t\t\tid = type.element;\n\t\t}\n\t}\n\treturn { type: id };\n}\nexport function aggregateIssue(\n\tvalue: Expression,\n\ttypes: ReadonlyMap<string, PlcType>,\n): string | undefined {\n\tconst type = types.get(value.type);\n\tif (!type) {\n\t\treturn \"Unknown expression type.\";\n\t}\n\tif (value.kind === \"constant\") {\n\t\treturn valueFits(value.value, type, types)\n\t\t\t? undefined\n\t\t\t: \"Constant does not fit its closed PLC layout.\";\n\t}\n\tif (value.kind === \"record\") {\n\t\treturn type.kind === \"record\" &&\n\t\t\tObject.keys(value.fields).length === type.fields.length &&\n\t\t\ttype.fields.every(\n\t\t\t\t(field) =>\n\t\t\t\t\tObject.hasOwn(value.fields, field.name) &&\n\t\t\t\t\tvalue.fields[field.name]?.type === field.type,\n\t\t\t)\n\t\t\t? undefined\n\t\t\t: \"Record expression differs from its layout.\";\n\t}\n\tif (value.kind === \"array\") {\n\t\treturn type.kind === \"array\" &&\n\t\t\tvalue.items.length === type.length &&\n\t\t\tvalue.items.every((item) => item.type === type.element)\n\t\t\t? undefined\n\t\t\t: \"Array expression differs from its layout.\";\n\t}\n\tif (value.kind === \"copy\") {\n\t\treturn aggregate(type) && value.operand.type === value.type\n\t\t\t? undefined\n\t\t\t: \"Copy requires one matching fixed aggregate.\";\n\t}\n\tif (value.kind === \"convert\") {\n\t\tconst source = types.get(value.operand.type);\n\t\treturn type.kind === \"string\" &&\n\t\t\tsource?.kind === \"string\" &&\n\t\t\tsource.encoding === type.encoding &&\n\t\t\tsource.capacity <= type.capacity &&\n\t\t\tvalue.policy === \"exact\"\n\t\t\t? undefined\n\t\t\t: \"Unsupported aggregate/domain conversion.\";\n\t}\n\tif (\n\t\tvalue.kind === \"load\" ||\n\t\tvalue.kind === \"call\" ||\n\t\tvalue.kind === \"conditional\"\n\t) {\n\t\treturn undefined;\n\t}\n\tif (value.kind === \"binary\" && comparisonOperators.has(value.operator)) {\n\t\tconst left = types.get(value.left.type);\n\t\treturn value.type === \"BOOL\" &&\n\t\t\tleft &&\n\t\t\t[\"enum\", \"string\"].includes(left.kind) &&\n\t\t\tvalue.left.type === value.right.type &&\n\t\t\t(left.kind !== \"enum\" || [\"equal\", \"notEqual\"].includes(value.operator))\n\t\t\t? undefined\n\t\t\t: \"Comparison requires compatible scalar domains; object identity is unsupported.\";\n\t}\n\treturn \"Operation is unsupported for this PLC domain.\";\n}\n\n// Route a reduced expression to the checker that owns its PLC domain. A binary\n// operation belongs to its operand domain, e.g. a TIME comparison yields BOOL.\nexport function expressionIssue(\n\tvalue: Expression,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tvariables: ReadonlyMap<string, Variable>,\n\tranges: ReadonlyMap<string, IntegerInterval>,\n): string | undefined {\n\tconst kinds = [\n\t\tvalue.type,\n\t\t...(value.kind === \"binary\" ? [value.left.type] : []),\n\t].map((id) => types.get(id)?.kind ?? \"\");\n\tif (kinds.some((kind) => [\"duration\", \"calendar\"].includes(kind))) {\n\t\treturn domainIssue(value, types);\n\t}\n\tif (\n\t\t[\"copy\", \"record\", \"array\"].includes(value.kind) ||\n\t\tkinds.some((kind) => [\"record\", \"array\", \"enum\", \"string\"].includes(kind))\n\t) {\n\t\treturn aggregateIssue(value, types);\n\t}\n\treturn scalarIssue(value, types, variables, ranges);\n}\n",
13
- "import type { BinaryOperator, UnaryOperator } from \"@tsplc/iec/arithmetic\";\nimport type { SourceSpan } from \"./diagnostics\";\nimport type {\n\tConstant,\n\tFunctionBlock,\n\tMethodOwner,\n\tPlcFunction,\n\tPlcModule,\n\tPlcProgram,\n\tTelemetryCall,\n\tVariable,\n} from \"./model\";\nimport type { PlcType } from \"./types\";\n\n// Core expressions contain no source-level calls. Their effects have already\n// become ordered statements, and every place has passed storage/bounds checks.\nexport type CorePath = readonly (\n\t| { readonly kind: \"field\"; readonly name: string }\n\t| { readonly kind: \"index\"; readonly value: CoreExpression }\n)[];\nexport interface CheckedPlace {\n\treadonly root: string;\n\treadonly path: CorePath;\n}\nexport type CoreExpression = {\n\treadonly type: string;\n\treadonly span: SourceSpan;\n} & (\n\t| { readonly kind: \"borrow\"; readonly place: CheckedPlace }\n\t| { readonly kind: \"constant\"; readonly value: Constant }\n\t| { readonly kind: \"load\"; readonly root: string; readonly path?: CorePath }\n\t| {\n\t\t\treadonly kind: \"unary\";\n\t\t\treadonly operator: UnaryOperator;\n\t\t\treadonly operand: CoreExpression;\n\t }\n\t| {\n\t\t\treadonly kind: \"binary\";\n\t\t\treadonly operator: BinaryOperator;\n\t\t\treadonly left: CoreExpression;\n\t\t\treadonly right: CoreExpression;\n\t\t\treadonly policy?: \"wrap\" | \"saturate\";\n\t }\n\t| {\n\t\t\treadonly kind: \"convert\";\n\t\t\treadonly operand: CoreExpression;\n\t\t\treadonly policy: \"exact\" | \"wrap\" | \"saturate\";\n\t }\n);\nexport type CoreStatement = { readonly span: SourceSpan } & (\n\t| {\n\t\t\treadonly kind: \"assign\";\n\t\t\treadonly root: string;\n\t\t\treadonly path?: CorePath;\n\t\t\treadonly value: CoreExpression;\n\t }\n\t| {\n\t\t\treadonly kind: \"if\";\n\t\t\treadonly condition: CoreExpression;\n\t\t\treadonly then: readonly CoreStatement[];\n\t\t\treadonly else: readonly CoreStatement[];\n\t }\n\t| {\n\t\t\treadonly kind: \"switch\";\n\t\t\treadonly value: CoreExpression;\n\t\t\treadonly cases: readonly {\n\t\t\t\tvalues: readonly Constant[];\n\t\t\t\tbody: readonly CoreStatement[];\n\t\t\t}[];\n\t\t\treadonly fallback: readonly CoreStatement[];\n\t }\n\t| {\n\t\t\treadonly kind: \"for\";\n\t\t\treadonly counter: string;\n\t\t\treadonly counterScope?: \"existing\";\n\t\t\treadonly start: Constant;\n\t\t\treadonly limit: Constant;\n\t\t\treadonly step: string;\n\t\t\treadonly dynamic?: {\n\t\t\t\treadonly start: CoreExpression;\n\t\t\t\treadonly limit: CoreExpression;\n\t\t\t\treadonly exclusive?: true;\n\t\t\t};\n\t\t\treadonly maxIterations: number;\n\t\t\treadonly body: readonly CoreStatement[];\n\t }\n\t| {\n\t\t\treadonly kind: \"invoke\";\n\t\t\treadonly function: string;\n\t\t\treadonly instance?: string;\n\t\t\treadonly index?: CoreExpression;\n\t\t\treadonly arguments: readonly CoreExpression[];\n\t\t\treadonly destination?: string;\n\t }\n\t| {\n\t\t\treadonly kind: \"blockUpdate\";\n\t\t\treadonly instance: string;\n\t\t\treadonly index?: CoreExpression;\n\t\t\treadonly inputs: Readonly<Record<string, CoreExpression>>;\n\t }\n\t| { readonly kind: \"return\"; readonly value?: CoreExpression }\n\t| { readonly kind: \"break\" | \"continue\" }\n\t| ({ readonly kind: \"telemetry\" } & TelemetryCall<CoreExpression>)\n);\n/** The statement lists nested directly inside a statement. */\nexport const nestedBodies = (\n\titem: CoreStatement,\n): readonly (readonly CoreStatement[])[] => {\n\tif (item.kind === \"if\") {\n\t\treturn [item.then, item.else];\n\t}\n\tif (item.kind === \"switch\") {\n\t\treturn [...item.cases.map((branch) => branch.body), item.fallback];\n\t}\n\tif (item.kind === \"for\") {\n\t\treturn [item.body];\n\t}\n\treturn [];\n};\n/**\n * The storage roots a statement writes itself, in statement order: an assignment's target, a\n * loop's counter, a call's destination and every place it borrows. Nested bodies and the\n * routines a call runs are the caller's to follow.\n */\nexport const directWrites = (item: CoreStatement): readonly string[] => {\n\tif (item.kind === \"assign\") {\n\t\treturn [item.root];\n\t}\n\tif (item.kind === \"for\") {\n\t\treturn [item.counter];\n\t}\n\tif (item.kind === \"invoke\") {\n\t\treturn [\n\t\t\t...(item.destination ? [item.destination] : []),\n\t\t\t...item.arguments.flatMap((argument) =>\n\t\t\t\targument.kind === \"borrow\" ? [argument.place.root] : [],\n\t\t\t),\n\t\t];\n\t}\n\tif (item.kind === \"blockUpdate\") {\n\t\treturn Object.values(item.inputs).flatMap((input) =>\n\t\t\tinput.kind === \"borrow\" ? [input.place.root] : [],\n\t\t);\n\t}\n\treturn [];\n};\nexport interface CoreFunction {\n\treadonly owner?: MethodOwner;\n\treadonly origin?: PlcFunction[\"origin\"];\n\treadonly id: string;\n\treadonly name: string;\n\treadonly parameters: readonly Variable[];\n\treadonly result?: string;\n\treadonly locals: readonly Variable[];\n\treadonly body: readonly CoreStatement[];\n\treadonly span: SourceSpan;\n}\nexport interface CoreFunctionBlock\n\textends Readonly<Omit<FunctionBlock, \"body\">> {\n\treadonly body: readonly CoreStatement[];\n}\nexport const verified: unique symbol = Symbol(\"verified core\");\nexport interface VerifiedCoreModule {\n\treadonly [verified]: true;\n\treadonly folded?: PlcModule[\"folded\"];\n\treadonly references?: PlcModule[\"references\"];\n\treadonly types: readonly PlcType[];\n\treadonly variables: readonly Variable[];\n\treadonly functions: readonly CoreFunction[];\n\treadonly blocks: readonly CoreFunctionBlock[];\n\treadonly programs: readonly PlcProgram[];\n}\n",
14
- "export interface SourceSpan {\n\tfile: string;\n\tstart: number;\n\tend: number;\n\tline: number;\n\tcolumn: number;\n}\n\nexport interface Diagnostic {\n\torigin: \"typescript\" | \"plc\" | \"config\" | \"backend\" | \"vendor\";\n\tcode: string;\n\tseverity: \"error\" | \"warning\";\n\tmessage: string;\n\tspan?: SourceSpan;\n\tnotes?: readonly string[];\n\trelated?: readonly { span: SourceSpan; message: string }[];\n}\n\nexport function error(\n\tcode: string,\n\tmessage: string,\n\tspan?: SourceSpan,\n): Diagnostic {\n\treturn {\n\t\torigin: \"plc\",\n\t\tcode,\n\t\tseverity: \"error\",\n\t\tmessage,\n\t\t...(span && { span }),\n\t};\n}\n\nexport function hasErrors(diagnostics: readonly Diagnostic[]): boolean {\n\treturn diagnostics.some((diagnostic) => diagnostic.severity === \"error\");\n}\n\nexport function formatDiagnostic(\n\tdiagnostic: Diagnostic,\n\tsource?: string,\n): string {\n\tconst { span } = diagnostic;\n\tconst location = span ? `${span.file}:${span.line}:${span.column}: ` : \"\";\n\tlet result = `${location}${diagnostic.code}: ${diagnostic.message}`;\n\tif (source !== undefined && span) {\n\t\tconst line = source.split(/\\r?\\n/)[span.line - 1];\n\t\tif (line !== undefined) {\n\t\t\tconst width = Math.max(\n\t\t\t\t1,\n\t\t\t\tMath.min(span.end - span.start, line.length - span.column + 2),\n\t\t\t);\n\t\t\tresult += `\\n${span.line} | ${line}\\n${\" \".repeat(String(span.line).length + 3 + span.column - 1)}${\"^\".repeat(width)}`;\n\t\t}\n\t}\n\tfor (const related of diagnostic.related ?? []) {\n\t\tresult += `\\n ${related.span.file}:${related.span.line}:${related.span.column}: ${related.message}`;\n\t}\n\tfor (const note of diagnostic.notes ?? []) {\n\t\tresult += `\\n ${note}`;\n\t}\n\treturn result;\n}\n",
5
+ "export { nanosecondsPerMillisecond } from \"@tsplc/iec\";\nexport {\n\taggregate,\n\taggregateIssue,\n\tdefaultValue,\n\texpressionIssue,\n\tplaceType,\n\tvalueFits,\n} from \"./aggregates\";\nexport {\n\ttype LoopConditions,\n\ttype PathCondition,\n\tpathConditions,\n\tprojectReconstruction,\n\ttype ReconstructedSegment,\n\ttype Reconstruction,\n\ttype RoutineConditions,\n\ttype StatementConditions,\n\tstaticNames,\n} from \"./conditions\";\nexport {\n\ttype CheckedPlace,\n\ttype CoreExpression,\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CorePath,\n\ttype CoreStatement,\n\tconstantIndex,\n\tdirectWrites,\n\tfreeze,\n\tinstanceFields,\n\tisBlockRoutine,\n\tisTemporary,\n\tisVerifiedCore,\n\tnestedBodies,\n\ttype VerifiedCoreModule,\n} from \"./core-model\";\nexport {\n\ttype Diagnostic,\n\terror,\n\tformatDiagnostic,\n\thasErrors,\n\ttype SourceSpan,\n} from \"./diagnostics\";\nexport {\n\tcalendarLiteral,\n\tdomainConstantFits,\n\tdomainIssue,\n\tdurationLiteral,\n} from \"./domains\";\nexport { fold } from \"./fold\";\nexport { identityDigest, pascalCase } from \"./identity\";\nexport {\n\terrorName,\n\tfailureCode,\n\tfailureName,\n\thttpErrors,\n\tjobError,\n\tjobErrors,\n\treservedErrors,\n} from \"./job-errors\";\nexport {\n\ttype LayoutBudget,\n\tlayoutIssue,\n\tmaxNestingDepth,\n\tmaxScalarElements,\n\tmaxScalarElementsText,\n\tmaxStringCapacity,\n} from \"./layouts\";\nexport {\n\ttype Artifact,\n\ttype Constant,\n\tcomparisonOperators,\n\ttype Deployment,\n\ttype EmitResult,\n\ttype Expression,\n\ttype FunctionBlock,\n\ttype GeneratedObject,\n\ttype HttpMethod,\n\thttpMethods,\n\tisLogicalIo,\n\ttype MethodOwner,\n\toptionalRecord,\n\ttype Place,\n\ttype PlcFunction,\n\ttype PlcModule,\n\ttype PlcProgram,\n\ttype Retention,\n\ttype StandardBlock,\n\ttype Statement,\n\tstandardBlocks,\n\ttype Task,\n\ttype TelemetryCall,\n\ttelemetryOperands,\n\ttype Variable,\n} from \"./model\";\nexport { normalizeModule } from \"./normalize\";\nexport {\n\tcanAssign,\n\tconstantFits,\n\texactIntegerLimit,\n\ttype IntegerInterval,\n\tisRadixLiteral,\n\tliteralOutsideType,\n\tparseFloatLiteral,\n\tparseInteger,\n\twrapsNatively,\n} from \"./numeric\";\nexport {\n\tpathIndexes,\n\tstatementExpressions,\n\tsubexpressions,\n} from \"./operands\";\nexport {\n\tinterval,\n\tloopBounds,\n\tmaxLoopIterations,\n\tnarrowRanges,\n} from \"./ranges\";\nexport { scalarIssue } from \"./scalars\";\nexport {\n\tfoldConstantRoutines,\n\ttype SharedRoutines,\n\tshareRoutines,\n} from \"./share\";\nexport { type CoreTables, coreTables } from \"./tables\";\nexport { forwardTemporaries } from \"./temporaries\";\nexport {\n\ttype Field,\n\tinstancedBlock,\n\tintegerRange,\n\tintegerType,\n\ttype PlcType,\n\tprimitiveTypes,\n\ttype SymbolId,\n\ttype TypeId,\n} from \"./types\";\n",
6
+ "import { isComparison } from \"@tsplc/iec/arithmetic\";\nimport {\n\tcalendarZero,\n\tcomparedType,\n\tdomainConstantFits,\n\tdomainIssue,\n} from \"./domains\";\nimport type { Constant, Expression, Place, Variable } from \"./model\";\nimport { constantFits, type IntegerInterval } from \"./numeric\";\nimport { interval } from \"./ranges\";\nimport { scalarIssue } from \"./scalars\";\nimport { lookup } from \"./tables\";\nimport type { PlcType } from \"./types\";\n\nexport function aggregate(type: PlcType | undefined): boolean {\n\treturn type?.kind === \"record\" || type?.kind === \"array\";\n}\nexport function valueFits(\n\tvalue: Constant,\n\ttype: PlcType,\n\ttypes: ReadonlyMap<string, PlcType>,\n): boolean {\n\tif (type.kind === \"duration\" || type.kind === \"calendar\") {\n\t\treturn domainConstantFits(value, type);\n\t}\n\tif (type.kind === \"enum\") {\n\t\treturn (\n\t\t\tvalue.kind === \"integer\" &&\n\t\t\ttype.members.some((member) => member.value === value.value)\n\t\t);\n\t}\n\tif (type.kind === \"string\") {\n\t\treturn (\n\t\t\tvalue.kind === \"string\" &&\n\t\t\t!value.value.includes(\"\\0\") &&\n\t\t\t(type.encoding === \"utf8\"\n\t\t\t\t? new TextEncoder().encode(value.value).length <= type.capacity\n\t\t\t\t: value.value.length <= type.capacity)\n\t\t);\n\t}\n\tif (type.kind === \"array\") {\n\t\treturn (\n\t\t\tvalue.kind === \"array\" &&\n\t\t\tvalue.items.length === type.length &&\n\t\t\tvalue.items.every((item) =>\n\t\t\t\tvalueFits(item, lookup(types, type.element, \"type\"), types),\n\t\t\t)\n\t\t);\n\t}\n\tif (type.kind === \"record\") {\n\t\treturn (\n\t\t\tvalue.kind === \"record\" &&\n\t\t\tObject.keys(value.fields).length === type.fields.length &&\n\t\t\ttype.fields.every((field) => {\n\t\t\t\tconst fieldValue = Object.hasOwn(value.fields, field.name)\n\t\t\t\t\t? value.fields[field.name]\n\t\t\t\t\t: undefined;\n\t\t\t\treturn (\n\t\t\t\t\tfieldValue !== undefined &&\n\t\t\t\t\tvalueFits(fieldValue, lookup(types, field.type, \"type\"), types)\n\t\t\t\t);\n\t\t\t})\n\t\t);\n\t}\n\treturn constantFits(value, type);\n}\nexport function defaultValue(\n\ttypeId: string,\n\ttypes: ReadonlyMap<string, PlcType>,\n): Constant {\n\tconst type = types.get(typeId);\n\tif (!type) {\n\t\tthrow new Error(\"Unknown default-value type\");\n\t}\n\tif (type.kind === \"bool\") {\n\t\treturn { kind: \"bool\", value: false };\n\t}\n\tif (type.kind === \"float\") {\n\t\treturn { kind: \"float\", value: 0 };\n\t}\n\tif (type.kind === \"string\") {\n\t\treturn { kind: \"string\", value: \"\" };\n\t}\n\tif (type.kind === \"enum\") {\n\t\tconst member =\n\t\t\ttype.members.find((item) => item.value === \"0\") ?? type.members[0];\n\t\tif (!member) {\n\t\t\tthrow new Error(`Enum ${type.id} has no members.`);\n\t\t}\n\t\treturn { kind: \"integer\", value: member.value };\n\t}\n\tif (type.kind === \"array\") {\n\t\treturn {\n\t\t\tkind: \"array\",\n\t\t\titems: Array.from({ length: type.length }, () =>\n\t\t\t\tdefaultValue(type.element, types),\n\t\t\t),\n\t\t};\n\t}\n\tif (type.kind === \"record\") {\n\t\treturn {\n\t\t\tkind: \"record\",\n\t\t\tfields: Object.fromEntries(\n\t\t\t\ttype.fields.map((field) => [\n\t\t\t\t\tfield.name,\n\t\t\t\t\tdefaultValue(field.type, types),\n\t\t\t\t]),\n\t\t\t),\n\t\t};\n\t}\n\tif (type.kind === \"duration\") {\n\t\treturn { kind: \"duration\", nanoseconds: \"0\" };\n\t}\n\tif (type.kind === \"calendar\") {\n\t\treturn { kind: \"calendar\", value: calendarZero[type.domain] };\n\t}\n\tif (type.kind === \"integer\" || type.kind === \"bits\") {\n\t\treturn { kind: \"integer\", value: \"0\" };\n\t}\n\tthrow new Error(\"Unsupported default-value type\");\n}\nexport function placeType(\n\tplace: Place,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tvariables: ReadonlyMap<string, Variable>,\n\tranges: ReadonlyMap<string, IntegerInterval>,\n\twritable = false,\n): { type?: string; issue?: string } {\n\tconst root = variables.get(place.root);\n\tif (!root) {\n\t\treturn { issue: \"Unknown storage root.\" };\n\t}\n\tif (\n\t\twritable &&\n\t\t(root.storage === \"input\" ||\n\t\t\troot.storage === \"constant\" ||\n\t\t\troot.storage === \"blockOutput\" ||\n\t\t\t(root.storage === \"parameter\" && root.mode !== \"inOut\") ||\n\t\t\t(!place.path.length && !root.mutable))\n\t) {\n\t\treturn {\n\t\t\tissue:\n\t\t\t\t\"This storage is read-only here: copy it into a let and change the copy.\",\n\t\t};\n\t}\n\treturn place.path.reduce<Walk>(\n\t\t(walk, segment) =>\n\t\t\t\"issue\" in walk\n\t\t\t\t? walk\n\t\t\t\t: segmentType(walk.type, segment, types, variables, ranges, writable),\n\t\t{ type: root.type },\n\t);\n}\n\ntype Walk = { type: string } | { issue: string };\n\n/** The type a path segment selects from `id`, or why it cannot. */\nfunction segmentType(\n\tid: string,\n\tsegment: Place[\"path\"][number],\n\ttypes: ReadonlyMap<string, PlcType>,\n\tvariables: ReadonlyMap<string, Variable>,\n\tranges: ReadonlyMap<string, IntegerInterval>,\n\twritable: boolean,\n): Walk {\n\tconst type = types.get(id);\n\tif (segment.kind === \"field\") {\n\t\tif (type?.kind === \"block\" && segment.name === \"out\" && type.output) {\n\t\t\treturn writable\n\t\t\t\t? { issue: \"Function block output views are read-only.\" }\n\t\t\t\t: { type: type.output };\n\t\t}\n\t\tif (type?.kind !== \"record\") {\n\t\t\treturn { issue: \"Field access requires a record.\" };\n\t\t}\n\t\tconst field = type.fields.find((field) => field.name === segment.name);\n\t\tif (!field) {\n\t\t\treturn { issue: \"Unknown record field.\" };\n\t\t}\n\t\tif (writable && field.readonly) {\n\t\t\treturn { issue: \"This field is read-only.\" };\n\t\t}\n\t\treturn { type: field.type };\n\t}\n\tif (type?.kind !== \"array\") {\n\t\treturn { issue: \"Index access requires a fixed array.\" };\n\t}\n\t// Enum values are closed, and admission proves an enum-keyed array's members are its bounds.\n\t// An integer, such as a for…of counter, still needs its bounds proof.\n\tif (type.index && segment.value.type === type.index) {\n\t\treturn { type: type.element };\n\t}\n\tconst indexType = types.get(segment.value.type);\n\tconst bounds = interval(segment.value, types, variables, ranges);\n\tif (\n\t\tindexType?.kind !== \"integer\" ||\n\t\t!bounds ||\n\t\tbounds[0] < BigInt(type.lowerBound) ||\n\t\tbounds[1] >= BigInt(type.lowerBound + type.length)\n\t) {\n\t\treturn { issue: \"Array index must be proved within the declared bounds.\" };\n\t}\n\treturn { type: type.element };\n}\nexport function aggregateIssue(\n\tvalue: Expression,\n\ttypes: ReadonlyMap<string, PlcType>,\n): string | undefined {\n\tconst type = types.get(value.type);\n\tif (!type) {\n\t\treturn \"Unknown expression type.\";\n\t}\n\tif (value.kind === \"constant\") {\n\t\treturn valueFits(value.value, type, types)\n\t\t\t? undefined\n\t\t\t: \"Constant does not fit its closed PLC layout.\";\n\t}\n\tif (value.kind === \"record\") {\n\t\treturn type.kind === \"record\" &&\n\t\t\tObject.keys(value.fields).length === type.fields.length &&\n\t\t\ttype.fields.every(\n\t\t\t\t(field) =>\n\t\t\t\t\tObject.hasOwn(value.fields, field.name) &&\n\t\t\t\t\tvalue.fields[field.name]?.type === field.type,\n\t\t\t)\n\t\t\t? undefined\n\t\t\t: \"Record expression differs from its layout.\";\n\t}\n\tif (value.kind === \"array\") {\n\t\treturn type.kind === \"array\" &&\n\t\t\tvalue.items.length === type.length &&\n\t\t\tvalue.items.every((item) => item.type === type.element)\n\t\t\t? undefined\n\t\t\t: \"Array expression differs from its layout.\";\n\t}\n\tif (value.kind === \"copy\") {\n\t\treturn aggregate(type) && value.operand.type === value.type\n\t\t\t? undefined\n\t\t\t: \"Copy requires one matching fixed aggregate.\";\n\t}\n\tif (value.kind === \"convert\") {\n\t\tconst source = types.get(value.operand.type);\n\t\treturn type.kind === \"string\" &&\n\t\t\tsource?.kind === \"string\" &&\n\t\t\tsource.encoding === type.encoding &&\n\t\t\tsource.capacity <= type.capacity &&\n\t\t\tvalue.policy === \"exact\"\n\t\t\t? undefined\n\t\t\t: \"Unsupported aggregate/domain conversion.\";\n\t}\n\tif (\n\t\tvalue.kind === \"load\" ||\n\t\tvalue.kind === \"call\" ||\n\t\tvalue.kind === \"conditional\"\n\t) {\n\t\treturn undefined;\n\t}\n\tif (value.kind === \"binary\" && isComparison(value.operator)) {\n\t\tconst compared = comparedType(value, types, [\"enum\", \"string\"]);\n\t\treturn compared &&\n\t\t\t(compared.kind !== \"enum\" ||\n\t\t\t\t[\"equal\", \"notEqual\"].includes(value.operator))\n\t\t\t? undefined\n\t\t\t: \"Comparison requires compatible scalar domains; object identity is unsupported.\";\n\t}\n\treturn \"Operation is unsupported for this PLC domain.\";\n}\n\n// Route a reduced expression to the checker that owns its PLC domain. A binary\n// operation belongs to its operand domain, e.g. a TIME comparison yields BOOL.\nexport function expressionIssue(\n\tvalue: Expression,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tvariables: ReadonlyMap<string, Variable>,\n\tranges: ReadonlyMap<string, IntegerInterval>,\n): string | undefined {\n\tconst kinds = [\n\t\tvalue.type,\n\t\t...(value.kind === \"binary\" ? [value.left.type] : []),\n\t].map((id) => types.get(id)?.kind ?? \"\");\n\tif (kinds.some((kind) => [\"duration\", \"calendar\"].includes(kind))) {\n\t\treturn domainIssue(value, types);\n\t}\n\tif (\n\t\t[\"copy\", \"record\", \"array\"].includes(value.kind) ||\n\t\tkinds.some((kind) => [\"record\", \"array\", \"enum\", \"string\"].includes(kind))\n\t) {\n\t\treturn aggregateIssue(value, types);\n\t}\n\treturn scalarIssue(value, types, variables, ranges);\n}\n",
7
+ "import {\n\tlatestCalendarSecond,\n\tlatestTimeNanoseconds,\n\tnanosecondsPerMillisecond,\n} from \"@tsplc/iec\";\nimport { isComparison } from \"@tsplc/iec/arithmetic\";\nimport type { Constant, Expression } from \"./model\";\nimport { canonicalInteger, exactDecimal } from \"./numeric\";\nimport type { PlcType } from \"./types\";\n\nconst latestDateTime = new Date(Number(latestCalendarSecond) * 1000)\n\t.toISOString()\n\t.slice(0, \"YYYY-MM-DDTHH:mm:ss\".length);\nconst latestDate = latestDateTime.slice(0, \"YYYY-MM-DD\".length);\n\n/** Each calendar domain's zero value, which is also its earliest. */\nexport const calendarZero: Record<\n\tExtract<PlcType, { kind: \"calendar\" }>[\"domain\"],\n\tstring\n> = {\n\tdate: \"1970-01-01\",\n\ttimeOfDay: \"00:00:00.000\",\n\tdateTime: \"1970-01-01T00:00:00\",\n};\n\nexport function durationLiteral(\n\ttext: string,\n\tscaleNanoseconds: bigint,\n): Constant | undefined {\n\tconst clean = text\n\t\t.replaceAll(\"_\", \"\")\n\t\t.replace(/^(-?)\\./, (_, sign: string) => `${sign}0.`);\n\tconst value = exactDecimal(clean, scaleNanoseconds);\n\treturn typeof value === \"bigint\" && validDuration(value)\n\t\t? { kind: \"duration\", nanoseconds: String(value) }\n\t\t: undefined;\n}\nfunction validDuration(nanoseconds: bigint): boolean {\n\treturn (\n\t\tnanoseconds >= 0n &&\n\t\tnanoseconds <= latestTimeNanoseconds &&\n\t\tnanoseconds % nanosecondsPerMillisecond === 0n\n\t);\n}\nfunction validDate(text: string): boolean {\n\tconst match = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(text);\n\tif (!match) {\n\t\treturn false;\n\t}\n\tconst year = Number(match[1]);\n\tconst month = Number(match[2]);\n\tconst day = Number(match[3]);\n\tconst leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n\tconst length = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][\n\t\tmonth - 1\n\t];\n\treturn Boolean(\n\t\tlength &&\n\t\t\tday >= 1 &&\n\t\t\tday <= length &&\n\t\t\ttext >= calendarZero.date &&\n\t\t\ttext <= latestDate,\n\t);\n}\nfunction validClock(text: string, milliseconds: boolean): boolean {\n\tconst match = (\n\t\tmilliseconds\n\t\t\t? /^(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{3})$/\n\t\t\t: /^(\\d{2}):(\\d{2}):(\\d{2})$/\n\t).exec(text);\n\treturn Boolean(\n\t\tmatch &&\n\t\t\tNumber(match[1]) < 24 &&\n\t\t\tNumber(match[2]) < 60 &&\n\t\t\tNumber(match[3]) < 60,\n\t);\n}\nexport function calendarLiteral(\n\tdomain: Extract<PlcType, { kind: \"calendar\" }>[\"domain\"],\n\ttext: string,\n): Constant | undefined {\n\tif (domain === \"date\") {\n\t\treturn validDate(text) ? { kind: \"calendar\", value: text } : undefined;\n\t}\n\tif (domain === \"timeOfDay\") {\n\t\tconst canonical = /^\\d{2}:\\d{2}:\\d{2}$/.test(text) ? `${text}.000` : text;\n\t\treturn validClock(canonical, true)\n\t\t\t? { kind: \"calendar\", value: canonical }\n\t\t\t: undefined;\n\t}\n\treturn text.length === 19 &&\n\t\ttext[10] === \"T\" &&\n\t\tvalidDate(text.slice(0, 10)) &&\n\t\tvalidClock(text.slice(11), false) &&\n\t\ttext <= latestDateTime\n\t\t? { kind: \"calendar\", value: text }\n\t\t: undefined;\n}\nexport function domainConstantFits(value: Constant, type: PlcType): boolean {\n\tif (type.kind === \"duration\") {\n\t\treturn (\n\t\t\tvalue.kind === \"duration\" &&\n\t\t\tcanonicalInteger.test(value.nanoseconds) &&\n\t\t\tvalidDuration(BigInt(value.nanoseconds))\n\t\t);\n\t}\n\tif (type.kind === \"calendar\" && value.kind === \"calendar\") {\n\t\tconst parsed = calendarLiteral(type.domain, value.value);\n\t\treturn parsed?.kind === \"calendar\" && parsed.value === value.value;\n\t}\n\treturn false;\n}\nexport function domainIssue(\n\tvalue: Expression,\n\ttypes: ReadonlyMap<string, PlcType>,\n): string | undefined {\n\tconst type = types.get(value.type);\n\tif (value.kind === \"constant\") {\n\t\treturn type && domainConstantFits(value.value, type)\n\t\t\t? undefined\n\t\t\t: \"Invalid TIME/calendar constant.\";\n\t}\n\tif (\n\t\tvalue.kind === \"load\" ||\n\t\tvalue.kind === \"call\" ||\n\t\tvalue.kind === \"conditional\"\n\t) {\n\t\treturn undefined;\n\t}\n\tif (value.kind === \"binary\" && isComparison(value.operator)) {\n\t\treturn comparedType(value, types, [\"duration\", \"calendar\"])\n\t\t\t? undefined\n\t\t\t: \"Time comparisons require matching domains.\";\n\t}\n\treturn \"TIME and calendar domains permit storage, typed copies and comparisons; implicit numeric arithmetic is unsupported.\";\n}\n\n/** The operands' type of a BOOL comparison of two operands of one type, when that type is one of `kinds`. */\nexport function comparedType(\n\tvalue: Extract<Expression, { kind: \"binary\" }>,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tkinds: readonly PlcType[\"kind\"][],\n): PlcType | undefined {\n\tconst left = types.get(value.left.type);\n\treturn value.type === \"BOOL\" &&\n\t\tleft &&\n\t\tkinds.includes(left.kind) &&\n\t\tvalue.left.type === value.right.type\n\t\t? left\n\t\t: undefined;\n}\n",
8
+ "import { roundFloat } from \"@tsplc/iec/arithmetic\";\nimport type { Constant } from \"./model\";\nimport { integerRange, integerType, type PlcType } from \"./types\";\n\ntype FloatType = Extract<PlcType, { kind: \"float\" }>;\n\n/**\n * The values from a lowest to a highest, inclusive. `excluded`, when given, is one value strictly\n * between them that the range doesn't hold, as `n !== 0` proves of a signed `n`.\n */\nexport type IntegerInterval = readonly [bigint, bigint, excluded?: bigint];\n\nexport const lowest = (a: bigint, b: bigint): bigint => (a < b ? a : b);\nexport const highest = (a: bigint, b: bigint): bigint => (a > b ? a : b);\n\n/** Whether every value of `inner` lies in `outer`. */\nexport const within = (\n\tinner: IntegerInterval,\n\touter: IntegerInterval,\n): boolean =>\n\tinner[0] >= outer[0] &&\n\tinner[1] <= outer[1] &&\n\t(outer[2] === undefined || !admits(inner, outer[2]));\n\n/** Whether `interval` admits `value`, such as a divisor that may be zero. */\nexport const admits = (interval: IntegerInterval, value: bigint): boolean =>\n\tinterval[0] <= value && value <= interval[1] && interval[2] !== value;\n\n/** Integer constants are canonical decimal text: no leading zeros and no negative zero. */\nexport const canonicalInteger = /^(?:0|-?[1-9][0-9]*)$/;\n\n// The significand precision of REAL (IEEE 754 binary32) and LREAL (binary64), which bounds the\n// integers each format holds exactly.\nconst floatPrecision = { 32: 24, 64: 53 } as const;\n\n/** Every integer from minus this limit to this limit converts to the float type exactly. */\nexport const exactIntegerLimit = (type: FloatType): bigint =>\n\t1n << BigInt(floatPrecision[type.bits]);\n\ntype DecimalIssue = \"malformed\" | \"exponent\" | \"fraction\";\n\n/**\n * A signed decimal with an optional fraction and exponent, times `scale`, exactly; it must come\n * to a whole number. The exponent is capped so a literal cannot demand a vast power of ten.\n */\nexport const exactDecimal = (\n\ttext: string,\n\tscale: bigint,\n): bigint | DecimalIssue => {\n\tconst match = /^(-?\\d+)(?:\\.(\\d*))?(?:e([+-]?\\d+))?$/i.exec(text);\n\tif (!match) {\n\t\treturn \"malformed\";\n\t}\n\tconst [, whole, fraction = \"\", exponentText = \"0\"] = match;\n\tconst exponent = Number(exponentText) - fraction.length;\n\tif (!Number.isSafeInteger(exponent) || Math.abs(exponent) > 400) {\n\t\treturn \"exponent\";\n\t}\n\tconst digits = BigInt(`${whole}${fraction}`) * scale;\n\tif (exponent >= 0) {\n\t\treturn digits * 10n ** BigInt(exponent);\n\t}\n\tconst divisor = 10n ** BigInt(-exponent);\n\treturn digits % divisor ? \"fraction\" : digits / divisor;\n};\n\nconst integerLiteralIssues: Record<DecimalIssue, string> = {\n\tmalformed: \"Expected an exact integer literal.\",\n\texponent: \"Integer literal exponent is out of range.\",\n\tfraction:\n\t\t\"Integer literals cannot have a fractional part; to hold fractions, annotate the field or variable REAL or LREAL.\",\n};\n\n/** Whether a numeric literal is written in hexadecimal, octal or binary, which has no fraction or exponent. */\nexport const isRadixLiteral = (text: string): boolean =>\n\t/^-?0[xob]/i.test(text);\n\nexport const parseInteger = (text: string): bigint => {\n\tconst clean = text.replaceAll(\"_\", \"\").replace(/n$/, \"\");\n\tif (isRadixLiteral(clean)) {\n\t\treturn clean.startsWith(\"-\") ? -BigInt(clean.slice(1)) : BigInt(clean);\n\t}\n\tconst value = exactDecimal(clean, 1n);\n\tif (typeof value !== \"bigint\") {\n\t\tthrow new Error(integerLiteralIssues[value]);\n\t}\n\treturn value;\n};\n\n/** A float literal's value, rounded to its type's width. */\nexport const parseFloatLiteral = (text: string, type: FloatType): number => {\n\tconst clean = text.replaceAll(\"_\", \"\");\n\tconst value = isRadixLiteral(clean)\n\t\t? Number(parseInteger(clean))\n\t\t: Number(clean);\n\treturn roundFloat(value, type);\n};\n\nexport const literalOutsideType =\n\t\"Literal is outside its PLC type or has the wrong domain.\";\n\nexport const constantFits = (value: Constant, type: PlcType): boolean => {\n\tif (type.kind === \"bool\") {\n\t\treturn value.kind === \"bool\";\n\t}\n\tif (integerType(type)) {\n\t\treturn (\n\t\t\tvalue.kind === \"integer\" &&\n\t\t\tcanonicalInteger.test(value.value) &&\n\t\t\tadmits(integerRange(type), BigInt(value.value))\n\t\t);\n\t}\n\tif (type.kind === \"float\") {\n\t\treturn (\n\t\t\tvalue.kind === \"float\" &&\n\t\t\tNumber.isFinite(value.value) &&\n\t\t\tObject.is(roundFloat(value.value, type), value.value)\n\t\t);\n\t}\n\treturn false;\n};\n\nexport const canAssign = (\n\tsource: PlcType,\n\tdestination: PlcType,\n\tvalue?: Constant,\n): boolean => {\n\tif (value) {\n\t\treturn source.kind === destination.kind && constantFits(value, destination);\n\t}\n\tif (source.id === destination.id) {\n\t\treturn true;\n\t}\n\tif (source.kind === \"integer\" && destination.kind === \"integer\") {\n\t\treturn within(integerRange(source), integerRange(destination));\n\t}\n\treturn (\n\t\tsource.kind === \"float\" &&\n\t\tdestination.kind === \"float\" &&\n\t\tsource.bits <= destination.bits\n\t);\n};\n\n/**\n * Integer +, - and *: native IEC arithmetic wraps them on overflow as hand-written ST does, and\n * they are the operations that take an explicit wrap or saturate policy.\n */\nexport const wrappingOperators: ReadonlySet<string> = new Set([\n\t\"add\",\n\t\"subtract\",\n\t\"multiply\",\n]);\n\n/** Whether an expression is plain integer +, - or *, which wraps natively. */\nexport const wrapsNatively = (expression: {\n\tkind: string;\n\toperator?: string;\n\tpolicy?: string;\n}): boolean =>\n\texpression.kind === \"binary\" &&\n\t!expression.policy &&\n\texpression.operator !== undefined &&\n\twrappingOperators.has(expression.operator);\n",
9
+ "import {\n\ttype ElementaryType,\n\tintegerRange as elementaryIntegerRange,\n\telementaryTypes,\n} from \"@tsplc/iec\";\n\nexport type TypeId = string;\nexport type SymbolId = string;\n\nexport interface Field {\n\tname: string;\n\ttype: TypeId;\n\treadonly: boolean;\n\tmode?: \"inOut\";\n}\n\nexport type PlcType =\n\t| { id: TypeId; kind: \"bool\" }\n\t| { id: TypeId; kind: \"integer\"; bits: 8 | 16 | 32 | 64; signed: boolean }\n\t| { id: TypeId; kind: \"bits\"; bits: 8 | 16 | 32 | 64 }\n\t| { id: TypeId; kind: \"float\"; bits: 32 | 64 }\n\t| { id: TypeId; kind: \"duration\" }\n\t| { id: TypeId; kind: \"calendar\"; domain: \"date\" | \"timeOfDay\" | \"dateTime\" }\n\t| { id: TypeId; kind: \"string\"; capacity: number; encoding: \"utf8\" | \"utf16\" }\n\t| {\n\t\t\tid: TypeId;\n\t\t\tkind: \"array\";\n\t\t\telement: TypeId;\n\t\t\tlength: number;\n\t\t\tlowerBound: number;\n\t\t\t/** `Record<Enum, T>`: the enum whose contiguous member values are the bounds and the only indexes. */\n\t\t\tindex?: TypeId;\n\t }\n\t| { id: TypeId; kind: \"record\"; fields: readonly Field[] }\n\t| {\n\t\t\tid: TypeId;\n\t\t\tkind: \"enum\";\n\t\t\tbase: TypeId;\n\t\t\t/** `text` is the string a plain TypeScript program's literal union member stands for. */\n\t\t\tmembers: readonly { name: string; value: string; text?: string }[];\n\t }\n\t| { id: TypeId; kind: \"block\"; block: SymbolId; output?: TypeId };\n\n/** The block allocated by a type: a block itself, or a fixed array of one. */\nexport const instancedBlock = (\n\tid: TypeId,\n\ttypes: ReadonlyMap<TypeId, PlcType>,\n): Extract<PlcType, { kind: \"block\" }> | undefined => {\n\tconst type = types.get(id);\n\tconst element = type?.kind === \"array\" ? types.get(type.element) : type;\n\treturn element?.kind === \"block\" ? element : undefined;\n};\n\n/**\n * Whether a type holds a value: neither a block instance nor a record with a reference field,\n * through every field and element.\n */\nexport const isValueType = (\n\tid: TypeId,\n\ttypes: ReadonlyMap<TypeId, PlcType>,\n): boolean => {\n\tconst seen = new Set<TypeId>();\n\tconst valueType = (current: TypeId): boolean => {\n\t\tif (seen.has(current)) {\n\t\t\treturn true;\n\t\t}\n\t\tseen.add(current);\n\t\tconst type = types.get(current);\n\t\treturn Boolean(\n\t\t\ttype &&\n\t\t\t\ttype.kind !== \"block\" &&\n\t\t\t\t(type.kind !== \"record\" ||\n\t\t\t\t\ttype.fields.every((field) => !field.mode && valueType(field.type))) &&\n\t\t\t\t(type.kind !== \"array\" || valueType(type.element)),\n\t\t);\n\t};\n\treturn valueType(id);\n};\n\nconst primitiveType = (type: ElementaryType): PlcType[] => {\n\tswitch (type.family) {\n\t\tcase \"bool\":\n\t\t\treturn [{ id: type.name, kind: \"bool\" }];\n\t\tcase \"integer\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: type.name,\n\t\t\t\t\tkind: \"integer\",\n\t\t\t\t\tbits: type.bits,\n\t\t\t\t\tsigned: type.signed,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"bits\":\n\t\t\treturn [{ id: type.name, kind: \"bits\", bits: type.bits }];\n\t\tcase \"real\":\n\t\t\treturn [{ id: type.name, kind: \"float\", bits: type.bits }];\n\t\tcase \"duration\":\n\t\t\treturn type.bits === 32 ? [{ id: type.name, kind: \"duration\" }] : [];\n\t\tcase \"date\":\n\t\tcase \"timeOfDay\":\n\t\tcase \"dateTime\":\n\t\t\treturn type.bits === 32\n\t\t\t\t? [{ id: type.name, kind: \"calendar\", domain: type.family }]\n\t\t\t\t: [];\n\t\tcase \"char\":\n\t\tcase \"string\":\n\t\t\treturn [];\n\t}\n};\n\ntype IntegerType = Extract<PlcType, { kind: \"integer\" | \"bits\" }>;\n\nexport const integerType = (type: PlcType): type is IntegerType =>\n\ttype.kind === \"integer\" || type.kind === \"bits\";\n\nconst integerKindRank = (type: IntegerType) => {\n\tif (type.kind === \"bits\") {\n\t\treturn 2;\n\t}\n\treturn type.signed ? 0 : 1;\n};\n\nconst elementaryPrimitives = elementaryTypes.flatMap(primitiveType);\n\n/**\n * The elementary types a program uses by name. Date and time types are the 32-bit ones;\n * strings are sized where they are declared, and characters are not modelled.\n *\n * Integers are grouped by width (signed, unsigned, bit string), because the debug manifest\n * lists types in this order and the build id written into the emitted ST hashes it.\n */\nexport const primitiveTypes: readonly PlcType[] = [\n\t...elementaryPrimitives.filter((type) => type.kind === \"bool\"),\n\t...elementaryPrimitives\n\t\t.filter(integerType)\n\t\t.sort(\n\t\t\t(left, right) =>\n\t\t\t\tleft.bits - right.bits ||\n\t\t\t\tintegerKindRank(left) - integerKindRank(right),\n\t\t),\n\t...elementaryPrimitives.filter(\n\t\t(type) => type.kind !== \"bool\" && !integerType(type),\n\t),\n];\n\nexport function integerRange(type: IntegerType): readonly [bigint, bigint] {\n\treturn elementaryIntegerRange({\n\t\tbits: type.bits,\n\t\tsigned: type.kind === \"integer\" && type.signed,\n\t});\n}\n",
10
+ "import { type BinaryOperator, loopIterations } from \"@tsplc/iec/arithmetic\";\nimport { fold } from \"./fold\";\nimport type { Expression, Variable } from \"./model\";\nimport {\n\tadmits,\n\thighest,\n\ttype IntegerInterval,\n\tlowest,\n\twithin,\n} from \"./numeric\";\nimport { integerRange, integerType, type PlcType } from \"./types\";\n\nexport const interval = (\n\texpression: Expression,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tvariables: ReadonlyMap<string, Variable>,\n\tranges: ReadonlyMap<string, IntegerInterval>,\n): IntegerInterval | undefined =>\n\tfactInterval(expression, { types, variables, ranges, facts: [] });\n\n/** What a range proof reads, and what the conditions around a conditional's branch proved about its operands. */\ninterface RangeContext {\n\ttypes: ReadonlyMap<string, PlcType>;\n\tvariables: ReadonlyMap<string, Variable>;\n\tranges: ReadonlyMap<string, IntegerInterval>;\n\tfacts: readonly Fact[];\n}\n\n/** A range an expression is proved to keep where a branch runs, as `a` is below `b` in `a < b ? a : b`. */\ninterface Fact {\n\texpression: Expression;\n\trange: IntegerInterval;\n}\n\nconst factInterval = (\n\texpression: Expression,\n\tcontext: RangeContext,\n): IntegerInterval | undefined => {\n\tconst own = ownInterval(expression, context);\n\tconst fact = context.facts.find((known) =>\n\t\tsameValue(known.expression, expression),\n\t);\n\tif (!own || !fact) {\n\t\treturn own;\n\t}\n\tconst met = excluding(\n\t\texcluding(\n\t\t\t[highest(own[0], fact.range[0]), lowest(own[1], fact.range[1])],\n\t\t\town[2],\n\t\t),\n\t\tfact.range[2],\n\t);\n\treturn met[0] <= met[1] ? met : own;\n};\n\nconst ownInterval = (\n\texpression: Expression,\n\tcontext: RangeContext,\n): IntegerInterval | undefined => {\n\tconst { types, variables, ranges } = context;\n\tconst interval = (operand: Expression) => factInterval(operand, context);\n\tif (expression.kind === \"length\") {\n\t\tconst array = types.get(expression.operand.type);\n\t\tif (array?.kind === \"array\") {\n\t\t\treturn [BigInt(array.length), BigInt(array.length)];\n\t\t}\n\t}\n\tconst value = fold(expression, variables, types);\n\tif (value?.kind === \"integer\") {\n\t\treturn [BigInt(value.value), BigInt(value.value)];\n\t}\n\tconst type = types.get(expression.type);\n\tif (!type || !integerType(type)) {\n\t\treturn undefined;\n\t}\n\tif (expression.kind === \"load\") {\n\t\treturn ranges.get(expression.place.root) ?? integerRange(type);\n\t}\n\tif (expression.kind === \"convert\") {\n\t\treturn expression.policy === \"exact\"\n\t\t\t? interval(expression.operand)\n\t\t\t: integerRange(type);\n\t}\n\tif (expression.kind === \"unary\" && expression.operator === \"negate\") {\n\t\tconst operand = interval(expression.operand);\n\t\treturn operand && [-operand[1], -operand[0]];\n\t}\n\tif (expression.kind === \"binary\" && !expression.policy) {\n\t\tconst left = interval(expression.left);\n\t\tconst right = interval(expression.right);\n\t\treturn (\n\t\t\tleft &&\n\t\t\tright &&\n\t\t\tarithmeticInterval(expression.operator, left, right, integerRange(type))\n\t\t);\n\t}\n\tif (expression.kind === \"conditional\") {\n\t\tconst whenTrue = branchInterval(expression, true, context);\n\t\tconst whenFalse = branchInterval(expression, false, context);\n\t\treturn (\n\t\t\twhenTrue &&\n\t\t\twhenFalse && [\n\t\t\t\tlowest(whenTrue[0], whenFalse[0]),\n\t\t\t\thighest(whenTrue[1], whenFalse[1]),\n\t\t\t]\n\t\t);\n\t}\n\treturn integerRange(type);\n};\n\n/**\n * A conditional's branch, with what its condition proves where the branch runs: the ranges an `if`\n * narrows, and each compared operand bounded by the other, which gives `a < b ? a : b` (`Math.min`)\n * and `x < 0 ? -x : x` (`Math.abs`) their ranges.\n */\nconst branchInterval = (\n\texpression: Extract<Expression, { kind: \"conditional\" }>,\n\ttruth: boolean,\n\tcontext: RangeContext,\n): IntegerInterval | undefined => {\n\tconst { condition } = expression;\n\tconst narrowed: RangeContext = {\n\t\t...context,\n\t\tranges: narrowRanges(\n\t\t\tcondition,\n\t\t\ttruth,\n\t\t\tcontext.types,\n\t\t\tcontext.variables,\n\t\t\tcontext.ranges,\n\t\t),\n\t\tfacts: [...context.facts, ...comparisonFacts(condition, truth, context)],\n\t};\n\treturn factInterval(truth ? expression.then : expression.else, narrowed);\n};\n\nconst flippedComparisons: Partial<Record<BinaryOperator, BinaryOperator>> = {\n\tless: \"greater\",\n\tlessEqual: \"greaterEqual\",\n\tgreater: \"less\",\n\tgreaterEqual: \"lessEqual\",\n};\n\n/** The range each side of an integer comparison keeps where the comparison is `truth`, bounded by the other side. */\nconst comparisonFacts = (\n\tcondition: Expression,\n\ttruth: boolean,\n\tcontext: RangeContext,\n): Fact[] => {\n\tif (condition.kind !== \"binary\") {\n\t\treturn [];\n\t}\n\tconst operator = truth\n\t\t? condition.operator\n\t\t: negatedComparisons[condition.operator];\n\tconst flipped = operator && flippedComparisons[operator];\n\tif (!operator || !flipped) {\n\t\treturn [];\n\t}\n\tconst left = factInterval(condition.left, context);\n\tconst right = factInterval(condition.right, context);\n\tif (!left || !right) {\n\t\treturn [];\n\t}\n\tconst side = (\n\t\texpression: Expression,\n\t\town: IntegerInterval,\n\t\tcomparison: BinaryOperator,\n\t\tother: IntegerInterval,\n\t): Fact[] =>\n\t\tpure(expression)\n\t\t\t? [{ expression, range: boundedBy(own, comparison, other) }]\n\t\t\t: [];\n\treturn [\n\t\t...side(condition.left, left, operator, right),\n\t\t...side(condition.right, right, flipped, left),\n\t];\n};\n\n/** `own` where `own comparison other` holds for some value of `other`. */\nconst boundedBy = (\n\town: IntegerInterval,\n\tcomparison: BinaryOperator,\n\tother: IntegerInterval,\n): IntegerInterval => {\n\tswitch (comparison) {\n\t\tcase \"less\":\n\t\tcase \"lessEqual\":\n\t\t\treturn bounded(own, comparison, other[1]);\n\t\tdefault:\n\t\t\treturn bounded(own, comparison, other[0]);\n\t}\n};\n\n/** Whether an expression reads the same value each time it is evaluated: no call, whose result may differ. */\nconst pure = (expression: Expression): boolean => {\n\tswitch (expression.kind) {\n\t\tcase \"constant\":\n\t\t\treturn true;\n\t\tcase \"load\":\n\t\t\treturn expression.place.path.every(\n\t\t\t\t(segment) => segment.kind === \"field\" || pure(segment.value),\n\t\t\t);\n\t\tcase \"unary\":\n\t\tcase \"convert\":\n\t\tcase \"length\":\n\t\t\treturn pure(expression.operand);\n\t\tcase \"binary\":\n\t\t\treturn pure(expression.left) && pure(expression.right);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n};\n\n/** Whether two expressions compute the same value: the same tree, wherever each is written. */\nconst sameValue = (left: Expression, right: Expression): boolean =>\n\tpure(left) && valueKey(left) === valueKey(right);\n\nconst valueKey = (expression: Expression): string =>\n\tJSON.stringify(expression, (key, value) => {\n\t\tif (key === \"span\") {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn typeof value === \"bigint\" ? String(value) : value;\n\t});\n\n/** The range of `left operator right`; a result that may wrap spans its whole type. */\nconst arithmeticInterval = (\n\toperator: BinaryOperator,\n\tleft: IntegerInterval,\n\tright: IntegerInterval,\n\ttype: IntegerInterval,\n): IntegerInterval | undefined => {\n\tconst unwrapped = (result: IntegerInterval): IntegerInterval =>\n\t\twithin(result, type) ? result : type;\n\tconst corners = (\n\t\tcombine: (a: bigint, b: bigint) => bigint,\n\t\tdivisor: IntegerInterval = right,\n\t) => [\n\t\tcombine(left[0], divisor[0]),\n\t\tcombine(left[0], divisor[1]),\n\t\tcombine(left[1], divisor[0]),\n\t\tcombine(left[1], divisor[1]),\n\t];\n\tswitch (operator) {\n\t\tcase \"add\":\n\t\t\treturn unwrapped([left[0] + right[0], left[1] + right[1]]);\n\t\tcase \"subtract\":\n\t\t\treturn unwrapped([left[0] - right[1], left[1] - right[0]]);\n\t\tcase \"multiply\": {\n\t\t\tconst products = corners((a, b) => a * b);\n\t\t\treturn unwrapped([products.reduce(lowest), products.reduce(highest)]);\n\t\t}\n\t\tcase \"divide\": {\n\t\t\tif (admits(right, 0n)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\t// A divisor whose range runs through an excluded zero divides by each side of it, where\n\t\t\t// the quotients nearest zero's neighbours are the largest.\n\t\t\tconst divisors: readonly IntegerInterval[] =\n\t\t\t\tright[2] === 0n\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t[right[0], -1n],\n\t\t\t\t\t\t\t[1n, right[1]],\n\t\t\t\t\t\t]\n\t\t\t\t\t: [right];\n\t\t\tconst quotients = divisors.flatMap((divisor) =>\n\t\t\t\tcorners((a, b) => a / b, divisor),\n\t\t\t);\n\t\t\treturn [quotients.reduce(lowest), quotients.reduce(highest)];\n\t\t}\n\t\tcase \"remainder\": {\n\t\t\tif (admits(right, 0n)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst magnitude = (value: bigint) => (value < 0n ? -value : value);\n\t\t\tconst largest = highest(magnitude(right[0]), magnitude(right[1])) - 1n;\n\t\t\treturn [left[0] < 0n ? -largest : 0n, left[1] > 0n ? largest : 0n];\n\t\t}\n\t\tdefault:\n\t\t\treturn type;\n\t}\n};\n\n/** The most iterations a bounded loop may prove. */\nexport const maxLoopIterations = 1_000_000n;\n\n/**\n * A loop's widest counter range and most iterations over every start and limit in their ranges.\n * `terminal` is the counter's value after a loop that ran: exact when both bounds are single\n * values, otherwise the furthest it can reach.\n */\nexport const loopBounds = (\n\tstart: IntegerInterval,\n\tlimit: IntegerInterval,\n\tstep: bigint,\n\texclusive = false,\n) => {\n\tconst excluded = exclusive ? 1n : 0n;\n\tconst first = step > 0n ? start[0] : start[1];\n\tconst last = step > 0n ? limit[1] - excluded : limit[0] + excluded;\n\tconst count = loopIterations(\n\t\tfirst,\n\t\tlimit[step > 0n ? 1 : 0],\n\t\texclusive,\n\t\tstep,\n\t);\n\tconst range: IntegerInterval = first <= last ? [first, last] : [last, first];\n\tconst fixed = start[0] === start[1] && limit[0] === limit[1];\n\tconst terminal = fixed\n\t\t? first + count * step\n\t\t: (step > 0n ? range[1] : range[0]) + step;\n\treturn { first, last, count, range, terminal };\n};\n\nconst negatedComparisons: Partial<Record<BinaryOperator, BinaryOperator>> = {\n\tless: \"greaterEqual\",\n\tlessEqual: \"greater\",\n\tgreater: \"lessEqual\",\n\tgreaterEqual: \"less\",\n\tequal: \"notEqual\",\n\tnotEqual: \"equal\",\n};\n\n/** `current` where `current operator value` holds, keeping the value it already excludes. */\nconst bounded = (\n\tcurrent: IntegerInterval,\n\toperator: BinaryOperator | undefined,\n\tvalue: bigint,\n): IntegerInterval => {\n\tconst [lower, upper, excluded] = current;\n\tswitch (operator) {\n\t\tcase \"less\":\n\t\t\treturn excluding([lower, lowest(upper, value - 1n)], excluded);\n\t\tcase \"lessEqual\":\n\t\t\treturn excluding([lower, lowest(upper, value)], excluded);\n\t\tcase \"greater\":\n\t\t\treturn excluding([highest(lower, value + 1n), upper], excluded);\n\t\tcase \"greaterEqual\":\n\t\t\treturn excluding([highest(lower, value), upper], excluded);\n\t\tcase \"equal\":\n\t\t\treturn excluding([highest(lower, value), lowest(upper, value)], excluded);\n\t\tcase \"notEqual\":\n\t\t\treturn excluding(current, value);\n\t\tdefault:\n\t\t\treturn current;\n\t}\n};\n\n/**\n * `range` without `value`: an end moves past it, and a value strictly inside becomes the range's\n * one exclusion. When it already has one, zero is kept, the value a divisor must not be.\n */\nconst excluding = (\n\trange: IntegerInterval,\n\tvalue: bigint | undefined,\n): IntegerInterval => {\n\tconst [lower, upper, held] = range;\n\tif (value === undefined || value < lower || value > upper) {\n\t\treturn range;\n\t}\n\tif (value === lower) {\n\t\treturn excluding([lower + 1n, upper], held);\n\t}\n\tif (value === upper) {\n\t\treturn excluding([lower, upper - 1n], held);\n\t}\n\treturn [lower, upper, held === undefined || value === 0n ? value : held];\n};\n\n// Only storage no statement can change carries branch refinements: loop counters,\n// by-value parameters and const locals, so the proof survives through the branch.\nexport const narrowRanges = (\n\tcondition: Expression,\n\ttruth: boolean,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tvariables: ReadonlyMap<string, Variable>,\n\tranges: ReadonlyMap<string, IntegerInterval>,\n): Map<string, IntegerInterval> => {\n\tconst narrowed = new Map(ranges);\n\tif (condition.kind !== \"binary\") {\n\t\treturn narrowed;\n\t}\n\tif (condition.operator === \"and\") {\n\t\treturn truth\n\t\t\t? narrowRanges(\n\t\t\t\t\tcondition.right,\n\t\t\t\t\ttruth,\n\t\t\t\t\ttypes,\n\t\t\t\t\tvariables,\n\t\t\t\t\tnarrowRanges(condition.left, truth, types, variables, ranges),\n\t\t\t\t)\n\t\t\t: narrowed;\n\t}\n\tif (condition.left.kind !== \"load\" || condition.left.place.path.length) {\n\t\treturn narrowed;\n\t}\n\tconst root = condition.left.place.root;\n\tconst variable = variables.get(root);\n\tconst type = types.get(condition.left.type);\n\tconst fixed =\n\t\tvariable &&\n\t\t((variable.storage === \"parameter\" && !variable.mode) ||\n\t\t\t(variable.storage === \"local\" && !variable.mutable));\n\tconst current =\n\t\tranges.get(root) ??\n\t\t(fixed && type && integerType(type) ? integerRange(type) : undefined);\n\tconst bound = interval(condition.right, types, variables, ranges);\n\tif (!current || !bound || bound[0] !== bound[1]) {\n\t\treturn narrowed;\n\t}\n\tconst range = bounded(\n\t\tcurrent,\n\t\ttruth ? condition.operator : negatedComparisons[condition.operator],\n\t\tbound[0],\n\t);\n\tif (range[0] <= range[1]) {\n\t\tnarrowed.set(root, range);\n\t}\n\treturn narrowed;\n};\n",
11
+ "import {\n\tapplyIntegerPolicy,\n\tbooleanOperation,\n\tcompare,\n\tfloatArithmetic,\n\tfloatUnary,\n\tintegerArithmetic,\n\tintegerUnary,\n\troundFloat,\n\tsaturateFloat,\n\tsaturateFloatToInteger,\n} from \"@tsplc/iec/arithmetic\";\nimport {\n\ttype Constant,\n\ttype Expression,\n\tisLogicalIo,\n\ttype Variable,\n} from \"./model\";\nimport { integerType, type PlcType } from \"./types\";\n\ntype Types = ReadonlyMap<string, PlcType>;\n\nexport const fold = (\n\texpression: Expression,\n\tvariables: ReadonlyMap<string, Variable>,\n\ttypes: Types,\n): Constant | undefined => {\n\tswitch (expression.kind) {\n\t\tcase \"constant\":\n\t\t\treturn expression.value;\n\t\tcase \"copy\":\n\t\t\treturn fold(expression.operand, variables, types);\n\t\tcase \"length\":\n\t\t\treturn foldLength(expression, variables, types);\n\t\tcase \"record\":\n\t\t\treturn foldRecord(expression, variables, types);\n\t\tcase \"array\": {\n\t\t\tconst items = expression.items.map((item) =>\n\t\t\t\tfold(item, variables, types),\n\t\t\t);\n\t\t\treturn items.every((item): item is Constant => item !== undefined)\n\t\t\t\t? { kind: \"array\", items }\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"load\": {\n\t\t\tif (expression.place.path.length) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst variable = variables.get(expression.place.root);\n\t\t\treturn variable?.storage === \"constant\" ? variable.initial : undefined;\n\t\t}\n\t\tcase \"convert\":\n\t\t\treturn foldConvert(\n\t\t\t\texpression,\n\t\t\t\tfold(expression.operand, variables, types),\n\t\t\t\ttypes.get(expression.type),\n\t\t\t);\n\t\tcase \"unary\":\n\t\t\treturn foldUnary(\n\t\t\t\texpression,\n\t\t\t\tfold(expression.operand, variables, types),\n\t\t\t\ttypes.get(expression.type),\n\t\t\t);\n\t\tcase \"binary\": {\n\t\t\tconst left = fold(expression.left, variables, types);\n\t\t\tconst right = fold(expression.right, variables, types);\n\t\t\treturn left && right\n\t\t\t\t? foldBinary(expression, left, right, types.get(expression.type))\n\t\t\t\t: undefined;\n\t\t}\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n};\n\nconst foldLength = (\n\texpression: Extract<Expression, { kind: \"length\" }>,\n\tvariables: ReadonlyMap<string, Variable>,\n\ttypes: Types,\n): Constant | undefined => {\n\tconst type = types.get(expression.operand.type);\n\tconst receiver =\n\t\texpression.operand.kind === \"load\"\n\t\t\t? variables.get(expression.operand.place.root)\n\t\t\t: undefined;\n\tconst pure =\n\t\texpression.operand.kind === \"load\" &&\n\t\texpression.operand.place.path.every(\n\t\t\t(segment) => segment.kind === \"field\",\n\t\t) &&\n\t\tBoolean(receiver && (receiver.initial || isLogicalIo(receiver)));\n\tif (\n\t\ttype?.kind === \"array\" &&\n\t\t(pure || fold(expression.operand, variables, types))\n\t) {\n\t\treturn { kind: \"integer\", value: String(type.length) };\n\t}\n\treturn undefined;\n};\n\nconst foldRecord = (\n\texpression: Extract<Expression, { kind: \"record\" }>,\n\tvariables: ReadonlyMap<string, Variable>,\n\ttypes: Types,\n): Constant | undefined => {\n\tconst fields: Record<string, Constant> = Object.create(null);\n\tfor (const [name, operand] of Object.entries(expression.fields)) {\n\t\tconst value = fold(operand, variables, types);\n\t\tif (!value) {\n\t\t\treturn undefined;\n\t\t}\n\t\tfields[name] = value;\n\t}\n\treturn { kind: \"record\", fields };\n};\n\nconst foldConvert = (\n\texpression: Extract<Expression, { kind: \"convert\" }>,\n\tvalue: Constant | undefined,\n\ttarget: PlcType | undefined,\n): Constant | undefined => {\n\tif (value?.kind === \"integer\" && target && integerType(target)) {\n\t\tconst integer = BigInt(value.value);\n\t\treturn {\n\t\t\tkind: \"integer\",\n\t\t\tvalue: String(\n\t\t\t\texpression.policy === \"exact\"\n\t\t\t\t\t? integer\n\t\t\t\t\t: applyIntegerPolicy(integer, target, expression.policy),\n\t\t\t),\n\t\t};\n\t}\n\tif (value?.kind === \"integer\" && target?.kind === \"float\") {\n\t\treturn { kind: \"float\", value: roundFloat(Number(value.value), target) };\n\t}\n\tif (\n\t\tvalue?.kind === \"float\" &&\n\t\ttarget &&\n\t\tintegerType(target) &&\n\t\texpression.policy === \"saturate\"\n\t) {\n\t\treturn {\n\t\t\tkind: \"integer\",\n\t\t\tvalue: String(saturateFloatToInteger(value.value, target)),\n\t\t};\n\t}\n\tif (value?.kind === \"float\" && target?.kind === \"float\") {\n\t\treturn {\n\t\t\tkind: \"float\",\n\t\t\tvalue:\n\t\t\t\texpression.policy === \"saturate\"\n\t\t\t\t\t? saturateFloat(value.value, target)\n\t\t\t\t\t: roundFloat(value.value, target),\n\t\t};\n\t}\n\treturn undefined;\n};\n\nconst foldUnary = (\n\t{ operator }: Extract<Expression, { kind: \"unary\" }>,\n\tvalue: Constant | undefined,\n\ttarget: PlcType | undefined,\n): Constant | undefined => {\n\tif (value?.kind === \"bool\") {\n\t\treturn operator === \"not\"\n\t\t\t? { kind: \"bool\", value: !value.value }\n\t\t\t: undefined;\n\t}\n\tif (value?.kind === \"float\") {\n\t\tconst result = floatUnary(operator, value.value);\n\t\treturn result === undefined ? undefined : finiteFloat(result, target);\n\t}\n\tif (value?.kind === \"duration\") {\n\t\tconst result = integerUnary(operator, BigInt(value.nanoseconds));\n\t\treturn operator === \"timeToMilliseconds\" && result !== undefined\n\t\t\t? { kind: \"integer\", value: String(result) }\n\t\t\t: undefined;\n\t}\n\tif (value?.kind !== \"integer\" || operator === \"timeToMilliseconds\") {\n\t\treturn undefined;\n\t}\n\tconst result = integerUnary(operator, BigInt(value.value));\n\tif (result === undefined) {\n\t\treturn undefined;\n\t}\n\t// Negation is left unwrapped: its proof requires the result to fit.\n\tif (operator !== \"bitNot\") {\n\t\treturn { kind: \"integer\", value: String(result) };\n\t}\n\treturn target?.kind === \"bits\"\n\t\t? {\n\t\t\t\tkind: \"integer\",\n\t\t\t\tvalue: String(applyIntegerPolicy(result, target, \"wrap\")),\n\t\t\t}\n\t\t: undefined;\n};\n\ntype Ordered = Exclude<Constant, { kind: \"bool\" | \"array\" | \"record\" }>;\n\nconst ordered = (value: Constant): value is Ordered =>\n\tvalue.kind !== \"bool\" && value.kind !== \"array\" && value.kind !== \"record\";\n\n/** The value two constants of one kind compare as; durations compare by nanoseconds. */\nconst comparable = (value: Ordered): bigint | number | string => {\n\tswitch (value.kind) {\n\t\tcase \"integer\":\n\t\t\treturn BigInt(value.value);\n\t\tcase \"duration\":\n\t\t\treturn BigInt(value.nanoseconds);\n\t\tdefault:\n\t\t\treturn value.value;\n\t}\n};\n\nconst foldBinary = (\n\texpression: Extract<Expression, { kind: \"binary\" }>,\n\tleft: Constant,\n\tright: Constant,\n\ttarget: PlcType | undefined,\n): Constant | undefined => {\n\tif (left.kind === \"bool\" && right.kind === \"bool\") {\n\t\tconst value = booleanOperation(\n\t\t\texpression.operator,\n\t\t\tleft.value,\n\t\t\tright.value,\n\t\t);\n\t\treturn value === undefined ? undefined : { kind: \"bool\", value };\n\t}\n\tif (left.kind !== right.kind || !ordered(left) || !ordered(right)) {\n\t\treturn undefined;\n\t}\n\tconst compared = compare(\n\t\texpression.operator,\n\t\tcomparable(left),\n\t\tcomparable(right),\n\t);\n\tif (compared !== undefined) {\n\t\treturn { kind: \"bool\", value: compared };\n\t}\n\tif (left.kind === \"integer\" && right.kind === \"integer\") {\n\t\tconst value = integerArithmetic(\n\t\t\texpression.operator,\n\t\t\tBigInt(left.value),\n\t\t\tBigInt(right.value),\n\t\t);\n\t\tif (value === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst wrapped =\n\t\t\ttarget &&\n\t\t\tintegerType(target) &&\n\t\t\t(expression.policy || target.kind === \"bits\")\n\t\t\t\t? applyIntegerPolicy(value, target, expression.policy ?? \"wrap\")\n\t\t\t\t: value;\n\t\treturn { kind: \"integer\", value: String(wrapped) };\n\t}\n\tif (left.kind === \"float\" && right.kind === \"float\") {\n\t\tconst value = floatArithmetic(expression.operator, left.value, right.value);\n\t\tif (value === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tkind: \"float\",\n\t\t\tvalue: target?.kind === \"float\" ? roundFloat(value, target) : value,\n\t\t};\n\t}\n\treturn undefined;\n};\n\n/** A float result as its type holds it, or nothing when it isn't finite, as NaN and infinities aren't constants. */\nconst finiteFloat = (\n\tvalue: number,\n\ttarget: PlcType | undefined,\n): Constant | undefined => {\n\tconst rounded = target?.kind === \"float\" ? roundFloat(value, target) : value;\n\treturn Number.isFinite(rounded)\n\t\t? { kind: \"float\", value: rounded }\n\t\t: undefined;\n};\n",
12
+ "import {\n\ttype BinaryOperator,\n\tcomparisonOperatorNames,\n\ttype UnaryOperator,\n} from \"@tsplc/iec/arithmetic\";\nimport type { Diagnostic, SourceSpan } from \"./diagnostics\";\nimport type { PlcType, SymbolId, TypeId } from \"./types\";\n\nexport type Constant =\n\t| { kind: \"bool\"; value: boolean }\n\t| { kind: \"integer\"; value: string }\n\t| { kind: \"float\"; value: number }\n\t| { kind: \"duration\"; nanoseconds: string }\n\t| { kind: \"calendar\"; value: string }\n\t| { kind: \"string\"; value: string }\n\t| { kind: \"array\"; items: readonly Constant[] }\n\t| { kind: \"record\"; fields: Readonly<Record<string, Constant>> };\n\n/**\n * What a variable keeps when the controller restarts: nothing, a warm restart (`RETAIN`), or also\n * a download and a cold reset (`PERSISTENT RETAIN`).\n */\nexport type Retention = \"none\" | \"retain\" | \"persist\";\n\nexport interface Variable {\n\tid: SymbolId;\n\tname: string;\n\ttype: TypeId;\n\tstorage:\n\t\t| \"module\"\n\t\t| \"local\"\n\t\t| \"parameter\"\n\t\t| \"input\"\n\t\t| \"output\"\n\t\t| \"field\"\n\t\t| \"instance\"\n\t\t| \"constant\"\n\t\t| \"blockOutput\";\n\tmutable: boolean;\n\tretention: Retention;\n\texported?: true;\n\tmode?: \"inOut\";\n\tinitial?: Constant;\n\tspan: SourceSpan;\n}\n\n/** Whether a variable is one of the module's logical inputs and outputs, bound to the process image. */\nexport const isLogicalIo = (\n\tvariable: Variable,\n): variable is Variable & { storage: \"input\" | \"output\" } =>\n\tvariable.storage === \"input\" || variable.storage === \"output\";\n\n/** How `T | undefined` is stored: the record `{ has, value }`, named with this prefix and `T`. */\nexport const optionalRecord = {\n\tprefix: \"Optional_\",\n\thas: \"has\",\n\tvalue: \"value\",\n} as const;\n\nexport interface Place {\n\troot: SymbolId;\n\tpath: readonly (\n\t\t| { kind: \"field\"; name: string }\n\t\t| { kind: \"index\"; value: Expression }\n\t)[];\n}\n\nexport const comparisonOperators: ReadonlySet<BinaryOperator> = new Set(\n\tcomparisonOperatorNames,\n);\n\nexport type Expression = { type: TypeId; span: SourceSpan } & (\n\t| { kind: \"constant\"; value: Constant }\n\t| { kind: \"load\"; place: Place }\n\t| {\n\t\t\tkind: \"unary\";\n\t\t\toperator: UnaryOperator;\n\t\t\toperand: Expression;\n\t }\n\t| {\n\t\t\tkind: \"binary\";\n\t\t\toperator: BinaryOperator;\n\t\t\tleft: Expression;\n\t\t\tright: Expression;\n\t\t\tpolicy?: \"wrap\" | \"saturate\";\n\t }\n\t| {\n\t\t\tkind: \"call\";\n\t\t\tfunction: SymbolId;\n\t\t\tinstance?: SymbolId;\n\t\t\tindex?: Expression;\n\t\t\targuments: readonly Expression[];\n\t }\n\t| {\n\t\t\tkind: \"conditional\";\n\t\t\tcondition: Expression;\n\t\t\tthen: Expression;\n\t\t\telse: Expression;\n\t }\n\t| {\n\t\t\tkind: \"convert\";\n\t\t\toperand: Expression;\n\t\t\tpolicy: \"exact\" | \"wrap\" | \"saturate\";\n\t }\n\t| { kind: \"borrow\"; place: Place }\n\t| { kind: \"length\"; operand: Expression }\n\t| { kind: \"copy\"; operand: Expression }\n\t| { kind: \"record\"; fields: Readonly<Record<string, Expression>> }\n\t| { kind: \"array\"; items: readonly Expression[] }\n);\n\nexport type Statement = { span: SourceSpan } & (\n\t| { kind: \"assign\"; destination: Place; value: Expression }\n\t| {\n\t\t\tkind: \"if\";\n\t\t\tcondition: Expression;\n\t\t\tthen: readonly Statement[];\n\t\t\telse: readonly Statement[];\n\t }\n\t| {\n\t\t\tkind: \"switch\";\n\t\t\tvalue: Expression;\n\t\t\tcases: readonly {\n\t\t\t\tvalues: readonly Constant[];\n\t\t\t\tbody: readonly Statement[];\n\t\t\t}[];\n\t\t\tfallback: readonly Statement[];\n\t }\n\t| {\n\t\t\tkind: \"for\";\n\t\t\tcounter: SymbolId;\n\t\t\t/** Existing storage remains observable after the loop exits. */\n\t\t\tcounterScope?: \"existing\";\n\t\t\tstart: Expression;\n\t\t\tlimit: Expression;\n\t\t\tstep: string;\n\t\t\texclusive?: true;\n\t\t\tmaxIterations: number;\n\t\t\tbody: readonly Statement[];\n\t }\n\t| {\n\t\t\tkind: \"invoke\";\n\t\t\tfunction: SymbolId;\n\t\t\tinstance?: SymbolId;\n\t\t\tindex?: Expression;\n\t\t\targuments: readonly Expression[];\n\t\t\tdestination?: Place;\n\t }\n\t| {\n\t\t\tkind: \"blockUpdate\";\n\t\t\tinstance: SymbolId;\n\t\t\tindex?: Expression;\n\t\t\tinputs: Readonly<Record<string, Expression>>;\n\t }\n\t| { kind: \"return\"; value?: Expression }\n\t| { kind: \"break\" | \"continue\" }\n\t| ({ kind: \"telemetry\" } & TelemetryCall<Expression>)\n);\n\n/**\n * A `@tsplc/compiler/telemetry` call. `record` is what the record says besides its properties;\n * a property with a `length` is a byte array, borrowed, sent as text up to that length.\n */\nexport interface TelemetryCall<E> {\n\trecord:\n\t\t| { kind: \"event\"; event: string }\n\t\t| { kind: \"log\"; level: \"info\" | \"warn\" | \"error\"; message: string }\n\t\t| { kind: \"exception\"; code: E };\n\tproperties: readonly { name: string; value: E; length?: E }[];\n}\n\n/** Every value a telemetry call reads, in evaluation order. */\nexport const telemetryOperands = <E>({\n\trecord,\n\tproperties,\n}: TelemetryCall<E>): E[] => [\n\t...(record.kind === \"exception\" ? [record.code] : []),\n\t...properties.flatMap(({ value, length }) =>\n\t\tlength ? [value, length] : [value],\n\t),\n];\n\nexport interface MethodOwner {\n\tblock: SymbolId;\n\taccess: \"public\" | \"private\" | \"protected\";\n}\n\nexport interface PlcFunction {\n\towner?: MethodOwner;\n\tid: SymbolId;\n\tname: string;\n\tparameters: readonly Variable[];\n\tlocals: readonly Variable[];\n\tresult?: TypeId;\n\t/** The source method this function was specialized from, as `Class.method`, and the TypeScript path of its `this`. */\n\torigin?: { name: string; instance?: string };\n\tbody: readonly Statement[];\n\tspan: SourceSpan;\n}\n\n// Native vendor blocks under their TypeScript names. Ports are [name, native name, type];\n// every output starts at its type's default, matching the vendor library blocks.\nconst timer = (input: string, output: string) =>\n\t({\n\t\tinputs: [\n\t\t\t[input, \"IN\", \"BOOL\"],\n\t\t\t[\"duration\", \"PT\", \"TIME\"],\n\t\t],\n\t\toutputs: [\n\t\t\t[output, \"Q\", \"BOOL\"],\n\t\t\t[\"elapsed\", \"ET\", \"TIME\"],\n\t\t],\n\t}) as const;\nexport const standardBlocks = {\n\tOnDelayTimer: { native: \"TON\", ...timer(\"enabled\", \"done\") },\n\tOffDelayTimer: { native: \"TOF\", ...timer(\"enabled\", \"active\") },\n\tPulseTimer: { native: \"TP\", ...timer(\"start\", \"active\") },\n\tRisingEdge: {\n\t\tnative: \"R_TRIG\",\n\t\tinputs: [[\"signal\", \"CLK\", \"BOOL\"]],\n\t\toutputs: [[\"rose\", \"Q\", \"BOOL\"]],\n\t},\n\tFallingEdge: {\n\t\tnative: \"F_TRIG\",\n\t\tinputs: [[\"signal\", \"CLK\", \"BOOL\"]],\n\t\toutputs: [[\"fell\", \"Q\", \"BOOL\"]],\n\t},\n\tUpCounter: {\n\t\tnative: \"CTU\",\n\t\tinputs: [\n\t\t\t[\"countUp\", \"CU\", \"BOOL\"],\n\t\t\t[\"reset\", \"RESET\", \"BOOL\"],\n\t\t\t[\"preset\", \"PV\", \"WORD\"],\n\t\t],\n\t\toutputs: [\n\t\t\t[\"reachedPreset\", \"Q\", \"BOOL\"],\n\t\t\t[\"value\", \"CV\", \"WORD\"],\n\t\t],\n\t},\n\tDownCounter: {\n\t\tnative: \"CTD\",\n\t\tinputs: [\n\t\t\t[\"countDown\", \"CD\", \"BOOL\"],\n\t\t\t[\"load\", \"LOAD\", \"BOOL\"],\n\t\t\t[\"preset\", \"PV\", \"WORD\"],\n\t\t],\n\t\toutputs: [\n\t\t\t[\"atZero\", \"Q\", \"BOOL\"],\n\t\t\t[\"value\", \"CV\", \"WORD\"],\n\t\t],\n\t},\n\tUpDownCounter: {\n\t\tnative: \"CTUD\",\n\t\tinputs: [\n\t\t\t[\"countUp\", \"CU\", \"BOOL\"],\n\t\t\t[\"countDown\", \"CD\", \"BOOL\"],\n\t\t\t[\"reset\", \"RESET\", \"BOOL\"],\n\t\t\t[\"load\", \"LOAD\", \"BOOL\"],\n\t\t\t[\"preset\", \"PV\", \"WORD\"],\n\t\t],\n\t\toutputs: [\n\t\t\t[\"reachedPreset\", \"QU\", \"BOOL\"],\n\t\t\t[\"atZero\", \"QD\", \"BOOL\"],\n\t\t\t[\"value\", \"CV\", \"WORD\"],\n\t\t],\n\t},\n\tBlinker: {\n\t\tnative: \"Util.BLINK\",\n\t\tinputs: [\n\t\t\t[\"enabled\", \"ENABLE\", \"BOOL\"],\n\t\t\t[\"offTime\", \"TIMELOW\", \"TIME\"],\n\t\t\t[\"onTime\", \"TIMEHIGH\", \"TIME\"],\n\t\t],\n\t\toutputs: [[\"on\", \"OUT\", \"BOOL\"]],\n\t},\n} as const;\nexport type StandardBlock = keyof typeof standardBlocks;\n\n/** The methods a service call or `fetch` may use. */\nexport const httpMethods = [\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"] as const;\nexport type HttpMethod = (typeof httpMethods)[number];\n\nexport interface FunctionBlock {\n\tid: SymbolId;\n\tname: string;\n\tinputs: readonly Variable[];\n\toutputs: readonly Variable[];\n\tstate: readonly Variable[];\n\tlocals: readonly Variable[];\n\tbody: readonly Statement[];\n\tresult?: TypeId;\n\tstandard?: StandardBlock;\n\truntime?:\n\t\t| { kind: \"mailbox\" }\n\t\t| { kind: \"backgroundHost\" }\n\t\t| { kind: \"rpc\"; path: string }\n\t\t| {\n\t\t\t\tkind: \"http\";\n\t\t\t\turl: string;\n\t\t\t\tmethod: HttpMethod;\n\t\t\t\tjson: boolean;\n\t\t };\n\t/** The async function lowered to this block, and the source each `step` value stands for. */\n\tjob?: {\n\t\tname: string;\n\t\t/** The TypeScript path of `this`, for a method specialized to one instance. */\n\t\tinstance?: string;\n\t\tspan: SourceSpan;\n\t\tsteps: readonly {\n\t\t\tstep: number;\n\t\t\tkind: \"await\" | \"return\" | \"throw\" | \"statement\";\n\t\t\tspan: SourceSpan;\n\t\t\ttext: string;\n\t\t}[];\n\t};\n\tspan: SourceSpan;\n}\n\nexport interface PlcProgram {\n\tid: SymbolId;\n\tname: string;\n\tentry: SymbolId;\n\tcontinuation?: { instance: string; file: string };\n\tbackground?: {\n\t\tintervalNanoseconds: string;\n\t\tpriority: number;\n\t\tmailbox: string;\n\t\tworker: string;\n\t};\n}\n\nexport interface PlcModule {\n\t/**\n\t * Fields the elaborator folded into constants: no storage, but a known value at each TypeScript\n\t * path. `type` is the scalar's PLC type; strings, often enum members, have none.\n\t */\n\tfolded?: readonly {\n\t\tpath: string;\n\t\tvalue: Constant;\n\t\ttype?: TypeId;\n\t\tspan: SourceSpan;\n\t}[];\n\t/**\n\t * Object references: the module storage path of each object by the id a reference holds (−1 is\n\t * `undefined`), and the storage paths of the fields that hold a reference.\n\t */\n\treferences?: {\n\t\tobjects: readonly { id: number; path: string }[];\n\t\tfields: readonly string[];\n\t};\n\ttypes: readonly PlcType[];\n\tvariables: readonly Variable[];\n\tfunctions: readonly PlcFunction[];\n\tblocks: readonly FunctionBlock[];\n\tprograms: readonly PlcProgram[];\n}\n\nexport interface Task {\n\tname: string;\n\tintervalNanoseconds: string;\n\tpriority: number;\n\tprograms: readonly string[];\n}\n\nexport interface Deployment {\n\ttasks: readonly Task[];\n}\n\nexport interface Artifact {\n\tpath: string;\n\tcontent: string;\n}\n\nexport interface GeneratedObject {\n\tparent?: SymbolId;\n\tsourcePath?: string;\n\tid: SymbolId;\n\tkind:\n\t\t| \"program\"\n\t\t| \"function\"\n\t\t| \"functionBlock\"\n\t\t| \"method\"\n\t\t| \"globalList\"\n\t\t| \"dataType\";\n\tname: string;\n\tdeclaration: string;\n\timplementation?: string;\n}\n\nexport interface EmitResult {\n\tartifacts: readonly Artifact[];\n\tobjects: readonly GeneratedObject[];\n\tdiagnostics: readonly Diagnostic[];\n}\n",
13
+ "import {\n\ttype ElementaryFunction,\n\tfloatMaximum,\n\tisComparison,\n\tisElementary,\n\troundFloat,\n} from \"@tsplc/iec/arithmetic\";\nimport { fold } from \"./fold\";\nimport type { Constant, Expression, Variable } from \"./model\";\nimport {\n\tadmits,\n\tcanAssign,\n\tconstantFits,\n\texactIntegerLimit,\n\ttype IntegerInterval,\n\tliteralOutsideType,\n\twithin,\n\twrappingOperators,\n\twrapsNatively,\n} from \"./numeric\";\nimport { interval } from \"./ranges\";\nimport { integerRange, integerType, type PlcType } from \"./types\";\n\n/** An operand's constant value and proved integer range, over the storage in scope. */\ninterface Proof {\n\tfold: (value: Expression) => Constant | undefined;\n\tinterval: (value: Expression) => IntegerInterval | undefined;\n}\n\nconst scalarKinds: ReadonlySet<PlcType[\"kind\"]> = new Set([\n\t\"bool\",\n\t\"integer\",\n\t\"bits\",\n\t\"float\",\n]);\n\nconst bitwiseOperators: ReadonlySet<string> = new Set([\n\t\"bitAnd\",\n\t\"bitOr\",\n\t\"bitXor\",\n\t\"shiftLeft\",\n\t\"shiftRight\",\n]);\n\nexport const scalarIssue = (\n\texpression: Expression,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tvariables: ReadonlyMap<string, Variable>,\n\tranges: ReadonlyMap<string, IntegerInterval>,\n): string | undefined => {\n\tconst proof: Proof = {\n\t\tfold: (value) => fold(value, variables, types),\n\t\tinterval: (value) => interval(value, types, variables, ranges),\n\t};\n\tconst type = types.get(expression.type);\n\tif (!type || !scalarKinds.has(type.kind)) {\n\t\treturn \"Unknown scalar expression type.\";\n\t}\n\tif (expression.kind === \"constant\") {\n\t\treturn constantFits(expression.value, type)\n\t\t\t? undefined\n\t\t\t: literalOutsideType;\n\t}\n\tif (expression.kind === \"load\" || expression.kind === \"call\") {\n\t\treturn undefined;\n\t}\n\tif (expression.kind === \"convert\" || expression.kind === \"unary\") {\n\t\tconst source = types.get(expression.operand.type);\n\t\tif (!source) {\n\t\t\treturn \"Unknown operand type.\";\n\t\t}\n\t\treturn expression.kind === \"convert\"\n\t\t\t? conversionIssue(expression, source, type, proof)\n\t\t\t: unaryIssue(expression, source, type, proof);\n\t}\n\tif (expression.kind === \"binary\") {\n\t\tconst left = types.get(expression.left.type);\n\t\tconst right = types.get(expression.right.type);\n\t\tif (!left || !right) {\n\t\t\treturn \"Unknown operand type.\";\n\t\t}\n\t\treturn binaryIssue(expression, left, right, type, proof);\n\t}\n\tif (\"operand\" in expression && !types.has(expression.operand.type)) {\n\t\treturn \"Unknown operand type.\";\n\t}\n\treturn \"Expression has not been reduced to a scalar operation.\";\n};\n\nconst conversionIssue = (\n\texpression: Extract<Expression, { kind: \"convert\" }>,\n\tsource: PlcType,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tif (source.kind === \"bool\" || type.kind === \"bool\") {\n\t\treturn \"Numeric conversions cannot use BOOL.\";\n\t}\n\tif (expression.policy === \"exact\") {\n\t\treturn exactConversionIssue(expression, source, type, proof);\n\t}\n\t// A float saturates to an integer by truncating toward zero: there is no wrap of a float,\n\t// whose whole part may exceed every integer width.\n\tif (\n\t\texpression.policy === \"saturate\" &&\n\t\tsource.kind === \"float\" &&\n\t\t(type.kind === \"float\" || integerType(type))\n\t) {\n\t\treturn undefined;\n\t}\n\tif (integerType(source) && integerType(type)) {\n\t\treturn undefined;\n\t}\n\treturn expression.policy === \"saturate\"\n\t\t? \"Saturate conversions go to an integer/bit-string type from an integer, bit-string or floating operand, or between floating types.\"\n\t\t: \"Wrap conversions require integer or bit-string operands.\";\n};\n\nconst exactConversionIssue = (\n\texpression: Extract<Expression, { kind: \"convert\" }>,\n\tsource: PlcType,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tconst value = proof.fold(expression.operand);\n\tif (\n\t\tcanAssign(source, type, value) ||\n\t\t(value &&\n\t\t\tintegerType(source) &&\n\t\t\tintegerType(type) &&\n\t\t\tconstantFits(value, type))\n\t) {\n\t\treturn undefined;\n\t}\n\tif (!integerType(source)) {\n\t\treturn \"Exact conversion cannot be proved lossless.\";\n\t}\n\tif (type.kind === \"float\" && value?.kind === \"integer\") {\n\t\tconst converted = roundFloat(Number(value.value), type);\n\t\tif (\n\t\t\tNumber.isFinite(converted) &&\n\t\t\tNumber.isInteger(converted) &&\n\t\t\tBigInt(converted) === BigInt(value.value)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\tconst proved = proof.interval(expression.operand) ?? integerRange(source);\n\tif (type.kind === \"float\") {\n\t\tconst limit = exactIntegerLimit(type);\n\t\tif (within(proved, [-limit, limit])) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\tif (integerType(type) && within(proved, integerRange(type))) {\n\t\treturn undefined;\n\t}\n\treturn \"Exact conversion cannot be proved lossless.\";\n};\n\nconst unaryIssue = (\n\texpression: Extract<Expression, { kind: \"unary\" }>,\n\tsource: PlcType,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tif (isElementary(expression.operator)) {\n\t\tif (source.kind !== \"float\" || source.id !== type.id) {\n\t\t\treturn \"Elementary functions take and return one floating type.\";\n\t\t}\n\t\treturn operandDomainIssue(\n\t\t\texpression.operator,\n\t\t\texpression.operand,\n\t\t\ttype,\n\t\t\tproof,\n\t\t);\n\t}\n\tswitch (expression.operator) {\n\t\tcase \"truncate\":\n\t\t\treturn source.kind === \"float\" && source.id === type.id\n\t\t\t\t? undefined\n\t\t\t\t: \"trunc takes and returns one floating type.\";\n\t\tcase \"clock\":\n\t\t\treturn type.id === \"DINT\"\n\t\t\t\t? undefined\n\t\t\t\t: \"now() returns DINT milliseconds.\";\n\t\tcase \"timeToMilliseconds\":\n\t\t\treturn source.id === \"TIME\" &&\n\t\t\t\tsource.kind === \"duration\" &&\n\t\t\t\ttype.id === \"UDINT\"\n\t\t\t\t? undefined\n\t\t\t\t: \"timeToMilliseconds requires TIME and returns UDINT.\";\n\t\tcase \"not\":\n\t\t\treturn type.kind === \"bool\" && source.kind === \"bool\"\n\t\t\t\t? undefined\n\t\t\t\t: \"Logical negation requires BOOL.\";\n\t\tcase \"bitNot\":\n\t\t\treturn type.kind === \"bits\" && source.id === type.id\n\t\t\t\t? undefined\n\t\t\t\t: \"Bitwise complement requires a bit string.\";\n\t\tcase \"negate\":\n\t\t\tif (\n\t\t\t\tsource.id !== type.id ||\n\t\t\t\t!(type.kind === \"integer\" || type.kind === \"float\")\n\t\t\t) {\n\t\t\t\treturn \"Numeric negation requires one arithmetic type.\";\n\t\t\t}\n\t\t\treturn resultIssue(expression, type, proof);\n\t}\n};\n\nconst binaryIssue = (\n\texpression: Extract<Expression, { kind: \"binary\" }>,\n\tleft: PlcType,\n\tright: PlcType,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tif (expression.operator === \"and\" || expression.operator === \"or\") {\n\t\treturn type.kind === \"bool\" && left.kind === \"bool\" && right.kind === \"bool\"\n\t\t\t? undefined\n\t\t\t: \"Logical operators require BOOL.\";\n\t}\n\tif (isComparison(expression.operator)) {\n\t\treturn type.kind === \"bool\" &&\n\t\t\tleft.id === right.id &&\n\t\t\tscalarKinds.has(left.kind) &&\n\t\t\t(left.kind !== \"bool\" ||\n\t\t\t\t[\"equal\", \"notEqual\"].includes(expression.operator))\n\t\t\t? undefined\n\t\t\t: \"Comparison operands need the same PLC domain.\";\n\t}\n\tif (bitwiseOperators.has(expression.operator)) {\n\t\tif (type.kind !== \"bits\" || left.id !== type.id) {\n\t\t\treturn \"Bitwise operators require bit strings.\";\n\t\t}\n\t\tif (\n\t\t\texpression.operator === \"shiftLeft\" ||\n\t\t\texpression.operator === \"shiftRight\"\n\t\t) {\n\t\t\tconst count = proof.fold(expression.right);\n\t\t\treturn count?.kind === \"integer\" &&\n\t\t\t\tBigInt(count.value) >= 0n &&\n\t\t\t\tBigInt(count.value) < BigInt(type.bits)\n\t\t\t\t? undefined\n\t\t\t\t: \"Shift count must be a compile-time integer within the bit width.\";\n\t\t}\n\t\treturn right.id === type.id ? undefined : \"Bit-string widths differ.\";\n\t}\n\tif (expression.operator === \"power\") {\n\t\tif (type.kind !== \"float\" || left.id !== type.id || right.id !== type.id) {\n\t\t\treturn \"A power takes and returns one floating type.\";\n\t\t}\n\t\treturn powerIssue(expression, type, proof);\n\t}\n\tif (\n\t\tleft.id !== type.id ||\n\t\tright.id !== type.id ||\n\t\t(type.kind !== \"integer\" && type.kind !== \"float\")\n\t) {\n\t\treturn \"Arithmetic operands need one integer or floating type.\";\n\t}\n\tif (expression.policy) {\n\t\treturn type.kind === \"integer\" && wrappingOperators.has(expression.operator)\n\t\t\t? undefined\n\t\t\t: \"Explicit arithmetic policies require integer addition, subtraction or multiplication.\";\n\t}\n\tif (\n\t\t(expression.operator === \"divide\" || expression.operator === \"remainder\") &&\n\t\ttype.kind === \"integer\"\n\t) {\n\t\tconst divisor = proof.interval(expression.right);\n\t\tif (!divisor || admits(divisor, 0n)) {\n\t\t\treturn \"Division requires a proved nonzero divisor.\";\n\t\t}\n\t\tconst dividend = proof.interval(expression.left);\n\t\tconst [minimum] = integerRange(type);\n\t\tif (\n\t\t\ttype.signed &&\n\t\t\tdividend &&\n\t\t\tdividend[0] <= minimum &&\n\t\t\tadmits(divisor, -1n)\n\t\t) {\n\t\t\treturn \"Signed minimum divided by -1 cannot be represented.\";\n\t\t}\n\t}\n\treturn resultIssue(expression, type, proof);\n};\n\n/**\n * The bounds a floating operand is proved to keep: a constant's value, or the proved range of an\n * integer converted to it exactly. Other floating values have no proved bounds.\n */\nconst floatBounds = (\n\texpression: Expression,\n\tproof: Proof,\n): readonly [number, number] | undefined => {\n\tconst value = proof.fold(expression);\n\tif (value?.kind === \"float\") {\n\t\treturn [value.value, value.value];\n\t}\n\tif (value?.kind === \"integer\") {\n\t\treturn [Number(value.value), Number(value.value)];\n\t}\n\tif (expression.kind === \"convert\" && expression.policy === \"exact\") {\n\t\tconst proved = proof.interval(expression.operand);\n\t\treturn proved && [Number(proved[0]), Number(proved[1])];\n\t}\n\treturn undefined;\n};\n\n/** Where each elementary function's result is finite, and what to prove when its operand may leave there. */\nconst domains: Readonly<\n\tRecord<\n\t\tElementaryFunction,\n\t\t| {\n\t\t\t\tholds: (low: number, high: number, type: PlcType) => boolean;\n\t\t\t\tneeds: string;\n\t\t }\n\t\t| undefined\n\t>\n> = {\n\tsqrt: { holds: (low) => low >= 0, needs: \"not negative\" },\n\tln: { holds: (low) => low > 0, needs: \"greater than zero\" },\n\tlog10: { holds: (low) => low > 0, needs: \"greater than zero\" },\n\texp: {\n\t\tholds: (_, high, type) =>\n\t\t\ttype.kind === \"float\" &&\n\t\t\tNumber.isFinite(roundFloat(Math.exp(high), type)),\n\t\tneeds: \"small enough for a finite result\",\n\t},\n\tasin: {\n\t\tholds: (low, high) => low >= -1 && high <= 1,\n\t\tneeds: \"between -1 and 1\",\n\t},\n\tacos: {\n\t\tholds: (low, high) => low >= -1 && high <= 1,\n\t\tneeds: \"between -1 and 1\",\n\t},\n\tsin: undefined,\n\tcos: undefined,\n\ttan: undefined,\n\tatan: undefined,\n};\n\n/** A finite float operand keeps sine, cosine, tangent and arctangent finite; the others need their operand's domain proved. */\nconst operandDomainIssue = (\n\toperator: ElementaryFunction,\n\toperand: Expression,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tconst domain = domains[operator];\n\tif (!domain) {\n\t\treturn undefined;\n\t}\n\tconst bounds = floatBounds(operand, proof);\n\tif (bounds && domain.holds(bounds[0], bounds[1], type)) {\n\t\treturn undefined;\n\t}\n\treturn `${operator} needs its operand proved ${domain.needs}, as a constant or an integer converted exactly is.`;\n};\n\n/** A power needs a constant exponent and a base whose proved bounds keep the result real and finite. */\nconst powerIssue = (\n\texpression: Extract<Expression, { kind: \"binary\" }>,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tconst folded = proof.fold(expression);\n\tif (folded) {\n\t\treturn constantFits(folded, type)\n\t\t\t? undefined\n\t\t\t: \"Floating result is not finite or representable.\";\n\t}\n\tconst exponent = proof.fold(expression.right);\n\tconst base = floatBounds(expression.left, proof);\n\tif (exponent?.kind !== \"float\" || !base || type.kind !== \"float\") {\n\t\treturn \"A power needs a constant exponent and a base proved within bounds, as a constant or an integer converted exactly is.\";\n\t}\n\tconst [low, high] = base;\n\tif (!Number.isInteger(exponent.value) && low < 0) {\n\t\treturn \"A fractional power needs its base proved not negative.\";\n\t}\n\tif (exponent.value < 0 && low <= 0 && high >= 0) {\n\t\treturn \"A negative power needs its base proved not zero.\";\n\t}\n\tconst magnitudes = [Math.abs(low), Math.abs(high)];\n\tconst largest =\n\t\texponent.value >= 0\n\t\t\t? Math.max(...magnitudes) ** exponent.value\n\t\t\t: Math.min(...magnitudes) ** exponent.value;\n\treturn Number.isFinite(roundFloat(largest, type))\n\t\t? undefined\n\t\t: \"The power may not be finite.\";\n};\n\n/** Whether an arithmetic result is proved to stay in its integer type, or finite in its float type. */\nconst resultIssue = (\n\texpression: Extract<Expression, { kind: \"unary\" | \"binary\" }>,\n\ttype: PlcType,\n\tproof: Proof,\n): string | undefined => {\n\tif (integerType(type)) {\n\t\tconst result = proof.interval(expression);\n\t\tif (\n\t\t\t!(wrapsNatively(expression) && !proof.fold(expression)) &&\n\t\t\t(!result || !within(result, integerRange(type)))\n\t\t) {\n\t\t\treturn \"Arithmetic may overflow; widen the result or use an explicit wrap/saturate operation.\";\n\t\t}\n\t\treturn undefined;\n\t}\n\tif (type.kind !== \"float\") {\n\t\treturn undefined;\n\t}\n\tconst result = proof.fold(expression);\n\tif (result) {\n\t\treturn constantFits(result, type)\n\t\t\t? undefined\n\t\t\t: \"Floating result is not finite or representable.\";\n\t}\n\tif (expression.kind === \"unary\") {\n\t\treturn undefined;\n\t}\n\tconst lhs = proof.fold(expression.left);\n\tconst rhs = proof.fold(expression.right);\n\tif (\n\t\t[\"add\", \"subtract\"].includes(expression.operator) &&\n\t\t(lhs?.kind === \"float\" || rhs?.kind === \"float\")\n\t) {\n\t\t// Addition/subtraction and nearest rounding are monotone. Checking both\n\t\t// finite endpoints proves every finite input without changing its arithmetic.\n\t\tconst maximum = floatMaximum(type);\n\t\tconst finite = [-maximum, maximum].every((endpoint) => {\n\t\t\tconst a = lhs?.kind === \"float\" ? lhs.value : endpoint;\n\t\t\tconst b = rhs?.kind === \"float\" ? rhs.value : endpoint;\n\t\t\tconst value = expression.operator === \"add\" ? a + b : a - b;\n\t\t\treturn Number.isFinite(roundFloat(value, type));\n\t\t});\n\t\tif (finite) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\tif (\n\t\trhs?.kind === \"float\" &&\n\t\trhs.value === 1 &&\n\t\t[\"multiply\", \"divide\"].includes(expression.operator)\n\t) {\n\t\treturn undefined;\n\t}\n\treturn \"Floating arithmetic must prove a finite result.\";\n};\n",
14
+ "import type { BinaryOperator, UnaryOperator } from \"@tsplc/iec/arithmetic\";\nimport type { SourceSpan } from \"./diagnostics\";\nimport type {\n\tConstant,\n\tFunctionBlock,\n\tPlcFunction,\n\tPlcModule,\n\tPlcProgram,\n\tTelemetryCall,\n\tVariable,\n} from \"./model\";\nimport { instancedBlock, type PlcType } from \"./types\";\n\n// Core expressions contain no source-level calls. Their effects have already\n// become ordered statements, and every place has passed storage/bounds checks.\nexport type CorePath = readonly (\n\t| { readonly kind: \"field\"; readonly name: string }\n\t| { readonly kind: \"index\"; readonly value: CoreExpression }\n)[];\nexport interface CheckedPlace {\n\treadonly root: string;\n\treadonly path: CorePath;\n}\nexport type CoreExpression = {\n\treadonly type: string;\n\treadonly span: SourceSpan;\n} & (\n\t| { readonly kind: \"borrow\"; readonly place: CheckedPlace }\n\t| { readonly kind: \"constant\"; readonly value: Constant }\n\t| { readonly kind: \"load\"; readonly root: string; readonly path?: CorePath }\n\t| {\n\t\t\treadonly kind: \"unary\";\n\t\t\treadonly operator: UnaryOperator;\n\t\t\treadonly operand: CoreExpression;\n\t }\n\t| {\n\t\t\treadonly kind: \"binary\";\n\t\t\treadonly operator: BinaryOperator;\n\t\t\treadonly left: CoreExpression;\n\t\t\treadonly right: CoreExpression;\n\t\t\treadonly policy?: \"wrap\" | \"saturate\";\n\t }\n\t| {\n\t\t\treadonly kind: \"convert\";\n\t\t\treadonly operand: CoreExpression;\n\t\t\treadonly policy: \"exact\" | \"wrap\" | \"saturate\";\n\t }\n);\nexport type CoreStatement = { readonly span: SourceSpan } & (\n\t| {\n\t\t\treadonly kind: \"assign\";\n\t\t\treadonly root: string;\n\t\t\treadonly path?: CorePath;\n\t\t\treadonly value: CoreExpression;\n\t }\n\t| {\n\t\t\treadonly kind: \"if\";\n\t\t\treadonly condition: CoreExpression;\n\t\t\treadonly then: readonly CoreStatement[];\n\t\t\treadonly else: readonly CoreStatement[];\n\t }\n\t| {\n\t\t\treadonly kind: \"switch\";\n\t\t\treadonly value: CoreExpression;\n\t\t\treadonly cases: readonly {\n\t\t\t\tvalues: readonly Constant[];\n\t\t\t\tbody: readonly CoreStatement[];\n\t\t\t}[];\n\t\t\treadonly fallback: readonly CoreStatement[];\n\t }\n\t| {\n\t\t\treadonly kind: \"for\";\n\t\t\treadonly counter: string;\n\t\t\treadonly counterScope?: \"existing\";\n\t\t\treadonly start: Constant;\n\t\t\treadonly limit: Constant;\n\t\t\treadonly step: string;\n\t\t\treadonly dynamic?: {\n\t\t\t\treadonly start: CoreExpression;\n\t\t\t\treadonly limit: CoreExpression;\n\t\t\t\treadonly exclusive?: true;\n\t\t\t};\n\t\t\treadonly maxIterations: number;\n\t\t\treadonly body: readonly CoreStatement[];\n\t }\n\t| {\n\t\t\treadonly kind: \"invoke\";\n\t\t\treadonly function: string;\n\t\t\treadonly instance?: string;\n\t\t\treadonly index?: CoreExpression;\n\t\t\treadonly arguments: readonly CoreExpression[];\n\t\t\treadonly destination?: string;\n\t }\n\t| {\n\t\t\treadonly kind: \"blockUpdate\";\n\t\t\treadonly instance: string;\n\t\t\treadonly index?: CoreExpression;\n\t\t\treadonly inputs: Readonly<Record<string, CoreExpression>>;\n\t }\n\t| { readonly kind: \"return\"; readonly value?: CoreExpression }\n\t| { readonly kind: \"break\" | \"continue\" }\n\t| ({ readonly kind: \"telemetry\" } & TelemetryCall<CoreExpression>)\n);\n/** Whether a statement assigns the whole of `root`. */\nexport const wholeAssign = (\n\titem: CoreStatement | undefined,\n\troot: string,\n): item is Extract<CoreStatement, { kind: \"assign\" }> =>\n\titem?.kind === \"assign\" && item.root === root && !item.path?.length;\n/** The statement lists nested directly inside a statement. */\nexport const nestedBodies = (\n\titem: CoreStatement,\n): readonly (readonly CoreStatement[])[] => {\n\tif (item.kind === \"if\") {\n\t\treturn [item.then, item.else];\n\t}\n\tif (item.kind === \"switch\") {\n\t\treturn [...item.cases.map((branch) => branch.body), item.fallback];\n\t}\n\tif (item.kind === \"for\") {\n\t\treturn [item.body];\n\t}\n\treturn [];\n};\n/** A statement with each list `nestedBodies` returns replaced by `map` of it. */\nexport const mapBodies = (\n\titem: CoreStatement,\n\tmap: (body: readonly CoreStatement[]) => readonly CoreStatement[],\n): CoreStatement => {\n\tswitch (item.kind) {\n\t\tcase \"if\":\n\t\t\t// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n\t\t\treturn { ...item, then: map(item.then), else: map(item.else) };\n\t\tcase \"switch\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\tcases: item.cases.map((branch) => ({\n\t\t\t\t\t...branch,\n\t\t\t\t\tbody: map(branch.body),\n\t\t\t\t})),\n\t\t\t\tfallback: map(item.fallback),\n\t\t\t};\n\t\tcase \"for\":\n\t\t\treturn { ...item, body: map(item.body) };\n\t\tdefault:\n\t\t\treturn item;\n\t}\n};\n/**\n * The storage roots a statement writes itself, in statement order: an assignment's target, a\n * loop's counter, a call's destination and every place it borrows. Nested bodies and the\n * routines a call runs are the caller's to follow.\n */\nexport const directWrites = (item: CoreStatement): readonly string[] => {\n\tif (item.kind === \"assign\") {\n\t\treturn [item.root];\n\t}\n\tif (item.kind === \"for\") {\n\t\treturn [item.counter];\n\t}\n\tif (item.kind === \"invoke\") {\n\t\treturn [\n\t\t\t...(item.destination ? [item.destination] : []),\n\t\t\t...item.arguments.flatMap((argument) =>\n\t\t\t\targument.kind === \"borrow\" ? [argument.place.root] : [],\n\t\t\t),\n\t\t];\n\t}\n\tif (item.kind === \"blockUpdate\") {\n\t\treturn Object.values(item.inputs).flatMap((input) =>\n\t\t\tinput.kind === \"borrow\" ? [input.place.root] : [],\n\t\t);\n\t}\n\treturn [];\n};\n/** The routine a statement runs: an invoke's function, or the block its instance's type instantiates. */\nexport const calledRoutine = (\n\titem: CoreStatement,\n\tvariableOf: (id: string) => Variable | undefined,\n\ttypes: ReadonlyMap<string, PlcType>,\n): string | undefined => {\n\tif (item.kind === \"invoke\") {\n\t\treturn item.function;\n\t}\n\tif (item.kind !== \"blockUpdate\") {\n\t\treturn undefined;\n\t}\n\tconst variable = variableOf(item.instance);\n\treturn variable && instancedBlock(variable.type, types)?.block;\n};\nexport interface CoreFunction\n\textends Readonly<Omit<PlcFunction, \"body\" | \"bounds\">> {\n\treadonly body: readonly CoreStatement[];\n}\nexport interface CoreFunctionBlock\n\textends Readonly<Omit<FunctionBlock, \"body\">> {\n\treadonly body: readonly CoreStatement[];\n}\nexport const verified: unique symbol = Symbol(\"verified core\");\nexport interface VerifiedCoreModule {\n\treadonly [verified]: true;\n\treadonly folded?: PlcModule[\"folded\"];\n\treadonly references?: PlcModule[\"references\"];\n\treadonly types: readonly PlcType[];\n\treadonly variables: readonly Variable[];\n\treadonly functions: readonly CoreFunction[];\n\treadonly blocks: readonly CoreFunctionBlock[];\n\treadonly programs: readonly PlcProgram[];\n}\n\nconst verifiedModules = new WeakSet<object>();\nexport function isVerifiedCore(value: unknown): value is VerifiedCoreModule {\n\treturn (\n\t\ttypeof value === \"object\" && value !== null && verifiedModules.has(value)\n\t);\n}\n\n/** Freezes a value and everything it holds. */\nexport function freeze(value: unknown): void {\n\tif (typeof value !== \"object\" || value === null || Object.isFrozen(value)) {\n\t\treturn;\n\t}\n\tfor (const child of Object.values(value)) {\n\t\tfreeze(child);\n\t}\n\tObject.freeze(value);\n}\n\n/**\n * Admits a module across the trust boundary. Only normalization, and transformations of an\n * admitted module that keep what it verified, call this.\n */\nexport function admitCore(core: VerifiedCoreModule): VerifiedCoreModule {\n\tfreeze(core);\n\tverifiedModules.add(core);\n\treturn core;\n}\n\n/** Whether a routine is a function block rather than a function. */\nexport function isBlockRoutine(\n\troutine: CoreFunction | CoreFunctionBlock,\n): routine is CoreFunctionBlock;\nexport function isBlockRoutine(\n\troutine: PlcFunction | FunctionBlock,\n): routine is FunctionBlock;\nexport function isBlockRoutine(\n\troutine: CoreFunction | CoreFunctionBlock | PlcFunction | FunctionBlock,\n): boolean {\n\treturn \"inputs\" in routine;\n}\n\n/** The fields of a block's instance, in the order its type declares them: inputs, outputs, then state. */\nexport const instanceFields = (\n\tblock: CoreFunctionBlock,\n): readonly Variable[] => [...block.inputs, ...block.outputs, ...block.state];\n\n/** Every variable a routine declares: a function's parameters and locals, a block's ports, state and locals. */\nexport const routineVariables = (\n\troutine: CoreFunction | CoreFunctionBlock,\n): readonly Variable[] =>\n\tisBlockRoutine(routine)\n\t\t? [...instanceFields(routine), ...routine.locals]\n\t\t: [...routine.parameters, ...routine.locals];\n\nconst temporaryPrefix = (routine: string) => `${routine}:temporary:`;\nexport const temporaryId = (routine: string, index: number) =>\n\t`${temporaryPrefix(routine)}${index}`;\n\n/** Whether a local is a temporary the normalizer made for `routine`, rather than one its source declares. */\nexport function isTemporary(routine: string, variable: Variable): boolean {\n\tconst prefix = temporaryPrefix(routine);\n\treturn (\n\t\tvariable.storage === \"local\" &&\n\t\tvariable.id.startsWith(prefix) &&\n\t\t/^\\d+$/.test(variable.id.slice(prefix.length))\n\t);\n}\n\n/**\n * An index's value when it is an integer constant. Structural, because conditions' reconstructions\n * carry indexes too, and they are not core expressions.\n */\nexport const constantIndex = (expression: {\n\treadonly kind: string;\n\treadonly value?: Constant;\n}): number | undefined =>\n\texpression.kind === \"constant\" && expression.value?.kind === \"integer\"\n\t\t? Number(expression.value.value)\n\t\t: undefined;\n",
15
+ "import {\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CorePath,\n\ttype CoreStatement,\n\tcalledRoutine,\n\troutineVariables,\n\ttype VerifiedCoreModule,\n} from \"./core-model\";\nimport type { Variable } from \"./model\";\nimport type { PlcType } from \"./types\";\n\n/** The entry `id` names in a table that admission closed over every reference, so a miss is a compiler bug. */\nexport const lookup = <Key, T>(\n\ttable: ReadonlyMap<Key, T>,\n\tid: Key,\n\tkind: string,\n): T => {\n\tconst entry = table.get(id);\n\tif (entry === undefined) {\n\t\tthrow new Error(`Unknown ${kind} ${String(id)}.`);\n\t}\n\treturn entry;\n};\n\nexport interface CoreTables {\n\treadonly types: ReadonlyMap<string, PlcType>;\n\treadonly functions: ReadonlyMap<string, CoreFunction>;\n\treadonly blocks: ReadonlyMap<string, CoreFunctionBlock>;\n\t/** Module storage, and each routine's parameters, locals and members. */\n\treadonly variables: ReadonlyMap<string, Variable>;\n\treadonly typeOf: (id: string) => PlcType;\n\treadonly functionOf: (id: string) => CoreFunction;\n\treadonly blockOf: (id: string) => CoreFunctionBlock;\n\treadonly variableOf: (id: string) => Variable;\n\t/** The routine a statement runs, as `calledRoutine` names it. */\n\treadonly calledRoutineOf: (\n\t\titem: CoreStatement,\n\t) => CoreFunction | CoreFunctionBlock | undefined;\n\treadonly updatedBlock: (\n\t\titem: Extract<CoreStatement, { kind: \"blockUpdate\" }>,\n\t) => CoreFunctionBlock;\n\t/** The type a path selects from a root type through record fields and array elements. */\n\treadonly placeType: (rootType: string, path: CorePath) => PlcType | undefined;\n}\n\nconst built = new WeakMap<VerifiedCoreModule, CoreTables>();\n\nconst buildTables = (core: VerifiedCoreModule): CoreTables => {\n\tconst types = new Map(core.types.map((type) => [type.id, type]));\n\tconst functions = new Map(core.functions.map((fn) => [fn.id, fn]));\n\tconst blocks = new Map(core.blocks.map((block) => [block.id, block]));\n\tconst variables = new Map(\n\t\t[\n\t\t\t...core.variables,\n\t\t\t...core.functions.flatMap(routineVariables),\n\t\t\t...core.blocks.flatMap(routineVariables),\n\t\t].map((variable) => [variable.id, variable]),\n\t);\n\tconst functionOf = (id: string) => lookup(functions, id, \"function\");\n\tconst blockOf = (id: string) => lookup(blocks, id, \"block\");\n\tconst variableOf = (id: string) => lookup(variables, id, \"variable\");\n\treturn {\n\t\ttypes,\n\t\tfunctions,\n\t\tblocks,\n\t\tvariables,\n\t\ttypeOf: (id) => lookup(types, id, \"type\"),\n\t\tfunctionOf,\n\t\tblockOf,\n\t\tvariableOf,\n\t\tcalledRoutineOf: (item) => {\n\t\t\tconst called = calledRoutine(item, variableOf, types);\n\t\t\tif (called === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn item.kind === \"invoke\" ? functionOf(called) : blockOf(called);\n\t\t},\n\t\tupdatedBlock: (item) => {\n\t\t\tconst called = calledRoutine(item, variableOf, types);\n\t\t\tif (called === undefined) {\n\t\t\t\tthrow new Error(`${item.instance} is not a block instance.`);\n\t\t\t}\n\t\t\treturn blockOf(called);\n\t\t},\n\t\tplaceType: (rootType, path) =>\n\t\t\tpath.reduce<PlcType | undefined>((type, segment) => {\n\t\t\t\tif (segment.kind === \"field\" && type?.kind === \"record\") {\n\t\t\t\t\tconst field = type.fields.find(\n\t\t\t\t\t\t(candidate) => candidate.name === segment.name,\n\t\t\t\t\t);\n\t\t\t\t\treturn field && types.get(field.type);\n\t\t\t\t}\n\t\t\t\tif (segment.kind === \"index\" && type?.kind === \"array\") {\n\t\t\t\t\treturn types.get(type.element);\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t}, types.get(rootType)),\n\t};\n};\n\n/** A verified module's types, routines and variables by id, built once per module: it is frozen. */\nexport const coreTables = (core: VerifiedCoreModule): CoreTables => {\n\tconst known = built.get(core);\n\tif (known) {\n\t\treturn known;\n\t}\n\tconst tables = buildTables(core);\n\tbuilt.set(core, tables);\n\treturn tables;\n};\n",
16
+ "import {\n\ttype CoreExpression,\n\ttype CoreStatement,\n\twholeAssign,\n} from \"./core-model\";\nimport type { SourceSpan } from \"./diagnostics\";\n\ntype Assign = Extract<CoreStatement, { kind: \"assign\" }>;\ntype If = Extract<CoreStatement, { kind: \"if\" }>;\n\n/** An operand that runs only on one branch: the statements that evaluate it, then its value. */\nexport interface BranchOperand {\n\treadonly statements: readonly CoreStatement[];\n\treadonly value: CoreExpression;\n}\n\n/** Where a lowered `&&`, `||` or `?:` stores its result: a BOOL temporary for `&&` and `||`. */\ninterface Result {\n\treadonly root: string;\n\treadonly type: string;\n}\n\nconst store = (result: Result, value: CoreExpression, span: SourceSpan) =>\n\t({ kind: \"assign\", root: result.root, value, span }) satisfies Assign;\n\n/**\n * `left && right` as `t := left; IF t THEN …; t := right END_IF`, and `||` the same under\n * `IF NOT t`, so `right` runs only when `left` does not decide.\n */\nexport const lowerLogical = ({\n\toperator,\n\tresult,\n\tleft,\n\tright,\n\tspan,\n}: {\n\toperator: \"and\" | \"or\";\n\tresult: Result;\n\tleft: CoreExpression;\n\tright: BranchOperand;\n\tspan: SourceSpan;\n}): readonly [CoreStatement, CoreStatement] => {\n\tconst tested: CoreExpression = {\n\t\tkind: \"load\",\n\t\troot: result.root,\n\t\ttype: result.type,\n\t\tspan,\n\t};\n\treturn [\n\t\tstore(result, left, span),\n\t\t{\n\t\t\tkind: \"if\",\n\t\t\tcondition:\n\t\t\t\toperator === \"and\"\n\t\t\t\t\t? tested\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tkind: \"unary\",\n\t\t\t\t\t\t\toperator: \"not\",\n\t\t\t\t\t\t\toperand: tested,\n\t\t\t\t\t\t\ttype: \"BOOL\",\n\t\t\t\t\t\t\tspan,\n\t\t\t\t\t\t},\n\t\t\t// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n\t\t\tthen: [...right.statements, store(result, right.value, span)],\n\t\t\telse: [],\n\t\t\tspan,\n\t\t},\n\t];\n};\n\n/** The `&&` or `||` that `item` and `next` are, as `lowerLogical` writes it. */\nexport const loweredLogical = (\n\titem: CoreStatement,\n\tnext: CoreStatement | undefined,\n):\n\t| { operator: \"and\" | \"or\"; left: Assign; right: Assign; test: If }\n\t| undefined => {\n\tif (\n\t\titem.kind !== \"assign\" ||\n\t\titem.path?.length ||\n\t\tnext?.kind !== \"if\" ||\n\t\tnext.else.length\n\t) {\n\t\treturn undefined;\n\t}\n\tconst { condition } = next;\n\tconst negated = condition.kind === \"unary\" && condition.operator === \"not\";\n\tconst tested = negated ? condition.operand : condition;\n\tconst right = next.then.at(-1);\n\tif (\n\t\ttested.kind !== \"load\" ||\n\t\ttested.path?.length ||\n\t\ttested.root !== item.root ||\n\t\t!wholeAssign(right, item.root)\n\t) {\n\t\treturn undefined;\n\t}\n\treturn { operator: negated ? \"or\" : \"and\", left: item, right, test: next };\n};\n\n/** `condition ? then : else` as `IF condition THEN …; t := then ELSE …; t := else END_IF`. */\nexport const lowerSelect = ({\n\tresult,\n\tcondition,\n\twhenTrue,\n\twhenFalse,\n\tspan,\n}: {\n\tresult: Result;\n\tcondition: CoreExpression;\n\twhenTrue: BranchOperand;\n\twhenFalse: BranchOperand;\n\tspan: SourceSpan;\n}): CoreStatement => ({\n\tkind: \"if\",\n\tcondition,\n\t// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n\tthen: [...whenTrue.statements, store(result, whenTrue.value, span)],\n\telse: [...whenFalse.statements, store(result, whenFalse.value, span)],\n\tspan,\n});\n\n/** The `?:` that `item` is, as `lowerSelect` writes it. */\nexport const loweredSelect = (\n\titem: CoreStatement,\n): { root: string; test: If; then: Assign; else: Assign } | undefined => {\n\tif (item.kind !== \"if\") {\n\t\treturn undefined;\n\t}\n\tconst then = item.then.at(-1);\n\tconst otherwise = item.else.at(-1);\n\tif (\n\t\tthen?.kind !== \"assign\" ||\n\t\t!wholeAssign(then, then.root) ||\n\t\t!wholeAssign(otherwise, then.root)\n\t) {\n\t\treturn undefined;\n\t}\n\treturn { root: then.root, test: item, then, else: otherwise };\n};\n",
17
+ "import type { jobStateFields } from \"@tsplc/debug/manifest\";\nimport type { BinaryOperator, UnaryOperator } from \"@tsplc/iec/arithmetic\";\nimport {\n\ttype CoreExpression,\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CorePath,\n\ttype CoreStatement,\n\tconstantIndex,\n\tisBlockRoutine,\n\tisTemporary,\n\tnestedBodies,\n\twholeAssign,\n} from \"./core-model\";\nimport type { SourceSpan } from \"./diagnostics\";\nimport type { Constant, Variable } from \"./model\";\nimport { loweredLogical, loweredSelect } from \"./short-circuit\";\nimport { lookup } from \"./tables\";\n\ntype Routine = CoreFunction | CoreFunctionBlock;\ntype Assign = Extract<CoreStatement, { kind: \"assign\" }>;\ntype If = Extract<CoreStatement, { kind: \"if\" }>;\ntype For = Extract<CoreStatement, { kind: \"for\" }>;\ntype Invoke = Extract<CoreStatement, { kind: \"invoke\" }>;\n\nexport type ReconstructedSegment =\n\t| { readonly kind: \"field\"; readonly name: string }\n\t| { readonly kind: \"index\"; readonly value: Reconstruction };\n\n/**\n * A core expression as its source wrote it: the temporaries lowering made for captures, `&&`,\n * `||`, `?:`, record literals and call results inlined back into the expression they stand for.\n * Positions are pre-order statement indexes within the routine.\n */\nexport type Reconstruction = {\n\treadonly type: string;\n\treadonly span: SourceSpan;\n} & (\n\t| {\n\t\t\t/** Storage the routine doesn't own: module storage, or a field of the block it runs on. */\n\t\t\treadonly kind: \"read\";\n\t\t\treadonly root: string;\n\t\t\treadonly path: readonly ReconstructedSegment[];\n\t\t\t/** Where the value was captured. */\n\t\t\treadonly capturedAt: number;\n\t\t\t/** Whether a call runs between the capture and the use, and may have changed it. */\n\t\t\treadonly interleaved: boolean;\n\t }\n\t| { readonly kind: \"constant\"; readonly value: Constant }\n\t| {\n\t\t\treadonly kind: \"record\";\n\t\t\treadonly fields: Readonly<Record<string, Reconstruction>>;\n\t }\n\t| {\n\t\t\treadonly kind: \"array\";\n\t\t\t/** The index of the first item. */\n\t\t\treadonly lower: number;\n\t\t\treadonly items: readonly Reconstruction[];\n\t }\n\t| {\n\t\t\t/** A local the source declares, read at `at`. */\n\t\t\treadonly kind: \"local\";\n\t\t\treadonly root: string;\n\t\t\treadonly path: readonly ReconstructedSegment[];\n\t\t\treadonly at: number;\n\t }\n\t| {\n\t\t\treadonly kind: \"parameter\";\n\t\t\treadonly parameter: number;\n\t\t\treadonly root: string;\n\t\t\treadonly path: readonly ReconstructedSegment[];\n\t\t\treadonly at: number;\n\t }\n\t| {\n\t\t\t/** A call's result, or one of its fields. */\n\t\t\treadonly kind: \"call\";\n\t\t\treadonly call: Invoke;\n\t\t\treadonly path: readonly string[];\n\t }\n\t| { readonly kind: \"clock\" }\n\t| {\n\t\t\treadonly kind: \"unary\";\n\t\t\treadonly operator: Exclude<UnaryOperator, \"clock\">;\n\t\t\treadonly operand: Reconstruction;\n\t }\n\t| {\n\t\t\treadonly kind: \"binary\";\n\t\t\treadonly operator: Exclude<BinaryOperator, \"and\" | \"or\">;\n\t\t\treadonly policy?: \"wrap\" | \"saturate\";\n\t\t\treadonly left: Reconstruction;\n\t\t\treadonly right: Reconstruction;\n\t }\n\t| {\n\t\t\treadonly kind: \"convert\";\n\t\t\treadonly policy: \"exact\" | \"wrap\" | \"saturate\";\n\t\t\treadonly operand: Reconstruction;\n\t }\n\t| {\n\t\t\t/** `&&` or `||`: `right` is evaluated only when `left` doesn't decide. */\n\t\t\treadonly kind: \"logical\";\n\t\t\treadonly operator: \"and\" | \"or\";\n\t\t\treadonly left: Reconstruction;\n\t\t\treadonly right: Reconstruction;\n\t }\n\t| {\n\t\t\treadonly kind: \"select\";\n\t\t\treadonly condition: Reconstruction;\n\t\t\treadonly then: Reconstruction;\n\t\t\treadonly else: Reconstruction;\n\t }\n\t| {\n\t\t\treadonly kind: \"opaque\";\n\t\t\treadonly reason: string;\n\t\t\treadonly reads: readonly Reconstruction[];\n\t }\n);\n\n/** A condition a statement runs under. Tests carry `at`, the position that evaluates them. */\nexport type PathCondition =\n\t| {\n\t\t\treadonly kind: \"test\";\n\t\t\treadonly test: Reconstruction;\n\t\t\treadonly holds: boolean;\n\t\t\treadonly at: number;\n\t\t\treadonly span: SourceSpan;\n\t }\n\t| {\n\t\t\treadonly kind: \"cases\";\n\t\t\treadonly test: Reconstruction;\n\t\t\treadonly values: readonly Constant[];\n\t\t\treadonly member: boolean;\n\t\t\treadonly at: number;\n\t\t\treadonly span: SourceSpan;\n\t }\n\t| {\n\t\t\t/** Holds when none of the conjunctions holds: an earlier statement did not leave. */\n\t\t\treadonly kind: \"exits\";\n\t\t\treadonly any: readonly (readonly PathCondition[])[];\n\t }\n\t| { readonly kind: \"loop\"; readonly loop: number }\n\t/** Holds when no iteration of the loop returned from the routine. */\n\t| { readonly kind: \"loopReturns\"; readonly loop: number }\n\t/** A job's step `step` is current. */\n\t| { readonly kind: \"job\"; readonly step: number }\n\t/** The job is busy: its dispatcher returns at once otherwise. */\n\t| { readonly kind: \"jobBusy\" };\n\nexport interface StatementConditions {\n\treadonly position: number;\n\t/** Outermost first. */\n\treadonly conditions: readonly PathCondition[];\n\t/** The innermost loop the statement runs in, as an index into `loops`. */\n\treadonly loop: number | null;\n}\n\nexport interface LoopConditions {\n\treadonly statement: For;\n\treadonly position: number;\n\treadonly counter: string;\n\treadonly first: Reconstruction;\n\treadonly limit: Reconstruction;\n\treadonly exclusive: boolean;\n\treadonly step: bigint;\n\treadonly maxIterations: number;\n\t/** The conjunctions, within one iteration, under which a `break` stops the loop. */\n\treadonly breaks: readonly (readonly PathCondition[])[];\n\t/** Whether an iteration can return from the routine. */\n\treadonly returns: boolean;\n\treadonly parent: number | null;\n}\n\nexport interface RoutineConditions {\n\treadonly statements: ReadonlyMap<CoreStatement, StatementConditions>;\n\treadonly loops: readonly LoopConditions[];\n\t/** `expression` as the source wrote it, used at position `at`. */\n\treadonly reconstruct: (\n\t\texpression: CoreExpression,\n\t\tat: number,\n\t) => Reconstruction;\n}\n\ntype Conjunction = readonly PathCondition[];\ninterface Exits {\n\treadonly returns: readonly Conjunction[];\n\treadonly breaks: readonly Conjunction[];\n\treadonly continues: readonly Conjunction[];\n}\nconst noExits: Exits = { returns: [], breaks: [], continues: [] };\n\nconst prefixed = (conditions: Conjunction, exits: Exits): Exits => ({\n\treturns: exits.returns.map((item) => [...conditions, ...item]),\n\tbreaks: exits.breaks.map((item) => [...conditions, ...item]),\n\tcontinues: exits.continues.map((item) => [...conditions, ...item]),\n});\n\nconst merged = (...all: readonly Exits[]): Exits => ({\n\treturns: all.flatMap((exits) => exits.returns),\n\tbreaks: all.flatMap((exits) => exits.breaks),\n\tcontinues: all.flatMap((exits) => exits.continues),\n});\n\n/** A field of a job's state, which the frontend's generated job block declares. */\nconst jobField = (\n\tjob: CoreFunctionBlock,\n\tname: keyof typeof jobStateFields,\n): string | undefined => job.state.find((field) => field.name === name)?.id;\n\n/** A constant's field or element, when it has one. */\nconst constantPart = (\n\tvalue: Constant,\n\tsegment: ReconstructedSegment,\n): Constant | undefined => {\n\tif (segment.kind === \"field\") {\n\t\treturn value.kind === \"record\" ? value.fields[segment.name] : undefined;\n\t}\n\tconst index = constantIndex(segment.value);\n\treturn value.kind === \"array\" && index !== undefined\n\t\t? value.items[index]\n\t\t: undefined;\n};\n\n/** The names along a path of fields and constant indexes, or nothing when an index is dynamic. */\nexport const staticNames = (\n\tpath: readonly ReconstructedSegment[],\n): string[] | undefined => {\n\tconst names: string[] = [];\n\tfor (const segment of path) {\n\t\tif (segment.kind === \"field\") {\n\t\t\tnames.push(segment.name);\n\t\t\tcontinue;\n\t\t}\n\t\tif (\n\t\t\tsegment.value.kind !== \"constant\" ||\n\t\t\tsegment.value.value.kind !== \"integer\"\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tnames.push(segment.value.value.value);\n\t}\n\treturn names;\n};\n\nconst opaque = (\n\treason: string,\n\ttype: string,\n\tspan: SourceSpan,\n\treads: readonly Reconstruction[] = [],\n): Reconstruction => ({ kind: \"opaque\", reason, reads, type, span });\n\n/** A part of a reconstructed value: a field or element of a record, array, constant or place. */\nexport const projectReconstruction = (\n\tnode: Reconstruction,\n\tpath: readonly ReconstructedSegment[],\n\ttype: string,\n): Reconstruction => {\n\tconst [segment, ...rest] = path;\n\tif (!segment) {\n\t\treturn node;\n\t}\n\tswitch (node.kind) {\n\t\tcase \"read\":\n\t\tcase \"local\":\n\t\tcase \"parameter\":\n\t\t\treturn { ...node, path: [...node.path, ...path], type };\n\t\tcase \"call\": {\n\t\t\tconst names = staticNames(path);\n\t\t\treturn names\n\t\t\t\t? { ...node, path: [...node.path, ...names], type }\n\t\t\t\t: opaque(\"a call result at a dynamic index\", type, node.span);\n\t\t}\n\t\tcase \"record\": {\n\t\t\tconst field =\n\t\t\t\tsegment.kind === \"field\" ? node.fields[segment.name] : undefined;\n\t\t\treturn field\n\t\t\t\t? projectReconstruction(field, rest, type)\n\t\t\t\t: opaque(\"a field the record doesn't set\", type, node.span);\n\t\t}\n\t\tcase \"array\": {\n\t\t\tconst index =\n\t\t\t\tsegment.kind === \"index\" ? constantIndex(segment.value) : undefined;\n\t\t\tconst item =\n\t\t\t\tindex === undefined ? undefined : node.items[index - node.lower];\n\t\t\treturn item\n\t\t\t\t? projectReconstruction(item, rest, type)\n\t\t\t\t: opaque(\"an element at a dynamic index\", type, node.span);\n\t\t}\n\t\tcase \"constant\": {\n\t\t\tconst part = constantPart(node.value, segment);\n\t\t\treturn part\n\t\t\t\t? projectReconstruction(\n\t\t\t\t\t\t{ kind: \"constant\", value: part, type, span: node.span },\n\t\t\t\t\t\trest,\n\t\t\t\t\t\ttype,\n\t\t\t\t\t)\n\t\t\t\t: opaque(\"a part of a constant\", type, node.span);\n\t\t}\n\t\tcase \"select\":\n\t\t\treturn {\n\t\t\t\t...node,\n\t\t\t\ttype,\n\t\t\t\t// biome-ignore lint/suspicious/noThenProperty: a reconstructed `?:` is data, not a thenable.\n\t\t\t\tthen: projectReconstruction(node.then, path, type),\n\t\t\t\telse: projectReconstruction(node.else, path, type),\n\t\t\t};\n\t\tdefault:\n\t\t\treturn opaque(\"a part of a computed value\", type, node.span, [node]);\n\t}\n};\n\n/**\n * Each statement's conditions from routine entry, and the inverse of `routine.ts`'s lowering\n * for the expressions it evaluates. `variables` resolves the types of storage the routine\n * doesn't declare, such as a stored loop counter.\n */\nexport function pathConditions(\n\troutine: Routine,\n\tvariables: ReadonlyMap<string, Pick<Variable, \"type\">>,\n): RoutineConditions {\n\tconst temporaries = new Set(\n\t\troutine.locals\n\t\t\t.filter((local) => isTemporary(routine.id, local))\n\t\t\t.map((local) => local.id),\n\t);\n\tconst locals = new Map(\n\t\troutine.locals\n\t\t\t.filter((local) => !temporaries.has(local.id))\n\t\t\t.map((local) => [local.id, local]),\n\t);\n\tconst parameters = new Map(\n\t\tisBlockRoutine(routine)\n\t\t\t? []\n\t\t\t: routine.parameters.map((parameter, index) => [parameter.id, index]),\n\t);\n\tconst typeOf = (root: string): string | undefined =>\n\t\tlocals.get(root)?.type ??\n\t\t(isBlockRoutine(routine)\n\t\t\t? undefined\n\t\t\t: routine.parameters.find((parameter) => parameter.id === root)?.type) ??\n\t\tvariables.get(root)?.type;\n\n\tconst positions = new Map<CoreStatement, number>();\n\tconst calls: number[] = [];\n\tconst definitions = new Map<string, CoreStatement[]>();\n\tconst logicals = new Map<\n\t\tstring,\n\t\t{ operator: \"and\" | \"or\"; left: Assign; right: Assign }\n\t>();\n\tconst synthetic = new Map<If, { operator: \"and\" | \"or\"; left: Assign }>();\n\tconst selects = new Map<string, { test: If; then: Assign; else: Assign }>();\n\tconst sequences: (readonly CoreStatement[])[] = [];\n\tconst number = (items: readonly CoreStatement[]): void => {\n\t\tsequences.push(items);\n\t\tfor (const item of items) {\n\t\t\tpositions.set(item, positions.size);\n\t\t\tif (item.kind === \"invoke\" || item.kind === \"blockUpdate\") {\n\t\t\t\tcalls.push(positions.size - 1);\n\t\t\t}\n\t\t\tconst defined =\n\t\t\t\titem.kind === \"assign\"\n\t\t\t\t\t? item.root\n\t\t\t\t\t: (item.kind === \"invoke\" && item.destination) || undefined;\n\t\t\tif (defined && temporaries.has(defined)) {\n\t\t\t\tdefinitions.set(defined, [...(definitions.get(defined) ?? []), item]);\n\t\t\t}\n\t\t\tnestedBodies(item).forEach(number);\n\t\t}\n\t};\n\tnumber(routine.body);\n\tconst position = (item: CoreStatement): number =>\n\t\tlookup(positions, item, \"statement\");\n\t// A temporary that only a lowered `&&`, `||` or `?:` defines stands for it.\n\tconst lowered = (root: string) =>\n\t\ttemporaries.has(root) && definitions.get(root)?.length === 2;\n\tfor (const items of sequences) {\n\t\titems.forEach((item, index) => {\n\t\t\tconst logical = loweredLogical(item, items[index + 1]);\n\t\t\tif (logical && lowered(logical.left.root)) {\n\t\t\t\tconst { operator, left, right, test } = logical;\n\t\t\t\tlogicals.set(left.root, { operator, left, right });\n\t\t\t\tsynthetic.set(test, { operator, left });\n\t\t\t}\n\t\t\tconst select = loweredSelect(item);\n\t\t\tif (select && lowered(select.root)) {\n\t\t\t\tselects.set(select.root, select);\n\t\t\t}\n\t\t});\n\t}\n\n\tconst interleaved = (capturedAt: number, at: number): boolean =>\n\t\tcalls.some((call) => call > capturedAt && call < at);\n\n\tconst segments = (path: CorePath, at: number): ReconstructedSegment[] =>\n\t\tpath.map((segment) =>\n\t\t\tsegment.kind === \"field\"\n\t\t\t\t? segment\n\t\t\t\t: { kind: \"index\", value: reconstruct(segment.value, at) },\n\t\t);\n\n\t/** A stored, local or parameter place, read where it was captured. */\n\tconst place = (\n\t\troot: string,\n\t\tpath: readonly ReconstructedSegment[],\n\t\tcapturedAt: number,\n\t\tat: number,\n\t\ttype: string,\n\t\tspan: SourceSpan,\n\t): Reconstruction => {\n\t\tif (temporaries.has(root)) {\n\t\t\treturn temporary(root, path, at, type, span);\n\t\t}\n\t\tif (locals.has(root)) {\n\t\t\treturn { kind: \"local\", root, path, at: capturedAt, type, span };\n\t\t}\n\t\tconst parameter = parameters.get(root);\n\t\tif (parameter !== undefined) {\n\t\t\treturn {\n\t\t\t\tkind: \"parameter\",\n\t\t\t\tparameter,\n\t\t\t\troot,\n\t\t\t\tpath,\n\t\t\t\tat: capturedAt,\n\t\t\t\ttype,\n\t\t\t\tspan,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tkind: \"read\",\n\t\t\troot,\n\t\t\tpath,\n\t\t\tcapturedAt,\n\t\t\tinterleaved: interleaved(capturedAt, at),\n\t\t\ttype,\n\t\t\tspan,\n\t\t};\n\t};\n\n\tconst temporary = (\n\t\troot: string,\n\t\tpath: readonly ReconstructedSegment[],\n\t\tat: number,\n\t\ttype: string,\n\t\tspan: SourceSpan,\n\t): Reconstruction => {\n\t\tconst logical = logicals.get(root);\n\t\tif (logical) {\n\t\t\treturn projectReconstruction(\n\t\t\t\t{\n\t\t\t\t\tkind: \"logical\",\n\t\t\t\t\toperator: logical.operator,\n\t\t\t\t\tleft: reconstruct(logical.left.value, position(logical.left)),\n\t\t\t\t\tright: reconstruct(logical.right.value, position(logical.right)),\n\t\t\t\t\ttype: \"BOOL\",\n\t\t\t\t\tspan,\n\t\t\t\t},\n\t\t\t\tpath,\n\t\t\t\ttype,\n\t\t\t);\n\t\t}\n\t\tconst select = selects.get(root);\n\t\tif (select) {\n\t\t\tconst branch = (item: Assign) => reconstruct(item.value, position(item));\n\t\t\treturn projectReconstruction(\n\t\t\t\t{\n\t\t\t\t\tkind: \"select\",\n\t\t\t\t\tcondition: reconstruct(select.test.condition, position(select.test)),\n\t\t\t\t\t// biome-ignore lint/suspicious/noThenProperty: a reconstructed `?:` is data, not a thenable.\n\t\t\t\t\tthen: branch(select.then),\n\t\t\t\t\telse: branch(select.else),\n\t\t\t\t\ttype: select.then.value.type,\n\t\t\t\t\tspan,\n\t\t\t\t},\n\t\t\t\tpath,\n\t\t\t\ttype,\n\t\t\t);\n\t\t}\n\t\tconst defined = definitions.get(root) ?? [];\n\t\tconst [only] = defined;\n\t\tif (defined.length === 1 && only?.kind === \"invoke\") {\n\t\t\treturn projectReconstruction(\n\t\t\t\t{\n\t\t\t\t\tkind: \"call\",\n\t\t\t\t\tcall: only,\n\t\t\t\t\tpath: [],\n\t\t\t\t\ttype: typeOf(root) ?? type,\n\t\t\t\t\tspan: only.span,\n\t\t\t\t},\n\t\t\t\tpath,\n\t\t\t\ttype,\n\t\t\t);\n\t\t}\n\t\tif (defined.length === 1 && only && wholeAssign(only, root)) {\n\t\t\tconst value = only.value;\n\t\t\tif (value.kind === \"load\") {\n\t\t\t\treturn place(\n\t\t\t\t\tvalue.root,\n\t\t\t\t\t[...segments(value.path ?? [], position(only)), ...path],\n\t\t\t\t\tposition(only),\n\t\t\t\t\tat,\n\t\t\t\t\ttype,\n\t\t\t\t\tvalue.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn projectReconstruction(\n\t\t\t\treconstruct(value, position(only)),\n\t\t\t\tpath,\n\t\t\t\ttype,\n\t\t\t);\n\t\t}\n\t\treturn parts(root, defined, path, type, span);\n\t};\n\n\t/** A temporary built field by field or element by element: a record or array literal, or an `.out` snapshot. */\n\tconst parts = (\n\t\troot: string,\n\t\tdefined: readonly CoreStatement[],\n\t\tpath: readonly ReconstructedSegment[],\n\t\ttype: string,\n\t\tspan: SourceSpan,\n\t): Reconstruction => {\n\t\tconst fields = new Map<string, Assign>();\n\t\tconst items = new Map<number, Assign>();\n\t\tfor (const item of defined) {\n\t\t\tconst [segment, ...rest] =\n\t\t\t\titem.kind === \"assign\" ? (item.path ?? []) : [];\n\t\t\tconst index =\n\t\t\t\tsegment?.kind === \"index\" ? constantIndex(segment.value) : undefined;\n\t\t\tif (item.kind !== \"assign\" || !segment || rest.length) {\n\t\t\t\treturn opaque(\"a value set in several places\", type, span);\n\t\t\t}\n\t\t\tif (segment.kind === \"field\" && !fields.has(segment.name)) {\n\t\t\t\tfields.set(segment.name, item);\n\t\t\t} else if (index !== undefined && !items.has(index) && !fields.size) {\n\t\t\t\titems.set(index, item);\n\t\t\t} else {\n\t\t\t\treturn opaque(\"a value set in several places\", type, span);\n\t\t\t}\n\t\t}\n\t\tconst value = (item: Assign) => reconstruct(item.value, position(item));\n\t\tif (items.size) {\n\t\t\tconst indexes = [...items.keys()].sort((a, b) => a - b);\n\t\t\tconst lower = indexes[0] ?? 0;\n\t\t\tconst contiguous = indexes.every(\n\t\t\t\t(index, offset) => index === lower + offset,\n\t\t\t);\n\t\t\tif (!contiguous) {\n\t\t\t\treturn opaque(\"an array with gaps\", type, span);\n\t\t\t}\n\t\t\treturn projectReconstruction(\n\t\t\t\t{\n\t\t\t\t\tkind: \"array\",\n\t\t\t\t\tlower,\n\t\t\t\t\titems: indexes.flatMap((index) => {\n\t\t\t\t\t\tconst item = items.get(index);\n\t\t\t\t\t\treturn item ? [value(item)] : [];\n\t\t\t\t\t}),\n\t\t\t\t\ttype: typeOf(root) ?? type,\n\t\t\t\t\tspan,\n\t\t\t\t},\n\t\t\t\tpath,\n\t\t\t\ttype,\n\t\t\t);\n\t\t}\n\t\tif (!fields.size) {\n\t\t\treturn opaque(\"a value with no definition\", type, span);\n\t\t}\n\t\treturn projectReconstruction(\n\t\t\t{\n\t\t\t\tkind: \"record\",\n\t\t\t\tfields: Object.fromEntries(\n\t\t\t\t\t[...fields].map(([name, item]) => [name, value(item)]),\n\t\t\t\t),\n\t\t\t\ttype: typeOf(root) ?? type,\n\t\t\t\tspan,\n\t\t\t},\n\t\t\tpath,\n\t\t\ttype,\n\t\t);\n\t};\n\n\tconst reconstruct = (\n\t\texpression: CoreExpression,\n\t\tat: number,\n\t): Reconstruction => {\n\t\tconst { type, span } = expression;\n\t\tswitch (expression.kind) {\n\t\t\tcase \"constant\":\n\t\t\t\treturn { kind: \"constant\", value: expression.value, type, span };\n\t\t\tcase \"borrow\":\n\t\t\t\treturn place(\n\t\t\t\t\texpression.place.root,\n\t\t\t\t\tsegments(expression.place.path, at),\n\t\t\t\t\tat,\n\t\t\t\t\tat,\n\t\t\t\t\ttype,\n\t\t\t\t\tspan,\n\t\t\t\t);\n\t\t\tcase \"load\":\n\t\t\t\treturn place(\n\t\t\t\t\texpression.root,\n\t\t\t\t\tsegments(expression.path ?? [], at),\n\t\t\t\t\tat,\n\t\t\t\t\tat,\n\t\t\t\t\ttype,\n\t\t\t\t\tspan,\n\t\t\t\t);\n\t\t\tcase \"unary\":\n\t\t\t\tif (expression.operator === \"clock\") {\n\t\t\t\t\treturn { kind: \"clock\", type, span };\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"unary\",\n\t\t\t\t\toperator: expression.operator,\n\t\t\t\t\toperand: reconstruct(expression.operand, at),\n\t\t\t\t\ttype,\n\t\t\t\t\tspan,\n\t\t\t\t};\n\t\t\tcase \"convert\":\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"convert\",\n\t\t\t\t\tpolicy: expression.policy,\n\t\t\t\t\toperand: reconstruct(expression.operand, at),\n\t\t\t\t\ttype,\n\t\t\t\t\tspan,\n\t\t\t\t};\n\t\t\tcase \"binary\": {\n\t\t\t\tconst left = reconstruct(expression.left, at);\n\t\t\t\tconst right = reconstruct(expression.right, at);\n\t\t\t\tif (expression.operator === \"and\" || expression.operator === \"or\") {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tkind: \"logical\",\n\t\t\t\t\t\toperator: expression.operator,\n\t\t\t\t\t\tleft,\n\t\t\t\t\t\tright,\n\t\t\t\t\t\ttype,\n\t\t\t\t\t\tspan,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"binary\",\n\t\t\t\t\toperator: expression.operator,\n\t\t\t\t\t...(expression.policy && { policy: expression.policy }),\n\t\t\t\t\tleft,\n\t\t\t\t\tright,\n\t\t\t\t\ttype,\n\t\t\t\t\tspan,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t};\n\n\tconst job =\n\t\tisBlockRoutine(routine) && routine.job\n\t\t\t? { busy: jobField(routine, \"busy\"), step: jobField(routine, \"step\") }\n\t\t\t: undefined;\n\tconst isField = (node: Reconstruction, field: string | undefined): boolean =>\n\t\tfield !== undefined &&\n\t\tnode.kind === \"read\" &&\n\t\tnode.root === field &&\n\t\t!node.path.length;\n\t/** The job dispatcher's `IF NOT busy THEN RETURN`. */\n\tconst busyGuard = (item: CoreStatement): boolean => {\n\t\tif (\n\t\t\titem.kind !== \"if\" ||\n\t\t\titem.else.length ||\n\t\t\titem.then.length !== 1 ||\n\t\t\titem.then[0]?.kind !== \"return\"\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\tconst test = reconstruct(item.condition, position(item));\n\t\treturn (\n\t\t\ttest.kind === \"unary\" &&\n\t\t\ttest.operator === \"not\" &&\n\t\t\tisField(test.operand, job?.busy)\n\t\t);\n\t};\n\t/** The dispatcher's `switch` on `step`. */\n\tconst stepSwitch = (item: CoreStatement): boolean =>\n\t\titem.kind === \"switch\" &&\n\t\tisField(reconstruct(item.value, position(item)), job?.step);\n\n\tconst statements = new Map<CoreStatement, StatementConditions>();\n\tconst loops: LoopConditions[] = [];\n\ttype Mode = \"plain\" | \"jobDispatcher\" | \"jobTransitions\";\n\n\tconst sequence = (\n\t\titems: readonly CoreStatement[],\n\t\tconditions: Conjunction,\n\t\tloop: number | null,\n\t\tmode: Mode,\n\t): Exits => {\n\t\tconst guards: PathCondition[] = [];\n\t\tconst exits: Exits[] = [];\n\t\tfor (const item of items) {\n\t\t\tconst here = [...conditions, ...guards];\n\t\t\tstatements.set(item, {\n\t\t\t\tposition: position(item),\n\t\t\t\tconditions: here,\n\t\t\t\tloop,\n\t\t\t});\n\t\t\tif (mode === \"jobDispatcher\" && busyGuard(item)) {\n\t\t\t\tfor (const branch of nestedBodies(item)) {\n\t\t\t\t\tsequence(branch, here, loop, \"plain\");\n\t\t\t\t}\n\t\t\t\tguards.push({ kind: \"jobBusy\" });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tmode === \"jobDispatcher\" &&\n\t\t\t\titem.kind === \"for\" &&\n\t\t\t\titem.body.some(stepSwitch)\n\t\t\t) {\n\t\t\t\tsequence(item.body, here, loop, \"jobTransitions\");\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst own = statementExits(item, here, loop, mode);\n\t\t\texits.push(prefixed(guards, own));\n\t\t\tconst any = [...own.returns, ...own.breaks, ...own.continues];\n\t\t\tif (any.length) {\n\t\t\t\tguards.push({ kind: \"exits\", any });\n\t\t\t}\n\t\t}\n\t\treturn merged(...exits);\n\t};\n\n\tconst statementExits = (\n\t\titem: CoreStatement,\n\t\there: Conjunction,\n\t\tloop: number | null,\n\t\tmode: Mode,\n\t): Exits => {\n\t\tconst at = position(item);\n\t\tswitch (item.kind) {\n\t\t\tcase \"return\":\n\t\t\t\treturn { ...noExits, returns: [[]] };\n\t\t\tcase \"break\":\n\t\t\t\treturn { ...noExits, breaks: [[]] };\n\t\t\tcase \"continue\":\n\t\t\t\treturn { ...noExits, continues: [[]] };\n\t\t\tcase \"if\": {\n\t\t\t\tconst lowered = synthetic.get(item);\n\t\t\t\tconst tested = lowered ? lowered.left.value : item.condition;\n\t\t\t\tconst test = reconstruct(tested, lowered ? position(lowered.left) : at);\n\t\t\t\tconst holds = lowered?.operator !== \"or\";\n\t\t\t\tconst condition = (truth: boolean): PathCondition => ({\n\t\t\t\t\tkind: \"test\",\n\t\t\t\t\ttest,\n\t\t\t\t\tholds: truth === holds,\n\t\t\t\t\tat,\n\t\t\t\t\tspan: tested.span,\n\t\t\t\t});\n\t\t\t\tconst yes = condition(true);\n\t\t\t\tconst no = condition(false);\n\t\t\t\treturn merged(\n\t\t\t\t\tprefixed([yes], sequence(item.then, [...here, yes], loop, \"plain\")),\n\t\t\t\t\tprefixed([no], sequence(item.else, [...here, no], loop, \"plain\")),\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase \"switch\": {\n\t\t\t\tconst test = reconstruct(item.value, at);\n\t\t\t\tconst steps = mode === \"jobTransitions\" && stepSwitch(item);\n\t\t\t\tconst inside = steps\n\t\t\t\t\t? here.filter((condition) => condition.kind !== \"jobBusy\")\n\t\t\t\t\t: here;\n\t\t\t\tconst branch = (\n\t\t\t\t\tcondition: PathCondition,\n\t\t\t\t\tbody: readonly CoreStatement[],\n\t\t\t\t) =>\n\t\t\t\t\tprefixed(\n\t\t\t\t\t\t[condition],\n\t\t\t\t\t\tsequence(body, [...inside, condition], loop, \"plain\"),\n\t\t\t\t\t);\n\t\t\t\tconst cases = item.cases.map((entry) => {\n\t\t\t\t\tconst [value] = entry.values;\n\t\t\t\t\tconst step =\n\t\t\t\t\t\tsteps && value?.kind === \"integer\" && entry.values.length === 1\n\t\t\t\t\t\t\t? Number(value.value)\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\treturn branch(\n\t\t\t\t\t\tstep === undefined\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tkind: \"cases\",\n\t\t\t\t\t\t\t\t\ttest,\n\t\t\t\t\t\t\t\t\tvalues: entry.values,\n\t\t\t\t\t\t\t\t\tmember: true,\n\t\t\t\t\t\t\t\t\tat,\n\t\t\t\t\t\t\t\t\tspan: item.value.span,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: { kind: \"job\", step },\n\t\t\t\t\t\tentry.body,\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\tconst fallback = branch(\n\t\t\t\t\t{\n\t\t\t\t\t\tkind: \"cases\",\n\t\t\t\t\t\ttest,\n\t\t\t\t\t\tvalues: item.cases.flatMap((entry) => entry.values),\n\t\t\t\t\t\tmember: false,\n\t\t\t\t\t\tat,\n\t\t\t\t\t\tspan: item.value.span,\n\t\t\t\t\t},\n\t\t\t\t\titem.fallback,\n\t\t\t\t);\n\t\t\t\treturn merged(...cases, fallback);\n\t\t\t}\n\t\t\tcase \"for\": {\n\t\t\t\tconst id = loops.length;\n\t\t\t\tconst counter = typeOf(item.counter) ?? \"DINT\";\n\t\t\t\tconst bound = (value: Constant): Reconstruction => ({\n\t\t\t\t\tkind: \"constant\",\n\t\t\t\t\tvalue,\n\t\t\t\t\ttype: counter,\n\t\t\t\t\tspan: item.span,\n\t\t\t\t});\n\t\t\t\tconst slot: LoopConditions = {\n\t\t\t\t\tstatement: item,\n\t\t\t\t\tposition: at,\n\t\t\t\t\tcounter: item.counter,\n\t\t\t\t\tfirst: item.dynamic\n\t\t\t\t\t\t? reconstruct(item.dynamic.start, at)\n\t\t\t\t\t\t: bound(item.start),\n\t\t\t\t\tlimit: item.dynamic\n\t\t\t\t\t\t? reconstruct(item.dynamic.limit, at)\n\t\t\t\t\t\t: bound(item.limit),\n\t\t\t\t\texclusive: item.dynamic?.exclusive === true,\n\t\t\t\t\tstep: BigInt(item.step),\n\t\t\t\t\tmaxIterations: item.maxIterations,\n\t\t\t\t\tbreaks: [],\n\t\t\t\t\treturns: false,\n\t\t\t\t\tparent: loop,\n\t\t\t\t};\n\t\t\t\tloops.push(slot);\n\t\t\t\tconst body = sequence(\n\t\t\t\t\titem.body,\n\t\t\t\t\t[...here, { kind: \"loop\", loop: id }],\n\t\t\t\t\tid,\n\t\t\t\t\t\"plain\",\n\t\t\t\t);\n\t\t\t\tloops[id] = {\n\t\t\t\t\t...slot,\n\t\t\t\t\tbreaks: body.breaks,\n\t\t\t\t\treturns: body.returns.length > 0,\n\t\t\t\t};\n\t\t\t\treturn body.returns.length\n\t\t\t\t\t? { ...noExits, returns: [[{ kind: \"loopReturns\", loop: id }]] }\n\t\t\t\t\t: noExits;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn noExits;\n\t\t}\n\t};\n\n\tsequence(routine.body, [], null, job ? \"jobDispatcher\" : \"plain\");\n\treturn { statements, loops, reconstruct };\n}\n",
18
+ "export interface SourceSpan {\n\tfile: string;\n\tstart: number;\n\tend: number;\n\tline: number;\n\tcolumn: number;\n}\n\nexport interface Diagnostic {\n\torigin: \"typescript\" | \"plc\" | \"config\" | \"backend\" | \"vendor\";\n\tcode: string;\n\tseverity: \"error\" | \"warning\";\n\tmessage: string;\n\tspan?: SourceSpan;\n\tnotes?: readonly string[];\n\trelated?: readonly { span: SourceSpan; message: string }[];\n}\n\nexport function error(\n\tcode: string,\n\tmessage: string,\n\tspan?: SourceSpan,\n): Diagnostic {\n\treturn {\n\t\torigin: \"plc\",\n\t\tcode,\n\t\tseverity: \"error\",\n\t\tmessage,\n\t\t...(span && { span }),\n\t};\n}\n\nexport function hasErrors(diagnostics: readonly Diagnostic[]): boolean {\n\treturn diagnostics.some((diagnostic) => diagnostic.severity === \"error\");\n}\n\nexport function formatDiagnostic(\n\tdiagnostic: Diagnostic,\n\tsource?: string,\n): string {\n\tconst { span } = diagnostic;\n\tconst location = span ? `${span.file}:${span.line}:${span.column}: ` : \"\";\n\treturn [\n\t\t`${location}${diagnostic.code}: ${diagnostic.message}`,\n\t\t...(source !== undefined && span ? excerpt(span, source) : []),\n\t\t...(diagnostic.related ?? []).map(\n\t\t\t(related) =>\n\t\t\t\t` ${related.span.file}:${related.span.line}:${related.span.column}: ${related.message}`,\n\t\t),\n\t\t...(diagnostic.notes ?? []).map((note) => ` ${note}`),\n\t].join(\"\\n\");\n}\n\n/** The source line a span starts on, underlined from the span's column. */\nconst excerpt = (span: SourceSpan, source: string): string[] => {\n\tconst line = source.split(/\\r?\\n/)[span.line - 1];\n\tif (line === undefined) {\n\t\treturn [];\n\t}\n\tconst width = Math.max(\n\t\t1,\n\t\tMath.min(span.end - span.start, line.length - span.column + 2),\n\t);\n\treturn [\n\t\t`${span.line} | ${line}`,\n\t\t`${\" \".repeat(String(span.line).length + 3 + span.column - 1)}${\"^\".repeat(width)}`,\n\t];\n};\n",
19
+ "import { createHash } from \"node:crypto\";\n\n/**\n * Generated names are a fixed function of the identity of what they stand for, so the same source\n * names the same things whatever else changes: an online change then finds every piece of state\n * where it left it. A digest keeps the name short and its identity out of the PLC's namespace.\n */\nexport const identityDigest = (identity: string): string =>\n\tcreateHash(\"sha256\").update(identity).digest(\"hex\").slice(0, 8);\n\n/**\n * Text in PascalCase, as generated names use it: `bin_full` and `bin full` become `BinFull`.\n * Capitals inside a word are kept, so `PlantIO` stays as written while `plant-io` is `PlantIo`.\n */\nexport const pascalCase = (text: string): string =>\n\ttext\n\t\t.split(/[^A-Za-z0-9]+/)\n\t\t.map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n\t\t.join(\"\");\n",
20
+ "/** Job error codes by meaning, as generated async blocks and service calls set them. */\nexport const jobError = {\n\tcancelled: 1,\n\ttimeout: 2,\n\ttooLarge: 3,\n\tmalformedResponse: 4,\n\tnetwork: 5,\n\ttls: 6,\n\tnoRequestSlot: 7,\n\t/**\n\t * An online change replaced the code of a job that was running: its step and stored state\n\t * were made for the old code, so it stops instead of resuming in the new. Like `cancelled`,\n\t * it skips `catch`, so a retry can't send a request twice.\n\t */\n\tcodeChanged: 11001,\n} as const;\n\nconst httpBase = 10000;\n\n/**\n * An HTTP response fails a job with `base` + its status, up to `last`. `refused` is a 400: the\n * server can't take the request, so sending it again cannot succeed.\n */\nexport const httpErrors = {\n\tbase: httpBase,\n\tlast: 10999,\n\trefused: httpBase + 400,\n};\n\n/** Codes tsPLC itself reports from 11000 on, which a program's own `throw` may not use. */\nexport const reservedErrors = { first: 11000, last: 11099 };\n\nconst errorMeanings: Record<number, string> = {\n\t[jobError.cancelled]: \"cancelled\",\n\t[jobError.timeout]: \"timeout\",\n\t[jobError.tooLarge]: \"request or response too large to encode\",\n\t[jobError.malformedResponse]: \"malformed response\",\n\t[jobError.network]: \"network error or server restarted\",\n\t[jobError.tls]: \"TLS error\",\n\t[jobError.noRequestSlot]: \"no free request slot\",\n\t[jobError.codeChanged]:\n\t\t\"an online change replaced the job's code while it ran\",\n};\n\n/** Job error codes, as every generated async block and service call reports them. */\nexport const jobErrors: Record<string, string> = {\n\t...errorMeanings,\n\t[httpErrors.base]: `HTTP status: ${httpErrors.base} + status code`,\n};\n\n/** What a telemetry exception record calls an error code: its meaning when it is a job error. */\nexport const errorName = (code: number): string | undefined => {\n\tif (code > httpErrors.base && code <= httpErrors.last) {\n\t\treturn `HTTP ${code - httpErrors.base}`;\n\t}\n\treturn errorMeanings[code];\n};\n\n/** The code a failure reports: its job error code, or 0 for anything else thrown, such as an Error under Bun. */\nexport const failureCode = (reason: unknown): number =>\n\ttypeof reason === \"number\" ? reason : 0;\n\n/** What an exception record calls a failure: a job error's meaning, or a thrown Error's message. */\nexport const failureName = (reason: unknown): string | undefined => {\n\tif (typeof reason === \"number\") {\n\t\treturn errorName(reason);\n\t}\n\treturn reason instanceof Error ? reason.message : String(reason);\n};\n",
21
+ "import { elementaryType, integerRange } from \"@tsplc/iec\";\nimport { reject } from \"./normalization-error\";\nimport { constantFits } from \"./numeric\";\nimport { lookup } from \"./tables\";\nimport { type PlcType, primitiveTypes } from \"./types\";\n\n/** The finite storage budget: scalar elements in one layout or allocation, and nesting depth. */\nexport const maxScalarElements = 1_000_000;\n/** `maxScalarElements` as diagnostics spell it. */\nexport const maxScalarElementsText = \"one million\";\nexport const maxNestingDepth = 64;\n\n/** The largest capacity a bounded string may declare. */\nexport const maxStringCapacity = 65535;\n\n// Array bounds and indexes are DINT.\nconst [firstIndex, lastIndex] = integerRange(elementaryType(\"DINT\"));\n\nconst definitionIssue = (\n\ttype: PlcType,\n\ttypes: ReadonlyMap<string, PlcType>,\n): string | undefined => {\n\tconst canonical = primitiveTypes.find((item) => item.id === type.id);\n\tif (canonical) {\n\t\treturn type.kind !== canonical.kind ||\n\t\t\t(\"bits\" in canonical &&\n\t\t\t\t(!(\"bits\" in type) || type.bits !== canonical.bits)) ||\n\t\t\t(\"signed\" in canonical &&\n\t\t\t\t(!(\"signed\" in type) || type.signed !== canonical.signed)) ||\n\t\t\t(\"domain\" in canonical &&\n\t\t\t\t(!(\"domain\" in type) || type.domain !== canonical.domain))\n\t\t\t? `Conflicting primitive type ${type.id}`\n\t\t\t: undefined;\n\t}\n\tswitch (type.kind) {\n\t\tcase \"record\":\n\t\t\treturn !type.fields.length ||\n\t\t\t\tnew Set(type.fields.map((field) => field.name)).size !==\n\t\t\t\t\ttype.fields.length ||\n\t\t\t\ttype.fields.some((field) => !field.name || !types.has(field.type))\n\t\t\t\t? `Invalid closed record layout ${type.id}`\n\t\t\t\t: undefined;\n\t\tcase \"array\": {\n\t\t\tif (\n\t\t\t\t!types.has(type.element) ||\n\t\t\t\t!Number.isSafeInteger(type.length) ||\n\t\t\t\ttype.length < 1 ||\n\t\t\t\ttype.length > maxScalarElements ||\n\t\t\t\t!Number.isInteger(type.lowerBound) ||\n\t\t\t\tBigInt(type.lowerBound) < firstIndex ||\n\t\t\t\tBigInt(type.lowerBound + type.length - 1) > lastIndex\n\t\t\t) {\n\t\t\t\treturn `Invalid fixed array layout ${type.id}`;\n\t\t\t}\n\t\t\tif (type.index === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst index = types.get(type.index);\n\t\t\treturn index?.kind !== \"enum\" ||\n\t\t\t\tindex.members.length !== type.length ||\n\t\t\t\tindex.members.some(\n\t\t\t\t\t(member) =>\n\t\t\t\t\t\tNumber(member.value) < type.lowerBound ||\n\t\t\t\t\t\tNumber(member.value) >= type.lowerBound + type.length,\n\t\t\t\t)\n\t\t\t\t? `Invalid enum-keyed array layout ${type.id}`\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"enum\": {\n\t\t\tconst base = types.get(type.base);\n\t\t\treturn type.base !== \"DINT\" ||\n\t\t\t\tbase?.kind !== \"integer\" ||\n\t\t\t\t!type.members.length ||\n\t\t\t\tnew Set(type.members.map((member) => member.name)).size !==\n\t\t\t\t\ttype.members.length ||\n\t\t\t\tnew Set(type.members.map((member) => member.value)).size !==\n\t\t\t\t\ttype.members.length ||\n\t\t\t\ttype.members.some(\n\t\t\t\t\t(member) =>\n\t\t\t\t\t\t!member.name ||\n\t\t\t\t\t\t!constantFits({ kind: \"integer\", value: member.value }, base),\n\t\t\t\t)\n\t\t\t\t? `Invalid enum layout ${type.id}`\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"string\":\n\t\t\treturn !Number.isInteger(type.capacity) ||\n\t\t\t\ttype.capacity < 1 ||\n\t\t\t\ttype.capacity > maxStringCapacity\n\t\t\t\t? `Invalid bounded string layout ${type.id}`\n\t\t\t\t: undefined;\n\t\tcase \"block\":\n\t\t\treturn !type.block ||\n\t\t\t\t(type.output && types.get(type.output)?.kind !== \"record\")\n\t\t\t\t? `Invalid block type ${type.id}`\n\t\t\t\t: undefined;\n\t\tdefault:\n\t\t\treturn `Unsupported core type definition ${type.id}`;\n\t}\n};\n\ninterface Layout {\n\tsize: number;\n\theight: number;\n}\n\n/** The part of the storage budget a layout exceeds. */\nexport type LayoutBudget = \"size\" | \"nesting\";\n\n/**\n * Measures by-value layouts against the storage budget, each once, and hands the first that\n * exceeds it to `exceeded`.\n */\nconst layoutMeasure = (\n\ttypes: ReadonlyMap<string, PlcType>,\n\texceeded: (budget: LayoutBudget, message: string) => never,\n) => {\n\tconst active = new Set<string>();\n\tconst layouts = new Map<string, Layout>();\n\tconst measure = (id: string, depth: number): Layout => {\n\t\tif (active.has(id) || depth > maxNestingDepth) {\n\t\t\texceeded(\n\t\t\t\t\"nesting\",\n\t\t\t\t`Recursive or excessively nested by-value layout ${id}`,\n\t\t\t);\n\t\t}\n\t\tconst cached = layouts.get(id);\n\t\tif (cached) {\n\t\t\tif (depth + cached.height > maxNestingDepth) {\n\t\t\t\texceeded(\n\t\t\t\t\t\"nesting\",\n\t\t\t\t\t`Layout nesting exceeds ${maxNestingDepth} levels ${id}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn cached;\n\t\t}\n\t\tactive.add(id);\n\t\tconst layout = composite(lookup(types, id, \"type\"), depth);\n\t\tactive.delete(id);\n\t\tif (layout.size > maxScalarElements) {\n\t\t\texceeded(\n\t\t\t\t\"size\",\n\t\t\t\t`Layout exceeds ${maxScalarElementsText} scalar elements ${id}`,\n\t\t\t);\n\t\t}\n\t\tif (depth + layout.height > maxNestingDepth) {\n\t\t\texceeded(\n\t\t\t\t\"nesting\",\n\t\t\t\t`Layout nesting exceeds ${maxNestingDepth} levels ${id}`,\n\t\t\t);\n\t\t}\n\t\tlayouts.set(id, layout);\n\t\treturn layout;\n\t};\n\tconst composite = (type: PlcType, depth: number): Layout => {\n\t\tif (type.kind === \"array\") {\n\t\t\tconst element = measure(type.element, depth + 1);\n\t\t\treturn { size: type.length * element.size, height: 1 + element.height };\n\t\t}\n\t\tif (type.kind === \"record\") {\n\t\t\tconst fields = type.fields.map((field) => measure(field.type, depth + 1));\n\t\t\treturn {\n\t\t\t\tsize: fields.reduce((sum, field) => sum + field.size, 0),\n\t\t\t\theight:\n\t\t\t\t\t1 +\n\t\t\t\t\tfields.reduce((maximum, field) => Math.max(maximum, field.height), 0),\n\t\t\t};\n\t\t}\n\t\treturn { size: 1, height: 0 };\n\t};\n\treturn (id: string) => measure(id, 0);\n};\n\n/**\n * Validates every layout edge once, before constants or places can traverse them, and measures\n * each by-value layout against the storage budget. Returns each type's size in scalar elements.\n */\nexport const admitLayouts = (\n\ttypes: ReadonlyMap<string, PlcType>,\n): ReadonlyMap<string, number> => {\n\tfor (const type of types.values()) {\n\t\tconst issue = definitionIssue(type, types);\n\t\tif (issue) {\n\t\t\treject(issue);\n\t\t}\n\t}\n\tconst measure = layoutMeasure(types, (_budget, message) => reject(message));\n\treturn new Map([...types.keys()].map((id) => [id, measure(id).size]));\n};\n\nclass BudgetExceeded {\n\tconstructor(readonly budget: LayoutBudget) {}\n}\n\n/** Which part of the storage budget the by-value layout of `id` exceeds, if any. */\nexport const layoutIssue = (\n\ttypes: ReadonlyMap<string, PlcType>,\n\tid: string,\n): LayoutBudget | undefined => {\n\ttry {\n\t\tlayoutMeasure(types, (budget) => {\n\t\t\tthrow new BudgetExceeded(budget);\n\t\t})(id);\n\t\treturn undefined;\n\t} catch (cause) {\n\t\tif (cause instanceof BudgetExceeded) {\n\t\t\treturn cause.budget;\n\t\t}\n\t\tthrow cause;\n\t}\n};\n",
15
22
  "import { type Diagnostic, error, type SourceSpan } from \"./diagnostics\";\n\nexport class InvalidCore extends Error {\n\tconstructor(readonly diagnostic: Diagnostic) {\n\t\tsuper(diagnostic.message);\n\t}\n}\nexport function reject(message: string, span?: SourceSpan): never {\n\tthrow new InvalidCore(error(\"PLC6001\", message, span));\n}\n",
16
- "// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.\nimport { aggregate, expressionIssue, placeType, valueFits } from \"./aggregates\";\nimport type {\n\tCoreExpression,\n\tCoreFunction,\n\tCoreFunctionBlock,\n\tCorePath,\n\tCoreStatement,\n} from \"./core-model\";\nimport type { ModuleDeclarations } from \"./declarations\";\nimport type { SourceSpan } from \"./diagnostics\";\nimport { fold } from \"./fold\";\nimport type {\n\tExpression,\n\tFunctionBlock,\n\tPlace,\n\tPlcFunction,\n\tStatement,\n\tVariable,\n} from \"./model\";\nimport { reject } from \"./normalization-error\";\nimport { admits, canonicalInteger, type IntegerInterval } from \"./numeric\";\nimport {\n\tinterval,\n\tloopBounds,\n\tmaxLoopIterations,\n\tnarrowRanges,\n\tvalueRange,\n} from \"./ranges\";\nimport { instancedBlock, integerRange } from \"./types\";\n\ntype Flow = \"fallthrough\" | \"return\" | \"loop\" | \"mixed\";\ninterface FlowState {\n\tflow: Flow;\n\tinitialized: Set<string>;\n}\ninterface BodyResult extends FlowState {\n\tbody: CoreStatement[];\n}\n\n// Only paths that reach the next statement participate in a join. A local is\n// definitely initialized when every such path initialized it; branches that\n// return or leave the loop do not constrain it.\nconst join = (\n\tbranches: readonly [BodyResult, ...BodyResult[]],\n\tinitialized: Set<string>,\n): FlowState => {\n\tconst [falling, ...others] = branches.filter(\n\t\t(branch) => branch.flow === \"fallthrough\",\n\t);\n\tif (falling) {\n\t\treturn {\n\t\t\tflow: \"fallthrough\",\n\t\t\tinitialized: new Set(\n\t\t\t\t[...falling.initialized].filter((id) =>\n\t\t\t\t\tothers.every((branch) => branch.initialized.has(id)),\n\t\t\t\t),\n\t\t\t),\n\t\t};\n\t}\n\tconst [{ flow }] = branches;\n\treturn {\n\t\tflow: branches.every((branch) => branch.flow === flow) ? flow : \"mixed\",\n\t\tinitialized,\n\t};\n};\n\n// All mutable lowering state belongs to one invocation of one authored routine.\n// sourceScope admits authored places; scope additionally contains captured temps.\nconst temporaryPrefix = (routine: string) => `${routine}:temporary:`;\nconst temporaryId = (routine: string, index: number) =>\n\t`${temporaryPrefix(routine)}${index}`;\n\n/** Whether a local is a temporary the normalizer made for `routine`, rather than one its source declares. */\nexport function isTemporary(routine: string, variable: Variable): boolean {\n\tconst prefix = temporaryPrefix(routine);\n\treturn (\n\t\tvariable.storage === \"local\" &&\n\t\tvariable.id.startsWith(prefix) &&\n\t\t/^\\d+$/.test(variable.id.slice(prefix.length))\n\t);\n}\n\nexport class RoutineNormalizer {\n\tprivate readonly fn: PlcFunction;\n\n\tprivate readonly block: FunctionBlock | undefined;\n\tprivate readonly owner: FunctionBlock | undefined;\n\n\tprivate readonly scope: Map<string, Variable>;\n\n\tprivate readonly sourceScope: Map<string, Variable>;\n\n\tprivate readonly locals: Variable[];\n\n\tprivate readonly ranges = new Map<string, IntegerInterval>();\n\n\tprivate readonly counters = new Set<string>();\n\n\tprivate readonly callees = new Set<string>();\n\n\tprivate temporaryCount = 0;\n\n\tconstructor(\n\t\troutine: PlcFunction | FunctionBlock,\n\t\tprivate readonly declarations: ModuleDeclarations,\n\t) {\n\t\tthis.block = \"inputs\" in routine ? routine : undefined;\n\t\tthis.owner =\n\t\t\tthis.block ??\n\t\t\t(\"owner\" in routine && routine.owner\n\t\t\t\t? declarations.blocks.get(routine.owner.block)\n\t\t\t\t: undefined);\n\t\tconst parameters =\n\t\t\t\"parameters\" in routine ? routine.parameters : routine.inputs;\n\t\tthis.fn = {\n\t\t\tid: routine.id,\n\t\t\tname: routine.name,\n\t\t\t...(\"owner\" in routine && routine.owner && { owner: routine.owner }),\n\t\t\t...(\"origin\" in routine && routine.origin && { origin: routine.origin }),\n\t\t\tparameters,\n\t\t\tlocals: routine.locals,\n\t\t\tbody: routine.body,\n\t\t\tspan: routine.span,\n\t\t\t...(routine.result && { result: routine.result }),\n\t\t};\n\t\tthis.scope = new Map(declarations.globals);\n\t\tfor (const item of [\n\t\t\t...parameters,\n\t\t\t...(this.owner ? [...this.owner.state, ...this.owner.outputs] : []),\n\t\t\t...routine.locals,\n\t\t]) {\n\t\t\tthis.scope.set(item.id, item);\n\t\t}\n\t\tthis.sourceScope = new Map(this.scope);\n\t\tthis.locals = [...routine.locals];\n\t}\n\n\tnormalize(): {\n\t\troutine: CoreFunction | CoreFunctionBlock;\n\t\tcallees: ReadonlySet<string>;\n\t} {\n\t\tif (this.block?.standard) {\n\t\t\treturn { routine: { ...this.block, body: [] }, callees: this.callees };\n\t\t}\n\t\tconst normalized = this.body(\n\t\t\tthis.fn.body,\n\t\t\tnew Set(this.fn.parameters.map((item) => item.id)),\n\t\t);\n\t\tif (this.fn.result && normalized.flow !== \"return\") {\n\t\t\treject(\"A typed helper must return on every path.\", this.fn.span);\n\t\t}\n\t\tconst routine = this.block\n\t\t\t? { ...this.block, locals: this.locals, body: normalized.body }\n\t\t\t: { ...this.fn, locals: this.locals, body: normalized.body };\n\t\treturn { routine, callees: this.callees };\n\t}\n\n\tprivate temporary(type: string, span: SourceSpan): Variable {\n\t\tlet id: string;\n\t\tdo {\n\t\t\tid = temporaryId(this.fn.id, this.temporaryCount++);\n\t\t} while (this.declarations.hasId(id));\n\t\tthis.declarations.claimId(id);\n\t\tconst item: Variable = {\n\t\t\tid,\n\t\t\tname: `temporary_${this.temporaryCount}`,\n\t\t\ttype,\n\t\t\tstorage: \"local\",\n\t\t\tmutable: true,\n\t\t\tretain: false,\n\t\t\tspan,\n\t\t};\n\t\tthis.scope.set(id, item);\n\t\tthis.locals.push(item);\n\t\treturn item;\n\t}\n\n\tprivate load(variable: Variable, span: SourceSpan): CoreExpression {\n\t\treturn { kind: \"load\", root: variable.id, type: variable.type, span };\n\t}\n\n\t/** The block a method or update receiver instantiates: a static instance, or an InOut reference to one. */\n\tprivate receiverBlock(id: string): string | undefined {\n\t\tconst variable = this.sourceScope.get(id);\n\t\tif (variable?.storage !== \"instance\" && variable?.mode !== \"inOut\") {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn instancedBlock(variable.type, this.declarations.types)?.block;\n\t}\n\n\tprivate verifyCall(\n\t\tid: string,\n\t\targuments_: readonly Expression[],\n\t\tspan: SourceSpan,\n\t\tinstance: string | undefined,\n\t): PlcFunction {\n\t\tconst called = this.declarations.signatures.get(id);\n\t\tif (!called || called.parameters.length !== arguments_.length) {\n\t\t\treject(\"Unknown helper or wrong argument count.\", span);\n\t\t}\n\t\tif (called.owner) {\n\t\t\tif (instance) {\n\t\t\t\tif (this.receiverBlock(instance) !== called.owner.block) {\n\t\t\t\t\treject(\n\t\t\t\t\t\t\"Method calls require a matching static block instance.\",\n\t\t\t\t\t\tspan,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (this.owner?.id !== called.owner.block) {\n\t\t\t\treject(\n\t\t\t\t\t\"An implicit method call requires its owning block scope.\",\n\t\t\t\t\tspan,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tcalled.owner.access !== \"public\" &&\n\t\t\t\tthis.owner?.id !== called.owner.block\n\t\t\t) {\n\t\t\t\treject(\n\t\t\t\t\t\"Private and protected methods require their owning block scope.\",\n\t\t\t\t\tspan,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (instance) {\n\t\t\treject(\"Ordinary functions cannot have an instance receiver.\", span);\n\t\t}\n\t\tthis.callees.add(id);\n\t\targuments_.forEach((argument, index) => {\n\t\t\tif (argument.type !== called.parameters[index]?.type) {\n\t\t\t\treject(\"Helper argument has the wrong PLC type.\", argument.span);\n\t\t\t}\n\t\t});\n\t\treturn called;\n\t}\n\n\tprivate expression(\n\t\tvalue: Expression,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t\tallowAggregateLoad = false,\n\t): CoreExpression {\n\t\tconst type = this.declarations.types.get(value.type);\n\t\tif (!type || !this.declarations.isValueType(value.type)) {\n\t\t\treject(\"Unknown or non-value expression type.\", value.span);\n\t\t}\n\t\tif (value.kind === \"borrow\") {\n\t\t\treject(\n\t\t\t\t\"Borrowed places are only valid in block update arguments.\",\n\t\t\t\tvalue.span,\n\t\t\t);\n\t\t}\n\t\tconst common = { type: value.type, span: value.span };\n\t\tif (value.kind === \"length\") {\n\t\t\tconst array = this.declarations.types.get(value.operand.type);\n\t\t\tif (array?.kind !== \"array\" || value.type !== \"DINT\") {\n\t\t\t\treject(\"Length requires a fixed array and DINT result.\", value.span);\n\t\t\t}\n\t\t\tif (value.operand.kind === \"load\") {\n\t\t\t\tconst source = this.sourceScope.get(value.operand.place.root);\n\t\t\t\tconst checked = placeType(\n\t\t\t\t\tvalue.operand.place,\n\t\t\t\t\tthis.declarations.types,\n\t\t\t\t\tthis.sourceScope,\n\t\t\t\t\tthis.ranges,\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\t!source ||\n\t\t\t\t\tchecked.issue ||\n\t\t\t\t\tchecked.type !== value.operand.type ||\n\t\t\t\t\t(source.storage === \"local\" && !initialized.has(source.id))\n\t\t\t\t) {\n\t\t\t\t\treject(checked.issue ?? \"Invalid array receiver.\", value.span);\n\t\t\t\t}\n\t\t\t\tthis.normalizePath(value.operand.place, initialized, output);\n\t\t\t} else {\n\t\t\t\tthis.expression(value.operand, initialized, output, true);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...common,\n\t\t\t\tkind: \"constant\",\n\t\t\t\tvalue: { kind: \"integer\", value: String(array.length) },\n\t\t\t};\n\t\t}\n\t\tif (value.kind === \"conditional\") {\n\t\t\tif (\n\t\t\t\tvalue.condition.type !== \"BOOL\" ||\n\t\t\t\tvalue.then.type !== value.type ||\n\t\t\t\tvalue.else.type !== value.type\n\t\t\t) {\n\t\t\t\treject(\"Invalid conditional types.\", value.span);\n\t\t\t}\n\t\t\tconst condition = this.expression(value.condition, initialized, output);\n\t\t\tconst result = this.temporary(value.type, value.span);\n\t\t\tconst branch = (operand: Expression): CoreStatement[] => {\n\t\t\t\tconst statements: CoreStatement[] = [];\n\t\t\t\tconst evaluated = this.expression(\n\t\t\t\t\toperand,\n\t\t\t\t\tnew Set(initialized),\n\t\t\t\t\tstatements,\n\t\t\t\t);\n\t\t\t\tstatements.push({\n\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\troot: result.id,\n\t\t\t\t\tvalue: evaluated,\n\t\t\t\t\tspan: value.span,\n\t\t\t\t});\n\t\t\t\treturn statements;\n\t\t\t};\n\t\t\toutput.push({\n\t\t\t\tkind: \"if\",\n\t\t\t\tcondition,\n\t\t\t\t// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n\t\t\t\tthen: branch(value.then),\n\t\t\t\telse: branch(value.else),\n\t\t\t\tspan: value.span,\n\t\t\t});\n\t\t\tinitialized.add(result.id);\n\t\t\treturn this.load(result, value.span);\n\t\t}\n\t\tif (value.kind === \"call\") {\n\t\t\tconst called = this.verifyCall(\n\t\t\t\tvalue.function,\n\t\t\t\tvalue.arguments,\n\t\t\t\tvalue.span,\n\t\t\t\tvalue.instance,\n\t\t\t);\n\t\t\tif (called.result !== value.type) {\n\t\t\t\treject(\"Expression call requires a matching result type.\", value.span);\n\t\t\t}\n\t\t\tconst index =\n\t\t\t\tvalue.instance &&\n\t\t\t\tthis.instanceIndex(\n\t\t\t\t\tvalue.instance,\n\t\t\t\t\tvalue.index,\n\t\t\t\t\tinitialized,\n\t\t\t\t\toutput,\n\t\t\t\t\tvalue.span,\n\t\t\t\t);\n\t\t\tconst arguments_ = this.arguments(\n\t\t\t\tcalled.parameters,\n\t\t\t\tvalue.arguments,\n\t\t\t\tinitialized,\n\t\t\t\toutput,\n\t\t\t);\n\t\t\tconst result = this.temporary(value.type, value.span);\n\t\t\toutput.push({\n\t\t\t\tkind: \"invoke\",\n\t\t\t\tfunction: value.function,\n\t\t\t\t...(value.instance && { instance: value.instance }),\n\t\t\t\t...(index && { index }),\n\t\t\t\targuments: arguments_,\n\t\t\t\tdestination: result.id,\n\t\t\t\tspan: value.span,\n\t\t\t});\n\t\t\tinitialized.add(result.id);\n\t\t\treturn this.load(result, value.span);\n\t\t}\n\t\tconst issue = expressionIssue(\n\t\t\tvalue,\n\t\t\tthis.declarations.types,\n\t\t\tthis.scope,\n\t\t\tthis.ranges,\n\t\t);\n\t\tif (issue) {\n\t\t\treject(issue, value.span);\n\t\t}\n\t\tswitch (value.kind) {\n\t\t\tcase \"copy\":\n\t\t\t\treturn this.expression(value.operand, initialized, output, true);\n\t\t\tcase \"record\":\n\t\t\tcase \"array\": {\n\t\t\t\tconst result = this.temporary(value.type, value.span);\n\t\t\t\tif (value.kind === \"record\") {\n\t\t\t\t\tfor (const [name, operand] of Object.entries(value.fields)) {\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\t\t\troot: result.id,\n\t\t\t\t\t\t\tpath: [{ kind: \"field\", name }],\n\t\t\t\t\t\t\tvalue: this.expression(operand, initialized, output),\n\t\t\t\t\t\t\tspan: operand.span,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (type.kind !== \"array\") {\n\t\t\t\t\t\treject(\"Invalid array construction.\", value.span);\n\t\t\t\t\t}\n\t\t\t\t\tvalue.items.forEach((operand, index) => {\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\t\t\troot: result.id,\n\t\t\t\t\t\t\tpath: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tkind: \"index\",\n\t\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\t\tkind: \"constant\",\n\t\t\t\t\t\t\t\t\t\ttype: \"DINT\",\n\t\t\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\t\t\tkind: \"integer\",\n\t\t\t\t\t\t\t\t\t\t\tvalue: String(type.lowerBound + index),\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tspan: operand.span,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tvalue: this.expression(operand, initialized, output),\n\t\t\t\t\t\t\tspan: operand.span,\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tinitialized.add(result.id);\n\t\t\t\treturn this.load(result, value.span);\n\t\t\t}\n\t\t\tcase \"constant\": {\n\t\t\t\tif (!aggregate(type)) {\n\t\t\t\t\treturn { ...common, kind: \"constant\", value: value.value };\n\t\t\t\t}\n\t\t\t\tconst result = this.temporary(value.type, value.span);\n\t\t\t\toutput.push({\n\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\troot: result.id,\n\t\t\t\t\tvalue: { ...common, kind: \"constant\", value: value.value },\n\t\t\t\t\tspan: value.span,\n\t\t\t\t});\n\t\t\t\tinitialized.add(result.id);\n\t\t\t\treturn this.load(result, value.span);\n\t\t\t}\n\t\t\tcase \"load\": {\n\t\t\t\tconst source = this.sourceScope.get(value.place.root);\n\t\t\t\tconst checked = placeType(\n\t\t\t\t\tvalue.place,\n\t\t\t\t\tthis.declarations.types,\n\t\t\t\t\tthis.sourceScope,\n\t\t\t\t\tthis.ranges,\n\t\t\t\t);\n\t\t\t\tif (!source || checked.issue || checked.type !== value.type) {\n\t\t\t\t\treject(checked.issue ?? \"Invalid PLC load.\", value.span);\n\t\t\t\t}\n\t\t\t\tif (aggregate(type) && !allowAggregateLoad) {\n\t\t\t\t\treject(\n\t\t\t\t\t\t\"Aggregate loads require explicit copy or a readonly value argument.\",\n\t\t\t\t\t\tvalue.span,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (source.storage === \"local\" && !initialized.has(source.id)) {\n\t\t\t\t\treject(\"Local read before initialization.\", value.span);\n\t\t\t\t}\n\t\t\t\t// The virtual .out view is not a vendor record value. Snapshot its\n\t\t\t\t// declared fields, rather than copying the whole FB instance.\n\t\t\t\tconst first = value.place.path[0];\n\t\t\t\tif (\n\t\t\t\t\tsource.storage === \"instance\" &&\n\t\t\t\t\tvalue.place.path.length === 1 &&\n\t\t\t\t\tfirst?.kind === \"field\" &&\n\t\t\t\t\tfirst.name === \"out\" &&\n\t\t\t\t\ttype.kind === \"record\"\n\t\t\t\t) {\n\t\t\t\t\tconst result = this.temporary(value.type, value.span);\n\t\t\t\t\tfor (const field of type.fields) {\n\t\t\t\t\t\tconst selected: Expression = {\n\t\t\t\t\t\t\tkind: \"load\",\n\t\t\t\t\t\t\ttype: field.type,\n\t\t\t\t\t\t\tplace: {\n\t\t\t\t\t\t\t\troot: source.id,\n\t\t\t\t\t\t\t\tpath: [\n\t\t\t\t\t\t\t\t\t...value.place.path,\n\t\t\t\t\t\t\t\t\t{ kind: \"field\", name: field.name },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tspan: value.span,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst captured = this.expression(\n\t\t\t\t\t\t\tselected,\n\t\t\t\t\t\t\tinitialized,\n\t\t\t\t\t\t\toutput,\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t);\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\t\t\troot: result.id,\n\t\t\t\t\t\t\tpath: [{ kind: \"field\", name: field.name }],\n\t\t\t\t\t\t\tvalue: captured,\n\t\t\t\t\t\t\tspan: value.span,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tinitialized.add(result.id);\n\t\t\t\t\treturn this.load(result, value.span);\n\t\t\t\t}\n\t\t\t\tconst path = this.normalizePath(value.place, initialized, output);\n\t\t\t\tif (source.storage === \"constant\" && source.initial && !path.length) {\n\t\t\t\t\treturn { ...common, kind: \"constant\", value: source.initial };\n\t\t\t\t}\n\t\t\t\t// Capture now, before a later operand can invoke an effectful helper.\n\t\t\t\tconst result = this.temporary(value.type, value.span);\n\t\t\t\toutput.push({\n\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\troot: result.id,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\t...common,\n\t\t\t\t\t\tkind: \"load\",\n\t\t\t\t\t\troot: source.id,\n\t\t\t\t\t\t...(path.length && { path }),\n\t\t\t\t\t},\n\t\t\t\t\tspan: value.span,\n\t\t\t\t});\n\t\t\t\tconst bound = interval(\n\t\t\t\t\tvalue,\n\t\t\t\t\tthis.declarations.types,\n\t\t\t\t\tthis.scope,\n\t\t\t\t\tthis.ranges,\n\t\t\t\t);\n\t\t\t\tif (bound) {\n\t\t\t\t\tthis.ranges.set(result.id, bound);\n\t\t\t\t}\n\t\t\t\tinitialized.add(result.id);\n\t\t\t\treturn this.load(result, value.span);\n\t\t\t}\n\t\t\tcase \"unary\": {\n\t\t\t\tconst operand = this.expression(value.operand, initialized, output);\n\t\t\t\tconst constant = fold(value, this.scope, this.declarations.types);\n\t\t\t\treturn constant\n\t\t\t\t\t? { ...common, kind: \"constant\", value: constant }\n\t\t\t\t\t: { ...common, kind: \"unary\", operator: value.operator, operand };\n\t\t\t}\n\t\t\tcase \"convert\": {\n\t\t\t\tconst operand = this.expression(value.operand, initialized, output);\n\t\t\t\tconst constant = fold(value, this.scope, this.declarations.types);\n\t\t\t\tif (value.type === value.operand.type) {\n\t\t\t\t\treturn operand;\n\t\t\t\t}\n\t\t\t\treturn constant\n\t\t\t\t\t? { ...common, kind: \"constant\", value: constant }\n\t\t\t\t\t: { ...common, kind: \"convert\", operand, policy: value.policy };\n\t\t\t}\n\t\t\tcase \"binary\": {\n\t\t\t\tconst left = this.expression(value.left, initialized, output);\n\t\t\t\tif (value.operator === \"and\" || value.operator === \"or\") {\n\t\t\t\t\tconst result = this.temporary(\"BOOL\", value.span);\n\t\t\t\t\tconst branch: CoreStatement[] = [];\n\t\t\t\t\toutput.push({\n\t\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\t\troot: result.id,\n\t\t\t\t\t\tvalue: left,\n\t\t\t\t\t\tspan: value.span,\n\t\t\t\t\t});\n\t\t\t\t\tconst right = this.expression(\n\t\t\t\t\t\tvalue.right,\n\t\t\t\t\t\tnew Set(initialized),\n\t\t\t\t\t\tbranch,\n\t\t\t\t\t);\n\t\t\t\t\tbranch.push({\n\t\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\t\troot: result.id,\n\t\t\t\t\t\tvalue: right,\n\t\t\t\t\t\tspan: value.span,\n\t\t\t\t\t});\n\t\t\t\t\tconst condition: CoreExpression =\n\t\t\t\t\t\tvalue.operator === \"and\"\n\t\t\t\t\t\t\t? this.load(result, value.span)\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\tkind: \"unary\",\n\t\t\t\t\t\t\t\t\toperator: \"not\",\n\t\t\t\t\t\t\t\t\toperand: this.load(result, value.span),\n\t\t\t\t\t\t\t\t\ttype: \"BOOL\",\n\t\t\t\t\t\t\t\t\tspan: value.span,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\toutput.push({\n\t\t\t\t\t\tkind: \"if\",\n\t\t\t\t\t\tcondition,\n\t\t\t\t\t\t// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n\t\t\t\t\t\tthen: branch,\n\t\t\t\t\t\telse: [],\n\t\t\t\t\t\tspan: value.span,\n\t\t\t\t\t});\n\t\t\t\t\tinitialized.add(result.id);\n\t\t\t\t\treturn this.load(result, value.span);\n\t\t\t\t}\n\t\t\t\tconst right = this.expression(value.right, initialized, output);\n\t\t\t\tconst constant = fold(value, this.scope, this.declarations.types);\n\t\t\t\tif (constant) {\n\t\t\t\t\treturn { ...common, kind: \"constant\", value: constant };\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\t...common,\n\t\t\t\t\tkind: \"binary\",\n\t\t\t\t\toperator: value.operator,\n\t\t\t\t\tleft,\n\t\t\t\t\tright,\n\t\t\t\t\t...(value.policy && { policy: value.policy }),\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate normalizePath(\n\t\tplace: Place,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): CorePath {\n\t\t// An index is evaluated and captured once, before later arguments can change\n\t\t// its source storage. The resulting path denotes that selected cell.\n\t\treturn place.path.map((segment) =>\n\t\t\tsegment.kind === \"field\"\n\t\t\t\t? segment\n\t\t\t\t: {\n\t\t\t\t\t\tkind: \"index\",\n\t\t\t\t\t\tvalue: this.expression(segment.value, initialized, output),\n\t\t\t\t\t},\n\t\t);\n\t}\n\n\tprivate destination(\n\t\tplace: Place,\n\t\ttype: string,\n\t\tinitialized: Set<string>,\n\t\tspan: SourceSpan,\n\t): Variable {\n\t\tconst target = this.sourceScope.get(place.root);\n\t\tconst initializing =\n\t\t\ttarget?.storage === \"local\" &&\n\t\t\t!initialized.has(place.root) &&\n\t\t\t!place.path.length;\n\t\tconst checked = placeType(\n\t\t\tplace,\n\t\t\tthis.declarations.types,\n\t\t\tthis.sourceScope,\n\t\t\tthis.ranges,\n\t\t\t!initializing,\n\t\t);\n\t\tif (\n\t\t\t!target ||\n\t\t\tchecked.issue ||\n\t\t\tchecked.type !== type ||\n\t\t\tthis.counters.has(place.root)\n\t\t) {\n\t\t\treject(checked.issue ?? \"Invalid assignment destination.\", span);\n\t\t}\n\t\tif (\n\t\t\tplace.path.length &&\n\t\t\ttarget.storage === \"local\" &&\n\t\t\t!initialized.has(target.id)\n\t\t) {\n\t\t\treject(\"Initialize the whole aggregate before assigning fields.\", span);\n\t\t}\n\t\treturn target;\n\t}\n\n\tprivate instanceIndex(\n\t\tinstance: string,\n\t\tindex: Expression | undefined,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t\tspan: SourceSpan,\n\t): CoreExpression | undefined {\n\t\tif (!index) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst checked = placeType(\n\t\t\t{ root: instance, path: [{ kind: \"index\", value: index }] },\n\t\t\tthis.declarations.types,\n\t\t\tthis.sourceScope,\n\t\t\tthis.ranges,\n\t\t);\n\t\tif (checked.issue) {\n\t\t\treject(checked.issue, span);\n\t\t}\n\t\treturn this.expression(index, initialized, output);\n\t}\n\n\tprivate blockUpdate(\n\t\titem: Extract<Statement, { kind: \"blockUpdate\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): void {\n\t\tconst block = this.receiverBlock(item.instance);\n\t\tconst called = block && this.declarations.blocks.get(block);\n\t\tif (!called) {\n\t\t\treject(\n\t\t\t\t\"Updates require a statically allocated block instance.\",\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\tconst index = this.instanceIndex(\n\t\t\titem.instance,\n\t\t\titem.index,\n\t\t\tinitialized,\n\t\t\toutput,\n\t\t\titem.span,\n\t\t);\n\t\t// Input names are unique, so a matching count means every input appears exactly once.\n\t\tconst supplied = Object.entries(item.inputs).flatMap(([name, value]) => {\n\t\t\tconst input = called.inputs.find((port) => port.name === name);\n\t\t\treturn input ? [{ input, value }] : [];\n\t\t});\n\t\tif (\n\t\t\tObject.keys(item.inputs).length !== called.inputs.length ||\n\t\t\tsupplied.length !== called.inputs.length\n\t\t) {\n\t\t\treject(\n\t\t\t\t\"Block update must supply every named input exactly once.\",\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\tthis.callees.add(called.id);\n\t\t// Inputs evaluate in source property order.\n\t\tconst inputs = Object.fromEntries(\n\t\t\tsupplied.map(({ input, value }) => [\n\t\t\t\tinput.name,\n\t\t\t\tthis.argument(input, value, initialized, output),\n\t\t\t]),\n\t\t);\n\t\toutput.push({\n\t\t\tkind: \"blockUpdate\",\n\t\t\tinstance: item.instance,\n\t\t\t...(index && { index }),\n\t\t\tinputs,\n\t\t\tspan: item.span,\n\t\t});\n\t}\n\n\t// verifyCall has matched the argument count to the parameters.\n\tprivate arguments(\n\t\tparameters: readonly Variable[],\n\t\tvalues: readonly Expression[],\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): CoreExpression[] {\n\t\treturn values.map((value, index) =>\n\t\t\tthis.argument(parameters[index]!, value, initialized, output),\n\t\t);\n\t}\n\n\tprivate argument(\n\t\tinput: Variable,\n\t\tvalue: Expression,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): CoreExpression {\n\t\tif (value.type !== input.type) {\n\t\t\treject(\"Block input differs from its concrete PLC type.\", value.span);\n\t\t}\n\t\tif (input.mode === \"inOut\" && value.kind === \"borrow\") {\n\t\t\treturn this.borrow(value, initialized, output);\n\t\t}\n\t\tif (input.mode === \"inOut\") {\n\t\t\t// A value with no writable address reaches the callee through a temporary.\n\t\t\tif (this.declarations.types.get(value.type)?.kind === \"block\") {\n\t\t\t\treject(\"Pass a block instance by name.\", value.span);\n\t\t\t}\n\t\t\tconst temporary = this.temporary(value.type, value.span);\n\t\t\toutput.push({\n\t\t\t\tkind: \"assign\",\n\t\t\t\troot: temporary.id,\n\t\t\t\tvalue: this.expression(value, initialized, output),\n\t\t\t\tspan: value.span,\n\t\t\t});\n\t\t\tinitialized.add(temporary.id);\n\t\t\treturn {\n\t\t\t\tkind: \"borrow\",\n\t\t\t\ttype: value.type,\n\t\t\t\tplace: { root: temporary.id, path: [] },\n\t\t\t\tspan: value.span,\n\t\t\t};\n\t\t}\n\t\tif (value.kind === \"borrow\") {\n\t\t\treject(\n\t\t\t\t\"Readonly value inputs cannot receive borrowed references.\",\n\t\t\t\tvalue.span,\n\t\t\t);\n\t\t}\n\t\treturn this.expression(value, initialized, output, true);\n\t}\n\n\tprivate borrow(\n\t\tvalue: Extract<Expression, { kind: \"borrow\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): CoreExpression {\n\t\tconst block = this.declarations.types.get(value.type)?.kind === \"block\";\n\t\tconst root = this.sourceScope.get(value.place.root);\n\t\tconst checked = placeType(\n\t\t\tvalue.place,\n\t\t\tthis.declarations.types,\n\t\t\tthis.sourceScope,\n\t\t\tthis.ranges,\n\t\t\t!block,\n\t\t);\n\t\tif (\n\t\t\t!root ||\n\t\t\tchecked.issue ||\n\t\t\tchecked.type !== value.type ||\n\t\t\t(!block && !this.declarations.isValueType(value.type)) ||\n\t\t\tthis.counters.has(root.id) ||\n\t\t\t(root.storage === \"local\" && !initialized.has(root.id))\n\t\t) {\n\t\t\treject(\n\t\t\t\tchecked.issue ??\n\t\t\t\t\t\"Borrow requires initialized mutable value storage of the exact type.\",\n\t\t\t\tvalue.span,\n\t\t\t);\n\t\t}\n\t\treturn {\n\t\t\tkind: \"borrow\",\n\t\t\ttype: value.type,\n\t\t\tplace: {\n\t\t\t\troot: value.place.root,\n\t\t\t\tpath: this.normalizePath(value.place, initialized, output),\n\t\t\t},\n\t\t\tspan: value.span,\n\t\t};\n\t}\n\n\tprivate body(\n\t\tstatements: readonly Statement[],\n\t\tinitialized: Set<string>,\n\t): BodyResult {\n\t\tconst output: CoreStatement[] = [];\n\t\tlet state: FlowState = { flow: \"fallthrough\", initialized };\n\t\tfor (const item of statements) {\n\t\t\tif (state.flow !== \"fallthrough\") {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tstate = this.statement(item, state.initialized, output);\n\t\t}\n\t\treturn { body: output, ...state };\n\t}\n\n\tprivate statement(\n\t\titem: Statement,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): FlowState {\n\t\tswitch (item.kind) {\n\t\t\tcase \"assign\":\n\t\t\t\tthis.assign(item, initialized, output);\n\t\t\t\treturn { flow: \"fallthrough\", initialized };\n\t\t\tcase \"blockUpdate\":\n\t\t\t\tthis.blockUpdate(item, initialized, output);\n\t\t\t\treturn { flow: \"fallthrough\", initialized };\n\t\t\tcase \"invoke\":\n\t\t\t\tthis.invoke(item, initialized, output);\n\t\t\t\treturn { flow: \"fallthrough\", initialized };\n\t\t\tcase \"if\":\n\t\t\t\treturn this.ifStatement(item, initialized, output);\n\t\t\tcase \"switch\":\n\t\t\t\treturn this.switchStatement(item, initialized, output);\n\t\t\tcase \"for\":\n\t\t\t\tthis.forStatement(item, initialized, output);\n\t\t\t\treturn { flow: \"fallthrough\", initialized };\n\t\t\tcase \"return\": {\n\t\t\t\tif (item.value?.type !== this.fn.result) {\n\t\t\t\t\treject(\"Return differs from the function signature.\", item.span);\n\t\t\t\t}\n\t\t\t\tconst value =\n\t\t\t\t\titem.value && this.expression(item.value, initialized, output);\n\t\t\t\toutput.push({\n\t\t\t\t\tkind: \"return\",\n\t\t\t\t\tspan: item.span,\n\t\t\t\t\t...(value && { value }),\n\t\t\t\t});\n\t\t\t\treturn { flow: \"return\", initialized };\n\t\t\t}\n\t\t\tcase \"telemetry\":\n\t\t\t\tthis.telemetry(item, initialized, output);\n\t\t\t\treturn { flow: \"fallthrough\", initialized };\n\t\t\tcase \"break\":\n\t\t\tcase \"continue\":\n\t\t\t\t// Every active bounded loop holds its counter.\n\t\t\t\tif (!this.counters.size) {\n\t\t\t\t\treject(\"Loop control appears outside a bounded loop.\", item.span);\n\t\t\t\t}\n\t\t\t\toutput.push({ kind: item.kind, span: item.span });\n\t\t\t\treturn { flow: \"loop\", initialized };\n\t\t\tdefault:\n\t\t\t\treject(\"Unknown PLC statement.\");\n\t\t}\n\t}\n\n\tprivate assign(\n\t\titem: Extract<Statement, { kind: \"assign\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): void {\n\t\tthis.destination(item.destination, item.value.type, initialized, item.span);\n\t\tconst path = this.normalizePath(item.destination, initialized, output);\n\t\t// A const is assigned once, so its initializer's range holds wherever it is read.\n\t\tconst bound =\n\t\t\t!path.length &&\n\t\t\tthis.scope.get(item.destination.root)?.mutable === false &&\n\t\t\tvalueRange(\n\t\t\t\titem.value,\n\t\t\t\tthis.declarations.types,\n\t\t\t\tthis.scope,\n\t\t\t\tthis.ranges,\n\t\t\t\tthis.declarations.signatures,\n\t\t\t);\n\t\tconst value = this.expression(item.value, initialized, output);\n\t\tif (bound) {\n\t\t\tthis.ranges.set(item.destination.root, bound);\n\t\t}\n\t\tif (!path.length) {\n\t\t\tinitialized.add(item.destination.root);\n\t\t}\n\t\toutput.push({\n\t\t\tkind: \"assign\",\n\t\t\troot: item.destination.root,\n\t\t\t...(path.length && { path }),\n\t\t\tvalue,\n\t\t\tspan: item.span,\n\t\t});\n\t}\n\n\tprivate invoke(\n\t\titem: Extract<Statement, { kind: \"invoke\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): void {\n\t\tconst called = this.verifyCall(\n\t\t\titem.function,\n\t\t\titem.arguments,\n\t\t\titem.span,\n\t\t\titem.instance,\n\t\t);\n\t\tif (item.destination) {\n\t\t\tif (item.destination.path.length || !called.result) {\n\t\t\t\treject(\"Invalid helper destination.\", item.span);\n\t\t\t}\n\t\t\tthis.destination(item.destination, called.result, initialized, item.span);\n\t\t}\n\t\tconst index =\n\t\t\titem.instance &&\n\t\t\tthis.instanceIndex(\n\t\t\t\titem.instance,\n\t\t\t\titem.index,\n\t\t\t\tinitialized,\n\t\t\t\toutput,\n\t\t\t\titem.span,\n\t\t\t);\n\t\t// Each argument snapshots its reads before the next argument can invoke\n\t\t// a helper that mutates shared state.\n\t\tconst arguments_ = this.arguments(\n\t\t\tcalled.parameters,\n\t\t\titem.arguments,\n\t\t\tinitialized,\n\t\t\toutput,\n\t\t);\n\t\toutput.push({\n\t\t\tkind: \"invoke\",\n\t\t\tfunction: item.function,\n\t\t\t...(item.instance && { instance: item.instance }),\n\t\t\t...(index && { index }),\n\t\t\targuments: arguments_,\n\t\t\tspan: item.span,\n\t\t\t...(item.destination && { destination: item.destination.root }),\n\t\t});\n\t\tif (item.destination) {\n\t\t\tinitialized.add(item.destination.root);\n\t\t}\n\t}\n\n\tprivate ifStatement(\n\t\titem: Extract<Statement, { kind: \"if\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): FlowState {\n\t\tif (item.condition.type !== \"BOOL\") {\n\t\t\treject(\"Conditions require BOOL.\", item.span);\n\t\t}\n\t\tconst condition = this.expression(item.condition, initialized, output);\n\t\tconst originalRanges = new Map(this.ranges);\n\t\tconst branch = (statements: readonly Statement[], truth: boolean) => {\n\t\t\tthis.ranges.clear();\n\t\t\tfor (const [root, range] of narrowRanges(\n\t\t\t\titem.condition,\n\t\t\t\ttruth,\n\t\t\t\tthis.declarations.types,\n\t\t\t\tthis.sourceScope,\n\t\t\t\toriginalRanges,\n\t\t\t)) {\n\t\t\t\tthis.ranges.set(root, range);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\treturn this.body(statements, new Set(initialized));\n\t\t\t} finally {\n\t\t\t\tthis.ranges.clear();\n\t\t\t\tfor (const [root, range] of originalRanges) {\n\t\t\t\t\tthis.ranges.set(root, range);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tconst yes = branch(item.then, true);\n\t\tconst no = branch(item.else, false);\n\t\toutput.push({\n\t\t\tkind: \"if\",\n\t\t\tcondition,\n\t\t\t// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n\t\t\tthen: yes.body,\n\t\t\telse: no.body,\n\t\t\tspan: item.span,\n\t\t});\n\t\treturn join([yes, no], initialized);\n\t}\n\n\tprivate switchStatement(\n\t\titem: Extract<Statement, { kind: \"switch\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): FlowState {\n\t\tconst value = this.expression(item.value, initialized, output);\n\t\t// The expression above admitted the value's type.\n\t\tconst type = this.declarations.types.get(item.value.type)!;\n\t\tconst seen = new Set<string>();\n\t\tconst cases = item.cases.map((branch) => {\n\t\t\tfor (const constant of branch.values) {\n\t\t\t\tif (!valueFits(constant, type, this.declarations.types)) {\n\t\t\t\t\treject(\"Invalid case constant.\", item.span);\n\t\t\t\t}\n\t\t\t\tconst key = JSON.stringify(constant);\n\t\t\t\tif (seen.has(key)) {\n\t\t\t\t\treject(\"Duplicate case constant.\", item.span);\n\t\t\t\t}\n\t\t\t\tseen.add(key);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tvalues: branch.values,\n\t\t\t\tresult: this.body(branch.body, new Set(initialized)),\n\t\t\t};\n\t\t});\n\t\tconst fallback = this.body(item.fallback, new Set(initialized));\n\t\toutput.push({\n\t\t\tkind: \"switch\",\n\t\t\tvalue,\n\t\t\tcases: cases.map((branch) => ({\n\t\t\t\tvalues: branch.values,\n\t\t\t\tbody: branch.result.body,\n\t\t\t})),\n\t\t\tfallback: fallback.body,\n\t\t\tspan: item.span,\n\t\t});\n\t\treturn join(\n\t\t\t[fallback, ...cases.map((branch) => branch.result)],\n\t\t\tinitialized,\n\t\t);\n\t}\n\n\tprivate forStatement(\n\t\titem: Extract<Statement, { kind: \"for\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): void {\n\t\tconst counter = this.sourceScope.get(item.counter);\n\t\tconst counterType = counter && this.declarations.types.get(counter.type);\n\t\tconst storage =\n\t\t\titem.counterScope === \"existing\"\n\t\t\t\t? [\"local\", \"module\", \"field\"]\n\t\t\t\t: [\"local\"];\n\t\tif (\n\t\t\t!counter ||\n\t\t\t!storage.includes(counter.storage) ||\n\t\t\t!counter.mutable ||\n\t\t\tcounterType?.kind !== \"integer\" ||\n\t\t\tthis.counters.has(counter.id) ||\n\t\t\titem.start.type !== counter.type ||\n\t\t\titem.limit.type !== counter.type ||\n\t\t\t!canonicalInteger.test(item.step) ||\n\t\t\titem.step === \"0\"\n\t\t) {\n\t\t\treject(\"Invalid bounded loop.\", item.span);\n\t\t}\n\t\tconst start = fold(item.start, this.scope, this.declarations.types);\n\t\tconst limit = fold(item.limit, this.scope, this.declarations.types);\n\t\tconst startRange = interval(\n\t\t\titem.start,\n\t\t\tthis.declarations.types,\n\t\t\tthis.sourceScope,\n\t\t\tthis.ranges,\n\t\t);\n\t\tconst limitRange = interval(\n\t\t\titem.limit,\n\t\t\tthis.declarations.types,\n\t\t\tthis.sourceScope,\n\t\t\tthis.ranges,\n\t\t);\n\t\tif (!startRange || !limitRange) {\n\t\t\treject(\"Loop bounds require finite integer ranges.\", item.span);\n\t\t}\n\t\tconst step = BigInt(item.step);\n\t\tconst { first, last, count, range } = loopBounds(\n\t\t\tstartRange,\n\t\t\tlimitRange,\n\t\t\tstep,\n\t\t\titem.exclusive,\n\t\t);\n\t\tconst dynamic = start?.kind !== \"integer\" || limit?.kind !== \"integer\";\n\t\tif (\n\t\t\tcount > maxLoopIterations ||\n\t\t\tNumber(count) !== item.maxIterations ||\n\t\t\t!Number.isSafeInteger(item.maxIterations)\n\t\t) {\n\t\t\treject(\"Loop iteration proof differs from its bounds.\", item.span);\n\t\t}\n\t\tif (item.counterScope === \"existing\") {\n\t\t\tconst lastValue = step > 0n ? range[1] : range[0];\n\t\t\tconst terminal = dynamic ? lastValue + step : first + count * step;\n\t\t\tif (count > 0n && !admits(integerRange(counterType), terminal)) {\n\t\t\t\treject(\n\t\t\t\t\t\"The existing loop counter overflows on termination.\",\n\t\t\t\t\titem.span,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tconst evaluatedStart = this.expression(item.start, initialized, output);\n\t\tconst evaluatedLimit = this.expression(item.limit, initialized, output);\n\t\tinitialized.add(counter.id);\n\t\tthis.counters.add(counter.id);\n\t\tthis.ranges.set(counter.id, range);\n\t\tconst nested = this.body(item.body, new Set(initialized));\n\t\tthis.counters.delete(counter.id);\n\t\tthis.ranges.delete(counter.id);\n\t\tif (item.counterScope !== \"existing\") {\n\t\t\tinitialized.delete(counter.id);\n\t\t}\n\t\toutput.push({\n\t\t\tkind: \"for\",\n\t\t\tcounter: counter.id,\n\t\t\t...(item.counterScope && { counterScope: item.counterScope }),\n\t\t\tstart: { kind: \"integer\", value: String(first) },\n\t\t\tlimit: { kind: \"integer\", value: String(last) },\n\t\t\t...(dynamic && {\n\t\t\t\tdynamic: {\n\t\t\t\t\tstart: evaluatedStart,\n\t\t\t\t\tlimit: evaluatedLimit,\n\t\t\t\t\t...(item.exclusive && { exclusive: item.exclusive }),\n\t\t\t\t},\n\t\t\t}),\n\t\t\tstep: item.step,\n\t\t\tmaxIterations: item.maxIterations,\n\t\t\tbody: nested.body,\n\t\t\tspan: item.span,\n\t\t});\n\t}\n\n\tprivate telemetry(\n\t\titem: Extract<Statement, { kind: \"telemetry\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): void {\n\t\tconst evaluate = (value: Expression) =>\n\t\t\tthis.expression(value, initialized, output);\n\t\tconst { record } = item;\n\t\toutput.push({\n\t\t\tkind: \"telemetry\",\n\t\t\trecord:\n\t\t\t\trecord.kind === \"exception\"\n\t\t\t\t\t? { kind: \"exception\", code: evaluate(record.code) }\n\t\t\t\t\t: record,\n\t\t\tproperties: item.properties.map(({ name, value, length }) => {\n\t\t\t\tif (!length) {\n\t\t\t\t\treturn { name, value: evaluate(value) };\n\t\t\t\t}\n\t\t\t\tif (value.kind !== \"borrow\") {\n\t\t\t\t\treject(\"Telemetry text reads a byte array in place.\", value.span);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tname,\n\t\t\t\t\tvalue: this.borrow(value, initialized, output),\n\t\t\t\t\tlength: evaluate(length),\n\t\t\t\t};\n\t\t\t}),\n\t\t\tspan: item.span,\n\t\t});\n\t}\n}\n",
17
- "import type { BinaryOperator, UnaryOperator } from \"@tsplc/iec/arithmetic\";\nimport {\n\ttype CoreExpression,\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CorePath,\n\ttype CoreStatement,\n\tnestedBodies,\n} from \"./core-model\";\nimport type { SourceSpan } from \"./diagnostics\";\nimport type { Constant, Variable } from \"./model\";\nimport { isTemporary } from \"./routine\";\n\ntype Routine = CoreFunction | CoreFunctionBlock;\ntype Assign = Extract<CoreStatement, { kind: \"assign\" }>;\ntype If = Extract<CoreStatement, { kind: \"if\" }>;\ntype For = Extract<CoreStatement, { kind: \"for\" }>;\ntype Invoke = Extract<CoreStatement, { kind: \"invoke\" }>;\n\nexport type ReconstructedSegment =\n\t| { readonly kind: \"field\"; readonly name: string }\n\t| { readonly kind: \"index\"; readonly value: Reconstruction };\n\n/**\n * A core expression as its source wrote it: the temporaries lowering made for captures, `&&`,\n * `||`, `?:`, record literals and call results inlined back into the expression they stand for.\n * Positions are pre-order statement indexes within the routine.\n */\nexport type Reconstruction = {\n\treadonly type: string;\n\treadonly span: SourceSpan;\n} & (\n\t| {\n\t\t\t/** Storage the routine doesn't own: module storage, or a field of the block it runs on. */\n\t\t\treadonly kind: \"read\";\n\t\t\treadonly root: string;\n\t\t\treadonly path: readonly ReconstructedSegment[];\n\t\t\t/** Where the value was captured. */\n\t\t\treadonly capturedAt: number;\n\t\t\t/** Whether a call runs between the capture and the use, and may have changed it. */\n\t\t\treadonly interleaved: boolean;\n\t }\n\t| { readonly kind: \"constant\"; readonly value: Constant }\n\t| {\n\t\t\treadonly kind: \"record\";\n\t\t\treadonly fields: Readonly<Record<string, Reconstruction>>;\n\t }\n\t| {\n\t\t\treadonly kind: \"array\";\n\t\t\t/** The index of the first item. */\n\t\t\treadonly lower: number;\n\t\t\treadonly items: readonly Reconstruction[];\n\t }\n\t| {\n\t\t\t/** A local the source declares, read at `at`. */\n\t\t\treadonly kind: \"local\";\n\t\t\treadonly root: string;\n\t\t\treadonly path: readonly ReconstructedSegment[];\n\t\t\treadonly at: number;\n\t }\n\t| {\n\t\t\treadonly kind: \"parameter\";\n\t\t\treadonly parameter: number;\n\t\t\treadonly root: string;\n\t\t\treadonly path: readonly ReconstructedSegment[];\n\t\t\treadonly at: number;\n\t }\n\t| {\n\t\t\t/** A call's result, or one of its fields. */\n\t\t\treadonly kind: \"call\";\n\t\t\treadonly call: Invoke;\n\t\t\treadonly path: readonly string[];\n\t }\n\t| { readonly kind: \"clock\" }\n\t| {\n\t\t\treadonly kind: \"unary\";\n\t\t\treadonly operator: Exclude<UnaryOperator, \"clock\">;\n\t\t\treadonly operand: Reconstruction;\n\t }\n\t| {\n\t\t\treadonly kind: \"binary\";\n\t\t\treadonly operator: Exclude<BinaryOperator, \"and\" | \"or\">;\n\t\t\treadonly policy?: \"wrap\" | \"saturate\";\n\t\t\treadonly left: Reconstruction;\n\t\t\treadonly right: Reconstruction;\n\t }\n\t| {\n\t\t\treadonly kind: \"convert\";\n\t\t\treadonly policy: \"exact\" | \"wrap\" | \"saturate\";\n\t\t\treadonly operand: Reconstruction;\n\t }\n\t| {\n\t\t\t/** `&&` or `||`: `right` is evaluated only when `left` doesn't decide. */\n\t\t\treadonly kind: \"logical\";\n\t\t\treadonly operator: \"and\" | \"or\";\n\t\t\treadonly left: Reconstruction;\n\t\t\treadonly right: Reconstruction;\n\t }\n\t| {\n\t\t\treadonly kind: \"select\";\n\t\t\treadonly condition: Reconstruction;\n\t\t\treadonly then: Reconstruction;\n\t\t\treadonly else: Reconstruction;\n\t }\n\t| {\n\t\t\treadonly kind: \"opaque\";\n\t\t\treadonly reason: string;\n\t\t\treadonly reads: readonly Reconstruction[];\n\t }\n);\n\n/** A condition a statement runs under. Tests carry `at`, the position that evaluates them. */\nexport type PathCondition =\n\t| {\n\t\t\treadonly kind: \"test\";\n\t\t\treadonly test: Reconstruction;\n\t\t\treadonly holds: boolean;\n\t\t\treadonly at: number;\n\t\t\treadonly span: SourceSpan;\n\t }\n\t| {\n\t\t\treadonly kind: \"cases\";\n\t\t\treadonly test: Reconstruction;\n\t\t\treadonly values: readonly Constant[];\n\t\t\treadonly member: boolean;\n\t\t\treadonly at: number;\n\t\t\treadonly span: SourceSpan;\n\t }\n\t| {\n\t\t\t/** Holds when none of the conjunctions holds: an earlier statement did not leave. */\n\t\t\treadonly kind: \"exits\";\n\t\t\treadonly any: readonly (readonly PathCondition[])[];\n\t }\n\t| { readonly kind: \"loop\"; readonly loop: number }\n\t/** Holds when no iteration of the loop returned from the routine. */\n\t| { readonly kind: \"loopReturns\"; readonly loop: number }\n\t/** A job's step `step` is current. */\n\t| { readonly kind: \"job\"; readonly step: number }\n\t/** The job is busy: its dispatcher returns at once otherwise. */\n\t| { readonly kind: \"jobBusy\" };\n\nexport interface StatementConditions {\n\treadonly position: number;\n\t/** Outermost first. */\n\treadonly conditions: readonly PathCondition[];\n\t/** The innermost loop the statement runs in, as an index into `loops`. */\n\treadonly loop: number | null;\n}\n\nexport interface LoopConditions {\n\treadonly statement: For;\n\treadonly position: number;\n\treadonly counter: string;\n\treadonly first: Reconstruction;\n\treadonly limit: Reconstruction;\n\treadonly exclusive: boolean;\n\treadonly step: bigint;\n\treadonly maxIterations: number;\n\t/** The conjunctions, within one iteration, under which a `break` stops the loop. */\n\treadonly breaks: readonly (readonly PathCondition[])[];\n\t/** Whether an iteration can return from the routine. */\n\treadonly returns: boolean;\n\treadonly parent: number | null;\n}\n\nexport interface RoutineConditions {\n\treadonly statements: ReadonlyMap<CoreStatement, StatementConditions>;\n\treadonly loops: readonly LoopConditions[];\n\t/** `expression` as the source wrote it, used at position `at`. */\n\treadonly reconstruct: (\n\t\texpression: CoreExpression,\n\t\tat: number,\n\t) => Reconstruction;\n}\n\ntype Conjunction = readonly PathCondition[];\ninterface Exits {\n\treadonly returns: readonly Conjunction[];\n\treadonly breaks: readonly Conjunction[];\n\treadonly continues: readonly Conjunction[];\n}\nconst noExits: Exits = { returns: [], breaks: [], continues: [] };\n\nconst prefixed = (conditions: Conjunction, exits: Exits): Exits => ({\n\treturns: exits.returns.map((item) => [...conditions, ...item]),\n\tbreaks: exits.breaks.map((item) => [...conditions, ...item]),\n\tcontinues: exits.continues.map((item) => [...conditions, ...item]),\n});\n\nconst merged = (...all: readonly Exits[]): Exits => ({\n\treturns: all.flatMap((exits) => exits.returns),\n\tbreaks: all.flatMap((exits) => exits.breaks),\n\tcontinues: all.flatMap((exits) => exits.continues),\n});\n\nconst wholeAssign = (\n\titem: CoreStatement | undefined,\n\troot: string,\n): item is Assign =>\n\titem?.kind === \"assign\" && item.root === root && !item.path?.length;\n\nconst loadedRoot = (value: CoreExpression): string | undefined =>\n\tvalue.kind === \"load\" && !value.path?.length ? value.root : undefined;\n\nconst constantIndex = (value: CoreExpression): number | undefined =>\n\tvalue.kind === \"constant\" && value.value.kind === \"integer\"\n\t\t? Number(value.value.value)\n\t\t: undefined;\n\n/** A constant's field or element, when it has one. */\nconst constantPart = (\n\tvalue: Constant,\n\tsegment: ReconstructedSegment,\n\tlower: number,\n): Constant | undefined => {\n\tif (segment.kind === \"field\") {\n\t\treturn value.kind === \"record\" ? value.fields[segment.name] : undefined;\n\t}\n\tconst index =\n\t\tsegment.value.kind === \"constant\" && segment.value.value.kind === \"integer\"\n\t\t\t? Number(segment.value.value.value)\n\t\t\t: undefined;\n\treturn value.kind === \"array\" && index !== undefined\n\t\t? value.items[index - lower]\n\t\t: undefined;\n};\n\n/** The names along a path of fields and constant indexes, or nothing when an index is dynamic. */\nconst staticNames = (\n\tpath: readonly ReconstructedSegment[],\n): string[] | undefined => {\n\tconst names: string[] = [];\n\tfor (const segment of path) {\n\t\tif (segment.kind === \"field\") {\n\t\t\tnames.push(segment.name);\n\t\t\tcontinue;\n\t\t}\n\t\tif (\n\t\t\tsegment.value.kind !== \"constant\" ||\n\t\t\tsegment.value.value.kind !== \"integer\"\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tnames.push(segment.value.value.value);\n\t}\n\treturn names;\n};\n\nconst opaque = (\n\treason: string,\n\ttype: string,\n\tspan: SourceSpan,\n\treads: readonly Reconstruction[] = [],\n): Reconstruction => ({ kind: \"opaque\", reason, reads, type, span });\n\n/** A part of a reconstructed value: a field or element of a record, array, constant or place. */\nexport const projectReconstruction = (\n\tnode: Reconstruction,\n\tpath: readonly ReconstructedSegment[],\n\ttype: string,\n): Reconstruction => {\n\tconst [segment, ...rest] = path;\n\tif (!segment) {\n\t\treturn node;\n\t}\n\tswitch (node.kind) {\n\t\tcase \"read\":\n\t\tcase \"local\":\n\t\tcase \"parameter\":\n\t\t\treturn { ...node, path: [...node.path, ...path], type };\n\t\tcase \"call\": {\n\t\t\tconst names = staticNames(path);\n\t\t\treturn names\n\t\t\t\t? { ...node, path: [...node.path, ...names], type }\n\t\t\t\t: opaque(\"a call result at a dynamic index\", type, node.span);\n\t\t}\n\t\tcase \"record\": {\n\t\t\tconst field =\n\t\t\t\tsegment.kind === \"field\" ? node.fields[segment.name] : undefined;\n\t\t\treturn field\n\t\t\t\t? projectReconstruction(field, rest, type)\n\t\t\t\t: opaque(\"a field the record doesn't set\", type, node.span);\n\t\t}\n\t\tcase \"array\": {\n\t\t\tconst index =\n\t\t\t\tsegment.kind === \"index\" &&\n\t\t\t\tsegment.value.kind === \"constant\" &&\n\t\t\t\tsegment.value.value.kind === \"integer\"\n\t\t\t\t\t? Number(segment.value.value.value)\n\t\t\t\t\t: undefined;\n\t\t\tconst item =\n\t\t\t\tindex === undefined ? undefined : node.items[index - node.lower];\n\t\t\treturn item\n\t\t\t\t? projectReconstruction(item, rest, type)\n\t\t\t\t: opaque(\"an element at a dynamic index\", type, node.span);\n\t\t}\n\t\tcase \"constant\": {\n\t\t\tconst part = constantPart(node.value, segment, 0);\n\t\t\treturn part\n\t\t\t\t? projectReconstruction(\n\t\t\t\t\t\t{ kind: \"constant\", value: part, type, span: node.span },\n\t\t\t\t\t\trest,\n\t\t\t\t\t\ttype,\n\t\t\t\t\t)\n\t\t\t\t: opaque(\"a part of a constant\", type, node.span);\n\t\t}\n\t\tcase \"select\":\n\t\t\treturn {\n\t\t\t\t...node,\n\t\t\t\ttype,\n\t\t\t\t// biome-ignore lint/suspicious/noThenProperty: a reconstructed `?:` is data, not a thenable.\n\t\t\t\tthen: projectReconstruction(node.then, path, type),\n\t\t\t\telse: projectReconstruction(node.else, path, type),\n\t\t\t};\n\t\tdefault:\n\t\t\treturn opaque(\"a part of a computed value\", type, node.span, [node]);\n\t}\n};\n\n/**\n * Each statement's conditions from routine entry, and the inverse of `routine.ts`'s lowering\n * for the expressions it evaluates. `variables` resolves the types of storage the routine\n * doesn't declare, such as a stored loop counter.\n */\nexport function pathConditions(\n\troutine: Routine,\n\tvariables: ReadonlyMap<string, Pick<Variable, \"type\">>,\n): RoutineConditions {\n\tconst temporaries = new Set(\n\t\troutine.locals\n\t\t\t.filter((local) => isTemporary(routine.id, local))\n\t\t\t.map((local) => local.id),\n\t);\n\tconst locals = new Map(\n\t\troutine.locals\n\t\t\t.filter((local) => !temporaries.has(local.id))\n\t\t\t.map((local) => [local.id, local]),\n\t);\n\tconst parameters = new Map(\n\t\t\"parameters\" in routine\n\t\t\t? routine.parameters.map((parameter, index) => [parameter.id, index])\n\t\t\t: [],\n\t);\n\tconst typeOf = (root: string): string | undefined =>\n\t\tlocals.get(root)?.type ??\n\t\t(\"parameters\" in routine\n\t\t\t? routine.parameters.find((parameter) => parameter.id === root)?.type\n\t\t\t: undefined) ??\n\t\tvariables.get(root)?.type;\n\n\tconst positions = new Map<CoreStatement, number>();\n\tconst calls: number[] = [];\n\tconst definitions = new Map<string, CoreStatement[]>();\n\tconst logicals = new Map<\n\t\tstring,\n\t\t{ operator: \"and\" | \"or\"; left: Assign; right: Assign }\n\t>();\n\tconst synthetic = new Map<If, { operator: \"and\" | \"or\"; left: Assign }>();\n\tconst selects = new Map<string, { test: If; then: Assign; else: Assign }>();\n\tconst sequences: (readonly CoreStatement[])[] = [];\n\tconst number = (items: readonly CoreStatement[]): void => {\n\t\tsequences.push(items);\n\t\tfor (const item of items) {\n\t\t\tpositions.set(item, positions.size);\n\t\t\tif (item.kind === \"invoke\" || item.kind === \"blockUpdate\") {\n\t\t\t\tcalls.push(positions.size - 1);\n\t\t\t}\n\t\t\tconst defined =\n\t\t\t\titem.kind === \"assign\"\n\t\t\t\t\t? item.root\n\t\t\t\t\t: (item.kind === \"invoke\" && item.destination) || undefined;\n\t\t\tif (defined && temporaries.has(defined)) {\n\t\t\t\tdefinitions.set(defined, [...(definitions.get(defined) ?? []), item]);\n\t\t\t}\n\t\t\tnestedBodies(item).forEach(number);\n\t\t}\n\t};\n\tnumber(routine.body);\n\tconst position = (item: CoreStatement): number => positions.get(item) ?? 0;\n\t// `a && b` lowers to `t := a; if t { …; t := b }`, `||` the same under `if NOT t`, and\n\t// `c ? x : y` to `if c { …; t := x } else { …; t := y }`.\n\tfor (const items of sequences) {\n\t\titems.forEach((item, index) => {\n\t\t\tconst next = items[index + 1];\n\t\t\tif (\n\t\t\t\titem.kind === \"assign\" &&\n\t\t\t\t!item.path?.length &&\n\t\t\t\ttemporaries.has(item.root) &&\n\t\t\t\tnext?.kind === \"if\" &&\n\t\t\t\t!next.else.length\n\t\t\t) {\n\t\t\t\tconst negated =\n\t\t\t\t\tnext.condition.kind === \"unary\" && next.condition.operator === \"not\";\n\t\t\t\tconst tested = loadedRoot(\n\t\t\t\t\tnext.condition.kind === \"unary\" && next.condition.operator === \"not\"\n\t\t\t\t\t\t? next.condition.operand\n\t\t\t\t\t\t: next.condition,\n\t\t\t\t);\n\t\t\t\tconst right = next.then.at(-1);\n\t\t\t\tif (\n\t\t\t\t\ttested === item.root &&\n\t\t\t\t\twholeAssign(right, item.root) &&\n\t\t\t\t\tdefinitions.get(item.root)?.length === 2\n\t\t\t\t) {\n\t\t\t\t\tconst operator = negated ? \"or\" : \"and\";\n\t\t\t\t\tlogicals.set(item.root, { operator, left: item, right });\n\t\t\t\t\tsynthetic.set(next, { operator, left: item });\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (item.kind === \"if\") {\n\t\t\t\tconst then = item.then.at(-1);\n\t\t\t\tconst otherwise = item.else.at(-1);\n\t\t\t\tif (\n\t\t\t\t\tthen?.kind === \"assign\" &&\n\t\t\t\t\ttemporaries.has(then.root) &&\n\t\t\t\t\twholeAssign(then, then.root) &&\n\t\t\t\t\twholeAssign(otherwise, then.root) &&\n\t\t\t\t\tdefinitions.get(then.root)?.length === 2\n\t\t\t\t) {\n\t\t\t\t\tselects.set(then.root, { test: item, then, else: otherwise });\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tconst interleaved = (capturedAt: number, at: number): boolean =>\n\t\tcalls.some((call) => call > capturedAt && call < at);\n\n\tconst segments = (path: CorePath, at: number): ReconstructedSegment[] =>\n\t\tpath.map((segment) =>\n\t\t\tsegment.kind === \"field\"\n\t\t\t\t? segment\n\t\t\t\t: { kind: \"index\", value: reconstruct(segment.value, at) },\n\t\t);\n\n\t/** A stored, local or parameter place, read where it was captured. */\n\tconst place = (\n\t\troot: string,\n\t\tpath: readonly ReconstructedSegment[],\n\t\tcapturedAt: number,\n\t\tat: number,\n\t\ttype: string,\n\t\tspan: SourceSpan,\n\t): Reconstruction => {\n\t\tif (temporaries.has(root)) {\n\t\t\treturn temporary(root, path, at, type, span);\n\t\t}\n\t\tif (locals.has(root)) {\n\t\t\treturn { kind: \"local\", root, path, at: capturedAt, type, span };\n\t\t}\n\t\tconst parameter = parameters.get(root);\n\t\tif (parameter !== undefined) {\n\t\t\treturn {\n\t\t\t\tkind: \"parameter\",\n\t\t\t\tparameter,\n\t\t\t\troot,\n\t\t\t\tpath,\n\t\t\t\tat: capturedAt,\n\t\t\t\ttype,\n\t\t\t\tspan,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tkind: \"read\",\n\t\t\troot,\n\t\t\tpath,\n\t\t\tcapturedAt,\n\t\t\tinterleaved: interleaved(capturedAt, at),\n\t\t\ttype,\n\t\t\tspan,\n\t\t};\n\t};\n\n\tconst temporary = (\n\t\troot: string,\n\t\tpath: readonly ReconstructedSegment[],\n\t\tat: number,\n\t\ttype: string,\n\t\tspan: SourceSpan,\n\t): Reconstruction => {\n\t\tconst logical = logicals.get(root);\n\t\tif (logical) {\n\t\t\treturn projectReconstruction(\n\t\t\t\t{\n\t\t\t\t\tkind: \"logical\",\n\t\t\t\t\toperator: logical.operator,\n\t\t\t\t\tleft: reconstruct(logical.left.value, position(logical.left)),\n\t\t\t\t\tright: reconstruct(logical.right.value, position(logical.right)),\n\t\t\t\t\ttype: \"BOOL\",\n\t\t\t\t\tspan,\n\t\t\t\t},\n\t\t\t\tpath,\n\t\t\t\ttype,\n\t\t\t);\n\t\t}\n\t\tconst select = selects.get(root);\n\t\tif (select) {\n\t\t\tconst branch = (item: Assign) => reconstruct(item.value, position(item));\n\t\t\treturn projectReconstruction(\n\t\t\t\t{\n\t\t\t\t\tkind: \"select\",\n\t\t\t\t\tcondition: reconstruct(select.test.condition, position(select.test)),\n\t\t\t\t\t// biome-ignore lint/suspicious/noThenProperty: a reconstructed `?:` is data, not a thenable.\n\t\t\t\t\tthen: branch(select.then),\n\t\t\t\t\telse: branch(select.else),\n\t\t\t\t\ttype: select.then.value.type,\n\t\t\t\t\tspan,\n\t\t\t\t},\n\t\t\t\tpath,\n\t\t\t\ttype,\n\t\t\t);\n\t\t}\n\t\tconst defined = definitions.get(root) ?? [];\n\t\tconst [only] = defined;\n\t\tif (defined.length === 1 && only?.kind === \"invoke\") {\n\t\t\treturn projectReconstruction(\n\t\t\t\t{\n\t\t\t\t\tkind: \"call\",\n\t\t\t\t\tcall: only,\n\t\t\t\t\tpath: [],\n\t\t\t\t\ttype: typeOf(root) ?? type,\n\t\t\t\t\tspan: only.span,\n\t\t\t\t},\n\t\t\t\tpath,\n\t\t\t\ttype,\n\t\t\t);\n\t\t}\n\t\tif (defined.length === 1 && only && wholeAssign(only, root)) {\n\t\t\tconst value = only.value;\n\t\t\tif (value.kind === \"load\") {\n\t\t\t\treturn place(\n\t\t\t\t\tvalue.root,\n\t\t\t\t\t[...segments(value.path ?? [], position(only)), ...path],\n\t\t\t\t\tposition(only),\n\t\t\t\t\tat,\n\t\t\t\t\ttype,\n\t\t\t\t\tvalue.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn projectReconstruction(\n\t\t\t\treconstruct(value, position(only)),\n\t\t\t\tpath,\n\t\t\t\ttype,\n\t\t\t);\n\t\t}\n\t\treturn parts(root, defined, path, type, span);\n\t};\n\n\t/** A temporary built field by field or element by element: a record or array literal, or an `.out` snapshot. */\n\tconst parts = (\n\t\troot: string,\n\t\tdefined: readonly CoreStatement[],\n\t\tpath: readonly ReconstructedSegment[],\n\t\ttype: string,\n\t\tspan: SourceSpan,\n\t): Reconstruction => {\n\t\tconst fields = new Map<string, Assign>();\n\t\tconst items = new Map<number, Assign>();\n\t\tfor (const item of defined) {\n\t\t\tconst [segment, ...rest] =\n\t\t\t\titem.kind === \"assign\" ? (item.path ?? []) : [];\n\t\t\tconst index =\n\t\t\t\tsegment?.kind === \"index\" ? constantIndex(segment.value) : undefined;\n\t\t\tif (item.kind !== \"assign\" || !segment || rest.length) {\n\t\t\t\treturn opaque(\"a value set in several places\", type, span);\n\t\t\t}\n\t\t\tif (segment.kind === \"field\" && !fields.has(segment.name)) {\n\t\t\t\tfields.set(segment.name, item);\n\t\t\t} else if (index !== undefined && !items.has(index) && !fields.size) {\n\t\t\t\titems.set(index, item);\n\t\t\t} else {\n\t\t\t\treturn opaque(\"a value set in several places\", type, span);\n\t\t\t}\n\t\t}\n\t\tconst value = (item: Assign) => reconstruct(item.value, position(item));\n\t\tif (items.size) {\n\t\t\tconst indexes = [...items.keys()].sort((a, b) => a - b);\n\t\t\tconst lower = indexes[0] ?? 0;\n\t\t\tconst contiguous = indexes.every(\n\t\t\t\t(index, offset) => index === lower + offset,\n\t\t\t);\n\t\t\tif (!contiguous) {\n\t\t\t\treturn opaque(\"an array with gaps\", type, span);\n\t\t\t}\n\t\t\treturn projectReconstruction(\n\t\t\t\t{\n\t\t\t\t\tkind: \"array\",\n\t\t\t\t\tlower,\n\t\t\t\t\titems: indexes.flatMap((index) => {\n\t\t\t\t\t\tconst item = items.get(index);\n\t\t\t\t\t\treturn item ? [value(item)] : [];\n\t\t\t\t\t}),\n\t\t\t\t\ttype: typeOf(root) ?? type,\n\t\t\t\t\tspan,\n\t\t\t\t},\n\t\t\t\tpath,\n\t\t\t\ttype,\n\t\t\t);\n\t\t}\n\t\tif (!fields.size) {\n\t\t\treturn opaque(\"a value with no definition\", type, span);\n\t\t}\n\t\treturn projectReconstruction(\n\t\t\t{\n\t\t\t\tkind: \"record\",\n\t\t\t\tfields: Object.fromEntries(\n\t\t\t\t\t[...fields].map(([name, item]) => [name, value(item)]),\n\t\t\t\t),\n\t\t\t\ttype: typeOf(root) ?? type,\n\t\t\t\tspan,\n\t\t\t},\n\t\t\tpath,\n\t\t\ttype,\n\t\t);\n\t};\n\n\tconst reconstruct = (\n\t\texpression: CoreExpression,\n\t\tat: number,\n\t): Reconstruction => {\n\t\tconst { type, span } = expression;\n\t\tswitch (expression.kind) {\n\t\t\tcase \"constant\":\n\t\t\t\treturn { kind: \"constant\", value: expression.value, type, span };\n\t\t\tcase \"borrow\":\n\t\t\t\treturn place(\n\t\t\t\t\texpression.place.root,\n\t\t\t\t\tsegments(expression.place.path, at),\n\t\t\t\t\tat,\n\t\t\t\t\tat,\n\t\t\t\t\ttype,\n\t\t\t\t\tspan,\n\t\t\t\t);\n\t\t\tcase \"load\":\n\t\t\t\treturn place(\n\t\t\t\t\texpression.root,\n\t\t\t\t\tsegments(expression.path ?? [], at),\n\t\t\t\t\tat,\n\t\t\t\t\tat,\n\t\t\t\t\ttype,\n\t\t\t\t\tspan,\n\t\t\t\t);\n\t\t\tcase \"unary\":\n\t\t\t\tif (expression.operator === \"clock\") {\n\t\t\t\t\treturn { kind: \"clock\", type, span };\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"unary\",\n\t\t\t\t\toperator: expression.operator,\n\t\t\t\t\toperand: reconstruct(expression.operand, at),\n\t\t\t\t\ttype,\n\t\t\t\t\tspan,\n\t\t\t\t};\n\t\t\tcase \"convert\":\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"convert\",\n\t\t\t\t\tpolicy: expression.policy,\n\t\t\t\t\toperand: reconstruct(expression.operand, at),\n\t\t\t\t\ttype,\n\t\t\t\t\tspan,\n\t\t\t\t};\n\t\t\tcase \"binary\": {\n\t\t\t\tconst left = reconstruct(expression.left, at);\n\t\t\t\tconst right = reconstruct(expression.right, at);\n\t\t\t\tif (expression.operator === \"and\" || expression.operator === \"or\") {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tkind: \"logical\",\n\t\t\t\t\t\toperator: expression.operator,\n\t\t\t\t\t\tleft,\n\t\t\t\t\t\tright,\n\t\t\t\t\t\ttype,\n\t\t\t\t\t\tspan,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"binary\",\n\t\t\t\t\toperator: expression.operator,\n\t\t\t\t\t...(expression.policy && { policy: expression.policy }),\n\t\t\t\t\tleft,\n\t\t\t\t\tright,\n\t\t\t\t\ttype,\n\t\t\t\t\tspan,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t};\n\n\tconst job =\n\t\t\"inputs\" in routine && routine.job\n\t\t\t? {\n\t\t\t\t\tbusy: routine.state.find((field) => field.name === \"busy\")?.id,\n\t\t\t\t\tstep: routine.state.find((field) => field.name === \"step\")?.id,\n\t\t\t\t}\n\t\t\t: undefined;\n\tconst isField = (node: Reconstruction, field: string | undefined): boolean =>\n\t\tfield !== undefined &&\n\t\tnode.kind === \"read\" &&\n\t\tnode.root === field &&\n\t\t!node.path.length;\n\t/** The job dispatcher's `IF NOT busy THEN RETURN`. */\n\tconst busyGuard = (item: CoreStatement): boolean => {\n\t\tif (\n\t\t\titem.kind !== \"if\" ||\n\t\t\titem.else.length ||\n\t\t\titem.then.length !== 1 ||\n\t\t\titem.then[0]?.kind !== \"return\"\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\tconst test = reconstruct(item.condition, position(item));\n\t\treturn (\n\t\t\ttest.kind === \"unary\" &&\n\t\t\ttest.operator === \"not\" &&\n\t\t\tisField(test.operand, job?.busy)\n\t\t);\n\t};\n\t/** The dispatcher's `switch` on `step`. */\n\tconst stepSwitch = (item: CoreStatement): boolean =>\n\t\titem.kind === \"switch\" &&\n\t\tisField(reconstruct(item.value, position(item)), job?.step);\n\n\tconst statements = new Map<CoreStatement, StatementConditions>();\n\tconst loops: LoopConditions[] = [];\n\ttype Mode = \"plain\" | \"jobDispatcher\" | \"jobTransitions\";\n\n\tconst sequence = (\n\t\titems: readonly CoreStatement[],\n\t\tconditions: Conjunction,\n\t\tloop: number | null,\n\t\tmode: Mode,\n\t): Exits => {\n\t\tconst guards: PathCondition[] = [];\n\t\tconst exits: Exits[] = [];\n\t\tfor (const item of items) {\n\t\t\tconst here = [...conditions, ...guards];\n\t\t\tstatements.set(item, {\n\t\t\t\tposition: position(item),\n\t\t\t\tconditions: here,\n\t\t\t\tloop,\n\t\t\t});\n\t\t\tif (mode === \"jobDispatcher\" && busyGuard(item)) {\n\t\t\t\tfor (const branch of nestedBodies(item)) {\n\t\t\t\t\tsequence(branch, here, loop, \"plain\");\n\t\t\t\t}\n\t\t\t\tguards.push({ kind: \"jobBusy\" });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tmode === \"jobDispatcher\" &&\n\t\t\t\titem.kind === \"for\" &&\n\t\t\t\titem.body.some(stepSwitch)\n\t\t\t) {\n\t\t\t\tsequence(item.body, here, loop, \"jobTransitions\");\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst own = statementExits(item, here, loop, mode);\n\t\t\texits.push(prefixed(guards, own));\n\t\t\tconst any = [...own.returns, ...own.breaks, ...own.continues];\n\t\t\tif (any.length) {\n\t\t\t\tguards.push({ kind: \"exits\", any });\n\t\t\t}\n\t\t}\n\t\treturn merged(...exits);\n\t};\n\n\tconst statementExits = (\n\t\titem: CoreStatement,\n\t\there: Conjunction,\n\t\tloop: number | null,\n\t\tmode: Mode,\n\t): Exits => {\n\t\tconst at = position(item);\n\t\tswitch (item.kind) {\n\t\t\tcase \"return\":\n\t\t\t\treturn { ...noExits, returns: [[]] };\n\t\t\tcase \"break\":\n\t\t\t\treturn { ...noExits, breaks: [[]] };\n\t\t\tcase \"continue\":\n\t\t\t\treturn { ...noExits, continues: [[]] };\n\t\t\tcase \"if\": {\n\t\t\t\tconst lowered = synthetic.get(item);\n\t\t\t\tconst tested = lowered ? lowered.left.value : item.condition;\n\t\t\t\tconst test = reconstruct(tested, lowered ? position(lowered.left) : at);\n\t\t\t\tconst holds = lowered?.operator !== \"or\";\n\t\t\t\tconst condition = (truth: boolean): PathCondition => ({\n\t\t\t\t\tkind: \"test\",\n\t\t\t\t\ttest,\n\t\t\t\t\tholds: truth === holds,\n\t\t\t\t\tat,\n\t\t\t\t\tspan: tested.span,\n\t\t\t\t});\n\t\t\t\tconst yes = condition(true);\n\t\t\t\tconst no = condition(false);\n\t\t\t\treturn merged(\n\t\t\t\t\tprefixed([yes], sequence(item.then, [...here, yes], loop, \"plain\")),\n\t\t\t\t\tprefixed([no], sequence(item.else, [...here, no], loop, \"plain\")),\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase \"switch\": {\n\t\t\t\tconst test = reconstruct(item.value, at);\n\t\t\t\tconst steps = mode === \"jobTransitions\" && stepSwitch(item);\n\t\t\t\tconst inside = steps\n\t\t\t\t\t? here.filter((condition) => condition.kind !== \"jobBusy\")\n\t\t\t\t\t: here;\n\t\t\t\tconst branch = (\n\t\t\t\t\tcondition: PathCondition,\n\t\t\t\t\tbody: readonly CoreStatement[],\n\t\t\t\t) =>\n\t\t\t\t\tprefixed(\n\t\t\t\t\t\t[condition],\n\t\t\t\t\t\tsequence(body, [...inside, condition], loop, \"plain\"),\n\t\t\t\t\t);\n\t\t\t\tconst cases = item.cases.map((entry) => {\n\t\t\t\t\tconst [value] = entry.values;\n\t\t\t\t\tconst step =\n\t\t\t\t\t\tsteps && value?.kind === \"integer\" && entry.values.length === 1\n\t\t\t\t\t\t\t? Number(value.value)\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\treturn branch(\n\t\t\t\t\t\tstep === undefined\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tkind: \"cases\",\n\t\t\t\t\t\t\t\t\ttest,\n\t\t\t\t\t\t\t\t\tvalues: entry.values,\n\t\t\t\t\t\t\t\t\tmember: true,\n\t\t\t\t\t\t\t\t\tat,\n\t\t\t\t\t\t\t\t\tspan: item.value.span,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: { kind: \"job\", step },\n\t\t\t\t\t\tentry.body,\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\tconst fallback = branch(\n\t\t\t\t\t{\n\t\t\t\t\t\tkind: \"cases\",\n\t\t\t\t\t\ttest,\n\t\t\t\t\t\tvalues: item.cases.flatMap((entry) => entry.values),\n\t\t\t\t\t\tmember: false,\n\t\t\t\t\t\tat,\n\t\t\t\t\t\tspan: item.value.span,\n\t\t\t\t\t},\n\t\t\t\t\titem.fallback,\n\t\t\t\t);\n\t\t\t\treturn merged(...cases, fallback);\n\t\t\t}\n\t\t\tcase \"for\": {\n\t\t\t\tconst id = loops.length;\n\t\t\t\tconst counter = typeOf(item.counter) ?? \"DINT\";\n\t\t\t\tconst bound = (value: Constant): Reconstruction => ({\n\t\t\t\t\tkind: \"constant\",\n\t\t\t\t\tvalue,\n\t\t\t\t\ttype: counter,\n\t\t\t\t\tspan: item.span,\n\t\t\t\t});\n\t\t\t\tconst slot: LoopConditions = {\n\t\t\t\t\tstatement: item,\n\t\t\t\t\tposition: at,\n\t\t\t\t\tcounter: item.counter,\n\t\t\t\t\tfirst: item.dynamic\n\t\t\t\t\t\t? reconstruct(item.dynamic.start, at)\n\t\t\t\t\t\t: bound(item.start),\n\t\t\t\t\tlimit: item.dynamic\n\t\t\t\t\t\t? reconstruct(item.dynamic.limit, at)\n\t\t\t\t\t\t: bound(item.limit),\n\t\t\t\t\texclusive: item.dynamic?.exclusive === true,\n\t\t\t\t\tstep: BigInt(item.step),\n\t\t\t\t\tmaxIterations: item.maxIterations,\n\t\t\t\t\tbreaks: [],\n\t\t\t\t\treturns: false,\n\t\t\t\t\tparent: loop,\n\t\t\t\t};\n\t\t\t\tloops.push(slot);\n\t\t\t\tconst body = sequence(\n\t\t\t\t\titem.body,\n\t\t\t\t\t[...here, { kind: \"loop\", loop: id }],\n\t\t\t\t\tid,\n\t\t\t\t\t\"plain\",\n\t\t\t\t);\n\t\t\t\tloops[id] = {\n\t\t\t\t\t...slot,\n\t\t\t\t\tbreaks: body.breaks,\n\t\t\t\t\treturns: body.returns.length > 0,\n\t\t\t\t};\n\t\t\t\treturn body.returns.length\n\t\t\t\t\t? { ...noExits, returns: [[{ kind: \"loopReturns\", loop: id }]] }\n\t\t\t\t\t: noExits;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn noExits;\n\t\t}\n\t};\n\n\tsequence(routine.body, [], null, job ? \"jobDispatcher\" : \"plain\");\n\treturn { statements, loops, reconstruct };\n}\n",
18
- "import { createHash } from \"node:crypto\";\n\n/**\n * Generated names are a fixed function of the identity of what they stand for, so the same source\n * names the same things whatever else changes: an online change then finds every piece of state\n * where it left it. A digest keeps the name short and its identity out of the PLC's namespace.\n */\nexport const identityDigest = (identity: string): string =>\n\tcreateHash(\"sha256\").update(identity).digest(\"hex\").slice(0, 8);\n",
19
- "/** Job error codes by meaning, as generated async blocks and service calls set them. */\nexport const jobError = {\n\tcancelled: 1,\n\ttimeout: 2,\n\ttooLarge: 3,\n\tmalformedResponse: 4,\n\tnetwork: 5,\n\ttls: 6,\n\tnoRequestSlot: 7,\n\t/**\n\t * An online change replaced the code of a job that was running: its step and stored state\n\t * were made for the old code, so it stops instead of resuming in the new. Like `cancelled`,\n\t * it skips `catch`, so a retry can't send a request twice.\n\t */\n\tcodeChanged: 11001,\n} as const;\n\n/** An HTTP response fails a job with `base` + its status, up to `last`. */\nexport const httpErrors = { base: 10000, last: 10999 };\n\n/** Codes tsPLC itself reports from 11000 on, which a program's own `throw` may not use. */\nexport const reservedErrors = { first: 11000, last: 11099 };\n\n/** Job error codes, as every generated async block and service call reports them. */\nexport const jobErrors: Record<string, string> = {\n\t[jobError.cancelled]: \"cancelled\",\n\t[jobError.timeout]: \"timeout\",\n\t[jobError.tooLarge]: \"request or response too large to encode\",\n\t[jobError.malformedResponse]: \"malformed response\",\n\t[jobError.network]: \"network error or server restarted\",\n\t[jobError.tls]: \"TLS error\",\n\t[jobError.noRequestSlot]: \"no free request slot\",\n\t[jobError.codeChanged]:\n\t\t\"an online change replaced the job's code while it ran\",\n\t[httpErrors.base]: \"HTTP status: 10000 + status code\",\n};\n\n/** What a telemetry exception record calls an error code: its meaning when it is a job error. */\nexport const errorName = (code: number): string | undefined => {\n\tif (code > httpErrors.base && code <= httpErrors.last) {\n\t\treturn `HTTP ${code - httpErrors.base}`;\n\t}\n\tif (code >= reservedErrors.first && code <= reservedErrors.last) {\n\t\treturn jobErrors[code];\n\t}\n\treturn code < httpErrors.base ? jobErrors[code] : undefined;\n};\n",
20
- "// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.\nimport { elementaryType, integerRange } from \"@tsplc/iec\";\nimport { InvalidCore, reject } from \"./normalization-error\";\nimport { constantFits } from \"./numeric\";\nimport { type PlcType, primitiveTypes } from \"./types\";\n\n/** The finite storage budget: scalar elements in one layout or allocation, and nesting depth. */\nexport const maxScalarElements = 1_000_000;\nexport const maxNestingDepth = 64;\n\n// Array bounds and indexes are DINT.\nconst [firstIndex, lastIndex] = integerRange(elementaryType(\"DINT\"));\n\nconst definitionIssue = (\n\ttype: PlcType,\n\ttypes: ReadonlyMap<string, PlcType>,\n): string | undefined => {\n\tconst canonical = primitiveTypes.find((item) => item.id === type.id);\n\tif (canonical) {\n\t\treturn type.kind !== canonical.kind ||\n\t\t\t(\"bits\" in canonical &&\n\t\t\t\t(!(\"bits\" in type) || type.bits !== canonical.bits)) ||\n\t\t\t(\"signed\" in canonical &&\n\t\t\t\t(!(\"signed\" in type) || type.signed !== canonical.signed)) ||\n\t\t\t(\"domain\" in canonical &&\n\t\t\t\t(!(\"domain\" in type) || type.domain !== canonical.domain))\n\t\t\t? `Conflicting primitive type ${type.id}`\n\t\t\t: undefined;\n\t}\n\tswitch (type.kind) {\n\t\tcase \"record\":\n\t\t\treturn !type.fields.length ||\n\t\t\t\tnew Set(type.fields.map((field) => field.name)).size !==\n\t\t\t\t\ttype.fields.length ||\n\t\t\t\ttype.fields.some(\n\t\t\t\t\t(field) =>\n\t\t\t\t\t\t!field.name ||\n\t\t\t\t\t\ttypeof field.readonly !== \"boolean\" ||\n\t\t\t\t\t\t(field.mode && field.mode !== \"inOut\") ||\n\t\t\t\t\t\t!types.has(field.type),\n\t\t\t\t)\n\t\t\t\t? `Invalid closed record layout ${type.id}`\n\t\t\t\t: undefined;\n\t\tcase \"array\": {\n\t\t\tif (\n\t\t\t\t!types.has(type.element) ||\n\t\t\t\t!Number.isSafeInteger(type.length) ||\n\t\t\t\ttype.length < 1 ||\n\t\t\t\ttype.length > maxScalarElements ||\n\t\t\t\t!Number.isInteger(type.lowerBound) ||\n\t\t\t\tBigInt(type.lowerBound) < firstIndex ||\n\t\t\t\tBigInt(type.lowerBound + type.length - 1) > lastIndex\n\t\t\t) {\n\t\t\t\treturn `Invalid fixed array layout ${type.id}`;\n\t\t\t}\n\t\t\tif (type.index === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst index = types.get(type.index);\n\t\t\treturn index?.kind !== \"enum\" ||\n\t\t\t\tindex.members.length !== type.length ||\n\t\t\t\tindex.members.some(\n\t\t\t\t\t(member) =>\n\t\t\t\t\t\tNumber(member.value) < type.lowerBound ||\n\t\t\t\t\t\tNumber(member.value) >= type.lowerBound + type.length,\n\t\t\t\t)\n\t\t\t\t? `Invalid enum-keyed array layout ${type.id}`\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"enum\": {\n\t\t\tconst base = types.get(type.base);\n\t\t\treturn type.base !== \"DINT\" ||\n\t\t\t\tbase?.kind !== \"integer\" ||\n\t\t\t\t!type.members.length ||\n\t\t\t\tnew Set(type.members.map((member) => member.name)).size !==\n\t\t\t\t\ttype.members.length ||\n\t\t\t\tnew Set(type.members.map((member) => member.value)).size !==\n\t\t\t\t\ttype.members.length ||\n\t\t\t\ttype.members.some(\n\t\t\t\t\t(member) =>\n\t\t\t\t\t\t!member.name ||\n\t\t\t\t\t\t!constantFits({ kind: \"integer\", value: member.value }, base),\n\t\t\t\t)\n\t\t\t\t? `Invalid enum layout ${type.id}`\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"string\":\n\t\t\treturn !Number.isInteger(type.capacity) ||\n\t\t\t\ttype.capacity < 1 ||\n\t\t\t\ttype.capacity > 65535 ||\n\t\t\t\t![\"utf8\", \"utf16\"].includes(type.encoding)\n\t\t\t\t? `Invalid bounded string layout ${type.id}`\n\t\t\t\t: undefined;\n\t\tcase \"block\":\n\t\t\treturn !type.block ||\n\t\t\t\t(type.output && types.get(type.output)?.kind !== \"record\")\n\t\t\t\t? `Invalid block type ${type.id}`\n\t\t\t\t: undefined;\n\t\tdefault:\n\t\t\treturn `Unsupported core type definition ${type.id}`;\n\t}\n};\n\ninterface Layout {\n\tsize: number;\n\theight: number;\n}\n\n/**\n * Validates every layout edge once, before constants or places can traverse them, and measures\n * each by-value layout against the storage budget. Returns each type's size in scalar elements.\n */\nexport const admitLayouts = (\n\ttypes: ReadonlyMap<string, PlcType>,\n): ReadonlyMap<string, number> => {\n\tfor (const type of types.values()) {\n\t\tconst issue = definitionIssue(type, types);\n\t\tif (issue) {\n\t\t\treject(issue);\n\t\t}\n\t}\n\tconst active = new Set<string>();\n\tconst layouts = new Map<string, Layout>();\n\tconst measure = (id: string, depth: number): Layout => {\n\t\tif (active.has(id) || depth > maxNestingDepth) {\n\t\t\treject(`Recursive or excessively nested by-value layout ${id}`);\n\t\t}\n\t\tconst cached = layouts.get(id);\n\t\tif (cached) {\n\t\t\tif (depth + cached.height > maxNestingDepth) {\n\t\t\t\treject(`Layout nesting exceeds ${maxNestingDepth} levels ${id}`);\n\t\t\t}\n\t\t\treturn cached;\n\t\t}\n\t\tactive.add(id);\n\t\t// Every edge was validated above.\n\t\tconst layout = composite(types.get(id)!, depth);\n\t\tactive.delete(id);\n\t\tif (layout.size > maxScalarElements) {\n\t\t\treject(`Layout exceeds one million scalar elements ${id}`);\n\t\t}\n\t\tif (depth + layout.height > maxNestingDepth) {\n\t\t\treject(`Layout nesting exceeds ${maxNestingDepth} levels ${id}`);\n\t\t}\n\t\tlayouts.set(id, layout);\n\t\treturn layout;\n\t};\n\tconst composite = (type: PlcType, depth: number): Layout => {\n\t\tif (type.kind === \"array\") {\n\t\t\tconst element = measure(type.element, depth + 1);\n\t\t\treturn { size: type.length * element.size, height: 1 + element.height };\n\t\t}\n\t\tif (type.kind === \"record\") {\n\t\t\tconst fields = type.fields.map((field) => measure(field.type, depth + 1));\n\t\t\treturn {\n\t\t\t\tsize: fields.reduce((sum, field) => sum + field.size, 0),\n\t\t\t\theight:\n\t\t\t\t\t1 +\n\t\t\t\t\tfields.reduce((maximum, field) => Math.max(maximum, field.height), 0),\n\t\t\t};\n\t\t}\n\t\treturn { size: 1, height: 0 };\n\t};\n\tfor (const id of types.keys()) {\n\t\tmeasure(id, 0);\n\t}\n\treturn new Map([...layouts].map(([id, layout]) => [id, layout.size]));\n};\n\nexport const layoutIssue = (\n\ttypes: ReadonlyMap<string, PlcType>,\n): string | undefined => {\n\ttry {\n\t\tadmitLayouts(types);\n\t\treturn undefined;\n\t} catch (cause) {\n\t\tif (cause instanceof InvalidCore) {\n\t\t\treturn cause.diagnostic.message;\n\t\t}\n\t\tthrow cause;\n\t}\n};\n",
21
- "// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.\nimport type { ModuleDeclarations } from \"./declarations\";\nimport { maxNestingDepth, maxScalarElements } from \"./layouts\";\nimport type { PlcModule } from \"./model\";\nimport { reject } from \"./normalization-error\";\nimport { instancedBlock } from \"./types\";\n\nexport function checkStaticAllocation(\n\tmodule: PlcModule,\n\tdeclarations: ModuleDeclarations,\n): void {\n\tconst { types, blocks, layoutSizes } = declarations;\n\n\t// Declaration admission closes these registries over every referenced type\n\t// and block before allocation starts; a missing entry cannot be authored here.\n\t// Static allocation is a separate graph from scan calls: even an unused child\n\t// consumes memory, and a recursive child cannot be allocated by value.\n\tconst payload = (id: string): number => layoutSizes.get(id)!;\n\n\tconst instanceSize = (id: string): number => {\n\t\tconst type = types.get(id)!;\n\t\treturn type.kind === \"array\"\n\t\t\t? type.length * instanceSize(type.element)\n\t\t\t: allocation(type.kind === \"block\" ? type.block : \"\").size;\n\t};\n\tconst allocations = new Map<string, { size: number; height: number }>();\n\tconst allocating = new Set<string>();\n\tconst allocation = (id: string): { size: number; height: number } => {\n\t\tif (allocating.size >= maxNestingDepth) {\n\t\t\treject(\n\t\t\t\t`Static block allocation nesting exceeds ${maxNestingDepth} levels.`,\n\t\t\t\tblocks.get(id)?.span,\n\t\t\t);\n\t\t}\n\t\tif (allocating.has(id)) {\n\t\t\treject(\"Recursive static block allocation.\", blocks.get(id)?.span);\n\t\t}\n\t\tconst cached = allocations.get(id);\n\t\tif (cached) {\n\t\t\treturn cached;\n\t\t}\n\t\tallocating.add(id);\n\t\tconst block = blocks.get(id)!;\n\t\tconst children = block.state\n\t\t\t.filter((item) => item.storage === \"instance\")\n\t\t\t.map((item) => ({\n\t\t\t\theight: allocation(instancedBlock(item.type, types)!.block).height,\n\t\t\t\tsize: instanceSize(item.type),\n\t\t\t}));\n\t\tconst own = [\n\t\t\t...block.inputs,\n\t\t\t...block.outputs,\n\t\t\t...block.state.filter((item) => item.storage !== \"instance\"),\n\t\t].reduce(\n\t\t\t(sum, item) => sum + (item.mode === \"inOut\" ? 1 : payload(item.type)),\n\t\t\t1,\n\t\t);\n\t\tconst size = own + children.reduce((sum, child) => sum + child.size, 0);\n\t\tconst height = children.length\n\t\t\t? 1 + Math.max(...children.map((child) => child.height))\n\t\t\t: 1;\n\t\tif (size > maxScalarElements || height > maxNestingDepth) {\n\t\t\treject(\"Static block allocation exceeds its finite budget.\", block.span);\n\t\t}\n\t\tallocating.delete(id);\n\t\tconst result = { size, height };\n\t\tallocations.set(id, result);\n\t\treturn result;\n\t};\n\n\tfor (const block of module.blocks) {\n\t\tallocation(block.id);\n\t}\n\tconst staticPayload = module.variables.reduce((sum, variable) => {\n\t\treturn (\n\t\t\tsum +\n\t\t\t(instancedBlock(variable.type, types)\n\t\t\t\t? instanceSize(variable.type)\n\t\t\t\t: payload(variable.type))\n\t\t);\n\t}, 0);\n\tif (staticPayload > maxScalarElements) {\n\t\treject(\"Static module storage exceeds one million scalar elements.\");\n\t}\n}\n",
22
- "import { valueFits } from \"./aggregates\";\nimport type { SourceSpan } from \"./diagnostics\";\nimport { admitLayouts } from \"./layouts\";\nimport {\n\ttype FunctionBlock,\n\ttype PlcFunction,\n\ttype PlcModule,\n\ttype StandardBlock,\n\tstandardBlocks,\n\ttype Variable,\n} from \"./model\";\nimport { reject } from \"./normalization-error\";\nimport { instancedBlock, type PlcType } from \"./types\";\n\nconst matchesPorts = (\n\tvariables: readonly Variable[],\n\tschema: readonly (readonly [string, string, string])[],\n): boolean =>\n\tvariables.length === schema.length &&\n\tschema.every(([name, , type]) =>\n\t\tvariables.some(\n\t\t\t(variable) =>\n\t\t\t\tvariable.name === name &&\n\t\t\t\tvariable.type === type &&\n\t\t\t\t!variable.mode &&\n\t\t\t\t!variable.retain,\n\t\t),\n\t);\n\n/** A standard block is exactly its vendor table entry: no body or state, and outputs at their defaults. */\nconst checkStandardBlock = (\n\tblock: FunctionBlock,\n\tstandard: StandardBlock,\n): void => {\n\tconst expected = Object.hasOwn(standardBlocks, standard)\n\t\t? standardBlocks[standard]\n\t\t: undefined;\n\tif (\n\t\t!expected ||\n\t\tblock.name !== standard ||\n\t\tblock.body.length ||\n\t\tblock.state.length ||\n\t\tblock.locals.length ||\n\t\t!matchesPorts(block.inputs, expected.inputs) ||\n\t\t!matchesPorts(block.outputs, expected.outputs) ||\n\t\tblock.outputs.some(({ initial }) => {\n\t\t\tswitch (initial?.kind) {\n\t\t\t\tcase \"bool\":\n\t\t\t\t\treturn initial.value !== false;\n\t\t\t\tcase \"duration\":\n\t\t\t\t\treturn initial.nanoseconds !== \"0\";\n\t\t\t\tcase \"integer\":\n\t\t\t\t\treturn initial.value !== \"0\";\n\t\t\t\tdefault:\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t})\n\t) {\n\t\treject(\"Invalid canonical standard block definition.\", block.span);\n\t}\n};\n\n// This index owns the module namespace and storage declarations. Routine\n// lowering may claim temporary identifiers, but cannot weaken admission rules.\nexport class ModuleDeclarations {\n\tprivate readonly ids = new Set<string>();\n\treadonly types = new Map<string, PlcType>();\n\t/** Each type's by-value size in scalar elements. */\n\treadonly layoutSizes: ReadonlyMap<string, number>;\n\treadonly globals = new Map<string, Variable>();\n\treadonly blocks: Map<string, FunctionBlock>;\n\treadonly signatures: Map<string, PlcFunction>;\n\n\tconstructor(module: PlcModule) {\n\t\tfor (const type of module.types) {\n\t\t\tif (this.types.has(type.id)) {\n\t\t\t\treject(`Duplicate type ${type.id}.`);\n\t\t\t}\n\t\t\tthis.types.set(type.id, type);\n\t\t}\n\t\tthis.layoutSizes = admitLayouts(this.types);\n\t\tif (this.types.get(\"BOOL\")?.kind !== \"bool\") {\n\t\t\treject(\"Missing canonical BOOL type.\");\n\t\t}\n\n\t\tthis.blocks = new Map(module.blocks.map((block) => [block.id, block]));\n\t\tfor (const item of module.variables) {\n\t\t\tthis.checkVariable(item, [\n\t\t\t\t\"module\",\n\t\t\t\t\"instance\",\n\t\t\t\t\"input\",\n\t\t\t\t\"output\",\n\t\t\t\t\"constant\",\n\t\t\t]);\n\t\t\tthis.globals.set(item.id, item);\n\t\t}\n\n\t\tthis.signatures = new Map(module.functions.map((fn) => [fn.id, fn]));\n\t\tfor (const fn of module.functions) {\n\t\t\tthis.claimId(fn.id, fn.span);\n\t\t\tif (\n\t\t\t\tfn.owner &&\n\t\t\t\t(!this.blocks.has(fn.owner.block) ||\n\t\t\t\t\tthis.blocks.get(fn.owner.block)?.standard ||\n\t\t\t\t\t![\"public\", \"private\", \"protected\"].includes(fn.owner.access))\n\t\t\t) {\n\t\t\t\treject(\n\t\t\t\t\t\"Methods require a user block owner and a valid access modifier.\",\n\t\t\t\t\tfn.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (fn.result && !this.isValueType(fn.result)) {\n\t\t\t\treject(\"Unknown or non-value function result type.\", fn.span);\n\t\t\t}\n\t\t\tfor (const parameter of fn.parameters) {\n\t\t\t\tthis.checkVariable(parameter, [\"parameter\"], true);\n\t\t\t\tif (parameter.mutable && !parameter.mode) {\n\t\t\t\t\treject(\"Value parameters are readonly.\", parameter.span);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const local of fn.locals) {\n\t\t\t\tthis.checkVariable(local, [\"local\"]);\n\t\t\t}\n\t\t}\n\n\t\tfor (const block of module.blocks) {\n\t\t\tthis.claimId(block.id, block.span);\n\t\t\tfor (const input of block.inputs) {\n\t\t\t\tthis.checkVariable(input, [\"parameter\"], true);\n\t\t\t\tif (!input.mode && input.mutable) {\n\t\t\t\t\treject(\"Value block inputs are readonly.\", input.span);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const output of block.outputs) {\n\t\t\t\tthis.checkVariable(output, [\"blockOutput\"]);\n\t\t\t}\n\t\t\tfor (const state of block.state) {\n\t\t\t\tthis.checkVariable(state, [\"field\", \"instance\"]);\n\t\t\t}\n\t\t\tfor (const local of block.locals) {\n\t\t\t\tthis.checkVariable(local, [\"local\"]);\n\t\t\t}\n\t\t\tfor (const ports of [block.inputs, block.outputs]) {\n\t\t\t\tif (\n\t\t\t\t\tnew Set(ports.map((variable) => variable.name)).size !== ports.length\n\t\t\t\t) {\n\t\t\t\t\treject(\n\t\t\t\t\t\t\"Block input and output names must each be unique within their schema.\",\n\t\t\t\t\t\tblock.span,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst result = block.result ? this.types.get(block.result) : undefined;\n\t\t\tif (\n\t\t\t\tblock.outputs.length\n\t\t\t\t\t? result?.kind !== \"record\" ||\n\t\t\t\t\t\t!this.isValueType(result.id) ||\n\t\t\t\t\t\tresult.fields.length !== block.outputs.length ||\n\t\t\t\t\t\tresult.fields.some(\n\t\t\t\t\t\t\t(field) =>\n\t\t\t\t\t\t\t\t!block.outputs.some(\n\t\t\t\t\t\t\t\t\t(output) =>\n\t\t\t\t\t\t\t\t\t\toutput.name === field.name && output.type === field.type,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t: Boolean(block.result)\n\t\t\t) {\n\t\t\t\treject(\n\t\t\t\t\t\"Block output schema differs from its result record.\",\n\t\t\t\t\tblock.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (block.standard) {\n\t\t\t\tcheckStandardBlock(block, block.standard);\n\t\t\t}\n\t\t}\n\n\t\tfor (const type of this.types.values()) {\n\t\t\tif (type.kind === \"block\") {\n\t\t\t\tconst definition = this.blocks.get(type.block);\n\t\t\t\tif (!definition || definition.result !== type.output) {\n\t\t\t\t\treject(\"Block type differs from its definition.\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\thasId(id: string): boolean {\n\t\treturn this.ids.has(id);\n\t}\n\n\tpublic claimId(id: string, span?: SourceSpan): void {\n\t\tif (this.ids.has(id)) {\n\t\t\treject(`Duplicate symbol ${id}.`, span);\n\t\t}\n\t\tthis.ids.add(id);\n\t}\n\n\tpublic isValueType(id: string, seen = new Set<string>()): boolean {\n\t\tif (seen.has(id)) {\n\t\t\treturn true;\n\t\t}\n\t\tseen.add(id);\n\t\tconst type = this.types.get(id);\n\t\treturn Boolean(\n\t\t\ttype &&\n\t\t\t\ttype.kind !== \"block\" &&\n\t\t\t\t(type.kind !== \"record\" ||\n\t\t\t\t\ttype.fields.every(\n\t\t\t\t\t\t(field) => !field.mode && this.isValueType(field.type, seen),\n\t\t\t\t\t)) &&\n\t\t\t\t(type.kind !== \"array\" || this.isValueType(type.element, seen)),\n\t\t);\n\t}\n\n\tprivate checkVariable(\n\t\titem: Variable,\n\t\tstorage: readonly Variable[\"storage\"][],\n\t\tallowBorrow = false,\n\t): void {\n\t\tthis.claimId(item.id, item.span);\n\t\tconst type = this.types.get(item.type);\n\t\tif (!type || !storage.includes(item.storage)) {\n\t\t\treject(\"Invalid storage type or class.\", item.span);\n\t\t}\n\t\tif (\n\t\t\titem.mode &&\n\t\t\t(item.mode !== \"inOut\" ||\n\t\t\t\t!allowBorrow ||\n\t\t\t\t!item.mutable ||\n\t\t\t\titem.storage !== \"parameter\")\n\t\t) {\n\t\t\treject(\"InOut belongs only on mutable parameters.\", item.span);\n\t\t}\n\t\tconst mutableState =\n\t\t\titem.mutable ||\n\t\t\ttype.kind === \"array\" ||\n\t\t\t(type.kind === \"record\" && type.fields.some((field) => !field.readonly));\n\t\tif (\n\t\t\titem.retain &&\n\t\t\t!(\n\t\t\t\titem.storage === \"instance\" ||\n\t\t\t\t([\"module\", \"field\"].includes(item.storage) && mutableState)\n\t\t\t)\n\t\t) {\n\t\t\treject(\n\t\t\t\t\"Only mutable static state or block instances may retain.\",\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\tif (item.storage === \"instance\") {\n\t\t\tconst instanced = instancedBlock(item.type, this.types);\n\t\t\tif (\n\t\t\t\t!instanced ||\n\t\t\t\t!this.blocks.has(instanced.block) ||\n\t\t\t\titem.initial ||\n\t\t\t\titem.mode\n\t\t\t) {\n\t\t\t\treject(\n\t\t\t\t\t\"Instances require a known static block and cannot have value initializers.\",\n\t\t\t\t\titem.span,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (\n\t\t\t!this.isValueType(item.type) &&\n\t\t\t!(allowBorrow && item.mode === \"inOut\" && type.kind === \"block\")\n\t\t) {\n\t\t\treject(\n\t\t\t\t\"Block instances and reference schemas cannot be stored as values.\",\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\tif (item.storage === \"parameter\" && item.initial) {\n\t\t\treject(\n\t\t\t\t\"Inputs are supplied at each invocation and cannot have stored initializers.\",\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\tif (item.initial && !valueFits(item.initial, type, this.types)) {\n\t\t\treject(\"Initializer has the wrong type or is out of range.\", item.span);\n\t\t}\n\t\tif (\n\t\t\t[\"module\", \"field\", \"constant\", \"blockOutput\"].includes(item.storage) &&\n\t\t\t!item.initial\n\t\t) {\n\t\t\treject(\"Persistent storage requires initialization.\", item.span);\n\t\t}\n\t\tif (\n\t\t\t[\"input\", \"constant\", \"blockOutput\"].includes(item.storage) &&\n\t\t\titem.mutable\n\t\t) {\n\t\t\treject(\"Readonly storage marked mutable.\", item.span);\n\t\t}\n\t}\n}\n",
23
- "// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.\nimport {\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CoreStatement,\n\tdirectWrites,\n\tnestedBodies,\n} from \"./core-model\";\nimport type { ModuleDeclarations } from \"./declarations\";\nimport { type PlcModule, telemetryOperands } from \"./model\";\nimport { reject } from \"./normalization-error\";\nimport { instancedBlock, type PlcType } from \"./types\";\n\ntype Edges = ReadonlyMap<string, ReadonlySet<string>>;\ntype Routine = CoreFunction | CoreFunctionBlock;\n\n// Validate the complete authored call graph before pruning unreachable code.\n// Static instances keep their child layouts even when a child has no scan call.\nexport function linkModule(\n\tmodule: PlcModule,\n\tdeclarations: ModuleDeclarations,\n\tfunctions: CoreFunction[],\n\tnormalizedBlocks: CoreFunctionBlock[],\n\tedges: Edges,\n) {\n\tconst entries = checkPrograms(module, declarations);\n\tconst routines = new Map<string, Routine>(\n\t\t[...functions, ...normalizedBlocks].map((fn) => [fn.id, fn]),\n\t);\n\tcheckRecursion(routines, edges, entries, declarations);\n\tcheckLoopCounterWrites(module, declarations, routines, edges);\n\n\t// Only after the complete graph is valid may emission discard unused helpers.\n\tconst reachable = reachableRoutines(\n\t\tmodule,\n\t\tdeclarations,\n\t\tfunctions,\n\t\tentries,\n\t\tedges,\n\t);\n\tconst linkedFunctions = functions.filter((fn) => reachable.has(fn.id));\n\tconst linkedBlocks = normalizedBlocks.filter((block) =>\n\t\treachable.has(block.id),\n\t);\n\tconst usedTypes = usedTypeIds(\n\t\tmodule,\n\t\tdeclarations.types,\n\t\tlinkedFunctions,\n\t\tlinkedBlocks,\n\t);\n\treturn {\n\t\ttypes: module.types.filter((type) => usedTypes.has(type.id)),\n\t\tvariables: module.variables,\n\t\tfunctions: linkedFunctions,\n\t\tblocks: linkedBlocks,\n\t\tprograms: module.programs,\n\t\t...(module.folded && { folded: module.folded }),\n\t\t...(module.references && { references: module.references }),\n\t};\n}\n\n/** Checks each program's entry and name, and returns the entry routines. */\nconst checkPrograms = (\n\tmodule: PlcModule,\n\tdeclarations: ModuleDeclarations,\n): ReadonlySet<string> => {\n\tconst names = new Set<string>();\n\tconst entries = new Set<string>();\n\tfor (const program of module.programs) {\n\t\tdeclarations.claimId(program.id);\n\t\tconst entry = declarations.signatures.get(program.entry);\n\t\tif (!entry || entry.owner || entry.parameters.length || entry.result) {\n\t\t\treject(\"Program entry must be a parameterless void helper.\");\n\t\t}\n\t\tif (names.has(program.name)) {\n\t\t\treject(`Duplicate program ${program.name}.`);\n\t\t}\n\t\tnames.add(program.name);\n\t\tentries.add(program.entry);\n\t}\n\tif (!module.programs.length) {\n\t\treject(\"At least one program is required.\");\n\t}\n\treturn entries;\n};\n\n// Authored execution cycles are invalid even in unreachable routines. Static\n// allocation has its own cycle check because it does not depend on scan calls.\nconst checkRecursion = (\n\troutines: ReadonlyMap<string, Routine>,\n\tedges: Edges,\n\tentries: ReadonlySet<string>,\n\t{ signatures }: ModuleDeclarations,\n): void => {\n\tconst visited = new Set<string>();\n\tconst active = new Set<string>();\n\tconst visit = (id: string): void => {\n\t\tif (active.has(id)) {\n\t\t\treject(\"Recursive scan calls are prohibited.\", signatures.get(id)?.span);\n\t\t}\n\t\tif (visited.has(id)) {\n\t\t\treturn;\n\t\t}\n\t\tactive.add(id);\n\t\tfor (const child of edges.get(id) ?? []) {\n\t\t\tif (entries.has(child)) {\n\t\t\t\treject(\n\t\t\t\t\t\"Program entries cannot be called as ordinary helpers.\",\n\t\t\t\t\tsignatures.get(id)?.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\tvisit(child);\n\t\t}\n\t\tactive.delete(id);\n\t\tvisited.add(id);\n\t};\n\tfor (const id of routines.keys()) {\n\t\tvisit(id);\n\t}\n};\n\n// A bounded loop can only reconstruct its counter if called helpers leave\n// that storage alone. Include transitive calls, not just direct assignments.\nconst checkLoopCounterWrites = (\n\tmodule: PlcModule,\n\t{ types }: ModuleDeclarations,\n\troutines: ReadonlyMap<string, Routine>,\n\tedges: Edges,\n): void => {\n\tconst variables = new Map(\n\t\t[\n\t\t\t...module.variables,\n\t\t\t...[...routines.values()].flatMap((routine) =>\n\t\t\t\t\"inputs\" in routine\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t...routine.inputs,\n\t\t\t\t\t\t\t...routine.outputs,\n\t\t\t\t\t\t\t...routine.state,\n\t\t\t\t\t\t\t...routine.locals,\n\t\t\t\t\t\t]\n\t\t\t\t\t: [...routine.parameters, ...routine.locals],\n\t\t\t),\n\t\t].map((variable) => [variable.id, variable]),\n\t);\n\tconst calledRoutine = (item: CoreStatement): string | undefined => {\n\t\tif (item.kind === \"invoke\") {\n\t\t\treturn item.function;\n\t\t}\n\t\tif (item.kind !== \"blockUpdate\") {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst variable = variables.get(item.instance);\n\t\treturn variable && instancedBlock(variable.type, types)?.block;\n\t};\n\tconst writes = new Map<string, Set<string>>();\n\tconst routineWrites = (id: string): Set<string> => {\n\t\tconst cached = writes.get(id);\n\t\tif (cached) {\n\t\t\treturn cached;\n\t\t}\n\t\tconst result = new Set<string>();\n\t\tconst inspect = (body: readonly CoreStatement[]) => {\n\t\t\tfor (const item of body) {\n\t\t\t\tfor (const root of directWrites(item)) {\n\t\t\t\t\tresult.add(root);\n\t\t\t\t}\n\t\t\t\tfor (const nested of nestedBodies(item)) {\n\t\t\t\t\tinspect(nested);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\t// Calls resolve within the module's routines; routine lowering verified each callee.\n\t\tinspect(routines.get(id)!.body);\n\t\tfor (const child of edges.get(id) ?? []) {\n\t\t\tfor (const root of routineWrites(child)) {\n\t\t\t\tresult.add(root);\n\t\t\t}\n\t\t}\n\t\twrites.set(id, result);\n\t\treturn result;\n\t};\n\tconst checkCalls = (\n\t\tbody: readonly CoreStatement[],\n\t\tcounters: ReadonlySet<string>,\n\t) => {\n\t\tfor (const item of body) {\n\t\t\tconst called = calledRoutine(item);\n\t\t\tif (\n\t\t\t\tcalled &&\n\t\t\t\t[...counters].some((counter) => routineWrites(called).has(counter))\n\t\t\t) {\n\t\t\t\treject(\n\t\t\t\t\t\"A called routine may mutate an active loop counter.\",\n\t\t\t\t\titem.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst nestedCounters =\n\t\t\t\titem.kind === \"for\" ? new Set([...counters, item.counter]) : counters;\n\t\t\tfor (const nested of nestedBodies(item)) {\n\t\t\t\tcheckCalls(nested, nestedCounters);\n\t\t\t}\n\t\t}\n\t};\n\tfor (const routine of routines.values()) {\n\t\tcheckCalls(routine.body, new Set());\n\t}\n};\n\nconst reachableRoutines = (\n\tmodule: PlcModule,\n\t{ signatures, blocks, types }: ModuleDeclarations,\n\tfunctions: readonly CoreFunction[],\n\tentries: ReadonlySet<string>,\n\tedges: Edges,\n): ReadonlySet<string> => {\n\tconst reachable = new Set<string>();\n\tconst link = (id: string): void => {\n\t\tif (reachable.has(id)) {\n\t\t\treturn;\n\t\t}\n\t\treachable.add(id);\n\t\tfor (const child of edges.get(id) ?? []) {\n\t\t\tlink(child);\n\t\t}\n\t\tconst owner = signatures.get(id)?.owner;\n\t\tif (owner) {\n\t\t\tlink(owner.block);\n\t\t}\n\t\tfor (const method of functions.filter((fn) => fn.owner?.block === id)) {\n\t\t\tlink(method.id);\n\t\t}\n\t\tfor (const instance of blocks\n\t\t\t.get(id)\n\t\t\t?.state.filter((variable) => variable.storage === \"instance\") ?? []) {\n\t\t\tconst type = instancedBlock(instance.type, types);\n\t\t\tif (type) {\n\t\t\t\tlink(type.block);\n\t\t\t}\n\t\t}\n\t};\n\tfor (const entry of entries) {\n\t\tlink(entry);\n\t}\n\tfor (const variable of module.variables) {\n\t\tconst type = instancedBlock(variable.type, types);\n\t\tif (type) {\n\t\t\tlink(type.block);\n\t\t}\n\t}\n\treturn reachable;\n};\n\n// Admission has already validated every referenced type; these lookups are\n// closed over the declaration registry, including dependencies kept by DUTs.\nconst usedTypeIds = (\n\tmodule: PlcModule,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tlinkedFunctions: readonly CoreFunction[],\n\tlinkedBlocks: readonly CoreFunctionBlock[],\n): ReadonlySet<string> => {\n\tconst usedTypes = new Set<string>();\n\tconst useType = (id: string): void => {\n\t\tif (usedTypes.has(id)) {\n\t\t\treturn;\n\t\t}\n\t\tusedTypes.add(id);\n\t\tconst type = types.get(id)!;\n\t\tif (type.kind === \"record\") {\n\t\t\tfor (const field of type.fields) {\n\t\t\t\tuseType(field.type);\n\t\t\t}\n\t\t}\n\t\tif (type.kind === \"array\") {\n\t\t\tuseType(type.element);\n\t\t\tif (type.index) {\n\t\t\t\tuseType(type.index);\n\t\t\t}\n\t\t}\n\t\tif (type.kind === \"enum\") {\n\t\t\tuseType(type.base);\n\t\t}\n\t\tif (type.kind === \"block\" && type.output) {\n\t\t\tuseType(type.output);\n\t\t}\n\t};\n\t// Primitive definitions also support backend-generated numeric helpers.\n\ttypes.forEach((type) => {\n\t\tif (\n\t\t\t[\"bool\", \"integer\", \"bits\", \"float\", \"duration\", \"calendar\"].includes(\n\t\t\t\ttype.kind,\n\t\t\t)\n\t\t) {\n\t\t\tuseType(type.id);\n\t\t}\n\t});\n\tfor (const variable of module.variables) {\n\t\tuseType(variable.type);\n\t}\n\tfor (const fn of linkedFunctions) {\n\t\tif (fn.result) {\n\t\t\tuseType(fn.result);\n\t\t}\n\t\tfor (const variable of [...fn.parameters, ...fn.locals]) {\n\t\t\tuseType(variable.type);\n\t\t}\n\t}\n\tfor (const block of linkedBlocks) {\n\t\tif (block.result) {\n\t\t\tuseType(block.result);\n\t\t}\n\t\tfor (const variable of [\n\t\t\t...block.inputs,\n\t\t\t...block.outputs,\n\t\t\t...block.state,\n\t\t\t...block.locals,\n\t\t]) {\n\t\t\tuseType(variable.type);\n\t\t}\n\t}\n\t// A telemetry property can be its type's only use, such as an enum field the elaborator folded.\n\tconst useTelemetryTypes = (body: readonly CoreStatement[]): void => {\n\t\tfor (const item of body) {\n\t\t\tif (item.kind === \"telemetry\") {\n\t\t\t\tfor (const operand of telemetryOperands(item)) {\n\t\t\t\t\tuseType(operand.type);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const nested of nestedBodies(item)) {\n\t\t\t\tuseTelemetryTypes(nested);\n\t\t\t}\n\t\t}\n\t};\n\tfor (const routine of [...linkedFunctions, ...linkedBlocks]) {\n\t\tuseTelemetryTypes(routine.body);\n\t}\n\treturn usedTypes;\n};\n",
24
- "import { checkStaticAllocation } from \"./allocation\";\nimport {\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype VerifiedCoreModule,\n\tverified,\n} from \"./core-model\";\nimport { ModuleDeclarations } from \"./declarations\";\nimport type { Diagnostic } from \"./diagnostics\";\nimport { linkModule } from \"./link\";\nimport type { PlcModule } from \"./model\";\nimport { InvalidCore } from \"./normalization-error\";\nimport { RoutineNormalizer } from \"./routine\";\n\nconst verifiedModules = new WeakSet<object>();\nexport function isVerifiedCore(value: unknown): value is VerifiedCoreModule {\n\treturn (\n\t\ttypeof value === \"object\" && value !== null && verifiedModules.has(value)\n\t);\n}\n\nfunction freeze(value: unknown): void {\n\tif (typeof value !== \"object\" || value === null || Object.isFrozen(value)) {\n\t\treturn;\n\t}\n\tfor (const child of Object.values(value)) {\n\t\tfreeze(child);\n\t}\n\tObject.freeze(value);\n}\n/**\n * Admits a module across the trust boundary. Only normalization, and transformations of an\n * admitted module that keep what it verified, call this.\n */\nexport function admitCore(core: VerifiedCoreModule): VerifiedCoreModule {\n\tfreeze(core);\n\tverifiedModules.add(core);\n\treturn core;\n}\n\n// The module crosses the trust boundary only after admission, lowering and linking.\nexport function normalizeModule(module: PlcModule): {\n\tcore?: VerifiedCoreModule;\n\tdiagnostics: readonly Diagnostic[];\n} {\n\ttry {\n\t\tconst declarations = new ModuleDeclarations(module);\n\t\tcheckStaticAllocation(module, declarations);\n\n\t\tconst functions: CoreFunction[] = [];\n\t\tconst blocks: CoreFunctionBlock[] = [];\n\t\tconst edges = new Map<string, ReadonlySet<string>>();\n\t\tfor (const source of [...module.functions, ...module.blocks]) {\n\t\t\tconst normalized = new RoutineNormalizer(\n\t\t\t\tsource,\n\t\t\t\tdeclarations,\n\t\t\t).normalize();\n\t\t\tedges.set(source.id, normalized.callees);\n\t\t\tif (\"inputs\" in normalized.routine) {\n\t\t\t\tblocks.push(normalized.routine);\n\t\t\t} else {\n\t\t\t\tfunctions.push(normalized.routine);\n\t\t\t}\n\t\t}\n\n\t\tconst linked = linkModule(module, declarations, functions, blocks, edges);\n\t\treturn {\n\t\t\tcore: admitCore({ ...structuredClone(linked), [verified]: true }),\n\t\t\tdiagnostics: [],\n\t\t};\n\t} catch (cause) {\n\t\tif (cause instanceof InvalidCore) {\n\t\t\treturn { diagnostics: [cause.diagnostic] };\n\t\t}\n\t\tthrow cause;\n\t}\n}\n",
25
- "import type { CoreExpression, CorePath, CoreStatement } from \"./core-model\";\nimport { telemetryOperands } from \"./model\";\n\n/** The index expressions along a place's path. */\nexport const pathIndexes = (path: CorePath = []): CoreExpression[] =>\n\tpath.flatMap((segment) => (segment.kind === \"index\" ? [segment.value] : []));\n\n/** The expressions an expression evaluates directly: its operands, or the indexes of the place it loads or borrows. */\nexport const subexpressions = (\n\tvalue: CoreExpression,\n): readonly CoreExpression[] => {\n\tswitch (value.kind) {\n\t\tcase \"constant\":\n\t\t\treturn [];\n\t\tcase \"load\":\n\t\t\treturn pathIndexes(value.path);\n\t\tcase \"borrow\":\n\t\t\treturn pathIndexes(value.place.path);\n\t\tcase \"unary\":\n\t\tcase \"convert\":\n\t\t\treturn [value.operand];\n\t\tcase \"binary\":\n\t\t\treturn [value.left, value.right];\n\t}\n};\n\n/**\n * The expressions a statement evaluates itself, a place's indexes before the value stored or\n * passed there. The statements nested in it are `nestedBodies`.\n */\nexport const statementExpressions = (\n\titem: CoreStatement,\n): readonly CoreExpression[] => {\n\tswitch (item.kind) {\n\t\tcase \"assign\":\n\t\t\treturn [...pathIndexes(item.path), item.value];\n\t\tcase \"if\":\n\t\t\treturn [item.condition];\n\t\tcase \"switch\":\n\t\t\treturn [item.value];\n\t\tcase \"for\":\n\t\t\treturn item.dynamic ? [item.dynamic.start, item.dynamic.limit] : [];\n\t\tcase \"invoke\":\n\t\t\treturn [...(item.index ? [item.index] : []), ...item.arguments];\n\t\tcase \"blockUpdate\":\n\t\t\treturn [\n\t\t\t\t...(item.index ? [item.index] : []),\n\t\t\t\t...Object.values(item.inputs),\n\t\t\t];\n\t\tcase \"return\":\n\t\t\treturn item.value ? [item.value] : [];\n\t\tcase \"telemetry\":\n\t\t\treturn telemetryOperands(item);\n\t\tcase \"break\":\n\t\tcase \"continue\":\n\t\t\treturn [];\n\t}\n};\n",
26
- "import {\n\ttype CoreExpression,\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CorePath,\n\ttype CoreStatement,\n\tnestedBodies,\n\ttype VerifiedCoreModule,\n} from \"./core-model\";\nimport type { Variable } from \"./model\";\nimport { admitCore } from \"./normalize\";\nimport type { PlcType } from \"./types\";\n\n/**\n * Routines that are the same code over different storage, such as one method elaborated once per\n * instance, merged into one routine that borrows that storage. `routines` maps every routine that\n * was merged away to the one that runs in its place.\n */\nexport interface SharedRoutines {\n\tcore: VerifiedCoreModule;\n\troutines: ReadonlyMap<string, string>;\n}\n\n/**\n * Merges free routines whose bodies differ only in the persistent storage they reach. Each place a\n * routine reaches through a fixed path into module storage starts at an anchor: the place without\n * its last field, or the whole place when it ends in a constant index or reaches the first index\n * that is computed at run time. Routines with the same anchored body, declaration and partition\n * share one routine that takes each anchor that differs between them as an `InOut` parameter;\n * each call site borrows its routine's anchors. A borrowed place is the caller's storage, read and\n * written where the original routine read and wrote it, so evaluation order and aliasing are\n * unchanged. Callees merge before their callers, whose calls then differ only in what they borrow.\n *\n * `partition` keeps routines apart that must stay apart, such as those of different tasks; a\n * routine it gives no partition is left as it is.\n */\nexport function shareRoutines(\n\tcore: VerifiedCoreModule,\n\tpartition: (routine: CoreFunction) => string | undefined,\n): SharedRoutines {\n\tconst types = new Map(core.types.map((type) => [type.id, type]));\n\tconst globals = new Map(core.variables.map((item) => [item.id, item]));\n\tconst entries = new Set(core.programs.map((program) => program.entry));\n\tconst bodies = new Map<string, readonly CoreStatement[]>(\n\t\t[...core.functions, ...core.blocks].map((routine) => [\n\t\t\troutine.id,\n\t\t\troutine.body,\n\t\t]),\n\t);\n\tconst merged = new Map<string, string>();\n\tconst shared = new Map<string, CoreFunction>();\n\n\t// A reference can only bind to plain data: a block instance or a stored reference stays where it is.\n\tconst plainData = (id: string, seen = new Set<string>()): boolean => {\n\t\tconst type = types.get(id);\n\t\tif (!type || seen.has(id)) {\n\t\t\treturn type !== undefined;\n\t\t}\n\t\tseen.add(id);\n\t\tif (type.kind === \"block\") {\n\t\t\treturn false;\n\t\t}\n\t\tif (type.kind === \"array\") {\n\t\t\treturn plainData(type.element, seen);\n\t\t}\n\t\tif (type.kind === \"record\") {\n\t\t\treturn type.fields.every(\n\t\t\t\t(field) => field.mode !== \"inOut\" && plainData(field.type, seen),\n\t\t\t);\n\t\t}\n\t\treturn true;\n\t};\n\tconst roots: Roots = {\n\t\tanchorable: (root) => {\n\t\t\tconst variable = globals.get(root);\n\t\t\treturn variable !== undefined && variable.storage !== \"constant\";\n\t\t},\n\t\ttype: (root) => globals.get(root)?.type,\n\t\tname: (root) => globals.get(root)?.name ?? \"anchor\",\n\t\tplainData: (type) => plainData(type),\n\t};\n\n\tconst candidates = core.functions.filter(\n\t\t(fn) => !fn.owner && !entries.has(fn.id),\n\t);\n\tfor (const level of callLevels(candidates, bodies)) {\n\t\tconst groups = new Map<string, Anchored[]>();\n\t\tfor (const fn of level) {\n\t\t\tconst group = partition(fn);\n\t\t\tif (group === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst anchored = anchor(\n\t\t\t\t{ ...fn, body: bodies.get(fn.id) ?? fn.body },\n\t\t\t\ttypes,\n\t\t\t\troots,\n\t\t\t);\n\t\t\tif (!anchored) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst key = `${group}\\n${anchored.key}`;\n\t\t\tgroups.set(key, [...(groups.get(key) ?? []), anchored]);\n\t\t}\n\t\tconst calls = new Map<string, MergedCall>();\n\t\tfor (const members of groups.values()) {\n\t\t\tconst [first] = members;\n\t\t\tif (!first || members.length < 2) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst varying: Varying = {\n\t\t\t\tanchors: first.anchors.map((slot, index) =>\n\t\t\t\t\tmembers.some((member) => member.anchors[index]?.key !== slot.key),\n\t\t\t\t),\n\t\t\t\tconstants: first.constants.map((constant, index) =>\n\t\t\t\t\tmembers.some(\n\t\t\t\t\t\t(member) =>\n\t\t\t\t\t\t\tJSON.stringify(member.constants[index]?.value) !==\n\t\t\t\t\t\t\tJSON.stringify(constant.value),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t};\n\t\t\tshared.set(first.fn.id, mergedRoutine(first, varying, roots, types));\n\t\t\tfor (const [index, member] of members.entries()) {\n\t\t\t\tif (index) {\n\t\t\t\t\tmerged.set(member.fn.id, first.fn.id);\n\t\t\t\t}\n\t\t\t\tcalls.set(member.fn.id, {\n\t\t\t\t\ttarget: first.fn.id,\n\t\t\t\t\tborrows: member.anchors.filter((_, slot) => varying.anchors[slot]),\n\t\t\t\t\tvalues: member.constants.filter((_, slot) => varying.constants[slot]),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tif (!calls.size) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const [id, body] of bodies) {\n\t\t\tbodies.set(id, rewriteCalls(body, calls));\n\t\t}\n\t}\n\tif (!merged.size) {\n\t\treturn { core, routines: merged };\n\t}\n\n\tconst functions = core.functions.flatMap((fn): CoreFunction[] => {\n\t\tif (merged.has(fn.id)) {\n\t\t\treturn [];\n\t\t}\n\t\tconst routine = shared.get(fn.id);\n\t\tif (routine) {\n\t\t\treturn [routine];\n\t\t}\n\t\treturn [{ ...fn, body: bodies.get(fn.id) ?? fn.body }];\n\t});\n\tconst blocks = core.blocks.map(\n\t\t(block): CoreFunctionBlock => ({\n\t\t\t...block,\n\t\t\tbody: bodies.get(block.id) ?? block.body,\n\t\t}),\n\t);\n\treturn {\n\t\tcore: admitCore({ ...core, functions, blocks }),\n\t\troutines: merged,\n\t};\n}\n\ninterface Roots {\n\t/** Whether a root is module storage, whose places a routine can borrow. */\n\tanchorable: (root: string) => boolean;\n\ttype: (root: string) => string | undefined;\n\tname: (root: string) => string;\n\t/** Whether a type holds only data, which a reference can bind to. */\n\tplainData: (type: string) => boolean;\n}\n\n/** A place a routine reaches in module storage, from the routine's own anchor. */\ninterface Borrow {\n\troot: string;\n\tpath: CorePath;\n\ttype: string;\n}\n\n/** A routine's body with its anchors numbered in the order it first reaches them. */\ninterface Anchored {\n\tfn: CoreFunction;\n\tkey: string;\n\tanchors: readonly (Borrow & { key: string })[];\n\t/** Each scalar constant the body evaluates, in order. */\n\tconstants: readonly Extract<CoreExpression, { kind: \"constant\" }>[];\n}\n\n/** Candidate routines, callees before their callers. A routine's level is one more than its deepest callee's. */\nfunction callLevels(\n\tcandidates: readonly CoreFunction[],\n\tbodies: ReadonlyMap<string, readonly CoreStatement[]>,\n): CoreFunction[][] {\n\tconst levels = new Map<string, number>();\n\tconst callees = (items: readonly CoreStatement[], found: Set<string>) => {\n\t\tfor (const item of items) {\n\t\t\tif (item.kind === \"invoke\") {\n\t\t\t\tfound.add(item.function);\n\t\t\t}\n\t\t\tfor (const body of nestedBodies(item)) {\n\t\t\t\tcallees(body, found);\n\t\t\t}\n\t\t}\n\t\treturn found;\n\t};\n\tconst level = (id: string, path: Set<string>): number => {\n\t\tconst known = levels.get(id);\n\t\tif (known !== undefined) {\n\t\t\treturn known;\n\t\t}\n\t\t// Verified routines do not recurse; a cycle would only stop merging, never recurse here.\n\t\tif (path.has(id)) {\n\t\t\treturn 0;\n\t\t}\n\t\tpath.add(id);\n\t\tconst deepest = [...callees(bodies.get(id) ?? [], new Set())].reduce(\n\t\t\t(depth, callee) => Math.max(depth, level(callee, path) + 1),\n\t\t\t0,\n\t\t);\n\t\tpath.delete(id);\n\t\tlevels.set(id, deepest);\n\t\treturn deepest;\n\t};\n\tconst ordered: CoreFunction[][] = [];\n\tfor (const fn of candidates) {\n\t\tconst depth = level(fn.id, new Set());\n\t\tordered[depth] = [...(ordered[depth] ?? []), fn];\n\t}\n\treturn ordered.filter((items) => items !== undefined);\n}\n\nconst staticIndex = (segment: CorePath[number]) =>\n\tsegment.kind === \"index\" &&\n\tsegment.value.kind === \"constant\" &&\n\tsegment.value.value.kind === \"integer\";\n\n/** The fixed part of a place that an anchor holds, by the rule `shareRoutines` describes. */\nfunction anchorLength(path: CorePath): number {\n\tconst dynamic = path.findIndex(\n\t\t(segment) => segment.kind === \"index\" && !staticIndex(segment),\n\t);\n\tif (dynamic >= 0) {\n\t\treturn dynamic;\n\t}\n\treturn path.at(-1)?.kind === \"field\" ? path.length - 1 : path.length;\n}\n\nconst pathType = (\n\troot: string,\n\tpath: CorePath,\n\ttypes: ReadonlyMap<string, PlcType>,\n): string | undefined =>\n\tpath.reduce<string | undefined>((id, segment) => {\n\t\tconst type = id === undefined ? undefined : types.get(id);\n\t\tif (segment.kind === \"field\" && type?.kind === \"record\") {\n\t\t\treturn type.fields.find((field) => field.name === segment.name)?.type;\n\t\t}\n\t\tif (segment.kind === \"index\" && type?.kind === \"array\") {\n\t\t\treturn type.element;\n\t\t}\n\t\treturn undefined;\n\t}, root);\n\nconst constantText = (segment: CorePath[number]) =>\n\tsegment.kind === \"field\"\n\t\t? `.${segment.name}`\n\t\t: `[${segment.value.kind === \"constant\" ? JSON.stringify(segment.value.value) : \"?\"}]`;\n\n/**\n * Numbers a routine's anchors and writes its body with each anchored place as its anchor's number\n * and the rest of its path, and its own variables by position. Two routines with the same key run\n * the same statements over their own anchors. Undefined when a place cannot be anchored the same\n * way in every routine, such as a loop counter in module storage.\n */\nfunction anchor(\n\tfn: CoreFunction,\n\ttypes: ReadonlyMap<string, PlcType>,\n\troots: Roots,\n): Anchored | undefined {\n\tconst own = new Map(\n\t\t[...fn.parameters, ...fn.locals].map((variable, index) => [\n\t\t\tvariable.id,\n\t\t\t`#${index}`,\n\t\t]),\n\t);\n\tconst anchors: (Borrow & { key: string })[] = [];\n\tconst constants: Extract<CoreExpression, { kind: \"constant\" }>[] = [];\n\tconst numbers = new Map<string, number>();\n\tconst rewrite: PlaceRewrite = {\n\t\tconstant: (value) => {\n\t\t\tif (!scalarConstant(value, types)) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\tconstants.push(value);\n\t\t\treturn {\n\t\t\t\tkind: \"load\",\n\t\t\t\ttype: value.type,\n\t\t\t\tspan: value.span,\n\t\t\t\troot: `$${constants.length - 1}`,\n\t\t\t};\n\t\t},\n\t\tplace: (root, path) => {\n\t\t\tif (!roots.anchorable(root)) {\n\t\t\t\treturn { root: own.get(root) ?? root, path: mapPath(path) };\n\t\t\t}\n\t\t\tconst { fixed, key } = anchorOf(root, path);\n\t\t\tconst rest = mapPath(path.slice(fixed.length));\n\t\t\tconst known = numbers.get(key);\n\t\t\tif (known !== undefined) {\n\t\t\t\treturn { root: `@${known}`, path: rest };\n\t\t\t}\n\t\t\tconst rootType = roots.type(root);\n\t\t\tconst type =\n\t\t\t\trootType === undefined ? undefined : pathType(rootType, fixed, types);\n\t\t\tif (type === undefined) {\n\t\t\t\tthrow new Unanchored();\n\t\t\t}\n\t\t\t// A block instance is not borrowed: its place stays as written, the same in every routine or none.\n\t\t\tif (!roots.plainData(type)) {\n\t\t\t\treturn { root, path: [...fixed, ...rest] };\n\t\t\t}\n\t\t\tnumbers.set(key, anchors.length);\n\t\t\tanchors.push({ root, path: fixed, type, key });\n\t\t\treturn { root: `@${anchors.length - 1}`, path: rest };\n\t\t},\n\t\tidentity: (root) => {\n\t\t\tif (roots.anchorable(root)) {\n\t\t\t\tthrow new Unanchored();\n\t\t\t}\n\t\t\treturn own.get(root) ?? root;\n\t\t},\n\t};\n\tconst mapPath = (path: CorePath): CorePath =>\n\t\tpath.map((segment) =>\n\t\t\tsegment.kind === \"field\"\n\t\t\t\t? segment\n\t\t\t\t: { kind: \"index\", value: rewriteExpression(segment.value, rewrite) },\n\t\t);\n\ttry {\n\t\tconst body = rewriteStatements(fn.body, rewrite);\n\t\t// Not the name: the elaborator numbers each instance's copy of a routine. The declaration\n\t\t// and the body say what it does.\n\t\tconst signature = {\n\t\t\tspan: fn.span,\n\t\t\tresult: fn.result,\n\t\t\tparameters: fn.parameters.map(({ id, ...rest }) => rest),\n\t\t\tlocals: fn.locals.map(({ id, ...rest }) => rest),\n\t\t\tanchors: anchors.map((item) => item.type),\n\t\t};\n\t\treturn { fn, key: JSON.stringify([signature, body]), anchors, constants };\n\t} catch (cause) {\n\t\tif (cause instanceof Unanchored) {\n\t\t\treturn undefined;\n\t\t}\n\t\tthrow cause;\n\t}\n}\n\n/** A place's anchor, and the key that identifies it. */\nconst anchorOf = (root: string, path: CorePath) => {\n\tconst fixed = path.slice(0, anchorLength(path));\n\treturn { fixed, key: `${root}${fixed.map(constantText).join(\"\")}` };\n};\n\n/**\n * The first routine of a group, taking each anchor that differs between the routines as an\n * `InOut` parameter after its own parameters, then each constant that differs as a value\n * parameter. Anchors and constants all of them share stay in place.\n */\nfunction mergedRoutine(\n\t{ fn, anchors, constants }: Anchored,\n\tvarying: Varying,\n\troots: Roots,\n\ttypes: ReadonlyMap<string, PlcType>,\n): CoreFunction {\n\tconst borrowed = new Map<number, Variable>();\n\tfor (const [index, slot] of anchors.entries()) {\n\t\tif (!varying.anchors[index]) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst field = [...slot.path]\n\t\t\t.reverse()\n\t\t\t.find((segment) => segment.kind === \"field\");\n\t\tborrowed.set(index, {\n\t\t\tid: `${fn.id}:anchor${index}`,\n\t\t\tname: field?.kind === \"field\" ? field.name : roots.name(slot.root),\n\t\t\ttype: slot.type,\n\t\t\tstorage: \"parameter\",\n\t\t\tmutable: true,\n\t\t\tretain: false,\n\t\t\tmode: \"inOut\",\n\t\t\tspan: fn.span,\n\t\t});\n\t}\n\tconst values = new Map<number, Variable>();\n\tfor (const [index, constant] of constants.entries()) {\n\t\tif (varying.constants[index]) {\n\t\t\tvalues.set(index, {\n\t\t\t\tid: `${fn.id}:value${index}`,\n\t\t\t\tname: \"value\",\n\t\t\t\ttype: constant.type,\n\t\t\t\tstorage: \"parameter\",\n\t\t\t\tmutable: false,\n\t\t\t\tretain: false,\n\t\t\t\tspan: fn.span,\n\t\t\t});\n\t\t}\n\t}\n\tconst slots = new Map(anchors.map((slot, index) => [slot.key, index]));\n\t// Scalar constants come in the order `anchor` numbered them in.\n\tconst order = constants.keys();\n\tconst rewrite: PlaceRewrite = {\n\t\tconstant: (value) => {\n\t\t\tif (!scalarConstant(value, types)) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\tconst parameter = values.get(order.next().value ?? -1);\n\t\t\treturn parameter\n\t\t\t\t? {\n\t\t\t\t\t\tkind: \"load\",\n\t\t\t\t\t\ttype: value.type,\n\t\t\t\t\t\tspan: value.span,\n\t\t\t\t\t\troot: parameter.id,\n\t\t\t\t\t}\n\t\t\t\t: value;\n\t\t},\n\t\tplace: (root, path) => {\n\t\t\tif (!roots.anchorable(root)) {\n\t\t\t\treturn { root, path: mapPath(path) };\n\t\t\t}\n\t\t\tconst { fixed, key } = anchorOf(root, path);\n\t\t\tconst rest = mapPath(path.slice(fixed.length));\n\t\t\tconst parameter = borrowed.get(slots.get(key) ?? -1);\n\t\t\treturn parameter\n\t\t\t\t? { root: parameter.id, path: rest }\n\t\t\t\t: { root, path: [...fixed, ...rest] };\n\t\t},\n\t\tidentity: (root) => root,\n\t};\n\tconst mapPath = (path: CorePath): CorePath =>\n\t\tpath.map((segment) =>\n\t\t\tsegment.kind === \"field\"\n\t\t\t\t? segment\n\t\t\t\t: { kind: \"index\", value: rewriteExpression(segment.value, rewrite) },\n\t\t);\n\treturn {\n\t\t...fn,\n\t\tparameters: [...fn.parameters, ...borrowed.values(), ...values.values()],\n\t\tbody: rewriteStatements(fn.body, rewrite),\n\t};\n}\n\n/** Which anchors and constants differ between the routines of a group, by number. */\ninterface Varying {\n\tanchors: readonly boolean[];\n\tconstants: readonly boolean[];\n}\n\n/** What a call to a merged routine adds after its own arguments. */\ninterface MergedCall {\n\ttarget: string;\n\tborrows: readonly Borrow[];\n\tvalues: readonly CoreExpression[];\n}\n\n/** Calls to merged routines go to the routine that runs in their place, borrowing their anchors. */\nfunction rewriteCalls(\n\titems: readonly CoreStatement[],\n\tcalls: ReadonlyMap<string, MergedCall>,\n): CoreStatement[] {\n\treturn items.map((item): CoreStatement => {\n\t\tif (item.kind === \"invoke\") {\n\t\t\tconst call = calls.get(item.function);\n\t\t\tif (!call) {\n\t\t\t\treturn item;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\tfunction: call.target,\n\t\t\t\targuments: [\n\t\t\t\t\t...item.arguments,\n\t\t\t\t\t...call.borrows.map(\n\t\t\t\t\t\t(borrow): CoreExpression => ({\n\t\t\t\t\t\t\tkind: \"borrow\",\n\t\t\t\t\t\t\ttype: borrow.type,\n\t\t\t\t\t\t\tspan: item.span,\n\t\t\t\t\t\t\tplace: { root: borrow.root, path: borrow.path },\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t\t...call.values,\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\t\tswitch (item.kind) {\n\t\t\tcase \"if\":\n\t\t\t\treturn {\n\t\t\t\t\t...item,\n\t\t\t\t\t// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n\t\t\t\t\tthen: rewriteCalls(item.then, calls),\n\t\t\t\t\telse: rewriteCalls(item.else, calls),\n\t\t\t\t};\n\t\t\tcase \"switch\":\n\t\t\t\treturn {\n\t\t\t\t\t...item,\n\t\t\t\t\tcases: item.cases.map((branch) => ({\n\t\t\t\t\t\t...branch,\n\t\t\t\t\t\tbody: rewriteCalls(branch.body, calls),\n\t\t\t\t\t})),\n\t\t\t\t\tfallback: rewriteCalls(item.fallback, calls),\n\t\t\t\t};\n\t\t\tcase \"for\":\n\t\t\t\treturn { ...item, body: rewriteCalls(item.body, calls) };\n\t\t\tdefault:\n\t\t\t\treturn item;\n\t\t}\n\t});\n}\n\nclass Unanchored extends Error {}\n\ninterface PlaceRewrite {\n\tplace: (root: string, path: CorePath) => { root: string; path: CorePath };\n\t/** A root a statement names without a path: a loop counter, call destination or block instance. */\n\tidentity: (root: string) => string;\n\t/** A scalar constant the body evaluates; case labels and loop bounds are not expressions. */\n\tconstant: (\n\t\tvalue: Extract<CoreExpression, { kind: \"constant\" }>,\n\t) => CoreExpression;\n}\n\n/** Constants a routine can take as a value parameter instead: scalars of an elementary or enum type. */\nconst scalarConstant = (\n\tvalue: Extract<CoreExpression, { kind: \"constant\" }>,\n\ttypes: ReadonlyMap<string, PlcType>,\n) =>\n\t[\"bool\", \"integer\", \"float\", \"duration\", \"calendar\"].includes(\n\t\tvalue.value.kind,\n\t) && types.get(value.type)?.kind !== \"string\";\n\nfunction rewriteExpression(\n\tvalue: CoreExpression,\n\trewrite: PlaceRewrite,\n): CoreExpression {\n\tswitch (value.kind) {\n\t\tcase \"constant\":\n\t\t\treturn rewrite.constant(value);\n\t\tcase \"load\": {\n\t\t\tconst place = rewrite.place(value.root, value.path ?? []);\n\t\t\treturn {\n\t\t\t\t...value,\n\t\t\t\troot: place.root,\n\t\t\t\t...(value.path || place.path.length ? { path: place.path } : {}),\n\t\t\t};\n\t\t}\n\t\tcase \"borrow\":\n\t\t\treturn {\n\t\t\t\t...value,\n\t\t\t\tplace: rewrite.place(value.place.root, value.place.path),\n\t\t\t};\n\t\tcase \"unary\":\n\t\tcase \"convert\":\n\t\t\treturn { ...value, operand: rewriteExpression(value.operand, rewrite) };\n\t\tcase \"binary\":\n\t\t\treturn {\n\t\t\t\t...value,\n\t\t\t\tleft: rewriteExpression(value.left, rewrite),\n\t\t\t\tright: rewriteExpression(value.right, rewrite),\n\t\t\t};\n\t}\n}\n\nfunction rewriteStatements(\n\titems: readonly CoreStatement[],\n\trewrite: PlaceRewrite,\n): CoreStatement[] {\n\tconst expression = (value: CoreExpression) =>\n\t\trewriteExpression(value, rewrite);\n\tconst statements = (body: readonly CoreStatement[]) =>\n\t\trewriteStatements(body, rewrite);\n\treturn items.map((item) =>\n\t\trewriteStatement(item, rewrite, expression, statements),\n\t);\n}\n\nfunction rewriteStatement(\n\titem: CoreStatement,\n\trewrite: PlaceRewrite,\n\texpression: (value: CoreExpression) => CoreExpression,\n\tstatements: (body: readonly CoreStatement[]) => CoreStatement[],\n): CoreStatement {\n\tswitch (item.kind) {\n\t\tcase \"assign\": {\n\t\t\tconst place = rewrite.place(item.root, item.path ?? []);\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\troot: place.root,\n\t\t\t\t...(item.path || place.path.length ? { path: place.path } : {}),\n\t\t\t\tvalue: expression(item.value),\n\t\t\t};\n\t\t}\n\t\tcase \"if\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\tcondition: expression(item.condition),\n\t\t\t\t// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n\t\t\t\tthen: statements(item.then),\n\t\t\t\telse: statements(item.else),\n\t\t\t};\n\t\tcase \"switch\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\tvalue: expression(item.value),\n\t\t\t\tcases: item.cases.map((branch) => ({\n\t\t\t\t\t...branch,\n\t\t\t\t\tbody: statements(branch.body),\n\t\t\t\t})),\n\t\t\t\tfallback: statements(item.fallback),\n\t\t\t};\n\t\tcase \"for\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\tcounter: rewrite.identity(item.counter),\n\t\t\t\t...(item.dynamic && {\n\t\t\t\t\tdynamic: {\n\t\t\t\t\t\t...item.dynamic,\n\t\t\t\t\t\tstart: expression(item.dynamic.start),\n\t\t\t\t\t\tlimit: expression(item.dynamic.limit),\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\tbody: statements(item.body),\n\t\t\t};\n\t\tcase \"invoke\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\t...(item.instance !== undefined && {\n\t\t\t\t\tinstance: rewrite.identity(item.instance),\n\t\t\t\t}),\n\t\t\t\t...(item.index && { index: expression(item.index) }),\n\t\t\t\targuments: item.arguments.map(expression),\n\t\t\t\t...(item.destination !== undefined && {\n\t\t\t\t\tdestination: rewrite.identity(item.destination),\n\t\t\t\t}),\n\t\t\t};\n\t\tcase \"blockUpdate\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\tinstance: rewrite.identity(item.instance),\n\t\t\t\t...(item.index && { index: expression(item.index) }),\n\t\t\t\tinputs: Object.fromEntries(\n\t\t\t\t\tObject.entries(item.inputs).map(([name, input]) => [\n\t\t\t\t\t\tname,\n\t\t\t\t\t\texpression(input),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t};\n\t\tcase \"return\":\n\t\t\treturn item.value ? { ...item, value: expression(item.value) } : item;\n\t\tcase \"telemetry\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\tproperties: item.properties.map((property) => ({\n\t\t\t\t\t...property,\n\t\t\t\t\tvalue: expression(property.value),\n\t\t\t\t\t...(property.length && { length: expression(property.length) }),\n\t\t\t\t})),\n\t\t\t\t...(item.record.kind === \"exception\" && {\n\t\t\t\t\trecord: { ...item.record, code: expression(item.record.code) },\n\t\t\t\t}),\n\t\t\t};\n\t\tcase \"break\":\n\t\tcase \"continue\":\n\t\t\treturn item;\n\t}\n}\n\nconst returns = (items: readonly CoreStatement[]): boolean =>\n\titems.some(\n\t\t(item) => item.kind === \"return\" || nestedBodies(item).some(returns),\n\t);\n\n/** A routine that only returns a constant, or does nothing: what each of its calls amounts to. */\nfunction constantResult(\n\tfn: CoreFunction,\n): { value?: CoreExpression } | undefined {\n\tconst [only, ...rest] = fn.body;\n\tif (rest.length || fn.owner) {\n\t\treturn undefined;\n\t}\n\tif (!only) {\n\t\treturn fn.result ? undefined : {};\n\t}\n\tif (only.kind !== \"return\") {\n\t\treturn undefined;\n\t}\n\tif (!only.value) {\n\t\treturn fn.result ? undefined : {};\n\t}\n\treturn only.value.kind === \"constant\" ? { value: only.value } : undefined;\n}\n\n/** The path a load or borrow reads through. */\nconst placePath = (value: CoreExpression): CorePath | undefined => {\n\tif (value.kind === \"load\") {\n\t\treturn value.path ?? [];\n\t}\n\treturn value.kind === \"borrow\" ? value.place.path : undefined;\n};\n\n/** Arguments that reading cannot fault: loads, borrows and constants, without arithmetic in their indexes. */\nconst plainArgument = (value: CoreExpression): boolean => {\n\tif (value.kind === \"constant\") {\n\t\treturn true;\n\t}\n\treturn (\n\t\tplacePath(value)?.every(\n\t\t\t(segment) => segment.kind === \"field\" || plainArgument(segment.value),\n\t\t) ?? false\n\t);\n};\n\n/**\n * Replaces each call of a routine that only returns a constant with an assignment of that\n * constant, and drops each call of one that does nothing. A call whose arguments compute\n * something stays, so evaluating them can still fault as it would have. Routines no call\n * reaches any more, other than program entries, are dropped.\n */\nexport function foldConstantRoutines(core: VerifiedCoreModule): {\n\tcore: VerifiedCoreModule;\n\troutines: ReadonlySet<string>;\n} {\n\tconst entries = new Set(core.programs.map((program) => program.entry));\n\tconst constants = new Map(\n\t\tcore.functions.flatMap((fn) => {\n\t\t\tconst result = entries.has(fn.id) ? undefined : constantResult(fn);\n\t\t\treturn result ? [[fn.id, result] as const] : [];\n\t\t}),\n\t);\n\tif (!constants.size) {\n\t\treturn { core, routines: new Set() };\n\t}\n\tconst called = new Set<string>();\n\tconst fold = (items: readonly CoreStatement[]): CoreStatement[] =>\n\t\titems.flatMap((item): CoreStatement[] => {\n\t\t\tif (item.kind === \"invoke\") {\n\t\t\t\tconst result = constants.get(item.function);\n\t\t\t\tif (!result || !item.arguments.every(plainArgument)) {\n\t\t\t\t\tcalled.add(item.function);\n\t\t\t\t\treturn [item];\n\t\t\t\t}\n\t\t\t\tif (item.destination === undefined || !result.value) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\t\tspan: item.span,\n\t\t\t\t\t\troot: item.destination,\n\t\t\t\t\t\tvalue: { ...result.value, span: item.span },\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\t\t\tswitch (item.kind) {\n\t\t\t\tcase \"if\":\n\t\t\t\t\treturn [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...item,\n\t\t\t\t\t\t\t// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n\t\t\t\t\t\t\tthen: fold(item.then),\n\t\t\t\t\t\t\telse: fold(item.else),\n\t\t\t\t\t\t},\n\t\t\t\t\t];\n\t\t\t\tcase \"switch\":\n\t\t\t\t\treturn [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...item,\n\t\t\t\t\t\t\tcases: item.cases.map((branch) => ({\n\t\t\t\t\t\t\t\t...branch,\n\t\t\t\t\t\t\t\tbody: fold(branch.body),\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\tfallback: fold(item.fallback),\n\t\t\t\t\t\t},\n\t\t\t\t\t];\n\t\t\t\tcase \"for\":\n\t\t\t\t\treturn [{ ...item, body: fold(item.body) }];\n\t\t\t\tdefault:\n\t\t\t\t\treturn [item];\n\t\t\t}\n\t\t});\n\tconst functions = core.functions.map((fn) => ({\n\t\t...fn,\n\t\tbody: fold(fn.body),\n\t}));\n\tconst blocks = core.blocks.map(\n\t\t(block): CoreFunctionBlock => ({ ...block, body: fold(block.body) }),\n\t);\n\tconst routines = new Set(\n\t\t[...constants.keys()].filter((id) => !called.has(id)),\n\t);\n\treturn {\n\t\tcore: admitCore({\n\t\t\t...core,\n\t\t\tfunctions: functions.filter((fn) => !routines.has(fn.id)),\n\t\t\tblocks,\n\t\t}),\n\t\troutines,\n\t};\n}\n",
27
- "import {\n\ttype CoreExpression,\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CorePath,\n\ttype CoreStatement,\n\tnestedBodies,\n\ttype VerifiedCoreModule,\n} from \"./core-model\";\nimport { admitCore } from \"./normalize\";\nimport { statementExpressions, subexpressions } from \"./operands\";\nimport { isTemporary } from \"./routine\";\n\n/**\n * Writes a temporary's value where it is read, when nothing can happen in between: the temporary\n * is assigned once, as a whole, and read once, by the statement right after the assignment, in\n * an expression that statement evaluates before it writes or calls anything. Loop bounds and\n * switch values are left alone: ST evaluates them more than once.\n *\n * Only a load, a constant or a BOOL moves. An arithmetic value keeps its temporary, which\n * stores it at its own type: written into a wider expression, ST could compute it wider.\n */\nexport function forwardTemporaries(\n\tcore: VerifiedCoreModule,\n): VerifiedCoreModule {\n\tconst functions = core.functions.map((fn): CoreFunction => forward(fn));\n\tconst blocks = core.blocks.map((block): CoreFunctionBlock => forward(block));\n\treturn admitCore({ ...core, functions, blocks });\n}\n\nfunction forward<Routine extends CoreFunction | CoreFunctionBlock>(\n\troutine: Routine,\n): Routine {\n\tconst temporaries = new Set(\n\t\troutine.locals\n\t\t\t.filter((local) => isTemporary(routine.id, local))\n\t\t\t.map((local) => local.id),\n\t);\n\tif (!temporaries.size) {\n\t\treturn routine;\n\t}\n\tconst writes = new Map<string, number>();\n\tconst reads = new Map<string, number>();\n\tconst count = (counts: Map<string, number>, root: string) =>\n\t\tcounts.set(root, (counts.get(root) ?? 0) + 1);\n\tconst expression = (value: CoreExpression): void => {\n\t\tif (value.kind === \"load\") {\n\t\t\tcount(reads, value.root);\n\t\t}\n\t\tif (value.kind === \"borrow\") {\n\t\t\t// A borrowed temporary is written through its reference.\n\t\t\tcount(writes, value.place.root);\n\t\t\tcount(reads, value.place.root);\n\t\t}\n\t\tsubexpressions(value).forEach(expression);\n\t};\n\tconst statements = (items: readonly CoreStatement[]): void => {\n\t\tfor (const item of items) {\n\t\t\tif (item.kind === \"assign\") {\n\t\t\t\tcount(writes, item.root);\n\t\t\t}\n\t\t\tif (item.kind === \"for\") {\n\t\t\t\tcount(writes, item.counter);\n\t\t\t}\n\t\t\tif (item.kind === \"invoke\" && item.destination !== undefined) {\n\t\t\t\tcount(writes, item.destination);\n\t\t\t}\n\t\t\tstatementExpressions(item).forEach(expression);\n\t\t\tnestedBodies(item).forEach(statements);\n\t\t}\n\t};\n\tstatements(routine.body);\n\tconst movable = (\n\t\titem: CoreStatement,\n\t): item is Extract<CoreStatement, { kind: \"assign\" }> =>\n\t\titem.kind === \"assign\" &&\n\t\t!item.path?.length &&\n\t\ttemporaries.has(item.root) &&\n\t\twrites.get(item.root) === 1 &&\n\t\treads.get(item.root) === 1 &&\n\t\t(item.value.kind === \"load\" ||\n\t\t\titem.value.kind === \"constant\" ||\n\t\t\titem.value.type === \"BOOL\");\n\n\tconst forwarded = new Set<string>();\n\tconst rewrite = (items: readonly CoreStatement[]): CoreStatement[] => {\n\t\tconst result = items.map((item) => withBodies(item, rewrite));\n\t\t// From the end, so a value can move through a chain of temporaries.\n\t\tfor (let index = result.length - 2; index >= 0; index--) {\n\t\t\tconst item = result[index];\n\t\t\tconst next = result[index + 1];\n\t\t\tif (!item || !next || !movable(item) || !readsOwn(next, item.root)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tresult.splice(index, 2, substitute(next, item.root, item.value));\n\t\t\tforwarded.add(item.root);\n\t\t}\n\t\treturn result;\n\t};\n\tconst body = rewrite(routine.body);\n\tif (!forwarded.size) {\n\t\treturn routine;\n\t}\n\treturn {\n\t\t...routine,\n\t\tlocals: routine.locals.filter((local) => !forwarded.has(local.id)),\n\t\tbody,\n\t};\n}\n\n/** Whether a statement reads `root` in what it evaluates once, before it writes or calls. */\nfunction readsOwn(item: CoreStatement, root: string): boolean {\n\tif (item.kind === \"for\" || item.kind === \"switch\") {\n\t\treturn false;\n\t}\n\tconst reads = (value: CoreExpression): boolean =>\n\t\t(value.kind === \"load\" && value.root === root) ||\n\t\tsubexpressions(value).some(reads);\n\treturn statementExpressions(item).some(reads);\n}\n\n/** A statement with each nested body rewritten. */\nfunction withBodies(\n\titem: CoreStatement,\n\trewrite: (items: readonly CoreStatement[]) => CoreStatement[],\n): CoreStatement {\n\tswitch (item.kind) {\n\t\tcase \"if\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\t// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n\t\t\t\tthen: rewrite(item.then),\n\t\t\t\telse: rewrite(item.else),\n\t\t\t};\n\t\tcase \"switch\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\tcases: item.cases.map((branch) => ({\n\t\t\t\t\t...branch,\n\t\t\t\t\tbody: rewrite(branch.body),\n\t\t\t\t})),\n\t\t\t\tfallback: rewrite(item.fallback),\n\t\t\t};\n\t\tcase \"for\":\n\t\t\treturn { ...item, body: rewrite(item.body) };\n\t\tdefault:\n\t\t\treturn item;\n\t}\n}\n\n/** A statement with its read of `root` replaced by `value`. */\nfunction substitute(\n\titem: CoreStatement,\n\troot: string,\n\tvalue: CoreExpression,\n): CoreStatement {\n\tconst replace = (expression: CoreExpression): CoreExpression => {\n\t\tif (expression.kind === \"load\" && expression.root === root) {\n\t\t\treturn value;\n\t\t}\n\t\tswitch (expression.kind) {\n\t\t\tcase \"constant\":\n\t\t\t\treturn expression;\n\t\t\tcase \"load\":\n\t\t\t\treturn expression.path\n\t\t\t\t\t? { ...expression, path: replacePath(expression.path) }\n\t\t\t\t\t: expression;\n\t\t\tcase \"borrow\":\n\t\t\t\treturn {\n\t\t\t\t\t...expression,\n\t\t\t\t\tplace: {\n\t\t\t\t\t\t...expression.place,\n\t\t\t\t\t\tpath: replacePath(expression.place.path),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\tcase \"unary\":\n\t\t\tcase \"convert\":\n\t\t\t\treturn { ...expression, operand: replace(expression.operand) };\n\t\t\tcase \"binary\":\n\t\t\t\treturn {\n\t\t\t\t\t...expression,\n\t\t\t\t\tleft: replace(expression.left),\n\t\t\t\t\tright: replace(expression.right),\n\t\t\t\t};\n\t\t}\n\t};\n\tconst replacePath = (path: CorePath): CorePath =>\n\t\tpath.map((segment) =>\n\t\t\tsegment.kind === \"field\"\n\t\t\t\t? segment\n\t\t\t\t: { kind: \"index\", value: replace(segment.value) },\n\t\t);\n\tswitch (item.kind) {\n\t\tcase \"assign\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\t...(item.path && { path: replacePath(item.path) }),\n\t\t\t\tvalue: replace(item.value),\n\t\t\t};\n\t\tcase \"if\":\n\t\t\treturn { ...item, condition: replace(item.condition) };\n\t\tcase \"invoke\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\t...(item.index && { index: replace(item.index) }),\n\t\t\t\targuments: item.arguments.map(replace),\n\t\t\t};\n\t\tcase \"blockUpdate\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\t...(item.index && { index: replace(item.index) }),\n\t\t\t\tinputs: Object.fromEntries(\n\t\t\t\t\tObject.entries(item.inputs).map(([name, input]) => [\n\t\t\t\t\t\tname,\n\t\t\t\t\t\treplace(input),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t};\n\t\tcase \"return\":\n\t\t\treturn item.value ? { ...item, value: replace(item.value) } : item;\n\t\tcase \"telemetry\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\t...(item.record.kind === \"exception\" && {\n\t\t\t\t\trecord: { ...item.record, code: replace(item.record.code) },\n\t\t\t\t}),\n\t\t\t\tproperties: item.properties.map((property) => ({\n\t\t\t\t\t...property,\n\t\t\t\t\tvalue: replace(property.value),\n\t\t\t\t\t...(property.length && { length: replace(property.length) }),\n\t\t\t\t})),\n\t\t\t};\n\t\tdefault:\n\t\t\treturn item;\n\t}\n}\n"
23
+ "import type { ModuleDeclarations } from \"./declarations\";\nimport {\n\tmaxNestingDepth,\n\tmaxScalarElements,\n\tmaxScalarElementsText,\n} from \"./layouts\";\nimport type { PlcModule } from \"./model\";\nimport { reject } from \"./normalization-error\";\nimport { lookup } from \"./tables\";\nimport { instancedBlock } from \"./types\";\n\ninterface Allocation {\n\tsize: number;\n\theight: number;\n}\n\nexport function checkStaticAllocation(\n\tmodule: PlcModule,\n\tdeclarations: ModuleDeclarations,\n): void {\n\tconst { types, blocks, layoutSizes } = declarations;\n\n\t// Static allocation is a separate graph from scan calls: even an unused child\n\t// consumes memory, and a recursive child cannot be allocated by value.\n\tconst payload = (id: string): number => lookup(layoutSizes, id, \"layout\");\n\n\tconst instance = (id: string): Allocation => {\n\t\tconst instanced = instancedBlock(id, types);\n\t\tif (!instanced) {\n\t\t\tthrow new Error(`Type ${id} instantiates no block.`);\n\t\t}\n\t\tconst block = allocation(instanced.block);\n\t\tconst type = lookup(types, id, \"type\");\n\t\treturn type.kind === \"array\"\n\t\t\t? { size: type.length * block.size, height: block.height }\n\t\t\t: block;\n\t};\n\tconst allocations = new Map<string, Allocation>();\n\tconst allocating = new Set<string>();\n\tconst allocation = (id: string): Allocation => {\n\t\tif (allocating.size >= maxNestingDepth) {\n\t\t\treject(\n\t\t\t\t`Static block allocation nesting exceeds ${maxNestingDepth} levels.`,\n\t\t\t\tblocks.get(id)?.span,\n\t\t\t);\n\t\t}\n\t\tif (allocating.has(id)) {\n\t\t\treject(\"Recursive static block allocation.\", blocks.get(id)?.span);\n\t\t}\n\t\tconst cached = allocations.get(id);\n\t\tif (cached) {\n\t\t\treturn cached;\n\t\t}\n\t\tallocating.add(id);\n\t\tconst block = lookup(blocks, id, \"block\");\n\t\tconst children = block.state\n\t\t\t.filter((item) => item.storage === \"instance\")\n\t\t\t.map((item) => instance(item.type));\n\t\tconst own = [\n\t\t\t...block.inputs,\n\t\t\t...block.outputs,\n\t\t\t...block.state.filter((item) => item.storage !== \"instance\"),\n\t\t].reduce(\n\t\t\t(sum, item) => sum + (item.mode === \"inOut\" ? 1 : payload(item.type)),\n\t\t\t1,\n\t\t);\n\t\tconst size = own + children.reduce((sum, child) => sum + child.size, 0);\n\t\tconst height = children.length\n\t\t\t? 1 + Math.max(...children.map((child) => child.height))\n\t\t\t: 1;\n\t\tif (size > maxScalarElements || height > maxNestingDepth) {\n\t\t\treject(\"Static block allocation exceeds its finite budget.\", block.span);\n\t\t}\n\t\tallocating.delete(id);\n\t\tconst result = { size, height };\n\t\tallocations.set(id, result);\n\t\treturn result;\n\t};\n\n\tfor (const block of module.blocks) {\n\t\tallocation(block.id);\n\t}\n\tconst staticPayload = module.variables.reduce((sum, variable) => {\n\t\treturn (\n\t\t\tsum +\n\t\t\t(instancedBlock(variable.type, types)\n\t\t\t\t? instance(variable.type).size\n\t\t\t\t: payload(variable.type))\n\t\t);\n\t}, 0);\n\tif (staticPayload > maxScalarElements) {\n\t\treject(\n\t\t\t`Static module storage exceeds ${maxScalarElementsText} scalar elements.`,\n\t\t);\n\t}\n}\n",
24
+ "import { valueFits } from \"./aggregates\";\nimport type { SourceSpan } from \"./diagnostics\";\nimport { admitLayouts } from \"./layouts\";\nimport {\n\ttype FunctionBlock,\n\ttype PlcFunction,\n\ttype PlcModule,\n\ttype StandardBlock,\n\tstandardBlocks,\n\ttype Variable,\n} from \"./model\";\nimport { reject } from \"./normalization-error\";\nimport { instancedBlock, isValueType, type PlcType } from \"./types\";\n\nconst matchesPorts = (\n\tvariables: readonly Variable[],\n\tschema: readonly (readonly [string, string, string])[],\n): boolean =>\n\tvariables.length === schema.length &&\n\tschema.every(([name, , type]) =>\n\t\tvariables.some(\n\t\t\t(variable) =>\n\t\t\t\tvariable.name === name &&\n\t\t\t\tvariable.type === type &&\n\t\t\t\t!variable.mode &&\n\t\t\t\tvariable.retention === \"none\",\n\t\t),\n\t);\n\n/** A standard block is exactly its vendor table entry: no body or state, and outputs at their defaults. */\nconst checkStandardBlock = (\n\tblock: FunctionBlock,\n\tstandard: StandardBlock,\n): void => {\n\tconst expected = standardBlocks[standard];\n\tif (\n\t\tblock.name !== standard ||\n\t\tblock.body.length ||\n\t\tblock.state.length ||\n\t\tblock.locals.length ||\n\t\t!matchesPorts(block.inputs, expected.inputs) ||\n\t\t!matchesPorts(block.outputs, expected.outputs) ||\n\t\tblock.outputs.some(({ initial }) => {\n\t\t\tswitch (initial?.kind) {\n\t\t\t\tcase \"bool\":\n\t\t\t\t\treturn initial.value !== false;\n\t\t\t\tcase \"duration\":\n\t\t\t\t\treturn initial.nanoseconds !== \"0\";\n\t\t\t\tcase \"integer\":\n\t\t\t\t\treturn initial.value !== \"0\";\n\t\t\t\tdefault:\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t})\n\t) {\n\t\treject(\"Invalid canonical standard block definition.\", block.span);\n\t}\n};\n\n// This index owns the module namespace and storage declarations. Routine\n// lowering may claim temporary identifiers, but cannot weaken admission rules.\nexport class ModuleDeclarations {\n\tprivate readonly ids = new Set<string>();\n\treadonly types = new Map<string, PlcType>();\n\t/** Each type's by-value size in scalar elements. */\n\treadonly layoutSizes: ReadonlyMap<string, number>;\n\treadonly globals = new Map<string, Variable>();\n\treadonly blocks: Map<string, FunctionBlock>;\n\treadonly signatures: Map<string, PlcFunction>;\n\n\tconstructor(module: PlcModule) {\n\t\tfor (const type of module.types) {\n\t\t\tif (this.types.has(type.id)) {\n\t\t\t\treject(`Duplicate type ${type.id}.`);\n\t\t\t}\n\t\t\tthis.types.set(type.id, type);\n\t\t}\n\t\tthis.layoutSizes = admitLayouts(this.types);\n\t\tif (this.types.get(\"BOOL\")?.kind !== \"bool\") {\n\t\t\treject(\"Missing canonical BOOL type.\");\n\t\t}\n\n\t\tthis.blocks = new Map(module.blocks.map((block) => [block.id, block]));\n\t\tfor (const item of module.variables) {\n\t\t\tthis.checkVariable(item, [\n\t\t\t\t\"module\",\n\t\t\t\t\"instance\",\n\t\t\t\t\"input\",\n\t\t\t\t\"output\",\n\t\t\t\t\"constant\",\n\t\t\t]);\n\t\t\tthis.globals.set(item.id, item);\n\t\t}\n\n\t\tthis.signatures = new Map(module.functions.map((fn) => [fn.id, fn]));\n\t\tfor (const fn of module.functions) {\n\t\t\tthis.claimId(fn.id, fn.span);\n\t\t\tif (\n\t\t\t\tfn.owner &&\n\t\t\t\t(!this.blocks.has(fn.owner.block) ||\n\t\t\t\t\tthis.blocks.get(fn.owner.block)?.standard)\n\t\t\t) {\n\t\t\t\treject(\n\t\t\t\t\t\"Methods require a user block owner and a valid access modifier.\",\n\t\t\t\t\tfn.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (fn.result && !isValueType(fn.result, this.types)) {\n\t\t\t\treject(\"Unknown or non-value function result type.\", fn.span);\n\t\t\t}\n\t\t\tfor (const parameter of fn.parameters) {\n\t\t\t\tthis.checkVariable(parameter, [\"parameter\"], { allowBorrow: true });\n\t\t\t\tif (parameter.mutable && !parameter.mode) {\n\t\t\t\t\treject(\"Value parameters are readonly.\", parameter.span);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const local of fn.locals) {\n\t\t\t\tthis.checkVariable(local, [\"local\"]);\n\t\t\t}\n\t\t}\n\n\t\tfor (const block of module.blocks) {\n\t\t\tthis.claimId(block.id, block.span);\n\t\t\tfor (const input of block.inputs) {\n\t\t\t\tthis.checkVariable(input, [\"parameter\"], { allowBorrow: true });\n\t\t\t\tif (!input.mode && input.mutable) {\n\t\t\t\t\treject(\"Value block inputs are readonly.\", input.span);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const output of block.outputs) {\n\t\t\t\tthis.checkVariable(output, [\"blockOutput\"]);\n\t\t\t}\n\t\t\tfor (const state of block.state) {\n\t\t\t\tthis.checkVariable(state, [\"field\", \"instance\"]);\n\t\t\t\t// A controller has one persistent list, and it holds globals: an instance's state is the instance's to persist.\n\t\t\t\tif (state.retention === \"persist\") {\n\t\t\t\t\treject(\n\t\t\t\t\t\t\"Only module state may persist; persist the module binding that holds the instance.\",\n\t\t\t\t\t\tstate.span,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const local of block.locals) {\n\t\t\t\tthis.checkVariable(local, [\"local\"]);\n\t\t\t}\n\t\t\tfor (const ports of [block.inputs, block.outputs]) {\n\t\t\t\tif (\n\t\t\t\t\tnew Set(ports.map((variable) => variable.name)).size !== ports.length\n\t\t\t\t) {\n\t\t\t\t\treject(\n\t\t\t\t\t\t\"Block input and output names must each be unique within their schema.\",\n\t\t\t\t\t\tblock.span,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst result = block.result ? this.types.get(block.result) : undefined;\n\t\t\tif (\n\t\t\t\tblock.outputs.length\n\t\t\t\t\t? result?.kind !== \"record\" ||\n\t\t\t\t\t\t!isValueType(result.id, this.types) ||\n\t\t\t\t\t\tresult.fields.length !== block.outputs.length ||\n\t\t\t\t\t\tresult.fields.some(\n\t\t\t\t\t\t\t(field) =>\n\t\t\t\t\t\t\t\t!block.outputs.some(\n\t\t\t\t\t\t\t\t\t(output) =>\n\t\t\t\t\t\t\t\t\t\toutput.name === field.name && output.type === field.type,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t: Boolean(block.result)\n\t\t\t) {\n\t\t\t\treject(\n\t\t\t\t\t\"Block output schema differs from its result record.\",\n\t\t\t\t\tblock.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (block.standard) {\n\t\t\t\tcheckStandardBlock(block, block.standard);\n\t\t\t}\n\t\t}\n\n\t\tfor (const type of this.types.values()) {\n\t\t\tif (type.kind === \"block\") {\n\t\t\t\tconst definition = this.blocks.get(type.block);\n\t\t\t\tif (!definition || definition.result !== type.output) {\n\t\t\t\t\treject(\"Block type differs from its definition.\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\thasId(id: string): boolean {\n\t\treturn this.ids.has(id);\n\t}\n\n\tpublic claimId(id: string, span?: SourceSpan): void {\n\t\tif (this.ids.has(id)) {\n\t\t\treject(`Duplicate symbol ${id}.`, span);\n\t\t}\n\t\tthis.ids.add(id);\n\t}\n\n\tprivate checkVariable(\n\t\titem: Variable,\n\t\tstorage: readonly Variable[\"storage\"][],\n\t\t{ allowBorrow }: { allowBorrow?: true } = {},\n\t): void {\n\t\tthis.claimId(item.id, item.span);\n\t\tconst type = this.types.get(item.type);\n\t\tif (!type || !storage.includes(item.storage)) {\n\t\t\treject(\"Invalid storage type or class.\", item.span);\n\t\t}\n\t\tif (\n\t\t\titem.mode &&\n\t\t\t(item.mode !== \"inOut\" ||\n\t\t\t\t!allowBorrow ||\n\t\t\t\t!item.mutable ||\n\t\t\t\titem.storage !== \"parameter\")\n\t\t) {\n\t\t\treject(\"InOut belongs only on mutable parameters.\", item.span);\n\t\t}\n\t\tconst mutableState =\n\t\t\titem.mutable ||\n\t\t\ttype.kind === \"array\" ||\n\t\t\t(type.kind === \"record\" && type.fields.some((field) => !field.readonly));\n\t\tif (\n\t\t\titem.retention !== \"none\" &&\n\t\t\t!(\n\t\t\t\titem.storage === \"instance\" ||\n\t\t\t\t([\"module\", \"field\"].includes(item.storage) && mutableState)\n\t\t\t)\n\t\t) {\n\t\t\treject(\n\t\t\t\t\"Only mutable static state or block instances may retain.\",\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\tif (item.storage === \"instance\") {\n\t\t\tconst instanced = instancedBlock(item.type, this.types);\n\t\t\tif (\n\t\t\t\t!instanced ||\n\t\t\t\t!this.blocks.has(instanced.block) ||\n\t\t\t\titem.initial ||\n\t\t\t\titem.mode\n\t\t\t) {\n\t\t\t\treject(\n\t\t\t\t\t\"Instances require a known static block and cannot have value initializers.\",\n\t\t\t\t\titem.span,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (\n\t\t\t!isValueType(item.type, this.types) &&\n\t\t\t!(allowBorrow && item.mode === \"inOut\" && type.kind === \"block\")\n\t\t) {\n\t\t\treject(\n\t\t\t\t\"Block instances and reference schemas cannot be stored as values.\",\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\tif (item.storage === \"parameter\" && item.initial) {\n\t\t\treject(\n\t\t\t\t\"Inputs are supplied at each invocation and cannot have stored initializers.\",\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\tif (item.initial && !valueFits(item.initial, type, this.types)) {\n\t\t\treject(\"Initializer has the wrong type or is out of range.\", item.span);\n\t\t}\n\t\tif (\n\t\t\t[\"module\", \"field\", \"constant\", \"blockOutput\"].includes(item.storage) &&\n\t\t\t!item.initial\n\t\t) {\n\t\t\treject(\"Persistent storage requires initialization.\", item.span);\n\t\t}\n\t\tif (\n\t\t\t[\"input\", \"constant\", \"blockOutput\"].includes(item.storage) &&\n\t\t\titem.mutable\n\t\t) {\n\t\t\treject(\"Readonly storage marked mutable.\", item.span);\n\t\t}\n\t}\n}\n",
25
+ "import {\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CoreStatement,\n\tcalledRoutine,\n\tdirectWrites,\n\tnestedBodies,\n\troutineVariables,\n} from \"./core-model\";\nimport type { ModuleDeclarations } from \"./declarations\";\nimport { type PlcModule, telemetryOperands } from \"./model\";\nimport { reject } from \"./normalization-error\";\nimport { lookup } from \"./tables\";\nimport { instancedBlock, type PlcType } from \"./types\";\n\ntype Edges = ReadonlyMap<string, ReadonlySet<string>>;\ntype Routine = CoreFunction | CoreFunctionBlock;\n\n// Static instances keep their child layouts even when a child has no scan call.\nexport function linkModule(\n\tmodule: PlcModule,\n\tdeclarations: ModuleDeclarations,\n\tfunctions: CoreFunction[],\n\tnormalizedBlocks: CoreFunctionBlock[],\n\tedges: Edges,\n) {\n\tconst entries = checkPrograms(module, declarations);\n\tconst routines = new Map<string, Routine>(\n\t\t[...functions, ...normalizedBlocks].map((fn) => [fn.id, fn]),\n\t);\n\tcheckRecursion(routines, edges, entries, declarations);\n\tcheckLoopCounterWrites(module, declarations, routines, edges);\n\n\tconst reachable = reachableRoutines(\n\t\tmodule,\n\t\tdeclarations,\n\t\tfunctions,\n\t\tentries,\n\t\tedges,\n\t);\n\tconst linkedFunctions = functions.filter((fn) => reachable.has(fn.id));\n\tconst linkedBlocks = normalizedBlocks.filter((block) =>\n\t\treachable.has(block.id),\n\t);\n\tconst usedTypes = usedTypeIds(\n\t\tmodule,\n\t\tdeclarations.types,\n\t\tlinkedFunctions,\n\t\tlinkedBlocks,\n\t);\n\treturn {\n\t\ttypes: module.types.filter((type) => usedTypes.has(type.id)),\n\t\tvariables: module.variables,\n\t\tfunctions: linkedFunctions,\n\t\tblocks: linkedBlocks,\n\t\tprograms: module.programs,\n\t\t...(module.folded && { folded: module.folded }),\n\t\t...(module.references && { references: module.references }),\n\t};\n}\n\n/** Checks each program's entry and name, and returns the entry routines. */\nconst checkPrograms = (\n\tmodule: PlcModule,\n\tdeclarations: ModuleDeclarations,\n): ReadonlySet<string> => {\n\tconst names = new Set<string>();\n\tconst entries = new Set<string>();\n\tfor (const program of module.programs) {\n\t\tdeclarations.claimId(program.id);\n\t\tconst entry = declarations.signatures.get(program.entry);\n\t\tif (!entry || entry.owner || entry.parameters.length || entry.result) {\n\t\t\treject(\"Program entry must be a parameterless void helper.\");\n\t\t}\n\t\tif (names.has(program.name)) {\n\t\t\treject(`Duplicate program ${program.name}.`);\n\t\t}\n\t\tnames.add(program.name);\n\t\tentries.add(program.entry);\n\t}\n\tif (!module.programs.length) {\n\t\treject(\"At least one program is required.\");\n\t}\n\treturn entries;\n};\n\n// Authored execution cycles are invalid even in unreachable routines. Static\n// allocation has its own cycle check because it does not depend on scan calls.\nconst checkRecursion = (\n\troutines: ReadonlyMap<string, Routine>,\n\tedges: Edges,\n\tentries: ReadonlySet<string>,\n\t{ signatures }: ModuleDeclarations,\n): void => {\n\tconst visited = new Set<string>();\n\tconst active = new Set<string>();\n\tconst visit = (id: string): void => {\n\t\tif (active.has(id)) {\n\t\t\treject(\"Recursive scan calls are prohibited.\", signatures.get(id)?.span);\n\t\t}\n\t\tif (visited.has(id)) {\n\t\t\treturn;\n\t\t}\n\t\tactive.add(id);\n\t\tfor (const child of edges.get(id) ?? []) {\n\t\t\tif (entries.has(child)) {\n\t\t\t\treject(\n\t\t\t\t\t\"Program entries cannot be called as ordinary helpers.\",\n\t\t\t\t\tsignatures.get(id)?.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\tvisit(child);\n\t\t}\n\t\tactive.delete(id);\n\t\tvisited.add(id);\n\t};\n\tfor (const id of routines.keys()) {\n\t\tvisit(id);\n\t}\n};\n\n// A bounded loop can only reconstruct its counter if called helpers leave\n// that storage alone. Include transitive calls, not just direct assignments.\nconst checkLoopCounterWrites = (\n\tmodule: PlcModule,\n\t{ types }: ModuleDeclarations,\n\troutines: ReadonlyMap<string, Routine>,\n\tedges: Edges,\n): void => {\n\tconst variables = new Map(\n\t\t[\n\t\t\t...module.variables,\n\t\t\t...[...routines.values()].flatMap(routineVariables),\n\t\t].map((variable) => [variable.id, variable]),\n\t);\n\tconst writes = new Map<string, Set<string>>();\n\tconst routineWrites = (id: string): Set<string> => {\n\t\tconst cached = writes.get(id);\n\t\tif (cached) {\n\t\t\treturn cached;\n\t\t}\n\t\tconst result = new Set<string>();\n\t\tconst inspect = (body: readonly CoreStatement[]) => {\n\t\t\tfor (const item of body) {\n\t\t\t\tfor (const root of directWrites(item)) {\n\t\t\t\t\tresult.add(root);\n\t\t\t\t}\n\t\t\t\tfor (const nested of nestedBodies(item)) {\n\t\t\t\t\tinspect(nested);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tinspect(lookup(routines, id, \"routine\").body);\n\t\tfor (const child of edges.get(id) ?? []) {\n\t\t\tfor (const root of routineWrites(child)) {\n\t\t\t\tresult.add(root);\n\t\t\t}\n\t\t}\n\t\twrites.set(id, result);\n\t\treturn result;\n\t};\n\tconst checkCalls = (\n\t\tbody: readonly CoreStatement[],\n\t\tcounters: ReadonlySet<string>,\n\t) => {\n\t\tfor (const item of body) {\n\t\t\tconst called = calledRoutine(item, (id) => variables.get(id), types);\n\t\t\tif (\n\t\t\t\tcalled &&\n\t\t\t\t[...counters].some((counter) => routineWrites(called).has(counter))\n\t\t\t) {\n\t\t\t\treject(\n\t\t\t\t\t\"A called routine may mutate an active loop counter.\",\n\t\t\t\t\titem.span,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst nestedCounters =\n\t\t\t\titem.kind === \"for\" ? new Set([...counters, item.counter]) : counters;\n\t\t\tfor (const nested of nestedBodies(item)) {\n\t\t\t\tcheckCalls(nested, nestedCounters);\n\t\t\t}\n\t\t}\n\t};\n\tfor (const routine of routines.values()) {\n\t\tcheckCalls(routine.body, new Set());\n\t}\n};\n\nconst reachableRoutines = (\n\tmodule: PlcModule,\n\t{ signatures, blocks, types }: ModuleDeclarations,\n\tfunctions: readonly CoreFunction[],\n\tentries: ReadonlySet<string>,\n\tedges: Edges,\n): ReadonlySet<string> => {\n\tconst reachable = new Set<string>();\n\tconst link = (id: string): void => {\n\t\tif (reachable.has(id)) {\n\t\t\treturn;\n\t\t}\n\t\treachable.add(id);\n\t\tfor (const child of edges.get(id) ?? []) {\n\t\t\tlink(child);\n\t\t}\n\t\tconst owner = signatures.get(id)?.owner;\n\t\tif (owner) {\n\t\t\tlink(owner.block);\n\t\t}\n\t\tfor (const method of functions.filter((fn) => fn.owner?.block === id)) {\n\t\t\tlink(method.id);\n\t\t}\n\t\tfor (const instance of blocks\n\t\t\t.get(id)\n\t\t\t?.state.filter((variable) => variable.storage === \"instance\") ?? []) {\n\t\t\tconst type = instancedBlock(instance.type, types);\n\t\t\tif (type) {\n\t\t\t\tlink(type.block);\n\t\t\t}\n\t\t}\n\t};\n\tfor (const entry of entries) {\n\t\tlink(entry);\n\t}\n\tfor (const variable of module.variables) {\n\t\tconst type = instancedBlock(variable.type, types);\n\t\tif (type) {\n\t\t\tlink(type.block);\n\t\t}\n\t}\n\treturn reachable;\n};\n\nconst usedTypeIds = (\n\tmodule: PlcModule,\n\ttypes: ReadonlyMap<string, PlcType>,\n\tlinkedFunctions: readonly CoreFunction[],\n\tlinkedBlocks: readonly CoreFunctionBlock[],\n): ReadonlySet<string> => {\n\tconst usedTypes = new Set<string>();\n\tconst useType = (id: string): void => {\n\t\tif (usedTypes.has(id)) {\n\t\t\treturn;\n\t\t}\n\t\tusedTypes.add(id);\n\t\tconst type = lookup(types, id, \"type\");\n\t\tif (type.kind === \"record\") {\n\t\t\tfor (const field of type.fields) {\n\t\t\t\tuseType(field.type);\n\t\t\t}\n\t\t}\n\t\tif (type.kind === \"array\") {\n\t\t\tuseType(type.element);\n\t\t\tif (type.index) {\n\t\t\t\tuseType(type.index);\n\t\t\t}\n\t\t}\n\t\tif (type.kind === \"enum\") {\n\t\t\tuseType(type.base);\n\t\t}\n\t\tif (type.kind === \"block\" && type.output) {\n\t\t\tuseType(type.output);\n\t\t}\n\t};\n\t// Primitive definitions also support backend-generated numeric helpers.\n\ttypes.forEach((type) => {\n\t\tif (\n\t\t\t[\"bool\", \"integer\", \"bits\", \"float\", \"duration\", \"calendar\"].includes(\n\t\t\t\ttype.kind,\n\t\t\t)\n\t\t) {\n\t\t\tuseType(type.id);\n\t\t}\n\t});\n\tfor (const variable of module.variables) {\n\t\tuseType(variable.type);\n\t}\n\tfor (const routine of [...linkedFunctions, ...linkedBlocks]) {\n\t\tif (routine.result) {\n\t\t\tuseType(routine.result);\n\t\t}\n\t\tfor (const variable of routineVariables(routine)) {\n\t\t\tuseType(variable.type);\n\t\t}\n\t}\n\t// A telemetry property can be its type's only use, such as an enum field the elaborator folded.\n\tconst useTelemetryTypes = (body: readonly CoreStatement[]): void => {\n\t\tfor (const item of body) {\n\t\t\tif (item.kind === \"telemetry\") {\n\t\t\t\tfor (const operand of telemetryOperands(item)) {\n\t\t\t\t\tuseType(operand.type);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const nested of nestedBodies(item)) {\n\t\t\t\tuseTelemetryTypes(nested);\n\t\t\t}\n\t\t}\n\t};\n\tfor (const routine of [...linkedFunctions, ...linkedBlocks]) {\n\t\tuseTelemetryTypes(routine.body);\n\t}\n\treturn usedTypes;\n};\n",
26
+ "import { aggregate, expressionIssue, placeType, valueFits } from \"./aggregates\";\nimport {\n\ttype CoreExpression,\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CorePath,\n\ttype CoreStatement,\n\tisBlockRoutine,\n\ttemporaryId,\n} from \"./core-model\";\nimport type { ModuleDeclarations } from \"./declarations\";\nimport type { SourceSpan } from \"./diagnostics\";\nimport { fold } from \"./fold\";\nimport type {\n\tExpression,\n\tFunctionBlock,\n\tPlace,\n\tPlcFunction,\n\tStatement,\n\tVariable,\n} from \"./model\";\nimport { reject } from \"./normalization-error\";\nimport { admits, canonicalInteger, type IntegerInterval } from \"./numeric\";\nimport {\n\tinterval,\n\tloopBounds,\n\tmaxLoopIterations,\n\tnarrowRanges,\n} from \"./ranges\";\nimport { type BranchOperand, lowerLogical, lowerSelect } from \"./short-circuit\";\nimport { lookup } from \"./tables\";\nimport { instancedBlock, integerRange, isValueType } from \"./types\";\n\ntype Flow = \"fallthrough\" | \"return\" | \"loop\" | \"mixed\";\ninterface FlowState {\n\tflow: Flow;\n\tinitialized: Set<string>;\n}\ninterface BodyResult extends FlowState {\n\tbody: CoreStatement[];\n}\n\n// Only paths that reach the next statement participate in a join. A local is\n// definitely initialized when every such path initialized it; branches that\n// return or leave the loop do not constrain it.\nconst join = (\n\tbranches: readonly [BodyResult, ...BodyResult[]],\n\tinitialized: Set<string>,\n): FlowState => {\n\tconst [falling, ...others] = branches.filter(\n\t\t(branch) => branch.flow === \"fallthrough\",\n\t);\n\tif (falling) {\n\t\treturn {\n\t\t\tflow: \"fallthrough\",\n\t\t\tinitialized: new Set(\n\t\t\t\t[...falling.initialized].filter((id) =>\n\t\t\t\t\tothers.every((branch) => branch.initialized.has(id)),\n\t\t\t\t),\n\t\t\t),\n\t\t};\n\t}\n\tconst [{ flow }] = branches;\n\treturn {\n\t\tflow: branches.every((branch) => branch.flow === flow) ? flow : \"mixed\",\n\t\tinitialized,\n\t};\n};\n\nexport class RoutineNormalizer {\n\tprivate readonly parameters: readonly Variable[];\n\n\tprivate readonly owner: FunctionBlock | undefined;\n\n\t/** The storage the routine's source may name; temporaries are not in it, so a place the source names can't reach one. */\n\tprivate readonly scope: Map<string, Variable>;\n\n\tprivate readonly locals: Variable[];\n\n\tprivate readonly ranges = new Map<string, IntegerInterval>();\n\n\tprivate readonly counters = new Set<string>();\n\n\tprivate readonly callees = new Set<string>();\n\n\tprivate temporaryCount = 0;\n\n\tconstructor(\n\t\tprivate readonly routine: PlcFunction | FunctionBlock,\n\t\tprivate readonly declarations: ModuleDeclarations,\n\t) {\n\t\tif (isBlockRoutine(routine)) {\n\t\t\tthis.owner = routine;\n\t\t\tthis.parameters = routine.inputs;\n\t\t} else {\n\t\t\tthis.owner = routine.owner\n\t\t\t\t? declarations.blocks.get(routine.owner.block)\n\t\t\t\t: undefined;\n\t\t\tthis.parameters = routine.parameters;\n\t\t}\n\t\tthis.scope = new Map(declarations.globals);\n\t\tfor (const item of [\n\t\t\t...this.parameters,\n\t\t\t...(this.owner ? [...this.owner.state, ...this.owner.outputs] : []),\n\t\t\t...routine.locals,\n\t\t]) {\n\t\t\tthis.scope.set(item.id, item);\n\t\t}\n\t\tthis.locals = [...routine.locals];\n\t}\n\n\tnormalize(): {\n\t\troutine: CoreFunction | CoreFunctionBlock;\n\t\tcallees: ReadonlySet<string>;\n\t} {\n\t\tconst { routine } = this;\n\t\t// A standard block has no body: the vendor library implements it.\n\t\tif (isBlockRoutine(routine) && routine.standard) {\n\t\t\treturn { routine: { ...routine, body: [] }, callees: this.callees };\n\t\t}\n\t\treturn {\n\t\t\troutine: { ...routine, locals: this.locals, body: this.routineBody() },\n\t\t\tcallees: this.callees,\n\t\t};\n\t}\n\n\tprivate routineBody(): CoreStatement[] {\n\t\tconst normalized = this.body(\n\t\t\tthis.routine.body,\n\t\t\tnew Set(this.parameters.map((item) => item.id)),\n\t\t);\n\t\tif (this.routine.result && normalized.flow !== \"return\") {\n\t\t\treject(\"A typed helper must return on every path.\", this.routine.span);\n\t\t}\n\t\treturn normalized.body;\n\t}\n\n\tprivate temporary(type: string, span: SourceSpan): Variable {\n\t\tconst id = this.unclaimedTemporaryId();\n\t\tthis.declarations.claimId(id);\n\t\tconst item: Variable = {\n\t\t\tid,\n\t\t\tname: `temporary_${this.temporaryCount}`,\n\t\t\ttype,\n\t\t\tstorage: \"local\",\n\t\t\tmutable: true,\n\t\t\tretention: \"none\",\n\t\t\tspan,\n\t\t};\n\t\tthis.locals.push(item);\n\t\treturn item;\n\t}\n\n\tprivate unclaimedTemporaryId(): string {\n\t\tconst id = temporaryId(this.routine.id, this.temporaryCount++);\n\t\treturn this.declarations.hasId(id) ? this.unclaimedTemporaryId() : id;\n\t}\n\n\tprivate load(variable: Variable, span: SourceSpan): CoreExpression {\n\t\treturn { kind: \"load\", root: variable.id, type: variable.type, span };\n\t}\n\n\t/** The block a method or update receiver instantiates: a static instance, or an InOut reference to one. */\n\tprivate receiverBlock(id: string): string | undefined {\n\t\tconst variable = this.scope.get(id);\n\t\tif (variable?.storage !== \"instance\" && variable?.mode !== \"inOut\") {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn instancedBlock(variable.type, this.declarations.types)?.block;\n\t}\n\n\tprivate verifyCall(\n\t\tid: string,\n\t\targuments_: readonly Expression[],\n\t\tspan: SourceSpan,\n\t\tinstance: string | undefined,\n\t): PlcFunction {\n\t\tconst called = this.declarations.signatures.get(id);\n\t\tif (!called || called.parameters.length !== arguments_.length) {\n\t\t\treject(\"Unknown helper or wrong argument count.\", span);\n\t\t}\n\t\tif (called.owner) {\n\t\t\tif (instance) {\n\t\t\t\tif (this.receiverBlock(instance) !== called.owner.block) {\n\t\t\t\t\treject(\n\t\t\t\t\t\t\"Method calls require a matching static block instance.\",\n\t\t\t\t\t\tspan,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (this.owner?.id !== called.owner.block) {\n\t\t\t\treject(\n\t\t\t\t\t\"An implicit method call requires its owning block scope.\",\n\t\t\t\t\tspan,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tcalled.owner.access !== \"public\" &&\n\t\t\t\tthis.owner?.id !== called.owner.block\n\t\t\t) {\n\t\t\t\treject(\n\t\t\t\t\t\"Private and protected methods require their owning block scope.\",\n\t\t\t\t\tspan,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (instance) {\n\t\t\treject(\"Ordinary functions cannot have an instance receiver.\", span);\n\t\t}\n\t\tthis.callees.add(id);\n\t\targuments_.forEach((argument, index) => {\n\t\t\tif (argument.type !== called.parameters[index]?.type) {\n\t\t\t\treject(\"Helper argument has the wrong PLC type.\", argument.span);\n\t\t\t}\n\t\t});\n\t\treturn called;\n\t}\n\n\tprivate expression(\n\t\tvalue: Expression,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t\t{ allowAggregateLoad }: { allowAggregateLoad?: true } = {},\n\t): CoreExpression {\n\t\tconst type = this.declarations.types.get(value.type);\n\t\tif (!type || !isValueType(value.type, this.declarations.types)) {\n\t\t\treject(\"Unknown or non-value expression type.\", value.span);\n\t\t}\n\t\tif (value.kind === \"borrow\") {\n\t\t\treject(\n\t\t\t\t\"Borrowed places are only valid in block update arguments.\",\n\t\t\t\tvalue.span,\n\t\t\t);\n\t\t}\n\t\tconst common = { type: value.type, span: value.span };\n\t\tif (value.kind === \"length\") {\n\t\t\tconst array = this.declarations.types.get(value.operand.type);\n\t\t\tif (array?.kind !== \"array\" || value.type !== \"DINT\") {\n\t\t\t\treject(\"Length requires a fixed array and DINT result.\", value.span);\n\t\t\t}\n\t\t\tif (value.operand.kind === \"load\") {\n\t\t\t\tconst source = this.scope.get(value.operand.place.root);\n\t\t\t\tconst checked = placeType(\n\t\t\t\t\tvalue.operand.place,\n\t\t\t\t\tthis.declarations.types,\n\t\t\t\t\tthis.scope,\n\t\t\t\t\tthis.ranges,\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\t!source ||\n\t\t\t\t\tchecked.issue ||\n\t\t\t\t\tchecked.type !== value.operand.type ||\n\t\t\t\t\t(source.storage === \"local\" && !initialized.has(source.id))\n\t\t\t\t) {\n\t\t\t\t\treject(checked.issue ?? \"Invalid array receiver.\", value.span);\n\t\t\t\t}\n\t\t\t\tthis.normalizePath(value.operand.place, initialized, output);\n\t\t\t} else {\n\t\t\t\tthis.expression(value.operand, initialized, output, {\n\t\t\t\t\tallowAggregateLoad: true,\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...common,\n\t\t\t\tkind: \"constant\",\n\t\t\t\tvalue: { kind: \"integer\", value: String(array.length) },\n\t\t\t};\n\t\t}\n\t\tif (value.kind === \"conditional\") {\n\t\t\tif (\n\t\t\t\tvalue.condition.type !== \"BOOL\" ||\n\t\t\t\tvalue.then.type !== value.type ||\n\t\t\t\tvalue.else.type !== value.type\n\t\t\t) {\n\t\t\t\treject(\"Invalid conditional types.\", value.span);\n\t\t\t}\n\t\t\tconst condition = this.expression(value.condition, initialized, output);\n\t\t\tconst result = this.temporary(value.type, value.span);\n\t\t\tconst whenTrue = this.branchOperand(value.then, initialized);\n\t\t\tconst whenFalse = this.branchOperand(value.else, initialized);\n\t\t\toutput.push(\n\t\t\t\tlowerSelect({\n\t\t\t\t\tresult: { root: result.id, type: result.type },\n\t\t\t\t\tcondition,\n\t\t\t\t\twhenTrue,\n\t\t\t\t\twhenFalse,\n\t\t\t\t\tspan: value.span,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tinitialized.add(result.id);\n\t\t\treturn this.load(result, value.span);\n\t\t}\n\t\tif (value.kind === \"call\") {\n\t\t\tconst called = this.verifyCall(\n\t\t\t\tvalue.function,\n\t\t\t\tvalue.arguments,\n\t\t\t\tvalue.span,\n\t\t\t\tvalue.instance,\n\t\t\t);\n\t\t\tif (called.result !== value.type) {\n\t\t\t\treject(\"Expression call requires a matching result type.\", value.span);\n\t\t\t}\n\t\t\tconst index =\n\t\t\t\tvalue.instance &&\n\t\t\t\tthis.instanceIndex(\n\t\t\t\t\tvalue.instance,\n\t\t\t\t\tvalue.index,\n\t\t\t\t\tinitialized,\n\t\t\t\t\toutput,\n\t\t\t\t\tvalue.span,\n\t\t\t\t);\n\t\t\tconst arguments_ = this.arguments(\n\t\t\t\tcalled.parameters,\n\t\t\t\tvalue.arguments,\n\t\t\t\tinitialized,\n\t\t\t\toutput,\n\t\t\t);\n\t\t\tconst result = this.temporary(value.type, value.span);\n\t\t\toutput.push({\n\t\t\t\tkind: \"invoke\",\n\t\t\t\tfunction: value.function,\n\t\t\t\t...(value.instance && { instance: value.instance }),\n\t\t\t\t...(index && { index }),\n\t\t\t\targuments: arguments_,\n\t\t\t\tdestination: result.id,\n\t\t\t\tspan: value.span,\n\t\t\t});\n\t\t\tinitialized.add(result.id);\n\t\t\treturn this.load(result, value.span);\n\t\t}\n\t\tconst issue = expressionIssue(\n\t\t\tvalue,\n\t\t\tthis.declarations.types,\n\t\t\tthis.scope,\n\t\t\tthis.ranges,\n\t\t);\n\t\tif (issue) {\n\t\t\treject(issue, value.span);\n\t\t}\n\t\tswitch (value.kind) {\n\t\t\tcase \"copy\":\n\t\t\t\treturn this.expression(value.operand, initialized, output, {\n\t\t\t\t\tallowAggregateLoad: true,\n\t\t\t\t});\n\t\t\tcase \"record\":\n\t\t\tcase \"array\": {\n\t\t\t\tconst result = this.temporary(value.type, value.span);\n\t\t\t\tif (value.kind === \"record\") {\n\t\t\t\t\tfor (const [name, operand] of Object.entries(value.fields)) {\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\t\t\troot: result.id,\n\t\t\t\t\t\t\tpath: [{ kind: \"field\", name }],\n\t\t\t\t\t\t\tvalue: this.expression(operand, initialized, output),\n\t\t\t\t\t\t\tspan: operand.span,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (type.kind !== \"array\") {\n\t\t\t\t\t\treject(\"Invalid array construction.\", value.span);\n\t\t\t\t\t}\n\t\t\t\t\tvalue.items.forEach((operand, index) => {\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\t\t\troot: result.id,\n\t\t\t\t\t\t\tpath: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tkind: \"index\",\n\t\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\t\tkind: \"constant\",\n\t\t\t\t\t\t\t\t\t\ttype: \"DINT\",\n\t\t\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\t\t\tkind: \"integer\",\n\t\t\t\t\t\t\t\t\t\t\tvalue: String(type.lowerBound + index),\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tspan: operand.span,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tvalue: this.expression(operand, initialized, output),\n\t\t\t\t\t\t\tspan: operand.span,\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tinitialized.add(result.id);\n\t\t\t\treturn this.load(result, value.span);\n\t\t\t}\n\t\t\tcase \"constant\": {\n\t\t\t\tif (!aggregate(type)) {\n\t\t\t\t\treturn { ...common, kind: \"constant\", value: value.value };\n\t\t\t\t}\n\t\t\t\tconst result = this.temporary(value.type, value.span);\n\t\t\t\toutput.push({\n\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\troot: result.id,\n\t\t\t\t\tvalue: { ...common, kind: \"constant\", value: value.value },\n\t\t\t\t\tspan: value.span,\n\t\t\t\t});\n\t\t\t\tinitialized.add(result.id);\n\t\t\t\treturn this.load(result, value.span);\n\t\t\t}\n\t\t\tcase \"load\": {\n\t\t\t\tconst source = this.scope.get(value.place.root);\n\t\t\t\tconst checked = placeType(\n\t\t\t\t\tvalue.place,\n\t\t\t\t\tthis.declarations.types,\n\t\t\t\t\tthis.scope,\n\t\t\t\t\tthis.ranges,\n\t\t\t\t);\n\t\t\t\tif (!source || checked.issue || checked.type !== value.type) {\n\t\t\t\t\treject(checked.issue ?? \"Invalid PLC load.\", value.span);\n\t\t\t\t}\n\t\t\t\tif (aggregate(type) && !allowAggregateLoad) {\n\t\t\t\t\treject(\n\t\t\t\t\t\t\"Aggregate loads require explicit copy or a readonly value argument.\",\n\t\t\t\t\t\tvalue.span,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (source.storage === \"local\" && !initialized.has(source.id)) {\n\t\t\t\t\treject(\"Local read before initialization.\", value.span);\n\t\t\t\t}\n\t\t\t\t// The virtual .out view is not a vendor record value. Snapshot its\n\t\t\t\t// declared fields, rather than copying the whole FB instance.\n\t\t\t\tconst first = value.place.path[0];\n\t\t\t\tif (\n\t\t\t\t\tsource.storage === \"instance\" &&\n\t\t\t\t\tvalue.place.path.length === 1 &&\n\t\t\t\t\tfirst?.kind === \"field\" &&\n\t\t\t\t\tfirst.name === \"out\" &&\n\t\t\t\t\ttype.kind === \"record\"\n\t\t\t\t) {\n\t\t\t\t\tconst result = this.temporary(value.type, value.span);\n\t\t\t\t\tfor (const field of type.fields) {\n\t\t\t\t\t\tconst selected: Expression = {\n\t\t\t\t\t\t\tkind: \"load\",\n\t\t\t\t\t\t\ttype: field.type,\n\t\t\t\t\t\t\tplace: {\n\t\t\t\t\t\t\t\troot: source.id,\n\t\t\t\t\t\t\t\tpath: [\n\t\t\t\t\t\t\t\t\t...value.place.path,\n\t\t\t\t\t\t\t\t\t{ kind: \"field\", name: field.name },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tspan: value.span,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst captured = this.expression(selected, initialized, output, {\n\t\t\t\t\t\t\tallowAggregateLoad: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\t\t\troot: result.id,\n\t\t\t\t\t\t\tpath: [{ kind: \"field\", name: field.name }],\n\t\t\t\t\t\t\tvalue: captured,\n\t\t\t\t\t\t\tspan: value.span,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tinitialized.add(result.id);\n\t\t\t\t\treturn this.load(result, value.span);\n\t\t\t\t}\n\t\t\t\tconst path = this.normalizePath(value.place, initialized, output);\n\t\t\t\tif (source.storage === \"constant\" && source.initial && !path.length) {\n\t\t\t\t\treturn { ...common, kind: \"constant\", value: source.initial };\n\t\t\t\t}\n\t\t\t\t// Capture now, before a later operand can invoke an effectful helper.\n\t\t\t\tconst result = this.temporary(value.type, value.span);\n\t\t\t\toutput.push({\n\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\troot: result.id,\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\t...common,\n\t\t\t\t\t\tkind: \"load\",\n\t\t\t\t\t\troot: source.id,\n\t\t\t\t\t\t...(path.length && { path }),\n\t\t\t\t\t},\n\t\t\t\t\tspan: value.span,\n\t\t\t\t});\n\t\t\t\tconst bound = interval(\n\t\t\t\t\tvalue,\n\t\t\t\t\tthis.declarations.types,\n\t\t\t\t\tthis.scope,\n\t\t\t\t\tthis.ranges,\n\t\t\t\t);\n\t\t\t\tif (bound) {\n\t\t\t\t\tthis.ranges.set(result.id, bound);\n\t\t\t\t}\n\t\t\t\tinitialized.add(result.id);\n\t\t\t\treturn this.load(result, value.span);\n\t\t\t}\n\t\t\tcase \"unary\": {\n\t\t\t\tconst operand = this.expression(value.operand, initialized, output);\n\t\t\t\tconst constant = fold(value, this.scope, this.declarations.types);\n\t\t\t\treturn constant\n\t\t\t\t\t? { ...common, kind: \"constant\", value: constant }\n\t\t\t\t\t: { ...common, kind: \"unary\", operator: value.operator, operand };\n\t\t\t}\n\t\t\tcase \"convert\": {\n\t\t\t\tconst operand = this.expression(value.operand, initialized, output);\n\t\t\t\tif (value.type === value.operand.type) {\n\t\t\t\t\treturn operand;\n\t\t\t\t}\n\t\t\t\tconst constant = fold(value, this.scope, this.declarations.types);\n\t\t\t\treturn constant\n\t\t\t\t\t? { ...common, kind: \"constant\", value: constant }\n\t\t\t\t\t: { ...common, kind: \"convert\", operand, policy: value.policy };\n\t\t\t}\n\t\t\tcase \"binary\": {\n\t\t\t\tconst left = this.expression(value.left, initialized, output);\n\t\t\t\tif (value.operator === \"and\" || value.operator === \"or\") {\n\t\t\t\t\tconst result = this.temporary(\"BOOL\", value.span);\n\t\t\t\t\tconst right = this.branchOperand(value.right, initialized);\n\t\t\t\t\toutput.push(\n\t\t\t\t\t\t...lowerLogical({\n\t\t\t\t\t\t\toperator: value.operator,\n\t\t\t\t\t\t\tresult: { root: result.id, type: result.type },\n\t\t\t\t\t\t\tleft,\n\t\t\t\t\t\t\tright,\n\t\t\t\t\t\t\tspan: value.span,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t\tinitialized.add(result.id);\n\t\t\t\t\treturn this.load(result, value.span);\n\t\t\t\t}\n\t\t\t\tconst right = this.expression(value.right, initialized, output);\n\t\t\t\tconst constant = fold(value, this.scope, this.declarations.types);\n\t\t\t\tif (constant) {\n\t\t\t\t\treturn { ...common, kind: \"constant\", value: constant };\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\t...common,\n\t\t\t\t\tkind: \"binary\",\n\t\t\t\t\toperator: value.operator,\n\t\t\t\t\tleft,\n\t\t\t\t\tright,\n\t\t\t\t\t...(value.policy && { policy: value.policy }),\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\t/** An operand that runs only on one branch, so what it initializes stays there. */\n\tprivate branchOperand(\n\t\toperand: Expression,\n\t\tinitialized: Set<string>,\n\t): BranchOperand {\n\t\tconst statements: CoreStatement[] = [];\n\t\tconst value = this.expression(operand, new Set(initialized), statements);\n\t\treturn { statements, value };\n\t}\n\n\tprivate normalizePath(\n\t\tplace: Place,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): CorePath {\n\t\t// An index is evaluated and captured once, before later arguments can change\n\t\t// its source storage. The resulting path denotes that selected cell.\n\t\treturn place.path.map((segment) =>\n\t\t\tsegment.kind === \"field\"\n\t\t\t\t? segment\n\t\t\t\t: {\n\t\t\t\t\t\tkind: \"index\",\n\t\t\t\t\t\tvalue: this.expression(segment.value, initialized, output),\n\t\t\t\t\t},\n\t\t);\n\t}\n\n\tprivate destination(\n\t\tplace: Place,\n\t\ttype: string,\n\t\tinitialized: Set<string>,\n\t\tspan: SourceSpan,\n\t): Variable {\n\t\tconst target = this.scope.get(place.root);\n\t\tconst initializing =\n\t\t\ttarget?.storage === \"local\" &&\n\t\t\t!initialized.has(place.root) &&\n\t\t\t!place.path.length;\n\t\tconst checked = placeType(\n\t\t\tplace,\n\t\t\tthis.declarations.types,\n\t\t\tthis.scope,\n\t\t\tthis.ranges,\n\t\t\t!initializing,\n\t\t);\n\t\tif (\n\t\t\t!target ||\n\t\t\tchecked.issue ||\n\t\t\tchecked.type !== type ||\n\t\t\tthis.counters.has(place.root)\n\t\t) {\n\t\t\treject(checked.issue ?? \"Invalid assignment destination.\", span);\n\t\t}\n\t\tif (\n\t\t\tplace.path.length &&\n\t\t\ttarget.storage === \"local\" &&\n\t\t\t!initialized.has(target.id)\n\t\t) {\n\t\t\treject(\"Initialize the whole aggregate before assigning fields.\", span);\n\t\t}\n\t\treturn target;\n\t}\n\n\tprivate instanceIndex(\n\t\tinstance: string,\n\t\tindex: Expression | undefined,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t\tspan: SourceSpan,\n\t): CoreExpression | undefined {\n\t\tif (!index) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst checked = placeType(\n\t\t\t{ root: instance, path: [{ kind: \"index\", value: index }] },\n\t\t\tthis.declarations.types,\n\t\t\tthis.scope,\n\t\t\tthis.ranges,\n\t\t);\n\t\tif (checked.issue) {\n\t\t\treject(checked.issue, span);\n\t\t}\n\t\treturn this.expression(index, initialized, output);\n\t}\n\n\tprivate blockUpdate(\n\t\titem: Extract<Statement, { kind: \"blockUpdate\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): void {\n\t\tconst block = this.receiverBlock(item.instance);\n\t\tconst called = block && this.declarations.blocks.get(block);\n\t\tif (!called) {\n\t\t\treject(\n\t\t\t\t\"Updates require a statically allocated block instance.\",\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\tconst index = this.instanceIndex(\n\t\t\titem.instance,\n\t\t\titem.index,\n\t\t\tinitialized,\n\t\t\toutput,\n\t\t\titem.span,\n\t\t);\n\t\t// Input names are unique, so a matching count means every input appears exactly once.\n\t\tconst supplied = Object.entries(item.inputs).flatMap(([name, value]) => {\n\t\t\tconst input = called.inputs.find((port) => port.name === name);\n\t\t\treturn input ? [{ input, value }] : [];\n\t\t});\n\t\tif (\n\t\t\tObject.keys(item.inputs).length !== called.inputs.length ||\n\t\t\tsupplied.length !== called.inputs.length\n\t\t) {\n\t\t\treject(\n\t\t\t\t\"Block update must supply every named input exactly once.\",\n\t\t\t\titem.span,\n\t\t\t);\n\t\t}\n\t\tthis.callees.add(called.id);\n\t\t// Inputs evaluate in source property order.\n\t\tconst inputs = Object.fromEntries(\n\t\t\tsupplied.map(({ input, value }) => [\n\t\t\t\tinput.name,\n\t\t\t\tthis.argument(input, value, initialized, output),\n\t\t\t]),\n\t\t);\n\t\toutput.push({\n\t\t\tkind: \"blockUpdate\",\n\t\t\tinstance: item.instance,\n\t\t\t...(index && { index }),\n\t\t\tinputs,\n\t\t\tspan: item.span,\n\t\t});\n\t}\n\n\tprivate arguments(\n\t\tparameters: readonly Variable[],\n\t\tvalues: readonly Expression[],\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): CoreExpression[] {\n\t\treturn values.map((value, index) => {\n\t\t\tconst parameter = parameters[index];\n\t\t\tif (!parameter) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"A call passes more arguments than its callee declares.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn this.argument(parameter, value, initialized, output);\n\t\t});\n\t}\n\n\tprivate argument(\n\t\tinput: Variable,\n\t\tvalue: Expression,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): CoreExpression {\n\t\tif (value.type !== input.type) {\n\t\t\treject(\"Block input differs from its concrete PLC type.\", value.span);\n\t\t}\n\t\tif (input.mode === \"inOut\" && value.kind === \"borrow\") {\n\t\t\treturn this.borrow(value, initialized, output);\n\t\t}\n\t\tif (input.mode === \"inOut\") {\n\t\t\tif (this.declarations.types.get(value.type)?.kind === \"block\") {\n\t\t\t\treject(\"Pass a block instance by name.\", value.span);\n\t\t\t}\n\t\t\tconst temporary = this.temporary(value.type, value.span);\n\t\t\toutput.push({\n\t\t\t\tkind: \"assign\",\n\t\t\t\troot: temporary.id,\n\t\t\t\tvalue: this.expression(value, initialized, output),\n\t\t\t\tspan: value.span,\n\t\t\t});\n\t\t\tinitialized.add(temporary.id);\n\t\t\treturn {\n\t\t\t\tkind: \"borrow\",\n\t\t\t\ttype: value.type,\n\t\t\t\tplace: { root: temporary.id, path: [] },\n\t\t\t\tspan: value.span,\n\t\t\t};\n\t\t}\n\t\tif (value.kind === \"borrow\") {\n\t\t\treject(\n\t\t\t\t\"Readonly value inputs cannot receive borrowed references.\",\n\t\t\t\tvalue.span,\n\t\t\t);\n\t\t}\n\t\treturn this.expression(value, initialized, output, {\n\t\t\tallowAggregateLoad: true,\n\t\t});\n\t}\n\n\tprivate borrow(\n\t\tvalue: Extract<Expression, { kind: \"borrow\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): CoreExpression {\n\t\tconst block = this.declarations.types.get(value.type)?.kind === \"block\";\n\t\tconst root = this.scope.get(value.place.root);\n\t\tconst checked = placeType(\n\t\t\tvalue.place,\n\t\t\tthis.declarations.types,\n\t\t\tthis.scope,\n\t\t\tthis.ranges,\n\t\t\t!block,\n\t\t);\n\t\tif (\n\t\t\t!root ||\n\t\t\tchecked.issue ||\n\t\t\tchecked.type !== value.type ||\n\t\t\t(!block && !isValueType(value.type, this.declarations.types)) ||\n\t\t\tthis.counters.has(root.id) ||\n\t\t\t(root.storage === \"local\" && !initialized.has(root.id))\n\t\t) {\n\t\t\treject(\n\t\t\t\tchecked.issue ??\n\t\t\t\t\t\"Borrow requires initialized mutable value storage of the exact type.\",\n\t\t\t\tvalue.span,\n\t\t\t);\n\t\t}\n\t\treturn {\n\t\t\tkind: \"borrow\",\n\t\t\ttype: value.type,\n\t\t\tplace: {\n\t\t\t\troot: value.place.root,\n\t\t\t\tpath: this.normalizePath(value.place, initialized, output),\n\t\t\t},\n\t\t\tspan: value.span,\n\t\t};\n\t}\n\n\tprivate body(\n\t\tstatements: readonly Statement[],\n\t\tinitialized: Set<string>,\n\t): BodyResult {\n\t\tconst output: CoreStatement[] = [];\n\t\tconst state = statements.reduce<FlowState>(\n\t\t\t(reached, item) =>\n\t\t\t\treached.flow === \"fallthrough\"\n\t\t\t\t\t? this.statement(item, reached.initialized, output)\n\t\t\t\t\t: reached,\n\t\t\t{ flow: \"fallthrough\", initialized },\n\t\t);\n\t\treturn { body: output, ...state };\n\t}\n\n\tprivate statement(\n\t\titem: Statement,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): FlowState {\n\t\tswitch (item.kind) {\n\t\t\tcase \"assign\":\n\t\t\t\tthis.assign(item, initialized, output);\n\t\t\t\treturn { flow: \"fallthrough\", initialized };\n\t\t\tcase \"blockUpdate\":\n\t\t\t\tthis.blockUpdate(item, initialized, output);\n\t\t\t\treturn { flow: \"fallthrough\", initialized };\n\t\t\tcase \"invoke\":\n\t\t\t\tthis.invoke(item, initialized, output);\n\t\t\t\treturn { flow: \"fallthrough\", initialized };\n\t\t\tcase \"if\":\n\t\t\t\treturn this.ifStatement(item, initialized, output);\n\t\t\tcase \"switch\":\n\t\t\t\treturn this.switchStatement(item, initialized, output);\n\t\t\tcase \"for\":\n\t\t\t\tthis.forStatement(item, initialized, output);\n\t\t\t\treturn { flow: \"fallthrough\", initialized };\n\t\t\tcase \"return\": {\n\t\t\t\tif (item.value?.type !== this.routine.result) {\n\t\t\t\t\treject(\"Return differs from the function signature.\", item.span);\n\t\t\t\t}\n\t\t\t\tconst value =\n\t\t\t\t\titem.value && this.expression(item.value, initialized, output);\n\t\t\t\toutput.push({\n\t\t\t\t\tkind: \"return\",\n\t\t\t\t\tspan: item.span,\n\t\t\t\t\t...(value && { value }),\n\t\t\t\t});\n\t\t\t\treturn { flow: \"return\", initialized };\n\t\t\t}\n\t\t\tcase \"telemetry\":\n\t\t\t\tthis.telemetry(item, initialized, output);\n\t\t\t\treturn { flow: \"fallthrough\", initialized };\n\t\t\tcase \"break\":\n\t\t\tcase \"continue\":\n\t\t\t\tif (!this.counters.size) {\n\t\t\t\t\treject(\"Loop control appears outside a bounded loop.\", item.span);\n\t\t\t\t}\n\t\t\t\toutput.push({ kind: item.kind, span: item.span });\n\t\t\t\treturn { flow: \"loop\", initialized };\n\t\t}\n\t}\n\n\tprivate assign(\n\t\titem: Extract<Statement, { kind: \"assign\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): void {\n\t\tthis.destination(item.destination, item.value.type, initialized, item.span);\n\t\tconst path = this.normalizePath(item.destination, initialized, output);\n\t\t// A const is assigned once, so its initializer's range holds wherever it is read.\n\t\tconst bound =\n\t\t\t!path.length &&\n\t\t\tthis.scope.get(item.destination.root)?.mutable === false &&\n\t\t\tinterval(item.value, this.declarations.types, this.scope, this.ranges);\n\t\tconst value = this.expression(item.value, initialized, output);\n\t\tif (bound) {\n\t\t\tthis.ranges.set(item.destination.root, bound);\n\t\t}\n\t\tif (!path.length) {\n\t\t\tinitialized.add(item.destination.root);\n\t\t}\n\t\toutput.push({\n\t\t\tkind: \"assign\",\n\t\t\troot: item.destination.root,\n\t\t\t...(path.length && { path }),\n\t\t\tvalue,\n\t\t\tspan: item.span,\n\t\t});\n\t}\n\n\tprivate invoke(\n\t\titem: Extract<Statement, { kind: \"invoke\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): void {\n\t\tconst called = this.verifyCall(\n\t\t\titem.function,\n\t\t\titem.arguments,\n\t\t\titem.span,\n\t\t\titem.instance,\n\t\t);\n\t\tif (item.destination) {\n\t\t\tif (item.destination.path.length || !called.result) {\n\t\t\t\treject(\"Invalid helper destination.\", item.span);\n\t\t\t}\n\t\t\tthis.destination(item.destination, called.result, initialized, item.span);\n\t\t}\n\t\tconst index =\n\t\t\titem.instance &&\n\t\t\tthis.instanceIndex(\n\t\t\t\titem.instance,\n\t\t\t\titem.index,\n\t\t\t\tinitialized,\n\t\t\t\toutput,\n\t\t\t\titem.span,\n\t\t\t);\n\t\t// Each argument snapshots its reads before the next argument can invoke\n\t\t// a helper that mutates shared state.\n\t\tconst arguments_ = this.arguments(\n\t\t\tcalled.parameters,\n\t\t\titem.arguments,\n\t\t\tinitialized,\n\t\t\toutput,\n\t\t);\n\t\toutput.push({\n\t\t\tkind: \"invoke\",\n\t\t\tfunction: item.function,\n\t\t\t...(item.instance && { instance: item.instance }),\n\t\t\t...(index && { index }),\n\t\t\targuments: arguments_,\n\t\t\tspan: item.span,\n\t\t\t...(item.destination && { destination: item.destination.root }),\n\t\t});\n\t\tif (item.destination) {\n\t\t\tinitialized.add(item.destination.root);\n\t\t}\n\t}\n\n\tprivate ifStatement(\n\t\titem: Extract<Statement, { kind: \"if\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): FlowState {\n\t\tif (item.condition.type !== \"BOOL\") {\n\t\t\treject(\"Conditions require BOOL.\", item.span);\n\t\t}\n\t\tconst condition = this.expression(item.condition, initialized, output);\n\t\tconst originalRanges = new Map(this.ranges);\n\t\tconst branch = (statements: readonly Statement[], truth: boolean) => {\n\t\t\tthis.ranges.clear();\n\t\t\tfor (const [root, range] of narrowRanges(\n\t\t\t\titem.condition,\n\t\t\t\ttruth,\n\t\t\t\tthis.declarations.types,\n\t\t\t\tthis.scope,\n\t\t\t\toriginalRanges,\n\t\t\t)) {\n\t\t\t\tthis.ranges.set(root, range);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\treturn this.body(statements, new Set(initialized));\n\t\t\t} finally {\n\t\t\t\tthis.ranges.clear();\n\t\t\t\tfor (const [root, range] of originalRanges) {\n\t\t\t\t\tthis.ranges.set(root, range);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tconst yes = branch(item.then, true);\n\t\tconst no = branch(item.else, false);\n\t\toutput.push({\n\t\t\tkind: \"if\",\n\t\t\tcondition,\n\t\t\t// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.\n\t\t\tthen: yes.body,\n\t\t\telse: no.body,\n\t\t\tspan: item.span,\n\t\t});\n\t\treturn join([yes, no], initialized);\n\t}\n\n\tprivate switchStatement(\n\t\titem: Extract<Statement, { kind: \"switch\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): FlowState {\n\t\tconst value = this.expression(item.value, initialized, output);\n\t\tconst type = lookup(this.declarations.types, item.value.type, \"type\");\n\t\tconst seen = new Set<string>();\n\t\tconst cases = item.cases.map((branch) => {\n\t\t\tfor (const constant of branch.values) {\n\t\t\t\tif (!valueFits(constant, type, this.declarations.types)) {\n\t\t\t\t\treject(\"Invalid case constant.\", item.span);\n\t\t\t\t}\n\t\t\t\tconst key = JSON.stringify(constant);\n\t\t\t\tif (seen.has(key)) {\n\t\t\t\t\treject(\"Duplicate case constant.\", item.span);\n\t\t\t\t}\n\t\t\t\tseen.add(key);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tvalues: branch.values,\n\t\t\t\tresult: this.body(branch.body, new Set(initialized)),\n\t\t\t};\n\t\t});\n\t\tconst fallback = this.body(item.fallback, new Set(initialized));\n\t\toutput.push({\n\t\t\tkind: \"switch\",\n\t\t\tvalue,\n\t\t\tcases: cases.map((branch) => ({\n\t\t\t\tvalues: branch.values,\n\t\t\t\tbody: branch.result.body,\n\t\t\t})),\n\t\t\tfallback: fallback.body,\n\t\t\tspan: item.span,\n\t\t});\n\t\treturn join(\n\t\t\t[fallback, ...cases.map((branch) => branch.result)],\n\t\t\tinitialized,\n\t\t);\n\t}\n\n\tprivate forStatement(\n\t\titem: Extract<Statement, { kind: \"for\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): void {\n\t\tconst counter = this.scope.get(item.counter);\n\t\tconst counterType = counter && this.declarations.types.get(counter.type);\n\t\tconst storage =\n\t\t\titem.counterScope === \"existing\"\n\t\t\t\t? [\"local\", \"module\", \"field\"]\n\t\t\t\t: [\"local\"];\n\t\tif (\n\t\t\t!counter ||\n\t\t\t!storage.includes(counter.storage) ||\n\t\t\t!counter.mutable ||\n\t\t\tcounterType?.kind !== \"integer\" ||\n\t\t\tthis.counters.has(counter.id) ||\n\t\t\titem.start.type !== counter.type ||\n\t\t\titem.limit.type !== counter.type ||\n\t\t\t!canonicalInteger.test(item.step) ||\n\t\t\titem.step === \"0\"\n\t\t) {\n\t\t\treject(\"Invalid bounded loop.\", item.span);\n\t\t}\n\t\tconst start = fold(item.start, this.scope, this.declarations.types);\n\t\tconst limit = fold(item.limit, this.scope, this.declarations.types);\n\t\tconst startRange = interval(\n\t\t\titem.start,\n\t\t\tthis.declarations.types,\n\t\t\tthis.scope,\n\t\t\tthis.ranges,\n\t\t);\n\t\tconst limitRange = interval(\n\t\t\titem.limit,\n\t\t\tthis.declarations.types,\n\t\t\tthis.scope,\n\t\t\tthis.ranges,\n\t\t);\n\t\tif (!startRange || !limitRange) {\n\t\t\treject(\"Loop bounds require finite integer ranges.\", item.span);\n\t\t}\n\t\tconst step = BigInt(item.step);\n\t\tconst { first, last, count, range, terminal } = loopBounds(\n\t\t\tstartRange,\n\t\t\tlimitRange,\n\t\t\tstep,\n\t\t\titem.exclusive,\n\t\t);\n\t\tconst dynamic = start?.kind !== \"integer\" || limit?.kind !== \"integer\";\n\t\tif (count > maxLoopIterations || Number(count) !== item.maxIterations) {\n\t\t\treject(\"Loop iteration proof differs from its bounds.\", item.span);\n\t\t}\n\t\tif (item.counterScope === \"existing\") {\n\t\t\tif (count > 0n && !admits(integerRange(counterType), terminal)) {\n\t\t\t\treject(\n\t\t\t\t\t\"The existing loop counter overflows on termination.\",\n\t\t\t\t\titem.span,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tconst evaluatedStart = this.expression(item.start, initialized, output);\n\t\tconst evaluatedLimit = this.expression(item.limit, initialized, output);\n\t\tinitialized.add(counter.id);\n\t\tthis.counters.add(counter.id);\n\t\tthis.ranges.set(counter.id, range);\n\t\tconst nested = this.body(item.body, new Set(initialized));\n\t\tthis.counters.delete(counter.id);\n\t\tthis.ranges.delete(counter.id);\n\t\tif (item.counterScope !== \"existing\") {\n\t\t\tinitialized.delete(counter.id);\n\t\t}\n\t\toutput.push({\n\t\t\tkind: \"for\",\n\t\t\tcounter: counter.id,\n\t\t\t...(item.counterScope && { counterScope: item.counterScope }),\n\t\t\tstart: { kind: \"integer\", value: String(first) },\n\t\t\tlimit: { kind: \"integer\", value: String(last) },\n\t\t\t...(dynamic && {\n\t\t\t\tdynamic: {\n\t\t\t\t\tstart: evaluatedStart,\n\t\t\t\t\tlimit: evaluatedLimit,\n\t\t\t\t\t...(item.exclusive && { exclusive: item.exclusive }),\n\t\t\t\t},\n\t\t\t}),\n\t\t\tstep: item.step,\n\t\t\tmaxIterations: item.maxIterations,\n\t\t\tbody: nested.body,\n\t\t\tspan: item.span,\n\t\t});\n\t}\n\n\tprivate telemetry(\n\t\titem: Extract<Statement, { kind: \"telemetry\" }>,\n\t\tinitialized: Set<string>,\n\t\toutput: CoreStatement[],\n\t): void {\n\t\tconst evaluate = (value: Expression) =>\n\t\t\tthis.expression(value, initialized, output);\n\t\tconst { record } = item;\n\t\toutput.push({\n\t\t\tkind: \"telemetry\",\n\t\t\trecord:\n\t\t\t\trecord.kind === \"exception\"\n\t\t\t\t\t? { kind: \"exception\", code: evaluate(record.code) }\n\t\t\t\t\t: record,\n\t\t\tproperties: item.properties.map(({ name, value, length }) => {\n\t\t\t\tif (!length) {\n\t\t\t\t\treturn { name, value: evaluate(value) };\n\t\t\t\t}\n\t\t\t\tif (value.kind !== \"borrow\") {\n\t\t\t\t\treject(\"Telemetry text reads a byte array in place.\", value.span);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tname,\n\t\t\t\t\tvalue: this.borrow(value, initialized, output),\n\t\t\t\t\tlength: evaluate(length),\n\t\t\t\t};\n\t\t\t}),\n\t\t\tspan: item.span,\n\t\t});\n\t}\n}\n",
27
+ "import { checkStaticAllocation } from \"./allocation\";\nimport {\n\tadmitCore,\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\tisBlockRoutine,\n\ttype VerifiedCoreModule,\n\tverified,\n} from \"./core-model\";\nimport { ModuleDeclarations } from \"./declarations\";\nimport type { Diagnostic } from \"./diagnostics\";\nimport { linkModule } from \"./link\";\nimport type { PlcModule } from \"./model\";\nimport { InvalidCore } from \"./normalization-error\";\nimport { RoutineNormalizer } from \"./routine\";\n\nexport function normalizeModule(module: PlcModule): {\n\tcore?: VerifiedCoreModule;\n\tdiagnostics: readonly Diagnostic[];\n} {\n\ttry {\n\t\tconst declarations = new ModuleDeclarations(module);\n\t\tcheckStaticAllocation(module, declarations);\n\n\t\tconst functions: CoreFunction[] = [];\n\t\tconst blocks: CoreFunctionBlock[] = [];\n\t\tconst edges = new Map<string, ReadonlySet<string>>();\n\t\tfor (const source of [...module.functions, ...module.blocks]) {\n\t\t\tconst normalized = new RoutineNormalizer(\n\t\t\t\tsource,\n\t\t\t\tdeclarations,\n\t\t\t).normalize();\n\t\t\tedges.set(source.id, normalized.callees);\n\t\t\tif (isBlockRoutine(normalized.routine)) {\n\t\t\t\tblocks.push(normalized.routine);\n\t\t\t} else {\n\t\t\t\tfunctions.push(normalized.routine);\n\t\t\t}\n\t\t}\n\n\t\tconst linked = linkModule(module, declarations, functions, blocks, edges);\n\t\treturn {\n\t\t\tcore: admitCore({ ...structuredClone(linked), [verified]: true }),\n\t\t\tdiagnostics: [],\n\t\t};\n\t} catch (cause) {\n\t\tif (cause instanceof InvalidCore) {\n\t\t\treturn { diagnostics: [cause.diagnostic] };\n\t\t}\n\t\tthrow cause;\n\t}\n}\n",
28
+ "import type { CoreExpression, CorePath, CoreStatement } from \"./core-model\";\nimport { telemetryOperands } from \"./model\";\n\n/** The index expressions along a place's path. */\nexport const pathIndexes = (path: CorePath = []): CoreExpression[] =>\n\tpath.flatMap((segment) => (segment.kind === \"index\" ? [segment.value] : []));\n\n/** A path with each index replaced by `map` of it. */\nexport const mapPath = (\n\tpath: CorePath,\n\tmap: (index: CoreExpression) => CoreExpression,\n): CorePath =>\n\tpath.map((segment) =>\n\t\tsegment.kind === \"field\"\n\t\t\t? segment\n\t\t\t: { kind: \"index\", value: map(segment.value) },\n\t);\n\n/** The expressions an expression evaluates directly: its operands, or the indexes of the place it loads or borrows. */\nexport const subexpressions = (\n\tvalue: CoreExpression,\n): readonly CoreExpression[] => {\n\tswitch (value.kind) {\n\t\tcase \"constant\":\n\t\t\treturn [];\n\t\tcase \"load\":\n\t\t\treturn pathIndexes(value.path);\n\t\tcase \"borrow\":\n\t\t\treturn pathIndexes(value.place.path);\n\t\tcase \"unary\":\n\t\tcase \"convert\":\n\t\t\treturn [value.operand];\n\t\tcase \"binary\":\n\t\t\treturn [value.left, value.right];\n\t}\n};\n\n/** An expression with each of its `subexpressions` replaced by `map` of it. */\nexport const mapExpression = (\n\tvalue: CoreExpression,\n\tmap: (operand: CoreExpression) => CoreExpression,\n): CoreExpression => {\n\tswitch (value.kind) {\n\t\tcase \"constant\":\n\t\t\treturn value;\n\t\tcase \"load\":\n\t\t\treturn value.path ? { ...value, path: mapPath(value.path, map) } : value;\n\t\tcase \"borrow\":\n\t\t\treturn {\n\t\t\t\t...value,\n\t\t\t\tplace: { ...value.place, path: mapPath(value.place.path, map) },\n\t\t\t};\n\t\tcase \"unary\":\n\t\tcase \"convert\":\n\t\t\treturn { ...value, operand: map(value.operand) };\n\t\tcase \"binary\":\n\t\t\treturn { ...value, left: map(value.left), right: map(value.right) };\n\t}\n};\n\n/**\n * The expressions a statement evaluates itself, a place's indexes before the value stored or\n * passed there. The statements nested in it are `nestedBodies`.\n */\nexport const statementExpressions = (\n\titem: CoreStatement,\n): readonly CoreExpression[] => {\n\tswitch (item.kind) {\n\t\tcase \"assign\":\n\t\t\treturn [...pathIndexes(item.path), item.value];\n\t\tcase \"if\":\n\t\t\treturn [item.condition];\n\t\tcase \"switch\":\n\t\t\treturn [item.value];\n\t\tcase \"for\":\n\t\t\treturn item.dynamic ? [item.dynamic.start, item.dynamic.limit] : [];\n\t\tcase \"invoke\":\n\t\t\treturn [...(item.index ? [item.index] : []), ...item.arguments];\n\t\tcase \"blockUpdate\":\n\t\t\treturn [\n\t\t\t\t...(item.index ? [item.index] : []),\n\t\t\t\t...Object.values(item.inputs),\n\t\t\t];\n\t\tcase \"return\":\n\t\t\treturn item.value ? [item.value] : [];\n\t\tcase \"telemetry\":\n\t\t\treturn telemetryOperands(item);\n\t\tcase \"break\":\n\t\tcase \"continue\":\n\t\t\treturn [];\n\t}\n};\n\n/**\n * A statement with each of its `statementExpressions` replaced by `map` of it. A telemetry call's\n * properties are mapped before its exception code: routine sharing numbers constants in the order\n * it maps them, and that order is the merged routine's value parameter order in the emitted ST.\n */\nexport const mapStatementExpressions = (\n\titem: CoreStatement,\n\tmap: (operand: CoreExpression) => CoreExpression,\n): CoreStatement => {\n\tswitch (item.kind) {\n\t\tcase \"assign\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\t...(item.path && { path: mapPath(item.path, map) }),\n\t\t\t\tvalue: map(item.value),\n\t\t\t};\n\t\tcase \"if\":\n\t\t\treturn { ...item, condition: map(item.condition) };\n\t\tcase \"switch\":\n\t\t\treturn { ...item, value: map(item.value) };\n\t\tcase \"for\":\n\t\t\treturn item.dynamic\n\t\t\t\t? {\n\t\t\t\t\t\t...item,\n\t\t\t\t\t\tdynamic: {\n\t\t\t\t\t\t\t...item.dynamic,\n\t\t\t\t\t\t\tstart: map(item.dynamic.start),\n\t\t\t\t\t\t\tlimit: map(item.dynamic.limit),\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: item;\n\t\tcase \"invoke\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\t...(item.index && { index: map(item.index) }),\n\t\t\t\targuments: item.arguments.map(map),\n\t\t\t};\n\t\tcase \"blockUpdate\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\t...(item.index && { index: map(item.index) }),\n\t\t\t\tinputs: Object.fromEntries(\n\t\t\t\t\tObject.entries(item.inputs).map(([name, input]) => [\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tmap(input),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t};\n\t\tcase \"return\":\n\t\t\treturn item.value ? { ...item, value: map(item.value) } : item;\n\t\tcase \"telemetry\":\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\tproperties: item.properties.map((property) => ({\n\t\t\t\t\t...property,\n\t\t\t\t\tvalue: map(property.value),\n\t\t\t\t\t...(property.length && { length: map(property.length) }),\n\t\t\t\t})),\n\t\t\t\t...(item.record.kind === \"exception\" && {\n\t\t\t\t\trecord: { ...item.record, code: map(item.record.code) },\n\t\t\t\t}),\n\t\t\t};\n\t\tcase \"break\":\n\t\tcase \"continue\":\n\t\t\treturn item;\n\t}\n};\n",
29
+ "import { parse } from \"node:path\";\nimport {\n\tadmitCore,\n\ttype CoreExpression,\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CorePath,\n\ttype CoreStatement,\n\tconstantIndex,\n\tmapBodies,\n\tnestedBodies,\n\ttype VerifiedCoreModule,\n} from \"./core-model\";\nimport type { Variable } from \"./model\";\nimport { mapExpression, mapPath, mapStatementExpressions } from \"./operands\";\nimport { type CoreTables, coreTables, lookup } from \"./tables\";\nimport { isValueType, type PlcType } from \"./types\";\n\n/**\n * Routines that are the same code over different storage, such as one method elaborated once per\n * instance, merged into one routine that borrows that storage. `routines` maps every routine that\n * was merged away to the one that runs in its place.\n */\nexport interface SharedRoutines {\n\tcore: VerifiedCoreModule;\n\troutines: ReadonlyMap<string, string>;\n}\n\n/**\n * Merges free routines whose bodies differ only in the persistent storage they reach. Each place a\n * routine reaches through a fixed path into module storage starts at an anchor: the place without\n * its last field, or the whole place when it ends in a constant index or reaches the first index\n * that is computed at run time. Routines with the same anchored body, declaration and partition\n * share one routine that takes each anchor that differs between them as an `InOut` parameter;\n * each call site borrows its routine's anchors. A borrowed place is the caller's storage, read and\n * written where the original routine read and wrote it, so evaluation order and aliasing are\n * unchanged. Callees merge before their callers, whose calls then differ only in what they borrow.\n *\n * `partition` keeps routines apart that must stay apart, such as those of different tasks; a\n * routine it gives no partition is left as it is.\n */\nexport function shareRoutines(\n\tcore: VerifiedCoreModule,\n\tpartition: (routine: CoreFunction) => string | undefined,\n): SharedRoutines {\n\tconst tables = coreTables(core);\n\tconst globals = new Map(core.variables.map((item) => [item.id, item]));\n\tconst entries = new Set(core.programs.map((program) => program.entry));\n\tconst bodies = new Map<string, readonly CoreStatement[]>(\n\t\t[...core.functions, ...core.blocks].map((routine) => [\n\t\t\troutine.id,\n\t\t\troutine.body,\n\t\t]),\n\t);\n\tconst merged = new Map<string, string>();\n\tconst shared = new Map<string, CoreFunction>();\n\tconst body = (id: string) => lookup(bodies, id, \"routine\");\n\n\tconst roots: Roots = {\n\t\tanchorable: (root) => {\n\t\t\tconst variable = globals.get(root);\n\t\t\treturn variable !== undefined && variable.storage !== \"constant\";\n\t\t},\n\t\tvariable: (root) => lookup(globals, root, \"variable\"),\n\t\t// A reference can only bind to plain data: a block instance or a stored reference stays where it is.\n\t\tplainData: (type) => isValueType(type, tables.types),\n\t};\n\n\tconst candidates = core.functions.filter(\n\t\t(fn) => !fn.owner && !entries.has(fn.id),\n\t);\n\tfor (const level of callLevels(candidates, body)) {\n\t\tconst groups = new Map<string, Anchored[]>();\n\t\tfor (const fn of level) {\n\t\t\tconst group = partition(fn);\n\t\t\tif (group === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst anchored = anchor({ ...fn, body: body(fn.id) }, tables, roots);\n\t\t\tif (!anchored) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst key = `${group}\\n${anchored.key}`;\n\t\t\tgroups.set(key, [...(groups.get(key) ?? []), anchored]);\n\t\t}\n\t\tconst calls = new Map<string, MergedCall>();\n\t\tfor (const members of groups.values()) {\n\t\t\tconst [first] = members;\n\t\t\tif (!first || members.length < 2) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst varying: Varying = {\n\t\t\t\tanchors: first.anchors.map((slot, index) =>\n\t\t\t\t\tmembers.some((member) => member.anchors[index]?.key !== slot.key),\n\t\t\t\t),\n\t\t\t\tconstants: constantParameters(members),\n\t\t\t};\n\t\t\tshared.set(\n\t\t\t\tfirst.fn.id,\n\t\t\t\tmergedRoutine(members, varying, roots, core.folded ?? []),\n\t\t\t);\n\t\t\tfor (const [index, member] of members.entries()) {\n\t\t\t\tif (index) {\n\t\t\t\t\tmerged.set(member.fn.id, first.fn.id);\n\t\t\t\t}\n\t\t\t\tcalls.set(member.fn.id, {\n\t\t\t\t\ttarget: first.fn.id,\n\t\t\t\t\tborrows: member.anchors.filter((_, slot) => varying.anchors[slot]),\n\t\t\t\t\tvalues: member.constants.filter(\n\t\t\t\t\t\t(_, slot) => varying.constants[slot] === slot,\n\t\t\t\t\t),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tif (!calls.size) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const [id, items] of bodies) {\n\t\t\tbodies.set(id, rewriteCalls(items, calls));\n\t\t}\n\t}\n\tif (!merged.size) {\n\t\treturn { core, routines: merged };\n\t}\n\n\tconst functions = core.functions.flatMap((fn): CoreFunction[] => {\n\t\tif (merged.has(fn.id)) {\n\t\t\treturn [];\n\t\t}\n\t\treturn [shared.get(fn.id) ?? { ...fn, body: body(fn.id) }];\n\t});\n\tconst blocks = core.blocks.map(\n\t\t(block): CoreFunctionBlock => ({ ...block, body: body(block.id) }),\n\t);\n\treturn {\n\t\tcore: admitCore({ ...core, functions, blocks }),\n\t\troutines: merged,\n\t};\n}\n\ninterface Roots {\n\t/** Whether a root is module storage, whose places a routine can borrow. */\n\tanchorable: (root: string) => boolean;\n\tvariable: (root: string) => Variable;\n\t/** Whether a type holds only data, which a reference can bind to. */\n\tplainData: (type: string) => boolean;\n}\n\n/** A place a routine reaches in module storage, from the routine's own anchor. */\ninterface Borrow {\n\troot: string;\n\tpath: CorePath;\n\ttype: string;\n}\n\ntype ConstantExpression = Extract<CoreExpression, { kind: \"constant\" }>;\n\n/** A routine's body with its anchors numbered in the order it first reaches them. */\ninterface Anchored {\n\tfn: CoreFunction;\n\tkey: string;\n\tanchors: readonly (Borrow & { key: string })[];\n\t/** Each scalar constant the body evaluates, in the order it first reaches them. */\n\tconstants: readonly ConstantExpression[];\n\t/** Each scalar constant's number, which the key writes in its place. */\n\tslots: ReadonlyMap<ConstantExpression, number>;\n}\n\n/** Candidate routines, callees before their callers. A routine's level is one more than its deepest callee's. */\nfunction callLevels(\n\tcandidates: readonly CoreFunction[],\n\tbody: (id: string) => readonly CoreStatement[],\n): CoreFunction[][] {\n\tconst levels = new Map<string, number>();\n\tconst callees = (items: readonly CoreStatement[], found: Set<string>) => {\n\t\tfor (const item of items) {\n\t\t\tif (item.kind === \"invoke\") {\n\t\t\t\tfound.add(item.function);\n\t\t\t}\n\t\t\tfor (const nested of nestedBodies(item)) {\n\t\t\t\tcallees(nested, found);\n\t\t\t}\n\t\t}\n\t\treturn found;\n\t};\n\tconst level = (id: string): number => {\n\t\tconst known = levels.get(id);\n\t\tif (known !== undefined) {\n\t\t\treturn known;\n\t\t}\n\t\tconst deepest = [...callees(body(id), new Set())].reduce(\n\t\t\t(depth, callee) => Math.max(depth, level(callee) + 1),\n\t\t\t0,\n\t\t);\n\t\tlevels.set(id, deepest);\n\t\treturn deepest;\n\t};\n\tconst ordered: CoreFunction[][] = [];\n\tfor (const fn of candidates) {\n\t\tconst depth = level(fn.id);\n\t\tordered[depth] = [...(ordered[depth] ?? []), fn];\n\t}\n\treturn ordered.filter((items) => items !== undefined);\n}\n\n/** The fixed part of a place that an anchor holds, by the rule `shareRoutines` describes. */\nfunction anchorLength(path: CorePath): number {\n\tconst dynamic = path.findIndex(\n\t\t(segment) =>\n\t\t\tsegment.kind === \"index\" && constantIndex(segment.value) === undefined,\n\t);\n\tif (dynamic >= 0) {\n\t\treturn dynamic;\n\t}\n\treturn path.at(-1)?.kind === \"field\" ? path.length - 1 : path.length;\n}\n\nconst constantText = (segment: CorePath[number]) =>\n\tsegment.kind === \"field\"\n\t\t? `.${segment.name}`\n\t\t: `[${segment.value.kind === \"constant\" ? JSON.stringify(segment.value.value) : \"?\"}]`;\n\n/**\n * Numbers a routine's anchors and scalar constants and writes its body with each anchored place\n * as its anchor's number and the rest of its path, each constant as its number, and its own\n * variables by position. Two routines with the same key run the same statements over their own\n * anchors and constants. Undefined when a place cannot be anchored the same way in every routine,\n * such as a loop counter in module storage.\n */\nfunction anchor(\n\tfn: CoreFunction,\n\ttables: CoreTables,\n\troots: Roots,\n): Anchored | undefined {\n\tconst own = new Map(\n\t\t[...fn.parameters, ...fn.locals].map((variable, index) => [\n\t\t\tvariable.id,\n\t\t\t`#${index}`,\n\t\t]),\n\t);\n\tconst anchors: (Borrow & { key: string })[] = [];\n\tconst slots = new Map<ConstantExpression, number>();\n\tconst numbers = new Map<string, number>();\n\tconst rewrite: PlaceRewrite = {\n\t\tconstant: (value) => {\n\t\t\tif (!scalarConstant(value, tables.types)) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\tconst slot = slots.get(value) ?? slots.size;\n\t\t\tslots.set(value, slot);\n\t\t\treturn {\n\t\t\t\tkind: \"load\",\n\t\t\t\ttype: value.type,\n\t\t\t\tspan: value.span,\n\t\t\t\troot: `$${slot}`,\n\t\t\t};\n\t\t},\n\t\tplace: (root, path, index) => {\n\t\t\tif (!roots.anchorable(root)) {\n\t\t\t\treturn { root: own.get(root) ?? root, path: mapPath(path, index) };\n\t\t\t}\n\t\t\tconst { fixed, key } = anchorOf(root, path);\n\t\t\tconst rest = mapPath(path.slice(fixed.length), index);\n\t\t\tconst known = numbers.get(key);\n\t\t\tif (known !== undefined) {\n\t\t\t\treturn { root: `@${known}`, path: rest };\n\t\t\t}\n\t\t\tconst type = tables.placeType(roots.variable(root).type, fixed)?.id;\n\t\t\tif (type === undefined) {\n\t\t\t\tthrow new Unanchored();\n\t\t\t}\n\t\t\t// A block instance is not borrowed: its place stays as written, the same in every routine or none.\n\t\t\tif (!roots.plainData(type)) {\n\t\t\t\treturn { root, path: [...fixed, ...rest] };\n\t\t\t}\n\t\t\tnumbers.set(key, anchors.length);\n\t\t\tanchors.push({ root, path: fixed, type, key });\n\t\t\treturn { root: `@${anchors.length - 1}`, path: rest };\n\t\t},\n\t\tidentity: (root) => {\n\t\t\tif (roots.anchorable(root)) {\n\t\t\t\tthrow new Unanchored();\n\t\t\t}\n\t\t\treturn own.get(root) ?? root;\n\t\t},\n\t};\n\ttry {\n\t\tconst body = rewriteStatements(fn.body, rewrite);\n\t\t// Not the name: the elaborator numbers each instance's copy of a routine. The declaration\n\t\t// and the body say what it does.\n\t\tconst signature = {\n\t\t\tspan: fn.span,\n\t\t\tresult: fn.result,\n\t\t\tparameters: fn.parameters.map(({ id, ...rest }) => rest),\n\t\t\tlocals: fn.locals.map(({ id, ...rest }) => rest),\n\t\t\tanchors: anchors.map((item) => item.type),\n\t\t};\n\t\treturn {\n\t\t\tfn,\n\t\t\tkey: JSON.stringify([signature, body]),\n\t\t\tanchors,\n\t\t\tconstants: [...slots.keys()],\n\t\t\tslots,\n\t\t};\n\t} catch (cause) {\n\t\tif (cause instanceof Unanchored) {\n\t\t\treturn undefined;\n\t\t}\n\t\tthrow cause;\n\t}\n}\n\n/** A place's anchor, and the key that identifies it. */\nconst anchorOf = (root: string, path: CorePath) => {\n\tconst fixed = path.slice(0, anchorLength(path));\n\treturn { fixed, key: `${root}${fixed.map(constantText).join(\"\")}` };\n};\n\n/**\n * Each constant's parameter, by number: undefined when every routine of the group evaluates the\n * same value there, else the first constant whose values in every routine are the same as its\n * own, so a value the routines take at several places is one parameter.\n */\nfunction constantParameters(\n\tmembers: readonly Anchored[],\n): (number | undefined)[] {\n\tconst [first] = members;\n\tconst firstSlots = new Map<string, number>();\n\treturn (first?.constants ?? []).map((constant, index) => {\n\t\tconst values = members.map((member) => member.constants[index]?.value);\n\t\tif (\n\t\t\tvalues.every(\n\t\t\t\t(value) => JSON.stringify(value) === JSON.stringify(constant.value),\n\t\t\t)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst key = JSON.stringify([constant.type, values]);\n\t\tconst slot = firstSlots.get(key) ?? index;\n\t\tfirstSlots.set(key, slot);\n\t\treturn slot;\n\t});\n}\n\n/**\n * The first routine of a group, taking each anchor that differs between the routines as an\n * `InOut` parameter after its own parameters, then each constant that differs as a value\n * parameter. Anchors and constants all of them share stay in place. Each parameter is named for\n * what it holds: an anchor for its path, a constant for the field setup folded it from.\n */\nfunction mergedRoutine(\n\tmembers: readonly Anchored[],\n\tvarying: Varying,\n\troots: Roots,\n\tfolded: Folded,\n): CoreFunction {\n\tconst [{ fn, anchors, constants, slots }] = required(members);\n\tconst anchorNames = borrowNames(members, varying, roots);\n\tconst borrowed = new Map<number, Variable>();\n\tfor (const [index, slot] of anchors.entries()) {\n\t\tconst name = anchorNames.get(index);\n\t\tif (name === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tborrowed.set(index, {\n\t\t\tid: `${fn.id}:anchor${index}`,\n\t\t\tname,\n\t\t\ttype: slot.type,\n\t\t\tstorage: \"parameter\",\n\t\t\tmutable: true,\n\t\t\tretention: \"none\",\n\t\t\tmode: \"inOut\",\n\t\t\tspan: fn.span,\n\t\t});\n\t}\n\tconst values = new Map<number, Variable>();\n\tfor (const [index, constant] of constants.entries()) {\n\t\tif (varying.constants[index] === index) {\n\t\t\tvalues.set(index, {\n\t\t\t\tid: `${fn.id}:value${index}`,\n\t\t\t\tname: foldedName(members, index, folded) ?? \"value\",\n\t\t\t\ttype: constant.type,\n\t\t\t\tstorage: \"parameter\",\n\t\t\t\tmutable: false,\n\t\t\t\tretention: \"none\",\n\t\t\t\tspan: fn.span,\n\t\t\t});\n\t\t}\n\t}\n\tconst anchorSlots = new Map(anchors.map((slot, index) => [slot.key, index]));\n\tconst parameter = (\n\t\tparameters: ReadonlyMap<number, Variable>,\n\t\tslot: number | undefined,\n\t) => (slot === undefined ? undefined : parameters.get(slot));\n\tconst rewrite: PlaceRewrite = {\n\t\tconstant: (value) => {\n\t\t\tconst slot = slots.get(value);\n\t\t\tconst replacement = parameter(\n\t\t\t\tvalues,\n\t\t\t\tslot === undefined ? undefined : varying.constants[slot],\n\t\t\t);\n\t\t\treturn replacement\n\t\t\t\t? {\n\t\t\t\t\t\tkind: \"load\",\n\t\t\t\t\t\ttype: value.type,\n\t\t\t\t\t\tspan: value.span,\n\t\t\t\t\t\troot: replacement.id,\n\t\t\t\t\t}\n\t\t\t\t: value;\n\t\t},\n\t\tplace: (root, path, index) => {\n\t\t\tif (!roots.anchorable(root)) {\n\t\t\t\treturn { root, path: mapPath(path, index) };\n\t\t\t}\n\t\t\tconst { fixed, key } = anchorOf(root, path);\n\t\t\tconst rest = mapPath(path.slice(fixed.length), index);\n\t\t\tconst borrow = parameter(borrowed, anchorSlots.get(key));\n\t\t\treturn borrow\n\t\t\t\t? { root: borrow.id, path: rest }\n\t\t\t\t: { root, path: [...fixed, ...rest] };\n\t\t},\n\t\tidentity: (root) => root,\n\t};\n\treturn {\n\t\t...fn,\n\t\tparameters: [...fn.parameters, ...borrowed.values(), ...values.values()],\n\t\tbody: rewriteStatements(fn.body, rewrite),\n\t};\n}\n\n/** Which anchors differ between the routines of a group, and each constant's parameter, by number. */\ninterface Varying {\n\tanchors: readonly boolean[];\n\tconstants: readonly (number | undefined)[];\n}\n\ntype Folded = NonNullable<VerifiedCoreModule[\"folded\"]>;\n\nconst required = <T>(items: readonly T[]): [T, ...T[]] => {\n\tconst [first, ...rest] = items;\n\tif (first === undefined) {\n\t\tthrow new Error(\"A merged group has routines.\");\n\t}\n\treturn [first, ...rest];\n};\n\n/**\n * The field a constant parameter stands for: the one field of each routine's instance that setup\n * folded to the value the routine evaluates there, as `settle.durationMs` of `pumps[0]` is 500.\n * Undefined when a routine has no instance or no single field answers in every routine.\n */\nfunction foldedName(\n\tmembers: readonly Anchored[],\n\tslot: number,\n\tfolded: Folded,\n): string | undefined {\n\tconst fields = members.map((member) => {\n\t\tconst instance = member.fn.origin?.instance;\n\t\tconst constant = member.constants[slot];\n\t\tif (instance === undefined || constant === undefined) {\n\t\t\treturn new Set<string>();\n\t\t}\n\t\treturn new Set(\n\t\t\tfolded.flatMap((item) =>\n\t\t\t\titem.path.startsWith(`${instance}.`) &&\n\t\t\t\tJSON.stringify(item.value) === JSON.stringify(constant.value)\n\t\t\t\t\t? [item.path.slice(instance.length + 1)]\n\t\t\t\t\t: [],\n\t\t\t),\n\t\t);\n\t});\n\tconst [first, ...rest] = fields;\n\tconst shared = [...(first ?? [])].filter((field) =>\n\t\trest.every((other) => other.has(field)),\n\t);\n\tconst [only, ...others] = shared;\n\treturn only !== undefined && !others.length\n\t\t? only.replace(/[.[\\]]+/g, \"_\").replace(/_$/, \"\")\n\t\t: undefined;\n}\n\n/**\n * Each borrowed anchor's name, by number: its full fixed path, as `track_bins`, where an index\n * that differs between the routines reads `item`, since no one name can hold the index each call\n * passes, and a root or field that differs is left out. Anchors of different modules that would\n * share a name are told apart by their module.\n */\nfunction borrowNames(\n\tmembers: readonly Anchored[],\n\tvarying: Varying,\n\troots: Roots,\n): Map<number, string> {\n\tconst words = (borrow: Borrow): string[] => [\n\t\troots.variable(borrow.root).name,\n\t\t...borrow.path.map((segment) =>\n\t\t\tsegment.kind === \"field\"\n\t\t\t\t? segment.name\n\t\t\t\t: String(constantIndex(segment.value) ?? \"item\"),\n\t\t),\n\t];\n\tconst [first] = required(members);\n\tconst names = new Map<number, string>();\n\tfor (const [index, slot] of first.anchors.entries()) {\n\t\tif (!varying.anchors[index]) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst each = members.map((member) => {\n\t\t\tconst borrow = member.anchors[index];\n\t\t\treturn borrow ? words(borrow) : [];\n\t\t});\n\t\tconst own = words(slot);\n\t\tconst name = own.flatMap((word, position) => {\n\t\t\tif (each.every((other) => other[position] === word)) {\n\t\t\t\treturn [word];\n\t\t\t}\n\t\t\tconst segment = slot.path[position - 1];\n\t\t\treturn segment?.kind === \"index\" ? [\"item\"] : [];\n\t\t});\n\t\tnames.set(index, name.join(\"_\") || \"item\");\n\t}\n\tconst module = (index: number): string => {\n\t\tconst slot = first.anchors[index];\n\t\treturn slot ? parse(roots.variable(slot.root).span.file).name : \"\";\n\t};\n\tconst modules = new Map<string, Set<string>>();\n\tfor (const [index, name] of names) {\n\t\tmodules.set(name, (modules.get(name) ?? new Set()).add(module(index)));\n\t}\n\treturn new Map(\n\t\t[...names].map(([index, name]) => [\n\t\t\tindex,\n\t\t\t(modules.get(name)?.size ?? 0) > 1 ? `${module(index)}_${name}` : name,\n\t\t]),\n\t);\n}\n\n/** What a call to a merged routine adds after its own arguments. */\ninterface MergedCall {\n\ttarget: string;\n\tborrows: readonly Borrow[];\n\tvalues: readonly CoreExpression[];\n}\n\n/** Calls to merged routines go to the routine that runs in their place, borrowing their anchors. */\nfunction rewriteCalls(\n\titems: readonly CoreStatement[],\n\tcalls: ReadonlyMap<string, MergedCall>,\n): CoreStatement[] {\n\treturn items.map((item): CoreStatement => {\n\t\tif (item.kind !== \"invoke\") {\n\t\t\treturn mapBodies(item, (body) => rewriteCalls(body, calls));\n\t\t}\n\t\tconst call = calls.get(item.function);\n\t\tif (!call) {\n\t\t\treturn item;\n\t\t}\n\t\treturn {\n\t\t\t...item,\n\t\t\tfunction: call.target,\n\t\t\targuments: [\n\t\t\t\t...item.arguments,\n\t\t\t\t...call.borrows.map(\n\t\t\t\t\t(borrow): CoreExpression => ({\n\t\t\t\t\t\tkind: \"borrow\",\n\t\t\t\t\t\ttype: borrow.type,\n\t\t\t\t\t\tspan: item.span,\n\t\t\t\t\t\tplace: { root: borrow.root, path: borrow.path },\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\t// A fresh constant per call site: every call to one routine shares `call.values`, and `anchor`\n\t\t\t\t// gives a repeated constant object one slot.\n\t\t\t\t...call.values.map((value) => ({ ...value })),\n\t\t\t],\n\t\t};\n\t});\n}\n\nclass Unanchored extends Error {}\n\ninterface PlaceRewrite {\n\t/** A place and the rewrite of each index along it. */\n\tplace: (\n\t\troot: string,\n\t\tpath: CorePath,\n\t\tindex: (value: CoreExpression) => CoreExpression,\n\t) => { root: string; path: CorePath };\n\t/** A root a statement names without a path: a loop counter, call destination or block instance. */\n\tidentity: (root: string) => string;\n\t/** A constant the body evaluates; case labels and loop bounds are not expressions. */\n\tconstant: (value: ConstantExpression) => CoreExpression;\n}\n\n/** Constants a routine can take as a value parameter instead: scalars of an elementary or enum type. */\nconst scalarConstant = (\n\tvalue: ConstantExpression,\n\ttypes: ReadonlyMap<string, PlcType>,\n) =>\n\t[\"bool\", \"integer\", \"float\", \"duration\", \"calendar\"].includes(\n\t\tvalue.value.kind,\n\t) && types.get(value.type)?.kind !== \"string\";\n\nfunction rewriteExpression(\n\tvalue: CoreExpression,\n\trewrite: PlaceRewrite,\n): CoreExpression {\n\tconst index = (operand: CoreExpression) =>\n\t\trewriteExpression(operand, rewrite);\n\tif (value.kind === \"constant\") {\n\t\treturn rewrite.constant(value);\n\t}\n\tif (value.kind === \"load\") {\n\t\tconst place = rewrite.place(value.root, value.path ?? [], index);\n\t\treturn {\n\t\t\t...value,\n\t\t\troot: place.root,\n\t\t\t...(value.path || place.path.length ? { path: place.path } : {}),\n\t\t};\n\t}\n\tif (value.kind === \"borrow\") {\n\t\treturn {\n\t\t\t...value,\n\t\t\tplace: rewrite.place(value.place.root, value.place.path, index),\n\t\t};\n\t}\n\treturn mapExpression(value, index);\n}\n\nfunction rewriteStatements(\n\titems: readonly CoreStatement[],\n\trewrite: PlaceRewrite,\n): CoreStatement[] {\n\treturn items.map((item) => rewriteStatement(item, rewrite));\n}\n\nfunction rewriteStatement(\n\titem: CoreStatement,\n\trewrite: PlaceRewrite,\n): CoreStatement {\n\tconst expression = (value: CoreExpression) =>\n\t\trewriteExpression(value, rewrite);\n\tconst statements = (body: readonly CoreStatement[]) =>\n\t\trewriteStatements(body, rewrite);\n\tswitch (item.kind) {\n\t\tcase \"assign\": {\n\t\t\tconst place = rewrite.place(item.root, item.path ?? [], expression);\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\troot: place.root,\n\t\t\t\t...(item.path || place.path.length ? { path: place.path } : {}),\n\t\t\t\tvalue: expression(item.value),\n\t\t\t};\n\t\t}\n\t\tcase \"for\":\n\t\t\treturn mapBodies(\n\t\t\t\tmapStatementExpressions(\n\t\t\t\t\t{ ...item, counter: rewrite.identity(item.counter) },\n\t\t\t\t\texpression,\n\t\t\t\t),\n\t\t\t\tstatements,\n\t\t\t);\n\t\tcase \"invoke\":\n\t\t\treturn mapStatementExpressions(\n\t\t\t\t{\n\t\t\t\t\t...item,\n\t\t\t\t\t...(item.instance !== undefined && {\n\t\t\t\t\t\tinstance: rewrite.identity(item.instance),\n\t\t\t\t\t}),\n\t\t\t\t\t...(item.destination !== undefined && {\n\t\t\t\t\t\tdestination: rewrite.identity(item.destination),\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t\texpression,\n\t\t\t);\n\t\tcase \"blockUpdate\":\n\t\t\treturn mapStatementExpressions(\n\t\t\t\t{ ...item, instance: rewrite.identity(item.instance) },\n\t\t\t\texpression,\n\t\t\t);\n\t\tcase \"if\":\n\t\tcase \"switch\":\n\t\tcase \"return\":\n\t\tcase \"telemetry\":\n\t\tcase \"break\":\n\t\tcase \"continue\":\n\t\t\treturn mapBodies(mapStatementExpressions(item, expression), statements);\n\t}\n}\n\n/** A routine that only returns a constant, or does nothing: what each of its calls amounts to. */\nfunction constantResult(\n\tfn: CoreFunction,\n): { value?: CoreExpression } | undefined {\n\tconst [only, ...rest] = fn.body;\n\tif (rest.length || fn.owner) {\n\t\treturn undefined;\n\t}\n\tif (!only) {\n\t\treturn fn.result ? undefined : {};\n\t}\n\tif (only.kind !== \"return\") {\n\t\treturn undefined;\n\t}\n\tif (!only.value) {\n\t\treturn fn.result ? undefined : {};\n\t}\n\treturn only.value.kind === \"constant\" ? { value: only.value } : undefined;\n}\n\n/** The path a load or borrow reads through. */\nconst placePath = (value: CoreExpression): CorePath | undefined => {\n\tif (value.kind === \"load\") {\n\t\treturn value.path ?? [];\n\t}\n\treturn value.kind === \"borrow\" ? value.place.path : undefined;\n};\n\n/** Arguments that reading cannot fault: loads, borrows and constants, without arithmetic in their indexes. */\nconst plainArgument = (value: CoreExpression): boolean => {\n\tif (value.kind === \"constant\") {\n\t\treturn true;\n\t}\n\treturn (\n\t\tplacePath(value)?.every(\n\t\t\t(segment) => segment.kind === \"field\" || plainArgument(segment.value),\n\t\t) ?? false\n\t);\n};\n\n/**\n * Replaces each call of a routine that only returns a constant with an assignment of that\n * constant, and drops each call of one that does nothing. A call whose arguments compute\n * something stays, so evaluating them can still fault as it would have. Routines no call\n * reaches any more, other than program entries, are dropped.\n */\nexport function foldConstantRoutines(core: VerifiedCoreModule): {\n\tcore: VerifiedCoreModule;\n\troutines: ReadonlySet<string>;\n} {\n\tconst entries = new Set(core.programs.map((program) => program.entry));\n\tconst constants = new Map(\n\t\tcore.functions.flatMap((fn) => {\n\t\t\tconst result = entries.has(fn.id) ? undefined : constantResult(fn);\n\t\t\treturn result ? [[fn.id, result] as const] : [];\n\t\t}),\n\t);\n\tif (!constants.size) {\n\t\treturn { core, routines: new Set() };\n\t}\n\tconst called = new Set<string>();\n\tconst fold = (items: readonly CoreStatement[]): CoreStatement[] =>\n\t\titems.flatMap((item): CoreStatement[] => {\n\t\t\tif (item.kind !== \"invoke\") {\n\t\t\t\treturn [mapBodies(item, fold)];\n\t\t\t}\n\t\t\tconst result = constants.get(item.function);\n\t\t\tif (!result || !item.arguments.every(plainArgument)) {\n\t\t\t\tcalled.add(item.function);\n\t\t\t\treturn [item];\n\t\t\t}\n\t\t\tif (item.destination === undefined || !result.value) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\tspan: item.span,\n\t\t\t\t\troot: item.destination,\n\t\t\t\t\tvalue: { ...result.value, span: item.span },\n\t\t\t\t},\n\t\t\t];\n\t\t});\n\tconst functions = core.functions.map((fn) => ({\n\t\t...fn,\n\t\tbody: fold(fn.body),\n\t}));\n\tconst blocks = core.blocks.map(\n\t\t(block): CoreFunctionBlock => ({ ...block, body: fold(block.body) }),\n\t);\n\tconst routines = new Set(\n\t\t[...constants.keys()].filter((id) => !called.has(id)),\n\t);\n\treturn {\n\t\tcore: admitCore({\n\t\t\t...core,\n\t\t\tfunctions: functions.filter((fn) => !routines.has(fn.id)),\n\t\t\tblocks,\n\t\t}),\n\t\troutines,\n\t};\n}\n",
30
+ "import {\n\tadmitCore,\n\ttype CoreExpression,\n\ttype CoreFunction,\n\ttype CoreFunctionBlock,\n\ttype CoreStatement,\n\tisTemporary,\n\tmapBodies,\n\tnestedBodies,\n\ttype VerifiedCoreModule,\n} from \"./core-model\";\nimport {\n\tmapExpression,\n\tmapStatementExpressions,\n\tstatementExpressions,\n\tsubexpressions,\n} from \"./operands\";\n\n/**\n * Writes a temporary's value where it is read, when nothing can happen in between: the temporary\n * is assigned once, as a whole, and read once, by the statement right after the assignment, in\n * an expression that statement evaluates before it writes or calls anything. Loop bounds and\n * switch values are left alone: ST evaluates them more than once.\n *\n * Only a load, a constant or a BOOL moves. An arithmetic value keeps its temporary, which\n * stores it at its own type: written into a wider expression, ST could compute it wider.\n */\nexport function forwardTemporaries(\n\tcore: VerifiedCoreModule,\n): VerifiedCoreModule {\n\tconst functions = core.functions.map((fn): CoreFunction => forward(fn));\n\tconst blocks = core.blocks.map((block): CoreFunctionBlock => forward(block));\n\treturn admitCore({ ...core, functions, blocks });\n}\n\nfunction forward<Routine extends CoreFunction | CoreFunctionBlock>(\n\troutine: Routine,\n): Routine {\n\tconst temporaries = new Set(\n\t\troutine.locals\n\t\t\t.filter((local) => isTemporary(routine.id, local))\n\t\t\t.map((local) => local.id),\n\t);\n\tif (!temporaries.size) {\n\t\treturn routine;\n\t}\n\tconst writes = new Map<string, number>();\n\tconst reads = new Map<string, number>();\n\tconst count = (counts: Map<string, number>, root: string) =>\n\t\tcounts.set(root, (counts.get(root) ?? 0) + 1);\n\tconst expression = (value: CoreExpression): void => {\n\t\tif (value.kind === \"load\") {\n\t\t\tcount(reads, value.root);\n\t\t}\n\t\tif (value.kind === \"borrow\") {\n\t\t\t// A borrowed temporary is written through its reference.\n\t\t\tcount(writes, value.place.root);\n\t\t\tcount(reads, value.place.root);\n\t\t}\n\t\tsubexpressions(value).forEach(expression);\n\t};\n\tconst statements = (items: readonly CoreStatement[]): void => {\n\t\tfor (const item of items) {\n\t\t\tif (item.kind === \"assign\") {\n\t\t\t\tcount(writes, item.root);\n\t\t\t}\n\t\t\tif (item.kind === \"for\") {\n\t\t\t\tcount(writes, item.counter);\n\t\t\t}\n\t\t\tif (item.kind === \"invoke\" && item.destination !== undefined) {\n\t\t\t\tcount(writes, item.destination);\n\t\t\t}\n\t\t\tstatementExpressions(item).forEach(expression);\n\t\t\tnestedBodies(item).forEach(statements);\n\t\t}\n\t};\n\tstatements(routine.body);\n\tconst movable = (\n\t\titem: CoreStatement,\n\t): item is Extract<CoreStatement, { kind: \"assign\" }> =>\n\t\titem.kind === \"assign\" &&\n\t\t!item.path?.length &&\n\t\ttemporaries.has(item.root) &&\n\t\twrites.get(item.root) === 1 &&\n\t\treads.get(item.root) === 1 &&\n\t\t(item.value.kind === \"load\" ||\n\t\t\titem.value.kind === \"constant\" ||\n\t\t\titem.value.type === \"BOOL\");\n\n\tconst forwarded = new Set<string>();\n\tconst rewrite = (items: readonly CoreStatement[]): CoreStatement[] => {\n\t\tconst result = items.map((item) => mapBodies(item, rewrite));\n\t\t// From the end, so a value can move through a chain of temporaries.\n\t\tfor (let index = result.length - 2; index >= 0; index--) {\n\t\t\tconst item = result[index];\n\t\t\tconst next = result[index + 1];\n\t\t\tif (!item || !next || !movable(item) || !readsOwn(next, item.root)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tresult.splice(index, 2, substitute(next, item.root, item.value));\n\t\t\tforwarded.add(item.root);\n\t\t}\n\t\treturn result;\n\t};\n\tconst body = rewrite(routine.body);\n\tif (!forwarded.size) {\n\t\treturn routine;\n\t}\n\treturn {\n\t\t...routine,\n\t\tlocals: routine.locals.filter((local) => !forwarded.has(local.id)),\n\t\tbody,\n\t};\n}\n\n/** Whether a statement reads `root` in what it evaluates once, before it writes or calls. */\nfunction readsOwn(item: CoreStatement, root: string): boolean {\n\tif (item.kind === \"for\" || item.kind === \"switch\") {\n\t\treturn false;\n\t}\n\tconst reads = (value: CoreExpression): boolean =>\n\t\t(value.kind === \"load\" && value.root === root) ||\n\t\tsubexpressions(value).some(reads);\n\treturn statementExpressions(item).some(reads);\n}\n\n/** A statement with its read of `root` replaced by `value`. */\nfunction substitute(\n\titem: CoreStatement,\n\troot: string,\n\tvalue: CoreExpression,\n): CoreStatement {\n\tconst replace = (expression: CoreExpression): CoreExpression =>\n\t\texpression.kind === \"load\" && expression.root === root\n\t\t\t? value\n\t\t\t: mapExpression(expression, replace);\n\treturn mapStatementExpressions(item, replace);\n}\n"
28
31
  ],
29
- "mappings": ";AAAA,yCAAyB;;;ACAzB;AAAA;AAAA;AAiDO,IAAM,sBAAmD,IAAI,IACnE,uBACD;AAuGO,IAAM,oBAAoB;AAAA,EAChC;AAAA,EACA;AAAA,MAC4B;AAAA,EAC5B,GAAI,OAAO,SAAS,cAAc,CAAC,OAAO,IAAI,IAAI,CAAC;AAAA,EACnD,GAAG,WAAW,QAAQ,GAAG,OAAO,aAC/B,SAAS,CAAC,OAAO,MAAM,IAAI,CAAC,KAAK,CAClC;AACD;AAyBA,IAAM,QAAQ,CAAC,OAAe,YAC5B;AAAA,EACA,QAAQ;AAAA,IACP,CAAC,OAAO,MAAM,MAAM;AAAA,IACpB,CAAC,YAAY,MAAM,MAAM;AAAA,EAC1B;AAAA,EACA,SAAS;AAAA,IACR,CAAC,QAAQ,KAAK,MAAM;AAAA,IACpB,CAAC,WAAW,MAAM,MAAM;AAAA,EACzB;AACD;AACM,IAAM,iBAAiB;AAAA,EAC7B,cAAc,EAAE,QAAQ,UAAU,MAAM,WAAW,MAAM,EAAE;AAAA,EAC3D,eAAe,EAAE,QAAQ,UAAU,MAAM,WAAW,QAAQ,EAAE;AAAA,EAC9D,YAAY,EAAE,QAAQ,SAAS,MAAM,SAAS,QAAQ,EAAE;AAAA,E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