@tsplc/tmp-compiler 0.0.0-stage → 0.6.2

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 (184) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -2
  3. package/dist/cli.js +2325 -0
  4. package/dist/cli.js.map +26 -0
  5. package/dist/clock.js +11 -0
  6. package/dist/clock.js.map +11 -0
  7. package/dist/codesys.js +6558 -0
  8. package/dist/codesys.js.map +51 -0
  9. package/dist/collections.js +399 -0
  10. package/dist/collections.js.map +10 -0
  11. package/dist/index.js +16076 -0
  12. package/dist/index.js.map +61 -0
  13. package/dist/ir.js +3948 -0
  14. package/dist/ir.js.map +35 -0
  15. package/dist/retain.js +10 -0
  16. package/dist/retain.js.map +10 -0
  17. package/dist/signals.js +115 -0
  18. package/dist/signals.js.map +10 -0
  19. package/dist/telemetry.js +121 -0
  20. package/dist/telemetry.js.map +12 -0
  21. package/package.json +122 -4
  22. package/src/codesys/config.ts +50 -0
  23. package/src/codesys/debug.ts +655 -0
  24. package/src/codesys/emit.ts +185 -0
  25. package/src/codesys/endpoints.ts +111 -0
  26. package/src/codesys/engineering.ts +96 -0
  27. package/src/codesys/explain/expressions.ts +445 -0
  28. package/src/codesys/explain/flags.ts +134 -0
  29. package/src/codesys/explain/parameters.ts +53 -0
  30. package/src/codesys/explain/rows.ts +182 -0
  31. package/src/codesys/explain/tables.ts +79 -0
  32. package/src/codesys/explain/tasks.ts +68 -0
  33. package/src/codesys/explain/writes.ts +497 -0
  34. package/src/codesys/explain.ts +149 -0
  35. package/src/codesys/expressions.ts +100 -0
  36. package/src/codesys/global-lists.ts +284 -0
  37. package/src/codesys/global-names.ts +66 -0
  38. package/src/codesys/http.ts +1078 -0
  39. package/src/codesys/index.ts +13 -0
  40. package/src/codesys/instrumentation.ts +574 -0
  41. package/src/codesys/io-paths.ts +149 -0
  42. package/src/codesys/loops.ts +101 -0
  43. package/src/codesys/manifest.ts +684 -0
  44. package/src/codesys/names.ts +58 -0
  45. package/src/codesys/numeric.ts +516 -0
  46. package/src/codesys/plan.ts +688 -0
  47. package/src/codesys/programs.ts +138 -0
  48. package/src/codesys/publication.ts +99 -0
  49. package/src/codesys/required.ts +8 -0
  50. package/src/codesys/routines.ts +247 -0
  51. package/src/codesys/scan-clock.ts +103 -0
  52. package/src/codesys/scheduling.ts +96 -0
  53. package/src/codesys/service-channels.ts +24 -0
  54. package/src/codesys/sources.ts +118 -0
  55. package/src/codesys/st-files.ts +219 -0
  56. package/src/codesys/statements.ts +409 -0
  57. package/src/codesys/storage.ts +150 -0
  58. package/src/codesys/symbols.ts +240 -0
  59. package/src/codesys/task-access.ts +186 -0
  60. package/src/codesys/telemetry-settings.ts +19 -0
  61. package/src/codesys/telemetry.ts +852 -0
  62. package/src/codesys/types.ts +310 -0
  63. package/src/codesys/vendor.ts +113 -0
  64. package/src/frontend/analyzer.ts +779 -0
  65. package/src/frontend/async.ts +530 -0
  66. package/src/frontend/blocks.ts +578 -0
  67. package/src/frontend/configuration.ts +83 -0
  68. package/src/frontend/const-functions.ts +204 -0
  69. package/src/frontend/control-flow.ts +787 -0
  70. package/src/frontend/cooperative.ts +114 -0
  71. package/src/frontend/coroutines.ts +1336 -0
  72. package/src/frontend/dialect-names.ts +104 -0
  73. package/src/frontend/elaborate/array-searches.ts +224 -0
  74. package/src/frontend/elaborate/assignments.ts +343 -0
  75. package/src/frontend/elaborate/calls.ts +1342 -0
  76. package/src/frontend/elaborate/capture-protocol.ts +237 -0
  77. package/src/frontend/elaborate/capture.ts +388 -0
  78. package/src/frontend/elaborate/declarations.ts +124 -0
  79. package/src/frontend/elaborate/dialect.ts +473 -0
  80. package/src/frontend/elaborate/expressions.ts +2171 -0
  81. package/src/frontend/elaborate/filtered-arrays.ts +643 -0
  82. package/src/frontend/elaborate/frame.ts +145 -0
  83. package/src/frontend/elaborate/generics.ts +123 -0
  84. package/src/frontend/elaborate/graph.ts +141 -0
  85. package/src/frontend/elaborate/imports.ts +105 -0
  86. package/src/frontend/elaborate/index.ts +851 -0
  87. package/src/frontend/elaborate/initializers.ts +235 -0
  88. package/src/frontend/elaborate/iterators.ts +1541 -0
  89. package/src/frontend/elaborate/layouts.ts +1025 -0
  90. package/src/frontend/elaborate/model.ts +478 -0
  91. package/src/frontend/elaborate/names.ts +134 -0
  92. package/src/frontend/elaborate/reduce.ts +900 -0
  93. package/src/frontend/elaborate/references.ts +727 -0
  94. package/src/frontend/elaborate/retention.ts +284 -0
  95. package/src/frontend/elaborate/specialize.ts +1137 -0
  96. package/src/frontend/elaborate/statements.ts +1220 -0
  97. package/src/frontend/elaborate/storage.ts +836 -0
  98. package/src/frontend/elaborate/time-constructors.ts +34 -0
  99. package/src/frontend/elaborate/values.ts +200 -0
  100. package/src/frontend/elaborate/writes.ts +415 -0
  101. package/src/frontend/expressions.ts +1382 -0
  102. package/src/frontend/generated-names.ts +95 -0
  103. package/src/frontend/intrinsics.ts +382 -0
  104. package/src/frontend/lowering-key.ts +23 -0
  105. package/src/frontend/module-graph.ts +156 -0
  106. package/src/frontend/positions.ts +359 -0
  107. package/src/frontend/promise-chains.ts +872 -0
  108. package/src/frontend/promises.ts +419 -0
  109. package/src/frontend/routines.ts +239 -0
  110. package/src/frontend/sdk.ts +187 -0
  111. package/src/frontend/services.ts +609 -0
  112. package/src/frontend/statements.ts +871 -0
  113. package/src/frontend/tasks.ts +526 -0
  114. package/src/frontend/telemetry.ts +174 -0
  115. package/src/frontend/types.ts +1073 -0
  116. package/src/frontend/typescript.ts +651 -0
  117. package/src/index.ts +9 -0
  118. package/src/ir/aggregates.ts +291 -0
  119. package/src/ir/allocation.ts +96 -0
  120. package/src/ir/conditions.ts +855 -0
  121. package/src/ir/core-model.ts +289 -0
  122. package/src/ir/declarations.ts +281 -0
  123. package/src/ir/diagnostics.ts +68 -0
  124. package/src/ir/domains.ts +151 -0
  125. package/src/ir/fold.ts +279 -0
  126. package/src/ir/identity.ts +19 -0
  127. package/src/ir/index.ts +137 -0
  128. package/src/ir/job-errors.ts +69 -0
  129. package/src/ir/layouts.ts +211 -0
  130. package/src/ir/link.ts +302 -0
  131. package/src/ir/model.ts +394 -0
  132. package/src/ir/normalization-error.ts +10 -0
  133. package/src/ir/normalize.ts +52 -0
  134. package/src/ir/numeric.ts +163 -0
  135. package/src/ir/operands.ts +160 -0
  136. package/src/ir/ranges.ts +420 -0
  137. package/src/ir/routine.ts +1116 -0
  138. package/src/ir/scalars.ts +453 -0
  139. package/src/ir/share.ts +790 -0
  140. package/src/ir/short-circuit.ts +140 -0
  141. package/src/ir/tables.ts +111 -0
  142. package/src/ir/temporaries.ts +138 -0
  143. package/src/ir/types.ts +151 -0
  144. package/src/project/artifacts.ts +424 -0
  145. package/src/project/cli.ts +211 -0
  146. package/src/project/debugger.ts +111 -0
  147. package/src/project/deployments.ts +387 -0
  148. package/src/project/flags.ts +14 -0
  149. package/src/project/git.ts +35 -0
  150. package/src/project/plant.ts +629 -0
  151. package/src/project/project-commands.ts +507 -0
  152. package/src/project/project.ts +559 -0
  153. package/src/project/release.ts +152 -0
  154. package/src/project/server-check.ts +54 -0
  155. package/src/project/server.ts +165 -0
  156. package/src/project/terminal.ts +45 -0
  157. package/src/runtime/async.ts +207 -0
  158. package/src/runtime/launch.ts +59 -0
  159. package/src/runtime/main.ts +59 -0
  160. package/src/runtime/missing-file.ts +3 -0
  161. package/src/runtime/process.ts +177 -0
  162. package/src/runtime/program.ts +109 -0
  163. package/src/runtime/retain.ts +108 -0
  164. package/src/runtime/runtime.ts +324 -0
  165. package/src/runtime/settings.ts +27 -0
  166. package/src/runtime/storage.ts +456 -0
  167. package/src/runtime/symbols.ts +97 -0
  168. package/src/runtime/telemetry.ts +154 -0
  169. package/src/runtime/transport.ts +168 -0
  170. package/stdlib/clock.ts +8 -0
  171. package/stdlib/collections.ts +534 -0
  172. package/stdlib/plc-time.ts +2 -0
  173. package/stdlib/retain.ts +4 -0
  174. package/stdlib/signals.ts +142 -0
  175. package/stdlib/telemetry.ts +89 -0
  176. package/types/async.d.ts +87 -0
  177. package/types/clock.d.ts +8 -0
  178. package/types/config.d.ts +2 -0
  179. package/types/data-types.d.ts +31 -0
  180. package/types/dialect.d.ts +49 -0
  181. package/types/globals.d.ts +10 -0
  182. package/types/index.d.ts +212 -0
  183. package/types/retain.d.ts +12 -0
  184. package/types/telemetry.d.ts +47 -0
@@ -0,0 +1,61 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/frontend/typescript.ts", "../src/frontend/analyzer.ts", "../src/frontend/blocks.ts", "../src/frontend/types.ts", "../src/frontend/lowering-key.ts", "../src/frontend/sdk.ts", "../src/frontend/expressions.ts", "../src/frontend/intrinsics.ts", "../src/frontend/module-graph.ts", "../src/frontend/routines.ts", "../src/frontend/statements.ts", "../src/frontend/telemetry.ts", "../src/frontend/async.ts", "../src/frontend/coroutines.ts", "../src/frontend/cooperative.ts", "../src/frontend/positions.ts", "../src/frontend/tasks.ts", "../src/frontend/generated-names.ts", "../src/frontend/configuration.ts", "../src/frontend/const-functions.ts", "../src/frontend/control-flow.ts", "../src/frontend/promise-chains.ts", "../src/frontend/dialect-names.ts", "../src/frontend/elaborate/index.ts", "../src/frontend/elaborate/generics.ts", "../src/frontend/elaborate/graph.ts", "../src/frontend/elaborate/capture-protocol.ts", "../src/frontend/elaborate/writes.ts", "../src/frontend/elaborate/imports.ts", "../src/frontend/elaborate/layouts.ts", "../src/frontend/elaborate/model.ts", "../src/frontend/elaborate/names.ts", "../src/frontend/elaborate/values.ts", "../src/frontend/elaborate/reduce.ts", "../src/frontend/elaborate/retention.ts", "../src/frontend/elaborate/specialize.ts", "../src/frontend/elaborate/declarations.ts", "../src/frontend/elaborate/dialect.ts", "../src/frontend/elaborate/references.ts", "../src/frontend/elaborate/assignments.ts", "../src/frontend/elaborate/time-constructors.ts", "../src/frontend/elaborate/expressions.ts", "../src/frontend/elaborate/calls.ts", "../src/frontend/elaborate/array-searches.ts", "../src/frontend/elaborate/filtered-arrays.ts", "../src/frontend/elaborate/iterators.ts", "../src/frontend/elaborate/frame.ts", "../src/frontend/elaborate/initializers.ts", "../src/frontend/elaborate/storage.ts", "../src/frontend/elaborate/statements.ts", "../src/frontend/promises.ts", "../src/frontend/services.ts"],
4
+ "sourcesContent": [
5
+ "import { mkdirSync, writeFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, join, relative, resolve } from \"node:path\";\nimport { type Diagnostic, hasErrors, type PlcModule } from \"@tsplc/compiler/ir\";\nimport type { Environment } from \"@tsplc/config\";\nimport { generatedDirectory } from \"@tsplc/config/project-files\";\nimport ts from \"typescript\";\nimport { Analyzer, suppressionDiagnostics } from \"./analyzer\";\nimport { type AsyncLowering, lowerAsync } from \"./async\";\nimport { lowerEnvironment } from \"./configuration\";\nimport { lowerConstFunctions } from \"./const-functions\";\nimport { lowerControlFlow } from \"./control-flow\";\nimport { dialectUses } from \"./dialect-names\";\nimport { lowerElaboration } from \"./elaborate/index\";\nimport { declarationKey, typeKey } from \"./lowering-key\";\nimport { runtimeSources } from \"./module-graph\";\nimport { type Mapped, Positions, sourceSpan } from \"./positions\";\nimport { lowerPromises } from \"./promises\";\nimport { dialectFor, inSdk, sdkFor } from \"./sdk\";\nimport { lowerServices, type ServiceOptions, serviceRecords } from \"./services\";\n\n/** What a compilation writes or adds to help debug the compiler itself. */\nexport interface CompileDebug {\n\t/** Writes every module the compiler generates or rewrites here, as the next step reads it. */\n\tlowered: string | null;\n\t/** Adds stack traces to elaboration errors. */\n\tstackTraces: boolean;\n}\n\n/** The documented switches: `TSPLC_LOWERED=<directory>` and `TSPLC_DEBUG=1`. */\nconst compileDebug = (environment: Environment): CompileDebug => ({\n\tlowered: environment.TSPLC_LOWERED || null,\n\tstackTraces: Boolean(environment.TSPLC_DEBUG),\n});\n\nexport interface FrontendOptions {\n\tsourceScope?: \"project\" | \"entry\";\n\tservices?: ServiceOptions;\n\ttsconfig: string;\n\tprograms: Readonly<Record<string, { module: string; export: string }>>;\n\t/** What `env()` reads, and the debug switches; this process's environment by default. */\n\tenvironment?: Environment;\n\t/**\n\t * The state paths the config's `io` binds. The hardware writes them, so the object each starts\n\t * from is state even where scan code only reads it.\n\t */\n\tio: readonly BoundPath[];\n}\n\n/** A state path the config's `io` binds, and the input address the hardware writes it from. */\nexport interface BoundPath {\n\tpath: string;\n\t/** The `%I` address of an input, which scan code can't assign; null for an output. */\n\tinput: string | null;\n}\n\nexport interface FrontendResult {\n\tmodule?: PlcModule;\n\tdiagnostics: readonly Diagnostic[];\n}\n\nfunction tsDiagnostic(\n\tdiagnostic: ts.Diagnostic,\n\tlocate: typeof sourceSpan,\n): Diagnostic {\n\tconst result: Diagnostic = {\n\t\torigin: \"typescript\",\n\t\tcode: `TS${diagnostic.code}`,\n\t\tseverity:\n\t\t\tdiagnostic.category === ts.DiagnosticCategory.Error ? \"error\" : \"warning\",\n\t\tmessage: ts.flattenDiagnosticMessageText(diagnostic.messageText, \"\\n\"),\n\t};\n\tif (diagnostic.file && diagnostic.start !== undefined) {\n\t\tresult.span = locate(\n\t\t\tdiagnostic.file,\n\t\t\tdiagnostic.start,\n\t\t\tdiagnostic.start + (diagnostic.length ?? 1),\n\t\t);\n\t}\n\treturn result;\n}\n\n/**\n * Type checks a subset of a tsconfig's files without emitting. A project-reference\n * tsconfig's composite and declaration settings would demand every file be listed\n * (TS6307) or conflict with noEmit, so these replace them.\n */\nexport const typeCheckOnly: ts.CompilerOptions = {\n\tcomposite: false,\n\tdeclaration: false,\n\tdeclarationMap: false,\n\temitDeclarationOnly: false,\n\tincremental: false,\n\tnoEmit: true,\n\ttsBuildInfoFile: undefined,\n};\n\n/** Compiles a program's PLC TypeScript into the PLC model: plain TypeScript, never the dialect. */\nexport function analyze(options: FrontendOptions): FrontendResult {\n\treturn compileFrontend(options, \"rejected\");\n}\n\n/**\n * Compiles source that may be written in the tsPLC dialect, the language plain programs lower\n * into. No command reaches it: the compiler's tests write the dialect to drive its later stages.\n */\nexport function analyzeDialect(options: FrontendOptions): FrontendResult {\n\treturn compileFrontend(options, \"accepted\");\n}\n\n/**\n * The frontend. With the dialect `rejected`, every program is plain TypeScript that elaboration\n * compiles from its setup; `accepted`, a program elaborates only when it declares a plain class.\n */\nfunction compileFrontend(\n\toptions: FrontendOptions,\n\tdialect: \"rejected\" | \"accepted\",\n): FrontendResult {\n\tconst environment = options.environment ?? { ...process.env };\n\tconst debug = compileDebug(environment);\n\tconst filename = resolve(options.tsconfig);\n\tconst root = dirname(filename);\n\tconst config = ts.readConfigFile(filename, ts.sys.readFile);\n\tif (config.error) {\n\t\treturn { diagnostics: [tsDiagnostic(config.error, sourceSpan)] };\n\t}\n\tconst parsed = ts.parseJsonConfigFileContent(\n\t\tconfig.config,\n\t\tts.sys,\n\t\troot,\n\t\tundefined,\n\t\tfilename,\n\t);\n\tif (parsed.errors.length) {\n\t\treturn {\n\t\t\tdiagnostics: parsed.errors.map((diagnostic) =>\n\t\t\t\ttsDiagnostic(diagnostic, sourceSpan),\n\t\t\t),\n\t\t};\n\t}\n\tconst programFiles = Object.values(options.programs).map((entry) =>\n\t\tresolve(root, entry.module),\n\t);\n\t// Full-stack builds follow entry imports; standalone projects retain explicit tsconfig globals.\n\tconst scope = options.sourceScope ?? (options.services ? \"entry\" : \"project\");\n\t// The project's own ambient declarations; a shared base tsconfig's typings are for the host runtime.\n\tconst ambient = parsed.fileNames.filter(\n\t\t(file) => /\\.d\\.[cm]?ts$/.test(file) && file.startsWith(`${root}/`),\n\t);\n\tconst projectFiles = scope === \"project\" ? parsed.fileNames : ambient;\n\tconst compilerOptions: ts.CompilerOptions = {\n\t\t...parsed.options,\n\t\t...typeCheckOnly,\n\t\t// Lowered sources import their runtime helpers by .ts path and drop the imports they replace.\n\t\tallowImportingTsExtensions: true,\n\t\tnoUnusedLocals: false,\n\t\tnoUnusedParameters: false,\n\t\tstrict: true,\n\t\tnoImplicitAny: true,\n\t\tstrictNullChecks: true,\n\t\tnoCheck: false,\n\t\tallowJs: false,\n\t\tskipLibCheck: false,\n\t\ttypes: [],\n\t\tlib: [\"lib.es2025.d.ts\"],\n\t\tmodule: ts.ModuleKind.ESNext,\n\t\tmoduleResolution: ts.ModuleResolutionKind.Bundler,\n\t};\n\t// Nothing is emitted, and a service client's router type imports modules outside these (TS6059).\n\tdelete compilerOptions.rootDir;\n\tdelete compilerOptions.outDir;\n\tconst sdk = sdkFor(filename, compilerOptions);\n\tconst rootNames = [\n\t\t...new Set([...projectFiles, ...programFiles, sdk, dialectFor(sdk)]),\n\t];\n\tconst virtualSources = new Map<string, string>();\n\t// Lowering also adds modules, such as the service client, that exist only here.\n\tconst host = loweringHost(compilerOptions, virtualSources);\n\tconst program = ts.createProgram(rootNames, compilerOptions, host);\n\tconst plcFiles = (program: ts.Program) => {\n\t\tconst files = new Set(runtimeSources(program));\n\t\tfor (const source of program.getSourceFiles()) {\n\t\t\tif (inSdk(sdk, source.fileName)) {\n\t\t\t\tfiles.add(source);\n\t\t\t}\n\t\t}\n\t\treturn files;\n\t};\n\tconst positions = new Positions();\n\tconst generated = (file: ts.SourceFile) =>\n\t\tvirtualSources.has(file.fileName) &&\n\t\tfile.fileName.includes(`/${generatedDirectory}/`);\n\t// Only PLC files: a type-only import of the server router brings the server's sources along.\n\tconst sourceDiagnostics = (\n\t\tprogram: ts.Program,\n\t\tfiles: ReadonlySet<ts.SourceFile>,\n\t) =>\n\t\t[\n\t\t\t...program.getConfigFileParsingDiagnostics(),\n\t\t\t...program.getOptionsDiagnostics(),\n\t\t\t...program.getGlobalDiagnostics(),\n\t\t\t...[...files].flatMap((file) => [\n\t\t\t\t...program.getSyntacticDiagnostics(file),\n\t\t\t\t...program.getSemanticDiagnostics(file),\n\t\t\t]),\n\t\t]\n\t\t\t.filter(\n\t\t\t\t(diagnostic) => !storesGeneratedGlobal(program, diagnostic, generated),\n\t\t\t)\n\t\t\t.map((diagnostic) => tsDiagnostic(diagnostic, positions.span));\n\tconst files = plcFiles(program);\n\tconst diagnostics = sourceDiagnostics(program, files);\n\tif (\n\t\tprogram\n\t\t\t.getSyntacticDiagnostics()\n\t\t\t.some((item) => !item.file || files.has(item.file))\n\t) {\n\t\treturn { diagnostics };\n\t}\n\tif (dialect === \"rejected\") {\n\t\tconst uses = dialectUses(program, sdk, positions);\n\t\tif (uses.length) {\n\t\t\treturn { diagnostics: [...diagnostics, ...uses] };\n\t\t}\n\t}\n\t// Only shown when compiling fails, which one of them may explain.\n\tconst lost: Diagnostic[] = [];\n\tconst lowerings = new LoweringPipeline(program, (program, lowering) => {\n\t\tdiagnostics.push(...lowering.diagnostics);\n\t\tfor (const source of runtimeSources(program)) {\n\t\t\tif (lowering.sources.has(source.fileName)) {\n\t\t\t\tdiagnostics.push(...suppressionDiagnostics(source, positions));\n\t\t\t}\n\t\t}\n\t\tif (\n\t\t\tlowering.diagnostics.length ||\n\t\t\t(lowering.sources.size && hasErrors(diagnostics))\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (!lowering.sources.size) {\n\t\t\treturn program;\n\t\t}\n\t\tpositions.record(lowering.sources, program);\n\t\tfor (const [path, text] of lowering.sources) {\n\t\t\tvirtualSources.set(path, text.text);\n\t\t}\n\t\tif (debug.lowered) {\n\t\t\tfor (const [path, text] of lowering.sources) {\n\t\t\t\tconst target = join(debug.lowered, relative(root, path));\n\t\t\t\tmkdirSync(dirname(target), { recursive: true });\n\t\t\t\twriteFileSync(target, text.text);\n\t\t\t}\n\t\t}\n\t\tconst lowered = ts.createProgram({\n\t\t\trootNames,\n\t\t\toptions: compilerOptions,\n\t\t\thost,\n\t\t\toldProgram: program,\n\t\t});\n\t\tconst plc = plcFiles(lowered);\n\t\tdiagnostics.push(...sourceDiagnostics(lowered, plc));\n\t\tlost.push(\n\t\t\t...lostImports({\n\t\t\t\tbefore: program,\n\t\t\t\tafter: lowered,\n\t\t\t\trewritten: lowering.sources,\n\t\t\t\tplc: new Set(\n\t\t\t\t\t[...plc, ...plcFiles(program)].map(({ fileName }) => fileName),\n\t\t\t\t),\n\t\t\t\troot,\n\t\t\t\tpositions,\n\t\t\t}),\n\t\t);\n\t\treturn lowered;\n\t});\n\t// A plain program's setup reads the configuration this resolves. The pass runs again below for\n\t// the reads that the services pass generates.\n\tconst configuration = lowerings.run((program) =>\n\t\tlowerEnvironment(program, sdk, positions, environment),\n\t);\n\tconst elaboration =\n\t\tconfiguration &&\n\t\tlowerings.run((program) =>\n\t\t\tlowerElaboration(program, sdk, options.programs, root, positions, {\n\t\t\t\tdebug,\n\t\t\t\tconfiguration: configuration.read,\n\t\t\t\talways: dialect === \"rejected\",\n\t\t\t\tio: options.io,\n\t\t\t}),\n\t\t);\n\tlowerings.run(lowerControlFlow);\n\tconst services = lowerings.run((program) =>\n\t\tlowerServices(program, sdk, positions, options.services),\n\t);\n\tlowerings.run((program) =>\n\t\tlowerEnvironment(program, sdk, positions, environment),\n\t);\n\tlowerings.run((program) => lowerConstFunctions(program, positions));\n\tconst promises = lowerings.run((program) =>\n\t\tlowerPromises(program, sdk, positions, root),\n\t);\n\tconst lowering = lowerings.run((program) =>\n\t\tlowerAsync(program, sdk, positions, root),\n\t);\n\tconst lowered = lowerings.program;\n\tif (!lowered || !elaboration || !services || !promises || !lowering) {\n\t\treturn { diagnostics: [...diagnostics, ...lost] };\n\t}\n\tconst analyzer = new Analyzer(\n\t\tlowered,\n\t\thost,\n\t\troot,\n\t\tsdk,\n\t\tdiagnostics,\n\t\tpositions,\n\t\tserviceRecords(lowered, services),\n\t\telaboration.reduced,\n\t);\n\tconst module = analyzer.run({ ...options.programs, ...lowering.programs });\n\tattachLowerings(module, root, { elaboration, promises, lowering });\n\treturn hasErrors(diagnostics)\n\t\t? { diagnostics: [...diagnostics, ...lost] }\n\t\t: { module, diagnostics };\n}\n\n/**\n * Whether a diagnostic is TypeScript refusing a lowered module's write to a global of a module\n * elaboration generated, through its namespace import. A namespace import is read-only in\n * TypeScript, but each generated module is a global variable list, and the PLC assigns its\n * variables from any program.\n */\nfunction storesGeneratedGlobal(\n\tprogram: ts.Program,\n\tdiagnostic: ts.Diagnostic,\n\tgenerated: (file: ts.SourceFile) => boolean,\n): boolean {\n\tconst { file, start, length } = diagnostic;\n\tif (\n\t\tdiagnostic.code !== readOnlyAssignment ||\n\t\t!file ||\n\t\tstart === undefined ||\n\t\tlength === undefined\n\t) {\n\t\treturn false;\n\t}\n\tconst target = reportedAccess(file, start, start + length);\n\tif (!target || !ts.isIdentifier(target.expression)) {\n\t\treturn false;\n\t}\n\tconst checker = program.getTypeChecker();\n\tconst namespace = checker\n\t\t.getSymbolAtLocation(target.expression)\n\t\t?.declarations?.find(ts.isNamespaceImport);\n\tconst source =\n\t\tnamespace &&\n\t\tchecker.getSymbolAtLocation(namespace.parent.parent.moduleSpecifier)\n\t\t\t?.valueDeclaration;\n\treturn Boolean(source && ts.isSourceFile(source) && generated(source));\n}\n\n/** TypeScript's errors for an import that names something its module doesn't export. */\nconst missingExportCodes: ReadonlySet<number> = new Set([\n\t2305, 2459, 2460, 2614, 2724,\n]);\n\n/** The file an import or re-export's module specifier resolves to, if it resolves to a source file. */\nfunction importedFile(\n\tchecker: ts.TypeChecker,\n\tstatement: ts.Statement,\n): string | undefined {\n\tif (\n\t\t!(ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement)) ||\n\t\t!statement.moduleSpecifier\n\t) {\n\t\treturn undefined;\n\t}\n\tconst module = checker.getSymbolAtLocation(\n\t\tstatement.moduleSpecifier,\n\t)?.valueDeclaration;\n\treturn module && ts.isSourceFile(module) ? module.fileName : undefined;\n}\n\n/**\n * Imports a lowering pass broke in files tsPLC doesn't compile, such as a server's router: the\n * pass rewrote a module and dropped a name the file still imports. Only PLC files' TypeScript\n * errors are reported, so without this a server schema reads the lost name as nothing, and the\n * error surfaces far from its cause. The server itself runs the module as written, so a lost name\n * matters only where tsPLC reads that file's types: these are warnings, shown beside the errors\n * they may explain.\n */\nfunction lostImports({\n\tbefore,\n\tafter,\n\trewritten,\n\tplc,\n\troot,\n\tpositions,\n}: {\n\tbefore: ts.Program;\n\tafter: ts.Program;\n\trewritten: ReadonlyMap<string, Mapped>;\n\t/** The PLC program's files before the pass and after it, whose errors are reported anyway. */\n\tplc: ReadonlySet<string>;\n\troot: string;\n\tpositions: Positions;\n}): Diagnostic[] {\n\tconst checker = after.getTypeChecker();\n\treturn after.getSourceFiles().flatMap((file) => {\n\t\tconst imports = file.statements.flatMap((statement) => {\n\t\t\tconst imported = importedFile(checker, statement);\n\t\t\treturn imported && rewritten.has(imported)\n\t\t\t\t? [{ statement, imported }]\n\t\t\t\t: [];\n\t\t});\n\t\tconst original = before.getSourceFile(file.fileName);\n\t\tif (\n\t\t\t!imports.length ||\n\t\t\t!original ||\n\t\t\tfile.isDeclarationFile ||\n\t\t\tplc.has(file.fileName) ||\n\t\t\trewritten.has(file.fileName)\n\t\t) {\n\t\t\treturn [];\n\t\t}\n\t\tconst missing = (program: ts.Program, source: ts.SourceFile) =>\n\t\t\tprogram\n\t\t\t\t.getSemanticDiagnostics(source)\n\t\t\t\t.filter(\n\t\t\t\t\t(diagnostic) =>\n\t\t\t\t\t\tmissingExportCodes.has(diagnostic.code) &&\n\t\t\t\t\t\tdiagnostic.start !== undefined,\n\t\t\t\t);\n\t\tconst known = new Set(\n\t\t\tmissing(before, original).map(({ start, code }) => `${start}:${code}`),\n\t\t);\n\t\treturn missing(after, file).flatMap(({ start = 0, length = 1, code }) => {\n\t\t\tconst broken = imports.find(\n\t\t\t\t({ statement }) => statement.pos <= start && start < statement.end,\n\t\t\t);\n\t\t\tif (!broken || known.has(`${start}:${code}`)) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tconst name = file.text.slice(start, start + length);\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\torigin: \"plc\" as const,\n\t\t\t\t\tcode: \"PLC1016\",\n\t\t\t\t\tseverity: \"warning\" as const,\n\t\t\t\t\tmessage: `tsPLC dropped ${name} from ${relative(root, broken.imported)} while compiling the PLC program, but ${relative(root, file.fileName)} imports it, so tsPLC reads that file's types without it. If an error here is in what that file declares, this is its cause, and a tsPLC bug.`,\n\t\t\t\t\tspan: positions.span(file, start, start + length),\n\t\t\t\t},\n\t\t\t];\n\t\t});\n\t});\n}\n\n/** TS2540: \"Cannot assign to '…' because it is a read-only property.\" */\nconst readOnlyAssignment = 2540;\n\n/** The property access whose name a diagnostic spans from `start` to `end`, if it spans one. */\nfunction reportedAccess(\n\tfile: ts.SourceFile,\n\tstart: number,\n\tend: number,\n): ts.PropertyAccessExpression | undefined {\n\tconst visit = (node: ts.Node): ts.PropertyAccessExpression | undefined => {\n\t\tif (\n\t\t\tts.isPropertyAccessExpression(node) &&\n\t\t\tnode.name.getStart(file) === start &&\n\t\t\tnode.name.end === end\n\t\t) {\n\t\t\treturn node;\n\t\t}\n\t\treturn node.pos <= start && end <= node.end\n\t\t\t? ts.forEachChild(node, visit)\n\t\t\t: undefined;\n\t};\n\treturn ts.forEachChild(file, visit);\n}\n\n/** What every lowering pass returns: the modules it rewrote or generated, and what it rejected. */\ninterface Lowering {\n\tsources: ReadonlyMap<string, Mapped>;\n\tdiagnostics: readonly Diagnostic[];\n}\n\n/**\n * Runs the lowering passes in order, each over the program the one before it produced. `next`\n * takes a pass's result to the program the following pass reads, or to undefined when the pass\n * failed; the passes after a failure do not run.\n */\nclass LoweringPipeline {\n\tprivate current: ts.Program | undefined;\n\n\tconstructor(\n\t\tprogram: ts.Program,\n\t\tprivate readonly next: (\n\t\t\tprogram: ts.Program,\n\t\t\tlowering: Lowering,\n\t\t) => ts.Program | undefined,\n\t) {\n\t\tthis.current = program;\n\t}\n\n\t/** The program the passes produced; undefined once one has failed. */\n\tget program(): ts.Program | undefined {\n\t\treturn this.current;\n\t}\n\n\t/** The result of `pass` over the current program; undefined when it or an earlier pass failed. */\n\trun<T extends Lowering>(pass: (program: ts.Program) => T): T | undefined {\n\t\tif (!this.current) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst lowering = pass(this.current);\n\t\tthis.current = this.next(this.current, lowering);\n\t\treturn this.current && lowering;\n\t}\n}\n\n/**\n * The compiler host of every lowering pass: lowered and generated modules are read from\n * `virtualSources`, and everything else from disk. Each pass builds a new program, so the host\n * parses a file again only when its text changed, and the program reuses its predecessor's module\n * structure; a pass then costs its type check rather than reparsing thousands of declarations.\n */\nfunction loweringHost(\n\toptions: ts.CompilerOptions,\n\tvirtualSources: ReadonlyMap<string, string>,\n): ts.CompilerHost {\n\tconst host = ts.createCompilerHost(options);\n\tconst read = host.readFile;\n\tconst exists = host.fileExists;\n\tconst directoryExists = host.directoryExists?.bind(host);\n\tconst parse = host.getSourceFile;\n\thost.readFile = (path) => virtualSources.get(path) ?? read(path);\n\thost.fileExists = (path) => virtualSources.has(path) || exists(path);\n\t// Generated modules can live in a directory that only exists in memory.\n\thost.directoryExists = (path) =>\n\t\t[...virtualSources.keys()].some((file) =>\n\t\t\tfile.startsWith(`${path.replace(/\\/$/, \"\")}/`),\n\t\t) ||\n\t\t(directoryExists?.(path) ?? true);\n\tconst parsed = new Map<string, ts.SourceFile>();\n\thost.getSourceFile = (fileName, version, onError, createNew) => {\n\t\tconst key = `${fileName}\\0${typeof version === \"object\" ? `${version.languageVersion}:${version.impliedNodeFormat}` : version}`;\n\t\tconst known = parsed.get(key);\n\t\tconst lowered = virtualSources.get(fileName);\n\t\t// A rewritten module never returns to its file on disk, so a file without lowered text is unchanged.\n\t\tif (\n\t\t\tknown &&\n\t\t\t!createNew &&\n\t\t\t(lowered === undefined || known.text === lowered)\n\t\t) {\n\t\t\treturn known;\n\t\t}\n\t\tconst file = parse(fileName, version, onError, createNew);\n\t\tif (file) {\n\t\t\tparsed.set(key, file);\n\t\t}\n\t\treturn file;\n\t};\n\treturn host;\n}\n\n/**\n * The lowerings record what they generated by lowering key. The analyzed model's\n * spans point at the user's files, but its ids still start with the lowered module\n * each item was declared in, so the records are matched back by id.\n */\nfunction attachLowerings(\n\tmodule: PlcModule,\n\troot: string,\n\t{\n\t\telaboration,\n\t\tpromises,\n\t\tlowering,\n\t}: {\n\t\telaboration: ReturnType<typeof lowerElaboration>;\n\t\tpromises: ReturnType<typeof lowerPromises>;\n\t\tlowering: AsyncLowering;\n\t},\n): void {\n\tfor (const fn of module.functions) {\n\t\tconst origin = elaboration.origins.get(declarationKey(root, fn));\n\t\tif (origin) {\n\t\t\tfn.origin = origin;\n\t\t}\n\t}\n\tmodule.types = module.types.map((type) => {\n\t\tconst literals =\n\t\t\ttype.kind === \"enum\" && elaboration.literals.get(typeKey(root, type.id));\n\t\treturn type.kind === \"enum\" && literals\n\t\t\t? {\n\t\t\t\t\t...type,\n\t\t\t\t\tmembers: type.members.map((member) => ({\n\t\t\t\t\t\t...member,\n\t\t\t\t\t\ttext: literals[member.name],\n\t\t\t\t\t})),\n\t\t\t\t}\n\t\t\t: type;\n\t});\n\tfor (const block of module.blocks) {\n\t\tconst key = declarationKey(root, block);\n\t\tconst runtime = promises.runtimeBlocks.get(key) ?? lowering.blocks.get(key);\n\t\tif (runtime) {\n\t\t\tblock.runtime = runtime;\n\t\t}\n\t\tconst job = lowering.jobs.get(key);\n\t\tconst origin = elaboration.origins.get(key);\n\t\tif (job) {\n\t\t\tblock.job = origin ? { ...job, ...origin } : job;\n\t\t}\n\t}\n\tif (elaboration.folded.length) {\n\t\tmodule.folded = elaboration.folded;\n\t}\n\tif (elaboration.references?.fields.length) {\n\t\tmodule.references = elaboration.references;\n\t}\n\tfor (const entry of module.programs) {\n\t\tconst background = lowering.schedules.get(entry.name);\n\t\tif (background) {\n\t\t\tentry.background = background;\n\t\t}\n\t\tconst continuation = lowering.continuations.get(entry.name);\n\t\tif (continuation) {\n\t\t\tentry.continuation = continuation;\n\t\t}\n\t}\n}\n\nexport function checkHostConfig(file: string): readonly Diagnostic[] {\n\tconst bunTypes = createRequire(import.meta.url).resolve(\n\t\t\"@types/bun/index.d.ts\",\n\t);\n\tconst program = ts.createProgram([file], {\n\t\tstrict: true,\n\t\tnoEmit: true,\n\t\ttarget: ts.ScriptTarget.ES2022,\n\t\tmodule: ts.ModuleKind.ESNext,\n\t\tmoduleResolution: ts.ModuleResolutionKind.Bundler,\n\t\tallowImportingTsExtensions: true,\n\t\tskipLibCheck: true,\n\t\ttypes: [bunTypes],\n\t});\n\treturn ts\n\t\t.getPreEmitDiagnostics(program)\n\t\t.map((diagnostic) => tsDiagnostic(diagnostic, sourceSpan));\n}\n",
6
+ "import { resolve } from \"node:path\";\nimport {\n\taggregate,\n\ttype Diagnostic,\n\terror,\n\ttype PlcFunction,\n\ttype PlcModule,\n\ttype PlcProgram,\n\ttype Variable,\n} from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport { BlockResolver, storageInitializer } from \"./blocks\";\nimport type { Uncompiled } from \"./elaborate/reduce\";\nimport {\n\ttype AnalysisContext,\n\tExpressionLowering,\n\ttype LoweringScope,\n} from \"./expressions\";\nimport { runtimeImport, runtimeSources } from \"./module-graph\";\nimport type { Positions } from \"./positions\";\nimport { methodAccess, RoutineTable } from \"./routines\";\nimport { inSdk, unaliased } from \"./sdk\";\nimport { StatementLowering } from \"./statements\";\nimport {\n\ttype Fail,\n\thasModifier,\n\tinferredStorageType,\n\ttype ResolvedType,\n\tSemanticError,\n\ttype ServiceRecord,\n\tTypeResolver,\n} from \"./types\";\nimport type { FrontendOptions } from \"./typescript\";\n\n/** What a module variable's initializer and keyword establish about its storage. */\ninterface StorageFacts {\n\tinstance: string | undefined;\n\ttable: ResolvedType | undefined;\n\timmutable: boolean;\n\tinitializer: ts.Expression | undefined;\n}\n\nexport const suppressionDiagnostics = (\n\tsource: ts.SourceFile,\n\tpositions: Positions,\n): Diagnostic[] => {\n\tconst diagnostics: Diagnostic[] = [];\n\tconst scanner = ts.createScanner(\n\t\tts.ScriptTarget.Latest,\n\t\tfalse,\n\t\tts.LanguageVariant.Standard,\n\t\tsource.text,\n\t);\n\tfor (\n\t\tlet token = scanner.scan();\n\t\ttoken !== ts.SyntaxKind.EndOfFileToken;\n\t\ttoken = scanner.scan()\n\t) {\n\t\tif (\n\t\t\ttoken !== ts.SyntaxKind.SingleLineCommentTrivia &&\n\t\t\ttoken !== ts.SyntaxKind.MultiLineCommentTrivia\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst match =\n\t\t\t/(?<=(?:^|\\n)\\s*(?:\\/\\/+|\\/\\*+|\\*)\\s*)@ts-(?:nocheck|ignore|expect-error)\\b/.exec(\n\t\t\t\tscanner.getTokenText(),\n\t\t\t);\n\t\tif (!match) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst start = scanner.getTokenPos() + match.index;\n\t\tdiagnostics.push(\n\t\t\terror(\n\t\t\t\t\"PLC1009\",\n\t\t\t\t\"TypeScript diagnostic suppression is not allowed in PLC source.\",\n\t\t\t\tpositions.span(source, start, start + match[0].length),\n\t\t\t),\n\t\t);\n\t}\n\treturn diagnostics;\n};\n\nexport class Analyzer {\n\tprivate readonly checker: ts.TypeChecker;\n\tprivate readonly resolver: TypeResolver;\n\tprivate readonly routines: RoutineTable;\n\tprivate readonly blocks: BlockResolver;\n\tprivate readonly globalVariables: Variable[] = [];\n\tprivate readonly sources: readonly ts.SourceFile[];\n\tprivate readonly context: AnalysisContext;\n\t/** Lowers module and block initializers, which run before any routine. */\n\tprivate readonly moduleScope: ExpressionLowering;\n\n\tconstructor(\n\t\tprivate readonly program: ts.Program,\n\t\tprivate readonly host: ts.ModuleResolutionHost,\n\t\tprivate readonly root: string,\n\t\tprivate readonly sdk: string,\n\t\tprivate readonly diagnostics: Diagnostic[],\n\t\tprivate readonly positions: Positions,\n\t\tserviceRecord: ServiceRecord | null,\n\t\t/** What of each module elaboration rewrote is PLC code, where that is not all of it. */\n\t\tprivate readonly reduced: ReadonlyMap<string, Uncompiled>,\n\t) {\n\t\tthis.checker = program.getTypeChecker();\n\t\tthis.resolver = new TypeResolver(\n\t\t\tthis.checker,\n\t\t\troot,\n\t\t\tsdk,\n\t\t\tthis.fail,\n\t\t\tserviceRecord,\n\t\t);\n\t\tthis.routines = new RoutineTable(\n\t\t\tthis.checker,\n\t\t\tthis.resolver,\n\t\t\tpositions,\n\t\t\tthis.fail,\n\t\t);\n\t\tconst sdkSource = program.getSourceFile(sdk);\n\t\tif (!sdkSource) {\n\t\t\tthrow new Error(`The program does not include the SDK ${sdk}.`);\n\t\t}\n\t\tthis.blocks = new BlockResolver(\n\t\t\tthis.resolver,\n\t\t\tpositions.node,\n\t\t\tthis.fail,\n\t\t\tpositions.node(sdkSource),\n\t\t);\n\t\tthis.context = {\n\t\t\tchecker: this.checker,\n\t\t\tresolver: this.resolver,\n\t\t\tblocks: this.blocks,\n\t\t\troutines: this.routines,\n\t\t\tpositions,\n\t\t\tfail: this.fail,\n\t\t};\n\t\tthis.moduleScope = new ExpressionLowering(this.context, {\n\t\t\tfn: undefined,\n\t\t\tblock: undefined,\n\t\t\tenvironment: new Map(),\n\t\t\tvariables: new Map(),\n\t\t});\n\t\tconst roots = new Set(program.getRootFileNames());\n\t\tthis.sources = runtimeSources(program).filter(\n\t\t\t(source) =>\n\t\t\t\tsource.fileName !== sdk &&\n\t\t\t\t!inSdk(sdk, source.fileName) &&\n\t\t\t\t!program.isSourceFileDefaultLibrary(source) &&\n\t\t\t\t(!source.isDeclarationFile || roots.has(source.fileName)),\n\t\t);\n\t}\n\n\tprivate readonly fail: Fail = (node, code, message) => {\n\t\tthrow new SemanticError(error(code, message, this.positions.node(node)));\n\t};\n\n\t/** Runs `action`, reporting the diagnostic it fails with unless an earlier action reported it. */\n\tprivate guard(action: () => void): void {\n\t\ttry {\n\t\t\taction();\n\t\t} catch (cause) {\n\t\t\tif (!(cause instanceof SemanticError)) {\n\t\t\t\tthrow cause;\n\t\t\t}\n\t\t\tif (!this.diagnostics.includes(cause.diagnostic)) {\n\t\t\t\tthis.diagnostics.push(cause.diagnostic);\n\t\t\t}\n\t\t}\n\t}\n\n\trun(entries: FrontendOptions[\"programs\"]): PlcModule {\n\t\t// Collect every declaration before resolving initializers and routine bodies.\n\t\t// Generic calls can enqueue more helpers, so resolve entry points last.\n\t\tthis.collectDeclarations();\n\t\tthis.initializeStorage();\n\t\tthis.analyzeBlockBodies();\n\t\tthis.analyzePendingFunctions();\n\t\tconst programs = this.resolvePrograms(entries);\n\n\t\treturn {\n\t\t\ttypes: [...this.resolver.types.values()],\n\t\t\tvariables: this.globalVariables,\n\t\t\tfunctions: [...this.routines.instances.values()],\n\t\t\tblocks: [...this.blocks.definitions.values()],\n\t\t\tprograms,\n\t\t};\n\t}\n\n\t/**\n\t * A module's statements that are PLC code. A module elaboration cut down is there for\n\t * TypeScript, but for the constants a module of constants reads; the entry module it wrote also\n\t * declares, for other modules to import, names that are no code of its own.\n\t */\n\tprivate statements(source: ts.SourceFile): readonly ts.Statement[] {\n\t\tconst part = this.reduced.get(source.fileName);\n\t\tif (!part) {\n\t\t\treturn source.statements;\n\t\t}\n\t\tconst names = (statement: ts.Statement): string[] => {\n\t\t\tif (ts.isVariableStatement(statement)) {\n\t\t\t\treturn statement.declarationList.declarations.map((declaration) =>\n\t\t\t\t\tdeclaration.name.getText(),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn ts.isEnumDeclaration(statement) ? [statement.name.text] : [];\n\t\t};\n\t\treturn source.statements.filter((statement) =>\n\t\t\t\"compiled\" in part\n\t\t\t\t? ts.isVariableStatement(statement) &&\n\t\t\t\t\tnames(statement).some((name) => part.compiled.has(name))\n\t\t\t\t: !names(statement).some((name) => part.declared.has(name)),\n\t\t);\n\t}\n\n\tprivate collectDeclarations(): void {\n\t\tconst classes = this.sources.flatMap((source) =>\n\t\t\tthis.statements(source).filter(ts.isClassDeclaration),\n\t\t);\n\t\tthis.blocks.index(classes);\n\t\tfor (const node of classes) {\n\t\t\tthis.guard(() => this.blocks.collect(node));\n\t\t}\n\t\tfor (const source of this.blocks.sources.values()) {\n\t\t\tfor (const method of source.methods) {\n\t\t\t\tthis.guard(() =>\n\t\t\t\t\tthis.routines.declareMethod(\n\t\t\t\t\t\tthis.resolver.symbol(method.name),\n\t\t\t\t\t\tmethod,\n\t\t\t\t\t\t{ block: source.block.id, access: methodAccess(method) },\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tfor (const source of this.sources) {\n\t\t\tthis.diagnostics.push(...suppressionDiagnostics(source, this.positions));\n\t\t\tfor (const statement of this.statements(source)) {\n\t\t\t\tthis.guard(() => this.declaration(statement));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate initializeStorage(): void {\n\t\tfor (const source of this.sources) {\n\t\t\tfor (const statement of this.statements(source)) {\n\t\t\t\tif (ts.isVariableStatement(statement) && !source.isDeclarationFile) {\n\t\t\t\t\tthis.guard(() => {\n\t\t\t\t\t\tfor (const declaration of statement.declarationList.declarations) {\n\t\t\t\t\t\t\tif (!declaration.initializer) {\n\t\t\t\t\t\t\t\tthis.fail(\n\t\t\t\t\t\t\t\t\tdeclaration,\n\t\t\t\t\t\t\t\t\t\"PLC3001\",\n\t\t\t\t\t\t\t\t\t\"Persistent PLC state requires a constant initializer.\",\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst variable = this.moduleScope\n\t\t\t\t\t\t\t\t.bySymbol()\n\t\t\t\t\t\t\t\t.get(this.resolver.symbol(declaration.name));\n\t\t\t\t\t\t\tif (!variable || variable.storage === \"instance\") {\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst initializer = storageInitializer(\n\t\t\t\t\t\t\t\tdeclaration.initializer,\n\t\t\t\t\t\t\t\tthis.resolver,\n\t\t\t\t\t\t\t\tthis.fail,\n\t\t\t\t\t\t\t).value;\n\t\t\t\t\t\t\tconst inferred = variable.type === \"inferred\";\n\t\t\t\t\t\t\tconst expression = this.moduleScope.expression(\n\t\t\t\t\t\t\t\tinitializer,\n\t\t\t\t\t\t\t\tinferred ? undefined : variable.type,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tvariable.type = expression.type;\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tinferred &&\n\t\t\t\t\t\t\t\tvariable.storage === \"constant\" &&\n\t\t\t\t\t\t\t\taggregate(this.resolver.types.get(variable.type))\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tvariable.storage = \"module\";\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tvariable.retention !== \"none\" &&\n\t\t\t\t\t\t\t\tvariable.storage === \"constant\"\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tthis.fail(\n\t\t\t\t\t\t\t\t\tdeclaration,\n\t\t\t\t\t\t\t\t\t\"PLC3004\",\n\t\t\t\t\t\t\t\t\t`${variable.retention} requires mutable persistent storage or a static block instance.`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst value = this.moduleScope.constant(\n\t\t\t\t\t\t\t\tthis.moduleScope.implicitCopy(expression),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (!value) {\n\t\t\t\t\t\t\t\tthis.fail(\n\t\t\t\t\t\t\t\t\tdeclaration.initializer,\n\t\t\t\t\t\t\t\t\t\"PLC3001\",\n\t\t\t\t\t\t\t\t\t\"Persistent initializers must be compile-time constants.\",\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvariable.initial = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate analyzeBlockBodies(): void {\n\t\tfor (const source of this.blocks.sources.values()) {\n\t\t\tthis.guard(() => {\n\t\t\t\tfor (const [variable, node] of source.initializers) {\n\t\t\t\t\tconst value = this.moduleScope.constant(\n\t\t\t\t\t\tthis.moduleScope.expression(node, variable.type),\n\t\t\t\t\t);\n\t\t\t\t\tif (!value) {\n\t\t\t\t\t\tthis.fail(\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\"PLC3001\",\n\t\t\t\t\t\t\t\"Block state requires a compile-time constant initializer.\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tvariable.initial = value;\n\t\t\t\t}\n\t\t\t\tconst { block } = source;\n\t\t\t\tconst routine = this.routineBody(\n\t\t\t\t\t{\n\t\t\t\t\t\tid: block.id,\n\t\t\t\t\t\tname: block.name,\n\t\t\t\t\t\tparameters: block.inputs,\n\t\t\t\t\t\tlocals: [],\n\t\t\t\t\t\tbody: [],\n\t\t\t\t\t\tspan: block.span,\n\t\t\t\t\t\t...(block.result && { result: block.result }),\n\t\t\t\t\t},\n\t\t\t\t\tsource.fieldBindings,\n\t\t\t\t\tsource.body,\n\t\t\t\t\t{ block: source, environment: new Map() },\n\t\t\t\t);\n\t\t\t\tblock.locals = routine.locals;\n\t\t\t\tblock.body = routine.body;\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate analyzePendingFunctions(): void {\n\t\t// A worklist allows explicit generic instances to share source without sharing locals.\n\t\t// Lowering a body can append instances, which this loop then reaches.\n\t\tfor (const instance of this.routines.pending) {\n\t\t\tthis.guard(() => {\n\t\t\t\tconst block = instance.fn.owner\n\t\t\t\t\t? [...this.blocks.sources.values()].find(\n\t\t\t\t\t\t\t(source) => source.block.id === instance.fn.owner?.block,\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined;\n\t\t\t\tconst fn = this.routineBody(\n\t\t\t\t\tinstance.fn,\n\t\t\t\t\t[...(block?.fieldBindings ?? []), ...instance.parameters],\n\t\t\t\t\tinstance.body,\n\t\t\t\t\t{ block, environment: instance.environment },\n\t\t\t\t);\n\t\t\t\tthis.routines.complete(instance, fn);\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate routineBody(\n\t\tfn: PlcFunction,\n\t\tbindings: Iterable<readonly [ts.Symbol, Variable]>,\n\t\tbody: ts.Block,\n\t\tscope: Pick<LoweringScope, \"block\" | \"environment\">,\n\t): PlcFunction {\n\t\tconst expressions = new ExpressionLowering(this.context, {\n\t\t\t...scope,\n\t\t\tfn,\n\t\t\tvariables: this.moduleScope.bySymbol(),\n\t\t});\n\t\tfor (const [symbol, variable] of bindings) {\n\t\t\texpressions.bind(symbol, variable);\n\t\t}\n\t\tconst statements = new StatementLowering(this.context, expressions, fn);\n\t\treturn { ...fn, ...statements.lowerRoutine(body) };\n\t}\n\n\tprivate resolvePrograms(entries: FrontendOptions[\"programs\"]): PlcProgram[] {\n\t\tconst programs: PlcProgram[] = [];\n\t\tfor (const [name, entry] of Object.entries(entries)) {\n\t\t\tconst source = this.program.getSourceFile(\n\t\t\t\tresolve(this.root, entry.module),\n\t\t\t);\n\t\t\tif (!source) {\n\t\t\t\tthis.diagnostics.push(\n\t\t\t\t\terror(\"PLC4001\", `Program source not found: ${entry.module}.`),\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.guard(() => {\n\t\t\t\tconst moduleSymbol = this.checker.getSymbolAtLocation(source);\n\t\t\t\tconst exported =\n\t\t\t\t\tmoduleSymbol &&\n\t\t\t\t\tthis.checker\n\t\t\t\t\t\t.getExportsOfModule(moduleSymbol)\n\t\t\t\t\t\t.find((symbol) => symbol.name === entry.export);\n\t\t\t\tif (!exported) {\n\t\t\t\t\tthis.fail(\n\t\t\t\t\t\tsource,\n\t\t\t\t\t\t\"PLC4001\",\n\t\t\t\t\t\t`Program export ${entry.export} was not found.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst fn = this.routines.functions.get(\n\t\t\t\t\tunaliased(this.checker, exported),\n\t\t\t\t);\n\t\t\t\tif (!fn || fn.parameters.length || fn.result) {\n\t\t\t\t\tthis.fail(\n\t\t\t\t\t\tsource,\n\t\t\t\t\t\t\"PLC4001\",\n\t\t\t\t\t\t\"Program entry must be an implemented parameterless void function.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tprograms.push({ id: `program:${name}`, name, entry: fn.id });\n\t\t\t});\n\t\t}\n\t\treturn programs;\n\t}\n\n\tprivate dependency(node: ts.ImportDeclaration | ts.ExportDeclaration): void {\n\t\tif (!node.moduleSpecifier) {\n\t\t\treturn;\n\t\t}\n\t\tif (!ts.isStringLiteral(node.moduleSpecifier)) {\n\t\t\tthis.fail(node, \"PLC1001\", \"Only static module imports are supported.\");\n\t\t}\n\t\tconst resolved = ts.resolveModuleName(\n\t\t\tnode.moduleSpecifier.text,\n\t\t\tnode.getSourceFile().fileName,\n\t\t\tthis.program.getCompilerOptions(),\n\t\t\tthis.host,\n\t\t).resolvedModule;\n\t\tif (!resolved) {\n\t\t\tthis.fail(\n\t\t\t\tnode.moduleSpecifier,\n\t\t\t\t\"PLC1008\",\n\t\t\t\t\"This dependency could not be resolved to PLC source.\",\n\t\t\t);\n\t\t}\n\t\tif (!runtimeImport(node, this.checker)) {\n\t\t\treturn;\n\t\t}\n\t\tconst source = this.program.getSourceFile(resolved.resolvedFileName);\n\t\tif (source && !source.isDeclarationFile) {\n\t\t\treturn;\n\t\t}\n\t\tif (inSdk(this.sdk, resolved.resolvedFileName)) {\n\t\t\treturn;\n\t\t}\n\t\tconst authoredIo =\n\t\t\tsource &&\n\t\t\tthis.sources.includes(source) &&\n\t\t\tsource.statements.some(ts.isVariableStatement) &&\n\t\t\tsource.statements.every(\n\t\t\t\t(statement) =>\n\t\t\t\t\tts.isTypeAliasDeclaration(statement) ||\n\t\t\t\t\tts.isEmptyStatement(statement) ||\n\t\t\t\t\t(ts.isVariableStatement(statement) &&\n\t\t\t\t\t\tstatement.declarationList.declarations.every(\n\t\t\t\t\t\t\t(declaration) =>\n\t\t\t\t\t\t\t\tdeclaration.type && this.resolver.resolve(declaration.type).io,\n\t\t\t\t\t\t)),\n\t\t\t);\n\t\tif (authoredIo) {\n\t\t\treturn;\n\t\t}\n\t\tthis.fail(\n\t\t\tnode.moduleSpecifier,\n\t\t\t\"PLC1008\",\n\t\t\t\"Runtime dependencies need PLC TypeScript implementation source; JavaScript and declaration-only value imports are unsupported.\",\n\t\t);\n\t}\n\n\tprivate declaration(statement: ts.Statement): void {\n\t\tif (\n\t\t\tts.isImportDeclaration(statement) ||\n\t\t\tts.isExportDeclaration(statement)\n\t\t) {\n\t\t\tthis.dependency(statement);\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\tts.isClassDeclaration(statement) ||\n\t\t\tts.isTypeAliasDeclaration(statement) ||\n\t\t\tts.isInterfaceDeclaration(statement) ||\n\t\t\tts.isEmptyStatement(statement)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (ts.isEnumDeclaration(statement)) {\n\t\t\tthis.resolver.enumeration(statement);\n\t\t\treturn;\n\t\t}\n\t\tif (ts.isVariableStatement(statement)) {\n\t\t\tthis.moduleVariables(statement);\n\t\t\treturn;\n\t\t}\n\t\tif (ts.isFunctionDeclaration(statement)) {\n\t\t\tif (!statement.name || !statement.body) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tstatement,\n\t\t\t\t\t\"PLC1001\",\n\t\t\t\t\t\"PLC functions need a name and an implementation.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (hasModifier(statement, ts.SyntaxKind.AsyncKeyword)) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tstatement,\n\t\t\t\t\t\"PLC1007\",\n\t\t\t\t\t\"Async execution is not supported in PLC scan code.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (statement.asteriskToken) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tstatement,\n\t\t\t\t\t\"PLC1007\",\n\t\t\t\t\t\"Generators are not supported in PLC scan code.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.routines.declareFunction(\n\t\t\t\tthis.resolver.symbol(statement.name),\n\t\t\t\tstatement,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tthis.fail(\n\t\t\tstatement,\n\t\t\t\"PLC1001\",\n\t\t\t`${ts.SyntaxKind[statement.kind]} is not supported in PLC source.`,\n\t\t);\n\t}\n\n\tprivate moduleVariables(statement: ts.VariableStatement): void {\n\t\tif (\n\t\t\t!(\n\t\t\t\tstatement.declarationList.flags &\n\t\t\t\t(ts.NodeFlags.Let | ts.NodeFlags.Const)\n\t\t\t)\n\t\t) {\n\t\t\tthis.fail(statement, \"PLC1001\", \"Use let or const instead of var.\");\n\t\t}\n\t\tconst immutable = Boolean(\n\t\t\tstatement.declarationList.flags & ts.NodeFlags.Const,\n\t\t);\n\t\tfor (const declaration of statement.declarationList.declarations) {\n\t\t\tif (!ts.isIdentifier(declaration.name)) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tdeclaration.name,\n\t\t\t\t\t\"PLC1001\",\n\t\t\t\t\t\"Destructuring declarations are not supported.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst initializer =\n\t\t\t\tdeclaration.initializer &&\n\t\t\t\tstorageInitializer(declaration.initializer, this.resolver, this.fail);\n\t\t\tconst table =\n\t\t\t\tinitializer && this.tableType(declaration, initializer.value);\n\t\t\tconst instance =\n\t\t\t\tinitializer &&\n\t\t\t\tthis.allocatedBlock(declaration, initializer.value, table);\n\t\t\tif (table && !immutable) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"A readonly table is a const declaration.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst type = this.storageType(declaration, {\n\t\t\t\tinstance,\n\t\t\t\ttable,\n\t\t\t\timmutable,\n\t\t\t\tinitializer: initializer?.value,\n\t\t\t});\n\t\t\tconst ambient = declaration.getSourceFile().isDeclarationFile;\n\t\t\tif (type.mode || this.resolver.hasReferences(type.type)) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Borrow schemas cannot be stored as values.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (this.resolver.types.get(type.type)?.kind === \"block\" && !instance) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t\"PLC1007\",\n\t\t\t\t\t\"Block instances require a static constructor initializer.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tinstance &&\n\t\t\t\t(!immutable ||\n\t\t\t\t\t(declaration.type &&\n\t\t\t\t\t\tthis.resolver.resolve(declaration.type).type !== instance))\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Static block instances require const bindings and matching annotations.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst retention = initializer?.retention ?? \"none\";\n\t\t\tif (\n\t\t\t\tretention !== \"none\" &&\n\t\t\t\t(ambient ||\n\t\t\t\t\t(immutable &&\n\t\t\t\t\t\ttype.type !== \"inferred\" &&\n\t\t\t\t\t\t!instance &&\n\t\t\t\t\t\t!aggregate(this.resolver.types.get(type.type))))\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t\"PLC3004\",\n\t\t\t\t\t`${retention} requires mutable persistent storage or a static block instance.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (ambient && !type.io) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t\"PLC4002\",\n\t\t\t\t\t\"Ambient PLC variables must declare Input or Output.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!ambient && type.io) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t\"PLC4002\",\n\t\t\t\t\t\"Logical I/O belongs in an ambient declaration file.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (type.io === \"input\" && !immutable) {\n\t\t\t\tthis.fail(declaration, \"PLC4002\", \"Inputs must use declare const.\");\n\t\t\t}\n\t\t\tif (type.io === \"output\" && immutable) {\n\t\t\t\tthis.fail(declaration, \"PLC4002\", \"Outputs must use declare let.\");\n\t\t\t}\n\t\t\tconst variable: Variable = {\n\t\t\t\tid: this.resolver.id(declaration, declaration.name.text),\n\t\t\t\tname: declaration.name.text,\n\t\t\t\ttype: type.type,\n\t\t\t\tstorage: this.storageClass(type, { instance, table, immutable }),\n\t\t\t\tmutable: !immutable,\n\t\t\t\tretention,\n\t\t\t\t...(hasModifier(statement, ts.SyntaxKind.ExportKeyword) && {\n\t\t\t\t\texported: true as const,\n\t\t\t\t}),\n\t\t\t\tspan: this.positions.node(declaration),\n\t\t\t};\n\t\t\tthis.moduleScope.bind(this.resolver.symbol(declaration.name), variable);\n\t\t\tthis.globalVariables.push(variable);\n\t\t}\n\t}\n\n\t/** The block a static instance or instance-array initializer allocates. */\n\tprivate allocatedBlock(\n\t\tdeclaration: ts.VariableDeclaration,\n\t\tinitializer: ts.Expression,\n\t\ttable: ResolvedType | undefined,\n\t): string | undefined {\n\t\tif (ts.isNewExpression(initializer)) {\n\t\t\treturn this.blocks.instanceType(initializer);\n\t\t}\n\t\treturn table\n\t\t\t? undefined\n\t\t\t: this.blocks.instanceArrayType(declaration.type, initializer);\n\t}\n\n\t/** An unannotated const takes its initializer's type once initializers resolve. */\n\tprivate storageType(\n\t\tdeclaration: ts.VariableDeclaration,\n\t\t{ instance, table, immutable, initializer }: StorageFacts,\n\t): ResolvedType {\n\t\tif (instance) {\n\t\t\treturn { type: instance };\n\t\t}\n\t\tif (table) {\n\t\t\treturn table;\n\t\t}\n\t\tif (declaration.type) {\n\t\t\treturn this.resolver.resolve(declaration.type);\n\t\t}\n\t\tif (immutable) {\n\t\t\treturn { type: \"inferred\" };\n\t\t}\n\t\t// Without an initializer, initializing storage reports the missing one.\n\t\tif (!initializer) {\n\t\t\treturn { type: \"BOOL\" };\n\t\t}\n\t\treturn {\n\t\t\ttype:\n\t\t\t\tinferredStorageType(initializer) ??\n\t\t\t\tthis.fail(declaration, \"PLC2001\", \"Annotate PLC storage explicitly.\"),\n\t\t};\n\t}\n\n\t/** A const record or array keeps mutable fields, so only scalars and readonly tables are constants. */\n\tprivate storageClass(\n\t\ttype: ResolvedType,\n\t\t{ instance, table, immutable }: Omit<StorageFacts, \"initializer\">,\n\t): Variable[\"storage\"] {\n\t\tif (instance) {\n\t\t\treturn \"instance\";\n\t\t}\n\t\tif (type.io) {\n\t\t\treturn type.io;\n\t\t}\n\t\treturn immutable &&\n\t\t\t(table || !aggregate(this.resolver.types.get(type.type)))\n\t\t\t? \"constant\"\n\t\t\t: \"module\";\n\t}\n\n\t/**\n\t * `const table: readonly T[] = [...]` or `const table = [...] as const satisfies readonly T[]`,\n\t * also spelled `ReadonlyArray<T>`, is a constant `FixedArray<T, N>` whose length is the\n\t * literal's element count.\n\t */\n\tprivate tableType(\n\t\tdeclaration: ts.VariableDeclaration,\n\t\tinitializer: ts.Expression,\n\t): ResolvedType | undefined {\n\t\tconst satisfied = ts.isSatisfiesExpression(initializer)\n\t\t\t? initializer\n\t\t\t: undefined;\n\t\tconst annotation = declaration.type ?? satisfied?.type;\n\t\tif (!annotation) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst element = this.readonlyElement(annotation);\n\t\tif (!element) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst literal = withoutConstAssertion(satisfied?.expression ?? initializer);\n\t\tif (!ts.isArrayLiteralExpression(literal)) {\n\t\t\tthis.fail(\n\t\t\t\tdeclaration,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"A readonly table is initialized by an array literal.\",\n\t\t\t);\n\t\t}\n\t\treturn this.resolver.fixedArray(\n\t\t\tannotation,\n\t\t\tthis.resolver.resolve(element),\n\t\t\t{ kind: \"integer\", value: literal.elements.length },\n\t\t\t{ kind: \"integer\", value: 0 },\n\t\t);\n\t}\n\n\t/** The element type of `readonly T[]` or the standard `ReadonlyArray<T>`. */\n\tprivate readonlyElement(annotation: ts.TypeNode): ts.TypeNode | undefined {\n\t\tif (\n\t\t\tts.isTypeOperatorNode(annotation) &&\n\t\t\tannotation.operator === ts.SyntaxKind.ReadonlyKeyword &&\n\t\t\tts.isArrayTypeNode(annotation.type)\n\t\t) {\n\t\t\treturn annotation.type.elementType;\n\t\t}\n\t\tif (\n\t\t\tts.isTypeReferenceNode(annotation) &&\n\t\t\tannotation.typeName.getText() === \"ReadonlyArray\" &&\n\t\t\tannotation.typeArguments?.length === 1 &&\n\t\t\tthis.resolver.standardLibrary(this.resolver.symbol(annotation.typeName))\n\t\t) {\n\t\t\treturn annotation.typeArguments[0];\n\t\t}\n\t\treturn undefined;\n\t}\n}\n\nconst withoutConstAssertion = (node: ts.Expression): ts.Expression =>\n\tts.isParenthesizedExpression(node) ||\n\t(ts.isAsExpression(node) && ts.isConstTypeReference(node.type))\n\t\t? withoutConstAssertion(node.expression)\n\t\t: node;\n",
7
+ "import {\n\tdefaultValue,\n\ttype FunctionBlock,\n\tinstancedBlock,\n\ttype Retention,\n\ttype SourceSpan,\n\ttype StandardBlock,\n\tstandardBlocks,\n\ttype Variable,\n} from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport {\n\tcalleeName,\n\ttype Fail,\n\thasModifier,\n\tinferredStorageType,\n\tSemanticError,\n\ttype TypeResolver,\n} from \"./types\";\n\nexport interface BlockSource {\n\tblock: FunctionBlock;\n\t/** The block's layout. */\n\ttype: string;\n\t/** The body of its `execute` method. */\n\tbody: ts.Block;\n\tmethods: readonly ts.MethodDeclaration[];\n\tinputSymbol: ts.Symbol;\n\tinputBindings: ReadonlyMap<string, Variable>;\n\tfieldBindings: ReadonlyMap<ts.Symbol, Variable>;\n\tinitializers: ReadonlyMap<Variable, ts.Expression>;\n}\n/** The SDK call an initializer is wrapped in to keep its storage through restarts, and what it keeps. */\nconst retentionCalls: ReadonlyMap<string, Retention> = new Map([\n\t[\"persist\", \"persist\"],\n\t[\"retain\", \"retain\"],\n]);\n\nexport function storageInitializer(\n\tnode: ts.Expression,\n\ttypes: TypeResolver,\n\tfail: Fail,\n): { value: ts.Expression; retention: Retention } {\n\tif (!ts.isCallExpression(node)) {\n\t\treturn { value: node, retention: \"none\" };\n\t}\n\tconst callee = calleeName(node.expression);\n\tconst name = callee && types.sdkName(callee);\n\tconst retention = name && retentionCalls.get(name);\n\tif (!name || !retention) {\n\t\treturn { value: node, retention: \"none\" };\n\t}\n\tconst [value, ...rest] = node.arguments;\n\tif (!value || rest.length || (node.typeArguments?.length ?? 0) > 1) {\n\t\tfail(node, \"PLC3004\", `${name} requires one static storage initializer.`);\n\t}\n\treturn { value, retention };\n}\n\n/** How deep block instances may nest inside one another's state. */\nconst maxInstanceNesting = 64;\n\nconst isStandardBlock = (name: string): name is StandardBlock =>\n\tObject.hasOwn(standardBlocks, name);\n\nexport class BlockResolver {\n\treadonly definitions = new Map<string, FunctionBlock>();\n\treadonly sources = new Map<ts.Symbol, BlockSource>();\n\tprivate readonly declarations = new Map<ts.Symbol, ts.ClassDeclaration>();\n\t/** Classes whose collection failed, so another instance reports nothing new. */\n\tprivate readonly failures = new Map<ts.Symbol, SemanticError>();\n\tprivate readonly active = new Set<ts.Symbol>();\n\tconstructor(\n\t\tprivate readonly types: TypeResolver,\n\t\tprivate readonly origin: (node: ts.Node) => SourceSpan,\n\t\tprivate readonly fail: Fail,\n\t\tsdkSpan: SourceSpan,\n\t) {\n\t\tfor (const name of Object.keys(standardBlocks).filter(isStandardBlock)) {\n\t\t\tconst schema = standardBlocks[name];\n\t\t\tconst id = `stdlib:${name}`;\n\t\t\tconst output = `${id}:out`;\n\t\t\tconst variable = (\n\t\t\t\tlabel: string,\n\t\t\t\ttype: string,\n\t\t\t\tstorage: Variable[\"storage\"],\n\t\t\t): Variable => ({\n\t\t\t\tid: `${id}:${label}`,\n\t\t\t\tname: label,\n\t\t\t\ttype,\n\t\t\t\tstorage,\n\t\t\t\tmutable: false,\n\t\t\t\tretention: \"none\",\n\t\t\t\tspan: sdkSpan,\n\t\t\t\t...(storage === \"blockOutput\" && {\n\t\t\t\t\tinitial: defaultValue(type, types.types),\n\t\t\t\t}),\n\t\t\t});\n\t\t\tconst block: FunctionBlock = {\n\t\t\t\tid,\n\t\t\t\tname,\n\t\t\t\tinputs: schema.inputs.map(([label, , type]) =>\n\t\t\t\t\tvariable(label, type, \"parameter\"),\n\t\t\t\t),\n\t\t\t\toutputs: schema.outputs.map(([label, , type]) =>\n\t\t\t\t\tvariable(label, type, \"blockOutput\"),\n\t\t\t\t),\n\t\t\t\tstate: [],\n\t\t\t\tlocals: [],\n\t\t\t\tbody: [],\n\t\t\t\tresult: output,\n\t\t\t\tstandard: name,\n\t\t\t\tspan: sdkSpan,\n\t\t\t};\n\t\t\tthis.definitions.set(id, block);\n\t\t\ttypes.declareStandardBlock(name, id, {\n\t\t\t\tid: output,\n\t\t\t\tfields: block.outputs.map((field) => ({\n\t\t\t\t\tname: field.name,\n\t\t\t\t\ttype: field.type,\n\t\t\t\t\treadonly: true,\n\t\t\t\t})),\n\t\t\t});\n\t\t}\n\t}\n\n\t/** Makes named classes allocatable; `collect` reports a class without a name. */\n\tindex(nodes: readonly ts.ClassDeclaration[]): void {\n\t\tfor (const node of nodes) {\n\t\t\tif (node.name) {\n\t\t\t\tthis.declarations.set(this.types.symbol(node.name), node);\n\t\t\t}\n\t\t}\n\t}\n\n\tinstanceType(node: ts.NewExpression): string {\n\t\tconst name = calleeName(node.expression);\n\t\tif (node.arguments?.length || node.typeArguments?.length || !name) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1007\",\n\t\t\t\t\"Block instances use a concrete zero-argument constructor at static storage declarations.\",\n\t\t\t);\n\t\t}\n\t\tconst official = this.types.sdkName(name);\n\t\tconst standard = official && this.types.standardBlock(official);\n\t\tif (standard) {\n\t\t\treturn standard;\n\t\t}\n\t\tconst declaration = this.declarations.get(this.types.symbol(name));\n\t\tif (!declaration) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1007\",\n\t\t\t\t\"Only recognized static function block allocation is supported.\",\n\t\t\t);\n\t\t}\n\t\treturn this.collect(declaration).type;\n\t}\n\n\t/**\n\t * `FixedArray<Block, N>` storage allocated with `defaultValue`; its elements are static\n\t * instances. The allocation names the type, so an annotation is optional but must agree.\n\t */\n\tinstanceArrayType(\n\t\tannotation: ts.TypeNode | undefined,\n\t\tvalue: ts.Expression,\n\t): string | undefined {\n\t\tconst blockArray = (type: string) =>\n\t\t\tthis.types.types.get(type)?.kind === \"array\" &&\n\t\t\tinstancedBlock(type, this.types.types)\n\t\t\t\t? type\n\t\t\t\t: undefined;\n\t\tconst declared = annotation && this.types.resolve(annotation).type;\n\t\tif (declared && !blockArray(declared)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst callee = ts.isCallExpression(value) && calleeName(value.expression);\n\t\tconst allocated =\n\t\t\tcallee &&\n\t\t\tthis.types.sdkName(callee) === \"defaultValue\" &&\n\t\t\tvalue.typeArguments?.length === 1\n\t\t\t\t? value.typeArguments[0]\n\t\t\t\t: undefined;\n\t\tconst allocation = allocated && this.types.resolve(allocated).type;\n\t\tif (!declared) {\n\t\t\treturn allocation && blockArray(allocation);\n\t\t}\n\t\tif (allocation !== declared) {\n\t\t\tthis.fail(\n\t\t\t\tvalue,\n\t\t\t\t\"PLC1007\",\n\t\t\t\t\"Block arrays allocate with defaultValue<FixedArray<Block, N>>() of their declared type.\",\n\t\t\t);\n\t\t}\n\t\treturn declared;\n\t}\n\n\tcollect(node: ts.ClassDeclaration): BlockSource {\n\t\tif (!node.name) {\n\t\t\tthis.fail(node, \"PLC1001\", \"Function block classes need names.\");\n\t\t}\n\t\tconst symbol = this.types.symbol(node.name);\n\t\tconst collected = this.sources.get(symbol);\n\t\tif (collected) {\n\t\t\treturn collected;\n\t\t}\n\t\tconst failure = this.failures.get(symbol);\n\t\tif (failure) {\n\t\t\tthrow failure;\n\t\t}\n\t\ttry {\n\t\t\treturn this.collectClass(node, node.name, symbol);\n\t\t} catch (cause) {\n\t\t\tif (cause instanceof SemanticError) {\n\t\t\t\tthis.failures.set(symbol, cause);\n\t\t\t}\n\t\t\tthrow cause;\n\t\t}\n\t}\n\n\tprivate collectClass(\n\t\tnode: ts.ClassDeclaration,\n\t\tname: ts.Identifier,\n\t\tsymbol: ts.Symbol,\n\t): BlockSource {\n\t\tif (this.active.has(symbol) || this.active.size >= maxInstanceNesting) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1007\",\n\t\t\t\t\"Recursive or excessively nested block instance layout.\",\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\tnode.typeParameters?.length ||\n\t\t\tnode.modifiers?.some(\n\t\t\t\t(modifier) =>\n\t\t\t\t\tmodifier.kind === ts.SyntaxKind.Decorator ||\n\t\t\t\t\tmodifier.kind === ts.SyntaxKind.AbstractKeyword,\n\t\t\t)\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1001\",\n\t\t\t\t\"Block classes are concrete; generic classes and decorators are unsupported.\",\n\t\t\t);\n\t\t}\n\t\tconst [heritage, ...otherHeritage] = node.heritageClauses ?? [];\n\t\tconst [base, ...otherBases] = heritage?.types ?? [];\n\t\tif (\n\t\t\totherHeritage.length ||\n\t\t\theritage?.token !== ts.SyntaxKind.ExtendsKeyword ||\n\t\t\t!base ||\n\t\t\totherBases.length\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1001\",\n\t\t\t\t\"Function block classes extend the canonical FunctionBlock marker only.\",\n\t\t\t);\n\t\t}\n\t\tconst [inputNode, outputNode, ...otherSchemas] = base.typeArguments ?? [];\n\t\tif (\n\t\t\tthis.types.sdkName(base.expression) !== \"FunctionBlock\" ||\n\t\t\t!inputNode ||\n\t\t\totherSchemas.length\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tbase,\n\t\t\t\t\"PLC1001\",\n\t\t\t\t\"Extend FunctionBlock<Inputs, Outputs> with concrete schemas.\",\n\t\t\t);\n\t\t}\n\t\t// Register identity before nested fields; the active set rejects recursive allocation.\n\t\tthis.active.add(symbol);\n\t\tconst id = this.types.id(node, name.text);\n\t\tconst typeId = this.types.declareBlock(symbol, id);\n\t\ttry {\n\t\t\tconst inputFields = this.types.inputFields(inputNode);\n\t\t\tconst result = outputNode && this.outputRecord(outputNode);\n\t\t\tconst fieldBindings = new Map<ts.Symbol, Variable>();\n\t\t\tconst initializers = new Map<Variable, ts.Expression>();\n\t\t\tconst state: Variable[] = [];\n\t\t\tlet execute: { method: ts.MethodDeclaration; body: ts.Block } | undefined;\n\t\t\tconst methods: ts.MethodDeclaration[] = [];\n\t\t\tfor (const member of node.members) {\n\t\t\t\tif (ts.isMethodDeclaration(member)) {\n\t\t\t\t\tif (ts.isIdentifier(member.name) && member.name.text !== \"execute\") {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!member.body ||\n\t\t\t\t\t\t\tmember.asteriskToken ||\n\t\t\t\t\t\t\tmember.questionToken ||\n\t\t\t\t\t\t\tmember.typeParameters?.length ||\n\t\t\t\t\t\t\t[\"update\", \"out\"].includes(member.name.text) ||\n\t\t\t\t\t\t\tmember.modifiers?.some(\n\t\t\t\t\t\t\t\t(modifier) =>\n\t\t\t\t\t\t\t\t\t![\n\t\t\t\t\t\t\t\t\t\tts.SyntaxKind.PublicKeyword,\n\t\t\t\t\t\t\t\t\t\tts.SyntaxKind.PrivateKeyword,\n\t\t\t\t\t\t\t\t\t\tts.SyntaxKind.ProtectedKeyword,\n\t\t\t\t\t\t\t\t\t].includes(modifier.kind),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthis.fail(\n\t\t\t\t\t\t\t\tmember,\n\t\t\t\t\t\t\t\t\"PLC1001\",\n\t\t\t\t\t\t\t\t\"Block methods require concrete instance implementations without generics or overloads.\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmethods.push(member);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\texecute ||\n\t\t\t\t\t\t!ts.isIdentifier(member.name) ||\n\t\t\t\t\t\tmember.name.text !== \"execute\" ||\n\t\t\t\t\t\t!member.body ||\n\t\t\t\t\t\tmember.asteriskToken ||\n\t\t\t\t\t\tmember.modifiers?.some(\n\t\t\t\t\t\t\t(modifier) =>\n\t\t\t\t\t\t\t\t![\n\t\t\t\t\t\t\t\t\tts.SyntaxKind.ProtectedKeyword,\n\t\t\t\t\t\t\t\t\tts.SyntaxKind.OverrideKeyword,\n\t\t\t\t\t\t\t\t].includes(modifier.kind),\n\t\t\t\t\t\t) ||\n\t\t\t\t\t\t!hasModifier(member, ts.SyntaxKind.ProtectedKeyword)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.fail(\n\t\t\t\t\t\t\tmember,\n\t\t\t\t\t\t\t\"PLC1001\",\n\t\t\t\t\t\t\t\"A block implements one protected execute method.\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\texecute = { method: member, body: member.body };\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst field = this.collectStateField(member, id);\n\t\t\t\tstate.push(field.variable);\n\t\t\t\tfieldBindings.set(field.symbol, field.variable);\n\t\t\t\tif (field.initializer) {\n\t\t\t\t\tinitializers.set(field.variable, field.initializer);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst parameter = execute?.method.parameters[0];\n\t\t\tif (\n\t\t\t\t!execute ||\n\t\t\t\t!parameter ||\n\t\t\t\texecute.method.parameters.length !== 1 ||\n\t\t\t\texecute.method.typeParameters?.length\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC1001\",\n\t\t\t\t\t\"Block execute requires one concrete input record parameter.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst { method, body } = execute;\n\t\t\tif (\n\t\t\t\t!ts.isIdentifier(parameter.name) ||\n\t\t\t\t!parameter.type ||\n\t\t\t\tparameter.initializer ||\n\t\t\t\tparameter.questionToken ||\n\t\t\t\tparameter.dotDotDotToken\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tparameter,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Block execute requires one named, explicitly typed input parameter.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst methodFields = this.types.inputFields(parameter.type);\n\t\t\tif (JSON.stringify(methodFields) !== JSON.stringify(inputFields)) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tparameter,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"execute input schema differs from its FunctionBlock marker.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (\n\t\t\t\t!method.type ||\n\t\t\t\t(result\n\t\t\t\t\t? this.types.resolve(method.type).type !== result\n\t\t\t\t\t: method.type.kind !== ts.SyntaxKind.VoidKeyword)\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tmethod,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"execute return annotation must match the complete output record, or void when there are no outputs.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst inputs = inputFields.map((field) => {\n\t\t\t\tconst mode = this.types.parameterMode(field);\n\t\t\t\treturn {\n\t\t\t\t\tid: `${id}:input:${field.name}`,\n\t\t\t\t\tname: field.name,\n\t\t\t\t\ttype: field.type,\n\t\t\t\t\tstorage: \"parameter\" as const,\n\t\t\t\t\tmutable: mode === \"inOut\",\n\t\t\t\t\tretention: \"none\" as const,\n\t\t\t\t\tspan: this.origin(parameter),\n\t\t\t\t\t...(mode && { mode }),\n\t\t\t\t};\n\t\t\t});\n\t\t\tconst outputType = result && this.types.types.get(result);\n\t\t\tconst outputs: Variable[] =\n\t\t\t\toutputType && outputType.kind === \"record\"\n\t\t\t\t\t? outputType.fields.map((field) => ({\n\t\t\t\t\t\t\tid: `${id}:output:${field.name}`,\n\t\t\t\t\t\t\tname: field.name,\n\t\t\t\t\t\t\ttype: field.type,\n\t\t\t\t\t\t\tstorage: \"blockOutput\",\n\t\t\t\t\t\t\tmutable: false,\n\t\t\t\t\t\t\tretention: \"none\",\n\t\t\t\t\t\t\tinitial: defaultValue(field.type, this.types.types),\n\t\t\t\t\t\t\tspan: this.origin(method),\n\t\t\t\t\t\t}))\n\t\t\t\t\t: [];\n\t\t\tconst block: FunctionBlock = {\n\t\t\t\tid,\n\t\t\t\tname: name.text,\n\t\t\t\tinputs,\n\t\t\t\toutputs,\n\t\t\t\tstate,\n\t\t\t\tlocals: [],\n\t\t\t\tbody: [],\n\t\t\t\tspan: this.origin(node),\n\t\t\t\t...(result && { result }),\n\t\t\t};\n\t\t\tthis.definitions.set(id, block);\n\t\t\tif (result) {\n\t\t\t\tthis.types.blockOutput(typeId, id, result);\n\t\t\t}\n\t\t\tconst source: BlockSource = {\n\t\t\t\tblock,\n\t\t\t\ttype: typeId,\n\t\t\t\tbody,\n\t\t\t\tmethods,\n\t\t\t\tinputSymbol: this.types.symbol(parameter.name),\n\t\t\t\tinputBindings: new Map(\n\t\t\t\t\tinputs.map((variable) => [variable.name, variable]),\n\t\t\t\t),\n\t\t\t\tfieldBindings,\n\t\t\t\tinitializers,\n\t\t\t};\n\t\t\tthis.sources.set(symbol, source);\n\t\t\treturn source;\n\t\t} finally {\n\t\t\tthis.active.delete(symbol);\n\t\t}\n\t}\n\t/** The record an output schema names; undefined for `{}`, a block without outputs. */\n\tprivate outputRecord(node: ts.TypeNode): string | undefined {\n\t\tif (ts.isTypeLiteralNode(node) && !node.members.length) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst resolved = this.types.resolve(node);\n\t\tif (\n\t\t\tresolved.io ||\n\t\t\tresolved.mode ||\n\t\t\tthis.types.hasReferences(resolved.type) ||\n\t\t\tthis.types.types.get(resolved.type)?.kind !== \"record\"\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Block outputs require a closed value record.\",\n\t\t\t);\n\t\t}\n\t\treturn resolved.type;\n\t}\n\n\tprivate collectStateField(\n\t\tmember: ts.ClassElement,\n\t\tid: string,\n\t): {\n\t\tvariable: Variable;\n\t\tsymbol: ts.Symbol;\n\t\tinitializer?: ts.Expression;\n\t} {\n\t\tif (\n\t\t\t!ts.isPropertyDeclaration(member) ||\n\t\t\t!ts.isIdentifier(member.name) ||\n\t\t\t!member.initializer ||\n\t\t\tmember.questionToken ||\n\t\t\tmember.exclamationToken ||\n\t\t\t!hasModifier(member, ts.SyntaxKind.PrivateKeyword) ||\n\t\t\tmember.modifiers?.some(\n\t\t\t\t(modifier) =>\n\t\t\t\t\t![\n\t\t\t\t\t\tts.SyntaxKind.PrivateKeyword,\n\t\t\t\t\t\tts.SyntaxKind.ReadonlyKeyword,\n\t\t\t\t\t].includes(modifier.kind),\n\t\t\t)\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tmember,\n\t\t\t\t\"PLC1001\",\n\t\t\t\t\"Block state uses private initialized instance fields; constructors, static fields and decorators are unsupported.\",\n\t\t\t);\n\t\t}\n\t\tconst initial = storageInitializer(\n\t\t\tmember.initializer,\n\t\t\tthis.types,\n\t\t\tthis.fail,\n\t\t);\n\t\tconst type = this.stateType(member, initial.value);\n\t\tconst instance = Boolean(instancedBlock(type, this.types.types));\n\t\tif (\n\t\t\tthis.types.types.get(type)?.kind === \"block\" &&\n\t\t\t!ts.isNewExpression(initial.value)\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tmember,\n\t\t\t\t\"PLC1007\",\n\t\t\t\t\"Block instances require static constructor initialization.\",\n\t\t\t);\n\t\t}\n\t\tconst variable: Variable = {\n\t\t\tid: `${id}:field:${member.name.text}`,\n\t\t\tname: member.name.text,\n\t\t\ttype,\n\t\t\tstorage: instance ? \"instance\" : \"field\",\n\t\t\tmutable: !instance && !hasModifier(member, ts.SyntaxKind.ReadonlyKeyword),\n\t\t\tretention: initial.retention,\n\t\t\tspan: this.origin(member),\n\t\t};\n\t\treturn {\n\t\t\tvariable,\n\t\t\tsymbol: this.types.symbol(member.name),\n\t\t\t...(!instance && { initializer: initial.value }),\n\t\t};\n\t}\n\n\t/** A state field's type: the block or block array it allocates, its annotation, or its literal's type. */\n\tprivate stateType(\n\t\tmember: ts.PropertyDeclaration,\n\t\tvalue: ts.Expression,\n\t): string {\n\t\tif (ts.isNewExpression(value)) {\n\t\t\tconst instance = this.instanceType(value);\n\t\t\tif (member.type && this.types.resolve(member.type).type !== instance) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tmember,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Instance annotation differs from its constructor.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn instance;\n\t\t}\n\t\tconst instanceArray = this.instanceArrayType(member.type, value);\n\t\tif (instanceArray) {\n\t\t\treturn instanceArray;\n\t\t}\n\t\tif (!member.type) {\n\t\t\treturn (\n\t\t\t\tinferredStorageType(value) ??\n\t\t\t\tthis.fail(\n\t\t\t\t\tmember,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Annotate private numeric and aggregate state explicitly.\",\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t\tconst annotation = this.types.resolve(member.type);\n\t\tif (\n\t\t\tannotation.io ||\n\t\t\tannotation.mode ||\n\t\t\tthis.types.hasReferences(annotation.type)\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tmember,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Borrow and I/O wrappers cannot be stored in block state.\",\n\t\t\t);\n\t\t}\n\t\treturn annotation.type;\n\t}\n}\n",
8
+ "import { dirname } from \"node:path\";\nimport {\n\taggregate,\n\ttype Diagnostic,\n\ttype Field,\n\tinstancedBlock,\n\tisRadixLiteral,\n\tlayoutIssue,\n\tmaxNestingDepth,\n\tmaxScalarElements,\n\tmaxScalarElementsText,\n\tmaxStringCapacity,\n\ttype PlcType,\n\tparseInteger,\n\tpascalCase,\n\tprimitiveTypes,\n} from \"@tsplc/compiler/ir\";\nimport { defaultStringLength, elementaryType, integerRange } from \"@tsplc/iec\";\nimport { generatedNamePattern } from \"@tsplc/iec/st\";\nimport ts from \"typescript\";\nimport { modulePath } from \"./lowering-key\";\nimport {\n\tdeclaredBySdk,\n\tisTelemetryDeclaration,\n\ttelemetryMethods,\n\tunaliased,\n\tvalueSymbol,\n} from \"./sdk\";\n\nexport interface ResolvedType {\n\ttype: string;\n\tio?: \"input\" | \"output\";\n\tmode?: \"inOut\";\n}\nexport type TypeArgument =\n\t| { kind: \"type\"; value: ResolvedType }\n\t| { kind: \"integer\"; value: number };\nexport type TypeEnvironment = ReadonlyMap<ts.Symbol, TypeArgument>;\nexport type Fail = (node: ts.Node, code: string, message: string) => never;\n\n// Array bounds and indexes are DINT, and so is every integer a layout takes as an argument and\n// every PLC enum value.\nconst [lowestDint, highestDint] = integerRange(elementaryType(\"DINT\"));\n/** How many generic declarations may be expanding at once, which bounds recursive expansion. */\nconst maxSubstitutionDepth = 64;\n\n/** What a Fail throws: one diagnostic that abandons the declaration or routine being analyzed. */\nexport class SemanticError extends Error {\n\tconstructor(readonly diagnostic: Diagnostic) {\n\t\tsuper(diagnostic.message);\n\t}\n}\n\n/** The PLC types an unannotated TypeScript `number` holds, whole or fractional, and a `bigint`. */\nexport const defaultNumericTypes = {\n\tnumber: \"DINT\",\n\tfloat: \"LREAL\",\n\tbigint: \"LINT\",\n} as const;\n\n// The PLC type of an unannotated numeric literal: `number` means DINT unless it is fractional.\nexport const numericLiteralType = (text: string) => {\n\tif (text.endsWith(\"n\")) {\n\t\treturn defaultNumericTypes.bigint;\n\t}\n\treturn /[.e]/i.test(text) && !isRadixLiteral(text)\n\t\t? defaultNumericTypes.float\n\t\t: defaultNumericTypes.number;\n};\n\n/** The expression inside any parentheses, and inside non-null assertions when `nonNull` is set. */\nexport const unparenthesized = (\n\tnode: ts.Expression,\n\toptions?: { nonNull: boolean },\n): ts.Expression =>\n\tts.isParenthesizedExpression(node) ||\n\t(options?.nonNull && ts.isNonNullExpression(node))\n\t\t? unparenthesized(node.expression, options)\n\t\t: node;\n\n/** `T` in a `Promise<T>` annotation. */\nexport const promisedType = (node: ts.TypeNode): ts.TypeNode | undefined =>\n\tts.isTypeReferenceNode(node) &&\n\tts.isIdentifier(node.typeName) &&\n\tnode.typeName.text === \"Promise\" &&\n\tnode.typeArguments?.length === 1\n\t\t? node.typeArguments[0]\n\t\t: undefined;\n\n/** The name of a record value's type: its alias or its named declaration; undefined for a scalar or an anonymous type. */\nexport const namedRecordText = (\n\tchecker: ts.TypeChecker,\n\tnode: ts.Expression,\n): string | undefined => {\n\tconst type = checker.getTypeAtLocation(node);\n\tif (\n\t\t!(type.flags & ts.TypeFlags.Object) ||\n\t\t(!type.aliasSymbol && (!type.symbol || type.symbol.name === \"__type\"))\n\t) {\n\t\treturn undefined;\n\t}\n\treturn checker.typeToString(\n\t\ttype,\n\t\tnode,\n\t\tts.TypeFormatFlags.NoTruncation |\n\t\t\tts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope,\n\t);\n};\n\n/** Whether a node only wraps the expression in it: parentheses, a non-null assertion or a type assertion. */\nexport const isWrapper = (\n\tnode: ts.Node,\n): node is\n\t| ts.ParenthesizedExpression\n\t| ts.NonNullExpression\n\t| ts.AsExpression\n\t| ts.SatisfiesExpression =>\n\tts.isParenthesizedExpression(node) ||\n\tts.isNonNullExpression(node) ||\n\tts.isAsExpression(node) ||\n\tts.isSatisfiesExpression(node);\n\n/**\n * The name of the field, parameter or variable an inline type or object literal is written for,\n * through the arrays and unions it is an element or member of: `points` of `points: { x: DINT }[]`.\n */\nexport const declaringName = (\n\tnode: ts.Node | undefined,\n): string | undefined => {\n\tif (!node) {\n\t\treturn undefined;\n\t}\n\tif (\n\t\t(ts.isPropertySignature(node) ||\n\t\t\tts.isPropertyDeclaration(node) ||\n\t\t\tts.isPropertyAssignment(node) ||\n\t\t\tts.isParameter(node) ||\n\t\t\tts.isVariableDeclaration(node)) &&\n\t\tts.isIdentifier(node.name)\n\t) {\n\t\treturn node.name.text;\n\t}\n\tif (\n\t\tts.isArrayTypeNode(node) ||\n\t\tts.isUnionTypeNode(node) ||\n\t\tts.isParenthesizedTypeNode(node) ||\n\t\tts.isTypeReferenceNode(node) ||\n\t\tts.isArrayLiteralExpression(node) ||\n\t\tisWrapper(node)\n\t) {\n\t\treturn declaringName(node.parent);\n\t}\n\treturn undefined;\n};\n\n/** Whether `type` is an aggregate (a record, array or block) rather than a scalar. */\nexport const isAggregateType = (type: ts.Type): boolean =>\n\tBoolean(type.flags & ts.TypeFlags.Object);\n\n// The source text of a numeric literal, negated literals included.\nexport function numericLiteral(node: ts.Expression): string | undefined {\n\tconst literal = unparenthesized(node);\n\tif (ts.isNumericLiteral(literal) || ts.isBigIntLiteral(literal)) {\n\t\treturn literal.getText();\n\t}\n\tif (\n\t\tts.isPrefixUnaryExpression(literal) &&\n\t\tliteral.operator === ts.SyntaxKind.MinusToken\n\t) {\n\t\tconst operand = numericLiteral(literal.operand);\n\t\tif (operand !== undefined) {\n\t\t\treturn operand.startsWith(\"-\") ? operand.slice(1) : `-${operand}`;\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/** The PLC type of storage declared without an annotation: only a numeric or boolean literal says it. */\nexport const inferredStorageType = (\n\tinitializer: ts.Expression,\n): string | undefined => {\n\tif (\n\t\tinitializer.kind === ts.SyntaxKind.TrueKeyword ||\n\t\tinitializer.kind === ts.SyntaxKind.FalseKeyword\n\t) {\n\t\treturn \"BOOL\";\n\t}\n\tconst literal = numericLiteral(initializer);\n\treturn literal === undefined ? undefined : numericLiteralType(literal);\n};\n\n/** The integer a literal names exactly; undefined when it has a fraction or is not a literal. */\nconst exactInteger = (text: string): bigint | undefined => {\n\ttry {\n\t\treturn parseInteger(text);\n\t} catch {\n\t\treturn undefined;\n\t}\n};\n\n/** The text of a numeric literal type, such as `4` or `-1`. */\nconst numericLiteralTypeText = (node: ts.TypeNode): string | undefined =>\n\tts.isLiteralTypeNode(node) &&\n\t(ts.isNumericLiteral(node.literal) ||\n\t\tts.isPrefixUnaryExpression(node.literal))\n\t\t? node.literal.getText()\n\t\t: undefined;\n\n// The statically named callee of `name(...)` or `namespace.name(...)`.\nexport function calleeName(node: ts.Expression): ts.MemberName | undefined {\n\tif (ts.isIdentifier(node)) {\n\t\treturn node;\n\t}\n\treturn ts.isPropertyAccessExpression(node) ? node.name : undefined;\n}\n\n/** Whether a declaration carries a modifier keyword such as `export` or `async`. */\nexport const hasModifier = (\n\tnode: ts.HasModifiers,\n\tkind: ts.ModifierSyntaxKind,\n): boolean =>\n\tBoolean(node.modifiers?.some((modifier) => modifier.kind === kind));\n\n/** Whether an identifier names a property, as in `a.name` or `{ name: value }`, rather than reading a variable. */\nexport const isPropertyName = (node: ts.Identifier): boolean =>\n\t(ts.isPropertyAccessExpression(node.parent) && node.parent.name === node) ||\n\t(ts.isPropertyAssignment(node.parent) && node.parent.name === node);\n\n/** `name: value` or shorthand `name` in an object literal; undefined for spreads, methods and computed names. */\nexport function namedProperty(\n\tproperty: ts.ObjectLiteralElementLike,\n): { name: string; value: ts.Expression } | undefined {\n\tif (\n\t\t!(\n\t\t\tts.isPropertyAssignment(property) ||\n\t\t\tts.isShorthandPropertyAssignment(property)\n\t\t) ||\n\t\t!ts.isIdentifier(property.name)\n\t) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tname: property.name.text,\n\t\tvalue: ts.isPropertyAssignment(property)\n\t\t\t? property.initializer\n\t\t\t: property.name,\n\t};\n}\n\nexport type TelemetryMethod = (typeof telemetryMethods)[number];\n\n/** The declaration of a type parameter an environment binds. */\nconst typeParameter = (symbol: ts.Symbol): ts.Declaration => {\n\tconst [declaration] = symbol.declarations ?? [];\n\tif (!declaration) {\n\t\tthrow new Error(`Type parameter ${symbol.name} has no declaration.`);\n\t}\n\treturn declaration;\n};\n\n/** A service client's struct for a type naming a called procedure's record. */\nexport type ServiceRecord = (type: ts.Type) => ts.Symbol | undefined;\n\n// The PLC layouts TypeScript annotations name. The checker resolves declarations; it never\n// supplies erased numeric widths. Service records are the exception: `iec.*` schemas carry\n// their widths as literal types.\nexport class TypeResolver {\n\tprivate readonly layouts = new Map<string, PlcType>(\n\t\tprimitiveTypes.map((type) => [type.id, type]),\n\t);\n\treadonly types: ReadonlyMap<string, PlcType> = this.layouts;\n\tprivate readonly blockTypes = new Map<ts.Symbol, string>();\n\tprivate readonly standardTypes = new Map<string, string>();\n\treadonly unions = new Set<string>();\n\tprivate readonly active = new Set<string>();\n\t/** Type literals' records by their fields. */\n\tprivate readonly anonymousRecords = new Map<string, string>();\n\tconstructor(\n\t\tprivate readonly checker: ts.TypeChecker,\n\t\tprivate readonly root: string,\n\t\tprivate readonly sdk: string,\n\t\tprivate readonly fail: Fail,\n\t\tprivate readonly serviceRecord: ServiceRecord | null,\n\t) {}\n\n\t/** Registers a block class's layout before its fields resolve, so a recursive allocation finds it. */\n\tdeclareBlock(symbol: ts.Symbol, block: string): string {\n\t\tconst id = `block:${block}`;\n\t\tthis.layouts.set(id, { id, kind: \"block\", block });\n\t\tthis.blockTypes.set(symbol, id);\n\t\treturn id;\n\t}\n\n\t/** Completes a collected block's layout with its output record. */\n\tblockOutput(id: string, block: string, output: string): void {\n\t\tthis.layouts.set(id, { id, kind: \"block\", block, output });\n\t}\n\n\t/** Registers the SDK's standard block `name`, implemented by `block`, whose outputs form `output`. */\n\tdeclareStandardBlock(\n\t\tname: string,\n\t\tblock: string,\n\t\toutput: { id: string; fields: Field[] },\n\t): void {\n\t\tthis.layouts.set(output.id, {\n\t\t\tid: output.id,\n\t\t\tkind: \"record\",\n\t\t\tfields: output.fields,\n\t\t});\n\t\tconst id = `block:${block}`;\n\t\tthis.layouts.set(id, { id, kind: \"block\", block, output: output.id });\n\t\tthis.standardTypes.set(name, id);\n\t}\n\n\t/** The layout of the SDK's standard block `name`, such as `OnDelayTimer`. */\n\tstandardBlock(name: string): string | undefined {\n\t\treturn this.standardTypes.get(name);\n\t}\n\n\t/** How a routine receives `type`: records, arrays and blocks pass by reference, as objects do in TypeScript. */\n\tparameterMode({ type, mode }: Pick<Field, \"type\" | \"mode\">) {\n\t\tconst layout = this.layouts.get(type);\n\t\treturn (\n\t\t\tmode ??\n\t\t\t(layout?.kind === \"block\" || aggregate(layout) ? \"inOut\" : undefined)\n\t\t);\n\t}\n\n\t/** The symbol `node` reads, followed through import and export aliases. */\n\tsymbol(node: ts.Node): ts.Symbol {\n\t\tconst symbol = valueSymbol(this.checker, node);\n\t\tif (!symbol) {\n\t\t\tthis.fail(node, \"PLC1002\", \"This name has no PLC declaration.\");\n\t\t}\n\t\treturn unaliased(this.checker, symbol);\n\t}\n\n\t/** Declared by TypeScript's default library, such as `Record` or `Object`. */\n\tstandardLibrary(symbol: ts.Symbol): boolean {\n\t\treturn Boolean(\n\t\t\tsymbol.declarations?.every(\n\t\t\t\t(declaration) =>\n\t\t\t\t\tdirname(declaration.getSourceFile().fileName) ===\n\t\t\t\t\tdirname(ts.getDefaultLibFilePath({})),\n\t\t\t),\n\t\t);\n\t}\n\n\tsdkName(node: ts.Node): string | undefined {\n\t\tconst symbol = this.symbol(node);\n\t\treturn declaredBySdk(this.sdk, symbol) ? symbol.getName() : undefined;\n\t}\n\n\t/** The `@tsplc/compiler/telemetry` method a call names, such as `capture`. */\n\ttelemetryMethod(node: ts.CallExpression): TelemetryMethod | undefined {\n\t\tif (!ts.isPropertyAccessExpression(node.expression)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst symbol = this.checker.getSymbolAtLocation(node.expression.name);\n\t\tconst declared = symbol?.declarations?.some((declaration) =>\n\t\t\tisTelemetryDeclaration(this.sdk, declaration),\n\t\t);\n\t\treturn declared\n\t\t\t? telemetryMethods.find((name) => name === symbol?.name)\n\t\t\t: undefined;\n\t}\n\n\tid(node: ts.Node, name: string): string {\n\t\treturn `${modulePath(this.root, node.getSourceFile().fileName)}:${node.getStart()}:${name}`;\n\t}\n\n\t/**\n\t * An inline type's id, named after the field, parameter or variable it is written for, else\n\t * `fallback`. Type arguments it was resolved with go before the name, which stays the last segment.\n\t */\n\tprivate inlineId(\n\t\tnode: ts.Node,\n\t\tfallback: string,\n\t\targuments_: string,\n\t): string {\n\t\tconst owner = declaringName(node.parent);\n\t\tconst name = owner === undefined ? fallback : pascalCase(owner);\n\t\treturn this.id(node, `${arguments_ ? `<${arguments_}>:` : \"\"}${name}`);\n\t}\n\n\t/**\n\t * A type literal's record. Type literals with the same fields are one type, as TypeScript's\n\t * structural types are, so a value passes between them unconverted; the first one resolved\n\t * names it.\n\t */\n\tprivate typeLiteral(\n\t\tnode: ts.TypeLiteralNode,\n\t\tenvironment: TypeEnvironment,\n\t): ResolvedType {\n\t\tconst fields = this.fields(node.members, environment);\n\t\tconst shape = JSON.stringify(fields);\n\t\tconst known = this.anonymousRecords.get(shape);\n\t\tif (known !== undefined) {\n\t\t\treturn { type: known };\n\t\t}\n\t\t// Environment keys are admitted, declared type parameters with concrete bindings.\n\t\tconst arguments_ = [...environment]\n\t\t\t.map(\n\t\t\t\t([symbol, value]) =>\n\t\t\t\t\t`${this.id(typeParameter(symbol), symbol.name)}=${this.key(value)}`,\n\t\t\t)\n\t\t\t.sort()\n\t\t\t.join(\",\");\n\t\tconst resolved = this.record(\n\t\t\tnode,\n\t\t\tthis.inlineId(node, \"Fields\", arguments_),\n\t\t\tfields,\n\t\t);\n\t\tthis.anonymousRecords.set(shape, resolved.type);\n\t\treturn resolved;\n\t}\n\n\targument(node: ts.TypeNode, environment: TypeEnvironment): TypeArgument {\n\t\tif (ts.isTypeReferenceNode(node)) {\n\t\t\tconst bound = environment.get(this.symbol(node.typeName));\n\t\t\tif (bound && !node.typeArguments?.length) {\n\t\t\t\treturn bound;\n\t\t\t}\n\t\t}\n\t\t// `(typeof table)[\"length\"]` or `typeof table.length` has the literal type of an `as const` table.\n\t\tconst queried =\n\t\t\tts.isIndexedAccessTypeNode(node) || ts.isTypeQueryNode(node)\n\t\t\t\t? this.checker.getTypeFromTypeNode(node)\n\t\t\t\t: undefined;\n\t\tconst text = queried?.isNumberLiteral()\n\t\t\t? String(queried.value)\n\t\t\t: numericLiteralTypeText(node);\n\t\tif (text !== undefined) {\n\t\t\tconst value =\n\t\t\t\texactInteger(text) ??\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Layout arguments must be exact integer literals.\",\n\t\t\t\t);\n\t\t\tif (value < lowestDint || value > highestDint) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Layout argument is outside signed DINT range.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn { kind: \"integer\", value: Number(value) };\n\t\t}\n\t\treturn { kind: \"type\", value: this.resolve(node, environment) };\n\t}\n\n\t/**\n\t * The environment a generic declaration's body resolves in, and the suffix that tells its\n\t * specialization apart: each type parameter's argument in order, empty when it has none.\n\t */\n\tbindings(\n\t\tparameters: readonly ts.TypeParameterDeclaration[] | undefined,\n\t\targuments_: readonly ts.TypeNode[] | undefined,\n\t\touter: TypeEnvironment,\n\t\tnode: ts.Node,\n\t): { environment: TypeEnvironment; suffix: string } {\n\t\tconst environment = new Map(outer);\n\t\tconst params = parameters ?? [];\n\t\tconst args = arguments_ ?? [];\n\t\tif (args.length > params.length) {\n\t\t\tthis.fail(node, \"PLC2001\", \"Too many concrete type arguments.\");\n\t\t}\n\t\tconst keys = params.map((parameter, index) => {\n\t\t\tconst argument = args[index] ?? parameter.default;\n\t\t\tif (!argument) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Generic PLC declarations require explicit concrete type arguments.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst value = this.argument(argument, environment);\n\t\t\tenvironment.set(this.symbol(parameter.name), value);\n\t\t\treturn this.key(value);\n\t\t});\n\t\treturn { environment, suffix: keys.join(\",\") };\n\t}\n\n\tresolve(\n\t\tnode: ts.TypeNode,\n\t\tenvironment: TypeEnvironment = new Map(),\n\t): ResolvedType {\n\t\tif (node.kind === ts.SyntaxKind.BooleanKeyword) {\n\t\t\treturn { type: \"BOOL\" };\n\t\t}\n\t\tif (node.kind === ts.SyntaxKind.NumberKeyword) {\n\t\t\treturn { type: defaultNumericTypes.number };\n\t\t}\n\t\tif (node.kind === ts.SyntaxKind.StringKeyword) {\n\t\t\tconst id = `STRING<${defaultStringLength}>`;\n\t\t\tthis.layouts.set(id, {\n\t\t\t\tid,\n\t\t\t\tkind: \"string\",\n\t\t\t\tcapacity: defaultStringLength,\n\t\t\t\tencoding: \"utf8\",\n\t\t\t});\n\t\t\treturn { type: id };\n\t\t}\n\t\tif (ts.isParenthesizedTypeNode(node)) {\n\t\t\treturn this.resolve(node.type, environment);\n\t\t}\n\t\tif (ts.isTypeLiteralNode(node)) {\n\t\t\treturn this.typeLiteral(node, environment);\n\t\t}\n\t\tif (ts.isUnionTypeNode(node)) {\n\t\t\treturn this.union(node, this.inlineId(node, \"Union\", \"\"), environment);\n\t\t}\n\t\tif (ts.isIndexedAccessTypeNode(node)) {\n\t\t\tconst record = this.serviceRecord?.(\n\t\t\t\tthis.checker.getTypeFromTypeNode(node),\n\t\t\t);\n\t\t\tif (record) {\n\t\t\t\treturn this.declaration(record, undefined, environment, node);\n\t\t\t}\n\t\t}\n\t\tif (!ts.isTypeReferenceNode(node)) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Use an explicit supported PLC type; optional and dynamic layouts are unsupported.\",\n\t\t\t);\n\t\t}\n\t\tconst symbol = this.symbol(node.typeName);\n\t\tconst bound = environment.get(symbol);\n\t\tif (bound) {\n\t\t\tif (bound.kind !== \"type\" || node.typeArguments?.length) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"An integer layout argument is not a storage type.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn bound.value;\n\t\t}\n\t\tconst official = this.sdkName(node.typeName);\n\t\tconst block =\n\t\t\tthis.blockTypes.get(symbol) ??\n\t\t\t(official ? this.standardTypes.get(official) : undefined);\n\t\tif (block) {\n\t\t\tif (node.typeArguments?.length) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Function block classes are concrete and take no type arguments.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn { type: block };\n\t\t}\n\t\tif (official === \"InOut\") {\n\t\t\tconst inner = this.resolve(\n\t\t\t\tthis.soleTypeArgument(node, \"InOut requires one concrete value type.\"),\n\t\t\t\tenvironment,\n\t\t\t);\n\t\t\tif (inner.io || !this.isValue(inner)) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"InOut cannot nest or borrow a block instance.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn { type: inner.type, mode: \"inOut\" };\n\t\t}\n\t\tif (official && this.layouts.has(official)) {\n\t\t\tif (node.typeArguments?.length) {\n\t\t\t\tthis.fail(node, \"PLC2001\", \"Scalar types take no type arguments.\");\n\t\t\t}\n\t\t\treturn { type: official };\n\t\t}\n\t\tif (official === \"Input\" || official === \"Output\") {\n\t\t\tconst inner = this.resolve(\n\t\t\t\tthis.soleTypeArgument(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"I/O types need exactly one PLC type argument.\",\n\t\t\t\t),\n\t\t\t\tenvironment,\n\t\t\t);\n\t\t\tif (inner.io || inner.mode || this.hasReferences(inner.type)) {\n\t\t\t\tthis.fail(node, \"PLC2001\", \"I/O type wrappers cannot be nested.\");\n\t\t\t}\n\t\t\treturn {\n\t\t\t\ttype: inner.type,\n\t\t\t\tio: official === \"Input\" ? \"input\" : \"output\",\n\t\t\t};\n\t\t}\n\t\tif (official === \"FixedArray\") {\n\t\t\tconst [element, length, lower, ...rest] = node.typeArguments ?? [];\n\t\t\tif (!element || !length || rest.length) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"FixedArray needs element, length and optional lower bound.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn this.fixedArray(\n\t\t\t\tnode,\n\t\t\t\tthis.resolve(element, environment),\n\t\t\t\tthis.argument(length, environment),\n\t\t\t\tlower\n\t\t\t\t\t? this.argument(lower, environment)\n\t\t\t\t\t: { kind: \"integer\", value: 0 },\n\t\t\t);\n\t\t}\n\t\t// TypeScript's own `Record`; its keys are a contiguous enum.\n\t\tif (symbol.name === \"Record\" && this.standardLibrary(symbol)) {\n\t\t\tconst [key, value] = node.typeArguments ?? [];\n\t\t\tconst index =\n\t\t\t\tkey && ts.isTypeReferenceNode(key)\n\t\t\t\t\t? this.layouts.get(this.resolve(key, environment).type)\n\t\t\t\t\t: undefined;\n\t\t\tif (index?.kind !== \"enum\" || !value) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Record keys must be a numeric PLC enum; dynamic index signatures are unsupported.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst values = index.members.map((member) => Number(member.value));\n\t\t\tconst lower = Math.min(...values);\n\t\t\tif (Math.max(...values) - lower + 1 !== values.length) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Record<Enum, T> needs enum member values without gaps.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst element = this.resolve(value, environment);\n\t\t\tif (element.io || !this.isValue(element)) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Enum-keyed records need a plain value element.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst id = `array<${element.type},${values.length},${lower},${index.id}>`;\n\t\t\tthis.layouts.set(id, {\n\t\t\t\tid,\n\t\t\t\tkind: \"array\",\n\t\t\t\telement: element.type,\n\t\t\t\tlength: values.length,\n\t\t\t\tlowerBound: lower,\n\t\t\t\tindex: index.id,\n\t\t\t});\n\t\t\tthis.checkSize(id, node);\n\t\t\treturn { type: id };\n\t\t}\n\t\tif (official === \"STRING\" || official === \"WSTRING\") {\n\t\t\tconst capacity = this.argument(\n\t\t\t\tthis.soleTypeArgument(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"Bounded strings require one capacity argument.\",\n\t\t\t\t),\n\t\t\t\tenvironment,\n\t\t\t);\n\t\t\tif (\n\t\t\t\tcapacity.kind !== \"integer\" ||\n\t\t\t\tcapacity.value < 1 ||\n\t\t\t\tcapacity.value > maxStringCapacity\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t`String capacity must be 1..${maxStringCapacity}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst id = `${official}<${capacity.value}>`;\n\t\t\tthis.layouts.set(id, {\n\t\t\t\tid,\n\t\t\t\tkind: \"string\",\n\t\t\t\tcapacity: capacity.value,\n\t\t\t\tencoding: official === \"STRING\" ? \"utf8\" : \"utf16\",\n\t\t\t});\n\t\t\treturn { type: id };\n\t\t}\n\t\treturn this.declaration(symbol, node.typeArguments, environment, node);\n\t}\n\n\tprivate soleTypeArgument(\n\t\tnode: ts.TypeReferenceNode,\n\t\tmessage: string,\n\t): ts.TypeNode {\n\t\tconst [argument, ...rest] = node.typeArguments ?? [];\n\t\tif (!argument || rest.length) {\n\t\t\tthis.fail(node, \"PLC2001\", message);\n\t\t}\n\t\treturn argument;\n\t}\n\n\tfixedArray(\n\t\tnode: ts.Node,\n\t\telement: ResolvedType,\n\t\tlength: TypeArgument,\n\t\tlower: TypeArgument,\n\t): ResolvedType {\n\t\tif (\n\t\t\telement.io ||\n\t\t\t!(\n\t\t\t\tthis.isValue(element) ||\n\t\t\t\tthis.layouts.get(element.type)?.kind === \"block\"\n\t\t\t) ||\n\t\t\tlength.kind !== \"integer\" ||\n\t\t\tlower.kind !== \"integer\" ||\n\t\t\tlength.value < 1 ||\n\t\t\tlength.value > maxScalarElements ||\n\t\t\tBigInt(lower.value + length.value - 1) > highestDint\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Fixed arrays need a supported element, positive bounded length and signed DINT bounds.\",\n\t\t\t);\n\t\t}\n\t\tconst id = `array<${element.type},${length.value},${lower.value}>`;\n\t\tthis.layouts.set(id, {\n\t\t\tid,\n\t\t\tkind: \"array\",\n\t\t\telement: element.type,\n\t\t\tlength: length.value,\n\t\t\tlowerBound: lower.value,\n\t\t});\n\t\tthis.checkSize(id, node);\n\t\treturn { type: id };\n\t}\n\n\tprivate declaration(\n\t\tsymbol: ts.Symbol,\n\t\targuments_: readonly ts.TypeNode[] | undefined,\n\t\tenvironment: TypeEnvironment,\n\t\tnode: ts.Node,\n\t): ResolvedType {\n\t\tconst declarations = symbol.declarations ?? [];\n\t\tif (declarations.filter(ts.isInterfaceDeclaration).length > 1) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Interface declaration merging is unsupported; use one closed layout declaration.\",\n\t\t\t);\n\t\t}\n\t\tconst declaration = declarations.find(\n\t\t\t(item) =>\n\t\t\t\tts.isTypeAliasDeclaration(item) ||\n\t\t\t\tts.isInterfaceDeclaration(item) ||\n\t\t\t\tts.isEnumDeclaration(item),\n\t\t);\n\t\tif (!declaration) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"This type is not implemented by the PLC frontend.\",\n\t\t\t);\n\t\t}\n\t\tif (ts.isEnumDeclaration(declaration)) {\n\t\t\tif (arguments_?.length) {\n\t\t\t\tthis.fail(node, \"PLC2001\", \"Enums take no type arguments.\");\n\t\t\t}\n\t\t\treturn this.enumeration(declaration);\n\t\t}\n\t\tconst { environment: bindings, suffix } = this.bindings(\n\t\t\tdeclaration.typeParameters,\n\t\t\targuments_,\n\t\t\tenvironment,\n\t\t\tnode,\n\t\t);\n\t\tconst id = `${this.id(declaration, declaration.name.text)}${suffix ? `<${suffix}>` : \"\"}`;\n\t\tif (this.active.has(id)) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Recursive by-value PLC layouts are unsupported.\",\n\t\t\t);\n\t\t}\n\t\tif (this.layouts.has(id)) {\n\t\t\treturn { type: id };\n\t\t}\n\t\tif (this.active.size >= maxSubstitutionDepth) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t`Type substitution exceeds ${maxSubstitutionDepth} levels; recursive expansion is unsupported.`,\n\t\t\t);\n\t\t}\n\t\tthis.active.add(id);\n\t\ttry {\n\t\t\tif (ts.isTypeAliasDeclaration(declaration)) {\n\t\t\t\tif (ts.isTypeLiteralNode(declaration.type)) {\n\t\t\t\t\treturn this.record(\n\t\t\t\t\t\tdeclaration,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tthis.fields(declaration.type.members, bindings),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (ts.isUnionTypeNode(declaration.type)) {\n\t\t\t\t\treturn this.union(declaration.type, id, bindings);\n\t\t\t\t}\n\t\t\t\treturn this.resolve(declaration.type, bindings);\n\t\t\t}\n\t\t\tconst inherited: Field[] = [];\n\t\t\tfor (const heritage of declaration.heritageClauses ?? []) {\n\t\t\t\tfor (const base of heritage.types) {\n\t\t\t\t\tconst baseSymbol = this.symbol(base.expression);\n\t\t\t\t\tconst baseType = this.declaration(\n\t\t\t\t\t\tbaseSymbol,\n\t\t\t\t\t\tbase.typeArguments,\n\t\t\t\t\t\tbindings,\n\t\t\t\t\t\tbase,\n\t\t\t\t\t);\n\t\t\t\t\tconst layout = this.layouts.get(baseType.type);\n\t\t\t\t\tif (layout?.kind !== \"record\") {\n\t\t\t\t\t\tthis.fail(base, \"PLC2001\", \"Inherited layout must be a record.\");\n\t\t\t\t\t}\n\t\t\t\t\tinherited.push(...layout.fields);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn this.record(\n\t\t\t\tdeclaration,\n\t\t\t\tid,\n\t\t\t\tthis.fields(declaration.members, bindings, inherited),\n\t\t\t);\n\t\t} finally {\n\t\t\tthis.active.delete(id);\n\t\t}\n\t}\n\t// Specialization identity includes I/O and InOut modes: equal value widths alone\n\t// must not merge a readonly value parameter with a mutable borrowed input.\n\tkey(argument: TypeArgument): string {\n\t\tif (argument.kind === \"integer\") {\n\t\t\treturn String(argument.value);\n\t\t}\n\t\tconst { type, io, mode } = argument.value;\n\t\treturn `${type}${io ? `:${io}` : \"\"}${mode ? `:${mode}` : \"\"}`;\n\t}\n\n\t/**\n\t * A discriminated union is one fixed layout: a `kind` enum plus the fields of every variant.\n\t * TypeScript's narrowing guards which fields a branch can read; a literal's unset fields are zero.\n\t */\n\tprivate union(\n\t\tnode: ts.UnionTypeNode,\n\t\tid: string,\n\t\tenvironment: TypeEnvironment,\n\t): ResolvedType {\n\t\tconst fields = new Map<string, Field>();\n\t\tconst kinds: string[] = [];\n\t\tfor (const variant of node.types) {\n\t\t\tconst members = ts.isTypeLiteralNode(variant)\n\t\t\t\t? variant.members\n\t\t\t\t: undefined;\n\t\t\tconst tag = members?.find(\n\t\t\t\t(member) =>\n\t\t\t\t\tts.isPropertySignature(member) && member.name.getText() === \"kind\",\n\t\t\t);\n\t\t\tconst literal =\n\t\t\t\ttag &&\n\t\t\t\tts.isPropertySignature(tag) &&\n\t\t\t\ttag.type &&\n\t\t\t\tts.isLiteralTypeNode(tag.type)\n\t\t\t\t\t? tag.type.literal\n\t\t\t\t\t: undefined;\n\t\t\tif (\n\t\t\t\t!members ||\n\t\t\t\t!literal ||\n\t\t\t\t!ts.isStringLiteral(literal) ||\n\t\t\t\t!generatedNamePattern.test(literal.text)\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tvariant,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t'Union variants are object types with an identifier string literal `kind`, such as { kind: \"idle\" }.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (kinds.includes(literal.text)) {\n\t\t\t\tthis.fail(variant, \"PLC2001\", \"Duplicate union kind.\");\n\t\t\t}\n\t\t\tkinds.push(literal.text);\n\t\t\tfor (const field of this.fields(\n\t\t\t\tmembers.filter((member) => member !== tag),\n\t\t\t\tenvironment,\n\t\t\t)) {\n\t\t\t\tconst existing = fields.get(field.name);\n\t\t\t\tif (existing && existing.type !== field.type) {\n\t\t\t\t\tthis.fail(\n\t\t\t\t\t\tvariant,\n\t\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\t\"Union variants may share a field only with the same type.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tfields.set(field.name, field);\n\t\t\t}\n\t\t}\n\t\tconst kindId = `${id}Kind`;\n\t\tthis.layouts.set(kindId, {\n\t\t\tid: kindId,\n\t\t\tkind: \"enum\",\n\t\t\tbase: \"DINT\",\n\t\t\tmembers: kinds.map((name, value) => ({ name, value: String(value) })),\n\t\t});\n\t\tthis.layouts.set(id, {\n\t\t\tid,\n\t\t\tkind: \"record\",\n\t\t\tfields: [\n\t\t\t\t{ name: \"kind\", type: kindId, readonly: false },\n\t\t\t\t...fields.values(),\n\t\t\t],\n\t\t});\n\t\tthis.unions.add(id);\n\t\tthis.checkSize(id, node);\n\t\treturn { type: id };\n\t}\n\n\tprivate record(node: ts.Node, id: string, fields: Field[]): ResolvedType {\n\t\tif (!fields.length) {\n\t\t\tthis.fail(node, \"PLC2001\", \"PLC records require at least one field.\");\n\t\t}\n\t\tthis.layouts.set(id, { id, kind: \"record\", fields });\n\t\tthis.checkSize(id, node);\n\t\treturn { type: id };\n\t}\n\n\tprivate fields(\n\t\tmembers: readonly ts.TypeElement[],\n\t\tenvironment: TypeEnvironment,\n\t\tinherited: readonly Field[] = [],\n\t): Field[] {\n\t\tconst fields = [...inherited];\n\t\tconst names = new Set(fields.map((field) => field.name));\n\t\tfor (const member of members) {\n\t\t\tif (\n\t\t\t\t!ts.isPropertySignature(member) ||\n\t\t\t\t!member.type ||\n\t\t\t\tmember.questionToken ||\n\t\t\t\t!member.name ||\n\t\t\t\t!ts.isIdentifier(member.name)\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tmember,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"PLC records have named, required, explicitly typed fields; methods and index signatures are unsupported.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (names.has(member.name.text)) {\n\t\t\t\tthis.fail(member, \"PLC2001\", \"Duplicate record field.\");\n\t\t\t}\n\t\t\tconst type = this.resolve(member.type, environment);\n\t\t\tif (instancedBlock(type.type, this.types)) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tmember,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Block instances belong in module or private block fields, not value records.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (type.io) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tmember,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Logical I/O wrappers belong on ambient bindings, not fields.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tfields.push({\n\t\t\t\tname: member.name.text,\n\t\t\t\ttype: type.type,\n\t\t\t\t...(type.mode && { mode: type.mode }),\n\t\t\t\treadonly: hasModifier(member, ts.SyntaxKind.ReadonlyKeyword),\n\t\t\t});\n\t\t\tnames.add(member.name.text);\n\t\t}\n\t\treturn fields;\n\t}\n\n\tinputFields(node: ts.TypeNode): readonly Field[] {\n\t\tif (ts.isTypeLiteralNode(node) && !node.members.length) {\n\t\t\treturn [];\n\t\t}\n\t\tconst resolved = this.resolve(node);\n\t\tconst type = this.layouts.get(resolved.type);\n\t\tif (resolved.io || resolved.mode || type?.kind !== \"record\") {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Block inputs require one closed record schema.\",\n\t\t\t);\n\t\t}\n\t\tif (type.fields.some((field) => this.hasReferences(field.type))) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"InOut belongs directly on input fields, not nested records.\",\n\t\t\t);\n\t\t}\n\t\treturn type.fields;\n\t}\n\n\t// A plain value layout: no InOut borrow, nested borrow schema or block instance.\n\tisValue(resolved: ResolvedType): boolean {\n\t\treturn (\n\t\t\t!resolved.mode &&\n\t\t\t!this.hasReferences(resolved.type) &&\n\t\t\t!instancedBlock(resolved.type, this.types)\n\t\t);\n\t}\n\n\thasReferences(id: string, seen = new Set<string>()): boolean {\n\t\tif (seen.has(id)) {\n\t\t\treturn false;\n\t\t}\n\t\tseen.add(id);\n\t\tconst type = this.layouts.get(id);\n\t\tif (type?.kind === \"record\") {\n\t\t\treturn type.fields.some(\n\t\t\t\t(field) => field.mode || this.hasReferences(field.type, seen),\n\t\t\t);\n\t\t}\n\t\treturn type?.kind === \"array\" && this.hasReferences(type.element, seen);\n\t}\n\n\tenumeration(node: ts.EnumDeclaration): ResolvedType {\n\t\tconst id = this.id(node, node.name.text);\n\t\tif (this.layouts.has(id)) {\n\t\t\treturn { type: id };\n\t\t}\n\t\tif (!node.members.length) {\n\t\t\tthis.fail(node, \"PLC2001\", \"PLC enums cannot be empty.\");\n\t\t}\n\t\tconst members = node.members.map((member) => {\n\t\t\tif (!ts.isIdentifier(member.name)) {\n\t\t\t\tthis.fail(member, \"PLC2001\", \"Enum members require identifier names.\");\n\t\t\t}\n\t\t\tconst value = this.checker.getConstantValue(member);\n\t\t\tif (\n\t\t\t\ttypeof value !== \"number\" ||\n\t\t\t\t!Number.isInteger(value) ||\n\t\t\t\tBigInt(value) < lowestDint ||\n\t\t\t\tBigInt(value) > highestDint\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tmember,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"PLC enum values must be compile-time DINT integers.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn { name: member.name.text, value: String(value) };\n\t\t});\n\t\tif (\n\t\t\tnew Set(members.map((member) => member.value)).size !== members.length\n\t\t) {\n\t\t\tthis.fail(node, \"PLC2001\", \"PLC enum members require distinct values.\");\n\t\t}\n\t\tthis.layouts.set(id, { id, kind: \"enum\", base: \"DINT\", members });\n\t\treturn { type: id };\n\t}\n\n\tprivate checkSize(id: string, node: ts.Node): void {\n\t\tconst budget = layoutIssue(this.layouts, id);\n\t\tif (budget === \"nesting\") {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t`PLC layout nesting exceeds ${maxNestingDepth} levels.`,\n\t\t\t);\n\t\t}\n\t\tif (budget === \"size\") {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t`PLC layout exceeds ${maxScalarElementsText} scalar elements.`,\n\t\t\t);\n\t\t}\n\t}\n}\n",
9
+ "import { relative, resolve } from \"node:path\";\n\n/** A file's path from the project root, with forward slashes, as generated names, digests and declaration ids spell it. */\nexport const modulePath = (projectRoot: string, file: string): string =>\n\trelative(projectRoot, file).replace(/\\\\/g, \"/\");\n\n/** The key a lowering pass records what it learned about a module's declaration under. */\nexport const loweringKey = (file: string, name: string): string =>\n\t`${file}:${name}`;\n\n/** The lowering key of a verified declaration, whose id begins `<modulePath>:<start>:<name>`. */\nexport const declarationKey = (\n\troot: string,\n\tdeclaration: { id: string; name: string },\n): string =>\n\tloweringKey(\n\t\tresolve(root, declaration.id.slice(0, declaration.id.indexOf(\":\"))),\n\t\tdeclaration.name,\n\t);\n\n/** The lowering key of a verified type, which carries its name only in its id. */\nexport const typeKey = (root: string, id: string): string =>\n\tdeclarationKey(root, { id, name: id.slice(id.lastIndexOf(\":\") + 1) });\n",
10
+ "import { realpathSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { basename, dirname, join } from \"node:path\";\nimport ts from \"typescript\";\n\n/** The specifiers a program imports the SDK's modules by. */\nexport const sdkModules = {\n\tasync: \"@tsplc/compiler/async\",\n\tclock: \"@tsplc/compiler/clock\",\n\tconfig: \"@tsplc/compiler/config\",\n\tglobals: \"@tsplc/compiler/globals\",\n\tretain: \"@tsplc/compiler/retain\",\n\ttelemetry: \"@tsplc/compiler/telemetry\",\n\ttypes: \"@tsplc/compiler/types\",\n} as const;\n\n/** The methods of `@tsplc/compiler/telemetry`'s `telemetry`. */\nexport const telemetryMethods = [\n\t\"capture\",\n\t\"info\",\n\t\"warn\",\n\t\"error\",\n\t\"captureException\",\n\t\"text\",\n] as const;\n\n/** The `@tsplc/compiler/globals` declaration file a project compiles against. */\nexport const sdkFor = (\n\tproject: string,\n\toptions: ts.CompilerOptions,\n): string => {\n\tconst resolveSdk = (from: string) =>\n\t\tcreateRequire(from).resolve(sdkModules.globals).replaceAll(\"\\\\\", \"/\");\n\ttry {\n\t\tconst installed = resolveSdk(project);\n\t\t// Bun answers a project without node_modules from its global cache, which holds whatever\n\t\t// version it last fetched: that is no install of the project's.\n\t\tif (!installed.includes(\"/node_modules/\")) {\n\t\t\treturn resolveSdk(import.meta.url);\n\t\t}\n\t\tconst resolved = ts.resolveModuleName(\n\t\t\tsdkModules.globals,\n\t\t\tproject,\n\t\t\toptions,\n\t\t\tts.sys,\n\t\t).resolvedModule;\n\t\t// TypeScript may preserve a workspace symlink. A path alias may only stand in\n\t\t// for the SDK if it resolves to the same installed declaration.\n\t\tif (\n\t\t\tresolved &&\n\t\t\trealpathSync(resolved.resolvedFileName) === realpathSync(installed)\n\t\t) {\n\t\t\treturn resolved.resolvedFileName;\n\t\t}\n\t\treturn installed;\n\t} catch (cause) {\n\t\tif (\n\t\t\t!(cause instanceof Error) ||\n\t\t\t!(\"code\" in cause) ||\n\t\t\tcause.code !== \"MODULE_NOT_FOUND\"\n\t\t) {\n\t\t\tthrow cause;\n\t\t}\n\t\t// A project that does not install @tsplc/compiler, as the compiler's own test projects\n\t\t// do not, compiles against this compiler's SDK.\n\t\treturn resolveSdk(import.meta.url);\n\t}\n};\n\n/** The dialect's globals beside `sdk`, which only the compiler's own generated code may use. */\nexport const dialectFor = (sdk: string): string =>\n\tjoin(dirname(sdk), \"dialect.d.ts\").replaceAll(\"\\\\\", \"/\");\n\n/** Whether `fileName` is one of the SDK declaration files, which sit beside `sdk`. */\nexport const inSdk = (sdk: string, fileName: string): boolean =>\n\tfileName.startsWith(`${dirname(sdk)}/`);\n\n/** The path a program imports an SDK declaration file by: `index.d.ts` is `@tsplc/compiler/types`, any other its own name. */\nexport const sdkModule = (fileName: string): string => {\n\tconst name = basename(fileName, \".d.ts\");\n\treturn `@tsplc/compiler/${name === \"index\" ? \"types\" : name}`;\n};\n\n/** Whether `declaration` is in the SDK module a program imports by `module`. */\nexport const declaredInSdkModule = (\n\tsdk: string,\n\tmodule: (typeof sdkModules)[keyof typeof sdkModules],\n\tdeclaration: ts.Declaration,\n): boolean => {\n\tconst file = declaration.getSourceFile().fileName;\n\treturn inSdk(sdk, file) && sdkModule(file) === module;\n};\n\n/** Whether `declaration` is in the SDK's `@tsplc/compiler/telemetry`. */\nexport const isTelemetryDeclaration = (\n\tsdk: string,\n\tdeclaration: ts.Declaration,\n): boolean => declaredInSdkModule(sdk, sdkModules.telemetry, declaration);\n\n/** A symbol followed through import and export aliases to what it names. */\nexport const unaliased = (\n\tchecker: ts.TypeChecker,\n\tsymbol: ts.Symbol,\n): ts.Symbol =>\n\tsymbol.flags & ts.SymbolFlags.Alias\n\t\t? unaliased(checker, checker.getAliasedSymbol(symbol))\n\t\t: symbol;\n\n/** The symbol `node` names, followed through import and export aliases. */\nexport const symbolAt = (\n\tchecker: ts.TypeChecker,\n\tnode: ts.Node,\n): ts.Symbol | undefined => {\n\tconst symbol = checker.getSymbolAtLocation(node);\n\treturn symbol && unaliased(checker, symbol);\n};\n\n/** The symbol `node` reads; a shorthand property's own name reads the variable it is named for, not the property it declares. */\nexport const valueSymbol = (\n\tchecker: ts.TypeChecker,\n\tnode: ts.Node,\n): ts.Symbol | undefined =>\n\tts.isShorthandPropertyAssignment(node.parent) && node.parent.name === node\n\t\t? checker.getShorthandAssignmentValueSymbol(node.parent)\n\t\t: checker.getSymbolAtLocation(node);\n\n/** Whether the SDK declares `symbol`. */\nexport const declaredBySdk = (sdk: string, symbol: ts.Symbol): boolean =>\n\tBoolean(\n\t\tsymbol.declarations?.some((declaration) =>\n\t\t\tinSdk(sdk, declaration.getSourceFile().fileName),\n\t\t),\n\t);\n\n/** Whether `node` names the SDK's `name`, such as `sleep` or `env`. */\nexport const namesSdk = (\n\tchecker: ts.TypeChecker,\n\tsdk: string,\n\tnode: ts.Node,\n\tname: string,\n): boolean => {\n\tconst symbol = symbolAt(checker, node);\n\treturn symbol?.name === name && declaredBySdk(sdk, symbol);\n};\n\n/** Whether a type holds an InOut borrow, directly or through the layouts it names. */\nexport const holdsBorrow = (\n\tcontext: {\n\t\tnamesSdk: (node: ts.Node, name: string) => boolean;\n\t\tsymbol: (node: ts.Node) => ts.Symbol | undefined;\n\t},\n\ttype: ts.Node,\n): boolean => {\n\tconst seen = new Set<ts.Symbol>();\n\tconst visit = (node: ts.Node): boolean => {\n\t\tif (ts.isTypeReferenceNode(node)) {\n\t\t\tif (context.namesSdk(node.typeName, \"InOut\")) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tconst symbol = context.symbol(node.typeName);\n\t\t\tif (symbol && !seen.has(symbol)) {\n\t\t\t\tseen.add(symbol);\n\t\t\t\tfor (const declaration of symbol.declarations ?? []) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tts.isInterfaceDeclaration(declaration) &&\n\t\t\t\t\t\tdeclaration.members.some(\n\t\t\t\t\t\t\t(member) =>\n\t\t\t\t\t\t\t\tts.isPropertySignature(member) &&\n\t\t\t\t\t\t\t\tmember.type &&\n\t\t\t\t\t\t\t\tvisit(member.type),\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tts.isTypeAliasDeclaration(declaration) &&\n\t\t\t\t\t\tvisit(declaration.type)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ts.forEachChild(node, (child) => visit(child) || undefined) ?? false;\n\t};\n\treturn visit(type);\n};\n",
11
+ "import {\n\taggregate,\n\ttype Constant,\n\tcanAssign,\n\tcomparisonOperators,\n\tdefaultValue,\n\ttype Expression,\n\terror,\n\texpressionIssue,\n\tfold,\n\ttype IntegerInterval,\n\tinstancedBlock,\n\tinterval,\n\tnarrowRanges,\n\ttype Place,\n\ttype PlcFunction,\n\ttype PlcType,\n\tparseFloatLiteral,\n\tparseInteger,\n\tplaceType,\n\ttype SourceSpan,\n\ttype Statement,\n\ttype Variable,\n} from \"@tsplc/compiler/ir\";\nimport type { BinaryOperator } from \"@tsplc/iec/arithmetic\";\nimport ts from \"typescript\";\nimport type { BlockResolver, BlockSource } from \"./blocks\";\nimport { intrinsicExpression } from \"./intrinsics\";\nimport type { Positions } from \"./positions\";\nimport type { RoutineTable } from \"./routines\";\nimport {\n\tcalleeName,\n\ttype Fail,\n\tnamedProperty,\n\tnumericLiteral,\n\tnumericLiteralType,\n\ttype ResolvedType,\n\tSemanticError,\n\ttype TypeEnvironment,\n\ttype TypeResolver,\n\tunparenthesized,\n} from \"./types\";\n\ntype UnaryOperator = Extract<Expression, { kind: \"unary\" }>[\"operator\"];\ntype ArrayLayout = Extract<PlcType, { kind: \"array\" }>;\ntype RecordLayout = Extract<PlcType, { kind: \"record\" }>;\n\nconst unaryOperators = new Map<ts.SyntaxKind, UnaryOperator>([\n\t[ts.SyntaxKind.ExclamationToken, \"not\"],\n\t[ts.SyntaxKind.MinusToken, \"negate\"],\n\t[ts.SyntaxKind.TildeToken, \"bitNot\"],\n]);\nconst operators = new Map<ts.SyntaxKind, BinaryOperator>([\n\t[ts.SyntaxKind.AmpersandAmpersandToken, \"and\"],\n\t[ts.SyntaxKind.BarBarToken, \"or\"],\n\t[ts.SyntaxKind.EqualsEqualsEqualsToken, \"equal\"],\n\t[ts.SyntaxKind.ExclamationEqualsEqualsToken, \"notEqual\"],\n\t[ts.SyntaxKind.LessThanToken, \"less\"],\n\t[ts.SyntaxKind.LessThanEqualsToken, \"lessEqual\"],\n\t[ts.SyntaxKind.GreaterThanToken, \"greater\"],\n\t[ts.SyntaxKind.GreaterThanEqualsToken, \"greaterEqual\"],\n\t[ts.SyntaxKind.PlusToken, \"add\"],\n\t[ts.SyntaxKind.MinusToken, \"subtract\"],\n\t[ts.SyntaxKind.AsteriskToken, \"multiply\"],\n\t[ts.SyntaxKind.SlashToken, \"divide\"],\n\t[ts.SyntaxKind.PercentToken, \"remainder\"],\n\t[ts.SyntaxKind.AmpersandToken, \"bitAnd\"],\n\t[ts.SyntaxKind.BarToken, \"bitOr\"],\n\t[ts.SyntaxKind.CaretToken, \"bitXor\"],\n\t[ts.SyntaxKind.LessThanLessThanToken, \"shiftLeft\"],\n\t[ts.SyntaxKind.GreaterThanGreaterThanToken, \"shiftRight\"],\n]);\n\n/** What every lowering scope shares with the analyzer. */\nexport interface AnalysisContext {\n\tchecker: ts.TypeChecker;\n\tresolver: TypeResolver;\n\tblocks: BlockResolver;\n\troutines: RoutineTable;\n\tpositions: Positions;\n\tfail: Fail;\n}\n\n/** A routine body, or the module's static initializers when `fn` is undefined. */\nexport interface LoweringScope {\n\tfn: PlcFunction | undefined;\n\tblock: BlockSource | undefined;\n\tenvironment: TypeEnvironment;\n\t/** Module storage, with the routine's parameters or block fields over it. */\n\tvariables: ReadonlyMap<ts.Symbol, Variable>;\n}\n\n/** A call to a helper or block method, with its instance receiver if it has one. */\ninterface RoutineCall {\n\tfn: PlcFunction;\n\targuments: Expression[];\n\tinstance?: string;\n\tindex?: Expression;\n}\n\n/**\n * Lowers the expressions of one scope to the PLC model, and holds the facts\n * that scope has proved so far: ranges, aliases, loop counters and copy sources.\n */\nexport class ExpressionLowering {\n\tprivate readonly checker: ts.TypeChecker;\n\treadonly resolver: TypeResolver;\n\tprivate readonly blocks: BlockResolver;\n\tprivate readonly routines: RoutineTable;\n\treadonly positions: Positions;\n\treadonly fail: Fail;\n\tprivate readonly variables: Map<ts.Symbol, Variable>;\n\tprivate readonly environment: TypeEnvironment;\n\tprivate readonly activeBlock: BlockSource | undefined;\n\tprivate readonly activeFunction: PlcFunction | undefined;\n\tprivate readonly ranges = new Map<string, IntegerInterval>();\n\tprivate readonly loopCounters = new Set<string>();\n\tprivate readonly aliases = new Map<ts.Symbol, Place>();\n\tprivate readonly copySources: Place[] = [];\n\t/** `byId()`, until the next binding. */\n\tprivate storage: ReadonlyMap<string, Variable> | undefined;\n\n\tconstructor(context: AnalysisContext, scope: LoweringScope) {\n\t\tthis.checker = context.checker;\n\t\tthis.resolver = context.resolver;\n\t\tthis.blocks = context.blocks;\n\t\tthis.routines = context.routines;\n\t\tthis.positions = context.positions;\n\t\tthis.fail = context.fail;\n\t\tthis.variables = new Map(scope.variables);\n\t\tthis.environment = scope.environment;\n\t\tthis.activeBlock = scope.block;\n\t\tthis.activeFunction = scope.fn;\n\t}\n\n\t/** Brings a global, parameter, block field, local, loop counter or loop key into scope. */\n\tbind(symbol: ts.Symbol, variable: Variable): void {\n\t\tthis.variables.set(symbol, variable);\n\t\tthis.storage = undefined;\n\t}\n\n\t/** Brings a const alias into scope; each use re-reads `place`. */\n\talias(symbol: ts.Symbol, place: Place): void {\n\t\tthis.aliases.set(symbol, place);\n\t}\n\n\t/** A const is assigned once, so its initializer's range holds wherever it is read. */\n\tholdRange(id: string, value: Expression): void {\n\t\tconst bound = this.interval(value);\n\t\tif (bound) {\n\t\t\tthis.ranges.set(id, bound);\n\t\t}\n\t}\n\n\t/** Lowers a branch with the ranges `condition` proves when it is `truth`, then restores them. */\n\tnarrowed<T>(condition: Expression, truth: boolean, lower: () => T): T {\n\t\tconst original = new Map(this.ranges);\n\t\tthis.ranges.clear();\n\t\tfor (const [root, range] of narrowRanges(\n\t\t\tcondition,\n\t\t\ttruth,\n\t\t\tthis.resolver.types,\n\t\t\tthis.byId(),\n\t\t\toriginal,\n\t\t)) {\n\t\t\tthis.ranges.set(root, range);\n\t\t}\n\t\ttry {\n\t\t\treturn lower();\n\t\t} finally {\n\t\t\tthis.ranges.clear();\n\t\t\tfor (const [root, range] of original) {\n\t\t\t\tthis.ranges.set(root, range);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Lowers a loop body with `counters` read-only and `counter` proved to lie in `range`. */\n\tcounting<T>(\n\t\tcounters: readonly string[],\n\t\tcounter: string,\n\t\trange: IntegerInterval,\n\t\tlower: () => T,\n\t): T {\n\t\tfor (const id of counters) {\n\t\t\tthis.loopCounters.add(id);\n\t\t}\n\t\tthis.ranges.set(counter, range);\n\t\ttry {\n\t\t\treturn lower();\n\t\t} finally {\n\t\t\tfor (const id of counters) {\n\t\t\t\tthis.loopCounters.delete(id);\n\t\t\t}\n\t\t\tthis.ranges.delete(counter);\n\t\t}\n\t}\n\n\t/** The range `expression` is proved to lie in, if it has one. */\n\tinterval(expression: Expression): IntegerInterval | undefined {\n\t\treturn interval(expression, this.resolver.types, this.byId(), this.ranges);\n\t}\n\n\tplaceType(place: Place): ReturnType<typeof placeType> {\n\t\treturn placeType(place, this.resolver.types, this.byId(), this.ranges);\n\t}\n\n\tprivate writablePlaceType(place: Place): ReturnType<typeof placeType> {\n\t\treturn placeType(\n\t\t\tplace,\n\t\t\tthis.resolver.types,\n\t\t\tthis.byId(),\n\t\t\tthis.ranges,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\ttype(node: ts.TypeNode): ResolvedType {\n\t\treturn this.resolver.resolve(node, this.environment);\n\t}\n\n\tstorageId(node: ts.Node, name: string): string {\n\t\treturn `${this.resolver.id(node, name)}${this.activeFunction ? `@${this.activeFunction.id}` : \"\"}`;\n\t}\n\n\t/** The scope's storage by symbol. */\n\tbySymbol(): ReadonlyMap<ts.Symbol, Variable> {\n\t\treturn this.variables;\n\t}\n\n\t/** The scope's storage by id, including the enclosing block's inputs and outputs. */\n\tbyId(): ReadonlyMap<string, Variable> {\n\t\tthis.storage ??= new Map(\n\t\t\t[\n\t\t\t\t...this.variables.values(),\n\t\t\t\t...(this.activeBlock\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t...this.activeBlock.block.inputs,\n\t\t\t\t\t\t\t...this.activeBlock.block.outputs,\n\t\t\t\t\t\t]\n\t\t\t\t\t: []),\n\t\t\t].map((variable) => [variable.id, variable]),\n\t\t);\n\t\treturn this.storage;\n\t}\n\n\t/** Rejects a lowered expression the model cannot hold, at the expression's own span. */\n\tprivate reject(\n\t\tspan: SourceSpan | undefined,\n\t\tcode: string,\n\t\tmessage: string,\n\t): never {\n\t\tthrow new SemanticError(error(code, message, span));\n\t}\n\n\tchecked(value: Expression): Expression {\n\t\tconst message = expressionIssue(\n\t\t\tvalue,\n\t\t\tthis.resolver.types,\n\t\t\tthis.byId(),\n\t\t\tthis.ranges,\n\t\t);\n\t\tif (message) {\n\t\t\tthis.reject(value.span, \"PLC2002\", message);\n\t\t}\n\t\treturn value;\n\t}\n\n\tprivate coerce(value: Expression, destination: string): Expression {\n\t\tif (value.type === destination) {\n\t\t\treturn value;\n\t\t}\n\t\tconst source = this.resolver.types.get(value.type);\n\t\tconst target = this.resolver.types.get(destination);\n\t\tif (!source || !target) {\n\t\t\tthis.reject(\n\t\t\t\tvalue.span,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"This PLC type has not been resolved.\",\n\t\t\t);\n\t\t}\n\t\tconst constant = fold(value, this.byId(), this.resolver.types);\n\t\tconst widerString =\n\t\t\tsource.kind === \"string\" &&\n\t\t\ttarget.kind === \"string\" &&\n\t\t\tsource.encoding === target.encoding &&\n\t\t\tsource.capacity <= target.capacity;\n\t\tif (!widerString && !canAssign(source, target, constant)) {\n\t\t\tthis.reject(\n\t\t\t\tvalue.span,\n\t\t\t\t\"PLC2002\",\n\t\t\t\t\"Use an explicit conversion between these PLC domains or widths.\",\n\t\t\t);\n\t\t}\n\t\tif (constant) {\n\t\t\treturn {\n\t\t\t\tkind: \"constant\",\n\t\t\t\ttype: destination,\n\t\t\t\tvalue: constant,\n\t\t\t\tspan: value.span,\n\t\t\t};\n\t\t}\n\t\tconst converted: Expression = {\n\t\t\tkind: \"convert\",\n\t\t\ttype: destination,\n\t\t\toperand: value,\n\t\t\tpolicy: \"exact\",\n\t\t\tspan: value.span,\n\t\t};\n\t\treturn widerString ? converted : this.checked(converted);\n\t}\n\n\tconstant(expression: Expression): Constant | undefined {\n\t\treturn fold(expression, this.byId(), this.resolver.types);\n\t}\n\n\texpression(node: ts.Expression, expected?: string): Expression {\n\t\tif (\n\t\t\tts.isParenthesizedExpression(node) ||\n\t\t\tts.isSatisfiesExpression(node) ||\n\t\t\t(ts.isAsExpression(node) && ts.isConstTypeReference(node.type))\n\t\t) {\n\t\t\treturn this.expression(node.expression, expected);\n\t\t}\n\t\tconst literal = this.literal(node, expected);\n\t\tif (literal) {\n\t\t\treturn literal;\n\t\t}\n\t\tconst value = this.rawExpression(node, expected);\n\t\treturn expected ? this.coerce(value, expected) : value;\n\t}\n\n\tprivate rawExpression(node: ts.Expression, expected?: string): Expression {\n\t\tif (\n\t\t\tnode.kind === ts.SyntaxKind.TrueKeyword ||\n\t\t\tnode.kind === ts.SyntaxKind.FalseKeyword\n\t\t) {\n\t\t\treturn {\n\t\t\t\tspan: this.positions.node(node),\n\t\t\t\ttype: \"BOOL\",\n\t\t\t\tkind: \"constant\",\n\t\t\t\tvalue: { kind: \"bool\", value: node.kind === ts.SyntaxKind.TrueKeyword },\n\t\t\t};\n\t\t}\n\t\tif (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {\n\t\t\treturn this.stringLiteral(node, expected);\n\t\t}\n\t\tif (ts.isObjectLiteralExpression(node)) {\n\t\t\tconst type = this.layout(expected);\n\t\t\tif (type?.kind === \"array\" && type.index) {\n\t\t\t\treturn this.enumKeyedLiteral(node, type, type.index);\n\t\t\t}\n\t\t\tif (type?.kind !== \"record\") {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Record literals require an explicit closed PLC record type.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn this.recordLiteral(node, type);\n\t\t}\n\t\tif (ts.isArrayLiteralExpression(node)) {\n\t\t\treturn this.arrayLiteral(node, expected);\n\t\t}\n\t\tif (ts.isPropertyAccessExpression(node)) {\n\t\t\tconst value = this.enumMember(node) ?? this.arrayLength(node);\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\t\tif (\n\t\t\tts.isPropertyAccessExpression(node) ||\n\t\t\tts.isElementAccessExpression(node) ||\n\t\t\t(ts.isIdentifier(node) && this.aliases.has(this.resolver.symbol(node)))\n\t\t) {\n\t\t\treturn this.placeLoad(node);\n\t\t}\n\t\tif (ts.isIdentifier(node)) {\n\t\t\treturn this.variableLoad(node);\n\t\t}\n\t\tif (ts.isPrefixUnaryExpression(node)) {\n\t\t\treturn this.unary(node, expected);\n\t\t}\n\t\tif (ts.isCallExpression(node)) {\n\t\t\treturn this.callExpression(node, expected);\n\t\t}\n\t\tif (ts.isConditionalExpression(node)) {\n\t\t\tconst then = this.expression(node.whenTrue, expected);\n\t\t\treturn {\n\t\t\t\tspan: this.positions.node(node),\n\t\t\t\ttype: then.type,\n\t\t\t\tkind: \"conditional\",\n\t\t\t\tcondition: this.expression(node.condition, \"BOOL\"),\n\t\t\t\tthen,\n\t\t\t\telse: this.expression(node.whenFalse, then.type),\n\t\t\t};\n\t\t}\n\t\tif (ts.isBinaryExpression(node)) {\n\t\t\treturn this.binaryExpression(node, expected);\n\t\t}\n\t\tthis.fail(\n\t\t\tnode,\n\t\t\t\"PLC1001\",\n\t\t\t`${ts.SyntaxKind[node.kind]} is not supported in PLC expressions.`,\n\t\t);\n\t}\n\n\t/** The layout a literal is lowered into. */\n\tprivate layout(expected: string | undefined): PlcType | undefined {\n\t\treturn expected ? this.resolver.types.get(expected) : undefined;\n\t}\n\n\tprivate literal(\n\t\tnode: ts.Expression,\n\t\texpected?: string,\n\t): Expression | undefined {\n\t\tconst text = numericLiteral(node);\n\t\tif (text === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst type = expected ?? numericLiteralType(text);\n\t\tconst target = this.resolver.types.get(type);\n\t\tif (!target || ![\"integer\", \"bits\", \"float\"].includes(target.kind)) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Numeric literals require an arithmetic or bit-string PLC type; use named enum members.\",\n\t\t\t);\n\t\t}\n\t\treturn this.checked({\n\t\t\tkind: \"constant\",\n\t\t\ttype,\n\t\t\tvalue:\n\t\t\t\ttarget.kind === \"float\"\n\t\t\t\t\t? { kind: \"float\", value: parseFloatLiteral(text, target) }\n\t\t\t\t\t: this.integerConstant(node, text),\n\t\t\tspan: this.positions.node(node),\n\t\t});\n\t}\n\n\tprivate integerConstant(node: ts.Expression, text: string): Constant {\n\t\ttry {\n\t\t\treturn { kind: \"integer\", value: String(parseInteger(text)) };\n\t\t} catch (cause) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2002\",\n\t\t\t\tcause instanceof Error ? cause.message : \"Invalid integer literal.\",\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate stringLiteral(\n\t\tnode: ts.StringLiteral | ts.NoSubstitutionTemplateLiteral,\n\t\texpected: string | undefined,\n\t): Expression {\n\t\tconst span = this.positions.node(node);\n\t\tconst type = this.layout(expected);\n\t\tif (type?.kind === \"enum\") {\n\t\t\tconst member = type.members.find((member) => member.name === node.text);\n\t\t\tif (member) {\n\t\t\t\treturn {\n\t\t\t\t\tspan,\n\t\t\t\t\ttype: type.id,\n\t\t\t\t\tkind: \"constant\",\n\t\t\t\t\tvalue: { kind: \"integer\", value: member.value },\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\tif (type?.kind !== \"string\") {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"String literals require a bounded STRING or WSTRING context.\",\n\t\t\t);\n\t\t}\n\t\treturn this.checked({\n\t\t\tspan,\n\t\t\ttype: type.id,\n\t\t\tkind: \"constant\",\n\t\t\tvalue: { kind: \"string\", value: node.text },\n\t\t});\n\t}\n\n\t/** Like an array literal, every element in order, so items evaluate in source order. */\n\tprivate enumKeyedLiteral(\n\t\tnode: ts.ObjectLiteralExpression,\n\t\ttype: ArrayLayout,\n\t\tindex: string,\n\t): Expression {\n\t\tconst order =\n\t\t\t\"Enum-keyed record literals list every enum member once, in value order.\";\n\t\tconst items: Expression[] = [];\n\t\tfor (const property of node.properties) {\n\t\t\tif (\n\t\t\t\t!ts.isPropertyAssignment(property) ||\n\t\t\t\t!ts.isComputedPropertyName(property.name)\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tproperty,\n\t\t\t\t\t\"PLC1001\",\n\t\t\t\t\t\"Enum-keyed record literals use computed member keys such as [Station.A].\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst key = this.expression(property.name.expression, index);\n\t\t\tif (\n\t\t\t\tkey.kind !== \"constant\" ||\n\t\t\t\tkey.type !== index ||\n\t\t\t\tkey.value.kind !== \"integer\"\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tproperty.name,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Keys must be members of the record's enum.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (Number(key.value.value) !== type.lowerBound + items.length) {\n\t\t\t\tthis.fail(property, \"PLC2001\", order);\n\t\t\t}\n\t\t\titems.push(\n\t\t\t\tthis.implicitCopy(this.expression(property.initializer, type.element)),\n\t\t\t);\n\t\t}\n\t\tif (items.length !== type.length) {\n\t\t\tthis.fail(node, \"PLC2001\", order);\n\t\t}\n\t\treturn this.checked({\n\t\t\tspan: this.positions.node(node),\n\t\t\ttype: type.id,\n\t\t\tkind: \"array\",\n\t\t\titems,\n\t\t});\n\t}\n\n\tprivate recordLiteral(\n\t\tnode: ts.ObjectLiteralExpression,\n\t\ttype: RecordLayout,\n\t): Expression {\n\t\tconst span = this.positions.node(node);\n\t\tconst fields = this.namedFields(node, type.fields, {\n\t\t\tspread: (_, value) => {\n\t\t\t\t// TypeScript's spread shares a nested record or array, so a later write to it diverges.\n\t\t\t\tthis.recordCopySource(value);\n\t\t\t\treturn this.implicitCopy(value);\n\t\t\t},\n\t\t\tnamed: (field, value) =>\n\t\t\t\tthis.implicitCopy(this.expression(value, field.type)),\n\t\t\tunnamed: {\n\t\t\t\tcode: \"PLC1001\",\n\t\t\t\tmessage:\n\t\t\t\t\t\"Record literals take named fields after at most one leading spread; methods are unsupported.\",\n\t\t\t},\n\t\t\tunknown: \"Unknown or duplicate record field.\",\n\t\t});\n\t\tif (this.resolver.unions.has(type.id)) {\n\t\t\tfor (const field of type.fields) {\n\t\t\t\tif (!Object.hasOwn(fields, field.name)) {\n\t\t\t\t\tfields[field.name] = {\n\t\t\t\t\t\tspan,\n\t\t\t\t\t\ttype: field.type,\n\t\t\t\t\t\tkind: \"constant\",\n\t\t\t\t\t\tvalue: defaultValue(field.type, this.resolver.types),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn this.checked({ span, type: type.id, kind: \"record\", fields });\n\t}\n\n\tprivate arrayLiteral(\n\t\tnode: ts.ArrayLiteralExpression,\n\t\texpected: string | undefined,\n\t): Expression {\n\t\tconst type = this.layout(expected);\n\t\tif (type?.kind !== \"array\") {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Array literals require an explicit FixedArray type.\",\n\t\t\t);\n\t\t}\n\t\tconst items = node.elements.map((element) => {\n\t\t\tif (ts.isOmittedExpression(element) || ts.isSpreadElement(element)) {\n\t\t\t\tthis.fail(\n\t\t\t\t\telement,\n\t\t\t\t\t\"PLC1001\",\n\t\t\t\t\t\"Fixed arrays cannot have holes or spreading.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn this.implicitCopy(this.expression(element, type.element));\n\t\t});\n\t\treturn this.checked({\n\t\t\tspan: this.positions.node(node),\n\t\t\ttype: type.id,\n\t\t\tkind: \"array\",\n\t\t\titems,\n\t\t});\n\t}\n\n\tprivate enumMember(\n\t\tnode: ts.PropertyAccessExpression,\n\t): Expression | undefined {\n\t\tconst declaration = this.resolver\n\t\t\t.symbol(node.name)\n\t\t\t.declarations?.find(ts.isEnumMember);\n\t\tif (!declaration) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst type = this.resolver.enumeration(declaration.parent).type;\n\t\tconst layout = this.resolver.types.get(type);\n\t\tif (layout?.kind !== \"enum\") {\n\t\t\tthis.fail(node, \"PLC2001\", \"Invalid enum layout.\");\n\t\t}\n\t\tconst member = layout.members.find(\n\t\t\t(member) => member.name === declaration.name.getText(),\n\t\t);\n\t\tif (!member) {\n\t\t\tthis.fail(node, \"PLC2001\", \"Invalid enum layout.\");\n\t\t}\n\t\treturn {\n\t\t\tspan: this.positions.node(node),\n\t\t\ttype,\n\t\t\tkind: \"constant\",\n\t\t\tvalue: { kind: \"integer\", value: member.value },\n\t\t};\n\t}\n\n\tprivate arrayLength(\n\t\tnode: ts.PropertyAccessExpression,\n\t): Expression | undefined {\n\t\t// A module global named length, read through its namespace import, is storage, not an array's length.\n\t\tif (\n\t\t\tnode.name.text !== \"length\" ||\n\t\t\tthis.variables.has(this.resolver.symbol(node.name))\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst base = this.expression(node.expression);\n\t\tconst type = this.resolver.types.get(base.type);\n\t\treturn type?.kind === \"array\"\n\t\t\t? {\n\t\t\t\t\tspan: this.positions.node(node),\n\t\t\t\t\ttype: \"DINT\",\n\t\t\t\t\tkind: \"length\",\n\t\t\t\t\toperand: base,\n\t\t\t\t}\n\t\t\t: undefined;\n\t}\n\n\tprivate placeLoad(node: ts.Expression): Expression {\n\t\tconst span = this.positions.node(node);\n\t\tconst place = this.place(node);\n\t\tconst { type, issue } = this.placeType(place);\n\t\tif (issue || !type) {\n\t\t\tthis.fail(node, \"PLC2001\", issue ?? \"Invalid PLC place.\");\n\t\t}\n\t\treturn { span, type, kind: \"load\", place };\n\t}\n\n\tprivate variableLoad(node: ts.Identifier): Expression {\n\t\tconst variable = this.variables.get(this.resolver.symbol(node));\n\t\tif (!variable) {\n\t\t\tthis.fail(node, \"PLC1002\", \"This value has no supported PLC storage.\");\n\t\t}\n\t\tif (variable.type === \"inferred\") {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC3001\",\n\t\t\t\t\"Resolve constant initializer dependencies in declaration order.\",\n\t\t\t);\n\t\t}\n\t\treturn {\n\t\t\tspan: this.positions.node(node),\n\t\t\ttype: variable.type,\n\t\t\tkind: \"load\",\n\t\t\tplace: { root: variable.id, path: [] },\n\t\t};\n\t}\n\n\tprivate unary(\n\t\tnode: ts.PrefixUnaryExpression,\n\t\texpected: string | undefined,\n\t): Expression {\n\t\tconst operator = unaryOperators.get(node.operator);\n\t\tif (!operator) {\n\t\t\tthis.fail(node, \"PLC2001\", \"Unsupported unary operation.\");\n\t\t}\n\t\tconst operand = this.expression(\n\t\t\tnode.operand,\n\t\t\toperator === \"not\" ? \"BOOL\" : expected,\n\t\t);\n\t\treturn this.checked({\n\t\t\tspan: this.positions.node(node),\n\t\t\ttype: operator === \"not\" ? \"BOOL\" : operand.type,\n\t\t\tkind: \"unary\",\n\t\t\toperator,\n\t\t\toperand,\n\t\t});\n\t}\n\n\tprivate callExpression(\n\t\tnode: ts.CallExpression,\n\t\texpected: string | undefined,\n\t): Expression {\n\t\tconst intrinsic = intrinsicExpression(this, node, expected);\n\t\tif (intrinsic) {\n\t\t\treturn intrinsic;\n\t\t}\n\t\tconst call = this.call(node);\n\t\tif (!call.fn.result) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"A void helper cannot produce an expression value.\",\n\t\t\t);\n\t\t}\n\t\treturn {\n\t\t\tspan: this.positions.node(node),\n\t\t\ttype: call.fn.result,\n\t\t\tkind: \"call\",\n\t\t\tfunction: call.fn.id,\n\t\t\targuments: call.arguments,\n\t\t\t...(call.instance && { instance: call.instance }),\n\t\t\t...(call.index && { index: call.index }),\n\t\t};\n\t}\n\n\tprivate binaryExpression(\n\t\tnode: ts.BinaryExpression,\n\t\texpected?: string,\n\t): Expression {\n\t\tconst span = this.positions.node(node);\n\t\tconst operator = operators.get(node.operatorToken.kind);\n\t\tif (!operator) {\n\t\t\tthis.fail(\n\t\t\t\tnode.operatorToken,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Unsupported binary operation; implicit coercion is prohibited.\",\n\t\t\t);\n\t\t}\n\t\tconst logical = operator === \"and\" || operator === \"or\";\n\t\tconst comparison = comparisonOperators.has(operator);\n\t\tconst { left, right: lowered } = this.leftOperand(node, operator, expected);\n\t\tconst rightType =\n\t\t\toperator === \"shiftLeft\" || operator === \"shiftRight\"\n\t\t\t\t? \"DINT\"\n\t\t\t\t: left.type;\n\t\t// Lowered in the type it already has, an operand lowers the same again.\n\t\tconst right =\n\t\t\tlowered?.type === rightType\n\t\t\t\t? lowered\n\t\t\t\t: this.expression(node.right, rightType);\n\t\tif (\n\t\t\toperator === \"divide\" &&\n\t\t\tthis.resolver.types.get(left.type)?.kind !== \"float\"\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2002\",\n\t\t\t\t\"Use div<T>() for truncating integer division.\",\n\t\t\t);\n\t\t}\n\t\treturn this.checked({\n\t\t\tspan,\n\t\t\ttype: logical || comparison ? \"BOOL\" : left.type,\n\t\t\tkind: \"binary\",\n\t\t\toperator,\n\t\t\tleft,\n\t\t\tright,\n\t\t});\n\t}\n\n\t/**\n\t * The left operand in the type the operation works in: BOOL for logic, the right\n\t * operand's type when a literal is compared to it, and the wider side of any other\n\t * comparison. The right operand then takes the left's type; `right` is how it lowered\n\t * on its own, when its type decided the left's.\n\t */\n\tprivate leftOperand(\n\t\tnode: ts.BinaryExpression,\n\t\toperator: BinaryOperator,\n\t\texpected: string | undefined,\n\t): { left: Expression; right?: Expression } {\n\t\tif (operator === \"and\" || operator === \"or\") {\n\t\t\treturn { left: this.expression(node.left, \"BOOL\") };\n\t\t}\n\t\tif (!comparisonOperators.has(operator)) {\n\t\t\treturn { left: this.expression(node.left, expected) };\n\t\t}\n\t\tif (contextualLiteral(node.left)) {\n\t\t\tconst right = this.expression(node.right);\n\t\t\treturn { left: this.expression(node.left, right.type), right };\n\t\t}\n\t\tconst left = this.expression(node.left);\n\t\tif (contextualLiteral(node.right)) {\n\t\t\treturn { left };\n\t\t}\n\t\t// Compare at the wider type; widening cannot change the value.\n\t\tconst right = this.expression(node.right);\n\t\tconst from = this.resolver.types.get(left.type);\n\t\tconst to = this.resolver.types.get(right.type);\n\t\treturn {\n\t\t\tleft:\n\t\t\t\tfrom && to && !canAssign(to, from) && canAssign(from, to)\n\t\t\t\t\t? this.coerce(left, right.type)\n\t\t\t\t\t: left,\n\t\t\tright,\n\t\t};\n\t}\n\n\tsdkCall(node: ts.CallExpression): string | undefined {\n\t\tconst name = calleeName(node.expression);\n\t\treturn name && this.resolver.sdkName(name);\n\t}\n\n\t/** `instance.update({ ... })` with every block input bound, or undefined for any other call. */\n\tupdate(node: ts.CallExpression): Statement | undefined {\n\t\tif (\n\t\t\t!ts.isPropertyAccessExpression(node.expression) ||\n\t\t\tnode.expression.name.text !== \"update\"\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst receiver = this.blockReceiver(node.expression.expression);\n\t\tif (!receiver.block || !receiver.selected) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1007\",\n\t\t\t\t\"Update requires a static block instance binding.\",\n\t\t\t);\n\t\t}\n\t\tconst definition = this.blocks.definitions.get(receiver.block);\n\t\tif (!definition) {\n\t\t\tthrow new Error(`Block ${receiver.block} has no definition.`);\n\t\t}\n\t\tconst [record, ...rest] = node.arguments;\n\t\tif (\n\t\t\tnode.typeArguments?.length ||\n\t\t\t!record ||\n\t\t\trest.length ||\n\t\t\t!ts.isObjectLiteralExpression(record)\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Block update requires one complete named input record.\",\n\t\t\t);\n\t\t}\n\t\tconst inputs = this.namedFields(record, definition.inputs, {\n\t\t\tspread: (parameter, value) =>\n\t\t\t\tparameter.mode === \"inOut\" ? this.reference(value, parameter) : value,\n\t\t\tnamed: (parameter, value) => this.inputArgument(value, parameter),\n\t\t\tunnamed: {\n\t\t\t\tcode: \"PLC2001\",\n\t\t\t\tmessage:\n\t\t\t\t\t\"Block inputs are named fields after at most one leading spread.\",\n\t\t\t},\n\t\t\tunknown: \"Unknown or duplicate block input.\",\n\t\t});\n\t\tif (definition.inputs.some((input) => !Object.hasOwn(inputs, input.name))) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Block update must bind every input on each call.\",\n\t\t\t);\n\t\t}\n\t\treturn {\n\t\t\tkind: \"blockUpdate\",\n\t\t\tinstance: receiver.place.root,\n\t\t\t...(receiver.index && { index: receiver.index }),\n\t\t\tinputs,\n\t\t\tspan: this.positions.node(node),\n\t\t};\n\t}\n\n\t/** The block instance a receiver names: a static instance, or one element of an instance array. */\n\tprivate blockReceiver(node: ts.Expression) {\n\t\tconst place = this.place(node);\n\t\tconst variable = this.byId().get(place.root);\n\t\tconst [selector, ...rest] = place.path;\n\t\tconst index = selector?.kind === \"index\" ? selector.value : undefined;\n\t\tconst array =\n\t\t\tvariable !== undefined &&\n\t\t\tthis.resolver.types.get(variable.type)?.kind === \"array\";\n\t\treturn {\n\t\t\tplace,\n\t\t\tvariable,\n\t\t\tblock:\n\t\t\t\tvariable && instancedBlock(variable.type, this.resolver.types)?.block,\n\t\t\tindex,\n\t\t\tselected: !rest.length && (array ? Boolean(index) : !selector),\n\t\t};\n\t}\n\n\tcall(node: ts.CallExpression): RoutineCall {\n\t\tconst name = calleeName(node.expression);\n\t\tif (!name) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1001\",\n\t\t\t\t\"Call a statically resolved PLC helper or block method.\",\n\t\t\t);\n\t\t}\n\t\tconst symbol = this.resolver.symbol(name);\n\t\t// Structural return types can give a receiver a transient property symbol.\n\t\t// Resolve its declaration back to the canonical instance method identity.\n\t\tconst method =\n\t\t\tthis.routines.methods.get(symbol) ??\n\t\t\tsymbol.declarations\n\t\t\t\t?.filter(ts.isMethodDeclaration)\n\t\t\t\t.map((node) =>\n\t\t\t\t\tthis.routines.methods.get(this.resolver.symbol(node.name)),\n\t\t\t\t)\n\t\t\t\t.find((fn) => fn !== undefined);\n\t\tif (method) {\n\t\t\treturn this.methodCall(node, method);\n\t\t}\n\t\tconst declaration = this.routines.functionDeclarations.get(symbol);\n\t\tif (!declaration) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1001\",\n\t\t\t\t\"Calls require PLC TypeScript implementation source.\",\n\t\t\t);\n\t\t}\n\t\tconst fn = declaration.typeParameters?.length\n\t\t\t? this.routines.instantiate(\n\t\t\t\t\tdeclaration,\n\t\t\t\t\tnode.typeArguments ?? [],\n\t\t\t\t\tnode,\n\t\t\t\t\tthis.environment,\n\t\t\t\t)\n\t\t\t: this.routines.functions.get(symbol);\n\t\tif (\n\t\t\t!fn ||\n\t\t\t(!declaration.typeParameters?.length && node.typeArguments?.length)\n\t\t) {\n\t\t\tthis.fail(node, \"PLC2001\", \"Type arguments require a generic helper.\");\n\t\t}\n\t\treturn { fn, arguments: this.callArguments(node, fn) };\n\t}\n\n\tprivate methodCall(\n\t\tnode: ts.CallExpression,\n\t\tmethod: PlcFunction,\n\t): RoutineCall {\n\t\tif (\n\t\t\t!ts.isPropertyAccessExpression(node.expression) ||\n\t\t\tnode.typeArguments?.length\n\t\t) {\n\t\t\tthis.fail(node, \"PLC1007\", \"Methods require a static instance receiver.\");\n\t\t}\n\t\tconst receiver = node.expression.expression;\n\t\tif (receiver.kind === ts.SyntaxKind.ThisKeyword) {\n\t\t\tif (method.owner?.block !== this.activeBlock?.block.id) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC1007\",\n\t\t\t\t\t\"Method receiver differs from the enclosing block.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn { fn: method, arguments: this.callArguments(node, method) };\n\t\t}\n\t\tconst instance = this.blockReceiver(receiver);\n\t\tif (\n\t\t\t(instance.variable?.storage !== \"instance\" &&\n\t\t\t\tinstance.variable?.mode !== \"inOut\") ||\n\t\t\t!instance.selected ||\n\t\t\tinstance.block !== method.owner?.block\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1007\",\n\t\t\t\t\"Methods require a matching static block instance.\",\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\tmethod.owner?.access !== \"public\" &&\n\t\t\tmethod.owner?.block !== this.activeBlock?.block.id\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1007\",\n\t\t\t\t\"Private and protected methods are only accessible within their block.\",\n\t\t\t);\n\t\t}\n\t\treturn {\n\t\t\tfn: method,\n\t\t\targuments: this.callArguments(node, method),\n\t\t\tinstance: instance.place.root,\n\t\t\t...(instance.index && { index: instance.index }),\n\t\t};\n\t}\n\n\tprivate callArguments(\n\t\tnode: ts.CallExpression,\n\t\tfn: PlcFunction,\n\t): Expression[] {\n\t\tif (node.arguments.length !== fn.parameters.length) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"PLC argument count differs from its signature.\",\n\t\t\t);\n\t\t}\n\t\treturn node.arguments.map((argument, index) => {\n\t\t\tconst parameter = fn.parameters[index];\n\t\t\tif (!parameter) {\n\t\t\t\tthrow new Error(`${fn.id} takes ${fn.parameters.length} arguments.`);\n\t\t\t}\n\t\t\treturn this.inputArgument(argument, parameter);\n\t\t});\n\t}\n\n\tprivate inputArgument(value: ts.Expression, parameter: Variable): Expression {\n\t\tif (parameter.mode !== \"inOut\") {\n\t\t\treturn this.expression(value, parameter.type);\n\t\t}\n\t\tif (ts.isCallExpression(value) && this.sdkCall(value) === \"ref\") {\n\t\t\tconst [borrowed, ...rest] = value.arguments;\n\t\t\tif (!borrowed || rest.length || value.typeArguments?.length) {\n\t\t\t\tthis.fail(value, \"PLC3003\", \"ref takes one place.\");\n\t\t\t}\n\t\t\tconst target = this.target(borrowed);\n\t\t\tif (target.type !== parameter.type) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tvalue,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Borrowed place type must exactly match its InOut parameter.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"borrow\",\n\t\t\t\tplace: target.place,\n\t\t\t\ttype: target.type,\n\t\t\t\tspan: this.positions.node(value),\n\t\t\t};\n\t\t}\n\t\tif (this.resolver.types.get(parameter.type)?.kind === \"block\") {\n\t\t\tconst place = this.place(value);\n\t\t\tif (this.placeType(place).type !== parameter.type) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tvalue,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Pass a block instance of the parameter's type.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"borrow\",\n\t\t\t\tplace,\n\t\t\t\ttype: parameter.type,\n\t\t\t\tspan: this.positions.node(value),\n\t\t\t};\n\t\t}\n\t\treturn this.reference(this.expression(value, parameter.type), parameter);\n\t}\n\n\t/**\n\t * An aggregate InOut argument borrows its place; a value with no writable address reaches\n\t * the callee through a compiler temporary.\n\t */\n\tprivate reference(argument: Expression, parameter: Variable): Expression {\n\t\tif (!aggregate(this.resolver.types.get(parameter.type))) {\n\t\t\tthis.reject(\n\t\t\t\targument.span,\n\t\t\t\t\"PLC3003\",\n\t\t\t\t\"Scalar InOut arguments require a direct ref(place) borrow.\",\n\t\t\t);\n\t\t}\n\t\treturn argument.kind === \"load\" &&\n\t\t\t!this.loopCounters.has(argument.place.root) &&\n\t\t\t!this.writablePlaceType(argument.place).issue\n\t\t\t? {\n\t\t\t\t\tkind: \"borrow\",\n\t\t\t\t\tplace: argument.place,\n\t\t\t\t\ttype: argument.type,\n\t\t\t\t\tspan: argument.span,\n\t\t\t\t}\n\t\t\t: this.implicitCopy(argument);\n\t}\n\n\t/**\n\t * The values an object literal gives its targets: named fields after at most one leading\n\t * spread, each target written at most once. A named field overrides the spread and keeps its\n\t * source evaluation order.\n\t */\n\tprivate namedFields<Target extends { name: string; type: string }>(\n\t\trecord: ts.ObjectLiteralExpression,\n\t\ttargets: readonly Target[],\n\t\trules: {\n\t\t\tspread: (target: Target, value: Expression) => Expression;\n\t\t\tnamed: (target: Target, value: ts.Expression) => Expression;\n\t\t\tunnamed: { code: string; message: string };\n\t\t\tunknown: string;\n\t\t},\n\t): Record<string, Expression> {\n\t\tconst values: Record<string, Expression> = Object.create(null);\n\t\tconst written = new Set<string>();\n\t\tfor (const [position, property] of record.properties.entries()) {\n\t\t\tif (ts.isSpreadAssignment(property) && !position) {\n\t\t\t\tfor (const [target, value] of this.spreadFields(\n\t\t\t\t\tproperty.expression,\n\t\t\t\t\ttargets,\n\t\t\t\t)) {\n\t\t\t\t\tvalues[target.name] = rules.spread(target, value);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst named = namedProperty(property);\n\t\t\tif (!named) {\n\t\t\t\tthis.fail(property, rules.unnamed.code, rules.unnamed.message);\n\t\t\t}\n\t\t\tconst target = targets.find((target) => target.name === named.name);\n\t\t\tif (!target || written.has(target.name)) {\n\t\t\t\tthis.fail(property, \"PLC2001\", rules.unknown);\n\t\t\t}\n\t\t\twritten.add(target.name);\n\t\t\tdelete values[target.name];\n\t\t\tvalues[target.name] = rules.named(target, named.value);\n\t\t}\n\t\treturn values;\n\t}\n\n\t/**\n\t * The fields `{ ...base }` supplies, each with the target it fills: base is a record whose\n\t * fields are all target fields of the same type. A stored base is read field by field;\n\t * `defaultValue<T>()` gives constants.\n\t */\n\tprivate spreadFields<Target extends { name: string; type: string }>(\n\t\tnode: ts.Expression,\n\t\ttargets: readonly Target[],\n\t): [Target, Expression][] {\n\t\tconst spread = this.expression(node);\n\t\tconst layout = this.resolver.types.get(spread.type);\n\t\tconst filled: [Target, string][] = [];\n\t\tfor (const field of layout?.kind === \"record\" ? layout.fields : []) {\n\t\t\tconst target = targets.find((target) => target.name === field.name);\n\t\t\tif (target?.type !== field.type) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfilled.push([target, field.name]);\n\t\t}\n\t\tif (layout?.kind !== \"record\" || filled.length !== layout.fields.length) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"A spread is a record whose fields are all fields of the target, with the same types.\",\n\t\t\t);\n\t\t}\n\t\t// Static initializers run before any scan, so a stored base contributes its initial value.\n\t\tconst initial =\n\t\t\t!this.activeFunction &&\n\t\t\tspread.kind === \"load\" &&\n\t\t\t!spread.place.path.length\n\t\t\t\t? this.byId().get(spread.place.root)?.initial\n\t\t\t\t: undefined;\n\t\tconst base: Expression = initial\n\t\t\t? { ...spread, kind: \"constant\", value: initial }\n\t\t\t: spread;\n\t\tif (base.kind === \"load\") {\n\t\t\tconst { place } = base;\n\t\t\treturn filled.map(([target, name]) => [\n\t\t\t\ttarget,\n\t\t\t\t{\n\t\t\t\t\tkind: \"load\",\n\t\t\t\t\ttype: target.type,\n\t\t\t\t\tplace: {\n\t\t\t\t\t\troot: place.root,\n\t\t\t\t\t\tpath: [...place.path, { kind: \"field\", name }],\n\t\t\t\t\t},\n\t\t\t\t\tspan: base.span,\n\t\t\t\t},\n\t\t\t]);\n\t\t}\n\t\tif (base.kind !== \"constant\" || base.value.kind !== \"record\") {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1001\",\n\t\t\t\t\"Spread a record in storage or defaultValue<T>(); bind other values to a const first.\",\n\t\t\t);\n\t\t}\n\t\tconst { value } = base;\n\t\treturn filled.map(([target, name]) => {\n\t\t\tconst field = value.fields[name];\n\t\t\tif (!field) {\n\t\t\t\tthrow new Error(`A ${spread.type} constant has no ${name} field.`);\n\t\t\t}\n\t\t\treturn [\n\t\t\t\ttarget,\n\t\t\t\t{ kind: \"constant\", type: target.type, value: field, span: base.span },\n\t\t\t];\n\t\t});\n\t}\n\n\t/** A record or array assigned into storage copies: fixed storage cannot repoint at its source. */\n\timplicitCopy(value: Expression): Expression {\n\t\tif (instancedBlock(value.type, this.resolver.types)) {\n\t\t\tthis.reject(\n\t\t\t\tvalue.span,\n\t\t\t\t\"PLC3003\",\n\t\t\t\t\"Block instances cannot be copied, aliased or returned.\",\n\t\t\t);\n\t\t}\n\t\treturn aggregate(this.resolver.types.get(value.type)) &&\n\t\t\tvalue.kind === \"load\"\n\t\t\t? { kind: \"copy\", type: value.type, operand: value, span: value.span }\n\t\t\t: value;\n\t}\n\n\t/** Remember a copied source, so a later write to it in this routine cannot silently diverge. */\n\trecordCopySource(value: Expression): void {\n\t\tif (\n\t\t\tvalue.kind === \"load\" &&\n\t\t\taggregate(this.resolver.types.get(value.type))\n\t\t) {\n\t\t\tthis.copySources.push(value.place);\n\t\t}\n\t}\n\n\t/** An alias re-reads its path at each use, so its indexes must keep their value for its scope. */\n\tunchanging(value: Expression): boolean {\n\t\tif (value.kind === \"constant\") {\n\t\t\treturn true;\n\t\t}\n\t\tif (value.kind === \"convert\") {\n\t\t\treturn this.unchanging(value.operand);\n\t\t}\n\t\tif (value.kind === \"binary\") {\n\t\t\treturn this.unchanging(value.left) && this.unchanging(value.right);\n\t\t}\n\t\tif (value.kind !== \"load\" || value.place.path.length) {\n\t\t\treturn false;\n\t\t}\n\t\tconst root = this.byId().get(value.place.root);\n\t\treturn (\n\t\t\tthis.loopCounters.has(value.place.root) ||\n\t\t\tBoolean(\n\t\t\t\troot &&\n\t\t\t\t\t!root.mutable &&\n\t\t\t\t\t[\"parameter\", \"local\", \"constant\"].includes(root.storage),\n\t\t\t)\n\t\t);\n\t}\n\n\tplace(node: ts.Expression): Place {\n\t\tif (ts.isParenthesizedExpression(node)) {\n\t\t\treturn this.place(node.expression);\n\t\t}\n\t\tif (this.activeBlock && ts.isPropertyAccessExpression(node)) {\n\t\t\tif (\n\t\t\t\tts.isIdentifier(node.expression) &&\n\t\t\t\tthis.resolver.symbol(node.expression) === this.activeBlock.inputSymbol\n\t\t\t) {\n\t\t\t\tconst variable = this.activeBlock.inputBindings.get(node.name.text);\n\t\t\t\tif (!variable) {\n\t\t\t\t\tthis.fail(node, \"PLC2001\", \"Unknown block input field.\");\n\t\t\t\t}\n\t\t\t\treturn { root: variable.id, path: [] };\n\t\t\t}\n\t\t\tif (\n\t\t\t\tts.isPropertyAccessExpression(node.expression) &&\n\t\t\t\tnode.expression.expression.kind === ts.SyntaxKind.ThisKeyword &&\n\t\t\t\tnode.expression.name.text === \"out\"\n\t\t\t) {\n\t\t\t\tconst variable = this.activeBlock.block.outputs.find(\n\t\t\t\t\t(output) => output.name === node.name.text,\n\t\t\t\t);\n\t\t\t\tif (!variable) {\n\t\t\t\t\tthis.fail(node, \"PLC2001\", \"Unknown block output field.\");\n\t\t\t\t}\n\t\t\t\treturn { root: variable.id, path: [] };\n\t\t\t}\n\t\t}\n\t\tif (\n\t\t\tts.isPropertyAccessExpression(node) &&\n\t\t\tthis.activeBlock?.fieldBindings.has(this.resolver.symbol(node.name)) &&\n\t\t\tnode.expression.kind !== ts.SyntaxKind.ThisKeyword\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1007\",\n\t\t\t\t\"Private block state is accessible through this.field only.\",\n\t\t\t);\n\t\t}\n\t\tif (ts.isIdentifier(node)) {\n\t\t\tconst alias = this.aliases.get(this.resolver.symbol(node));\n\t\t\tif (alias) {\n\t\t\t\treturn alias;\n\t\t\t}\n\t\t}\n\t\tif (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node)) {\n\t\t\tconst variable = this.variables.get(\n\t\t\t\tthis.resolver.symbol(ts.isIdentifier(node) ? node : node.name),\n\t\t\t);\n\t\t\tif (variable) {\n\t\t\t\treturn { root: variable.id, path: [] };\n\t\t\t}\n\t\t}\n\t\tif (ts.isPropertyAccessExpression(node)) {\n\t\t\tconst base = this.place(node.expression);\n\t\t\treturn {\n\t\t\t\troot: base.root,\n\t\t\t\tpath: [...base.path, { kind: \"field\", name: node.name.text }],\n\t\t\t};\n\t\t}\n\t\tif (ts.isElementAccessExpression(node) && node.argumentExpression) {\n\t\t\tconst base = this.place(node.expression);\n\t\t\tconst value = this.expression(node.argumentExpression);\n\t\t\tconst baseType = this.placeType(base).type;\n\t\t\tconst array =\n\t\t\t\tbaseType === undefined ? undefined : this.resolver.types.get(baseType);\n\t\t\tif (\n\t\t\t\tarray?.kind === \"array\" &&\n\t\t\t\tarray.index &&\n\t\t\t\tvalue.type !== array.index\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"An enum-keyed record is indexed only by its own enum.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\troot: base.root,\n\t\t\t\tpath: [...base.path, { kind: \"index\", value }],\n\t\t\t};\n\t\t}\n\t\tthis.fail(\n\t\t\tnode,\n\t\t\t\"PLC1001\",\n\t\t\t\"Access requires statically allocated PLC storage.\",\n\t\t);\n\t}\n\n\ttarget(node: ts.Expression): { place: Place; type: string } {\n\t\tif (ts.isIdentifier(node)) {\n\t\t\tconst binding = this.checker.getSymbolAtLocation(node);\n\t\t\tif (binding && binding.flags & ts.SymbolFlags.Alias) {\n\t\t\t\tthis.fail(node, \"PLC3002\", \"Imported scalar bindings are read-only.\");\n\t\t\t}\n\t\t}\n\t\tconst place = this.place(node);\n\t\tconst { type, issue } = this.writablePlaceType(place);\n\t\tif (issue || !type || this.loopCounters.has(place.root)) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC3002\",\n\t\t\t\tissue ??\n\t\t\t\t\t\"This storage is read-only here: copy it into a let and change the copy.\",\n\t\t\t);\n\t\t}\n\t\tconst overlaps = (source: Place) =>\n\t\t\tsource.root === place.root &&\n\t\t\tsource.path.every((segment, index) => {\n\t\t\t\tconst other = place.path[index];\n\t\t\t\treturn (\n\t\t\t\t\t!other ||\n\t\t\t\t\tsegment.kind !== \"field\" ||\n\t\t\t\t\tother.kind !== \"field\" ||\n\t\t\t\t\tsegment.name === other.name\n\t\t\t\t);\n\t\t\t});\n\t\tif (this.copySources.some(overlaps)) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC3003\",\n\t\t\t\t\"This value was assigned into other storage, which holds a copy, so this write will not reach it. Assign it afterwards, or use copy(value) if separate values are intended.\",\n\t\t\t);\n\t\t}\n\t\treturn { place, type };\n\t}\n}\n\n/** A literal whose type comes from the other side of a comparison. */\nfunction contextualLiteral(node: ts.Expression): boolean {\n\tconst inner = unparenthesized(node);\n\treturn (\n\t\tnumericLiteral(inner) !== undefined ||\n\t\tts.isStringLiteral(inner) ||\n\t\tts.isNoSubstitutionTemplateLiteral(inner)\n\t);\n}\n",
12
+ "import {\n\ttype Constant,\n\tcalendarLiteral,\n\tdefaultValue,\n\tdurationLiteral,\n\ttype Expression,\n\tisRadixLiteral,\n\tparseInteger,\n} from \"@tsplc/compiler/ir\";\nimport { nanosecondsPerMillisecond } from \"@tsplc/iec\";\nimport { elementaryFunctions, type UnaryOperator } from \"@tsplc/iec/arithmetic\";\nimport ts from \"typescript\";\nimport type { ExpressionLowering } from \"./expressions\";\nimport { numericLiteral } from \"./types\";\n\ntype Conversion = Extract<Expression, { kind: \"convert\" }>[\"policy\"];\ntype Arithmetic = Pick<\n\tExtract<Expression, { kind: \"binary\" }>,\n\t\"operator\" | \"policy\"\n>;\n\n/** The SDK's TIME constructors, such as `ms`, by the nanoseconds one unit of each is. */\nexport const durationScales: ReadonlyMap<string, bigint> = new Map([\n\t[\"ms\", nanosecondsPerMillisecond],\n\t[\"seconds\", 1000n * nanosecondsPerMillisecond],\n\t[\"minutes\", 60_000n * nanosecondsPerMillisecond],\n]);\nconst calendarTypes = new Map<string, string>([\n\t[\"date\", \"DATE\"],\n\t[\"timeOfDay\", \"TIME_OF_DAY\"],\n\t[\"dateAndTime\", \"DATE_AND_TIME\"],\n]);\n/** The SDK's conversions, each named for the policy it applies. */\nconst conversions: readonly Conversion[] = [\"exact\", \"wrap\", \"saturate\"];\nconst isConversion = (name: string): name is Conversion =>\n\tconversions.some((conversion) => conversion === name);\n/** The SDK's one-operand math functions, each over the floating type its type argument names. */\nconst mathFunctions = new Map<string, UnaryOperator>([\n\t...elementaryFunctions.map((name): [string, UnaryOperator] => [name, name]),\n\t[\"trunc\", \"truncate\"],\n]);\n\nconst arithmetic = new Map<string, Arithmetic>([\n\t[\"div\", { operator: \"divide\" }],\n\t[\"expt\", { operator: \"power\" }],\n\t[\"wrapAdd\", { operator: \"add\", policy: \"wrap\" }],\n\t[\"wrapSubtract\", { operator: \"subtract\", policy: \"wrap\" }],\n\t[\"wrapMultiply\", { operator: \"multiply\", policy: \"wrap\" }],\n\t[\"saturatingAdd\", { operator: \"add\", policy: \"saturate\" }],\n\t[\"saturatingSubtract\", { operator: \"subtract\", policy: \"saturate\" }],\n\t[\"saturatingMultiply\", { operator: \"multiply\", policy: \"saturate\" }],\n]);\n\n/** The SDK calls whose value has the PLC type their type argument names, such as `wrap<INT>(x)`. */\nexport const typeArgumentIntrinsics: ReadonlySet<string> = new Set([\n\t...conversions,\n\t...mathFunctions.keys(),\n\t...arithmetic.keys(),\n\t\"defaultValue\",\n\t\"copy\",\n]);\n\n/** A call to an SDK intrinsic such as `ms`, `wrap<T>` or `defaultValue<T>`; undefined for any other call. */\nexport function intrinsicExpression(\n\tlowering: ExpressionLowering,\n\tnode: ts.CallExpression,\n\texpected?: string,\n): Expression | undefined {\n\tconst name = lowering.sdkCall(node);\n\tif (name === undefined) {\n\t\treturn undefined;\n\t}\n\tconst scale = durationScales.get(name);\n\tif (scale !== undefined) {\n\t\treturn timeConstant(lowering, node, \"TIME\", (argument) =>\n\t\t\tdurationConstant(lowering, argument, scale),\n\t\t);\n\t}\n\tconst calendar = calendarTypes.get(name);\n\tif (calendar !== undefined) {\n\t\treturn timeConstant(lowering, node, calendar, (argument) =>\n\t\t\tcalendarConstant(lowering, argument, calendar),\n\t\t);\n\t}\n\tif (isConversion(name)) {\n\t\treturn converted(lowering, node, name);\n\t}\n\tconst operation = arithmetic.get(name);\n\tif (operation !== undefined) {\n\t\treturn arithmeticExpression(lowering, node, operation);\n\t}\n\tconst mathOperator = mathFunctions.get(name);\n\tif (mathOperator !== undefined) {\n\t\treturn mathExpression(lowering, node, mathOperator);\n\t}\n\tswitch (name) {\n\t\tcase \"errorCode\":\n\t\t\treturn errorCode(lowering, node);\n\t\tcase \"now\":\n\t\t\treturn now(lowering, node);\n\t\tcase \"timeToMilliseconds\":\n\t\t\treturn timeToMilliseconds(lowering, node);\n\t\tcase \"defaultValue\":\n\t\t\treturn defaultValueExpression(lowering, node);\n\t\tcase \"copy\":\n\t\t\treturn copyExpression(lowering, node, expected);\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nfunction errorCode(\n\tlowering: ExpressionLowering,\n\tnode: ts.CallExpression,\n): Expression {\n\tconst [reason, ...rest] = node.arguments;\n\tif (!reason || rest.length) {\n\t\tlowering.fail(node, \"PLC1012\", \"errorCode requires one rejection reason.\");\n\t}\n\treturn lowering.expression(reason, \"UDINT\");\n}\n\n/** A TIME or calendar value from its one compile-time argument. */\nfunction timeConstant(\n\tlowering: ExpressionLowering,\n\tnode: ts.CallExpression,\n\ttype: string,\n\tconstant: (argument: ts.Expression) => Constant | undefined,\n): Expression {\n\tconst [argument, ...rest] = node.arguments;\n\tif (!argument || rest.length || node.typeArguments?.length) {\n\t\tlowering.fail(\n\t\t\tnode,\n\t\t\t\"PLC2001\",\n\t\t\t\"Time constructors require one compile-time literal argument.\",\n\t\t);\n\t}\n\tconst value = constant(argument);\n\tif (!value) {\n\t\tlowering.fail(\n\t\t\targument,\n\t\t\t\"PLC2002\",\n\t\t\t\"Invalid time literal: require an exact supported domain value and millisecond TIME precision.\",\n\t\t);\n\t}\n\treturn lowering.checked({\n\t\tspan: lowering.positions.node(node),\n\t\ttype,\n\t\tkind: \"constant\",\n\t\tvalue,\n\t});\n}\n\nfunction durationConstant(\n\tlowering: ExpressionLowering,\n\targument: ts.Expression,\n\tscale: bigint,\n): Constant | undefined {\n\tconst text = durationText(lowering, argument);\n\treturn text === undefined ? undefined : literalDuration(text, scale);\n}\n\n/** The TIME value a numeric literal's text stands for in units of `scale` nanoseconds. */\nexport function literalDuration(\n\ttext: string,\n\tscale: bigint,\n): Constant | undefined {\n\tconst decimal = isRadixLiteral(text) ? String(parseInteger(text)) : text;\n\treturn durationLiteral(decimal.replace(/n$/, \"\"), scale);\n}\n\n/** The literal as written, so its decimal spelling survives, or a folded integer constant. */\nfunction durationText(\n\tlowering: ExpressionLowering,\n\targument: ts.Expression,\n): string | undefined {\n\tconst literal = numericLiteral(argument);\n\tif (literal !== undefined) {\n\t\treturn literal;\n\t}\n\tconst folded = lowering.constant(lowering.expression(argument));\n\treturn folded?.kind === \"integer\" ? folded.value : undefined;\n}\n\nfunction calendarConstant(\n\tlowering: ExpressionLowering,\n\targument: ts.Expression,\n\ttype: string,\n): Constant | undefined {\n\tconst layout = lowering.resolver.types.get(type);\n\treturn layout?.kind === \"calendar\" &&\n\t\t(ts.isStringLiteral(argument) ||\n\t\t\tts.isNoSubstitutionTemplateLiteral(argument))\n\t\t? calendarLiteral(layout.domain, argument.text)\n\t\t: undefined;\n}\n\nfunction now(\n\tlowering: ExpressionLowering,\n\tnode: ts.CallExpression,\n): Expression {\n\tif (node.arguments.length || node.typeArguments?.length) {\n\t\tlowering.fail(node, \"PLC2001\", \"now() takes no arguments.\");\n\t}\n\tconst span = lowering.positions.node(node);\n\treturn lowering.checked({\n\t\tspan,\n\t\ttype: \"DINT\",\n\t\tkind: \"unary\",\n\t\toperator: \"clock\",\n\t\toperand: {\n\t\t\tspan,\n\t\t\ttype: \"DINT\",\n\t\t\tkind: \"constant\",\n\t\t\tvalue: { kind: \"integer\", value: \"0\" },\n\t\t},\n\t});\n}\n\nfunction timeToMilliseconds(\n\tlowering: ExpressionLowering,\n\tnode: ts.CallExpression,\n): Expression {\n\tconst [time, ...rest] = node.arguments;\n\tif (!time || rest.length || node.typeArguments?.length) {\n\t\tlowering.fail(\n\t\t\tnode,\n\t\t\t\"PLC2001\",\n\t\t\t\"timeToMilliseconds requires one TIME argument and no type arguments.\",\n\t\t);\n\t}\n\treturn lowering.checked({\n\t\tspan: lowering.positions.node(node),\n\t\ttype: \"UDINT\",\n\t\tkind: \"unary\",\n\t\toperator: \"timeToMilliseconds\",\n\t\toperand: lowering.expression(time),\n\t});\n}\n\nfunction defaultValueExpression(\n\tlowering: ExpressionLowering,\n\tnode: ts.CallExpression,\n): Expression {\n\tconst [layout, ...rest] = node.typeArguments ?? [];\n\tif (node.arguments.length || !layout || rest.length) {\n\t\tlowering.fail(\n\t\t\tnode,\n\t\t\t\"PLC2001\",\n\t\t\t\"defaultValue requires exactly one concrete type and no value arguments.\",\n\t\t);\n\t}\n\tconst type = lowering.type(layout);\n\tif (!lowering.resolver.isValue(type)) {\n\t\tlowering.fail(\n\t\t\tnode,\n\t\t\t\"PLC2001\",\n\t\t\t\"defaultValue requires a fixed value layout, not an instance or borrow schema.\",\n\t\t);\n\t}\n\tif (type.io) {\n\t\tlowering.fail(node, \"PLC4002\", \"Default values cannot create logical I/O.\");\n\t}\n\treturn lowering.checked({\n\t\tspan: lowering.positions.node(node),\n\t\ttype: type.type,\n\t\tkind: \"constant\",\n\t\tvalue: defaultValue(type.type, lowering.resolver.types),\n\t});\n}\n\nfunction copyExpression(\n\tlowering: ExpressionLowering,\n\tnode: ts.CallExpression,\n\texpected: string | undefined,\n): Expression {\n\tconst [value, ...rest] = node.arguments;\n\tif (\n\t\t!value ||\n\t\trest.length ||\n\t\t(node.typeArguments && node.typeArguments.length !== 1)\n\t) {\n\t\tlowering.fail(node, \"PLC2001\", \"copy requires one fixed aggregate value.\");\n\t}\n\tconst layout = node.typeArguments?.[0];\n\tconst operand = lowering.expression(\n\t\tvalue,\n\t\tlayout ? lowering.type(layout).type : expected,\n\t);\n\treturn lowering.checked({\n\t\tspan: lowering.positions.node(node),\n\t\ttype: operand.type,\n\t\tkind: \"copy\",\n\t\toperand,\n\t});\n}\n\n/** The explicit PLC type argument a numeric conversion or arithmetic operation works in. */\nfunction operationType(\n\tlowering: ExpressionLowering,\n\tnode: ts.CallExpression,\n): string {\n\tconst [argument, ...rest] = node.typeArguments ?? [];\n\tif (!argument || rest.length) {\n\t\tlowering.fail(\n\t\t\tnode,\n\t\t\t\"PLC2001\",\n\t\t\t\"Numeric SDK operations require one explicit PLC type argument.\",\n\t\t);\n\t}\n\tconst target = lowering.type(argument);\n\tif (target.io) {\n\t\tlowering.fail(\n\t\t\targument,\n\t\t\t\"PLC2001\",\n\t\t\t\"I/O wrappers cannot select an operation type.\",\n\t\t);\n\t}\n\treturn target.type;\n}\n\nfunction converted(\n\tlowering: ExpressionLowering,\n\tnode: ts.CallExpression,\n\tpolicy: Conversion,\n): Expression {\n\tconst type = operationType(lowering, node);\n\tconst [operand, ...rest] = node.arguments;\n\tif (!operand || rest.length) {\n\t\tlowering.fail(node, \"PLC2001\", \"Conversion needs exactly one operand.\");\n\t}\n\treturn lowering.checked({\n\t\tspan: lowering.positions.node(node),\n\t\ttype,\n\t\tkind: \"convert\",\n\t\tpolicy,\n\t\toperand: lowering.expression(operand),\n\t});\n}\n\nfunction mathExpression(\n\tlowering: ExpressionLowering,\n\tnode: ts.CallExpression,\n\toperator: UnaryOperator,\n): Expression {\n\tconst type = operationType(lowering, node);\n\tconst [operand, ...rest] = node.arguments;\n\tif (!operand || rest.length) {\n\t\tlowering.fail(node, \"PLC2001\", \"A math function takes one operand.\");\n\t}\n\treturn lowering.checked({\n\t\tspan: lowering.positions.node(node),\n\t\ttype,\n\t\tkind: \"unary\",\n\t\toperator,\n\t\toperand: lowering.expression(operand, type),\n\t});\n}\n\nfunction arithmeticExpression(\n\tlowering: ExpressionLowering,\n\tnode: ts.CallExpression,\n\toperation: Arithmetic,\n): Expression {\n\tconst type = operationType(lowering, node);\n\tconst [left, right, ...rest] = node.arguments;\n\tif (!left || !right || rest.length) {\n\t\tlowering.fail(\n\t\t\tnode,\n\t\t\t\"PLC2001\",\n\t\t\t\"Arithmetic SDK operation needs two operands.\",\n\t\t);\n\t}\n\treturn lowering.checked({\n\t\tspan: lowering.positions.node(node),\n\t\ttype,\n\t\tkind: \"binary\",\n\t\t...operation,\n\t\tleft: lowering.expression(left, type),\n\t\tright: lowering.expression(right, type),\n\t});\n}\n",
13
+ "import { dirname, relative } from \"node:path\";\nimport ts from \"typescript\";\nimport { namesSdk, symbolAt } from \"./sdk\";\n\n/** The quoted specifier an import generated into `importer` uses to reach `target`. */\nexport const importSpecifier = (importer: string, target: string): string => {\n\tconst path = relative(dirname(importer), target).replaceAll(\"\\\\\", \"/\");\n\t// A file beside the importer may itself start with a dot, as a generated `.tsplc-services.ts` does.\n\treturn JSON.stringify(/^\\.\\.?\\//.test(path) ? path : `./${path}`);\n};\n\n/**\n * Whether an import or re-export loads its module when the importer runs: not when it is\n * type-only, nor when every name it lists is a type.\n */\nexport const runtimeImport = (\n\tstatement: ts.ImportDeclaration | ts.ExportDeclaration,\n\tchecker: ts.TypeChecker,\n): boolean => {\n\tconst typeOnly = ts.isImportDeclaration(statement)\n\t\t? statement.importClause?.isTypeOnly\n\t\t: statement.isTypeOnly;\n\tif (typeOnly) {\n\t\treturn false;\n\t}\n\tconst bindings = ts.isImportDeclaration(statement)\n\t\t? statement.importClause?.namedBindings\n\t\t: statement.exportClause;\n\tconst defaultName = ts.isImportDeclaration(statement)\n\t\t? statement.importClause?.name\n\t\t: undefined;\n\tconst namesOnlyTypes =\n\t\tbindings &&\n\t\t(ts.isNamedImports(bindings) || ts.isNamedExports(bindings)) &&\n\t\tbindings.elements.length > 0 &&\n\t\tbindings.elements.every((binding) => {\n\t\t\tconst symbol = symbolAt(checker, binding.name);\n\t\t\treturn (\n\t\t\t\tbinding.isTypeOnly ||\n\t\t\t\t(symbol !== undefined && !(symbol.flags & ts.SymbolFlags.Value))\n\t\t\t);\n\t\t});\n\treturn !namesOnlyTypes || defaultName !== undefined;\n};\n\n/** `Block` in a `FixedArray<Block, ...>` annotation, where `namesFixedArray` tells whether a reference names `FixedArray`. */\nconst fixedArrayElement = (\n\tnode: ts.Node,\n\tnamesFixedArray: (name: ts.EntityName) => boolean,\n): ts.TypeReferenceNode | undefined => {\n\tif (!ts.isTypeReferenceNode(node) || !namesFixedArray(node.typeName)) {\n\t\treturn undefined;\n\t}\n\tconst [element] = node.typeArguments ?? [];\n\treturn element && ts.isTypeReferenceNode(element) ? element : undefined;\n};\n\n/** `Block` in a `FixedArray<Block, ...>` annotation, whose instances the array allocates when it names a block class. */\nexport const blockArrayElement = (\n\tnode: ts.TypeNode,\n\tchecker: ts.TypeChecker,\n\tsdk: string,\n): ts.TypeReferenceNode | undefined =>\n\tfixedArrayElement(node, (name) => namesSdk(checker, sdk, name, \"FixedArray\"));\n\n/** Runtime imports define execution; type-only imports provide layouts without allocating state. */\nexport const runtimeSources = (\n\tprogram: ts.Program,\n): readonly ts.SourceFile[] => {\n\tconst checker = program.getTypeChecker();\n\tconst visited = new Set<ts.SourceFile>();\n\t// A block array allocates through its type, so its block's module runs even when type-imported.\n\tconst visitBlockArrays = (node: ts.Node): void => {\n\t\tconst element = fixedArrayElement(\n\t\t\tnode,\n\t\t\t(name) => name.getText() === \"FixedArray\",\n\t\t);\n\t\tconst block =\n\t\t\telement &&\n\t\t\tsymbolAt(checker, element.typeName)?.declarations?.find(\n\t\t\t\tts.isClassDeclaration,\n\t\t\t);\n\t\tif (block) {\n\t\t\tvisit(block.getSourceFile());\n\t\t}\n\t\tts.forEachChild(node, visitBlockArrays);\n\t};\n\tconst visit = (source: ts.SourceFile): void => {\n\t\tif (visited.has(source)) {\n\t\t\treturn;\n\t\t}\n\t\tvisited.add(source);\n\t\tif (source.isDeclarationFile) {\n\t\t\treturn;\n\t\t}\n\t\tvisitBlockArrays(source);\n\t\tfor (const statement of source.statements) {\n\t\t\tif (\n\t\t\t\t(ts.isImportDeclaration(statement) ||\n\t\t\t\t\tts.isExportDeclaration(statement)) &&\n\t\t\t\tstatement.moduleSpecifier &&\n\t\t\t\truntimeImport(statement, checker)\n\t\t\t) {\n\t\t\t\tconst target = checker\n\t\t\t\t\t.getSymbolAtLocation(statement.moduleSpecifier)\n\t\t\t\t\t?.declarations?.find(ts.isSourceFile);\n\t\t\t\tif (target) {\n\t\t\t\t\tvisit(target);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\tfor (const file of program.getRootFileNames()) {\n\t\tconst source = program.getSourceFile(file);\n\t\tif (source) {\n\t\t\tvisit(source);\n\t\t}\n\t}\n\treturn program.getSourceFiles().filter((source) => visited.has(source));\n};\n\n/** The program's runtime sources the compiler lowers: its own TypeScript, not declaration files. */\nexport const plcSources = (program: ts.Program): readonly ts.SourceFile[] =>\n\truntimeSources(program).filter((source) => !source.isDeclarationFile);\n\n/** A named top-level function or class method. */\nexport type NamedRoutine = (ts.FunctionDeclaration | ts.MethodDeclaration) & {\n\treadonly name: ts.PropertyName;\n};\n\nconst isNamedRoutine = (node: ts.Node): node is NamedRoutine =>\n\t(ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node)) &&\n\tnode.name !== undefined;\n\n/** The named top-level functions and class methods of `sources`, by symbol. */\nexport const namedRoutines = (\n\tsources: readonly ts.SourceFile[],\n\tchecker: ts.TypeChecker,\n): ReadonlyMap<ts.Symbol, NamedRoutine> => {\n\tconst routines = new Map<ts.Symbol, NamedRoutine>();\n\tfor (const source of sources) {\n\t\tfor (const statement of source.statements) {\n\t\t\tconst candidates = ts.isClassDeclaration(statement)\n\t\t\t\t? statement.members.filter(ts.isMethodDeclaration)\n\t\t\t\t: [statement];\n\t\t\tfor (const candidate of candidates) {\n\t\t\t\tconst symbol =\n\t\t\t\t\tisNamedRoutine(candidate) && symbolAt(checker, candidate.name);\n\t\t\t\tif (symbol) {\n\t\t\t\t\troutines.set(symbol, candidate);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn routines;\n};\n",
14
+ "import type { MethodOwner, PlcFunction, Variable } from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport type { Positions } from \"./positions\";\nimport {\n\ttype Fail,\n\thasModifier,\n\ttype TypeEnvironment,\n\ttype TypeResolver,\n} from \"./types\";\n\n/** A routine whose signature is admitted and whose body is still to be lowered. */\ninterface PendingRoutine {\n\tnode: ts.FunctionDeclaration | ts.MethodDeclaration;\n\tbody: ts.Block;\n\tfn: PlcFunction;\n\t/** Each parameter's symbol and the variable it binds. */\n\tparameters: readonly (readonly [ts.Symbol, Variable])[];\n\tenvironment: TypeEnvironment;\n}\n\n/** Concrete helpers that generic calls may specialize, which bounds recursive specialization. */\nconst maxSpecializations = 256;\n\n/**\n * The routines a module contains: helpers and block methods by symbol, every\n * instance by id, and the worklist of bodies still to lower. Lowering a body can\n * instantiate more generic helpers, which join the worklist.\n */\nexport class RoutineTable {\n\tprivate readonly functionsBySymbol = new Map<ts.Symbol, PlcFunction>();\n\treadonly functions: ReadonlyMap<ts.Symbol, PlcFunction> =\n\t\tthis.functionsBySymbol;\n\tprivate readonly methodsBySymbol = new Map<ts.Symbol, PlcFunction>();\n\treadonly methods: ReadonlyMap<ts.Symbol, PlcFunction> = this.methodsBySymbol;\n\tprivate readonly declarations = new Map<ts.Symbol, ts.FunctionDeclaration>();\n\treadonly functionDeclarations: ReadonlyMap<\n\t\tts.Symbol,\n\t\tts.FunctionDeclaration\n\t> = this.declarations;\n\tprivate readonly instancesById = new Map<string, PlcFunction>();\n\treadonly instances: ReadonlyMap<string, PlcFunction> = this.instancesById;\n\tprivate readonly worklist: PendingRoutine[] = [];\n\treadonly pending: readonly PendingRoutine[] = this.worklist;\n\tprivate specializations = 0;\n\n\tconstructor(\n\t\tprivate readonly checker: ts.TypeChecker,\n\t\tprivate readonly resolver: TypeResolver,\n\t\tprivate readonly positions: Positions,\n\t\tprivate readonly fail: Fail,\n\t) {}\n\n\t/** Admits a helper declaration; one without type parameters has its single instance now. */\n\tdeclareFunction(symbol: ts.Symbol, node: ts.FunctionDeclaration): void {\n\t\tthis.declarations.set(symbol, node);\n\t\tif (!node.typeParameters?.length) {\n\t\t\tthis.functionsBySymbol.set(\n\t\t\t\tsymbol,\n\t\t\t\tthis.instantiate(node, [], node, new Map()),\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Admits a block method, which `owner` calls on its instances. */\n\tdeclareMethod(\n\t\tsymbol: ts.Symbol,\n\t\tnode: ts.MethodDeclaration,\n\t\towner: MethodOwner,\n\t): void {\n\t\tthis.methodsBySymbol.set(\n\t\t\tsymbol,\n\t\t\tthis.instance(node, [], node, new Map(), owner),\n\t\t);\n\t}\n\n\t/** Replaces a pending routine's instance with `fn`, its lowered body. */\n\tcomplete(routine: PendingRoutine, fn: PlcFunction): void {\n\t\tthis.instancesById.set(fn.id, fn);\n\t\tconst { node } = routine;\n\t\tif (\n\t\t\tts.isFunctionDeclaration(node) &&\n\t\t\tnode.name &&\n\t\t\t!node.typeParameters?.length\n\t\t) {\n\t\t\tthis.functionsBySymbol.set(this.resolver.symbol(node.name), fn);\n\t\t}\n\t}\n\n\tinstantiate(\n\t\tnode: ts.FunctionDeclaration | ts.MethodDeclaration,\n\t\targuments_: readonly ts.TypeNode[],\n\t\tcall: ts.Node,\n\t\touter: TypeEnvironment,\n\t): PlcFunction {\n\t\treturn this.instance(node, arguments_, call, outer, null);\n\t}\n\n\tprivate instance(\n\t\tnode: ts.FunctionDeclaration | ts.MethodDeclaration,\n\t\targuments_: readonly ts.TypeNode[],\n\t\tcall: ts.Node,\n\t\touter: TypeEnvironment,\n\t\towner: MethodOwner | null,\n\t): PlcFunction {\n\t\tif (!node.name || !ts.isIdentifier(node.name)) {\n\t\t\tthis.fail(node, \"PLC1001\", \"PLC routines need identifier names.\");\n\t\t}\n\t\tconst routineName = node.name.text;\n\t\tconst { environment, suffix } = this.resolver.bindings(\n\t\t\tnode.typeParameters,\n\t\t\targuments_,\n\t\t\touter,\n\t\t\tcall,\n\t\t);\n\t\tconst id = `${this.resolver.id(node, routineName)}${suffix ? `<${suffix}>` : \"\"}`;\n\t\tconst existing = this.instancesById.get(id);\n\t\tif (existing) {\n\t\t\treturn existing;\n\t\t}\n\t\tif (suffix && this.specializations >= maxSpecializations) {\n\t\t\tthis.fail(\n\t\t\t\tcall,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t`Generic specialization exceeds ${maxSpecializations} concrete helpers; recursive specialization is unsupported.`,\n\t\t\t);\n\t\t}\n\t\tconst body = node.body;\n\t\tif (!body) {\n\t\t\tthrow new Error(`Routine ${id} has no implementation to lower.`);\n\t\t}\n\t\tconst parameters = node.parameters.map((parameter) => {\n\t\t\tif (\n\t\t\t\t!ts.isIdentifier(parameter.name) ||\n\t\t\t\t!parameter.type ||\n\t\t\t\tparameter.initializer ||\n\t\t\t\tparameter.questionToken ||\n\t\t\t\tparameter.dotDotDotToken\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tparameter,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"PLC parameters need names and explicit types; optional/rest/default parameters are unsupported.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst type = this.resolver.resolve(parameter.type, environment);\n\t\t\tconst block = this.resolver.types.get(type.type)?.kind === \"block\";\n\t\t\tif (type.mode !== \"inOut\" && !block && !this.resolver.isValue(type)) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tparameter,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Parameters require value types or InOut borrows.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (type.io) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tparameter,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Parameters cannot use logical I/O wrappers.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst mode = this.resolver.parameterMode(type);\n\t\t\tconst variable: Variable = {\n\t\t\t\tid: `${this.resolver.id(parameter, parameter.name.text)}@${id}`,\n\t\t\t\tname: parameter.name.text,\n\t\t\t\ttype: type.type,\n\t\t\t\tstorage: \"parameter\",\n\t\t\t\tmutable: mode === \"inOut\",\n\t\t\t\t...(mode && { mode }),\n\t\t\t\tretention: \"none\",\n\t\t\t\tspan: this.positions.node(parameter),\n\t\t\t};\n\t\t\treturn [this.resolver.symbol(parameter.name), variable] as const;\n\t\t});\n\t\tconst result = this.result(node, environment);\n\t\tconst fn: PlcFunction = {\n\t\t\tid,\n\t\t\tname: `${routineName}${suffix ? `_${suffix}` : \"\"}`,\n\t\t\tparameters: parameters.map(([, variable]) => variable),\n\t\t\tlocals: [],\n\t\t\tbody: [],\n\t\t\tspan: this.positions.node(node),\n\t\t\t...(result && { result }),\n\t\t\t...(owner && { owner }),\n\t\t};\n\t\tthis.instancesById.set(id, fn);\n\t\tif (suffix) {\n\t\t\tthis.specializations++;\n\t\t}\n\t\tthis.worklist.push({ node, body, fn, parameters, environment });\n\t\treturn fn;\n\t}\n\n\t/** The type a routine returns; undefined when it returns nothing. */\n\tprivate result(\n\t\tnode: ts.FunctionDeclaration | ts.MethodDeclaration,\n\t\tenvironment: TypeEnvironment,\n\t): string | undefined {\n\t\tif (!node.type) {\n\t\t\tconst signature = this.checker.getSignatureFromDeclaration(node);\n\t\t\tif (\n\t\t\t\t!signature ||\n\t\t\t\t!(\n\t\t\t\t\tthis.checker.getReturnTypeOfSignature(signature).flags &\n\t\t\t\t\tts.TypeFlags.Void\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthis.fail(node, \"PLC2001\", \"Annotate helper results explicitly.\");\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t\tif (node.type.kind === ts.SyntaxKind.VoidKeyword) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst type = this.resolver.resolve(node.type, environment);\n\t\tif (!this.resolver.isValue(type)) {\n\t\t\tthis.fail(node.type, \"PLC2001\", \"Helper results require value types.\");\n\t\t}\n\t\tif (type.io) {\n\t\t\tthis.fail(\n\t\t\t\tnode.type,\n\t\t\t\t\"PLC4002\",\n\t\t\t\t\"Helper results cannot use I/O wrappers.\",\n\t\t\t);\n\t\t}\n\t\treturn type.type;\n\t}\n}\n\nexport const methodAccess = (\n\tmethod: ts.MethodDeclaration,\n): MethodOwner[\"access\"] => {\n\tif (hasModifier(method, ts.SyntaxKind.PrivateKeyword)) {\n\t\treturn \"private\";\n\t}\n\tif (hasModifier(method, ts.SyntaxKind.ProtectedKeyword)) {\n\t\treturn \"protected\";\n\t}\n\treturn \"public\";\n};\n",
15
+ "import {\n\taggregate,\n\ttype Constant,\n\ttype Expression,\n\ttype IntegerInterval,\n\tintegerRange,\n\tloopBounds,\n\tmaxLoopIterations,\n\ttype PlcFunction,\n\ttype PlcType,\n\ttype Statement,\n\ttype Variable,\n} from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport type { AnalysisContext, ExpressionLowering } from \"./expressions\";\nimport type { Positions } from \"./positions\";\nimport { telemetryStatement } from \"./telemetry\";\nimport { type Fail, inferredStorageType, type TypeResolver } from \"./types\";\n\ntype IterationForm = \"elements\" | \"entries\" | \"recordValues\" | \"recordEntries\";\n\n/** The counter a for header initializes, and where the header stands. */\ninterface LoopHeader {\n\theader: ts.ForInitializer;\n\tcounter: Variable;\n\tinitializer: ts.Expression;\n\texisting: boolean;\n}\n\n/**\n * A case's statements, out of the braces that scope its declarations, as control-flow lowering\n * writes every case: they end where the braces do, and blocks lower without a scope of their own.\n */\nconst unbraced = (\n\tstatements: readonly ts.Statement[],\n): readonly ts.Statement[] => {\n\tconst [only] = statements;\n\treturn statements.length === 1 && only && ts.isBlock(only)\n\t\t? unbraced(only.statements)\n\t\t: statements;\n};\n\nconst caseEndMessage = (last: ts.Statement | undefined): string => {\n\tif (last && ts.isThrowStatement(last)) {\n\t\treturn \"A switch case cannot end in throw; end it with break or return.\";\n\t}\n\tif (last && ts.isContinueStatement(last)) {\n\t\treturn \"A switch case cannot end in continue; end it with break or return.\";\n\t}\n\treturn \"The last switch case must end with break or return.\";\n};\n\n/**\n * Lowers one routine's statements. Expressions, and the scope facts that\n * declarations, branches and loops establish, go through its ExpressionLowering.\n */\nexport class StatementLowering {\n\tprivate readonly resolver: TypeResolver;\n\tprivate readonly positions: Positions;\n\tprivate readonly fail: Fail;\n\tprivate readonly breakTargets: (\"loop\" | \"switch\")[] = [];\n\tprivate readonly locals: Variable[] = [];\n\n\tconstructor(\n\t\tcontext: AnalysisContext,\n\t\tprivate readonly expressions: ExpressionLowering,\n\t\tprivate readonly routine: PlcFunction,\n\t) {\n\t\tthis.resolver = context.resolver;\n\t\tthis.positions = context.positions;\n\t\tthis.fail = context.fail;\n\t}\n\n\t/** Lowers a routine's statements, collecting the locals they declare. */\n\tlowerRoutine(body: ts.Block): { locals: Variable[]; body: Statement[] } {\n\t\treturn { locals: this.locals, body: this.statements(body.statements) };\n\t}\n\n\tprivate statements(nodes: readonly ts.Statement[]): Statement[] {\n\t\treturn nodes.flatMap((node) => this.statement(node));\n\t}\n\n\tprivate body(node: ts.Statement): Statement[] {\n\t\treturn ts.isBlock(node)\n\t\t\t? this.statements(node.statements)\n\t\t\t: this.statement(node);\n\t}\n\n\tprivate statement(node: ts.Statement): Statement[] {\n\t\tconst origin = { span: this.positions.node(node) };\n\t\tif (ts.isBlock(node)) {\n\t\t\treturn this.statements(node.statements);\n\t\t}\n\t\tif (ts.isEmptyStatement(node)) {\n\t\t\treturn [];\n\t\t}\n\t\tif (ts.isIfStatement(node)) {\n\t\t\tconst condition = this.expressions.expression(node.expression, \"BOOL\");\n\t\t\tconst branch = (body: ts.Statement | undefined, truth: boolean) =>\n\t\t\t\tthis.expressions.narrowed(condition, truth, () =>\n\t\t\t\t\tbody ? this.body(body) : [],\n\t\t\t\t);\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\t...origin,\n\t\t\t\t\tkind: \"if\",\n\t\t\t\t\tcondition,\n\t\t\t\t\t// biome-ignore lint/suspicious/noThenProperty: This is the IR branch field, not a Promise method.\n\t\t\t\t\tthen: branch(node.thenStatement, true),\n\t\t\t\t\telse: branch(node.elseStatement, false),\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t\tif (ts.isReturnStatement(node)) {\n\t\t\tconst result = this.routine.result;\n\t\t\tif (!result && node.expression) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Void helpers and program entries cannot return a value.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (result && !node.expression) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Typed helpers must return their declared PLC result.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst value =\n\t\t\t\tnode.expression && result\n\t\t\t\t\t? this.expressions.implicitCopy(\n\t\t\t\t\t\t\tthis.expressions.expression(node.expression, result),\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined;\n\t\t\treturn [{ ...origin, kind: \"return\", ...(value && { value }) }];\n\t\t}\n\t\tif (ts.isBreakStatement(node) || ts.isContinueStatement(node)) {\n\t\t\t// Control-flow lowering has turned every jump Structured Text cannot make into flags; what\n\t\t\t// is left here is a jump TypeScript rejects too.\n\t\t\tif (\n\t\t\t\tnode.label ||\n\t\t\t\t!this.breakTargets.includes(\"loop\") ||\n\t\t\t\t(ts.isBreakStatement(node) && this.breakTargets.at(-1) === \"switch\")\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC1001\",\n\t\t\t\t\t\"break and continue must leave an enclosing loop.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn [\n\t\t\t\t{ ...origin, kind: ts.isBreakStatement(node) ? \"break\" : \"continue\" },\n\t\t\t];\n\t\t}\n\t\tif (ts.isVariableStatement(node)) {\n\t\t\treturn this.localDeclarations(node);\n\t\t}\n\t\tif (ts.isForStatement(node)) {\n\t\t\treturn this.loop(node);\n\t\t}\n\t\tif (ts.isForOfStatement(node)) {\n\t\t\treturn this.forOf(node);\n\t\t}\n\t\tif (ts.isSwitchStatement(node)) {\n\t\t\treturn this.switchStatement(node);\n\t\t}\n\t\tif (ts.isExpressionStatement(node)) {\n\t\t\tconst expression = node.expression;\n\t\t\tif (ts.isCallExpression(expression)) {\n\t\t\t\tconst telemetry = telemetryStatement(this.expressions, expression);\n\t\t\t\tif (telemetry) {\n\t\t\t\t\treturn [telemetry];\n\t\t\t\t}\n\t\t\t\tconst update = this.expressions.update(expression);\n\t\t\t\tif (update) {\n\t\t\t\t\treturn [update];\n\t\t\t\t}\n\t\t\t\tconst call = this.expressions.call(expression);\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\t...origin,\n\t\t\t\t\t\tkind: \"invoke\",\n\t\t\t\t\t\tfunction: call.fn.id,\n\t\t\t\t\t\targuments: call.arguments,\n\t\t\t\t\t\t...(call.instance && { instance: call.instance }),\n\t\t\t\t\t\t...(call.index && { index: call.index }),\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\t\t\tif (ts.isBinaryExpression(expression)) {\n\t\t\t\tconst variable = this.expressions.target(expression.left);\n\t\t\t\tif (expression.operatorToken.kind !== ts.SyntaxKind.EqualsToken) {\n\t\t\t\t\tthis.fail(\n\t\t\t\t\t\texpression,\n\t\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\t\"Use explicit assignment and arithmetic policies.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst value = this.expressions.expression(\n\t\t\t\t\texpression.right,\n\t\t\t\t\tvariable.type,\n\t\t\t\t);\n\t\t\t\tthis.expressions.recordCopySource(value);\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\t...origin,\n\t\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\t\tdestination: variable.place,\n\t\t\t\t\t\tvalue: this.expressions.implicitCopy(value),\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\t\t}\n\t\tthis.fail(\n\t\t\tnode,\n\t\t\t\"PLC1001\",\n\t\t\t`${ts.SyntaxKind[node.kind]} is not supported in PLC scan code.`,\n\t\t);\n\t}\n\n\t/** A routine-local variable, declared where `declaration` stands. */\n\tprivate local(\n\t\tdeclaration: ts.Node,\n\t\tname: string,\n\t\ttype: string,\n\t\t{ mutable }: { mutable: boolean },\n\t): Variable {\n\t\tconst variable: Variable = {\n\t\t\tid: this.expressions.storageId(declaration, name),\n\t\t\tname,\n\t\t\ttype,\n\t\t\tstorage: \"local\",\n\t\t\tmutable,\n\t\t\tretention: \"none\",\n\t\t\tspan: this.positions.node(declaration),\n\t\t};\n\t\tthis.locals.push(variable);\n\t\treturn variable;\n\t}\n\n\t/** Grouped labels share the body of the clause that ends them; a default label's body is the fallback. */\n\tprivate switchStatement(node: ts.SwitchStatement): Statement[] {\n\t\tconst origin = { span: this.positions.node(node) };\n\t\tthis.breakTargets.push(\"switch\");\n\t\ttry {\n\t\t\tconst value = this.expressions.expression(node.expression);\n\t\t\tconst { clauses } = node.caseBlock;\n\t\t\tconst cases: { values: Constant[]; body: Statement[] }[] = [];\n\t\t\tconst labels: Constant[] = [];\n\t\t\tconst bodies = clauses.map((clause) => {\n\t\t\t\tif (!ts.isDefaultClause(clause)) {\n\t\t\t\t\tlabels.push(this.caseValue(clause, value.type));\n\t\t\t\t}\n\t\t\t\tconst statements = unbraced(clause.statements);\n\t\t\t\tconst body = statements.length\n\t\t\t\t\t? this.caseBody(clause, statements)\n\t\t\t\t\t: undefined;\n\t\t\t\tif (body && labels.length) {\n\t\t\t\t\tcases.push({ values: labels.splice(0), body });\n\t\t\t\t}\n\t\t\t\treturn body;\n\t\t\t});\n\t\t\tif (labels.length) {\n\t\t\t\tcases.push({ values: labels, body: [] });\n\t\t\t}\n\t\t\t// The default label shares the body of the clause that ends its group.\n\t\t\tconst fallbackIndex = clauses.findIndex(ts.isDefaultClause);\n\t\t\tconst fallback =\n\t\t\t\tfallbackIndex < 0\n\t\t\t\t\t? []\n\t\t\t\t\t: (bodies.slice(fallbackIndex).find((body) => body !== undefined) ??\n\t\t\t\t\t\t[]);\n\t\t\treturn [{ ...origin, kind: \"switch\", value, cases, fallback }];\n\t\t} finally {\n\t\t\tthis.breakTargets.pop();\n\t\t}\n\t}\n\n\tprivate caseValue(clause: ts.CaseClause, type: string): Constant {\n\t\tconst constant = this.expressions.constant(\n\t\t\tthis.expressions.expression(clause.expression, type),\n\t\t);\n\t\tif (!constant) {\n\t\t\tthis.fail(\n\t\t\t\tclause,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Case values must be compile-time constants.\",\n\t\t\t);\n\t\t}\n\t\treturn constant;\n\t}\n\n\t/** A case's statements without the break that ends it. */\n\tprivate caseBody(\n\t\tclause: ts.CaseOrDefaultClause,\n\t\tstatements: readonly ts.Statement[],\n\t): Statement[] {\n\t\tconst last = statements.at(-1);\n\t\tif (last && ts.isBreakStatement(last) && !last.label) {\n\t\t\treturn this.statements(statements.slice(0, -1));\n\t\t}\n\t\tif (last && ts.isReturnStatement(last)) {\n\t\t\treturn this.statements(statements);\n\t\t}\n\t\t// Control-flow lowering gives a case that runs on into the next its own break, so only the\n\t\t// last case can still run off the end.\n\t\tthis.fail(clause, \"PLC1001\", caseEndMessage(last));\n\t}\n\n\tprivate localDeclarations(node: ts.VariableStatement): Statement[] {\n\t\tconst origin = { span: this.positions.node(node) };\n\t\tif (\n\t\t\t!(node.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const))\n\t\t) {\n\t\t\tthis.fail(node, \"PLC1001\", \"Use let or const for invocation locals.\");\n\t\t}\n\t\tconst immutable = Boolean(node.declarationList.flags & ts.NodeFlags.Const);\n\t\treturn node.declarationList.declarations.flatMap((declaration) => {\n\t\t\tif (!ts.isIdentifier(declaration.name)) {\n\t\t\t\tthis.fail(declaration, \"PLC1001\", \"Destructuring is not supported.\");\n\t\t\t}\n\t\t\tif (!declaration.initializer) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t\"PLC3001\",\n\t\t\t\t\t\"Initialize invocation-local PLC variables explicitly.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst annotation = declaration.type\n\t\t\t\t? this.expressions.type(declaration.type)\n\t\t\t\t: undefined;\n\t\t\tif (annotation && !this.resolver.isValue(annotation)) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Invocation locals require value types, not instances or borrow schemas.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (annotation?.io) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t\"PLC4002\",\n\t\t\t\t\t\"Logical I/O cannot be invocation-local.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (\n\t\t\t\t!annotation &&\n\t\t\t\t!immutable &&\n\t\t\t\tinferredStorageType(declaration.initializer) === undefined\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Annotate mutable numeric storage explicitly.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst initial = this.expressions.expression(\n\t\t\t\tdeclaration.initializer,\n\t\t\t\tannotation?.type,\n\t\t\t);\n\t\t\tif (\n\t\t\t\timmutable &&\n\t\t\t\tinitial.kind === \"load\" &&\n\t\t\t\taggregate(this.resolver.types.get(initial.type))\n\t\t\t) {\n\t\t\t\tfor (const segment of initial.place.path) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tsegment.kind === \"index\" &&\n\t\t\t\t\t\t!this.expressions.unchanging(segment.value)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.fail(\n\t\t\t\t\t\t\tdeclaration,\n\t\t\t\t\t\t\t\"PLC3003\",\n\t\t\t\t\t\t\t\"An alias index must keep its value while the alias is in scope; use copy(value) for a snapshot.\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.expressions.alias(\n\t\t\t\t\tthis.resolver.symbol(declaration.name),\n\t\t\t\t\tinitial.place,\n\t\t\t\t);\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tthis.expressions.recordCopySource(initial);\n\t\t\tconst value = this.expressions.implicitCopy(initial);\n\t\t\tconst variable = this.local(\n\t\t\t\tdeclaration,\n\t\t\t\tdeclaration.name.text,\n\t\t\t\tvalue.type,\n\t\t\t\t{ mutable: !immutable },\n\t\t\t);\n\t\t\tthis.expressions.bind(this.resolver.symbol(declaration.name), variable);\n\t\t\tif (!variable.mutable) {\n\t\t\t\tthis.expressions.holdRange(variable.id, value);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...origin,\n\t\t\t\tkind: \"assign\",\n\t\t\t\tdestination: { root: variable.id, path: [] },\n\t\t\t\tvalue,\n\t\t\t};\n\t\t});\n\t}\n\n\tprivate loop(node: ts.ForStatement): Statement[] {\n\t\tconst { header, counter, initializer, existing } = this.loopHeader(node);\n\t\tconst type = counter.type;\n\t\tconst plcType = this.resolver.types.get(type);\n\t\tif (plcType?.kind !== \"integer\") {\n\t\t\tthis.fail(header, \"PLC2001\", \"Loop counters require integer types.\");\n\t\t}\n\t\tconst startExpression = this.expressions.expression(initializer, type);\n\t\tconst start = this.expressions.constant(startExpression);\n\t\tconst isCounter = (expression: ts.Expression): boolean => {\n\t\t\tconst place = this.expressions.place(expression);\n\t\t\treturn place.root === counter.id && place.path.length === 0;\n\t\t};\n\t\tconst condition = node.condition;\n\t\tif (\n\t\t\t!condition ||\n\t\t\t!ts.isBinaryExpression(condition) ||\n\t\t\t!isCounter(condition.left)\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1001\",\n\t\t\t\t\"Loop condition must compare its counter to a bounded integer.\",\n\t\t\t);\n\t\t}\n\t\tconst boundExpression = this.expressions.expression(condition.right, type);\n\t\tconst bound = this.expressions.constant(boundExpression);\n\t\tconst step = this.loopStep(node, type, isCounter);\n\t\tconst operator = condition.operatorToken.kind;\n\t\tconst ascending = step > 0n;\n\t\tconst comparisons = ascending\n\t\t\t? [ts.SyntaxKind.LessThanToken, ts.SyntaxKind.LessThanEqualsToken]\n\t\t\t: [ts.SyntaxKind.GreaterThanToken, ts.SyntaxKind.GreaterThanEqualsToken];\n\t\tif (!comparisons.includes(operator)) {\n\t\t\tthis.fail(\n\t\t\t\tcondition,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Loop direction and comparison must agree.\",\n\t\t\t);\n\t\t}\n\t\tconst exclusive =\n\t\t\toperator === ts.SyntaxKind.LessThanToken ||\n\t\t\toperator === ts.SyntaxKind.GreaterThanToken;\n\t\tif (start?.kind !== \"integer\" || bound?.kind !== \"integer\") {\n\t\t\tconst startRange = this.expressions.interval(startExpression);\n\t\t\tconst limitRange = this.expressions.interval(boundExpression);\n\t\t\tif (!startRange || !limitRange) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Loop bounds require finite integer ranges.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst proof = loopBounds(startRange, limitRange, step, exclusive);\n\t\t\tthis.checkIterations(node, proof.count);\n\t\t\tif (existing && proof.count > 0n) {\n\t\t\t\tthis.checkFinalIncrement(node, plcType, proof.terminal);\n\t\t\t}\n\t\t\treturn this.inLoop([counter.id], counter.id, proof.range, () => [\n\t\t\t\t{\n\t\t\t\t\tspan: this.positions.node(node),\n\t\t\t\t\tkind: \"for\",\n\t\t\t\t\tcounter: counter.id,\n\t\t\t\t\t...(existing && { counterScope: \"existing\" as const }),\n\t\t\t\t\tstart: startExpression,\n\t\t\t\t\tlimit: boundExpression,\n\t\t\t\t\tstep: String(step),\n\t\t\t\t\t...(exclusive && { exclusive: true as const }),\n\t\t\t\t\tmaxIterations: Number(proof.count),\n\t\t\t\t\tbody: this.body(node.statement),\n\t\t\t\t},\n\t\t\t]);\n\t\t}\n\t\tconst first = BigInt(start.value);\n\t\tconst limit = BigInt(bound.value);\n\t\tconst { last, count, range, terminal } = loopBounds(\n\t\t\t[first, first],\n\t\t\t[limit, limit],\n\t\t\tstep,\n\t\t\texclusive,\n\t\t);\n\t\tthis.checkIterations(node, count);\n\t\tif (existing) {\n\t\t\tthis.checkFinalIncrement(node, plcType, terminal);\n\t\t}\n\t\tconst body = this.inLoop([counter.id], counter.id, range, () =>\n\t\t\tthis.body(node.statement),\n\t\t);\n\t\tconst startConstant: Expression = {\n\t\t\tkind: \"constant\",\n\t\t\ttype,\n\t\t\tvalue: start,\n\t\t\tspan: this.positions.node(initializer),\n\t\t};\n\t\tif (!count) {\n\t\t\t// The body never runs, but an existing counter still takes its start value.\n\t\t\treturn existing\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tkind: \"assign\",\n\t\t\t\t\t\t\tdestination: { root: counter.id, path: [] },\n\t\t\t\t\t\t\tvalue: startConstant,\n\t\t\t\t\t\t\tspan: this.positions.node(header),\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: [];\n\t\t}\n\t\treturn [\n\t\t\t{\n\t\t\t\tspan: this.positions.node(node),\n\t\t\t\tkind: \"for\",\n\t\t\t\tcounter: counter.id,\n\t\t\t\t...(existing && { counterScope: \"existing\" as const }),\n\t\t\t\tstart: startConstant,\n\t\t\t\tlimit: {\n\t\t\t\t\tkind: \"constant\",\n\t\t\t\t\ttype,\n\t\t\t\t\tvalue: { kind: \"integer\", value: String(last) },\n\t\t\t\t\tspan: this.positions.node(condition.right),\n\t\t\t\t},\n\t\t\t\tstep: String(step),\n\t\t\t\tmaxIterations: Number(count),\n\t\t\t\tbody,\n\t\t\t},\n\t\t];\n\t}\n\n\t/** A new `let` counter, or an assigned local, module variable or private block field. */\n\tprivate loopHeader(node: ts.ForStatement): LoopHeader {\n\t\tconst header = node.initializer;\n\t\tif (header && ts.isVariableDeclarationList(header)) {\n\t\t\tconst [declaration, ...others] = header.declarations;\n\t\t\tif (!(header.flags & ts.NodeFlags.Let) || !declaration || others.length) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"PLC1001\",\n\t\t\t\t\t\"A bounded for loop requires one let counter or an existing counter assignment.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!ts.isIdentifier(declaration.name) || !declaration.initializer) {\n\t\t\t\tthis.fail(node, \"PLC2001\", \"Initialize the integer loop counter.\");\n\t\t\t}\n\t\t\tconst annotation = declaration.type\n\t\t\t\t? this.expressions.type(declaration.type)\n\t\t\t\t: { type: \"DINT\" };\n\t\t\tif (annotation.io) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t\"PLC4002\",\n\t\t\t\t\t\"Loop counters cannot use I/O wrappers.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst counter = this.local(\n\t\t\t\tdeclaration,\n\t\t\t\tdeclaration.name.text,\n\t\t\t\tannotation.type,\n\t\t\t\t{ mutable: true },\n\t\t\t);\n\t\t\tthis.expressions.bind(this.resolver.symbol(declaration.name), counter);\n\t\t\treturn {\n\t\t\t\theader,\n\t\t\t\tcounter,\n\t\t\t\tinitializer: declaration.initializer,\n\t\t\t\texisting: false,\n\t\t\t};\n\t\t}\n\t\tif (\n\t\t\theader &&\n\t\t\tts.isBinaryExpression(header) &&\n\t\t\theader.operatorToken.kind === ts.SyntaxKind.EqualsToken\n\t\t) {\n\t\t\tconst target = this.expressions.target(header.left);\n\t\t\tconst counter = this.expressions.byId().get(target.place.root);\n\t\t\tif (\n\t\t\t\t!counter ||\n\t\t\t\ttarget.place.path.length ||\n\t\t\t\t![\"local\", \"module\", \"field\"].includes(counter.storage)\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\theader,\n\t\t\t\t\t\"PLC1001\",\n\t\t\t\t\t\"An existing loop counter must be a local, module variable or private block field.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn { header, counter, initializer: header.right, existing: true };\n\t\t}\n\t\tthis.fail(\n\t\t\tnode,\n\t\t\t\"PLC1001\",\n\t\t\t\"Initialize one let counter or assign an existing counter in the for header.\",\n\t\t);\n\t}\n\n\t/** The header's constant step: `i++`, `i--`, `i += step` or `i -= step`. */\n\tprivate loopStep(\n\t\tnode: ts.ForStatement,\n\t\ttype: string,\n\t\tisCounter: (expression: ts.Expression) => boolean,\n\t): bigint {\n\t\tconst increment = node.incrementor;\n\t\tif (\n\t\t\tincrement &&\n\t\t\t(ts.isPostfixUnaryExpression(increment) ||\n\t\t\t\tts.isPrefixUnaryExpression(increment)) &&\n\t\t\tisCounter(increment.operand) &&\n\t\t\t[ts.SyntaxKind.PlusPlusToken, ts.SyntaxKind.MinusMinusToken].includes(\n\t\t\t\tincrement.operator,\n\t\t\t)\n\t\t) {\n\t\t\treturn increment.operator === ts.SyntaxKind.PlusPlusToken ? 1n : -1n;\n\t\t}\n\t\tif (\n\t\t\tincrement &&\n\t\t\tts.isBinaryExpression(increment) &&\n\t\t\tisCounter(increment.left) &&\n\t\t\t[ts.SyntaxKind.PlusEqualsToken, ts.SyntaxKind.MinusEqualsToken].includes(\n\t\t\t\tincrement.operatorToken.kind,\n\t\t\t)\n\t\t) {\n\t\t\tconst amount = this.expressions.constant(\n\t\t\t\tthis.expressions.expression(increment.right, type),\n\t\t\t);\n\t\t\tif (amount?.kind !== \"integer\" || BigInt(amount.value) <= 0n) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tincrement,\n\t\t\t\t\t\"PLC2001\",\n\t\t\t\t\t\"Loop step must be a positive constant integer.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst magnitude = BigInt(amount.value);\n\t\t\treturn increment.operatorToken.kind === ts.SyntaxKind.PlusEqualsToken\n\t\t\t\t? magnitude\n\t\t\t\t: -magnitude;\n\t\t}\n\t\tthis.fail(\n\t\t\tnode,\n\t\t\t\"PLC1001\",\n\t\t\t\"Use i++, i--, i += step or i -= step in the for header.\",\n\t\t);\n\t}\n\n\tprivate checkIterations(node: ts.ForStatement, count: bigint): void {\n\t\tif (count > maxLoopIterations) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t`A scan loop cannot exceed ${maxLoopIterations.toLocaleString(\"en-US\")} iterations.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/** An existing counter keeps its value after the loop, so its final increment must fit. */\n\tprivate checkFinalIncrement(\n\t\tnode: ts.ForStatement,\n\t\ttype: Extract<PlcType, { kind: \"integer\" }>,\n\t\tterminal: bigint,\n\t): void {\n\t\tconst [minimum, maximum] = integerRange(type);\n\t\tif (terminal < minimum || terminal > maximum) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"The existing loop counter would overflow on its final increment.\",\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * `for (const element of array)` is a bounded FOR over the array's declared bounds whose\n\t * element binding aliases `array[counter]`. `array.entries()` also binds the counter. An\n\t * enum-keyed Record iterates with `Object.values(record)`, or SDK `entries(record)` for its key.\n\t */\n\tprivate forOf(node: ts.ForOfStatement): Statement[] {\n\t\tconst list = node.initializer;\n\t\tconst [declaration, ...others] = ts.isVariableDeclarationList(list)\n\t\t\t? list.declarations\n\t\t\t: [];\n\t\tif (\n\t\t\tnode.awaitModifier ||\n\t\t\t!ts.isVariableDeclarationList(list) ||\n\t\t\t!(list.flags & ts.NodeFlags.Const) ||\n\t\t\t!declaration ||\n\t\t\tothers.length\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tnode,\n\t\t\t\t\"PLC1001\",\n\t\t\t\t\"for…of binds one const element of a PLC array.\",\n\t\t\t);\n\t\t}\n\t\tconst { form, iterated } = this.iteration(node.expression);\n\t\tconst binding = declaration.name;\n\t\tconst keyed = form === \"entries\" || form === \"recordEntries\";\n\t\tconst names = ts.isArrayBindingPattern(binding)\n\t\t\t? binding.elements.map((element) =>\n\t\t\t\t\tts.isBindingElement(element) &&\n\t\t\t\t\t!element.dotDotDotToken &&\n\t\t\t\t\t!element.initializer &&\n\t\t\t\t\tts.isIdentifier(element.name)\n\t\t\t\t\t\t? element.name\n\t\t\t\t\t\t: undefined,\n\t\t\t\t)\n\t\t\t: [undefined, ts.isIdentifier(binding) ? binding : undefined];\n\t\tconst [indexName, elementName] = names;\n\t\tif (names.length !== 2 || !elementName || Boolean(indexName) !== keyed) {\n\t\t\tthis.fail(\n\t\t\t\tbinding,\n\t\t\t\t\"PLC1001\",\n\t\t\t\t\"Bind one element, or destructure [index, element] from array.entries() or entries(record).\",\n\t\t\t);\n\t\t}\n\t\tconst place = this.expressions.place(iterated);\n\t\tconst iteratedType = this.expressions.placeType(place).type;\n\t\tconst array =\n\t\t\titeratedType === undefined\n\t\t\t\t? undefined\n\t\t\t\t: this.resolver.types.get(iteratedType);\n\t\tif (\n\t\t\tarray?.kind !== \"array\" ||\n\t\t\tBoolean(array.index) !== form.startsWith(\"record\")\n\t\t) {\n\t\t\tthis.fail(\n\t\t\t\tnode.expression,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"for…of iterates a FixedArray, array.entries(), or an enum-keyed Record through Object.values(record) or entries(record).\",\n\t\t\t);\n\t\t}\n\t\tfor (const segment of place.path) {\n\t\t\tif (\n\t\t\t\tsegment.kind === \"index\" &&\n\t\t\t\t!this.expressions.unchanging(segment.value)\n\t\t\t) {\n\t\t\t\tthis.fail(\n\t\t\t\t\tnode.expression,\n\t\t\t\t\t\"PLC3003\",\n\t\t\t\t\t\"An iterated array's index must keep its value.\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst origin = { span: this.positions.node(node) };\n\t\tconst constant = (type: string, value: string): Expression => ({\n\t\t\t...origin,\n\t\t\tkind: \"constant\",\n\t\t\ttype,\n\t\t\tvalue: { kind: \"integer\", value },\n\t\t});\n\t\tconst counter = this.local(\n\t\t\tnode,\n\t\t\tform === \"entries\" && indexName ? indexName.text : \"index\",\n\t\t\t\"DINT\",\n\t\t\t{ mutable: true },\n\t\t);\n\t\tconst index: Expression = {\n\t\t\t...origin,\n\t\t\tkind: \"load\",\n\t\t\ttype: \"DINT\",\n\t\t\tplace: { root: counter.id, path: [] },\n\t\t};\n\t\tconst before: Statement[] = [];\n\t\tconst prefix: Statement[] = [];\n\t\tconst counters = [counter.id];\n\t\tconst enumeration = array.index\n\t\t\t? this.resolver.types.get(array.index)\n\t\t\t: undefined;\n\t\tif (indexName && enumeration?.kind === \"enum\") {\n\t\t\tconst key = this.local(indexName, indexName.text, enumeration.id, {\n\t\t\t\tmutable: true,\n\t\t\t});\n\t\t\tconst assign = (value: string): Statement => ({\n\t\t\t\t...origin,\n\t\t\t\tkind: \"assign\",\n\t\t\t\tdestination: { root: key.id, path: [] },\n\t\t\t\tvalue: constant(key.type, value),\n\t\t\t});\n\t\t\tbefore.push(assign(String(array.lowerBound)));\n\t\t\tprefix.push({\n\t\t\t\t...origin,\n\t\t\t\tkind: \"switch\",\n\t\t\t\tvalue: index,\n\t\t\t\tcases: enumeration.members.map((member) => ({\n\t\t\t\t\tvalues: [{ kind: \"integer\", value: member.value }],\n\t\t\t\t\tbody: [assign(member.value)],\n\t\t\t\t})),\n\t\t\t\tfallback: [],\n\t\t\t});\n\t\t\tcounters.push(key.id);\n\t\t\tthis.expressions.bind(this.resolver.symbol(indexName), key);\n\t\t} else if (indexName) {\n\t\t\tthis.expressions.bind(this.resolver.symbol(indexName), counter);\n\t\t}\n\t\tthis.expressions.alias(this.resolver.symbol(elementName), {\n\t\t\troot: place.root,\n\t\t\tpath: [...place.path, { kind: \"index\", value: index }],\n\t\t});\n\n\t\tconst upper = array.lowerBound + array.length - 1;\n\t\treturn this.inLoop(\n\t\t\tcounters,\n\t\t\tcounter.id,\n\t\t\t[BigInt(array.lowerBound), BigInt(upper)],\n\t\t\t() => [\n\t\t\t\t...before,\n\t\t\t\t{\n\t\t\t\t\t...origin,\n\t\t\t\t\tkind: \"for\",\n\t\t\t\t\tcounter: counter.id,\n\t\t\t\t\tstart: constant(\"DINT\", String(array.lowerBound)),\n\t\t\t\t\tlimit: constant(\"DINT\", String(upper)),\n\t\t\t\t\tstep: \"1\",\n\t\t\t\t\tmaxIterations: array.length,\n\t\t\t\t\tbody: [...prefix, ...this.body(node.statement)],\n\t\t\t\t},\n\t\t\t],\n\t\t);\n\t}\n\n\t/** What a for…of iterates: an array's elements or `entries()`, or a record's `Object.values` or SDK `entries`. */\n\tprivate iteration(expression: ts.Expression): {\n\t\tform: IterationForm;\n\t\titerated: ts.Expression;\n\t} {\n\t\tif (!ts.isCallExpression(expression)) {\n\t\t\treturn { form: \"elements\", iterated: expression };\n\t\t}\n\t\tconst callee = expression.expression;\n\t\tif (\n\t\t\tts.isPropertyAccessExpression(callee) &&\n\t\t\tcallee.name.text === \"entries\" &&\n\t\t\t!expression.arguments.length\n\t\t) {\n\t\t\treturn { form: \"entries\", iterated: callee.expression };\n\t\t}\n\t\tconst [record, ...rest] = expression.arguments;\n\t\tif (!record || rest.length) {\n\t\t\treturn { form: \"elements\", iterated: expression };\n\t\t}\n\t\tif (this.expressions.sdkCall(expression) === \"entries\") {\n\t\t\treturn { form: \"recordEntries\", iterated: record };\n\t\t}\n\t\tif (\n\t\t\tts.isPropertyAccessExpression(callee) &&\n\t\t\tcallee.name.text === \"values\" &&\n\t\t\tts.isIdentifier(callee.expression) &&\n\t\t\tthis.resolver.standardLibrary(this.resolver.symbol(callee.expression))\n\t\t) {\n\t\t\treturn { form: \"recordValues\", iterated: record };\n\t\t}\n\t\treturn { form: \"elements\", iterated: expression };\n\t}\n\n\t/** Lowers a loop body as `counting` does, inside a loop that break and continue leave. */\n\tprivate inLoop<T>(\n\t\tcounters: readonly string[],\n\t\tcounter: string,\n\t\trange: IntegerInterval,\n\t\tlower: () => T,\n\t): T {\n\t\tthis.breakTargets.push(\"loop\");\n\t\ttry {\n\t\t\treturn this.expressions.counting(counters, counter, range, lower);\n\t\t} finally {\n\t\t\tthis.breakTargets.pop();\n\t\t}\n\t}\n}\n",
16
+ "import type { Statement } from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport type { ExpressionLowering } from \"./expressions\";\nimport { namedProperty, type TelemetryMethod } from \"./types\";\n\ntype Telemetry = Extract<Statement, { kind: \"telemetry\" }>;\n\n/** A `@tsplc/compiler/telemetry` call, which the backend encodes as one record (docs/03-guides/telemetry.md). */\nexport function telemetryStatement(\n\tlowering: ExpressionLowering,\n\tnode: ts.CallExpression,\n): Statement | undefined {\n\tconst method = lowering.resolver.telemetryMethod(node);\n\tif (!method) {\n\t\treturn undefined;\n\t}\n\tif (method === \"text\") {\n\t\tlowering.fail(\n\t\t\tnode,\n\t\t\t\"PLC2001\",\n\t\t\t\"telemetry.text is a property value of a telemetry call.\",\n\t\t);\n\t}\n\tconst [first, properties, ...rest] = node.arguments;\n\tif (!first || rest.length || node.typeArguments?.length) {\n\t\tlowering.fail(\n\t\t\tnode,\n\t\t\t\"PLC2001\",\n\t\t\t`telemetry.${method} takes one value and optional properties.`,\n\t\t);\n\t}\n\treturn {\n\t\tspan: lowering.positions.node(node),\n\t\tkind: \"telemetry\",\n\t\trecord: telemetryRecord(lowering, method, first),\n\t\tproperties: properties ? telemetryProperties(lowering, properties) : [],\n\t};\n}\n\nfunction telemetryRecord(\n\tlowering: ExpressionLowering,\n\tmethod: Exclude<TelemetryMethod, \"text\">,\n\tfirst: ts.Expression,\n): Telemetry[\"record\"] {\n\tswitch (method) {\n\t\tcase \"captureException\":\n\t\t\treturn { kind: \"exception\", code: lowering.expression(first, \"UDINT\") };\n\t\tcase \"capture\":\n\t\t\treturn {\n\t\t\t\tkind: \"event\",\n\t\t\t\tevent: literalText(lowering, method, first, \"event name\"),\n\t\t\t};\n\t\tdefault:\n\t\t\treturn {\n\t\t\t\tkind: \"log\",\n\t\t\t\tlevel: method,\n\t\t\t\tmessage: literalText(lowering, method, first, \"message\"),\n\t\t\t};\n\t}\n}\n\n/** An event name or log message is fixed text; changing values go in the properties. */\nfunction literalText(\n\tlowering: ExpressionLowering,\n\tmethod: TelemetryMethod,\n\tnode: ts.Expression,\n\tlabel: string,\n): string {\n\tif (!ts.isStringLiteral(node) && !ts.isNoSubstitutionTemplateLiteral(node)) {\n\t\tlowering.fail(\n\t\t\tnode,\n\t\t\t\"PLC2001\",\n\t\t\t`telemetry.${method} needs its ${label} as a string literal; put changing values in its properties.`,\n\t\t);\n\t}\n\treturn node.text;\n}\n\nfunction telemetryProperties(\n\tlowering: ExpressionLowering,\n\tnode: ts.Expression,\n): Telemetry[\"properties\"] {\n\tif (!ts.isObjectLiteralExpression(node)) {\n\t\tlowering.fail(\n\t\t\tnode,\n\t\t\t\"PLC2001\",\n\t\t\t\"Telemetry properties are an object literal.\",\n\t\t);\n\t}\n\tif (node.properties.length > 8) {\n\t\tlowering.fail(\n\t\t\tnode,\n\t\t\t\"PLC2001\",\n\t\t\t\"A telemetry call has at most 8 properties.\",\n\t\t);\n\t}\n\treturn node.properties.map((property) => {\n\t\tconst named = namedProperty(property);\n\t\tif (!named) {\n\t\t\tlowering.fail(\n\t\t\t\tproperty,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t\"Name each telemetry property with an identifier.\",\n\t\t\t);\n\t\t}\n\t\tconst { name, value } = named;\n\t\tif (\n\t\t\tts.isCallExpression(value) &&\n\t\t\tlowering.resolver.telemetryMethod(value) === \"text\"\n\t\t) {\n\t\t\treturn { name, ...textProperty(lowering, value) };\n\t\t}\n\t\tconst expression = lowering.expression(value);\n\t\tconst type = lowering.resolver.types.get(expression.type);\n\t\tif (\n\t\t\t!type ||\n\t\t\t![\"bool\", \"integer\", \"bits\", \"float\", \"enum\", \"string\"].includes(\n\t\t\t\ttype.kind,\n\t\t\t) ||\n\t\t\t(type.kind === \"string\" && type.encoding !== \"utf8\")\n\t\t) {\n\t\t\tlowering.fail(\n\t\t\t\tvalue,\n\t\t\t\t\"PLC2001\",\n\t\t\t\t`Telemetry property ${name} is ${expression.type}; send BOOL, integers, REAL, LREAL, enums, STRINGs or telemetry.text(bytes, length).`,\n\t\t\t);\n\t\t}\n\t\treturn { name, value: expression };\n\t});\n}\n\n/** `telemetry.text(bytes, length)`: the first `length` bytes of a BYTE array, sent as text. */\nfunction textProperty(\n\tlowering: ExpressionLowering,\n\tnode: ts.CallExpression,\n): Omit<Telemetry[\"properties\"][number], \"name\"> {\n\tconst [bytes, length, ...rest] = node.arguments;\n\tif (!bytes || !length || rest.length) {\n\t\tlowering.fail(\n\t\t\tnode,\n\t\t\t\"PLC2001\",\n\t\t\t\"telemetry.text takes a byte array and a length.\",\n\t\t);\n\t}\n\tconst place = lowering.place(bytes);\n\tconst { type } = lowering.placeType(place);\n\tconst array =\n\t\ttype === undefined ? undefined : lowering.resolver.types.get(type);\n\tconst element =\n\t\tarray?.kind === \"array\"\n\t\t\t? lowering.resolver.types.get(array.element)\n\t\t\t: undefined;\n\tif (\n\t\t!type ||\n\t\t(element?.kind !== \"bits\" && element?.kind !== \"integer\") ||\n\t\telement.bits !== 8\n\t) {\n\t\tlowering.fail(bytes, \"PLC2001\", \"telemetry.text reads an array of BYTE.\");\n\t}\n\tconst counted = lowering.expression(length);\n\tconst countKind = lowering.resolver.types.get(counted.type)?.kind;\n\tif (countKind !== \"integer\" && countKind !== \"bits\") {\n\t\tlowering.fail(length, \"PLC2001\", \"telemetry.text needs an integer length.\");\n\t}\n\treturn {\n\t\tvalue: {\n\t\t\tkind: \"borrow\",\n\t\t\tplace,\n\t\t\ttype,\n\t\t\tspan: lowering.positions.node(bytes),\n\t\t},\n\t\tlength: counted,\n\t};\n}\n",
17
+ "import { resolve } from \"node:path\";\nimport {\n\ttype Diagnostic,\n\terror,\n\ttype FunctionBlock,\n\ttype PlcProgram,\n} from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport { lowerCoroutine } from \"./coroutines\";\nimport { GeneratedNames } from \"./generated-names\";\nimport {\n\tblockArrayElement,\n\timportSpecifier,\n\ttype NamedRoutine,\n\tnamedRoutines,\n\tplcSources,\n} from \"./module-graph\";\nimport {\n\ttype Edit,\n\tedited,\n\tfrom,\n\tjoined,\n\ttype Mapped,\n\tmapped,\n\ttype Positions,\n\tslice,\n} from \"./positions\";\nimport { namesSdk, symbolAt } from \"./sdk\";\nimport { lowerTaskDefinitions } from \"./tasks\";\nimport { hasModifier, SemanticError } from \"./types\";\n\nexport type Job = NonNullable<FunctionBlock[\"job\"]>;\ntype Runtime = NonNullable<FunctionBlock[\"runtime\"]>;\ntype Schedule = NonNullable<PlcProgram[\"background\"]>;\ntype Continuation = NonNullable<PlcProgram[\"continuation\"]>;\n\nexport interface AsyncLowering {\n\tsources: Map<string, Mapped>;\n\tblocks: Map<string, Runtime>;\n\t/** The async function each generated block runs, by lowering key. */\n\tjobs: Map<string, Job>;\n\tprograms: Record<string, { module: string; export: string }>;\n\tschedules: Map<string, Schedule>;\n\tdiagnostics: Diagnostic[];\n\tcontinuations: Map<string, Continuation>;\n}\n\n/** The names of the members an async method's coroutine adds to its block. */\nexport interface MethodMembers {\n\tstart: string;\n\treset: string;\n\tsnapshot: string;\n\tadvance: string;\n}\n\n/** The type aliases a routine's module exports for its result and arguments, so other modules can name them. */\ninterface RoutineAliases {\n\tresult: string;\n\targument: (index: number) => string;\n}\n\n/** What every part of async lowering shares while it rewrites the program. */\nexport interface AsyncContext {\n\tchecker: ts.TypeChecker;\n\tsdk: string;\n\tpositions: Positions;\n\t/** Async routines by symbol. */\n\tfunctions: ReadonlyMap<ts.Symbol, NamedRoutine>;\n\t/** Async methods by symbol, with the members their coroutine adds. */\n\tmethods: ReadonlyMap<ts.Symbol, MethodMembers>;\n\tsymbol: (node: ts.Node) => ts.Symbol | undefined;\n\t/** Whether a node names the SDK declaration `name`. */\n\tnamesSdk: (node: ts.Node, name: string) => boolean;\n\tfail: (node: ts.Node, message: string) => never;\n\t/** Names for generated declarations, from the source node each stands for. */\n\tnames: GeneratedNames;\n\taliases: (fn: NamedRoutine) => RoutineAliases;\n\timportAliases: typeof importAliases;\n\t/** Whether code anywhere in the program reads the binding `declaration` declares. */\n\treferenced: (declaration: ts.VariableDeclaration) => boolean;\n}\n\n/** A background job a block's instances serve: the block method that serves it, and its schedule. */\ninterface OwnedJob {\n\tmethod: string;\n\tschedule: Schedule;\n}\n\n/**\n * One source file being rewritten: edits to its text, declarations added around it, and the\n * records of what it generates, which count only once the whole source has been rewritten.\n */\nexport interface SourceRewrite {\n\tsource: ts.SourceFile;\n\treplacements: Edit[];\n\textra: Mapped[];\n\t/** The routine aliases its imports name. */\n\timportedAliases: Set<string>;\n\tblocks: Map<string, Runtime>;\n\tjobs: Map<string, Job>;\n\tprograms: AsyncLowering[\"programs\"];\n\tschedules: Map<string, Schedule>;\n\tcontinuations: Map<string, Continuation>;\n\t/** The polls and background jobs of the blocks it declares, which their instances run, by block symbol. */\n\townedPolls: Map<ts.Symbol, string[]>;\n\townedJobs: Map<ts.Symbol, OwnedJob[]>;\n}\n\nconst asyncDiagnostic = (\n\tpositions: Positions,\n\tnode: ts.Node,\n\tmessage: string,\n): Diagnostic => error(\"PLC1010\", message, positions.node(node));\n\n/** Lower suspension into ordinary typed blocks before the PLC semantic pass. */\nexport const lowerAsync = (\n\tprogram: ts.Program,\n\tsdk: string,\n\tpositions: Positions,\n\troot: string,\n): AsyncLowering => {\n\tconst result: AsyncLowering = {\n\t\tsources: new Map(),\n\t\tblocks: new Map(),\n\t\tjobs: new Map(),\n\t\tprograms: {},\n\t\tschedules: new Map(),\n\t\tdiagnostics: [],\n\t\tcontinuations: new Map(),\n\t};\n\tconst checker = program.getTypeChecker();\n\tconst symbol = (node: ts.Node) => symbolAt(checker, node);\n\tconst fail: (node: ts.Node, message: string) => never = (node, message) => {\n\t\tthrow new SemanticError(asyncDiagnostic(positions, node, message));\n\t};\n\tconst names = new GeneratedNames(root);\n\tconst sources = plcSources(program);\n\tconst { functions, methods } = asyncRoutines(sources, checker, names);\n\tif (!functions.size) {\n\t\treturn result;\n\t}\n\tconst recursion = recursiveRoutine(functions, symbol);\n\tif (recursion) {\n\t\tresult.diagnostics.push(\n\t\t\tasyncDiagnostic(\n\t\t\t\tpositions,\n\t\t\t\trecursion.name,\n\t\t\t\t`${recursion.name.getText()} calls itself, and a PLC routine can't: each call's state is allocated when the program compiles. Write the repetition as a loop.`,\n\t\t\t),\n\t\t);\n\t\treturn result;\n\t}\n\tconst context: AsyncContext = {\n\t\tchecker,\n\t\tsdk,\n\t\tpositions,\n\t\tfunctions,\n\t\tmethods,\n\t\tsymbol,\n\t\tnamesSdk: (node, name) => namesSdk(checker, sdk, node, name),\n\t\tfail,\n\t\tnames,\n\t\taliases: (fn) => {\n\t\t\tconst prefix = names.name(\n\t\t\t\t`TsplcAsync${fn.name.getText(fn.getSourceFile())}`,\n\t\t\t\tfn,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tresult: `${prefix}Result`,\n\t\t\t\targument: (index) => `${prefix}Argument${index}`,\n\t\t\t};\n\t\t},\n\t\timportAliases,\n\t\treferenced: (declaration) => {\n\t\t\tconst target = symbol(declaration.name);\n\t\t\tconst reads = (node: ts.Node): boolean =>\n\t\t\t\t(ts.isIdentifier(node) &&\n\t\t\t\t\tnode !== declaration.name &&\n\t\t\t\t\ttarget !== undefined &&\n\t\t\t\t\tsymbol(node) === target) ||\n\t\t\t\tts.forEachChild(node, reads) === true;\n\t\t\treturn sources.some(reads);\n\t\t},\n\t};\n\tconst ownedPolls = new Map<ts.Symbol, string[]>();\n\tconst ownedJobs = new Map<ts.Symbol, OwnedJob[]>();\n\tfor (const source of sources) {\n\t\tconst rewrite = rewriteSource(context, source);\n\t\tif (rewrite instanceof SemanticError) {\n\t\t\tresult.diagnostics.push(rewrite.diagnostic);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!rewrite) {\n\t\t\tcontinue;\n\t\t}\n\t\tresult.sources.set(source.fileName, rewrittenText(rewrite));\n\t\tfor (const [key, value] of rewrite.blocks) {\n\t\t\tresult.blocks.set(key, value);\n\t\t}\n\t\tfor (const [key, value] of rewrite.jobs) {\n\t\t\tresult.jobs.set(key, value);\n\t\t}\n\t\tObject.assign(result.programs, rewrite.programs);\n\t\tfor (const [key, value] of rewrite.schedules) {\n\t\t\tresult.schedules.set(key, value);\n\t\t}\n\t\tfor (const [key, value] of rewrite.continuations) {\n\t\t\tresult.continuations.set(key, value);\n\t\t}\n\t\tfor (const [block, polls] of rewrite.ownedPolls) {\n\t\t\townedPolls.set(block, polls);\n\t\t}\n\t\tfor (const [block, jobs] of rewrite.ownedJobs) {\n\t\t\townedJobs.set(block, jobs);\n\t\t}\n\t}\n\tfor (const source of sources) {\n\t\taddInstanceEntries(context, { ownedPolls, ownedJobs }, source, result);\n\t}\n\treturn result;\n};\n\n/** Imports those of `names`, aliases `fn`'s module exports, that the source does not import yet. */\nfunction importAliases(\n\tfile: Pick<SourceRewrite, \"source\" | \"extra\" | \"importedAliases\">,\n\tnode: ts.Node,\n\tfn: NamedRoutine,\n\tnames: readonly string[],\n): void {\n\tconst missing = names.filter((name) => !file.importedAliases.has(name));\n\tif (!missing.length) {\n\t\treturn;\n\t}\n\tfor (const name of missing) {\n\t\tfile.importedAliases.add(name);\n\t}\n\tfile.extra.push(\n\t\tfrom(\n\t\t\tnode,\n\t\t\t`import type {${missing.join(\",\")}} from ${importSpecifier(file.source.fileName, fn.getSourceFile().fileName)};`,\n\t\t),\n\t);\n}\n\n/**\n * An async function that calls itself, directly or through other async functions. Each becomes a\n * block holding an instance of every function it calls, so a cycle would be a block inside itself.\n * An async method keeps its state in its own instance, so its calls allocate nothing.\n */\nfunction recursiveRoutine(\n\tfunctions: ReadonlyMap<ts.Symbol, NamedRoutine>,\n\tsymbol: (node: ts.Node) => ts.Symbol | undefined,\n): NamedRoutine | undefined {\n\tconst callees = (fn: NamedRoutine): ts.Symbol[] => {\n\t\tconst found: ts.Symbol[] = [];\n\t\tconst visit = (node: ts.Node): void => {\n\t\t\tif (ts.isCallExpression(node)) {\n\t\t\t\tconst callee = ts.isPropertyAccessExpression(node.expression)\n\t\t\t\t\t? node.expression.name\n\t\t\t\t\t: node.expression;\n\t\t\t\tconst target = symbol(callee);\n\t\t\t\tconst routine = target && functions.get(target);\n\t\t\t\tif (target && routine && ts.isFunctionDeclaration(routine)) {\n\t\t\t\t\tfound.push(target);\n\t\t\t\t}\n\t\t\t}\n\t\t\tts.forEachChild(node, visit);\n\t\t};\n\t\tif (fn.body) {\n\t\t\tvisit(fn.body);\n\t\t}\n\t\treturn found;\n\t};\n\tconst finished = new Set<ts.Symbol>();\n\tconst active = new Set<ts.Symbol>();\n\tconst cycle = (key: ts.Symbol): NamedRoutine | undefined => {\n\t\tconst fn = functions.get(key);\n\t\tif (active.has(key)) {\n\t\t\treturn fn;\n\t\t}\n\t\tif (finished.has(key) || !fn) {\n\t\t\treturn undefined;\n\t\t}\n\t\tactive.add(key);\n\t\tfor (const callee of callees(fn)) {\n\t\t\tconst found = cycle(callee);\n\t\t\tif (found) {\n\t\t\t\treturn found;\n\t\t\t}\n\t\t}\n\t\tactive.delete(key);\n\t\tfinished.add(key);\n\t\treturn undefined;\n\t};\n\tfor (const key of functions.keys()) {\n\t\tconst found = cycle(key);\n\t\tif (found) {\n\t\t\treturn found;\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/** Async functions and methods by symbol; methods also get the names of their coroutine members. */\nfunction asyncRoutines(\n\tsources: readonly ts.SourceFile[],\n\tchecker: ts.TypeChecker,\n\tnames: GeneratedNames,\n) {\n\tconst functions = new Map<ts.Symbol, NamedRoutine>();\n\tconst methods = new Map<ts.Symbol, MethodMembers>();\n\tfor (const [key, fn] of namedRoutines(sources, checker)) {\n\t\tif (!hasModifier(fn, ts.SyntaxKind.AsyncKeyword)) {\n\t\t\tcontinue;\n\t\t}\n\t\tfunctions.set(key, fn);\n\t\tif (ts.isMethodDeclaration(fn)) {\n\t\t\tconst prefix = names.name(`tsplcAsync${fn.name.getText()}`, fn);\n\t\t\tmethods.set(key, {\n\t\t\t\tstart: `${prefix}Start`,\n\t\t\t\treset: `${prefix}Reset`,\n\t\t\t\tsnapshot: `${prefix}Snapshot`,\n\t\t\t\tadvance: `${prefix}Advance`,\n\t\t\t});\n\t\t}\n\t}\n\treturn { functions, methods };\n}\n\n/**\n * Replaces a source's async routines and task definitions with generated blocks: undefined when\n * it has none, and the reason when it fails, in which case it is left as written.\n */\nfunction rewriteSource(\n\tcontext: AsyncContext,\n\tsource: ts.SourceFile,\n): SourceRewrite | SemanticError | undefined {\n\tconst rewrite: SourceRewrite = {\n\t\tsource,\n\t\treplacements: [],\n\t\textra: [],\n\t\timportedAliases: new Set(),\n\t\tblocks: new Map(),\n\t\tjobs: new Map(),\n\t\tprograms: {},\n\t\tschedules: new Map(),\n\t\tcontinuations: new Map(),\n\t\townedPolls: new Map(),\n\t\townedJobs: new Map(),\n\t};\n\ttry {\n\t\tfor (const fn of context.functions.values()) {\n\t\t\tif (fn.getSourceFile() === source) {\n\t\t\t\tlowerCoroutine(context, rewrite, fn);\n\t\t\t}\n\t\t}\n\t\tlowerTaskDefinitions(context, rewrite);\n\t} catch (cause) {\n\t\tif (!(cause instanceof SemanticError)) {\n\t\t\tthrow cause;\n\t\t}\n\t\treturn cause;\n\t}\n\treturn rewrite.replacements.length ? rewrite : undefined;\n}\n\n/** A rewritten source's text: generated classes first, the source with its edits, then the other declarations. */\nfunction rewrittenText({ source, replacements, extra }: SourceRewrite): Mapped {\n\tconst added = joined(extra, \"\\n\");\n\tconst generated = ts.createSourceFile(\n\t\tsource.fileName,\n\t\tadded.text,\n\t\tts.ScriptTarget.Latest,\n\t\ttrue,\n\t);\n\tconst part = (node: ts.Node) =>\n\t\tslice(added, node.getStart(generated), node.end);\n\tconst before = generated.statements.filter(ts.isClassDeclaration).map(part);\n\tconst after = generated.statements\n\t\t.filter((statement) => !ts.isClassDeclaration(statement))\n\t\t.map(part);\n\treturn mapped`${joined(before, \"\\n\")}\\n${edited(source, replacements)}\\n${joined(after, \"\\n\")}`;\n}\n\n/**\n * A block that owns continuations or background jobs runs them through its instances, so each\n * module-level instance gets an entry point per poll and job.\n */\nfunction addInstanceEntries(\n\tcontext: AsyncContext,\n\towned: Pick<SourceRewrite, \"ownedPolls\" | \"ownedJobs\">,\n\tsource: ts.SourceFile,\n\tresult: AsyncLowering,\n): void {\n\tconst { positions } = context;\n\tconst entries: Mapped[] = [];\n\tconst program = (entry: string) => {\n\t\tresult.programs[entry] = {\n\t\t\tmodule: resolve(source.fileName),\n\t\t\texport: entry,\n\t\t};\n\t};\n\tconst visit = (node: ts.Node): void => {\n\t\tconst instance = allocatedInstance(context, node);\n\t\tconst block = instance && context.symbol(instance.block);\n\t\tconst jobs = block && owned.ownedJobs.get(block);\n\t\tconst polls = block && owned.ownedPolls.get(block);\n\t\tif (!instance || (!jobs && !polls)) {\n\t\t\tts.forEachChild(node, visit);\n\t\t\treturn;\n\t\t}\n\t\tconst declaration = node.parent;\n\t\tif (\n\t\t\t!ts.isVariableDeclaration(declaration) ||\n\t\t\t!ts.isIdentifier(declaration.name) ||\n\t\t\t!ts.isVariableDeclarationList(declaration.parent) ||\n\t\t\t!ts.isVariableStatement(declaration.parent.parent) ||\n\t\t\t!ts.isSourceFile(declaration.parent.parent.parent) ||\n\t\t\t(jobs && instance.elements)\n\t\t) {\n\t\t\tresult.diagnostics.push(\n\t\t\t\tasyncDiagnostic(\n\t\t\t\t\tpositions,\n\t\t\t\t\tnode,\n\t\t\t\t\tjobs\n\t\t\t\t\t\t? \"Function blocks with background jobs require module-level named instances.\"\n\t\t\t\t\t\t: \"Function blocks with continuations require module-level named instances.\",\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst name = declaration.name.text;\n\t\t// One entry polls all of an instance's sites, in their order: they share its task.\n\t\tif (polls?.length) {\n\t\t\tconst range =\n\t\t\t\tinstance.elements && elementRange(context, instance.elements);\n\t\t\tif (range === null) {\n\t\t\t\tresult.diagnostics.push(\n\t\t\t\t\tasyncDiagnostic(\n\t\t\t\t\t\tpositions,\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\"A block array whose blocks have continuations needs a literal length and lower bound.\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst entry = context.names.name(\"tsplcContinuation\", declaration);\n\t\t\tconst calls = polls.map((poll) =>\n\t\t\t\trange === undefined\n\t\t\t\t\t? `${name}.${poll}();`\n\t\t\t\t\t: `for(let element:DINT=${range.first};element<=${range.last};element++){${name}[element].${poll}();}`,\n\t\t\t);\n\t\t\tentries.push(\n\t\t\t\tfrom(node, `export function ${entry}():void{${calls.join(\"\")}}`),\n\t\t\t);\n\t\t\tprogram(entry);\n\t\t\tresult.continuations.set(entry, {\n\t\t\t\tinstance: name,\n\t\t\t\tfile: positions.node(declaration).file,\n\t\t\t});\n\t\t}\n\t\tfor (const job of jobs ?? []) {\n\t\t\tconst entry = context.names.name(\n\t\t\t\t`tsplcBackground_${job.method}`,\n\t\t\t\tdeclaration,\n\t\t\t);\n\t\t\tentries.push(\n\t\t\t\tfrom(node, `export function ${entry}():void{${name}.${job.method}();}`),\n\t\t\t);\n\t\t\tprogram(entry);\n\t\t\tresult.schedules.set(entry, { ...job.schedule, worker: name });\n\t\t}\n\t\tts.forEachChild(node, visit);\n\t};\n\tvisit(source);\n\tif (entries.length) {\n\t\tresult.sources.set(\n\t\t\tsource.fileName,\n\t\t\tmapped`${result.sources.get(source.fileName) ?? edited(source, [])}\\n${joined(entries, \"\\n\")}`,\n\t\t);\n\t}\n}\n\n/**\n * The block instances an expression allocates: `new Block()` one instance, and\n * `defaultValue<FixedArray<Block, N, Lower>>()` one per element, whose length and lower bound\n * are type arguments.\n */\nfunction allocatedInstance(\n\tcontext: AsyncContext,\n\tnode: ts.Node,\n):\n\t| { block: ts.Node; elements?: { length: ts.TypeNode; lower?: ts.TypeNode } }\n\t| undefined {\n\tif (ts.isNewExpression(node)) {\n\t\treturn { block: node.expression };\n\t}\n\tif (\n\t\t!ts.isCallExpression(node) ||\n\t\t!context.namesSdk(node.expression, \"defaultValue\")\n\t) {\n\t\treturn undefined;\n\t}\n\tconst [type] = node.typeArguments ?? [];\n\tconst element = type && blockArrayElement(type, context.checker, context.sdk);\n\tconst [, length, lower] =\n\t\ttype && ts.isTypeReferenceNode(type) ? (type.typeArguments ?? []) : [];\n\tif (!element || !length) {\n\t\treturn undefined;\n\t}\n\treturn { block: element.typeName, elements: { length, lower } };\n}\n\n/** A block array's first and last index; null when its length or lower bound is not a literal. */\nfunction elementRange(\n\t{ checker }: AsyncContext,\n\t{ length, lower }: { length: ts.TypeNode; lower?: ts.TypeNode },\n): { first: number; last: number } | null {\n\t// A literal, or a table's `(typeof table)[\"length\"]`.\n\tconst literal = (node: ts.TypeNode) => {\n\t\tconst type = checker.getTypeFromTypeNode(node);\n\t\treturn type.isNumberLiteral() ? type.value : undefined;\n\t};\n\tconst first = lower ? literal(lower) : 0;\n\tconst count = literal(length);\n\tif (first === undefined || count === undefined) {\n\t\treturn null;\n\t}\n\treturn { first, last: first + count - 1 };\n}\n",
18
+ "import {\n\ttype HttpMethod,\n\thttpMethods,\n\tidentityDigest,\n\tjobError,\n\treservedErrors,\n} from \"@tsplc/compiler/ir\";\nimport { jobStateFields } from \"@tsplc/debug/manifest\";\nimport ts from \"typescript\";\nimport type { AsyncContext, Job, MethodMembers, SourceRewrite } from \"./async\";\nimport { copyValue } from \"./cooperative\";\nimport { loweringKey } from \"./lowering-key\";\nimport type { NamedRoutine } from \"./module-graph\";\nimport {\n\tcopied,\n\ttype Edit,\n\tedited,\n\tfrom,\n\tjoined,\n\ttype Mapped,\n\tmapped,\n\ttype Part,\n} from \"./positions\";\nimport { holdsBorrow, symbolAt } from \"./sdk\";\nimport { backgroundJob } from \"./tasks\";\nimport {\n\tcalleeName,\n\thasModifier,\n\tisAggregateType,\n\tisPropertyName,\n\tnamedRecordText,\n\tpromisedType,\n} from \"./types\";\n\ntype Step = Job[\"steps\"][number];\n/** What a step does when the operation it waits on fails; `cancellable` failures may be a cancel. */\ntype Reject = (error: Part, options: { cancellable: boolean }) => Part;\n\n/**\n * How the generated code names what it reads on its block: the members the coroutine adds, the\n * methods that run it, and, in an async method, the members of the method's own class.\n */\ninterface Naming {\n\tmember: (name: string) => string;\n\t/** A method's declaration, with its modifier. */\n\tentry: (name: keyof MethodMembers) => string;\n\t/** `this.name` of a method's own class; undefined in a function, which has none. */\n\town: ((name: string) => string) | undefined;\n}\n\nconst blockEntries: Record<keyof MethodMembers, string> = {\n\tstart: \"start\",\n\treset: \"reset\",\n\tsnapshot: \"snapshot\",\n\tadvance: \"protected execute\",\n};\n\n/** An async function's own block. */\nconst blockNaming: Naming = {\n\tmember: (name) => name,\n\tentry: (name) => blockEntries[name],\n\town: undefined,\n};\n\nconst isHttpMethod = (value: string | undefined): value is HttpMethod =>\n\thttpMethods.some((method) => method === value);\n\n/** A parameter, local or caught error, which lives on the block across suspensions. */\ninterface Field {\n\tname: string;\n\ttype: string;\n\taggregate: boolean;\n}\n\n/** Statements that end in a semicolon. */\nconst terminated = (node: ts.Node) =>\n\tts.isExpressionStatement(node) ||\n\tts.isVariableStatement(node) ||\n\tts.isReturnStatement(node) ||\n\tts.isThrowStatement(node) ||\n\tts.isBreakOrContinueStatement(node);\n\n/** The operator a compound update in a loop header applies. */\nconst compoundSteps = new Map<ts.SyntaxKind, string>([\n\t[ts.SyntaxKind.PlusEqualsToken, \"+\"],\n\t[ts.SyntaxKind.MinusEqualsToken, \"-\"],\n]);\n\n/** The call an await waits on. */\nconst awaitedCall = (node: ts.Node) =>\n\tts.isAwaitExpression(node) ? node.expression : node;\n\nconst containsAwait = (node: ts.Node, source: ts.SourceFile): boolean =>\n\tts.isAwaitExpression(node) ||\n\tnode.getChildren(source).some((child) => containsAwait(child, source));\n\n/** Whether the coroutine copies a statement into one step as written, rather than lowering it into steps. */\nexport const copiedWhole = (\n\tstatement: ts.Statement,\n\tsource: ts.SourceFile,\n): boolean =>\n\tts.isSwitchStatement(statement) ||\n\t(ts.isIterationStatement(statement, false) &&\n\t\t!containsAwait(statement, source));\n\n/**\n * A job's code identity: its steps, their targets and the state they keep. A job stores it when it\n * starts and stops with `codeChanged` when an online change brings other code, since its step and\n * fields were made for the code it started with. Never 0, the value of a field an online change adds.\n */\nconst codeDigest = (code: string): number =>\n\tNumber.parseInt(identityDigest(code), 16) || 1;\n\n/** URL expressions are compile-time values, never reads from mutable PLC state. */\nconst staticString = (\n\tchecker: ts.TypeChecker,\n\troot: ts.Expression,\n): string | undefined => {\n\tconst active = new Set<ts.Node>();\n\tconst valueNode = (node: ts.Node): ts.Node | undefined => {\n\t\tif (ts.isParenthesizedExpression(node)) {\n\t\t\treturn node.expression;\n\t\t}\n\t\tif (ts.isIdentifier(node)) {\n\t\t\tconst declaration = symbolAt(checker, node)?.declarations?.find(\n\t\t\t\tts.isVariableDeclaration,\n\t\t\t);\n\t\t\tif (\n\t\t\t\tdeclaration &&\n\t\t\t\tts.isVariableDeclarationList(declaration.parent) &&\n\t\t\t\tdeclaration.parent.flags & ts.NodeFlags.Const\n\t\t\t) {\n\t\t\t\treturn declaration.initializer;\n\t\t\t}\n\t\t}\n\t\tif (ts.isPropertyAccessExpression(node)) {\n\t\t\tconst field = symbolAt(checker, node.name);\n\t\t\tif (\n\t\t\t\t!field?.declarations?.some(\n\t\t\t\t\t(declaration) =>\n\t\t\t\t\t\tts.canHaveModifiers(declaration) &&\n\t\t\t\t\t\thasModifier(declaration, ts.SyntaxKind.ReadonlyKeyword),\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst object = resolve(node.expression);\n\t\t\tif (object && ts.isObjectLiteralExpression(object)) {\n\t\t\t\tfor (const property of object.properties) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tts.isPropertyAssignment(property) &&\n\t\t\t\t\t\t(ts.isIdentifier(property.name) ||\n\t\t\t\t\t\t\tts.isStringLiteral(property.name)) &&\n\t\t\t\t\t\tproperty.name.text === node.name.text\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn property.initializer;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\treturn node;\n\t};\n\tconst resolve = (node: ts.Node): ts.Node | undefined => {\n\t\tif (active.has(node)) {\n\t\t\treturn;\n\t\t}\n\t\tactive.add(node);\n\t\ttry {\n\t\t\tconst next = valueNode(node);\n\t\t\treturn next && next !== node ? resolve(next) : next;\n\t\t} finally {\n\t\t\tactive.delete(node);\n\t\t}\n\t};\n\tconst read = (node: ts.Node): string | undefined => {\n\t\tconst resolved = resolve(node);\n\t\tif (!resolved || active.has(resolved)) {\n\t\t\treturn;\n\t\t}\n\t\tactive.add(resolved);\n\t\ttry {\n\t\t\tif (\n\t\t\t\tts.isStringLiteral(resolved) ||\n\t\t\t\tts.isNoSubstitutionTemplateLiteral(resolved)\n\t\t\t) {\n\t\t\t\treturn resolved.text;\n\t\t\t}\n\t\t\tif (ts.isTemplateExpression(resolved)) {\n\t\t\t\tlet value = resolved.head.text;\n\t\t\t\tfor (const part of resolved.templateSpans) {\n\t\t\t\t\tconst item = read(part.expression);\n\t\t\t\t\tif (item === undefined) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tvalue += item + part.literal.text;\n\t\t\t\t}\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tts.isBinaryExpression(resolved) &&\n\t\t\t\tresolved.operatorToken.kind === ts.SyntaxKind.PlusToken\n\t\t\t) {\n\t\t\t\tconst left = read(resolved.left);\n\t\t\t\tconst right = read(resolved.right);\n\t\t\t\tif (left !== undefined && right !== undefined) {\n\t\t\t\t\treturn left + right;\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tactive.delete(resolved);\n\t\t}\n\t};\n\treturn read(root);\n};\n\n/**\n * Replaces an async routine with a block that runs it as a resumable state machine. An async\n * method's block joins its own class as members, renamed apart from the class's own.\n */\nexport function lowerCoroutine(\n\tcontext: AsyncContext,\n\tfile: SourceRewrite,\n\tfn: NamedRoutine,\n): void {\n\tconst symbol = context.symbol(fn.name);\n\tconst method = symbol && context.methods.get(symbol);\n\tconst replace = (text: Part) =>\n\t\tfile.replacements.push({\n\t\t\tstart: fn.getStart(file.source),\n\t\t\tend: fn.end,\n\t\t\ttext,\n\t\t});\n\tif (!method) {\n\t\tconst coroutine = new Coroutine(context, file, fn, blockNaming);\n\t\treplace(coroutine.blockClass(coroutine.digest()));\n\t\tconst name = fn.name.getText(file.source);\n\t\tfile.jobs.set(loweringKey(file.source.fileName, name), {\n\t\t\tname,\n\t\t\tspan: context.positions.node(fn),\n\t\t\tsteps: coroutine.steps,\n\t\t});\n\t\treturn;\n\t}\n\t// The digest is of the code as a block of its own would run it, with the class's members as\n\t// `this[\"name\"]`, which keeps the digests an online change compares from one build to the next.\n\tconst code = new Coroutine(\n\t\tcontext,\n\t\t{\n\t\t\tsource: file.source,\n\t\t\textra: [],\n\t\t\timportedAliases: new Set(),\n\t\t\tblocks: new Map(),\n\t\t},\n\t\tfn,\n\t\t{\n\t\t\t...blockNaming,\n\t\t\town: (name) => `this[${JSON.stringify(name)}]`,\n\t\t},\n\t).digest();\n\tconst prefix = context.names.name(\"tsplcAsync\", fn);\n\tconst members = new Coroutine(context, file, fn, {\n\t\tmember: (name) => `${prefix}_${name}`,\n\t\tentry: (name) => `public ${method[name]}`,\n\t\town: (name) => `this.${name}`,\n\t}).members(code);\n\treplace(joined(members, \"\\n\"));\n}\n\n/**\n * One async routine's block under construction. Each step is a case of the block's state\n * machine; awaiting an operation adds a child block or borrow that the steps start and poll.\n */\nclass Coroutine {\n\tprivate readonly body: ts.Block;\n\tprivate readonly returnsVoid: boolean;\n\tprivate readonly returnType: string;\n\tprivate readonly resultAggregate: boolean;\n\tprivate readonly fields = new Map<ts.Symbol, Field>();\n\tprivate readonly parameters: (Field & { field: string })[];\n\tprivate readonly states = new Map<number, Mapped>();\n\t/** The loops that suspend, innermost last, with the steps their break and continue go to. */\n\tprivate readonly loops: { breakStep: number; continueStep: number }[] = [];\n\tprivate readonly yielding = new Set<number>();\n\treadonly steps: Step[] = [];\n\tprivate readonly children: string[] = [];\n\tprivate readonly resets: string[] = [];\n\tprivate readonly cancels: string[] = [];\n\n\tprivate readonly entry: number;\n\n\tconstructor(\n\t\tprivate readonly context: AsyncContext,\n\t\tprivate readonly file: Pick<\n\t\t\tSourceRewrite,\n\t\t\t\"source\" | \"extra\" | \"importedAliases\" | \"blocks\"\n\t\t>,\n\t\tprivate readonly fn: NamedRoutine,\n\t\tprivate readonly naming: Naming,\n\t) {\n\t\tconst promised = fn.type && promisedType(fn.type);\n\t\tif (!fn.body || fn.typeParameters?.length || !promised) {\n\t\t\tcontext.fail(\n\t\t\t\tfn,\n\t\t\t\t\"Async functions require concrete parameters and an explicit Promise<T> result.\",\n\t\t\t);\n\t\t}\n\t\tthis.body = fn.body;\n\t\tthis.returnsVoid = promised.kind === ts.SyntaxKind.VoidKeyword;\n\t\tthis.returnType = this.returnsVoid ? \"BOOL\" : this.text(promised);\n\t\tthis.resultAggregate = isAggregateType(\n\t\t\tcontext.checker.getTypeFromTypeNode(promised),\n\t\t);\n\t\tthis.parameters = fn.parameters.map((parameter, index) =>\n\t\t\tthis.parameter(parameter, index),\n\t\t);\n\t\tthis.collect(fn.body);\n\t\tconst end = this.body.getLastToken(file.source);\n\t\tif (!end) {\n\t\t\tthrow new Error(\"A block body ends in a brace.\");\n\t\t}\n\t\tthis.entry = this.block(\n\t\t\tthis.body.statements,\n\t\t\tthis.returnsVoid\n\t\t\t\t? this.state(this.finish(\"true\"), end, \"return\", { yields: false })\n\t\t\t\t: this.state(this.failure(jobError.malformedResponse), end, \"throw\", {\n\t\t\t\t\t\tyields: false,\n\t\t\t\t\t}),\n\t\t\t(error) => this.failure(error),\n\t\t);\n\t}\n\n\tprivate text(node: ts.Node): string {\n\t\treturn node.getText(this.file.source);\n\t}\n\n\t/** `this.name` of a member the coroutine adds. */\n\tprivate self(name: string): string {\n\t\treturn `this.${this.naming.member(name)}`;\n\t}\n\n\t/** A symbol the program declares, which every declaration the coroutine reads has. */\n\tprivate declared(node: ts.Node): ts.Symbol {\n\t\tconst symbol = this.context.symbol(node);\n\t\tif (!symbol) {\n\t\t\tthrow new Error(`${node.getText(this.file.source)} declares no symbol.`);\n\t\t}\n\t\treturn symbol;\n\t}\n\n\tprivate parameter(\n\t\tparameter: ts.ParameterDeclaration,\n\t\tindex: number,\n\t): Field & { field: string } {\n\t\tif (\n\t\t\t!ts.isIdentifier(parameter.name) ||\n\t\t\t!parameter.type ||\n\t\t\tparameter.initializer ||\n\t\t\tparameter.questionToken ||\n\t\t\tparameter.dotDotDotToken\n\t\t) {\n\t\t\tthis.context.fail(\n\t\t\t\tparameter,\n\t\t\t\t\"Async parameters require explicit concrete value types.\",\n\t\t\t);\n\t\t}\n\t\tif (holdsBorrow(this.context, parameter.type)) {\n\t\t\tthis.context.fail(\n\t\t\t\tparameter,\n\t\t\t\t\"InOut cannot cross an async suspension; pass a value snapshot.\",\n\t\t\t);\n\t\t}\n\t\tconst type = this.text(parameter.type);\n\t\tconst aggregate = isAggregateType(\n\t\t\tthis.context.checker.getTypeFromTypeNode(parameter.type),\n\t\t);\n\t\tconst field = `argument${index}`;\n\t\tthis.fields.set(this.declared(parameter.name), {\n\t\t\tname: field,\n\t\t\ttype,\n\t\t\taggregate,\n\t\t});\n\t\treturn { name: parameter.name.text, type, aggregate, field };\n\t}\n\n\t/** Moves the routine's locals and caught errors onto the block, and rejects what cannot suspend. */\n\tprivate collect(node: ts.Node): void {\n\t\t// A loop that doesn't suspend runs within one step, with its own locals.\n\t\tif (\n\t\t\tts.isIterationStatement(node, false) &&\n\t\t\tcopiedWhole(node, this.file.source)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (ts.isForOfStatement(node)) {\n\t\t\tthis.context.fail(\n\t\t\t\tnode,\n\t\t\t\t\"A for…of whose body awaits is not supported; count through the array's indexes with a for loop.\",\n\t\t\t);\n\t\t}\n\t\tif (ts.isFunctionLike(node) && node !== this.fn) {\n\t\t\tthis.context.fail(\n\t\t\t\tnode,\n\t\t\t\t\"Closures and nested functions are not supported in async PLC routines.\",\n\t\t\t);\n\t\t}\n\t\tif (ts.isCatchClause(node)) {\n\t\t\tconst declaration = node.variableDeclaration;\n\t\t\tif (declaration) {\n\t\t\t\tif (!ts.isIdentifier(declaration.name)) {\n\t\t\t\t\tthis.context.fail(\n\t\t\t\t\t\tdeclaration,\n\t\t\t\t\t\t\"Catch requires a named error code or no binding.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.fields.set(this.declared(declaration.name), {\n\t\t\t\t\tname: `caught${this.fields.size}`,\n\t\t\t\t\ttype: \"UDINT\",\n\t\t\t\t\taggregate: false,\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis.collect(node.block);\n\t\t\treturn;\n\t\t}\n\t\tif (ts.isVariableDeclaration(node)) {\n\t\t\tif (!ts.isIdentifier(node.name) || !node.initializer) {\n\t\t\t\tthis.context.fail(node, \"Async locals need names and initializers.\");\n\t\t\t}\n\t\t\tconst type = node.type\n\t\t\t\t? this.text(node.type)\n\t\t\t\t: this.inferredType(node, node.initializer);\n\t\t\tif (!type) {\n\t\t\t\tthis.context.fail(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"Annotate async locals with their concrete PLC type.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.fields.set(this.declared(node.name), {\n\t\t\t\tname: `local${this.fields.size}`,\n\t\t\t\ttype,\n\t\t\t\taggregate: isAggregateType(\n\t\t\t\t\tthis.context.checker.getTypeAtLocation(node),\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\t\tts.forEachChild(node, (child) => this.collect(child));\n\t}\n\n\t/** An unannotated local's type: BOOL for a boolean literal, or the result of the routine it awaits. */\n\tprivate inferredType(\n\t\tnode: ts.VariableDeclaration,\n\t\tinitializer: ts.Expression,\n\t): string | undefined {\n\t\tif (\n\t\t\tinitializer.kind === ts.SyntaxKind.TrueKeyword ||\n\t\t\tinitializer.kind === ts.SyntaxKind.FalseKeyword\n\t\t) {\n\t\t\treturn \"BOOL\";\n\t\t}\n\t\tif (\n\t\t\t!ts.isAwaitExpression(initializer) ||\n\t\t\t!ts.isCallExpression(initializer.expression)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst target = calleeName(initializer.expression.expression);\n\t\tconst symbol = target && this.context.symbol(target);\n\t\tconst called = symbol && this.context.functions.get(symbol);\n\t\tconst promised = called?.type && promisedType(called.type);\n\t\tif (!called || !promised) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst { source } = this.file;\n\t\tif (called.getSourceFile() === source) {\n\t\t\treturn promised.getText(source);\n\t\t}\n\t\tconst type = this.context.aliases(called).result;\n\t\tthis.context.importAliases(this.file, node, called, [type]);\n\t\treturn type;\n\t}\n\n\t/** The user's text with locals moved onto the block, so positions in it map exactly. */\n\tprivate rewrite(node: ts.Node): Mapped {\n\t\tconst { source } = this.file;\n\t\tconst edits: Edit[] = [];\n\t\tconst visit = (child: ts.Node): void => {\n\t\t\t// A step runs within one scan; only the awaits the statement lowering suspends at can wait.\n\t\t\tif (ts.isAwaitExpression(child)) {\n\t\t\t\tthis.context.fail(\n\t\t\t\t\tchild,\n\t\t\t\t\t\"This suspension position is not supported; await into a named local or return.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst replacement = this.replacement(child);\n\t\t\tif (replacement === undefined) {\n\t\t\t\tts.forEachChild(child, visit);\n\t\t\t} else {\n\t\t\t\tedits.push({\n\t\t\t\t\tstart: child.getStart(source),\n\t\t\t\t\tend: child.end,\n\t\t\t\t\ttext: replacement,\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\t\tvisit(node);\n\t\tconst start = node.getStart(source);\n\t\tconst rewritten = edited(\n\t\t\tcopied(node),\n\t\t\tedits.map((edit) => ({\n\t\t\t\t...edit,\n\t\t\t\tstart: edit.start - start,\n\t\t\t\tend: edit.end - start,\n\t\t\t})),\n\t\t);\n\t\t// A statement written without its semicolon is followed by more code here.\n\t\treturn terminated(node) && !rewritten.text.endsWith(\";\")\n\t\t\t? mapped`${rewritten};`\n\t\t\t: rewritten;\n\t}\n\n\t/** What a node becomes on the block: a field read, or a method's own member. */\n\tprivate replacement(node: ts.Node): string | undefined {\n\t\tconst { own } = this.naming;\n\t\tif (\n\t\t\town &&\n\t\t\tts.isPropertyAccessExpression(node) &&\n\t\t\tnode.expression.kind === ts.SyntaxKind.ThisKeyword\n\t\t) {\n\t\t\treturn own(node.name.text);\n\t\t}\n\t\tif (ts.isIdentifier(node) && !isPropertyName(node)) {\n\t\t\tconst symbol = this.context.symbol(node);\n\t\t\tconst field = symbol && this.fields.get(symbol);\n\t\t\tif (field) {\n\t\t\t\treturn this.self(field.name);\n\t\t\t}\n\t\t}\n\t\tif (ts.isShorthandPropertyAssignment(node)) {\n\t\t\tconst value =\n\t\t\t\tthis.context.checker.getShorthandAssignmentValueSymbol(node);\n\t\t\tconst field = value && this.fields.get(value);\n\t\t\tif (field) {\n\t\t\t\treturn `${node.name.text}: ${this.self(field.name)}`;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** A step of the job: `body` runs while it is current; `origin` is the source it runs. */\n\tprivate state(\n\t\tbody: Part,\n\t\torigin: ts.Node,\n\t\tkind: Step[\"kind\"],\n\t\t{ yields }: { yields: boolean },\n\t): number {\n\t\tconst id = this.states.size + 1;\n\t\tthis.states.set(id, from(origin, body));\n\t\tthis.steps.push({\n\t\t\tstep: id,\n\t\t\tkind,\n\t\t\tspan: this.context.positions.node(origin),\n\t\t\ttext: this.context.positions.excerpt(\n\t\t\t\tkind === \"await\" ? awaitedCall(origin) : origin,\n\t\t\t),\n\t\t});\n\t\tif (yields) {\n\t\t\tthis.yielding.add(id);\n\t\t}\n\t\treturn id;\n\t}\n\n\tprivate finish(value: Part): Mapped {\n\t\treturn mapped`${this.self(\"value\")} = ${copyValue(value, this.resultAggregate)}; ${this.self(\"busy\")} = false; ${this.self(\"done\")} = true; ${this.self(\"step\")} = 0;`;\n\t}\n\n\tprivate failure(error: Part): Mapped {\n\t\tconst code = this.self(\"error\");\n\t\treturn mapped`${code} = ${error}; if(${code} === 0)${code}=${jobError.malformedResponse}; ${this.self(\"busy\")} = false; ${this.self(\"done\")} = true; ${this.self(\"step\")} = 0;`;\n\t}\n\n\t/** An awaited call's result as the target stores it: records and arrays are copied. */\n\tprivate awaitedValue(value: string, call: ts.CallExpression): Part {\n\t\tconst { checker } = this.context;\n\t\tconst awaited = checker.getAwaitedType(checker.getTypeAtLocation(call));\n\t\treturn copyValue(value, awaited !== undefined && isAggregateType(awaited));\n\t}\n\n\t/** The steps that start and poll an awaited operation, then store its result in `target`. */\n\tprivate awaitState(\n\t\tawaited: ts.AwaitExpression | ts.CallExpression,\n\t\ttarget: string | undefined,\n\t\tnext: number,\n\t\treject: Reject,\n\t): number {\n\t\tconst call = ts.isAwaitExpression(awaited) ? awaited.expression : awaited;\n\t\tif (!ts.isCallExpression(call)) {\n\t\t\tthis.context.fail(\n\t\t\t\tawaited,\n\t\t\t\t\"Await requires a tsPLC operation or a statically named async function.\",\n\t\t\t);\n\t\t}\n\t\tconst name = calleeName(call.expression);\n\t\tif (!name) {\n\t\t\tthis.context.fail(\n\t\t\t\tcall,\n\t\t\t\t\"Await requires a known async helper or SDK operation.\",\n\t\t\t);\n\t\t}\n\t\tconst awaiting = { awaited, call, target, next, reject };\n\t\tif (this.context.namesSdk(name, \"sleep\")) {\n\t\t\treturn this.sleepState(awaiting);\n\t\t}\n\t\tconst rpc = this.context.namesSdk(name, \"opcuaCall\");\n\t\tif (rpc || this.context.namesSdk(name, \"fetch\")) {\n\t\t\treturn this.requestState(awaiting, { rpc });\n\t\t}\n\t\tconst symbol = this.context.symbol(name);\n\t\tif (backgroundJob(this.context, symbol)) {\n\t\t\treturn this.jobState(awaiting);\n\t\t}\n\t\tif (!symbol || !this.context.functions.has(symbol)) {\n\t\t\tthis.context.fail(\n\t\t\t\tcall,\n\t\t\t\t\"Await requires a known async helper or SDK operation.\",\n\t\t\t);\n\t\t}\n\t\tconst method = this.context.methods.get(symbol);\n\t\tif (method) {\n\t\t\treturn this.methodState(awaiting, method);\n\t\t}\n\t\treturn this.helperState(awaiting);\n\t}\n\n\t/** `await sleep(duration)`: an on-delay timer child. */\n\tprivate sleepState({ awaited, call, target, next }: Awaiting): number {\n\t\tconst child = `child${this.children.length}`;\n\t\tconst [duration, ...rest] = call.arguments;\n\t\tif (!duration || rest.length || call.typeArguments?.length || target) {\n\t\t\tthis.context.fail(call, \"sleep takes one TIME and returns void.\");\n\t\t}\n\t\tthis.children.push(\n\t\t\t`private ${this.naming.member(child)} = new OnDelayTimer();`,\n\t\t);\n\t\tthis.resets.push(\n\t\t\t`${this.self(child)}.update({enabled:false,duration:ms(0)});`,\n\t\t);\n\t\tconst poll = this.state(\n\t\t\tmapped`${this.self(child)}.update({enabled:true,duration:${this.rewrite(duration)}}); if(${this.self(child)}.out.done) { ${this.self(\"step\")} = ${next}; }`,\n\t\t\tawaited,\n\t\t\t\"await\",\n\t\t\t{ yields: false },\n\t\t);\n\t\treturn this.state(\n\t\t\tmapped`${this.self(child)}.update({enabled:true,duration:${this.rewrite(duration)}});${this.self(\"step\")}=${poll};`,\n\t\t\tawaited,\n\t\t\t\"await\",\n\t\t\t{ yields: true },\n\t\t);\n\t}\n\n\t/** `await fetch(url, options)` or `await opcuaCall(path, request)`: an HTTP or RPC child block. */\n\tprivate requestState(\n\t\t{ awaited, call, target, next, reject }: Awaiting,\n\t\t{ rpc }: { rpc: boolean },\n\t): number {\n\t\tconst { checker } = this.context;\n\t\tconst { source, extra, blocks } = this.file;\n\t\tconst child = `child${this.children.length}`;\n\t\tconst [address, second, ...rest] = call.arguments;\n\t\tconst [response, request, ...more] = call.typeArguments ?? [];\n\t\tif (!address || rest.length || !response || more.length) {\n\t\t\tthis.context.fail(\n\t\t\t\tcall,\n\t\t\t\t\"fetch<Response, Request?> requires a URL and optional { method, json } options.\",\n\t\t\t);\n\t\t}\n\t\tconst url = staticString(checker, address);\n\t\tif (url === undefined) {\n\t\t\tthis.context.fail(\n\t\t\t\taddress,\n\t\t\t\t\"fetch URL must be a literal or compile-time const string; configuration properties must be readonly.\",\n\t\t\t);\n\t\t}\n\t\tconst { method, json } = rpc\n\t\t\t? { method: \"POST\" as const, json: second }\n\t\t\t: this.fetchOptions(second);\n\t\tif (method === \"GET\" && json) {\n\t\t\tthis.context.fail(call, \"GET requests cannot contain json.\");\n\t\t}\n\t\tconst responseType = this.text(response);\n\t\tconst httpName = this.context.names.name(\n\t\t\t`Tsplc${rpc ? \"Rpc\" : \"Http\"}`,\n\t\t\tcall,\n\t\t);\n\t\tif (!json) {\n\t\t\textra.push(from(call, `interface ${httpName}Request {reserved:BOOL}`));\n\t\t}\n\t\tconst requestType = json\n\t\t\t? this.requestType(json, request)\n\t\t\t: `${httpName}Request`;\n\t\textra.push(\n\t\t\tfrom(\n\t\t\t\tcall,\n\t\t\t\t`interface ${httpName}Input {start:BOOL;cancel:BOOL;request:${requestType}}\ninterface ${httpName}Output {busy:BOOL;done:BOOL;error:UDINT;result:${responseType}}\nclass ${httpName} extends FunctionBlock<${httpName}Input,${httpName}Output> { protected execute(input:${httpName}Input):${httpName}Output {return {busy:false,done:false,error:0,result:defaultValue<${responseType}>()};} }`,\n\t\t\t),\n\t\t);\n\t\tblocks.set(\n\t\t\tloweringKey(source.fileName, httpName),\n\t\t\trpc\n\t\t\t\t? { kind: \"rpc\", path: url }\n\t\t\t\t: {\n\t\t\t\t\t\tkind: \"http\",\n\t\t\t\t\t\turl,\n\t\t\t\t\t\tmethod,\n\t\t\t\t\t\tjson: Boolean(json),\n\t\t\t\t\t},\n\t\t);\n\t\tthis.children.push(\n\t\t\t`private ${this.naming.member(child)} = new ${httpName}();`,\n\t\t);\n\t\tthis.resets.push(\n\t\t\t`${this.self(child)}.update({start:false,cancel:false,request:defaultValue<${requestType}>()});`,\n\t\t);\n\t\tthis.cancels.push(\n\t\t\t`${this.self(child)}.update({start:false,cancel:true,request:defaultValue<${requestType}>()});`,\n\t\t);\n\t\treturn this.state(\n\t\t\tmapped`${this.self(child)}.update({start:true,cancel:false,request:${json ? this.rewrite(json) : `defaultValue<${requestType}>()`}}); if(${this.self(child)}.out.done) { if(${this.self(child)}.out.error !== 0) {${reject(`${this.self(child)}.out.error`, { cancellable: true })}} else {${target ? mapped`${target} = ${this.awaitedValue(`${this.self(child)}.out.result`, call)};` : \"\"}${this.self(\"step\")} = ${next};} }`,\n\t\t\tawaited,\n\t\t\t\"await\",\n\t\t\t{ yields: false },\n\t\t);\n\t}\n\n\t/** A fetch's inline `{ method, json }` options. */\n\tprivate fetchOptions(options: ts.Expression | undefined): {\n\t\tmethod: HttpMethod;\n\t\tjson: ts.Expression | undefined;\n\t} {\n\t\tif (!options) {\n\t\t\treturn { method: \"GET\", json: undefined };\n\t\t}\n\t\tif (!ts.isObjectLiteralExpression(options)) {\n\t\t\tthis.context.fail(\n\t\t\t\toptions,\n\t\t\t\t\"fetch options must be an inline { method, json } object.\",\n\t\t\t);\n\t\t}\n\t\tconst chosen: { method: HttpMethod; json: ts.Expression | undefined } = {\n\t\t\tmethod: \"GET\",\n\t\t\tjson: undefined,\n\t\t};\n\t\tfor (const property of options.properties) {\n\t\t\tif (\n\t\t\t\t!ts.isPropertyAssignment(property) ||\n\t\t\t\t!ts.isIdentifier(property.name)\n\t\t\t) {\n\t\t\t\tthis.context.fail(property, \"fetch options require named properties.\");\n\t\t\t}\n\t\t\tif (property.name.text === \"method\") {\n\t\t\t\tconst value = staticString(this.context.checker, property.initializer);\n\t\t\t\tif (!isHttpMethod(value)) {\n\t\t\t\t\tthis.context.fail(property, \"Unsupported fetch method.\");\n\t\t\t\t}\n\t\t\t\tchosen.method = value;\n\t\t\t} else if (property.name.text === \"json\") {\n\t\t\t\tchosen.json = property.initializer;\n\t\t\t} else {\n\t\t\t\tthis.context.fail(property, \"Unsupported fetch option.\");\n\t\t\t}\n\t\t}\n\t\treturn chosen;\n\t}\n\n\t/** A json body's PLC record: the Request type argument, or the named type of the value. */\n\tprivate requestType(\n\t\tjson: ts.Expression,\n\t\trequest: ts.TypeNode | undefined,\n\t): string {\n\t\tif (request) {\n\t\t\treturn this.text(request);\n\t\t}\n\t\treturn (\n\t\t\tnamedRecordText(this.context.checker, json) ??\n\t\t\tthis.context.fail(\n\t\t\t\tjson,\n\t\t\t\t\"Annotate json with a named PLC record or supply the Request type argument.\",\n\t\t\t)\n\t\t);\n\t}\n\n\t/** `await job(...)` on a background task: borrow its mailbox until the result is taken. */\n\tprivate jobState({ awaited, call, target, next, reject }: Awaiting): number {\n\t\tconst receiver = this.rewrite(call.expression);\n\t\tconst borrow = `borrow${this.children.length}`;\n\t\tthis.children.push(`private ${this.naming.member(borrow)}:BOOL=false;`);\n\t\tthis.resets.push(`${this.self(borrow)}=false;`);\n\t\tthis.cancels.push(\n\t\t\t`if(${this.self(borrow)}){${receiver}.cancel();const borrowed=${receiver}.snapshot();if(!borrowed.valid||borrowed.busy)return;if(!${receiver}.reset())return;${this.self(borrow)}=false;}`,\n\t\t);\n\t\tconst poll = this.state(\n\t\t\tmapped`const borrowed=${receiver}.snapshot();if(borrowed.valid&&borrowed.done){if(${receiver}.reset()){${this.self(borrow)}=false;if(borrowed.error!==0){${reject(\"borrowed.error\", { cancellable: true })}}else{${target ? mapped`${target}=${this.awaitedValue(\"borrowed.result\", call)};` : \"\"}${this.self(\"step\")}=${next};}}}`,\n\t\t\tawaited,\n\t\t\t\"await\",\n\t\t\t{ yields: false },\n\t\t);\n\t\treturn this.state(\n\t\t\tmapped`const available=${receiver}.snapshot();if(!available.valid)return;if(available.busy||available.done){${reject(jobError.noRequestSlot, { cancellable: false })}}else{const accepted:BOOL=${receiver}.start(${joined(\n\t\t\t\tcall.arguments.map((argument) => this.rewrite(argument)),\n\t\t\t\t\",\",\n\t\t\t)});if(accepted){${this.self(borrow)}=true;${this.self(\"step\")}=${poll};}}`,\n\t\t\tawaited,\n\t\t\t\"await\",\n\t\t\t{ yields: true },\n\t\t);\n\t}\n\n\t/** `await instance.method(...)`: drive the async method's members on its block. */\n\tprivate methodState(\n\t\t{ awaited, call, target, next, reject }: Awaiting,\n\t\tmethod: MethodMembers,\n\t): number {\n\t\tif (!ts.isPropertyAccessExpression(call.expression)) {\n\t\t\tthis.context.fail(call, \"Async methods require a static receiver.\");\n\t\t}\n\t\tconst receiver = this.rewrite(call.expression.expression);\n\t\tconst borrow = `methodBorrow${this.children.length}`;\n\t\tthis.children.push(`private ${this.naming.member(borrow)}:BOOL=false;`);\n\t\tthis.resets.push(\n\t\t\t`if(${this.self(borrow)}){${receiver}.${method.reset}();${this.self(borrow)}=false;}`,\n\t\t);\n\t\tthis.cancels.push(\n\t\t\t`if(${this.self(borrow)}){${receiver}.${method.advance}({cancel:true});const cancellingChild=${receiver}.${method.snapshot}();if(cancellingChild.busy)return;${receiver}.${method.reset}();${this.self(borrow)}=false;}`,\n\t\t);\n\t\tconst poll = this.state(\n\t\t\tmapped`${receiver}.${method.advance}({cancel:false});const childState=${receiver}.${method.snapshot}();if(childState.done){${receiver}.${method.reset}();${this.self(borrow)}=false;if(childState.error!==0){${reject(\"childState.error\", { cancellable: true })}}else{${target ? mapped`${target}=${this.awaitedValue(\"childState.result\", call)};` : \"\"}${this.self(\"step\")}=${next};}}`,\n\t\t\tawaited,\n\t\t\t\"await\",\n\t\t\t{ yields: false },\n\t\t);\n\t\treturn this.state(\n\t\t\tmapped`const accepted:BOOL=${receiver}.${method.start}(${joined(\n\t\t\t\tcall.arguments.map((argument) => this.rewrite(argument)),\n\t\t\t\t\",\",\n\t\t\t)});if(!accepted){${reject(jobError.noRequestSlot, { cancellable: false })}}else{${this.self(borrow)}=true;${receiver}.${method.advance}({cancel:false});${this.self(\"step\")}=${poll};}`,\n\t\t\tawaited,\n\t\t\t\"await\",\n\t\t\t{ yields: true },\n\t\t);\n\t}\n\n\t/** `await helper(...)`: the helper's own coroutine block as a child. */\n\tprivate helperState({\n\t\tawaited,\n\t\tcall,\n\t\ttarget,\n\t\tnext,\n\t\treject,\n\t}: Awaiting): number {\n\t\tconst child = `child${this.children.length}`;\n\t\tif (!ts.isIdentifier(call.expression)) {\n\t\t\tthis.context.fail(call, \"Async helpers require a static function.\");\n\t\t}\n\t\tthis.children.push(\n\t\t\t`private ${this.naming.member(child)} = new ${this.text(call.expression)}();`,\n\t\t);\n\t\tthis.resets.push(`${this.self(child)}.reset();`);\n\t\tthis.cancels.push(\n\t\t\t`${this.self(child)}.update({cancel:true});const cancellingChild=${this.self(child)}.snapshot();if(cancellingChild.busy)return;`,\n\t\t);\n\t\tconst poll = this.state(\n\t\t\tmapped`${this.self(child)}.update({cancel:false}); const childState = ${this.self(child)}.snapshot(); if(childState.done) {if(childState.error !== 0) {${reject(\"childState.error\", { cancellable: true })}} else {${target ? mapped`${target} = ${this.awaitedValue(\"childState.result\", call)};` : \"\"}${this.self(\"step\")} = ${next};} }`,\n\t\t\tawaited,\n\t\t\t\"await\",\n\t\t\t{ yields: false },\n\t\t);\n\t\treturn this.state(\n\t\t\tmapped`const accepted:BOOL = ${this.self(child)}.start(${joined(\n\t\t\t\tcall.arguments.map((argument) => this.rewrite(argument)),\n\t\t\t\t\",\",\n\t\t\t)}); if(accepted){${this.self(child)}.update({cancel:false});${this.self(\"step\")} = ${poll};}`,\n\t\t\tawaited,\n\t\t\t\"await\",\n\t\t\t{ yields: true },\n\t\t);\n\t}\n\n\t/** Lowers statements back to front, so each knows the step that follows it; returns the first. */\n\tprivate block(\n\t\tstatements: readonly ts.Statement[],\n\t\tnext: number,\n\t\treject: Reject,\n\t): number {\n\t\treturn statements.reduceRight(\n\t\t\t(following, statement) => this.statement(statement, following, reject),\n\t\t\tnext,\n\t\t);\n\t}\n\n\tprivate statement(\n\t\tstatement: ts.Statement,\n\t\tnext: number,\n\t\treject: Reject,\n\t): number {\n\t\tconst { checker } = this.context;\n\t\tif (ts.isBlock(statement)) {\n\t\t\treturn this.block(statement.statements, next, reject);\n\t\t}\n\t\tif (ts.isIfStatement(statement)) {\n\t\t\tconst yes = this.block([statement.thenStatement], next, reject);\n\t\t\tconst no = statement.elseStatement\n\t\t\t\t? this.block([statement.elseStatement], next, reject)\n\t\t\t\t: next;\n\t\t\treturn this.state(\n\t\t\t\tmapped`if(${this.rewrite(statement.expression)}) ${this.self(\"step\")} = ${yes}; else ${this.self(\"step\")} = ${no};`,\n\t\t\t\tstatement.expression,\n\t\t\t\t\"statement\",\n\t\t\t\t{ yields: false },\n\t\t\t);\n\t\t}\n\t\tif (ts.isTryStatement(statement)) {\n\t\t\treturn this.tryStatement(statement, next, reject);\n\t\t}\n\t\tif (\n\t\t\tts.isIterationStatement(statement, false) &&\n\t\t\t!copiedWhole(statement, this.file.source)\n\t\t) {\n\t\t\treturn this.loop(statement, next, reject);\n\t\t}\n\t\tconst loop = this.loops.at(-1);\n\t\tif (loop && ts.isBreakOrContinueStatement(statement) && !statement.label) {\n\t\t\treturn this.state(\n\t\t\t\t`${this.self(\"step\")} = ${ts.isBreakStatement(statement) ? loop.breakStep : loop.continueStep};`,\n\t\t\t\tstatement,\n\t\t\t\t\"statement\",\n\t\t\t\t{ yields: false },\n\t\t\t);\n\t\t}\n\t\tif (ts.isThrowStatement(statement)) {\n\t\t\tif (\n\t\t\t\t!checker.isTypeAssignableTo(\n\t\t\t\t\tchecker.getTypeAtLocation(statement.expression),\n\t\t\t\t\tchecker.getNumberType(),\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthis.context.fail(\n\t\t\t\t\tstatement,\n\t\t\t\t\t\"Async throw requires a numeric error code.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\t// Only a literal code is checked; a computed one is the program's to keep out of the range.\n\t\t\tif (\n\t\t\t\tts.isNumericLiteral(statement.expression) &&\n\t\t\t\tNumber(statement.expression.text) >= reservedErrors.first &&\n\t\t\t\tNumber(statement.expression.text) <= reservedErrors.last\n\t\t\t) {\n\t\t\t\tthis.context.fail(\n\t\t\t\t\tstatement,\n\t\t\t\t\t`Error codes ${reservedErrors.first} to ${reservedErrors.last} are tsPLC's own; throw another code.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn this.state(\n\t\t\t\treject(this.rewrite(statement.expression), { cancellable: false }),\n\t\t\t\tstatement,\n\t\t\t\t\"throw\",\n\t\t\t\t{ yields: false },\n\t\t\t);\n\t\t}\n\t\tif (ts.isReturnStatement(statement)) {\n\t\t\treturn this.returnStatement(statement, reject);\n\t\t}\n\t\tif (ts.isVariableStatement(statement)) {\n\t\t\treturn [...statement.declarationList.declarations].reduceRight(\n\t\t\t\t(following, declaration) =>\n\t\t\t\t\tthis.localInitializer(declaration, following, reject),\n\t\t\t\tnext,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\tts.isExpressionStatement(statement) &&\n\t\t\tts.isAwaitExpression(statement.expression)\n\t\t) {\n\t\t\treturn this.awaitState(statement.expression, undefined, next, reject);\n\t\t}\n\t\tif (ts.isWhileStatement(statement) || ts.isDoStatement(statement)) {\n\t\t\tthis.context.fail(\n\t\t\t\tstatement,\n\t\t\t\t\"Unbounded loops are not supported in async routines.\",\n\t\t\t);\n\t\t}\n\t\t// `count++;` and `total += n;` are assignments, the one form a step's statement takes.\n\t\tconst text = ts.isExpressionStatement(statement)\n\t\t\t? mapped`${this.updateText(statement.expression)};`\n\t\t\t: this.rewrite(statement);\n\t\treturn this.state(\n\t\t\tmapped`${text} ${this.self(\"step\")} = ${next};`,\n\t\t\tstatement,\n\t\t\t\"statement\",\n\t\t\t{ yields: false },\n\t\t);\n\t}\n\n\t/**\n\t * A loop that suspends runs as steps: its test, its body's steps and its update, which leads back to\n\t * the test. Each scan takes a bounded number of steps, so its iterations spread across scans.\n\t */\n\tprivate loop(\n\t\tstatement: ts.IterationStatement,\n\t\tnext: number,\n\t\treject: Reject,\n\t): number {\n\t\tconst test = this.reserve(statement, \"statement\");\n\t\tconst update = this.loopUpdate(statement, test);\n\t\tthis.loops.push({ breakStep: next, continueStep: update });\n\t\tconst body = this.block([statement.statement], update, reject);\n\t\tthis.loops.pop();\n\t\tthis.fill(test, statement, this.loopTest(statement, body, next));\n\t\tif (ts.isDoStatement(statement)) {\n\t\t\treturn body;\n\t\t}\n\t\tif (ts.isForStatement(statement) && statement.initializer) {\n\t\t\tconst start = ts.isVariableDeclarationList(statement.initializer)\n\t\t\t\t? statement.initializer.declarations.reduceRight(\n\t\t\t\t\t\t(following, declaration) =>\n\t\t\t\t\t\t\tthis.localInitializer(declaration, following, reject),\n\t\t\t\t\t\ttest,\n\t\t\t\t\t)\n\t\t\t\t: this.state(\n\t\t\t\t\t\tmapped`${this.rewrite(statement.initializer)}; ${this.self(\"step\")} = ${test};`,\n\t\t\t\t\t\tstatement.initializer,\n\t\t\t\t\t\t\"statement\",\n\t\t\t\t\t\t{ yields: false },\n\t\t\t\t\t);\n\t\t\treturn start;\n\t\t}\n\t\treturn test;\n\t}\n\n\t/** The step that moves a loop on to its next iteration, then back to its test. */\n\tprivate loopUpdate(statement: ts.IterationStatement, test: number): number {\n\t\tif (ts.isForStatement(statement) && statement.incrementor) {\n\t\t\treturn this.state(\n\t\t\t\tmapped`${this.updateText(statement.incrementor)}; ${this.self(\"step\")} = ${test};`,\n\t\t\t\tstatement.incrementor,\n\t\t\t\t\"statement\",\n\t\t\t\t{ yields: false },\n\t\t\t);\n\t\t}\n\t\treturn test;\n\t}\n\n\t/** An update as an assignment, the one form a step's statement takes: `i++` is `i = i + 1`. */\n\tprivate updateText(incrementor: ts.Expression): Mapped {\n\t\tif (\n\t\t\t(ts.isPrefixUnaryExpression(incrementor) ||\n\t\t\t\tts.isPostfixUnaryExpression(incrementor)) &&\n\t\t\t(incrementor.operator === ts.SyntaxKind.PlusPlusToken ||\n\t\t\t\tincrementor.operator === ts.SyntaxKind.MinusMinusToken)\n\t\t) {\n\t\t\tconst target = this.rewrite(incrementor.operand);\n\t\t\treturn mapped`${target} = ${target} ${incrementor.operator === ts.SyntaxKind.PlusPlusToken ? \"+\" : \"-\"} 1`;\n\t\t}\n\t\tconst compound =\n\t\t\tts.isBinaryExpression(incrementor) &&\n\t\t\tcompoundSteps.get(incrementor.operatorToken.kind);\n\t\tif (ts.isBinaryExpression(incrementor) && compound) {\n\t\t\tconst target = this.rewrite(incrementor.left);\n\t\t\treturn mapped`${target} = ${target} ${compound} ${this.rewrite(incrementor.right)}`;\n\t\t}\n\t\treturn this.rewrite(incrementor);\n\t}\n\n\t/** The step a loop takes before each iteration: into its body while it goes on, else past it. */\n\tprivate loopTest(\n\t\tstatement: ts.IterationStatement,\n\t\tbody: number,\n\t\tnext: number,\n\t): Mapped {\n\t\tconst condition = loopCondition(statement);\n\t\tif (!condition) {\n\t\t\treturn mapped`${this.self(\"step\")} = ${body};`;\n\t\t}\n\t\treturn mapped`if (${this.rewrite(condition)}) ${this.self(\"step\")} = ${body}; else ${this.self(\"step\")} = ${next};`;\n\t}\n\n\t/** A step whose body is written once what follows it is known, as a loop's test is. */\n\tprivate reserve(origin: ts.Node, kind: Step[\"kind\"]): number {\n\t\treturn this.state(\"\", origin, kind, { yields: false });\n\t}\n\n\tprivate fill(step: number, origin: ts.Node, body: Part): void {\n\t\tthis.states.set(step, from(origin, body));\n\t}\n\n\t/** The field `collect` gave a local or caught error. */\n\tprivate local(declaration: ts.VariableDeclaration): Field {\n\t\tconst field = this.fields.get(this.declared(declaration.name));\n\t\tif (!field) {\n\t\t\tthrow new Error(\"Every async local is collected onto the block.\");\n\t\t}\n\t\treturn field;\n\t}\n\n\t/** A failure inside `try` moves to the catch steps with the error code; a cancel still fails. */\n\tprivate tryStatement(\n\t\tstatement: ts.TryStatement,\n\t\tnext: number,\n\t\treject: Reject,\n\t): number {\n\t\tconst clause = statement.catchClause;\n\t\tif (!clause) {\n\t\t\tthrow new Error(\"Control-flow lowering gives every async try a catch.\");\n\t\t}\n\t\tconst caught = this.block(clause.block.statements, next, reject);\n\t\tconst declaration = clause.variableDeclaration;\n\t\tconst field = declaration && this.local(declaration);\n\t\treturn this.block(\n\t\t\tstatement.tryBlock.statements,\n\t\t\tnext,\n\t\t\t(error, { cancellable }) => {\n\t\t\t\tconst recover = mapped`${field ? mapped`${this.self(field.name)} = ${error};` : \"\"}${this.self(\"step\")} = ${caught};`;\n\t\t\t\treturn cancellable\n\t\t\t\t\t? mapped`if(${error} === ${jobError.cancelled} || ${error} === ${jobError.codeChanged}) {${this.failure(error)}} else {${recover}}`\n\t\t\t\t\t: recover;\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate returnStatement(\n\t\tstatement: ts.ReturnStatement,\n\t\treject: Reject,\n\t): number {\n\t\tconst { checker } = this.context;\n\t\tif (!statement.expression) {\n\t\t\tif (!this.returnsVoid) {\n\t\t\t\tthis.context.fail(statement, \"Async routines must return a value.\");\n\t\t\t}\n\t\t\treturn this.state(this.finish(\"true\"), statement, \"return\", {\n\t\t\t\tyields: false,\n\t\t\t});\n\t\t}\n\t\t// Returning another routine's promise waits for it, as an await would.\n\t\tconst adopted =\n\t\t\tts.isCallExpression(statement.expression) &&\n\t\t\tchecker.getAwaitedType(\n\t\t\t\tchecker.getTypeAtLocation(statement.expression),\n\t\t\t) !== checker.getTypeAtLocation(statement.expression)\n\t\t\t\t? statement.expression\n\t\t\t\t: undefined;\n\t\tconst suspension = ts.isAwaitExpression(statement.expression)\n\t\t\t? statement.expression\n\t\t\t: adopted;\n\t\tif (!suspension) {\n\t\t\treturn this.state(\n\t\t\t\tthis.finish(this.rewrite(statement.expression)),\n\t\t\t\tstatement,\n\t\t\t\t\"return\",\n\t\t\t\t{ yields: false },\n\t\t\t);\n\t\t}\n\t\treturn this.awaitState(\n\t\t\tsuspension,\n\t\t\tthis.returnsVoid ? undefined : this.self(\"value\"),\n\t\t\tthis.state(\n\t\t\t\tthis.finish(this.returnsVoid ? \"true\" : this.self(\"value\")),\n\t\t\t\tstatement,\n\t\t\t\t\"return\",\n\t\t\t\t{ yields: false },\n\t\t\t),\n\t\t\treject,\n\t\t);\n\t}\n\n\tprivate localInitializer(\n\t\tdeclaration: ts.VariableDeclaration,\n\t\tnext: number,\n\t\treject: Reject,\n\t): number {\n\t\tconst field = this.local(declaration);\n\t\tconst { initializer } = declaration;\n\t\tif (!initializer) {\n\t\t\tthrow new Error(\"Every async local has an initializer.\");\n\t\t}\n\t\tconst target = this.self(field.name);\n\t\treturn ts.isAwaitExpression(initializer)\n\t\t\t? this.awaitState(initializer, target, next, reject)\n\t\t\t: this.state(\n\t\t\t\t\tmapped`${target} = ${copyValue(this.rewrite(initializer), field.aggregate)}; ${this.self(\"step\")} = ${next};`,\n\t\t\t\t\tdeclaration,\n\t\t\t\t\t\"statement\",\n\t\t\t\t\t{ yields: false },\n\t\t\t\t);\n\t}\n\n\t/** The code digest: the block's fields, its parameters, its steps and how it resets and cancels. */\n\tdigest(): number {\n\t\treturn codeDigest(\n\t\t\t[\n\t\t\t\tthis.fieldText(),\n\t\t\t\tthis.parameters.map((p) => `${p.field}:${p.type}`).join(\",\"),\n\t\t\t\tthis.entry,\n\t\t\t\tthis.table().text,\n\t\t\t\tthis.resets.join(\" \"),\n\t\t\t\tthis.cancels.join(\" \"),\n\t\t\t\t[...this.yielding].join(\",\"),\n\t\t\t].join(\"\\n\"),\n\t\t);\n\t}\n\n\t/** An async function's block: its exported type aliases, then a class of its members. */\n\tblockClass(code: number): Mapped {\n\t\tconst { fn, parameters } = this;\n\t\tconst returnType = this.returnType;\n\t\tconst exported = hasModifier(fn, ts.SyntaxKind.ExportKeyword)\n\t\t\t? \"export \"\n\t\t\t: \"\";\n\t\tconst aliases = this.context.aliases(fn);\n\t\tconst [start, reset, snapshot, execute] = this.methods(code);\n\t\treturn mapped`export type ${aliases.result} = ${returnType};\\n${parameters.map((p, i) => `export type ${aliases.argument(i)} = ${p.type};`).join(\"\\n\")}\\n${exported}class ${this.text(fn.name)} extends FunctionBlock<{cancel:BOOL}> {\n${this.fieldText()}\n${this.codeFields().join(\" \")}\n${start}\n${reset}\n${snapshot}\n${execute}\n\n}`;\n\t}\n\n\t/** An async method's members, one per line, for its own class. */\n\tmembers(code: number): Part[] {\n\t\treturn [\n\t\t\t...Object.values(this.fieldGroups()).flat(),\n\t\t\t...this.codeFields(),\n\t\t\t...this.methods(code),\n\t\t];\n\t}\n\n\t/** The state the steps keep, the routine's locals and its children. */\n\tprivate fieldGroups(): {\n\t\tstate: string[];\n\t\tlocals: string[];\n\t\tchildren: string[];\n\t} {\n\t\tconst returnType = this.returnType;\n\t\tconst field = (name: string, rest: string) =>\n\t\t\t`private ${this.naming.member(name)}${rest}`;\n\t\treturn {\n\t\t\tstate: [\n\t\t\t\t...Object.entries(jobStateFields).map(([name, type]) =>\n\t\t\t\t\tfield(name, `:${type}=${type === \"BOOL\" ? \"false\" : \"0\"};`),\n\t\t\t\t),\n\t\t\t\tfield(\"value\", `:${returnType}=defaultValue<${returnType}>();`),\n\t\t\t],\n\t\t\tlocals: [...this.fields.values()].map((local) =>\n\t\t\t\tfield(local.name, `:${local.type}=defaultValue<${local.type}>();`),\n\t\t\t),\n\t\t\tchildren: this.children,\n\t\t};\n\t}\n\n\t/**\n\t * The fields as a function's block declares them: the state on one line, then one per line.\n\t * The empty line before the children is where loops once kept their positions; it stays, as\n\t * the code digest is taken over this text.\n\t */\n\tprivate fieldText(): string {\n\t\tconst { state, locals, children } = this.fieldGroups();\n\t\treturn `${state.join(\" \")}\\n${locals.join(\"\\n\")}\\n\\n${children.join(\"\\n\")}`;\n\t}\n\n\t/** The digest of the code a job started with, and the error a job stops with. */\n\tprivate codeFields(): string[] {\n\t\treturn [\n\t\t\t`private ${this.naming.member(\"tsplcCode\")}:UDINT=0;`,\n\t\t\t`private ${this.naming.member(\"tsplcPending\")}:UDINT=0;`,\n\t\t];\n\t}\n\n\t/** Start, reset and snapshot, and the method that runs steps until one yields. */\n\tprivate methods(code: number): [string, string, string, Mapped] {\n\t\tconst { parameters, naming } = this;\n\t\tconst returnType = this.returnType;\n\t\tconst busy = this.self(\"busy\");\n\t\tconst done = this.self(\"done\");\n\t\tconst error = this.self(\"error\");\n\t\tconst step = this.self(\"step\");\n\t\tconst cancelling = this.self(\"cancelling\");\n\t\tconst pending = this.self(\"tsplcPending\");\n\t\tconst started = this.self(\"tsplcCode\");\n\t\tconst resets = this.resets.join(\" \");\n\t\tconst { cancelled, codeChanged } = jobError;\n\t\tconst table = this.table();\n\t\treturn [\n\t\t\t`${naming.entry(\"start\")}(${parameters.map((p) => `${p.name}:${p.type}`).join(\",\")}):BOOL {if(${busy} || ${done})return false; ${parameters.map((p) => `${this.self(p.field)} = ${copyValue(p.name, p.aggregate)};`).join(\" \")} ${resets} ${this.self(\"value\")} = defaultValue<${returnType}>(); ${error}=0;${cancelling}=false;${pending}=0;${started}=${code};${busy}=true;${done}=false;${step}=${this.entry};return true;}`,\n\t\t\t`${naming.entry(\"reset\")}():void {${resets} ${busy}=false;${cancelling}=false;${pending}=0;${done}=false;${error}=0;${step}=0;}`,\n\t\t\t`${naming.entry(\"snapshot\")}():{busy:BOOL;done:BOOL;error:UDINT;result:${returnType}} {if(${done}&&${started}!==${code}){return {busy:false,done:true,error:${codeChanged},result:defaultValue<${returnType}>()};}return {busy:${busy},done:${done},error:${error},result:${copyValue(this.self(\"value\"), this.resultAggregate)}};}`,\n\t\t\tmapped`${naming.entry(\"advance\")}(input:{cancel:BOOL}):void {if(!${busy})return;if(${started}!==${code}&&!${cancelling}){${pending}=${codeChanged};${cancelling}=true;}if(input.cancel)${cancelling}=true;if(${cancelling}){${this.cancels.map((cancel) => `{${cancel}}`).join(\" \")}if(${pending}===0)${pending}=${cancelled};${this.failure(pending)}return;}for(let transition:DINT=0;transition<${this.states.size + 1};transition++){const previous:UINT=${step};switch(${step}){${table}\ndefault: {${pending}=${codeChanged};${cancelling}=true;return;} }if(!${busy}||${step}===previous${[...this.yielding].map((id) => `||previous===${id}`).join(\"\")})return;}}`,\n\t\t];\n\t}\n\n\t/** The steps, each a case of the block's state machine. */\n\tprivate table(): Mapped {\n\t\treturn joined(\n\t\t\t[...this.states].map(\n\t\t\t\t([id, body]) => mapped`case ${id}: {${body}} break;`,\n\t\t\t),\n\t\t\t\"\\n\",\n\t\t);\n\t}\n}\n\n/** The condition a loop tests before each iteration; undefined when it has none. */\nconst loopCondition = (\n\tstatement: ts.IterationStatement,\n): ts.Expression | undefined => {\n\tif (ts.isForStatement(statement)) {\n\t\treturn statement.condition;\n\t}\n\tif (ts.isWhileStatement(statement) || ts.isDoStatement(statement)) {\n\t\treturn statement.expression;\n\t}\n\treturn undefined;\n};\n\n/** An awaited call and where its result goes. */\ninterface Awaiting {\n\tawaited: ts.AwaitExpression | ts.CallExpression;\n\tcall: ts.CallExpression;\n\ttarget: string | undefined;\n\tnext: number;\n\treject: Reject;\n}\n",
19
+ "import { jobError } from \"@tsplc/compiler/ir\";\nimport { mapped, type Part } from \"./positions\";\n\ninterface Parameter {\n\tname: string;\n\ttype: string;\n\taggregate: boolean;\n}\n/** A generated site: its members, its poll method, and what its own methods are called in an owner. */\nexport interface Site {\n\tbody: string;\n\tpoll: string;\n\trenames: ReadonlyMap<string, string>;\n}\ninterface Worker {\n\tstart: string;\n\tadvance: string;\n\tsnapshot: string;\n\treset: string;\n\tdeclaration: string;\n}\n\n/** The shared diagnostics instance that the promise pass declares and detached chains report failures to. */\nexport const diagnosticsInstance = \"tsplcPromiseDiagnostics\";\n/** The SDK's `wrapAdd` as the promise pass imports it into generated code. */\nexport const asyncWrapAdd = \"tsplcAsyncWrapAdd\";\n/** The SDK's `cooperativeTasks` as the promise pass imports it into generated code. */\nexport const cooperativeTasksAlias = \"tsplcCooperative\";\n/** The SDK's `errorCode` as the promise pass imports it into generated code. */\nexport const errorCodeAlias = \"tsplcErrorCode\";\n\n/** A value as generated code stores it: records and arrays are copied, as TypeScript would share them. */\nexport const copyValue = (value: Part, aggregate: boolean) =>\n\taggregate ? mapped`copy(${value})` : value;\n\n/** A fixed call-site frame; callbacks and ordinary state stay in the caller task. */\nexport const cooperativeSite = (\n\tname: string,\n\tparameters: readonly Parameter[],\n\tworker: Worker,\n\tinline: boolean,\n): Site => {\n\tconst prefix = inline ? name : \"site\";\n\tconst field = (label: string) => `${prefix}_${label}`;\n\tconst member = (label: string) => `this.${field(label)}`;\n\tconst method = (label: string) => (inline ? `${name}_${label}` : label);\n\tconst invoke = (label: string, args = \"\") => `this.${method(label)}(${args})`;\n\tconst faults = `${member(\"faults\")}=${asyncWrapAdd}<UDINT>(${member(\"faults\")},1);${member(\"lastError\")}=${jobError.noRequestSlot};`;\n\tconst signature = parameters\n\t\t.map((parameter) => `${parameter.name}:${parameter.type}`)\n\t\t.join(\",\");\n\tconst args = parameters.map((parameter) => parameter.name).join(\",\");\n\tconst queued = parameters\n\t\t.map((parameter) => member(`queued_${parameter.name}`))\n\t\t.join(\",\");\n\tconst fields = `private ${field(\"active\")}:BOOL=false;private ${field(\"fresh\")}:BOOL=false;private ${field(\"cancelled\")}:BOOL=false;private ${field(\"queued\")}:BOOL=false;private ${field(\"faults\")}:UDINT=0;private ${field(\"lastError\")}:UDINT=0;\n${parameters.map((parameter) => `private ${field(`queued_${parameter.name}`)}:${parameter.type}=defaultValue<${parameter.type}>();`).join(\"\\n\")}\n${worker.declaration}`;\n\tconst body = `${fields}\npublic ${method(\"begin\")}(${signature}):void{const accepted:BOOL=${worker.start}(${args});if(!accepted){${faults}return;}${member(\"active\")}=true;${member(\"fresh\")}=true;${member(\"cancelled\")}=false;${worker.advance}({cancel:false});}\npublic ${method(\"start\")}(${signature}):void{if(${member(\"active\")}){if(${member(\"cancelled\")}&&!${member(\"queued\")}){${parameters.map((parameter) => `${member(`queued_${parameter.name}`)}=${copyValue(parameter.name, parameter.aggregate)};`).join(\"\")}${member(\"queued\")}=true;}else{${faults}}return;}${invoke(\"begin\", args)};}\npublic ${method(\"cancel\")}():void{${member(\"cancelled\")}=true;${member(\"queued\")}=false;}\npublic ${method(\"poll\")}():void{\nif(${member(\"faults\")}>0&&${diagnosticsInstance}.report(${member(\"lastError\")},${member(\"faults\")}))${member(\"faults\")}=0;\nif(!${member(\"active\")})return;\nif(${member(\"fresh\")}&&!${member(\"cancelled\")}){${member(\"fresh\")}=false;return;}\n${worker.advance}({cancel:${member(\"cancelled\")}});const state=${worker.snapshot}();if(!state.done)return;\nif(!${member(\"cancelled\")}&&state.error!==0&&state.error!==${jobError.cancelled}){${member(\"faults\")}=${asyncWrapAdd}<UDINT>(${member(\"faults\")},1);${member(\"lastError\")}=state.error;}\n${worker.reset}();${member(\"active\")}=false;\nif(${member(\"queued\")}){${member(\"queued\")}=false;${invoke(\"begin\", queued)};}\n}`;\n\treturn {\n\t\tbody,\n\t\tpoll: method(\"poll\"),\n\t\trenames: new Map(\n\t\t\t[\"start\", \"cancel\"].map((member) => [member, method(member)]),\n\t\t),\n\t};\n};\n\n/** A named task: the owner reads its state and result instead of attaching a callback. */\nexport const taskSite = (\n\tname: string,\n\tparameters: readonly Parameter[],\n\tworker: Worker,\n\tinline: boolean,\n\tvalue: { type: string; aggregate: boolean },\n): Site => {\n\tconst method = (label: string) => (inline ? `${name}_${label}` : label);\n\tconst cancelledField = inline ? `${name}_cancelled` : \"cancelled\";\n\tconst cancelled = `this.${cancelledField}`;\n\tconst signature = parameters\n\t\t.map((parameter) => `${parameter.name}:${parameter.type}`)\n\t\t.join(\",\");\n\tconst args = parameters.map((parameter) => parameter.name).join(\",\");\n\tconst result = copyValue(\"state.result\", value.aggregate);\n\tconst body = `private ${cancelledField}:BOOL=false;\n${worker.declaration}\npublic ${method(\"start\")}(${signature}):BOOL{const accepted:BOOL=${worker.start}(${args});if(accepted){${cancelled}=false;${worker.advance}({cancel:false});}return accepted;}\npublic ${method(\"cancel\")}():BOOL{const state=${worker.snapshot}();if(!state.busy&&!state.done)return false;${cancelled}=true;return true;}\npublic ${method(\"snapshot\")}():{valid:BOOL;busy:BOOL;done:BOOL;cancelRequested:BOOL;error:UDINT;result:${value.type}}{const state=${worker.snapshot}();if(${cancelled}&&state.done)return {valid:true,busy:false,done:true,cancelRequested:false,error:${jobError.cancelled},result:defaultValue<${value.type}>()};return {valid:true,busy:state.busy,done:state.done,cancelRequested:${cancelled},error:state.error,result:${result}};}\npublic ${method(\"reset\")}():BOOL{const state=${worker.snapshot}();if(state.busy)return false;${worker.reset}();${cancelled}=false;return true;}\npublic ${method(\"poll\")}():void{${worker.advance}({cancel:${cancelled}});}`;\n\treturn {\n\t\tbody,\n\t\tpoll: method(\"poll\"),\n\t\trenames: new Map(\n\t\t\t[\"start\", \"cancel\", \"snapshot\", \"reset\"].map((member) => [\n\t\t\t\tmember,\n\t\t\t\tmethod(member),\n\t\t\t]),\n\t\t),\n\t};\n};\n",
20
+ "import type { SourceSpan } from \"@tsplc/compiler/ir\";\nimport type ts from \"typescript\";\n\n/**\n * Where a run of lowered text, `start`..`end`, came from. Copied text maps offset for offset\n * onto `from`..`to` of `file`; generated text maps as a whole to the node it was generated from.\n */\ninterface Segment {\n\tstart: number;\n\tend: number;\n\tfile: string;\n\tfrom: number;\n\tto: number;\n\tcopied: boolean;\n}\n\n/** Text a lowering pass writes, with the source each part of it came from. Segments are in order. */\nexport class Mapped {\n\tconstructor(\n\t\treadonly text: string,\n\t\treadonly segments: readonly Segment[] = [],\n\t) {}\n\n\ttoString(): string {\n\t\treturn this.text;\n\t}\n}\n\nexport type Part = string | number | Mapped;\n\nconst append = (segments: Segment[], text: Part, offset: number): void => {\n\tif (text instanceof Mapped) {\n\t\tfor (const segment of text.segments) {\n\t\t\tsegments.push({\n\t\t\t\t...segment,\n\t\t\t\tstart: segment.start + offset,\n\t\t\t\tend: segment.end + offset,\n\t\t\t});\n\t\t}\n\t}\n};\n\nexport const joined = (parts: readonly Part[], separator: string): Mapped => {\n\tlet text = \"\";\n\tconst segments: Segment[] = [];\n\tparts.forEach((part, index) => {\n\t\tif (index) {\n\t\t\ttext += separator;\n\t\t}\n\t\tappend(segments, part, text.length);\n\t\ttext += String(part);\n\t});\n\treturn new Mapped(text, segments);\n};\n\n/** A template tag that concatenates like a template literal and keeps the origins of `Mapped` parts. */\nexport const mapped = (\n\tstrings: TemplateStringsArray,\n\t...parts: readonly Part[]\n): Mapped =>\n\tjoined(\n\t\tstrings.flatMap((text, index): Part[] => {\n\t\t\tconst part = parts[index];\n\t\t\treturn part === undefined ? [text] : [text, part];\n\t\t}),\n\t\t\"\",\n\t);\n\nconst fill = (text: Part, file: string, from: number, to: number): Mapped => {\n\tconst value = text instanceof Mapped ? text : new Mapped(String(text));\n\tconst segments: Segment[] = [];\n\tlet cursor = 0;\n\tconst gap = (end: number) => {\n\t\tif (end > cursor) {\n\t\t\tsegments.push({ start: cursor, end, file, from, to, copied: false });\n\t\t}\n\t};\n\tfor (const segment of value.segments) {\n\t\tgap(segment.start);\n\t\tsegments.push(segment);\n\t\tcursor = segment.end;\n\t}\n\tgap(value.text.length);\n\treturn new Mapped(value.text, segments);\n};\n\n/** Text generated from a node: the parts without an origin of their own map to the node. */\nexport const from = (node: ts.Node, text: Part): Mapped => {\n\tconst source = node.getSourceFile();\n\treturn fill(text, source.fileName, node.getStart(source), node.end);\n};\n\n/** A node's source text, copied. */\nexport const copied = (node: ts.Node): Mapped => {\n\tconst source = node.getSourceFile();\n\treturn copiedRange(source, node.getStart(source), node.end);\n};\n\n/** A run of a source's text, copied. */\nexport const copiedRange = (\n\tsource: ts.SourceFile,\n\tstart: number,\n\tend: number,\n): Mapped =>\n\tnew Mapped(source.text.slice(start, end), [\n\t\t{\n\t\t\tstart: 0,\n\t\t\tend: end - start,\n\t\t\tfile: source.fileName,\n\t\t\tfrom: start,\n\t\t\tto: end,\n\t\t\tcopied: true,\n\t\t},\n\t]);\n\nexport const slice = (text: Mapped, start: number, end: number): Mapped => {\n\tconst segments: Segment[] = [];\n\tfor (const segment of text.segments) {\n\t\tif (segment.end <= start || segment.start >= end) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst first = Math.max(segment.start, start);\n\t\tconst last = Math.min(segment.end, end);\n\t\tsegments.push({\n\t\t\t...segment,\n\t\t\tstart: first - start,\n\t\t\tend: last - start,\n\t\t\t...(segment.copied && {\n\t\t\t\tfrom: segment.from + first - segment.start,\n\t\t\t\tto: segment.from + last - segment.start,\n\t\t\t}),\n\t\t});\n\t}\n\treturn new Mapped(text.text.slice(start, end), segments);\n};\n\nexport interface Edit {\n\tstart: number;\n\tend: number;\n\ttext: Part;\n}\n\n/**\n * Text with edits applied. Unedited text keeps its origin; the parts of an edit's text without an\n * origin of their own map to the text the edit replaces. Edits at one position apply last first.\n */\nexport const edited = (\n\tbase: ts.SourceFile | Mapped,\n\tedits: readonly Edit[],\n): Mapped => {\n\tconst text =\n\t\tbase instanceof Mapped\n\t\t\t? base\n\t\t\t: new Mapped(base.text, [\n\t\t\t\t\t{\n\t\t\t\t\t\tstart: 0,\n\t\t\t\t\t\tend: base.text.length,\n\t\t\t\t\t\tfile: base.fileName,\n\t\t\t\t\t\tfrom: 0,\n\t\t\t\t\t\tto: base.text.length,\n\t\t\t\t\t\tcopied: true,\n\t\t\t\t\t},\n\t\t\t\t]);\n\tconst ordered = edits\n\t\t.map((edit, index) => ({ edit, index }))\n\t\t.sort(\n\t\t\t(left, right) =>\n\t\t\t\tleft.edit.start - right.edit.start || right.index - left.index,\n\t\t);\n\tconst parts: Mapped[] = [];\n\tlet cursor = 0;\n\tfor (const { edit } of ordered) {\n\t\tif (edit.start > cursor) {\n\t\t\tparts.push(slice(text, cursor, edit.start));\n\t\t}\n\t\tconst origin = resolve(text.segments, edit.start, edit.end);\n\t\tparts.push(\n\t\t\torigin\n\t\t\t\t? fill(edit.text, origin.file, origin.from, origin.to)\n\t\t\t\t: mapped`${edit.text}`,\n\t\t);\n\t\tcursor = Math.max(cursor, edit.end);\n\t}\n\tparts.push(slice(text, cursor, text.text.length));\n\treturn joined(parts, \"\");\n};\n\n/** The first segment that ends after `offset`. */\nconst search = (segments: readonly Segment[], offset: number): number => {\n\tlet low = 0;\n\tlet high = segments.length;\n\twhile (low < high) {\n\t\tconst middle = (low + high) >> 1;\n\t\tconst segment = segments[middle];\n\t\tif (segment !== undefined && segment.end > offset) {\n\t\t\thigh = middle;\n\t\t} else {\n\t\t\tlow = middle + 1;\n\t\t}\n\t}\n\treturn low;\n};\n\n/** Where `start`..`end` of mapped text came from; a range across origins maps to its start's. */\nconst resolve = (\n\tsegments: readonly Segment[],\n\tstart: number,\n\tend: number,\n): { file: string; from: number; to: number } | undefined => {\n\tconst first = search(segments, start);\n\tconst head = segments[first];\n\tif (!head || head.start >= Math.max(end, start + 1)) {\n\t\treturn undefined;\n\t}\n\tconst candidate = end > start ? search(segments, end - 1) : first;\n\tconst last =\n\t\t(segments[candidate]?.start ?? end) >= end ? candidate - 1 : candidate;\n\tconst tail = (last > first && segments[last]) || head;\n\tconst from = head.copied\n\t\t? head.from + Math.max(0, start - head.start)\n\t\t: head.from;\n\tconst until = (segment: Segment) =>\n\t\tsegment.copied\n\t\t\t? segment.from + Math.min(end, segment.end) - segment.start\n\t\t\t: segment.to;\n\tconst to = until(tail);\n\tif (tail.file === head.file && to >= from) {\n\t\treturn { file: head.file, from, to };\n\t}\n\treturn { file: head.file, from, to: Math.max(from, until(head)) };\n};\n\n/** A source the program read, which every recorded segment's file is. */\nconst sourceOf = (program: ts.Program, file: string): ts.SourceFile => {\n\tconst source = program.getSourceFile(file);\n\tif (!source) {\n\t\tthrow new Error(`The lowered program does not include ${file}.`);\n\t}\n\treturn source;\n};\n\nconst excerptLength = 120;\n\n/** A span of a source as its text reads. */\nexport const sourceSpan = (\n\tsource: ts.SourceFile,\n\tstart: number,\n\tend: number,\n): SourceSpan => {\n\tconst position = source.getLineAndCharacterOfPosition(start);\n\treturn {\n\t\tfile: source.fileName,\n\t\tstart,\n\t\tend,\n\t\tline: position.line + 1,\n\t\tcolumn: position.character + 1,\n\t};\n};\n\n/**\n * Maps offsets in the sources the frontend reads, rewritten by any number of lowerings, back to the\n * files the user wrote. Each lowering's output is composed with the maps of the text it read.\n */\nexport class Positions {\n\tprivate readonly maps = new Map<string, readonly Segment[]>();\n\t/** The user's files as written, for positions in files lowering has since rewritten. */\n\tprivate readonly originals = new Map<string, ts.SourceFile>();\n\n\t/** Records a lowering's rewritten and generated sources; `program` is the program it read. */\n\trecord(sources: ReadonlyMap<string, Mapped>, program: ts.Program): void {\n\t\t// Every source of one lowering maps into the text it read, so compose them all before replacing any map.\n\t\tconst composed = new Map<string, Segment[]>();\n\t\tfor (const [file, text] of sources) {\n\t\t\tconst segments: Segment[] = [];\n\t\t\tfor (const segment of text.segments) {\n\t\t\t\tconst previous = this.maps.get(segment.file);\n\t\t\t\tif (!previous) {\n\t\t\t\t\tif (!this.originals.has(segment.file)) {\n\t\t\t\t\t\tthis.originals.set(segment.file, sourceOf(program, segment.file));\n\t\t\t\t\t}\n\t\t\t\t\tsegments.push(segment);\n\t\t\t\t} else if (segment.copied) {\n\t\t\t\t\tfor (\n\t\t\t\t\t\tlet index = search(previous, segment.from);\n\t\t\t\t\t\tindex < previous.length;\n\t\t\t\t\t\tindex++\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst inner = previous[index];\n\t\t\t\t\t\tif (!inner || inner.start >= segment.to) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst first = Math.max(inner.start, segment.from);\n\t\t\t\t\t\tconst last = Math.min(inner.end, segment.to);\n\t\t\t\t\t\tsegments.push({\n\t\t\t\t\t\t\tstart: segment.start + first - segment.from,\n\t\t\t\t\t\t\tend: segment.start + last - segment.from,\n\t\t\t\t\t\t\tfile: inner.file,\n\t\t\t\t\t\t\tfrom: inner.copied\n\t\t\t\t\t\t\t\t? inner.from + first - inner.start\n\t\t\t\t\t\t\t\t: inner.from,\n\t\t\t\t\t\t\tto: inner.copied ? inner.from + last - inner.start : inner.to,\n\t\t\t\t\t\t\tcopied: inner.copied,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst origin = resolve(previous, segment.from, segment.to);\n\t\t\t\t\tif (origin) {\n\t\t\t\t\t\tsegments.push({ ...segment, ...origin });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcomposed.set(file, segments);\n\t\t}\n\t\tfor (const [file, segments] of composed) {\n\t\t\tthis.maps.set(file, segments);\n\t\t}\n\t}\n\n\t/** The user's source and offsets that `start`..`end` of a source the frontend reads came from. */\n\tprivate origin(source: ts.SourceFile, start: number, end: number) {\n\t\tconst segments = this.maps.get(source.fileName);\n\t\tconst origin = segments && resolve(segments, start, end);\n\t\tif (!origin) {\n\t\t\treturn { source, from: start, to: end };\n\t\t}\n\t\tconst original = this.originals.get(origin.file);\n\t\tif (!original) {\n\t\t\tthrow new Error(`No source was recorded for ${origin.file}.`);\n\t\t}\n\t\treturn { source: original, from: origin.from, to: origin.to };\n\t}\n\n\treadonly span = (\n\t\tsource: ts.SourceFile,\n\t\tstart: number,\n\t\tend: number,\n\t): SourceSpan => {\n\t\tconst origin = this.origin(source, start, end);\n\t\treturn sourceSpan(origin.source, origin.from, origin.to);\n\t};\n\n\treadonly node = (node: ts.Node): SourceSpan => {\n\t\tconst source = node.getSourceFile();\n\t\treturn this.span(source, node.getStart(source), node.end);\n\t};\n\n\t/** The user's text a node came from, on one line and at most `excerptLength` characters. */\n\texcerpt(node: ts.Node): string {\n\t\tconst source = node.getSourceFile();\n\t\tconst origin = this.origin(source, node.getStart(source), node.end);\n\t\tconst text = origin.source.text\n\t\t\t.slice(origin.from, origin.to)\n\t\t\t.replace(/\\s+/g, \" \")\n\t\t\t.trim();\n\t\treturn text.length > excerptLength\n\t\t\t? `${text.slice(0, excerptLength - 1)}…`\n\t\t\t: text;\n\t}\n}\n",
21
+ "import { resolve } from \"node:path\";\nimport { jobError } from \"@tsplc/compiler/ir\";\nimport { taskPriority } from \"@tsplc/config/build\";\nimport ts from \"typescript\";\nimport type { AsyncContext, SourceRewrite } from \"./async\";\nimport { cooperativeSite, copyValue, type Site, taskSite } from \"./cooperative\";\nimport { durationScales, literalDuration } from \"./intrinsics\";\nimport { loweringKey } from \"./lowering-key\";\nimport type { NamedRoutine } from \"./module-graph\";\nimport { from } from \"./positions\";\nimport { isAggregateType, promisedType } from \"./types\";\n\n/** A `<tasks>.define(...)` initializer, the declaration holding it, and that declaration's block. */\ninterface TaskDefinition {\n\tdeclaration: ts.VariableDeclaration | ts.PropertyDeclaration;\n\tinit: ts.CallExpression;\n\towner: ts.ClassLikeDeclaration | undefined;\n}\n\nconst taskCollections = [\n\t\"tasks\",\n\t\"cooperativeTasks\",\n\t\"backgroundTasks\",\n] as const;\ntype TaskCollection = (typeof taskCollections)[number];\n\n/** The SDK task collection a `<tasks>.define(...)` initializer defines a task on, and the call. */\nconst definedTask = (\n\tcontext: Pick<AsyncContext, \"namesSdk\">,\n\tnode: ts.Expression | undefined,\n): { collection: TaskCollection; init: ts.CallExpression } | undefined => {\n\tif (\n\t\t!node ||\n\t\t!ts.isCallExpression(node) ||\n\t\t!ts.isPropertyAccessExpression(node.expression) ||\n\t\tnode.expression.name.text !== \"define\"\n\t) {\n\t\treturn undefined;\n\t}\n\tconst receiver = node.expression.expression;\n\tconst collection = taskCollections.find((name) =>\n\t\tcontext.namesSdk(receiver, name),\n\t);\n\treturn collection && { collection, init: node };\n};\n\n/** The `backgroundTasks.define(...)` call that initializes the variable or field `symbol` names, if it is one. */\nexport const backgroundJob = (\n\tcontext: Pick<AsyncContext, \"namesSdk\">,\n\tsymbol: ts.Symbol | undefined,\n): ts.CallExpression | undefined => {\n\tconst declaration = symbol?.declarations?.find(\n\t\t(node): node is ts.VariableDeclaration | ts.PropertyDeclaration =>\n\t\t\tts.isVariableDeclaration(node) || ts.isPropertyDeclaration(node),\n\t);\n\tconst task = definedTask(context, declaration?.initializer);\n\treturn task?.collection === \"backgroundTasks\" ? task.init : undefined;\n};\n\n/**\n * Lowers `tasks.define`, `cooperativeTasks.define` and `backgroundTasks.define` in one\n * source: each becomes a generated site or mailbox block, with the entry points that run it.\n */\nexport function lowerTaskDefinitions(\n\tcontext: AsyncContext,\n\tfile: SourceRewrite,\n): void {\n\tfor (const declaration of declarations(file.source)) {\n\t\tconst task = definedTask(context, declaration.initializer);\n\t\tif (!task) {\n\t\t\tcontinue;\n\t\t}\n\t\t// A module's task nothing starts has no scan task to run it in, so it is left out.\n\t\tconst statement = declaration.parent.parent;\n\t\tif (\n\t\t\ttask.collection === \"tasks\" &&\n\t\t\tts.isVariableDeclaration(declaration) &&\n\t\t\tts.isVariableStatement(statement) &&\n\t\t\tstatement.declarationList.declarations.length === 1 &&\n\t\t\t!context.referenced(declaration)\n\t\t) {\n\t\t\tfile.replacements.push({\n\t\t\t\tstart: statement.getStart(file.source),\n\t\t\t\tend: statement.end,\n\t\t\t\ttext: \"\",\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tconst definition = {\n\t\t\tdeclaration,\n\t\t\tinit: task.init,\n\t\t\towner: ts.isPropertyDeclaration(declaration)\n\t\t\t\t? declaration.parent\n\t\t\t\t: undefined,\n\t\t};\n\t\tswitch (task.collection) {\n\t\t\tcase \"tasks\":\n\t\t\t\ttaskDefinition(context, file, definition);\n\t\t\t\tbreak;\n\t\t\tcase \"cooperativeTasks\":\n\t\t\t\tcooperativeDefinition(context, file, definition);\n\t\t\t\tbreak;\n\t\t\tcase \"backgroundTasks\":\n\t\t\t\tbackgroundDefinition(context, file, definition);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n/** Module variables and block fields, where task definitions live. */\nconst declarations = (source: ts.SourceFile) =>\n\tsource.statements.flatMap<ts.VariableDeclaration | ts.PropertyDeclaration>(\n\t\t(statement) => {\n\t\t\tif (ts.isVariableStatement(statement)) {\n\t\t\t\treturn [...statement.declarationList.declarations];\n\t\t\t}\n\t\t\tif (ts.isClassDeclaration(statement)) {\n\t\t\t\treturn statement.members.filter(ts.isPropertyDeclaration);\n\t\t\t}\n\t\t\treturn [];\n\t\t},\n\t);\n\n/** `tasks.define(work)`: a task the owner starts, polls and reads, with no callback. */\nfunction taskDefinition(\n\tcontext: AsyncContext,\n\tfile: SourceRewrite,\n\tdefinition: TaskDefinition,\n): void {\n\tconst { declaration, init, owner } = definition;\n\tconst [work, ...rest] = init.arguments;\n\tconst symbol = context.symbol(work ?? init);\n\tconst fn = symbol && context.functions.get(symbol);\n\tif (!ts.isIdentifier(declaration.name) || !work || rest.length || !fn?.type) {\n\t\tcontext.fail(\n\t\t\tinit,\n\t\t\t\"tasks.define requires one named async function with a return type.\",\n\t\t);\n\t}\n\tconst { params, valueType, valueAggregate } = workTypes(\n\t\tcontext,\n\t\tfile,\n\t\tfn,\n\t\tdeclaration,\n\t);\n\tconst worker = context.names.name(\"tsplcTaskWorker\", declaration);\n\tconst receiver = `this.${worker}`;\n\tconst site = taskSite(\n\t\tdeclaration.name.text,\n\t\tparams,\n\t\t{\n\t\t\tstart: `${receiver}.start`,\n\t\t\tadvance: `${receiver}.update`,\n\t\t\tsnapshot: `${receiver}.snapshot`,\n\t\t\treset: `${receiver}.reset`,\n\t\t\tdeclaration: `private ${worker}=new ${work.getText(file.source)}();`,\n\t\t},\n\t\tBoolean(owner),\n\t\t{ type: valueType, aggregate: valueAggregate },\n\t);\n\tplaceSite(context, file, definition, declaration.name.text, site, {\n\t\tsiteClass: \"TsplcTaskSite\",\n\t\tunnamedOwner: \"Task owners require a named block.\",\n\t});\n}\n\n/** `cooperativeTasks.define(work)`: a continuation slot the compiler polls for its owner. */\nfunction cooperativeDefinition(\n\tcontext: AsyncContext,\n\tfile: SourceRewrite,\n\tdefinition: TaskDefinition,\n): void {\n\tconst { declaration, init, owner } = definition;\n\tconst [work, ...rest] = init.arguments;\n\tif (!ts.isIdentifier(declaration.name) || !work || rest.length) {\n\t\tcontext.fail(init, \"Invalid compiler-owned continuation slot.\");\n\t}\n\tconst symbol = context.symbol(\n\t\tts.isPropertyAccessExpression(work) ? work.name : work,\n\t);\n\tconst routine = symbol && context.functions.get(symbol);\n\tif (!routine) {\n\t\tcontext.fail(work, \"A continuation requires a named async routine.\");\n\t}\n\tconst params = routine.parameters.map((parameter, index) => ({\n\t\tname: `argument${index}`,\n\t\ttype: parameterType(context, parameter),\n\t\taggregate: isAggregateType(context.checker.getTypeAtLocation(parameter)),\n\t}));\n\t// An async method runs as members of the owner itself; a helper runs in its own block.\n\tconst method = context.methods.get(symbol);\n\tconst worker = context.names.name(\"tsplcCooperativeWorker\", declaration);\n\tconst receiver = method ? \"this\" : `this.${worker}`;\n\tconst site = cooperativeSite(\n\t\tdeclaration.name.text,\n\t\tparams,\n\t\t{\n\t\t\tstart: `${receiver}.${method?.start ?? \"start\"}`,\n\t\t\tadvance: `${receiver}.${method?.advance ?? \"update\"}`,\n\t\t\tsnapshot: `${receiver}.${method?.snapshot ?? \"snapshot\"}`,\n\t\t\treset: `${receiver}.${method?.reset ?? \"reset\"}`,\n\t\t\tdeclaration: method\n\t\t\t\t? \"\"\n\t\t\t\t: `private ${worker}=new ${work.getText(file.source)}();`,\n\t\t},\n\t\tBoolean(owner),\n\t);\n\tplaceSite(context, file, definition, declaration.name.text, site, {\n\t\tsiteClass: \"TsplcCooperativeSite\",\n\t\tunnamedOwner: \"Continuation owners require a named block.\",\n\t});\n}\n\n/**\n * A site defined in a block replaces its field, is polled through the block's instances, and\n * takes calls to its members through the field. A module-level site gets its own block and a\n * continuation entry that polls it.\n */\nfunction placeSite(\n\tcontext: AsyncContext,\n\tfile: SourceRewrite,\n\t{ declaration, init, owner }: TaskDefinition,\n\tname: string,\n\tsite: Site,\n\t{ siteClass, unnamedOwner }: { siteClass: string; unnamedOwner: string },\n): void {\n\tconst { source, replacements, extra } = file;\n\tif (owner) {\n\t\tconst block = owner.name && context.symbol(owner.name);\n\t\tif (!block) {\n\t\t\tcontext.fail(owner, unnamedOwner);\n\t\t}\n\t\treplacements.push({\n\t\t\tstart: declaration.getStart(source),\n\t\t\tend: declaration.end,\n\t\t\ttext: site.body,\n\t\t});\n\t\tfile.ownedPolls.set(block, [\n\t\t\t...(file.ownedPolls.get(block) ?? []),\n\t\t\tsite.poll,\n\t\t]);\n\t\tconst field = context.symbol(declaration.name);\n\t\tconst visit = (node: ts.Node): void => {\n\t\t\tif (\n\t\t\t\tts.isCallExpression(node) &&\n\t\t\t\tts.isPropertyAccessExpression(node.expression) &&\n\t\t\t\tts.isPropertyAccessExpression(node.expression.expression) &&\n\t\t\t\tnode.expression.expression.expression.kind ===\n\t\t\t\t\tts.SyntaxKind.ThisKeyword &&\n\t\t\t\tcontext.symbol(node.expression.expression.name) === field\n\t\t\t) {\n\t\t\t\tconst renamed = site.renames.get(node.expression.name.text);\n\t\t\t\tif (renamed) {\n\t\t\t\t\treplacements.push({\n\t\t\t\t\t\tstart: node.expression.getStart(source),\n\t\t\t\t\t\tend: node.expression.end,\n\t\t\t\t\t\ttext: `this.${renamed}`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tts.forEachChild(node, visit);\n\t\t};\n\t\tvisit(owner);\n\t\treturn;\n\t}\n\tconst block = context.names.name(siteClass, declaration);\n\tconst entry = context.names.name(\"tsplcContinuation\", declaration);\n\textra.push(\n\t\tfrom(\n\t\t\tdeclaration,\n\t\t\t`class ${block} extends FunctionBlock<{}>{${site.body}protected execute(input:{}):void{}}\nexport function ${entry}():void{${name}.poll();}`,\n\t\t),\n\t);\n\treplacements.push({\n\t\tstart: init.getStart(source),\n\t\tend: init.end,\n\t\ttext: `new ${block}()`,\n\t});\n\tfile.programs[entry] = { module: resolve(source.fileName), export: entry };\n\tfile.continuations.set(entry, {\n\t\tinstance: name,\n\t\tfile: context.positions.node(declaration).file,\n\t});\n}\n\n/** `backgroundTasks.define(work, { interval, priority })`: a mailbox a scheduled task serves. */\nfunction backgroundDefinition(\n\tcontext: AsyncContext,\n\tfile: SourceRewrite,\n\tdefinition: TaskDefinition,\n): void {\n\tconst { declaration, init, owner } = definition;\n\tconst { source, replacements, extra } = file;\n\tconst [work, options, ...rest] = init.arguments;\n\tif (\n\t\t!ts.isIdentifier(declaration.name) ||\n\t\t!work ||\n\t\t!options ||\n\t\trest.length ||\n\t\t!ts.isObjectLiteralExpression(options)\n\t) {\n\t\tcontext.fail(\n\t\t\tdeclaration,\n\t\t\t\"Define background tasks at module scope or as function-block fields with a named async function and scheduling options.\",\n\t\t);\n\t}\n\tconst symbol = context.symbol(work);\n\tconst fn = symbol && context.functions.get(symbol);\n\tif (!fn?.type || !ts.isTypeReferenceNode(fn.type)) {\n\t\tcontext.fail(\n\t\t\tinit,\n\t\t\t\"backgroundTasks.define requires a named async function.\",\n\t\t);\n\t}\n\tconst { params, valueType, valueAggregate } = workTypes(\n\t\tcontext,\n\t\tfile,\n\t\tfn,\n\t\tdeclaration,\n\t);\n\tconst mailbox = context.names.name(\"TsplcMailbox\", declaration);\n\tconst worker = context.names.name(\"tsplcWorker\", declaration);\n\tconst entry = context.names.name(\"tsplcBackground\", declaration);\n\tconst requestType = `{ready:BOOL;${params.map((p) => `${p.field}:${p.type}`).join(\";\")}}`;\n\tconst snapshotType = `{valid:BOOL;busy:BOOL;done:BOOL;cancelRequested:BOOL;error:UDINT;result:${valueType}}`;\n\tconst emptySnapshot = `{valid:true,busy:this.pending || this.active,done:this.completed,cancelRequested:this.cancelRequested,error:this.failure,result:${copyValue(\"this.value\", valueAggregate)}}`;\n\textra.push(\n\t\tfrom(\n\t\t\tdeclaration,\n\t\t\t`class ${mailbox} extends FunctionBlock<{}> {\nprivate pending:BOOL=false;private active:BOOL=false;private completed:BOOL=false;private cancelRequested:BOOL=false;private failure:UDINT=0;private value:${valueType}=defaultValue<${valueType}>();\n${params.map((p) => `private ${p.field}:${p.type}=defaultValue<${p.type}>();`).join(\"\\n\")}\nstart(${params.map((p) => `${p.name}:${p.type}`).join(\",\")}):BOOL {if(this.pending || this.active || this.completed)return false;${params.map((p) => `this.${p.field}=${copyValue(p.name, p.aggregate)};`).join(\"\")}this.pending=true;return true;}\ntake():${requestType} {const ready:BOOL=this.pending; if(ready){this.pending=false;this.active=true;}return {ready,${params.map((p) => `${p.field}:${copyValue(`this.${p.field}`, p.aggregate)}`).join(\",\")}};}\npublish(value:${valueType},error:UDINT):BOOL {if(!this.active)return false;if(this.cancelRequested){this.value=defaultValue<${valueType}>();this.failure=${jobError.cancelled};}else{this.value=${copyValue(\"value\", valueAggregate)};this.failure=error;}this.active=false;this.completed=true;this.cancelRequested=false;return true;}\nsnapshot():${snapshotType} {return ${emptySnapshot};}\ncancel():BOOL {if(this.pending){this.pending=false;this.completed=true;this.failure=${jobError.cancelled};return true;}if(this.active){this.cancelRequested=true;return true;}return false;}\nreset():BOOL {if(this.pending || this.active)return false;this.completed=false;this.failure=0;this.cancelRequested=false;this.value=defaultValue<${valueType}>();return true;}\nprotected execute(input:{}):void {}\n}\n`,\n\t\t),\n\t);\n\tconst receiver = owner\n\t\t? `this.${declaration.name.text}`\n\t\t: declaration.name.text;\n\tconst workerReceiver = owner ? `this.${worker}` : worker;\n\tconst run = `const request=${receiver}.take();if(request.ready){const accepted:BOOL=${workerReceiver}.start(${params.map((p) => `request.${p.field}`).join(\",\")});}const control=${receiver}.snapshot();if(!control.valid)return;${workerReceiver}.update({cancel:control.cancelRequested});const state=${workerReceiver}.snapshot();if(state.done){const published:BOOL=${receiver}.publish(state.result,state.error);if(published)${workerReceiver}.reset();}`;\n\tconst block = owner?.name && context.symbol(owner.name);\n\tif (owner) {\n\t\tif (!owner.name || !block) {\n\t\t\tcontext.fail(owner, \"Background job owners need a named function block.\");\n\t\t}\n\t\treplacements.push({\n\t\t\tstart: owner.end - 1,\n\t\t\tend: owner.end - 1,\n\t\t\ttext: from(\n\t\t\t\tdeclaration,\n\t\t\t\t`private ${worker}=new ${work.getText(source)}();public ${entry}():void{${run}}`,\n\t\t\t),\n\t\t});\n\t\tfile.blocks.set(loweringKey(source.fileName, owner.name.text), {\n\t\t\tkind: \"backgroundHost\",\n\t\t});\n\t} else {\n\t\textra.push(\n\t\t\tfrom(\n\t\t\t\tdeclaration,\n\t\t\t\t`const ${worker}=new ${work.getText(source)}();export function ${entry}():void{${run}}`,\n\t\t\t),\n\t\t);\n\t}\n\tfile.blocks.set(loweringKey(source.fileName, mailbox), {\n\t\tkind: \"mailbox\",\n\t});\n\tconst schedule = {\n\t\t...scheduleTiming(context, source, init, options),\n\t\tmailbox: declaration.name.text,\n\t\tworker,\n\t};\n\tif (block) {\n\t\tfile.ownedJobs.set(block, [\n\t\t\t...(file.ownedJobs.get(block) ?? []),\n\t\t\t{ method: entry, schedule },\n\t\t]);\n\t} else {\n\t\tfile.programs[entry] = { module: resolve(source.fileName), export: entry };\n\t\tfile.schedules.set(entry, schedule);\n\t}\n\treplacements.push({\n\t\tstart: init.getStart(source),\n\t\tend: init.end,\n\t\ttext: `new ${mailbox}()`,\n\t});\n}\n\n/** The literal `interval: ms(n)` or `seconds(n)` and `priority` a background task runs at. */\nfunction scheduleTiming(\n\tcontext: AsyncContext,\n\tsource: ts.SourceFile,\n\tinit: ts.CallExpression,\n\toptions: ts.ObjectLiteralExpression,\n): { intervalNanoseconds: string; priority: number } {\n\tconst properties = new Map(\n\t\toptions.properties\n\t\t\t.filter(ts.isPropertyAssignment)\n\t\t\t.map((property) => [property.name.getText(source), property.initializer]),\n\t);\n\tconst interval = properties.get(\"interval\");\n\tconst priority = properties.get(\"priority\");\n\tconst [amount, ...rest] =\n\t\tinterval && ts.isCallExpression(interval) ? interval.arguments : [];\n\tconst unit =\n\t\tinterval &&\n\t\tts.isCallExpression(interval) &&\n\t\t[\"ms\", \"seconds\"].find((name) =>\n\t\t\tcontext.namesSdk(interval.expression, name),\n\t\t);\n\tconst scale = unit && durationScales.get(unit);\n\tif (\n\t\t!scale ||\n\t\t!amount ||\n\t\trest.length ||\n\t\t!ts.isNumericLiteral(amount) ||\n\t\t!priority ||\n\t\t!ts.isNumericLiteral(priority)\n\t) {\n\t\tcontext.fail(\n\t\t\tinit,\n\t\t\t\"Background schedules require a literal ms/seconds interval and priority.\",\n\t\t);\n\t}\n\tconst period = literalDuration(amount.text, scale);\n\tconst level = Number(priority.text);\n\tif (\n\t\tperiod?.kind !== \"duration\" ||\n\t\tperiod.nanoseconds === \"0\" ||\n\t\t!taskPriority.safeParse(level).success ||\n\t\t// CODESYS runs priority 0 ahead of everything; a background task stays below it, so a scan\n\t\t// task can always be given a higher priority than the background work it hands off.\n\t\tlevel < 1\n\t) {\n\t\tcontext.fail(\n\t\t\tinit,\n\t\t\t`Background interval must be positive and priority must be an integer in 1..${taskPriority.maxValue}.`,\n\t\t);\n\t}\n\treturn {\n\t\tintervalNanoseconds: period.nanoseconds,\n\t\tpriority: level,\n\t};\n}\n\n/**\n * The argument and result types a definition's worker routine has, as its defining module\n * can name them.\n */\nfunction workTypes(\n\tcontext: AsyncContext,\n\tfile: SourceRewrite,\n\tfn: NamedRoutine,\n\tdeclaration: ts.VariableDeclaration | ts.PropertyDeclaration,\n) {\n\tconst { checker } = context;\n\tconst result = fn.type && promisedType(fn.type);\n\tconst signature = checker.getSignatureFromDeclaration(fn);\n\tconst promised =\n\t\tsignature &&\n\t\tchecker.getAwaitedType(checker.getReturnTypeOfSignature(signature));\n\tif (!result || !promised) {\n\t\tcontext.fail(\n\t\t\tfn,\n\t\t\t\"Async functions require concrete parameters and an explicit Promise<T> result.\",\n\t\t);\n\t}\n\tconst returnType =\n\t\tresult.kind === ts.SyntaxKind.VoidKeyword\n\t\t\t? \"BOOL\"\n\t\t\t: result.getText(fn.getSourceFile());\n\tconst valueAggregate = isAggregateType(promised);\n\tconst parameter = (\n\t\tnode: ts.ParameterDeclaration,\n\t\tindex: number,\n\t\ttype: string,\n\t) => ({\n\t\tfield: `argument${index}`,\n\t\tname: `argument${index}`,\n\t\taggregate: isAggregateType(checker.getTypeAtLocation(node)),\n\t\ttype,\n\t});\n\tif (fn.getSourceFile() === file.source) {\n\t\t// The annotations keep the PLC widths the TypeScript checker erases.\n\t\treturn {\n\t\t\tparams: fn.parameters.map((node, index) =>\n\t\t\t\tparameter(node, index, parameterType(context, node)),\n\t\t\t),\n\t\t\tvalueType: returnType,\n\t\t\tvalueAggregate,\n\t\t};\n\t}\n\tconst aliases = context.aliases(fn);\n\tconst params = fn.parameters.map((node, index) =>\n\t\tparameter(node, index, aliases.argument(index)),\n\t);\n\tconst valueType = aliases.result;\n\tcontext.importAliases(file, declaration, fn, [\n\t\tvalueType,\n\t\t...params.map((param) => param.type),\n\t]);\n\treturn { params, valueType, valueAggregate };\n}\n\n/** An async routine's parameter type as its module writes it. */\nconst parameterType = (\n\tcontext: AsyncContext,\n\tparameter: ts.ParameterDeclaration,\n): string => {\n\tif (!parameter.type) {\n\t\tcontext.fail(\n\t\t\tparameter,\n\t\t\t\"Async parameters require explicit concrete value types.\",\n\t\t);\n\t}\n\treturn parameter.type.getText(parameter.getSourceFile());\n};\n",
22
+ "import { identityDigest } from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport { modulePath } from \"./lowering-key\";\n\n/**\n * Names for what lowering generates, each a fixed function of the source node it stands for: its\n * module, the declarations around it, and its ordinal among the nodes with the same key in the\n * innermost one. An edit elsewhere then never renames it, so an online change finds its state\n * where it left it; counting generated objects across the program renamed them all.\n */\nexport class GeneratedNames {\n\tconstructor(private readonly root: string) {}\n\n\t/** `base` followed by the digest of `node`'s identity. */\n\tname(base: string, node: ts.Node): string {\n\t\treturn `${base}_${identityDigest(this.identity(node))}`;\n\t}\n\n\tprivate identity(node: ts.Node): string {\n\t\tconst source = node.getSourceFile();\n\t\tconst module = modulePath(this.root, source.fileName);\n\t\tconst scopes = enclosingDeclarations(node);\n\t\tconst scope = scopes.at(-1)?.node ?? source;\n\t\tconst key = nodeKey(node, source);\n\t\tconst ordinal = sameKey(scope, key, source).indexOf(node);\n\t\treturn [\n\t\t\tmodule,\n\t\t\t...scopes.map((declaration) => declaration.name),\n\t\t\t`${key}#${ordinal}`,\n\t\t].join(\"\\0\");\n\t}\n}\n\n/** A call is told apart by its callee, a declaration by its name, anything else by its syntax. */\nconst nodeKey = (node: ts.Node, source: ts.SourceFile): string => {\n\tif (ts.isCallExpression(node)) {\n\t\treturn `call ${node.expression.getText(source)}`;\n\t}\n\tconst name = declarationName(node);\n\treturn name === undefined\n\t\t? ts.SyntaxKind[node.kind]\n\t\t: `${ts.SyntaxKind[node.kind]} ${name}`;\n};\n\n/** The nodes under `scope` with `key`, in source order. */\nconst sameKey = (\n\tscope: ts.Node,\n\tkey: string,\n\tsource: ts.SourceFile,\n): ts.Node[] => {\n\tconst found: ts.Node[] = [];\n\tconst visit = (node: ts.Node) => {\n\t\tif (nodeKey(node, source) === key) {\n\t\t\tfound.push(node);\n\t\t}\n\t\tts.forEachChild(node, visit);\n\t};\n\tts.forEachChild(scope, visit);\n\treturn found;\n};\n\nconst declarationName = (node: ts.Node): string | undefined => {\n\tif (\n\t\t(ts.isClassDeclaration(node) ||\n\t\t\tts.isFunctionDeclaration(node) ||\n\t\t\tts.isMethodDeclaration(node) ||\n\t\t\tts.isPropertyDeclaration(node) ||\n\t\t\tts.isGetAccessorDeclaration(node) ||\n\t\t\tts.isSetAccessorDeclaration(node) ||\n\t\t\tts.isVariableDeclaration(node) ||\n\t\t\tts.isInterfaceDeclaration(node) ||\n\t\t\tts.isTypeAliasDeclaration(node)) &&\n\t\tnode.name &&\n\t\t(ts.isIdentifier(node.name) || ts.isStringLiteral(node.name))\n\t) {\n\t\treturn node.name.text;\n\t}\n\tif (ts.isConstructorDeclaration(node)) {\n\t\treturn \"constructor\";\n\t}\n\treturn undefined;\n};\n\n/** The named declarations around `node`, outermost first. */\nconst enclosingDeclarations = (\n\tnode: ts.Node,\n): { name: string; node: ts.Node }[] => {\n\tconst parent = node.parent;\n\tif (!parent || ts.isSourceFile(parent)) {\n\t\treturn [];\n\t}\n\tconst name = declarationName(parent);\n\tconst outer = enclosingDeclarations(parent);\n\treturn name === undefined ? outer : [...outer, { name, node: parent }];\n};\n",
23
+ "import { type Diagnostic, error } from \"@tsplc/compiler/ir\";\nimport { type Environment, plainValue } from \"@tsplc/config\";\nimport ts from \"typescript\";\nimport { plcSources } from \"./module-graph\";\nimport { type Edit, edited, type Mapped, type Positions } from \"./positions\";\nimport { namesSdk } from \"./sdk\";\n\n/** Whether `node` is the initializer of a module-level const, where configuration is read once. */\nconst inModuleConst = (node: ts.Node): boolean => {\n\tconst owner = ts.findAncestor(\n\t\tnode.parent,\n\t\t(item) => ts.isVariableDeclaration(item) || ts.isFunctionLike(item),\n\t);\n\treturn (\n\t\towner !== undefined &&\n\t\tts.isVariableDeclaration(owner) &&\n\t\tts.isVariableDeclarationList(owner.parent) &&\n\t\tBoolean(owner.parent.flags & ts.NodeFlags.Const) &&\n\t\tts.isVariableStatement(owner.parent.parent) &&\n\t\tts.isSourceFile(owner.parent.parent.parent)\n\t);\n};\n\nexport const lowerEnvironment = (\n\tprogram: ts.Program,\n\tsdk: string,\n\tpositions: Positions,\n\tenvironment: Environment,\n) => {\n\tconst checker = program.getTypeChecker();\n\tconst sources = new Map<string, Mapped>();\n\tconst diagnostics: Diagnostic[] = [];\n\t/** Each environment value an `env()` call reads, by name. */\n\tconst read: Record<string, string> = {};\n\tfor (const source of plcSources(program)) {\n\t\tconst edits: Edit[] = [];\n\t\tconst visit = (node: ts.Node): void => {\n\t\t\tif (ts.isCallExpression(node)) {\n\t\t\t\tif (namesSdk(checker, sdk, node.expression, \"env\")) {\n\t\t\t\t\tconst reject = (message: string) =>\n\t\t\t\t\t\tdiagnostics.push(error(\"PLC1011\", message, positions.node(node)));\n\t\t\t\t\tconst [name, ...rest] = node.arguments;\n\t\t\t\t\tif (\n\t\t\t\t\t\t!inModuleConst(node) ||\n\t\t\t\t\t\t!name ||\n\t\t\t\t\t\trest.length ||\n\t\t\t\t\t\t!ts.isStringLiteral(name) ||\n\t\t\t\t\t\tnode.typeArguments?.length !== 1\n\t\t\t\t\t) {\n\t\t\t\t\t\treject(\n\t\t\t\t\t\t\t\"env<STRING<N>> requires a literal environment name in module-level const configuration.\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst value = environment[name.text];\n\t\t\t\t\tif (!value) {\n\t\t\t\t\t\treject(`Required environment value ${name.text} is missing.`);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (!plainValue.safeParse(value).success) {\n\t\t\t\t\t\treject(\n\t\t\t\t\t\t\t`Environment value ${name.text} contains an unsupported NUL byte.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tread[name.text] = value;\n\t\t\t\t\tedits.push({\n\t\t\t\t\t\tstart: node.getStart(source),\n\t\t\t\t\t\tend: node.end,\n\t\t\t\t\t\ttext: JSON.stringify(value),\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tts.forEachChild(node, visit);\n\t\t};\n\t\tvisit(source);\n\t\tif (edits.length) {\n\t\t\tsources.set(source.fileName, edited(source, edits));\n\t\t}\n\t}\n\treturn { sources, diagnostics, read };\n};\n",
24
+ "import { type Diagnostic, error } from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport { plcSources } from \"./module-graph\";\nimport {\n\tcopied,\n\ttype Edit,\n\tedited,\n\tfrom,\n\tjoined,\n\ttype Mapped,\n\tmapped,\n\ttype Part,\n\ttype Positions,\n} from \"./positions\";\nimport { hasModifier } from \"./types\";\n\n/** An arrow body as a function body: a block as written, or its expression returned (or, for void, evaluated). */\nconst functionBody = (\n\tbody: ts.ConciseBody,\n\tresult: ts.TypeNode | undefined,\n): Part => {\n\tif (ts.isBlock(body)) {\n\t\treturn copied(body);\n\t}\n\treturn result?.kind === ts.SyntaxKind.VoidKeyword\n\t\t? mapped`{ ${copied(body)}; }`\n\t\t: mapped`{ return ${copied(body)}; }`;\n};\n\n/**\n * `: Promise<void>` before the body of each async function and method that returns nothing\n * without saying so, since async lowering requires an explicit `Promise<T>` result.\n */\nconst voidAsyncAnnotations = (\n\tsource: ts.SourceFile,\n\tchecker: ts.TypeChecker,\n): Edit[] =>\n\tsource.statements\n\t\t.flatMap((statement): readonly ts.Node[] =>\n\t\t\tts.isClassDeclaration(statement)\n\t\t\t\t? statement.members.filter(ts.isMethodDeclaration)\n\t\t\t\t: [statement],\n\t\t)\n\t\t.flatMap((routine) => {\n\t\t\tif (\n\t\t\t\t(!ts.isFunctionDeclaration(routine) &&\n\t\t\t\t\t!ts.isMethodDeclaration(routine)) ||\n\t\t\t\troutine.type ||\n\t\t\t\t!routine.body ||\n\t\t\t\t!hasModifier(routine, ts.SyntaxKind.AsyncKeyword)\n\t\t\t) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tconst signature = checker.getSignatureFromDeclaration(routine);\n\t\t\tconst result =\n\t\t\t\tsignature &&\n\t\t\t\tchecker.getAwaitedType(checker.getReturnTypeOfSignature(signature));\n\t\t\tif (!result || !(result.flags & ts.TypeFlags.Void)) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tconst position = routine.body.getStart(source);\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tstart: position,\n\t\t\t\t\tend: position,\n\t\t\t\t\ttext: from(routine, \":Promise<void> \"),\n\t\t\t\t},\n\t\t\t];\n\t\t});\n\n/**\n * Normalizes static arrow bindings into function declarations, so all routine forms use the same\n * PLC analysis, and annotates async routines that return nothing (see `voidAsyncAnnotations`).\n */\nexport const lowerConstFunctions = (\n\tprogram: ts.Program,\n\tpositions: Positions,\n) => {\n\tconst checker = program.getTypeChecker();\n\tconst printer = ts.createPrinter();\n\tconst sources = new Map<string, Mapped>();\n\tconst diagnostics: Diagnostic[] = [];\n\n\tfor (const source of plcSources(program)) {\n\t\tconst edits = voidAsyncAnnotations(source, checker);\n\t\tfor (const statement of source.statements) {\n\t\t\tif (\n\t\t\t\t!ts.isVariableStatement(statement) ||\n\t\t\t\t!statement.declarationList.declarations.some(\n\t\t\t\t\t(declaration) =>\n\t\t\t\t\t\tdeclaration.initializer &&\n\t\t\t\t\t\tts.isArrowFunction(declaration.initializer),\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst print = (node: ts.Node) =>\n\t\t\t\tprinter.printNode(ts.EmitHint.Unspecified, node, source);\n\t\t\tconst declarations: Mapped[] = [];\n\t\t\tfor (const declaration of statement.declarationList.declarations) {\n\t\t\t\tconst arrow = declaration.initializer;\n\t\t\t\tif (!arrow || !ts.isArrowFunction(arrow)) {\n\t\t\t\t\tdeclarations.push(\n\t\t\t\t\t\tfrom(\n\t\t\t\t\t\t\tdeclaration,\n\t\t\t\t\t\t\tprint(\n\t\t\t\t\t\t\t\tts.factory.updateVariableStatement(\n\t\t\t\t\t\t\t\t\tstatement,\n\t\t\t\t\t\t\t\t\tstatement.modifiers,\n\t\t\t\t\t\t\t\t\tts.factory.updateVariableDeclarationList(\n\t\t\t\t\t\t\t\t\t\tstatement.declarationList,\n\t\t\t\t\t\t\t\t\t\t[declaration],\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),\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\t!(statement.declarationList.flags & ts.NodeFlags.Const) ||\n\t\t\t\t\t!ts.isIdentifier(declaration.name)\n\t\t\t\t) {\n\t\t\t\t\tdiagnostics.push(\n\t\t\t\t\t\terror(\n\t\t\t\t\t\t\t\"PLC1007\",\n\t\t\t\t\t\t\t\"PLC routines require named const bindings; mutable function values are unsupported.\",\n\t\t\t\t\t\t\tpositions.node(declaration),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst contextual =\n\t\t\t\t\tdeclaration.type && ts.isFunctionTypeNode(declaration.type)\n\t\t\t\t\t\t? declaration.type\n\t\t\t\t\t\t: undefined;\n\t\t\t\tconst signature = checker\n\t\t\t\t\t.getTypeAtLocation(declaration.name)\n\t\t\t\t\t.getCallSignatures()[0];\n\t\t\t\tconst returnsVoid =\n\t\t\t\t\tsignature &&\n\t\t\t\t\tBoolean(\n\t\t\t\t\t\tchecker.getReturnTypeOfSignature(signature).flags &\n\t\t\t\t\t\t\tts.TypeFlags.Void,\n\t\t\t\t\t);\n\t\t\t\tconst inferredResult =\n\t\t\t\t\tsignature &&\n\t\t\t\t\tchecker.getAwaitedType(checker.getReturnTypeOfSignature(signature));\n\t\t\t\tconst asyncVoid =\n\t\t\t\t\thasModifier(arrow, ts.SyntaxKind.AsyncKeyword) &&\n\t\t\t\t\tinferredResult &&\n\t\t\t\t\tinferredResult.flags & ts.TypeFlags.Void;\n\t\t\t\tconst inferredType = asyncVoid\n\t\t\t\t\t? ts.factory.createTypeReferenceNode(\"Promise\", [\n\t\t\t\t\t\t\tts.factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword),\n\t\t\t\t\t\t])\n\t\t\t\t\t: undefined;\n\t\t\t\tconst result =\n\t\t\t\t\tarrow.type ??\n\t\t\t\t\tcontextual?.type ??\n\t\t\t\t\t(returnsVoid\n\t\t\t\t\t\t? ts.factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword)\n\t\t\t\t\t\t: inferredType);\n\t\t\t\tconst parameters = arrow.parameters.map((parameter, index) =>\n\t\t\t\t\tts.factory.updateParameterDeclaration(\n\t\t\t\t\t\tparameter,\n\t\t\t\t\t\tparameter.modifiers,\n\t\t\t\t\t\tparameter.dotDotDotToken,\n\t\t\t\t\t\tparameter.name,\n\t\t\t\t\t\tparameter.questionToken,\n\t\t\t\t\t\tparameter.type ?? contextual?.parameters[index]?.type,\n\t\t\t\t\t\tparameter.initializer,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\t// The header is printed; the body stays the user's text, so its positions map exactly.\n\t\t\t\tconst head = print(\n\t\t\t\t\tts.factory.createFunctionDeclaration(\n\t\t\t\t\t\t[...(statement.modifiers ?? []), ...(arrow.modifiers ?? [])],\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tdeclaration.name,\n\t\t\t\t\t\tarrow.typeParameters ?? contextual?.typeParameters,\n\t\t\t\t\t\tparameters,\n\t\t\t\t\t\tresult,\n\t\t\t\t\t\tts.factory.createBlock([]),\n\t\t\t\t\t),\n\t\t\t\t).replace(/\\{\\s*\\}$/, \"\");\n\t\t\t\tdeclarations.push(\n\t\t\t\t\tfrom(declaration, mapped`${head}${functionBody(arrow.body, result)}`),\n\t\t\t\t);\n\t\t\t}\n\t\t\tedits.push({\n\t\t\t\tstart: statement.getStart(source),\n\t\t\t\tend: statement.end,\n\t\t\t\ttext: joined(declarations, \"\\n\"),\n\t\t\t});\n\t\t}\n\t\tif (edits.length) {\n\t\t\tsources.set(source.fileName, edited(source, edits));\n\t\t}\n\t}\n\treturn { sources, diagnostics };\n};\n",
25
+ "import ts from \"typescript\";\nimport { copiedWhole } from \"./coroutines\";\nimport { plcSources } from \"./module-graph\";\nimport {\n\tcopied,\n\tcopiedRange,\n\ttype Edit,\n\tedited,\n\tfrom,\n\tjoined,\n\ttype Mapped,\n\tmapped,\n\ttype Part,\n} from \"./positions\";\nimport { promiseCallback } from \"./promise-chains\";\nimport { sdkModules } from \"./sdk\";\nimport { hasModifier, promisedType } from \"./types\";\n\n/**\n * Structured Text exits a loop with EXIT and leaves a CASE at its end only, and has no labels and no\n * finally. Jumps it can't express become flags: the jump sets its flag, the statements after it run\n * only while the flag is clear, and the statement the jump targets clears it.\n */\n\ntype JumpKind = \"break\" | \"continue\" | \"return\";\n\n/** A statement a jump can leave or target. */\ninterface Target {\n\tkind: \"loop\" | \"switch\" | \"labelled\" | \"finally\";\n\tlabels: readonly string[];\n\t/**\n\t * The coroutine runs it inside one step of an async routine, so a jump from it to the steps around\n\t * it, written as is, would leave the step without moving the job on.\n\t */\n\twithinStep: boolean;\n\tbreakFlag?: string;\n\tcontinueFlag?: string;\n\t/** Of a try with finally: which of its blocks the statements being lowered sit in. */\n\tregion?: \"try\" | \"catch\" | \"finally\";\n}\n\n/** A jump that left its statement with its flag set; undefined `target` is the routine, for a return. */\ninterface Pending {\n\tkind: JumpKind;\n\tflag: string;\n\ttarget: Target | undefined;\n}\n\n/** A statement as lowered; `changed` when its text differs from the source's. */\ninterface Lowered {\n\ttext: Part;\n\tpending: readonly Pending[];\n\tchanged: boolean;\n}\n\ninterface List {\n\tparts: readonly Part[];\n\tpending: readonly Pending[];\n\tchanged: boolean;\n}\n\n/** One statement of a list, lowered when its turn comes, so guards can wrap the statements after it. */\ninterface Item {\n\torigin: ts.Node;\n\tlower: () => Lowered;\n}\n\ninterface RoutineScope {\n\tsource: ts.SourceFile;\n\tasync: boolean;\n\tstack: Target[];\n\t/** The routine's result type as written, or undefined when it returns nothing. */\n\tresultType: string | undefined;\n\tresult?: { flag: string; value: string | undefined };\n\tname: (base: string) => string;\n\t/** The SDK functions the lowered routine calls, which its module imports. */\n\tuses: Set<keyof typeof sdkNames>;\n}\n\nconst unique = (pending: readonly Pending[]): Pending[] => [\n\t...new Map(pending.map((item) => [item.flag, item])).values(),\n];\n\nconst anyOf = (pending: readonly Pending[]): string =>\n\tunique(pending)\n\t\t.map((item) => item.flag)\n\t\t.join(\" || \");\n\n/** A case's or block's statements, looking through the one block a braced case holds. */\nconst unbraced = (\n\tstatements: readonly ts.Statement[],\n): readonly ts.Statement[] => {\n\tconst [only, ...others] = statements;\n\treturn only && !others.length && ts.isBlock(only)\n\t\t? only.statements\n\t\t: statements;\n};\n\nconst isJump = (statement: ts.Statement | undefined): boolean =>\n\tstatement !== undefined &&\n\t(ts.isBreakStatement(statement) ||\n\t\tts.isContinueStatement(statement) ||\n\t\tts.isReturnStatement(statement) ||\n\t\tts.isThrowStatement(statement));\n\nconst containsAwaitOrThrow = (node: ts.Node): boolean =>\n\tts.isAwaitExpression(node) ||\n\tts.isThrowStatement(node) ||\n\t(!ts.isFunctionLike(node) &&\n\t\t(ts.forEachChild(node, containsAwaitOrThrow) ?? false));\n\n/** Whether Structured Text can make the jump as written, from inside `crossing` to `target`. */\nconst isNative = (\n\tkind: JumpKind,\n\ttarget: Target | undefined,\n\tcrossing: readonly Target[],\n): boolean => {\n\tif (\n\t\tcrossing.some(\n\t\t\t(item) => item.kind === \"finally\" && item.region !== \"finally\",\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\tif (!target?.withinStep && crossing.some((item) => item.withinStep)) {\n\t\treturn false;\n\t}\n\tif (kind === \"return\" || !target) {\n\t\treturn true;\n\t}\n\tif (target.kind !== \"loop\") {\n\t\treturn false;\n\t}\n\treturn kind === \"break\"\n\t\t? !crossing.some((item) => item.kind === \"loop\" || item.kind === \"switch\")\n\t\t: !crossing.some((item) => item.kind === \"loop\");\n};\n\n/** The innermost statement a native `break` would leave, past labelled blocks. */\nconst innermostExit = (\n\tcrossing: readonly Target[],\n): Target[\"kind\"] | undefined =>\n\t[...crossing].reverse().find((item) => item.kind !== \"labelled\")?.kind;\n\nconst targetIndex = (\n\tkind: JumpKind,\n\tlabel: string | undefined,\n\tstack: readonly Target[],\n): number | undefined => {\n\tif (kind === \"return\") {\n\t\treturn -1;\n\t}\n\tconst found = [...stack.entries()]\n\t\t.reverse()\n\t\t.find(([, item]) =>\n\t\t\tlabel === undefined\n\t\t\t\t? item.kind === \"loop\" || (kind === \"break\" && item.kind === \"switch\")\n\t\t\t\t: item.labels.includes(label),\n\t\t);\n\treturn found?.[0];\n};\n\nconst lowerItems = (items: readonly Item[], loop: Target | undefined): List => {\n\tconst [first, ...others] = items;\n\tif (!first) {\n\t\treturn { parts: [], pending: [], changed: false };\n\t}\n\tconst head = first.lower();\n\tconst tail = lowerItems(others, loop);\n\tconst changed = head.changed || tail.changed;\n\tif (!head.pending.length) {\n\t\treturn {\n\t\t\tparts: [head.text, ...tail.parts],\n\t\t\tpending: tail.pending,\n\t\t\tchanged,\n\t\t};\n\t}\n\t// Directly in a loop's body, a jump past the loop leaves it with EXIT; one continuing it skips the rest.\n\tconst continuing = loop\n\t\t? head.pending.filter(\n\t\t\t\t(item) => item.target === loop && item.kind === \"continue\",\n\t\t\t)\n\t\t: head.pending;\n\tconst leaving = loop\n\t\t? head.pending.filter(\n\t\t\t\t(item) => !(item.target === loop && item.kind === \"continue\"),\n\t\t\t)\n\t\t: [];\n\tconst parts: Part[] = [head.text];\n\tif (leaving.length) {\n\t\tparts.push(from(first.origin, `if (${anyOf(leaving)}) { break; }`));\n\t}\n\tif (tail.parts.length) {\n\t\tparts.push(\n\t\t\tcontinuing.length\n\t\t\t\t? from(\n\t\t\t\t\t\tfirst.origin,\n\t\t\t\t\t\tmapped`if (!(${anyOf(continuing)})) { ${joined(tail.parts, \" \")} }`,\n\t\t\t\t\t)\n\t\t\t\t: joined(tail.parts, \" \"),\n\t\t);\n\t}\n\treturn {\n\t\tparts,\n\t\tpending: unique([...head.pending, ...tail.pending]),\n\t\tchanged,\n\t};\n};\n\nconst statementItems = (\n\tstatements: readonly ts.Statement[],\n\troutine: RoutineScope,\n): Item[] =>\n\tstatements.map((statement) => ({\n\t\torigin: statement,\n\t\tlower: () => lower(statement, routine),\n\t}));\n\nconst lowerList = (\n\tstatements: readonly ts.Statement[],\n\tloop: Target | undefined,\n\troutine: RoutineScope,\n): List => lowerItems(statementItems(statements, routine), loop);\n\nconst settled = (pending: readonly Pending[], target: Target): Pending[] =>\n\tpending.filter((item) => item.target !== target);\n\n/** Declares the flags jumps to `target` set, before it runs, so each run of it starts with them clear. */\nconst declared = (target: Target, node: ts.Node, text: Part): Part => {\n\tconst flags = [target.breakFlag, target.continueFlag].filter(\n\t\t(flag) => flag !== undefined,\n\t);\n\tif (!flags.length) {\n\t\treturn text;\n\t}\n\treturn from(\n\t\tnode,\n\t\tmapped`{ ${flags.map((flag) => `let ${flag}: boolean = false;`).join(\" \")} ${text} }`,\n\t);\n};\n\nconst withinStep = (node: ts.Statement, routine: RoutineScope): boolean =>\n\troutine.async &&\n\t(routine.stack.some((item) => item.withinStep) ||\n\t\tcopiedWhole(node, routine.source));\n\nconst unchanged = (node: ts.Node): Lowered => ({\n\ttext: copied(node),\n\tpending: [],\n\tchanged: false,\n});\n\nconst lower = (node: ts.Statement, routine: RoutineScope): Lowered => {\n\tconst lowered = lowerStatement(node, routine);\n\treturn lowered.changed ? lowered : unchanged(node);\n};\n\nconst lowerStatement = (node: ts.Statement, routine: RoutineScope): Lowered => {\n\tif (ts.isLabeledStatement(node)) {\n\t\treturn labelled(node, routine);\n\t}\n\tif (ts.isIterationStatement(node, false)) {\n\t\treturn loop(node, [], routine);\n\t}\n\tif (ts.isSwitchStatement(node)) {\n\t\treturn switchStatement(node, [], routine);\n\t}\n\tif (ts.isBlock(node)) {\n\t\tconst list = lowerList(node.statements, undefined, routine);\n\t\treturn {\n\t\t\ttext: from(node, mapped`{ ${joined(list.parts, \" \")} }`),\n\t\t\tpending: list.pending,\n\t\t\tchanged: list.changed,\n\t\t};\n\t}\n\tif (ts.isIfStatement(node)) {\n\t\treturn ifStatement(node, routine);\n\t}\n\tif (ts.isTryStatement(node)) {\n\t\treturn node.finallyBlock\n\t\t\t? finallyStatement(node, node.finallyBlock, routine)\n\t\t\t: tryStatement(node, routine);\n\t}\n\tif (\n\t\tts.isBreakStatement(node) ||\n\t\tts.isContinueStatement(node) ||\n\t\tts.isReturnStatement(node)\n\t) {\n\t\treturn jump(node, routine);\n\t}\n\treturn unchanged(node);\n};\n\n/** Structured Text has no labels, so a labelled statement always changes. */\nconst labelled = (\n\tnode: ts.LabeledStatement,\n\troutine: RoutineScope,\n): Lowered => {\n\tconst { labels, inner } = unlabelled(node);\n\tif (ts.isIterationStatement(inner, false)) {\n\t\treturn { ...loop(inner, labels, routine), changed: true };\n\t}\n\tif (ts.isSwitchStatement(inner)) {\n\t\treturn { ...switchStatement(inner, labels, routine), changed: true };\n\t}\n\tconst target: Target = {\n\t\tkind: \"labelled\",\n\t\tlabels,\n\t\twithinStep: withinStep(inner, routine),\n\t};\n\troutine.stack.push(target);\n\tconst body = lower(inner, routine);\n\troutine.stack.pop();\n\treturn {\n\t\ttext: declared(target, node, body.text),\n\t\tpending: settled(body.pending, target),\n\t\tchanged: true,\n\t};\n};\n\n/** The statement under a run of labels, and the labels. */\nconst unlabelled = (\n\tnode: ts.LabeledStatement,\n): { labels: string[]; inner: ts.Statement } => {\n\tif (!ts.isLabeledStatement(node.statement)) {\n\t\treturn { labels: [node.label.text], inner: node.statement };\n\t}\n\tconst nested = unlabelled(node.statement);\n\treturn { labels: [node.label.text, ...nested.labels], inner: nested.inner };\n};\n\nconst loop = (\n\tnode: ts.IterationStatement,\n\tlabels: readonly string[],\n\troutine: RoutineScope,\n): Lowered => {\n\tconst target: Target = {\n\t\tkind: \"loop\",\n\t\tlabels,\n\t\twithinStep: withinStep(node, routine),\n\t};\n\troutine.stack.push(target);\n\tconst body = node.statement;\n\tconst list = lowerList(\n\t\tts.isBlock(body) ? body.statements : [body],\n\t\ttarget,\n\t\troutine,\n\t);\n\troutine.stack.pop();\n\tif (!list.changed) {\n\t\treturn unchanged(node);\n\t}\n\tconst { source } = routine;\n\tconst reset = target.continueFlag ? `${target.continueFlag} = false; ` : \"\";\n\tconst text = mapped`${copiedRange(source, node.getStart(source), body.getStart(source))}${from(body, mapped`{ ${reset}${joined(list.parts, \" \")} }`)}${copiedRange(source, body.end, node.end)}`;\n\treturn {\n\t\ttext: declared(target, node, text),\n\t\tpending: settled(list.pending, target),\n\t\tchanged: true,\n\t};\n};\n\nconst ifStatement = (node: ts.IfStatement, routine: RoutineScope): Lowered => {\n\tconst yes = lower(node.thenStatement, routine);\n\tconst no = node.elseStatement && lower(node.elseStatement, routine);\n\tif (!yes.changed && !no?.changed) {\n\t\treturn unchanged(node);\n\t}\n\tconst { source } = routine;\n\tconst head = copiedRange(\n\t\tsource,\n\t\tnode.getStart(source),\n\t\tnode.thenStatement.getStart(source),\n\t);\n\tconst otherwise =\n\t\tnode.elseStatement && no\n\t\t\t? mapped`${copiedRange(source, node.thenStatement.end, node.elseStatement.getStart(source))}${no.text}`\n\t\t\t: \"\";\n\treturn {\n\t\ttext: mapped`${head}${yes.text}${otherwise}`,\n\t\tpending: unique([...yes.pending, ...(no?.pending ?? [])]),\n\t\tchanged: true,\n\t};\n};\n\n/**\n * A case that doesn't end in a jump runs on into the next, so its body is the chain of bodies up to\n * one that does. Each case ends with the break Structured Text's CASE implies, or its return.\n */\nconst switchStatement = (\n\tnode: ts.SwitchStatement,\n\tlabels: readonly string[],\n\troutine: RoutineScope,\n): Lowered => {\n\tconst target: Target = {\n\t\tkind: \"switch\",\n\t\tlabels,\n\t\twithinStep: withinStep(node, routine),\n\t};\n\troutine.stack.push(target);\n\tconst { source } = routine;\n\tconst bodies = node.caseBlock.clauses.map((clause) =>\n\t\tunbraced(clause.statements),\n\t);\n\tconst clauses = node.caseBlock.clauses.map((clause, index): Lowered => {\n\t\tconst label = ts.isCaseClause(clause)\n\t\t\t? mapped`case ${copied(clause.expression)}:`\n\t\t\t: \"default:\";\n\t\tif (!bodies[index]?.length) {\n\t\t\treturn { text: from(clause, label), pending: [], changed: false };\n\t\t}\n\t\tconst chain: (readonly ts.Statement[])[] = [];\n\t\tfor (const body of bodies.slice(index)) {\n\t\t\tif (!body.length) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tchain.push(body);\n\t\t\tif (isJump(body.at(-1))) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tconst last = chain.at(-1) ?? [];\n\t\tconst end = last.at(-1);\n\t\tconst ending =\n\t\t\tend && ts.isBreakStatement(end) && !end.label ? last.slice(0, -1) : last;\n\t\tconst pieces = [...chain.slice(0, -1), ending];\n\t\tconst items: Item[] =\n\t\t\tpieces.length === 1\n\t\t\t\t? statementItems(ending, routine)\n\t\t\t\t: pieces.map((piece) => ({\n\t\t\t\t\t\torigin: piece[0] ?? clause,\n\t\t\t\t\t\tlower: () => {\n\t\t\t\t\t\t\tconst list = lowerList(piece, undefined, routine);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttext: from(clause, mapped`{ ${joined(list.parts, \" \")} }`),\n\t\t\t\t\t\t\t\tpending: list.pending,\n\t\t\t\t\t\t\t\tchanged: list.changed,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t},\n\t\t\t\t\t}));\n\t\tconst list = lowerItems(items, undefined);\n\t\tconst returns =\n\t\t\tend !== undefined &&\n\t\t\t(ts.isReturnStatement(end) || ts.isThrowStatement(end)) &&\n\t\t\t!list.pending.length;\n\t\tconst body = joined(list.parts, \" \");\n\t\treturn {\n\t\t\ttext: from(\n\t\t\t\tclause,\n\t\t\t\treturns\n\t\t\t\t\t? mapped`${label} { ${body} }`\n\t\t\t\t\t: mapped`${label} { ${body} } break;`,\n\t\t\t),\n\t\t\tpending: list.pending,\n\t\t\t// A case that runs on into the next one is a change in itself.\n\t\t\tchanged: chain.length > 1 || list.changed,\n\t\t};\n\t});\n\troutine.stack.pop();\n\tif (!clauses.some((clause) => clause.changed)) {\n\t\treturn unchanged(node);\n\t}\n\tconst text = mapped`${copiedRange(source, node.getStart(source), node.caseBlock.getStart(source))}{ ${joined(\n\t\tclauses.map((clause) => clause.text),\n\t\t\" \",\n\t)} }`;\n\treturn {\n\t\ttext: declared(target, node, text),\n\t\tpending: settled(\n\t\t\tunique(clauses.flatMap((clause) => clause.pending)),\n\t\t\ttarget,\n\t\t),\n\t\tchanged: true,\n\t};\n};\n\nconst tryStatement = (\n\tnode: ts.TryStatement,\n\troutine: RoutineScope,\n): Lowered => {\n\tconst attempt = lower(node.tryBlock, routine);\n\tconst caught = node.catchClause && lower(node.catchClause.block, routine);\n\tif (!attempt.changed && !caught?.changed) {\n\t\treturn unchanged(node);\n\t}\n\tconst { source } = routine;\n\tconst recovery =\n\t\tnode.catchClause && caught\n\t\t\t? mapped`${copiedRange(source, node.tryBlock.end, node.catchClause.block.getStart(source))}${caught.text}`\n\t\t\t: \"\";\n\treturn {\n\t\ttext: mapped`${copiedRange(source, node.getStart(source), node.tryBlock.getStart(source))}${attempt.text}${recovery}`,\n\t\tpending: unique([...attempt.pending, ...(caught?.pending ?? [])]),\n\t\tchanged: true,\n\t};\n};\n\n/**\n * The finally block runs after the try and catch blocks however they end. A jump out of them is held\n * until it has run; in an async routine a failure is caught, held and raised again after it.\n */\nconst finallyStatement = (\n\tnode: ts.TryStatement,\n\tfinallyBlock: ts.Block,\n\troutine: RoutineScope,\n): Lowered => {\n\tconst target: Target = {\n\t\tkind: \"finally\",\n\t\tlabels: [],\n\t\twithinStep: withinStep(node, routine),\n\t\tregion: \"try\",\n\t};\n\troutine.stack.push(target);\n\tconst attempt = lowerList(node.tryBlock.statements, undefined, routine);\n\ttarget.region = \"catch\";\n\tconst caught =\n\t\tnode.catchClause &&\n\t\tlowerList(node.catchClause.block.statements, undefined, routine);\n\ttarget.region = \"finally\";\n\tconst final = lowerList(finallyBlock.statements, undefined, routine);\n\troutine.stack.pop();\n\n\tconst held = unique([...attempt.pending, ...(caught?.pending ?? [])]);\n\tconst guarded = routine.async\n\t\t? caughtAttempt(node, attempt, caught, routine)\n\t\t: // Synchronous scan code can't fail, so its catch block never runs.\n\t\t\t{\n\t\t\t\tparts: [mapped`{ ${joined(attempt.parts, \" \")} }`],\n\t\t\t\trethrow: undefined,\n\t\t\t};\n\tconst parts: Part[] = [...guarded.parts];\n\tparts.push(mapped`{ ${joined(final.parts, \" \")} }`);\n\n\tconst resumed: string[] = guarded.rethrow ? [guarded.rethrow] : [];\n\tconst still: Pending[] = [];\n\tfor (const item of held) {\n\t\tconst index = item.target ? routine.stack.indexOf(item.target) : -1;\n\t\tconst crossing = routine.stack.slice(index + 1);\n\t\tif (!isNative(item.kind, item.target, crossing)) {\n\t\t\tstill.push(item);\n\t\t\tcontinue;\n\t\t}\n\t\tif (item.kind === \"return\") {\n\t\t\tconst value = routine.result?.value;\n\t\t\tresumed.push(`if (${item.flag}) { return${value ? ` ${value}` : \"\"}; }`);\n\t\t\tcontinue;\n\t\t}\n\t\tresumed.push(`if (${item.flag}) { ${item.kind}; }`);\n\t}\n\tif (resumed.length) {\n\t\tparts.push(\n\t\t\tfinal.pending.length\n\t\t\t\t? `if (!(${anyOf(final.pending)})) { ${resumed.join(\" \")} }`\n\t\t\t\t: resumed.join(\" \"),\n\t\t);\n\t}\n\treturn {\n\t\ttext: from(node, mapped`{ ${joined(parts, \" \")} }`),\n\t\tpending: unique([...still, ...final.pending]),\n\t\tchanged: true,\n\t};\n};\n\n/** An async try whose failures, in its try block or its catch block, are held until finally has run. */\nconst caughtAttempt = (\n\tnode: ts.TryStatement,\n\tattempt: List,\n\tcaught: List | undefined,\n\troutine: RoutineScope,\n): { parts: Part[]; rethrow: string } => {\n\tconst throwing = routine.name(\"tsplcThrowing\");\n\tconst error = routine.name(\"tsplcError\");\n\troutine.uses.add(\"errorCode\");\n\tconst hold = (caught: string) =>\n\t\t`${throwing} = true; ${error} = ${sdkNames.errorCode}(${caught});`;\n\tconst fallback = routine.name(\"tsplcCaught\");\n\tconst clause = node.catchClause;\n\tconst binding = clause?.variableDeclaration\n\t\t? copied(clause.variableDeclaration)\n\t\t: fallback;\n\tconst recovery = (): Part => {\n\t\tif (!clause || !caught) {\n\t\t\treturn hold(fallback);\n\t\t}\n\t\t// A failure in the catch block still runs finally, so it is caught again.\n\t\tif (!containsAwaitOrThrow(clause.block)) {\n\t\t\treturn joined(caught.parts, \" \");\n\t\t}\n\t\tconst again = routine.name(\"tsplcCaught\");\n\t\treturn mapped`try { ${joined(caught.parts, \" \")} } catch (${again}) { ${hold(again)} }`;\n\t};\n\treturn {\n\t\tparts: [\n\t\t\t`let ${throwing}: boolean = false; let ${error}: UDINT = 0;`,\n\t\t\tmapped`try { ${joined(attempt.parts, \" \")} } catch (${binding}) { ${recovery()} }`,\n\t\t],\n\t\trethrow: `if (${throwing}) { throw ${error}; }`,\n\t};\n};\n\nconst jump = (\n\tnode: ts.BreakStatement | ts.ContinueStatement | ts.ReturnStatement,\n\troutine: RoutineScope,\n): Lowered => {\n\tconst { kind, label } = jumpOf(node);\n\tconst index = targetIndex(kind, label, routine.stack);\n\tif (index === undefined) {\n\t\treturn unchanged(node);\n\t}\n\tconst target = index >= 0 ? routine.stack[index] : undefined;\n\tconst crossing = routine.stack.slice(index + 1);\n\tif (isNative(kind, target, crossing) && label === undefined) {\n\t\treturn unchanged(node);\n\t}\n\tif (isNative(kind, target, crossing)) {\n\t\treturn { text: from(node, `${kind};`), pending: [], changed: true };\n\t}\n\tconst flag = flagFor(kind, target, routine);\n\tconst value =\n\t\tts.isReturnStatement(node) && node.expression && routine.result?.value\n\t\t\t? mapped`${routine.result.value} = ${copied(node.expression)}; `\n\t\t\t: \"\";\n\tconst exit = innermostExit(crossing) === \"loop\" ? \" break;\" : \"\";\n\treturn {\n\t\ttext: from(node, mapped`{ ${flag} = true; ${value}${exit} }`),\n\t\tpending: [{ kind, flag, target }],\n\t\tchanged: true,\n\t};\n};\n\nconst jumpOf = (\n\tnode: ts.BreakStatement | ts.ContinueStatement | ts.ReturnStatement,\n): { kind: JumpKind; label: string | undefined } => {\n\tif (ts.isBreakStatement(node)) {\n\t\treturn { kind: \"break\", label: node.label?.text };\n\t}\n\tif (ts.isContinueStatement(node)) {\n\t\treturn { kind: \"continue\", label: node.label?.text };\n\t}\n\treturn { kind: \"return\", label: undefined };\n};\n\nconst flagFor = (\n\tkind: JumpKind,\n\ttarget: Target | undefined,\n\troutine: RoutineScope,\n): string => {\n\tif (!target) {\n\t\troutine.result ??= {\n\t\t\tflag: routine.name(\"tsplcReturning\"),\n\t\t\tvalue: routine.resultType ? routine.name(\"tsplcResult\") : undefined,\n\t\t};\n\t\treturn routine.result.flag;\n\t}\n\tif (kind === \"continue\") {\n\t\ttarget.continueFlag ??= routine.name(\"tsplcContinue\");\n\t\treturn target.continueFlag;\n\t}\n\ttarget.breakFlag ??= routine.name(\"tsplcBreak\");\n\treturn target.breakFlag;\n};\n\ntype RoutineNode =\n\t| ts.FunctionDeclaration\n\t| ts.MethodDeclaration\n\t| ts.GetAccessorDeclaration\n\t| ts.SetAccessorDeclaration\n\t| ts.ConstructorDeclaration\n\t| ts.ArrowFunction\n\t| ts.FunctionExpression;\n\nconst isRoutine = (node: ts.Node): node is RoutineNode =>\n\tts.isFunctionDeclaration(node) ||\n\tts.isMethodDeclaration(node) ||\n\tts.isGetAccessorDeclaration(node) ||\n\tts.isSetAccessorDeclaration(node) ||\n\tts.isConstructorDeclaration(node) ||\n\tts.isArrowFunction(node) ||\n\tts.isFunctionExpression(node);\n\n/** The result type a return statement's value is held as, as written, or undefined for a routine returning nothing. */\nconst resultType = (\n\tnode: RoutineNode,\n\tchecker: ts.TypeChecker,\n): string | undefined => {\n\tif (ts.isConstructorDeclaration(node) || ts.isSetAccessorDeclaration(node)) {\n\t\treturn undefined;\n\t}\n\tconst annotation = node.type;\n\tconst isAsync = hasModifier(node, ts.SyntaxKind.AsyncKeyword);\n\tif (annotation) {\n\t\tconst inner = isAsync ? promisedType(annotation) : annotation;\n\t\tif (!inner || inner.kind === ts.SyntaxKind.VoidKeyword) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn inner.getText();\n\t}\n\tconst signature = checker.getSignatureFromDeclaration(node);\n\tif (!signature) {\n\t\treturn undefined;\n\t}\n\tconst returns = checker.getReturnTypeOfSignature(signature);\n\tconst awaited = isAsync ? checker.getAwaitedType(returns) : returns;\n\tif (!awaited || awaited.flags & ts.TypeFlags.Void) {\n\t\treturn undefined;\n\t}\n\treturn checker.typeToString(awaited);\n};\n\n/** The SDK functions lowered code calls, by the names their imports give them. */\nconst sdkNames = {\n\tdefaultValue: \"tsplcHeldDefault\",\n\terrorCode: \"tsplcHeldErrorCode\",\n} as const;\n\nconst sdkNameModules: Record<keyof typeof sdkNames, string> = {\n\tdefaultValue: sdkModules.types,\n\terrorCode: sdkModules.async,\n};\n\n/** Lowers the jumps, labels, fallthrough and finally blocks Structured Text can't express in every routine. */\nexport const lowerControlFlow = (program: ts.Program) => {\n\tconst checker = program.getTypeChecker();\n\tconst sources = new Map<string, Mapped>();\n\tfor (const source of plcSources(program)) {\n\t\tconst edits: Edit[] = [];\n\t\tlet counter = 0;\n\t\tconst uses = new Set<keyof typeof sdkNames>();\n\t\tconst name = (base: string) => `${base}${++counter}`;\n\t\tconst visit = (node: ts.Node): void => {\n\t\t\tif (!isRoutine(node) || !node.body || !ts.isBlock(node.body)) {\n\t\t\t\tts.forEachChild(node, visit);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst body = node.body;\n\t\t\tconst routine: RoutineScope = {\n\t\t\t\tsource,\n\t\t\t\tasync:\n\t\t\t\t\thasModifier(node, ts.SyntaxKind.AsyncKeyword) ||\n\t\t\t\t\tpromiseCallback(node),\n\t\t\t\tstack: [],\n\t\t\t\tresultType: resultType(node, checker),\n\t\t\t\tname,\n\t\t\t\tuses,\n\t\t\t};\n\t\t\tconst list = lowerList(body.statements, undefined, routine);\n\t\t\tif (!list.changed) {\n\t\t\t\tts.forEachChild(node, visit);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst declarations: string[] = [];\n\t\t\tif (routine.result) {\n\t\t\t\tdeclarations.push(`let ${routine.result.flag}: boolean = false;`);\n\t\t\t\tif (routine.result.value && routine.resultType) {\n\t\t\t\t\tuses.add(\"defaultValue\");\n\t\t\t\t\tdeclarations.push(\n\t\t\t\t\t\t`let ${routine.result.value}: ${routine.resultType} = ${sdkNames.defaultValue}<${routine.resultType}>();`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Only a return can still be held here, and every other path through the routine returns.\n\t\t\tconst value = list.pending.length ? routine.result?.value : undefined;\n\t\t\tconst resumed = value ? [`return ${value};`] : [];\n\t\t\tedits.push({\n\t\t\t\tstart: body.getStart(source),\n\t\t\t\tend: body.end,\n\t\t\t\ttext: from(\n\t\t\t\t\tbody,\n\t\t\t\t\tmapped`{ ${declarations.join(\" \")} ${joined([...list.parts, ...resumed], \"\\n\")} }`,\n\t\t\t\t),\n\t\t\t});\n\t\t};\n\t\tvisit(source);\n\t\tif (!edits.length) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const used of uses) {\n\t\t\tedits.push({\n\t\t\t\tstart: 0,\n\t\t\t\tend: 0,\n\t\t\t\ttext: `import { ${used} as ${sdkNames[used]} } from \"${sdkNameModules[used]}\";\\n`,\n\t\t\t});\n\t\t}\n\t\tsources.set(source.fileName, edited(source, edits));\n\t}\n\treturn { sources, diagnostics: [] };\n};\n",
26
+ "import ts from \"typescript\";\nimport {\n\tcooperativeTasksAlias,\n\tcopyValue,\n\terrorCodeAlias,\n} from \"./cooperative\";\nimport { typeArgumentIntrinsics } from \"./intrinsics\";\nimport type { Callable, PromiseContext } from \"./promises\";\nimport { holdsBorrow, valueSymbol } from \"./sdk\";\nimport { backgroundJob } from \"./tasks\";\nimport {\n\tcalleeName,\n\thasModifier,\n\tisAggregateType,\n\tisPropertyName,\n\tnamedRecordText,\n\tpromisedType,\n} from \"./types\";\n\ntype Handler = ts.ArrowFunction | ts.FunctionExpression | Callable;\n\nconst linkKinds = [\"then\", \"catch\"] as const;\n\n/** A `.then(fulfilled, rejected)` or `.catch(rejected)` link of a chain. */\ninterface ChainLink {\n\tkind: (typeof linkKinds)[number];\n\thandlers: readonly ts.Expression[];\n}\n\n/** An async operation and the links chained onto it. */\nexport interface Chain {\n\troot: ts.CallExpression;\n\tlinks: ChainLink[];\n}\n\n/** A value a generated helper takes: a root call argument or a captured const. */\ninterface HelperParameter {\n\tname: string;\n\ttype: string;\n\texpression: string;\n}\n\n/** A callback as the chain calls it on an input, with the type it resolves to. */\ninterface Callback {\n\tcall: (input: string) => string;\n\ttype: string;\n\taggregate: boolean;\n}\n\n/** A step of the chain: the helper that runs it, with the type it resolves to. */\ninterface Step {\n\thelper: string;\n\ttype: string;\n\taggregate: boolean;\n}\n\nconst asyncRoutine = (context: PromiseContext, node: ts.Node) => {\n\tconst symbol = context.symbol(node);\n\tconst fn = symbol && context.routines.get(symbol);\n\treturn fn && hasModifier(fn, ts.SyntaxKind.AsyncKeyword) ? fn : undefined;\n};\n\n/** The async routine a `backgroundTasks.define` job runs. */\nconst job = (context: PromiseContext, node: ts.Node) => {\n\tconst [work] = backgroundJob(context, context.symbol(node))?.arguments ?? [];\n\treturn work && asyncRoutine(context, work);\n};\n\n/** The async routine a call runs, directly or as a background job. */\nconst operation = (context: PromiseContext, call: ts.CallExpression) => {\n\tconst callee = calleeName(call.expression);\n\treturn callee && (asyncRoutine(context, callee) ?? job(context, callee));\n};\n\nconst isSdk = (\n\tcontext: PromiseContext,\n\tcall: ts.CallExpression,\n\tname: string,\n) => {\n\tconst callee = calleeName(call.expression);\n\treturn callee !== undefined && context.namesSdk(callee, name);\n};\n\n/** The link a `.then` or `.catch` call adds, and the expression it is chained onto. */\nconst linkOf = (call: ts.CallExpression) => {\n\tconst callee = call.expression;\n\tif (!ts.isPropertyAccessExpression(callee)) {\n\t\treturn;\n\t}\n\tconst kind = linkKinds.find((link) => link === callee.name.text);\n\treturn kind && { kind, target: callee.expression };\n};\n\n/** An inline callback of a `.then` or `.catch` link, which promise lowering runs as a coroutine. */\nexport const promiseCallback = (node: ts.Node): boolean =>\n\t(ts.isArrowFunction(node) || ts.isFunctionExpression(node)) &&\n\tts.isCallExpression(node.parent) &&\n\tlinkOf(node.parent) !== undefined;\n\n/** The chain an expression is: an async call or SDK sleep or fetch, with its links. */\nexport const chainOf = (\n\tcontext: PromiseContext,\n\texpression: ts.Expression,\n): Chain | undefined => {\n\tif (!ts.isCallExpression(expression)) {\n\t\treturn;\n\t}\n\tconst link = linkOf(expression);\n\tif (link) {\n\t\tconst prefix = chainOf(context, link.target);\n\t\tif (!prefix) {\n\t\t\treturn;\n\t\t}\n\t\treturn {\n\t\t\troot: prefix.root,\n\t\t\tlinks: [\n\t\t\t\t...prefix.links,\n\t\t\t\t{ kind: link.kind, handlers: expression.arguments },\n\t\t\t],\n\t\t};\n\t}\n\tif (\n\t\toperation(context, expression) ||\n\t\tisSdk(context, expression, \"sleep\") ||\n\t\tisSdk(context, expression, \"fetch\")\n\t) {\n\t\treturn { root: expression, links: [] };\n\t}\n};\n\n/**\n * Replaces a chain with named helper coroutines, one for the operation and one per link.\n * A detached chain becomes a cooperative site its owner starts; otherwise the expression\n * becomes a call to the last helper.\n */\nexport const lowerChain = (\n\tcontext: PromiseContext,\n\texpression: ts.Expression,\n\tchain: Chain,\n\towner: Callable,\n\t{ detached }: { detached: boolean },\n): string =>\n\tnew PromiseChain(context, expression, chain, owner).lower({ detached });\n\nconst isAggregate = (type: ts.Type | undefined) =>\n\ttype !== undefined && isAggregateType(type);\n\nconst helperFinish = (\n\tcall: string,\n\ttype: string,\n\t{ discard }: { discard: boolean },\n) =>\n\ttype === \"void\" || discard\n\t\t? `await ${call};return;`\n\t\t: `return await ${call};`;\n\n/** One chain being lowered: its captures, root operation and helpers. */\nclass PromiseChain {\n\tprivate readonly source: ts.SourceFile;\n\t/** The class that owns the helpers when the chain is in a method; otherwise the module does. */\n\tprivate readonly classOwner: ts.ClassDeclaration | undefined;\n\tprivate readonly captures = new Map<\n\t\tts.Symbol,\n\t\t{ name: string; type: string; argument: string }\n\t>();\n\tprivate readonly captureNames: ReadonlyMap<ts.Symbol, string>;\n\tprivate readonly params: HelperParameter[];\n\tprivate readonly signature: string;\n\tprivate readonly args: string;\n\tprivate readonly rootInvocation: string;\n\tprivate readonly rootType: string;\n\n\tconstructor(\n\t\tprivate readonly context: PromiseContext,\n\t\tprivate readonly expression: ts.Expression,\n\t\tprivate readonly chain: Chain,\n\t\tprivate readonly owner: Callable,\n\t) {\n\t\tthis.source = expression.getSourceFile();\n\t\tthis.classOwner =\n\t\t\tts.isMethodDeclaration(owner) && ts.isClassDeclaration(owner.parent)\n\t\t\t\t? owner.parent\n\t\t\t\t: undefined;\n\t\tcontext.ensureImports(this.source, expression);\n\t\tcontext.useDiagnostics(expression);\n\t\tfor (const link of chain.links) {\n\t\t\tfor (const value of link.handlers) {\n\t\t\t\tif (ts.isArrowFunction(value) || ts.isFunctionExpression(value)) {\n\t\t\t\t\tthis.collectCaptures(value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.captureNames = new Map(\n\t\t\t[...this.captures].map(([key, value]) => [key, value.name]),\n\t\t);\n\t\tconst root = this.rootCall();\n\t\tthis.rootInvocation = root.invocation;\n\t\tthis.rootType = root.type;\n\t\tthis.params = [\n\t\t\t...root.arguments,\n\t\t\t...[...this.captures.values()].map((value) => ({\n\t\t\t\tname: value.name,\n\t\t\t\ttype: value.type,\n\t\t\t\texpression: value.argument,\n\t\t\t})),\n\t\t];\n\t\tthis.signature = this.params\n\t\t\t.map((value) => `${value.name}:${value.type}`)\n\t\t\t.join(\",\");\n\t\tthis.args = this.params.map((value) => value.name).join(\",\");\n\t}\n\n\t/** The routine's const locals and parameters a callback reads become helper parameters. */\n\tprivate collectCaptures(handler: ts.ArrowFunction | ts.FunctionExpression) {\n\t\tconst visit = (node: ts.Node): void => {\n\t\t\tif (ts.isIdentifier(node) && !isPropertyName(node)) {\n\t\t\t\tthis.capture(node);\n\t\t\t}\n\t\t\tts.forEachChild(node, visit);\n\t\t};\n\t\tvisit(handler.body);\n\t}\n\n\tprivate capture(node: ts.Identifier): void {\n\t\tconst { context } = this;\n\t\tconst key = valueSymbol(context.checker, node);\n\t\tconst declaration = key?.valueDeclaration;\n\t\tif (\n\t\t\t!key ||\n\t\t\t!declaration ||\n\t\t\t!(ts.isVariableDeclaration(declaration) || ts.isParameter(declaration)) ||\n\t\t\tts.findAncestor(declaration.parent, ts.isFunctionLike) !== this.owner ||\n\t\t\tthis.captures.has(key)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\tts.isVariableDeclaration(declaration) &&\n\t\t\t(!ts.isVariableDeclarationList(declaration.parent) ||\n\t\t\t\t!(declaration.parent.flags & ts.NodeFlags.Const))\n\t\t) {\n\t\t\tthis.context.fail(\n\t\t\t\tnode,\n\t\t\t\t\"Continuation captures must be const values; store mutable state on the controller instead.\",\n\t\t\t);\n\t\t}\n\t\tif (!declaration.type) {\n\t\t\tthis.context.fail(\n\t\t\t\tnode,\n\t\t\t\t\"Annotate a captured value with its concrete PLC type.\",\n\t\t\t);\n\t\t}\n\t\tif (holdsBorrow(context, declaration.type)) {\n\t\t\tthis.context.fail(\n\t\t\t\tnode,\n\t\t\t\t\"A continuation cannot capture borrowed InOut storage; capture values or use controller state.\",\n\t\t\t);\n\t\t}\n\t\tthis.captures.set(key, {\n\t\t\tname: `capture${this.captures.size}`,\n\t\t\ttype: context.typeText(declaration.type, this.source),\n\t\t\targument: node.text,\n\t\t});\n\t}\n\n\t/** The root operation's arguments, the call that runs it, and the type it resolves to. */\n\tprivate rootCall(): {\n\t\targuments: HelperParameter[];\n\t\tinvocation: string;\n\t\ttype: string;\n\t} {\n\t\tconst { context, source } = this;\n\t\tconst { root } = this.chain;\n\t\tconst fn = operation(context, root);\n\t\tif (fn) {\n\t\t\tconst promised = fn.type && promisedType(fn.type);\n\t\t\tif (!promised) {\n\t\t\t\tthis.context.fail(\n\t\t\t\t\tfn,\n\t\t\t\t\t\"Async calls need an explicit Promise<T> result.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst type = context.typeText(promised, source);\n\t\t\tconst parameters = fn.parameters.map((parameter, index) => {\n\t\t\t\tconst argument = root.arguments[index];\n\t\t\t\tif (!parameter.type || !argument) {\n\t\t\t\t\tthis.context.fail(\n\t\t\t\t\t\troot,\n\t\t\t\t\t\t\"Async argument count differs from its concrete signature.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tname: `argument${index}`,\n\t\t\t\t\ttype: context.typeText(parameter.type, source),\n\t\t\t\t\texpression: argument.getText(source),\n\t\t\t\t};\n\t\t\t});\n\t\t\treturn {\n\t\t\t\targuments: parameters,\n\t\t\t\tinvocation: `${root.expression.getText(source)}(${parameters.map((value) => value.name).join(\",\")})`,\n\t\t\t\ttype,\n\t\t\t};\n\t\t}\n\t\tif (isSdk(context, root, \"sleep\")) {\n\t\t\tconst [duration, ...rest] = root.arguments;\n\t\t\tif (!duration || rest.length) {\n\t\t\t\tthis.context.fail(root, \"sleep requires one TIME argument.\");\n\t\t\t}\n\t\t\treturn {\n\t\t\t\targuments: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"argument0\",\n\t\t\t\t\t\ttype: \"TIME\",\n\t\t\t\t\t\texpression: duration.getText(source),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tinvocation: `${root.expression.getText(source)}(argument0)`,\n\t\t\t\ttype: \"void\",\n\t\t\t};\n\t\t}\n\t\treturn this.fetchCall(root);\n\t}\n\n\t/** A fetch keeps its options in the call; only its json body becomes a helper parameter. */\n\tprivate fetchCall(root: ts.CallExpression) {\n\t\tconst { context, source } = this;\n\t\tconst typeArguments = root.typeArguments;\n\t\tconst response = typeArguments?.[0];\n\t\tif (!typeArguments || !response) {\n\t\t\tthis.context.fail(root, \"fetch requires a typed response.\");\n\t\t}\n\t\tconst type = context.typeText(response, source);\n\t\tconst [url, options] = root.arguments;\n\t\tif (!url) {\n\t\t\tthis.context.fail(root, \"fetch requires a URL.\");\n\t\t}\n\t\tif (options && !ts.isObjectLiteralExpression(options)) {\n\t\t\tthis.context.fail(options, \"fetch options must be an inline object.\");\n\t\t}\n\t\tconst parameters: HelperParameter[] = [];\n\t\tconst optionText = options\n\t\t\t? options.properties\n\t\t\t\t\t.map((property) => {\n\t\t\t\t\t\tif (!ts.isPropertyAssignment(property)) {\n\t\t\t\t\t\t\tthis.context.fail(property, \"fetch requires named options.\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (property.name.getText(source) !== \"json\") {\n\t\t\t\t\t\t\treturn property.getText(source);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tparameters.push({\n\t\t\t\t\t\t\tname: \"argument0\",\n\t\t\t\t\t\t\ttype: this.expressionType(property.initializer),\n\t\t\t\t\t\t\texpression: property.initializer.getText(source),\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn \"json:argument0\";\n\t\t\t\t\t})\n\t\t\t\t\t.join(\",\")\n\t\t\t: \"\";\n\t\treturn {\n\t\t\targuments: parameters,\n\t\t\tinvocation: `${root.expression.getText(source)}<${typeArguments.map((type) => type.getText(source)).join(\",\")}>(${url.getText(source)}${options ? `,{${optionText}}` : \"\"})`,\n\t\t\ttype,\n\t\t};\n\t}\n\n\t/** A value's PLC type: from an SDK type argument, its declaration, or the checker. */\n\tprivate expressionType(node: ts.Expression): string {\n\t\tconst { context, source } = this;\n\t\tconst { checker } = context;\n\t\tconst typeArgument = ts.isCallExpression(node)\n\t\t\t? node.typeArguments?.[0]\n\t\t\t: undefined;\n\t\tif (\n\t\t\ttypeArgument &&\n\t\t\tts.isCallExpression(node) &&\n\t\t\t[...typeArgumentIntrinsics].some((name) =>\n\t\t\t\tcontext.namesSdk(node.expression, name),\n\t\t\t)\n\t\t) {\n\t\t\treturn context.typeText(typeArgument, source);\n\t\t}\n\t\tconst name = ts.isPropertyAccessExpression(node) ? node.name : node;\n\t\tconst declaration = context\n\t\t\t.symbol(name)\n\t\t\t?.declarations?.find(isAnnotatedDeclaration);\n\t\tif (declaration) {\n\t\t\treturn context.typeText(declaration.type, source);\n\t\t}\n\t\tconst type = checker.getTypeAtLocation(node);\n\t\tif (type.flags & ts.TypeFlags.BooleanLike) {\n\t\t\treturn \"BOOL\";\n\t\t}\n\t\tif (type.flags & ts.TypeFlags.Void) {\n\t\t\treturn \"void\";\n\t\t}\n\t\treturn (\n\t\t\tnamedRecordText(checker, node) ??\n\t\t\tthis.context.fail(\n\t\t\t\tnode,\n\t\t\t\t\"Annotate this value with its concrete PLC type before using it in an async continuation.\",\n\t\t\t)\n\t\t);\n\t}\n\n\tprivate isPromise(node: ts.Node): boolean {\n\t\tconst { checker } = this.context;\n\t\tconst type = checker.getTypeAtLocation(node);\n\t\treturn checker.getAwaitedType(type) !== type;\n\t}\n\n\t/** A generated helper coroutine, declared in the class or module that owns the chain. */\n\tprivate declare(\n\t\tname: string,\n\t\tparameters: string,\n\t\ttype: string,\n\t\tbody: string,\n\t): string {\n\t\tconst { classOwner } = this;\n\t\treturn `${classOwner ? \"private \" : \"export \"}async ${classOwner ? \"\" : \"function \"}${name}(${parameters}):Promise<${type}>{${body}}`;\n\t}\n\n\t/**\n\t * Declares a helper that takes the chain's parameters, and an input of type `input` unless it\n\t * is null; returns the name it is called by.\n\t */\n\tprivate addHelper(\n\t\tname: string,\n\t\tbody: string,\n\t\ttype: string,\n\t\tinput: string | null,\n\t): string {\n\t\tconst { classOwner } = this;\n\t\tthis.context.append(\n\t\t\tclassOwner ?? this.source,\n\t\t\tthis.expression,\n\t\t\tthis.declare(\n\t\t\t\tname,\n\t\t\t\t[this.signature, input === null ? \"\" : `promiseInput:${input}`]\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join(\",\"),\n\t\t\t\ttype,\n\t\t\t\tbody,\n\t\t\t),\n\t\t);\n\t\treturn `${classOwner ? \"this.\" : \"\"}${name}`;\n\t}\n\n\t/** A call to a helper with the chain's parameters, then `input` when it takes one. */\n\tprivate invoke(helper: string, input: string): string {\n\t\treturn `${helper}(${[this.args, input].filter(Boolean).join(\",\")})`;\n\t}\n\n\tlower({ detached }: { detached: boolean }): string {\n\t\tconst { context, classOwner, source } = this;\n\t\tconst links = this.chain.links;\n\t\tconst operation: Step = {\n\t\t\thelper: this.addHelper(\n\t\t\t\tcontext.names.name(\"tsplcPromiseOperation\", this.chain.root),\n\t\t\t\thelperFinish(this.rootInvocation, this.rootType, { discard: false }),\n\t\t\t\tthis.rootType,\n\t\t\t\tnull,\n\t\t\t),\n\t\t\ttype: this.rootType,\n\t\t\taggregate: isAggregate(\n\t\t\t\tcontext.checker.getAwaitedType(\n\t\t\t\t\tcontext.checker.getTypeAtLocation(this.chain.root),\n\t\t\t\t),\n\t\t\t),\n\t\t};\n\t\tconst last = links.reduce(\n\t\t\t(previous, link, index) =>\n\t\t\t\tthis.link(link, previous, {\n\t\t\t\t\tterminal: detached && index === links.length - 1,\n\t\t\t\t\tindex,\n\t\t\t\t}),\n\t\t\toperation,\n\t\t);\n\t\tconst values = this.params.map((value) => value.expression).join(\",\");\n\t\tif (!detached) {\n\t\t\treturn `${last.helper}(${values})`;\n\t\t}\n\t\tconst site = context.names.name(\"tsplcPromiseSite\", this.chain.root);\n\t\tconst scope = classOwner ?? source;\n\t\tcontext.append(\n\t\t\tscope,\n\t\t\tthis.expression,\n\t\t\t`${classOwner ? \"private \" : \"const \"}${site}=${cooperativeTasksAlias}.define(${last.helper});`,\n\t\t);\n\t\tconst callee = calleeName(this.chain.root.expression);\n\t\tcontext.sites.set(scope, [\n\t\t\t...(context.sites.get(scope) ?? []),\n\t\t\t{ name: site, root: callee && context.symbol(callee) },\n\t\t]);\n\t\treturn `${classOwner ? \"this.\" : \"\"}${site}.start(${values});`;\n\t}\n\n\t/**\n\t * The helper for one link: it awaits the previous step, then calls the fulfilled or\n\t * rejected callback. A terminal link of a detached chain discards the result.\n\t */\n\tprivate link(\n\t\tlink: ChainLink,\n\t\tprevious: Step,\n\t\t{ terminal, index }: { terminal: boolean; index: number },\n\t): Step {\n\t\tconst fulfilled =\n\t\t\tlink.kind === \"then\"\n\t\t\t\t? this.callback(link.handlers[0], previous.type, `${index}Fulfilled`)\n\t\t\t\t: undefined;\n\t\tconst rejected = this.callback(\n\t\t\tlink.handlers[link.kind === \"catch\" ? 0 : 1],\n\t\t\t\"UDINT\",\n\t\t\t`${index}Rejected`,\n\t\t);\n\t\tif (!fulfilled && !rejected) {\n\t\t\treturn previous;\n\t\t}\n\t\tconst output = terminal ? \"void\" : (fulfilled?.type ?? previous.type);\n\t\tif (rejected && !terminal && rejected.type !== output) {\n\t\t\tthis.context.fail(\n\t\t\t\tthis.expression,\n\t\t\t\t\"A recovery callback must return the same PLC type as the fulfilled branch.\",\n\t\t\t);\n\t\t}\n\t\treturn {\n\t\t\thelper: this.addHelper(\n\t\t\t\tthis.context.names.name(`tsplcPromiseChain${index}`, this.chain.root),\n\t\t\t\tlinkBody(\n\t\t\t\t\t{ ...previous, call: this.invoke(previous.helper, \"\") },\n\t\t\t\t\t{ fulfilled, rejected, terminal },\n\t\t\t\t),\n\t\t\t\toutput,\n\t\t\t\tnull,\n\t\t\t),\n\t\t\ttype: output,\n\t\t\taggregate: terminal\n\t\t\t\t? false\n\t\t\t\t: (fulfilled?.aggregate ?? previous.aggregate),\n\t\t};\n\t}\n\n\t/**\n\t * How the chain calls a callback, declaring a helper for it when it needs one. `slot` tells the\n\t * callbacks of one chain apart: its link and whether it fulfils or rejects.\n\t */\n\tprivate callback(\n\t\texpression: ts.Expression | undefined,\n\t\tinputType: string,\n\t\tslot: string,\n\t): Callback | undefined {\n\t\tif (\n\t\t\t!expression ||\n\t\t\texpression.kind === ts.SyntaxKind.NullKeyword ||\n\t\t\t(ts.isIdentifier(expression) && expression.text === \"undefined\")\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tconst { context, source } = this;\n\t\tconst declaration = this.handlerDeclaration(expression);\n\t\tconst callbackSignature =\n\t\t\tcontext.checker.getSignatureFromDeclaration(declaration);\n\t\tconst aggregate = isAggregate(\n\t\t\tcallbackSignature &&\n\t\t\t\tcontext.checker.getAwaitedType(\n\t\t\t\t\tcontext.checker.getReturnTypeOfSignature(callbackSignature),\n\t\t\t\t),\n\t\t);\n\t\tif (!declaration.body || declaration.parameters.length > 1) {\n\t\t\tthis.context.fail(\n\t\t\t\tdeclaration,\n\t\t\t\t\"Promise callbacks take at most one value.\",\n\t\t\t);\n\t\t}\n\t\tif (declaration.getSourceFile() !== source) {\n\t\t\treturn this.namedCallback(expression, declaration, {\n\t\t\t\tinputType,\n\t\t\t\taggregate,\n\t\t\t\tslot,\n\t\t\t});\n\t\t}\n\t\tconst names = new Map(this.captureNames);\n\t\tconst parameter = declaration.parameters[0];\n\t\tif (parameter) {\n\t\t\tconst symbol = ts.isIdentifier(parameter.name)\n\t\t\t\t? context.symbol(parameter.name)\n\t\t\t\t: undefined;\n\t\t\tif (!symbol) {\n\t\t\t\tthis.context.fail(parameter, \"Promise callback parameters need names.\");\n\t\t\t}\n\t\t\tnames.set(symbol, \"promiseValue\");\n\t\t}\n\t\tconst type = this.callbackType(declaration, declaration.body, {\n\t\t\tparameter,\n\t\t\tinputType,\n\t\t});\n\t\tconst name = context.names.name(\n\t\t\t`tsplcPromiseHandler${slot}`,\n\t\t\tthis.chain.root,\n\t\t);\n\t\tconst body = this.replaceNames(declaration.body, names);\n\t\tconst takesInput = Boolean(parameter && inputType !== \"void\");\n\t\tconst handlerParams = [\n\t\t\t...(takesInput ? [`promiseValue:${inputType}`] : []),\n\t\t\t...this.params.map((value) => `${value.name}:${value.type}`),\n\t\t].join(\",\");\n\t\tcontext.append(\n\t\t\tthis.classOwner ?? source,\n\t\t\tdeclaration,\n\t\t\tthis.declare(\n\t\t\t\tname,\n\t\t\t\thandlerParams,\n\t\t\t\ttype,\n\t\t\t\tthis.callbackCode(declaration.body, body, type),\n\t\t\t),\n\t\t);\n\t\treturn {\n\t\t\tcall: (input) =>\n\t\t\t\t`${this.classOwner ? \"this.\" : \"\"}${name}(${[...(takesInput ? [input] : []), ...this.params.map((value) => value.name)].join(\",\")})`,\n\t\t\ttype,\n\t\t\taggregate,\n\t\t};\n\t}\n\n\t/** An inline callback, or the function declaration a named one refers to. */\n\tprivate handlerDeclaration(expression: ts.Expression): Handler {\n\t\tif (ts.isArrowFunction(expression) || ts.isFunctionExpression(expression)) {\n\t\t\treturn expression;\n\t\t}\n\t\tconst key = this.context.symbol(expression);\n\t\tconst named = key && this.context.routines.get(key);\n\t\tif (!named || !ts.isFunctionDeclaration(named)) {\n\t\t\tthis.context.fail(\n\t\t\t\texpression,\n\t\t\t\t\"Use a named function or inline arrow; bind instance methods with an arrow.\",\n\t\t\t);\n\t\t}\n\t\treturn named;\n\t}\n\n\t/** Named callbacks retain their original module and access to its private state. */\n\tprivate namedCallback(\n\t\texpression: ts.Expression,\n\t\tdeclaration: Handler,\n\t\t{\n\t\t\tinputType,\n\t\t\taggregate,\n\t\t\tslot,\n\t\t}: { inputType: string; aggregate: boolean; slot: string },\n\t): Callback {\n\t\tconst { context, source } = this;\n\t\tconst result = declaration.type;\n\t\tif (!result) {\n\t\t\tthis.context.fail(\n\t\t\t\tdeclaration,\n\t\t\t\t\"Annotate callback results with their concrete PLC type.\",\n\t\t\t);\n\t\t}\n\t\tconst callbackType = context.typeText(\n\t\t\tpromisedType(result) ?? result,\n\t\t\tsource,\n\t\t);\n\t\tconst name = expression.getText(source);\n\t\tconst takesInput = declaration.parameters.length > 0;\n\t\tif (hasModifier(declaration, ts.SyntaxKind.AsyncKeyword)) {\n\t\t\treturn {\n\t\t\t\tcall: (input) => `${name}(${takesInput ? input : \"\"})`,\n\t\t\t\ttype: callbackType,\n\t\t\t\taggregate,\n\t\t\t};\n\t\t}\n\t\tconst helper = this.addHelper(\n\t\t\tcontext.names.name(`tsplcPromiseNamed${slot}`, this.chain.root),\n\t\t\tcallbackType === \"void\"\n\t\t\t\t? `${name}(${takesInput ? \"promiseInput\" : \"\"});return;`\n\t\t\t\t: `return ${name}(${takesInput ? \"promiseInput\" : \"\"});`,\n\t\t\tcallbackType,\n\t\t\ttakesInput ? inputType : null,\n\t\t);\n\t\treturn {\n\t\t\tcall: (input) => this.invoke(helper, takesInput ? input : \"\"),\n\t\t\ttype: callbackType,\n\t\t\taggregate,\n\t\t};\n\t}\n\n\t/** An inline callback's result type: its annotation, or what its body evidently returns. */\n\tprivate callbackType(\n\t\tdeclaration: Handler,\n\t\tbody: ts.ConciseBody,\n\t\t{\n\t\t\tparameter,\n\t\t\tinputType,\n\t\t}: {\n\t\t\tparameter: ts.ParameterDeclaration | undefined;\n\t\t\tinputType: string;\n\t\t},\n\t): string {\n\t\tconst { context, source } = this;\n\t\tconst annotation = declaration.type;\n\t\tif (annotation) {\n\t\t\treturn context.typeText(promisedType(annotation) ?? annotation, source);\n\t\t}\n\t\tconst resolved = context.checker.getSignatureFromDeclaration(declaration);\n\t\tconst inferred =\n\t\t\tresolved &&\n\t\t\tcontext.checker.getAwaitedType(\n\t\t\t\tcontext.checker.getReturnTypeOfSignature(resolved),\n\t\t\t);\n\t\tif (inferred && inferred.flags & ts.TypeFlags.Void) {\n\t\t\treturn \"void\";\n\t\t}\n\t\tif (ts.isBlock(body)) {\n\t\t\tthis.context.fail(\n\t\t\t\tdeclaration,\n\t\t\t\t\"Annotate a callback that returns a value with its concrete PLC type.\",\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\tts.isIdentifier(body) &&\n\t\t\tparameter &&\n\t\t\tcontext.symbol(body) === context.symbol(parameter.name)\n\t\t) {\n\t\t\treturn inputType;\n\t\t}\n\t\tconst returned = ts.isCallExpression(body)\n\t\t\t? operation(context, body)?.type\n\t\t\t: undefined;\n\t\tconst promised = returned && promisedType(returned);\n\t\treturn promised\n\t\t\t? context.typeText(promised, source)\n\t\t\t: this.expressionType(body);\n\t}\n\n\t/** A callback body as a helper body: a block's statements, or a returned expression. */\n\tprivate callbackCode(body: ts.ConciseBody, printed: string, type: string) {\n\t\tif (ts.isBlock(body)) {\n\t\t\treturn printed.slice(1, -1);\n\t\t}\n\t\tif (type === \"void\") {\n\t\t\treturn `${printed};return;`;\n\t\t}\n\t\treturn `return ${this.isPromise(body) ? \"await \" : \"\"}${printed};`;\n\t}\n\n\t/** Prints a callback body with captures and its parameter renamed, awaiting returned promises. */\n\tprivate replaceNames(\n\t\tnode: ts.Node,\n\t\tnames: ReadonlyMap<ts.Symbol, string>,\n\t): string {\n\t\tconst { context } = this;\n\t\tconst transformed = ts.transform(node, [\n\t\t\t(transformation) => (root) => {\n\t\t\t\tconst visit = (value: ts.Node): ts.VisitResult<ts.Node> => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tts.isReturnStatement(value) &&\n\t\t\t\t\t\tvalue.expression &&\n\t\t\t\t\t\t!ts.isAwaitExpression(value.expression) &&\n\t\t\t\t\t\tthis.isPromise(value.expression)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn ts.factory.updateReturnStatement(\n\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\tts.factory.createAwaitExpression(\n\t\t\t\t\t\t\t\tts.visitNode(value.expression, visit, ts.isExpression),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (ts.isShorthandPropertyAssignment(value)) {\n\t\t\t\t\t\tconst key =\n\t\t\t\t\t\t\tcontext.checker.getShorthandAssignmentValueSymbol(value);\n\t\t\t\t\t\tconst name = key && names.get(key);\n\t\t\t\t\t\tif (name) {\n\t\t\t\t\t\t\treturn ts.factory.createPropertyAssignment(\n\t\t\t\t\t\t\t\tvalue.name,\n\t\t\t\t\t\t\t\tts.factory.createIdentifier(name),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (ts.isIdentifier(value) && !isPropertyName(value)) {\n\t\t\t\t\t\tconst key = context.symbol(value);\n\t\t\t\t\t\tconst name = key && names.get(key);\n\t\t\t\t\t\tif (name) {\n\t\t\t\t\t\t\treturn ts.factory.createIdentifier(name);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn ts.visitEachChild(value, visit, transformation);\n\t\t\t\t};\n\t\t\t\tconst visited = ts.visitNode(root, visit);\n\t\t\t\tif (!visited) {\n\t\t\t\t\tthrow new Error(\"A callback body lowered to nothing.\");\n\t\t\t\t}\n\t\t\t\treturn visited;\n\t\t\t},\n\t\t]);\n\t\tconst printed = transformed.transformed\n\t\t\t.map((root) =>\n\t\t\t\tprinter.printNode(ts.EmitHint.Unspecified, root, node.getSourceFile()),\n\t\t\t)\n\t\t\t.join(\"\");\n\t\ttransformed.dispose();\n\t\treturn printed;\n\t}\n}\n\nconst printer = ts.createPrinter();\n\nconst isAnnotatedDeclaration = (\n\tnode: ts.Declaration,\n): node is (\n\t| ts.VariableDeclaration\n\t| ts.ParameterDeclaration\n\t| ts.PropertyDeclaration\n\t| ts.PropertySignature\n) & { type: ts.TypeNode } =>\n\t(ts.isVariableDeclaration(node) ||\n\t\tts.isParameter(node) ||\n\t\tts.isPropertyDeclaration(node) ||\n\t\tts.isPropertySignature(node)) &&\n\tnode.type !== undefined;\n\n/**\n * A link helper's body. With both callbacks, the previous result is kept while a failure is\n * caught, so the fulfilled callback runs outside the try and its own failure propagates.\n */\nfunction linkBody(\n\tprevious: Step & { call: string },\n\t{\n\t\tfulfilled,\n\t\trejected,\n\t\tterminal,\n\t}: {\n\t\tfulfilled: Callback | undefined;\n\t\trejected: Callback | undefined;\n\t\tterminal: boolean;\n\t},\n): string {\n\tconst { call: prefix, type: resultType } = previous;\n\tconst success = successCode(fulfilled, resultType, terminal);\n\tconst load =\n\t\tresultType === \"void\"\n\t\t\t? `await ${prefix};`\n\t\t\t: `const promiseResult:${resultType}=await ${prefix};`;\n\tif (rejected && fulfilled) {\n\t\tconst stored =\n\t\t\tresultType === \"void\"\n\t\t\t\t? \"\"\n\t\t\t\t: `let promiseResult:${resultType}=defaultValue<${resultType}>();`;\n\t\tconst attempt =\n\t\t\tresultType === \"void\"\n\t\t\t\t? `await ${prefix};`\n\t\t\t\t: `const loaded:${resultType}=await ${prefix};promiseResult=${copyValue(\"loaded\", previous.aggregate)};`;\n\t\treturn `${stored}let succeeded:BOOL=false;let rejection:UDINT=0;try{${attempt}succeeded=true;}catch(promiseError){rejection=${errorCodeAlias}(promiseError);}if(!succeeded){${helperFinish(rejected.call(\"rejection\"), rejected.type, { discard: terminal })}}${success}`;\n\t}\n\tif (rejected) {\n\t\treturn `try{${load}${success}}catch(promiseError){${helperFinish(rejected.call(`${errorCodeAlias}(promiseError)`), rejected.type, { discard: terminal })}}`;\n\t}\n\treturn `${load}${success}`;\n}\n\nfunction successCode(\n\tfulfilled: Callback | undefined,\n\tresultType: string,\n\tterminal: boolean,\n): string {\n\tif (fulfilled) {\n\t\treturn helperFinish(fulfilled.call(\"promiseResult\"), fulfilled.type, {\n\t\t\tdiscard: terminal,\n\t\t});\n\t}\n\treturn resultType === \"void\" || terminal\n\t\t? \"return;\"\n\t\t: \"return promiseResult;\";\n}\n",
27
+ "import { type Diagnostic, error } from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport { plcSources } from \"./module-graph\";\nimport type { Positions } from \"./positions\";\nimport { dialectFor, inSdk, sdkModules, unaliased } from \"./sdk\";\n\n/** The SDK module of timers and edges, plain source a program imports like its own. */\nconst signals = \"@tsplc/compiler/signals\";\n\n/** Dialect names a program has no use for, with what to write instead. */\nconst unsupported: Readonly<Record<string, string>> = {\n\tFunctionBlock:\n\t\t\"write a plain class, whose instances keep their fields from one scan to the next\",\n\tInput:\n\t\t\"keep the input as a field of the program's state and bind its path in tsplc.config.ts io\",\n\tOutput:\n\t\t\"keep the output as a field of the program's state and bind its path in tsplc.config.ts io\",\n\tInOut:\n\t\t\"pass the object that holds the value; a callee changes it through that object\",\n\tref: \"pass the object that holds the value; a callee changes it through that object\",\n\tOnDelayTimer: `import OnDelayTimer from ${signals}`,\n\tOffDelayTimer: `import OffDelayTimer from ${signals}`,\n\tPulseTimer: `import PulseTimer from ${signals}`,\n\tRisingEdge: `import RisingEdge from ${signals}`,\n\tFallingEdge: `import FallingEdge from ${signals}`,\n\tBlinker:\n\t\t\"write it as a class, as the timers of @tsplc/compiler/signals are written\",\n\tUpCounter: \"count in a field of a class\",\n\tDownCounter: \"count in a field of a class\",\n\tUpDownCounter: \"count in a field of a class\",\n};\n\n/** The SDK's internal exports, which the compiler's own generated code calls. */\nconst internal = new Set([\"cooperativeTasks\", \"opcuaCall\"]);\n\n/** The module a program imports a dialect global from, when it may use it at all. */\nconst importedFrom = (name: string): string =>\n\tname === \"retain\" || name === \"persist\"\n\t\t? sdkModules.retain\n\t\t: sdkModules.types;\n\n/**\n * Where a program's own source uses the tsPLC dialect: its function blocks, IO declarations,\n * references and standard blocks, or a global that a plain program imports instead. The compiler\n * lowers programs into the dialect; a program writes plain TypeScript.\n */\nexport const dialectUses = (\n\tprogram: ts.Program,\n\tsdk: string,\n\tpositions: Positions,\n): Diagnostic[] => {\n\tconst checker = program.getTypeChecker();\n\tconst dialect = dialectFor(sdk);\n\tconst diagnostics: Diagnostic[] = [];\n\tfor (const source of plcSources(program)) {\n\t\tif (inSdk(sdk, source.fileName)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst reported = new Set<string>();\n\t\tconst visit = (node: ts.Node): void => {\n\t\t\tif (ts.isIdentifier(node) && !reported.has(node.text)) {\n\t\t\t\tconst message = dialectUse(checker, sdk, dialect, node);\n\t\t\t\tif (message) {\n\t\t\t\t\treported.add(node.text);\n\t\t\t\t\tdiagnostics.push(error(\"PLC1015\", message, positions.node(node)));\n\t\t\t\t}\n\t\t\t}\n\t\t\tts.forEachChild(node, visit);\n\t\t};\n\t\tvisit(source);\n\t}\n\treturn diagnostics;\n};\n\nconst dialectUse = (\n\tchecker: ts.TypeChecker,\n\tsdk: string,\n\tdialect: string,\n\tnode: ts.Identifier,\n): string | undefined => {\n\tconst symbol = checker.getSymbolAtLocation(node);\n\tconst declaration = symbol?.declarations?.[0];\n\tif (!symbol || !declaration) {\n\t\treturn undefined;\n\t}\n\tconst ambient = declaration.getSourceFile().fileName === dialect;\n\tconst named = unaliased(checker, symbol).declarations?.[0];\n\tconst fromSdk =\n\t\tambient ||\n\t\t(named !== undefined && inSdk(sdk, named.getSourceFile().fileName));\n\tif (!fromSdk) {\n\t\treturn undefined;\n\t}\n\tconst instead = unsupported[node.text];\n\tif (instead) {\n\t\treturn `${node.text} is not part of PLC TypeScript: ${instead}.`;\n\t}\n\tif (internal.has(node.text)) {\n\t\treturn `${node.text} is the compiler's own; a program uses tasks, backgroundTasks and createServiceClient.`;\n\t}\n\treturn ambient\n\t\t? `${node.text} is not a global: import it from ${importedFrom(node.text)}.`\n\t\t: undefined;\n};\n",
28
+ "import { dirname, join, resolve } from \"node:path\";\nimport {\n\ttype Constant,\n\ttype Diagnostic,\n\terror,\n\tidentityDigest,\n\ttype PlcModule,\n\ttype SourceSpan,\n\ttype TypeId,\n} from \"@tsplc/compiler/ir\";\nimport { generatedDirectory } from \"@tsplc/config/project-files\";\nimport ts from \"typescript\";\nimport { modulePath } from \"../lowering-key\";\nimport { plcSources } from \"../module-graph\";\nimport { from, joined, type Mapped, type Positions } from \"../positions\";\nimport { inSdk, namesSdk, sdkModules, unaliased } from \"../sdk\";\nimport { defaultNumericTypes } from \"../types\";\nimport type { BoundPath, CompileDebug } from \"../typescript\";\nimport type { CapturedValue } from \"./capture-protocol\";\nimport { GenericTypes } from \"./generics\";\nimport { captureGraph } from \"./graph\";\nimport { importPath } from \"./imports\";\nimport {\n\tplainName,\n\tquotedField,\n\tstringEnums,\n\ttype TypeDeclarations,\n} from \"./layouts\";\nimport { Model, type Root } from \"./model\";\nimport { unusedName } from \"./names\";\nimport {\n\tconstantInitializer,\n\tdefinesTask,\n\tReduction,\n\tserviceClients,\n\ttype Uncompiled,\n} from \"./reduce\";\nimport { Retention, retentionDeclarations } from \"./retention\";\nimport { closingBrace, Specializer } from \"./specialize\";\nimport type { RootField } from \"./storage\";\nimport { SpecializeError } from \"./values\";\n\n/**\n * A module the compiled program keeps as written: only types, enums, constants, tasks and the\n * service client. Everything else is plain TypeScript that elaboration compiles from its setup graph.\n * A const that scan code writes through, or that `io` binds the hardware to, is state, not a constant.\n */\nconst keptModule = (\n\tsource: ts.SourceFile,\n\tchecker: ts.TypeChecker,\n\tsdk: string,\n\t{\n\t\twritten,\n\t\tbound,\n\t}: { written: ReadonlySet<ts.Symbol>; bound: ReadonlySet<string> },\n): boolean => {\n\tconst work = taskWork(source, checker, sdk);\n\treturn source.statements.every((statement) => {\n\t\tif (\n\t\t\tts.isFunctionDeclaration(statement) &&\n\t\t\tstatement.name &&\n\t\t\twork.has(statement.name.text)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\tif (\n\t\t\tts.isImportDeclaration(statement) ||\n\t\t\tts.isExportDeclaration(statement) ||\n\t\t\tts.isInterfaceDeclaration(statement) ||\n\t\t\tts.isTypeAliasDeclaration(statement) ||\n\t\t\tts.isEnumDeclaration(statement)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\tif (!ts.isVariableStatement(statement)) {\n\t\t\treturn false;\n\t\t}\n\t\treturn statement.declarationList.declarations.every((declaration) => {\n\t\t\tconst symbol = checker.getSymbolAtLocation(declaration.name);\n\t\t\treturn (\n\t\t\t\tdeclaration.initializer &&\n\t\t\t\tconstantInitializer(declaration.initializer, checker, sdk) &&\n\t\t\t\t!(symbol && written.has(symbol)) &&\n\t\t\t\t!(ts.isIdentifier(declaration.name) && bound.has(declaration.name.text))\n\t\t\t);\n\t\t});\n\t});\n};\n\n/** The identifier a place is reached from: `a` of `a.b[i].c`. */\nconst placeRoot = (node: ts.Expression): ts.Identifier | undefined => {\n\tif (ts.isIdentifier(node)) {\n\t\treturn node;\n\t}\n\tif (\n\t\tts.isPropertyAccessExpression(node) ||\n\t\tts.isElementAccessExpression(node) ||\n\t\tts.isParenthesizedExpression(node) ||\n\t\tts.isNonNullExpression(node)\n\t) {\n\t\treturn placeRoot(node.expression);\n\t}\n\treturn undefined;\n};\n\n/** The bindings `sources` assign, or assign a field or element of, through any import of them. */\nconst writtenBindings = (\n\tsources: readonly ts.SourceFile[],\n\tchecker: ts.TypeChecker,\n): Set<ts.Symbol> => {\n\tconst written = new Set<ts.Symbol>();\n\tconst note = (target: ts.Expression) => {\n\t\tconst root = placeRoot(target);\n\t\tconst symbol = root && checker.getSymbolAtLocation(root);\n\t\tif (symbol) {\n\t\t\twritten.add(unaliased(checker, symbol));\n\t\t}\n\t};\n\tconst visit = (node: ts.Node): void => {\n\t\tif (\n\t\t\tts.isBinaryExpression(node) &&\n\t\t\tnode.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&\n\t\t\tnode.operatorToken.kind <= ts.SyntaxKind.LastAssignment\n\t\t) {\n\t\t\tnote(node.left);\n\t\t}\n\t\tif (\n\t\t\t(ts.isPrefixUnaryExpression(node) || ts.isPostfixUnaryExpression(node)) &&\n\t\t\t(node.operator === ts.SyntaxKind.PlusPlusToken ||\n\t\t\t\tnode.operator === ts.SyntaxKind.MinusMinusToken)\n\t\t) {\n\t\t\tnote(node.operand);\n\t\t}\n\t\tts.forEachChild(node, visit);\n\t};\n\tfor (const source of sources) {\n\t\tvisit(source);\n\t}\n\treturn written;\n};\n\n/**\n * The functions a module's tasks run: the names its module-level `define` calls pass as their work,\n * and the module's functions those call, which run in the task too.\n */\nconst taskWork = (\n\tsource: ts.SourceFile,\n\tchecker: ts.TypeChecker,\n\tsdk: string,\n): Set<string> => {\n\tconst functions = new Map(\n\t\tsource.statements.flatMap((statement) =>\n\t\t\tts.isFunctionDeclaration(statement) && statement.name\n\t\t\t\t? [[statement.name.text, statement] as const]\n\t\t\t\t: [],\n\t\t),\n\t);\n\tconst work = new Set<string>();\n\tconst add = (name: string): void => {\n\t\tconst declaration = functions.get(name);\n\t\tif (!declaration || work.has(name)) {\n\t\t\treturn;\n\t\t}\n\t\twork.add(name);\n\t\tconst visit = (node: ts.Node): void => {\n\t\t\tif (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {\n\t\t\t\tconst called = checker\n\t\t\t\t\t.getSymbolAtLocation(node.expression)\n\t\t\t\t\t?.declarations?.find(ts.isFunctionDeclaration);\n\t\t\t\tif (called?.name && called.parent === source) {\n\t\t\t\t\tadd(called.name.text);\n\t\t\t\t}\n\t\t\t}\n\t\t\tts.forEachChild(node, visit);\n\t\t};\n\t\tts.forEachChild(declaration, visit);\n\t};\n\tfor (const statement of source.statements) {\n\t\tif (!ts.isVariableStatement(statement)) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const declaration of statement.declarationList.declarations) {\n\t\t\tconst call = declaration.initializer;\n\t\t\tconst argument =\n\t\t\t\tcall && ts.isCallExpression(call) && definesTask(call, checker, sdk)\n\t\t\t\t\t? call.arguments[0]\n\t\t\t\t\t: undefined;\n\t\t\tif (argument && ts.isIdentifier(argument)) {\n\t\t\t\tadd(argument.text);\n\t\t\t}\n\t\t}\n\t}\n\treturn work;\n};\n\n/**\n * Whether the program is plain TypeScript: it declares a class that is not a function block, one\n * extending the SDK's `FunctionBlock` however the module names it.\n */\nconst needsElaboration = (\n\tsources: readonly ts.SourceFile[],\n\tkept: (file: string) => boolean,\n\tchecker: ts.TypeChecker,\n\tsdk: string,\n): boolean =>\n\tsources.some(\n\t\t(source) =>\n\t\t\t!kept(source.fileName) &&\n\t\t\tsource.statements.some(\n\t\t\t\t(statement) =>\n\t\t\t\t\tts.isClassDeclaration(statement) &&\n\t\t\t\t\t!statement.heritageClauses?.some((clause) =>\n\t\t\t\t\t\tclause.types.some((type) =>\n\t\t\t\t\t\t\tnamesSdk(checker, sdk, type.expression, \"FunctionBlock\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t),\n\t);\n\ninterface Folded {\n\tpath: string;\n\tvalue: Constant;\n\ttype?: TypeId;\n\tspan: SourceSpan;\n}\n\n/**\n * A folded primitive as a PLC constant, with its scalar type: the IEC width its declaration\n * names, or the one a TypeScript number of that value gets. Strings, often enum members, have none.\n */\nconst foldedConstant = (\n\tvalue: CapturedValue,\n\tiec: string | undefined,\n): Pick<Folded, \"value\" | \"type\"> | undefined => {\n\tswitch (value.kind) {\n\t\tcase \"number\":\n\t\t\treturn Number.isInteger(value.value)\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: { kind: \"integer\", value: String(value.value) },\n\t\t\t\t\t\ttype: iec ?? defaultNumericTypes.number,\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\tvalue: { kind: \"float\", value: value.value },\n\t\t\t\t\t\ttype: iec ?? defaultNumericTypes.float,\n\t\t\t\t\t};\n\t\tcase \"bigint\":\n\t\t\treturn {\n\t\t\t\tvalue: { kind: \"integer\", value: value.value },\n\t\t\t\ttype: iec ?? defaultNumericTypes.bigint,\n\t\t\t};\n\t\tcase \"boolean\":\n\t\t\treturn { value: { kind: \"bool\", value: value.value }, type: \"BOOL\" };\n\t\tcase \"string\":\n\t\t\treturn { value: { kind: \"string\", value: value.value } };\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n};\n\n/**\n * Compiles a plain TypeScript program: runs its setup, then specializes its scan code against\n * the objects setup built. The result is tsPLC dialect source the rest of the compiler reads.\n */\nexport const lowerElaboration = (\n\tprogram: ts.Program,\n\tsdk: string,\n\tentries: Readonly<Record<string, { module: string; export: string }>>,\n\troot: string,\n\tpositions: Positions,\n\t{\n\t\tdebug,\n\t\tconfiguration,\n\t\talways,\n\t\tio,\n\t}: {\n\t\tdebug: Pick<CompileDebug, \"stackTraces\">;\n\t\t/** The environment values the program's `env()` calls read, by name, which setup returns. */\n\t\tconfiguration: Readonly<Record<string, string>>;\n\t\t/** Whether every program is plain TypeScript, or only one that declares a plain class. */\n\t\talways: boolean;\n\t\t/** The state paths the config's `io` binds. */\n\t\tio: readonly BoundPath[];\n\t},\n): {\n\tsources: Map<string, Mapped>;\n\tdiagnostics: Diagnostic[];\n\t/** Routines specialized from class methods, by `<entry file>:<routine>`. */\n\torigins: Map<string, { name: string; instance?: string }>;\n\tfolded: Folded[];\n\t/** Each referable object's storage path by the id a reference holds, and the fields that hold one. */\n\treferences: NonNullable<PlcModule[\"references\"]>;\n\t/** The string each member of a literal union's enum stands for, by `<types file>:<enum>`. */\n\tliterals: Map<string, Record<string, string>>;\n\t/** What of each module rewritten here the PLC compiles, where that is not all of it. */\n\treduced: Map<string, Uncompiled>;\n} => {\n\tconst sources = new Map<string, Mapped>();\n\tconst diagnostics: Diagnostic[] = [];\n\tconst origins = new Map<string, { name: string; instance?: string }>();\n\tconst folded: Folded[] = [];\n\tconst literals = new Map<string, Record<string, string>>();\n\tconst reduced = new Map<string, Uncompiled>();\n\tconst references: { id: number; path: string }[] = [];\n\tconst referenceFields: string[] = [];\n\tconst result = {\n\t\tsources,\n\t\tdiagnostics,\n\t\torigins,\n\t\tfolded,\n\t\tliterals,\n\t\treduced,\n\t\treferences: { objects: references, fields: referenceFields },\n\t};\n\tconst runtime = plcSources(program).filter(\n\t\t(source) => !inSdk(sdk, source.fileName),\n\t);\n\tconst checker = program.getTypeChecker();\n\t// The bindings `io` reaches state through, which are never constants.\n\tconst bound = new Set(io.map(({ path }) => path.split(/[.[]/)[0] ?? path));\n\tconst inputs = new Map(\n\t\tio.flatMap(({ path, input }) => (input === null ? [] : [[path, input]])),\n\t);\n\tconst written = writtenBindings(runtime, checker);\n\tconst kept = new Set(\n\t\truntime\n\t\t\t.filter((source) => keptModule(source, checker, sdk, { written, bound }))\n\t\t\t.map((source) => source.fileName),\n\t);\n\tconst isKept = (file: string) => kept.has(file);\n\tif (!always && !needsElaboration(runtime, isKept, checker, sdk)) {\n\t\treturn result;\n\t}\n\tconst scanFunctions = [\n\t\t...new Set(Object.values(entries).map((item) => item.export)),\n\t];\n\tconst modules = new Set(\n\t\tObject.values(entries).map((item) =>\n\t\t\tresolve(root, item.module).replace(/\\\\/g, \"/\"),\n\t\t),\n\t);\n\tconst [entryFile, ...otherModules] = modules;\n\tconst [entry] = Object.values(entries);\n\tif (!entry || !entryFile || otherModules.length) {\n\t\tdiagnostics.push(\n\t\t\terror(\n\t\t\t\t\"PLC1001\",\n\t\t\t\t\"A plain TypeScript program exports all its scan functions from one module.\",\n\t\t\t),\n\t\t);\n\t\treturn result;\n\t}\n\tconst entrySource = program.getSourceFile(entryFile);\n\tif (!entrySource) {\n\t\tdiagnostics.push(\n\t\t\terror(\"PLC1001\", `${entry.module} is not part of the program.`),\n\t\t);\n\t\treturn result;\n\t}\n\tconst directory = join(dirname(entryFile), generatedDirectory).replace(\n\t\t/\\\\/g,\n\t\t\"/\",\n\t);\n\ttry {\n\t\tconst refused = stringEnums(runtime, checker);\n\t\tif (refused.length) {\n\t\t\tthrow new AggregateError(refused);\n\t\t}\n\t\tconst retained = retentionDeclarations(runtime, checker, sdk);\n\t\tconst graph = captureGraph(entryFile, runtime, checker, configuration);\n\t\t// Generic classes specialize per instance, through a checker that knows each one's type arguments.\n\t\tconst generics = new GenericTypes(checker);\n\t\tconst model = new Model(graph, generics.checker, program, entryFile, root, {\n\t\t\tbound,\n\t\t\tinputs,\n\t\t});\n\t\tconst generated = generatedModules(model.roots, { directory, root, bound });\n\t\tconst rootModule = generated.root;\n\t\t// A module that also holds state keeps its client and types, which a reply's type may need: the\n\t\t// router's types have no layout of their own.\n\t\tconst named = (source: ts.SourceFile) =>\n\t\t\tisKept(source.fileName) ||\n\t\t\tserviceClients(source, checker, sdk).length > 0;\n\t\tconst reduction = new Reduction(checker, sdk, {\n\t\t\truntime,\n\t\t\tkept: isKept,\n\t\t\tentry: entrySource,\n\t\t\twritten,\n\t\t\tbound,\n\t\t});\n\t\t// What the entry module declares for other modules to import, beside its code.\n\t\tconst declarations = reduction.entry();\n\t\tconst specializer = new Specializer(\n\t\t\tmodel,\n\t\t\tgenerics,\n\t\t\tsdk,\n\t\t\truntime,\n\t\t\t{\n\t\t\t\tkept: isKept,\n\t\t\t\tnamed,\n\t\t\t\tenumRefusal: (declaration) =>\n\t\t\t\t\treduction.sharesEnum(declaration)\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: reduction.enumRefusal(declaration),\n\t\t\t},\n\t\t\trootModule,\n\t\t);\n\t\tconst scans = scanFunctions.map((name) => {\n\t\t\tconst declaration = findEntry(entrySource, name);\n\t\t\treturn {\n\t\t\t\tname,\n\t\t\t\tdeclaration,\n\t\t\t\tbody: specializedEntry(specializer, declaration),\n\t\t\t};\n\t\t});\n\t\tconst [main] = scans.map((scan) => scan.declaration);\n\t\tif (!main) {\n\t\t\tthrow new Error(\"A plain TypeScript program needs a scan function.\");\n\t\t}\n\t\tif (specializer.failures.length) {\n\t\t\tdiagnostics.push(\n\t\t\t\t...specializer.failures.map((cause) =>\n\t\t\t\t\tfailure(cause, positions, debug),\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn result;\n\t\t}\n\n\t\t// Exported data the hardware, HMI and server address, and any object io binds the hardware\n\t\t// to, is stored whether or not code reads it.\n\t\tfor (const item of model.roots) {\n\t\t\tconst addressed =\n\t\t\t\t(item.exported && item.file === entryFile) || bound.has(item.name);\n\t\t\tif (addressed && !isKept(item.file)) {\n\t\t\t\tspecializer.storage.use(item);\n\t\t\t}\n\t\t}\n\n\t\tfor (const name of specializer.initializers.takeSdkCalls()) {\n\t\t\tspecializer.imports.addSdk(sdkModules.types, name);\n\t\t}\n\t\tconst retention = new Retention(model, specializer.storage, retained);\n\t\tconst stored = [...specializer.storage.roots].map((item) => ({\n\t\t\titem,\n\t\t\t...storageGlobals(specializer, retention, item),\n\t\t}));\n\t\tconst unretained = retention.unclaimed();\n\t\tif (unretained) {\n\t\t\tthrow unretained;\n\t\t}\n\t\t// Writing the globals declared the types they use.\n\t\tconst types = specializer.layouts.snapshot();\n\t\t// A storage module imports the generated types, so none of its variables can have a type's name.\n\t\tconst misnamed = stored.flatMap(({ item, fields }) =>\n\t\t\tfields.flatMap(({ name, declaration }) =>\n\t\t\t\ttypes.declarations.has(name)\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tnew SpecializeError(\n\t\t\t\t\t\t\t\tdeclaration ?? item.declaration,\n\t\t\t\t\t\t\t\t`${item.name}.${name}: each field of ${item.name} becomes a PLC variable of the field's name, and the generated code already names a type ${name}. Rename the field.`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t]\n\t\t\t\t\t: [],\n\t\t\t),\n\t\t);\n\t\tif (misnamed.length) {\n\t\t\tthrow new AggregateError(misnamed);\n\t\t}\n\t\tconst typesFile = generated.types;\n\t\tconst typeImports = (file: string) => [\n\t\t\t...specializer.layouts.imports.lines(file, \"import\"),\n\t\t\t...specializer.layouts.typeImports.lines(file, \"import type\"),\n\t\t];\n\t\tconst importTypes = (file: string) =>\n\t\t\ttypesModuleImports(types, importPath(file, typesFile));\n\t\tsources.set(\n\t\t\ttypesFile,\n\t\t\tjoined([...typeImports(typesFile), ...types.declarations.values()], \"\\n\"),\n\t\t);\n\t\tfor (const { item, lines } of stored) {\n\t\t\tconst file = rootModule(item);\n\t\t\tconst imports = [...typeImports(file), ...importTypes(file)];\n\t\t\tsources.set(\n\t\t\t\tfile,\n\t\t\t\tjoined(\n\t\t\t\t\t[...imports.map((line) => from(item.declaration, line)), ...lines],\n\t\t\t\t\t\"\\n\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tconst header = [\n\t\t\t...typeImports(entryFile),\n\t\t\t...importTypes(entryFile),\n\t\t\t...specializer.imports.lines(entryFile),\n\t\t];\n\t\t// An enum the generated code stores is declared before the code that reads it. What the entry\n\t\t// declares for other modules only comes last, where it moves nothing the program compiled to,\n\t\t// and is left out where the generated code already has the name for something of its own.\n\t\tconst storesEnum = (name: string) =>\n\t\t\tspecializer.layouts.imports.has(entryFile, name);\n\t\tconst free = ({ name }: { name: string }) =>\n\t\t\t!storesEnum(name) &&\n\t\t\t!specializer.named(name) &&\n\t\t\t!types.declarations.has(name);\n\t\tconst declared = [\n\t\t\t...declarations.enums.filter(free),\n\t\t\t...declarations.constants.filter(free),\n\t\t];\n\t\treduction.declaredByEntry(\n\t\t\tnew Set(\n\t\t\t\t[\n\t\t\t\t\t...declarations.enums.filter(({ name }) => storesEnum(name)),\n\t\t\t\t\t...declared,\n\t\t\t\t].map(({ name }) => name),\n\t\t\t),\n\t\t);\n\t\tsources.set(\n\t\t\tentryFile,\n\t\t\tjoined(\n\t\t\t\t[\n\t\t\t\t\t...header.map((line) => from(main, line)),\n\t\t\t\t\t...declarations.enums\n\t\t\t\t\t\t.filter(({ name }) => storesEnum(name))\n\t\t\t\t\t\t.map(({ line }) => line),\n\t\t\t\t\t...specializer.expressions.tableDeclarations,\n\t\t\t\t\t...specializer.routines,\n\t\t\t\t\t...scans.flatMap(({ name, declaration, body }) => [\n\t\t\t\t\t\tfrom(declaration, `export function ${name}(): void {`),\n\t\t\t\t\t\t...body,\n\t\t\t\t\t\tfrom(closingBrace(declaration), \"}\"),\n\t\t\t\t\t]),\n\t\t\t\t\t...declared.map(({ line }) => line),\n\t\t\t\t],\n\t\t\t\t\"\\n\",\n\t\t\t),\n\t\t);\n\t\tfor (const [name, origin] of specializer.origins) {\n\t\t\torigins.set(`${entryFile}:${name}`, origin);\n\t\t}\n\t\tfor (const { name, members } of specializer.layouts.literalEnums) {\n\t\t\tliterals.set(`${typesFile}:${name}`, members);\n\t\t}\n\t\tconst table = specializer.storage.referenceTable();\n\t\treferences.push(...table.references);\n\t\treferenceFields.push(...table.referenceFields);\n\t\tfor (const item of specializer.storage.folded()) {\n\t\t\tconst known = foldedConstant(item.value, item.iec);\n\t\t\tif (known) {\n\t\t\t\tfolded.push({\n\t\t\t\t\tpath: item.path,\n\t\t\t\t\t...known,\n\t\t\t\t\tspan: positions.node(item.declaration),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tfor (const source of reduction.modules) {\n\t\t\tsources.set(source.fileName, reduction.module(source));\n\t\t\treduced.set(source.fileName, { compiled: reduction.compiled(source) });\n\t\t}\n\t\treduced.set(entryFile, {\n\t\t\tdeclared: new Set(\n\t\t\t\t[...declarations.enums, ...declarations.constants].map(\n\t\t\t\t\t({ name }) => name,\n\t\t\t\t),\n\t\t\t),\n\t\t});\n\t} catch (cause) {\n\t\tconst causes = cause instanceof AggregateError ? cause.errors : [cause];\n\t\tdiagnostics.push(\n\t\t\t...causes.map((reported) => failure(reported, positions, debug)),\n\t\t);\n\t}\n\treturn result;\n};\n\n/**\n * The entry's specialized body. When specializing fails, the failures statements recorded before\n * escape with the cause: often they are its cause, as a skipped declaration's name is then unknown.\n */\nconst specializedEntry = (\n\tspecializer: Specializer,\n\tmain: ts.FunctionDeclaration | ts.ArrowFunction,\n): Mapped[] => {\n\ttry {\n\t\treturn specializer.entry(main);\n\t} catch (cause) {\n\t\tthrow new AggregateError([...specializer.failures, cause]);\n\t}\n};\n\n/** The imports of what the types module declares, from a module that reaches it at `path`. */\nconst typesModuleImports = (\n\ttypes: TypeDeclarations,\n\tpath: string,\n): string[] => {\n\tconst interfaces = [...types.declarations.keys()].filter(\n\t\t(name) => !types.enums.includes(name),\n\t);\n\treturn [\n\t\t...(types.enums.length\n\t\t\t? [`import { ${types.enums.join(\", \")} } from \"${path}\";`]\n\t\t\t: []),\n\t\t...(interfaces.length\n\t\t\t? [`import type { ${interfaces.join(\", \")} } from \"${path}\";`]\n\t\t\t: []),\n\t];\n};\n\n/**\n * The globals of a root's storage module: one per stored field of a record or instance, or the\n * root itself. The entry module assigns them through its namespace import of this module.\n * `fields` are the fields that became globals, each of which must be able to name a variable.\n */\nconst storageGlobals = (\n\tspecializer: Specializer,\n\tretention: Retention,\n\titem: Root,\n): { lines: Mapped[]; fields: RootField[] } => {\n\tconst { model, checker, layouts, storage, initializers } = specializer;\n\tconst lines: Mapped[] = [];\n\t/** The SDK calls the globals' initializers are wrapped in, `retain` or `persist`. */\n\tconst kept = new Set<string>();\n\tconst global = ({\n\t\tname,\n\t\tlayout,\n\t\tinitial,\n\t\tdeclaration,\n\t}: {\n\t\tname: string;\n\t\tlayout: string;\n\t\tinitial: string;\n\t\tdeclaration: ts.Node | undefined;\n\t}) => {\n\t\tconst origin = declaration ?? item.declaration;\n\t\tconst keeps = retention.global(item, storage.flattened(item) ? name : null);\n\t\tif (keeps !== \"none\") {\n\t\t\tkept.add(keeps);\n\t\t}\n\t\tconst value = keeps === \"none\" ? initial : `${keeps}(${initial})`;\n\t\tlines.push(from(origin, `export let ${name}: ${layout} = ${value};`));\n\t};\n\tconst node = model.node(item.value);\n\tconst sdkImports = (): Mapped[] => {\n\t\tconst calls = [...[...kept].sort(), ...initializers.takeSdkCalls()];\n\t\treturn calls.length\n\t\t\t? [\n\t\t\t\t\tfrom(\n\t\t\t\t\t\titem.declaration,\n\t\t\t\t\t\t`import { ${calls.join(\", \")} } from \"${sdkModules.types}\";`,\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t: [];\n\t};\n\tif (!node || !storage.flattened(item)) {\n\t\tconst declared = checker.getTypeAtLocation(item.declaration.name);\n\t\tconst layout = layouts.declaredText(item.declaration, declared, item.value);\n\t\tglobal({\n\t\t\tname: item.name,\n\t\t\tlayout,\n\t\t\tinitial: initializers.valueText(item.value, declared, layout),\n\t\t\tdeclaration: item.declaration,\n\t\t});\n\t\treturn { lines: [...sdkImports(), ...lines], fields: [] };\n\t}\n\tconst fieldInitializer = (name: string, layout: string): string => {\n\t\tif (node.captured.kind === \"instance\") {\n\t\t\treturn initializers.instanceFieldInitializer(node, name, layout);\n\t\t}\n\t\tconst declared = model.capturedFieldType(node, name);\n\t\tif (!declared) {\n\t\t\tthrow new Error(`${item.name}.${name} has no declared type.`);\n\t\t}\n\t\treturn initializers.valueText(model.field(node, name), declared, layout);\n\t};\n\tconst fields = storage.rootFields(item);\n\tfor (const field of fields) {\n\t\tconst origin = field.declaration ?? item.declaration;\n\t\tif (!plainName(field.name)) {\n\t\t\tthrow quotedField(origin, field.name);\n\t\t}\n\t\tif (reservedWords.has(field.name)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\torigin,\n\t\t\t\t`${item.name}.${field.name}: each field of ${item.name} becomes a PLC variable of the field's name, and \"${field.name}\" is a word TypeScript reserves, so no variable can have it. Rename the field.`,\n\t\t\t);\n\t\t}\n\t\tglobal({\n\t\t\t...field,\n\t\t\tinitial: fieldInitializer(field.name, field.layout),\n\t\t});\n\t}\n\treturn { lines: [...sdkImports(), ...lines], fields };\n};\n\n/**\n * The words no variable of a module can be named, exactly: every other word TypeScript knows,\n * such as `out`, `type` and `of`, names a variable as any name does.\n */\nconst reservedWords: ReadonlySet<string> = new Set([\n\t\"arguments\",\n\t\"await\",\n\t\"break\",\n\t\"case\",\n\t\"catch\",\n\t\"class\",\n\t\"const\",\n\t\"continue\",\n\t\"debugger\",\n\t\"default\",\n\t\"delete\",\n\t\"do\",\n\t\"else\",\n\t\"enum\",\n\t\"eval\",\n\t\"export\",\n\t\"extends\",\n\t\"false\",\n\t\"finally\",\n\t\"for\",\n\t\"function\",\n\t\"if\",\n\t\"implements\",\n\t\"import\",\n\t\"in\",\n\t\"instanceof\",\n\t\"interface\",\n\t\"let\",\n\t\"new\",\n\t\"null\",\n\t\"package\",\n\t\"private\",\n\t\"protected\",\n\t\"public\",\n\t\"return\",\n\t\"static\",\n\t\"super\",\n\t\"switch\",\n\t\"this\",\n\t\"throw\",\n\t\"true\",\n\t\"try\",\n\t\"typeof\",\n\t\"var\",\n\t\"void\",\n\t\"while\",\n\t\"with\",\n\t\"yield\",\n]);\n\n/** An elaboration failure as a diagnostic, at the node specialization stopped at when it knows one. */\nconst failure = (\n\tcause: unknown,\n\tpositions: Positions,\n\tdebug: Pick<CompileDebug, \"stackTraces\">,\n): Diagnostic => {\n\tif (cause instanceof SpecializeError) {\n\t\treturn error(\"PLC1010\", cause.message, positions.node(cause.node));\n\t}\n\tif (!(cause instanceof Error)) {\n\t\treturn error(\"PLC1010\", String(cause));\n\t}\n\treturn error(\n\t\t\"PLC1010\",\n\t\tdebug.stackTraces ? String(cause.stack) : cause.message,\n\t);\n};\n\nconst findEntry = (\n\tsource: ts.SourceFile,\n\tname: string,\n): ts.FunctionDeclaration | ts.ArrowFunction => {\n\tfor (const statement of source.statements) {\n\t\tif (\n\t\t\tts.isFunctionDeclaration(statement) &&\n\t\t\tstatement.name?.text === name &&\n\t\t\tstatement.body\n\t\t) {\n\t\t\treturn statement;\n\t\t}\n\t\tif (ts.isVariableStatement(statement)) {\n\t\t\tfor (const declaration of statement.declarationList.declarations) {\n\t\t\t\tif (\n\t\t\t\t\tts.isIdentifier(declaration.name) &&\n\t\t\t\t\tdeclaration.name.text === name &&\n\t\t\t\t\tdeclaration.initializer &&\n\t\t\t\t\tts.isArrowFunction(declaration.initializer)\n\t\t\t\t) {\n\t\t\t\t\treturn declaration.initializer;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tthrow new Error(`${source.fileName} exports no function ${name}.`);\n};\n\n/**\n * The generated modules: each root's storage module, and the module of generated types. A root's\n * module has the root's name, which io and the HMI reach its storage by, so the types module is\n * the one that gives way to a root named like it.\n *\n * Roots in different modules can share a name, up to case, and would then share one module and its\n * list; each of them is qualified by its own module instead. The config's `io` names a root by its\n * binding name, which then names none of them, so that is refused.\n */\nconst generatedModules = (\n\troots: readonly Root[],\n\t{\n\t\tdirectory,\n\t\troot: projectRoot,\n\t\tbound,\n\t}: { directory: string; root: string; bound: ReadonlySet<string> },\n): { root: (item: Root) => string; types: string } => {\n\tconst shareName = (item: Root) =>\n\t\troots.filter(\n\t\t\t(other) => other.name.toLowerCase() === item.name.toLowerCase(),\n\t\t);\n\tconst ambiguous = roots.filter(\n\t\t(item) => bound.has(item.name) && shareName(item).length > 1,\n\t);\n\tif (ambiguous.length) {\n\t\tthrow new AggregateError(\n\t\t\tambiguous.map((item) => {\n\t\t\t\tconst modules = shareName(item).map((other) =>\n\t\t\t\t\tmodulePath(projectRoot, other.file),\n\t\t\t\t);\n\t\t\t\treturn new SpecializeError(\n\t\t\t\t\titem.declaration,\n\t\t\t\t\t`The config's io names this root ${item.name}, which roots in ${modules.join(\" and \")} share: rename one of them.`,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t}\n\tconst qualified = (item: Root): string => {\n\t\tconst module = modulePath(projectRoot, item.file);\n\t\tconst sharing = shareName(item);\n\t\tif (sharing.length === 1) {\n\t\t\treturn item.name;\n\t\t}\n\t\t// Two roots of one module differ only in their capitals, which a file's name can't tell apart.\n\t\t// The last of them keeps the name the module alone gives, as it always had; the others add their own.\n\t\tconst twins = sharing.filter((other) => other.file === item.file);\n\t\treturn twins.at(-1) === item\n\t\t\t? `${item.name}_${identityDigest(module)}`\n\t\t\t: `${item.name}_${identityDigest(`${module}\\0${item.name}`)}`;\n\t};\n\tconst taken = new Set(roots.map((item) => qualified(item).toLowerCase()));\n\treturn {\n\t\troot: (item) => `${directory}/${qualified(item)}.ts`,\n\t\ttypes: `${directory}/${unusedName(\"types\", (name) => taken.has(name))}.ts`,\n\t};\n};\n",
29
+ "import ts from \"typescript\";\n\nconst isTypeReference = (type: ts.Type): type is ts.TypeReference =>\n\tBoolean(type.flags & ts.TypeFlags.Object) &&\n\t\"objectFlags\" in type &&\n\ttypeof type.objectFlags === \"number\" &&\n\tBoolean(type.objectFlags & ts.ObjectFlags.Reference);\n\n/**\n * Generic classes specialize per instance. While an instance's methods are specialized, the checker\n * the elaborator reads through answers with that instance's type arguments in place of its class's\n * type parameters, so `Ring<number>`'s `T[]` lays out as `number[]`.\n */\nexport class GenericTypes {\n\treadonly checker: ts.TypeChecker;\n\tprivate readonly scopes: Map<ts.Type, ts.Type>[] = [];\n\n\tconstructor(private readonly base: ts.TypeChecker) {\n\t\tthis.checker = new Proxy(base, {\n\t\t\tget: (target, property, receiver) => {\n\t\t\t\tconst value: unknown = Reflect.get(target, property, receiver);\n\t\t\t\tif (typeof value !== \"function\") {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t\t// Any answer that is a type, or a list of them, can name a type parameter.\n\t\t\t\treturn (...args: unknown[]) => {\n\t\t\t\t\tconst result: unknown = value.apply(target, args);\n\t\t\t\t\tif (isType(result)) {\n\t\t\t\t\t\treturn this.substitute(result);\n\t\t\t\t\t}\n\t\t\t\t\tif (Array.isArray(result) && result.every(isType)) {\n\t\t\t\t\t\treturn result.map((type) => this.substitute(type));\n\t\t\t\t\t}\n\t\t\t\t\treturn result;\n\t\t\t\t};\n\t\t\t},\n\t\t});\n\t}\n\n\t/** Runs `work` with the type arguments of `instanceType`, a generic class's instance, in scope. */\n\twithin<T>(\n\t\tdeclaration: ts.ClassLikeDeclaration | undefined,\n\t\tinstanceType: ts.Type | undefined,\n\t\twork: () => T,\n\t): T {\n\t\tconst parameters = declaration?.typeParameters ?? [];\n\t\tif (!parameters.length || !instanceType || !isTypeReference(instanceType)) {\n\t\t\treturn work();\n\t\t}\n\t\tconst args = this.base.getTypeArguments(instanceType);\n\t\tconst scope = new Map(\n\t\t\tparameters.flatMap((parameter, index): [ts.Type, ts.Type][] => {\n\t\t\t\tconst arg = args[index];\n\t\t\t\treturn arg\n\t\t\t\t\t? [[this.base.getTypeAtLocation(parameter), this.substitute(arg)]]\n\t\t\t\t\t: [];\n\t\t\t}),\n\t\t);\n\t\tthis.scopes.push(scope);\n\t\ttry {\n\t\t\treturn work();\n\t\t} finally {\n\t\t\tthis.scopes.pop();\n\t\t}\n\t}\n\n\t/**\n\t * Calls one of the checker's type constructors. TypeScript 6 has them on every checker but leaves\n\t * them out of its public declarations, so they are looked up by name.\n\t */\n\tprivate construct(\n\t\tname: \"getUnionType\" | \"createArrayType\",\n\t\targument: ts.Type | readonly ts.Type[],\n\t): ts.Type {\n\t\tconst make: unknown = Reflect.get(this.base, name);\n\t\tif (typeof make !== \"function\") {\n\t\t\tthrow new Error(`This TypeScript's checker has no ${name}.`);\n\t\t}\n\t\tconst made: unknown = make.call(this.base, argument);\n\t\tif (!isType(made)) {\n\t\t\tthrow new Error(`${name} made no type.`);\n\t\t}\n\t\treturn made;\n\t}\n\n\t/** A type with the type parameters in scope replaced, through unions and arrays. */\n\tsubstitute(type: ts.Type): ts.Type {\n\t\tif (!this.scopes.length) {\n\t\t\treturn type;\n\t\t}\n\t\tif (type.flags & ts.TypeFlags.TypeParameter) {\n\t\t\tfor (let index = this.scopes.length - 1; index >= 0; index--) {\n\t\t\t\tconst found = this.scopes[index]?.get(type);\n\t\t\t\tif (found) {\n\t\t\t\t\treturn found;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn type;\n\t\t}\n\t\tif (type.isUnion()) {\n\t\t\tconst members = type.types.map((member) => this.substitute(member));\n\t\t\treturn members.some((member, index) => member !== type.types[index])\n\t\t\t\t? this.construct(\"getUnionType\", members)\n\t\t\t\t: type;\n\t\t}\n\t\tif (this.base.isArrayType(type) && isTypeReference(type)) {\n\t\t\tconst [element] = this.base.getTypeArguments(type);\n\t\t\tconst replaced = element && this.substitute(element);\n\t\t\treturn replaced && replaced !== element\n\t\t\t\t? this.construct(\"createArrayType\", replaced)\n\t\t\t\t: type;\n\t\t}\n\t\treturn type;\n\t}\n}\n\n/** Whether a checker's answer is a type; a signature also has flags and its checker, but no type's methods. */\nconst isType = (value: unknown): value is ts.Type =>\n\ttypeof value === \"object\" &&\n\tvalue !== null &&\n\t\"flags\" in value &&\n\t\"checker\" in value &&\n\t\"isUnion\" in value;\n",
30
+ "import { spawnSync } from \"node:child_process\";\nimport { mkdtempSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport ts from \"typescript\";\nimport { z } from \"zod\";\nimport { valueSymbol } from \"../sdk\";\nimport { isPropertyName } from \"../types\";\nimport {\n\tbindingNames,\n\ttype CapturedGraph,\n\ttype CaptureRequest,\n\ttype ClosureSite,\n\tcapturedGraphSchema,\n} from \"./capture-protocol\";\nimport { within } from \"./writes\";\n\n/**\n * Every arrow and function expression not bound at module level, which setup may store, with the\n * names it captures from the functions around it, and `this` when it reads it. Setup notes what each\n * captured when it made it, so the PLC can call it with those values.\n */\nexport const closureSites = (\n\tsource: ts.SourceFile,\n\tchecker: ts.TypeChecker,\n): ClosureSite[] => {\n\tconst sites: ClosureSite[] = [];\n\tconst visit = (node: ts.Node, enclosing: ts.Node | undefined): void => {\n\t\tconst closure = ts.isArrowFunction(node) || ts.isFunctionExpression(node);\n\t\t// A module-level const's function is captured by its name instead.\n\t\tif (closure && !moduleFunction(node)) {\n\t\t\tsites.push({\n\t\t\t\tstart: node.getStart(source),\n\t\t\t\tend: node.end,\n\t\t\t\tcaptures: enclosing ? captures(node, enclosing, checker) : [],\n\t\t\t});\n\t\t}\n\t\tconst scope =\n\t\t\tts.isFunctionLike(node) || ts.isClassLike(node) ? node : enclosing;\n\t\tts.forEachChild(node, (child) => visit(child, scope));\n\t};\n\tvisit(source, undefined);\n\treturn sites;\n};\n\n/** The names a closure reads that the functions around it declare, and `this` if an arrow reads it. */\nconst captures = (\n\tclosure: ts.ArrowFunction | ts.FunctionExpression,\n\tenclosing: ts.Node,\n\tchecker: ts.TypeChecker,\n): string[] => {\n\tconst names = new Set<string>();\n\tconst visit = (node: ts.Node): void => {\n\t\tif (\n\t\t\tnode.kind === ts.SyntaxKind.ThisKeyword &&\n\t\t\tts.isArrowFunction(closure)\n\t\t) {\n\t\t\tnames.add(\"this\");\n\t\t}\n\t\tif (ts.isIdentifier(node) && !isPropertyName(node)) {\n\t\t\tconst declaration = valueSymbol(checker, node)?.valueDeclaration;\n\t\t\tif (\n\t\t\t\tdeclaration &&\n\t\t\t\t!within(declaration, closure) &&\n\t\t\t\twithin(declaration, enclosing) &&\n\t\t\t\t!ts.isClassLike(declaration)\n\t\t\t) {\n\t\t\t\tnames.add(node.text);\n\t\t\t}\n\t\t}\n\t\tif (!ts.isTypeNode(node)) {\n\t\t\tts.forEachChild(node, visit);\n\t\t}\n\t};\n\tvisit(closure.body);\n\treturn [...names];\n};\n\n/** A function a module-level const names, which capture finds by that name. */\nconst moduleFunction = (\n\tnode: ts.ArrowFunction | ts.FunctionExpression,\n): boolean => {\n\tconst declaration = node.parent;\n\tconst statement = declaration?.parent?.parent;\n\treturn (\n\t\tts.isVariableDeclaration(declaration) &&\n\t\tstatement !== undefined &&\n\t\tts.isVariableStatement(statement) &&\n\t\tts.isSourceFile(statement.parent)\n\t);\n};\n\n/** Runs the setup of the program's runtime `sources` in a Bun subprocess and returns the object graph it built. */\nexport const captureGraph = (\n\tentry: string,\n\tsources: readonly ts.SourceFile[],\n\tchecker: ts.TypeChecker,\n\tconfiguration: Readonly<Record<string, string>>,\n): CapturedGraph => {\n\tconst request: CaptureRequest = {\n\t\tentry,\n\t\tconfiguration,\n\t\tfiles: sources.map((source) => source.fileName),\n\t\tclosures: Object.fromEntries(\n\t\t\tsources.map((source) => [source.fileName, closureSites(source, checker)]),\n\t\t),\n\t\tbindings: Object.fromEntries(\n\t\t\tsources.map((source) => [source.fileName, bindingNames(source)]),\n\t\t),\n\t};\n\tconst directory = mkdtempSync(join(tmpdir(), \"tsplc-capture-\"));\n\ttry {\n\t\tconst file = join(directory, \"request.json\");\n\t\twriteFileSync(file, JSON.stringify(request));\n\t\tconst script = fileURLToPath(import.meta.resolve(\"#elaborate-capture\"));\n\t\t// The graph has its own file, so setup code is free to write to standard output.\n\t\tconst output = join(directory, \"graph.json\");\n\t\tconst result = spawnSync(process.execPath, [script, file, output], {\n\t\t\tencoding: \"utf8\",\n\t\t\tstdio: [\"ignore\", \"ignore\", \"pipe\"],\n\t\t\tmaxBuffer: 256 * 1024 * 1024,\n\t\t});\n\t\tif (result.status !== 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`Running the program's setup failed:\\n${result.stderr.trim()}`,\n\t\t\t);\n\t\t}\n\t\tconst graph = capturedGraphSchema.safeParse(\n\t\t\tJSON.parse(readFileSync(output, \"utf8\")),\n\t\t);\n\t\tif (!graph.success) {\n\t\t\tthrow new Error(\n\t\t\t\t`The program's setup produced an invalid object graph:\\n${z.prettifyError(graph.error)}`,\n\t\t\t);\n\t\t}\n\t\treturn graph.data;\n\t} finally {\n\t\trmSync(directory, { recursive: true, force: true });\n\t}\n};\n",
31
+ "import { readFileSync, realpathSync } from \"node:fs\";\nimport type { PluginBuilder } from \"bun\";\nimport ts from \"typescript\";\nimport { z } from \"zod\";\n\n// The files the compiler and its setup subprocess (capture.ts) exchange: the request names the\n// program's runtime files and the bindings each declares; the graph is what setup built. Setup\n// and the Bun runtime both load the program's modules with a registry of those bindings.\n\n/** An arrow or function expression setup may store, and the names it captures from around it. */\nconst closureSiteSchema = z.strictObject({\n\tstart: z.number().int().nonnegative(),\n\tend: z.number().int().nonnegative(),\n\tcaptures: z.array(z.string()),\n});\nexport type ClosureSite = z.infer<typeof closureSiteSchema>;\n\nconst bindingNamesSchema = z.strictObject({\n\tvalues: z.array(z.string()),\n\tclasses: z.array(z.string()),\n\tfunctions: z.array(z.string()),\n});\nexport type BindingNames = z.infer<typeof bindingNamesSchema>;\n\nexport const captureRequestSchema = z.strictObject({\n\tentry: z.string().nonempty(),\n\tfiles: z.array(z.string().nonempty()),\n\t/** By file, each closure whose creation setup notes, with what it captured. */\n\tclosures: z.record(z.string(), z.array(closureSiteSchema)),\n\tbindings: z.record(z.string(), bindingNamesSchema),\n\t/**\n\t * What each of the program's `env()` calls reads, by name. Only those values: the rest of the\n\t * environment, secrets the program never reads among it, stays out of this file.\n\t */\n\tconfiguration: z.record(z.string(), z.string()),\n});\nexport type CaptureRequest = z.infer<typeof captureRequestSchema>;\n\n/** The names a declaration's name binds: itself, or every name in its destructuring pattern. */\nexport const boundNames = (name: ts.BindingName): ts.Identifier[] =>\n\tts.isIdentifier(name)\n\t\t? [name]\n\t\t: name.elements.flatMap((element) =>\n\t\t\t\tts.isOmittedExpression(element) ? [] : boundNames(element.name),\n\t\t\t);\n\n/** The top-level bindings a module declares: values, classes and functions, arrow functions among them. */\nexport const bindingNames = (source: ts.SourceFile): BindingNames => {\n\tconst found: BindingNames = { values: [], classes: [], functions: [] };\n\tfor (const statement of source.statements) {\n\t\tif (ts.isVariableStatement(statement)) {\n\t\t\tfor (const declaration of statement.declarationList.declarations) {\n\t\t\t\t// A stored callback names its binding, so a function a variable holds is a function.\n\t\t\t\tif (\n\t\t\t\t\tts.isIdentifier(declaration.name) &&\n\t\t\t\t\tdeclaration.initializer &&\n\t\t\t\t\t(ts.isArrowFunction(declaration.initializer) ||\n\t\t\t\t\t\tts.isFunctionExpression(declaration.initializer))\n\t\t\t\t) {\n\t\t\t\t\tfound.functions.push(declaration.name.text);\n\t\t\t\t} else {\n\t\t\t\t\tfound.values.push(\n\t\t\t\t\t\t...boundNames(declaration.name).map((name) => name.text),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (ts.isClassDeclaration(statement) && statement.name) {\n\t\t\tfound.classes.push(statement.name.text);\n\t\t} else if (\n\t\t\tts.isFunctionDeclaration(statement) &&\n\t\t\tstatement.name &&\n\t\t\tstatement.body\n\t\t) {\n\t\t\tfound.functions.push(statement.name.text);\n\t\t}\n\t}\n\treturn found;\n};\n\nconst registryExport = \"__tsplcBindings\";\n\n/**\n * A module's top-level bindings as a host reads them: each value through a getter, so a `let`\n * reads as it is now, and its classes and functions themselves.\n */\nconst registrySchema = z.object({\n\tvalues: z.record(\n\t\tz.string(),\n\t\tz.custom<() => unknown>((value) => typeof value === \"function\"),\n\t),\n\tclasses: z.record(z.string(), z.unknown()),\n\tfunctions: z.record(z.string(), z.unknown()),\n});\nexport type Registry = z.infer<typeof registrySchema>;\n\n/** The registry a module loaded through `loadWithBindingRegistry` exports; undefined for any other module. */\nexport const bindingRegistry = (\n\tloaded: Record<string, unknown>,\n): Registry | undefined => {\n\tconst registry = registrySchema.safeParse(loaded[registryExport]);\n\treturn registry.success ? registry.data : undefined;\n};\n\nconst withBindingRegistry = (source: string, names: BindingNames) =>\n\t`${source}\\n;export const ${registryExport} = { values: { ${names.values\n\t\t.map((name) => `${JSON.stringify(name)}: () => ${name}`)\n\t\t.join(\", \")} }, classes: { ${names.classes\n\t\t.map((name) => `${JSON.stringify(name)}: ${name}`)\n\t\t.join(\", \")} }, functions: { ${names.functions\n\t\t.map((name) => `${JSON.stringify(name)}: ${name}`)\n\t\t.join(\", \")} } };\\n`;\n\nconst escapeRegExp = (text: string) =>\n\ttext.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\n/**\n * Has Bun load each of `files` with its binding registry: `module` turns the file's source into\n * the source that runs and the bindings it exports.\n */\nexport const loadWithBindingRegistry = (\n\tbuild: PluginBuilder,\n\tfiles: readonly string[],\n\tmodule: (loaded: { file: string; source: string }) => {\n\t\tsource: string;\n\t\tbindings: BindingNames;\n\t},\n): void => {\n\t// Bun loads modules by their real path; the compiler may name them through a symlink.\n\tconst named = new Map(files.map((file) => [realpathSync(file), file]));\n\tfor (const [path, file] of named) {\n\t\tbuild.onLoad({ filter: new RegExp(`^${escapeRegExp(path)}$`) }, () => {\n\t\t\tconst { source, bindings } = module({\n\t\t\t\tfile,\n\t\t\t\tsource: readFileSync(path, \"utf8\"),\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tcontents: withBindingRegistry(source, bindings),\n\t\t\t\tloader: path.endsWith(\".tsx\") ? \"tsx\" : \"ts\",\n\t\t\t};\n\t\t});\n\t}\n};\n\nconst capturedValueSchema = z.discriminatedUnion(\"kind\", [\n\tz.strictObject({ kind: z.literal(\"undefined\") }),\n\t// JSON has no NaN or infinity; capture rejects them rather than write null.\n\tz.strictObject({ kind: z.literal(\"number\"), value: z.number() }),\n\tz.strictObject({ kind: z.literal(\"boolean\"), value: z.boolean() }),\n\tz.strictObject({ kind: z.literal(\"string\"), value: z.string() }),\n\tz.strictObject({\n\t\tkind: z.literal(\"bigint\"),\n\t\tvalue: z.string().regex(/^-?\\d+$/),\n\t}),\n\tz.strictObject({\n\t\tkind: z.literal(\"node\"),\n\t\tid: z.number().int().nonnegative(),\n\t}),\n]);\nexport type CapturedValue = z.infer<typeof capturedValueSchema>;\n\n/** A captured value that is not an object setup built. */\nexport type CapturedPrimitive = Exclude<CapturedValue, { kind: \"node\" }>;\n\nconst fieldsSchema = z.record(z.string(), capturedValueSchema);\n\nconst capturedNodeSchema = z.discriminatedUnion(\"kind\", [\n\tz.strictObject({ kind: z.literal(\"object\"), fields: fieldsSchema }),\n\tz.strictObject({\n\t\tkind: z.literal(\"instance\"),\n\t\tfile: z.string(),\n\t\tname: z.string(),\n\t\tfields: fieldsSchema,\n\t}),\n\tz.strictObject({\n\t\tkind: z.literal(\"array\"),\n\t\titems: z.array(capturedValueSchema),\n\t}),\n\tz.strictObject({\n\t\tkind: z.literal(\"function\"),\n\t\tfile: z.string(),\n\t\tname: z.string(),\n\t}),\n\tz.strictObject({ kind: z.literal(\"service\"), path: z.string() }),\n\t/** What `tasks.define` or `backgroundTasks.define` returned: a task the PLC runs, which scan code calls through its binding. */\n\tz.strictObject({ kind: z.literal(\"task\") }),\n\t/** A function setup made inside another, by where it is written, with the values it captured. */\n\tz.strictObject({\n\t\tkind: z.literal(\"closure\"),\n\t\tfile: z.string(),\n\t\tstart: z.number().int().nonnegative(),\n\t\tcaptures: z.array(\n\t\t\tz.strictObject({ name: z.string(), value: capturedValueSchema }),\n\t\t),\n\t}),\n]);\nexport type CapturedNode = z.infer<typeof capturedNodeSchema>;\n\nexport const capturedGraphSchema = z\n\t.strictObject({\n\t\tnodes: z.array(capturedNodeSchema),\n\t\t/** Every module-level value binding, in module evaluation order. */\n\t\tbindings: z.array(\n\t\t\tz.strictObject({\n\t\t\t\tfile: z.string(),\n\t\t\t\tname: z.string(),\n\t\t\t\tvalue: capturedValueSchema,\n\t\t\t}),\n\t\t),\n\t\t/** The objects setup passed to `retain`. */\n\t\tretained: z.array(z.number().int().nonnegative()),\n\t})\n\t.superRefine((graph, context) => {\n\t\tconst references = [\n\t\t\t...graph.bindings.map((binding) => binding.value),\n\t\t\t...graph.nodes.flatMap((node) => {\n\t\t\t\tif (node.kind === \"array\") {\n\t\t\t\t\treturn node.items;\n\t\t\t\t}\n\t\t\t\tif (node.kind === \"object\" || node.kind === \"instance\") {\n\t\t\t\t\treturn Object.values(node.fields);\n\t\t\t\t}\n\t\t\t\treturn [];\n\t\t\t}),\n\t\t];\n\t\tfor (const id of graph.retained) {\n\t\t\treferences.push({ kind: \"node\", id });\n\t\t}\n\t\tfor (const value of references) {\n\t\t\tif (value.kind === \"node\" && value.id >= graph.nodes.length) {\n\t\t\t\tcontext.addIssue({\n\t\t\t\t\tcode: \"custom\",\n\t\t\t\t\tmessage: `Captured value refers to missing node ${value.id}.`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\nexport type CapturedGraph = z.infer<typeof capturedGraphSchema>;\n",
32
+ "import ts from \"typescript\";\nimport { valueSymbol } from \"../sdk\";\nimport { unparenthesized } from \"../types\";\nimport { boundNames } from \"./capture-protocol\";\n\n/**\n * The properties scan code assigns outside constructors. Fields scan code writes are state; the\n * rest keep what setup gave them.\n */\nexport class ScanWrites {\n\tprivate readonly assigned = new Set<ts.Symbol>();\n\n\tconstructor(\n\t\tprivate readonly checker: ts.TypeChecker,\n\t\tsources: readonly ts.SourceFile[],\n\t) {\n\t\tfor (const source of sources) {\n\t\t\tthis.collectAssignments(source, false);\n\t\t}\n\t}\n\n\t/** Whether scan code assigns the property `symbol` declares. */\n\tincludes(symbol: ts.Symbol): boolean {\n\t\tif (this.assigned.has(symbol)) {\n\t\t\treturn true;\n\t\t}\n\t\t// A union's property is written through any member's declaration of it.\n\t\treturn (symbol.declarations ?? []).some((declaration) => {\n\t\t\tconst own = this.ownSymbol(declaration);\n\t\t\treturn own !== undefined && this.assigned.has(own);\n\t\t});\n\t}\n\n\tprivate collectAssignments(node: ts.Node, inConstructor: boolean): void {\n\t\t// A closure made in a constructor runs later, as scan code, so its writes are state.\n\t\tconst constructing =\n\t\t\tts.isConstructorDeclaration(node) ||\n\t\t\t(inConstructor &&\n\t\t\t\t!ts.isArrowFunction(node) &&\n\t\t\t\t!ts.isFunctionExpression(node));\n\t\tif (!constructing) {\n\t\t\tconst write = (target: ts.Expression): void => {\n\t\t\t\tconst place = unparenthesized(target, { nonNull: true });\n\t\t\t\tif (ts.isPropertyAccessExpression(place)) {\n\t\t\t\t\tthis.markAssigned(place.name);\n\t\t\t\t} else if (ts.isElementAccessExpression(place)) {\n\t\t\t\t\tconst base = indexed(place.expression);\n\t\t\t\t\tif (ts.isPropertyAccessExpression(base)) {\n\t\t\t\t\t\tthis.markAssigned(base.name);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t\tif (\n\t\t\t\tts.isBinaryExpression(node) &&\n\t\t\t\tisAssignment(node.operatorToken.kind)\n\t\t\t) {\n\t\t\t\tassignedTargets(node.left).forEach(write);\n\t\t\t}\n\t\t\tif (isUpdate(node)) {\n\t\t\t\twrite(node.operand);\n\t\t\t}\n\t\t}\n\t\tts.forEachChild(node, (child) =>\n\t\t\tthis.collectAssignments(child, constructing),\n\t\t);\n\t}\n\n\tprivate markAssigned(name: ts.MemberName): void {\n\t\tconst symbol = this.checker.getSymbolAtLocation(name);\n\t\tif (!symbol) {\n\t\t\treturn;\n\t\t}\n\t\tthis.assigned.add(symbol);\n\t\t// A property of a union is a synthetic symbol over each member's own property.\n\t\tfor (const declaration of symbol.declarations ?? []) {\n\t\t\tconst own = this.ownSymbol(declaration);\n\t\t\tif (own) {\n\t\t\t\tthis.assigned.add(own);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** The symbol a declaration declares. */\n\tprivate ownSymbol(declaration: ts.Declaration): ts.Symbol | undefined {\n\t\tconst name = ts.getNameOfDeclaration(declaration);\n\t\treturn name && this.checker.getSymbolAtLocation(name);\n\t}\n}\n\n/** What an element access chain such as `a.b[1][2]` indexes: `a.b`. */\nconst indexed = (node: ts.Expression): ts.Expression =>\n\tts.isElementAccessExpression(node) ? indexed(node.expression) : node;\n\n/** Whether an expression steps its operand by one: `x++`, `++x`, `x--` or `--x`. */\nexport const isUpdate = (\n\tnode: ts.Node,\n): node is ts.PrefixUnaryExpression | ts.PostfixUnaryExpression =>\n\t(ts.isPrefixUnaryExpression(node) || ts.isPostfixUnaryExpression(node)) &&\n\t(node.operator === ts.SyntaxKind.PlusPlusToken ||\n\t\tnode.operator === ts.SyntaxKind.MinusMinusToken);\n\n/** Whether an operator assigns its left operand: `=`, a compound assignment or `??=`. */\nexport const isAssignment = (kind: ts.SyntaxKind): boolean =>\n\tkind >= ts.SyntaxKind.FirstAssignment && kind <= ts.SyntaxKind.LastAssignment;\n\n/**\n * The places an assignment's left side writes: the side itself, or each target a destructuring\n * pattern names, as `[a, { b }, c = 1] = value` writes `a`, `b` and `c`.\n */\nconst assignedTargets = (left: ts.Expression): ts.Expression[] => {\n\tconst place = unparenthesized(left, { nonNull: true });\n\tif (ts.isArrayLiteralExpression(place)) {\n\t\treturn place.elements.flatMap((element) =>\n\t\t\tassignedTargets(\n\t\t\t\tts.isSpreadElement(element) ? element.expression : element,\n\t\t\t),\n\t\t);\n\t}\n\tif (ts.isObjectLiteralExpression(place)) {\n\t\treturn place.properties.flatMap((property) => {\n\t\t\tif (ts.isPropertyAssignment(property)) {\n\t\t\t\treturn assignedTargets(property.initializer);\n\t\t\t}\n\t\t\tif (ts.isShorthandPropertyAssignment(property)) {\n\t\t\t\treturn [property.name];\n\t\t\t}\n\t\t\tif (ts.isSpreadAssignment(property)) {\n\t\t\t\treturn assignedTargets(property.expression);\n\t\t\t}\n\t\t\treturn [];\n\t\t});\n\t}\n\tif (\n\t\tts.isBinaryExpression(place) &&\n\t\tplace.operatorToken.kind === ts.SyntaxKind.EqualsToken\n\t) {\n\t\treturn assignedTargets(place.left);\n\t}\n\treturn [left];\n};\n\n/** Whether some node in `node` passes `test`, outside the functions it declares, which run apart from it. */\nexport const occursOutsideFunctions = (\n\tnode: ts.Node,\n\ttest: (node: ts.Node) => boolean,\n): boolean =>\n\ttest(node) ||\n\t(!ts.isFunctionLike(node) &&\n\t\t(ts.forEachChild(node, (child) => occursOutsideFunctions(child, test)) ??\n\t\t\tfalse));\n\n/** Whether `node` lies within `container`'s source range. */\nexport const within = (node: ts.Node, container: ts.Node): boolean =>\n\tnode.pos >= container.pos && node.end <= container.end;\n\n/** Whether the body assigns or steps any name the binding declares. */\nexport const assignsName = (\n\tbody: ts.Node,\n\tbinding: ts.BindingName,\n\tchecker: ts.TypeChecker,\n): boolean => {\n\tconst declared = new Set(\n\t\tboundNames(binding).flatMap((name) => {\n\t\t\tconst symbol = checker.getSymbolAtLocation(name);\n\t\t\treturn symbol ? [symbol] : [];\n\t\t}),\n\t);\n\treturn assignsSymbol(body, declared, checker);\n};\n\n/** Whether the body assigns or steps a name that refers to one of the symbols. */\nexport const assignsSymbol = (\n\tbody: ts.Node,\n\tdeclared: ReadonlySet<ts.Symbol>,\n\tchecker: ts.TypeChecker,\n): boolean => {\n\tconst target = (node: ts.Expression): boolean => {\n\t\tconst symbol = ts.isIdentifier(node)\n\t\t\t? valueSymbol(checker, node)\n\t\t\t: undefined;\n\t\treturn symbol !== undefined && declared.has(symbol);\n\t};\n\tconst visit = (node: ts.Node): boolean =>\n\t\t(ts.isBinaryExpression(node) &&\n\t\t\tisAssignment(node.operatorToken.kind) &&\n\t\t\tassignedTargets(node.left).some(target)) ||\n\t\t(isUpdate(node) && target(node.operand)) ||\n\t\t(ts.forEachChild(node, visit) ?? false);\n\treturn visit(body);\n};\n\n/**\n * Whether the body changes what a local holds through it, by writing one of its fields or elements,\n * or lends it to a call, which can.\n */\nexport const writesThrough = (\n\tbody: ts.Node,\n\tsymbol: ts.Symbol,\n\tchecker: ts.TypeChecker,\n): boolean => {\n\tconst root = (node: ts.Expression): ts.Expression =>\n\t\tts.isPropertyAccessExpression(node) ||\n\t\tts.isElementAccessExpression(node) ||\n\t\tts.isParenthesizedExpression(node) ||\n\t\tts.isNonNullExpression(node)\n\t\t\t? root(node.expression)\n\t\t\t: node;\n\tconst named = (node: ts.Expression): boolean =>\n\t\tts.isIdentifier(node) && checker.getSymbolAtLocation(node) === symbol;\n\tconst throughIt = (target: ts.Expression): boolean =>\n\t\ttarget !== root(target) && named(root(target));\n\tconst visit = (node: ts.Node): boolean =>\n\t\t(ts.isBinaryExpression(node) &&\n\t\t\tisAssignment(node.operatorToken.kind) &&\n\t\t\tassignedTargets(node.left).some(throughIt)) ||\n\t\t(isUpdate(node) && throughIt(node.operand)) ||\n\t\t(ts.isCallExpression(node) && node.arguments.some(named)) ||\n\t\t(ts.forEachChild(node, visit) ?? false);\n\treturn visit(body);\n};\n\n/** Where an alias is live: from its declaration to its last use, or its scope's end when a use can run again after a later write. */\ninterface AliasWindow {\n\tscope: ts.Node;\n\t/** What the alias was declared from: its initializer, or for `const { name } = value`, that property of the value. */\n\tsource: ts.Expression;\n\t/** The property a destructured alias reads from `source`. */\n\tproperty: string | undefined;\n\tfrom: number;\n\tuntil: number;\n}\n\nconst aliasWindow = (\n\tname: ts.Identifier,\n\tchecker: ts.TypeChecker,\n): AliasWindow | undefined => {\n\tconst symbol = checker.getSymbolAtLocation(name);\n\tconst scope = enclosingScope(name);\n\tconst binding = ts.isBindingElement(name.parent) ? name.parent : undefined;\n\tconst declaration = binding\n\t\t? ts.findAncestor(binding, ts.isVariableDeclaration)\n\t\t: name.parent;\n\tif (\n\t\t!symbol ||\n\t\t!scope ||\n\t\t!declaration ||\n\t\t!ts.isVariableDeclaration(declaration) ||\n\t\t!declaration.initializer ||\n\t\t// A nested pattern reads through more than one property.\n\t\t(binding && !ts.isVariableDeclaration(binding.parent.parent))\n\t) {\n\t\treturn undefined;\n\t}\n\tconst uses: ts.Identifier[] = [];\n\tconst collect = (node: ts.Node): void => {\n\t\tif (\n\t\t\tts.isIdentifier(node) &&\n\t\t\tnode !== name &&\n\t\t\tvalueSymbol(checker, node) === symbol\n\t\t) {\n\t\t\tuses.push(node);\n\t\t}\n\t\tts.forEachChild(node, collect);\n\t};\n\tcollect(scope);\n\tconst reentered = (use: ts.Node): boolean =>\n\t\tts.findAncestor(use.parent, (node) => {\n\t\t\tif (node === scope) {\n\t\t\t\treturn \"quit\";\n\t\t\t}\n\t\t\treturn (\n\t\t\t\t(ts.isIterationStatement(node, false) || ts.isFunctionLike(node)) &&\n\t\t\t\t!within(declaration, node)\n\t\t\t);\n\t\t}) !== undefined;\n\tconst from = declaration.end;\n\treturn {\n\t\tscope,\n\t\tsource: declaration.initializer,\n\t\tproperty: binding && (binding.propertyName ?? binding.name).getText(),\n\t\tfrom,\n\t\tuntil: uses.some(reentered)\n\t\t\t? scope.end\n\t\t\t: Math.max(from, ...uses.map((use) => use.getStart())),\n\t};\n};\n\n/** Whether any node of `scope` that runs wholly inside the window matches. */\nconst runsBetween = (\n\t{ scope, from, until }: AliasWindow,\n\tmatches: (node: ts.Node) => boolean,\n): boolean => {\n\tconst visit = (node: ts.Node): boolean =>\n\t\t(node.getStart() >= from && node.end <= until && matches(node)) ||\n\t\t(ts.forEachChild(node, visit) ?? false);\n\treturn visit(scope);\n};\n\n/** The names along a place's path, root first, past `this`; element indexes are left out. */\nconst pathNames = (place: ts.Expression): string[] | undefined => {\n\tconst node = unparenthesized(place, { nonNull: true });\n\tif (ts.isIdentifier(node)) {\n\t\treturn [node.text];\n\t}\n\tif (node.kind === ts.SyntaxKind.ThisKeyword) {\n\t\treturn [];\n\t}\n\tif (ts.isPropertyAccessExpression(node)) {\n\t\tconst base = pathNames(node.expression);\n\t\treturn base && [...base, node.name.text];\n\t}\n\tif (ts.isElementAccessExpression(node)) {\n\t\treturn pathNames(node.expression);\n\t}\n\treturn undefined;\n};\n\n/** Each assignment's left side and each step's operand in the window. */\nconst writesIn = (window: AliasWindow): ts.Expression[] => {\n\tconst targets: ts.Expression[] = [];\n\trunsBetween(window, (node) => {\n\t\tif (isUpdate(node)) {\n\t\t\ttargets.push(node.operand);\n\t\t} else if (\n\t\t\tts.isBinaryExpression(node) &&\n\t\t\tisAssignment(node.operatorToken.kind)\n\t\t) {\n\t\t\ttargets.push(node.left);\n\t\t}\n\t\treturn false;\n\t});\n\treturn targets;\n};\n\n/**\n * Whether nothing can change what an alias's indexes read between its declaration and its last use: no\n * assignment, step, call, await or yield finishes in between, and it is read in no loop or closure it was\n * declared outside of, which could run after something did. Its element is then the same at each use.\n */\nexport const stableAlias = (\n\tname: ts.Identifier,\n\tchecker: ts.TypeChecker,\n): boolean => {\n\tconst window = aliasWindow(name, checker);\n\tif (!window || window.property !== undefined) {\n\t\treturn false;\n\t}\n\t// What the alias's place reads, by name: a write to a place none of them name can't move it.\n\tconst read = new Set<string>();\n\tconst readNames = (node: ts.Node): void => {\n\t\tif (ts.isIdentifier(node) || ts.isPrivateIdentifier(node)) {\n\t\t\tread.add(node.text);\n\t\t}\n\t\tts.forEachChild(node, readNames);\n\t};\n\treadNames(window.source);\n\t// A destructuring assignment names no path, so it counts as writing what the alias reads: an alias\n\t// that holds its indexes is never wrong.\n\tconst writesRead = (target: ts.Expression): boolean => {\n\t\tconst names = pathNames(target);\n\t\treturn names === undefined || names.some((written) => read.has(written));\n\t};\n\treturn (\n\t\t!writesIn(window).some(writesRead) &&\n\t\t!runsBetween(\n\t\t\twindow,\n\t\t\t(node) =>\n\t\t\t\tts.isCallExpression(node) ||\n\t\t\t\tts.isNewExpression(node) ||\n\t\t\t\tts.isAwaitExpression(node) ||\n\t\t\t\tts.isYieldExpression(node) ||\n\t\t\t\tts.isTaggedTemplateExpression(node) ||\n\t\t\t\tts.isDeleteExpression(node),\n\t\t)\n\t);\n};\n\n/**\n * Whether the place an alias names is assigned anew while the alias is still read, as\n * `const { pending } = this; this.pending = undefined; use(pending)` does. TypeScript's alias keeps the\n * object it named; the PLC's would read the new value, so it needs a snapshot. A write into the place's\n * fields, such as `this.pending.travel += 1`, is one the alias sees in both.\n */\nexport const replacedWhileAliased = (\n\tname: ts.Identifier,\n\tchecker: ts.TypeChecker,\n): boolean => {\n\tconst window = aliasWindow(name, checker);\n\tconst base = window && pathNames(window.source);\n\tif (!window || !base) {\n\t\treturn false;\n\t}\n\tconst path =\n\t\twindow.property === undefined ? base : [...base, window.property];\n\t// Writing the place, or anything on its path, replaces what it holds.\n\treturn writesIn(window)\n\t\t.flatMap(assignedTargets)\n\t\t.some((target) => {\n\t\t\tconst written = pathNames(target);\n\t\t\tconst last = written?.at(-1);\n\t\t\treturn last !== undefined && path.includes(last);\n\t\t});\n};\n\n/** The block, clause or source a declaration's name is scoped to. */\nconst enclosingScope = (node: ts.Node): ts.Node | undefined =>\n\tts.findAncestor(\n\t\tnode.parent,\n\t\t(parent) =>\n\t\t\tts.isBlock(parent) ||\n\t\t\tts.isSourceFile(parent) ||\n\t\t\tts.isCaseClause(parent) ||\n\t\t\tts.isDefaultClause(parent) ||\n\t\t\tts.isFunctionLike(parent),\n\t);\n",
33
+ "import { dirname, relative } from \"node:path\";\nimport type { Names } from \"./names\";\n\n/** The specifier a generated module imports `to` by: relative, dot-prefixed and without its extension. */\nexport const importPath = (from: string, to: string): string => {\n\tconst path = relative(dirname(from), to)\n\t\t.replace(/\\\\/g, \"/\")\n\t\t.replace(/\\.tsx?$/, \"\");\n\treturn path.startsWith(\"./\") || path.startsWith(\"../\") ? path : `./${path}`;\n};\n\n/** Names generated code imports from other modules, by module file. */\nexport class ModuleImports {\n\t/** Each module's imported names, with the name generated code reads each by. */\n\tprivate readonly imported = new Map<string, Map<string, string>>();\n\n\tconstructor(\n\t\tprivate readonly names: Names,\n\t\t/** Names the modules that import these declare themselves, which an import gives way to. */\n\t\tprivate readonly avoided: ReadonlySet<string> = new Set(),\n\t) {}\n\n\t/** Whether `name` of `file` is imported. */\n\thas(file: string, name: string): boolean {\n\t\treturn this.imported.get(file)?.has(name) ?? false;\n\t}\n\n\t/**\n\t * Records an import of `name` from `file`, and returns the name to read it by: its own, unless\n\t * the generated modules already use that name for something else.\n\t */\n\tadd(file: string, name: string): string {\n\t\tconst names = this.imported.get(file) ?? new Map<string, string>();\n\t\tthis.imported.set(file, names);\n\t\tconst local = this.names.import(`${file}\\0${name}`, name, this.avoided);\n\t\tnames.set(name, local);\n\t\treturn local;\n\t}\n\n\t/** One import statement per module, as `importer` reaches it. */\n\tlines(importer: string, keyword: \"import\" | \"import type\"): string[] {\n\t\treturn [...this.imported].flatMap(([file, names]) => {\n\t\t\tconst list = [...names]\n\t\t\t\t// A module already has what it declares itself, under its own name.\n\t\t\t\t.filter(([name, local]) => file !== importer || name !== local)\n\t\t\t\t.map(([name, local]) =>\n\t\t\t\t\tname === local ? name : `${name} as ${local}`,\n\t\t\t\t);\n\t\t\treturn list.length\n\t\t\t\t? [\n\t\t\t\t\t\t`${keyword} { ${list.join(\", \")} } from \"${importPath(importer, file)}\";`,\n\t\t\t\t\t]\n\t\t\t\t: [];\n\t\t});\n\t}\n}\n\n/**\n * What the generated entry module imports besides the generated types: the storage modules,\n * kept modules' bindings, and the SDK functions scan code and generated conversions call.\n */\nexport class EntryImports {\n\t/** Storage modules generated code reads through a namespace import, by import name. */\n\tprivate readonly namespaces = new Map<string, string>();\n\t/** Bindings of kept modules, read by their own names unless something else has them. */\n\treadonly kept: ModuleImports;\n\t/** SDK functions by the module that declares them, such as `@tsplc/compiler/clock`. */\n\tprivate readonly sdk = new Map<string, Set<string>>();\n\n\tconstructor(private readonly names: Names) {\n\t\tthis.kept = new ModuleImports(names);\n\t}\n\n\t/**\n\t * Records a namespace import of a storage module, and returns the name to read it by: `name`,\n\t * unless the generated modules already use that for something else, as two roots whose names\n\t * differ only in their separators would.\n\t */\n\tnamespace(file: string, name: string): string {\n\t\tconst local = this.names.import(file, name);\n\t\tthis.namespaces.set(local, file);\n\t\treturn local;\n\t}\n\n\t/** Records a call of `name`, which `module` of the SDK declares. */\n\taddSdk(module: string, name: string): void {\n\t\tconst names = this.sdk.get(module) ?? new Set<string>();\n\t\tnames.add(name);\n\t\tthis.sdk.set(module, names);\n\t}\n\n\tlines(entryFile: string): string[] {\n\t\treturn [\n\t\t\t...[...this.namespaces].map(\n\t\t\t\t([name, file]) =>\n\t\t\t\t\t`import * as ${name} from \"${importPath(entryFile, file)}\";`,\n\t\t\t),\n\t\t\t...this.kept.lines(entryFile, \"import\"),\n\t\t\t...[...this.sdk].map(\n\t\t\t\t([module, names]) =>\n\t\t\t\t\t`import { ${[...names].join(\", \")} } from \"${module}\";`,\n\t\t\t),\n\t\t];\n\t}\n}\n",
34
+ "import { optionalRecord, pascalCase, primitiveTypes } from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport { from, type Mapped, mapped, type Part } from \"../positions\";\nimport {\n\tdeclaringName,\n\tdefaultNumericTypes,\n\thasModifier,\n\tpromisedType,\n} from \"../types\";\nimport type { CapturedValue } from \"./capture-protocol\";\nimport { ModuleImports } from \"./imports\";\nimport { isExported, type Model, type ModelNode, unionMembers } from \"./model\";\nimport { type Names, rootFieldNames } from \"./names\";\nimport { SpecializeError } from \"./values\";\n\n/** IEC names a program can write as types; they keep their width rather than becoming DINT. */\nconst iecNames = new Set(primitiveTypes.map((type) => type.id));\n\n/** What an instance that stores nothing is kept as where a record or array holds it. */\nexport const statelessLayout = \"boolean\";\n\n/**\n * A stored array's PLC type, `FixedArray<T, n>`, with how many elements it has room for and T when\n * T is an IEC name. A kept module's named array type is only its name.\n */\nexport interface ArrayLayout {\n\ttext: string;\n\tbound?: number;\n\telementIec?: string;\n}\n\n/** An optional record holding the defined value `text`. */\nexport const definedOptional = (text: Part): Mapped =>\n\tmapped`{ ${optionalRecord.has}: true, ${optionalRecord.value}: ${text} }`;\n\n/** An optional record holding nothing, its value the empty `text`. */\nexport const emptyOptional = (text: Part): Mapped =>\n\tmapped`{ ${optionalRecord.has}: false, ${optionalRecord.value}: ${text} }`;\n\n/** Whether the optional record `text` holds a value. */\nexport const optionalHas = (text: Part): Mapped =>\n\tmapped`${text}.${optionalRecord.has}`;\n\n/** The value the optional record `text` holds. */\nexport const optionalValue = (text: Part): Mapped =>\n\tmapped`${text}.${optionalRecord.value}`;\n\n/** The layout of an array of `length` elements: the PLC has no empty array, so it keeps at least one slot. */\nexport const arrayLayout = (\n\telement: string,\n\tlength: number,\n): ArrayLayout & { bound: number } => {\n\tconst bound = Math.max(length, 1);\n\treturn {\n\t\ttext: `FixedArray<${element}, ${bound}>`,\n\t\tbound,\n\t\t...(iecNames.has(element) && { elementIec: element }),\n\t};\n};\n\n/** A union of string literals: a PLC enum. */\ninterface LiteralEnum {\n\tname: string;\n\tmembers: string[];\n\t/** The union also allows undefined, stored as this extra member. */\n\toptional: boolean;\n}\n\n/** A union of object types told apart by a string-literal field, the tag. */\ninterface TaggedUnion {\n\ttag: string;\n\tvariants: ts.Type[];\n\t/** Each variant's tag, in the order of the variants. */\n\ttags: string[];\n\t/** The union also allows undefined. */\n\toptional: boolean;\n}\n\n/** What the generated types module declares: each declaration's text by name, and which of them are enums. */\nexport interface TypeDeclarations {\n\tdeclarations: ReadonlyMap<string, Part>;\n\tenums: readonly string[];\n}\n\n/**\n * Turns the program's TypeScript types into the PLC dialect's: string-literal unions become enums,\n * unions of objects become one record tagged by their literal field, `T | undefined` becomes an\n * optional record, and arrays take their captured length.\n */\nexport class Layouts {\n\tprivate readonly declarations = new Map<string, string>();\n\t/** The program's declaration each generated one stands for, where diagnostics about it point. */\n\tprivate readonly origins = new Map<string, ts.Node>();\n\t/**\n\t * Names a generated declaration mustn't take: what kept modules declare, which generated modules\n\t * may import beside the generated ones, and the namespaces storage modules are imported as.\n\t */\n\tprivate readonly takenNames: Set<string>;\n\t/** Enums the declarations need from the program's modules. */\n\treadonly imports: ModuleImports;\n\t/** Types the declarations need from kept modules. */\n\treadonly typeImports: ModuleImports;\n\tprivate readonly enums = new Map<string, LiteralEnum>();\n\tprivate readonly records = new Map<string, string>();\n\tprivate readonly names = new Map<string, number>();\n\n\t/** The type literals kept modules write, which name no type a generated module could import. */\n\tprivate readonly keptLiterals: ts.TypeLiteralNode[] = [];\n\n\t/** Exported types of kept modules by the type they declare, for types that lost their alias name. */\n\tprivate readonly keptTypes = new Map<\n\t\tts.Type,\n\t\t{ file: string; name: string }\n\t>();\n\n\tconstructor(\n\t\tprivate readonly model: Model,\n\t\tprivate readonly checker: ts.TypeChecker,\n\t\t/** Modules the compiled program keeps, whose named types and enums it imports rather than copies. */\n\t\tprivate readonly kept: (file: string) => boolean,\n\t\tkeptSources: readonly ts.SourceFile[],\n\t\t/** The stored layout of a class instance or an array of them, which storage, built on these layouts, gives. */\n\t\tprivate readonly instanceState: (node: ModelNode) => string | undefined,\n\t\tprivate readonly moduleNames: Names,\n\t\t/** Why the generated modules can't import an enum from the module that declares it; undefined when they can. */\n\t\tprivate readonly enumRefusal: (\n\t\t\tdeclaration: ts.EnumDeclaration,\n\t\t) => string | undefined,\n\t) {\n\t\t// Each is imported into every root's storage module, beside that root's fields.\n\t\tconst fields = rootFieldNames(model);\n\t\tthis.imports = new ModuleImports(moduleNames, fields);\n\t\tthis.typeImports = new ModuleImports(moduleNames, fields);\n\t\t// Storage imports a root's module under its capitalized name, unless the program names a type so.\n\t\tconst typeNames = new Set(\n\t\t\tmodel.program\n\t\t\t\t.getSourceFiles()\n\t\t\t\t.filter((source) => !source.isDeclarationFile)\n\t\t\t\t.flatMap((source) =>\n\t\t\t\t\tsource.statements.flatMap((statement) =>\n\t\t\t\t\t\tts.isVariableStatement(statement) ||\n\t\t\t\t\t\tts.isFunctionDeclaration(statement)\n\t\t\t\t\t\t\t? []\n\t\t\t\t\t\t\t: declaredNames(statement),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t);\n\t\tthis.takenNames = new Set(\n\t\t\tmodel.roots\n\t\t\t\t.map((root) => pascalCase(root.name))\n\t\t\t\t.filter((name) => !typeNames.has(name)),\n\t\t);\n\t\tconst collectLiterals = (node: ts.Node): void => {\n\t\t\tif (ts.isTypeLiteralNode(node)) {\n\t\t\t\tthis.keptLiterals.push(node);\n\t\t\t}\n\t\t\tts.forEachChild(node, collectLiterals);\n\t\t};\n\t\tfor (const source of keptSources) {\n\t\t\tcollectLiterals(source);\n\t\t\tfor (const statement of source.statements) {\n\t\t\t\tfor (const name of declaredNames(statement)) {\n\t\t\t\t\tthis.takenNames.add(name);\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\t(ts.isTypeAliasDeclaration(statement) ||\n\t\t\t\t\t\tts.isInterfaceDeclaration(statement)) &&\n\t\t\t\t\tisExported(statement)\n\t\t\t\t) {\n\t\t\t\t\tconst symbol = checker.getSymbolAtLocation(statement.name);\n\t\t\t\t\tif (symbol) {\n\t\t\t\t\t\tthis.keptTypes.set(checker.getDeclaredTypeOfSymbol(symbol), {\n\t\t\t\t\t\t\tfile: source.fileName,\n\t\t\t\t\t\t\tname: statement.name.text,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/** A declaration name no other declaration has, nor any of `takenNames`. */\n\tprivate unique(base: string): string {\n\t\tconst count = this.names.get(base) ?? 0;\n\t\tthis.names.set(base, count + 1);\n\t\tconst name = count ? `${base}_${count + 1}` : base;\n\t\tif (\n\t\t\tthis.declarations.has(name) ||\n\t\t\tthis.takenNames.has(name) ||\n\t\t\tthis.moduleNames.importedAs(name)\n\t\t) {\n\t\t\treturn this.unique(base);\n\t\t}\n\t\tthis.moduleNames.declare(name);\n\t\treturn name;\n\t}\n\n\t/**\n\t * Declares an interface of `body` under the first free name from `base`, standing for the\n\t * program's `origin` when it has one, and returns the name.\n\t */\n\tdeclare(base: string, body: string, origin: ts.Node | undefined): string {\n\t\tconst name = this.unique(base);\n\t\tthis.declarations.set(name, `export interface ${name} { ${body} }`);\n\t\tif (origin) {\n\t\t\tthis.origins.set(name, origin);\n\t\t}\n\t\treturn name;\n\t}\n\n\t/** What is declared so far. Generated modules import from the types module what it declares once every layout is made. */\n\tsnapshot(): TypeDeclarations {\n\t\treturn {\n\t\t\tdeclarations: new Map(\n\t\t\t\t[...this.declarations].map(([name, text]) => {\n\t\t\t\t\tconst origin = this.origins.get(name);\n\t\t\t\t\treturn [name, origin ? from(origin, text) : text];\n\t\t\t\t}),\n\t\t\t),\n\t\t\tenums: [...this.declarations]\n\t\t\t\t.filter(([, text]) => text.startsWith(\"export enum\"))\n\t\t\t\t.map(([name]) => name),\n\t\t};\n\t}\n\n\t/** Each string-literal union's enum, with the string each member stands for. */\n\tget literalEnums(): { name: string; members: Record<string, string> }[] {\n\t\treturn [...this.enums.values()].map((declared) => ({\n\t\t\tname: declared.name,\n\t\t\tmembers: Object.fromEntries(\n\t\t\t\tdeclared.members.map((member) => [literalMember(member), member]),\n\t\t\t),\n\t\t}));\n\t}\n\n\t/** The string literals of a union of them, without undefined. */\n\tliterals(\n\t\ttype: ts.Type,\n\t): { members: string[]; optional: boolean } | undefined {\n\t\tconst parts = unionMembers(type);\n\t\tconst defined = parts.filter((part) => !isAbsent(part));\n\t\tconst members = defined.flatMap((part) =>\n\t\t\tpart.isStringLiteral() ? [part.value] : [],\n\t\t);\n\t\tif (!members.length || members.length !== defined.length) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn { members, optional: defined.length !== parts.length };\n\t}\n\n\t/** The enum a string-literal union compiles to. */\n\tliteralEnum(type: ts.Type): LiteralEnum | undefined {\n\t\tconst literals = this.literals(type);\n\t\tif (!literals) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst key = enumKey(literals.members);\n\t\tconst existing = this.enums.get(key);\n\t\tif (existing) {\n\t\t\texisting.optional ||= literals.optional;\n\t\t\tthis.writeEnum(existing);\n\t\t\treturn existing;\n\t\t}\n\t\tconst alias =\n\t\t\ttype.aliasSymbol ?? this.checker.getNonNullableType(type).aliasSymbol;\n\t\tconst declared: LiteralEnum = {\n\t\t\tname: this.unique(\n\t\t\t\talias?.name ?? pascalCase(literals.members.join(\"_or_\")),\n\t\t\t),\n\t\t\tmembers: literals.members,\n\t\t\toptional: literals.optional,\n\t\t};\n\t\tconst origin = alias?.declarations?.[0];\n\t\tif (origin) {\n\t\t\tthis.origins.set(declared.name, origin);\n\t\t}\n\t\tthis.enums.set(key, declared);\n\t\tthis.writeEnum(declared);\n\t\treturn declared;\n\t}\n\n\tprivate writeEnum(declared: LiteralEnum): void {\n\t\tconst members = [\n\t\t\t...(declared.optional ? [\"Undefined = 0\"] : []),\n\t\t\t...declared.members.map(\n\t\t\t\t(member, index) => `${literalMember(member)} = ${index + 1}`,\n\t\t\t),\n\t\t];\n\t\tthis.declarations.set(\n\t\t\tdeclared.name,\n\t\t\t`export enum ${declared.name} { ${members.join(\", \")} }`,\n\t\t);\n\t}\n\n\t/** `Enum.Member` text for a string literal of a literal union. */\n\tmember(declared: LiteralEnum, value: string | undefined): string {\n\t\treturn `${declared.name}.${value === undefined ? \"Undefined\" : literalMember(value)}`;\n\t}\n\n\t/** The object types of a union of them, without undefined, when it has a literal tag field. */\n\ttagged(type: ts.Type): TaggedUnion | undefined {\n\t\tif (!type.isUnion()) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst variants = type.types.filter((part) => !isAbsent(part));\n\t\tconst [first, ...others] = variants;\n\t\tif (\n\t\t\t!first ||\n\t\t\t!others.length ||\n\t\t\tvariants.some((part) => !(part.flags & ts.TypeFlags.Object))\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst literal = (variant: ts.Type, name: string) => {\n\t\t\tconst own = variant.getProperty(name);\n\t\t\tconst value = own && this.checker.getTypeOfSymbol(own);\n\t\t\treturn value?.isStringLiteral() ? value.value : undefined;\n\t\t};\n\t\tfor (const property of first.getProperties()) {\n\t\t\tconst tags = variants.map((variant) => literal(variant, property.name));\n\t\t\tif (tags.every((tag): tag is string => tag !== undefined)) {\n\t\t\t\treturn {\n\t\t\t\t\ttag: property.name,\n\t\t\t\t\tvariants,\n\t\t\t\t\ttags,\n\t\t\t\t\toptional: variants.length !== type.types.length,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** The fields of a tagged union's record: the tag, then every variant's fields. */\n\ttaggedFields(tagged: TaggedUnion): string[] {\n\t\tconst names = [tagged.tag];\n\t\tfor (const variant of tagged.variants) {\n\t\t\tfor (const property of variant.getProperties()) {\n\t\t\t\tif (!names.includes(property.name)) {\n\t\t\t\t\tnames.push(property.name);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn names;\n\t}\n\n\t/** The declared type of a field of a tagged union, from the first variant that has it. */\n\ttaggedFieldType(\n\t\tdeclared: ts.Type,\n\t\ttagged: TaggedUnion,\n\t\tname: string,\n\t): ts.Type {\n\t\treturn this.checker.getTypeOfSymbol(\n\t\t\tthis.taggedField(declared, tagged, name),\n\t\t);\n\t}\n\n\t/** A field of a tagged union, from the first variant that has it, whose declaration names its IEC width. */\n\ttaggedField(declared: ts.Type, tagged: TaggedUnion, name: string): ts.Symbol {\n\t\tfor (const variant of tagged.variants) {\n\t\t\tconst property = variant.getProperty(name);\n\t\t\tif (property) {\n\t\t\t\treturn property;\n\t\t\t}\n\t\t}\n\t\tthrow new Error(\n\t\t\t`${name} is in no variant of ${this.checker.typeToString(declared)}.`,\n\t\t);\n\t}\n\n\t/** The type of a tagged union's tag, once the union's record and tag enum are declared. */\n\ttagType(declared: ts.Type, tagged: TaggedUnion): ts.Type {\n\t\tthis.text(declared);\n\t\tconst property = this.checker.getPropertyOfType(declared, tagged.tag);\n\t\treturn property ? this.checker.getTypeOfSymbol(property) : declared;\n\t}\n\n\t/** The enum of a tagged union's tag. */\n\ttagEnum(declared: ts.Type, tagged: TaggedUnion): LiteralEnum {\n\t\tconst tag = this.literalEnum(this.tagType(declared, tagged));\n\t\tif (!tag) {\n\t\t\tthrow new Error(\n\t\t\t\t`${tagged.tag} of ${this.checker.typeToString(declared)} is no string literal.`,\n\t\t\t);\n\t\t}\n\t\treturn tag;\n\t}\n\n\t/** `Enum.Member` text for the member of a TypeScript enum type that has `value`. */\n\tenumMember(type: ts.Type, value: number): string | undefined {\n\t\tconst member = this.enumDeclaration(type)?.members.find(\n\t\t\t(candidate) => this.checker.getConstantValue(candidate) === value,\n\t\t);\n\t\treturn member && `${this.text(type)}.${member.name.getText()}`;\n\t}\n\n\t/** Whether `T | undefined` is stored as `{ has, value }`; a literal union has an Undefined member instead. */\n\tisOptionalRecord(type: ts.Type): boolean {\n\t\treturn (\n\t\t\ttype.isUnion() &&\n\t\t\ttype.types.some((part) => isAbsent(part)) &&\n\t\t\t!this.literals(type)\n\t\t);\n\t}\n\n\t/** The dialect type text for `type`, holding `value` when it was captured. */\n\ttext(type: ts.Type, value?: CapturedValue, hint?: string): string {\n\t\tconst checker = this.checker;\n\t\tbothAbsent(checker, type);\n\t\tconst alias = type.aliasSymbol?.name;\n\t\tif (alias && iecNames.has(alias)) {\n\t\t\treturn alias;\n\t\t}\n\t\tif (type.flags & ts.TypeFlags.BooleanLike) {\n\t\t\treturn \"boolean\";\n\t\t}\n\t\tconst enumDeclaration = this.enumDeclaration(type);\n\t\tif (enumDeclaration) {\n\t\t\treturn this.enumName(enumDeclaration);\n\t\t}\n\t\tif (type.flags & ts.TypeFlags.NumberLike) {\n\t\t\t// A `number` is a DINT unless setup gave it a fraction, as an unannotated literal is.\n\t\t\treturn fractional(value) ? defaultNumericTypes.float : \"number\";\n\t\t}\n\t\tif (type.flags & ts.TypeFlags.BigIntLike) {\n\t\t\treturn defaultNumericTypes.bigint;\n\t\t}\n\t\tconst literal = this.literalEnum(type);\n\t\tif (literal) {\n\t\t\treturn literal.name;\n\t\t}\n\t\t// A kept module's tagged union is still a union, which the PLC stores as one tagged record.\n\t\tconst tagged = this.tagged(type);\n\t\tif (tagged) {\n\t\t\treturn this.taggedRecord(type, tagged);\n\t\t}\n\t\tconst named = this.namedKept(type);\n\t\tif (named) {\n\t\t\treturn named;\n\t\t}\n\t\tif (type.flags & ts.TypeFlags.StringLike) {\n\t\t\treturn \"string\";\n\t\t}\n\t\tif (type.isUnion()) {\n\t\t\tconst defined = checker.getNonNullableType(type);\n\t\t\tif (defined !== type) {\n\t\t\t\treturn this.optional(defined, value);\n\t\t\t}\n\t\t}\n\t\tconst element = this.model.elementType(type);\n\t\tif (\n\t\t\telement &&\n\t\t\t(checker.isArrayType(type) ||\n\t\t\t\tchecker.isTupleType(type) ||\n\t\t\t\tisReadonlyArray(type))\n\t\t) {\n\t\t\treturn this.array(type, element, value).text;\n\t\t}\n\t\tconst record = this.enumRecord(type);\n\t\tif (record) {\n\t\t\treturn record;\n\t\t}\n\t\tif (type.flags & ts.TypeFlags.Object) {\n\t\t\treturn this.record(type, value, hint);\n\t\t}\n\t\tthrow new Error(`${checker.typeToString(type)} has no PLC layout.`);\n\t}\n\n\t/** The TypeScript enum a type is, or is a union of members of. */\n\tenumDeclaration(type: ts.Type): ts.EnumDeclaration | undefined {\n\t\tconst parts = unionMembers(type);\n\t\tconst [first] = parts;\n\t\tif (!first || !parts.every((part) => part.flags & ts.TypeFlags.EnumLike)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst symbol = first.symbol;\n\t\tconst declaration =\n\t\t\tsymbol?.declarations?.find(ts.isEnumDeclaration) ??\n\t\t\tsymbol?.valueDeclaration?.parent;\n\t\treturn declaration && ts.isEnumDeclaration(declaration)\n\t\t\t? declaration\n\t\t\t: undefined;\n\t}\n\n\t/**\n\t * The IEC type a declaration names, such as `WORD`: TypeScript keeps no alias name for an alias\n\t * of a primitive, so the width is read from the declaration's annotation. An async routine's\n\t * result is the one its promise holds, as `(): Promise<UINT>` names.\n\t */\n\tiecName(declaration: ts.Node | undefined): string | undefined {\n\t\tconst node = annotation(declaration);\n\t\tconst awaits =\n\t\t\tdeclaration !== undefined &&\n\t\t\tts.canHaveModifiers(declaration) &&\n\t\t\thasModifier(declaration, ts.SyntaxKind.AsyncKeyword);\n\t\treturn iecTypeName(node && awaits ? promisedType(node) : node);\n\t}\n\n\t/**\n\t * The IEC width a declaration gives its elements, as `data: Array<BYTE>` does, or an enum-keyed\n\t * record its values, as `counts: Record<Lane, UINT>` does.\n\t */\n\telementIec(declaration: ts.Node | undefined): string | undefined {\n\t\tconst node = annotation(declaration);\n\t\treturn iecTypeName(arrayElement(node) ?? recordValue(node));\n\t}\n\n\t/** A declared field's layout, keeping the IEC widths its annotation names. */\n\tdeclaredText(\n\t\tdeclaration: ts.Node | undefined,\n\t\ttype: ts.Type,\n\t\tvalue?: CapturedValue,\n\t\thint?: string,\n\t): string {\n\t\tconst iec = this.iecName(declaration);\n\t\tif (iec) {\n\t\t\treturn this.isOptionalRecord(type) ? this.optionalLayout(iec) : iec;\n\t\t}\n\t\t// TypeScript keeps no alias name for a record's IEC values, so the width is read from the annotation.\n\t\tconst record = recordTypes(type);\n\t\tconst valueIec = iecTypeName(recordValue(annotation(declaration)));\n\t\tif (record && valueIec && this.enumRecord(type)) {\n\t\t\treturn `Record<${this.text(record.key)}, ${valueIec}>`;\n\t\t}\n\t\t// A class instance in a record stores the state its class holds, as one in a field does, and\n\t\t// an array of instances each instance's state.\n\t\tconst node = value && this.model.node(value);\n\t\tif (node?.captured.kind === \"instance\") {\n\t\t\treturn this.instanceState(node) ?? statelessLayout;\n\t\t}\n\t\tif (node && holdsInstances(this.model, node)) {\n\t\t\treturn (\n\t\t\t\tthis.instanceState(node) ??\n\t\t\t\tarrayLayout(statelessLayout, this.items(type, value).length).text\n\t\t\t);\n\t\t}\n\t\tconst elementName = iecTypeName(arrayElement(annotation(declaration)));\n\t\tif (elementName) {\n\t\t\treturn arrayLayout(elementName, this.items(type, value).length).text;\n\t\t}\n\t\treturn this.text(type, value, hint);\n\t}\n\n\t/** A declared array field's layout, as `declaredText` gives it, with the length setup gave it. */\n\tdeclaredArray(\n\t\tdeclaration: ts.Node | undefined,\n\t\ttype: ts.Type,\n\t\tvalue: CapturedValue | undefined,\n\t): ArrayLayout {\n\t\tconst elementName = iecTypeName(arrayElement(annotation(declaration)));\n\t\tif (elementName) {\n\t\t\treturn arrayLayout(elementName, this.items(type, value).length);\n\t\t}\n\t\tconst named = this.namedKept(type);\n\t\tif (named) {\n\t\t\treturn { text: named };\n\t\t}\n\t\tconst element = this.model.elementType(type);\n\t\tif (!element) {\n\t\t\tthrow new Error(`${this.checker.typeToString(type)} is no array.`);\n\t\t}\n\t\treturn this.array(type, element, value);\n\t}\n\n\t/** A record's array field's layout, with the length setup gave it. */\n\tfieldArray(property: ts.Symbol): ArrayLayout {\n\t\treturn this.declaredArray(\n\t\t\tproperty.valueDeclaration,\n\t\t\tthis.checker.getTypeOfSymbol(property),\n\t\t\tthis.fieldSample(property),\n\t\t);\n\t}\n\n\tprivate array(\n\t\ttype: ts.Type,\n\t\telement: ts.Type,\n\t\tvalue: CapturedValue | undefined,\n\t): ArrayLayout & { bound: number } {\n\t\tconst items = this.items(type, value);\n\t\treturn arrayLayout(\n\t\t\tthis.text(\n\t\t\t\telement,\n\t\t\t\titems.find(fractional) ?? items[0] ?? this.sample(element),\n\t\t\t),\n\t\t\titems.length,\n\t\t);\n\t}\n\n\t/** The items setup gave an array, which its type has no length for. */\n\tprivate items(\n\t\ttype: ts.Type,\n\t\tvalue: CapturedValue | undefined,\n\t): readonly CapturedValue[] {\n\t\tconst node = value && this.model.node(value);\n\t\tif (node?.captured.kind !== \"array\") {\n\t\t\tthrow new Error(\n\t\t\t\t`${this.checker.typeToString(type)} needs a length: build it during setup.`,\n\t\t\t);\n\t\t}\n\t\treturn node.captured.items;\n\t}\n\n\t/** A captured value of a field, from any captured record that has it. */\n\tprivate fieldSample(property: ts.Symbol): CapturedValue | undefined {\n\t\tfor (const node of this.model.nodes) {\n\t\t\tconst captured = node.captured;\n\t\t\tif (\n\t\t\t\t(captured.kind === \"object\" || captured.kind === \"instance\") &&\n\t\t\t\tnode.type?.getProperty(property.name) === property\n\t\t\t) {\n\t\t\t\treturn captured.fields[property.name];\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Some captured value of `type`, giving the lengths of an empty array's element. */\n\tprivate sample(type: ts.Type): CapturedValue | undefined {\n\t\tconst node = this.model.nodes.find((candidate) => candidate.type === type);\n\t\treturn node && { kind: \"node\", id: node.id };\n\t}\n\n\t/** A named type from a module the program keeps, such as a service's procedure record. */\n\tprivate namedKept(type: ts.Type): string | undefined {\n\t\tconst declared = this.keptTypes.get(type);\n\t\tif (declared) {\n\t\t\treturn this.typeImports.add(declared.file, declared.name);\n\t\t}\n\t\tconst symbol = type.aliasSymbol ?? type.getSymbol();\n\t\tconst declaration = symbol?.declarations?.[0];\n\t\tif (!symbol || !declaration) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (\n\t\t\t!ts.isTypeAliasDeclaration(declaration) &&\n\t\t\t!ts.isInterfaceDeclaration(declaration)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst file = declaration.getSourceFile().fileName;\n\t\tif (!this.kept(file) || !isExported(declaration)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.typeImports.add(file, symbol.name);\n\t}\n\n\t/**\n\t * The name generated code reads a TypeScript enum by: its own, imported from the module that\n\t * declares it, so the PLC, the server and the program's own modules share one enum.\n\t */\n\tprivate enumName(declaration: ts.EnumDeclaration): string {\n\t\tconst refusal = this.enumRefusal(declaration);\n\t\tif (refusal) {\n\t\t\tthrow new SpecializeError(declaration.name, refusal);\n\t\t}\n\t\treturn this.imports.add(\n\t\t\tdeclaration.getSourceFile().fileName,\n\t\t\tdeclaration.name.text,\n\t\t);\n\t}\n\n\t/** `Record<Enum, T>`: an object type whose properties are exactly an enum's members. */\n\tprivate enumRecord(type: ts.Type): string | undefined {\n\t\tconst record = recordTypes(type);\n\t\tif (\n\t\t\t!record ||\n\t\t\t(!this.enumDeclaration(record.key) && !this.literalEnum(record.key))\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn `Record<${this.text(record.key)}, ${this.text(record.value)}>`;\n\t}\n\n\t/** `{ has, value }` for `T | undefined`. */\n\tprivate optional(defined: ts.Type, value: CapturedValue | undefined): string {\n\t\treturn this.optionalLayout(\n\t\t\tthis.text(defined, value?.kind === \"undefined\" ? undefined : value),\n\t\t);\n\t}\n\n\t/** The optional record holding a value of layout `inner`. */\n\tprivate optionalLayout(layout: string): string {\n\t\t// A `number` is a DINT, so an optional DINT is the record an optional number is.\n\t\tconst inner = layout === defaultNumericTypes.number ? \"number\" : layout;\n\t\tconst name = `${optionalRecord.prefix}${inner.replace(/\\W+/g, \"_\")}`;\n\t\tif (!this.declarations.has(name)) {\n\t\t\tthis.declarations.set(\n\t\t\t\tname,\n\t\t\t\t`export interface ${name} { ${optionalRecord.has}: boolean; ${optionalRecord.value}: ${inner}; }`,\n\t\t\t);\n\t\t}\n\t\treturn name;\n\t}\n\n\t/** One record for a tagged union: the tag as an enum, and every variant's fields. */\n\tprivate taggedRecord(type: ts.Type, tagged: TaggedUnion): string {\n\t\tconst key = `tagged:${this.checker.typeToString(type)}`;\n\t\tconst known = this.records.get(key);\n\t\tif (known) {\n\t\t\treturn known;\n\t\t}\n\t\tconst name = this.unique(type.aliasSymbol?.name ?? \"Variant\");\n\t\tthis.records.set(key, name);\n\t\tconst origin = type.aliasSymbol?.declarations?.[0];\n\t\tif (origin) {\n\t\t\tthis.origins.set(name, origin);\n\t\t}\n\t\tconst tags = tagged.tags;\n\t\tconst tagEnum: LiteralEnum = {\n\t\t\tname: `${name}Kind`,\n\t\t\tmembers: tags,\n\t\t\toptional: tagged.optional,\n\t\t};\n\t\tthis.enums.set(enumKey(tags), tagEnum);\n\t\tthis.writeEnum(tagEnum);\n\t\tconst fields = new Map<string, string>();\n\t\tfor (const variant of tagged.variants) {\n\t\t\tfor (const property of variant.getProperties()) {\n\t\t\t\tif (property.name === tagged.tag || fields.has(property.name)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfields.set(\n\t\t\t\t\tproperty.name,\n\t\t\t\t\tthis.declaredText(\n\t\t\t\t\t\tproperty.valueDeclaration,\n\t\t\t\t\t\tthis.checker.getTypeOfSymbol(property),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tthis.declarations.set(\n\t\t\tname,\n\t\t\t`export interface ${name} { ${tagged.tag}: ${tagEnum.name}; ${[...fields]\n\t\t\t\t.map(([field, text]) => `${field}: ${text};`)\n\t\t\t\t.join(\" \")} }`,\n\t\t);\n\t\treturn name;\n\t}\n\n\t/** A record of an object type; captured arrays inside it can give it distinct variants. */\n\tprivate record(\n\t\ttype: ts.Type,\n\t\tvalue: CapturedValue | undefined,\n\t\thint?: string,\n\t): string {\n\t\tconst node = value && this.model.node(value);\n\t\tconst captured = (name: string) =>\n\t\t\tnode &&\n\t\t\t(node.captured.kind === \"object\" || node.captured.kind === \"instance\")\n\t\t\t\t? node.captured.fields[name]\n\t\t\t\t: undefined;\n\t\tconst body = this.recordBody(type, captured);\n\t\tconst symbolName = type.aliasSymbol?.name ?? type.getSymbol()?.name;\n\t\t// A type literal and an object literal with the same fields are one shape, so values pass between them unconverted.\n\t\tconst base =\n\t\t\tsymbolName === ts.InternalSymbolName.Type ||\n\t\t\tsymbolName === ts.InternalSymbolName.Object\n\t\t\t\t? undefined\n\t\t\t\t: symbolName;\n\t\tconst origin = (type.aliasSymbol ?? type.getSymbol())?.declarations?.[0];\n\t\tif (\n\t\t\tbase === undefined &&\n\t\t\tthis.likeKeptLiteral(type, origin, body, captured)\n\t\t) {\n\t\t\treturn `{ ${body} }`;\n\t\t}\n\t\tconst key = `${base ?? \"\"}:${body}`;\n\t\tconst known = this.records.get(key);\n\t\tif (known) {\n\t\t\treturn known;\n\t\t}\n\t\tconst owner = declaringName(origin?.parent);\n\t\tconst name = this.declare(\n\t\t\tbase ?? hint ?? (owner && pascalCase(owner)) ?? \"Fields\",\n\t\t\tbody,\n\t\t\torigin,\n\t\t);\n\t\tthis.records.set(key, name);\n\t\treturn name;\n\t}\n\n\t/**\n\t * Whether an anonymous record is a kept module's type literal or has the same fields as one. Such\n\t * a literal has no name to import, so the record is written out as a literal, and the PLC dialect\n\t * makes literals with the same fields one type, which values pass between unconverted.\n\t */\n\tprivate likeKeptLiteral(\n\t\ttype: ts.Type,\n\t\torigin: ts.Declaration | undefined,\n\t\tbody: string,\n\t\tcaptured: (name: string) => CapturedValue | undefined,\n\t): boolean {\n\t\tif (\n\t\t\torigin &&\n\t\t\tts.isTypeLiteralNode(origin) &&\n\t\t\tthis.kept(origin.getSourceFile().fileName)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\tconst names = fieldNames(this.checker, type);\n\t\treturn this.keptLiterals.some((literal) => {\n\t\t\tconst kept = this.checker.getTypeFromTypeNode(literal);\n\t\t\t// Laying out a literal whose fields differ by name could declare what the program never uses.\n\t\t\treturn (\n\t\t\t\tfieldNames(this.checker, kept) === names &&\n\t\t\t\tthis.recordBody(kept, captured) === body\n\t\t\t);\n\t\t});\n\t}\n\n\t/** A record's fields as dialect declarations, each holding the value `captured` gives its name when setup captured one. */\n\tprivate recordBody(\n\t\ttype: ts.Type,\n\t\tcaptured: (name: string) => CapturedValue | undefined,\n\t): string {\n\t\treturn this.checker\n\t\t\t.getPropertiesOfType(type)\n\t\t\t.map((property) => {\n\t\t\t\tif (!plainName(property.name)) {\n\t\t\t\t\tthrow quotedField(property.valueDeclaration, property.name);\n\t\t\t\t}\n\t\t\t\treturn `${property.name}: ${this.declaredText(property.valueDeclaration, this.checker.getTypeOfSymbol(property), captured(property.name) ?? this.fieldSample(property), pascalCase(property.name))};`;\n\t\t\t})\n\t\t\t.join(\" \");\n\t}\n}\n\n/**\n * The program's enums with a string member, each refused at its declaration: a PLC enum's members\n * are integers, and a union of string literals is the type the PLC stores as an enum of names.\n */\nexport const stringEnums = (\n\tsources: readonly ts.SourceFile[],\n\tchecker: ts.TypeChecker,\n): SpecializeError[] =>\n\tsources.flatMap((source) =>\n\t\tsource.statements.flatMap((statement) => {\n\t\t\tif (\n\t\t\t\t!ts.isEnumDeclaration(statement) ||\n\t\t\t\t!statement.members.some(\n\t\t\t\t\t(member) => typeof checker.getConstantValue(member) === \"string\",\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tconst values = statement.members.map((member) =>\n\t\t\t\tchecker.getConstantValue(member),\n\t\t\t);\n\t\t\tconst union = values.every((value) => typeof value === \"string\")\n\t\t\t\t? `, or use the string literal union ${values.map((value) => JSON.stringify(value)).join(\" | \")}, which the PLC stores as an enum`\n\t\t\t\t: \"\";\n\t\t\treturn [\n\t\t\t\tnew SpecializeError(\n\t\t\t\t\tstatement.name,\n\t\t\t\t\t`${statement.name.text} has string members, and PLC enums are integers: give each member a number${union}.`,\n\t\t\t\t),\n\t\t\t];\n\t\t}),\n\t);\n\n/** The top-level names a statement declares. */\nconst declaredNames = (statement: ts.Statement): string[] => {\n\tif (ts.isVariableStatement(statement)) {\n\t\treturn statement.declarationList.declarations.flatMap((declaration) =>\n\t\t\tts.isIdentifier(declaration.name) ? [declaration.name.text] : [],\n\t\t);\n\t}\n\tif (\n\t\t(ts.isTypeAliasDeclaration(statement) ||\n\t\t\tts.isInterfaceDeclaration(statement) ||\n\t\t\tts.isEnumDeclaration(statement) ||\n\t\t\tts.isClassDeclaration(statement) ||\n\t\t\tts.isFunctionDeclaration(statement)) &&\n\t\tstatement.name\n\t) {\n\t\treturn [statement.name.text];\n\t}\n\treturn [];\n};\n\n/** A record's field names in order, which tell whether two records could have the same fields. */\nconst fieldNames = (checker: ts.TypeChecker, type: ts.Type): string =>\n\tchecker\n\t\t.getPropertiesOfType(type)\n\t\t.map((property) => property.name)\n\t\t.join(\",\");\n\n/** Whether setup captured a number with a fractional part. */\nconst fractional = (value: CapturedValue | undefined): boolean =>\n\tvalue?.kind === \"number\" && !Number.isInteger(value.value);\n\n/** Whether a captured array holds class instances, whose stored layout is each one's state. */\nexport const holdsInstances = (model: Model, node: ModelNode): boolean =>\n\tnode.captured.kind === \"array\" &&\n\tnode.captured.items.some(\n\t\t(item) => model.node(item)?.captured.kind === \"instance\",\n\t);\n\n/** The key and value types of a `Record<K, V>`. */\nexport const recordTypes = (\n\ttype: ts.Type,\n): { key: ts.Type; value: ts.Type } | undefined => {\n\tconst [key, value] = type.aliasTypeArguments ?? [];\n\treturn type.aliasSymbol?.name === \"Record\" && key && value\n\t\t? { key, value }\n\t\t: undefined;\n};\n\n/** A declaration's type annotation, or a routine's result type. */\nconst annotation = (\n\tdeclaration: ts.Node | undefined,\n): ts.TypeNode | undefined =>\n\tdeclaration &&\n\t(ts.isVariableDeclaration(declaration) ||\n\t\tts.isPropertyDeclaration(declaration) ||\n\t\tts.isPropertySignature(declaration) ||\n\t\tts.isParameter(declaration) ||\n\t\tts.isFunctionLike(declaration))\n\t\t? declaration.type\n\t\t: undefined;\n\n/** The element type an annotation `T[]`, `Array<T>`, `ReadonlyArray<T>` or `FixedArray<T, N>` names. */\nconst arrayElement = (\n\tnode: ts.TypeNode | undefined,\n): ts.TypeNode | undefined => {\n\tif (node && ts.isArrayTypeNode(node)) {\n\t\treturn node.elementType;\n\t}\n\tif (\n\t\tnode &&\n\t\tts.isTypeReferenceNode(node) &&\n\t\t[\"Array\", \"ReadonlyArray\", \"FixedArray\"].includes(node.typeName.getText())\n\t) {\n\t\treturn node.typeArguments?.[0];\n\t}\n\treturn undefined;\n};\n\n/** The value type an annotation `Record<K, V>` names. */\nconst recordValue = (node: ts.TypeNode | undefined): ts.TypeNode | undefined =>\n\tnode &&\n\tts.isTypeReferenceNode(node) &&\n\tnode.typeName.getText() === \"Record\" &&\n\tnode.typeArguments?.length === 2\n\t\t? node.typeArguments[1]\n\t\t: undefined;\n\n/** The IEC type an annotation names, such as `WORD`, or the one `WORD | undefined` holds. */\nconst iecTypeName = (node: ts.TypeNode | undefined): string | undefined => {\n\tif (node && ts.isUnionTypeNode(node)) {\n\t\tconst [defined, ...others] = node.types.filter(\n\t\t\t(member) =>\n\t\t\t\t!(\n\t\t\t\t\tmember.kind === ts.SyntaxKind.UndefinedKeyword ||\n\t\t\t\t\t(ts.isLiteralTypeNode(member) &&\n\t\t\t\t\t\tmember.literal.kind === ts.SyntaxKind.NullKeyword)\n\t\t\t\t),\n\t\t);\n\t\treturn others.length ? undefined : iecTypeName(defined);\n\t}\n\tif (!node || !ts.isTypeReferenceNode(node)) {\n\t\treturn undefined;\n\t}\n\tconst name = node.typeName.getText();\n\tconst [length, ...rest] = node.typeArguments ?? [];\n\tif (!length) {\n\t\treturn iecNames.has(name) ? name : undefined;\n\t}\n\t// A sized string keeps its capacity, which its resolved type, a plain string, has lost.\n\treturn (name === \"STRING\" || name === \"WSTRING\") &&\n\t\t!rest.length &&\n\t\tts.isLiteralTypeNode(length) &&\n\t\tts.isNumericLiteral(length.literal)\n\t\t? `${name}<${length.literal.text}>`\n\t\t: undefined;\n};\n\nconst isReadonlyArray = (type: ts.Type): boolean =>\n\ttype.getSymbol()?.name === \"ReadonlyArray\";\n\n/** The key a string-literal union's enum is registered under, whatever order its members are written in. */\nconst enumKey = (members: readonly string[]): string =>\n\t[...members].sort().join(\"|\");\n\n/** Whether a field's name is one a PLC variable or record field can have: a plain name, or a table's number. */\nexport const plainName = (name: string): boolean =>\n\t/^(\\d+|[\\p{ID_Start}_$][\\p{ID_Continue}$]*)$/u.test(name);\n\n/** The refusal of a field whose name had to be quoted, at the field. */\nexport const quotedField = (\n\tdeclaration: ts.Node | undefined,\n\tname: string,\n): Error => {\n\tconst plain = name\n\t\t.replace(/[^A-Za-z0-9_$]+(.)?/g, (_, next: string | undefined) =>\n\t\t\tnext ? next.toUpperCase() : \"\",\n\t\t)\n\t\t.replace(/^\\d/, \"_$&\");\n\tconst message = `\"${name}\" can't name a field the PLC stores, which needs a plain name such as ${plain || \"field\"}. Rename the field.`;\n\treturn declaration\n\t\t? new SpecializeError(declaration, message)\n\t\t: new Error(message);\n};\n\n/** A string literal as an enum member name. */\nconst literalMember = (value: string): string => {\n\tconst name = pascalCase(value);\n\treturn /^[A-Za-z_]/.test(name) ? name : `_${name}`;\n};\n\n/** `null` and `undefined` are one empty value in the PLC: an optional's Undefined member, or `has` false. */\nexport const isAbsent = (type: ts.Type): boolean =>\n\tBoolean(type.flags & (ts.TypeFlags.Undefined | ts.TypeFlags.Null));\n\n/** A type holding both null and undefined would need two empty values, which the PLC's optionals don't have. */\nconst bothAbsent = (checker: ts.TypeChecker, type: ts.Type): void => {\n\tif (\n\t\ttype.isUnion() &&\n\t\ttype.types.some((part) => part.flags & ts.TypeFlags.Null) &&\n\t\ttype.types.some((part) => part.flags & ts.TypeFlags.Undefined)\n\t) {\n\t\tthrow new Error(\n\t\t\t`${checker.typeToString(type)}: null and undefined are one empty value in the PLC; use one of them.`,\n\t\t);\n\t}\n};\n",
35
+ "import { identityDigest } from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport { modulePath } from \"../lowering-key\";\nimport {\n\tboundNames,\n\ttype CapturedGraph,\n\ttype CapturedNode,\n\ttype CapturedValue,\n} from \"./capture-protocol\";\n\n/** One step from an owner to the object it holds. */\nexport type Step =\n\t| { kind: \"field\"; name: string }\n\t| { kind: \"index\"; index: number };\n\n/** Where a captured object is stored: a root binding and the steps to it. */\nexport interface Owner {\n\troot: Root;\n\tsteps: readonly Step[];\n}\n\n/** The TypeScript path of an owned object or field, as the program names it: `program.diverters.sampleCounters[10]`. */\nexport const tsPath = (owner: Owner): string =>\n\towner.root.name + owner.steps.map((step) => stepPath(step, String)).join(\"\");\n\n/** One step of a path: an index, a numeric key in brackets as `key` spells it, or a field. */\nexport const stepPath = (step: Step, key: (name: string) => string): string => {\n\tif (step.kind === \"index\") {\n\t\treturn `[${step.index}]`;\n\t}\n\treturn /^\\d+$/.test(step.name) ? `[${key(step.name)}]` : `.${step.name}`;\n};\n\n/** Where `holder`, owned at `owner`, puts what it holds at `step`. */\nexport const ownerAt = (owner: Owner, step: Step): Owner => ({\n\troot: owner.root,\n\tsteps: [...owner.steps, step],\n});\n\nconst sameStep = (left: Step, right: Step): boolean =>\n\tleft.kind === \"index\"\n\t\t? right.kind === \"index\" && left.index === right.index\n\t\t: right.kind === \"field\" && left.name === right.name;\n\n/** The members of a union, or the type itself. */\nexport const unionMembers = (type: ts.Type): readonly ts.Type[] =>\n\ttype.isUnion() ? type.types : [type];\n\nexport const isExported = (declaration: ts.Declaration): boolean =>\n\tBoolean(ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Export);\n\n/** Whether a module's export list names its binding `name`: `export { name }`. */\nconst listedExport = (source: ts.SourceFile, name: string): boolean =>\n\tsource.statements.some(\n\t\t(statement) =>\n\t\t\tts.isExportDeclaration(statement) &&\n\t\t\t!statement.moduleSpecifier &&\n\t\t\t!statement.isTypeOnly &&\n\t\t\tstatement.exportClause !== undefined &&\n\t\t\tts.isNamedExports(statement.exportClause) &&\n\t\t\tstatement.exportClause.elements.some(\n\t\t\t\t(element) =>\n\t\t\t\t\t!element.isTypeOnly &&\n\t\t\t\t\t(element.propertyName ?? element.name).text === name,\n\t\t\t),\n\t);\n\n/** Each step from a captured object to what it holds, with the value there. */\nexport const children = (captured: CapturedNode): [Step, CapturedValue][] => {\n\tif (captured.kind === \"array\") {\n\t\treturn captured.items.map((item, index) => [\n\t\t\t{ kind: \"index\", index },\n\t\t\titem,\n\t\t]);\n\t}\n\tif (captured.kind === \"object\" || captured.kind === \"instance\") {\n\t\treturn Object.entries(captured.fields).map(([name, field]) => [\n\t\t\t{ kind: \"field\", name },\n\t\t\tfield,\n\t\t]);\n\t}\n\treturn [];\n};\n\n/** The value one step down from a captured object, when it has one there. */\nconst child = (\n\tcaptured: CapturedNode,\n\tstep: Step,\n): CapturedValue | undefined => {\n\tif (step.kind === \"index\") {\n\t\treturn captured.kind === \"array\" ? captured.items[step.index] : undefined;\n\t}\n\treturn captured.kind === \"object\" || captured.kind === \"instance\"\n\t\t? captured.fields[step.name]\n\t\t: undefined;\n};\n\n/** A field a class declares: a property, or a constructor parameter property. */\ntype ClassField = ts.PropertyDeclaration | ts.ParameterPropertyDeclaration;\n\nexport interface Root {\n\tfile: string;\n\tname: string;\n\t/** The variable, or the element of a destructuring declaration, that names the root. */\n\tdeclaration: ts.VariableDeclaration | ts.BindingElement;\n\t/**\n\t * Whether something outside the program addresses it: an export the hardware, HMI and server\n\t * read, or a binding the config's `io` reaches. Every field of such a root is stored.\n\t */\n\texported: boolean;\n\t/** Whether the config's `io` reaches it, so the hardware may write any field of it. */\n\tbound: boolean;\n\t/** What setup bound it to. */\n\tvalue: CapturedValue;\n}\n\nexport interface ModelNode {\n\tid: number;\n\t/**\n\t * The id a reference to the object holds at runtime: a digest of where setup put it, so an\n\t * object added elsewhere changes no stored reference across an online change.\n\t */\n\treference: number;\n\tcaptured: CapturedNode;\n\t/** The declared type where the object is stored; undefined for functions and services. */\n\ttype?: ts.Type;\n\t/** The first place setup reached it. Every other place holding it refers to this one. */\n\towner?: Owner;\n}\n\n/** The captured setup graph with each object's owner and declared type. */\nexport class Model {\n\treadonly nodes: ModelNode[];\n\treadonly roots: Root[] = [];\n\t/** The paths the hardware writes every scan, with the input address of each. */\n\treadonly inputs: ReadonlyMap<string, string>;\n\tprivate readonly projectRoot: string;\n\n\tconstructor(\n\t\treadonly graph: CapturedGraph,\n\t\treadonly checker: ts.TypeChecker,\n\t\treadonly program: ts.Program,\n\t\tentry: string,\n\t\tprojectRoot: string,\n\t\t{\n\t\t\tbound,\n\t\t\tinputs,\n\t\t}: {\n\t\t\t/** The bindings the config's `io` reaches state through. */\n\t\t\tbound: ReadonlySet<string>;\n\t\t\t/** The paths the config's `io` binds to inputs, with each input's address. */\n\t\t\tinputs: ReadonlyMap<string, string>;\n\t\t},\n\t) {\n\t\tthis.inputs = inputs;\n\t\tthis.nodes = graph.nodes.map((captured, id) => ({\n\t\t\tid,\n\t\t\treference: id,\n\t\t\tcaptured,\n\t\t}));\n\t\t// Dependencies own what they build before the entry module's instances refer to it.\n\t\tconst ordered = [\n\t\t\t...graph.bindings.filter((binding) => binding.file !== entry),\n\t\t\t...graph.bindings.filter((binding) => binding.file === entry),\n\t\t];\n\t\tfor (const binding of ordered) {\n\t\t\tconst declaration = this.binding(binding.file, binding.name);\n\t\t\tconst root: Root = {\n\t\t\t\tfile: binding.file,\n\t\t\t\tname: binding.name,\n\t\t\t\tdeclaration,\n\t\t\t\texported:\n\t\t\t\t\tisExported(declaration) ||\n\t\t\t\t\tlistedExport(this.sourceFile(binding.file), binding.name) ||\n\t\t\t\t\tbound.has(binding.name),\n\t\t\t\tbound: bound.has(binding.name),\n\t\t\t\tvalue: binding.value,\n\t\t\t};\n\t\t\tthis.roots.push(root);\n\t\t\tthis.own(\n\t\t\t\tbinding.value,\n\t\t\t\t{ root, steps: [] },\n\t\t\t\tchecker.getTypeAtLocation(declaration.name),\n\t\t\t);\n\t\t}\n\t\tthis.projectRoot = projectRoot;\n\t\tthis.assignReferences();\n\t}\n\n\t/**\n\t * Where setup put an object, as generated names and reference ids are made from: its root's\n\t * module and its path from there. Undefined for an object no root owns.\n\t */\n\tidentity(node: ModelNode): string | undefined {\n\t\treturn node.owner && this.ownerIdentity(node.owner);\n\t}\n\n\tprivate ownerIdentity(owner: Owner): string {\n\t\treturn `${modulePath(this.projectRoot, owner.root.file)}:${tsPath(owner)}`;\n\t}\n\n\t/** Whether `node` is owned exactly at `owner`, rather than only held there. */\n\townsAt(node: ModelNode, owner: Owner): boolean {\n\t\tconst own = node.owner;\n\t\treturn (\n\t\t\town !== undefined &&\n\t\t\town.root === owner.root &&\n\t\t\town.steps.length === owner.steps.length &&\n\t\t\town.steps.every((step, index) => {\n\t\t\t\tconst other = owner.steps[index];\n\t\t\t\treturn other !== undefined && sameStep(step, other);\n\t\t\t})\n\t\t);\n\t}\n\n\t/** What setup left in a record's or instance's field: undefined when it set none. */\n\tfield(holder: ModelNode, name: string): CapturedValue {\n\t\treturn (\n\t\t\tchild(holder.captured, { kind: \"field\", name }) ?? { kind: \"undefined\" }\n\t\t);\n\t}\n\n\t/** Gives each object setup put somewhere its reference id, from its identity. */\n\tprivate assignReferences(): void {\n\t\tconst taken = new Map<number, Owner>();\n\t\tfor (const node of this.nodes) {\n\t\t\tconst owner = node.owner;\n\t\t\tif (!owner) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst reference =\n\t\t\t\tNumber.parseInt(identityDigest(this.ownerIdentity(owner)), 16) &\n\t\t\t\t0x7fffffff;\n\t\t\tconst other = taken.get(reference);\n\t\t\tif (other) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`${tsPath(other)} and ${tsPath(owner)} would hold the same reference id; rename one of them.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\ttaken.set(reference, owner);\n\t\t\tnode.reference = reference;\n\t\t}\n\t}\n\n\t/** The object a captured value refers to; undefined for a primitive. */\n\tnode(value: Extract<CapturedValue, { kind: \"node\" }>): ModelNode;\n\tnode(value: CapturedValue): ModelNode | undefined;\n\tnode(value: CapturedValue): ModelNode | undefined {\n\t\tif (value.kind !== \"node\") {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst node = this.nodes[value.id];\n\t\tif (!node) {\n\t\t\tthrow new Error(`The setup graph has no object ${value.id}.`);\n\t\t}\n\t\treturn node;\n\t}\n\n\tprivate binding(\n\t\tfile: string,\n\t\tname: string,\n\t): ts.VariableDeclaration | ts.BindingElement {\n\t\tconst declarations = this.sourceFile(file).statements.flatMap(\n\t\t\t(statement) =>\n\t\t\t\tts.isVariableStatement(statement)\n\t\t\t\t\t? [...statement.declarationList.declarations]\n\t\t\t\t\t: [],\n\t\t);\n\t\tfor (const declaration of declarations) {\n\t\t\tconst named = boundNames(declaration.name).find(\n\t\t\t\t(bound) => bound.text === name,\n\t\t\t)?.parent;\n\t\t\tif (\n\t\t\t\tnamed &&\n\t\t\t\t(ts.isVariableDeclaration(named) || ts.isBindingElement(named))\n\t\t\t) {\n\t\t\t\treturn named;\n\t\t\t}\n\t\t}\n\t\tthrow new Error(`${file}: no module binding ${name}.`);\n\t}\n\n\t/** The node at a path from a root, following captured values. */\n\tat(root: Root, steps: readonly Step[]): ModelNode | undefined {\n\t\tconst value = steps.reduce<CapturedValue | undefined>((current, step) => {\n\t\t\tconst node = current && this.node(current);\n\t\t\treturn node && child(node.captured, step);\n\t\t}, root.value);\n\t\treturn value && this.node(value);\n\t}\n\n\t/** A program source by its file name. */\n\tsourceFile(file: string): ts.SourceFile {\n\t\tconst source = this.program.getSourceFile(file);\n\t\tif (!source) {\n\t\t\tthrow new Error(`${file} is not part of the program.`);\n\t\t}\n\t\treturn source;\n\t}\n\n\t/** The class a captured instance belongs to. */\n\tclassOf(node: ModelNode): ts.ClassDeclaration {\n\t\tconst captured = node.captured;\n\t\tif (captured.kind !== \"instance\") {\n\t\t\tthrow new Error(\"Not a class instance.\");\n\t\t}\n\t\tconst source = this.program.getSourceFile(captured.file);\n\t\tconst found = source?.statements.find(\n\t\t\t(statement): statement is ts.ClassDeclaration =>\n\t\t\t\tts.isClassDeclaration(statement) &&\n\t\t\t\tstatement.name?.text === captured.name,\n\t\t);\n\t\tif (!found) {\n\t\t\tthrow new Error(`${captured.file}: no class ${captured.name}.`);\n\t\t}\n\t\treturn found;\n\t}\n\n\t/** The nearest member of a class or the classes it extends that is `name` and passes `is`. */\n\tmemberNamed<T extends ts.ClassElement>(\n\t\tdeclaration: ts.ClassDeclaration,\n\t\tname: string,\n\t\tis: (member: ts.ClassElement) => member is T,\n\t): T | undefined {\n\t\treturn this.members(declaration).find(\n\t\t\t(member): member is T => is(member) && member.name?.getText() === name,\n\t\t);\n\t}\n\n\t/** A class field's declaration: a property, or a constructor parameter property. */\n\tmember(\n\t\tdeclaration: ts.ClassDeclaration,\n\t\tname: string,\n\t): ClassField | undefined {\n\t\treturn this.fields(declaration).find(\n\t\t\t(field) => field.name.getText() === name,\n\t\t);\n\t}\n\n\t/** The class and the classes it extends, the class first. */\n\tancestry(declaration: ts.ClassDeclaration): ts.ClassDeclaration[] {\n\t\tconst base = declaration.heritageClauses?.find(\n\t\t\t(clause) => clause.token === ts.SyntaxKind.ExtendsKeyword,\n\t\t)?.types[0]?.expression;\n\t\tconst symbol = base && this.checker.getSymbolAtLocation(base);\n\t\tconst resolved =\n\t\t\tsymbol && symbol.flags & ts.SymbolFlags.Alias\n\t\t\t\t? this.checker.getAliasedSymbol(symbol)\n\t\t\t\t: symbol;\n\t\tconst parent = resolved?.declarations?.find(ts.isClassDeclaration);\n\t\treturn parent ? [declaration, ...this.ancestry(parent)] : [declaration];\n\t}\n\n\t/** A class's own and inherited members, nearest first, as a lookup finds an override before what it overrides. */\n\tmembers(declaration: ts.ClassDeclaration): ts.ClassElement[] {\n\t\treturn this.ancestry(declaration).flatMap((owner) => [...owner.members]);\n\t}\n\n\t/** A class's fields, inherited ones first, each in declaration order: properties and constructor parameter properties. */\n\tfields(declaration: ts.ClassDeclaration): ClassField[] {\n\t\treturn this.ancestry(declaration)\n\t\t\t.reverse()\n\t\t\t.flatMap((owner) => this.ownFields(owner));\n\t}\n\n\tprivate ownFields(declaration: ts.ClassDeclaration): ClassField[] {\n\t\treturn declaration.members.flatMap((member): ClassField[] => {\n\t\t\tif (ts.isPropertyDeclaration(member)) {\n\t\t\t\treturn [member];\n\t\t\t}\n\t\t\tif (ts.isConstructorDeclaration(member)) {\n\t\t\t\treturn member.parameters.filter(\n\t\t\t\t\t(parameter): parameter is ts.ParameterPropertyDeclaration =>\n\t\t\t\t\t\tts.isParameterPropertyDeclaration(parameter, member),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn [];\n\t\t});\n\t}\n\n\t/** The declared type of a field of a captured instance or record. */\n\tcapturedFieldType(holder: ModelNode, name: string): ts.Type | undefined {\n\t\tif (holder.captured.kind === \"instance\") {\n\t\t\t// An instance of a generic class has its fields at its own type arguments.\n\t\t\tconst instantiated =\n\t\t\t\tholder.type && this.checker.getPropertyOfType(holder.type, name);\n\t\t\tif (instantiated) {\n\t\t\t\treturn this.checker.getTypeOfSymbol(instantiated);\n\t\t\t}\n\t\t\tconst member = this.member(this.classOf(holder), name);\n\t\t\treturn member && this.checker.getTypeAtLocation(member.name);\n\t\t}\n\t\treturn holder.type && this.fieldType(holder.type, name, holder.captured);\n\t}\n\n\t/** The declared type of a field of `type` holding `value`, choosing the union member it matches. */\n\tfieldType(\n\t\ttype: ts.Type,\n\t\tname: string,\n\t\tholder: CapturedNode,\n\t): ts.Type | undefined {\n\t\tconst variant = this.variant(type, holder);\n\t\tconst property = variant.getProperty(name);\n\t\treturn property && this.checker.getTypeOfSymbol(property);\n\t}\n\n\t/** The member of a union of object types that a captured object is, by its literal fields. */\n\tvariant(type: ts.Type, value: CapturedNode): ts.Type {\n\t\tconst candidates = unionMembers(type).filter(\n\t\t\t(member) => !(member.flags & ts.TypeFlags.Undefined),\n\t\t);\n\t\tconst [first] = candidates;\n\t\tif (!first) {\n\t\t\treturn type;\n\t\t}\n\t\tif (candidates.length === 1 || value.kind !== \"object\") {\n\t\t\treturn first;\n\t\t}\n\t\treturn (\n\t\t\tcandidates.find((candidate) =>\n\t\t\t\tObject.entries(value.fields).every(([name, field]) => {\n\t\t\t\t\tconst property = candidate.getProperty(name);\n\t\t\t\t\tif (!property) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tconst fieldType = this.checker.getTypeOfSymbol(property);\n\t\t\t\t\treturn (\n\t\t\t\t\t\t!fieldType.isLiteral() ||\n\t\t\t\t\t\tfield.kind !== \"string\" ||\n\t\t\t\t\t\tfieldType.value === field.value\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t) ?? first\n\t\t);\n\t}\n\n\t/** The type of an array's or tuple's elements. */\n\telementType(type: ts.Type): ts.Type | undefined {\n\t\treturn this.checker.getIndexTypeOfType(\n\t\t\tthis.checker.getNonNullableType(type),\n\t\t\tts.IndexKind.Number,\n\t\t);\n\t}\n\n\t/**\n\t * Gives each object the root's shortest path to it as its owner, breadth first: an object in an array whose\n\t * elements also refer to each other, as a chain does, is stored in the array, not inside its neighbour.\n\t */\n\tprivate own(\n\t\tvalue: CapturedValue,\n\t\towner: Owner,\n\t\ttype: ts.Type | undefined,\n\t): void {\n\t\tconst queue = [{ owner, type, value }];\n\t\tfor (const next of queue) {\n\t\t\tconst node = this.node(next.value);\n\t\t\tif (!node || node.owner) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tnode.owner = next.owner;\n\t\t\tnode.type = next.type;\n\t\t\tconst element =\n\t\t\t\tnode.captured.kind === \"array\" && next.type\n\t\t\t\t\t? this.elementType(next.type)\n\t\t\t\t\t: undefined;\n\t\t\tfor (const [step, held] of children(node.captured)) {\n\t\t\t\tqueue.push({\n\t\t\t\t\towner: ownerAt(next.owner, step),\n\t\t\t\t\ttype:\n\t\t\t\t\t\tstep.kind === \"index\"\n\t\t\t\t\t\t\t? element\n\t\t\t\t\t\t\t: this.capturedFieldType(node, step.name),\n\t\t\t\t\tvalue: held,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n}\n",
36
+ "import ts from \"typescript\";\nimport type { Model } from \"./model\";\n\n/** `base`, or else the first of `base_2`, `base_3`… that `taken` does not hold. */\nexport const unusedName = (\n\tbase: string,\n\ttaken: (name: string) => boolean,\n): string => {\n\tif (!taken(base)) {\n\t\treturn base;\n\t}\n\tfor (let index = 2; ; index++) {\n\t\tconst name = `${base}_${index}`;\n\t\tif (!taken(name)) {\n\t\t\treturn name;\n\t\t}\n\t}\n};\n\n/**\n * The names the generated modules use at module level: what they declare, and what they import\n * the program's constants, enums, tasks and storage as. Every part of elaboration that makes one up\n * asks here, so two things of one name never meet, whichever modules the program wrote them in.\n *\n * What a generated module declares keeps the name it always had, since a routine's or a type's\n * name reaches the PLC. An import is local to the generated TypeScript, so it is the one renamed.\n */\nexport class Names {\n\tprivate readonly declared = new Set<string>();\n\t/** The name each import is read by, by what it imports. */\n\tprivate readonly imports = new Map<string, string>();\n\tprivate readonly imported = new Set<string>();\n\n\tconstructor(\n\t\t/** Names the entry module is sure to declare, which no import takes however early it is made. */\n\t\tprivate readonly reserved: ReadonlySet<string>,\n\t) {}\n\n\t/** Notes that a generated module declares `name`, which imports made from now on avoid. */\n\tdeclare(name: string): void {\n\t\tthis.declared.add(name);\n\t}\n\n\t/** Whether an import is read by `name`, which a declaration made after it must then avoid. */\n\timportedAs(name: string): boolean {\n\t\treturn this.imported.has(name);\n\t}\n\n\t/**\n\t * The name generated code reads an import by: its own, unless that is taken, reserved, or one\n\t * of `avoided`. `key` says what is imported, so the same thing is read by the same name everywhere.\n\t */\n\timport(\n\t\tkey: string,\n\t\tname: string,\n\t\tavoided: ReadonlySet<string> = new Set(),\n\t): string {\n\t\tconst known = this.imports.get(key);\n\t\tif (known) {\n\t\t\treturn known;\n\t\t}\n\t\tconst local = unusedName(\n\t\t\tname,\n\t\t\t(candidate) =>\n\t\t\t\tthis.imported.has(candidate) ||\n\t\t\t\tthis.declared.has(candidate) ||\n\t\t\t\tthis.reserved.has(candidate) ||\n\t\t\t\tavoided.has(candidate),\n\t\t);\n\t\tthis.imports.set(key, local);\n\t\tthis.imported.add(local);\n\t\treturn local;\n\t}\n}\n\n/**\n * The names the entry module is sure to declare under the program's own name for the thing: a\n * module's function that takes no parameters is one routine, named as the function is. A function\n * with parameters may become several routines, each named with a digest, so it reserves nothing.\n */\nexport const routineNames = (\n\tsources: readonly ts.SourceFile[],\n): Set<string> => {\n\tconst names = new Set<string>();\n\tfor (const source of sources) {\n\t\tfor (const statement of source.statements) {\n\t\t\tif (\n\t\t\t\tts.isFunctionDeclaration(statement) &&\n\t\t\t\tstatement.name &&\n\t\t\t\t!statement.parameters.length\n\t\t\t) {\n\t\t\t\tnames.add(statement.name.text);\n\t\t\t}\n\t\t\tif (!ts.isVariableStatement(statement)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const declaration of statement.declarationList.declarations) {\n\t\t\t\tconst initializer = declaration.initializer;\n\t\t\t\tif (\n\t\t\t\t\tts.isIdentifier(declaration.name) &&\n\t\t\t\t\tinitializer &&\n\t\t\t\t\t(ts.isArrowFunction(initializer) ||\n\t\t\t\t\t\tts.isFunctionExpression(initializer)) &&\n\t\t\t\t\t!initializer.parameters.length\n\t\t\t\t) {\n\t\t\t\t\tnames.add(declaration.name.text);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn names;\n};\n\n/**\n * The names a root's storage module may declare: one variable for each field of a root record or\n * instance. A storage module imports every enum and type the generated types use, so those give way.\n */\nexport const rootFieldNames = (model: Model): Set<string> => {\n\tconst names = new Set<string>();\n\tfor (const root of model.roots) {\n\t\tconst node = model.node(root.value);\n\t\tif (node?.captured.kind === \"object\") {\n\t\t\tfor (const field of Object.keys(node.captured.fields)) {\n\t\t\t\tnames.add(field);\n\t\t\t}\n\t\t}\n\t\tif (node?.captured.kind === \"instance\") {\n\t\t\tfor (const member of model.fields(model.classOf(node))) {\n\t\t\t\tnames.add(member.name.getText());\n\t\t\t}\n\t\t}\n\t}\n\treturn names;\n};\n",
37
+ "import ts from \"typescript\";\nimport type { Mapped } from \"../positions\";\nimport { isWrapper } from \"../types\";\nimport type { CapturedPrimitive } from \"./capture-protocol\";\nimport type { Frame } from \"./frame\";\nimport type { ArrayLayout } from \"./layouts\";\nimport type { ModelNode } from \"./model\";\n\nexport type FunctionLike =\n\t| ts.FunctionDeclaration\n\t| ts.MethodDeclaration\n\t| ts.ArrowFunction\n\t| ts.FunctionExpression\n\t| ts.GetAccessorDeclaration;\n\n/** What an expression is while specializing: known now, or code the PLC runs. */\nexport type Value =\n\t/** An object setup built: a class instance, record, array, function or service. */\n\t| { kind: \"static\"; node: ModelNode }\n\t/** A literal or folded primitive. `undefined` is a value too. */\n\t| { kind: \"const\"; value: number | boolean | string | undefined | bigint }\n\t/** An array or record built in scan code from known parts, used before it needs storage. */\n\t| { kind: \"virtual\"; items?: Value[]; fields?: Map<string, Value> }\n\t/** A function value: a module function, method of a known instance, or a local arrow. */\n\t| { kind: \"function\"; declaration: FunctionLike; self?: ModelNode; env?: Env }\n\t/** Code the PLC runs. `declared` is the storage's declared type, before narrowing. */\n\t| {\n\t\t\tkind: \"code\";\n\t\t\ttext: string | Mapped;\n\t\t\tdeclared?: ts.Type;\n\t\t\tplace?: boolean;\n\t\t\tiec?: string;\n\t\t\t/** For an array place, the IEC width its declaration gives its elements, as `Array<BYTE>` does. */\n\t\t\telementIec?: string;\n\t\t\t/** For an array place, its layout with the length setup gave it, such as `FixedArray<BYTE, 32>`. */\n\t\t\tlayout?: ArrayLayout;\n\t\t\t/** For an array place, the length setup gave it, so scan code can visit each element. */\n\t\t\tlength?: number;\n\t\t\t/** For a place the config's `io` binds to an input, or one holding such a place: the hardware writes it every scan. */\n\t\t\tinput?: { path: string; address: string };\n\t\t\t/**\n\t\t\t * For a place reached through a runtime index, the same place with its indexes held in\n\t\t\t * consts, so a name for it keeps meaning the element it named when it was bound.\n\t\t\t */\n\t\t\tpinned?: (frame: Frame) => Value;\n\t\t\t/**\n\t\t\t * A copy of stored state a routine returned, named for the error: TypeScript would hand back\n\t\t\t * the stored object, so writing it here would change nothing the PLC keeps.\n\t\t\t */\n\t\t\tcopyOf?: string;\n\t\t\t/** A float the program made whole with Math.trunc, floor, ceil or round, which an integer place takes saturated. */\n\t\t\twhole?: true;\n\t\t\t/** What an `await` gives, typed by the call it awaited. */\n\t\t\tawaited?: boolean;\n\t\t\t/** What a task's method returns, typed by the task's declaration in its kept module. */\n\t\t\ttypedByTask?: boolean;\n\t }\n\t/**\n\t * A reference scan code chooses at run time, among objects setup built. `index` is code for the\n\t * id of the object it holds, one of `options`, or `noReference` for undefined.\n\t */\n\t| {\n\t\t\tkind: \"choice\";\n\t\t\toptions: readonly ModelNode[];\n\t\t\tindex: string | Mapped;\n\t\t\toptional: boolean;\n\t\t\t/** Whether TypeScript narrowed out undefined where this was read, though `optional` says its storage may hold none. */\n\t\t\tnarrowed?: boolean;\n\t\t\t/** Whether `index` is storage scan code can assign: a reference field, or a let. */\n\t\t\tplace?: boolean;\n\t }\n\t/**\n\t * An array of known values a filter decided at run time: every candidate, each with whether the\n\t * array holds it. `order` is the comparator of a `toSorted` over it, which nothing has run yet.\n\t */\n\t| {\n\t\t\tkind: \"masked\";\n\t\t\tentries: readonly { item: Value; present: Value }[];\n\t\t\torder?: Value;\n\t }\n\t/**\n\t * An array whose length is decided at run time: a `toArray()` snapshot, or a slice with runtime\n\t * bounds. Its storage is fixed, and the elements from `start` up to `end` are the ones it has.\n\t */\n\t| {\n\t\t\tkind: \"counted\";\n\t\t\tsource: CountedSource;\n\t\t\t/** Indexes into the storage, known now or held in consts: 0 <= start <= end <= its length. */\n\t\t\tstart: Value;\n\t\t\tend: Value;\n\t };\n\n/**\n * Where a counted array's elements are read from: elements setup fixed, each known by itself, or an\n * array the PLC stores whole, which is a snapshot's local or a runtime array a routine was passed.\n */\nexport type CountedSource =\n\t| { kind: \"items\"; items: readonly Value[] }\n\t| {\n\t\t\tkind: \"array\";\n\t\t\ttext: string | Mapped;\n\t\t\t/** The array's PLC type, as a routine it is passed to declares it. */\n\t\t\tlayout: string;\n\t\t\t/** How many elements the array has room for. */\n\t\t\tbound: number;\n\t\t\t/** One element of the array, given the code that indexes it. */\n\t\t\telement: (index: string | Mapped) => Value;\n\t\t\t/** Whether the array is a copy nothing else writes, so a slice of it can be kept. */\n\t\t\tsnapshot: boolean;\n\t\t\t/** For a snapshot, how many slots it stored into; the rest still hold the element type's empty value. */\n\t\t\tfilled?: Value;\n\t };\n\nexport type Counted = Extract<Value, { kind: \"counted\" }>;\n\nexport type Env = Map<ts.Symbol, Value>;\n\nexport const constant = (\n\tvalue: number | boolean | string | undefined | bigint,\n): Value => ({\n\tkind: \"const\",\n\tvalue,\n});\n\n/** A primitive setup captured, as a value known while specializing. */\nexport const capturedPrimitive = (value: CapturedPrimitive): Value => {\n\tswitch (value.kind) {\n\t\tcase \"undefined\":\n\t\t\treturn constant(undefined);\n\t\tcase \"bigint\":\n\t\t\treturn constant(BigInt(value.value));\n\t\tdefault:\n\t\t\treturn constant(value.value);\n\t}\n};\n\n/** A number setup fixed; undefined for one decided at run time. */\nexport const known = (value: Value): number | undefined =>\n\tvalue.kind === \"const\" && typeof value.value === \"number\"\n\t\t? value.value\n\t\t: undefined;\n\n/**\n * A number folded now, which the PLC can hold only when finite: NaN and the infinities have no PLC\n * value, as setup capture finds too.\n */\nexport const finite = <T>(value: T, at: ts.Node): T => {\n\tif (typeof value === \"number\" && !Number.isFinite(value)) {\n\t\tthrow new SpecializeError(at, `${value} has no PLC value.`);\n\t}\n\treturn value;\n};\n\n/** Each entry `map` holds now, put back by the function returned. */\nexport const restoring = <K, V>(map: Map<K, V>): VoidFunction => {\n\tconst saved = [...map];\n\treturn () => {\n\t\tmap.clear();\n\t\tfor (const [key, value] of saved) {\n\t\t\tmap.set(key, value);\n\t\t}\n\t};\n};\n\n/** Whether a value is stored state: a record or array the PLC keeps, or a copy of one. */\nexport const isStoredState = (value: Value): boolean =>\n\tvalue.kind === \"code\" &&\n\t(value.copyOf !== undefined ||\n\t\t(value.place === true &&\n\t\t\tvalue.declared !== undefined &&\n\t\t\tBoolean(value.declared.flags & ts.TypeFlags.Object)));\n\n/** Whether a literal's own fields or items hold objects setup built: instances, functions or references to them. */\nexport const holdsSetupObjects = (\n\tvalue: Extract<Value, { kind: \"virtual\" }>,\n): boolean =>\n\t[...(value.fields?.values() ?? []), ...(value.items ?? [])].some(\n\t\t(item) =>\n\t\t\titem.kind === \"static\" ||\n\t\t\titem.kind === \"function\" ||\n\t\t\titem.kind === \"choice\",\n\t);\n\n/** An expression without the wrappers around it. */\nexport const unwrapped = (node: ts.Expression): ts.Expression =>\n\tisWrapper(node) ? unwrapped(node.expression) : node;\n\n/** Whether code names a place or a literal, which reads the same however often it is repeated. */\nexport const repeatable = (text: string | Mapped): boolean =>\n\t/^[\\w.[\\]]+$/.test(String(text));\n\n/** Scan code elaboration cannot compile, reported at the node it stopped at. */\nexport class SpecializeError extends Error {\n\tconstructor(\n\t\treadonly node: ts.Node,\n\t\tmessage: string,\n\t) {\n\t\tsuper(message);\n\t}\n}\n",
38
+ "import ts from \"typescript\";\nimport { copied, from, joined, type Mapped } from \"../positions\";\nimport { namesSdk, sdkModules, unaliased, valueSymbol } from \"../sdk\";\nimport { plainName } from \"./layouts\";\nimport { isExported } from \"./model\";\n\n/** Whether an initializer is what a module of constants may hold: literals, tables of them, names, a task or the service client. */\nexport const constantInitializer = (\n\tnode: ts.Expression,\n\tchecker: ts.TypeChecker,\n\tsdk: string,\n): boolean => {\n\tif (\n\t\tts.isNumericLiteral(node) ||\n\t\tts.isStringLiteral(node) ||\n\t\tts.isNoSubstitutionTemplateLiteral(node) ||\n\t\tts.isBigIntLiteral(node) ||\n\t\tnode.kind === ts.SyntaxKind.TrueKeyword ||\n\t\tnode.kind === ts.SyntaxKind.FalseKeyword\n\t) {\n\t\treturn true;\n\t}\n\tif (ts.isPrefixUnaryExpression(node)) {\n\t\treturn constantInitializer(node.operand, checker, sdk);\n\t}\n\tif (\n\t\tts.isAsExpression(node) ||\n\t\tts.isSatisfiesExpression(node) ||\n\t\tts.isParenthesizedExpression(node)\n\t) {\n\t\treturn constantInitializer(node.expression, checker, sdk);\n\t}\n\tif (ts.isPropertyAccessExpression(node)) {\n\t\treturn ts.isIdentifier(node.expression);\n\t}\n\tif (ts.isIdentifier(node)) {\n\t\treturn true;\n\t}\n\tif (ts.isObjectLiteralExpression(node)) {\n\t\treturn node.properties.every(\n\t\t\t(property) =>\n\t\t\t\t(ts.isPropertyAssignment(property) &&\n\t\t\t\t\tconstantInitializer(property.initializer, checker, sdk)) ||\n\t\t\t\tts.isShorthandPropertyAssignment(property),\n\t\t);\n\t}\n\tif (ts.isArrayLiteralExpression(node)) {\n\t\treturn node.elements.every((element) =>\n\t\t\tconstantInitializer(element, checker, sdk),\n\t\t);\n\t}\n\tif (ts.isCallExpression(node)) {\n\t\treturn (\n\t\t\tnamesSdk(checker, sdk, node.expression, \"createServiceClient\") ||\n\t\t\tdefinesTask(node, checker, sdk)\n\t\t);\n\t}\n\treturn false;\n};\n\n/** Whether `call` is `tasks.define(...)` or `backgroundTasks.define(...)`, which the async lowering compiles as written. */\nexport const definesTask = (\n\tcall: ts.CallExpression,\n\tchecker: ts.TypeChecker,\n\tsdk: string,\n): boolean =>\n\tts.isPropertyAccessExpression(call.expression) &&\n\tcall.expression.name.text === \"define\" &&\n\t(namesSdk(checker, sdk, call.expression.expression, \"tasks\") ||\n\t\tnamesSdk(checker, sdk, call.expression.expression, \"backgroundTasks\"));\n\n/** A module's statements that create the service client. */\nexport const serviceClients = (\n\tsource: ts.SourceFile,\n\tchecker: ts.TypeChecker,\n\tsdk: string,\n): ts.Statement[] =>\n\tsource.statements.filter(\n\t\t(statement) =>\n\t\t\tts.isVariableStatement(statement) &&\n\t\t\tstatement.declarationList.declarations.every(\n\t\t\t\t(declaration) =>\n\t\t\t\t\tdeclaration.initializer &&\n\t\t\t\t\tts.isCallExpression(declaration.initializer) &&\n\t\t\t\t\tnamesSdk(\n\t\t\t\t\t\tchecker,\n\t\t\t\t\t\tsdk,\n\t\t\t\t\t\tdeclaration.initializer.expression,\n\t\t\t\t\t\t\"createServiceClient\",\n\t\t\t\t\t),\n\t\t\t),\n\t);\n\n/** Whether an import names one of the SDK's modules, which every module can import. */\nconst importsSdk = (statement: ts.ImportDeclaration): boolean => {\n\tconst specifier = statement.moduleSpecifier;\n\treturn (\n\t\tts.isStringLiteral(specifier) &&\n\t\tObject.values(sdkModules).some((module) => module === specifier.text)\n\t);\n};\n\n/** The statement of a module-level `const` declared by a plain name; undefined for any other declaration. */\nconst constantStatement = (\n\tdeclaration: ts.Declaration | undefined,\n): ts.VariableStatement | undefined => {\n\tif (\n\t\t!declaration ||\n\t\t!ts.isVariableDeclaration(declaration) ||\n\t\t!ts.isIdentifier(declaration.name) ||\n\t\t!(declaration.parent.flags & ts.NodeFlags.Const)\n\t) {\n\t\treturn undefined;\n\t}\n\tconst statement = declaration.parent.parent;\n\treturn ts.isVariableStatement(statement) && ts.isSourceFile(statement.parent)\n\t\t? statement\n\t\t: undefined;\n};\n\n/** Whether a type is one literal value, or a readonly table of them, as `as const` gives. */\nconst literalType = (checker: ts.TypeChecker, type: ts.Type): boolean => {\n\tif (type.isLiteral() || type.flags & ts.TypeFlags.BooleanLiteral) {\n\t\treturn true;\n\t}\n\tif (\n\t\t!(type.flags & ts.TypeFlags.Object) ||\n\t\ttype.getCallSignatures().length ||\n\t\ttype.getConstructSignatures().length\n\t) {\n\t\treturn false;\n\t}\n\tif (checker.isTupleType(type)) {\n\t\treturn checker\n\t\t\t.getTypeArguments(type as ts.TypeReference)\n\t\t\t.every((item) => literalType(checker, item));\n\t}\n\tconst properties = type.getProperties();\n\treturn (\n\t\tproperties.length > 0 &&\n\t\t!type.getStringIndexType() &&\n\t\t!type.getNumberIndexType() &&\n\t\tproperties.every((property) => {\n\t\t\tconst declaration = property.valueDeclaration;\n\t\t\treturn (\n\t\t\t\tdeclaration !== undefined &&\n\t\t\t\tts.isPropertyAssignment(declaration) &&\n\t\t\t\tliteralType(checker, checker.getTypeOfSymbol(property))\n\t\t\t);\n\t\t})\n\t);\n};\n\n/** A module-level const whose type is a literal value, which a module can declare without its value. */\nconst literalConstant = (\n\tchecker: ts.TypeChecker,\n\tsymbol: ts.Symbol,\n): ts.VariableDeclaration | undefined => {\n\tconst declaration = symbol.valueDeclaration;\n\treturn declaration &&\n\t\tts.isVariableDeclaration(declaration) &&\n\t\tconstantStatement(declaration) &&\n\t\tliteralType(checker, checker.getTypeAtLocation(declaration.name))\n\t\t? declaration\n\t\t: undefined;\n};\n\n/** Each identifier under `node` that is no part of a type: what the code there reads. */\nconst readNames = (node: ts.Node): ts.Identifier[] => {\n\tconst found: ts.Identifier[] = [];\n\tconst visit = (inner: ts.Node): void => {\n\t\tif (ts.isTypeNode(inner)) {\n\t\t\treturn;\n\t\t}\n\t\tif (ts.isIdentifier(inner)) {\n\t\t\tfound.push(inner);\n\t\t}\n\t\tts.forEachChild(inner, visit);\n\t};\n\tvisit(node);\n\treturn found;\n};\n\n/** Each identifier under `node`, in code and in types. */\nconst allNames = (node: ts.Node): ts.Identifier[] => {\n\tconst found: ts.Identifier[] = [];\n\tconst visit = (inner: ts.Node): void => {\n\t\tif (ts.isIdentifier(inner)) {\n\t\t\tfound.push(inner);\n\t\t}\n\t\tts.forEachChild(inner, visit);\n\t};\n\tvisit(node);\n\treturn found;\n};\n\n/**\n * What of each rewritten module the PLC compiles. A cut-down module is there for TypeScript and\n * for other modules' types: only the constants named in `compiled` are PLC code. The entry module\n * is PLC code but for the names in `declared`, which it only declares for other modules to import.\n */\nexport type Uncompiled =\n\t| { compiled: ReadonlySet<string> }\n\t| { declared: ReadonlySet<string> };\n\n/**\n * Decides what stays of each plain module once its code and state have moved into the generated\n * program, statement by statement:\n * - its types, and its enums, stay as written;\n * - a class is declared without its code, when a type that stays names it;\n * - a constant stays as written when a module of constants reads it, since that module compiles as\n * written and needs the value; any other constant of one literal value is declared without it,\n * which is all a server's schema reads;\n * - the service client it creates stays, as it does in a module of constants;\n * - its re-exports stay, less the names their module no longer exports, and its imports become\n * type imports, less those names, except where a constant that stays reads the value.\n *\n * Nothing else stays: functions and state are in the generated modules.\n */\nexport class Reduction {\n\t/** The constants a module of constants reads, each staying as written. */\n\tprivate readonly needed = new Set<ts.VariableDeclaration>();\n\t/** The classes a type that stays names, each declared without its code. */\n\tprivate readonly classes = new Set<ts.ClassDeclaration>();\n\t/** Whether each constant may stay as written, once asked. */\n\tprivate readonly plain = new Map<ts.VariableDeclaration, boolean>();\n\tprivate readonly cutDown: ReadonlySet<ts.SourceFile>;\n\tprivate entryDeclares: ReadonlySet<string> = new Set();\n\tprivate readonly runtime: ReadonlySet<ts.SourceFile>;\n\n\tconstructor(\n\t\tprivate readonly checker: ts.TypeChecker,\n\t\tprivate readonly sdk: string,\n\t\tprivate readonly options: {\n\t\t\t/** The program's own modules. */\n\t\t\truntime: readonly ts.SourceFile[];\n\t\t\t/** Modules the compiled program keeps as written. */\n\t\t\tkept: (file: string) => boolean;\n\t\t\tentry: ts.SourceFile;\n\t\t\t/** The bindings scan code assigns, which are state. */\n\t\t\twritten: ReadonlySet<ts.Symbol>;\n\t\t\t/** The bindings the config's `io` reaches state through. */\n\t\t\tbound: ReadonlySet<string>;\n\t\t},\n\t) {\n\t\tconst { runtime, kept, entry } = options;\n\t\tthis.runtime = new Set(runtime);\n\t\tthis.cutDown = new Set(\n\t\t\truntime.filter((source) => source !== entry && !kept(source.fileName)),\n\t\t);\n\t\tfor (const source of runtime) {\n\t\t\tif (!kept(source.fileName)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const statement of source.statements) {\n\t\t\t\t// Importing or re-exporting a name reads nothing: the code that uses it does.\n\t\t\t\tif (\n\t\t\t\t\t!ts.isImportDeclaration(statement) &&\n\t\t\t\t\t!ts.isExportDeclaration(statement)\n\t\t\t\t) {\n\t\t\t\t\tthis.need(statement);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const source of runtime) {\n\t\t\tif (kept(source.fileName)) {\n\t\t\t\tthis.declareClasses(source);\n\t\t\t}\n\t\t\tif (!this.cutDown.has(source)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const statement of source.statements) {\n\t\t\t\tif (\n\t\t\t\t\tts.isInterfaceDeclaration(statement) ||\n\t\t\t\t\tts.isTypeAliasDeclaration(statement) ||\n\t\t\t\t\tthis.keptWritten(statement)\n\t\t\t\t) {\n\t\t\t\t\tthis.declareClasses(statement);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/** The modules cut down, which hold no PLC code but the constants a module of constants reads. */\n\tget modules(): readonly ts.SourceFile[] {\n\t\treturn [...this.cutDown];\n\t}\n\n\t/** Marks the constants of cut-down modules that the code under `node` reads, and those they read. */\n\tprivate need(node: ts.Node): void {\n\t\tfor (const name of readNames(node)) {\n\t\t\tconst symbol = valueSymbol(this.checker, name);\n\t\t\tconst declaration =\n\t\t\t\tsymbol && unaliased(this.checker, symbol).valueDeclaration;\n\t\t\tif (\n\t\t\t\tdeclaration &&\n\t\t\t\tts.isVariableDeclaration(declaration) &&\n\t\t\t\tthis.cutDown.has(declaration.getSourceFile()) &&\n\t\t\t\t!this.needed.has(declaration) &&\n\t\t\t\tthis.staysWritten(declaration)\n\t\t\t) {\n\t\t\t\t// A statement stays whole, so every constant it declares is read.\n\t\t\t\tconst list = declaration.parent;\n\t\t\t\tfor (const each of ts.isVariableDeclarationList(list)\n\t\t\t\t\t? list.declarations\n\t\t\t\t\t: []) {\n\t\t\t\t\tthis.needed.add(each);\n\t\t\t\t\tif (each.initializer) {\n\t\t\t\t\t\tthis.need(each.initializer);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Whether a cut-down module's constant can stay as written: it is a literal, or a table of\n\t * literals and of other values that stay, and neither scan code nor the hardware writes it.\n\t */\n\tprivate staysWritten(declaration: ts.VariableDeclaration): boolean {\n\t\tconst known = this.plain.get(declaration);\n\t\tif (known !== undefined) {\n\t\t\treturn known;\n\t\t}\n\t\t// A constant can't read itself, so one asked about again while being decided is not at fault.\n\t\tthis.plain.set(declaration, true);\n\t\tconst statement = constantStatement(declaration);\n\t\tconst stays = Boolean(\n\t\t\tstatement?.declarationList.declarations.every((each) =>\n\t\t\t\tthis.dataOnly(each),\n\t\t\t),\n\t\t);\n\t\tthis.plain.set(declaration, stays);\n\t\treturn stays;\n\t}\n\n\tprivate dataOnly(declaration: ts.VariableDeclaration): boolean {\n\t\tconst { checker, sdk } = this;\n\t\tconst { written, bound } = this.options;\n\t\tconst symbol = checker.getSymbolAtLocation(declaration.name);\n\t\tconst initializer = declaration.initializer;\n\t\tconst calls = (node: ts.Node): boolean =>\n\t\t\tts.isCallExpression(node) || Boolean(ts.forEachChild(node, calls));\n\t\treturn (\n\t\t\tts.isIdentifier(declaration.name) &&\n\t\t\tinitializer !== undefined &&\n\t\t\tconstantInitializer(initializer, checker, sdk) &&\n\t\t\t!calls(initializer) &&\n\t\t\t!(symbol && written.has(symbol)) &&\n\t\t\t!bound.has(declaration.name.text) &&\n\t\t\treadNames(initializer).every((name) => this.readable(name))\n\t\t);\n\t}\n\n\t/** Whether what `name` reads still has its value once every module is rewritten. */\n\tprivate readable(name: ts.Identifier): boolean {\n\t\t// A property's own name reads nothing.\n\t\tif (\n\t\t\t(ts.isPropertyAccessExpression(name.parent) &&\n\t\t\t\tname.parent.name === name) ||\n\t\t\t(ts.isPropertyAssignment(name.parent) && name.parent.name === name)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\tconst symbol = valueSymbol(this.checker, name);\n\t\tconst declaration =\n\t\t\tsymbol && unaliased(this.checker, symbol).valueDeclaration;\n\t\tif (!declaration) {\n\t\t\treturn true;\n\t\t}\n\t\tconst source = declaration.getSourceFile();\n\t\tif (!this.runtime.has(source) || this.options.kept(source.fileName)) {\n\t\t\treturn true;\n\t\t}\n\t\t// What the entry module declares is settled only once its code is generated.\n\t\tif (ts.isEnumDeclaration(declaration)) {\n\t\t\treturn source !== this.options.entry && this.keepsEnum(declaration);\n\t\t}\n\t\treturn (\n\t\t\tts.isVariableDeclaration(declaration) &&\n\t\t\tthis.cutDown.has(source) &&\n\t\t\tthis.staysWritten(declaration)\n\t\t);\n\t}\n\n\t/** Whether a statement of a cut-down module stays as written because a module of constants reads it. */\n\tprivate keptWritten(statement: ts.Statement): boolean {\n\t\treturn (\n\t\t\tts.isVariableStatement(statement) &&\n\t\t\tstatement.declarationList.declarations.some((declaration) =>\n\t\t\t\tthis.needed.has(declaration),\n\t\t\t)\n\t\t);\n\t}\n\n\t/** Marks the classes of cut-down modules that anything under `node` names, and those their members name. */\n\tprivate declareClasses(node: ts.Node): void {\n\t\tfor (const name of allNames(node)) {\n\t\t\tconst symbol = this.checker.getSymbolAtLocation(name);\n\t\t\tthis.declareClass(symbol && unaliased(this.checker, symbol));\n\t\t}\n\t}\n\n\tprivate declareClass(symbol: ts.Symbol | undefined): void {\n\t\tconst declaration = symbol?.declarations?.find(ts.isClassDeclaration);\n\t\tif (\n\t\t\t!symbol ||\n\t\t\t!declaration?.name ||\n\t\t\t!this.cutDown.has(declaration.getSourceFile()) ||\n\t\t\tthis.classes.has(declaration)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tthis.classes.add(declaration);\n\t\t// Its members are declared by their types, written or inferred, which may name more classes.\n\t\tconst instance = this.checker.getDeclaredTypeOfSymbol(symbol);\n\t\tfor (const property of this.checker.getPropertiesOfType(instance)) {\n\t\t\tconst member = property.valueDeclaration;\n\t\t\tif (\n\t\t\t\tmember &&\n\t\t\t\t!(ts.getCombinedModifierFlags(member) & ts.ModifierFlags.Private)\n\t\t\t) {\n\t\t\t\tthis.declareTypeClasses(\n\t\t\t\t\tthis.checker.getTypeOfSymbolAtLocation(property, declaration),\n\t\t\t\t\tnew Set(),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Marks the classes a member's type names: the type itself, a union's parts, and an array's or a generic's arguments. */\n\tprivate declareTypeClasses(type: ts.Type, seen: Set<ts.Type>): void {\n\t\tif (seen.has(type) || seen.size > 64) {\n\t\t\treturn;\n\t\t}\n\t\tseen.add(type);\n\t\tthis.declareClass(type.getSymbol());\n\t\tconst parts = [\n\t\t\t...(type.isUnionOrIntersection() ? type.types : []),\n\t\t\t...(type.aliasTypeArguments ?? []),\n\t\t\t...(type.flags & ts.TypeFlags.Object &&\n\t\t\t(type as ts.ObjectType).objectFlags & ts.ObjectFlags.Reference\n\t\t\t\t? this.checker.getTypeArguments(type as ts.TypeReference)\n\t\t\t\t: []),\n\t\t];\n\t\tfor (const part of parts) {\n\t\t\tthis.declareTypeClasses(part, seen);\n\t\t}\n\t}\n\n\t/**\n\t * Whether an enum's declaration stays in its module as written. One whose member is computed\n\t * from a constant doesn't: the constant may not stay.\n\t */\n\tkeepsEnum(declaration: ts.EnumDeclaration): boolean {\n\t\tconst source = declaration.getSourceFile();\n\t\tif (!this.runtime.has(source) || this.options.kept(source.fileName)) {\n\t\t\treturn true;\n\t\t}\n\t\tconst fixed = declaration.members.every(\n\t\t\t(member) =>\n\t\t\t\t!member.initializer ||\n\t\t\t\treadNames(member.initializer).every((name) => {\n\t\t\t\t\tconst symbol = this.checker.getSymbolAtLocation(name);\n\t\t\t\t\treturn (\n\t\t\t\t\t\tsymbol !== undefined &&\n\t\t\t\t\t\tBoolean(symbol.flags & ts.SymbolFlags.EnumMember)\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t);\n\t\t// The entry module is written anew, and declares again only the enums it exports.\n\t\treturn (\n\t\t\tfixed &&\n\t\t\t(source !== this.options.entry || this.exportedByName(declaration))\n\t\t);\n\t}\n\n\t/** Whether an enum is one the generated modules can import from its own module, by its own name. */\n\tsharesEnum(declaration: ts.EnumDeclaration): boolean {\n\t\treturn this.keepsEnum(declaration) && this.exportedByName(declaration);\n\t}\n\n\t/** Why the generated modules can't import an enum that `sharesEnum` refuses, for the program's author. */\n\tenumRefusal(declaration: ts.EnumDeclaration): string {\n\t\tconst name = declaration.name.text;\n\t\treturn this.exportedByName(declaration)\n\t\t\t? `${name}: give each member of this enum a literal value. The generated code stores the enum and imports it from its module, where a member computed from a constant can't stay.`\n\t\t\t: `${name}: export this enum from its module. The generated code stores it, and imports it from there.`;\n\t}\n\n\tprivate exportedByName(declaration: ts.EnumDeclaration): boolean {\n\t\tconst module = this.checker.getSymbolAtLocation(\n\t\t\tdeclaration.getSourceFile(),\n\t\t);\n\t\tconst symbol = this.checker.getSymbolAtLocation(declaration.name);\n\t\tconst exported =\n\t\t\tmodule &&\n\t\t\tthis.checker\n\t\t\t\t.getExportsOfModule(module)\n\t\t\t\t.find((candidate) => candidate.name === declaration.name.text);\n\t\treturn (\n\t\t\tisExported(declaration) ||\n\t\t\t(exported !== undefined &&\n\t\t\t\tsymbol !== undefined &&\n\t\t\t\tunaliased(this.checker, exported) === symbol)\n\t\t);\n\t}\n\n\t/**\n\t * Whether a module still exports `symbol`'s value once every module is rewritten. A type always\n\t * survives; the entry module is written anew, and exports only its scan functions, its exported\n\t * enums and the constants it declares.\n\t */\n\tsurvives(symbol: ts.Symbol): boolean {\n\t\tconst declaration = symbol.valueDeclaration;\n\t\tif (!(symbol.flags & ts.SymbolFlags.Value) || !declaration) {\n\t\t\treturn true;\n\t\t}\n\t\tconst source = declaration.getSourceFile();\n\t\tif (!this.runtime.has(source) || this.options.kept(source.fileName)) {\n\t\t\treturn true;\n\t\t}\n\t\tif (source === this.options.entry) {\n\t\t\treturn this.exportedNames(symbol).some((name) =>\n\t\t\t\tthis.entryDeclares.has(name),\n\t\t\t);\n\t\t}\n\t\tif (ts.isEnumDeclaration(declaration)) {\n\t\t\treturn this.keepsEnum(declaration);\n\t\t}\n\t\tif (ts.isClassDeclaration(declaration)) {\n\t\t\treturn this.classes.has(declaration);\n\t\t}\n\t\treturn (\n\t\t\tts.isVariableDeclaration(declaration) &&\n\t\t\t(this.needed.has(declaration) ||\n\t\t\t\tliteralConstant(this.checker, symbol) !== undefined ||\n\t\t\t\tserviceClients(source, this.checker, this.sdk).includes(\n\t\t\t\t\tdeclaration.parent.parent,\n\t\t\t\t))\n\t\t);\n\t}\n\n\t/** The names the entry module exports `symbol` by. */\n\tprivate exportedNames(symbol: ts.Symbol): string[] {\n\t\tconst module = this.checker.getSymbolAtLocation(this.options.entry);\n\t\treturn (module ? this.checker.getExportsOfModule(module) : [])\n\t\t\t.filter((exported) => unaliased(this.checker, exported) === symbol)\n\t\t\t.map((exported) => exported.name);\n\t}\n\n\t/**\n\t * Tells which of its exported enums and constants the generated entry module did declare, by\n\t * name: it leaves out one whose name its own code uses, and other modules' imports follow.\n\t */\n\tdeclaredByEntry(names: ReadonlySet<string>): void {\n\t\tthis.entryDeclares = names;\n\t}\n\n\t/** The constants of a cut-down module that stay as written, which the PLC compiles. */\n\tcompiled(source: ts.SourceFile): Set<string> {\n\t\treturn new Set(\n\t\t\t[...this.needed]\n\t\t\t\t.filter((declaration) => declaration.getSourceFile() === source)\n\t\t\t\t.map((declaration) => declaration.name.getText()),\n\t\t);\n\t}\n\n\t/** A plain module, cut down to what stays of it. */\n\tmodule(source: ts.SourceFile): Mapped {\n\t\tconst { checker, sdk } = this;\n\t\tconst clients = serviceClients(source, checker, sdk);\n\t\t// The imports a constant that stays reads the value of.\n\t\tconst read = new Set(\n\t\t\tsource.statements\n\t\t\t\t.filter((statement) => this.keptWritten(statement))\n\t\t\t\t.flatMap(readNames)\n\t\t\t\t.flatMap((name) => valueSymbol(checker, name) ?? []),\n\t\t);\n\t\treturn joined(\n\t\t\t[\n\t\t\t\t...source.statements.flatMap((statement): Mapped[] => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tts.isInterfaceDeclaration(statement) ||\n\t\t\t\t\t\tts.isTypeAliasDeclaration(statement) ||\n\t\t\t\t\t\t(ts.isEnumDeclaration(statement) && this.keepsEnum(statement)) ||\n\t\t\t\t\t\tclients.includes(statement) ||\n\t\t\t\t\t\tthis.keptWritten(statement)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn [copied(statement)];\n\t\t\t\t\t}\n\t\t\t\t\tif (ts.isClassDeclaration(statement)) {\n\t\t\t\t\t\treturn this.classes.has(statement)\n\t\t\t\t\t\t\t? [from(statement, this.declaredClass(statement))]\n\t\t\t\t\t\t\t: [];\n\t\t\t\t\t}\n\t\t\t\t\tif (ts.isImportDeclaration(statement)) {\n\t\t\t\t\t\treturn statement.importClause?.isTypeOnly ||\n\t\t\t\t\t\t\t(clients.length > 0 && importsSdk(statement))\n\t\t\t\t\t\t\t? [copied(statement)]\n\t\t\t\t\t\t\t: this.imports(statement, read);\n\t\t\t\t\t}\n\t\t\t\t\tif (ts.isExportDeclaration(statement) && statement.moduleSpecifier) {\n\t\t\t\t\t\treturn this.reExports(statement);\n\t\t\t\t\t}\n\t\t\t\t\treturn [];\n\t\t\t\t}),\n\t\t\t\t...this.listedExports(source, (declaration) =>\n\t\t\t\t\tthis.stays(declaration, clients),\n\t\t\t\t).lines,\n\t\t\t\t\"export {};\",\n\t\t\t],\n\t\t\t\"\\n\",\n\t\t);\n\t}\n\n\t/** Whether a cut-down module's own declaration is still in it, under its own name. */\n\tprivate stays(\n\t\tdeclaration: ts.Declaration,\n\t\tclients: readonly ts.Statement[],\n\t): boolean {\n\t\tif (\n\t\t\tts.isInterfaceDeclaration(declaration) ||\n\t\t\tts.isTypeAliasDeclaration(declaration)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\tif (ts.isEnumDeclaration(declaration)) {\n\t\t\treturn this.keepsEnum(declaration);\n\t\t}\n\t\tif (ts.isClassDeclaration(declaration)) {\n\t\t\treturn this.classes.has(declaration);\n\t\t}\n\t\treturn (\n\t\t\tts.isVariableDeclaration(declaration) &&\n\t\t\t(this.needed.has(declaration) ||\n\t\t\t\tclients.includes(declaration.parent.parent))\n\t\t);\n\t}\n\n\t/**\n\t * What the generated entry module declares besides its code, for other modules and the server\n\t * to import: the enums the entry exports, as written, and its exported constants of one literal\n\t * value, without their values. None is PLC code of the entry's.\n\t */\n\tentry(): {\n\t\tenums: { name: string; line: Mapped }[];\n\t\tconstants: { name: string; line: Mapped }[];\n\t} {\n\t\tconst source = this.options.entry;\n\t\tconst enums = source.statements\n\t\t\t.filter(ts.isEnumDeclaration)\n\t\t\t.filter((statement) => this.sharesEnum(statement));\n\t\t// An enum the entry exports in a list is exported where it is declared here.\n\t\tconst text = (statement: ts.EnumDeclaration): Mapped =>\n\t\t\tisExported(statement)\n\t\t\t\t? copied(statement)\n\t\t\t\t: joined([\"export \", copied(statement)], \"\");\n\t\treturn {\n\t\t\tenums: enums.map((statement) => ({\n\t\t\t\tname: statement.name.text,\n\t\t\t\tline: text(statement),\n\t\t\t})),\n\t\t\tconstants: this.listedExports(source, () => false).declared,\n\t\t};\n\t}\n\n\t/**\n\t * The exports a module's statements that stay don't carry themselves: a name its export list or\n\t * default export gives a declaration that `stays`, and each exported constant of one literal\n\t * value that doesn't stay, declared without its value. A server's schema can size a wire field\n\t * by such a constant, and reads that size from its type.\n\t */\n\tprivate listedExports(\n\t\tsource: ts.SourceFile,\n\t\tstays: (declaration: ts.Declaration) => boolean,\n\t): { lines: Mapped[]; declared: { name: string; line: Mapped }[] } {\n\t\tconst { checker } = this;\n\t\tconst module = checker.getSymbolAtLocation(source);\n\t\tconst lines: Mapped[] = [];\n\t\tconst declared: { name: string; line: Mapped }[] = [];\n\t\tfor (const exported of module ? checker.getExportsOfModule(module) : []) {\n\t\t\t// A name re-exported from another module is that module's to declare.\n\t\t\tconst here = exported.declarations?.find(\n\t\t\t\t(declaration) =>\n\t\t\t\t\tdeclaration.getSourceFile() === source &&\n\t\t\t\t\t!(\n\t\t\t\t\t\tts.isExportSpecifier(declaration) &&\n\t\t\t\t\t\tdeclaration.parent.parent.moduleSpecifier\n\t\t\t\t\t),\n\t\t\t);\n\t\t\tconst target = unaliased(checker, exported);\n\t\t\tconst declaration = target.declarations?.find(\n\t\t\t\t(candidate) =>\n\t\t\t\t\tcandidate.getSourceFile() === source &&\n\t\t\t\t\t!ts.isExportSpecifier(candidate) &&\n\t\t\t\t\t!ts.isExportAssignment(candidate),\n\t\t\t);\n\t\t\tif (!here || !declaration) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst isDefault = exported.name === \"default\";\n\t\t\tif (stays(declaration)) {\n\t\t\t\t// A declaration exported where it is declared carries its own export.\n\t\t\t\tif (here === declaration && !isDefault) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// A class declared without its code exports itself, default or not.\n\t\t\t\tif (here === declaration && ts.isClassDeclaration(declaration)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst keyword =\n\t\t\t\t\ttarget.flags & ts.SymbolFlags.Value ? \"export\" : \"export type\";\n\t\t\t\tlines.push(\n\t\t\t\t\tfrom(\n\t\t\t\t\t\there,\n\t\t\t\t\t\tisDefault\n\t\t\t\t\t\t\t? `export default ${target.name};`\n\t\t\t\t\t\t\t: `${keyword} { ${target.name === exported.name ? target.name : `${target.name} as ${exported.name}`} };`,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst constant = literalConstant(checker, target);\n\t\t\t// The entry module's code is PLC code, where a default export has no meaning.\n\t\t\tif (!constant || (isDefault && source === this.options.entry)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst type = checker.typeToString(\n\t\t\t\tchecker.getTypeAtLocation(constant.name),\n\t\t\t\tundefined,\n\t\t\t\tts.TypeFormatFlags.NoTruncation,\n\t\t\t);\n\t\t\tconst line = from(\n\t\t\t\tconstant,\n\t\t\t\tisDefault\n\t\t\t\t\t? `declare const tsplcDefault: ${type};\\nexport default tsplcDefault;`\n\t\t\t\t\t: `export declare const ${exported.name}: ${type};`,\n\t\t\t);\n\t\t\tdeclared.push({ name: exported.name, line });\n\t\t\tlines.push(line);\n\t\t}\n\t\treturn { lines, declared };\n\t}\n\n\t/**\n\t * An import's names that the module they come from still exports. Each is imported as a type,\n\t * which is all the declarations left can use, unless a constant that stays reads its value.\n\t */\n\tprivate imports(\n\t\tstatement: ts.ImportDeclaration,\n\t\tread: ReadonlySet<ts.Symbol>,\n\t): Mapped[] {\n\t\tconst { checker } = this;\n\t\tconst clause = statement.importClause;\n\t\tif (!clause) {\n\t\t\treturn [];\n\t\t}\n\t\tconst local = (name: ts.Identifier) => checker.getSymbolAtLocation(name);\n\t\tconst surviving = (name: ts.Identifier): boolean => {\n\t\t\tconst symbol = local(name);\n\t\t\treturn symbol !== undefined && this.survives(unaliased(checker, symbol));\n\t\t};\n\t\tconst isRead = (name: ts.Identifier): boolean => {\n\t\t\tconst symbol = local(name);\n\t\t\treturn symbol !== undefined && read.has(symbol);\n\t\t};\n\t\tconst specifier = statement.moduleSpecifier.getText();\n\t\tconst bindings = clause.namedBindings;\n\t\tconst named =\n\t\t\tbindings && ts.isNamedImports(bindings)\n\t\t\t\t? bindings.elements.filter((element) => surviving(element.name))\n\t\t\t\t: [];\n\t\tconst list = (elements: readonly ts.ImportSpecifier[]): string =>\n\t\t\telements\n\t\t\t\t.map((element) =>\n\t\t\t\t\telement.propertyName\n\t\t\t\t\t\t? `${element.propertyName.getText()} as ${element.name.text}`\n\t\t\t\t\t\t: element.name.text,\n\t\t\t\t)\n\t\t\t\t.join(\", \");\n\t\tconst values = named.filter(\n\t\t\t(element) => !element.isTypeOnly && isRead(element.name),\n\t\t);\n\t\tconst types = named.filter((element) => !values.includes(element));\n\t\tconst lines: string[] = [];\n\t\tif (clause.name && surviving(clause.name)) {\n\t\t\tlines.push(\n\t\t\t\t`${isRead(clause.name) ? \"import\" : \"import type\"} ${clause.name.text} from ${specifier};`,\n\t\t\t);\n\t\t}\n\t\tif (bindings && ts.isNamespaceImport(bindings)) {\n\t\t\tlines.push(\n\t\t\t\t`${isRead(bindings.name) ? \"import\" : \"import type\"} * as ${bindings.name.text} from ${specifier};`,\n\t\t\t);\n\t\t}\n\t\tif (values.length) {\n\t\t\tlines.push(`import { ${list(values)} } from ${specifier};`);\n\t\t}\n\t\tif (types.length) {\n\t\t\tlines.push(`import type { ${list(types)} } from ${specifier};`);\n\t\t}\n\t\treturn lines.map((line) => from(statement, line));\n\t}\n\n\t/** A re-export, without the names the module it names no longer exports. */\n\tprivate reExports(statement: ts.ExportDeclaration): Mapped[] {\n\t\tconst clause = statement.exportClause;\n\t\tif (statement.isTypeOnly || !clause || !ts.isNamedExports(clause)) {\n\t\t\treturn [copied(statement)];\n\t\t}\n\t\tconst kept = clause.elements.filter((element) => {\n\t\t\tconst symbol = this.checker.getSymbolAtLocation(element.name);\n\t\t\treturn (\n\t\t\t\telement.isTypeOnly ||\n\t\t\t\t(symbol !== undefined && this.survives(unaliased(this.checker, symbol)))\n\t\t\t);\n\t\t});\n\t\treturn kept.length\n\t\t\t? [\n\t\t\t\t\tfrom(\n\t\t\t\t\t\tstatement,\n\t\t\t\t\t\t`export { ${kept.map((element) => element.getText()).join(\", \")} } from ${statement.moduleSpecifier?.getText()};`,\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t: [];\n\t}\n\n\t/**\n\t * A class as a declaration of what its instances hold: every field and method, its base classes'\n\t * among them, with the type each was written with or has. That is what a type naming the class\n\t * needs; the class's code is in the generated program.\n\t */\n\tprivate declaredClass(node: ts.ClassDeclaration): string {\n\t\tconst { checker } = this;\n\t\tconst symbol = node.name && checker.getSymbolAtLocation(node.name);\n\t\tconst name = node.name?.text ?? \"\";\n\t\tconst flags = ts.TypeFormatFlags.NoTruncation;\n\t\tconst members = symbol\n\t\t\t? checker\n\t\t\t\t\t.getPropertiesOfType(checker.getDeclaredTypeOfSymbol(symbol))\n\t\t\t\t\t.flatMap((property): string[] => {\n\t\t\t\t\t\tconst member = property.valueDeclaration;\n\t\t\t\t\t\tif (!member || !plainName(property.name)) {\n\t\t\t\t\t\t\treturn [];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst modifiers = ts.getCombinedModifierFlags(member);\n\t\t\t\t\t\t// A private member has no type other code may use, only its name.\n\t\t\t\t\t\tif (modifiers & ts.ModifierFlags.Private) {\n\t\t\t\t\t\t\treturn [`private ${property.name};`];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst access =\n\t\t\t\t\t\t\tmodifiers & ts.ModifierFlags.Protected ? \"protected \" : \"\";\n\t\t\t\t\t\tconst type = checker.getTypeOfSymbolAtLocation(property, node);\n\t\t\t\t\t\tif (property.flags & ts.SymbolFlags.Method) {\n\t\t\t\t\t\t\treturn type\n\t\t\t\t\t\t\t\t.getCallSignatures()\n\t\t\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t\t\t(signature) =>\n\t\t\t\t\t\t\t\t\t\t`${access}${property.name}${checker.signatureToString(signature, node, flags)};`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst written =\n\t\t\t\t\t\t\t(ts.isPropertyDeclaration(member) || ts.isParameter(member)) &&\n\t\t\t\t\t\t\tmember.type &&\n\t\t\t\t\t\t\tmember.getSourceFile() === node.getSourceFile()\n\t\t\t\t\t\t\t\t? member.type.getText()\n\t\t\t\t\t\t\t\t: checker.typeToString(type, node, flags);\n\t\t\t\t\t\tconst readonly =\n\t\t\t\t\t\t\tmodifiers & ts.ModifierFlags.Readonly ||\n\t\t\t\t\t\t\t(property.flags & ts.SymbolFlags.GetAccessor &&\n\t\t\t\t\t\t\t\t!(property.flags & ts.SymbolFlags.SetAccessor))\n\t\t\t\t\t\t\t\t? \"readonly \"\n\t\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\t\tconst optional =\n\t\t\t\t\t\t\tproperty.flags & ts.SymbolFlags.Optional ? \"?\" : \"\";\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t`${access}${readonly}${property.name}${optional}: ${written};`,\n\t\t\t\t\t\t];\n\t\t\t\t\t})\n\t\t\t: [];\n\t\tconst modifiers = ts.getCombinedModifierFlags(node);\n\t\tconst isDefault = Boolean(modifiers & ts.ModifierFlags.Default);\n\t\tconst head = [\n\t\t\tmodifiers & ts.ModifierFlags.Export && !isDefault ? \"export \" : \"\",\n\t\t\t\"declare \",\n\t\t\tmodifiers & ts.ModifierFlags.Abstract ? \"abstract \" : \"\",\n\t\t\t`class ${name}`,\n\t\t\tnode.typeParameters\n\t\t\t\t? `<${node.typeParameters.map((parameter) => parameter.getText()).join(\", \")}>`\n\t\t\t\t: \"\",\n\t\t].join(\"\");\n\t\treturn [\n\t\t\t`${head} {`,\n\t\t\t...members.map((member) => `\\t${member}`),\n\t\t\t\"}\",\n\t\t\t...(isDefault ? [`export default ${name};`] : []),\n\t\t].join(\"\\n\");\n\t}\n}\n",
39
+ "import type { Variable } from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport { declaredInSdkModule, namesSdk, sdkModules } from \"../sdk\";\nimport type { CapturedValue } from \"./capture-protocol\";\nimport {\n\tchildren,\n\ttype Model,\n\ttype ModelNode,\n\ttype Owner,\n\townerAt,\n\ttype Root,\n\ttsPath,\n} from \"./model\";\nimport type { Storage } from \"./storage\";\nimport { SpecializeError } from \"./values\";\n\nconst unstored =\n\t\"retain retains nothing the PLC stores; retain state scan code writes, or exported data.\";\nconst unpersisted =\n\t\"persist persists nothing the PLC stores; persist state scan code writes, or exported data.\";\n\n/** A declaration whose initializer retains a primitive: a module binding or a class field. */\ntype RetainedDeclaration = ts.VariableDeclaration | ts.PropertyDeclaration;\n\n/** Whether a value of `type` has no identity setup can mark, so retaining it needs its declaration. */\nconst primitive = (type: ts.Type): boolean => {\n\tif (type.isUnion()) {\n\t\treturn type.types.every(primitive);\n\t}\n\tif (type.isIntersection()) {\n\t\treturn type.types.some(primitive);\n\t}\n\treturn !(type.flags & (ts.TypeFlags.Object | ts.TypeFlags.NonPrimitive));\n};\n\n/** Whether an imported name reaches its declaration through `@tsplc/compiler/retain`. */\nconst importedThroughRetain = (\n\tchecker: ts.TypeChecker,\n\tsdk: string,\n\tsymbol: ts.Symbol | undefined,\n): boolean =>\n\tsymbol !== undefined &&\n\tBoolean(symbol.flags & ts.SymbolFlags.Alias) &&\n\t((symbol.declarations ?? []).some((declaration) =>\n\t\tdeclaredInSdkModule(sdk, sdkModules.retain, declaration),\n\t) ||\n\t\timportedThroughRetain(\n\t\t\tchecker,\n\t\t\tsdk,\n\t\t\tchecker.getImmediateAliasedSymbol(symbol),\n\t\t));\n\n/** The module binding a call initializes. */\nconst moduleBinding = (\n\tcall: ts.CallExpression,\n): ts.VariableDeclaration | undefined => {\n\tconst parent = call.parent;\n\treturn ts.isVariableDeclaration(parent) &&\n\t\tparent.initializer === call &&\n\t\tts.isVariableDeclarationList(parent.parent) &&\n\t\tts.isVariableStatement(parent.parent.parent) &&\n\t\tts.isSourceFile(parent.parent.parent.parent)\n\t\t? parent\n\t\t: undefined;\n};\n\n/** The declaration a `retain` call initializes, when it retains a primitive there. */\nconst retainedDeclaration = (\n\tcall: ts.CallExpression,\n): RetainedDeclaration | undefined => {\n\tconst parent = call.parent;\n\tif (ts.isPropertyDeclaration(parent) && parent.initializer === call) {\n\t\treturn parent;\n\t}\n\treturn moduleBinding(call);\n};\n\n/** A call of `retain` or `persist`, which only `@tsplc/compiler/retain` gives a value as setup runs under Bun. */\nconst checkImported = (\n\tcall: ts.CallExpression,\n\tname: \"persist\" | \"retain\",\n\tchecker: ts.TypeChecker,\n\tsdk: string,\n): void => {\n\tconst symbol = checker.getSymbolAtLocation(call.expression);\n\tif (!symbol || !(symbol.flags & ts.SymbolFlags.Alias)) {\n\t\tthrow new SpecializeError(\n\t\t\tcall,\n\t\t\t`Setup runs under Bun, where the global ${name} has no value: import { ${name} } from \"${sdkModules.retain}\".`,\n\t\t);\n\t}\n\tif (!importedThroughRetain(checker, sdk, symbol)) {\n\t\tthrow new SpecializeError(\n\t\t\tcall,\n\t\t\t`Setup runs under Bun, where only ${sdkModules.retain} gives ${name} a value: import { ${name} } from \"${sdkModules.retain}\".`,\n\t\t);\n\t}\n};\n\n/** The declarations whose storage the program keeps through restarts, as its source says. */\nexport interface RetentionDeclarations {\n\t/**\n\t * The declarations that retain a primitive. Setup marks the objects it retains as it runs, but a\n\t * primitive has no identity, so its declaration is found here.\n\t */\n\tretained: ReadonlySet<ts.Node>;\n\t/** The module bindings that persist: everything each one stores does. */\n\tpersisted: ReadonlySet<ts.Node>;\n}\n\n/**\n * The declarations that retain a primitive or persist a module binding. Checked before setup runs,\n * so a `retain` or `persist` setup can't evaluate is reported where it is written.\n */\nexport const retentionDeclarations = (\n\tsources: readonly ts.SourceFile[],\n\tchecker: ts.TypeChecker,\n\tsdk: string,\n): RetentionDeclarations => {\n\tconst retained = new Set<ts.Node>();\n\tconst persisted = new Set<ts.Node>();\n\tconst visit = (node: ts.Node): void => {\n\t\tif (\n\t\t\tts.isCallExpression(node) &&\n\t\t\tnamesSdk(checker, sdk, node.expression, \"retain\")\n\t\t) {\n\t\t\tcheckImported(node, \"retain\", checker, sdk);\n\t\t\tconst [argument] = node.arguments;\n\t\t\tif (argument && primitive(checker.getTypeAtLocation(argument))) {\n\t\t\t\tconst declaration = retainedDeclaration(node);\n\t\t\t\tif (!declaration) {\n\t\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\"A primitive is retained only as a module let's or a class field's initializer; retain the record that holds it.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tretained.add(declaration);\n\t\t\t}\n\t\t}\n\t\tif (\n\t\t\tts.isCallExpression(node) &&\n\t\t\tnamesSdk(checker, sdk, node.expression, \"persist\")\n\t\t) {\n\t\t\tcheckImported(node, \"persist\", checker, sdk);\n\t\t\tconst binding = moduleBinding(node);\n\t\t\t// CODESYS keeps everything its persistent list declares, so a binding persists whole.\n\t\t\tif (!binding) {\n\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"persist keeps a whole module binding: write it as the initializer of a module-level const or let, such as export const settings = persist({ ... }).\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tpersisted.add(binding);\n\t\t}\n\t\tts.forEachChild(node, visit);\n\t};\n\tfor (const source of sources) {\n\t\tvisit(source);\n\t}\n\treturn { retained, persisted };\n};\n\n/**\n * Which storage globals are `RETAIN`, and which `PERSISTENT RETAIN`. CODESYS retains whole\n * variables, so a global is retained when it holds anything setup retained: an object it passed to\n * `retain`, or a field or binding whose declaration retains a primitive. Every global of a binding\n * that persists persists, whatever it holds. Every retained or persisted thing must end up in a\n * global that keeps it.\n */\nexport class Retention {\n\tprivate readonly objects: ReadonlySet<number>;\n\tprivate readonly declarations: ReadonlySet<ts.Node>;\n\tprivate readonly persisted: ReadonlySet<ts.Node>;\n\tprivate readonly claimed = new Set<number | ts.Node>();\n\n\tconstructor(\n\t\tprivate readonly model: Model,\n\t\tprivate readonly storage: Storage,\n\t\t{ retained, persisted }: RetentionDeclarations,\n\t) {\n\t\tthis.objects = new Set(model.graph.retained);\n\t\tthis.declarations = retained;\n\t\tthis.persisted = persisted;\n\t}\n\n\t/** What the global holding a root, or one field of a flattened root, keeps through restarts. */\n\tglobal(root: Root, field: string | null): Variable[\"retention\"] {\n\t\t// Claimed first, so what the global holds counts as kept when its binding persists.\n\t\tconst retained = this.retained(root, field);\n\t\tif (this.persisted.has(root.declaration)) {\n\t\t\tthis.claimed.add(root.declaration);\n\t\t\treturn \"persist\";\n\t\t}\n\t\treturn retained ? \"retain\" : \"none\";\n\t}\n\n\t/** Whether the global holding a root, or one field of a flattened root, is retained. */\n\tprivate retained(root: Root, field: string | null): boolean {\n\t\tconst node = this.model.node(root.value);\n\t\tif (field === null || !node) {\n\t\t\treturn this.claim(\n\t\t\t\tthis.declarations.has(root.declaration) ? root.declaration : null,\n\t\t\t\tthis.holds(root.value, { root, steps: [] }),\n\t\t\t);\n\t\t}\n\t\tconst member =\n\t\t\tnode.captured.kind === \"instance\"\n\t\t\t\t? this.model.member(this.model.classOf(node), field)\n\t\t\t\t: undefined;\n\t\tconst held = this.holds(this.model.field(node, field), {\n\t\t\troot,\n\t\t\tsteps: [{ kind: \"field\", name: field }],\n\t\t});\n\t\tconst declared = member && this.declarations.has(member) ? member : null;\n\t\tconst whole = this.objects.has(node.id) ? node.id : null;\n\t\treturn [this.claim(declared, held), this.claim(whole, held)].some(Boolean);\n\t}\n\n\t/** The error for a retained or persisted thing no global keeps; undefined when each is kept. */\n\tunclaimed(): Error | undefined {\n\t\tconst binding = [...this.persisted].find((item) => !this.claimed.has(item));\n\t\tif (binding) {\n\t\t\treturn new SpecializeError(binding, unpersisted);\n\t\t}\n\t\tconst object = [...this.objects].find((id) => !this.claimed.has(id));\n\t\tif (object !== undefined) {\n\t\t\tconst owner = this.model.nodes[object]?.owner;\n\t\t\treturn new Error(\n\t\t\t\t`${owner ? tsPath(owner) : \"A retained object\"}: ${unstored}`,\n\t\t\t);\n\t\t}\n\t\tconst declaration = [...this.declarations].find(\n\t\t\t(item) => !this.claimed.has(item),\n\t\t);\n\t\treturn declaration && new SpecializeError(declaration, unstored);\n\t}\n\n\t/** Claims a mark for the global being decided, and says whether that global is retained. */\n\tprivate claim(mark: number | ts.Node | null, held: boolean): boolean {\n\t\tif (mark === null) {\n\t\t\treturn held;\n\t\t}\n\t\tthis.claimed.add(mark);\n\t\treturn true;\n\t}\n\n\t/**\n\t * Whether what a global stores at `at` holds something retained, claiming each mark it finds.\n\t * An object stored elsewhere is that place's to retain.\n\t */\n\tprivate holds(value: CapturedValue, at: Owner): boolean {\n\t\tconst node = this.model.node(value);\n\t\tif (!node || !this.model.ownsAt(node, at)) {\n\t\t\treturn false;\n\t\t}\n\t\tconst marks = [\n\t\t\t...(this.objects.has(node.id) && this.storage.hasState(node)\n\t\t\t\t? [node.id]\n\t\t\t\t: []),\n\t\t\t...this.retainedMembers(node),\n\t\t];\n\t\tfor (const mark of marks) {\n\t\t\tthis.claimed.add(mark);\n\t\t}\n\t\tconst inner = children(node.captured).map(([step, held]) =>\n\t\t\tthis.holds(held, ownerAt(at, step)),\n\t\t);\n\t\treturn marks.length > 0 || inner.some(Boolean);\n\t}\n\n\t/** The fields of an instance the PLC stores whose declarations retain a primitive. */\n\tprivate retainedMembers(node: ModelNode): ts.Node[] {\n\t\tif (node.captured.kind !== \"instance\") {\n\t\t\treturn [];\n\t\t}\n\t\treturn this.model\n\t\t\t.fields(this.model.classOf(node))\n\t\t\t.filter(\n\t\t\t\t(member) =>\n\t\t\t\t\tthis.declarations.has(member) &&\n\t\t\t\t\tthis.storage.stored(node, member.name.getText()),\n\t\t\t);\n\t}\n}\n",
40
+ "import { identityDigest } from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport { from, joined, type Mapped, mapped } from \"../positions\";\nimport { sdkModules, valueSymbol } from \"../sdk\";\nimport {\n\tnamedElements,\n\tnamedFields,\n\tparameterDefault,\n\ttype RunTimeOptional,\n\trunTimeOptional,\n\tsymbolOf,\n} from \"./declarations\";\nimport { DialectText } from \"./dialect\";\nimport {\n\ttype Closure,\n\tExpressionSpecializer,\n\ttype RoutineCall,\n\ttype RoutineTable,\n\ttype SpecializeContext,\n\ttype Typing,\n} from \"./expressions\";\nimport { Emitter, type Frame, type Referents } from \"./frame\";\nimport type { GenericTypes } from \"./generics\";\nimport { EntryImports } from \"./imports\";\nimport { Initializers } from \"./initializers\";\nimport { type ArrayLayout, arrayLayout, Layouts } from \"./layouts\";\nimport { type Model, type ModelNode, type Root, tsPath } from \"./model\";\nimport { Names, routineNames, unusedName } from \"./names\";\nimport { referenceLayout, referenceType } from \"./references\";\nimport { StatementSpecializer } from \"./statements\";\nimport { Storage } from \"./storage\";\nimport {\n\ttype Counted,\n\tconstant,\n\ttype FunctionLike,\n\tholdsSetupObjects,\n\trestoring,\n\tSpecializeError,\n\ttype Value,\n} from \"./values\";\nimport { assignsSymbol } from \"./writes\";\n\n/**\n * Evaluates the program's scan code against the setup graph. Everything setup decided (which\n * instance `this` is, what a field refers to, array lengths, config never written in scan code)\n * resolves at compile time; what is left becomes tsPLC dialect code over the stored state.\n */\nexport class Specializer implements RoutineTable {\n\treadonly layouts: Layouts;\n\treadonly storage: Storage;\n\treadonly initializers: Initializers;\n\tprivate readonly dialect: DialectText;\n\treadonly expressions: ExpressionSpecializer;\n\tprivate readonly statements: StatementSpecializer;\n\treadonly imports: EntryImports;\n\t/** The names the generated modules use, which routines, types and imports share. */\n\tprivate readonly names: Names;\n\t/** The source of each routine specialized so far, in the order each was finished. */\n\tprivate readonly finished: Mapped[] = [];\n\t/** Each async routine specialized for an instance, by routine name, which `cancelAsync(this)` cancels. */\n\tprivate readonly asyncOwners = new Map<string, ModelNode>();\n\t/** The routine that cancels an instance's async calls, by the instance, for each `cancelAsync(this)`. */\n\tprivate readonly cancellers = new Map<ModelNode, string>();\n\t/** Routines specialized from a class method, by routine name: `Class.method` and the TypeScript path of `this`. */\n\treadonly origins = new Map<string, { name: string; instance?: string }>();\n\t/** The routine each specialization is, by what tells it apart. */\n\tprivate readonly specialized = new Map<string, Specialized>();\n\t/** The routines whose bodies are being specialized, which a call to one of them would recurse into. */\n\tprivate readonly unfinished = new Set<string>();\n\t/** What each routine gives its callers, by routine name; empty until its body is specialized. */\n\tprivate readonly results = new Map<string, RoutineResult>();\n\treadonly checker: ts.TypeChecker;\n\n\tconstructor(\n\t\treadonly model: Model,\n\t\tprivate readonly generics: GenericTypes,\n\t\tsdkFile: string,\n\t\tsources: readonly ts.SourceFile[],\n\t\t{\n\t\t\tkept,\n\t\t\tnamed,\n\t\t\tenumRefusal,\n\t\t}: {\n\t\t\t/** Modules the compiled program keeps as written. */\n\t\t\tkept: (file: string) => boolean;\n\t\t\t/** Modules whose exported types the compiled program imports by name rather than copies. */\n\t\t\tnamed: (source: ts.SourceFile) => boolean;\n\t\t\t/** Why the generated modules can't import an enum from the module that declares it; undefined when they can. */\n\t\t\tenumRefusal: (declaration: ts.EnumDeclaration) => string | undefined;\n\t\t},\n\t\trootModule: (root: Root) => string,\n\t) {\n\t\tconst checker = generics.checker;\n\t\tthis.checker = checker;\n\t\tthis.names = new Names(\n\t\t\troutineNames(sources.filter((source) => !kept(source.fileName))),\n\t\t);\n\t\tthis.imports = new EntryImports(this.names);\n\t\tthis.layouts = new Layouts(\n\t\t\tmodel,\n\t\t\tchecker,\n\t\t\tkept,\n\t\t\tsources.filter(named),\n\t\t\t(node) => this.storage.storageType(node),\n\t\t\tthis.names,\n\t\t\tenumRefusal,\n\t\t);\n\t\tthis.storage = new Storage(\n\t\t\tmodel,\n\t\t\tchecker,\n\t\t\tthis.layouts,\n\t\t\tthis.imports,\n\t\t\tsources,\n\t\t\tkept,\n\t\t\trootModule,\n\t\t);\n\t\tthis.initializers = new Initializers(\n\t\t\tmodel,\n\t\t\tchecker,\n\t\t\tthis.layouts,\n\t\t\tthis.storage,\n\t\t);\n\t\tthis.dialect = new DialectText(\n\t\t\tmodel,\n\t\t\tchecker,\n\t\t\tthis.layouts,\n\t\t\tthis.storage,\n\t\t\tthis.initializers,\n\t\t\tthis.imports,\n\t\t);\n\t\tconst context: SpecializeContext = {\n\t\t\tmodel,\n\t\t\tchecker,\n\t\t\tlayouts: this.layouts,\n\t\t\tstorage: this.storage,\n\t\t\tinitializers: this.initializers,\n\t\t\timports: this.imports,\n\t\t\tdialect: this.dialect,\n\t\t\tsdkFile,\n\t\t\tsources,\n\t\t\tisKept: kept,\n\t\t};\n\t\tthis.expressions = new ExpressionSpecializer(context, this);\n\t\tthis.statements = new StatementSpecializer(context, this.expressions);\n\t}\n\n\t/** Statements that couldn't be specialized, for the build to report together. */\n\tget failures(): readonly SpecializeError[] {\n\t\treturn this.statements.failures;\n\t}\n\n\t/** Specializes the entry function, returning its body. */\n\tentry(declaration: ts.FunctionDeclaration | ts.ArrowFunction): Mapped[] {\n\t\tif (!declaration.body) {\n\t\t\tthrow new SpecializeError(declaration, \"The entry function has no body.\");\n\t\t}\n\t\tconst frame: Frame = {\n\t\t\temitter: new Emitter(declaration),\n\t\t\tenv: new Map(),\n\t\t\tloops: [],\n\t\t\treturns: undefined,\n\t\t\tasync: false,\n\t\t};\n\t\tthis.statements.body(declaration.body, frame);\n\t\treturn frame.emitter.lines;\n\t}\n\n\t/**\n\t * The routines specialized, then each instance's canceller, written last: it names every async\n\t * routine of its instance, which may be specialized after the call that cancels them.\n\t */\n\tget routines(): Mapped[] {\n\t\treturn [\n\t\t\t...this.finished,\n\t\t\t...[...this.cancellers].map(([self, name]) => {\n\t\t\t\tconst owned = [...this.asyncOwners]\n\t\t\t\t\t.filter(([, owner]) => owner === self)\n\t\t\t\t\t.map(([routine]) => routine);\n\t\t\t\tconst body = owned.length ? ` cancelAsync(${owned.join(\", \")});` : \"\";\n\t\t\t\treturn mapped`function ${name}(): void {${body} }`;\n\t\t\t}),\n\t\t];\n\t}\n\n\t/** The routine that cancels the pending async calls of `self`'s methods, as `cancelAsync(this)` does. */\n\tcanceller(self: ModelNode): string {\n\t\tconst known = this.cancellers.get(self);\n\t\tif (known) {\n\t\t\treturn known;\n\t\t}\n\t\tconst name = unusedName(\n\t\t\t`tsplcCancel_${identityDigest(this.model.identity(self) ?? String(self.id))}`,\n\t\t\t(candidate) => this.routineNamed(candidate),\n\t\t);\n\t\tthis.results.set(name, {});\n\t\tthis.names.declare(name);\n\t\tthis.cancellers.set(self, name);\n\t\tthis.imports.addSdk(sdkModules.async, \"cancelAsync\");\n\t\treturn name;\n\t}\n\n\tspeculatively<T>(run: () => T): T {\n\t\tconst routines = this.finished.length;\n\t\tconst restored = [\n\t\t\trestoring(this.asyncOwners),\n\t\t\trestoring(this.cancellers),\n\t\t\trestoring(this.origins),\n\t\t\trestoring(this.specialized),\n\t\t\trestoring(this.results),\n\t\t];\n\t\ttry {\n\t\t\treturn run();\n\t\t} finally {\n\t\t\tthis.finished.splice(routines);\n\t\t\tfor (const restore of restored) {\n\t\t\t\trestore();\n\t\t\t}\n\t\t}\n\t}\n\n\t/** The name of `declaration` specialized for `self` and these known arguments. */\n\troutine(\n\t\tdeclaration: FunctionLike,\n\t\tself: ModelNode | undefined,\n\t\targs: Value[],\n\t\tclosure?: Closure,\n\t): RoutineCall {\n\t\t// A generic class's method specializes with its instance's type arguments in scope.\n\t\tconst owner =\n\t\t\tself?.captured.kind === \"instance\" ? this.model.classOf(self) : undefined;\n\t\treturn this.generics.within(owner, self?.type, () =>\n\t\t\tthis.specializeRoutine(declaration, self, args, closure),\n\t\t);\n\t}\n\n\tprivate specializeRoutine(\n\t\tdeclaration: FunctionLike,\n\t\tself: ModelNode | undefined,\n\t\targs: Value[],\n\t\tclosure?: Closure,\n\t): RoutineCall {\n\t\tconst signature = this.checker.getSignatureFromDeclaration(declaration);\n\t\tconst returnType =\n\t\t\tsignature && this.checker.getReturnTypeOfSignature(signature);\n\t\tconst isAsync = Boolean(\n\t\t\tts.canHaveModifiers(declaration) &&\n\t\t\t\tts\n\t\t\t\t\t.getModifiers(declaration)\n\t\t\t\t\t?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword),\n\t\t);\n\t\tconst frame: Frame = {\n\t\t\temitter: new Emitter(declaration),\n\t\t\tenv: new Map(closure?.env),\n\t\t\tloops: [],\n\t\t\tself,\n\t\t\treturns:\n\t\t\t\treturnType &&\n\t\t\t\t(isAsync ? this.checker.getAwaitedType(returnType) : returnType),\n\t\t\tasync: isAsync,\n\t\t\t...(returnType &&\n\t\t\t\treferenceType(returnType) && {\n\t\t\t\t\treferents: { options: new Set<ModelNode>(), optional: false },\n\t\t\t\t}),\n\t\t};\n\t\tconst parameters: RoutineParameter[] = [];\n\t\tconst keys: Specialization[] = [];\n\t\tconst parameterList = ts.isGetAccessorDeclaration(declaration)\n\t\t\t? []\n\t\t\t: declaration.parameters;\n\t\tparameterList.forEach((parameter, index) => {\n\t\t\tconst declared = this.checker.getTypeAtLocation(parameter);\n\t\t\tif (parameter.dotDotDotToken) {\n\t\t\t\tthis.bindRest(\n\t\t\t\t\tparameter,\n\t\t\t\t\targs.slice(index),\n\t\t\t\t\tdeclared,\n\t\t\t\t\tframe,\n\t\t\t\t\tparameters,\n\t\t\t\t\tkeys,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst arg = args[index] ?? constant(undefined);\n\t\t\tconst fallback = parameterDefault(this.checker, arg, parameter);\n\t\t\tif (fallback) {\n\t\t\t\tthis.bindDefault(\n\t\t\t\t\tparameter,\n\t\t\t\t\tfallback,\n\t\t\t\t\tdeclared,\n\t\t\t\t\tframe,\n\t\t\t\t\tparameters,\n\t\t\t\t\tkeys,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.bindParameter(\n\t\t\t\tparameter.name,\n\t\t\t\targ,\n\t\t\t\tdeclared,\n\t\t\t\tframe,\n\t\t\t\tparameters,\n\t\t\t\tkeys,\n\t\t\t);\n\t\t});\n\t\t// Captured runtime locals the routine reads become its parameters; one it writes is borrowed.\n\t\tconst read = readSymbols(declaration, this.checker);\n\t\tconst captured = [...(closure?.env ?? [])].filter(([symbol]) =>\n\t\t\tread.has(symbol),\n\t\t);\n\t\tconst locals = new Map<string, Value>();\n\t\tconst passed = new Map<ts.Symbol, Value | string>();\n\t\tfor (const [symbol, value] of captured) {\n\t\t\tif (\n\t\t\t\tvalue.kind === \"code\" &&\n\t\t\t\tvalue.place &&\n\t\t\t\tdeclaration.body !== undefined &&\n\t\t\t\tassignsSymbol(declaration.body, new Set([symbol]), this.checker)\n\t\t\t) {\n\t\t\t\tconst name = frame.emitter.local(symbol.name);\n\t\t\t\tconst type = this.expressions.heldType(value, parameterTyping);\n\t\t\t\tthis.imports.addSdk(sdkModules.types, \"ref\");\n\t\t\t\tparameters.push({\n\t\t\t\t\tname,\n\t\t\t\t\ttype: `InOut<${type}>`,\n\t\t\t\t\targument: mapped`ref(${value.text})`,\n\t\t\t\t});\n\t\t\t\tconst local: Value = {\n\t\t\t\t\tkind: \"code\",\n\t\t\t\t\ttext: name,\n\t\t\t\t\tdeclared: value.declared,\n\t\t\t\t\tplace: true,\n\t\t\t\t\tiec: value.iec,\n\t\t\t\t};\n\t\t\t\tlocals.set(String(value.text), local);\n\t\t\t\tframe.env.set(symbol, local);\n\t\t\t\tpassed.set(symbol, \"ref\");\n\t\t\t} else if (\n\t\t\t\tvalue.kind === \"code\" ||\n\t\t\t\tvalue.kind === \"choice\" ||\n\t\t\t\tvalue.kind === \"masked\" ||\n\t\t\t\tvalue.kind === \"counted\"\n\t\t\t) {\n\t\t\t\t// A captured reference is the caller's too: its run-time id is passed as a local's value is.\n\t\t\t\tconst lifted = this.lifted(\n\t\t\t\t\tvalue,\n\t\t\t\t\tsymbol.name,\n\t\t\t\t\tframe,\n\t\t\t\t\teveryValue(frame, parameters),\n\t\t\t\t);\n\t\t\t\tif (value.kind === \"code\") {\n\t\t\t\t\tlocals.set(String(value.text), lifted);\n\t\t\t\t}\n\t\t\t\tframe.env.set(symbol, lifted);\n\t\t\t\tpassed.set(symbol, lifted);\n\t\t\t}\n\t\t}\n\t\tfor (const [symbol, value] of captured) {\n\t\t\tkeys.push({ name: symbol.name, value: passed.get(symbol) ?? value });\n\t\t}\n\t\t// A captured arrow or literal is lifted after the locals, so a local it holds is the routine's parameter.\n\t\tconst lift = (parameter: Passing[\"parameter\"]) => {\n\t\t\tfor (const [symbol, value] of captured) {\n\t\t\t\tif (!passed.has(symbol)) {\n\t\t\t\t\tframe.env.set(\n\t\t\t\t\t\tsymbol,\n\t\t\t\t\t\tthis.lifted(value, symbol.name, frame, {\n\t\t\t\t\t\t\tparameter,\n\t\t\t\t\t\t\tlocal: (place) => locals.get(String(place)),\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\t// A run-time part that reads the caller's locals is passed in; any other is read where it is, so the key holds its text.\n\t\tconst parts: { base: string; text: string; caller: boolean }[] = [];\n\t\tlift((text, base) => {\n\t\t\tparts.push({\n\t\t\t\tbase,\n\t\t\t\ttext: String(text),\n\t\t\t\tcaller: Boolean(closure?.caller.names(text)),\n\t\t\t});\n\t\t\treturn undefined;\n\t\t});\n\t\tconst key = `${declarationKey(declaration)}|${self?.id ?? \"\"}|${[\n\t\t\t...keys.map((entry) => specializationKey(entry, { stable: false })),\n\t\t\t...parts.map(({ base, text, caller }) =>\n\t\t\t\tcaller ? `${base}<-` : `${base}@${text}`,\n\t\t\t),\n\t\t].join(\",\")}`;\n\t\tconst pass = everyValue(frame, parameters).parameter;\n\t\tconst known = this.specialized.get(key);\n\t\tif (known && this.unfinished.has(known.name)) {\n\t\t\tconst named = declaration.name?.getText() ?? \"This function\";\n\t\t\tthrow new SpecializeError(\n\t\t\t\tdeclaration.name ?? declaration,\n\t\t\t\t`${named} calls itself, and a PLC routine can't: each call's state is allocated when the program compiles. Write the repetition as a loop.`,\n\t\t\t);\n\t\t}\n\t\tif (known) {\n\t\t\tlift((text, base, type) =>\n\t\t\t\tknown.parts.has(base) ? pass(text, base, type) : undefined,\n\t\t\t);\n\t\t\treturn this.call(\n\t\t\t\tknown.name,\n\t\t\t\tdeclaration,\n\t\t\t\tparameters.map(({ argument }) => argument),\n\t\t\t\tframe.returns,\n\t\t\t);\n\t\t}\n\t\tconst name = this.routineName(declaration, self, keys);\n\t\tthis.specialized.set(key, { name, parts: new Set() });\n\t\tthis.unfinished.add(name);\n\t\tconst callerParts = new Set(\n\t\t\tparts.filter(({ caller }) => caller).map(({ base }) => base),\n\t\t);\n\t\tconst passedParts: { base: string; local: string }[] = [];\n\t\tlift((text, base, type) => {\n\t\t\tif (!callerParts.has(base)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst local = pass(text, base, type);\n\t\t\tpassedParts.push({ base, local });\n\t\t\treturn local;\n\t\t});\n\t\ttry {\n\t\t\tthis.specializeBody(declaration, frame);\n\t\t} finally {\n\t\t\tthis.unfinished.delete(name);\n\t\t}\n\t\tconst unread = new Set(\n\t\t\tpassedParts\n\t\t\t\t.map(({ local }) => local)\n\t\t\t\t.filter((local) => !frame.emitter.reads(local)),\n\t\t);\n\t\tconst kept = parameters.filter(({ name }) => !unread.has(name));\n\t\tthis.specialized.set(key, {\n\t\t\tname,\n\t\t\tparts: new Set(\n\t\t\t\tpassedParts\n\t\t\t\t\t.filter(({ local }) => !unread.has(local))\n\t\t\t\t\t.map(({ base }) => base),\n\t\t\t),\n\t\t});\n\t\tconst resultText = this.resultText(declaration, frame);\n\t\tconst head = `${frame.async ? \"async \" : \"\"}function ${name}(${kept.map((parameter) => `${parameter.name}: ${parameter.type}`).join(\", \")}): ${\n\t\t\tframe.async ? `Promise<${resultText}>` : resultText\n\t\t} {`;\n\t\tconst instance = self?.owner && tsPath(self.owner);\n\t\tif (\n\t\t\tself?.captured.kind === \"instance\" &&\n\t\t\t(ts.isMethodDeclaration(declaration) ||\n\t\t\t\tts.isGetAccessorDeclaration(declaration))\n\t\t) {\n\t\t\tthis.origins.set(name, {\n\t\t\t\tname: `${self.captured.name}.${declaration.name.getText()}`,\n\t\t\t\t...(instance && { instance }),\n\t\t\t});\n\t\t}\n\t\tif (frame.async && self?.captured.kind === \"instance\") {\n\t\t\tthis.asyncOwners.set(name, self);\n\t\t}\n\t\tthis.finished.push(\n\t\t\tjoined(\n\t\t\t\t[\n\t\t\t\t\tfrom(declaration, `${head}${instance ? ` /* ${instance} */` : \"\"}`),\n\t\t\t\t\t...frame.emitter.lines,\n\t\t\t\t\tfrom(closingBrace(declaration), \"}\"),\n\t\t\t\t],\n\t\t\t\t\"\\n\",\n\t\t\t),\n\t\t);\n\t\tthis.results.set(name, {\n\t\t\tlayout: frame.resultLayout,\n\t\t\tlength: frame.resultLength,\n\t\t\treturnsStored: frame.returnsStored,\n\t\t\treferents: frame.referents,\n\t\t});\n\t\treturn this.call(\n\t\t\tname,\n\t\t\tdeclaration,\n\t\t\tkept.map(({ argument }) => argument),\n\t\t\tframe.returns,\n\t\t);\n\t}\n\n\t/** A routine's body: its statements, or a one-expression arrow's result. */\n\tprivate specializeBody(declaration: FunctionLike, frame: Frame): void {\n\t\tif (ts.isArrowFunction(declaration) && !ts.isBlock(declaration.body)) {\n\t\t\tframe.emitter.origin = declaration.body;\n\t\t\tconst result = this.expressions.expression(\n\t\t\t\tdeclaration.body,\n\t\t\t\tframe,\n\t\t\t\tframe.returns,\n\t\t\t);\n\t\t\tthis.expressions.references.returned(result, declaration.body, frame);\n\t\t\tif (!frame.returns || frame.returns.flags & ts.TypeFlags.Void) {\n\t\t\t\tif (result.kind === \"code\") {\n\t\t\t\t\tframe.emitter.line(mapped`${result.text};`);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tframe.emitter.line(\n\t\t\t\t\tmapped`return ${this.dialect.code(result, frame.returns)};`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (declaration.body) {\n\t\t\tthis.statements.body(declaration.body, frame);\n\t\t} else {\n\t\t\tthrow new SpecializeError(declaration, \"This function has no body.\");\n\t\t}\n\t}\n\n\t/** A call to a routine with these runtime arguments: what its callers read from its result. */\n\tprivate call(\n\t\tname: string,\n\t\tdeclaration: FunctionLike,\n\t\targs: (string | Mapped)[],\n\t\treturns: ts.Type | undefined,\n\t): RoutineCall {\n\t\tconst result = this.results.get(name);\n\t\tconst referents = result?.referents;\n\t\treturn {\n\t\t\tname,\n\t\t\targs,\n\t\t\treturns,\n\t\t\tiec: this.layouts.iecName(declaration),\n\t\t\tlayout: result?.layout,\n\t\t\tlength: result?.length,\n\t\t\treturnsStored: result?.returnsStored,\n\t\t\treferents: referents && {\n\t\t\t\toptions: [...referents.options],\n\t\t\t\toptional: referents.optional,\n\t\t\t},\n\t\t};\n\t}\n\n\t/** The result type a routine's head declares: an IEC width the declaration names, as `(): UINT` does, wins. */\n\tprivate resultText(declaration: FunctionLike, frame: Frame): string {\n\t\tif (!frame.returns || frame.returns.flags & ts.TypeFlags.Void) {\n\t\t\treturn \"void\";\n\t\t}\n\t\treturn (\n\t\t\tframe.resultLayout?.text ??\n\t\t\tthis.layouts.iecName(declaration) ??\n\t\t\t(frame.referents ? referenceLayout : this.layouts.text(frame.returns))\n\t\t);\n\t}\n\n\t/**\n\t * A specialized routine's name: its class and method, and for an instance or a known argument a\n\t * digest of which. Numbering specializations in the order they were made renamed them when an\n\t * instance was added before, which renamed the routines a job calls, and so its code.\n\t */\n\tprivate routineName(\n\t\tdeclaration: FunctionLike,\n\t\tself: ModelNode | undefined,\n\t\tkeys: readonly Specialization[],\n\t): string {\n\t\tconst own =\n\t\t\tdeclaration.name && ts.isIdentifier(declaration.name)\n\t\t\t\t? declaration.name.text\n\t\t\t\t: undefined;\n\t\tconst variable =\n\t\t\t!own &&\n\t\t\tdeclaration.parent &&\n\t\t\tts.isVariableDeclaration(declaration.parent) &&\n\t\t\tts.isIdentifier(declaration.parent.name)\n\t\t\t\t? declaration.parent.name.text\n\t\t\t\t: undefined;\n\t\tconst owner =\n\t\t\tself?.captured.kind === \"instance\" ? self.captured.name : undefined;\n\t\tconst named = [owner, own ?? variable ?? \"callback\"]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\"_\");\n\t\tconst instance = self && this.model.identity(self);\n\t\tconst specialized = Boolean(instance) || keys.length > 0;\n\t\tconst stable = keys.map((entry) =>\n\t\t\tspecializationKey(entry, { stable: true }),\n\t\t);\n\t\tconst base = specialized\n\t\t\t? `${named}_${identityDigest([instance ?? \"\", ...stable].join(\"\\0\"))}`\n\t\t\t: named;\n\t\tconst name = unusedName(base, (candidate) => this.routineNamed(candidate));\n\t\tthis.results.set(name, {});\n\t\tthis.names.declare(name);\n\t\treturn name;\n\t}\n\n\t/** Whether the generated entry module already uses `name`, for a routine or an import. */\n\tnamed(name: string): boolean {\n\t\treturn this.routineNamed(name);\n\t}\n\n\t/** Whether a routine can't take `name`: another has it, or the entry module imports something as it. */\n\tprivate routineNamed(name: string): boolean {\n\t\treturn this.results.has(name) || this.names.importedAs(name);\n\t}\n\n\tprivate bindParameter(\n\t\tname: ts.BindingName,\n\t\targ: Value,\n\t\tdeclared: ts.Type,\n\t\tframe: Frame,\n\t\tparameters: RoutineParameter[],\n\t\tkeys: Specialization[],\n\t): void {\n\t\tif (ts.isObjectBindingPattern(name)) {\n\t\t\tfor (const { element, field } of namedFields(name, \"parameter\")) {\n\t\t\t\tthis.bindElement(\n\t\t\t\t\telement,\n\t\t\t\t\tthis.expressions.member(arg, field, element, frame),\n\t\t\t\t\tframe,\n\t\t\t\t\tparameters,\n\t\t\t\t\tkeys,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (ts.isArrayBindingPattern(name)) {\n\t\t\tfor (const { element, index } of namedElements(name, \"parameter\")) {\n\t\t\t\tthis.bindElement(\n\t\t\t\t\telement,\n\t\t\t\t\tthis.expressions.element(arg, constant(index), element, frame),\n\t\t\t\t\tframe,\n\t\t\t\t\tparameters,\n\t\t\t\t\tkeys,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tconst symbol = symbolOf(this.checker, name);\n\t\t// A known primitive stays a parameter too, so one routine serves every value.\n\t\tif (\n\t\t\targ.kind === \"code\" ||\n\t\t\t(arg.kind === \"virtual\" && !this.isKnownShape(arg)) ||\n\t\t\t(arg.kind === \"const\" &&\n\t\t\t\t!(declared.flags & ts.TypeFlags.Undefined) &&\n\t\t\t\targ.value !== undefined)\n\t\t) {\n\t\t\tconst local = frame.emitter.local(name.text);\n\t\t\t// A name destructured from a field keeps that field's width.\n\t\t\tconst iec =\n\t\t\t\tthis.layouts.iecName(name.parent) ??\n\t\t\t\t(arg.kind === \"code\" ? arg.iec : undefined);\n\t\t\t// An array parameter takes the length of the storage or literal passed to it, which its type doesn't name.\n\t\t\tconst element = this.checker.getIndexTypeOfType(\n\t\t\t\tdeclared,\n\t\t\t\tts.IndexKind.Number,\n\t\t\t);\n\t\t\tconst literal =\n\t\t\t\targ.kind === \"virtual\" && arg.items && element\n\t\t\t\t\t? arrayLayout(this.layouts.text(element), arg.items.length)\n\t\t\t\t\t: undefined;\n\t\t\tconst layout = arg.kind === \"code\" ? arg.layout : literal;\n\t\t\tconst type = iec ?? layout?.text ?? this.layouts.text(declared);\n\t\t\tparameters.push({\n\t\t\t\tname: local,\n\t\t\t\ttype,\n\t\t\t\targument: this.dialect.assignmentText(arg, declared, iec),\n\t\t\t});\n\t\t\t// A PLC parameter is read-only; one the routine assigns, as JavaScript allows, is a local copy.\n\t\t\tconst routine = ts.findAncestor(name, ts.isFunctionLike);\n\t\t\tconst assigned =\n\t\t\t\troutine !== undefined &&\n\t\t\t\t\"body\" in routine &&\n\t\t\t\troutine.body !== undefined &&\n\t\t\t\tassignsSymbol(routine.body, new Set([symbol]), this.checker);\n\t\t\tconst held = assigned ? frame.emitter.local(name.text) : local;\n\t\t\tif (assigned) {\n\t\t\t\tframe.emitter.line(`let ${held}: ${type} = ${local};`);\n\t\t\t}\n\t\t\tframe.env.set(symbol, {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: held,\n\t\t\t\tdeclared,\n\t\t\t\tplace: true,\n\t\t\t\tiec,\n\t\t\t\tlayout,\n\t\t\t\t// A copy of stored state stays one in the routine it is passed to.\n\t\t\t\tcopyOf: arg.kind === \"code\" ? arg.copyOf : undefined,\n\t\t\t});\n\t\t\tkeys.push({\n\t\t\t\tname: name.text,\n\t\t\t\tvalue: `code${layout ? `:${layout.text}` : \"\"}`,\n\t\t\t\twidth: iec,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tconst lifted = this.lifted(\n\t\t\targ,\n\t\t\tname.text,\n\t\t\tframe,\n\t\t\teveryValue(frame, parameters),\n\t\t);\n\t\tframe.env.set(symbol, lifted);\n\t\tkeys.push({ name: name.text, value: lifted });\n\t}\n\n\t/**\n\t * A pattern element's default is worked out in the routine, as a parameter's is: it may read an\n\t * earlier parameter, which the caller passing the part cannot name.\n\t */\n\tprivate bindElement(\n\t\telement: ts.BindingElement,\n\t\tpart: Value,\n\t\tframe: Frame,\n\t\tparameters: RoutineParameter[],\n\t\tkeys: Specialization[],\n\t): void {\n\t\tconst declared = this.checker.getTypeAtLocation(element);\n\t\tif (!element.initializer) {\n\t\t\tthis.bindParameter(element.name, part, declared, frame, parameters, keys);\n\t\t\treturn;\n\t\t}\n\t\tif (part.kind === \"const\" && part.value === undefined) {\n\t\t\tthis.bindDefault(\n\t\t\t\telement,\n\t\t\t\telement.initializer,\n\t\t\t\tdeclared,\n\t\t\t\tframe,\n\t\t\t\tparameters,\n\t\t\t\tkeys,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst optional = runTimeOptional(this.checker, part);\n\t\tif (!optional) {\n\t\t\tthis.bindParameter(element.name, part, declared, frame, parameters, keys);\n\t\t\treturn;\n\t\t}\n\t\tthis.expressions.bind(\n\t\t\telement.name,\n\t\t\tthis.expressions.defaulted(\n\t\t\t\tthis.passedPart(element, optional, frame, parameters, keys),\n\t\t\t\telement.initializer,\n\t\t\t\tframe,\n\t\t\t),\n\t\t\tframe,\n\t\t\tdeclared,\n\t\t\t{ mutable: true, iec: this.layouts.iecName(element) },\n\t\t);\n\t}\n\n\t/** A pattern part that may be undefined at run time, passed to the routine whole, as the routine reads it. */\n\tprivate passedPart(\n\t\telement: ts.BindingElement,\n\t\tpart: RunTimeOptional,\n\t\tframe: Frame,\n\t\tparameters: RoutineParameter[],\n\t\tkeys: Specialization[],\n\t): Value {\n\t\tconst name = element.name.getText();\n\t\tconst base = ts.isIdentifier(element.name) ? element.name.text : \"part\";\n\t\tif (part.kind === \"choice\") {\n\t\t\tconst lifted = this.lifted(\n\t\t\t\tpart,\n\t\t\t\tbase,\n\t\t\t\tframe,\n\t\t\t\teveryValue(frame, parameters),\n\t\t\t);\n\t\t\t// A narrowed choice passed whole has the same key, but its routine has no fallback.\n\t\t\tkeys.push({ name, value: lifted }, { name, value: \"default?\" });\n\t\t\treturn lifted;\n\t\t}\n\t\tconst local = frame.emitter.local(base);\n\t\tparameters.push({\n\t\t\tname: local,\n\t\t\ttype: this.layouts.text(part.declared),\n\t\t\targument: this.dialect.assignmentText(part, part.declared, undefined),\n\t\t});\n\t\t// Unlike a default bound in the routine, the part is passed, so the routine has one more parameter.\n\t\tkeys.push({ name, value: \"code?\" });\n\t\treturn { kind: \"code\", text: local, declared: part.declared, place: true };\n\t}\n\n\t/**\n\t * A literal argument that holds objects setup built is known to the routine, but a runtime value\n\t * inside it is the caller's: each becomes a parameter of its own, which the caller passes.\n\t */\n\tprivate lifted(\n\t\tvalue: Value,\n\t\tbase: string,\n\t\tframe: Frame,\n\t\tpassing: Passing,\n\t): Value {\n\t\tconst lift = (part: Value, name: string) =>\n\t\t\tthis.lifted(part, name, frame, passing);\n\t\t// A counted array passes its local array and each bound decided at run time.\n\t\tif (value.kind === \"counted\") {\n\t\t\tconst { source } = value;\n\t\t\tconst start = lift(value.start, `${base}_start`);\n\t\t\tconst end = lift(value.end, `${base}_end`);\n\t\t\tif (source.kind === \"items\") {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"counted\",\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tkind: \"items\",\n\t\t\t\t\t\titems: source.items.map((item, index) =>\n\t\t\t\t\t\t\tlift(item, `${base}_${index}`),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\tstart,\n\t\t\t\t\tend,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst local = passing.parameter(source.text, base, () => source.layout);\n\t\t\tif (local === undefined) {\n\t\t\t\treturn { ...value, start, end };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"counted\",\n\t\t\t\tsource: {\n\t\t\t\t\t...source,\n\t\t\t\t\ttext: local,\n\t\t\t\t\telement: (index) => reread(source.element(index), local, index),\n\t\t\t\t\t// The routine is passed the end as it is now, which a count it never saw can't be compared with.\n\t\t\t\t\tfilled: undefined,\n\t\t\t\t},\n\t\t\t\tstart,\n\t\t\t\tend,\n\t\t\t};\n\t\t}\n\t\t// A reference chosen at run time passes its id; the routine specializes on what it can be.\n\t\tif (value.kind === \"choice\") {\n\t\t\tconst local = passing.parameter(value.index, base, () => referenceLayout);\n\t\t\tif (local === undefined) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"choice\",\n\t\t\t\toptions: value.options,\n\t\t\t\tindex: local,\n\t\t\t\toptional: value.optional,\n\t\t\t};\n\t\t}\n\t\tif (value.kind === \"masked\") {\n\t\t\treturn {\n\t\t\t\t...value,\n\t\t\t\tentries: value.entries.map((entry, index) => ({\n\t\t\t\t\titem: lift(entry.item, `${base}_${index}`),\n\t\t\t\t\tpresent: lift(entry.present, `${base}_${index}_present`),\n\t\t\t\t})),\n\t\t\t\torder: value.order && lift(value.order, `${base}_order`),\n\t\t\t};\n\t\t}\n\t\tif (value.kind === \"code\") {\n\t\t\tconst own = value.place ? passing.local(value.text) : undefined;\n\t\t\tif (own) {\n\t\t\t\treturn own;\n\t\t\t}\n\t\t\tconst local = passing.parameter(value.text, base, () =>\n\t\t\t\tthis.expressions.heldType(value, parameterTyping),\n\t\t\t);\n\t\t\tif (local === undefined) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: local,\n\t\t\t\tdeclared: value.declared,\n\t\t\t\tplace: true,\n\t\t\t\tiec: value.iec,\n\t\t\t};\n\t\t}\n\t\t// A callback passed in carries what it captured from the caller: runtime values among them are passed too.\n\t\tif (value.kind === \"function\" && value.env) {\n\t\t\tconst read = readSymbols(value.declaration, this.checker);\n\t\t\treturn {\n\t\t\t\t...value,\n\t\t\t\tenv: new Map(\n\t\t\t\t\t[...value.env]\n\t\t\t\t\t\t.filter(([symbol]) => read.has(symbol))\n\t\t\t\t\t\t.map(([symbol, captured]) => [\n\t\t\t\t\t\t\tsymbol,\n\t\t\t\t\t\t\tlift(captured, `${base}_${symbol.name}`),\n\t\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t\tif (value.kind !== \"virtual\") {\n\t\t\treturn value;\n\t\t}\n\t\treturn {\n\t\t\t...value,\n\t\t\t...(value.items && {\n\t\t\t\titems: value.items.map((item, index) => lift(item, `${base}_${index}`)),\n\t\t\t}),\n\t\t\t...(value.fields && {\n\t\t\t\tfields: new Map(\n\t\t\t\t\t[...value.fields].map(([field, item]) => [\n\t\t\t\t\t\tfield,\n\t\t\t\t\t\tlift(item, `${base}_${field}`),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t}),\n\t\t};\n\t}\n\n\t/**\n\t * A default setup fixes is a known argument like any other; one read from scan state or an earlier\n\t * parameter is worked out when the routine starts, as JavaScript does.\n\t */\n\tprivate bindDefault(\n\t\tparameter: ts.ParameterDeclaration | ts.BindingElement,\n\t\tinitializer: ts.Expression,\n\t\tdeclared: ts.Type,\n\t\tframe: Frame,\n\t\tparameters: RoutineParameter[],\n\t\tkeys: Specialization[],\n\t): void {\n\t\tconst value = this.expressions.expression(initializer, frame, declared);\n\t\tif (value.kind !== \"const\") {\n\t\t\tthis.expressions.bind(parameter.name, value, frame, declared, {\n\t\t\t\tmutable: value.kind === \"code\",\n\t\t\t\tiec: this.layouts.iecName(parameter),\n\t\t\t});\n\t\t\tkeys.push({ name: parameter.name.getText(), value: \"default\" });\n\t\t\treturn;\n\t\t}\n\t\tthis.bindParameter(\n\t\t\tparameter.name,\n\t\t\tvalue,\n\t\t\tdeclared,\n\t\t\tframe,\n\t\t\tparameters,\n\t\t\tkeys,\n\t\t);\n\t}\n\n\t/** A rest parameter is the call's remaining arguments, each a parameter of its own when it is a runtime value. */\n\tprivate bindRest(\n\t\tparameter: ts.ParameterDeclaration,\n\t\targs: readonly Value[],\n\t\tdeclared: ts.Type,\n\t\tframe: Frame,\n\t\tparameters: RoutineParameter[],\n\t\tkeys: Specialization[],\n\t): void {\n\t\tif (!ts.isIdentifier(parameter.name)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tparameter.name,\n\t\t\t\t\"Name the rest parameter; destructure it in the body.\",\n\t\t\t);\n\t\t}\n\t\tconst element =\n\t\t\tthis.checker.getIndexTypeOfType(declared, ts.IndexKind.Number) ??\n\t\t\tthis.checker.getAnyType();\n\t\tconst name = parameter.name.text;\n\t\tconst items = args.map((arg, index): Value => {\n\t\t\tif (arg.kind !== \"code\" && arg.kind !== \"const\") {\n\t\t\t\tkeys.push({ name: `${name}[${index}]`, value: arg });\n\t\t\t\treturn arg;\n\t\t\t}\n\t\t\tconst local = frame.emitter.local(`${name}_${index}`);\n\t\t\tconst iec = arg.kind === \"code\" ? arg.iec : undefined;\n\t\t\tparameters.push({\n\t\t\t\tname: local,\n\t\t\t\ttype: iec ?? this.layouts.text(element),\n\t\t\t\targument: this.dialect.assignmentText(arg, element, iec),\n\t\t\t});\n\t\t\tkeys.push({ name: `${name}[${index}]`, value: \"code\" });\n\t\t\treturn { kind: \"code\", text: local, declared: element, place: true, iec };\n\t\t});\n\t\tframe.env.set(symbolOf(this.checker, parameter.name), {\n\t\t\tkind: \"virtual\",\n\t\t\titems,\n\t\t});\n\t}\n\n\t/** A literal holding objects setup built, or only values known now: an argument the routine specializes on. */\n\tprivate isKnownShape(value: Value): boolean {\n\t\tif (value.kind !== \"virtual\") {\n\t\t\treturn false;\n\t\t}\n\t\tconst inner = [...(value.fields?.values() ?? []), ...(value.items ?? [])];\n\t\treturn (\n\t\t\tholdsSetupObjects(value) ||\n\t\t\tinner.some((item) => this.isKnownShape(item)) ||\n\t\t\t(value.items !== undefined &&\n\t\t\t\tinner.every((item) => item.kind === \"const\"))\n\t\t);\n\t}\n}\n\n/** Where a routine ends: the closing brace of its body, or the whole of a one-expression arrow. */\nexport const closingBrace = (declaration: FunctionLike): ts.Node =>\n\t(declaration.body &&\n\t\tts.isBlock(declaration.body) &&\n\t\tdeclaration.body.getLastToken()) ||\n\tdeclaration;\n\n/** A specialized routine's result as its callers read it, once its body is specialized. */\ninterface RoutineResult {\n\tlayout?: ArrayLayout;\n\tlength?: number;\n\treturnsStored?: boolean;\n\treferents?: Referents;\n}\n\n/** What one parameter or captured name was specialized for: a known value, or how a runtime one is passed. */\ninterface Specialization {\n\tname: string;\n\tvalue: Value | string;\n\t/**\n\t * The IEC width a runtime parameter takes from its argument. Calls at different widths need a\n\t * routine each, but the routine's name leaves it out, so names stay as they were.\n\t */\n\twidth?: string;\n}\n\n/** One parameter of a routine, and what its call passes for it. */\ninterface RoutineParameter {\n\tname: string;\n\ttype: string;\n\targument: string | Mapped;\n}\n\n/** A routine specialized for one key, and the run-time parts of what it captured that it is passed. */\ninterface Specialized {\n\tname: string;\n\tparts: ReadonlySet<string>;\n}\n\n/** How a routine is given the runtime values lifted into it. */\ninterface Passing {\n\t/** The parameter named from `base` that passes `text`; undefined when the routine reads `text` as it is. */\n\tparameter: (\n\t\ttext: string | Mapped,\n\t\tbase: string,\n\t\ttype: () => string,\n\t) => string | undefined;\n\t/** A caller's local the routine already has a parameter for. */\n\tlocal: (place: string | Mapped) => Value | undefined;\n}\n\n/** Passes each runtime value lifted into a routine as a parameter of its own, which the caller passes. */\nconst everyValue = (frame: Frame, parameters: RoutineParameter[]) =>\n\t({\n\t\tparameter: (text: string | Mapped, base: string, type: () => string) => {\n\t\t\tconst local = frame.emitter.local(base);\n\t\t\tparameters.push({ name: local, type: type(), argument: text });\n\t\t\treturn local;\n\t\t},\n\t\tlocal: () => undefined,\n\t}) satisfies Passing;\n\n/**\n * A routine parameter is typed as the value passed to it says: the IEC width it carries, else its\n * declared type as written.\n */\nconst parameterTyping: Typing = {\n\twidth: true,\n\twiden: false,\n\tuntyped: \"number\",\n};\n\nconst declarationKey = (declaration: ts.Node): string =>\n\t`${declaration.getSourceFile().fileName}:${declaration.pos}`;\n\nconst specializationKey = (\n\t{ name, value, width }: Specialization,\n\toptions: { stable: boolean },\n): string =>\n\t`${name}=${typeof value === \"string\" ? value : valueKey(value, options)}${!options.stable && width ? `:${width}` : \"\"}`;\n\n/**\n * What tells a value apart to the routine specialized for it. The stable key, which names the\n * routine, leaves out a callback's source position, so a name doesn't move with an edit above it.\n */\nconst valueKey = (value: Value, options: { stable: boolean }): string => {\n\tconst key = (inner: Value) => valueKey(inner, options);\n\tswitch (value.kind) {\n\t\tcase \"static\":\n\t\t\treturn `#${value.node.reference}`;\n\t\tcase \"const\":\n\t\t\treturn `=${String(value.value)}`;\n\t\tcase \"function\":\n\t\t\treturn options.stable\n\t\t\t\t? \"fn\"\n\t\t\t\t: `fn:${declarationKey(value.declaration)}:${value.self?.id ?? \"\"}`;\n\t\tcase \"virtual\":\n\t\t\treturn value.items\n\t\t\t\t? `[${value.items.map(key).join(\",\")}]`\n\t\t\t\t: `{${[...(value.fields ?? [])].map(([name, inner]) => `${name}:${key(inner)}`).join(\",\")}}`;\n\t\tcase \"code\":\n\t\t\treturn \"code\";\n\t\tcase \"choice\":\n\t\t\treturn `ref(${value.options.map((option) => option.reference).join(\",\")})${value.optional ? \"?\" : \"\"}`;\n\t\tcase \"masked\":\n\t\t\treturn `some[${value.entries.map((entry) => `${key(entry.item)}:${key(entry.present)}`).join(\",\")}]${value.order ? `by ${key(value.order)}` : \"\"}`;\n\t\tcase \"counted\":\n\t\t\treturn countedKey(value, key);\n\t}\n};\n\n/** What tells two counted arguments apart to the routine specialized for them. */\nconst countedKey = (\n\tcounted: Counted,\n\tkey: (value: Value) => string,\n): string => {\n\tconst { source } = counted;\n\tconst bounds = `${key(counted.start)}..${key(counted.end)}`;\n\treturn source.kind === \"items\"\n\t\t? `counted[${source.items.map(key).join(\",\")}]${bounds}`\n\t\t: `counted:${source.layout}:${key(source.element(\"0\"))}:${bounds}`;\n};\n\n/** An element as a routine reads it from the array it was passed: the same slot of its own parameter. */\nconst reread = (\n\tsample: Value,\n\tarray: string,\n\tindex: string | Mapped,\n): Value => {\n\tconst place = mapped`${array}[${index}]`;\n\tif (sample.kind === \"choice\") {\n\t\treturn { ...sample, index: place };\n\t}\n\treturn sample.kind === \"code\" ? { ...sample, text: place } : sample;\n};\n\n/** The symbols a function's body reads, which are all of its closure it needs. */\nconst readSymbols = (\n\tdeclaration: ts.Node,\n\tchecker: ts.TypeChecker,\n): ReadonlySet<ts.Symbol> => {\n\tconst read = new Set<ts.Symbol>();\n\tconst visit = (node: ts.Node): void => {\n\t\tif (ts.isIdentifier(node)) {\n\t\t\tconst symbol = valueSymbol(checker, node);\n\t\t\tif (symbol) {\n\t\t\t\tread.add(symbol);\n\t\t\t}\n\t\t}\n\t\tts.forEachChild(node, visit);\n\t};\n\tvisit(declaration);\n\treturn read;\n};\n",
41
+ "import ts from \"typescript\";\nimport { valueSymbol } from \"../sdk\";\nimport { SpecializeError, type Value } from \"./values\";\n\n/** Whether `node` names something the JavaScript runtime provides: its library declares it, and the program doesn't. */\nexport const providedByRuntime = (\n\tchecker: ts.TypeChecker,\n\tnode: ts.Node,\n): boolean => {\n\tconst declaration = checker.getSymbolAtLocation(node)?.valueDeclaration;\n\treturn (\n\t\tdeclaration !== undefined &&\n\t\t(declaration.getSourceFile().isDeclarationFile ||\n\t\t\t(ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Ambient) !==\n\t\t\t\t0)\n\t);\n};\n\n/** Whether `node` is the runtime's global `name`, such as `Math` or `structuredClone`, rather than one the program declares. */\nexport const isGlobal = (\n\tchecker: ts.TypeChecker,\n\tnode: ts.Expression,\n\tname: string,\n): boolean =>\n\tts.isIdentifier(node) &&\n\tnode.text === name &&\n\tprovidedByRuntime(checker, node);\n\n/** The symbol a declared name binds. */\nexport const symbolOf = (\n\tchecker: ts.TypeChecker,\n\tname: ts.Identifier,\n): ts.Symbol => {\n\tconst symbol = valueSymbol(checker, name);\n\tif (!symbol) {\n\t\tthrow new SpecializeError(name, `${name.text} is not declared.`);\n\t}\n\treturn symbol;\n};\n\n/** A value only the run decides is undefined or not. */\nexport type RunTimeOptional =\n\t| Extract<Value, { kind: \"choice\" }>\n\t| (Extract<Value, { kind: \"code\" }> & { declared: ts.Type });\n\n/**\n * `value` when only the run decides whether it is undefined: optional code, or a reference chosen\n * at run time that may be none where TypeScript has not narrowed it to defined.\n */\nexport const runTimeOptional = (\n\tchecker: ts.TypeChecker,\n\tvalue: Value,\n): RunTimeOptional | undefined => {\n\tif (value.kind === \"choice\") {\n\t\treturn value.optional && !value.narrowed ? value : undefined;\n\t}\n\tif (\n\t\tvalue.kind !== \"code\" ||\n\t\t!value.declared ||\n\t\t!(value.declared.flags & ts.TypeFlags.Union) ||\n\t\tchecker.getNonNullableType(value.declared) === value.declared\n\t) {\n\t\treturn undefined;\n\t}\n\treturn { ...value, declared: value.declared };\n};\n\n/**\n * The default a parameter takes for `arg`: its initializer when the argument is missing or passed\n * as undefined. A run-time argument that may be undefined is refused, since only the run would\n * decide whether the default applies.\n */\nexport const parameterDefault = (\n\tchecker: ts.TypeChecker,\n\targ: Value,\n\tparameter: ts.ParameterDeclaration,\n): ts.Expression | undefined => {\n\tif (!parameter.initializer) {\n\t\treturn undefined;\n\t}\n\tif (arg.kind === \"const\") {\n\t\treturn arg.value === undefined ? parameter.initializer : undefined;\n\t}\n\tif (runTimeOptional(checker, arg)) {\n\t\tthrow new SpecializeError(\n\t\t\tparameter,\n\t\t\t\"Pass a defined value or leave the argument out: the default applies to a missing argument.\",\n\t\t);\n\t}\n\treturn undefined;\n};\n\n/** The elements an array pattern names, each with the index it reads; a rest element is refused. */\nexport const namedElements = (\n\tpattern: ts.ArrayBindingPattern,\n\tdeclared: \"parameter\" | \"pattern\",\n): { element: ts.BindingElement; index: number }[] =>\n\tpattern.elements.flatMap((element, index) => {\n\t\tif (ts.isOmittedExpression(element)) {\n\t\t\treturn [];\n\t\t}\n\t\tif (element.dotDotDotToken) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\telement,\n\t\t\t\t`Name each element of an array ${declared}; a rest element has no length here.`,\n\t\t\t);\n\t\t}\n\t\treturn [{ element, index }];\n\t});\n\n/** The elements an object pattern names, each with the field it reads; a rest element is refused. */\nexport const namedFields = (\n\tpattern: ts.ObjectBindingPattern,\n\tdeclared: \"parameter\" | \"pattern\",\n): { element: ts.BindingElement; field: string }[] =>\n\tpattern.elements.map((element) => {\n\t\tif (element.dotDotDotToken) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\telement,\n\t\t\t\t`Name each field of an object ${declared}; a rest element has no record here.`,\n\t\t\t);\n\t\t}\n\t\treturn { element, field: (element.propertyName ?? element.name).getText() };\n\t});\n",
42
+ "import { canAssign, integerType, primitiveTypes } from \"@tsplc/compiler/ir\";\nimport { elementaryType, fitsNumber, isIntegerValued } from \"@tsplc/iec\";\nimport ts from \"typescript\";\nimport { joined, type Mapped, mapped } from \"../positions\";\nimport { sdkModules } from \"../sdk\";\nimport { defaultNumericTypes } from \"../types\";\nimport type { EntryImports } from \"./imports\";\nimport type { Initializers } from \"./initializers\";\nimport {\n\tdefinedOptional,\n\temptyOptional,\n\ttype Layouts,\n\toptionalHas,\n\toptionalValue,\n} from \"./layouts\";\nimport type { Model } from \"./model\";\nimport { holds, present, referenceIndex, referenceType } from \"./references\";\nimport type { Storage } from \"./storage\";\nimport { calendarConstructor } from \"./time-constructors\";\nimport type { Value } from \"./values\";\n\n/**\n * Specialized values as dialect text, in a place of a declared type: literals as enum members,\n * optionals as `{ has, value }`, records with every field, and numbers converted as IEC does.\n */\nexport class DialectText {\n\tconstructor(\n\t\tprivate readonly model: Model,\n\t\tprivate readonly checker: ts.TypeChecker,\n\t\tprivate readonly layouts: Layouts,\n\t\tprivate readonly storage: Storage,\n\t\tprivate readonly initializers: Initializers,\n\t\tprivate readonly imports: EntryImports,\n\t) {}\n\n\t/** Dialect text for a value, in a place of `expected` type when known. */\n\tcode(value: Value, expected: ts.Type | undefined): string | Mapped {\n\t\t// Where a reference is held, a value is the id of the object it is.\n\t\tconst index =\n\t\t\texpected && referenceType(expected) ? referenceIndex(value) : undefined;\n\t\tif (index !== undefined) {\n\t\t\treturn index;\n\t\t}\n\t\tswitch (value.kind) {\n\t\t\tcase \"code\":\n\t\t\t\tif (\n\t\t\t\t\texpected &&\n\t\t\t\t\tvalue.declared &&\n\t\t\t\t\tthis.layouts.isOptionalRecord(value.declared) &&\n\t\t\t\t\t!this.layouts.isOptionalRecord(expected)\n\t\t\t\t) {\n\t\t\t\t\treturn optionalValue(value.text);\n\t\t\t\t}\n\t\t\t\treturn value.text;\n\t\t\tcase \"const\": {\n\t\t\t\tconst literal = expected && this.layouts.literalEnum(expected);\n\t\t\t\tif (\n\t\t\t\t\tliteral &&\n\t\t\t\t\t(typeof value.value === \"string\" || value.value === undefined)\n\t\t\t\t) {\n\t\t\t\t\treturn this.layouts.member(literal, value.value);\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\texpected &&\n\t\t\t\t\tthis.layouts.isOptionalRecord(expected) &&\n\t\t\t\t\tvalue.value === undefined\n\t\t\t\t) {\n\t\t\t\t\treturn this.emptyOptional(expected);\n\t\t\t\t}\n\t\t\t\tif (expected && typeof value.value === \"number\") {\n\t\t\t\t\tconst member = this.layouts.enumMember(expected, value.value);\n\t\t\t\t\tif (member) {\n\t\t\t\t\t\treturn member;\n\t\t\t\t\t}\n\t\t\t\t\t// Setup's TIME is a number of milliseconds; the dialect spells a TIME constant as a duration.\n\t\t\t\t\tif (expected.aliasSymbol?.name === \"TIME\") {\n\t\t\t\t\t\tthis.imports.addSdk(sdkModules.types, \"ms\");\n\t\t\t\t\t\treturn `ms(${value.value})`;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (value.value === undefined) {\n\t\t\t\t\tthrow new Error(\"undefined has no PLC value here.\");\n\t\t\t\t}\n\t\t\t\tif (typeof value.value === \"string\") {\n\t\t\t\t\treturn this.stringText(value.value, expected);\n\t\t\t\t}\n\t\t\t\tif (typeof value.value === \"bigint\") {\n\t\t\t\t\treturn `${value.value}n`;\n\t\t\t\t}\n\t\t\t\treturn String(value.value);\n\t\t\t}\n\t\t\tcase \"static\": {\n\t\t\t\tconst node = value.node;\n\t\t\t\tif (this.storage.storedNode(node)) {\n\t\t\t\t\treturn this.storage.pathText(node);\n\t\t\t\t}\n\t\t\t\tif (node.type) {\n\t\t\t\t\treturn this.initializers.valueText(\n\t\t\t\t\t\t{ kind: \"node\", id: node.id },\n\t\t\t\t\t\texpected ?? node.type,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthrow new Error(\"This object has no PLC value.\");\n\t\t\t}\n\t\t\tcase \"virtual\": {\n\t\t\t\tif (value.fields) {\n\t\t\t\t\tconst type = expected && this.checker.getNonNullableType(expected);\n\t\t\t\t\tif (!type) {\n\t\t\t\t\t\tthrow new Error(\"A record literal needs a declared type.\");\n\t\t\t\t\t}\n\t\t\t\t\treturn this.recordLiteral(value.fields, type);\n\t\t\t\t}\n\t\t\t\tif (value.items) {\n\t\t\t\t\tconst element = expected && this.model.elementType(expected);\n\t\t\t\t\treturn mapped`[${joined(\n\t\t\t\t\t\tvalue.items.map((item) => this.code(item, element)),\n\t\t\t\t\t\t\", \",\n\t\t\t\t\t)}]`;\n\t\t\t\t}\n\t\t\t\tthrow new Error(\"Empty value.\");\n\t\t\t}\n\t\t\tcase \"function\":\n\t\t\t\tthrow new Error(\"A function has no PLC value; call it.\");\n\t\t\tcase \"counted\":\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"An array whose length is decided at run time has no PLC value: read it with for…of, its length, an index or an array method.\",\n\t\t\t\t);\n\t\t\tcase \"choice\":\n\t\t\t\treturn expected ? this.chosenCopy(value, expected) : value.index;\n\t\t\tcase \"masked\":\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"An array filtered or sorted at run time has no PLC value: read its length, or pick from it.\",\n\t\t\t\t);\n\t\t}\n\t}\n\n\t/** A record chosen at run time, where the PLC holds a record's value: a copy of whichever it is. */\n\tprivate chosenCopy(\n\t\tchoice: Value & { kind: \"choice\" },\n\t\texpected: ts.Type,\n\t): string | Mapped {\n\t\tconst copies = choice.options.map((option) => ({\n\t\t\ttest: holds(choice, option),\n\t\t\ttext: this.code({ kind: \"static\", node: option }, expected),\n\t\t}));\n\t\tconst last = copies.pop();\n\t\tif (!last) {\n\t\t\tthrow new Error(\"A reference to no object has no PLC value.\");\n\t\t}\n\t\treturn copies.reduceRight<string | Mapped>(\n\t\t\t(otherwise, copy) => mapped`(${copy.test} ? ${copy.text} : ${otherwise})`,\n\t\t\tlast.text,\n\t\t);\n\t}\n\n\t/** A record literal of `type`, every field written; a tagged union fills the other variants' fields. */\n\tprivate recordLiteral(fields: Map<string, Value>, type: ts.Type): Mapped {\n\t\tconst tagged = this.layouts.tagged(type);\n\t\tconst fieldTypes: [string, ts.Type][] = tagged\n\t\t\t? this.layouts\n\t\t\t\t\t.taggedFields(tagged)\n\t\t\t\t\t.map((name) => [\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tname === tagged.tag\n\t\t\t\t\t\t\t? this.layouts.tagType(type, tagged)\n\t\t\t\t\t\t\t: this.layouts.taggedFieldType(type, tagged, name),\n\t\t\t\t\t])\n\t\t\t: this.checker\n\t\t\t\t\t.getPropertiesOfType(type)\n\t\t\t\t\t.map((property) => [\n\t\t\t\t\t\tproperty.name,\n\t\t\t\t\t\tthis.checker.getTypeOfSymbol(property),\n\t\t\t\t\t]);\n\t\treturn mapped`{ ${joined(\n\t\t\tfieldTypes.map(([name, fieldType]) => {\n\t\t\t\tconst value = fields.get(name);\n\t\t\t\tif (!value) {\n\t\t\t\t\treturn `${name}: ${this.initializers.defaultOf(fieldType)}`;\n\t\t\t\t}\n\t\t\t\tconst property = tagged\n\t\t\t\t\t? this.layouts.taggedField(type, tagged, name)\n\t\t\t\t\t: this.checker.getPropertyOfType(type, name);\n\t\t\t\t// A record field holds exactly its type, so a narrower integer widens explicitly, as a result does.\n\t\t\t\treturn mapped`${name}: ${this.returnText(value, fieldType, this.layouts.iecName(property?.valueDeclaration))}`;\n\t\t\t}),\n\t\t\t\", \",\n\t\t)} }`;\n\t}\n\n\t/**\n\t * A routine's result: stored as an assignment is, and a narrower integer widened explicitly, as\n\t * Structured Text's typed functions return exactly their declared type.\n\t */\n\treturnText(\n\t\tvalue: Value,\n\t\tdeclared: ts.Type | undefined,\n\t\tiec: string | undefined,\n\t): string | Mapped {\n\t\tconst target = storedWidth(declared, iec);\n\t\tconst from = value.kind === \"code\" ? value.iec : undefined;\n\t\tif (\n\t\t\ttarget &&\n\t\t\tfrom &&\n\t\t\tfrom !== target &&\n\t\t\tintegerTypes.has(from) &&\n\t\t\tintegerTypes.has(target) &&\n\t\t\t!needsConversion(from, target)\n\t\t) {\n\t\t\tthis.imports.addSdk(sdkModules.types, \"exact\");\n\t\t\treturn mapped`exact<${target}>(${this.code(value, undefined)})`;\n\t\t}\n\t\treturn this.assignmentText(value, declared, iec);\n\t}\n\n\t/** Whether storing `value` into a place of `declared` type converts it, as IEC assignment narrows. */\n\tconverts(\n\t\tvalue: Value,\n\t\tdeclared: ts.Type | undefined,\n\t\tiec: string | undefined,\n\t): boolean {\n\t\tconst target = storedWidth(declared, iec);\n\t\treturn (\n\t\t\ttarget !== undefined &&\n\t\t\tvalue.kind === \"code\" &&\n\t\t\tneedsConversion(value.iec ?? defaultNumericTypes.number, target)\n\t\t);\n\t}\n\n\t/** The text stored into a place of `declared` type, wrapping an optional's value. */\n\tassignmentText(\n\t\tvalue: Value,\n\t\tdeclared: ts.Type | undefined,\n\t\tiec: string | undefined,\n\t): string | Mapped {\n\t\tconst index =\n\t\t\tdeclared && referenceType(declared) ? referenceIndex(value) : undefined;\n\t\tif (index !== undefined) {\n\t\t\treturn index;\n\t\t}\n\t\tconst target = storedWidth(declared, iec);\n\t\t// A whole float fits an integer as TypeScript's number holds it, unless it is out of range.\n\t\tconst family = target && elementaryType(target)?.family;\n\t\tif (\n\t\t\ttarget &&\n\t\t\t(family === \"integer\" || family === \"bits\") &&\n\t\t\tvalue.kind === \"code\" &&\n\t\t\tvalue.whole\n\t\t) {\n\t\t\tthis.imports.addSdk(sdkModules.types, \"saturate\");\n\t\t\treturn mapped`saturate<${target}>(${this.code(value, undefined)})`;\n\t\t}\n\t\tif (target && this.converts(value, declared, iec)) {\n\t\t\t// A TypeScript number holds any of these; in the PLC a value converts as an IEC assignment does.\n\t\t\tthis.imports.addSdk(sdkModules.types, \"wrap\");\n\t\t\treturn mapped`wrap<${target}>(${this.code(value, undefined)})`;\n\t\t}\n\t\tif (declared && this.layouts.isOptionalRecord(declared)) {\n\t\t\tif (value.kind === \"const\" && value.value === undefined) {\n\t\t\t\treturn this.emptyOptional(declared);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tvalue.kind === \"code\" &&\n\t\t\t\tvalue.declared &&\n\t\t\t\tthis.layouts.isOptionalRecord(value.declared)\n\t\t\t) {\n\t\t\t\treturn value.text;\n\t\t\t}\n\t\t\tconst defined = this.wrapDefined(\n\t\t\t\tthis.code(value, this.checker.getNonNullableType(declared)),\n\t\t\t\tdeclared,\n\t\t\t);\n\t\t\t// A record chosen at run time may be none, which the optional says.\n\t\t\treturn value.kind === \"choice\" && value.optional\n\t\t\t\t? mapped`(${present(value.index)} ? ${defined} : ${this.emptyOptional(declared)})`\n\t\t\t\t: defined;\n\t\t}\n\t\treturn this.code(value, declared);\n\t}\n\n\t/**\n\t * An optional of `declared` type holding nothing. A record literal takes the place's own optional\n\t * record, whose value may have the IEC width the place's declaration names.\n\t */\n\tprivate emptyOptional(declared: ts.Type): Mapped {\n\t\treturn emptyOptional(\n\t\t\tthis.initializers.defaultOf(this.checker.getNonNullableType(declared)),\n\t\t);\n\t}\n\n\twrapDefined(\n\t\ttext: string | Mapped,\n\t\tdeclared: ts.Type | undefined,\n\t): string | Mapped {\n\t\treturn declared && this.layouts.isOptionalRecord(declared)\n\t\t\t? definedOptional(text)\n\t\t\t: text;\n\t}\n\n\tisUndefinedText(\n\t\ttext: string | Mapped,\n\t\tdeclared: ts.Type | undefined,\n\t): Mapped {\n\t\tif (declared && this.layouts.isOptionalRecord(declared)) {\n\t\t\treturn mapped`!${optionalHas(text)}`;\n\t\t}\n\t\tconst literal = declared && this.layouts.literalEnum(declared);\n\t\tif (literal) {\n\t\t\treturn mapped`${text} === ${this.layouts.member(literal, undefined)}`;\n\t\t}\n\t\tthrow new Error(\"Only optional values can be undefined.\");\n\t}\n\n\t/** A boolean condition, including JavaScript truthiness of optionals and enums. */\n\tcondition(value: Value, at: ts.Node): string | Mapped {\n\t\tif (value.kind === \"choice\") {\n\t\t\treturn value.optional ? mapped`(${present(value.index)})` : \"true\";\n\t\t}\n\t\tif (value.kind === \"code\" && value.declared) {\n\t\t\tconst declared = value.declared;\n\t\t\tif (\n\t\t\t\tthis.layouts.isOptionalRecord(declared) &&\n\t\t\t\t!ts.isPrefixUnaryExpression(at)\n\t\t\t) {\n\t\t\t\tconst type = this.checker.getTypeAtLocation(at);\n\t\t\t\tif (!(type.flags & ts.TypeFlags.BooleanLike)) {\n\t\t\t\t\treturn optionalHas(value.text);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst literal = this.layouts.literalEnum(declared);\n\t\t\tif (literal?.optional) {\n\t\t\t\treturn mapped`${value.text} !== ${this.layouts.member(literal, undefined)}`;\n\t\t\t}\n\t\t}\n\t\treturn this.code(value, undefined);\n\t}\n\n\t/** A string setup gave, as a calendar constant where a calendar type is expected. */\n\tprivate stringText(text: string, expected: ts.Type | undefined): string {\n\t\tconst calendar = calendarConstructor(expected?.aliasSymbol?.name ?? \"\");\n\t\tif (!calendar) {\n\t\t\treturn JSON.stringify(text);\n\t\t}\n\t\tthis.imports.addSdk(sdkModules.types, calendar);\n\t\treturn `${calendar}(${JSON.stringify(text)})`;\n\t}\n\n\t/**\n\t * Both sides of a comparison as text. Integers of different signedness, which TypeScript\n\t * compares as numbers, both widen to LINT so the PLC compares them exactly.\n\t */\n\tcomparable(\n\t\tleft: Value,\n\t\tright: Value,\n\t\tdeclared: ts.Type | undefined,\n\t): [string | Mapped, string | Mapped] {\n\t\t// A constant compared with code takes the code's type, as a calendar constant needs.\n\t\tconst leftText = this.code(\n\t\t\tleft,\n\t\t\tright.kind === \"code\" ? (right.declared ?? declared) : declared,\n\t\t);\n\t\tconst rightText = this.code(\n\t\t\tright,\n\t\t\tleft.kind === \"code\" ? (left.declared ?? declared) : declared,\n\t\t);\n\t\tif (left.kind !== \"code\" || right.kind !== \"code\") {\n\t\t\treturn [\n\t\t\t\tbigintBeside(left, right, leftText),\n\t\t\t\tbigintBeside(right, left, rightText),\n\t\t\t];\n\t\t}\n\t\tconst from = left.iec ?? defaultNumericTypes.number;\n\t\tconst to = right.iec ?? defaultNumericTypes.number;\n\t\tif (!needsConversion(from, to) || !needsConversion(to, from)) {\n\t\t\treturn [leftText, rightText];\n\t\t}\n\t\tthis.imports.addSdk(sdkModules.types, \"wrap\");\n\t\treturn [mapped`wrap<LINT>(${leftText})`, mapped`wrap<LINT>(${rightText})`];\n\t}\n\n\t/**\n\t * Operands of integer arithmetic at one width, as TypeScript numbers are: the narrower widens to\n\t * the other, or both to LINT when neither holds the other. `iec` is the width of the result.\n\t */\n\tarithmetic(\n\t\tleft: Value,\n\t\tright: Value,\n\t): { texts: [string | Mapped, string | Mapped]; iec: string | undefined } {\n\t\tconst leftText = this.code(left, undefined);\n\t\tconst rightText = this.code(right, undefined);\n\t\t// A literal takes the other operand's width, so the result keeps it.\n\t\tif (left.kind !== \"code\" || right.kind !== \"code\") {\n\t\t\tconst operand = left.kind === \"code\" ? left : right;\n\t\t\treturn {\n\t\t\t\ttexts: [\n\t\t\t\t\tbigintBeside(left, right, leftText),\n\t\t\t\t\tbigintBeside(right, left, rightText),\n\t\t\t\t],\n\t\t\t\tiec: operand.kind === \"code\" ? operand.iec : undefined,\n\t\t\t};\n\t\t}\n\t\tconst from = left.iec ?? defaultNumericTypes.number;\n\t\tconst to = right.iec ?? defaultNumericTypes.number;\n\t\tif (from === to || !integerTypes.has(from) || !integerTypes.has(to)) {\n\t\t\treturn { texts: [leftText, rightText], iec: left.iec };\n\t\t}\n\t\tconst common = commonWidth(from, to);\n\t\tthis.imports.addSdk(sdkModules.types, \"exact\");\n\t\tconst widened = (text: string | Mapped, width: string) =>\n\t\t\twidth === common ? text : mapped`exact<${common}>(${text})`;\n\t\treturn {\n\t\t\ttexts: [widened(leftText, from), widened(rightText, to)],\n\t\t\tiec: common === defaultNumericTypes.number ? undefined : common,\n\t\t};\n\t}\n}\n\n/** Whether TypeScript holds an integer of this IEC width as a bigint: the 64-bit ones. */\nconst bigintWidth = (iec: string | undefined): boolean => {\n\tconst type = iec === undefined ? undefined : elementaryType(iec);\n\treturn isIntegerValued(type) && !fitsNumber(type);\n};\n\n/**\n * A whole number constant beside a 64-bit integer, which TypeScript holds as a bigint, written as one: a widened\n * difference compared with or offset by a literal would otherwise mix a bigint and a number.\n */\nconst bigintBeside = (\n\tvalue: Value,\n\tother: Value,\n\ttext: string | Mapped,\n): string | Mapped =>\n\tvalue.kind === \"const\" &&\n\ttypeof value.value === \"number\" &&\n\tNumber.isInteger(value.value) &&\n\tother.kind === \"code\" &&\n\tbigintWidth(other.iec)\n\t\t? `${value.value}n`\n\t\t: text;\n\n/** IEC integer and bit-string types by name. */\nconst integerTypes = new Map(\n\tprimitiveTypes.filter(integerType).map((type) => [type.id, type]),\n);\n\n/** The IEC width a value is stored at: the one its place declares, or a TypeScript number's. */\nconst storedWidth = (\n\tdeclared: ts.Type | undefined,\n\tiec: string | undefined,\n): string | undefined =>\n\tiec ??\n\t(declared && declared.flags & ts.TypeFlags.Number\n\t\t? defaultNumericTypes.number\n\t\t: undefined);\n\n/** The width two integer widths widen to: the wider, or LINT when neither holds the other. */\nconst commonWidth = (from: string, to: string): string => {\n\tif (!needsConversion(from, to)) {\n\t\treturn to;\n\t}\n\tif (!needsConversion(to, from)) {\n\t\treturn from;\n\t}\n\treturn \"LINT\";\n};\n\n/** Whether IEC needs an explicit conversion from one integer type to another; widening is implicit. */\nconst needsConversion = (from: string, to: string): boolean => {\n\tconst source = integerTypes.get(from);\n\tconst target = integerTypes.get(to);\n\treturn (\n\t\tsource !== undefined && target !== undefined && !canAssign(source, target)\n\t);\n};\n",
43
+ "import ts from \"typescript\";\nimport { type Mapped, mapped, type Part } from \"../positions\";\nimport { unparenthesized } from \"../types\";\nimport { storeStatement } from \"./assignments\";\nimport type { ExpressionSpecializer, SpecializeContext } from \"./expressions\";\nimport type { Frame } from \"./frame\";\nimport { isAbsent } from \"./layouts\";\nimport { type ModelNode, unionMembers } from \"./model\";\nimport { constant, SpecializeError, type Value } from \"./values\";\n\ntype Choice = Extract<Value, { kind: \"choice\" }>;\n\n/** An assignment written through a reference chosen at run time: the place it writes in each object the reference can be. */\ninterface PlaceInEach {\n\tkind: \"each\";\n\tchoice: Choice;\n\tplace: (option: ModelNode) => Value;\n}\n\n/** The PLC type of a reference: the id of the object it refers to, or `noReference` for undefined. */\nexport const referenceLayout = \"number\";\n\n/** What a reference holds when it is undefined. */\nexport const noReference = \"-1\";\n\n/** Code for whether a reference holds an object. */\nexport const present = (index: string | Mapped): Mapped =>\n\tmapped`${index} >= 0`;\n\n/** Code for whether a reference is undefined. */\nexport const absent = (index: string | Mapped): Mapped => mapped`${index} < 0`;\n\n/** Whether a type's values are class instances, or undefined: what scan code holds by reference rather than as a copy. */\nexport const referenceType = (type: ts.Type): boolean => {\n\tconst defined = unionMembers(type).filter((part) => !isAbsent(part));\n\treturn defined.length > 0 && defined.every(isInstanceType);\n};\n\n/** A class's instances, not the class itself, which its constructor's type shares a symbol with. */\nconst isInstanceType = (type: ts.Type): boolean =>\n\tBoolean(type.flags & ts.TypeFlags.Object) &&\n\ttype.getConstructSignatures().length === 0 &&\n\tclassesOf(type).length > 0;\n\nconst classesOf = (type: ts.Type): ts.ClassDeclaration[] =>\n\ttype.getSymbol()?.declarations?.filter(ts.isClassDeclaration) ?? [];\n\n/** Objects a reference can refer to: functions and services are called, never held. */\nexport const referable = (node: ModelNode): boolean =>\n\tnode.captured.kind === \"instance\" ||\n\tnode.captured.kind === \"object\" ||\n\tnode.captured.kind === \"array\";\n\n/**\n * Code for the id a reference holds when it refers to the value: every object setup built has one\n * id, so a reference means the same object wherever it is stored, passed or compared. Undefined\n * for a value that is no reference.\n */\nexport const referenceIndex = (value: Value): string | Mapped | undefined => {\n\tif (value.kind === \"choice\") {\n\t\treturn value.index;\n\t}\n\tif (value.kind === \"static\" && referable(value.node)) {\n\t\treturn String(value.node.reference);\n\t}\n\tif (value.kind === \"const\" && value.value === undefined) {\n\t\treturn noReference;\n\t}\n\treturn undefined;\n};\n\n/** The objects a reference to the value can be. */\nconst optionsOf = (value: Value): readonly ModelNode[] => {\n\tif (value.kind === \"choice\") {\n\t\treturn value.options;\n\t}\n\treturn value.kind === \"static\" ? [value.node] : [];\n};\n\n/** Whether a reference to the value can be undefined. */\nconst absentOf = (value: Value): boolean =>\n\tvalue.kind === \"choice\" ? value.optional : value.kind === \"const\";\n\n/**\n * The objects references among the values can be, and whether one can be undefined; undefined\n * when none of the values is an object setup built.\n */\nexport const references = (\n\tvalues: readonly Value[],\n): { options: readonly ModelNode[]; optional: boolean } | undefined => {\n\tconst options = values.flatMap(optionsOf);\n\tif (!options.length) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\t// In the order setup built them, so the code over them is the same every build.\n\t\toptions: [...new Set(options)].sort((left, right) => left.id - right.id),\n\t\toptional: values.some(absentOf),\n\t};\n};\n\n/** Objects without repeats, in the order of their reference ids, so the code over them is the same every build. */\nexport const union = (nodes: readonly ModelNode[]): ModelNode[] =>\n\t[...new Set(nodes)].sort((left, right) => left.reference - right.reference);\n\nconst maybeAbsent = (type: ts.Type): boolean =>\n\tunionMembers(type).some(isAbsent);\n\n/** A reference that can only be one object is that object, and one that can be none is undefined. */\nexport const settled = (choice: Choice): Value => {\n\tconst [only, ...others] = choice.options;\n\tif (!only) {\n\t\treturn constant(undefined);\n\t}\n\treturn others.length === 0 && !choice.optional && !choice.place\n\t\t? { kind: \"static\", node: only }\n\t\t: choice;\n};\n\n/**\n * References scan code chooses at run time. Setup built every object, so a reference is the id of\n * one of them: reading or calling through it runs the code of whichever object it holds, and a\n * filter decided at run time is its candidates with a flag each.\n */\nexport class References {\n\tprivate readonly instances = new Map<string, ModelNode[]>();\n\n\tconstructor(\n\t\tprivate readonly context: SpecializeContext,\n\t\tprivate readonly expressions: ExpressionSpecializer,\n\t) {}\n\n\tprivate get model() {\n\t\treturn this.context.model;\n\t}\n\n\tprivate get checker() {\n\t\treturn this.context.checker;\n\t}\n\n\t/** Every instance setup built of the classes a type names, or of their subclasses: what a reference of that type can hold. */\n\tcandidates(type: ts.Type): ModelNode[] {\n\t\tconst classes = unionMembers(type).flatMap(classesOf);\n\t\tconst key = classes\n\t\t\t.map((owner) => `${owner.getSourceFile().fileName}:${owner.pos}`)\n\t\t\t.join(\"|\");\n\t\tconst known = this.instances.get(key);\n\t\tif (known) {\n\t\t\treturn known;\n\t\t}\n\t\t// An instance nothing owns has no storage, so scan code can't reach it.\n\t\tconst found = this.model.nodes.filter(\n\t\t\t(node) =>\n\t\t\t\tnode.captured.kind === \"instance\" &&\n\t\t\t\tnode.owner !== undefined &&\n\t\t\t\tthis.model\n\t\t\t\t\t.ancestry(this.model.classOf(node))\n\t\t\t\t\t.some((owner) => classes.includes(owner)),\n\t\t);\n\t\tthis.instances.set(key, found);\n\t\treturn found;\n\t}\n\n\t/** A field read from an instance: one that stores a reference reads as the choice it holds. */\n\tfield(read: Value, holder: ModelNode, name: string): Value {\n\t\tif (\n\t\t\tread.kind !== \"code\" ||\n\t\t\t!this.context.storage.referenceField(holder, name)\n\t\t) {\n\t\t\treturn read;\n\t\t}\n\t\tconst declared = read.declared;\n\t\treturn {\n\t\t\tkind: \"choice\",\n\t\t\toptions: declared ? this.candidates(declared) : [],\n\t\t\tindex: read.text,\n\t\t\toptional: declared ? maybeAbsent(declared) : true,\n\t\t\tplace: true,\n\t\t};\n\t}\n\n\t/** A reference as a condition: whether it holds an object. */\n\tpresent(choice: Choice): Value {\n\t\treturn choice.optional\n\t\t\t? {\n\t\t\t\t\tkind: \"code\",\n\t\t\t\t\ttext: mapped`(${present(choice.index)})`,\n\t\t\t\t\tdeclared: this.checker.getBooleanType(),\n\t\t\t\t}\n\t\t\t: constant(true);\n\t}\n\n\t/** `===` with a reference on either side compares ids; undefined when neither side is one. */\n\tequality(\n\t\tleft: Value,\n\t\tright: Value,\n\t\t{ negate }: { negate: boolean },\n\t): Value | undefined {\n\t\tconst [choice, other] =\n\t\t\tleft.kind === \"choice\" ? [left, right] : [right, left];\n\t\tif (choice.kind !== \"choice\") {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst test = this.same(choice, other);\n\t\tif (test === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (typeof test === \"boolean\") {\n\t\t\treturn constant(negate ? !test : test);\n\t\t}\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: negate ? mapped`!${test}` : test,\n\t\t\tdeclared: this.checker.getBooleanType(),\n\t\t};\n\t}\n\n\tprivate same(choice: Choice, other: Value): boolean | Mapped | undefined {\n\t\tswitch (other.kind) {\n\t\t\tcase \"choice\":\n\t\t\t\treturn mapped`(${choice.index} === ${other.index})`;\n\t\t\tcase \"static\":\n\t\t\t\treturn choice.options.includes(other.node)\n\t\t\t\t\t? mapped`(${holds(choice, other.node)})`\n\t\t\t\t\t: false;\n\t\t\tcase \"const\":\n\t\t\t\treturn other.value === undefined && choice.optional\n\t\t\t\t\t? mapped`(${absent(choice.index)})`\n\t\t\t\t\t: false;\n\t\t\tcase \"code\":\n\t\t\t\treturn undefined;\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Rejects `===` between two records the PLC holds as copied values: no identity survives the\n\t * copy, and comparing their contents would answer a different question than TypeScript's.\n\t */\n\tidentities(left: Value, right: Value, at: ts.Node): void {\n\t\tif (this.copied(left) && this.copied(right)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t\"=== asks whether two records are the same object, which the PLC can't tell: it holds a record as a copied value. Compare a field that identifies them, such as a key or an id.\",\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate copied(value: Value): boolean {\n\t\tif (value.kind === \"virtual\") {\n\t\t\treturn true;\n\t\t}\n\t\treturn (\n\t\t\tvalue.kind === \"code\" &&\n\t\t\tvalue.declared !== undefined &&\n\t\t\tBoolean(\n\t\t\t\tthis.checker.getNonNullableType(value.declared).flags &\n\t\t\t\t\tts.TypeFlags.Object,\n\t\t\t)\n\t\t);\n\t}\n\n\t/** A reference whose storage a later write could change, held in a const as it is now. */\n\theld(choice: Choice, frame: Frame): Value {\n\t\tif (!choice.place) {\n\t\t\treturn choice;\n\t\t}\n\t\tconst local = frame.emitter.temporary();\n\t\tframe.emitter.line(\n\t\t\tmapped`const ${local}: ${referenceLayout} = ${choice.index};`,\n\t\t);\n\t\treturn {\n\t\t\tkind: \"choice\",\n\t\t\toptions: choice.options,\n\t\t\tindex: local,\n\t\t\toptional: choice.optional,\n\t\t};\n\t}\n\n\t/**\n\t * What a local holding a reference is bound to: a let stores the id, so it can be assigned any\n\t * object of its type, and a const keeps the choice it was given. Undefined for other locals.\n\t */\n\tlocal(\n\t\tname: string,\n\t\tvalue: Value,\n\t\tdeclared: ts.Type,\n\t\tframe: Frame,\n\t\t{ mutable }: { mutable: boolean },\n\t): Value | undefined {\n\t\t// An array filtered at run time has no storage a let could hold: the name means the array.\n\t\tif (value.kind === \"masked\") {\n\t\t\treturn value;\n\t\t}\n\t\tconst index = referenceIndex(value);\n\t\tif (!mutable) {\n\t\t\treturn value.kind === \"choice\" ? this.held(value, frame) : undefined;\n\t\t}\n\t\tconst typed = referenceType(declared);\n\t\tif (index === undefined || (value.kind !== \"choice\" && !typed)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst local = frame.emitter.local(name);\n\t\tframe.emitter.line(mapped`let ${local}: ${referenceLayout} = ${index};`);\n\t\treturn {\n\t\t\tkind: \"choice\",\n\t\t\toptions: typed\n\t\t\t\t? union([...this.candidates(declared), ...optionsOf(value)])\n\t\t\t\t: optionsOf(value),\n\t\t\tindex: local,\n\t\t\toptional: typed ? maybeAbsent(declared) : absentOf(value),\n\t\t\tplace: true,\n\t\t};\n\t}\n\n\t/** `target = value` and `target ??= value` on a reference field or let. */\n\tassign(target: Choice, node: ts.BinaryExpression, frame: Frame): Value {\n\t\tif (!target.place) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode.left,\n\t\t\t\t\"Assign a reference to a field or a let; this name keeps the object it was given.\",\n\t\t\t);\n\t\t}\n\t\tconst operator = node.operatorToken.kind;\n\t\tconst store = (): void => {\n\t\t\tconst value = this.expressions.expression(node.right, frame);\n\t\t\tconst index = referenceIndex(value);\n\t\t\tif (\n\t\t\t\tindex === undefined ||\n\t\t\t\toptionsOf(value).some((option) => !target.options.includes(option))\n\t\t\t) {\n\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\tnode.right,\n\t\t\t\t\t\"Assign an object setup built that this reference can hold, or undefined.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tframe.emitter.line(storeStatement(target.index, index));\n\t\t};\n\t\tif (operator === ts.SyntaxKind.EqualsToken) {\n\t\t\tstore();\n\t\t\treturn target;\n\t\t}\n\t\tif (operator === ts.SyntaxKind.QuestionQuestionEqualsToken) {\n\t\t\tframe.emitter.open(mapped`if (${absent(target.index)}) {`);\n\t\t\tstore();\n\t\t\tframe.emitter.close();\n\t\t\treturn target;\n\t\t}\n\t\tthrow new SpecializeError(\n\t\t\tnode,\n\t\t\t`${node.operatorToken.getText()} is not supported on a reference.`,\n\t\t);\n\t}\n\n\t/**\n\t * The place an assignment's target names. A field reached through a reference chosen at run time\n\t * is a different place in each object the reference can be, so the caller writes each.\n\t */\n\ttarget(node: ts.Expression, frame: Frame): Value | PlaceInEach {\n\t\tconst place = unparenthesized(node, { nonNull: true });\n\t\t// Only an object of a class is reached by reference; `this` is the instance being specialized.\n\t\tif (\n\t\t\t!ts.isPropertyAccessExpression(place) ||\n\t\t\tplace.expression.kind === ts.SyntaxKind.ThisKeyword ||\n\t\t\tplace.expression.kind === ts.SyntaxKind.SuperKeyword ||\n\t\t\t!referenceType(this.checker.getTypeAtLocation(place.expression))\n\t\t) {\n\t\t\treturn this.expressions.expression(node, frame);\n\t\t}\n\t\tconst object = this.expressions.expression(place.expression, frame);\n\t\tif (object.kind !== \"choice\") {\n\t\t\treturn this.expressions.property(object, place, frame);\n\t\t}\n\t\treturn {\n\t\t\tkind: \"each\",\n\t\t\tchoice: object,\n\t\t\tplace: (option) =>\n\t\t\t\tthis.expressions.property(\n\t\t\t\t\t{ kind: \"static\", node: option },\n\t\t\t\t\tplace,\n\t\t\t\t\tframe,\n\t\t\t\t),\n\t\t};\n\t}\n\n\t/** Runs `write` on the object a reference holds: a branch for each object it can be. */\n\teach(choice: Choice, frame: Frame, write: (option: ModelNode) => void): void {\n\t\tbranches(\n\t\t\tchoice,\n\t\t\tframe,\n\t\t\tchoice.options.map((option) => ({\n\t\t\t\toption,\n\t\t\t\tlines: frame.emitter.detached({ nested: true }, () => write(option))\n\t\t\t\t\t.lines,\n\t\t\t})),\n\t\t);\n\t}\n\n\t/** `object.name` through a reference: the member of whichever object it holds. */\n\tmember(choice: Choice, name: string, at: ts.Node, frame: Frame): Value {\n\t\tconst [sample] = choice.options;\n\t\treturn this.dispatch(\n\t\t\tchoice,\n\t\t\tframe,\n\t\t\tat,\n\t\t\tsample && this.memberType(sample, name),\n\t\t\t(option) =>\n\t\t\t\tthis.expressions.member(\n\t\t\t\t\t{ kind: \"static\", node: option },\n\t\t\t\t\tname,\n\t\t\t\t\tat,\n\t\t\t\t\tframe,\n\t\t\t\t),\n\t\t);\n\t}\n\n\t/** `array[index]` through a reference to one of several arrays. */\n\telement(choice: Choice, index: Value, at: ts.Node, frame: Frame): Value {\n\t\treturn this.dispatch(choice, frame, at, undefined, (option) =>\n\t\t\tthis.expressions.element(\n\t\t\t\t{ kind: \"static\", node: option },\n\t\t\t\tindex,\n\t\t\t\tat,\n\t\t\t\tframe,\n\t\t\t),\n\t\t);\n\t}\n\n\t/** The declared type of a member every object of a reference has, from one of them. */\n\tprivate memberType(option: ModelNode, name: string): ts.Type | undefined {\n\t\tif (option.captured.kind === \"instance\") {\n\t\t\tconst accessor = this.model.memberNamed(\n\t\t\t\tthis.model.classOf(option),\n\t\t\t\tname,\n\t\t\t\tts.isGetAccessorDeclaration,\n\t\t\t);\n\t\t\tconst signature =\n\t\t\t\taccessor && this.checker.getSignatureFromDeclaration(accessor);\n\t\t\tif (signature) {\n\t\t\t\treturn this.checker.getReturnTypeOfSignature(signature);\n\t\t\t}\n\t\t}\n\t\treturn option.captured.kind === \"array\"\n\t\t\t? undefined\n\t\t\t: this.model.capturedFieldType(option, name);\n\t}\n\n\t/**\n\t * A value read through a reference: each object's value is worked out in its own branch, so\n\t * only the chosen object's code runs. The result is a reference again when every object gives\n\t * one, and otherwise a local of the value's type.\n\t */\n\tprivate dispatch(\n\t\tchoice: Choice,\n\t\tframe: Frame,\n\t\tat: ts.Node,\n\t\ttype: ts.Type | undefined,\n\t\tread: (option: ModelNode) => Value,\n\t): Value {\n\t\tconst arms = choice.options.map((option) => {\n\t\t\tconst { result, lines } = frame.emitter.detached({ nested: true }, () =>\n\t\t\t\tread(option),\n\t\t\t);\n\t\t\treturn { option, value: result, lines };\n\t\t});\n\t\tconst [first] = arms;\n\t\tif (!first) {\n\t\t\treturn constant(undefined);\n\t\t}\n\t\tconst known = first.value;\n\t\tif (\n\t\t\tknown.kind === \"const\" &&\n\t\t\tarms.every(\n\t\t\t\t(arm) => arm.value.kind === \"const\" && arm.value.value === known.value,\n\t\t\t)\n\t\t) {\n\t\t\tbranches(choice, frame, arms);\n\t\t\treturn known;\n\t\t}\n\t\tconst result = frame.emitter.temporary();\n\t\tconst referred = arms.map((arm) => ({\n\t\t\t...arm,\n\t\t\tindex: referenceIndex(arm.value),\n\t\t}));\n\t\tif (\n\t\t\treferred.every(\n\t\t\t\t(arm): arm is (typeof referred)[number] & { index: string | Mapped } =>\n\t\t\t\t\tarm.index !== undefined,\n\t\t\t)\n\t\t) {\n\t\t\tframe.emitter.line(`let ${result}: ${referenceLayout} = ${noReference};`);\n\t\t\tframe.emitter.chain(\n\t\t\t\treferred.map((arm) => ({\n\t\t\t\t\ttest: holds(choice, arm.option),\n\t\t\t\t\tbody: () => {\n\t\t\t\t\t\tframe.emitter.append(arm.lines);\n\t\t\t\t\t\tframe.emitter.line(mapped`${result} = ${arm.index};`);\n\t\t\t\t\t},\n\t\t\t\t})),\n\t\t\t);\n\t\t\treturn settled({\n\t\t\t\tkind: \"choice\",\n\t\t\t\toptions: union(arms.flatMap((arm) => optionsOf(arm.value))),\n\t\t\t\tindex: result,\n\t\t\t\toptional: choice.optional || arms.some((arm) => absentOf(arm.value)),\n\t\t\t});\n\t\t}\n\t\tconst sample = arms\n\t\t\t.map((arm) => arm.value)\n\t\t\t.find((value) => value.kind === \"code\");\n\t\tconst declared =\n\t\t\ttype ??\n\t\t\t(sample?.kind === \"code\" ? sample.declared : undefined) ??\n\t\t\t(ts.isExpression(at) ? this.checker.getTypeAtLocation(at) : undefined);\n\t\tif (\n\t\t\t!declared ||\n\t\t\tarms.some(\n\t\t\t\t(arm) => arm.value.kind !== \"const\" && arm.value.kind !== \"code\",\n\t\t\t)\n\t\t) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t\"This can't be read through a reference chosen at run time: read a value, or call the method where it is named.\",\n\t\t\t);\n\t\t}\n\t\tconst iec = sample?.kind === \"code\" ? sample.iec : undefined;\n\t\tconst layout = sample?.kind === \"code\" ? sample.layout : undefined;\n\t\tconst text = iec ?? layout?.text ?? this.expressions.localType(declared);\n\t\tframe.emitter.line(\n\t\t\t`let ${result}: ${text} = ${iec || layout ? `defaultValue<${text}>()` : this.context.initializers.defaultOf(declared)};`,\n\t\t);\n\t\tframe.emitter.chain(\n\t\t\tarms.map((arm) => ({\n\t\t\t\ttest: holds(choice, arm.option),\n\t\t\t\tbody: () => {\n\t\t\t\t\tframe.emitter.append(arm.lines);\n\t\t\t\t\tframe.emitter.line(\n\t\t\t\t\t\tmapped`${result} = ${this.context.dialect.assignmentText(arm.value, declared, iec)};`,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t})),\n\t\t);\n\t\t// A copy of what the chosen object holds: writing it would change no object, so it is no place.\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: result,\n\t\t\tdeclared,\n\t\t\t...(iec && { iec }),\n\t\t\t...(layout && { layout }),\n\t\t\t...(sample?.kind === \"code\" &&\n\t\t\t\tsample.length !== undefined && { length: sample.length }),\n\t\t};\n\t}\n\n\t/** The reference a routine call returns, held in a const: the call runs once however often the reference is read. */\n\tresult(\n\t\tcall: Mapped,\n\t\treferents: { options: readonly ModelNode[]; optional: boolean } | undefined,\n\t\treturns: ts.Type,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst local = frame.emitter.temporary();\n\t\tframe.emitter.line(mapped`const ${local}: ${referenceLayout} = ${call};`);\n\t\t// A routine still being specialized, as one that calls itself, has not said what it returns.\n\t\treturn settled({\n\t\t\tkind: \"choice\",\n\t\t\toptions: referents ? union(referents.options) : this.candidates(returns),\n\t\t\tindex: local,\n\t\t\toptional: referents ? referents.optional : maybeAbsent(returns),\n\t\t});\n\t}\n\n\t/** Notes what a return statement returns, in a routine whose result is a reference. */\n\treturned(value: Value, at: ts.Node, frame: Frame): void {\n\t\tconst referents = frame.referents;\n\t\tif (!referents) {\n\t\t\treturn;\n\t\t}\n\t\tif (referenceIndex(value) === undefined) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t\"Return an object setup built, or undefined: the routine's result is a reference.\",\n\t\t\t);\n\t\t}\n\t\tfor (const option of optionsOf(value)) {\n\t\t\treferents.options.add(option);\n\t\t}\n\t\treferents.optional ||= absentOf(value);\n\t}\n\n\t/**\n\t * `condition ? yes : no` between references. Each side is worked out in its own branch, so a\n\t * call that chooses one runs only when its side is taken.\n\t */\n\tbranch(\n\t\tcondition: Part,\n\t\tsides: readonly [() => Value, () => Value],\n\t\tat: ts.Node,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst result = frame.emitter.temporary();\n\t\tframe.emitter.line(`let ${result}: ${referenceLayout} = ${noReference};`);\n\t\tconst store = (side: () => Value): Value => {\n\t\t\tconst value = side();\n\t\t\tframe.emitter.line(mapped`${result} = ${this.index(value, at)};`);\n\t\t\treturn value;\n\t\t};\n\t\tframe.emitter.open(mapped`if (${condition}) {`);\n\t\tconst yes = store(sides[0]);\n\t\tframe.emitter.reopen(\"} else {\");\n\t\tconst no = store(sides[1]);\n\t\tframe.emitter.close();\n\t\treturn settled({\n\t\t\tkind: \"choice\",\n\t\t\toptions: union([...optionsOf(yes), ...optionsOf(no)]),\n\t\t\tindex: result,\n\t\t\toptional: absentOf(yes) || absentOf(no),\n\t\t});\n\t}\n\n\t/** `reference ?? other` and `reference || other`: the other side is worked out only when the reference is undefined. */\n\tfallback(left: Choice, right: () => Value, at: ts.Node, frame: Frame): Value {\n\t\tif (!left.optional) {\n\t\t\treturn left;\n\t\t}\n\t\tconst result = frame.emitter.temporary();\n\t\tframe.emitter.line(\n\t\t\tmapped`let ${result}: ${referenceLayout} = ${left.index};`,\n\t\t);\n\t\tframe.emitter.open(mapped`if (${absent(result)}) {`);\n\t\tconst value = right();\n\t\tframe.emitter.line(mapped`${result} = ${this.index(value, at)};`);\n\t\tframe.emitter.close();\n\t\treturn settled({\n\t\t\tkind: \"choice\",\n\t\t\toptions: union([...left.options, ...optionsOf(value)]),\n\t\t\tindex: result,\n\t\t\toptional: absentOf(value),\n\t\t});\n\t}\n\n\tprivate index(value: Value, at: ts.Node): string | Mapped {\n\t\tconst index = referenceIndex(value);\n\t\tif (index === undefined) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t\"Only an object setup built, or undefined, can be chosen here.\",\n\t\t\t);\n\t\t}\n\t\treturn index;\n\t}\n\n\t/** A method call through a reference: the method of whichever object it holds, the arguments worked out once. */\n\tcall(\n\t\tchoice: Choice,\n\t\tname: string,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t\texpected: ts.Type | undefined,\n\t): Value {\n\t\tconst [sample] = choice.options;\n\t\tconst declaration =\n\t\t\tsample?.captured.kind === \"instance\"\n\t\t\t\t? this.model.memberNamed(\n\t\t\t\t\t\tthis.model.classOf(sample),\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tts.isMethodDeclaration,\n\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\tconst args = this.expressions.inOrder(\n\t\t\tnode.arguments,\n\t\t\t(argument, index) => {\n\t\t\t\tconst parameter = declaration?.parameters[index];\n\t\t\t\treturn this.expressions.expression(\n\t\t\t\t\targument,\n\t\t\t\t\tframe,\n\t\t\t\t\tparameter && this.checker.getTypeAtLocation(parameter),\n\t\t\t\t);\n\t\t\t},\n\t\t\tframe,\n\t\t);\n\t\treturn this.dispatch(choice, frame, node, undefined, (option) => {\n\t\t\tconst method = this.expressions.member(\n\t\t\t\t{ kind: \"static\", node: option },\n\t\t\t\tname,\n\t\t\t\tnode.expression,\n\t\t\t\tframe,\n\t\t\t);\n\t\t\tconst result = this.expressions.invoke(\n\t\t\t\tmethod,\n\t\t\t\targs,\n\t\t\t\tnode,\n\t\t\t\tframe,\n\t\t\t\texpected,\n\t\t\t);\n\t\t\t// A call for its effect alone is a statement of its branch.\n\t\t\tif (\n\t\t\t\tresult.kind === \"code\" &&\n\t\t\t\t(!result.declared || result.declared.flags & ts.TypeFlags.Void)\n\t\t\t) {\n\t\t\t\tframe.emitter.line(mapped`${result.text};`);\n\t\t\t\treturn constant(undefined);\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\t}\n}\n\n/** Code for whether a reference holds `option`. */\nexport const holds = (choice: Choice, option: ModelNode): Mapped =>\n\tmapped`${choice.index} === ${option.reference}`;\n\n/** A branch for each object a reference can be that wrote lines, which run when it holds that object. */\nconst branches = (\n\tchoice: Choice,\n\tframe: Frame,\n\tarms: readonly { option: ModelNode; lines: readonly Mapped[] }[],\n): void =>\n\tframe.emitter.chain(\n\t\tarms\n\t\t\t.filter((arm) => arm.lines.length > 0)\n\t\t\t.map((arm) => ({\n\t\t\t\ttest: holds(choice, arm.option),\n\t\t\t\tbody: () => frame.emitter.append(arm.lines),\n\t\t\t})),\n\t);\n",
44
+ "import ts from \"typescript\";\nimport { type Mapped, mapped, type Part } from \"../positions\";\nimport type { DialectText } from \"./dialect\";\nimport type { ExpressionSpecializer, SpecializeContext } from \"./expressions\";\nimport type { Frame } from \"./frame\";\nimport { constant, SpecializeError, type Value } from \"./values\";\nimport { isAssignment, isUpdate, occursOutsideFunctions } from \"./writes\";\n\n/** The operator each compound assignment applies. */\nconst compoundOperators = new Map<ts.SyntaxKind, string>([\n\t[ts.SyntaxKind.PlusEqualsToken, \"+\"],\n\t[ts.SyntaxKind.MinusEqualsToken, \"-\"],\n\t[ts.SyntaxKind.AsteriskEqualsToken, \"*\"],\n\t[ts.SyntaxKind.BarEqualsToken, \"|\"],\n\t[ts.SyntaxKind.AmpersandEqualsToken, \"&\"],\n]);\n\n/** Whether evaluating the expression writes a place: an assignment or `++`/`--` in it, outside functions it declares. */\nexport const containsWrite = (node: ts.Node): boolean =>\n\toccursOutsideFunctions(\n\t\tnode,\n\t\t(inner) =>\n\t\t\t(ts.isBinaryExpression(inner) &&\n\t\t\t\tisAssignment(inner.operatorToken.kind)) ||\n\t\t\tisUpdate(inner),\n\t);\n\n/** A statement storing `value` into `place`. */\nexport const storeStatement = (place: Part, value: Part): Mapped =>\n\tmapped`${place} = ${value};`;\n\n/**\n * Assignments and steps. Structured Text assigns only in statements, so one used as a value is a\n * statement first, and the expression reads the place afterwards.\n */\nexport class AssignmentSpecializer {\n\tconstructor(\n\t\tprivate readonly context: SpecializeContext,\n\t\tprivate readonly expressions: ExpressionSpecializer,\n\t) {}\n\n\tprivate get checker(): ts.TypeChecker {\n\t\treturn this.context.checker;\n\t}\n\n\tprivate get dialect(): DialectText {\n\t\treturn this.context.dialect;\n\t}\n\n\t/** Stores the assignment and returns what the target then holds. */\n\tassign(node: ts.BinaryExpression, frame: Frame): Value {\n\t\tif (\n\t\t\tts.isArrayLiteralExpression(node.left) ||\n\t\t\tts.isObjectLiteralExpression(node.left)\n\t\t) {\n\t\t\tconst value = this.expressions.expression(node.right, frame);\n\t\t\tthis.destructure(node.left, value, frame);\n\t\t\treturn value;\n\t\t}\n\t\tconst target = this.expressions.references.target(node.left, frame);\n\t\tif (target.kind === \"each\") {\n\t\t\tthis.expressions.references.each(target.choice, frame, (option) => {\n\t\t\t\tthis.assignTo(target.place(option), node, frame);\n\t\t\t});\n\t\t\treturn constant(undefined);\n\t\t}\n\t\treturn this.assignTo(target, node, frame);\n\t}\n\n\tprivate assignTo(\n\t\ttarget: Value,\n\t\tnode: ts.BinaryExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tif (target.kind === \"choice\") {\n\t\t\treturn this.expressions.references.assign(target, node, frame);\n\t\t}\n\t\tconst text = this.placeText(target, node.left);\n\t\tconst declared = target.kind === \"code\" ? target.declared : undefined;\n\t\tconst operator = node.operatorToken.kind;\n\t\tif (operator === ts.SyntaxKind.QuestionQuestionEqualsToken) {\n\t\t\tconst value = this.expressions.expression(\n\t\t\t\tnode.right,\n\t\t\t\tframe,\n\t\t\t\tdeclared && this.checker.getNonNullableType(declared),\n\t\t\t);\n\t\t\tframe.emitter.open(\n\t\t\t\tmapped`if (${this.dialect.isUndefinedText(text, declared)}) {`,\n\t\t\t);\n\t\t\tframe.emitter.line(\n\t\t\t\tthis.store(\n\t\t\t\t\ttarget,\n\t\t\t\t\tthis.dialect.wrapDefined(\n\t\t\t\t\t\tthis.dialect.code(\n\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\tdeclared && this.checker.getNonNullableType(declared),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tdeclared,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t);\n\t\t\tframe.emitter.close();\n\t\t\treturn target;\n\t\t}\n\t\tconst value = this.expressions.expression(node.right, frame, declared);\n\t\tif (operator === ts.SyntaxKind.EqualsToken) {\n\t\t\tframe.emitter.line(this.stored(target, value));\n\t\t\treturn target;\n\t\t}\n\t\tconst binary = compoundOperators.get(operator);\n\t\tif (!binary) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t`${node.operatorToken.getText()} is not supported.`,\n\t\t\t);\n\t\t}\n\t\tframe.emitter.line(\n\t\t\tthis.store(\n\t\t\t\ttarget,\n\t\t\t\tmapped`${text} ${binary} ${this.dialect.code(value, declared)}`,\n\t\t\t),\n\t\t);\n\t\treturn target;\n\t}\n\n\t/** Steps the place by one; `x++` is worth what the place held before, `++x` what it holds after. */\n\tstep(\n\t\tnode: ts.PrefixUnaryExpression | ts.PostfixUnaryExpression,\n\t\tframe: Frame,\n\t\t{ used }: { used: boolean },\n\t): Value {\n\t\tconst target = this.expressions.references.target(node.operand, frame);\n\t\tif (target.kind === \"each\") {\n\t\t\tthis.expressions.references.each(target.choice, frame, (option) => {\n\t\t\t\tthis.stepOn(target.place(option), node, frame, { used: false });\n\t\t\t});\n\t\t\treturn constant(undefined);\n\t\t}\n\t\treturn this.stepOn(target, node, frame, { used });\n\t}\n\n\tprivate stepOn(\n\t\ttarget: Value,\n\t\tnode: ts.PrefixUnaryExpression | ts.PostfixUnaryExpression,\n\t\tframe: Frame,\n\t\t{ used }: { used: boolean },\n\t): Value {\n\t\tconst text = this.placeText(target, node.operand);\n\t\tconst before =\n\t\t\tused && ts.isPostfixUnaryExpression(node)\n\t\t\t\t? this.expressions.held(target, frame)\n\t\t\t\t: target;\n\t\tframe.emitter.line(\n\t\t\tthis.store(\n\t\t\t\ttarget,\n\t\t\t\tmapped`${text} ${node.operator === ts.SyntaxKind.PlusPlusToken ? \"+\" : \"-\"} 1`,\n\t\t\t),\n\t\t);\n\t\treturn before;\n\t}\n\n\t/**\n\t * Assigns each target of a pattern its part of `value`. Every part is read before any target is\n\t * written, so `[a, b] = [b, a]` swaps.\n\t */\n\tprivate destructure(\n\t\tpattern: ts.ArrayLiteralExpression | ts.ObjectLiteralExpression,\n\t\tvalue: Value,\n\t\tframe: Frame,\n\t): void {\n\t\tconst writes: (() => void)[] = [];\n\t\tthis.collect(pattern, value, frame, writes);\n\t\tfor (const write of writes) {\n\t\t\twrite();\n\t\t}\n\t}\n\n\tprivate collect(\n\t\tpattern: ts.Expression,\n\t\tvalue: Value,\n\t\tframe: Frame,\n\t\twrites: (() => void)[],\n\t): void {\n\t\tif (ts.isArrayLiteralExpression(pattern)) {\n\t\t\tpattern.elements.forEach((element, index) => {\n\t\t\t\tif (ts.isOmittedExpression(element)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (ts.isSpreadElement(element)) {\n\t\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\t\telement,\n\t\t\t\t\t\t\"Assign the rest of an array element by element.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.collectTarget(\n\t\t\t\t\telement,\n\t\t\t\t\tthis.expressions.element(value, constant(index), element, frame),\n\t\t\t\t\tframe,\n\t\t\t\t\twrites,\n\t\t\t\t);\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tif (ts.isObjectLiteralExpression(pattern)) {\n\t\t\tfor (const property of pattern.properties) {\n\t\t\t\tif (ts.isShorthandPropertyAssignment(property)) {\n\t\t\t\t\tconst part = this.expressions.member(\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tproperty.name.text,\n\t\t\t\t\t\tproperty,\n\t\t\t\t\t\tframe,\n\t\t\t\t\t);\n\t\t\t\t\tthis.collectTarget(\n\t\t\t\t\t\tproperty.name,\n\t\t\t\t\t\tthis.expressions.defaulted(\n\t\t\t\t\t\t\tpart,\n\t\t\t\t\t\t\tproperty.objectAssignmentInitializer,\n\t\t\t\t\t\t\tframe,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tframe,\n\t\t\t\t\t\twrites,\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!ts.isPropertyAssignment(property)) {\n\t\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\t\tproperty,\n\t\t\t\t\t\t\"Assign each field of a pattern by name.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.collectTarget(\n\t\t\t\t\tproperty.initializer,\n\t\t\t\t\tthis.expressions.member(\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tproperty.name.getText(),\n\t\t\t\t\t\tproperty,\n\t\t\t\t\t\tframe,\n\t\t\t\t\t),\n\t\t\t\t\tframe,\n\t\t\t\t\twrites,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tthrow new SpecializeError(pattern, \"Not a pattern.\");\n\t}\n\n\t/** One target of a pattern, with the default it takes when its part is undefined. */\n\tprivate collectTarget(\n\t\ttarget: ts.Expression,\n\t\tpart: Value,\n\t\tframe: Frame,\n\t\twrites: (() => void)[],\n\t): void {\n\t\tif (\n\t\t\tts.isBinaryExpression(target) &&\n\t\t\ttarget.operatorToken.kind === ts.SyntaxKind.EqualsToken\n\t\t) {\n\t\t\tthis.collectTarget(\n\t\t\t\ttarget.left,\n\t\t\t\tthis.expressions.defaulted(part, target.right, frame),\n\t\t\t\tframe,\n\t\t\t\twrites,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\tts.isArrayLiteralExpression(target) ||\n\t\t\tts.isObjectLiteralExpression(target)\n\t\t) {\n\t\t\tthis.collect(target, part, frame, writes);\n\t\t\treturn;\n\t\t}\n\t\tconst read = this.expressions.held(part, frame);\n\t\twrites.push(() => {\n\t\t\tthis.storeValue(\n\t\t\t\tthis.expressions.expression(target, frame),\n\t\t\t\tread,\n\t\t\t\ttarget,\n\t\t\t\tframe,\n\t\t\t);\n\t\t});\n\t}\n\n\t/** Stores a value into a place, converting it as an IEC assignment does. */\n\tstoreValue(place: Value, value: Value, at: ts.Node, frame: Frame): void {\n\t\tthis.placeText(place, at);\n\t\tframe.emitter.line(this.stored(place, value));\n\t}\n\n\t/** A statement storing a value into a place, converted as an IEC assignment does. */\n\tprivate stored(place: Value, value: Value): Mapped {\n\t\treturn this.store(\n\t\t\tplace,\n\t\t\tthis.dialect.assignmentText(\n\t\t\t\tvalue,\n\t\t\t\tplace.kind === \"code\" ? place.declared : undefined,\n\t\t\t\tplace.kind === \"code\" ? place.iec : undefined,\n\t\t\t),\n\t\t);\n\t}\n\n\t/** A statement storing `text` into a place. */\n\tprivate store(target: Value, text: Part): Mapped {\n\t\tif (target.kind !== \"code\") {\n\t\t\tthrow new Error(\"Not a place.\");\n\t\t}\n\t\treturn storeStatement(target.text, text);\n\t}\n\n\tprivate placeText(value: Value, node: ts.Node): string | Mapped {\n\t\tif (value.kind === \"code\" && value.copyOf) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t`This changes a copy: ${value.copyOf} returns stored state, which TypeScript would change in place but the PLC copies. Change it where it is stored, as a collection's update does.`,\n\t\t\t);\n\t\t}\n\t\tif (value.kind === \"code\" && value.input) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t`${value.input.path} is bound to ${value.input.address}, and the hardware overwrites it every scan: keep what scan code computes in a field of its own.`,\n\t\t\t);\n\t\t}\n\t\tif (value.kind === \"code\" && value.place) {\n\t\t\treturn value.text;\n\t\t}\n\t\tif (\n\t\t\tvalue.kind === \"function\" ||\n\t\t\t(value.kind === \"static\" &&\n\t\t\t\t(value.node.captured.kind === \"closure\" ||\n\t\t\t\t\tvalue.node.captured.kind === \"function\"))\n\t\t) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"This assigns a function, and the PLC calls only functions known when the program compiles: keep one function, and choose what it does with an if.\",\n\t\t\t);\n\t\t}\n\t\tthrow new SpecializeError(\n\t\t\tnode,\n\t\t\t\"Assign to stored state: a field scan code owns, or a let.\",\n\t\t);\n\t}\n}\n",
45
+ "import type { PlcType } from \"@tsplc/compiler/ir\";\n\ntype CalendarDomain = Extract<PlcType, { kind: \"calendar\" }>[\"domain\"];\n\n/** The SDK's TIME constructors. */\nexport const durationNames: ReadonlySet<string> = new Set([\n\t\"ms\",\n\t\"seconds\",\n\t\"minutes\",\n]);\n\n/** The SDK's calendar constructors: the domain each makes, its IEC type and the text it takes. */\nexport const calendarFormats = new Map<\n\tstring,\n\t{ domain: CalendarDomain; type: string; format: string }\n>([\n\t[\"date\", { domain: \"date\", type: \"DATE\", format: \"YYYY-MM-DD\" }],\n\t[\n\t\t\"timeOfDay\",\n\t\t{ domain: \"timeOfDay\", type: \"TIME_OF_DAY\", format: \"hh:mm:ss[.mmm]\" },\n\t],\n\t[\n\t\t\"dateAndTime\",\n\t\t{\n\t\t\tdomain: \"dateTime\",\n\t\t\ttype: \"DATE_AND_TIME\",\n\t\t\tformat: \"YYYY-MM-DDThh:mm:ss\",\n\t\t},\n\t],\n]);\n\n/** The calendar constructor that makes a value of the IEC type `type`, as `date` makes a DATE. */\nexport const calendarConstructor = (type: string): string | undefined =>\n\t[...calendarFormats].find(([, format]) => format.type === type)?.[0];\n",
46
+ "import {\n\tconstantFits,\n\tidentityDigest,\n\tintegerType,\n\tliteralOutsideType,\n\toptionalRecord,\n\tprimitiveTypes,\n} from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport { from, joined, type Mapped, mapped, type Part } from \"../positions\";\nimport { sdkModules, unaliased, valueSymbol } from \"../sdk\";\nimport { defaultNumericTypes } from \"../types\";\nimport { AssignmentSpecializer, containsWrite } from \"./assignments\";\nimport { CallSpecializer, floatIec } from \"./calls\";\nimport {\n\tisGlobal,\n\tnamedElements,\n\tnamedFields,\n\tparameterDefault,\n\tsymbolOf,\n} from \"./declarations\";\nimport type { DialectText } from \"./dialect\";\nimport { FilteredArrays } from \"./filtered-arrays\";\nimport type { Emitter, Frame } from \"./frame\";\nimport type { EntryImports } from \"./imports\";\nimport type { Initializers } from \"./initializers\";\nimport { Iterators } from \"./iterators\";\nimport {\n\ttype ArrayLayout,\n\tarrayLayout,\n\tisAbsent,\n\ttype Layouts,\n\toptionalValue,\n\trecordTypes,\n} from \"./layouts\";\nimport type { Model, ModelNode } from \"./model\";\nimport { References, referenceType } from \"./references\";\nimport type { Storage } from \"./storage\";\nimport {\n\tcapturedPrimitive,\n\tconstant,\n\ttype Env,\n\ttype FunctionLike,\n\tfinite,\n\tholdsSetupObjects,\n\trepeatable,\n\trestoring,\n\tSpecializeError,\n\tunwrapped,\n\ttype Value,\n} from \"./values\";\nimport {\n\tisAssignment,\n\tisUpdate,\n\treplacedWhileAliased,\n\tstableAlias,\n\twritesThrough,\n} from \"./writes\";\n\n/** What every part of scan-code specialization shares. */\nexport interface SpecializeContext {\n\tmodel: Model;\n\tchecker: ts.TypeChecker;\n\tlayouts: Layouts;\n\tstorage: Storage;\n\tinitializers: Initializers;\n\timports: EntryImports;\n\tdialect: DialectText;\n\t/** The SDK's globals declaration; its other declarations sit beside it. */\n\tsdkFile: string;\n\t/** The program's runtime sources, where the functions setup stored are declared. */\n\tsources: readonly ts.SourceFile[];\n\t/** Whether the compiled program keeps `file` as written instead of compiling it from setup. */\n\tisKept: (file: string) => boolean;\n}\n\n/** A call to a specialized routine: its name, the runtime arguments it takes and its result type. */\nexport interface RoutineCall {\n\tname: string;\n\targs: (string | Mapped)[];\n\treturns: ts.Type | undefined;\n\t/** The IEC width the routine's declaration gives its result, as `(): UINT` does. */\n\tiec?: string;\n\t/** An array result's layout, at the length the routine returns. */\n\tlayout?: ArrayLayout;\n\tlength?: number;\n\t/** Whether the routine returns stored state, which its caller gets a copy of. */\n\treturnsStored?: boolean;\n\t/** For a result that is a reference: the objects it can be, and whether it can be undefined. */\n\treferents?: { options: readonly ModelNode[]; optional: boolean };\n}\n\n/** Specializes a called function for its receiver and known arguments. */\nexport interface RoutineTable {\n\troutine(\n\t\tdeclaration: FunctionLike,\n\t\tself: ModelNode | undefined,\n\t\targs: Value[],\n\t\tclosure?: Closure,\n\t): RoutineCall;\n\t/** Runs `run`, then forgets the routines it specialized. */\n\tspeculatively<T>(run: () => T): T;\n\t/** The routine that cancels the pending async calls of an instance's methods. */\n\tcanceller(self: ModelNode): string;\n}\n\n/** What a local function captured, and the routine calling it, whose locals those values can read. */\nexport interface Closure {\n\tenv: Env;\n\tcaller: Emitter;\n}\n\ntype Code = Extract<Value, { kind: \"code\" }>;\n\n/** How a runtime value's PLC type is read where it is held or passed on. */\nexport interface Typing {\n\t/** Whether an IEC width the value carries types it, and stays with what holds it. */\n\twidth: boolean;\n\t/** Whether a literal type widens to its base type, as a local's does. */\n\twiden: boolean;\n\t/** The type of a value with no declared type. */\n\tuntyped: \"number\" | \"boolean\";\n}\n\n/** How `hold` keeps a runtime value in a const. */\nexport interface Holding extends Typing {\n\t/** Whether a place or literal, which reads the same however often it is repeated, is held too. */\n\trepeatable: boolean;\n}\n\n/** Evaluates expressions against the setup graph, and writes what remains as dialect text. */\nexport class ExpressionSpecializer {\n\tprivate readonly calls: CallSpecializer;\n\treadonly assignments: AssignmentSpecializer;\n\treadonly references: References;\n\treadonly filteredArrays: FilteredArrays;\n\treadonly iterators: Iterators;\n\tprivate readonly services = new Map<string, ModelNode>();\n\tprivate readonly tables = new Map<number, string>();\n\treadonly tableDeclarations: Mapped[] = [];\n\n\tconstructor(\n\t\tprivate readonly context: SpecializeContext,\n\t\tprivate readonly routineTable: RoutineTable,\n\t) {\n\t\tthis.calls = new CallSpecializer(context, this);\n\t\tthis.assignments = new AssignmentSpecializer(context, this);\n\t\tthis.references = new References(context, this);\n\t\tthis.filteredArrays = new FilteredArrays(context, this);\n\t\tthis.iterators = new Iterators(context, this);\n\t}\n\n\texpression(node: ts.Expression, frame: Frame, expected?: ts.Type): Value {\n\t\tconst value = this.evaluate(node, frame, expected);\n\t\tif (value.kind !== \"code\") {\n\t\t\treturn value;\n\t\t}\n\t\t// A name maps to where it is read, not to where its value came from.\n\t\treturn {\n\t\t\t...value,\n\t\t\ttext: from(node, ts.isIdentifier(node) ? String(value.text) : value.text),\n\t\t};\n\t}\n\n\tprivate evaluate(\n\t\tnode: ts.Expression,\n\t\tframe: Frame,\n\t\texpected?: ts.Type,\n\t): Value {\n\t\t// `x!` reads an optional's value, as `x` reads where TypeScript narrowed undefined out.\n\t\tif (ts.isNonNullExpression(node)) {\n\t\t\treturn this.narrowed(\n\t\t\t\tthis.expression(node.expression, frame, expected),\n\t\t\t\tnode,\n\t\t\t);\n\t\t}\n\t\tconst inner = unwrapped(node);\n\t\tif (inner !== node) {\n\t\t\treturn this.expression(inner, frame, expected);\n\t\t}\n\t\tif (ts.isNumericLiteral(node)) {\n\t\t\treturn constant(Number(node.text));\n\t\t}\n\t\tif (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {\n\t\t\treturn constant(node.text);\n\t\t}\n\t\tif (node.kind === ts.SyntaxKind.TrueKeyword) {\n\t\t\treturn constant(true);\n\t\t}\n\t\tif (node.kind === ts.SyntaxKind.FalseKeyword) {\n\t\t\treturn constant(false);\n\t\t}\n\t\t// null is the PLC's one empty value, as undefined is.\n\t\tif (node.kind === ts.SyntaxKind.NullKeyword) {\n\t\t\treturn constant(undefined);\n\t\t}\n\t\tif (ts.isBigIntLiteral(node)) {\n\t\t\treturn constant(BigInt(node.text.slice(0, -1)));\n\t\t}\n\t\tif (node.kind === ts.SyntaxKind.ThisKeyword) {\n\t\t\tif (!frame.self) {\n\t\t\t\tthrow new SpecializeError(node, \"`this` outside a method.\");\n\t\t\t}\n\t\t\treturn { kind: \"static\", node: frame.self };\n\t\t}\n\t\tif (ts.isIdentifier(node)) {\n\t\t\treturn this.identifier(node, frame);\n\t\t}\n\t\tif (ts.isPropertyAccessExpression(node)) {\n\t\t\tconst member = this.context.checker.getSymbolAtLocation(\n\t\t\t\tnode.name,\n\t\t\t)?.valueDeclaration;\n\t\t\tif (member && ts.isEnumMember(member)) {\n\t\t\t\treturn constant(this.context.checker.getConstantValue(member));\n\t\t\t}\n\t\t\tif (node.expression.kind === ts.SyntaxKind.SuperKeyword) {\n\t\t\t\treturn this.superMember(node, frame);\n\t\t\t}\n\t\t\tconst mathConstant = mathConstants.get(node.name.text);\n\t\t\tif (\n\t\t\t\tmathConstant !== undefined &&\n\t\t\t\tisGlobal(this.context.checker, node.expression, \"Math\")\n\t\t\t) {\n\t\t\t\treturn constant(mathConstant);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tnode.name.text === \"length\" &&\n\t\t\t\tthis.filteredArrays.isFilter(node.expression)\n\t\t\t) {\n\t\t\t\treturn this.filteredArrays.count(node.expression, frame);\n\t\t\t}\n\t\t\treturn this.property(\n\t\t\t\tthis.expression(node.expression, frame),\n\t\t\t\tnode,\n\t\t\t\tframe,\n\t\t\t);\n\t\t}\n\t\tif (ts.isElementAccessExpression(node)) {\n\t\t\tconst object = this.expression(node.expression, frame);\n\t\t\tconst index = this.expression(node.argumentExpression, frame);\n\t\t\treturn this.element(object, index, node, frame);\n\t\t}\n\t\tif (ts.isCallExpression(node)) {\n\t\t\treturn this.calls.call(node, frame, expected);\n\t\t}\n\t\tif (ts.isAwaitExpression(node)) {\n\t\t\tconst value = this.expression(node.expression, frame);\n\t\t\t// A `.then` or `.catch` link awaited its promise itself, and gives the value.\n\t\t\tif (isPromiseLink(unwrapped(node.expression)) || value.kind !== \"code\") {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: mapped`await ${this.context.dialect.code(value, undefined)}`,\n\t\t\t\tdeclared: this.context.checker.getTypeAtLocation(node),\n\t\t\t\tiec: value.kind === \"code\" ? value.iec : undefined,\n\t\t\t\tawaited: true,\n\t\t\t};\n\t\t}\n\t\tif (isUpdate(node)) {\n\t\t\treturn this.assignments.step(node, frame, { used: true });\n\t\t}\n\t\tif (ts.isTypeOfExpression(node)) {\n\t\t\treturn this.typeOf(this.expression(node.expression, frame));\n\t\t}\n\t\tif (ts.isPrefixUnaryExpression(node)) {\n\t\t\treturn this.unary(node, frame);\n\t\t}\n\t\tif (ts.isBinaryExpression(node)) {\n\t\t\treturn this.binary(node, frame, expected);\n\t\t}\n\t\tif (ts.isConditionalExpression(node)) {\n\t\t\tconst condition = this.expression(node.condition, frame);\n\t\t\tif (condition.kind === \"const\") {\n\t\t\t\treturn this.expression(\n\t\t\t\t\tcondition.value ? node.whenTrue : node.whenFalse,\n\t\t\t\t\tframe,\n\t\t\t\t\texpected,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst own = this.context.checker.getTypeAtLocation(node);\n\t\t\tif (referenceType(own)) {\n\t\t\t\treturn this.references.branch(\n\t\t\t\t\tthis.context.dialect.condition(condition, node.condition),\n\t\t\t\t\t[\n\t\t\t\t\t\t() => this.expression(node.whenTrue, frame),\n\t\t\t\t\t\t() => this.expression(node.whenFalse, frame),\n\t\t\t\t\t],\n\t\t\t\t\tnode,\n\t\t\t\t\tframe,\n\t\t\t\t);\n\t\t\t}\n\t\t\t// A choice between defined values stored into an optional is wrapped where it is stored.\n\t\t\tconst declared =\n\t\t\t\texpected &&\n\t\t\t\t!(\n\t\t\t\t\tthis.context.layouts.isOptionalRecord(expected) &&\n\t\t\t\t\t!this.context.layouts.isOptionalRecord(own)\n\t\t\t\t)\n\t\t\t\t\t? expected\n\t\t\t\t\t: own;\n\t\t\tif (\n\t\t\t\tthis.isAggregate(declared) ||\n\t\t\t\tthis.runsWhenNeeded(node.whenTrue, frame) ||\n\t\t\t\tthis.runsWhenNeeded(node.whenFalse, frame)\n\t\t\t) {\n\t\t\t\treturn this.branched(\n\t\t\t\t\tdeclared,\n\t\t\t\t\tthis.context.dialect.condition(condition, node.condition),\n\t\t\t\t\t[node.whenTrue, node.whenFalse],\n\t\t\t\t\tframe,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst whenTrue = this.expression(node.whenTrue, frame, declared);\n\t\t\tconst whenFalse = this.expression(node.whenFalse, frame, declared);\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: mapped`(${this.context.dialect.condition(condition, node.condition)} ? ${this.context.dialect.assignmentText(whenTrue, declared, undefined)} : ${this.context.dialect.assignmentText(whenFalse, declared, undefined)})`,\n\t\t\t\tdeclared,\n\t\t\t\tcopyOf: [whenTrue, whenFalse].find(\n\t\t\t\t\t(branch): branch is Value & { kind: \"code\" } =>\n\t\t\t\t\t\tbranch.kind === \"code\" && branch.copyOf !== undefined,\n\t\t\t\t)?.copyOf,\n\t\t\t};\n\t\t}\n\t\tif (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {\n\t\t\treturn {\n\t\t\t\tkind: \"function\",\n\t\t\t\tdeclaration: node,\n\t\t\t\tself: frame.self,\n\t\t\t\tenv: frame.env,\n\t\t\t};\n\t\t}\n\t\tif (ts.isObjectLiteralExpression(node)) {\n\t\t\treturn this.objectLiteral(node, frame);\n\t\t}\n\t\tif (ts.isArrayLiteralExpression(node)) {\n\t\t\tconst items: Value[] = [];\n\t\t\tfor (const element of node.elements) {\n\t\t\t\tif (ts.isSpreadElement(element)) {\n\t\t\t\t\tconst spread = this.items(this.expression(element.expression, frame));\n\t\t\t\t\tif (!spread) {\n\t\t\t\t\t\tthrow new SpecializeError(element, \"Spread an array setup built.\");\n\t\t\t\t\t}\n\t\t\t\t\titems.push(...spread);\n\t\t\t\t} else {\n\t\t\t\t\titems.push(this.expression(element, frame));\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { kind: \"virtual\", items };\n\t\t}\n\t\tif (ts.isTemplateExpression(node)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"Template strings are not supported in scan code.\",\n\t\t\t);\n\t\t}\n\t\tthrow new SpecializeError(\n\t\t\tnode,\n\t\t\t`${ts.SyntaxKind[node.kind]} is not supported in scan code.`,\n\t\t);\n\t}\n\n\t/** `object.name` once the object is known: its member, through `?.` and what TypeScript narrowed. */\n\tproperty(\n\t\tobject: Value,\n\t\tnode: ts.PropertyAccessExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tif (\n\t\t\tnode.questionDotToken &&\n\t\t\tobject.kind === \"const\" &&\n\t\t\tobject.value === undefined\n\t\t) {\n\t\t\treturn constant(undefined);\n\t\t}\n\t\tif (\n\t\t\tnode.questionDotToken &&\n\t\t\tobject.kind === \"code\" &&\n\t\t\tobject.declared &&\n\t\t\tthis.context.layouts.isOptionalRecord(object.declared)\n\t\t) {\n\t\t\treturn this.optionalMember(object, object.declared, node, frame);\n\t\t}\n\t\tif (node.questionDotToken && object.kind === \"choice\" && object.optional) {\n\t\t\treturn this.chained(\n\t\t\t\tobject,\n\t\t\t\t() => this.member(object, node.name.text, node, frame),\n\t\t\t\tnode,\n\t\t\t\tframe,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\tnode.questionDotToken &&\n\t\t\tobject.kind === \"code\" &&\n\t\t\tobject.declared &&\n\t\t\tthis.context.checker.getNonNullableType(object.declared) !==\n\t\t\t\tobject.declared\n\t\t) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"?. reads only an optional record or object here: test this value with !== undefined first, and read it inside the if.\",\n\t\t\t);\n\t\t}\n\t\treturn this.narrowed(\n\t\t\tthis.member(object, node.name.text, node, frame),\n\t\t\tnode,\n\t\t);\n\t}\n\n\tprivate identifier(node: ts.Identifier, frame: Frame): Value {\n\t\tif (node.text === \"undefined\") {\n\t\t\treturn constant(undefined);\n\t\t}\n\t\tconst symbol = symbolOf(this.context.checker, node);\n\t\tconst local = frame.env.get(symbol);\n\t\tif (local) {\n\t\t\treturn this.narrowed(local, node);\n\t\t}\n\t\tconst target = unaliased(this.context.checker, symbol);\n\t\tconst own = frame.env.get(target);\n\t\tif (own) {\n\t\t\treturn own;\n\t\t}\n\t\tconst declaration = target.valueDeclaration ?? target.declarations?.[0];\n\t\tif (!declaration) {\n\t\t\tthrow new SpecializeError(node, `${node.text} has no declaration.`);\n\t\t}\n\t\tif (ts.isFunctionDeclaration(declaration)) {\n\t\t\treturn { kind: \"function\", declaration };\n\t\t}\n\t\tconst initializer =\n\t\t\tts.isVariableDeclaration(declaration) && declaration.initializer;\n\t\tif (\n\t\t\tinitializer &&\n\t\t\t(ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer))\n\t\t) {\n\t\t\treturn { kind: \"function\", declaration: initializer };\n\t\t}\n\t\t// A module constant named by a destructuring declaration is a root of its own too.\n\t\tconst root = this.context.model.roots.find(\n\t\t\t(item) => item.declaration === declaration,\n\t\t);\n\t\tif (root) {\n\t\t\tconst value = this.context.storage.rootValue(root);\n\t\t\tthis.refuseOutsideWidth(\n\t\t\t\tvalue,\n\t\t\t\tthis.context.layouts.iecName(root.declaration),\n\t\t\t\troot.declaration,\n\t\t\t);\n\t\t\treturn value;\n\t\t}\n\t\tif (\n\t\t\tinitializer &&\n\t\t\tts.isVariableStatement(declaration.parent.parent) &&\n\t\t\tdeclaration.parent.parent.parent &&\n\t\t\tts.isSourceFile(declaration.parent.parent.parent)\n\t\t) {\n\t\t\treturn this.expression(initializer, { ...frame, env: new Map() });\n\t\t}\n\t\tif (ts.isEnumMember(declaration)) {\n\t\t\treturn constant(this.context.checker.getConstantValue(declaration));\n\t\t}\n\t\tif (ts.isParameter(declaration)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t`${node.text} is a parameter of a scan function, which its task calls with no arguments: read the value from the program's state instead.`,\n\t\t\t);\n\t\t}\n\t\tthrow new SpecializeError(\n\t\t\tnode,\n\t\t\t`${node.text} is not available in scan code.`,\n\t\t);\n\t}\n\n\tmember(object: Value, name: string, at: ts.Node, frame: Frame): Value {\n\t\tif (object.kind === \"counted\") {\n\t\t\treturn this.iterators.member(object, name, at);\n\t\t}\n\t\tif (object.kind === \"choice\") {\n\t\t\treturn this.references.member(object, name, at, frame);\n\t\t}\n\t\tif (object.kind === \"masked\") {\n\t\t\treturn this.filteredArrays.member(object, name, at, frame);\n\t\t}\n\t\tif (object.kind === \"static\") {\n\t\t\tconst node = object.node;\n\t\t\tconst captured = node.captured;\n\t\t\tif (captured.kind === \"service\") {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"static\",\n\t\t\t\t\tnode: this.serviceNode(\n\t\t\t\t\t\tcaptured.path ? `${captured.path}.${name}` : name,\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (captured.kind === \"instance\") {\n\t\t\t\tconst members = this.context.model.members(\n\t\t\t\t\tthis.context.model.classOf(node),\n\t\t\t\t);\n\t\t\t\tconst accessor = getterNamed(members, name);\n\t\t\t\tif (accessor) {\n\t\t\t\t\t// A getter that only returns an expression reads it in place, as a field is read, so one\n\t\t\t\t\t// naming an object setup built is that object rather than a routine's copy of it.\n\t\t\t\t\tconst returned = onlyReturned(accessor);\n\t\t\t\t\tif (returned) {\n\t\t\t\t\t\treturn this.expression(returned, {\n\t\t\t\t\t\t\t...frame,\n\t\t\t\t\t\t\tenv: new Map(),\n\t\t\t\t\t\t\tself: node,\n\t\t\t\t\t\t\treturns: undefined,\n\t\t\t\t\t\t\tgenerator: undefined,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\treturn this.invoke(\n\t\t\t\t\t\t{ kind: \"function\", declaration: accessor, self: node },\n\t\t\t\t\t\t[],\n\t\t\t\t\t\tat,\n\t\t\t\t\t\tframe,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst method = methodNamed(members, name);\n\t\t\t\tif (method) {\n\t\t\t\t\treturn { kind: \"function\", declaration: method, self: node };\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (captured.kind === \"array\" && name === \"length\") {\n\t\t\t\treturn constant(captured.items.length);\n\t\t\t}\n\t\t\tif (captured.kind === \"object\" || captured.kind === \"instance\") {\n\t\t\t\tconst field = captured.fields[name];\n\t\t\t\tif (!field) {\n\t\t\t\t\tif (captured.kind === \"object\") {\n\t\t\t\t\t\treturn constant(undefined);\n\t\t\t\t\t}\n\t\t\t\t\tthrow new SpecializeError(at, `${name} is not set during setup.`);\n\t\t\t\t}\n\t\t\t\treturn this.references.field(\n\t\t\t\t\tthis.context.storage.fromCaptured(field, node, {\n\t\t\t\t\t\tkind: \"field\",\n\t\t\t\t\t\tname,\n\t\t\t\t\t}),\n\t\t\t\t\tnode,\n\t\t\t\t\tname,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new SpecializeError(at, `${name} cannot be read from this value.`);\n\t\t}\n\t\tif (object.kind === \"virtual\") {\n\t\t\tif (name === \"length\" && object.items) {\n\t\t\t\treturn constant(object.items.length);\n\t\t\t}\n\t\t\tif (object.fields) {\n\t\t\t\treturn object.fields.get(name) ?? constant(undefined);\n\t\t\t}\n\t\t\tthrow new SpecializeError(at, `${name} is not set.`);\n\t\t}\n\t\tif (object.kind === \"code\") {\n\t\t\tconst declared =\n\t\t\t\tobject.declared && this.fieldDeclared(object.declared, name, at);\n\t\t\tconst property =\n\t\t\t\tobject.declared &&\n\t\t\t\tthis.context.checker.getPropertyOfType(\n\t\t\t\t\tthis.context.checker.getNonNullableType(object.declared),\n\t\t\t\t\tname,\n\t\t\t\t);\n\t\t\tconst pinnedObject = object.pinned;\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: mapped`${object.text}.${name}`,\n\t\t\t\tdeclared,\n\t\t\t\tplace: object.place,\n\t\t\t\tcopyOf: object.copyOf,\n\t\t\t\t...(pinnedObject && {\n\t\t\t\t\tpinned: (pinFrame: Frame) =>\n\t\t\t\t\t\tthis.member(pinnedObject(pinFrame), name, at, pinFrame),\n\t\t\t\t}),\n\t\t\t\tiec: this.context.layouts.iecName(property?.valueDeclaration),\n\t\t\t\telementIec: this.context.layouts.elementIec(property?.valueDeclaration),\n\t\t\t\tlayout:\n\t\t\t\t\tproperty && declared && this.context.checker.isArrayType(declared)\n\t\t\t\t\t\t? this.context.layouts.fieldArray(property)\n\t\t\t\t\t\t: undefined,\n\t\t\t};\n\t\t}\n\t\tif (object.kind === \"const\" && object.value === undefined) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t`Reading ${name} of undefined: this is undefined wherever the program runs, as setup leaves it and scan code never assigns it.`,\n\t\t\t);\n\t\t}\n\t\tthrow new SpecializeError(at, `${name} cannot be read from this value.`);\n\t}\n\n\t/** An optional's value, or a reference known defined, where TypeScript has narrowed out undefined, as `x` reads after `x !== undefined`. */\n\tprivate narrowed(value: Value, at: ts.Node): Value {\n\t\tif (value.kind === \"choice\") {\n\t\t\treturn value.optional && this.narrowedOut(at)\n\t\t\t\t? { ...value, narrowed: true }\n\t\t\t\t: value;\n\t\t}\n\t\tif (\n\t\t\tvalue.kind !== \"code\" ||\n\t\t\t!value.declared ||\n\t\t\t!this.context.layouts.isOptionalRecord(value.declared) ||\n\t\t\t!this.narrowedOut(at)\n\t\t) {\n\t\t\treturn value;\n\t\t}\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: optionalValue(value.text),\n\t\t\tdeclared: this.context.checker.getNonNullableType(value.declared),\n\t\t\tplace: value.place,\n\t\t\tcopyOf: value.copyOf,\n\t\t};\n\t}\n\n\t/** Whether TypeScript has narrowed undefined out of what `at` reads. */\n\tprivate narrowedOut(at: ts.Node): boolean {\n\t\tconst type = this.context.checker.getTypeAtLocation(at);\n\t\treturn !isAbsent(type) && !(type.isUnion() && type.types.some(isAbsent));\n\t}\n\n\t/** The declared type of a field of a runtime record, through optionals and tagged unions. */\n\tprivate fieldDeclared(\n\t\ttype: ts.Type,\n\t\tname: string,\n\t\tat: ts.Node,\n\t): ts.Type | undefined {\n\t\tconst defined = this.context.checker.getNonNullableType(type);\n\t\tconst tagged = this.context.layouts.tagged(defined);\n\t\tif (tagged) {\n\t\t\treturn name === tagged.tag\n\t\t\t\t? this.context.layouts.tagType(defined, tagged)\n\t\t\t\t: this.context.layouts.taggedFieldType(defined, tagged, name);\n\t\t}\n\t\tconst property = this.context.checker.getPropertyOfType(defined, name);\n\t\tif (!property) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t`${name} is not a field of ${this.context.checker.typeToString(type)}.`,\n\t\t\t);\n\t\t}\n\t\treturn this.context.checker.getTypeOfSymbol(property);\n\t}\n\n\tprivate serviceNode(path: string): ModelNode {\n\t\tconst known = this.services.get(path);\n\t\tif (known) {\n\t\t\treturn known;\n\t\t}\n\t\tconst id = -1 - this.services.size;\n\t\t// A service is called, never held, so no reference holds its id.\n\t\tconst node: ModelNode = {\n\t\t\tid,\n\t\t\treference: id,\n\t\t\tcaptured: { kind: \"service\", path },\n\t\t};\n\t\tthis.services.set(path, node);\n\t\treturn node;\n\t}\n\n\telement(object: Value, index: Value, at: ts.Node, frame: Frame): Value {\n\t\tif (object.kind === \"counted\") {\n\t\t\treturn this.iterators.element(object, index, at, frame);\n\t\t}\n\t\tif (object.kind === \"choice\") {\n\t\t\treturn this.references.element(object, index, at, frame);\n\t\t}\n\t\tif (object.kind === \"masked\") {\n\t\t\treturn this.filteredArrays.element(object, index, at, frame);\n\t\t}\n\t\tif (index.kind === \"const\" && typeof index.value === \"number\") {\n\t\t\tif (object.kind === \"virtual\" && object.items) {\n\t\t\t\tconst item = object.items[index.value];\n\t\t\t\tif (!item) {\n\t\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\t\tat,\n\t\t\t\t\t\t`Index ${index.value} is past the end.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn item;\n\t\t\t}\n\t\t\tif (object.kind === \"static\" && object.node.captured.kind === \"array\") {\n\t\t\t\tconst item = object.node.captured.items[index.value];\n\t\t\t\tif (!item) {\n\t\t\t\t\treturn constant(undefined);\n\t\t\t\t}\n\t\t\t\treturn this.context.storage.fromCaptured(item, object.node, {\n\t\t\t\t\tkind: \"index\",\n\t\t\t\t\tindex: index.value,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (object.kind === \"static\" && object.node.captured.kind === \"object\") {\n\t\t\t\tconst field = object.node.captured.fields[String(index.value)];\n\t\t\t\tif (!field) {\n\t\t\t\t\treturn constant(undefined);\n\t\t\t\t}\n\t\t\t\treturn this.context.storage.fromCaptured(field, object.node, {\n\t\t\t\t\tkind: \"field\",\n\t\t\t\t\tname: String(index.value),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tif (object.kind === \"static\") {\n\t\t\tconst node = object.node;\n\t\t\tconst declared =\n\t\t\t\tnode.type &&\n\t\t\t\t(node.captured.kind === \"array\"\n\t\t\t\t\t? this.context.model.elementType(node.type)\n\t\t\t\t\t: recordTypes(node.type)?.value);\n\t\t\tconst text = this.context.storage.storedNode(node)\n\t\t\t\t? this.context.storage.pathText(node)\n\t\t\t\t: this.table(node, at);\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: mapped`${text}[${this.context.dialect.code(index, node.type && recordTypes(node.type)?.key)}]`,\n\t\t\t\tdeclared,\n\t\t\t\tplace: true,\n\t\t\t\t...(index.kind === \"code\" && {\n\t\t\t\t\tpinned: (pinFrame: Frame) =>\n\t\t\t\t\t\tthis.element(object, this.held(index, pinFrame), at, pinFrame),\n\t\t\t\t}),\n\t\t\t};\n\t\t}\n\t\tif (object.kind === \"code\") {\n\t\t\tconst declared =\n\t\t\t\tobject.declared &&\n\t\t\t\t(this.context.model.elementType(object.declared) ??\n\t\t\t\t\trecordTypes(object.declared)?.value);\n\t\t\t// A key setup fixed reads as a number; an enum-keyed record takes its enum's member.\n\t\t\tconst key = object.declared && recordTypes(object.declared)?.key;\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: mapped`${object.text}[${this.context.dialect.code(index, key)}]`,\n\t\t\t\tdeclared,\n\t\t\t\tplace: object.place,\n\t\t\t\tiec: object.elementIec,\n\t\t\t\tcopyOf: object.copyOf,\n\t\t\t\t...((index.kind === \"code\" || object.pinned) && {\n\t\t\t\t\tpinned: (pinFrame: Frame) =>\n\t\t\t\t\t\tthis.element(\n\t\t\t\t\t\t\tobject.pinned ? object.pinned(pinFrame) : object,\n\t\t\t\t\t\t\tthis.held(index, pinFrame),\n\t\t\t\t\t\t\tat,\n\t\t\t\t\t\t\tpinFrame,\n\t\t\t\t\t\t),\n\t\t\t\t}),\n\t\t\t};\n\t\t}\n\t\tif (object.kind === \"virtual\" && object.items) {\n\t\t\tconst chosen = this.filteredArrays.indexed(\n\t\t\t\tobject.items,\n\t\t\t\tindex,\n\t\t\t\t{ fromEnd: false },\n\t\t\t\tat,\n\t\t\t\tframe,\n\t\t\t);\n\t\t\tif (chosen) {\n\t\t\t\treturn chosen;\n\t\t\t}\n\t\t\tconst text = this.materialize(object.items, at, frame);\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: mapped`${text}[${this.context.dialect.code(index, undefined)}]`,\n\t\t\t\tdeclared: this.context.checker.getTypeAtLocation(at),\n\t\t\t};\n\t\t}\n\t\tthrow new SpecializeError(at, \"This value cannot be indexed.\");\n\t}\n\n\t/** A fixed table setup built, emitted once, where scan code first indexes it at runtime. */\n\tprivate table(node: ModelNode, at: ts.Node): string {\n\t\tconst known = this.tables.get(node.id);\n\t\tif (known) {\n\t\t\treturn known;\n\t\t}\n\t\tif (!node.type) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t\"This array has no declared type to index it by at run time.\",\n\t\t\t);\n\t\t}\n\t\t// Named for where setup put it: numbered by first read, two tables swapped names under one type.\n\t\tconst identity = this.context.model.identity(node);\n\t\tconst name = identity\n\t\t\t? `tsplcTable_${identityDigest(identity)}`\n\t\t\t: `tsplcTable${this.tables.size + 1}`;\n\t\tthis.tables.set(node.id, name);\n\t\tconst type = this.context.layouts.text(node.type, {\n\t\t\tkind: \"node\",\n\t\t\tid: node.id,\n\t\t});\n\t\tthis.tableDeclarations.push(\n\t\t\tfrom(\n\t\t\t\tat,\n\t\t\t\t`const ${name}: ${type} = ${this.context.initializers.valueText({ kind: \"node\", id: node.id }, node.type, type)};`,\n\t\t\t),\n\t\t);\n\t\treturn name;\n\t}\n\n\t/** Stores a scan-built array in a local, for indexing at runtime. */\n\tprivate materialize(\n\t\titems: readonly Value[],\n\t\tat: ts.Node,\n\t\tframe: Frame,\n\t): string {\n\t\tconst type = this.context.checker.getTypeAtLocation(at);\n\t\tconst element = this.context.model.elementType(type);\n\t\tif (!element) {\n\t\t\tthrow new SpecializeError(at, \"Not an array.\");\n\t\t}\n\t\tconst local = frame.emitter.temporary();\n\t\tframe.emitter.line(\n\t\t\tmapped`const ${local}: ${arrayLayout(this.context.layouts.text(element), items.length).text} = [${joined(\n\t\t\t\titems.map((item) => this.context.dialect.code(item, element)),\n\t\t\t\t\", \",\n\t\t\t)}];`,\n\t\t);\n\t\treturn local;\n\t}\n\n\tprivate objectLiteral(node: ts.ObjectLiteralExpression, frame: Frame): Value {\n\t\tconst fields = new Map<string, Value>();\n\t\tfor (const property of node.properties) {\n\t\t\tif (ts.isPropertyAssignment(property)) {\n\t\t\t\tfields.set(\n\t\t\t\t\tproperty.name.getText(),\n\t\t\t\t\tthis.expression(\n\t\t\t\t\t\tproperty.initializer,\n\t\t\t\t\t\tframe,\n\t\t\t\t\t\tthis.context.checker.getContextualType(property.initializer),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else if (ts.isShorthandPropertyAssignment(property)) {\n\t\t\t\tfields.set(property.name.text, this.shorthand(property, frame));\n\t\t\t} else if (ts.isSpreadAssignment(property)) {\n\t\t\t\tfor (const [name, value] of this.recordFields(\n\t\t\t\t\tproperty.expression,\n\t\t\t\t\tframe,\n\t\t\t\t)) {\n\t\t\t\t\tfields.set(name, value);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new SpecializeError(property, \"Write each field of a record.\");\n\t\t\t}\n\t\t}\n\t\treturn { kind: \"virtual\", fields };\n\t}\n\n\t/** What `{ name }` gives its field: the local the name reads, not the property it declares. */\n\tshorthand(property: ts.ShorthandPropertyAssignment, frame: Frame): Value {\n\t\tconst symbol = valueSymbol(this.context.checker, property.name);\n\t\tconst local = symbol && frame.env.get(symbol);\n\t\treturn local ?? this.expression(property.name, frame);\n\t}\n\n\tprivate unary(node: ts.PrefixUnaryExpression, frame: Frame): Value {\n\t\tconst operand = this.expression(node.operand, frame);\n\t\tswitch (node.operator) {\n\t\t\tcase ts.SyntaxKind.ExclamationToken:\n\t\t\t\tif (operand.kind === \"const\") {\n\t\t\t\t\treturn constant(!operand.value);\n\t\t\t\t}\n\t\t\t\tif (operand.kind === \"static\" || operand.kind === \"function\") {\n\t\t\t\t\treturn constant(false);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"code\",\n\t\t\t\t\ttext: mapped`!${this.context.dialect.condition(operand, node.operand)}`,\n\t\t\t\t\tdeclared: this.context.checker.getBooleanType(),\n\t\t\t\t};\n\t\t\tcase ts.SyntaxKind.MinusToken:\n\t\t\t\tif (operand.kind === \"const\" && typeof operand.value === \"number\") {\n\t\t\t\t\treturn constant(-operand.value);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"code\",\n\t\t\t\t\ttext: mapped`-${this.context.dialect.code(operand, undefined)}`,\n\t\t\t\t\tdeclared: this.context.checker.getTypeAtLocation(node),\n\t\t\t\t};\n\t\t\tcase ts.SyntaxKind.PlusToken:\n\t\t\t\treturn operand;\n\t\t\tdefault:\n\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\tnode,\n\t\t\t\t\t`${ts.tokenToString(node.operator)} is not supported.`,\n\t\t\t\t);\n\t\t}\n\t}\n\n\tprivate binary(\n\t\tnode: ts.BinaryExpression,\n\t\tframe: Frame,\n\t\texpected?: ts.Type,\n\t): Value {\n\t\tconst kind = node.operatorToken.kind;\n\t\tif (\n\t\t\tkind === ts.SyntaxKind.AmpersandAmpersandToken ||\n\t\t\tkind === ts.SyntaxKind.BarBarToken\n\t\t) {\n\t\t\tconst left = this.expression(node.left, frame);\n\t\t\tconst and = kind === ts.SyntaxKind.AmpersandAmpersandToken;\n\t\t\tif (left.kind === \"const\") {\n\t\t\t\tif (Boolean(left.value) !== and) {\n\t\t\t\t\treturn left;\n\t\t\t\t}\n\t\t\t\treturn this.expression(node.right, frame, expected);\n\t\t\t}\n\t\t\tif (left.kind === \"static\" || left.kind === \"function\") {\n\t\t\t\treturn and ? this.expression(node.right, frame, expected) : left;\n\t\t\t}\n\t\t\tif (left.kind === \"choice\" && !and) {\n\t\t\t\treturn this.references.fallback(\n\t\t\t\t\tleft,\n\t\t\t\t\t() => this.expression(node.right, frame, expected),\n\t\t\t\t\tnode,\n\t\t\t\t\tframe,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tleft.kind === \"choice\" &&\n\t\t\t\treferenceType(this.context.checker.getTypeAtLocation(node))\n\t\t\t) {\n\t\t\t\treturn this.references.branch(\n\t\t\t\t\tthis.context.dialect.condition(left, node.left),\n\t\t\t\t\t[\n\t\t\t\t\t\t() => this.expression(node.right, frame, expected),\n\t\t\t\t\t\t() => constant(undefined),\n\t\t\t\t\t],\n\t\t\t\t\tnode,\n\t\t\t\t\tframe,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (\n\t\t\t\t!and &&\n\t\t\t\tleft.kind === \"code\" &&\n\t\t\t\tthis.isNumber(node.left) &&\n\t\t\t\t!this.runsWhenNeeded(node.right, frame)\n\t\t\t) {\n\t\t\t\treturn this.firstNonZero(left, node, frame);\n\t\t\t}\n\t\t\tif (this.runsWhenNeeded(node.right, frame)) {\n\t\t\t\t// The right operand's writes happen only when it is evaluated.\n\t\t\t\tconst result = frame.emitter.temporary();\n\t\t\t\tframe.emitter.line(\n\t\t\t\t\tmapped`let ${result}: boolean = ${this.context.dialect.condition(left, node.left)};`,\n\t\t\t\t);\n\t\t\t\tframe.emitter.open(and ? `if (${result}) {` : `if (!${result}) {`);\n\t\t\t\tconst right = this.expression(node.right, frame, expected);\n\t\t\t\tframe.emitter.line(\n\t\t\t\t\tmapped`${result} = ${this.context.dialect.condition(right, node.right)};`,\n\t\t\t\t);\n\t\t\t\tframe.emitter.close();\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"code\",\n\t\t\t\t\ttext: result,\n\t\t\t\t\tdeclared: this.context.checker.getBooleanType(),\n\t\t\t\t\tplace: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst right = this.expression(node.right, frame, expected);\n\t\t\tif (right.kind === \"const\") {\n\t\t\t\tif (Boolean(right.value) === and) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tkind: \"code\",\n\t\t\t\t\t\ttext: this.context.dialect.condition(left, node.left),\n\t\t\t\t\t\tdeclared: this.context.checker.getBooleanType(),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn constant(!and);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: mapped`(${this.context.dialect.condition(left, node.left)} ${and ? \"&&\" : \"||\"} ${this.context.dialect.condition(right, node.right)})`,\n\t\t\t\tdeclared: this.context.checker.getBooleanType(),\n\t\t\t};\n\t\t}\n\t\tif (kind === ts.SyntaxKind.QuestionQuestionToken) {\n\t\t\treturn this.orElse(\n\t\t\t\tthis.expression(node.left, frame),\n\t\t\t\tnode.right,\n\t\t\t\tframe,\n\t\t\t\texpected,\n\t\t\t);\n\t\t}\n\t\tif (isAssignment(kind)) {\n\t\t\treturn this.assignments.assign(node, frame);\n\t\t}\n\t\tconst equality = [\n\t\t\tts.SyntaxKind.EqualsEqualsEqualsToken,\n\t\t\tts.SyntaxKind.ExclamationEqualsEqualsToken,\n\t\t\tts.SyntaxKind.EqualsEqualsToken,\n\t\t\tts.SyntaxKind.ExclamationEqualsToken,\n\t\t].includes(kind);\n\t\tconst read = this.expression(node.left, frame);\n\t\t// A left operand read before the right one writes keeps the value it had.\n\t\tconst left = containsWrite(node.right) ? this.held(read, frame) : read;\n\t\tconst right = this.expression(\n\t\t\tnode.right,\n\t\t\tframe,\n\t\t\tread.kind === \"code\" ? read.declared : undefined,\n\t\t);\n\t\tconst negate =\n\t\t\tkind === ts.SyntaxKind.ExclamationEqualsEqualsToken ||\n\t\t\tkind === ts.SyntaxKind.ExclamationEqualsToken;\n\t\tif (equality) {\n\t\t\tthis.references.identities(left, right, node);\n\t\t\treturn this.equality(left, right, { negate });\n\t\t}\n\t\tif (\n\t\t\tleft.kind === \"const\" &&\n\t\t\tright.kind === \"const\" &&\n\t\t\ttypeof left.value === \"number\" &&\n\t\t\ttypeof right.value === \"number\"\n\t\t) {\n\t\t\tconst folded = foldNumber(kind, left.value, right.value);\n\t\t\tif (folded !== undefined) {\n\t\t\t\treturn constant(finite(folded, node));\n\t\t\t}\n\t\t}\n\t\tif (kind === ts.SyntaxKind.AsteriskAsteriskToken) {\n\t\t\treturn this.calls.floatMath(\"pow\", [left, right], node, frame);\n\t\t}\n\t\tconst declared = this.context.checker.getTypeAtLocation(node);\n\t\tconst comparison = comparisonOperators.get(kind);\n\t\tif (comparison) {\n\t\t\tconst [leftText, rightText] = this.context.dialect.comparable(\n\t\t\t\tleft,\n\t\t\t\tright,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: mapped`(${leftText} ${comparison} ${rightText})`,\n\t\t\t\tdeclared,\n\t\t\t};\n\t\t}\n\t\tif (\n\t\t\tkind === ts.SyntaxKind.SlashToken &&\n\t\t\t!floatIec(left) &&\n\t\t\t!floatIec(right)\n\t\t) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"/ on integers gives a fraction, which no integer holds: divide with div<T>(a, b) from @tsplc/compiler/types, which truncates toward zero, or make an operand REAL or LREAL.\",\n\t\t\t);\n\t\t}\n\t\tconst operator = arithmeticOperators.get(kind);\n\t\tif (!operator) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t`${node.operatorToken.getText()} is not supported.`,\n\t\t\t);\n\t\t}\n\t\tconst { texts, iec } = this.context.dialect.arithmetic(left, right);\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: mapped`(${texts[0]} ${operator} ${texts[1]})`,\n\t\t\tdeclared,\n\t\t\tiec,\n\t\t};\n\t}\n\n\t/** A plain number: an enum's members are numbers to TypeScript, but the PLC's enum is no integer. */\n\tprivate isNumber(node: ts.Expression): boolean {\n\t\tconst flags = this.context.checker.getTypeAtLocation(node).flags;\n\t\treturn (\n\t\t\tBoolean(flags & (ts.TypeFlags.Number | ts.TypeFlags.NumberLiteral)) &&\n\t\t\t!(flags & ts.TypeFlags.EnumLike)\n\t\t);\n\t}\n\n\t/**\n\t * `left || right` between numbers is a number, as a comparator's `byLoad || byId` is: the left\n\t * one unless it is zero. A right operand that writes keeps the boolean form, whose branch holds it.\n\t */\n\tprivate firstNonZero(\n\t\tleft: Value & { kind: \"code\" },\n\t\tnode: ts.BinaryExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst once = this.temporaryOf(left, frame);\n\t\tconst right = this.expression(node.right, frame);\n\t\tconst first = this.context.dialect.code(once, undefined);\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: mapped`(${first} !== 0 ? ${first} : ${this.context.dialect.code(right, undefined)})`,\n\t\t\tdeclared: this.context.checker.getTypeAtLocation(node),\n\t\t\tiec: left.iec,\n\t\t};\n\t}\n\n\t/** `left === right`, or `!==` when negated: known now when it can be, otherwise a comparison. */\n\tequality(left: Value, right: Value, { negate }: { negate: boolean }): Value {\n\t\tconst referred = this.references.equality(left, right, { negate });\n\t\tif (referred) {\n\t\t\treturn referred;\n\t\t}\n\t\tconst folded = this.equal(left, right);\n\t\tif (folded !== undefined) {\n\t\t\treturn constant(negate ? !folded : folded);\n\t\t}\n\t\tconst [code, other] = left.kind === \"code\" ? [left, right] : [right, left];\n\t\tif (\n\t\t\tcode.kind === \"code\" &&\n\t\t\tother.kind === \"const\" &&\n\t\t\tother.value === undefined\n\t\t) {\n\t\t\t// A value whose storage can't hold undefined never is, as an index setup filled isn't.\n\t\t\tif (\n\t\t\t\t!code.declared ||\n\t\t\t\t(!this.context.layouts.isOptionalRecord(code.declared) &&\n\t\t\t\t\t!this.context.layouts.literals(code.declared)?.optional)\n\t\t\t) {\n\t\t\t\treturn constant(negate);\n\t\t\t}\n\t\t\tconst test = this.context.dialect.isUndefinedText(\n\t\t\t\tcode.text,\n\t\t\t\tcode.declared,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: negate ? mapped`!(${test})` : test,\n\t\t\t\tdeclared: this.context.checker.getBooleanType(),\n\t\t\t};\n\t\t}\n\t\tconst declared = code.kind === \"code\" ? code.declared : undefined;\n\t\tconst [leftText, rightText] = this.context.dialect.comparable(\n\t\t\tleft,\n\t\t\tright,\n\t\t\tdeclared,\n\t\t);\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: mapped`(${leftText} ${negate ? \"!==\" : \"===\"} ${rightText})`,\n\t\t\tdeclared: this.context.checker.getBooleanType(),\n\t\t};\n\t}\n\n\t/** Equality known now: two known objects, or a known object against undefined. */\n\tprivate equal(left: Value, right: Value): boolean | undefined {\n\t\tif (left.kind === \"const\" && right.kind === \"const\") {\n\t\t\treturn left.value === right.value;\n\t\t}\n\t\tif (left.kind === \"static\" && right.kind === \"static\") {\n\t\t\treturn left.node === right.node;\n\t\t}\n\t\tif (\n\t\t\t(left.kind === \"static\" && right.kind === \"const\") ||\n\t\t\t(left.kind === \"const\" && right.kind === \"static\")\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Calls a function value: specializes it, or inlines a one-expression arrow. */\n\tinvoke(\n\t\ttarget: Value,\n\t\targs: Value[],\n\t\tat: ts.Node,\n\t\tframe: Frame,\n\t\texpected?: ts.Type,\n\t): Value {\n\t\tif (target.kind === \"static\" && target.node.captured.kind === \"closure\") {\n\t\t\treturn this.invoke(\n\t\t\t\tthis.closure(target.node.captured, at),\n\t\t\t\targs,\n\t\t\t\tat,\n\t\t\t\tframe,\n\t\t\t\texpected,\n\t\t\t);\n\t\t}\n\t\tif (target.kind !== \"function\") {\n\t\t\tthrow new SpecializeError(at, \"Only functions can be called.\");\n\t\t}\n\t\tconst declaration = target.declaration;\n\t\tif (!declaration.body && declaration.getSourceFile().isDeclarationFile) {\n\t\t\tconst name = declaration.name?.getText() ?? \"This function\";\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t`${name} is declared without a body, as JavaScript's own functions are: scan code calls functions the program writes and the SDK's, so compute the value in the program, or in setup.`,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\ttarget.env &&\n\t\t\tts.isArrowFunction(declaration) &&\n\t\t\t!ts.isBlock(declaration.body)\n\t\t) {\n\t\t\tconst inline: Frame = {\n\t\t\t\t...frame,\n\t\t\t\tenv: new Map(target.env),\n\t\t\t\tself: target.self ?? frame.self,\n\t\t\t};\n\t\t\tdeclaration.parameters.forEach((parameter, index) => {\n\t\t\t\tconst given = args[index] ?? constant(undefined);\n\t\t\t\tconst fallback = parameterDefault(\n\t\t\t\t\tthis.context.checker,\n\t\t\t\t\tgiven,\n\t\t\t\t\tparameter,\n\t\t\t\t);\n\t\t\t\tconst arg = fallback ? this.expression(fallback, inline) : given;\n\t\t\t\tconst value =\n\t\t\t\t\targ.kind === \"code\" && !arg.place\n\t\t\t\t\t\t? this.temporaryOf(arg, frame)\n\t\t\t\t\t\t: arg;\n\t\t\t\tthis.bind(\n\t\t\t\t\tparameter.name,\n\t\t\t\t\tvalue,\n\t\t\t\t\tinline,\n\t\t\t\t\tthis.context.checker.getTypeAtLocation(parameter),\n\t\t\t\t\t{ mutable: false, iec: this.context.layouts.iecName(parameter) },\n\t\t\t\t);\n\t\t\t});\n\t\t\tconst result = this.expression(declaration.body, inline, expected);\n\t\t\tconst iec = this.context.layouts.iecName(declaration);\n\t\t\tthis.refuseOutsideWidth(result, iec, declaration.body);\n\t\t\tif (iec === undefined || result.kind !== \"code\") {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tconst signature =\n\t\t\t\tthis.context.checker.getSignatureFromDeclaration(declaration);\n\t\t\tconst declared =\n\t\t\t\tsignature && this.context.checker.getReturnTypeOfSignature(signature);\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: this.context.dialect.assignmentText(result, declared, iec),\n\t\t\t\tdeclared,\n\t\t\t\tiec,\n\t\t\t};\n\t\t}\n\t\tconst called = this.routineTable.routine(\n\t\t\tdeclaration,\n\t\t\ttarget.self,\n\t\t\targs,\n\t\t\ttarget.env && { env: target.env, caller: frame.emitter },\n\t\t);\n\t\tconst text = mapped`${called.name}(${joined(called.args, \", \")})`;\n\t\tconst returns = called.returns;\n\t\tif (!returns || returns.flags & ts.TypeFlags.Void) {\n\t\t\tconst statement = ts.isAwaitExpression(at.parent) ? at.parent : at;\n\t\t\tif (ts.isExpressionStatement(statement.parent) || linksPromise(at)) {\n\t\t\t\treturn { kind: \"code\", text, declared: returns };\n\t\t\t}\n\t\t\tframe.emitter.line(mapped`${text};`);\n\t\t\treturn constant(undefined);\n\t\t}\n\t\tif (referenceType(returns)) {\n\t\t\treturn this.references.result(text, called.referents, returns, frame);\n\t\t}\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext,\n\t\t\tdeclared: returns,\n\t\t\tiec: called.iec,\n\t\t\tlayout: called.layout,\n\t\t\tlength: called.length,\n\t\t\t...(called.returnsStored && { copyOf: sourceName(target) }),\n\t\t};\n\t}\n\n\t/**\n\t * `super.name`: the member the class around the expression inherits, on the same instance. Every\n\t * instance's class is known when the program compiles, so this resolves then.\n\t */\n\tsuperMember(node: ts.PropertyAccessExpression, frame: Frame): Value {\n\t\tconst owner = ts.findAncestor(node, ts.isClassDeclaration);\n\t\tif (!owner || !frame.self) {\n\t\t\tthrow new SpecializeError(node, \"`super` outside a method.\");\n\t\t}\n\t\tconst name = node.name.text;\n\t\tconst inherited = this.context.model\n\t\t\t.ancestry(owner)\n\t\t\t.slice(1)\n\t\t\t.flatMap((base) => [...base.members]);\n\t\tconst accessor = getterNamed(inherited, name);\n\t\tif (accessor) {\n\t\t\treturn this.invoke(\n\t\t\t\t{ kind: \"function\", declaration: accessor, self: frame.self },\n\t\t\t\t[],\n\t\t\t\tnode,\n\t\t\t\tframe,\n\t\t\t);\n\t\t}\n\t\tconst method = methodNamed(inherited, name);\n\t\tif (!method) {\n\t\t\tthrow new SpecializeError(node, `The base class has no ${name}.`);\n\t\t}\n\t\treturn { kind: \"function\", declaration: method, self: frame.self };\n\t}\n\n\t/** Each field of a record-valued expression: a known record's, or each property its type declares. */\n\trecordFields(expression: ts.Expression, frame: Frame): [string, Value][] {\n\t\tconst evaluated = this.expression(expression, frame);\n\t\tif (evaluated.kind === \"virtual\" && evaluated.fields) {\n\t\t\treturn [...evaluated.fields];\n\t\t}\n\t\t// A runtime record is read once, so a call in it runs once.\n\t\tconst source =\n\t\t\tevaluated.kind === \"code\"\n\t\t\t\t? this.temporaryOf(evaluated, frame)\n\t\t\t\t: evaluated;\n\t\tconst type = this.context.checker.getTypeAtLocation(expression);\n\t\treturn this.context.checker\n\t\t\t.getPropertiesOfType(this.context.checker.getNonNullableType(type))\n\t\t\t.map((symbol): [string, Value] => [\n\t\t\t\tsymbol.name,\n\t\t\t\tthis.member(source, symbol.name, expression, frame),\n\t\t\t]);\n\t}\n\n\t/**\n\t * A record or array literal stays a value known now, unless the code changes it through its name or\n\t * lends it to a call: then it is a local, as a new object is. One holding objects setup built stays known.\n\t */\n\tprivate heldAsLocal(\n\t\tvalue: Value & { kind: \"virtual\" },\n\t\tname: ts.Identifier,\n\t\tsymbol: ts.Symbol,\n\t): boolean {\n\t\tif (holdsSetupObjects(value)) {\n\t\t\treturn false;\n\t\t}\n\t\treturn writesThrough(scopeOf(name), symbol, this.context.checker);\n\t}\n\n\t/** `typeof`, known when the program compiles: from a value setup fixed, or from runtime storage's declared type. */\n\tprivate typeOf(value: Value): Value {\n\t\tif (value.kind === \"const\") {\n\t\t\treturn constant(typeof value.value);\n\t\t}\n\t\tif (value.kind === \"function\") {\n\t\t\treturn constant(\"function\");\n\t\t}\n\t\tif (value.kind !== \"code\" || !value.declared) {\n\t\t\treturn constant(\"object\");\n\t\t}\n\t\tconst declared = value.declared;\n\t\tconst kinds: [ts.TypeFlags, string][] = [\n\t\t\t[ts.TypeFlags.NumberLike, \"number\"],\n\t\t\t[ts.TypeFlags.StringLike, \"string\"],\n\t\t\t[ts.TypeFlags.BooleanLike, \"boolean\"],\n\t\t\t[ts.TypeFlags.BigIntLike, \"bigint\"],\n\t\t];\n\t\tconst found = kinds.find(([flag]) => declared.flags & flag);\n\t\treturn constant(found ? found[1] : \"object\");\n\t}\n\n\t/**\n\t * A function setup made inside another and stored: its declaration, with the values it captured\n\t * as its closure, and the object it was made in as its `this`.\n\t */\n\tprivate closure(\n\t\tcaptured: Extract<ModelNode[\"captured\"], { kind: \"closure\" }>,\n\t\tat: ts.Node,\n\t): Value {\n\t\tconst source = this.context.model.sourceFile(captured.file);\n\t\tconst declaration = findClosure(source, captured.start);\n\t\tif (!declaration) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t\"The function setup stored isn't in the program.\",\n\t\t\t);\n\t\t}\n\t\tconst symbols = closureSymbols(declaration, this.context.checker);\n\t\tconst env: Env = new Map(\n\t\t\tcaptured.captures.flatMap(({ name, value }): [ts.Symbol, Value][] => {\n\t\t\t\tconst known: Value =\n\t\t\t\t\tvalue.kind === \"node\"\n\t\t\t\t\t\t? { kind: \"static\", node: this.context.model.node(value) }\n\t\t\t\t\t\t: capturedPrimitive(value);\n\t\t\t\treturn (symbols.get(name) ?? []).map((symbol): [ts.Symbol, Value] => [\n\t\t\t\t\tsymbol,\n\t\t\t\t\tknown,\n\t\t\t\t]);\n\t\t\t}),\n\t\t);\n\t\tconst made = captured.captures.find(({ name }) => name === \"this\");\n\t\tconst self = made && this.context.model.node(made.value);\n\t\treturn { kind: \"function\", declaration, self, env };\n\t}\n\n\t/**\n\t * `reference?.name` or `reference?.method()`: what `read` gives when the reference holds an\n\t * object, and undefined when it holds none, as JavaScript gives, never the read's empty value.\n\t */\n\tchained(\n\t\tobject: Extract<Value, { kind: \"choice\" }>,\n\t\tread: () => Value,\n\t\tnode: ts.Expression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst result = this.context.checker.getTypeAtLocation(node);\n\t\tconst present = this.context.dialect.condition(object, node);\n\t\tif (referenceType(result)) {\n\t\t\treturn this.references.branch(\n\t\t\t\tpresent,\n\t\t\t\t[read, () => constant(undefined)],\n\t\t\t\tnode,\n\t\t\t\tframe,\n\t\t\t);\n\t\t}\n\t\t// A call for its effect alone runs only when the reference holds an object, and gives nothing.\n\t\tconst defined = this.context.checker.getNonNullableType(result);\n\t\tif (\n\t\t\tresult.flags & ts.TypeFlags.Void ||\n\t\t\tdefined.flags & (ts.TypeFlags.Void | ts.TypeFlags.Never)\n\t\t) {\n\t\t\treturn read();\n\t\t}\n\t\tif (\n\t\t\t!this.context.layouts.isOptionalRecord(result) &&\n\t\t\t!this.context.layouts.literals(result)?.optional\n\t\t) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"?. through this reference gives a value the PLC can't hold as optional: test the reference with !== undefined first, and read it inside the if.\",\n\t\t\t);\n\t\t}\n\t\treturn this.branched(\n\t\t\tresult,\n\t\t\tpresent,\n\t\t\t[read, () => constant(undefined)],\n\t\t\tframe,\n\t\t);\n\t}\n\n\t/** `record?.field` on an optional record: the field as an optional, or the empty value when the record is. */\n\tprivate optionalMember(\n\t\tobject: Code,\n\t\tdeclared: ts.Type,\n\t\tnode: ts.PropertyAccessExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst held = this.temporaryOf(object, frame);\n\t\tconst defined: Value = {\n\t\t\tkind: \"code\",\n\t\t\ttext: optionalValue(held.text),\n\t\t\tdeclared: this.context.checker.getNonNullableType(declared),\n\t\t\tplace: held.place,\n\t\t};\n\t\tconst field = this.member(defined, node.name.text, node, frame);\n\t\tconst result = this.context.checker.getTypeAtLocation(node);\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: mapped`(${this.context.dialect.isUndefinedText(held.text, declared)} ? ${this.context.dialect.assignmentText(constant(undefined), result, undefined)} : ${this.context.dialect.assignmentText(field, result, undefined)})`,\n\t\t\tdeclared: result,\n\t\t};\n\t}\n\n\t/**\n\t * Evaluates operands left to right. A runtime value read before a later operand writes is held in\n\t * a const first, so it is the value JavaScript reads then.\n\t */\n\tinOrder<T extends ts.Node>(\n\t\tnodes: readonly T[],\n\t\tevaluate: (node: T, index: number) => Value,\n\t\tframe: Frame,\n\t): Value[] {\n\t\treturn nodes.map((node, index) => {\n\t\t\tconst value = evaluate(node, index);\n\t\t\treturn nodes.slice(index + 1).some(containsWrite)\n\t\t\t\t? this.held(value, frame)\n\t\t\t\t: value;\n\t\t});\n\t}\n\n\t/** A runtime scalar's current value, in a const of its own; aggregates and known values stay as they are. */\n\theld(value: Value, frame: Frame): Value {\n\t\tif (value.kind === \"choice\") {\n\t\t\treturn this.references.held(value, frame);\n\t\t}\n\t\tif (\n\t\t\tvalue.kind !== \"code\" ||\n\t\t\t(value.declared && this.isAggregate(value.declared))\n\t\t) {\n\t\t\treturn value;\n\t\t}\n\t\treturn this.hold(value, frame, {\n\t\t\twidth: true,\n\t\t\twiden: true,\n\t\t\tuntyped: \"number\",\n\t\t\trepeatable: true,\n\t\t});\n\t}\n\n\t/** A runtime value in a const of its own, so code after reads the const rather than running the value again. */\n\thold(value: Code, frame: Frame, holding: Holding): Code {\n\t\tif (!holding.repeatable && repeatable(value.text)) {\n\t\t\treturn value;\n\t\t}\n\t\tconst local = frame.emitter.temporary();\n\t\tframe.emitter.line(\n\t\t\tmapped`const ${local}: ${this.heldType(value, holding)} = ${value.text};`,\n\t\t);\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: local,\n\t\t\tdeclared: value.declared,\n\t\t\tplace: true,\n\t\t\t...(holding.width && { iec: value.iec }),\n\t\t};\n\t}\n\n\t/** A runtime value's PLC type, as `typing` reads it. */\n\theldType(value: Code, { width, widen, untyped }: Typing): string {\n\t\tconst iec = width ? value.iec : undefined;\n\t\tif (iec) {\n\t\t\treturn iec;\n\t\t}\n\t\tif (!value.declared) {\n\t\t\treturn untyped;\n\t\t}\n\t\treturn widen\n\t\t\t? this.localType(value.declared)\n\t\t\t: this.context.layouts.text(value.declared);\n\t}\n\n\t/** `.value` for an optional record, whose defined value sits in a field. */\n\toptionalValueSuffix(declared: ts.Type): string {\n\t\treturn this.context.layouts.isOptionalRecord(declared)\n\t\t\t? `.${optionalRecord.value}`\n\t\t\t: \"\";\n\t}\n\n\t/**\n\t * A choice whose branches write, as an if statement storing each branch's value in a local, so a\n\t * branch's writes happen only when it is taken.\n\t */\n\tprivate branched(\n\t\tdeclared: ts.Type,\n\t\tcondition: Part,\n\t\tbranches: readonly [\n\t\t\tts.Expression | (() => Value),\n\t\t\tts.Expression | (() => Value),\n\t\t],\n\t\tframe: Frame,\n\t): Value {\n\t\tconst result = frame.emitter.temporary();\n\t\tframe.emitter.line(\n\t\t\t`let ${result}: ${this.localType(declared)} = ${this.context.initializers.defaultOf(declared)};`,\n\t\t);\n\t\tconst evaluate = (branch: ts.Expression | (() => Value)): Value =>\n\t\t\ttypeof branch === \"function\"\n\t\t\t\t? branch()\n\t\t\t\t: this.expression(branch, frame, declared);\n\t\tconst [yes, no] = branches;\n\t\tframe.emitter.open(mapped`if (${condition}) {`);\n\t\tframe.emitter.line(\n\t\t\tmapped`${result} = ${this.context.dialect.assignmentText(evaluate(yes), declared, undefined)};`,\n\t\t);\n\t\tframe.emitter.reopen(\"} else {\");\n\t\tframe.emitter.line(\n\t\t\tmapped`${result} = ${this.context.dialect.assignmentText(evaluate(no), declared, undefined)};`,\n\t\t);\n\t\tframe.emitter.close();\n\t\treturn { kind: \"code\", text: result, declared, place: true };\n\t}\n\n\t/**\n\t * Whether an operand JavaScript evaluates only when it needs it is written as statements: it\n\t * writes a place, or runs a generator or a snapshot's loop. Those go in the branch that needs them.\n\t */\n\tprivate runsWhenNeeded(node: ts.Expression, frame: Frame): boolean {\n\t\treturn containsWrite(node) || this.iterators.traverses(node, frame);\n\t}\n\n\t/** The routine that cancels the pending async calls of an instance's methods, as `cancelAsync(this)` does. */\n\tcanceller(self: ModelNode): string {\n\t\treturn this.routineTable.canceller(self);\n\t}\n\n\t/**\n\t * Evaluates `run` only to learn what it gives: the routines, tables and service nodes it makes\n\t * belong to code nothing keeps, so they are forgotten after.\n\t */\n\tspeculatively<T>(run: () => T): T {\n\t\tconst declarations = this.tableDeclarations.length;\n\t\tconst restored = [restoring(this.tables), restoring(this.services)];\n\t\ttry {\n\t\t\treturn this.routineTable.speculatively(run);\n\t\t} finally {\n\t\t\tthis.tableDeclarations.splice(declarations);\n\t\t\tfor (const restore of restored) {\n\t\t\t\trestore();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * A known number named under an IEC integer annotation obeys the rule a literal stored there\n\t * obeys: one the type cannot hold is refused.\n\t */\n\tprivate refuseOutsideWidth(\n\t\tvalue: Value,\n\t\tiec: string | undefined,\n\t\tat: ts.Node,\n\t): void {\n\t\tconst type = primitiveTypes.find((primitive) => primitive.id === iec);\n\t\tif (\n\t\t\ttype === undefined ||\n\t\t\t!integerType(type) ||\n\t\t\tvalue.kind !== \"const\" ||\n\t\t\t(typeof value.value !== \"number\" && typeof value.value !== \"bigint\")\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (!constantFits({ kind: \"integer\", value: String(value.value) }, type)) {\n\t\t\tthrow new SpecializeError(at, literalOutsideType);\n\t\t}\n\t}\n\n\t/**\n\t * `left`, or `fallback` when it is undefined, as `??` and a pattern's default give: the fallback\n\t * runs only when it is needed.\n\t */\n\tprivate orElse(\n\t\tleft: Value,\n\t\tfallback: ts.Expression,\n\t\tframe: Frame,\n\t\texpected: ts.Type | undefined,\n\t): Value {\n\t\tif (left.kind === \"const\") {\n\t\t\treturn left.value === undefined\n\t\t\t\t? this.expression(fallback, frame, expected)\n\t\t\t\t: left;\n\t\t}\n\t\tif (left.kind === \"static\") {\n\t\t\treturn left;\n\t\t}\n\t\tif (left.kind === \"choice\") {\n\t\t\treturn this.references.fallback(\n\t\t\t\tleft,\n\t\t\t\t() => this.expression(fallback, frame, expected),\n\t\t\t\tfallback.parent,\n\t\t\t\tframe,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\tleft.kind !== \"code\" ||\n\t\t\t!left.declared ||\n\t\t\tthis.context.checker.getNonNullableType(left.declared) === left.declared\n\t\t) {\n\t\t\treturn left;\n\t\t}\n\t\tconst declared = left.declared;\n\t\tconst defined = this.context.checker.getNonNullableType(declared);\n\t\t// A record or array result is chosen by statements: PLC code loads one only into storage.\n\t\tif (this.runsWhenNeeded(fallback, frame) || this.isAggregate(defined)) {\n\t\t\t// Read once to test and once to give, so a call on the left runs once, into a const.\n\t\t\tconst held = this.isAggregate(declared)\n\t\t\t\t? this.temporaryOf(left, frame)\n\t\t\t\t: this.held(left, frame);\n\t\t\treturn this.branched(\n\t\t\t\tdefined,\n\t\t\t\tthis.context.dialect.isUndefinedText(\n\t\t\t\t\tthis.context.dialect.code(held, declared),\n\t\t\t\t\tdeclared,\n\t\t\t\t),\n\t\t\t\t[\n\t\t\t\t\tfallback,\n\t\t\t\t\t() => ({\n\t\t\t\t\t\tkind: \"code\",\n\t\t\t\t\t\ttext: mapped`${this.context.dialect.code(held, undefined)}${this.optionalValueSuffix(declared)}`,\n\t\t\t\t\t\tdeclared: defined,\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t\tframe,\n\t\t\t);\n\t\t}\n\t\t// The left operand is read twice, so a call in it runs once, into a const.\n\t\tconst once = this.temporaryOf(left, frame);\n\t\tconst right = this.expression(fallback, frame, defined);\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: mapped`(${this.context.dialect.isUndefinedText(this.context.dialect.code(once, declared), declared)} ? ${this.context.dialect.code(right, defined)} : ${this.context.dialect.code(once, undefined)}${this.optionalValueSuffix(declared)})`,\n\t\t\tdeclared: defined,\n\t\t};\n\t}\n\n\t/** What a pattern's part is worth: `fallback` when the part is undefined, as `{ x = 7 }` defaults. */\n\tdefaulted(\n\t\tpart: Value,\n\t\tfallback: ts.Expression | undefined,\n\t\tframe: Frame,\n\t): Value {\n\t\treturn fallback === undefined\n\t\t\t? part\n\t\t\t: this.orElse(part, fallback, frame, undefined);\n\t}\n\n\t/** A runtime value held in a const, so inlining doesn't evaluate it twice. */\n\ttemporaryOf(value: Code, frame: Frame): Code {\n\t\treturn this.hold(value, frame, {\n\t\t\twidth: false,\n\t\t\twiden: true,\n\t\t\tuntyped: \"number\",\n\t\t\trepeatable: false,\n\t\t});\n\t}\n\n\t/** Binds a local, or each name of a destructuring pattern, to a value. */\n\tbind(\n\t\tname: ts.BindingName,\n\t\tvalue: Value,\n\t\tframe: Frame,\n\t\tdeclared: ts.Type,\n\t\t{\n\t\t\tmutable,\n\t\t\tiec,\n\t\t}: {\n\t\t\tmutable: boolean;\n\t\t\t/** The IEC width the binding's annotation names, as `const slot: UINT` does. */\n\t\t\tiec: string | undefined;\n\t\t},\n\t): void {\n\t\t// A pattern reads its value once per name, so a computed value is held first.\n\t\tconst bound =\n\t\t\t!ts.isIdentifier(name) && value.kind === \"code\" && !value.place\n\t\t\t\t? this.temporaryOf(value, frame)\n\t\t\t\t: value;\n\t\tif (ts.isObjectBindingPattern(name)) {\n\t\t\tfor (const { element, field } of namedFields(name, \"pattern\")) {\n\t\t\t\tconst inner = this.defaulted(\n\t\t\t\t\tthis.member(bound, field, element, frame),\n\t\t\t\t\telement.initializer,\n\t\t\t\t\tframe,\n\t\t\t\t);\n\t\t\t\tthis.bind(\n\t\t\t\t\telement.name,\n\t\t\t\t\tinner,\n\t\t\t\t\tframe,\n\t\t\t\t\tthis.context.checker.getTypeAtLocation(element.name),\n\t\t\t\t\t{ mutable, iec: undefined },\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (ts.isArrayBindingPattern(name)) {\n\t\t\tfor (const { element, index } of namedElements(name, \"pattern\")) {\n\t\t\t\tconst inner = this.defaulted(\n\t\t\t\t\tthis.element(bound, constant(index), element, frame),\n\t\t\t\t\telement.initializer,\n\t\t\t\t\tframe,\n\t\t\t\t);\n\t\t\t\tthis.bind(\n\t\t\t\t\telement.name,\n\t\t\t\t\tinner,\n\t\t\t\t\tframe,\n\t\t\t\t\tthis.context.checker.getTypeAtLocation(element.name),\n\t\t\t\t\t{ mutable, iec: undefined },\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tconst symbol = symbolOf(this.context.checker, name);\n\t\tif (this.context.checker.getAwaitedType(declared) !== declared) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tname,\n\t\t\t\t`${name.text} would keep a promise, and the PLC runs an async call only where it is awaited: write const ${name.text} = await call(); where the call is made.`,\n\t\t\t);\n\t\t}\n\t\tconst reference = this.references.local(name.text, bound, declared, frame, {\n\t\t\tmutable,\n\t\t});\n\t\tif (reference) {\n\t\t\tframe.env.set(symbol, reference);\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\tbound.kind === \"virtual\" &&\n\t\t\t!isReadonly(declared, this.context.checker) &&\n\t\t\tthis.heldAsLocal(bound, name, symbol)\n\t\t) {\n\t\t\tconst local = frame.emitter.local(name.text);\n\t\t\tframe.emitter.line(\n\t\t\t\tmapped`let ${local}: ${this.localType(declared)} = ${this.context.dialect.assignmentText(bound, declared, undefined)};`,\n\t\t\t);\n\t\t\tframe.env.set(symbol, {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: local,\n\t\t\t\tdeclared,\n\t\t\t\tplace: true,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tif (mutable && bound.kind === \"function\" && ts.isIdentifier(name)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tname,\n\t\t\t\t`${name.text} is a let that holds a function, and the PLC calls only functions known when the program compiles: declare it with const, or choose which function to call with an if.`,\n\t\t\t);\n\t\t}\n\t\tif (!mutable && bound.kind !== \"code\") {\n\t\t\tthis.refuseOutsideWidth(bound, iec, name);\n\t\t\tframe.env.set(symbol, bound);\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\t!mutable &&\n\t\t\tbound.kind === \"code\" &&\n\t\t\tbound.place &&\n\t\t\tts.isIdentifier(name) &&\n\t\t\tthis.isAggregate(this.context.checker.getNonNullableType(declared)) &&\n\t\t\treplacedWhileAliased(name, this.context.checker)\n\t\t) {\n\t\t\tthis.snapshot(name, symbol, bound, declared, frame);\n\t\t\treturn;\n\t\t}\n\t\tif (!mutable && bound.kind === \"code\" && bound.place) {\n\t\t\t// A const naming a place is an alias, as an object binding is in TypeScript. Its runtime\n\t\t\t// indexes are held now, so it keeps naming that element when they change; an index read\n\t\t\t// again at each use stays a value the PLC's bounds proof can follow.\n\t\t\tif (this.isAggregate(declared)) {\n\t\t\t\tconst pin = bound.pinned;\n\t\t\t\tconst repeats =\n\t\t\t\t\tts.isIdentifier(name) &&\n\t\t\t\t\tpureRead(bound.text) &&\n\t\t\t\t\tstableAlias(name, this.context.checker);\n\t\t\t\tframe.env.set(symbol, pin && !repeats ? pin(frame) : bound);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t// A record an await gives, annotated with another record type, such as a narrower one, is\n\t\t// copied field by field from the awaited value, which keeps the call's own type.\n\t\tif (\n\t\t\tbound.kind === \"code\" &&\n\t\t\tbound.awaited &&\n\t\t\tbound.declared &&\n\t\t\tbound.declared !== declared &&\n\t\t\tthis.isAggregate(declared) &&\n\t\t\t!this.context.checker.isArrayType(declared) &&\n\t\t\tts.isVariableDeclaration(name.parent) &&\n\t\t\tname.parent.type !== undefined\n\t\t) {\n\t\t\tconst reply = frame.emitter.temporary();\n\t\t\tframe.emitter.line(mapped`const ${reply} = ${bound.text};`);\n\t\t\tconst held: Value = {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: reply,\n\t\t\t\tdeclared: bound.declared,\n\t\t\t\tplace: true,\n\t\t\t};\n\t\t\tconst fields = new Map(\n\t\t\t\tthis.context.checker\n\t\t\t\t\t.getPropertiesOfType(declared)\n\t\t\t\t\t.map((property): [string, Value] => [\n\t\t\t\t\t\tproperty.name,\n\t\t\t\t\t\tthis.member(held, property.name, name, frame),\n\t\t\t\t\t]),\n\t\t\t);\n\t\t\tthis.bind(name, { kind: \"virtual\", fields }, frame, declared, {\n\t\t\t\tmutable,\n\t\t\t\tiec,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tconst local = frame.emitter.local(name.text);\n\t\t// A const record changed through its name, or lent to a call that may, is a variable to the PLC:\n\t\t// TypeScript's const fixes the binding, not the object.\n\t\tconst changes =\n\t\t\t!mutable &&\n\t\t\tthis.isAggregate(declared) &&\n\t\t\twritesThrough(scopeOf(name), symbol, this.context.checker);\n\t\tconst width = iec ?? (bound.kind === \"code\" ? bound.iec : undefined);\n\t\tconst layout = bound.kind === \"code\" ? bound.layout : undefined;\n\t\tconst length = bound.kind === \"code\" ? bound.length : undefined;\n\t\tconst type = width ?? layout?.text ?? this.localType(declared);\n\t\t// The async lowering suspends only at a bare await, so an awaited value cannot be converted in place.\n\t\tif (\n\t\t\tiec !== undefined &&\n\t\t\tbound.kind === \"code\" &&\n\t\t\tbound.awaited &&\n\t\t\tthis.context.dialect.converts(bound, declared, iec)\n\t\t) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tname,\n\t\t\t\t`An awaited value keeps its routine's result type, ${bound.iec ?? defaultNumericTypes.number}; store it in a local of that type, then convert it.`,\n\t\t\t);\n\t\t}\n\t\t// An annotated width converts the value as IEC assignment does.\n\t\tconst text = iec\n\t\t\t? this.context.dialect.assignmentText(bound, declared, iec)\n\t\t\t: this.context.dialect.code(bound, declared);\n\t\t// What an await gives is typed by the call awaited, which the async lowering reads itself, and\n\t\t// what a task returns by the task's declaration, whose IEC result type no TypeScript type keeps.\n\t\tconst typedByCall =\n\t\t\tbound.kind === \"code\" &&\n\t\t\t(bound.awaited || bound.typedByTask) &&\n\t\t\t!iec &&\n\t\t\t// A record the program annotates keeps that layout: no width conversion stands between it\n\t\t\t// and the call, and the call alone may not name it, as fetch's type argument doesn't.\n\t\t\t!(\n\t\t\t\tbound.awaited &&\n\t\t\t\tthis.isAggregate(declared) &&\n\t\t\t\tts.isVariableDeclaration(name.parent) &&\n\t\t\t\tname.parent.type !== undefined\n\t\t\t);\n\t\tconst annotation = typedByCall ? \"\" : `: ${type}`;\n\t\tframe.emitter.line(\n\t\t\tmapped`${mutable || changes ? \"let\" : \"const\"} ${local}${annotation} = ${text};`,\n\t\t);\n\t\tframe.env.set(symbol, {\n\t\t\tkind: \"code\",\n\t\t\ttext: local,\n\t\t\tdeclared,\n\t\t\tplace: true,\n\t\t\tiec: width,\n\t\t\tlayout,\n\t\t\tlength,\n\t\t\tcopyOf: bound.kind === \"code\" ? bound.copyOf : undefined,\n\t\t});\n\t}\n\n\t/** A local's dialect type: a literal union keeps its enum; a lone literal widens to its base type. */\n\tlocalType(declared: ts.Type): string {\n\t\tif (this.context.layouts.literalEnum(declared)) {\n\t\t\treturn this.context.layouts.text(declared);\n\t\t}\n\t\treturn this.context.layouts.text(\n\t\t\tthis.context.checker.getBaseTypeOfLiteralType(declared),\n\t\t);\n\t}\n\n\t/**\n\t * A const record whose place is assigned anew while it is read keeps what the place held, as the\n\t * object TypeScript's const names does. The PLC reads a record const from its place at each use, so\n\t * it is a copy instead, which can't also pass writes through to the place.\n\t */\n\tprivate snapshot(\n\t\tname: ts.Identifier,\n\t\tsymbol: ts.Symbol,\n\t\tbound: Value & { kind: \"code\" },\n\t\tdeclared: ts.Type,\n\t\tframe: Frame,\n\t): void {\n\t\tif (writesThrough(scopeOf(name), symbol, this.context.checker)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tname,\n\t\t\t\t\"This const is changed through, and the place it names is assigned anew while it is still used: the PLC can't keep both. Take a structuredClone of it, or change the place through its own path.\",\n\t\t\t);\n\t\t}\n\t\tconst local = frame.emitter.local(name.text);\n\t\tconst type = bound.layout?.text ?? this.localType(declared);\n\t\tthis.context.imports.addSdk(sdkModules.types, \"copy\");\n\t\tframe.emitter.line(\n\t\t\tmapped`const ${local}: ${type} = copy(${this.context.dialect.code(bound, declared)});`,\n\t\t);\n\t\tframe.env.set(symbol, {\n\t\t\tkind: \"code\",\n\t\t\ttext: local,\n\t\t\tdeclared,\n\t\t\tplace: true,\n\t\t\tlayout: bound.layout,\n\t\t\tlength: bound.length,\n\t\t});\n\t}\n\n\tprivate isAggregate(type: ts.Type): boolean {\n\t\treturn (\n\t\t\tBoolean(type.flags & ts.TypeFlags.Object) &&\n\t\t\t!this.context.layouts.literalEnum(type)\n\t\t);\n\t}\n\n\t/**\n\t * The elements of an array setup built or scan code assembled from known parts; undefined for\n\t * a runtime array. Known arrays unroll, so each element's identity stays known.\n\t */\n\titems(value: Value): Value[] | undefined {\n\t\tif (value.kind === \"virtual\" && value.items) {\n\t\t\treturn value.items;\n\t\t}\n\t\tif (value.kind === \"code\" && value.length !== undefined) {\n\t\t\tconst declared =\n\t\t\t\tvalue.declared && this.context.model.elementType(value.declared);\n\t\t\treturn Array.from(\n\t\t\t\t{ length: value.length },\n\t\t\t\t(_, index): Value => ({\n\t\t\t\t\tkind: \"code\",\n\t\t\t\t\ttext: mapped`${value.text}[${index}]`,\n\t\t\t\t\tdeclared,\n\t\t\t\t\tplace: value.place,\n\t\t\t\t\tiec: value.elementIec,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tif (value.kind !== \"static\") {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst array = value.node;\n\t\tconst captured = array.captured;\n\t\tif (captured.kind !== \"array\") {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn captured.items.map((item, index) =>\n\t\t\tthis.context.storage.fromCaptured(item, array, { kind: \"index\", index }),\n\t\t);\n\t}\n}\n\n/** Comparisons the dialect writes as TypeScript does. */\nconst comparisonOperators = new Map<ts.SyntaxKind, string>([\n\t[ts.SyntaxKind.LessThanToken, \"<\"],\n\t[ts.SyntaxKind.LessThanEqualsToken, \"<=\"],\n\t[ts.SyntaxKind.GreaterThanToken, \">\"],\n\t[ts.SyntaxKind.GreaterThanEqualsToken, \">=\"],\n]);\n\n/** Arithmetic and bit operators the dialect writes as TypeScript does. */\nconst arithmeticOperators = new Map<ts.SyntaxKind, string>([\n\t[ts.SyntaxKind.PlusToken, \"+\"],\n\t[ts.SyntaxKind.MinusToken, \"-\"],\n\t[ts.SyntaxKind.AsteriskToken, \"*\"],\n\t[ts.SyntaxKind.SlashToken, \"/\"],\n\t[ts.SyntaxKind.PercentToken, \"%\"],\n\t[ts.SyntaxKind.AmpersandToken, \"&\"],\n\t[ts.SyntaxKind.BarToken, \"|\"],\n\t[ts.SyntaxKind.CaretToken, \"^\"],\n\t[ts.SyntaxKind.LessThanLessThanToken, \"<<\"],\n\t[ts.SyntaxKind.GreaterThanGreaterThanToken, \">>\"],\n]);\n\nconst foldNumber = (\n\tkind: ts.SyntaxKind,\n\tleft: number,\n\tright: number,\n): number | boolean | undefined => {\n\tswitch (kind) {\n\t\tcase ts.SyntaxKind.PlusToken:\n\t\t\treturn left + right;\n\t\tcase ts.SyntaxKind.MinusToken:\n\t\t\treturn left - right;\n\t\tcase ts.SyntaxKind.AsteriskToken:\n\t\t\treturn left * right;\n\t\tcase ts.SyntaxKind.AsteriskAsteriskToken:\n\t\t\treturn left ** right;\n\t\tcase ts.SyntaxKind.SlashToken:\n\t\t\treturn left / right;\n\t\tcase ts.SyntaxKind.PercentToken:\n\t\t\treturn right === 0 ? undefined : left % right;\n\t\tcase ts.SyntaxKind.LessThanToken:\n\t\t\treturn left < right;\n\t\tcase ts.SyntaxKind.LessThanEqualsToken:\n\t\t\treturn left <= right;\n\t\tcase ts.SyntaxKind.GreaterThanToken:\n\t\t\treturn left > right;\n\t\tcase ts.SyntaxKind.GreaterThanEqualsToken:\n\t\t\treturn left >= right;\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n};\n\nconst mathConstants = new Map([\n\t[\"E\", Math.E],\n\t[\"LN10\", Math.LN10],\n\t[\"LN2\", Math.LN2],\n\t[\"LOG10E\", Math.LOG10E],\n\t[\"LOG2E\", Math.LOG2E],\n\t[\"PI\", Math.PI],\n\t[\"SQRT1_2\", Math.SQRT1_2],\n\t[\"SQRT2\", Math.SQRT2],\n]);\n\n/** A function as its source names it, for a message: `Class.method`, or the function's name. */\nconst sourceName = (target: Extract<Value, { kind: \"function\" }>): string => {\n\tconst own = target.declaration.name?.getText() ?? \"this function\";\n\treturn target.self?.captured.kind === \"instance\"\n\t\t? `${target.self.captured.name}.${own}`\n\t\t: own;\n};\n\n/** Whether a call is a `.then` or `.catch` link on a promise. */\nexport const isPromiseLink = (node: ts.Node): node is ts.CallExpression =>\n\tts.isCallExpression(node) &&\n\tts.isPropertyAccessExpression(node.expression) &&\n\tpromiseLinks.has(node.expression.name.text);\n\nconst promiseLinks: ReadonlySet<string> = new Set([\"then\", \"catch\"]);\n\n/** Whether an expression is the promise a `.then` or `.catch` link is called on. */\nconst linksPromise = (node: ts.Node): boolean =>\n\tts.isPropertyAccessExpression(node.parent) &&\n\tnode.parent.expression === node &&\n\tisPromiseLink(node.parent.parent);\n\n/** The function, or else the module, a name is declared in. */\nconst scopeOf = (name: ts.Identifier): ts.Node =>\n\tts.findAncestor(name.parent, ts.isFunctionLike) ?? name.getSourceFile();\n\nconst getterNamed = (\n\tmembers: readonly ts.ClassElement[],\n\tname: string,\n): ts.GetAccessorDeclaration | undefined =>\n\tmembers.find(\n\t\t(member): member is ts.GetAccessorDeclaration =>\n\t\t\tts.isGetAccessorDeclaration(member) && member.name.getText() === name,\n\t);\n\nconst methodNamed = (\n\tmembers: readonly ts.ClassElement[],\n\tname: string,\n): ts.MethodDeclaration | undefined =>\n\tmembers.find(\n\t\t(member): member is ts.MethodDeclaration =>\n\t\t\tts.isMethodDeclaration(member) && member.name.getText() === name,\n\t);\n\n/** A readonly array or record: what holds it can't change it, so a literal given to it stays a value. */\nconst isReadonly = (type: ts.Type, checker: ts.TypeChecker): boolean =>\n\t(!checker.isArrayType(type) && type.getSymbol()?.name === \"ReadonlyArray\") ||\n\ttype.aliasSymbol?.name === \"Readonly\" ||\n\tchecker.typeToString(type).startsWith(\"readonly \");\n\n/** The arrow or function expression written at `start`. */\nconst findClosure = (\n\tsource: ts.SourceFile,\n\tstart: number,\n): ts.ArrowFunction | ts.FunctionExpression | undefined => {\n\tconst visit = (\n\t\tnode: ts.Node,\n\t): ts.ArrowFunction | ts.FunctionExpression | undefined => {\n\t\tif (\n\t\t\t(ts.isArrowFunction(node) || ts.isFunctionExpression(node)) &&\n\t\t\tnode.getStart(source) === start\n\t\t) {\n\t\t\treturn node;\n\t\t}\n\t\treturn node.pos <= start && start < node.end\n\t\t\t? ts.forEachChild(node, visit)\n\t\t\t: undefined;\n\t};\n\treturn visit(source);\n};\n\n/** The symbols a closure's identifiers read, by name; a shorthand property reads its value's. */\nconst closureSymbols = (\n\tdeclaration: ts.Node,\n\tchecker: ts.TypeChecker,\n): ReadonlyMap<string, ts.Symbol[]> => {\n\tconst found = new Map<string, ts.Symbol[]>();\n\tconst visit = (node: ts.Node): void => {\n\t\tif (ts.isIdentifier(node)) {\n\t\t\tconst symbol = valueSymbol(checker, node);\n\t\t\tconst known = found.get(node.text) ?? [];\n\t\t\tif (symbol && !known.includes(symbol)) {\n\t\t\t\tfound.set(node.text, [...known, symbol]);\n\t\t\t}\n\t\t}\n\t\tts.forEachChild(node, visit);\n\t};\n\tvisit(declaration);\n\treturn found;\n};\n\n/** The expression a getter's body is no more than `return`ing. */\nconst onlyReturned = (\n\taccessor: ts.GetAccessorDeclaration,\n): ts.Expression | undefined => {\n\tconst [only, ...others] = accessor.body?.statements ?? [];\n\treturn only && !others.length && ts.isReturnStatement(only)\n\t\t? only.expression\n\t\t: undefined;\n};\n\n/** Whether reading a value's text again reads the same places and runs nothing: no call besides a conversion. */\nconst pureRead = (text: string | Mapped): boolean =>\n\t!/[\\w\\]>]\\s*\\(/.test(String(text).replace(/\\b(?:wrap|exact)<\\w+>\\(/g, \"(\"));\n",
47
+ "import { calendarLiteral } from \"@tsplc/compiler/ir\";\nimport { elementaryType } from \"@tsplc/iec\";\nimport {\n\ttype ElementaryFunction,\n\telementaryFunctions,\n\telementaryValue,\n} from \"@tsplc/iec/arithmetic\";\nimport ts from \"typescript\";\nimport {\n\tcopied,\n\tfrom,\n\tjoined,\n\ttype Mapped,\n\tmapped,\n\ttype Part,\n} from \"../positions\";\nimport {\n\tdeclaredBySdk,\n\tinSdk,\n\tisTelemetryDeclaration,\n\tsdkModule,\n\tsdkModules,\n\tsymbolAt,\n\tunaliased,\n\tvalueSymbol,\n} from \"../sdk\";\nimport { ArraySearches, callbackArgument, ordered } from \"./array-searches\";\nimport { isGlobal } from \"./declarations\";\nimport {\n\ttype ExpressionSpecializer,\n\ttype Holding,\n\tisPromiseLink,\n\ttype SpecializeContext,\n} from \"./expressions\";\nimport type { Frame } from \"./frame\";\nimport type { ModelNode } from \"./model\";\nimport { calendarFormats, durationNames } from \"./time-constructors\";\nimport {\n\tconstant,\n\ttype FunctionLike,\n\tfinite,\n\tSpecializeError,\n\tunwrapped,\n\ttype Value,\n} from \"./values\";\n\n/** What calls read from the expression specializer: evaluation, invocation, and the specializers for array values. */\ntype CallParts = Pick<\n\tExpressionSpecializer,\n\t| \"expression\"\n\t| \"invoke\"\n\t| \"inOrder\"\n\t| \"member\"\n\t| \"superMember\"\n\t| \"recordFields\"\n\t| \"shorthand\"\n\t| \"items\"\n\t| \"element\"\n\t| \"canceller\"\n\t| \"chained\"\n\t| \"held\"\n\t| \"hold\"\n\t| \"localType\"\n\t| \"equality\"\n\t| \"assignments\"\n\t| \"references\"\n\t| \"filteredArrays\"\n\t| \"iterators\"\n>;\n\n/** Specializes calls: to what the language and SDK provide, to the service client, and to functions. */\nexport class CallSpecializer {\n\tprivate readonly searches: ArraySearches;\n\n\tconstructor(\n\t\tprivate readonly context: SpecializeContext,\n\t\tprivate readonly expressions: CallParts,\n\t) {\n\t\tthis.searches = new ArraySearches(context, expressions);\n\t}\n\n\tcall(node: ts.CallExpression, frame: Frame, expected?: ts.Type): Value {\n\t\tconst callee = node.expression;\n\t\tif (\n\t\t\tts.isPropertyAccessExpression(callee) ||\n\t\t\tts.isPropertyAccessChain(callee)\n\t\t) {\n\t\t\treturn this.method(node, callee, frame, expected);\n\t\t}\n\t\tif (isGlobal(this.context.checker, callee, \"structuredClone\")) {\n\t\t\treturn this.cloned(node, frame);\n\t\t}\n\t\tconst target = this.expressions.expression(callee, frame);\n\t\t// `f?.()` of a function setup left undefined calls nothing.\n\t\tif (\n\t\t\tnode.questionDotToken &&\n\t\t\ttarget.kind === \"const\" &&\n\t\t\ttarget.value === undefined\n\t\t) {\n\t\t\treturn constant(undefined);\n\t\t}\n\t\tif (target.kind === \"static\" && target.node.captured.kind === \"task\") {\n\t\t\treturn this.taskCall(target.node, null, node, frame);\n\t\t}\n\t\tif (target.kind === \"static\" && target.node.captured.kind === \"service\") {\n\t\t\treturn this.serviceCall(target.node.captured.path, node, frame);\n\t\t}\n\t\tif (target.kind === \"static\" && target.node.captured.kind === \"function\") {\n\t\t\tconst declaration = this.functionDeclaration(\n\t\t\t\ttarget.node.captured.file,\n\t\t\t\ttarget.node.captured.name,\n\t\t\t);\n\t\t\treturn this.invokeCall(\n\t\t\t\t{ kind: \"function\", declaration },\n\t\t\t\tnode,\n\t\t\t\tframe,\n\t\t\t\texpected,\n\t\t\t);\n\t\t}\n\t\tconst sdkFile = ts.isIdentifier(callee) && this.sdkDeclaration(callee);\n\t\tif (\n\t\t\tts.isIdentifier(callee) &&\n\t\t\tsdkFile &&\n\t\t\tcallee.text === \"cancelAsync\" &&\n\t\t\tsdkModule(sdkFile) === sdkModules.async &&\n\t\t\tnode.arguments.length\n\t\t) {\n\t\t\treturn this.cancelOwner(node, frame);\n\t\t}\n\t\tif (ts.isIdentifier(callee) && sdkFile) {\n\t\t\treturn this.sdk(callee.text, sdkModule(sdkFile), node, frame);\n\t\t}\n\t\treturn this.invokeCall(target, node, frame, expected);\n\t}\n\n\t/** `receiver.name(…)`: what the language and SDK provide on the receiver, or its method. */\n\tprivate method(\n\t\tnode: ts.CallExpression,\n\t\tcallee: ts.PropertyAccessExpression,\n\t\tframe: Frame,\n\t\texpected: ts.Type | undefined,\n\t): Value {\n\t\tconst name = callee.name.text;\n\t\tconst checker = this.context.checker;\n\t\tif (name === \"from\" && isGlobal(checker, callee.expression, \"Array\")) {\n\t\t\treturn this.arrayFrom(node, frame);\n\t\t}\n\t\tif (callee.expression.kind === ts.SyntaxKind.SuperKeyword) {\n\t\t\treturn this.invokeCall(\n\t\t\t\tthis.expressions.superMember(callee, frame),\n\t\t\t\tnode,\n\t\t\t\tframe,\n\t\t\t\texpected,\n\t\t\t);\n\t\t}\n\t\tif (isGlobal(checker, callee.expression, \"Math\")) {\n\t\t\treturn this.math(name, node, frame);\n\t\t}\n\t\tif (name === \"values\" && isGlobal(checker, callee.expression, \"Object\")) {\n\t\t\treturn this.objectValues(node, frame);\n\t\t}\n\t\tif (this.telemetryCall(callee)) {\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: this.telemetry(node, callee, frame),\n\t\t\t\tdeclared: checker.getTypeAtLocation(node),\n\t\t\t};\n\t\t}\n\t\tif (isPromiseLink(node) && this.isPromise(callee.expression)) {\n\t\t\treturn this.promiseLink(node, callee, frame);\n\t\t}\n\t\tconst iterated = this.expressions.iterators.call(node, frame);\n\t\tif (iterated) {\n\t\t\treturn iterated;\n\t\t}\n\t\tconst receiver = this.receiver(callee.expression, frame);\n\t\tif (receiver.kind === \"static\" && receiver.node.captured.kind === \"task\") {\n\t\t\treturn this.taskCall(receiver.node, name, node, frame);\n\t\t}\n\t\tconst counted = this.expressions.iterators.arrayCall(\n\t\t\tname,\n\t\t\treceiver,\n\t\t\tnode,\n\t\t\tframe,\n\t\t);\n\t\tif (counted) {\n\t\t\treturn counted;\n\t\t}\n\t\tif (receiver.kind === \"choice\") {\n\t\t\tconst call = () =>\n\t\t\t\tthis.expressions.references.call(receiver, name, node, frame, expected);\n\t\t\treturn callee.questionDotToken && receiver.optional\n\t\t\t\t? this.expressions.chained(receiver, call, node, frame)\n\t\t\t\t: call();\n\t\t}\n\t\tconst items = this.expressions.items(receiver);\n\t\tconst filtered = this.expressions.filteredArrays.call(\n\t\t\tname,\n\t\t\treceiver,\n\t\t\titems,\n\t\t\tnode,\n\t\t\tframe,\n\t\t);\n\t\tif (filtered) {\n\t\t\treturn filtered;\n\t\t}\n\t\tif (items && isArrayMethod(name)) {\n\t\t\treturn this.arrayMethod(name, receiver, items, node, frame);\n\t\t}\n\t\tconst method = this.expressions.member(receiver, name, callee, frame);\n\t\tif (\n\t\t\tnode.questionDotToken &&\n\t\t\tmethod.kind === \"const\" &&\n\t\t\tmethod.value === undefined\n\t\t) {\n\t\t\treturn constant(undefined);\n\t\t}\n\t\tif (method.kind === \"static\" && method.node.captured.kind === \"service\") {\n\t\t\treturn this.serviceCall(method.node.captured.path, node, frame);\n\t\t}\n\t\treturn this.invokeCall(method, node, frame, expected);\n\t}\n\n\t/**\n\t * What a method is called on. An element of an array of objects setup built, at an index decided\n\t * at run time, is a reference to whichever it is, so the call runs that object's method.\n\t */\n\tprivate receiver(node: ts.Expression, frame: Frame): Value {\n\t\tconst inner = unwrapped(node);\n\t\tif (!ts.isElementAccessExpression(inner)) {\n\t\t\treturn this.expressions.expression(node, frame);\n\t\t}\n\t\tconst object = this.expressions.expression(inner.expression, frame);\n\t\tconst index = this.expressions.expression(inner.argumentExpression, frame);\n\t\tconst items =\n\t\t\tobject.kind === \"static\" && object.node.captured.kind === \"array\"\n\t\t\t\t? this.expressions.items(object)\n\t\t\t\t: undefined;\n\t\tconst chosen =\n\t\t\titems?.every(\n\t\t\t\t(item) =>\n\t\t\t\t\titem.kind === \"static\" && item.node.captured.kind === \"instance\",\n\t\t\t) &&\n\t\t\tthis.expressions.filteredArrays.indexed(\n\t\t\t\titems,\n\t\t\t\tindex,\n\t\t\t\t{ fromEnd: false },\n\t\t\t\tinner,\n\t\t\t\tframe,\n\t\t\t);\n\t\treturn chosen || this.expressions.element(object, index, inner, frame);\n\t}\n\n\t/** `cancelAsync(object)`: cancels the pending async calls of that object's methods. */\n\tprivate cancelOwner(node: ts.CallExpression, frame: Frame): Value {\n\t\tconst [argument, ...rest] = node.arguments;\n\t\tconst owner = argument && this.expressions.expression(argument, frame);\n\t\tif (\n\t\t\trest.length ||\n\t\t\towner?.kind !== \"static\" ||\n\t\t\towner.node.captured.kind !== \"instance\"\n\t\t) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"cancelAsync takes an object setup built, such as this, whose pending async calls it cancels, or no argument to cancel every pending async call.\",\n\t\t\t);\n\t\t}\n\t\tframe.emitter.line(`${this.expressions.canceller(owner.node)}();`);\n\t\treturn constant(undefined);\n\t}\n\n\t/** Whether an expression is a promise: an async call TypeScript types as one. */\n\tprivate isPromise(node: ts.Expression): boolean {\n\t\tconst type = this.context.checker.getTypeAtLocation(node);\n\t\treturn this.context.checker.getAwaitedType(type) !== type;\n\t}\n\n\t/**\n\t * `promise.then(fulfilled, rejected)` or `promise.catch(rejected)`, awaited in an async routine:\n\t * the promise awaited into a local and the callback run on its value, or on its error code in the\n\t * catch block of a try around both. The link's value is what the await of it gives.\n\t */\n\tprivate promiseLink(\n\t\tnode: ts.CallExpression,\n\t\tcallee: ts.PropertyAccessExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst name = callee.name.text;\n\t\tif (!frame.async || !awaitedLink(node)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t`.${name} runs only where an async function awaits it: in an async function, write const value = await call(); inside a try, and handle the value, or the error in catch.`,\n\t\t\t);\n\t\t}\n\t\tconst { checker, initializers } = this.context;\n\t\tconst [first, second] = node.arguments;\n\t\tconst fulfilled = name === \"then\" ? first : undefined;\n\t\tconst rejected = name === \"then\" ? second : first;\n\t\tconst result = checker.getAwaitedType(checker.getTypeAtLocation(node));\n\t\tconst resultType =\n\t\t\tresult && !(result.flags & ts.TypeFlags.Void) ? result : undefined;\n\t\tconst fulfil = (): Value => {\n\t\t\tconst value = this.awaitedValue(\n\t\t\t\tthis.expressions.expression(callee.expression, frame),\n\t\t\t\tframe,\n\t\t\t);\n\t\t\treturn fulfilled ? this.handled(fulfilled, [value], frame) : value;\n\t\t};\n\t\tif (!rejected) {\n\t\t\treturn fulfil();\n\t\t}\n\t\tconst local = resultType && frame.emitter.temporary();\n\t\tif (local && resultType) {\n\t\t\tframe.emitter.line(\n\t\t\t\t`let ${local}: ${this.expressions.localType(resultType)} = ${initializers.defaultOf(resultType)};`,\n\t\t\t);\n\t\t}\n\t\tconst store = (value: Value) => {\n\t\t\tif (local) {\n\t\t\t\tframe.emitter.line(\n\t\t\t\t\tmapped`${local} = ${this.context.dialect.assignmentText(value, resultType, undefined)};`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t\tframe.emitter.open(\"try {\");\n\t\tstore(fulfil());\n\t\tconst error = frame.emitter.local(\"error\");\n\t\tframe.emitter.reopen(`} catch (${error}) {`);\n\t\t// The callback is given the error code, as errorCode reads it from the catch binding.\n\t\tconst code = frame.emitter.local(\"code\");\n\t\tthis.context.imports.addSdk(sdkModules.async, \"errorCode\");\n\t\tframe.emitter.line(`const ${code}: UDINT = errorCode(${error});`);\n\t\tstore(\n\t\t\tthis.handled(\n\t\t\t\trejected,\n\t\t\t\t[\n\t\t\t\t\t{\n\t\t\t\t\t\tkind: \"code\",\n\t\t\t\t\t\ttext: code,\n\t\t\t\t\t\tdeclared: checker.getNumberType(),\n\t\t\t\t\t\tplace: true,\n\t\t\t\t\t\tiec: \"UDINT\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tframe,\n\t\t\t),\n\t\t);\n\t\tframe.emitter.close();\n\t\treturn local\n\t\t\t? { kind: \"code\", text: local, declared: resultType, place: true }\n\t\t\t: constant(undefined);\n\t}\n\n\t/** What awaiting a promise gives: the call awaited into a local, or nothing for a void one. */\n\tprivate awaitedValue(promise: Value, frame: Frame): Value {\n\t\tif (promise.kind !== \"code\") {\n\t\t\treturn promise;\n\t\t}\n\t\tif (!promise.declared || promise.declared.flags & ts.TypeFlags.Void) {\n\t\t\tframe.emitter.line(mapped`await ${promise.text};`);\n\t\t\treturn constant(undefined);\n\t\t}\n\t\tconst local = frame.emitter.temporary();\n\t\tframe.emitter.line(mapped`const ${local} = await ${promise.text};`);\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: local,\n\t\t\tdeclared: promise.declared,\n\t\t\tplace: true,\n\t\t\tiec: promise.iec,\n\t\t};\n\t}\n\n\t/** A link's callback run on `args`; an async callback's promise is awaited too. */\n\tprivate handled(callback: ts.Expression, args: Value[], frame: Frame): Value {\n\t\tconst target = this.expressions.expression(callback, frame);\n\t\tconst value = this.expressions.invoke(target, args, callback, frame);\n\t\tconst isAsync =\n\t\t\ttarget.kind === \"function\" &&\n\t\t\tts.canHaveModifiers(target.declaration) &&\n\t\t\tts\n\t\t\t\t.getModifiers(target.declaration)\n\t\t\t\t?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword);\n\t\treturn isAsync ? this.awaitedValue(value, frame) : value;\n\t}\n\n\t/** Calls a function value with the call's arguments, each evaluated for the parameter it is passed to. */\n\tprivate invokeCall(\n\t\ttarget: Value,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t\texpected: ts.Type | undefined,\n\t): Value {\n\t\treturn this.expressions.invoke(\n\t\t\ttarget,\n\t\t\tthis.expressions.inOrder(\n\t\t\t\tnode.arguments,\n\t\t\t\t(argument, index) => this.argument(argument, target, index, frame),\n\t\t\t\tframe,\n\t\t\t),\n\t\t\tnode,\n\t\t\tframe,\n\t\t\texpected,\n\t\t);\n\t}\n\n\tprivate argument(\n\t\tnode: ts.Expression,\n\t\tcallee: Value,\n\t\tindex: number,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst parameter =\n\t\t\tcallee.kind === \"function\" &&\n\t\t\t!ts.isGetAccessorDeclaration(callee.declaration)\n\t\t\t\t? callee.declaration.parameters[index]\n\t\t\t\t: undefined;\n\t\treturn this.expressions.expression(\n\t\t\tnode,\n\t\t\tframe,\n\t\t\tparameter && this.context.checker.getTypeAtLocation(parameter),\n\t\t);\n\t}\n\n\tprivate functionDeclaration(file: string, name: string): FunctionLike {\n\t\tconst source = this.context.sources.find((item) => item.fileName === file);\n\t\tfor (const statement of source?.statements ?? []) {\n\t\t\tif (\n\t\t\t\tts.isFunctionDeclaration(statement) &&\n\t\t\t\tstatement.name?.text === name\n\t\t\t) {\n\t\t\t\treturn statement;\n\t\t\t}\n\t\t\tif (ts.isVariableStatement(statement)) {\n\t\t\t\tfor (const declaration of statement.declarationList.declarations) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tts.isIdentifier(declaration.name) &&\n\t\t\t\t\t\tdeclaration.name.text === name &&\n\t\t\t\t\t\tdeclaration.initializer &&\n\t\t\t\t\t\t(ts.isArrowFunction(declaration.initializer) ||\n\t\t\t\t\t\t\tts.isFunctionExpression(declaration.initializer))\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn declaration.initializer;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthrow new Error(`${file}: no function ${name}.`);\n\t}\n\n\t/** The SDK declaration file of the function `callee` names, or null when the SDK doesn't declare it. */\n\tprivate sdkDeclaration(callee: ts.Identifier): string | null {\n\t\tconst sdkFile = this.context.sdkFile;\n\t\tconst symbol = symbolAt(this.context.checker, callee);\n\t\tif (symbol === undefined || !declaredBySdk(sdkFile, symbol)) {\n\t\t\treturn null;\n\t\t}\n\t\treturn (\n\t\t\tsymbol.declarations\n\t\t\t\t?.map((declaration) => declaration.getSourceFile().fileName)\n\t\t\t\t.find((file) => inSdk(sdkFile, file)) ?? null\n\t\t);\n\t}\n\n\t/** A method of `@tsplc/compiler/telemetry`'s `telemetry`. */\n\tprivate telemetryCall(callee: ts.PropertyAccessExpression): boolean {\n\t\tconst declaration = this.context.checker.getSymbolAtLocation(callee.name)\n\t\t\t?.declarations?.[0];\n\t\treturn (\n\t\t\tdeclaration !== undefined &&\n\t\t\tisTelemetryDeclaration(this.context.sdkFile, declaration)\n\t\t);\n\t}\n\n\t/**\n\t * Keeps a telemetry call as written, with its values specialized: the analyzer checks and\n\t * lowers it, and needs its name, message and property names as they are.\n\t */\n\tprivate telemetry(\n\t\tnode: ts.CallExpression,\n\t\tcallee: ts.PropertyAccessExpression,\n\t\tframe: Frame,\n\t): Mapped {\n\t\tconst { checker, dialect } = this.context;\n\t\tconst value = (argument: ts.Expression): Part =>\n\t\t\tts.isCallExpression(argument) &&\n\t\t\tts.isPropertyAccessExpression(argument.expression) &&\n\t\t\tthis.telemetryCall(argument.expression)\n\t\t\t\t? this.telemetry(argument, argument.expression, frame)\n\t\t\t\t: // A folded enum field keeps its type, so it is sent as its member's name.\n\t\t\t\t\tdialect.code(\n\t\t\t\t\t\tthis.expressions.expression(argument, frame),\n\t\t\t\t\t\tchecker.getTypeAtLocation(argument),\n\t\t\t\t\t);\n\t\tconst args = node.arguments.map((argument): Part => {\n\t\t\tif (\n\t\t\t\tts.isStringLiteral(argument) ||\n\t\t\t\tts.isNoSubstitutionTemplateLiteral(argument)\n\t\t\t) {\n\t\t\t\treturn copied(argument);\n\t\t\t}\n\t\t\tif (ts.isObjectLiteralExpression(argument)) {\n\t\t\t\treturn this.telemetryProperties(argument, value, frame);\n\t\t\t}\n\t\t\tconst argumentType = checker.getTypeAtLocation(argument);\n\t\t\tif (\n\t\t\t\targumentType.flags & ts.TypeFlags.Object &&\n\t\t\t\t!checker.isArrayType(argumentType)\n\t\t\t) {\n\t\t\t\tconst fields = this.expressions\n\t\t\t\t\t.recordFields(argument, frame)\n\t\t\t\t\t.map(\n\t\t\t\t\t\t([name, field]) =>\n\t\t\t\t\t\t\tmapped`${name}: ${dialect.code(field, undefined)}`,\n\t\t\t\t\t);\n\t\t\t\treturn mapped`{ ${joined(fields, \", \")} }`;\n\t\t\t}\n\t\t\treturn value(argument);\n\t\t});\n\t\tthis.context.imports.addSdk(sdkModules.telemetry, \"telemetry\");\n\t\treturn from(\n\t\t\tnode,\n\t\t\tmapped`telemetry.${callee.name.text}(${joined(args, \", \")})`,\n\t\t);\n\t}\n\n\tprivate telemetryProperties(\n\t\targument: ts.ObjectLiteralExpression,\n\t\tvalue: (argument: ts.Expression) => Part,\n\t\tframe: Frame,\n\t): Mapped {\n\t\tconst { checker, dialect } = this.context;\n\t\tconst properties = argument.properties.flatMap((property): Part[] => {\n\t\t\tif (ts.isShorthandPropertyAssignment(property)) {\n\t\t\t\treturn [\n\t\t\t\t\tmapped`${copied(property.name)}: ${dialect.code(this.expressions.shorthand(property, frame), checker.getTypeAtLocation(property.name))}`,\n\t\t\t\t];\n\t\t\t}\n\t\t\tif (ts.isSpreadAssignment(property)) {\n\t\t\t\treturn this.expressions\n\t\t\t\t\t.recordFields(property.expression, frame)\n\t\t\t\t\t.map(\n\t\t\t\t\t\t([name, field]) =>\n\t\t\t\t\t\t\tmapped`${name}: ${dialect.code(field, undefined)}`,\n\t\t\t\t\t);\n\t\t\t}\n\t\t\tif (!ts.isPropertyAssignment(property)) {\n\t\t\t\tthrow new SpecializeError(property, \"Name each telemetry property.\");\n\t\t\t}\n\t\t\treturn [mapped`${copied(property.name)}: ${value(property.initializer)}`];\n\t\t});\n\t\treturn mapped`{ ${joined(properties, \", \")} }`;\n\t}\n\n\t/** An SDK function scan code calls, such as the PLC clock. */\n\tprivate sdk(\n\t\tname: string,\n\t\tmodule: string,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\t// A record built in scan code, such as fetch's `json`, is written as the type it was declared.\n\t\tconst code = (argument: ts.Expression) => {\n\t\t\tconst value = this.expressions.expression(argument, frame);\n\t\t\tif (module === sdkModules.types) {\n\t\t\t\trefuseTimeArgument(name, value, argument);\n\t\t\t}\n\t\t\treturn this.context.dialect.code(\n\t\t\t\tvalue,\n\t\t\t\tvalue.kind === \"virtual\"\n\t\t\t\t\t? this.context.checker.getTypeAtLocation(argument)\n\t\t\t\t\t: undefined,\n\t\t\t);\n\t\t};\n\t\t// An options record, such as fetch's, is the SDK's own type: its fields are written as given.\n\t\tconst args = node.arguments.map((argument) =>\n\t\t\tts.isObjectLiteralExpression(argument)\n\t\t\t\t? mapped`{ ${joined(\n\t\t\t\t\t\targument.properties.map((property) => {\n\t\t\t\t\t\t\tif (ts.isShorthandPropertyAssignment(property)) {\n\t\t\t\t\t\t\t\treturn mapped`${copied(property.name)}: ${this.context.dialect.code(this.expressions.shorthand(property, frame), undefined)}`;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!ts.isPropertyAssignment(property)) {\n\t\t\t\t\t\t\t\tthrow new SpecializeError(property, \"Name each option.\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn mapped`${copied(property.name)}: ${code(property.initializer)}`;\n\t\t\t\t\t\t}),\n\t\t\t\t\t\t\", \",\n\t\t\t\t\t)} }`\n\t\t\t\t: code(argument),\n\t\t);\n\t\t// A type argument names the operation's IEC type, which no resolved TypeScript type keeps.\n\t\tconst typeArguments = (node.typeArguments ?? []).map((argument) =>\n\t\t\telementaryType(argument.getText())\n\t\t\t\t? argument.getText()\n\t\t\t\t: this.context.layouts.text(\n\t\t\t\t\t\tthis.context.checker.getTypeFromTypeNode(argument),\n\t\t\t\t\t),\n\t\t);\n\t\tconst generic = typeArguments.length ? `<${typeArguments.join(\", \")}>` : \"\";\n\t\tthis.context.imports.addSdk(module, name);\n\t\tconst text = mapped`${name}${generic}(${joined(args, \", \")})`;\n\t\tconst declared = this.context.checker.getTypeAtLocation(node);\n\t\t// A record the SDK returns is held in a const its own declaration types, so its fields are read\n\t\t// from storage and keep the widths the SDK gives them.\n\t\tif (module === sdkModules.async && name === \"asyncDiagnostics\") {\n\t\t\tconst local = frame.emitter.temporary();\n\t\t\tframe.emitter.line(mapped`const ${local} = ${text};`);\n\t\t\treturn { kind: \"code\", text: local, declared, place: true };\n\t\t}\n\t\t// A numeric operation's result is of the IEC type its type argument names, as `div<UDINT>` is,\n\t\t// or else the one its declaration names, as errorCode's UDINT.\n\t\tconst [width] = typeArguments;\n\t\tconst iec =\n\t\t\twidth && elementaryType(width)\n\t\t\t\t? width\n\t\t\t\t: this.context.layouts.iecName(\n\t\t\t\t\t\tsymbolAt(this.context.checker, node.expression)?.valueDeclaration,\n\t\t\t\t\t);\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext,\n\t\t\tdeclared,\n\t\t\t...(iec && declared.flags & ts.TypeFlags.NumberLike && { iec }),\n\t\t};\n\t}\n\n\tprivate math(name: string, node: ts.CallExpression, frame: Frame): Value {\n\t\tconst args = node.arguments.map((argument) =>\n\t\t\tthis.expressions.expression(argument, frame),\n\t\t);\n\t\tconst values = args.flatMap((arg) =>\n\t\t\targ.kind === \"const\" && typeof arg.value === \"number\" ? [arg.value] : [],\n\t\t);\n\t\tconst fold = mathFolds.get(name);\n\t\tif (fold && values.length === args.length) {\n\t\t\treturn constant(finite(fold(...values), node));\n\t\t}\n\t\tif (name === \"random\") {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"Math.random has no PLC equivalent: keep a pseudo-random sequence in a UDINT field instead, stepped each time with wrapAdd and wrapMultiply from @tsplc/compiler/types.\",\n\t\t\t);\n\t\t}\n\t\tconst declared = this.context.checker.getTypeAtLocation(node);\n\t\tswitch (name) {\n\t\t\tcase \"abs\": {\n\t\t\t\tconst [operand] = args;\n\t\t\t\tif (!operand) {\n\t\t\t\t\tthrow new SpecializeError(node, \"Math.abs needs a value.\");\n\t\t\t\t}\n\t\t\t\tconst held =\n\t\t\t\t\toperand.kind === \"code\"\n\t\t\t\t\t\t? this.expressions.hold(operand, frame, comparedOperand)\n\t\t\t\t\t\t: operand;\n\t\t\t\tconst text = this.context.dialect.code(held, undefined);\n\t\t\t\t// A float negates exactly; an integer's most negative value wraps to itself, as `0 - x` does.\n\t\t\t\tconst negated = floatIec(held) ? mapped`-${text}` : mapped`0 - ${text}`;\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"code\",\n\t\t\t\t\ttext: mapped`(${text} < 0 ? ${negated} : ${text})`,\n\t\t\t\t\tdeclared,\n\t\t\t\t\tiec: held.kind === \"code\" ? held.iec : undefined,\n\t\t\t\t};\n\t\t\t}\n\t\t\tcase \"min\":\n\t\t\tcase \"max\": {\n\t\t\t\tconst [left, right, ...rest] = args;\n\t\t\t\tif (left === undefined || right === undefined || rest.length) {\n\t\t\t\t\tthrow new SpecializeError(node, `Math.${name} takes two values.`);\n\t\t\t\t}\n\t\t\t\t// Each operand is read twice, so one that computes is held and runs once.\n\t\t\t\tconst operand = (value: Value) =>\n\t\t\t\t\tvalue.kind === \"code\"\n\t\t\t\t\t\t? this.expressions.hold(value, frame, comparedOperand)\n\t\t\t\t\t\t: value;\n\t\t\t\t// Both operands at one width, which the result keeps, so its range proof follows them.\n\t\t\t\tconst {\n\t\t\t\t\ttexts: [first, second],\n\t\t\t\t\tiec,\n\t\t\t\t} = this.context.dialect.arithmetic(operand(left), operand(right));\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"code\",\n\t\t\t\t\ttext: mapped`(${first} ${name === \"min\" ? \"<\" : \">\"} ${second} ? ${first} : ${second})`,\n\t\t\t\t\tdeclared,\n\t\t\t\t\tiec,\n\t\t\t\t};\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn this.floatMath(name, args, node, frame);\n\t\t}\n\t}\n\n\t/**\n\t * A call of a task's `start`, `snapshot`, `cancel` or `reset`, through the binding a kept module\n\t * defines the task in, which the async lowering compiles as the dialect's task.\n\t */\n\tprivate taskCall(\n\t\ttask: ModelNode,\n\t\tname: string | null,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst { model, checker, dialect, imports } = this.context;\n\t\tconst root = model.roots.find(\n\t\t\t(item) => item.value.kind === \"node\" && item.value.id === task.id,\n\t\t);\n\t\tif (!root || !this.context.isKept(root.file)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"Define a task in a module-level const of a module that holds only constants, tasks and the service client.\",\n\t\t\t);\n\t\t}\n\t\tconst work = this.workFunction(root.declaration);\n\t\tif (work) {\n\t\t\tthis.refuseStateInWork(work);\n\t\t}\n\t\tconst local = imports.kept.add(root.file, root.name);\n\t\tconst args = node.arguments.map((argument) => {\n\t\t\tconst contextual = checker.getContextualType(argument);\n\t\t\treturn dialect.code(\n\t\t\t\tthis.expressions.expression(argument, frame, contextual),\n\t\t\t\tcontextual,\n\t\t\t);\n\t\t});\n\t\t// Calling a background task itself runs it and gives a promise of its result, as awaiting does.\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext:\n\t\t\t\tname === null\n\t\t\t\t\t? mapped`${local}(${joined(args, \", \")})`\n\t\t\t\t\t: mapped`${local}.${name}(${joined(args, \", \")})`,\n\t\t\tdeclared:\n\t\t\t\tname === null\n\t\t\t\t\t? checker.getAwaitedType(checker.getTypeAtLocation(node))\n\t\t\t\t\t: checker.getTypeAtLocation(node),\n\t\t\ttypedByTask: true,\n\t\t\t...(name === null && { iec: this.context.layouts.iecName(work) }),\n\t\t};\n\t}\n\n\t/** The named async function a task definition runs. */\n\tprivate workFunction(\n\t\tdeclaration: ts.VariableDeclaration | ts.BindingElement,\n\t): ts.FunctionDeclaration | undefined {\n\t\tconst init = declaration.initializer;\n\t\tconst work =\n\t\t\tinit && ts.isCallExpression(init) ? init.arguments[0] : undefined;\n\t\tconst symbol =\n\t\t\twork && ts.isIdentifier(work)\n\t\t\t\t? this.context.checker.getSymbolAtLocation(work)\n\t\t\t\t: undefined;\n\t\tconst fn =\n\t\t\tsymbol && unaliased(this.context.checker, symbol).valueDeclaration;\n\t\treturn fn && ts.isFunctionDeclaration(fn) && fn.body ? fn : undefined;\n\t}\n\n\t/**\n\t * A task's work runs on its own, given only its arguments; the program's state is compiled into\n\t * storage the kept module the task lives in can't import, so the work can't read it.\n\t */\n\tprivate refuseStateInWork(fn: ts.FunctionDeclaration): void {\n\t\tconst visit = (node: ts.Node): void => {\n\t\t\tif (ts.isIdentifier(node)) {\n\t\t\t\tconst read = valueSymbol(this.context.checker, node);\n\t\t\t\tconst declared =\n\t\t\t\t\tread && unaliased(this.context.checker, read).valueDeclaration;\n\t\t\t\tconst file = declared?.getSourceFile().fileName;\n\t\t\t\tif (\n\t\t\t\t\tdeclared &&\n\t\t\t\t\tfile &&\n\t\t\t\t\tmoduleLevel(declared) &&\n\t\t\t\t\tthis.context.sources.some((source) => source.fileName === file) &&\n\t\t\t\t\t!this.context.isKept(file)\n\t\t\t\t) {\n\t\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\t`A task's work runs on its own, given only its arguments, so it can't read ${node.text} from a module of program state: pass what it needs as arguments, and use its result in scan code.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tts.forEachChild(node, visit);\n\t\t};\n\t\tts.forEachChild(fn, visit);\n\t}\n\n\tprivate serviceCall(\n\t\tpath: string,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst { model, checker, dialect, imports } = this.context;\n\t\tconst client = model.roots.find((root) => {\n\t\t\tconst value = model.node(root.value);\n\t\t\treturn value?.captured.kind === \"service\" && value.captured.path === \"\";\n\t\t});\n\t\tif (!client) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"Create the service client in a module-level const, and import it where scan code calls it: the PLC calls the server through that one client, with the types the server's router gives each call.\",\n\t\t\t);\n\t\t}\n\t\tconst local = imports.kept.add(client.file, client.name);\n\t\tconst args = node.arguments.map((argument) => {\n\t\t\tconst contextual = checker.getContextualType(argument);\n\t\t\treturn dialect.code(\n\t\t\t\tthis.expressions.expression(argument, frame, contextual),\n\t\t\t\tcontextual,\n\t\t\t);\n\t\t});\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: mapped`${local}.${path}(${joined(args, \", \")})`,\n\t\t\tdeclared: checker.getTypeAtLocation(node),\n\t\t};\n\t}\n\n\t/** An array method on elements known now, which unrolls into code for each element. */\n\tprivate arrayMethod(\n\t\tname: ArrayMethod,\n\t\treceiver: Value,\n\t\titems: Value[],\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tswitch (name) {\n\t\t\tcase \"entries\":\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"virtual\",\n\t\t\t\t\titems: items.map((item, index) => ({\n\t\t\t\t\t\tkind: \"virtual\",\n\t\t\t\t\t\titems: [constant(index), item],\n\t\t\t\t\t})),\n\t\t\t\t};\n\t\t\tcase \"slice\":\n\t\t\t\treturn this.slice(items, node, frame);\n\t\t\tcase \"map\": {\n\t\t\t\tconst apply = this.callback(node, frame);\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"virtual\",\n\t\t\t\t\titems: items.map((item, index) =>\n\t\t\t\t\t\tthis.settle(apply([item, constant(index)]), frame),\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}\n\t\t\tcase \"forEach\": {\n\t\t\t\tconst apply = this.callback(node, frame);\n\t\t\t\titems.forEach((item, index) => {\n\t\t\t\t\tconst result = apply([item, constant(index)]);\n\t\t\t\t\tif (result.kind === \"code\") {\n\t\t\t\t\t\tframe.emitter.line(mapped`${result.text};`);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn constant(undefined);\n\t\t\t}\n\t\t\tcase \"some\":\n\t\t\tcase \"every\":\n\t\t\tcase \"includes\":\n\t\t\t\treturn this.expressions.iterators.unrolled(name, items, node, frame);\n\t\t\tcase \"reduce\":\n\t\t\tcase \"reduceRight\":\n\t\t\t\treturn this.reduce(\n\t\t\t\t\tname,\n\t\t\t\t\titems,\n\t\t\t\t\tnode,\n\t\t\t\t\tframe,\n\t\t\t\t\tthis.callback(node, frame),\n\t\t\t\t);\n\t\t\tcase \"find\":\n\t\t\tcase \"findLast\":\n\t\t\t\treturn this.searches.find(\n\t\t\t\t\titems,\n\t\t\t\t\tnode,\n\t\t\t\t\tframe,\n\t\t\t\t\t{ last: name === \"findLast\" },\n\t\t\t\t\tthis.callback(node, frame),\n\t\t\t\t);\n\t\t\tcase \"findIndex\":\n\t\t\tcase \"findLastIndex\":\n\t\t\t\treturn this.searches.findIndex(\n\t\t\t\t\titems,\n\t\t\t\t\tframe,\n\t\t\t\t\t{ last: name === \"findLastIndex\" },\n\t\t\t\t\tthis.callback(node, frame),\n\t\t\t\t);\n\t\t\tcase \"indexOf\":\n\t\t\tcase \"lastIndexOf\":\n\t\t\t\treturn this.searches.indexOf(items, node, frame, {\n\t\t\t\t\tlast: name === \"lastIndexOf\",\n\t\t\t\t});\n\t\t\tcase \"fill\":\n\t\t\t\treturn this.searches.fill(receiver, items, node, frame);\n\t\t\tcase \"at\":\n\t\t\t\treturn this.searches.at(items, node, frame);\n\t\t\tcase \"concat\":\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"virtual\",\n\t\t\t\t\titems: [\n\t\t\t\t\t\t...items,\n\t\t\t\t\t\t...node.arguments.flatMap((argument) => {\n\t\t\t\t\t\t\tconst value = this.expressions.expression(argument, frame);\n\t\t\t\t\t\t\treturn this.expressions.items(value) ?? [value];\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t}\n\t}\n\n\t/** An array method's callback as the step it runs on elements. */\n\tprivate callback(\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): (args: Value[]) => Value {\n\t\tconst callback = callbackArgument(node, frame, this.expressions);\n\t\treturn (args) => this.expressions.invoke(callback, args, node, frame);\n\t}\n\n\t/** `slice(start, end)` with bounds setup fixed picks elements now; one decided at run time is read in place. */\n\tprivate slice(\n\t\titems: readonly Value[],\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst [start, end] = node.arguments.map((argument) =>\n\t\t\tthis.expressions.expression(argument, frame),\n\t\t);\n\t\tconst startIndex = sliceBound(start);\n\t\tconst endIndex = sliceBound(end);\n\t\tif (startIndex === null || endIndex === null) {\n\t\t\treturn this.expressions.iterators.sliced(\n\t\t\t\titems,\n\t\t\t\t{ start, end },\n\t\t\t\tnode,\n\t\t\t\tframe,\n\t\t\t);\n\t\t}\n\t\treturn { kind: \"virtual\", items: items.slice(startIndex, endIndex) };\n\t}\n\n\t/** `reduce(step, initial)` and `reduceRight`: each step's result is the next one's accumulator. */\n\tprivate reduce(\n\t\tname: \"reduce\" | \"reduceRight\",\n\t\titems: readonly Value[],\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t\tapply: (args: Value[]) => Value,\n\t): Value {\n\t\tconst order = ordered(items, { last: name === \"reduceRight\" });\n\t\tconst [, initialNode] = node.arguments;\n\t\tconst [first] = order;\n\t\tconst initial = initialNode\n\t\t\t? this.expressions.expression(initialNode, frame)\n\t\t\t: first?.[1];\n\t\tif (!initial) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t`${name} of an array with no elements needs an initial value.`,\n\t\t\t);\n\t\t}\n\t\treturn (initialNode ? order : order.slice(1)).reduce(\n\t\t\t(accumulator, [index, item]) =>\n\t\t\t\tthis.settle(apply([accumulator, item, constant(index)]), frame),\n\t\t\tinitial,\n\t\t);\n\t}\n\n\t/**\n\t * Math on floating values, through the SDK's math functions. An integer argument becomes LREAL\n\t * exactly, so its proved range carries over; the result is floating, and converts as IEC assignment\n\t * does where it is stored as a number.\n\t */\n\tfloatMath(\n\t\tname: string,\n\t\targs: readonly Value[],\n\t\tnode: ts.Expression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst declared = this.context.checker.getTypeAtLocation(node);\n\t\tconst [first, second] = args;\n\t\tif (!first) {\n\t\t\tthrow new SpecializeError(node, `Math.${name} needs a value.`);\n\t\t}\n\t\tconst type = floatIec(first) ?? (second && floatIec(second)) ?? \"LREAL\";\n\t\tconst float = (value: Value) => this.asFloat(value, type);\n\t\tconst sdk = (fn: string, ...operands: readonly Part[]): Value => {\n\t\t\tthis.context.imports.addSdk(sdkModules.types, fn);\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: mapped`${fn}<${type}>(${joined(operands, \", \")})`,\n\t\t\t\tdeclared,\n\t\t\t\tiec: type,\n\t\t\t};\n\t\t};\n\t\tconst elementary = elementaryNames.get(name);\n\t\tif (elementary) {\n\t\t\treturn sdk(elementary, float(first));\n\t\t}\n\t\tif (name === \"pow\" && second) {\n\t\t\treturn sdk(\"expt\", float(first), float(second));\n\t\t}\n\t\tconst rounding = roundings.get(name);\n\t\tif (rounding) {\n\t\t\tif (!floatIec(first)) {\n\t\t\t\treturn first;\n\t\t\t}\n\t\t\treturn this.rounded(name, rounding, first, type, frame, declared);\n\t\t}\n\t\tif (name === \"sign\") {\n\t\t\tconst held = this.expressions.held(first, frame);\n\t\t\tconst zero = floatIec(first) ? \"0.0\" : \"0\";\n\t\t\tconst text = this.context.dialect.code(held, undefined);\n\t\t\treturn {\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: mapped`(${text} > ${zero} ? 1 : (${text} < ${zero} ? -1 : 0))`,\n\t\t\t\tdeclared,\n\t\t\t};\n\t\t}\n\t\tthrow new SpecializeError(\n\t\t\tnode,\n\t\t\t`Math.${name} has no PLC function whose result can be proved finite.`,\n\t\t);\n\t}\n\n\t/** A floating value toward zero, down, up or to the nearest whole value, as floating. */\n\tprivate rounded(\n\t\tname: string,\n\t\trounding: Rounding,\n\t\tvalue: Value,\n\t\ttype: string,\n\t\tframe: Frame,\n\t\tdeclared: ts.Type,\n\t): Value {\n\t\tthis.context.imports.addSdk(sdkModules.types, \"trunc\");\n\t\tconst text = this.context.dialect.code(value, undefined);\n\t\t// Math.round takes halves up: the nearest whole value is the floor of the value plus a half.\n\t\tconst source = name === \"round\" ? mapped`(${text} + 0.5)` : text;\n\t\tconst held = frame.emitter.temporary();\n\t\tframe.emitter.line(mapped`const ${held}: ${type} = ${source};`);\n\t\tconst whole = frame.emitter.temporary();\n\t\tframe.emitter.line(`const ${whole}: ${type} = trunc<${type}>(${held});`);\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: rounding(whole, held),\n\t\t\tdeclared,\n\t\t\tiec: type,\n\t\t\twhole: true,\n\t\t};\n\t}\n\n\t/** A value as the floating type: as it is when it already is, else converted exactly. */\n\tprivate asFloat(value: Value, type: string): Part {\n\t\tif (floatIec(value) || value.kind === \"const\") {\n\t\t\treturn this.context.dialect.code(value, undefined);\n\t\t}\n\t\tthis.context.imports.addSdk(sdkModules.types, \"exact\");\n\t\treturn mapped`exact<${type}>(${this.context.dialect.code(value, undefined)})`;\n\t}\n\n\t/**\n\t * `Array.from({ length }, make)` with a length known now: an array of that many values, as setup\n\t * builds one. Its length is fixed, so it needs no storage beyond its own.\n\t */\n\tprivate arrayFrom(node: ts.CallExpression, frame: Frame): Value {\n\t\tconst [shape, make] = node.arguments;\n\t\tconst length =\n\t\t\tshape &&\n\t\t\tts.isObjectLiteralExpression(shape) &&\n\t\t\tthis.expressions.member(\n\t\t\t\tthis.expressions.expression(shape, frame),\n\t\t\t\t\"length\",\n\t\t\t\tshape,\n\t\t\t\tframe,\n\t\t\t);\n\t\tif (\n\t\t\t!length ||\n\t\t\tlength.kind !== \"const\" ||\n\t\t\ttypeof length.value !== \"number\"\n\t\t) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"Array.from needs a length known when the program compiles.\",\n\t\t\t);\n\t\t}\n\t\tconst maker = make && this.expressions.expression(make, frame);\n\t\treturn {\n\t\t\tkind: \"virtual\",\n\t\t\titems: Array.from({ length: length.value }, (_, index) =>\n\t\t\t\tmaker\n\t\t\t\t\t? this.expressions.invoke(\n\t\t\t\t\t\t\tmaker,\n\t\t\t\t\t\t\t[constant(undefined), constant(index)],\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\tframe,\n\t\t\t\t\t\t)\n\t\t\t\t\t: constant(undefined),\n\t\t\t),\n\t\t};\n\t}\n\n\t/** `Object.values(record)` of a record setup built: its fields' values, in its order. */\n\tprivate objectValues(node: ts.CallExpression, frame: Frame): Value {\n\t\tconst [argument] = node.arguments;\n\t\tconst object = argument && this.expressions.expression(argument, frame);\n\t\tif (object?.kind !== \"static\" || object.node.captured.kind !== \"object\") {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"Object.values needs a record setup built.\",\n\t\t\t);\n\t\t}\n\t\treturn {\n\t\t\tkind: \"virtual\",\n\t\t\titems: Object.entries(object.node.captured.fields).map(([field, value]) =>\n\t\t\t\tthis.context.storage.fromCaptured(value, object.node, {\n\t\t\t\t\tkind: \"field\",\n\t\t\t\t\tname: field,\n\t\t\t\t}),\n\t\t\t),\n\t\t};\n\t}\n\n\t/**\n\t * `structuredClone(value)`: a record or array of its own, as the dialect's `copy` makes one, for\n\t * code that changes it and stores it back.\n\t */\n\tprivate cloned(node: ts.CallExpression, frame: Frame): Value {\n\t\tconst [argument] = node.arguments;\n\t\tif (!argument) {\n\t\t\tthrow new SpecializeError(node, \"structuredClone needs a value.\");\n\t\t}\n\t\tconst value = this.expressions.expression(argument, frame);\n\t\t// A primitive is a value already: its clone is itself.\n\t\tif (\n\t\t\tvalue.kind !== \"code\" ||\n\t\t\t(value.declared && !(value.declared.flags & ts.TypeFlags.Object))\n\t\t) {\n\t\t\treturn value;\n\t\t}\n\t\tthis.context.imports.addSdk(sdkModules.types, \"copy\");\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: mapped`copy(${value.text})`,\n\t\t\tdeclared: value.declared,\n\t\t\tiec: value.iec,\n\t\t\tlayout: value.layout,\n\t\t\tlength: value.length,\n\t\t};\n\t}\n\n\t/** Keeps a runtime result in a local, so later code reads it rather than repeating it. */\n\tprivate settle(value: Value, frame: Frame): Value {\n\t\treturn value.kind === \"code\"\n\t\t\t? this.expressions.hold(value, frame, settledResult)\n\t\t\t: value;\n\t}\n}\n\n/** Whether a promise link is awaited, directly or as the promise of an outer link that is. */\nconst awaitedLink = (node: ts.CallExpression): boolean => {\n\tconst parent = node.parent;\n\tif (ts.isAwaitExpression(parent)) {\n\t\treturn true;\n\t}\n\tif (ts.isParenthesizedExpression(parent)) {\n\t\treturn ts.isAwaitExpression(parent.parent);\n\t}\n\treturn (\n\t\tts.isPropertyAccessExpression(parent) &&\n\t\tisPromiseLink(parent.parent) &&\n\t\tawaitedLink(parent.parent)\n\t);\n};\n\n/** Whether a declaration is a module's own: a top-level variable, function or class. */\nconst moduleLevel = (declaration: ts.Declaration): boolean => {\n\tif (ts.isVariableDeclaration(declaration)) {\n\t\treturn ts.isSourceFile(declaration.parent.parent.parent);\n\t}\n\treturn (\n\t\t(ts.isFunctionDeclaration(declaration) ||\n\t\t\tts.isClassDeclaration(declaration)) &&\n\t\tts.isSourceFile(declaration.parent)\n\t);\n};\n\n/**\n * A TIME or calendar constructor's argument, which the PLC stores as a constant: a duration known\n * when the program compiles, or a calendar text in its format.\n */\nconst refuseTimeArgument = (\n\tname: string,\n\tvalue: Value,\n\targument: ts.Expression,\n): void => {\n\tconst calendar = calendarFormats.get(name);\n\tif (!calendar) {\n\t\tif (durationNames.has(name) && value.kind !== \"const\") {\n\t\t\tthrow new SpecializeError(\n\t\t\t\targument,\n\t\t\t\t`${name}() makes a TIME constant, so its value must be known when the program compiles: a literal, a constant or a field only setup writes. To wait a time scan code computes, sleep in steps until now() has passed it.`,\n\t\t\t);\n\t\t}\n\t\treturn;\n\t}\n\tif (\n\t\tvalue.kind !== \"const\" ||\n\t\ttypeof value.value !== \"string\" ||\n\t\t!calendarLiteral(calendar.domain, value.value)\n\t) {\n\t\tthrow new SpecializeError(\n\t\t\targument,\n\t\t\t`${name}() takes a ${calendar.type} written as \"${calendar.format}\", known when the program compiles.`,\n\t\t);\n\t}\n};\n\n/** Array methods scan code calls on arrays setup built, which unroll. */\nconst arrayMethods = [\n\t\"entries\",\n\t\"slice\",\n\t\"map\",\n\t\"forEach\",\n\t\"some\",\n\t\"every\",\n\t\"reduce\",\n\t\"reduceRight\",\n\t\"find\",\n\t\"findLast\",\n\t\"findIndex\",\n\t\"findLastIndex\",\n\t\"indexOf\",\n\t\"lastIndexOf\",\n\t\"includes\",\n\t\"fill\",\n\t\"at\",\n\t\"concat\",\n] as const;\n\ntype ArrayMethod = (typeof arrayMethods)[number];\n\nconst isArrayMethod = (name: string): name is ArrayMethod =>\n\tarrayMethods.some((method) => method === name);\n\n/** A `map` or `reduce` step's result, held as its local type, or as a boolean when nothing declares one. */\nconst settledResult: Holding = {\n\twidth: false,\n\twiden: true,\n\tuntyped: \"boolean\",\n\trepeatable: false,\n};\n\n/** An operand Math.min or Math.max reads twice, held at its own width. */\nconst comparedOperand: Holding = {\n\twidth: true,\n\twiden: true,\n\tuntyped: \"number\",\n\trepeatable: false,\n};\n\n/** The Math function each of the SDK's elementary functions is called as in scan code. */\nconst mathNames: Readonly<\n\tRecord<ElementaryFunction, Extract<keyof Math, string>>\n> = {\n\tsqrt: \"sqrt\",\n\tln: \"log\",\n\tlog10: \"log10\",\n\texp: \"exp\",\n\tsin: \"sin\",\n\tcos: \"cos\",\n\ttan: \"tan\",\n\tasin: \"asin\",\n\tacos: \"acos\",\n\tatan: \"atan\",\n};\n\nconst elementaryNames = new Map<string, ElementaryFunction>(\n\telementaryFunctions.map((name) => [mathNames[name], name]),\n);\n\n/** The Math functions scan code calls, as a constant call folds: the elementary ones as iec computes them. */\nconst mathFolds = new Map<string, (...values: number[]) => number>([\n\t[\"abs\", Math.abs],\n\t[\"min\", Math.min],\n\t[\"max\", Math.max],\n\t[\"floor\", Math.floor],\n\t[\"ceil\", Math.ceil],\n\t[\"round\", Math.round],\n\t[\"trunc\", Math.trunc],\n\t[\"sign\", Math.sign],\n\t[\"pow\", Math.pow],\n\t[\"hypot\", Math.hypot],\n\t[\"atan2\", Math.atan2],\n\t[\"log2\", Math.log2],\n\t[\"log1p\", Math.log1p],\n\t[\"expm1\", Math.expm1],\n\t[\"cbrt\", Math.cbrt],\n\t[\"sinh\", Math.sinh],\n\t[\"cosh\", Math.cosh],\n\t[\"tanh\", Math.tanh],\n\t[\"asinh\", Math.asinh],\n\t[\"acosh\", Math.acosh],\n\t[\"atanh\", Math.atanh],\n\t[\"clz32\", Math.clz32],\n\t[\"imul\", Math.imul],\n\t[\"fround\", Math.fround],\n\t...elementaryFunctions.map((name): [string, (value: number) => number] => [\n\t\tmathNames[name],\n\t\telementaryValue[name],\n\t]),\n]);\n\n/** A rounding's result from a value's whole part toward zero, `whole`, and the value, `held`. */\ntype Rounding = (whole: string, held: string) => string;\n\nconst downward: Rounding = (whole, held) =>\n\t`(${whole} > ${held} ? ${whole} - 1.0 : ${whole})`;\n\n/** Math's roundings of a floating value; round is the floor of the value plus a half. */\nconst roundings = new Map<string, Rounding>([\n\t[\"floor\", downward],\n\t[\"round\", downward],\n\t[\"ceil\", (whole, held) => `(${whole} < ${held} ? ${whole} + 1.0 : ${whole})`],\n\t[\"trunc\", (whole) => whole],\n]);\n\n/** The floating IEC type a value has, if it is floating. */\nexport const floatIec = (value: Value): string | undefined =>\n\tvalue.kind === \"code\" &&\n\tvalue.iec !== undefined &&\n\telementaryType(value.iec)?.family === \"real\"\n\t\t? value.iec\n\t\t: undefined;\n\n/** A slice bound setup fixed, undefined when left out, or null when it is decided at run time. */\nconst sliceBound = (bound: Value | undefined): number | undefined | null => {\n\tif (!bound) {\n\t\treturn undefined;\n\t}\n\tif (bound.kind !== \"const\") {\n\t\treturn null;\n\t}\n\treturn typeof bound.value === \"number\" ? bound.value : undefined;\n};\n",
48
+ "import type ts from \"typescript\";\nimport { mapped } from \"../positions\";\nimport type { ExpressionSpecializer, SpecializeContext } from \"./expressions\";\nimport type { Frame } from \"./frame\";\nimport { constant, SpecializeError, type Value } from \"./values\";\n\n/**\n * Searches and writes over an array setup built, decided at run time. Setup fixed the array's\n * length, so each runs as one test or store per element, in the order JavaScript visits them.\n */\nexport class ArraySearches {\n\tconstructor(\n\t\tprivate readonly context: SpecializeContext,\n\t\tprivate readonly expressions: Pick<\n\t\t\tExpressionSpecializer,\n\t\t\t\"expression\" | \"held\" | \"localType\" | \"equality\" | \"assignments\"\n\t\t>,\n\t) {}\n\n\t/** `indexOf(target)` and `lastIndexOf(target)`: the first or last index of an equal element, or -1. */\n\tindexOf(\n\t\titems: readonly Value[],\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t\t{ last }: { last: boolean },\n\t): Value {\n\t\tconst target = searchTarget(node, frame, this.expressions);\n\t\treturn this.firstIndex(items, frame, { last }, (item) =>\n\t\t\tthis.expressions.equality(item, target, { negate: false }),\n\t\t);\n\t}\n\n\t/** `findIndex(test)` and `findLastIndex(test)`: the test runs on elements until one passes. */\n\tfindIndex(\n\t\titems: readonly Value[],\n\t\tframe: Frame,\n\t\t{ last }: { last: boolean },\n\t\tapply: (args: Value[]) => Value,\n\t): Value {\n\t\treturn this.firstIndex(items, frame, { last }, (item, index) =>\n\t\t\tapply([item, constant(index)]),\n\t\t);\n\t}\n\n\t/**\n\t * `find(test)` and `findLast(test)`: the element that passed, or undefined. Among objects setup\n\t * built the one that passes is chosen now; among values, at run time.\n\t */\n\tfind(\n\t\titems: readonly Value[],\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t\t{ last }: { last: boolean },\n\t\tapply: (args: Value[]) => Value,\n\t): Value {\n\t\tif (\n\t\t\titems.some((item) => item.kind === \"static\" || item.kind === \"function\")\n\t\t) {\n\t\t\treturn decidedFind(items, node, { last }, apply);\n\t\t}\n\t\tconst { checker, dialect } = this.context;\n\t\tconst declared = checker.getTypeAtLocation(node);\n\t\tconst element = checker.getNonNullableType(declared);\n\t\tconst found = frame.emitter.temporary();\n\t\tconst result = frame.emitter.temporary();\n\t\tframe.emitter.line(`let ${found}: boolean = false;`);\n\t\tframe.emitter.line(\n\t\t\tmapped`let ${result}: ${this.expressions.localType(declared)} = ${dialect.assignmentText(constant(undefined), declared, undefined)};`,\n\t\t);\n\t\tfor (const [index, item] of ordered(items, { last })) {\n\t\t\tframe.emitter.open(`if (!${found}) {`);\n\t\t\tconst test = apply([item, constant(index)]);\n\t\t\tif (test.kind !== \"const\" || test.value) {\n\t\t\t\tconst passed =\n\t\t\t\t\ttest.kind === \"const\" ? \"true\" : dialect.condition(test, node);\n\t\t\t\tframe.emitter.open(mapped`if (${passed}) {`);\n\t\t\t\tframe.emitter.line(\n\t\t\t\t\tmapped`${result} = ${dialect.wrapDefined(dialect.code(item, element), declared)};`,\n\t\t\t\t);\n\t\t\t\tframe.emitter.line(`${found} = true;`);\n\t\t\t\tframe.emitter.close();\n\t\t\t}\n\t\t\tframe.emitter.close();\n\t\t}\n\t\treturn { kind: \"code\", text: result, declared, place: true };\n\t}\n\n\t/** `fill(value, start?, end?)` stores the value in each element in range and is worth the array. */\n\tfill(\n\t\treceiver: Value,\n\t\titems: readonly Value[],\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst [valueNode, startNode, endNode] = node.arguments;\n\t\tif (!valueNode) {\n\t\t\tthrow new SpecializeError(node, \"fill needs a value.\");\n\t\t}\n\t\tconst value = this.expressions.held(\n\t\t\tthis.expressions.expression(valueNode, frame),\n\t\t\tframe,\n\t\t);\n\t\tconst [start, end] = [startNode, endNode].map((bound) =>\n\t\t\tbound ? this.constantIndex(bound, items.length, frame) : undefined,\n\t\t);\n\t\tfor (const item of items.slice(start ?? 0, end ?? items.length)) {\n\t\t\tthis.expressions.assignments.storeValue(item, value, node, frame);\n\t\t}\n\t\treturn receiver;\n\t}\n\n\t/** `at(index)` with an index setup fixed, counting back from the end when negative. */\n\tat(items: readonly Value[], node: ts.CallExpression, frame: Frame): Value {\n\t\tconst [indexNode] = node.arguments;\n\t\tif (!indexNode) {\n\t\t\tthrow new SpecializeError(node, \"at needs an index.\");\n\t\t}\n\t\tconst index = this.constantIndex(indexNode, items.length, frame);\n\t\treturn items[index] ?? constant(undefined);\n\t}\n\n\t/** The index of the first element whose test passes, or -1; tests stop once one has. */\n\tprivate firstIndex(\n\t\titems: readonly Value[],\n\t\tframe: Frame,\n\t\t{ last }: { last: boolean },\n\t\ttest: (item: Value, index: number) => Value,\n\t): Value {\n\t\tconst result = frame.emitter.temporary();\n\t\tframe.emitter.line(`let ${result}: number = -1;`);\n\t\tfor (const [index, item] of ordered(items, { last })) {\n\t\t\tframe.emitter.open(`if (${result} === -1) {`);\n\t\t\tconst passed = test(item, index);\n\t\t\tif (passed.kind === \"const\") {\n\t\t\t\tif (passed.value) {\n\t\t\t\t\tframe.emitter.line(`${result} = ${index};`);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tframe.emitter.line(\n\t\t\t\t\tmapped`if (${this.context.dialect.condition(passed, frame.emitter.origin)}) { ${result} = ${index}; }`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tframe.emitter.close();\n\t\t}\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: result,\n\t\t\tdeclared: this.context.checker.getNumberType(),\n\t\t\tplace: true,\n\t\t};\n\t}\n\n\tprivate constantIndex(\n\t\tnode: ts.Expression,\n\t\tlength: number,\n\t\tframe: Frame,\n\t): number {\n\t\tconst value = this.expressions.expression(node, frame);\n\t\tif (value.kind !== \"const\" || typeof value.value !== \"number\") {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"Index with a value setup fixed; the element is chosen when the program compiles.\",\n\t\t\t);\n\t\t}\n\t\treturn value.value < 0 ? length + value.value : value.value;\n\t}\n}\n\n/** Elements with their indexes, first to last or, for a search from the end, last to first. */\nexport const ordered = <T>(\n\titems: readonly T[],\n\t{ last }: { last: boolean },\n): [number, T][] => {\n\tconst indexed = [...items.entries()];\n\treturn last ? indexed.reverse() : indexed;\n};\n\n/** An array method's callback: its first argument, the test or step it runs on elements. */\nexport const callbackArgument = (\n\tnode: ts.CallExpression,\n\tframe: Frame,\n\texpressions: Pick<ExpressionSpecializer, \"expression\">,\n): Value => {\n\tconst [argument] = node.arguments;\n\tif (!argument) {\n\t\tthrow new SpecializeError(node, \"Pass a callback.\");\n\t}\n\treturn expressions.expression(argument, frame);\n};\n\n/** What `includes` and `indexOf` look for, held so each element is compared with the value it had at the call. */\nexport const searchTarget = (\n\tnode: ts.CallExpression,\n\tframe: Frame,\n\texpressions: Pick<ExpressionSpecializer, \"expression\" | \"held\">,\n): Value => {\n\tconst [argument] = node.arguments;\n\tif (!argument) {\n\t\tthrow new SpecializeError(node, \"Pass the value to look for.\");\n\t}\n\treturn expressions.held(expressions.expression(argument, frame), frame);\n};\n\n/** `find` and `findLast` among objects setup built, whose tests are known now: the object that passes, or undefined. */\nconst decidedFind = (\n\titems: readonly Value[],\n\tnode: ts.CallExpression,\n\t{ last }: { last: boolean },\n\tapply: (args: Value[]) => Value,\n): Value => {\n\tfor (const [index, item] of ordered(items, { last })) {\n\t\tconst test = apply([item, constant(index)]);\n\t\tif (test.kind !== \"const\") {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"find picks one of the objects setup built, which scan code can't hold; use findIndex and index the array.\",\n\t\t\t);\n\t\t}\n\t\tif (test.value) {\n\t\t\treturn item;\n\t\t}\n\t}\n\treturn constant(undefined);\n};\n",
49
+ "import ts from \"typescript\";\nimport { joined, type Mapped, mapped, type Part } from \"../positions\";\nimport { callbackArgument, ordered } from \"./array-searches\";\nimport { providedByRuntime } from \"./declarations\";\nimport type { ExpressionSpecializer, SpecializeContext } from \"./expressions\";\nimport type { Frame } from \"./frame\";\nimport type { ModelNode } from \"./model\";\nimport {\n\tabsent,\n\tnoReference,\n\treferable,\n\treferenceLayout,\n\tsettled,\n\tunion,\n} from \"./references\";\nimport { constant, repeatable, SpecializeError, type Value } from \"./values\";\n\ntype Masked = Extract<Value, { kind: \"masked\" }>;\ntype Entry = Masked[\"entries\"][number];\n\nconst isTrue = (value: Value): boolean =>\n\tvalue.kind === \"const\" && Boolean(value.value);\n\nconst isFalse = (value: Value): boolean =>\n\tvalue.kind === \"const\" && !value.value;\n\nconst whole = (items: readonly Value[]): Entry[] =>\n\titems.map((item) => ({ item, present: constant(true) }));\n\nconst objects = (items: readonly Value[]): boolean =>\n\titems.every((item) => item.kind === \"static\" && referable(item.node));\n\n/**\n * Arrays of known values whose contents or order scan code decides. A filter with a test decided\n * at run time keeps every candidate with a flag for whether the array holds it, and `toSorted`\n * keeps its comparator; neither builds an array. What reads them counts the flags, or picks the\n * object a search or the sort's order puts first, as a reference.\n */\nexport class FilteredArrays {\n\tconstructor(\n\t\tprivate readonly context: SpecializeContext,\n\t\tprivate readonly expressions: Pick<\n\t\t\tExpressionSpecializer,\n\t\t\t\"expression\" | \"invoke\" | \"held\" | \"items\" | \"references\"\n\t\t>,\n\t) {}\n\n\t/**\n\t * An array method decided at run time: on a filtered array, or one over an array setup built\n\t * that filters, sorts or picks an object from it. Undefined for a call setup decides.\n\t */\n\tcall(\n\t\tname: string,\n\t\treceiver: Value,\n\t\titems: readonly Value[] | undefined,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value | undefined {\n\t\tif (receiver.kind === \"masked\") {\n\t\t\treturn this.method(receiver, name, node, frame);\n\t\t}\n\t\tif (!items) {\n\t\t\treturn undefined;\n\t\t}\n\t\tswitch (name) {\n\t\t\tcase \"toSorted\":\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"masked\",\n\t\t\t\t\tentries: whole(items),\n\t\t\t\t\torder: callbackArgument(node, frame, this.expressions),\n\t\t\t\t};\n\t\t\tcase \"filter\": {\n\t\t\t\tconst { entries } = this.filtered(\n\t\t\t\t\t{ kind: \"masked\", entries: whole(items) },\n\t\t\t\t\tthis.test(node, frame),\n\t\t\t\t\tnode,\n\t\t\t\t\tframe,\n\t\t\t\t);\n\t\t\t\t// A filter whose every test setup decides is the elements it keeps.\n\t\t\t\treturn entries.every(({ present }) => present.kind === \"const\")\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tkind: \"virtual\",\n\t\t\t\t\t\t\titems: entries\n\t\t\t\t\t\t\t\t.filter(({ present }) => isTrue(present))\n\t\t\t\t\t\t\t\t.map(({ item }) => item),\n\t\t\t\t\t\t}\n\t\t\t\t\t: { kind: \"masked\", entries };\n\t\t\t}\n\t\t\tcase \"find\":\n\t\t\tcase \"findLast\":\n\t\t\t\treturn objects(items)\n\t\t\t\t\t? this.search(\n\t\t\t\t\t\t\twhole(items),\n\t\t\t\t\t\t\t{ last: name === \"findLast\" },\n\t\t\t\t\t\t\tthis.test(node, frame),\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\tframe,\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined;\n\t\t\tcase \"at\": {\n\t\t\t\tconst [argument] = node.arguments;\n\t\t\t\treturn argument && objects(items)\n\t\t\t\t\t? this.indexed(\n\t\t\t\t\t\t\titems,\n\t\t\t\t\t\t\tthis.expressions.expression(argument, frame),\n\t\t\t\t\t\t\t{ fromEnd: true },\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\tframe,\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tprivate method(\n\t\tmasked: Masked,\n\t\tname: string,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tswitch (name) {\n\t\t\tcase \"filter\":\n\t\t\t\treturn this.filtered(masked, this.test(node, frame), node, frame);\n\t\t\tcase \"some\":\n\t\t\tcase \"every\":\n\t\t\t\treturn this.quantified(\n\t\t\t\t\tmasked,\n\t\t\t\t\t{ some: name === \"some\" },\n\t\t\t\t\tthis.test(node, frame),\n\t\t\t\t\tnode,\n\t\t\t\t\tframe,\n\t\t\t\t);\n\t\t\tcase \"find\":\n\t\t\tcase \"findLast\": {\n\t\t\t\tconst last = name === \"findLast\";\n\t\t\t\tconst test = this.test(node, frame);\n\t\t\t\t// In a sorted array the first to pass is the least of those that pass.\n\t\t\t\treturn masked.order\n\t\t\t\t\t? this.extreme(\n\t\t\t\t\t\t\tthis.filtered(masked, test, node, frame),\n\t\t\t\t\t\t\t{ last },\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\tframe,\n\t\t\t\t\t\t)\n\t\t\t\t\t: this.search(masked.entries, { last }, test, node, frame);\n\t\t\t}\n\t\t\tcase \"at\": {\n\t\t\t\tconst [argument] = node.arguments;\n\t\t\t\tconst index = argument && this.expressions.expression(argument, frame);\n\t\t\t\treturn this.end(masked, index, node, frame);\n\t\t\t}\n\t\t\tcase \"toSorted\":\n\t\t\t\tif (masked.order) {\n\t\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\"Sort an array once, with one comparator: a second toSorted would leave ties in the first one's order, which isn't kept.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\t...masked,\n\t\t\t\t\torder: callbackArgument(node, frame, this.expressions),\n\t\t\t\t};\n\t\t\tdefault:\n\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\tnode,\n\t\t\t\t\t`${name} is not available on an array filtered or sorted at run time, which has no storage: use its length, some, every, filter, find, toSorted, at(0) or at(-1).`,\n\t\t\t\t);\n\t\t}\n\t}\n\n\t/** `.length` of an array filtered at run time; it has nothing else to read. */\n\tmember(masked: Masked, name: string, at: ts.Node, frame: Frame): Value {\n\t\tif (name !== \"length\") {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t`${name} cannot be read from an array filtered or sorted at run time.`,\n\t\t\t);\n\t\t}\n\t\tconst live = masked.entries.filter((entry) => !isFalse(entry.present));\n\t\tconst certain = live.filter((entry) => isTrue(entry.present)).length;\n\t\tif (certain === live.length) {\n\t\t\treturn constant(certain);\n\t\t}\n\t\tconst total = frame.emitter.temporary();\n\t\tframe.emitter.line(`let ${total}: number = ${certain};`);\n\t\tfor (const entry of live) {\n\t\t\tif (entry.present.kind !== \"const\") {\n\t\t\t\tframe.emitter.line(\n\t\t\t\t\tmapped`if (${this.context.dialect.condition(entry.present, at)}) { ${total} = ${total} + 1; }`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn this.number(total);\n\t}\n\n\t/** Whether the expression is JavaScript's `array.filter(test)`, whose length counts the elements that pass. */\n\tisFilter(\n\t\tnode: ts.Expression,\n\t): node is ts.CallExpression & { expression: ts.PropertyAccessExpression } {\n\t\treturn (\n\t\t\tts.isCallExpression(node) &&\n\t\t\tts.isPropertyAccessExpression(node.expression) &&\n\t\t\tnode.expression.name.text === \"filter\" &&\n\t\t\tnode.arguments.length === 1 &&\n\t\t\tprovidedByRuntime(this.context.checker, node.expression.name)\n\t\t);\n\t}\n\n\t/**\n\t * `array.filter(test).length`: how many elements pass. A filter decided at run time has no array\n\t * to build, since its length isn't fixed, but its count is a number.\n\t */\n\tcount(\n\t\tnode: ts.CallExpression & { expression: ts.PropertyAccessExpression },\n\t\tframe: Frame,\n\t): Value {\n\t\tconst receiver = this.expressions.expression(\n\t\t\tnode.expression.expression,\n\t\t\tframe,\n\t\t);\n\t\tif (receiver.kind === \"masked\") {\n\t\t\treturn this.member(\n\t\t\t\tthis.filtered(receiver, this.test(node, frame), node, frame),\n\t\t\t\t\"length\",\n\t\t\t\tnode,\n\t\t\t\tframe,\n\t\t\t);\n\t\t}\n\t\tconst items = this.expressions.items(receiver);\n\t\tconst [testNode] = node.arguments;\n\t\tif (!items || !testNode) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"filter needs an array setup built and a test.\",\n\t\t\t);\n\t\t}\n\t\tconst test = this.test(node, frame);\n\t\tconst results = items.map((item, index) => test(item, index));\n\t\tif (results.every((result) => result.kind === \"const\")) {\n\t\t\treturn constant(results.filter(isTrue).length);\n\t\t}\n\t\tconst total = frame.emitter.temporary();\n\t\tframe.emitter.line(`let ${total}: number = 0;`);\n\t\tfor (const result of results) {\n\t\t\tif (result.kind === \"const\") {\n\t\t\t\tif (result.value) {\n\t\t\t\t\tframe.emitter.line(`${total} = ${total} + 1;`);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tframe.emitter.line(\n\t\t\t\tmapped`if (${this.context.dialect.condition(result, testNode)}) { ${total} = ${total} + 1; }`,\n\t\t\t);\n\t\t}\n\t\treturn this.number(total);\n\t}\n\n\t/** `array[0]` of an array filtered or sorted at run time: its first element. */\n\telement(masked: Masked, index: Value, at: ts.Node, frame: Frame): Value {\n\t\tif (index.kind === \"const\" && index.value === 0) {\n\t\t\treturn this.extreme(masked, { last: false }, at, frame);\n\t\t}\n\t\tthrow new SpecializeError(\n\t\t\tat,\n\t\t\t\"An array filtered or sorted at run time has no storage to index: read [0], at(0) or at(-1).\",\n\t\t);\n\t}\n\n\t/** `at(0)` and `at(-1)` of an array filtered or sorted at run time. */\n\tprivate end(\n\t\tmasked: Masked,\n\t\tindex: Value | undefined,\n\t\tat: ts.Node,\n\t\tframe: Frame,\n\t): Value {\n\t\tif (index?.kind === \"const\" && (index.value === 0 || index.value === -1)) {\n\t\t\treturn this.extreme(masked, { last: index.value === -1 }, at, frame);\n\t\t}\n\t\tthrow new SpecializeError(\n\t\t\tat,\n\t\t\t\"An array filtered or sorted at run time has no storage to index: read at(0) or at(-1).\",\n\t\t);\n\t}\n\n\t/** An array method's callback as a test of one element. */\n\tprivate test(\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): (item: Value, index: number) => Value {\n\t\tconst callback = callbackArgument(node, frame, this.expressions);\n\t\treturn (item, index) =>\n\t\t\tthis.truth(\n\t\t\t\tthis.expressions.invoke(callback, [item, constant(index)], node, frame),\n\t\t\t);\n\t}\n\n\t/** A callback's result as a condition: an object is truthy, and a reference is when it holds one. */\n\tprivate truth(value: Value): Value {\n\t\tif (value.kind === \"choice\") {\n\t\t\treturn this.expressions.references.present(value);\n\t\t}\n\t\treturn value.kind === \"const\" || value.kind === \"code\"\n\t\t\t? value\n\t\t\t: constant(true);\n\t}\n\n\tprivate flag(text: string | Mapped): Value {\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext,\n\t\t\tdeclared: this.context.checker.getBooleanType(),\n\t\t\tplace: true,\n\t\t};\n\t}\n\n\tprivate number(text: string): Value {\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext,\n\t\t\tdeclared: this.context.checker.getNumberType(),\n\t\t\tplace: true,\n\t\t};\n\t}\n\n\t/**\n\t * `filter(test)` decided at run time: the same candidates, each present when it was and its\n\t * test passes. A test runs only on a candidate the array holds.\n\t */\n\tprivate filtered(\n\t\tmasked: Masked,\n\t\ttest: (item: Value, index: number) => Value,\n\t\tat: ts.Node,\n\t\tframe: Frame,\n\t): Masked {\n\t\tconst tested = masked.entries.map((entry, index) => {\n\t\t\tif (isFalse(entry.present)) {\n\t\t\t\treturn { entry, passes: constant(false), lines: [] };\n\t\t\t}\n\t\t\tconst { result, lines } = frame.emitter.detached(\n\t\t\t\t{ nested: entry.present.kind !== \"const\" },\n\t\t\t\t() => test(entry.item, index),\n\t\t\t);\n\t\t\treturn { entry, passes: result, lines };\n\t\t});\n\t\tconst entries = tested.map(({ entry, passes, lines }): Entry => {\n\t\t\tconst { item, present } = entry;\n\t\t\tif (present.kind === \"const\") {\n\t\t\t\tframe.emitter.append(lines);\n\t\t\t\tif (passes.kind === \"const\") {\n\t\t\t\t\treturn { item, present: constant(isTrue(passes)) };\n\t\t\t\t}\n\t\t\t\tconst text = this.context.dialect.condition(passes, at);\n\t\t\t\tif (repeatable(text)) {\n\t\t\t\t\treturn { item, present: passes };\n\t\t\t\t}\n\t\t\t\tconst held = frame.emitter.temporary();\n\t\t\t\tframe.emitter.line(mapped`const ${held}: boolean = ${text};`);\n\t\t\t\treturn { item, present: this.flag(held) };\n\t\t\t}\n\t\t\tif (passes.kind === \"const\" && lines.length === 0) {\n\t\t\t\treturn { item, present: passes.value ? present : constant(false) };\n\t\t\t}\n\t\t\tconst held = frame.emitter.temporary();\n\t\t\tframe.emitter.line(`let ${held}: boolean = false;`);\n\t\t\tframe.emitter.open(\n\t\t\t\tmapped`if (${this.context.dialect.condition(present, at)}) {`,\n\t\t\t);\n\t\t\tframe.emitter.append(lines);\n\t\t\tframe.emitter.line(\n\t\t\t\tmapped`${held} = ${this.context.dialect.condition(passes, at)};`,\n\t\t\t);\n\t\t\tframe.emitter.close();\n\t\t\treturn { item, present: this.flag(held) };\n\t\t});\n\t\treturn { ...masked, entries };\n\t}\n\n\t/** `some(test)` and `every(test)` over the candidates an array filtered at run time holds; tests stop once one decides. */\n\tprivate quantified(\n\t\tmasked: Masked,\n\t\t{ some }: { some: boolean },\n\t\ttest: (item: Value, index: number) => Value,\n\t\tat: ts.Node,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst result = frame.emitter.temporary();\n\t\tframe.emitter.line(`let ${result}: boolean = ${!some};`);\n\t\tfor (const [index, entry] of masked.entries.entries()) {\n\t\t\tif (isFalse(entry.present)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst guards: Part[] = [\n\t\t\t\tsome ? `!${result}` : result,\n\t\t\t\t...(entry.present.kind === \"const\"\n\t\t\t\t\t? []\n\t\t\t\t\t: [this.context.dialect.condition(entry.present, at)]),\n\t\t\t];\n\t\t\tframe.emitter.open(mapped`if (${joined(guards, \" && \")}) {`);\n\t\t\tconst passes = test(entry.item, index);\n\t\t\tif (passes.kind !== \"const\") {\n\t\t\t\tframe.emitter.line(\n\t\t\t\t\tmapped`${result} = ${this.context.dialect.condition(passes, at)};`,\n\t\t\t\t);\n\t\t\t} else if (Boolean(passes.value) === some) {\n\t\t\t\tframe.emitter.line(`${result} = ${some};`);\n\t\t\t}\n\t\t\tframe.emitter.close();\n\t\t}\n\t\treturn this.flag(result);\n\t}\n\n\t/**\n\t * `find` and `findLast` among objects setup built, and the first or last an unsorted filtered\n\t * array holds: the first candidate present whose test passes, tests stopping once one has.\n\t */\n\tprivate search(\n\t\tentries: readonly Entry[],\n\t\t{ last }: { last: boolean },\n\t\ttest: ((item: Value, index: number) => Value) | undefined,\n\t\tat: ts.Node,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst arms: {\n\t\t\tnode: ModelNode;\n\t\t\tpresent: Value;\n\t\t\tpasses: Value;\n\t\t\tlines: Mapped[];\n\t\t}[] = [];\n\t\tfor (const [index, entry] of ordered(entries, { last })) {\n\t\t\tif (isFalse(entry.present)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst node = this.object(entry.item, at);\n\t\t\tconst { result: passes, lines } = test\n\t\t\t\t? frame.emitter.detached({ nested: true }, () =>\n\t\t\t\t\t\ttest(entry.item, index),\n\t\t\t\t\t)\n\t\t\t\t: { result: constant(true), lines: [] };\n\t\t\tif (isFalse(passes) && lines.length === 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tarms.push({ node, present: entry.present, passes, lines });\n\t\t\tif (isTrue(entry.present) && isTrue(passes)) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tconst final = arms.at(-1);\n\t\tif (!final) {\n\t\t\treturn constant(undefined);\n\t\t}\n\t\tconst certain = isTrue(final.present) && isTrue(final.passes);\n\t\tif (arms.length === 1 && certain && final.lines.length === 0) {\n\t\t\treturn { kind: \"static\", node: final.node };\n\t\t}\n\t\tconst result = frame.emitter.temporary();\n\t\tframe.emitter.line(`let ${result}: ${referenceLayout} = ${noReference};`);\n\t\tfor (const arm of arms) {\n\t\t\tconst guards: Part[] = [\n\t\t\t\tabsent(result),\n\t\t\t\t...(arm.present.kind === \"const\"\n\t\t\t\t\t? []\n\t\t\t\t\t: [this.context.dialect.condition(arm.present, at)]),\n\t\t\t];\n\t\t\tframe.emitter.open(mapped`if (${joined(guards, \" && \")}) {`);\n\t\t\tframe.emitter.append(arm.lines);\n\t\t\tif (isTrue(arm.passes)) {\n\t\t\t\tframe.emitter.line(`${result} = ${arm.node.reference};`);\n\t\t\t} else if (arm.passes.kind !== \"const\") {\n\t\t\t\tframe.emitter.line(\n\t\t\t\t\tmapped`if (${this.context.dialect.condition(arm.passes, at)}) { ${result} = ${arm.node.reference}; }`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tframe.emitter.close();\n\t\t}\n\t\treturn settled({\n\t\t\tkind: \"choice\",\n\t\t\toptions: union(\n\t\t\t\tarms.filter((arm) => !isFalse(arm.passes)).map((arm) => arm.node),\n\t\t\t),\n\t\t\tindex: result,\n\t\t\toptional: !certain,\n\t\t});\n\t}\n\n\t/**\n\t * The first or last element of an array filtered at run time, in the order its `toSorted`\n\t * gives: the least, or the greatest, of the candidates present. Each candidate is compared with\n\t * the best before it, and wins only when strictly less (or, for the last, not less), so equal\n\t * candidates keep their order as a stable sort does.\n\t */\n\tprivate extreme(\n\t\tmasked: Masked,\n\t\t{ last }: { last: boolean },\n\t\tat: ts.Node,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst order = masked.order;\n\t\tif (!order) {\n\t\t\treturn this.search(masked.entries, { last }, undefined, at, frame);\n\t\t}\n\t\tconst live = masked.entries\n\t\t\t.filter((entry) => !isFalse(entry.present))\n\t\t\t.map((entry) => ({ ...entry, node: this.object(entry.item, at) }));\n\t\tconst [only, ...others] = live;\n\t\tif (!only) {\n\t\t\treturn constant(undefined);\n\t\t}\n\t\tif (others.length === 0 && isTrue(only.present)) {\n\t\t\treturn only.item;\n\t\t}\n\t\tconst best = frame.emitter.temporary();\n\t\tframe.emitter.line(`let ${best}: ${referenceLayout} = ${noReference};`);\n\t\tlive.forEach((entry, position) => {\n\t\t\tconst before = live.slice(0, position);\n\t\t\tconst guarded = entry.present.kind !== \"const\";\n\t\t\tif (guarded) {\n\t\t\t\tframe.emitter.open(\n\t\t\t\t\tmapped`if (${this.context.dialect.condition(entry.present, at)}) {`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst take = `${best} = ${entry.node.reference};`;\n\t\t\tconst rivals = union(before.map((rival) => rival.node))\n\t\t\t\t.filter((rival) => rival !== entry.node)\n\t\t\t\t.map((rival) => {\n\t\t\t\t\tconst { result, lines } = frame.emitter.detached(\n\t\t\t\t\t\t{ nested: true },\n\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\tthis.wins(\n\t\t\t\t\t\t\t\tthis.expressions.invoke(\n\t\t\t\t\t\t\t\t\torder,\n\t\t\t\t\t\t\t\t\t[entry.item, { kind: \"static\", node: rival }],\n\t\t\t\t\t\t\t\t\tat,\n\t\t\t\t\t\t\t\t\tframe,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t{ last },\n\t\t\t\t\t\t\t\tat,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\treturn { rival, wins: result, lines };\n\t\t\t\t});\n\t\t\tframe.emitter.chain([\n\t\t\t\t// Until a candidate is surely present, none may have been taken yet.\n\t\t\t\t...(before.some((rival) => isTrue(rival.present))\n\t\t\t\t\t? []\n\t\t\t\t\t: [{ test: absent(best), body: () => frame.emitter.line(take) }]),\n\t\t\t\t...rivals\n\t\t\t\t\t.filter(({ wins, lines }) => !isFalse(wins) || lines.length > 0)\n\t\t\t\t\t.map(({ rival, wins, lines }) => ({\n\t\t\t\t\t\ttest: `${best} === ${rival.reference}`,\n\t\t\t\t\t\tbody: () => {\n\t\t\t\t\t\t\tframe.emitter.append(lines);\n\t\t\t\t\t\t\tif (isTrue(wins)) {\n\t\t\t\t\t\t\t\tframe.emitter.line(take);\n\t\t\t\t\t\t\t} else if (wins.kind !== \"const\") {\n\t\t\t\t\t\t\t\tframe.emitter.line(\n\t\t\t\t\t\t\t\t\tmapped`if (${this.context.dialect.condition(wins, at)}) { ${take} }`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t})),\n\t\t\t]);\n\t\t\tif (guarded) {\n\t\t\t\tframe.emitter.close();\n\t\t\t}\n\t\t});\n\t\treturn settled({\n\t\t\tkind: \"choice\",\n\t\t\toptions: union(live.map((entry) => entry.node)),\n\t\t\tindex: best,\n\t\t\toptional: !live.some((entry) => isTrue(entry.present)),\n\t\t});\n\t}\n\n\t/** Whether a comparator's result puts its first argument ahead of the best so far. */\n\tprivate wins(\n\t\tcompared: Value,\n\t\t{ last }: { last: boolean },\n\t\tat: ts.Node,\n\t): Value {\n\t\tif (compared.kind === \"const\" && typeof compared.value === \"number\") {\n\t\t\treturn constant(last ? compared.value >= 0 : compared.value < 0);\n\t\t}\n\t\tif (compared.kind !== \"code\") {\n\t\t\tthrow new SpecializeError(at, \"A comparator returns a number.\");\n\t\t}\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: mapped`(${compared.text} ${last ? \">=\" : \"<\"} 0)`,\n\t\t\tdeclared: this.context.checker.getBooleanType(),\n\t\t};\n\t}\n\n\t/**\n\t * `array[index]` and `array.at(index)` with an index decided at run time, among objects setup\n\t * built: the object there, `at` counting back when negative. Undefined when setup decides the\n\t * index, or the elements are values.\n\t */\n\tindexed(\n\t\titems: readonly Value[],\n\t\tindex: Value,\n\t\t{ fromEnd }: { fromEnd: boolean },\n\t\tat: ts.Node,\n\t\tframe: Frame,\n\t): Value | undefined {\n\t\tif (index.kind !== \"code\" || !objects(items)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst held = this.context.dialect.code(\n\t\t\tthis.expressions.held(index, frame),\n\t\t\tundefined,\n\t\t);\n\t\tconst result = frame.emitter.temporary();\n\t\tframe.emitter.line(`let ${result}: ${referenceLayout} = ${noReference};`);\n\t\tconst nodes = items.map((item) => this.object(item, at));\n\t\tframe.emitter.chain(\n\t\t\tnodes.map((item, position) => ({\n\t\t\t\ttest: fromEnd\n\t\t\t\t\t? mapped`${held} === ${position} || ${held} === ${position - nodes.length}`\n\t\t\t\t\t: mapped`${held} === ${position}`,\n\t\t\t\tbody: () => frame.emitter.line(`${result} = ${item.reference};`),\n\t\t\t})),\n\t\t);\n\t\treturn settled({\n\t\t\tkind: \"choice\",\n\t\t\toptions: union(nodes),\n\t\t\tindex: result,\n\t\t\toptional: true,\n\t\t});\n\t}\n\n\t/** The object an array element is, for a reference to it; values have no identity to refer to. */\n\tprivate object(item: Value, at: ts.Node): ModelNode {\n\t\tif (item.kind !== \"static\" || !referable(item.node)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t\"Only objects setup built can be picked at run time: an array of values filtered or sorted then has no element to hand back. Use findIndex, or loop over the array.\",\n\t\t\t);\n\t\t}\n\t\treturn item.node;\n\t}\n}\n",
50
+ "import ts from \"typescript\";\nimport { joined, Mapped, mapped, type Part } from \"../positions\";\nimport { isWrapper } from \"../types\";\nimport { callbackArgument, searchTarget } from \"./array-searches\";\nimport { providedByRuntime } from \"./declarations\";\nimport type { ExpressionSpecializer, SpecializeContext } from \"./expressions\";\nimport { Emitter, type Frame, looping } from \"./frame\";\nimport { arrayLayout } from \"./layouts\";\nimport type { ModelNode } from \"./model\";\nimport {\n\tnoReference,\n\treferenceIndex,\n\treferenceLayout,\n\treferences,\n} from \"./references\";\nimport {\n\ttype Counted,\n\tconstant,\n\ttype FunctionLike,\n\tisStoredState,\n\tknown,\n\tSpecializeError,\n\tunwrapped,\n\ttype Value,\n} from \"./values\";\n\n/** How a local keeps what a traversal passes on: its PLC type, what it holds before anything is stored, and a value going in and coming out. */\ninterface Slot {\n\ttype: string;\n\tempty: () => string | Mapped;\n\tstore: (value: Value) => Part;\n\tread: (place: string | Mapped) => Value;\n}\n\n/** A generator call as it runs in place: its body, the object it runs on and its arguments. */\nexport interface GeneratorCall {\n\tdeclaration: FunctionLike;\n\tself?: ModelNode;\n\targs: Value[];\n}\n\n/**\n * The labelled statements around the code that uses one element: leaving `label` moves on to the\n * next element, and leaving `whole` ends the traversal.\n */\nexport interface Jumps {\n\twhole: string;\n\tlabel: string;\n}\n\n/** One element where a traversal reaches it. */\nexport interface Visited extends Jumps {\n\tvalue: Value;\n\t/** Its position among the traversal's elements, where the traversal knows it. */\n\tindex?: Value;\n\t/** How many times the code written for this visit can run in one traversal; undefined when no loop bound says. */\n\trepeats: number | undefined;\n}\n\n/**\n * Elements in the order JavaScript reads them. `run` writes the code that reaches each one, and\n * `visit` writes, inside it, the code that uses the element.\n */\nexport interface Traversal {\n\trun(frame: Frame, visit: (element: Visited) => void): void;\n\t/** Whether each element comes with its position, as an array's do. */\n\tindexed?: boolean;\n\t/** The most elements it can pass on whatever it reads, as `take(2)` sets. */\n\tlimit?: number;\n}\n\n/** Runs a generator's body in place. The statement specializer does, which is built after this. */\nexport interface GeneratorRunner {\n\trun(\n\t\tgenerator: GeneratorCall,\n\t\tframe: Frame,\n\t\tat: ts.Node,\n\t\teach: (value: Value, jumps: Jumps) => void,\n\t): void;\n}\n\n/** Iterator helpers that give another iterator, which runs only once something reads it. */\nconst adapters = new Set([\"map\", \"filter\", \"take\", \"drop\", \"flatMap\"]);\n\n/**\n * JavaScript's iterator helpers over generators, and arrays whose length is decided at run time.\n * A generator runs in place, so a helper is code at each of its yields: `some` stops it at the\n * first element that decides, and `toArray` copies what it yields into a local array sized for\n * the most it can yield. A slice with runtime bounds copies nothing: it is the same elements,\n * each read only when its index is in range.\n */\nexport class Iterators {\n\tprivate runner: GeneratorRunner | undefined;\n\n\tconstructor(\n\t\tprivate readonly context: SpecializeContext,\n\t\tprivate readonly expressions: Pick<\n\t\t\tExpressionSpecializer,\n\t\t\t| \"expression\"\n\t\t\t| \"invoke\"\n\t\t\t| \"inOrder\"\n\t\t\t| \"member\"\n\t\t\t| \"held\"\n\t\t\t| \"temporaryOf\"\n\t\t\t| \"localType\"\n\t\t\t| \"equality\"\n\t\t\t| \"speculatively\"\n\t\t>,\n\t) {}\n\n\tattach(runner: GeneratorRunner): void {\n\t\tthis.runner = runner;\n\t}\n\n\t/** A helper called on an iterator: what it is worth, or undefined when the call is no iterator helper. */\n\tcall(node: ts.CallExpression, frame: Frame): Value | undefined {\n\t\tconst helper = this.helper(node);\n\t\tif (!helper) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (adapters.has(helper.name)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t`${helper.name} gives an iterator, which runs only where it is read: follow it with toArray, some, every, find, forEach or reduce, or loop over it with for…of.`,\n\t\t\t);\n\t\t}\n\t\treturn this.terminal(\n\t\t\thelper.name,\n\t\t\tthis.pipeline(helper.receiver, frame),\n\t\t\tnode,\n\t\t\tframe,\n\t\t);\n\t}\n\n\t/** The iterator a for…of loops over, when helpers read a generator call into it. */\n\titerated(node: ts.Expression, frame: Frame): Traversal | undefined {\n\t\tconst helper = this.helper(unwrapped(node));\n\t\treturn helper && adapters.has(helper.name)\n\t\t\t? this.pipeline(node, frame)\n\t\t\t: undefined;\n\t}\n\n\t/**\n\t * A method called on a counted array, or a slice of a runtime array; undefined for a receiver that\n\t * is neither.\n\t */\n\tarrayCall(\n\t\tname: string,\n\t\tvalue: Value,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value | undefined {\n\t\tif (value.kind === \"counted\") {\n\t\t\treturn this.method(name, value, node, frame);\n\t\t}\n\t\tconst stored = name === \"slice\" ? this.storage(value) : undefined;\n\t\treturn stored && this.method(name, stored, node, frame);\n\t}\n\n\t/**\n\t * `some`, `every` and `includes` over elements setup fixed, as one expression: each element's\n\t * test is written out.\n\t */\n\tunrolled(\n\t\tname: \"some\" | \"every\" | \"includes\",\n\t\titems: readonly Value[],\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\treturn this.tested(\n\t\t\tname,\n\t\t\t{\n\t\t\t\tkind: \"counted\",\n\t\t\t\tsource: { kind: \"items\", items },\n\t\t\t\tstart: constant(0),\n\t\t\t\tend: constant(items.length),\n\t\t\t},\n\t\t\titems,\n\t\t\tnode,\n\t\t\tframe,\n\t\t);\n\t}\n\n\t/** A generator call, as a for…of runs it: its body, the object it runs on and its arguments. */\n\tgenerator(node: ts.Expression, frame: Frame): GeneratorCall | undefined {\n\t\tif (!ts.isCallExpression(node)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst declaration =\n\t\t\tthis.context.checker.getResolvedSignature(node)?.declaration;\n\t\tif (\n\t\t\t!declaration ||\n\t\t\t!(\n\t\t\t\tts.isFunctionDeclaration(declaration) ||\n\t\t\t\tts.isMethodDeclaration(declaration) ||\n\t\t\t\tts.isFunctionExpression(declaration)\n\t\t\t) ||\n\t\t\t!declaration.asteriskToken ||\n\t\t\t!declaration.body\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst callee = node.expression;\n\t\tconst target = ts.isPropertyAccessExpression(callee)\n\t\t\t? this.expressions.member(\n\t\t\t\t\tthis.expressions.expression(callee.expression, frame),\n\t\t\t\t\tcallee.name.text,\n\t\t\t\t\tcallee,\n\t\t\t\t\tframe,\n\t\t\t\t)\n\t\t\t: this.expressions.expression(callee, frame);\n\t\tconst self = target.kind === \"function\" ? target.self : undefined;\n\t\tconst args = this.expressions.inOrder(\n\t\t\tnode.arguments,\n\t\t\t(argument) => this.expressions.expression(argument, frame),\n\t\t\tframe,\n\t\t);\n\t\treturn { declaration, self, args };\n\t}\n\n\tprivate method(\n\t\tname: string,\n\t\treceiver: Counted,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tif (name === \"slice\") {\n\t\t\tconst [start, end] = node.arguments.map((argument) =>\n\t\t\t\tthis.expressions.expression(argument, frame),\n\t\t\t);\n\t\t\tif (receiver.source.kind === \"items\" || !receiver.source.snapshot) {\n\t\t\t\tthis.readInPlace(node);\n\t\t\t}\n\t\t\treturn this.slice(receiver, { start, end }, node, frame);\n\t\t}\n\t\tconst { source } = receiver;\n\t\tif (\n\t\t\tsource.kind === \"items\" &&\n\t\t\t(name === \"some\" || name === \"every\" || name === \"includes\")\n\t\t) {\n\t\t\treturn this.tested(name, receiver, source.items, node, frame);\n\t\t}\n\t\treturn this.terminal(name, this.over(receiver), node, frame);\n\t}\n\n\t/**\n\t * `array.slice(start, end)` over elements setup fixed, with a bound decided at run time. Nothing\n\t * is copied, so the slice is read where it is made, before anything can change the elements.\n\t */\n\tsliced(\n\t\titems: readonly Value[],\n\t\tbounds: { start: Value | undefined; end: Value | undefined },\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tthis.readInPlace(node);\n\t\treturn this.slice(\n\t\t\t{\n\t\t\t\tkind: \"counted\",\n\t\t\t\tsource: { kind: \"items\", items },\n\t\t\t\tstart: constant(0),\n\t\t\t\tend: constant(items.length),\n\t\t\t},\n\t\t\tbounds,\n\t\t\tnode,\n\t\t\tframe,\n\t\t);\n\t}\n\n\tprivate readInPlace(node: ts.CallExpression): void {\n\t\tconst user = outside(node);\n\t\tif (\n\t\t\t!ts.isPropertyAccessExpression(user) &&\n\t\t\t!ts.isElementAccessExpression(user) &&\n\t\t\t!ts.isForOfStatement(user)\n\t\t) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"A slice with bounds decided at run time has no array to keep: read it where it is made, with every, some, find, findIndex, forEach, includes, indexOf, length or for…of.\",\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * A runtime array as a counted array of all its elements, for a slice of it: one a routine was\n\t * passed, or a runtime record's field, whose layout says how many elements it stores. Undefined\n\t * for an array whose elements are each known, which a slice reads one by one.\n\t */\n\tprivate storage(value: Value): Counted | undefined {\n\t\tif (value.kind !== \"code\" || value.length !== undefined || !value.layout) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst { layout } = value;\n\t\tconst { bound } = layout;\n\t\tif (bound === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst declared =\n\t\t\tvalue.declared && this.context.model.elementType(value.declared);\n\t\treturn {\n\t\t\tkind: \"counted\",\n\t\t\tsource: {\n\t\t\t\tkind: \"array\",\n\t\t\t\ttext: value.text,\n\t\t\t\tlayout: layout.text,\n\t\t\t\tbound,\n\t\t\t\telement: (index) => ({\n\t\t\t\t\tkind: \"code\",\n\t\t\t\t\ttext: mapped`${value.text}[${index}]`,\n\t\t\t\t\tdeclared,\n\t\t\t\t\tplace: value.place,\n\t\t\t\t\tiec: value.elementIec ?? layout.elementIec,\n\t\t\t\t\tcopyOf: value.copyOf,\n\t\t\t\t}),\n\t\t\t\tsnapshot: false,\n\t\t\t},\n\t\t\tstart: constant(0),\n\t\t\tend: constant(bound),\n\t\t};\n\t}\n\n\t/** A counted array's `length`: how many elements it has now. */\n\tmember(counted: Counted, name: string, at: ts.Node): Value {\n\t\tif (name !== \"length\") {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t`${name} cannot be read from an array whose length is decided at run time.`,\n\t\t\t);\n\t\t}\n\t\treturn this.difference(counted.end, counted.start);\n\t}\n\n\t/**\n\t * `array[index]` on a counted array. Past its end JavaScript reads undefined: where the type allows\n\t * undefined that is what is read, and elsewhere the element type's empty value, which a snapshot's\n\t * unused slots hold.\n\t */\n\telement(counted: Counted, index: Value, at: ts.Node, frame: Frame): Value {\n\t\tconst { source } = counted;\n\t\tconst offset = known(index);\n\t\tif (index.kind !== \"code\" && offset === undefined) {\n\t\t\tthrow new SpecializeError(at, \"Index an array with a number.\");\n\t\t}\n\t\tif (offset !== undefined && offset < 0) {\n\t\t\treturn constant(undefined);\n\t\t}\n\t\tconst position = this.sum(counted.start, index);\n\t\tconst fixed = known(position);\n\t\tconst inside = all([\n\t\t\tthis.compare(constant(0), \"<=\", index),\n\t\t\tthis.compare(position, \"<\", counted.end),\n\t\t]);\n\t\tif (inside === false) {\n\t\t\treturn constant(undefined);\n\t\t}\n\t\tconst item = this.stored(source, position, fixed, at);\n\t\tif (item === undefined) {\n\t\t\treturn constant(undefined);\n\t\t}\n\t\tif (inside === true) {\n\t\t\treturn item;\n\t\t}\n\t\tif (item.kind === \"choice\") {\n\t\t\t// A reference has an id for undefined, whatever the element's type says.\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\tindex: mapped`(${inside} ? ${item.index} : ${noReference})`,\n\t\t\t\toptional: true,\n\t\t\t};\n\t\t}\n\t\tif (item.kind !== \"code\") {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t\"Index the array the slice was taken from: whether the slice has this element is decided at run time.\",\n\t\t\t);\n\t\t}\n\t\t// Past the end of a whole snapshot the slot was never stored into, so it reads as empty already.\n\t\tif (\n\t\t\tsource.kind === \"array\" &&\n\t\t\tsource.filled &&\n\t\t\tsameNumber(source.filled, counted.end)\n\t\t) {\n\t\t\treturn item;\n\t\t}\n\t\tconst { checker, dialect } = this.context;\n\t\tconst declared = checker.getTypeAtLocation(at);\n\t\tconst optional = checker.getNonNullableType(declared) !== declared;\n\t\tconst empty = optional\n\t\t\t? dialect.assignmentText(constant(undefined), declared, undefined)\n\t\t\t: this.context.initializers.defaultOf(declared);\n\t\tconst result = frame.emitter.temporary();\n\t\tframe.emitter.line(\n\t\t\tmapped`let ${result}: ${this.expressions.localType(declared)} = ${empty};`,\n\t\t);\n\t\tframe.emitter.line(\n\t\t\tmapped`if (${inside}) { ${result} = ${dialect.assignmentText(item, declared, undefined)}; }`,\n\t\t);\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: result,\n\t\t\tdeclared,\n\t\t\tplace: true,\n\t\t\tcopyOf: copiedFrom([item], \"slice\"),\n\t\t};\n\t}\n\n\t/** A for…of over a counted array, or a method that reads each of its elements. */\n\tover(counted: Counted): Traversal {\n\t\tconst { source, start, end } = counted;\n\t\tif (source.kind === \"items\") {\n\t\t\treturn this.overItems(counted, source.items);\n\t\t}\n\t\tconst first = known(start);\n\t\tconst last = known(end);\n\t\treturn {\n\t\t\tindexed: true,\n\t\t\trun: (frame, visit) => {\n\t\t\t\tconst whole = frame.emitter.local(\"tsplcEach\");\n\t\t\t\tconst counter = frame.emitter.local(\"tsplcIndex\");\n\t\t\t\t// The counter never passes the array's bound, which is what proves each index in range.\n\t\t\t\tconst stop =\n\t\t\t\t\tlast === undefined ? source.bound : Math.min(last, source.bound);\n\t\t\t\tframe.emitter.open(\n\t\t\t\t\t`${whole}: for (let ${counter}: number = ${first ?? 0}; ${counter} < ${stop}; ${counter}++) {`,\n\t\t\t\t);\n\t\t\t\tif (last === undefined) {\n\t\t\t\t\tframe.emitter.line(\n\t\t\t\t\t\tmapped`if (${counter} >= ${this.text(end)}) { break ${whole}; }`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (first === undefined) {\n\t\t\t\t\tframe.emitter.open(mapped`if (${counter} >= ${this.text(start)}) {`);\n\t\t\t\t}\n\t\t\t\tconst label = frame.emitter.local(\"tsplcStep\");\n\t\t\t\tframe.emitter.open(`${label}: {`);\n\t\t\t\tlooping(frame, source.bound, () =>\n\t\t\t\t\tvisit({\n\t\t\t\t\t\tvalue: source.element(counter),\n\t\t\t\t\t\tindex: this.difference(this.number(counter), start),\n\t\t\t\t\t\twhole,\n\t\t\t\t\t\tlabel,\n\t\t\t\t\t\trepeats: source.bound,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tframe.emitter.close();\n\t\t\t\tif (first === undefined) {\n\t\t\t\t\tframe.emitter.close();\n\t\t\t\t}\n\t\t\t\tframe.emitter.close();\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Whether evaluating the expression runs a traversal as statements, outside functions it declares.\n\t * JavaScript evaluates the right of `&&`, `||`, `??` and a conditional's branches only when it\n\t * needs them, so one that does this is written inside the branch that needs it.\n\t */\n\ttraverses(node: ts.Node, frame: Frame): boolean {\n\t\tif (ts.isFunctionLike(node)) {\n\t\t\treturn false;\n\t\t}\n\t\tif (ts.isCallExpression(node) && this.traversing(node, frame)) {\n\t\t\treturn true;\n\t\t}\n\t\treturn (\n\t\t\tts.forEachChild(node, (child) => this.traverses(child, frame)) ?? false\n\t\t);\n\t}\n\n\tprivate get generators(): GeneratorRunner {\n\t\tif (!this.runner) {\n\t\t\tthrow new Error(\"Nothing runs generators yet.\");\n\t\t}\n\t\treturn this.runner;\n\t}\n\n\t/** `iterator.name(…)`, a call to one of JavaScript's iterator helpers. */\n\tprivate helper(\n\t\tnode: ts.Expression,\n\t): { name: string; receiver: ts.Expression } | undefined {\n\t\tif (\n\t\t\t!ts.isCallExpression(node) ||\n\t\t\t!ts.isPropertyAccessExpression(node.expression)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst receiver = node.expression.expression;\n\t\tconst type = this.context.checker.getTypeAtLocation(receiver);\n\t\t// The helpers are JavaScript's own; a program's class may share their names.\n\t\tif (\n\t\t\t!type.getProperty(\"next\") ||\n\t\t\t!type.getProperty(\"toArray\") ||\n\t\t\t!providedByRuntime(this.context.checker, node.expression.name)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn { name: node.expression.name.text, receiver };\n\t}\n\n\tprivate traversing(node: ts.CallExpression, frame: Frame): boolean {\n\t\tif (this.helper(node)) {\n\t\t\treturn true;\n\t\t}\n\t\treturn (\n\t\t\tts.isPropertyAccessExpression(node.expression) &&\n\t\t\tnode.expression.name.text !== \"slice\" &&\n\t\t\tthis.loopsAtRunTime(node.expression.expression, frame, { sliced: false })\n\t\t);\n\t}\n\n\t/**\n\t * Whether an array's methods loop over it at run time: a snapshot by its name, or a slice of a\n\t * snapshot or of a runtime array.\n\t */\n\tprivate loopsAtRunTime(\n\t\tnode: ts.Expression,\n\t\tframe: Frame,\n\t\t{ sliced }: { sliced: boolean },\n\t): boolean {\n\t\tconst inner = unwrapped(node);\n\t\tif (\n\t\t\tts.isCallExpression(inner) &&\n\t\t\tts.isPropertyAccessExpression(inner.expression) &&\n\t\t\tinner.expression.name.text === \"slice\"\n\t\t) {\n\t\t\treturn this.loopsAtRunTime(inner.expression.expression, frame, {\n\t\t\t\tsliced: true,\n\t\t\t});\n\t\t}\n\t\tconst value = this.glance(inner, frame, { sliced });\n\t\tif (value?.kind === \"counted\") {\n\t\t\treturn value.source.kind === \"array\";\n\t\t}\n\t\treturn sliced && value !== undefined && this.storage(value) !== undefined;\n\t}\n\n\t/**\n\t * What an array expression is, without writing code for it: a local by its name, and a field\n\t * a slice is taken of by evaluating it and dropping the code. Undefined for anything else.\n\t */\n\tprivate glance(\n\t\tnode: ts.Expression,\n\t\tframe: Frame,\n\t\t{ sliced }: { sliced: boolean },\n\t): Value | undefined {\n\t\tif (ts.isIdentifier(node)) {\n\t\t\tconst symbol = this.context.checker.getSymbolAtLocation(node);\n\t\t\treturn symbol && frame.env.get(symbol);\n\t\t}\n\t\tif (!sliced || !ts.isPropertyAccessExpression(node)) {\n\t\t\treturn undefined;\n\t\t}\n\t\ttry {\n\t\t\treturn this.expressions.speculatively(() =>\n\t\t\t\tthis.expressions.expression(node, {\n\t\t\t\t\t...frame,\n\t\t\t\t\temitter: new Emitter(node),\n\t\t\t\t}),\n\t\t\t);\n\t\t} catch (cause) {\n\t\t\tif (cause instanceof SpecializeError) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tthrow cause;\n\t\t}\n\t}\n\n\t/** A generator call, read through the helpers that give another iterator. */\n\tprivate pipeline(node: ts.Expression, frame: Frame): Traversal {\n\t\tconst inner = unwrapped(node);\n\t\tconst generator = this.generator(inner, frame);\n\t\tif (generator) {\n\t\t\treturn this.generated(generator, inner);\n\t\t}\n\t\tconst helper = this.helper(inner);\n\t\tif (!helper || !ts.isCallExpression(inner)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"A generator runs in place: call it where a for…of or an iterator helper reads it.\",\n\t\t\t);\n\t\t}\n\t\tconst source = this.pipeline(helper.receiver, frame);\n\t\tswitch (helper.name) {\n\t\t\tcase \"map\":\n\t\t\t\treturn this.mapped(\n\t\t\t\t\tsource,\n\t\t\t\t\tcallbackArgument(inner, frame, this.expressions),\n\t\t\t\t\tinner,\n\t\t\t\t);\n\t\t\tcase \"filter\":\n\t\t\t\treturn this.filtered(\n\t\t\t\t\tsource,\n\t\t\t\t\tcallbackArgument(inner, frame, this.expressions),\n\t\t\t\t\tinner,\n\t\t\t\t);\n\t\t\tcase \"take\":\n\t\t\t\treturn this.taken(source, this.amount(inner, frame));\n\t\t\tcase \"drop\":\n\t\t\t\treturn this.dropped(source, this.amount(inner, frame));\n\t\t\tdefault:\n\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\tinner,\n\t\t\t\t\t`${helper.name} gives no iterator the PLC can run in place; use map, filter, take or drop.`,\n\t\t\t\t);\n\t\t}\n\t}\n\n\tprivate generated(generator: GeneratorCall, at: ts.Node): Traversal {\n\t\treturn {\n\t\t\trun: (frame, visit) => {\n\t\t\t\tconst depth = frame.loops.length;\n\t\t\t\tthis.generators.run(generator, frame, at, (value, jumps) =>\n\t\t\t\t\tvisit({ ...jumps, value, repeats: repeats(frame, depth) }),\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate mapped(\n\t\tsource: Traversal,\n\t\tcallback: Value,\n\t\tat: ts.CallExpression,\n\t): Traversal {\n\t\treturn {\n\t\t\tlimit: source.limit,\n\t\t\trun: (frame, visit) => {\n\t\t\t\tconst index = this.indexer(source, callback, 1, frame);\n\t\t\t\tsource.run(frame, (element) =>\n\t\t\t\t\tvisit({\n\t\t\t\t\t\t...element,\n\t\t\t\t\t\tvalue: this.expressions.invoke(\n\t\t\t\t\t\t\tcallback,\n\t\t\t\t\t\t\t[element.value, index(element)],\n\t\t\t\t\t\t\tat,\n\t\t\t\t\t\t\tframe,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tindex: undefined,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate filtered(\n\t\tsource: Traversal,\n\t\tcallback: Value,\n\t\tat: ts.CallExpression,\n\t): Traversal {\n\t\treturn {\n\t\t\tlimit: source.limit,\n\t\t\trun: (frame, visit) => {\n\t\t\t\tconst index = this.indexer(source, callback, 1, frame);\n\t\t\t\tsource.run(frame, (element) => {\n\t\t\t\t\tconst value = this.once(element.value, frame);\n\t\t\t\t\tconst test = this.expressions.invoke(\n\t\t\t\t\t\tcallback,\n\t\t\t\t\t\t[value, index(element)],\n\t\t\t\t\t\tat,\n\t\t\t\t\t\tframe,\n\t\t\t\t\t);\n\t\t\t\t\tconst passed = truth(test);\n\t\t\t\t\tif (passed === false) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (passed === undefined) {\n\t\t\t\t\t\tframe.emitter.open(mapped`if (${this.condition(test, at)}) {`);\n\t\t\t\t\t}\n\t\t\t\t\tvisit({ ...element, value, index: undefined });\n\t\t\t\t\tif (passed === undefined) {\n\t\t\t\t\t\tframe.emitter.close();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t}\n\n\t/** `take(limit)` ends the generator once it has passed on `limit` elements, before the generator runs on to its next yield. */\n\tprivate taken(source: Traversal, limit: Value): Traversal {\n\t\tconst fixed = known(limit);\n\t\treturn {\n\t\t\tlimit: fewest(source.limit, fixed),\n\t\t\trun: (frame, visit) => {\n\t\t\t\tif (fixed !== undefined && fixed <= 0) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst taken = frame.emitter.temporary();\n\t\t\t\tframe.emitter.line(`let ${taken}: number = 0;`);\n\t\t\t\tif (fixed === undefined) {\n\t\t\t\t\tframe.emitter.open(mapped`if (${this.text(limit)} > 0) {`);\n\t\t\t\t}\n\t\t\t\tsource.run(frame, (element) => {\n\t\t\t\t\tconst label = frame.emitter.local(\"tsplcStep\");\n\t\t\t\t\tframe.emitter.line(`${taken} = ${taken} + 1;`);\n\t\t\t\t\t// A continue in the code reading the element must still reach the count below.\n\t\t\t\t\tframe.emitter.open(`${label}: {`);\n\t\t\t\t\tvisit({ ...element, label });\n\t\t\t\t\tframe.emitter.close();\n\t\t\t\t\tframe.emitter.line(\n\t\t\t\t\t\tmapped`if (${taken} >= ${this.text(limit)}) { break ${element.whole}; }`,\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\tif (fixed === undefined) {\n\t\t\t\t\tframe.emitter.close();\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate dropped(source: Traversal, limit: Value): Traversal {\n\t\tconst fixed = known(limit);\n\t\tif (fixed !== undefined && fixed <= 0) {\n\t\t\treturn source;\n\t\t}\n\t\treturn {\n\t\t\tlimit: source.limit,\n\t\t\trun: (frame, visit) => {\n\t\t\t\tconst dropped = frame.emitter.temporary();\n\t\t\t\tframe.emitter.line(`let ${dropped}: number = 0;`);\n\t\t\t\tsource.run(frame, (element) => {\n\t\t\t\t\tframe.emitter.line(\n\t\t\t\t\t\tmapped`if (${dropped} < ${this.text(limit)}) { ${dropped} = ${dropped} + 1; break ${element.label}; }`,\n\t\t\t\t\t);\n\t\t\t\t\tvisit({ ...element, index: undefined });\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t}\n\n\t/** A helper or array method that reads a traversal to its result. */\n\tprivate terminal(\n\t\tname: string,\n\t\ttraversal: Traversal,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tswitch (name) {\n\t\t\tcase \"some\":\n\t\t\tcase \"every\": {\n\t\t\t\tconst callback = callbackArgument(node, frame, this.expressions);\n\t\t\t\tconst index = this.indexer(traversal, callback, 1, frame);\n\t\t\t\treturn this.decided(\n\t\t\t\t\ttraversal,\n\t\t\t\t\tnode,\n\t\t\t\t\tframe,\n\t\t\t\t\t{ some: name === \"some\" },\n\t\t\t\t\t(element) =>\n\t\t\t\t\t\tthis.expressions.invoke(\n\t\t\t\t\t\t\tcallback,\n\t\t\t\t\t\t\t[element.value, index(element)],\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\tframe,\n\t\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase \"includes\": {\n\t\t\t\tconst target = searchTarget(node, frame, this.expressions);\n\t\t\t\treturn this.decided(traversal, node, frame, { some: true }, (element) =>\n\t\t\t\t\tthis.expressions.equality(element.value, target, { negate: false }),\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase \"find\":\n\t\t\t\treturn this.find(traversal, node, frame);\n\t\t\tcase \"findIndex\": {\n\t\t\t\tconst callback = callbackArgument(node, frame, this.expressions);\n\t\t\t\treturn this.position(traversal, node, frame, (element) =>\n\t\t\t\t\tthis.expressions.invoke(\n\t\t\t\t\t\tcallback,\n\t\t\t\t\t\t[element.value, element.index ?? constant(undefined)],\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\tframe,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase \"indexOf\": {\n\t\t\t\tconst target = searchTarget(node, frame, this.expressions);\n\t\t\t\treturn this.position(traversal, node, frame, (element) =>\n\t\t\t\t\tthis.expressions.equality(element.value, target, { negate: false }),\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase \"forEach\": {\n\t\t\t\tconst callback = callbackArgument(node, frame, this.expressions);\n\t\t\t\tconst index = this.indexer(traversal, callback, 1, frame);\n\t\t\t\ttraversal.run(frame, (element) => {\n\t\t\t\t\tconst result = this.expressions.invoke(\n\t\t\t\t\t\tcallback,\n\t\t\t\t\t\t[element.value, index(element)],\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\tframe,\n\t\t\t\t\t);\n\t\t\t\t\tif (result.kind === \"code\") {\n\t\t\t\t\t\tframe.emitter.line(mapped`${result.text};`);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn constant(undefined);\n\t\t\t}\n\t\t\tcase \"reduce\":\n\t\t\t\treturn this.reduce(traversal, node, frame);\n\t\t\tcase \"toArray\":\n\t\t\t\treturn this.snapshot(traversal, node, frame);\n\t\t\tdefault:\n\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\tnode,\n\t\t\t\t\t`${name} is not supported on an iterator, or an array whose length is decided at run time.`,\n\t\t\t\t);\n\t\t}\n\t}\n\n\t/** `some` and `every`: the traversal ends at the first element whose test decides the result. */\n\tprivate decided(\n\t\ttraversal: Traversal,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t\t{ some }: { some: boolean },\n\t\ttest: (element: Visited) => Value,\n\t): Value {\n\t\tconst result = frame.emitter.temporary();\n\t\tframe.emitter.line(`let ${result}: boolean = ${!some};`);\n\t\ttraversal.run(frame, (element) => {\n\t\t\tconst tested = test(element);\n\t\t\tconst passed = truth(tested);\n\t\t\tif (passed === undefined) {\n\t\t\t\tconst condition = this.condition(tested, node);\n\t\t\t\tframe.emitter.line(\n\t\t\t\t\tmapped`if (${some ? condition : mapped`!(${condition})`}) { ${result} = ${String(some)}; break ${element.whole}; }`,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (passed === some) {\n\t\t\t\tframe.emitter.line(`${result} = ${some};`);\n\t\t\t\tframe.emitter.line(`break ${element.whole};`);\n\t\t\t}\n\t\t});\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: result,\n\t\t\tdeclared: this.context.checker.getBooleanType(),\n\t\t\tplace: true,\n\t\t};\n\t}\n\n\t/**\n\t * `find`: the first element whose test passes, or undefined; the traversal ends there. Among\n\t * objects setup built it is a reference to the one that passed, and otherwise a copy of the value.\n\t */\n\tprivate find(\n\t\ttraversal: Traversal,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst callback = callbackArgument(node, frame, this.expressions);\n\t\tconst index = this.indexer(traversal, callback, 1, frame);\n\t\tconst declared = this.context.checker.getTypeAtLocation(node);\n\t\tconst values = this.trial(traversal, frame).map(({ value }) => value);\n\t\tconst referred = references(values);\n\t\tconst slot = referred\n\t\t\t? this.referenceSlot({ ...referred, optional: true }, node)\n\t\t\t: this.optionalSlot(values, declared, node);\n\t\tconst result = frame.emitter.temporary();\n\t\tframe.emitter.line(mapped`let ${result}: ${slot.type} = ${slot.empty()};`);\n\t\ttraversal.run(frame, (visited) => {\n\t\t\tconst value = this.once(visited.value, frame);\n\t\t\tconst test = this.expressions.invoke(\n\t\t\t\tcallback,\n\t\t\t\t[value, index(visited)],\n\t\t\t\tnode,\n\t\t\t\tframe,\n\t\t\t);\n\t\t\tconst passed = truth(test);\n\t\t\tif (passed === false) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (passed === undefined) {\n\t\t\t\tframe.emitter.open(mapped`if (${this.condition(test, node)}) {`);\n\t\t\t}\n\t\t\tframe.emitter.line(mapped`${result} = ${slot.store(value)};`);\n\t\t\tframe.emitter.line(`break ${visited.whole};`);\n\t\t\tif (passed === undefined) {\n\t\t\t\tframe.emitter.close();\n\t\t\t}\n\t\t});\n\t\treturn slot.read(result);\n\t}\n\n\t/** `findIndex` and `indexOf`: the index of the first element whose test passes, or -1. */\n\tprivate position(\n\t\ttraversal: Traversal,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t\ttest: (element: Visited) => Value,\n\t): Value {\n\t\tconst result = frame.emitter.temporary();\n\t\tframe.emitter.line(`let ${result}: number = -1;`);\n\t\ttraversal.run(frame, (element) => {\n\t\t\tif (!element.index) {\n\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\tnode,\n\t\t\t\t\t\"Only an array's elements have indexes.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst tested = test(element);\n\t\t\tconst passed = truth(tested);\n\t\t\tif (passed === false) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst found = mapped`${result} = ${this.text(element.index)}; break ${element.whole};`;\n\t\t\tframe.emitter.line(\n\t\t\t\tpassed === undefined\n\t\t\t\t\t? mapped`if (${this.condition(tested, node)}) { ${found} }`\n\t\t\t\t\t: found,\n\t\t\t);\n\t\t});\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: result,\n\t\t\tdeclared: this.context.checker.getNumberType(),\n\t\t\tplace: true,\n\t\t};\n\t}\n\n\t/** `reduce(step, initial)`: the result so far is a local each element's step stores into. */\n\tprivate reduce(\n\t\ttraversal: Traversal,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst callback = callbackArgument(node, frame, this.expressions);\n\t\tconst [, initialNode] = node.arguments;\n\t\tif (!initialNode) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"reduce needs an initial value here: whether there is a first element is decided at run time.\",\n\t\t\t);\n\t\t}\n\t\tconst declared = this.context.checker.getTypeAtLocation(node);\n\t\tconst initial = this.expressions.expression(initialNode, frame, declared);\n\t\tconst total = frame.emitter.temporary();\n\t\tframe.emitter.line(\n\t\t\tmapped`let ${total}: ${this.expressions.localType(declared)} = ${this.context.dialect.assignmentText(initial, declared, undefined)};`,\n\t\t);\n\t\tconst accumulated: Value = {\n\t\t\tkind: \"code\",\n\t\t\ttext: total,\n\t\t\tdeclared,\n\t\t\tplace: true,\n\t\t};\n\t\tconst index = this.indexer(traversal, callback, 2, frame);\n\t\ttraversal.run(frame, (element) => {\n\t\t\tconst next = this.expressions.invoke(\n\t\t\t\tcallback,\n\t\t\t\t[accumulated, element.value, index(element)],\n\t\t\t\tnode,\n\t\t\t\tframe,\n\t\t\t);\n\t\t\tframe.emitter.line(\n\t\t\t\tmapped`${total} = ${this.context.dialect.assignmentText(next, declared, undefined)};`,\n\t\t\t);\n\t\t});\n\t\treturn accumulated;\n\t}\n\n\t/**\n\t * `toArray()`: a local array filled with what the traversal passes on, and how many it did. The\n\t * traversal is written out once without keeping it, to learn what it yields and how often, since\n\t * the array is declared before the code that fills it.\n\t */\n\tprivate snapshot(\n\t\ttraversal: Traversal,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst trial = this.trial(traversal, frame);\n\t\tconst unbounded = trial.some(({ repeats }) => repeats === undefined);\n\t\tif (unbounded && traversal.limit === undefined) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"toArray needs the most the generator can yield, to size its array: a yield here is in a loop with no counted bound. Yield from a counted for loop, or from a loop over what setup built.\",\n\t\t\t);\n\t\t}\n\t\tconst yielded = unbounded\n\t\t\t? Number.POSITIVE_INFINITY\n\t\t\t: trial.reduce((total, { repeats }) => total + (repeats ?? 0), 0);\n\t\tconst bound = Math.min(yielded, traversal.limit ?? yielded);\n\t\tconst element = this.context.model.elementType(\n\t\t\tthis.context.checker.getTypeAtLocation(node),\n\t\t);\n\t\tconst values = trial.map(({ value }) => value);\n\t\tconst referred = references(values);\n\t\tconst slot = referred\n\t\t\t? this.referenceSlot(referred, node)\n\t\t\t: this.valueSlot(values, element, node);\n\t\tconst array = frame.emitter.temporary();\n\t\tconst count = frame.emitter.temporary();\n\t\tconst layout = arrayLayout(slot.type, bound);\n\t\tframe.emitter.line(\n\t\t\t`let ${array}: ${layout.text} = defaultValue<${layout.text}>();`,\n\t\t);\n\t\t// Unsigned, so its remainder is proved an index of the array; the count itself never reaches the bound.\n\t\tframe.emitter.line(`let ${count}: UDINT = 0;`);\n\t\ttraversal.run(frame, ({ value }) => {\n\t\t\tframe.emitter.line(\n\t\t\t\tmapped`${array}[${count} % ${layout.bound}] = ${slot.store(value)};`,\n\t\t\t);\n\t\t\tframe.emitter.line(`${count} = ${count} + 1;`);\n\t\t});\n\t\tconst length = frame.emitter.temporary();\n\t\tframe.emitter.line(\n\t\t\tmapped`const ${length}: number = ${this.context.dialect.assignmentText({ kind: \"code\", text: count, iec: \"UDINT\" }, this.context.checker.getNumberType(), undefined)};`,\n\t\t);\n\t\treturn {\n\t\t\tkind: \"counted\",\n\t\t\tsource: {\n\t\t\t\tkind: \"array\",\n\t\t\t\ttext: array,\n\t\t\t\tlayout: layout.text,\n\t\t\t\tbound,\n\t\t\t\tsnapshot: true,\n\t\t\t\tfilled: this.number(length),\n\t\t\t\telement: (index) => slot.read(mapped`${array}[${index}]`),\n\t\t\t},\n\t\t\tstart: constant(0),\n\t\t\tend: this.number(length),\n\t\t};\n\t}\n\n\t/** What a traversal passes on, each with how often, from writing it out without keeping anything it wrote. */\n\tprivate trial(traversal: Traversal, frame: Frame): Visited[] {\n\t\tconst visits: Visited[] = [];\n\t\tthis.expressions.speculatively(() =>\n\t\t\ttraversal.run(\n\t\t\t\t{ ...frame, emitter: new Emitter(frame.emitter.origin) },\n\t\t\t\t(element) => {\n\t\t\t\t\tvisits.push(element);\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t\treturn visits;\n\t}\n\n\t/** A local that keeps a reference to one of the objects setup built: the object's id, so it is still that object. */\n\tprivate referenceSlot(\n\t\t{ options, optional }: { options: readonly ModelNode[]; optional: boolean },\n\t\tnode: ts.CallExpression,\n\t): Slot {\n\t\treturn {\n\t\t\ttype: referenceLayout,\n\t\t\tempty: () => noReference,\n\t\t\tstore: (value) => {\n\t\t\t\tconst index = referenceIndex(value);\n\t\t\t\tif (index === undefined) {\n\t\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\"This keeps references to objects setup built, and one of its values is none.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn index;\n\t\t\t},\n\t\t\tread: (place) => ({ kind: \"choice\", options, index: place, optional }),\n\t\t};\n\t}\n\n\t/** A local that keeps a copy of a value, as JavaScript copies a number and the PLC copies a record. */\n\tprivate valueSlot(\n\t\tvalues: readonly Value[],\n\t\telement: ts.Type | undefined,\n\t\tnode: ts.CallExpression,\n\t): Slot {\n\t\tif (!element) {\n\t\t\tthrow new SpecializeError(node, \"toArray needs an element type.\");\n\t\t}\n\t\treturn {\n\t\t\ttype: this.expressions.localType(element),\n\t\t\tempty: () => `defaultValue<${this.expressions.localType(element)}>()`,\n\t\t\tstore: (value) =>\n\t\t\t\tthis.context.dialect.assignmentText(\n\t\t\t\t\tcopyable(value, node),\n\t\t\t\t\telement,\n\t\t\t\t\tundefined,\n\t\t\t\t),\n\t\t\tread: (place) => ({\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: place,\n\t\t\t\tdeclared: element,\n\t\t\t\tplace: true,\n\t\t\t\tcopyOf: copiedFrom(values, \"toArray\"),\n\t\t\t}),\n\t\t};\n\t}\n\n\t/** A local that keeps a copy of a value or undefined, as `find`'s result is. */\n\tprivate optionalSlot(\n\t\tvalues: readonly Value[],\n\t\tdeclared: ts.Type,\n\t\tnode: ts.CallExpression,\n\t): Slot {\n\t\tconst element = this.context.checker.getNonNullableType(declared);\n\t\treturn {\n\t\t\ttype: this.expressions.localType(declared),\n\t\t\tempty: () =>\n\t\t\t\tthis.context.dialect.assignmentText(\n\t\t\t\t\tconstant(undefined),\n\t\t\t\t\tdeclared,\n\t\t\t\t\tundefined,\n\t\t\t\t),\n\t\t\tstore: (value) =>\n\t\t\t\tthis.context.dialect.wrapDefined(\n\t\t\t\t\tthis.context.dialect.code(copyable(value, node), element),\n\t\t\t\t\tdeclared,\n\t\t\t\t),\n\t\t\tread: (place) => ({\n\t\t\t\tkind: \"code\",\n\t\t\t\ttext: place,\n\t\t\t\tdeclared,\n\t\t\t\tplace: true,\n\t\t\t\tcopyOf: copiedFrom(values, \"find\"),\n\t\t\t}),\n\t\t};\n\t}\n\n\t/** Elements setup fixed, each read only if its index is in the slice's range. */\n\tprivate overItems(counted: Counted, items: readonly Value[]): Traversal {\n\t\treturn {\n\t\t\tindexed: true,\n\t\t\trun: (frame, visit) => {\n\t\t\t\tconst whole = frame.emitter.local(\"tsplcEach\");\n\t\t\t\tframe.emitter.open(`${whole}: {`);\n\t\t\t\titems.forEach((item, position) => {\n\t\t\t\t\tconst inside = this.has(counted, position);\n\t\t\t\t\tif (inside === false) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (inside !== true) {\n\t\t\t\t\t\tframe.emitter.open(mapped`if (${inside}) {`);\n\t\t\t\t\t}\n\t\t\t\t\tconst label = frame.emitter.local(\"tsplcStep\");\n\t\t\t\t\tframe.emitter.open(`${label}: {`);\n\t\t\t\t\tvisit({\n\t\t\t\t\t\tvalue: item,\n\t\t\t\t\t\tindex: this.difference(constant(position), counted.start),\n\t\t\t\t\t\twhole,\n\t\t\t\t\t\tlabel,\n\t\t\t\t\t\trepeats: 1,\n\t\t\t\t\t});\n\t\t\t\t\tframe.emitter.close();\n\t\t\t\t\tif (inside !== true) {\n\t\t\t\t\t\tframe.emitter.close();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tframe.emitter.close();\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * `some`, `every` and `includes` over elements setup fixed, as one expression: each element's\n\t * test counts only when its index is in range. An expression needs no statements, so `&&` and\n\t * `||` around it skip it as JavaScript does.\n\t */\n\tprivate tested(\n\t\tname: \"some\" | \"every\" | \"includes\",\n\t\tcounted: Counted,\n\t\titems: readonly Value[],\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst some = name !== \"every\";\n\t\tconst test = this.elementTest(name, node, frame);\n\t\tconst terms: (string | Mapped)[] = [];\n\t\tfor (const [position, item] of items.entries()) {\n\t\t\tconst inside = this.has(counted, position);\n\t\t\tif (inside === false) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst tested = test(\n\t\t\t\titem,\n\t\t\t\tthis.difference(constant(position), counted.start),\n\t\t\t);\n\t\t\tconst passed = truth(tested);\n\t\t\tif (passed === !some) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (passed === some && inside === true) {\n\t\t\t\treturn constant(some);\n\t\t\t}\n\t\t\tconst condition =\n\t\t\t\tpassed === undefined ? this.condition(tested, node) : undefined;\n\t\t\tterms.push(this.term(inside, condition, { some }));\n\t\t}\n\t\tif (!terms.length) {\n\t\t\treturn constant(!some);\n\t\t}\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: mapped`(${joined(terms, some ? \" || \" : \" && \")})`,\n\t\t\tdeclared: this.context.checker.getBooleanType(),\n\t\t};\n\t}\n\n\t/** One element's part of a `some` or `every`: for `some` in range and passing, for `every` out of range or passing. */\n\tprivate term(\n\t\tinside: true | Mapped,\n\t\tcondition: string | Mapped | undefined,\n\t\t{ some }: { some: boolean },\n\t): string | Mapped {\n\t\tif (inside === true) {\n\t\t\treturn condition ?? String(some);\n\t\t}\n\t\tif (condition === undefined) {\n\t\t\treturn some ? mapped`(${inside})` : mapped`!(${inside})`;\n\t\t}\n\t\treturn some\n\t\t\t? mapped`(${inside} && ${condition})`\n\t\t\t: mapped`(!(${inside}) || ${condition})`;\n\t}\n\n\tprivate elementTest(\n\t\tname: \"some\" | \"every\" | \"includes\",\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): (item: Value, index: Value) => Value {\n\t\tif (name === \"includes\") {\n\t\t\tconst target = searchTarget(node, frame, this.expressions);\n\t\t\treturn (item) =>\n\t\t\t\tthis.expressions.equality(item, target, { negate: false });\n\t\t}\n\t\tconst callback = callbackArgument(node, frame, this.expressions);\n\t\treturn (item, index) =>\n\t\t\tthis.expressions.invoke(callback, [item, index], node, frame);\n\t}\n\n\t/** Whether a counted array has the element at a storage index: known now, or a test of its bounds. */\n\tprivate has(counted: Counted, position: number): boolean | Mapped {\n\t\treturn all([\n\t\t\tthis.compare(counted.start, \"<=\", constant(position)),\n\t\t\tthis.compare(constant(position), \"<\", counted.end),\n\t\t]);\n\t}\n\n\t/** The element a counted array keeps at a storage index; undefined when the storage ends before it. */\n\tprivate stored(\n\t\tsource: Counted[\"source\"],\n\t\tposition: Value,\n\t\tfixed: number | undefined,\n\t\tat: ts.Node,\n\t): Value | undefined {\n\t\tif (source.kind === \"array\") {\n\t\t\treturn fixed !== undefined && fixed >= source.bound\n\t\t\t\t? undefined\n\t\t\t\t: source.element(this.text(position));\n\t\t}\n\t\tif (fixed === undefined) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t\"Index the array the slice was taken from, or the slice with an index setup fixed.\",\n\t\t\t);\n\t\t}\n\t\treturn source.items[fixed];\n\t}\n\n\t/** The slice of a counted array from `start` to `end`, each counting back from the end when negative, as JavaScript reads them. */\n\tprivate slice(\n\t\ttarget: Counted,\n\t\tbounds: { start: Value | undefined; end: Value | undefined },\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value {\n\t\tconst length = this.kept(this.difference(target.end, target.start), frame);\n\t\tconst start = this.bound(bounds.start, node, frame);\n\t\tconst end = this.bound(bounds.end, node, frame);\n\t\tconst from = this.kept(\n\t\t\tstart ? this.relative(start, length) : constant(0),\n\t\t\tframe,\n\t\t);\n\t\tconst to = this.kept(end ? this.relative(end, length) : length, frame);\n\t\treturn {\n\t\t\tkind: \"counted\",\n\t\t\tsource: target.source,\n\t\t\tstart: this.kept(this.sum(target.start, from), frame),\n\t\t\t// A slice that ends before it starts is empty, which an end at its start says.\n\t\t\tend: this.kept(\n\t\t\t\tthis.sum(target.start, known(from) === 0 ? to : this.most(to, from)),\n\t\t\t\tframe,\n\t\t\t),\n\t\t};\n\t}\n\n\t/** A slice bound as a number: known now, or held in a const where the slice is made. */\n\tprivate bound(\n\t\tvalue: Value | undefined,\n\t\tnode: ts.CallExpression,\n\t\tframe: Frame,\n\t): Value | undefined {\n\t\tif (!value || (value.kind === \"const\" && value.value === undefined)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst fixed = known(value);\n\t\tif (fixed !== undefined) {\n\t\t\treturn constant(Math.trunc(fixed));\n\t\t}\n\t\tif (value.kind !== \"code\") {\n\t\t\tthrow new SpecializeError(node, \"slice needs numbers for its bounds.\");\n\t\t}\n\t\tconst local = frame.emitter.temporary();\n\t\tframe.emitter.line(\n\t\t\tmapped`const ${local}: number = ${this.context.dialect.assignmentText(value, this.context.checker.getNumberType(), undefined)};`,\n\t\t);\n\t\treturn this.number(local);\n\t}\n\n\t/** A slice bound as an index from 0 to the length. */\n\tprivate relative(bound: Value, length: Value): Value {\n\t\tconst fixed = known(bound);\n\t\tif (fixed === 0) {\n\t\t\treturn bound;\n\t\t}\n\t\tif (fixed !== undefined && fixed > 0) {\n\t\t\treturn this.least(bound, length);\n\t\t}\n\t\tif (fixed !== undefined) {\n\t\t\treturn this.most(this.difference(length, constant(-fixed)), constant(0));\n\t\t}\n\t\tconst index = this.text(bound);\n\t\tconst size = this.text(length);\n\t\treturn this.number(\n\t\t\tmapped`(${index} < 0 ? (${size} + ${index} > 0 ? ${size} + ${index} : 0) : (${index} < ${size} ? ${index} : ${size}))`,\n\t\t);\n\t}\n\n\t/** The position a callback is given, counted at run time only if the callback takes it. */\n\tprivate indexer(\n\t\ttraversal: Traversal,\n\t\tcallback: Value,\n\t\tparameter: number,\n\t\tframe: Frame,\n\t): (element: Visited) => Value {\n\t\tif (!takes(callback, parameter) || traversal.indexed) {\n\t\t\treturn (element) => element.index ?? constant(undefined);\n\t\t}\n\t\tconst total = frame.emitter.temporary();\n\t\tframe.emitter.line(`let ${total}: number = 0;`);\n\t\treturn () => {\n\t\t\tconst index = frame.emitter.temporary();\n\t\t\t// Held before the count moves on, which a continue in the code after this would skip.\n\t\t\tframe.emitter.line(`const ${index}: number = ${total};`);\n\t\t\tframe.emitter.line(`${total} = ${total} + 1;`);\n\t\t\treturn this.number(index);\n\t\t};\n\t}\n\n\t/** `take` and `drop`'s count: known now, or held in a const before the generator runs. */\n\tprivate amount(node: ts.CallExpression, frame: Frame): Value {\n\t\tconst [argument] = node.arguments;\n\t\tconst value = argument && this.expressions.expression(argument, frame);\n\t\tconst count = value && this.bound(value, node, frame);\n\t\tif (!count) {\n\t\t\tthrow new SpecializeError(node, \"Pass how many elements.\");\n\t\t}\n\t\treturn count;\n\t}\n\n\t/**\n\t * A computed value read once, into a const, where the code after reads it more than once. A place\n\t * is read where it is: a const naming one would be an alias of it, not a copy.\n\t */\n\tprivate once(value: Value, frame: Frame): Value {\n\t\treturn value.kind === \"code\" && !value.place\n\t\t\t? this.expressions.temporaryOf(value, frame)\n\t\t\t: value;\n\t}\n\n\t/** A number computed at run time in a const of its own, so the bounds that use it read it rather than repeat it. */\n\tprivate kept(value: Value, frame: Frame): Value {\n\t\treturn value.kind === \"code\"\n\t\t\t? this.expressions.temporaryOf(value, frame)\n\t\t\t: value;\n\t}\n\n\tprivate condition(value: Value, at: ts.CallExpression): string | Mapped {\n\t\treturn this.context.dialect.condition(value, at.arguments[0] ?? at);\n\t}\n\n\tprivate number(text: string | Mapped): Value {\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext,\n\t\t\tdeclared: this.context.checker.getNumberType(),\n\t\t\tplace: true,\n\t\t};\n\t}\n\n\tprivate text(value: Value): string | Mapped {\n\t\treturn this.context.dialect.code(value, undefined);\n\t}\n\n\tprivate sum(left: Value, right: Value): Value {\n\t\tconst [first, second] = [known(left), known(right)];\n\t\tif (first !== undefined && second !== undefined) {\n\t\t\treturn constant(first + second);\n\t\t}\n\t\tif (first === 0) {\n\t\t\treturn right;\n\t\t}\n\t\tif (second === 0) {\n\t\t\treturn left;\n\t\t}\n\t\treturn this.number(mapped`(${this.text(left)} + ${this.text(right)})`);\n\t}\n\n\tprivate difference(left: Value, right: Value): Value {\n\t\tconst [first, second] = [known(left), known(right)];\n\t\tif (first !== undefined && second !== undefined) {\n\t\t\treturn constant(first - second);\n\t\t}\n\t\tif (second === 0) {\n\t\t\treturn left;\n\t\t}\n\t\treturn this.number(mapped`(${this.text(left)} - ${this.text(right)})`);\n\t}\n\n\tprivate least(left: Value, right: Value): Value {\n\t\tconst [first, second] = [known(left), known(right)];\n\t\tif (first !== undefined && second !== undefined) {\n\t\t\treturn constant(Math.min(first, second));\n\t\t}\n\t\tconst [low, other] = [this.text(left), this.text(right)];\n\t\treturn this.number(mapped`(${low} < ${other} ? ${low} : ${other})`);\n\t}\n\n\tprivate most(left: Value, right: Value): Value {\n\t\tconst [first, second] = [known(left), known(right)];\n\t\tif (first !== undefined && second !== undefined) {\n\t\t\treturn constant(Math.max(first, second));\n\t\t}\n\t\tconst [high, other] = [this.text(left), this.text(right)];\n\t\treturn this.number(mapped`(${high} > ${other} ? ${high} : ${other})`);\n\t}\n\n\tprivate compare(\n\t\tleft: Value,\n\t\toperator: \"<\" | \"<=\",\n\t\tright: Value,\n\t): boolean | Mapped {\n\t\tconst [first, second] = [known(left), known(right)];\n\t\tif (first !== undefined && second !== undefined) {\n\t\t\treturn operator === \"<\" ? first < second : first <= second;\n\t\t}\n\t\treturn mapped`${this.text(left)} ${operator} ${this.text(right)}`;\n\t}\n}\n\n/** How many times code written now can run, for the loops entered since `depth`. */\nconst repeats = (frame: Frame, depth: number): number | undefined =>\n\tframe.loops\n\t\t.slice(depth)\n\t\t.reduce<number | undefined>(\n\t\t\t(product, runs) =>\n\t\t\t\tproduct === undefined || runs === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: product * runs,\n\t\t\t1,\n\t\t);\n\n/** A value a local can keep a copy of. */\nconst copyable = (value: Value, at: ts.Node): Value => {\n\tif (value.kind === \"function\" || value.kind === \"counted\") {\n\t\tthrow new SpecializeError(\n\t\t\tat,\n\t\t\t\"This copies each value, and a function or an array whose length is decided at run time has no PLC value to copy.\",\n\t\t);\n\t}\n\treturn value;\n};\n\n/**\n * `method` when one of the values it copies is stored state: a record or array the PLC keeps,\n * or a copy of one. TypeScript would hand back the stored object itself, so writing the copy is\n * reported rather than lost.\n */\nconst copiedFrom = (\n\tvalues: readonly Value[],\n\tmethod: string,\n): string | undefined => (values.some(isStoredState) ? method : undefined);\n\n/** The smaller of two limits, either of which may be unknown. */\nconst fewest = (\n\tleft: number | undefined,\n\tright: number | undefined,\n): number | undefined => {\n\tif (left === undefined || right === undefined) {\n\t\treturn left ?? right;\n\t}\n\treturn Math.min(left, right);\n};\n\n/** Whether two numbers are the same one: equal constants, or the same local. */\nconst sameNumber = (left: Value, right: Value): boolean => {\n\tif (left.kind === \"code\" && right.kind === \"code\") {\n\t\treturn String(left.text) === String(right.text);\n\t}\n\tconst fixed = known(left);\n\treturn fixed !== undefined && fixed === known(right);\n};\n\n/**\n * A test's result when it is known now: a value setup fixed, or an object, which is always truthy.\n * A reference that may hold none is decided at run time.\n */\nconst truth = (value: Value): boolean | undefined => {\n\tif (value.kind === \"const\") {\n\t\treturn Boolean(value.value);\n\t}\n\tif (value.kind === \"choice\") {\n\t\treturn value.optional ? undefined : true;\n\t}\n\treturn value.kind === \"code\" ? undefined : true;\n};\n\n/** Every condition at once: false if one is known false, true if all are known true, otherwise the rest as one test. */\nconst all = (conditions: readonly (boolean | Mapped)[]): boolean | Mapped => {\n\tif (conditions.includes(false)) {\n\t\treturn false;\n\t}\n\tconst tests = conditions.filter(\n\t\t(condition): condition is Mapped => condition instanceof Mapped,\n\t);\n\treturn tests.length ? joined(tests, \" && \") : true;\n};\n\n/** Whether a callback declares the parameter at a position, so it reads what is passed there. */\nconst takes = (callback: Value, parameter: number): boolean =>\n\tcallback.kind === \"function\" &&\n\t!ts.isGetAccessorDeclaration(callback.declaration) &&\n\tcallback.declaration.parameters.some(\n\t\t(declared, position) =>\n\t\t\tposition === parameter ||\n\t\t\t(declared.dotDotDotToken !== undefined && position < parameter),\n\t);\n\n/** What reads an expression, outside the wrappers around it. */\nconst outside = (node: ts.Node): ts.Node =>\n\tisWrapper(node.parent) ? outside(node.parent) : node.parent;\n",
51
+ "import type ts from \"typescript\";\nimport { from, type Mapped, mapped, type Part } from \"../positions\";\nimport type { ArrayLayout } from \"./layouts\";\nimport type { ModelNode } from \"./model\";\nimport { unusedName } from \"./names\";\nimport type { Env, Value } from \"./values\";\n\n/** Indented lines of one generated routine, with the local names it has used. */\nexport class Emitter {\n\treadonly lines: Mapped[] = [];\n\tprivate depth = 1;\n\tprivate readonly used = new Set<string>();\n\tprivate temporaries = 0;\n\n\t/** @param origin The source the next lines come from: the statement being specialized. */\n\tconstructor(public origin: ts.Node) {}\n\n\tline(text: Part): void {\n\t\tthis.lines.push(\n\t\t\tfrom(this.origin, mapped`${\" \".repeat(this.depth)}${text}`),\n\t\t);\n\t}\n\topen(text: Part): void {\n\t\tthis.line(text);\n\t\tthis.depth++;\n\t}\n\tclose(text: Part = \"}\"): void {\n\t\tthis.depth--;\n\t\tthis.line(text);\n\t}\n\t/** Ends one block and starts the next on the same line, as `} else {` does. */\n\treopen(text: Part): void {\n\t\tthis.depth--;\n\t\tthis.line(text);\n\t\tthis.depth++;\n\t}\n\tlocal(name: string): string {\n\t\tconst unused = unusedName(name, (candidate) => this.used.has(candidate));\n\t\tthis.used.add(unused);\n\t\treturn unused;\n\t}\n\ttemporary(): string {\n\t\treturn this.local(`tsplcTemp${++this.temporaries}`);\n\t}\n\t/** Whether code reads a local this routine has named. */\n\tnames(text: Part): boolean {\n\t\treturn namesIn(text).some((name) => this.used.has(name));\n\t}\n\t/** Whether a line this routine has written reads `name`. */\n\treads(name: string): boolean {\n\t\treturn this.lines.some((line) => namesIn(line).includes(name));\n\t}\n\t/**\n\t * Runs `write` and takes the lines it wrote instead of keeping them, for a caller that places\n\t * them once it knows what surrounds them. `nested` indents them for a block the caller opens.\n\t */\n\tdetached<T>(\n\t\t{ nested }: { nested: boolean },\n\t\twrite: () => T,\n\t): { result: T; lines: Mapped[] } {\n\t\tconst start = this.lines.length;\n\t\tconst depth = this.depth;\n\t\tthis.depth += nested ? 1 : 0;\n\t\ttry {\n\t\t\tconst result = write();\n\t\t\treturn { result, lines: this.lines.splice(start) };\n\t\t} finally {\n\t\t\tthis.depth = depth;\n\t\t}\n\t}\n\t/** Places lines `detached` took. */\n\tappend(lines: readonly Mapped[]): void {\n\t\tthis.lines.push(...lines);\n\t}\n\t/** An if…else if chain, one arm for each test. */\n\tchain(arms: readonly { test: Part; body: VoidFunction }[]): void {\n\t\tarms.forEach((arm, index) => {\n\t\t\tif (index === 0) {\n\t\t\t\tthis.open(mapped`if (${arm.test}) {`);\n\t\t\t} else {\n\t\t\t\tthis.reopen(mapped`} else if (${arm.test}) {`);\n\t\t\t}\n\t\t\tarm.body();\n\t\t});\n\t\tif (arms.length > 0) {\n\t\t\tthis.close();\n\t\t}\n\t}\n}\n\n/** The names code reads: not a member's, nor the digits of a typed literal such as `16#FF`. */\nconst namesIn = (text: Part): string[] =>\n\tString(text).match(/(?<![\\w.#])[A-Za-z_]\\w*/g) ?? [];\n\nexport interface Frame {\n\temitter: Emitter;\n\tenv: Env;\n\t/**\n\t * How many times the body of each PLC loop being written can run, outermost first; undefined for\n\t * a loop with no counted bound. Frames within one routine share it.\n\t */\n\tloops: (number | undefined)[];\n\tself?: ModelNode;\n\t/** The routine's declared return type, for literal and optional results. */\n\treturns?: ts.Type;\n\tasync: boolean;\n\t/**\n\t * In a generator run inline for a for…of: what each yield runs, the loop's body over the value,\n\t * and the labelled block a return leaves.\n\t */\n\tgenerator?: { yields: (value: Value) => void; exit: string };\n\t/** An array result's layout, at the length the routine's return statements give it. */\n\tresultLayout?: ArrayLayout;\n\tresultLength?: number;\n\t/** Whether a return statement returned a stored record or array, which a caller only gets a copy of. */\n\treturnsStored?: boolean;\n\t/**\n\t * In a routine whose result is a reference: the objects its return statements return, and\n\t * whether one returns undefined.\n\t */\n\treferents?: Referents;\n}\n\n/**\n * Writes the body of a loop that stays a loop in the PLC. A yield in it runs up to `runs` times,\n * which sizes a snapshot of the generator; an unrolled loop needs none, as each step is written out.\n */\nexport const looping = <T>(\n\tframe: Frame,\n\truns: number | undefined,\n\tbody: () => T,\n): T => {\n\tframe.loops.push(runs);\n\ttry {\n\t\treturn body();\n\t} finally {\n\t\tframe.loops.pop();\n\t}\n};\n\n/** What a reference a routine returns can be. */\nexport interface Referents {\n\toptions: Set<ModelNode>;\n\toptional: boolean;\n}\n",
52
+ "import ts from \"typescript\";\nimport type { CapturedValue } from \"./capture-protocol\";\nimport {\n\tdefinedOptional,\n\tholdsInstances,\n\ttype Layouts,\n\trecordTypes,\n} from \"./layouts\";\nimport type { Model, ModelNode } from \"./model\";\nimport { noReference } from \"./references\";\nimport { mixedStateText, type Storage } from \"./storage\";\nimport { calendarConstructor } from \"./time-constructors\";\n\n/** Values setup captured as dialect text: storage initializers, and fixed data scan code reads. */\nexport class Initializers {\n\t/** SDK functions the text written since `takeSdkCalls` last ran calls, which its module imports. */\n\tprivate readonly sdkCalls = new Set<string>();\n\n\tconstructor(\n\t\tprivate readonly model: Model,\n\t\tprivate readonly checker: ts.TypeChecker,\n\t\tprivate readonly layouts: Layouts,\n\t\tprivate readonly storage: Storage,\n\t) {}\n\n\t/** A captured value as dialect text of its declared type. */\n\tvalueText(value: CapturedValue, declared: ts.Type, layout?: string): string {\n\t\tconst node = this.model.node(value);\n\t\tconst literal = this.layouts.literalEnum(declared);\n\t\tif (literal) {\n\t\t\treturn this.layouts.member(\n\t\t\t\tliteral,\n\t\t\t\tvalue.kind === \"string\" ? value.value : undefined,\n\t\t\t);\n\t\t}\n\t\tconst optional = this.layouts.isOptionalRecord(declared);\n\t\tif (optional) {\n\t\t\tconst inner = this.checker.getNonNullableType(declared);\n\t\t\tconst name = layout ?? this.layouts.text(declared, value);\n\t\t\treturn value.kind === \"undefined\"\n\t\t\t\t? `defaultValue<${name}>()`\n\t\t\t\t: definedOptional(this.valueText(value, inner)).text;\n\t\t}\n\t\tif (this.layouts.enumDeclaration(declared) && value.kind === \"number\") {\n\t\t\treturn (\n\t\t\t\tthis.layouts.enumMember(declared, value.value) ?? String(value.value)\n\t\t\t);\n\t\t}\n\t\t// Setup's TIME is a number of milliseconds; the dialect spells a TIME constant as a duration.\n\t\tif (\n\t\t\tvalue.kind === \"number\" &&\n\t\t\t(layout ?? declared.aliasSymbol?.name) === \"TIME\"\n\t\t) {\n\t\t\tthis.sdkCalls.add(\"ms\");\n\t\t\treturn `ms(${value.value})`;\n\t\t}\n\t\t// Setup's calendar value is the text it was written in, which its constructor takes.\n\t\tconst calendar = calendarConstructor(\n\t\t\tlayout ?? declared.aliasSymbol?.name ?? \"\",\n\t\t);\n\t\tif (value.kind === \"string\" && calendar) {\n\t\t\tthis.sdkCalls.add(calendar);\n\t\t\treturn `${calendar}(${JSON.stringify(value.value)})`;\n\t\t}\n\t\tif (!node) {\n\t\t\treturn this.literal(value);\n\t\t}\n\t\tif (node.captured.kind === \"array\") {\n\t\t\tconst element = this.model.elementType(declared);\n\t\t\t// Instances of different classes are stored side by side, a field each.\n\t\t\tconst mixed = this.storage.mixedStates(node);\n\t\t\tconst items = node.captured.items.map((item) =>\n\t\t\t\telement ? this.valueText(item, element) : this.literal(item),\n\t\t\t);\n\t\t\tif (mixed) {\n\t\t\t\treturn mixedStateText(items);\n\t\t\t}\n\t\t\tif (!items.length) {\n\t\t\t\treturn `defaultValue<${layout ?? this.layouts.text(declared, value)}>()`;\n\t\t\t}\n\t\t\treturn `[${items.join(\", \")}]`;\n\t\t}\n\t\tif (node.captured.kind === \"object\") {\n\t\t\treturn this.recordInitializer(node, declared);\n\t\t}\n\t\tif (node.captured.kind === \"instance\") {\n\t\t\tconst text = this.storage.storageType(node);\n\t\t\treturn text ? this.instanceInitializer(node) : \"{}\";\n\t\t}\n\t\tthrow new Error(\"A function has no stored value.\");\n\t}\n\n\t/** The SDK functions of `@tsplc/compiler/types` the text written since the last call calls. */\n\ttakeSdkCalls(): string[] {\n\t\tconst names = [...this.sdkCalls];\n\t\tthis.sdkCalls.clear();\n\t\treturn names;\n\t}\n\n\tprivate instanceInitializer(node: ModelNode): string {\n\t\treturn `{ ${this.storage\n\t\t\t.instanceFields(node)\n\t\t\t.map(\n\t\t\t\t([name, layout]) =>\n\t\t\t\t\t`${name}: ${this.instanceFieldInitializer(node, name, layout)}`,\n\t\t\t)\n\t\t\t.join(\", \")} }`;\n\t}\n\n\t/** The initial value of one of an instance's stored fields. */\n\tinstanceFieldInitializer(\n\t\tnode: ModelNode,\n\t\tname: string,\n\t\tlayout: string,\n\t): string {\n\t\tconst captured = node.captured;\n\t\tif (captured.kind !== \"instance\") {\n\t\t\tthrow new Error(\"Not an instance.\");\n\t\t}\n\t\tconst value = this.model.field(node, name);\n\t\tconst inner = this.model.node(value);\n\t\tif (this.storage.referenceField(node, name)) {\n\t\t\treturn inner ? String(inner.reference) : noReference;\n\t\t}\n\t\tif (inner?.captured.kind === \"instance\") {\n\t\t\treturn this.instanceInitializer(inner);\n\t\t}\n\t\tif (inner?.captured.kind === \"array\" && holdsInstances(this.model, inner)) {\n\t\t\tconst states = inner.captured.items.map((item) => {\n\t\t\t\tconst instance = this.model.node(item);\n\t\t\t\tif (!instance) {\n\t\t\t\t\tthrow new Error(`${name} holds a primitive among its instances.`);\n\t\t\t\t}\n\t\t\t\treturn this.instanceInitializer(instance);\n\t\t\t});\n\t\t\treturn this.storage.mixedStates(inner)\n\t\t\t\t? mixedStateText(states)\n\t\t\t\t: `[${states.join(\", \")}]`;\n\t\t}\n\t\tconst declared = this.model.capturedFieldType(node, name);\n\t\tif (!declared) {\n\t\t\tthrow new Error(`${name} has no declared type.`);\n\t\t}\n\t\treturn this.valueText(value, declared, layout);\n\t}\n\n\tprivate recordInitializer(node: ModelNode, declared: ts.Type): string {\n\t\tconst captured = node.captured;\n\t\tif (captured.kind !== \"object\") {\n\t\t\tthrow new Error(\"Not a record.\");\n\t\t}\n\t\tconst tagged = this.layouts.tagged(declared);\n\t\tconst record = recordTypes(declared);\n\t\tconst recordType = record\n\t\t\t? declared\n\t\t\t: this.model.variant(declared, captured);\n\t\tconst properties = tagged\n\t\t\t? this.layouts.taggedFields(tagged)\n\t\t\t: this.checker\n\t\t\t\t\t.getPropertiesOfType(recordType)\n\t\t\t\t\t.map((property) => property.name);\n\t\tconst fields = properties.map((name): [string, string] => {\n\t\t\tconst field = captured.fields[name];\n\t\t\tif (tagged && name === tagged.tag) {\n\t\t\t\tconst tag = this.layouts.tagEnum(declared, tagged);\n\t\t\t\treturn [\n\t\t\t\t\tname,\n\t\t\t\t\tthis.layouts.member(\n\t\t\t\t\t\ttag,\n\t\t\t\t\t\tfield?.kind === \"string\" ? field.value : undefined,\n\t\t\t\t\t),\n\t\t\t\t];\n\t\t\t}\n\t\t\tconst fieldType =\n\t\t\t\tthis.model.fieldType(recordType, name, captured) ??\n\t\t\t\t(tagged && this.layouts.taggedFieldType(declared, tagged, name));\n\t\t\tif (!fieldType) {\n\t\t\t\tthrow new Error(`${name} has no declared type.`);\n\t\t\t}\n\t\t\treturn [\n\t\t\t\tname,\n\t\t\t\tfield\n\t\t\t\t\t? this.valueText(field, fieldType)\n\t\t\t\t\t: `defaultValue<${this.layouts.text(fieldType)}>()`,\n\t\t\t];\n\t\t});\n\t\tif (!record) {\n\t\t\treturn `{ ${fields.map(([name, value]) => `${name}: ${value}`).join(\", \")} }`;\n\t\t}\n\t\tconst literal = this.layouts.literalEnum(record.key);\n\t\tconst entries = fields.map(([name, value]) => {\n\t\t\t// A string member of a mixed enum has no number; its key stays as written for verification to reject.\n\t\t\tconst key = literal\n\t\t\t\t? this.layouts.member(literal, name)\n\t\t\t\t: (this.layouts.enumMember(record.key, Number(name)) ??\n\t\t\t\t\tJSON.stringify(name));\n\t\t\treturn `[${key}]: ${value}`;\n\t\t});\n\t\t// An enum that is also optional elsewhere has an Undefined member the table must cover.\n\t\tif (literal?.optional) {\n\t\t\tentries.unshift(\n\t\t\t\t`[${this.layouts.member(literal, undefined)}]: ${this.defaultOf(record.value)}`,\n\t\t\t);\n\t\t}\n\t\treturn `{ ${entries.join(\", \")} }`;\n\t}\n\n\tprivate literal(value: CapturedValue): string {\n\t\tswitch (value.kind) {\n\t\t\tcase \"number\":\n\t\t\tcase \"boolean\":\n\t\t\t\treturn String(value.value);\n\t\t\tcase \"string\":\n\t\t\t\treturn JSON.stringify(value.value);\n\t\t\tcase \"bigint\":\n\t\t\t\treturn `${value.value}n`;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`A captured ${value.kind} has no literal.`);\n\t\t}\n\t}\n\n\t/** The value a place of `type` starts with, as dialect text; nothing for void. */\n\tdefaultOf(type: ts.Type | undefined): string {\n\t\tif (!type || type.flags & ts.TypeFlags.Void) {\n\t\t\treturn \"\";\n\t\t}\n\t\tif (type.flags & ts.TypeFlags.BooleanLike) {\n\t\t\treturn \"false\";\n\t\t}\n\t\tif (type.flags & ts.TypeFlags.NumberLike) {\n\t\t\treturn \"0\";\n\t\t}\n\t\treturn `defaultValue<${this.layouts.text(type)}>()`;\n\t}\n}\n",
53
+ "import { basename } from \"node:path\";\nimport { pascalCase } from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport { hasModifier } from \"../types\";\nimport type { CapturedValue } from \"./capture-protocol\";\nimport type { EntryImports } from \"./imports\";\nimport {\n\tarrayLayout,\n\ttype Layouts,\n\trecordTypes,\n\tstatelessLayout,\n} from \"./layouts\";\nimport {\n\tchildren,\n\ttype Model,\n\ttype ModelNode,\n\ttype Owner,\n\townerAt,\n\ttype Root,\n\ttype Step,\n\tstepPath,\n\ttsPath,\n} from \"./model\";\nimport { referable, referenceLayout, referenceType } from \"./references\";\nimport { capturedPrimitive, type Value } from \"./values\";\nimport { ScanWrites } from \"./writes\";\n\n/** A primitive scan code read from setup and folded, at its TypeScript path. */\ninterface FoldedField {\n\tpath: string;\n\tvalue: CapturedValue;\n\t/** The declaration of the field or array holding it, or its root's. */\n\tdeclaration: ts.Node;\n\t/** The IEC width that declaration names. */\n\tiec?: string;\n}\n\n/** A stored field of a flattened root: a global of the root's storage module. */\nexport interface RootField {\n\tname: string;\n\tlayout: string;\n\tdeclaration: ts.Node | undefined;\n}\n\n/**\n * Where the state setup built lives in the PLC, and how scan code reads it. A field is stored when\n * scan code writes it or its root is exported; what setup fixed otherwise folds where it is read.\n */\nexport class Storage {\n\tprivate readonly readConstants = new Set<string>();\n\tprivate readonly writes: ScanWrites;\n\tprivate readonly storedRoots = new Set<Root>();\n\tprivate readonly layoutNames = new Map<string, string>();\n\n\tconstructor(\n\t\tprivate readonly model: Model,\n\t\tprivate readonly checker: ts.TypeChecker,\n\t\tprivate readonly layouts: Layouts,\n\t\tprivate readonly imports: EntryImports,\n\t\tsources: readonly ts.SourceFile[],\n\t\tprivate readonly kept: (file: string) => boolean,\n\t\tprivate readonly rootModule: (root: Root) => string,\n\t) {\n\t\tthis.writes = new ScanWrites(checker, sources);\n\t\tthis.typeNames = new Set(\n\t\t\tsources.flatMap((source) =>\n\t\t\t\tsource.statements.flatMap((statement) =>\n\t\t\t\t\t(ts.isInterfaceDeclaration(statement) ||\n\t\t\t\t\t\tts.isTypeAliasDeclaration(statement) ||\n\t\t\t\t\t\tts.isClassDeclaration(statement) ||\n\t\t\t\t\t\tts.isEnumDeclaration(statement)) &&\n\t\t\t\t\tstatement.name\n\t\t\t\t\t\t? [statement.name.text]\n\t\t\t\t\t\t: [],\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t}\n\n\t/** The program's own type names, which a root's namespace mustn't take: `line` and the `Line` interface. */\n\tprivate readonly typeNames: ReadonlySet<string>;\n\n\t/** The declaration symbol of a captured field, to ask whether scan code writes it. */\n\tprivate fieldSymbol(holder: ModelNode, name: string): ts.Symbol | undefined {\n\t\tif (holder.captured.kind === \"instance\") {\n\t\t\tconst member = this.model.member(this.model.classOf(holder), name);\n\t\t\treturn member && this.checker.getSymbolAtLocation(member.name);\n\t\t}\n\t\tif (!holder.type) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.model.variant(holder.type, holder.captured).getProperty(name);\n\t}\n\n\t/** Whether a field holds state the PLC stores, rather than a value fixed at setup. */\n\tstored(holder: ModelNode, name: string): boolean {\n\t\tif (holder.owner?.root.exported) {\n\t\t\treturn true;\n\t\t}\n\t\treturn this.written(holder, name);\n\t}\n\n\t/**\n\t * Whether a stored field still reads as the value setup gave it: a readonly field scan code never\n\t * assigns, as a collection's capacity is, which an exported root stores for the HMI to read. A\n\t * root `io` reaches is the hardware's to write, so none of its fields is fixed.\n\t */\n\tprivate fixed(holder: ModelNode, name: string): boolean {\n\t\tconst declaration = this.fieldDeclaration(holder, name);\n\t\treturn (\n\t\t\tholder.owner !== undefined &&\n\t\t\t!holder.owner.root.bound &&\n\t\t\tdeclaration !== undefined &&\n\t\t\tts.canHaveModifiers(declaration) &&\n\t\t\thasModifier(declaration, ts.SyntaxKind.ReadonlyKeyword) &&\n\t\t\t!this.written(holder, name)\n\t\t);\n\t}\n\n\t/** Whether scan code assigns the field itself. */\n\tprivate written(holder: ModelNode, name: string): boolean {\n\t\tconst symbol = this.fieldSymbol(holder, name);\n\t\treturn symbol !== undefined && this.writes.includes(symbol);\n\t}\n\n\t/**\n\t * Whether an instance's field stores a reference: one of a class's type that scan code assigns.\n\t * The PLC keeps the id of the object it refers to, not a copy of the object.\n\t */\n\treferenceField(holder: ModelNode, name: string): boolean {\n\t\tconst key = `${holder.id}.${name}`;\n\t\tconst known = this.referenceFields.get(key);\n\t\tif (known !== undefined) {\n\t\t\treturn known;\n\t\t}\n\t\tconst type =\n\t\t\tholder.captured.kind === \"instance\"\n\t\t\t\t? this.model.capturedFieldType(holder, name)\n\t\t\t\t: undefined;\n\t\tconst found =\n\t\t\ttype !== undefined && referenceType(type) && this.written(holder, name);\n\t\tthis.referenceFields.set(key, found);\n\t\tif (found) {\n\t\t\tthis.references.push({ holder, name });\n\t\t}\n\t\treturn found;\n\t}\n\n\t/** The fields that store a reference, found while laying out instances. */\n\tprivate readonly references: { holder: ModelNode; name: string }[] = [];\n\n\t/**\n\t * Where each referable object is, in the storage spelling the debugger names module storage\n\t * with, and the storage paths of fields that store a reference: the debugger shows a reference's\n\t * id as the object it is. Empty when no field stores a reference.\n\t */\n\treferenceTable(): {\n\t\treferences: { id: number; path: string }[];\n\t\treferenceFields: string[];\n\t} {\n\t\tif (!this.references.length) {\n\t\t\treturn { references: [], referenceFields: [] };\n\t\t}\n\t\treturn {\n\t\t\treferences: this.model.nodes.flatMap((node) =>\n\t\t\t\treferable(node) && node.owner\n\t\t\t\t\t? [{ id: node.reference, path: this.storagePlace(node.owner) }]\n\t\t\t\t\t: [],\n\t\t\t),\n\t\t\treferenceFields: this.references.flatMap(({ holder, name }) =>\n\t\t\t\tholder.owner ? [`${this.storagePlace(holder.owner)}.${name}`] : [],\n\t\t\t),\n\t\t};\n\t}\n\n\t/** A place as module storage: its root's module, the root unless flattened, then fields and indexes. */\n\tprivate storagePlace(owner: Owner): string {\n\t\tconst module = basename(this.rootModule(owner.root), \".ts\");\n\t\tconst root = this.flattened(owner.root)\n\t\t\t? module\n\t\t\t: `${module}.${owner.root.name}`;\n\t\treturn root + this.stepsText(owner, (_, key) => key);\n\t}\n\n\t/**\n\t * The steps from a place's root down to it, as storage spells them: an element of a mixed-state\n\t * array is a field of its record, and `key` spells a numeric key of the object holding it.\n\t */\n\tprivate stepsText(\n\t\towner: Owner,\n\t\tkey: (holder: ModelNode | undefined, key: string) => string,\n\t): string {\n\t\treturn owner.steps\n\t\t\t.map((step, index) => {\n\t\t\t\tconst holder = this.model.at(owner.root, owner.steps.slice(0, index));\n\t\t\t\tif (step.kind === \"index\" && holder && this.mixedStates(holder)) {\n\t\t\t\t\treturn `.${mixedItem(step.index)}`;\n\t\t\t\t}\n\t\t\t\treturn stepPath(step, (name) => key(holder, name));\n\t\t\t})\n\t\t\t.join(\"\");\n\t}\n\n\t/** Asked of every field each time an instance's layout is, so answered once. */\n\tprivate readonly referenceFields = new Map<string, boolean>();\n\n\t/** Array elements are stored when the field holding the array is, or its root is exported. */\n\tprivate storedArray(array: ModelNode): boolean {\n\t\tconst owner = array.owner;\n\t\tif (!owner) {\n\t\t\treturn false;\n\t\t}\n\t\tif (owner.root.exported) {\n\t\t\treturn true;\n\t\t}\n\t\tconst last = owner.steps.at(-1);\n\t\tif (!last) {\n\t\t\treturn false;\n\t\t}\n\t\tconst holder = this.model.at(owner.root, owner.steps.slice(0, -1));\n\t\treturn (\n\t\t\tlast.kind === \"field\" &&\n\t\t\tholder !== undefined &&\n\t\t\tthis.stored(holder, last.name)\n\t\t);\n\t}\n\n\t/** Dialect text for a stored node's place. Generated code then reads its root's storage, so this stores the root. */\n\tpathText(node: ModelNode): string {\n\t\tconst owner = node.owner;\n\t\tif (!owner) {\n\t\t\tthrow new Error(\"An object with no owner has no storage.\");\n\t\t}\n\t\treturn this.placeText(owner);\n\t}\n\n\t/** Dialect text for a place, which stores its root; a `Record<Enum, T>` key indexes by its enum member. */\n\tprivate placeText(owner: Owner): string {\n\t\tconst namespace = this.reach(owner.root);\n\t\tconst root = this.flattened(owner.root)\n\t\t\t? namespace\n\t\t\t: `${namespace}.${owner.root.name}`;\n\t\treturn (\n\t\t\troot +\n\t\t\tthis.stepsText(owner, (holder, key) =>\n\t\t\t\tholder?.type ? this.keyText(holder.type, key) : key,\n\t\t\t)\n\t\t);\n\t}\n\n\t/** The enum member naming a key of a `Record<Enum, T>`. */\n\tprivate keyText(type: ts.Type, key: string): string {\n\t\tconst keyType = recordTypes(type)?.key;\n\t\tif (!keyType) {\n\t\t\treturn key;\n\t\t}\n\t\treturn this.layouts.enumMember(keyType, Number(key)) ?? key;\n\t}\n\n\t/**\n\t * A record or instance root becomes its own global list, one global per field. A table keyed by\n\t * enum members or numbers is stored whole: its keys name no global.\n\t */\n\tflattened(root: Root): boolean {\n\t\tconst node = this.model.node(root.value);\n\t\tif (node?.captured.kind === \"instance\") {\n\t\t\treturn true;\n\t\t}\n\t\tif (node?.captured.kind !== \"object\") {\n\t\t\treturn false;\n\t\t}\n\t\tconst key = node.type && recordTypes(node.type)?.key;\n\t\treturn (\n\t\t\t!key ||\n\t\t\t(key.flags & (ts.TypeFlags.EnumLike | ts.TypeFlags.NumberLike)) === 0\n\t\t);\n\t}\n\n\t/**\n\t * Stores a root and has the entry module import its storage module, and returns the namespace\n\t * generated code reads that module through.\n\t */\n\tprivate reach(root: Root): string {\n\t\tconst module = this.rootModule(root);\n\t\tconst pascal = pascalCase(basename(module, \".ts\"));\n\t\tthis.storedRoots.add(root);\n\t\treturn this.imports.namespace(\n\t\t\tmodule,\n\t\t\tthis.typeNames.has(pascal) ? `${pascal}Root` : pascal,\n\t\t);\n\t}\n\n\t/** Stores a root whether or not scan code reads it, as exported data must be. */\n\tuse(root: Root): void {\n\t\tthis.reach(root);\n\t}\n\n\t/** Roots generated code reached, which need storage declarations. */\n\tget roots(): ReadonlySet<Root> {\n\t\treturn this.storedRoots;\n\t}\n\n\t/** Whether anything inside a node is state the PLC stores. */\n\thasState(node: ModelNode): boolean {\n\t\tconst captured = node.captured;\n\t\tif (node.owner?.root.exported) {\n\t\t\treturn true;\n\t\t}\n\t\tif (captured.kind === \"instance\") {\n\t\t\treturn this.instanceFields(node).length > 0;\n\t\t}\n\t\tif (captured.kind === \"array\") {\n\t\t\treturn (\n\t\t\t\tthis.storedArray(node) ||\n\t\t\t\tcaptured.items.some((item, index) => {\n\t\t\t\t\tconst inner = this.model.node(item);\n\t\t\t\t\treturn (\n\t\t\t\t\t\tinner !== undefined &&\n\t\t\t\t\t\tthis.owns(node, inner, { kind: \"index\", index }) &&\n\t\t\t\t\t\tthis.hasState(inner)\n\t\t\t\t\t);\n\t\t\t\t})\n\t\t\t);\n\t\t}\n\t\tif (captured.kind === \"object\") {\n\t\t\treturn Object.entries(captured.fields).some(([name, value]) => {\n\t\t\t\tif (this.stored(node, name)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconst inner = this.model.node(value);\n\t\t\t\treturn (\n\t\t\t\t\tinner !== undefined &&\n\t\t\t\t\tthis.owns(node, inner, { kind: \"field\", name }) &&\n\t\t\t\t\tthis.hasState(inner)\n\t\t\t\t);\n\t\t\t});\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * The stored layout of a node, or undefined when nothing in it is stored. Records and arrays\n\t * keep their declared type; an instance stores a record of the fields that hold its state.\n\t */\n\tstorageType(node: ModelNode): string | undefined {\n\t\tconst captured = node.captured;\n\t\tif (!this.hasState(node)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (captured.kind === \"instance\") {\n\t\t\tconst fields = this.instanceFields(node);\n\t\t\treturn this.layoutName(\n\t\t\t\t`${captured.name}State`,\n\t\t\t\tfields.map(([field, text]) => `${field}: ${text};`).join(\" \"),\n\t\t\t\tthis.model.classOf(node),\n\t\t\t);\n\t\t}\n\t\tif (captured.kind === \"array\") {\n\t\t\tconst first = captured.items[0] && this.model.node(captured.items[0]);\n\t\t\tconst states = this.itemLayouts(node);\n\t\t\t// Elements whose states differ, as instances of different subclasses do, are kept side by side.\n\t\t\tif (states && new Set(states).size > 1) {\n\t\t\t\treturn this.layoutName(\n\t\t\t\t\t\"MixedStates\",\n\t\t\t\t\tstates\n\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t(state, index) =>\n\t\t\t\t\t\t\t\t`${mixedItem(index)}: ${state ?? statelessLayout};`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\" \"),\n\t\t\t\t\tthis.holderDeclaration(node),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst state = states?.[0];\n\t\t\tif (first?.captured.kind === \"instance\" && state) {\n\t\t\t\treturn arrayLayout(state, captured.items.length).text;\n\t\t\t}\n\t\t}\n\t\tif (!node.type) {\n\t\t\tthrow new Error(\"Stored state needs a declared type.\");\n\t\t}\n\t\treturn this.layouts.declaredText(this.holderDeclaration(node), node.type, {\n\t\t\tkind: \"node\",\n\t\t\tid: node.id,\n\t\t});\n\t}\n\n\t/**\n\t * Whether an array holds instances whose states differ, so it is stored as a record with a field\n\t * per element; scan code reaches each element by an index known when it compiles.\n\t */\n\tmixedStates(node: ModelNode): boolean {\n\t\tconst known = this.mixed.get(node);\n\t\tif (known !== undefined) {\n\t\t\treturn known;\n\t\t}\n\t\tconst found = this.statesDiffer(node);\n\t\tthis.mixed.set(node, found);\n\t\treturn found;\n\t}\n\n\t/**\n\t * Every path through an array asks this, and the answer walks all the array holds; setup and the\n\t * fields scan code writes fix it, so it is worked out once.\n\t */\n\tprivate readonly mixed = new Map<ModelNode, boolean>();\n\n\tprivate statesDiffer(node: ModelNode): boolean {\n\t\tif (!this.hasState(node)) {\n\t\t\treturn false;\n\t\t}\n\t\tconst layouts = this.itemLayouts(node);\n\t\treturn layouts !== undefined && new Set(layouts).size > 1;\n\t}\n\n\t/**\n\t * Each element's stored layout, for an array of instances or of records: records holding instances\n\t * can differ too, as when one instance owns objects the others only refer to.\n\t */\n\tprivate itemLayouts(node: ModelNode): (string | undefined)[] | undefined {\n\t\tconst captured = node.captured;\n\t\tif (captured.kind !== \"array\") {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst items = captured.items.flatMap((item) => {\n\t\t\tconst inner = this.model.node(item);\n\t\t\treturn inner ? [inner] : [];\n\t\t});\n\t\tif (items.length !== captured.items.length) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst element = node.type && this.model.elementType(node.type);\n\t\treturn items.map((item) => {\n\t\t\tif (item.captured.kind === \"instance\") {\n\t\t\t\treturn this.storageType(item);\n\t\t\t}\n\t\t\treturn element\n\t\t\t\t? this.layouts.text(element, { kind: \"node\", id: item.id })\n\t\t\t\t: undefined;\n\t\t});\n\t}\n\n\t/** Records stored as a whole: anything in them is state. */\n\tprivate storedWhole(node: ModelNode): boolean {\n\t\treturn node.captured.kind !== \"instance\" && this.hasState(node);\n\t}\n\n\t/** An instance's stored fields: what scan code writes, and owned objects holding state. */\n\tinstanceFields(node: ModelNode): [string, string][] {\n\t\tconst captured = node.captured;\n\t\tif (captured.kind !== \"instance\") {\n\t\t\treturn [];\n\t\t}\n\t\tconst fields = this.model.fields(this.model.classOf(node));\n\t\treturn fields.flatMap((member): [string, string][] => {\n\t\t\tconst name = member.name.getText();\n\t\t\tconst value = this.model.field(node, name);\n\t\t\tconst inner = this.model.node(value);\n\t\t\tconst type = this.model.capturedFieldType(node, name);\n\t\t\tif (!type) {\n\t\t\t\tthrow new Error(`${captured.name}.${name} has no declared type.`);\n\t\t\t}\n\t\t\tconst owned =\n\t\t\t\tinner !== undefined && this.owns(node, inner, { kind: \"field\", name });\n\t\t\tif (this.referenceField(node, name)) {\n\t\t\t\t// The object setup put there is stored through this field, which a reference would replace.\n\t\t\t\tif (owned) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`${captured.name}.${name} is assigned in scan code, but it is where setup first put the object it starts with, so that object is stored there. Give the object another owner: a module constant, or a readonly field setup assigns before this one.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn [[name, referenceLayout]];\n\t\t\t}\n\t\t\tif (inner) {\n\t\t\t\tif (callable(inner)) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\tif (!owned) {\n\t\t\t\t\tif (!this.stored(node, name)) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\t// A stored field holds its own copy of the record setup gave it. A copied instance\n\t\t\t\t\t// keeps the record its class's type describes, which emitted ST names `ST_<Class>`.\n\t\t\t\t\tconst layout =\n\t\t\t\t\t\tinner.captured.kind === \"instance\"\n\t\t\t\t\t\t\t? this.layouts.text(type, value)\n\t\t\t\t\t\t\t: this.layouts.declaredText(member, type, value);\n\t\t\t\t\treturn [[name, layout]];\n\t\t\t\t}\n\t\t\t\tif (inner.captured.kind !== \"instance\" && this.stored(node, name)) {\n\t\t\t\t\treturn [[name, this.layouts.declaredText(member, type, value)]];\n\t\t\t\t}\n\t\t\t\tconst text = this.storageType(inner);\n\t\t\t\treturn text ? [[name, text]] : [];\n\t\t\t}\n\t\t\tif (!this.stored(node, name)) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\treturn [[name, this.layouts.declaredText(member, type, value)]];\n\t\t});\n\t}\n\n\t/** A flattened root's stored fields, each a global of its storage module; an exported record stores every field. */\n\trootFields(root: Root): RootField[] {\n\t\tconst node = this.model.node(root.value);\n\t\tif (node?.captured.kind === \"instance\") {\n\t\t\tconst declaration = this.model.classOf(node);\n\t\t\treturn this.instanceFields(node).map(([name, layout]) => ({\n\t\t\t\tname,\n\t\t\t\tlayout,\n\t\t\t\tdeclaration: this.model.member(declaration, name),\n\t\t\t}));\n\t\t}\n\t\tif (node?.captured.kind !== \"object\") {\n\t\t\treturn [];\n\t\t}\n\t\treturn Object.entries(node.captured.fields).flatMap(\n\t\t\t([name, value]): RootField[] => {\n\t\t\t\tconst declared = this.model.capturedFieldType(node, name);\n\t\t\t\tif (!declared) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\tconst declaration = this.fieldDeclaration(node, name);\n\t\t\t\tconst inner = this.model.node(value);\n\t\t\t\tif (inner && callable(inner)) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\tif (root.exported || (!inner && this.stored(node, name))) {\n\t\t\t\t\tconst hint = name.charAt(0).toUpperCase() + name.slice(1);\n\t\t\t\t\treturn [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tlayout: this.layouts.declaredText(\n\t\t\t\t\t\t\t\tdeclaration,\n\t\t\t\t\t\t\t\tdeclared,\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\thint,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tdeclaration,\n\t\t\t\t\t\t},\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\tif (!inner) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\t// A record scan code assigns as a whole holds its own copy of what setup gave it.\n\t\t\t\tconst layout =\n\t\t\t\t\tinner.captured.kind === \"object\" && this.stored(node, name)\n\t\t\t\t\t\t? this.layouts.declaredText(declaration, declared, value)\n\t\t\t\t\t\t: this.storageType(inner);\n\t\t\t\treturn layout ? [{ name, layout, declaration }] : [];\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate layoutName(\n\t\tbase: string,\n\t\tbody: string,\n\t\torigin: ts.Node | undefined,\n\t): string {\n\t\tconst known = this.layoutNames.get(body);\n\t\tif (known) {\n\t\t\treturn known;\n\t\t}\n\t\tconst name = this.layouts.declare(base, body, origin);\n\t\tthis.layoutNames.set(body, name);\n\t\treturn name;\n\t}\n\n\trootValue(root: Root): Value {\n\t\tconst value = root.value;\n\t\tif (value.kind === \"node\") {\n\t\t\tconst node = this.model.node(value);\n\t\t\t// Scan code calls a service client or a task, so it stays an object setup built.\n\t\t\tif (\n\t\t\t\tthis.kept(root.file) &&\n\t\t\t\tnode.captured.kind !== \"service\" &&\n\t\t\t\tnode.captured.kind !== \"task\"\n\t\t\t) {\n\t\t\t\treturn this.keptRoot(root);\n\t\t\t}\n\t\t\treturn { kind: \"static\", node };\n\t\t}\n\t\tif (\n\t\t\tthis.kept(root.file) ||\n\t\t\tts.getCombinedNodeFlags(root.declaration) & ts.NodeFlags.Const\n\t\t) {\n\t\t\treturn capturedPrimitive(value);\n\t\t}\n\t\t// A module `let` of a plain module is state in its own global list.\n\t\tconst namespace = this.reach(root);\n\t\tconst input = this.input({ root, steps: [] });\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: `${namespace}.${root.name}`,\n\t\t\tdeclared: this.checker.getTypeAtLocation(root.declaration.name),\n\t\t\tplace: true,\n\t\t\tiec: this.layouts.iecName(root.declaration),\n\t\t\t...(input && { input }),\n\t\t};\n\t}\n\n\t/** A binding in a module the program keeps, read through the entry's import of it. */\n\tprivate keptRoot(root: Root): Value {\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: this.imports.kept.add(root.file, root.name),\n\t\t\tdeclared: this.checker.getTypeAtLocation(root.declaration.name),\n\t\t\tplace: !(ts.getCombinedNodeFlags(root.declaration) & ts.NodeFlags.Const),\n\t\t};\n\t}\n\n\t/** A known node or primitive read from a captured object at one step. */\n\tfromCaptured(value: CapturedValue, holder: ModelNode, step: Step): Value {\n\t\tif (value.kind === \"node\") {\n\t\t\tconst node = this.model.node(value);\n\t\t\t// A reference field is a place too, though it starts as an object: it holds that object's id.\n\t\t\tif (step.kind === \"field\" && this.referenceField(holder, step.name)) {\n\t\t\t\treturn this.storedField(holder, step);\n\t\t\t}\n\t\t\t// A field scan code assigns as a whole is a place, holding its own copy of what setup gave it.\n\t\t\tif (\n\t\t\t\t(node.captured.kind === \"object\" || node.captured.kind === \"array\") &&\n\t\t\t\tstep.kind === \"field\" &&\n\t\t\t\tthis.written(holder, step.name)\n\t\t\t) {\n\t\t\t\treturn node.captured.kind === \"array\"\n\t\t\t\t\t? this.storedArrayField(holder, step.name, node)\n\t\t\t\t\t: this.storedField(holder, step);\n\t\t\t}\n\t\t\treturn { kind: \"static\", node };\n\t\t}\n\t\tconst stored =\n\t\t\tstep.kind === \"field\"\n\t\t\t\t? this.stored(holder, step.name) && !this.fixed(holder, step.name)\n\t\t\t\t: this.storedArray(holder);\n\t\tif (stored) {\n\t\t\treturn this.storedField(holder, step);\n\t\t}\n\t\tif (holder.owner) {\n\t\t\tthis.readConstants.add(tsPath(ownerAt(holder.owner, step)));\n\t\t}\n\t\treturn capturedPrimitive(value);\n\t}\n\n\t/** A captured field's declaration: a class member or a record's property. */\n\tprivate fieldDeclaration(\n\t\tholder: ModelNode,\n\t\tname: string,\n\t): ts.Node | undefined {\n\t\treturn holder.captured.kind === \"instance\"\n\t\t\t? this.model.member(this.model.classOf(holder), name)\n\t\t\t: this.fieldSymbol(holder, name)?.valueDeclaration;\n\t}\n\n\t/** The IEC width a captured field's declaration names. */\n\tprivate fieldIec(holder: ModelNode, name: string): string | undefined {\n\t\treturn this.layouts.iecName(this.fieldDeclaration(holder, name));\n\t}\n\n\t/** The declaration of the field holding a record or array. */\n\tprivate holderDeclaration(node: ModelNode): ts.Node | undefined {\n\t\tconst owner = node.owner;\n\t\tconst last = owner?.steps.at(-1);\n\t\tif (!owner || last?.kind !== \"field\") {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst holder = this.model.at(owner.root, owner.steps.slice(0, -1));\n\t\treturn holder && this.fieldDeclaration(holder, last.name);\n\t}\n\n\t/** The IEC width of an array's elements, from the declaration holding the array. */\n\tprivate arrayElementIec(array: ModelNode): string | undefined {\n\t\treturn this.layouts.elementIec(this.holderDeclaration(array));\n\t}\n\n\t/**\n\t * Primitives setup stored in fields and arrays that scan code only reads. Specialization folds\n\t * them into the code, so they have no storage; this is where their values remain known.\n\t */\n\tfolded(): FoldedField[] {\n\t\tconst found: FoldedField[] = [];\n\t\tconst visit = (node: ModelNode, owner: Owner, whole: boolean): void => {\n\t\t\tconst captured = node.captured;\n\t\t\t// A record or array stored as a whole stores everything in it; a flattened root stores fields.\n\t\t\tconst stores =\n\t\t\t\twhole ||\n\t\t\t\t(captured.kind === \"object\" &&\n\t\t\t\t\t!(owner.steps.length === 0 && this.flattened(owner.root)) &&\n\t\t\t\t\tthis.storedWhole(node)) ||\n\t\t\t\t(captured.kind === \"array\" && this.storedArray(node));\n\t\t\tfor (const [step, value] of children(captured)) {\n\t\t\t\tconst at = ownerAt(owner, step);\n\t\t\t\tconst inner = this.model.node(value);\n\t\t\t\tif (inner) {\n\t\t\t\t\t// Visit what this node owns; other places holding it refer to its owner.\n\t\t\t\t\tif (this.model.ownsAt(inner, at)) {\n\t\t\t\t\t\tvisit(inner, at, stores);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\tvalue.kind === \"undefined\" ||\n\t\t\t\t\tstores ||\n\t\t\t\t\t!this.readConstants.has(tsPath(at))\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (step.kind === \"field\" && this.stored(node, step.name)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst declaration =\n\t\t\t\t\tstep.kind === \"field\"\n\t\t\t\t\t\t? this.fieldDeclaration(node, step.name)\n\t\t\t\t\t\t: this.holderDeclaration(node);\n\t\t\t\tconst iec =\n\t\t\t\t\tstep.kind === \"field\"\n\t\t\t\t\t\t? this.fieldIec(node, step.name)\n\t\t\t\t\t\t: this.arrayElementIec(node);\n\t\t\t\tfound.push({\n\t\t\t\t\tpath: tsPath(at),\n\t\t\t\t\tvalue,\n\t\t\t\t\tdeclaration: declaration ?? owner.root.declaration,\n\t\t\t\t\t...(iec && { iec }),\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\t\tfor (const root of this.model.roots) {\n\t\t\tconst node = this.model.node(root.value);\n\t\t\tif (\n\t\t\t\tnode?.owner?.root === root &&\n\t\t\t\t!root.exported &&\n\t\t\t\t!this.kept(root.file)\n\t\t\t) {\n\t\t\t\tvisit(node, { root, steps: [] }, false);\n\t\t\t}\n\t\t}\n\t\treturn found;\n\t}\n\n\tprivate storedField(holder: ModelNode, step: Step): Value {\n\t\tconst owner = holder.owner;\n\t\tif (!owner) {\n\t\t\tthrow new Error(\"An object with no owner has no storage.\");\n\t\t}\n\t\tconst declared =\n\t\t\tstep.kind === \"index\"\n\t\t\t\t? holder.type && this.model.elementType(holder.type)\n\t\t\t\t: this.model.capturedFieldType(holder, step.name);\n\t\tconst input = this.input(ownerAt(owner, step));\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: this.placeText(ownerAt(owner, step)),\n\t\t\tdeclared,\n\t\t\tplace: true,\n\t\t\t...(input && { input }),\n\t\t\t...(step.kind === \"field\"\n\t\t\t\t? {\n\t\t\t\t\t\tiec: this.fieldIec(holder, step.name),\n\t\t\t\t\t\telementIec: this.layouts.elementIec(\n\t\t\t\t\t\t\tthis.fieldDeclaration(holder, step.name),\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t: { iec: this.arrayElementIec(holder) }),\n\t\t};\n\t}\n\n\t/** An input the hardware writes at `place` or inside it, which scan code must not assign. */\n\tprivate input(place: Owner): { path: string; address: string } | undefined {\n\t\tconst path = tsPath(place);\n\t\tfor (const [bound, address] of this.model.inputs) {\n\t\t\tif (\n\t\t\t\tbound === path ||\n\t\t\t\tbound.startsWith(`${path}.`) ||\n\t\t\t\tbound.startsWith(`${path}[`)\n\t\t\t) {\n\t\t\t\treturn { path: bound, address };\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** A stored array field, with the layout and length of the array setup put there, which an array parameter takes when the field is passed to one. */\n\tprivate storedArrayField(\n\t\tholder: ModelNode,\n\t\tname: string,\n\t\tarray: ModelNode,\n\t): Value {\n\t\tconst stored = this.storedField(holder, { kind: \"field\", name });\n\t\tif (\n\t\t\tstored.kind !== \"code\" ||\n\t\t\t!stored.declared ||\n\t\t\t!this.checker.isArrayType(stored.declared) ||\n\t\t\tarray.captured.kind !== \"array\"\n\t\t) {\n\t\t\treturn stored;\n\t\t}\n\t\treturn {\n\t\t\t...stored,\n\t\t\tlayout: this.layouts.declaredArray(\n\t\t\t\tthis.fieldDeclaration(holder, name),\n\t\t\t\tstored.declared,\n\t\t\t\t{ kind: \"node\", id: array.id },\n\t\t\t),\n\t\t\tlength: array.captured.items.length,\n\t\t};\n\t}\n\n\t/** Whether `holder` owns `node` at `step`. */\n\tprivate owns(holder: ModelNode, node: ModelNode, step: Step): boolean {\n\t\treturn (\n\t\t\tholder.owner !== undefined &&\n\t\t\tthis.model.ownsAt(node, ownerAt(holder.owner, step))\n\t\t);\n\t}\n\n\tstoredNode(node: ModelNode): boolean {\n\t\treturn node.captured.kind === \"array\"\n\t\t\t? this.storedArray(node)\n\t\t\t: this.storedWhole(node);\n\t}\n}\n\n/** Whether setup built a function, service client or task: scan code calls it, and the PLC stores nothing for it. */\nconst callable = (node: ModelNode): boolean =>\n\tnode.captured.kind === \"function\" ||\n\tnode.captured.kind === \"closure\" ||\n\tnode.captured.kind === \"service\" ||\n\tnode.captured.kind === \"task\";\n\n/** The field of a mixed-state array's record that holds element `index`. */\nconst mixedItem = (index: number): string => `item${index}`;\n\n/** A mixed-state array's record holding each element's value, given as text. */\nexport const mixedStateText = (items: readonly string[]): string =>\n\t`{ ${items.map((item, index) => `${mixedItem(index)}: ${item}`).join(\", \")} }`;\n",
54
+ "import { loopIterations } from \"@tsplc/iec/arithmetic\";\nimport ts from \"typescript\";\nimport { copied, mapped, type Part } from \"../positions\";\nimport { namesSdk, sdkModules } from \"../sdk\";\nimport { unparenthesized } from \"../types\";\nimport { parameterDefault } from \"./declarations\";\nimport type { DialectText } from \"./dialect\";\nimport type { ExpressionSpecializer, SpecializeContext } from \"./expressions\";\nimport { type Frame, looping } from \"./frame\";\nimport type { Initializers } from \"./initializers\";\nimport type { GeneratorCall, Jumps, Traversal } from \"./iterators\";\nimport { arrayLayout, type Layouts } from \"./layouts\";\nimport {\n\tconstant,\n\ttype FunctionLike,\n\tisStoredState,\n\tknown,\n\tSpecializeError,\n\ttype Value,\n} from \"./values\";\nimport {\n\tassignsName,\n\tisAssignment,\n\tisUpdate,\n\toccursOutsideFunctions,\n} from \"./writes\";\n\n/**\n * A statement break and continue can reach. One emitted as written keeps its user's labels; one setup\n * unrolled or folded is a labelled block, which a jump leaves by its emitted label.\n */\ninterface JumpScope {\n\tkind: \"loop\" | \"switch\" | \"labelled\";\n\tlabels: readonly string[];\n\tbreakLabel?: string;\n\tcontinueLabel?: string;\n}\n\n/** Specializes one routine's statements; expressions in them go through its ExpressionSpecializer. */\nexport class StatementSpecializer {\n\tprivate readonly scopes: JumpScope[] = [];\n\t/** Statements that couldn't be specialized, each once, so one run reports every one. */\n\treadonly failures: SpecializeError[] = [];\n\t/** The generators running in place, outermost first, so one can't recurse into itself. */\n\tprivate readonly generators: FunctionLike[] = [];\n\n\tconstructor(\n\t\tprivate readonly context: SpecializeContext,\n\t\tprivate readonly expressions: ExpressionSpecializer,\n\t) {\n\t\texpressions.iterators.attach({\n\t\t\trun: (generator, frame, at, each) =>\n\t\t\t\tthis.runGenerator(generator, frame, [], at, each),\n\t\t});\n\t}\n\n\tbody(node: ts.ConciseBody, frame: Frame): void {\n\t\tif (ts.isBlock(node)) {\n\t\t\tthis.statements(node.statements, frame);\n\t\t} else {\n\t\t\tframe.emitter.origin = node;\n\t\t\tframe.emitter.line(\n\t\t\t\tmapped`${this.dialect.code(this.expressions.expression(node, frame), undefined)};`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Statements after one that always jumps are unreachable, and may read what setup left undefined on that path. */\n\tprivate statements(\n\t\tnodes: ReadonlyArray<ts.Statement>,\n\t\tframe: Frame,\n\t): boolean {\n\t\tfor (const [index, statement] of nodes.entries()) {\n\t\t\tconst rest = nodes.slice(index + 1);\n\t\t\tif (\n\t\t\t\tts.isIfStatement(statement) &&\n\t\t\t\t!statement.elseStatement &&\n\t\t\t\trest.length\n\t\t\t) {\n\t\t\t\treturn this.recorded(statement, frame, () =>\n\t\t\t\t\tthis.guard(statement, rest, frame),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (this.statement(statement, frame)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * An `if` without `else`, then the statements after it. When its branch always jumps, as a loop's\n\t * `if (i >= count) break;` does, they run only when the condition is false: they are its `else`,\n\t * where the PLC's range proofs know the condition is false, as they know it inside an `else`.\n\t */\n\tprivate guard(\n\t\tnode: ts.IfStatement,\n\t\trest: ReadonlyArray<ts.Statement>,\n\t\tframe: Frame,\n\t): boolean {\n\t\tconst condition = this.expressions.expression(node.expression, frame);\n\t\tif (\n\t\t\tcondition.kind === \"const\" ||\n\t\t\tcondition.kind === \"static\" ||\n\t\t\tcondition.kind === \"function\"\n\t\t) {\n\t\t\tconst truthy =\n\t\t\t\tcondition.kind === \"const\" ? Boolean(condition.value) : true;\n\t\t\treturn (\n\t\t\t\t(truthy && this.statement(node.thenStatement, frame)) ||\n\t\t\t\tthis.statements(rest, frame)\n\t\t\t);\n\t\t}\n\t\tframe.emitter.open(\n\t\t\tmapped`if (${this.dialect.condition(condition, node.expression)}) {`,\n\t\t);\n\t\tif (!this.inner(node.thenStatement, frame)) {\n\t\t\tframe.emitter.close();\n\t\t\treturn this.statements(rest, frame);\n\t\t}\n\t\tframe.emitter.reopen(\"} else {\");\n\t\tconst restJumps = this.statements(rest, frame);\n\t\tframe.emitter.close();\n\t\treturn restJumps;\n\t}\n\n\tprivate get checker(): ts.TypeChecker {\n\t\treturn this.context.checker;\n\t}\n\n\tprivate get dialect(): DialectText {\n\t\treturn this.context.dialect;\n\t}\n\n\tprivate get layouts(): Layouts {\n\t\treturn this.context.layouts;\n\t}\n\n\tprivate get initializers(): Initializers {\n\t\treturn this.context.initializers;\n\t}\n\n\t/** True when control never continues past the statement: it returns, throws, breaks or continues on every path. */\n\tprivate statement(node: ts.Statement, frame: Frame): boolean {\n\t\treturn this.recorded(node, frame, () =>\n\t\t\tthis.specializeStatement(node, frame),\n\t\t);\n\t}\n\n\t/** Specializes a statement, recording a failure in it and skipping it, so the build reports every failure. */\n\tprivate recorded(\n\t\tnode: ts.Statement,\n\t\tframe: Frame,\n\t\tspecialize: () => boolean,\n\t): boolean {\n\t\tconst enclosing = frame.emitter.origin;\n\t\tframe.emitter.origin = node;\n\t\ttry {\n\t\t\treturn specialize();\n\t\t} catch (cause) {\n\t\t\tif (\n\t\t\t\t!(cause instanceof SpecializeError) ||\n\t\t\t\tts.isBlock(node) ||\n\t\t\t\tnode.getChildren().some((child) => ts.isBlock(child))\n\t\t\t) {\n\t\t\t\tthrow cause;\n\t\t\t}\n\t\t\tif (\n\t\t\t\t!this.failures.some(\n\t\t\t\t\t(failure) =>\n\t\t\t\t\t\tfailure.node === cause.node && failure.message === cause.message,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthis.failures.push(cause);\n\t\t\t}\n\t\t\treturn false;\n\t\t} finally {\n\t\t\tframe.emitter.origin = enclosing;\n\t\t}\n\t}\n\n\tprivate specializeStatement(node: ts.Statement, frame: Frame): boolean {\n\t\tconst { emitter } = frame;\n\t\tif (ts.isBlock(node)) {\n\t\t\temitter.open(\"{\");\n\t\t\tconst jumps = this.statements(node.statements, frame);\n\t\t\temitter.close();\n\t\t\treturn jumps;\n\t\t}\n\t\tif (ts.isVariableStatement(node)) {\n\t\t\tconst mutable = !(node.declarationList.flags & ts.NodeFlags.Const);\n\t\t\tfor (const declaration of node.declarationList.declarations) {\n\t\t\t\tthis.declare(declaration, mutable, frame);\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tif (ts.isExpressionStatement(node)) {\n\t\t\tif (ts.isYieldExpression(node.expression)) {\n\t\t\t\tthis.yieldStatement(node.expression, frame);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis.effect(node.expression, frame);\n\t\t\treturn false;\n\t\t}\n\t\tif (ts.isIfStatement(node)) {\n\t\t\treturn this.ifStatement(node, frame);\n\t\t}\n\t\tif (ts.isReturnStatement(node)) {\n\t\t\tthis.returnStatement(node, frame);\n\t\t\treturn true;\n\t\t}\n\t\tif (ts.isIterationStatement(node, false) || ts.isSwitchStatement(node)) {\n\t\t\tthis.loopOrSwitch(node, [], frame);\n\t\t\treturn false;\n\t\t}\n\t\tif (ts.isTryStatement(node)) {\n\t\t\tthis.tryStatement(node, frame);\n\t\t\treturn false;\n\t\t}\n\t\tif (ts.isBreakStatement(node) || ts.isContinueStatement(node)) {\n\t\t\temitter.line(this.jumpText(node));\n\t\t\treturn true;\n\t\t}\n\t\tif (ts.isLabeledStatement(node)) {\n\t\t\tthis.labelled(node, frame);\n\t\t\treturn false;\n\t\t}\n\t\tif (ts.isEmptyStatement(node)) {\n\t\t\treturn false;\n\t\t}\n\t\tif (ts.isThrowStatement(node) && frame.async) {\n\t\t\t// An async routine fails with an error code, which its caller's catch block receives.\n\t\t\tconst code = this.expressions.expression(node.expression, frame);\n\t\t\temitter.line(mapped`throw ${this.dialect.code(code, undefined)};`);\n\t\t\treturn true;\n\t\t}\n\t\tthrow unsupported(node);\n\t}\n\n\t/** A loop or switch, which jumps reach by the labels written on it. */\n\tprivate loopOrSwitch(\n\t\tnode: ts.IterationStatement | ts.SwitchStatement,\n\t\tlabels: readonly string[],\n\t\tframe: Frame,\n\t): void {\n\t\tif (ts.isForOfStatement(node)) {\n\t\t\tthis.forOf(node, labels, frame);\n\t\t\treturn;\n\t\t}\n\t\tif (ts.isSwitchStatement(node)) {\n\t\t\tthis.switch(node, labels, frame);\n\t\t\treturn;\n\t\t}\n\t\tif (ts.isForStatement(node)) {\n\t\t\tthis.forLoop(node, labels, frame);\n\t\t\treturn;\n\t\t}\n\t\tif (!ts.isWhileStatement(node) && !ts.isDoStatement(node)) {\n\t\t\tthrow unsupported(node);\n\t\t}\n\t\tif (\n\t\t\tframe.async &&\n\t\t\toccursOutsideFunctions(node.statement, ts.isAwaitExpression)\n\t\t) {\n\t\t\tthis.suspendingLoop(node, labels, frame);\n\t\t\treturn;\n\t\t}\n\t\tthrow new SpecializeError(\n\t\t\tnode,\n\t\t\t\"Use a counted for loop or for…of; while loops have no bound to prove.\",\n\t\t);\n\t}\n\n\t/** A jump as written, or out of the labelled block standing for a loop or switch setup unrolled or folded. */\n\tprivate jumpText(node: ts.BreakStatement | ts.ContinueStatement): Part {\n\t\tconst label = node.label?.text;\n\t\tconst scope = [...this.scopes].reverse().find((item) => {\n\t\t\tif (label !== undefined) {\n\t\t\t\treturn item.labels.includes(label);\n\t\t\t}\n\t\t\treturn (\n\t\t\t\titem.kind === \"loop\" ||\n\t\t\t\t(ts.isBreakStatement(node) && item.kind === \"switch\")\n\t\t\t);\n\t\t});\n\t\tconst emitted = ts.isBreakStatement(node)\n\t\t\t? scope?.breakLabel\n\t\t\t: scope?.continueLabel;\n\t\treturn emitted ? `break ${emitted};` : copied(node);\n\t}\n\n\t/** Gives the labels on the statement to the loop or switch it labels; a labelled block keeps them as written. */\n\tprivate labelled(node: ts.LabeledStatement, frame: Frame): void {\n\t\tconst labels: string[] = [];\n\t\tconst inner = innermostLabelled(node, labels);\n\t\tif (ts.isIterationStatement(inner, false) || ts.isSwitchStatement(inner)) {\n\t\t\tthis.recorded(inner, frame, () => {\n\t\t\t\tthis.loopOrSwitch(inner, labels, frame);\n\t\t\t\treturn false;\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tframe.emitter.open(`${labelText(labels)}{`);\n\t\tthis.scoped({ kind: \"labelled\", labels }, () => this.inner(inner, frame));\n\t\tframe.emitter.close();\n\t}\n\n\tprivate scoped<T>(scope: JumpScope, run: () => T): T {\n\t\tthis.scopes.push(scope);\n\t\ttry {\n\t\t\treturn run();\n\t\t} finally {\n\t\t\tthis.scopes.pop();\n\t\t}\n\t}\n\n\t/** An if on a value setup fixed keeps only the branch it takes. */\n\tprivate ifStatement(node: ts.IfStatement, frame: Frame): boolean {\n\t\tconst condition = this.expressions.expression(node.expression, frame);\n\t\tif (\n\t\t\tcondition.kind === \"const\" ||\n\t\t\tcondition.kind === \"static\" ||\n\t\t\tcondition.kind === \"function\"\n\t\t) {\n\t\t\tconst truthy =\n\t\t\t\tcondition.kind === \"const\" ? Boolean(condition.value) : true;\n\t\t\tif (truthy) {\n\t\t\t\treturn this.statement(node.thenStatement, frame);\n\t\t\t}\n\t\t\treturn node.elseStatement !== undefined\n\t\t\t\t? this.statement(node.elseStatement, frame)\n\t\t\t\t: false;\n\t\t}\n\t\tframe.emitter.open(\n\t\t\tmapped`if (${this.dialect.condition(condition, node.expression)}) {`,\n\t\t);\n\t\tconst thenJumps = this.inner(node.thenStatement, frame);\n\t\tconst elseJumps =\n\t\t\tnode.elseStatement !== undefined &&\n\t\t\tthis.elseBranch(node.elseStatement, frame);\n\t\tframe.emitter.close();\n\t\treturn thenJumps && elseJumps;\n\t}\n\n\tprivate elseBranch(node: ts.Statement, frame: Frame): boolean {\n\t\tframe.emitter.reopen(\"} else {\");\n\t\treturn this.inner(node, frame);\n\t}\n\n\t/** `return x satisfies never` marks an unreachable end, which returns the result type's default. */\n\tprivate returnStatement(node: ts.ReturnStatement, frame: Frame): void {\n\t\tif (frame.generator) {\n\t\t\tframe.emitter.line(`break ${frame.generator.exit};`);\n\t\t\treturn;\n\t\t}\n\t\tif (!node.expression) {\n\t\t\tframe.emitter.line(\"return;\");\n\t\t\treturn;\n\t\t}\n\t\tif (unreachableEnd(node)) {\n\t\t\tframe.emitter.line(\n\t\t\t\t`return ${this.initializers.defaultOf(frame.returns)};`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst value = this.expressions.expression(\n\t\t\tnode.expression,\n\t\t\tframe,\n\t\t\tframe.returns,\n\t\t);\n\t\tthis.expressions.references.returned(value, node.expression, frame);\n\t\tif (isStoredState(value)) {\n\t\t\tframe.returnsStored = true;\n\t\t}\n\t\t// An array's length is what is returned, as its type names none.\n\t\tconst element =\n\t\t\tframe.returns &&\n\t\t\tthis.checker.getIndexTypeOfType(frame.returns, ts.IndexKind.Number);\n\t\tif (element && value.kind === \"virtual\" && value.items) {\n\t\t\tframe.resultLayout = arrayLayout(\n\t\t\t\tthis.layouts.text(element),\n\t\t\t\tvalue.items.length,\n\t\t\t);\n\t\t\tframe.resultLength = value.items.length;\n\t\t} else if (element && value.kind === \"code\" && value.layout) {\n\t\t\tframe.resultLayout = value.layout;\n\t\t\tframe.resultLength = value.length;\n\t\t}\n\t\t// A return stores into the result as an assignment does: wrapped as an optional, converted to its width.\n\t\tframe.emitter.line(\n\t\t\tmapped`return ${this.dialect.returnText(value, frame.returns, this.resultIec(frame))};`,\n\t\t);\n\t}\n\n\t/** The IEC width a routine's result is declared with, as `(): UINT` gives it. */\n\tprivate resultIec(frame: Frame): string | undefined {\n\t\tconst declaration = frame.emitter.origin;\n\t\treturn this.layouts.iecName(\n\t\t\tts.findAncestor(declaration, ts.isFunctionLike),\n\t\t);\n\t}\n\n\t/** A try keeps its blocks, for the service calls in it. */\n\tprivate tryStatement(node: ts.TryStatement, frame: Frame): void {\n\t\t// Synchronous scan code can't fail, so its catch block never runs, with or without finally.\n\t\tif (!frame.async && !node.finallyBlock) {\n\t\t\tframe.emitter.open(\"{\");\n\t\t\tthis.statements(node.tryBlock.statements, frame);\n\t\t\tframe.emitter.close();\n\t\t\treturn;\n\t\t}\n\t\tframe.emitter.open(\"try {\");\n\t\tthis.statements(node.tryBlock.statements, frame);\n\t\tif (node.catchClause && frame.async) {\n\t\t\tconst binding = node.catchClause.variableDeclaration?.name;\n\t\t\tframe.emitter.reopen(\n\t\t\t\t`} catch${binding ? ` (${binding.getText()})` : \"\"} {`,\n\t\t\t);\n\t\t\t// The binding holds the error code, which a catch block can only pass on as it is.\n\t\t\tif (binding && ts.isIdentifier(binding)) {\n\t\t\t\tthis.bindLocal(binding, binding.text, frame, undefined);\n\t\t\t}\n\t\t\tthis.statements(node.catchClause.block.statements, frame);\n\t\t}\n\t\tif (node.finallyBlock) {\n\t\t\tframe.emitter.reopen(\"} finally {\");\n\t\t\tthis.statements(node.finallyBlock.statements, frame);\n\t\t}\n\t\tframe.emitter.close();\n\t}\n\n\t/** A branch body: blocks keep their statements without another brace level. */\n\tprivate inner(node: ts.Statement, frame: Frame): boolean {\n\t\treturn ts.isBlock(node)\n\t\t\t? this.statements(node.statements, frame)\n\t\t\t: this.statement(node, frame);\n\t}\n\n\t/** Binds a name to the PLC local that holds it, which scan code may assign. */\n\tprivate bindLocal(\n\t\tname: ts.Identifier,\n\t\tlocal: string,\n\t\tframe: Frame,\n\t\tiec: string | undefined,\n\t): void {\n\t\tconst symbol = this.checker.getSymbolAtLocation(name);\n\t\tif (!symbol) {\n\t\t\tthrow new SpecializeError(name, `${name.text} names nothing.`);\n\t\t}\n\t\tframe.env.set(symbol, {\n\t\t\tkind: \"code\",\n\t\t\ttext: local,\n\t\t\tdeclared: this.checker.getTypeAtLocation(name),\n\t\t\tplace: true,\n\t\t\t...(iec && { iec }),\n\t\t});\n\t}\n\n\tprivate declare(\n\t\tdeclaration: ts.VariableDeclaration,\n\t\tmutable: boolean,\n\t\tframe: Frame,\n\t): void {\n\t\tconst initializer = declaration.initializer;\n\t\tconst declared = this.checker.getTypeAtLocation(declaration.name);\n\t\t// TypeScript proves a local assigned before it is read, so one declared bare starts at its type's default.\n\t\tconst value = initializer\n\t\t\t? this.expressions.expression(\n\t\t\t\t\tinitializer,\n\t\t\t\t\tframe,\n\t\t\t\t\tdeclaration.type && this.checker.getTypeAtLocation(declaration.type),\n\t\t\t\t)\n\t\t\t: this.bareValue(declared);\n\t\tthis.expressions.bind(declaration.name, value, frame, declared, {\n\t\t\tmutable,\n\t\t\tiec: this.layouts.iecName(declaration),\n\t\t});\n\t}\n\n\t/** What a local declared without a value holds until it is assigned. */\n\tprivate bareValue(declared: ts.Type): Value {\n\t\tif (this.checker.getNonNullableType(declared) !== declared) {\n\t\t\treturn constant(undefined);\n\t\t}\n\t\treturn {\n\t\t\tkind: \"code\",\n\t\t\ttext: this.initializers.defaultOf(declared),\n\t\t\tdeclared,\n\t\t};\n\t}\n\n\tprivate forOf(\n\t\tnode: ts.ForOfStatement,\n\t\tlabels: readonly string[],\n\t\tframe: Frame,\n\t): void {\n\t\tconst generator = this.expressions.iterators.generator(\n\t\t\tnode.expression,\n\t\t\tframe,\n\t\t);\n\t\t// Over a generator, each yield runs the loop's body in a labelled block its continue leaves;\n\t\t// break or the generator's return leave the block around the whole generator.\n\t\tif (generator) {\n\t\t\tthis.runGenerator(\n\t\t\t\tgenerator,\n\t\t\t\tframe,\n\t\t\t\tlabels,\n\t\t\t\tnode,\n\t\t\t\tthis.loopBody(node, labels, frame),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst iterated = this.expressions.iterators.iterated(\n\t\t\tnode.expression,\n\t\t\tframe,\n\t\t);\n\t\tif (iterated) {\n\t\t\tthis.overTraversal(node, iterated, labels, frame);\n\t\t\treturn;\n\t\t}\n\t\tconst call = node.expression;\n\t\tif (\n\t\t\tts.isCallExpression(call) &&\n\t\t\tts.isPropertyAccessExpression(call.expression) &&\n\t\t\tcall.expression.name.text === \"entries\" &&\n\t\t\t!call.arguments.length\n\t\t) {\n\t\t\tconst array = this.expressions.expression(\n\t\t\t\tcall.expression.expression,\n\t\t\t\tframe,\n\t\t\t);\n\t\t\tif (array.kind === \"code\") {\n\t\t\t\tthis.forEntries(node, mapped`${array.text}.entries()`, labels, frame);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t// The SDK's entries(record) over stored state stays a loop over the record's enum keys.\n\t\tif (\n\t\t\tts.isCallExpression(call) &&\n\t\t\tnamesSdk(this.checker, this.context.sdkFile, call.expression, \"entries\")\n\t\t) {\n\t\t\tconst [argument] = call.arguments;\n\t\t\tconst record = argument && this.expressions.expression(argument, frame);\n\t\t\tif (record?.kind === \"code\") {\n\t\t\t\tthis.context.imports.addSdk(sdkModules.types, \"entries\");\n\t\t\t\tthis.forEntries(node, mapped`entries(${record.text})`, labels, frame);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// A record setup built unrolls over its keys, each its enum member.\n\t\t\tif (record?.kind === \"static\" && record.node.captured.kind === \"object\") {\n\t\t\t\tconst holder = record.node;\n\t\t\t\tconst pairs = Object.entries(record.node.captured.fields).map(\n\t\t\t\t\t([key, field]): Value => ({\n\t\t\t\t\t\tkind: \"virtual\",\n\t\t\t\t\t\titems: [\n\t\t\t\t\t\t\tconstant(Number(key)),\n\t\t\t\t\t\t\tthis.context.storage.fromCaptured(field, holder, {\n\t\t\t\t\t\t\t\tkind: \"field\",\n\t\t\t\t\t\t\t\tname: key,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t],\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tconst name = loopDeclaration(node).name;\n\t\t\t\tconst declared = this.checker.getTypeAtLocation(name);\n\t\t\t\tthis.unrolled(node.statement, labels, pairs, frame, (pair) =>\n\t\t\t\t\tthis.expressions.bind(name, pair, frame, declared, {\n\t\t\t\t\t\tmutable: false,\n\t\t\t\t\t\tiec: undefined,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tconst iterable = this.expressions.expression(node.expression, frame);\n\t\tif (iterable.kind === \"counted\") {\n\t\t\tthis.overTraversal(\n\t\t\t\tnode,\n\t\t\t\tthis.expressions.iterators.over(iterable),\n\t\t\t\tlabels,\n\t\t\t\tframe,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst items = this.expressions.items(iterable);\n\t\tconst name = loopDeclaration(node).name;\n\t\tconst declared = this.checker.getTypeAtLocation(name);\n\t\tif (items) {\n\t\t\tthis.unrolled(node.statement, labels, items, frame, (item) =>\n\t\t\t\tthis.expressions.bind(name, item, frame, declared, {\n\t\t\t\t\tmutable: false,\n\t\t\t\t\tiec: undefined,\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tif (iterable.kind !== \"code\") {\n\t\t\tthrow new SpecializeError(node.expression, \"for…of needs an array.\");\n\t\t}\n\t\tif (!ts.isIdentifier(name)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tname,\n\t\t\t\t\"Destructure a runtime element inside the loop.\",\n\t\t\t);\n\t\t}\n\t\tconst local = frame.emitter.local(name.text);\n\t\tframe.emitter.open(\n\t\t\tmapped`${labelText(labels)}for (const ${local} of ${iterable.text}) {`,\n\t\t);\n\t\tthis.bindLocal(name, local, frame, undefined);\n\t\tthis.loop(node.statement, labels, undefined, frame);\n\t\tframe.emitter.close();\n\t}\n\n\t/** The body of a loop that stays a loop in the PLC, which runs up to `runs` times when that is known. */\n\tprivate loop(\n\t\tbody: ts.Statement,\n\t\tlabels: readonly string[],\n\t\truns: number | undefined,\n\t\tframe: Frame,\n\t): void {\n\t\tlooping(frame, runs, () =>\n\t\t\tthis.scoped({ kind: \"loop\", labels }, () => this.inner(body, frame)),\n\t\t);\n\t}\n\n\t/** A for…of over an iterator read through helpers, or over an array whose length is decided at run time. */\n\tprivate overTraversal(\n\t\tnode: ts.ForOfStatement,\n\t\ttraversal: Traversal,\n\t\tlabels: readonly string[],\n\t\tframe: Frame,\n\t): void {\n\t\tconst body = this.loopBody(node, labels, frame);\n\t\ttraversal.run(frame, (element) => body(element.value, element));\n\t}\n\n\t/**\n\t * What a for…of does with each value it is given where the value is produced: binds its name\n\t * and runs its body, whose break and continue leave the labelled statements around it.\n\t */\n\tprivate loopBody(\n\t\tnode: ts.ForOfStatement,\n\t\tlabels: readonly string[],\n\t\tframe: Frame,\n\t): (value: Value, jumps: Jumps) => void {\n\t\tconst declaration = loopDeclaration(node);\n\t\tconst declared = this.checker.getTypeAtLocation(declaration.name);\n\t\tconst loop: Frame = { ...frame, env: new Map(frame.env) };\n\t\treturn (value, jumps) => {\n\t\t\tthis.expressions.bind(declaration.name, value, loop, declared, {\n\t\t\t\tmutable: false,\n\t\t\t\tiec: undefined,\n\t\t\t});\n\t\t\tthis.scoped(\n\t\t\t\t{\n\t\t\t\t\tkind: \"loop\",\n\t\t\t\t\tlabels,\n\t\t\t\t\tbreakLabel: jumps.whole,\n\t\t\t\t\tcontinueLabel: jumps.label,\n\t\t\t\t},\n\t\t\t\t() => this.inner(node.statement, loop),\n\t\t\t);\n\t\t};\n\t}\n\n\t/** Runs a generator's body in place, calling `each` for every value it yields. */\n\tprivate runGenerator(\n\t\tgenerator: GeneratorCall,\n\t\tframe: Frame,\n\t\tlabels: readonly string[],\n\t\tat: ts.Node,\n\t\teach: (value: Value, jumps: Jumps) => void,\n\t): void {\n\t\tconst { declaration } = generator;\n\t\tif (this.generators.includes(declaration)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tat,\n\t\t\t\t\"A generator runs in place, so it can't yield from itself.\",\n\t\t\t);\n\t\t}\n\t\tconst body = declaration.body;\n\t\tif (!body || !ts.isBlock(body)) {\n\t\t\tthrow new SpecializeError(at, \"A generator needs a body.\");\n\t\t}\n\t\tconst whole = frame.emitter.local(\"tsplcGenerator\");\n\t\tconst outside = this.generators.length;\n\t\tconst inner: Frame = {\n\t\t\t...frame,\n\t\t\tenv: new Map(),\n\t\t\tself: generator.self,\n\t\t\treturns: undefined,\n\t\t\tgenerator: {\n\t\t\t\texit: whole,\n\t\t\t\tyields: (value) => {\n\t\t\t\t\tconst label = frame.emitter.local(\"tsplcStep\");\n\t\t\t\t\tframe.emitter.open(`${label}: {`);\n\t\t\t\t\t// What reads the value is outside this generator, so it may run the same generator itself.\n\t\t\t\t\tconst running = this.generators.splice(outside);\n\t\t\t\t\ttry {\n\t\t\t\t\t\teach(value, { whole, label });\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tthis.generators.push(...running);\n\t\t\t\t\t}\n\t\t\t\t\tframe.emitter.close();\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t\tif (!ts.isGetAccessorDeclaration(declaration)) {\n\t\t\tdeclaration.parameters.forEach((parameter, index) => {\n\t\t\t\tconst given = generator.args[index] ?? constant(undefined);\n\t\t\t\tconst fallback = parameterDefault(this.checker, given, parameter);\n\t\t\t\tconst value = fallback\n\t\t\t\t\t? this.expressions.expression(fallback, inner)\n\t\t\t\t\t: given;\n\t\t\t\t// A parameter the generator never assigns keeps what was passed, which can be known now.\n\t\t\t\tthis.expressions.bind(\n\t\t\t\t\tparameter.name,\n\t\t\t\t\tvalue,\n\t\t\t\t\tinner,\n\t\t\t\t\tthis.checker.getTypeAtLocation(parameter),\n\t\t\t\t\t{\n\t\t\t\t\t\tmutable: assignsName(body, parameter.name, this.checker),\n\t\t\t\t\t\tiec: this.layouts.iecName(parameter),\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t}\n\t\tframe.emitter.open(`${labelText(labels)}${whole}: {`);\n\t\tthis.generators.push(declaration);\n\t\ttry {\n\t\t\tthis.statements(body.statements, inner);\n\t\t} finally {\n\t\t\tthis.generators.pop();\n\t\t}\n\t\tframe.emitter.close();\n\t}\n\n\t/** A yield statement runs the loop over the generator on its value; `yield*` runs another generator in place. */\n\tprivate yieldStatement(node: ts.YieldExpression, frame: Frame): void {\n\t\tconst generator = frame.generator;\n\t\tif (!generator) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"A generator runs only where a for…of or an iterator helper reads it.\",\n\t\t\t);\n\t\t}\n\t\tif (!node.expression) {\n\t\t\tgenerator.yields(constant(undefined));\n\t\t\treturn;\n\t\t}\n\t\tif (node.asteriskToken) {\n\t\t\tconst delegated = this.expressions.iterators.generator(\n\t\t\t\tnode.expression,\n\t\t\t\tframe,\n\t\t\t);\n\t\t\tif (!delegated) {\n\t\t\t\tthrow new SpecializeError(\n\t\t\t\t\tnode.expression,\n\t\t\t\t\t\"yield* runs another generator in place; pass it a generator call.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.runGenerator(delegated, frame, [], node, (value) =>\n\t\t\t\tgenerator.yields(value),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tgenerator.yields(this.expressions.expression(node.expression, frame));\n\t}\n\n\t/**\n\t * A loop over what setup built runs its body once per item. A body that breaks or continues runs\n\t * inside labelled blocks, the whole loop's and each step's, which its jumps leave.\n\t */\n\tprivate unrolled(\n\t\tbody: ts.Statement,\n\t\tlabels: readonly string[],\n\t\titems: readonly Value[],\n\t\tframe: Frame,\n\t\tbindStep: (item: Value) => void,\n\t): void {\n\t\tconst jumps = containsJump(body);\n\t\tconst whole = jumps ? frame.emitter.local(\"tsplcLoop\") : undefined;\n\t\tif (whole) {\n\t\t\tframe.emitter.open(`${whole}: {`);\n\t\t}\n\t\tfor (const item of items) {\n\t\t\tconst step = jumps ? frame.emitter.local(\"tsplcStep\") : undefined;\n\t\t\tframe.emitter.open(step ? `${step}: {` : \"{\");\n\t\t\tbindStep(item);\n\t\t\tthis.scoped(\n\t\t\t\t{ kind: \"loop\", labels, breakLabel: whole, continueLabel: step },\n\t\t\t\t() => this.inner(body, frame),\n\t\t\t);\n\t\t\tframe.emitter.close();\n\t\t}\n\t\tif (whole) {\n\t\t\tframe.emitter.close();\n\t\t}\n\t}\n\n\t/** `for (const [index, item] of array.entries())` over a runtime array stays a loop, as the backend lowers it. */\n\tprivate forEntries(\n\t\tnode: ts.ForOfStatement,\n\t\titerated: Part,\n\t\tlabels: readonly string[],\n\t\tframe: Frame,\n\t): void {\n\t\tconst binding = onlyDeclaration(node.initializer)?.name;\n\t\tconst names =\n\t\t\tbinding && ts.isArrayBindingPattern(binding)\n\t\t\t\t? binding.elements.map((element) =>\n\t\t\t\t\t\tts.isBindingElement(element) && ts.isIdentifier(element.name)\n\t\t\t\t\t\t\t? element.name\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t)\n\t\t\t\t: [];\n\t\tconst [indexName, itemName] = names;\n\t\tif (names.length !== 2 || !indexName || !itemName) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode.initializer,\n\t\t\t\t\"Destructure [index, item] from array.entries().\",\n\t\t\t);\n\t\t}\n\t\tconst [index, item] = [indexName, itemName].map((name) => {\n\t\t\tconst local = frame.emitter.local(name.text);\n\t\t\tthis.bindLocal(name, local, frame, undefined);\n\t\t\treturn local;\n\t\t});\n\t\tframe.emitter.open(\n\t\t\tmapped`${labelText(labels)}for (const [${[index, item].join(\", \")}] of ${iterated}) {`,\n\t\t);\n\t\tthis.loop(node.statement, labels, undefined, frame);\n\t\tframe.emitter.close();\n\t}\n\n\t/**\n\t * A while or do loop that awaits, in an async routine: each wait ends a scan's share of it, so it\n\t * needs no bound for a scan to finish.\n\t */\n\tprivate suspendingLoop(\n\t\tnode: ts.WhileStatement | ts.DoStatement,\n\t\tlabels: readonly string[],\n\t\tframe: Frame,\n\t): void {\n\t\tconst test = () =>\n\t\t\tthis.dialect.condition(\n\t\t\t\tthis.expressions.expression(node.expression, frame),\n\t\t\t\tnode.expression,\n\t\t\t);\n\t\tif (ts.isWhileStatement(node)) {\n\t\t\tframe.emitter.open(mapped`${labelText(labels)}while (${test()}) {`);\n\t\t} else {\n\t\t\tframe.emitter.open(`${labelText(labels)}do {`);\n\t\t}\n\t\tthis.loop(node.statement, labels, undefined, frame);\n\t\tif (ts.isWhileStatement(node)) {\n\t\t\tframe.emitter.close();\n\t\t\treturn;\n\t\t}\n\t\tframe.emitter.close(mapped`} while (${test()});`);\n\t}\n\n\t/** A counted loop stays a loop, in the header shape the backend proves bounded: `let i = start; i < bound; i++`. */\n\tprivate forLoop(\n\t\tnode: ts.ForStatement,\n\t\tlabels: readonly string[],\n\t\tframe: Frame,\n\t): void {\n\t\tconst { condition, incrementor, initializer } = node;\n\t\tconst declaration = onlyDeclaration(initializer);\n\t\tif (!declaration || !(declaration.parent.flags & ts.NodeFlags.Let)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"Declare one let counter in the for header.\",\n\t\t\t);\n\t\t}\n\t\tconst name = declaration.name;\n\t\tif (!ts.isIdentifier(name) || !declaration.initializer) {\n\t\t\tthrow new SpecializeError(declaration, \"Initialize the loop counter.\");\n\t\t}\n\t\tif (!condition || !ts.isBinaryExpression(condition) || !incrementor) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t\"Compare the counter to a bound and step it in the for header.\",\n\t\t\t);\n\t\t}\n\t\tif (assignsName(node.statement, name, this.checker)) {\n\t\t\tthrow new SpecializeError(\n\t\t\t\tnode,\n\t\t\t\t`The loop changes its counter ${name.text} in its body, and a PLC FOR loop's counter is stepped only by its header: step it in the header, or count with a separate let.`,\n\t\t\t);\n\t\t}\n\t\tconst declared = this.checker.getTypeAtLocation(name);\n\t\t// An annotation such as UINT keeps the counter's width, to index alongside unsigned fields.\n\t\tconst iec = this.layouts.iecName(declaration);\n\t\tconst first = this.expressions.expression(\n\t\t\tdeclaration.initializer,\n\t\t\tframe,\n\t\t\tdeclared,\n\t\t);\n\t\tconst start = this.dialect.code(first, declared);\n\t\tconst local = frame.emitter.local(name.text);\n\t\tthis.bindLocal(name, local, frame, iec);\n\t\tconst compared = this.expressions.expression(condition.left, frame);\n\t\tconst limit = this.expressions.expression(condition.right, frame);\n\t\tconst test = mapped`${this.dialect.code(compared, declared)} ${condition.operatorToken.getText()} ${this.dialect.code(limit, declared)}`;\n\t\tconst step = this.loopStep(incrementor, name, local, declared, frame);\n\t\tframe.emitter.open(\n\t\t\tmapped`${labelText(labels)}for (let ${local}: ${iec ?? this.expressions.localType(declared)} = ${start}; ${test}; ${step}) {`,\n\t\t);\n\t\t// How often the body runs is known when the header compares the counter itself with a bound setup fixed.\n\t\tconst runs =\n\t\t\tcompared.kind === \"code\" && String(compared.text) === local\n\t\t\t\t? iterationCount(\n\t\t\t\t\t\tfirst,\n\t\t\t\t\t\tcondition.operatorToken.kind,\n\t\t\t\t\t\tlimit,\n\t\t\t\t\t\tincrementor,\n\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\tthis.loop(node.statement, labels, runs, frame);\n\t\tframe.emitter.close();\n\t}\n\n\t/** The step in a counted loop's header, as `i++` or `i += n` on the counter's local. */\n\tprivate loopStep(\n\t\tincrementor: ts.Expression,\n\t\tcounter: ts.Identifier,\n\t\tlocal: string,\n\t\tdeclared: ts.Type,\n\t\tframe: Frame,\n\t): Part {\n\t\tconst counterSymbol = this.checker.getSymbolAtLocation(counter);\n\t\tconst isCounter = (target: ts.Expression): boolean =>\n\t\t\tthis.checker.getSymbolAtLocation(unparenthesized(target)) ===\n\t\t\tcounterSymbol;\n\t\tif (\n\t\t\t(ts.isPrefixUnaryExpression(incrementor) ||\n\t\t\t\tts.isPostfixUnaryExpression(incrementor)) &&\n\t\t\tunitSteps.has(incrementor.operator) &&\n\t\t\tisCounter(incrementor.operand)\n\t\t) {\n\t\t\treturn `${local}${ts.tokenToString(incrementor.operator)}`;\n\t\t}\n\t\tif (\n\t\t\tts.isBinaryExpression(incrementor) &&\n\t\t\tcompoundSteps.has(incrementor.operatorToken.kind) &&\n\t\t\tisCounter(incrementor.left)\n\t\t) {\n\t\t\treturn mapped`${local} ${incrementor.operatorToken.getText()} ${this.dialect.code(this.expressions.expression(incrementor.right, frame), declared)}`;\n\t\t}\n\t\tthrow new SpecializeError(\n\t\t\tincrementor,\n\t\t\t\"Use i++, i--, i += step or i -= step in the for header.\",\n\t\t);\n\t}\n\n\tprivate switch(\n\t\tnode: ts.SwitchStatement,\n\t\tlabels: readonly string[],\n\t\tframe: Frame,\n\t): void {\n\t\tconst subject = this.expressions.expression(node.expression, frame);\n\t\tconst declared = subject.kind === \"code\" ? subject.declared : undefined;\n\t\tif (subject.kind === \"const\") {\n\t\t\tthis.constantSwitch(node, subject, labels, frame);\n\t\t\treturn;\n\t\t}\n\t\tframe.emitter.open(\n\t\t\tmapped`${labelText(labels)}switch (${this.dialect.code(subject, declared)}) {`,\n\t\t);\n\t\tthis.scoped({ kind: \"switch\", labels }, () =>\n\t\t\tthis.switchClauses(node, declared, frame),\n\t\t);\n\t\tframe.emitter.close();\n\t}\n\n\tprivate switchClauses(\n\t\tnode: ts.SwitchStatement,\n\t\tdeclared: ts.Type | undefined,\n\t\tframe: Frame,\n\t): void {\n\t\tfor (const clause of node.caseBlock.clauses) {\n\t\t\tif (ts.isDefaultClause(clause)) {\n\t\t\t\tframe.emitter.open(\"default: {\");\n\t\t\t\tif (clause.statements.some(unreachableEnd)) {\n\t\t\t\t\tframe.emitter.line(\n\t\t\t\t\t\tframe.returns && !(frame.returns.flags & ts.TypeFlags.Void)\n\t\t\t\t\t\t\t? `return ${this.initializers.defaultOf(frame.returns)};`\n\t\t\t\t\t\t\t: \"break;\",\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.statements(clause.statements, frame);\n\t\t\t\t}\n\t\t\t\tframe.emitter.close();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst label = this.expressions.expression(\n\t\t\t\tclause.expression,\n\t\t\t\tframe,\n\t\t\t\tdeclared,\n\t\t\t);\n\t\t\tframe.emitter.open(mapped`case ${this.dialect.code(label, declared)}: {`);\n\t\t\tthis.statements(clause.statements, frame);\n\t\t\tframe.emitter.close();\n\t\t}\n\t}\n\n\t/**\n\t * A switch on a value setup fixed runs the clause it matches, falling through as JavaScript does. A\n\t * break nested in it leaves the labelled block standing for the switch.\n\t */\n\tprivate constantSwitch(\n\t\tnode: ts.SwitchStatement,\n\t\tsubject: Value & { kind: \"const\" },\n\t\tlabels: readonly string[],\n\t\tframe: Frame,\n\t): void {\n\t\tconst nested = node.caseBlock.clauses.some((clause) =>\n\t\t\tclause.statements.some(\n\t\t\t\t(statement) =>\n\t\t\t\t\t!ts.isBreakStatement(statement) && containsJump(statement),\n\t\t\t),\n\t\t);\n\t\tconst label = nested ? frame.emitter.local(\"tsplcSwitch\") : undefined;\n\t\tif (label) {\n\t\t\tframe.emitter.open(`${label}: {`);\n\t\t}\n\t\tthis.scoped({ kind: \"switch\", labels, breakLabel: label }, () =>\n\t\t\tthis.matchedClauses(node, subject, labels, frame),\n\t\t);\n\t\tif (label) {\n\t\t\tframe.emitter.close();\n\t\t}\n\t}\n\n\tprivate matchedClauses(\n\t\tnode: ts.SwitchStatement,\n\t\tsubject: Value & { kind: \"const\" },\n\t\tlabels: readonly string[],\n\t\tframe: Frame,\n\t): void {\n\t\tconst clauses = node.caseBlock.clauses;\n\t\tconst start = clauses.findIndex((clause) => {\n\t\t\tif (ts.isDefaultClause(clause)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tconst label = this.expressions.expression(clause.expression, frame);\n\t\t\treturn label.kind === \"const\" && label.value === subject.value;\n\t\t});\n\t\tif (start < 0) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const clause of clauses.slice(start)) {\n\t\t\tfor (const statement of clause.statements) {\n\t\t\t\tif (\n\t\t\t\t\tts.isBreakStatement(statement) &&\n\t\t\t\t\t(!statement.label || labels.includes(statement.label.text))\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (this.statement(statement, frame)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/** An expression evaluated for its effect. */\n\tprivate effect(node: ts.Expression, frame: Frame): void {\n\t\tif (ts.isVoidExpression(node)) {\n\t\t\tconst value = this.expressions.expression(node.expression, frame);\n\t\t\tif (value.kind === \"code\") {\n\t\t\t\tframe.emitter.line(mapped`void ${value.text};`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (ts.isBinaryExpression(node) && isAssignment(node.operatorToken.kind)) {\n\t\t\tthis.expressions.assignments.assign(node, frame);\n\t\t\treturn;\n\t\t}\n\t\tif (isUpdate(node)) {\n\t\t\tthis.expressions.assignments.step(node, frame, { used: false });\n\t\t\treturn;\n\t\t}\n\t\tconst value = this.expressions.expression(node, frame);\n\t\tif (value.kind === \"code\" && String(value.text).includes(\"(\")) {\n\t\t\tframe.emitter.line(mapped`${value.text};`);\n\t\t}\n\t}\n}\n\n/** The one const a for…of declares. */\nconst loopDeclaration = (node: ts.ForOfStatement): ts.VariableDeclaration => {\n\tconst declaration = onlyDeclaration(node.initializer);\n\tif (!declaration) {\n\t\tthrow new SpecializeError(node.initializer, \"Declare one const in for…of.\");\n\t}\n\treturn declaration;\n};\n\n/** The one variable a loop header declares; undefined when it declares none or several. */\nconst onlyDeclaration = (\n\tinitializer: ts.ForInitializer | undefined,\n): ts.VariableDeclaration | undefined => {\n\tif (!initializer || !ts.isVariableDeclarationList(initializer)) {\n\t\treturn undefined;\n\t}\n\tconst [declaration, ...others] = initializer.declarations;\n\treturn others.length ? undefined : declaration;\n};\n\n/**\n * How many times a counted loop's body can run: from its start, the bound its counter is compared\n * with and its step, when setup fixed them all. Undefined for a header that doesn't say.\n */\nconst iterationCount = (\n\tstart: Value,\n\tcomparison: ts.SyntaxKind,\n\tlimit: Value,\n\tincrementor: ts.Expression,\n): number | undefined => {\n\tconst first = known(start);\n\tconst last = known(limit);\n\tconst step = stepOf(incrementor);\n\tif (\n\t\tfirst === undefined ||\n\t\tlast === undefined ||\n\t\tstep === undefined ||\n\t\t!Number.isInteger(first) ||\n\t\t!Number.isInteger(last)\n\t) {\n\t\treturn undefined;\n\t}\n\tconst rising = step > 0;\n\tconst exclusive = rising\n\t\t? ts.SyntaxKind.LessThanToken\n\t\t: ts.SyntaxKind.GreaterThanToken;\n\tconst inclusive = rising\n\t\t? ts.SyntaxKind.LessThanEqualsToken\n\t\t: ts.SyntaxKind.GreaterThanEqualsToken;\n\tif (comparison !== exclusive && comparison !== inclusive) {\n\t\treturn undefined;\n\t}\n\treturn Number(\n\t\tloopIterations(\n\t\t\tBigInt(first),\n\t\t\tBigInt(last),\n\t\t\tcomparison === exclusive,\n\t\t\tBigInt(step),\n\t\t),\n\t);\n};\n\n/** A counted loop's step, as `i++`, `i--`, `i += 2` or `i -= 2` writes it. */\nconst stepOf = (incrementor: ts.Expression): number | undefined => {\n\tif (\n\t\tts.isPrefixUnaryExpression(incrementor) ||\n\t\tts.isPostfixUnaryExpression(incrementor)\n\t) {\n\t\treturn unitSteps.get(incrementor.operator);\n\t}\n\tif (\n\t\t!ts.isBinaryExpression(incrementor) ||\n\t\t!ts.isNumericLiteral(incrementor.right)\n\t) {\n\t\treturn undefined;\n\t}\n\tconst size = Number(incrementor.right.text);\n\tif (!Number.isInteger(size) || size <= 0) {\n\t\treturn undefined;\n\t}\n\tconst sign = compoundSteps.get(incrementor.operatorToken.kind);\n\treturn sign === undefined ? undefined : sign * size;\n};\n\nconst unitSteps = new Map<ts.SyntaxKind, number>([\n\t[ts.SyntaxKind.PlusPlusToken, 1],\n\t[ts.SyntaxKind.MinusMinusToken, -1],\n]);\n\nconst compoundSteps = new Map<ts.SyntaxKind, number>([\n\t[ts.SyntaxKind.PlusEqualsToken, 1],\n\t[ts.SyntaxKind.MinusEqualsToken, -1],\n]);\n\nconst labelText = (labels: readonly string[]): string =>\n\tlabels.map((label) => `${label}: `).join(\"\");\n\n/** The statement under a run of labels, collecting them. */\nconst innermostLabelled = (\n\tnode: ts.LabeledStatement,\n\tlabels: string[],\n): ts.Statement => {\n\tlabels.push(node.label.text);\n\treturn ts.isLabeledStatement(node.statement)\n\t\t? innermostLabelled(node.statement, labels)\n\t\t: node.statement;\n};\n\n/** Whether a break or continue sits in the statement, outside functions it declares. */\nconst containsJump = (node: ts.Node): boolean =>\n\toccursOutsideFunctions(\n\t\tnode,\n\t\t(inner) => ts.isBreakStatement(inner) || ts.isContinueStatement(inner),\n\t);\n\n/** `return x satisfies never`, which marks an end the program never reaches. */\nconst unreachableEnd = (statement: ts.Statement): boolean =>\n\tts.isReturnStatement(statement) &&\n\tstatement.expression !== undefined &&\n\tts.isSatisfiesExpression(statement.expression) &&\n\tstatement.expression.type.kind === ts.SyntaxKind.NeverKeyword;\n\nconst unsupported = (node: ts.Statement): SpecializeError =>\n\tnew SpecializeError(\n\t\tnode,\n\t\t`${ts.SyntaxKind[node.kind]} is not supported in scan code.`,\n\t);\n",
55
+ "import { type Diagnostic, error } from \"@tsplc/compiler/ir\";\nimport ts from \"typescript\";\nimport {\n\tasyncWrapAdd,\n\tcooperativeTasksAlias,\n\tdiagnosticsInstance,\n\terrorCodeAlias,\n} from \"./cooperative\";\nimport { GeneratedNames } from \"./generated-names\";\nimport { loweringKey } from \"./lowering-key\";\nimport { importSpecifier, namedRoutines, plcSources } from \"./module-graph\";\nimport {\n\ttype Edit,\n\tedited,\n\tfrom,\n\tjoined,\n\ttype Mapped,\n\tmapped,\n\ttype Positions,\n} from \"./positions\";\nimport { type Chain, chainOf, lowerChain } from \"./promise-chains\";\nimport { namesSdk, sdkModules, symbolAt } from \"./sdk\";\nimport { hasModifier, SemanticError } from \"./types\";\n\n/** A function or method a chain can call or be written in. */\nexport type Callable = ts.FunctionDeclaration | ts.MethodDeclaration;\n\ninterface PromiseLowering {\n\tsources: Map<string, Mapped>;\n\tdiagnostics: Diagnostic[];\n\truntimeBlocks: Map<string, { kind: \"mailbox\" }>;\n}\n\n/** A detached chain's site, and the routine its chain starts with. */\nexport interface ChainSite {\n\tname: string;\n\troot: ts.Symbol | undefined;\n}\n\n/** What lowering one chain needs from the rewrite of the whole program. */\nexport interface PromiseContext {\n\treadonly checker: ts.TypeChecker;\n\t/** Every function and method by symbol; named callbacks and operations resolve here. */\n\treadonly routines: ReadonlyMap<ts.Symbol, Callable>;\n\t/**\n\t * The sites of detached chains, by the module or class whose cancelAsync cancels them, each with\n\t * the routine its chain starts with.\n\t */\n\treadonly sites: Map<ts.SourceFile | ts.ClassDeclaration, ChainSite[]>;\n\tsymbol(node: ts.Node): ts.Symbol | undefined;\n\t/** Whether a node names the SDK declaration `name`. */\n\tnamesSdk(node: ts.Node, name: string): boolean;\n\tfail(node: ts.Node, message: string): never;\n\t/** Names for generated declarations, from the source node each stands for. */\n\treadonly names: GeneratedNames;\n\t/** Adds generated code to the end of a module, or to a class, mapped to the node it was made for. */\n\tappend(\n\t\tscope: ts.SourceFile | ts.ClassDeclaration,\n\t\torigin: ts.Node,\n\t\ttext: string,\n\t): void;\n\t/** A type's text as `source` names it: declared elsewhere, it is aliased there and imported. */\n\ttypeText(node: ts.TypeNode, source: ts.SourceFile): string;\n\t/** Imports the SDK names generated helpers use into `source`, once. */\n\tensureImports(source: ts.SourceFile, origin: ts.Node): void;\n\t/** Marks that generated code reports to the shared diagnostics block. */\n\tuseDiagnostics(node: ts.Node): void;\n}\n\n/** Normalize promise syntax into named coroutines; scheduling stays in async lowering. */\nexport const lowerPromises = (\n\tprogram: ts.Program,\n\tsdk: string,\n\tpositions: Positions,\n\troot: string,\n): PromiseLowering => {\n\tconst files = plcSources(program);\n\tconst rewrite = new PromiseRewrite(\n\t\tprogram.getTypeChecker(),\n\t\tsdk,\n\t\tpositions,\n\t\tfiles,\n\t\tnew GeneratedNames(root),\n\t);\n\tconst diagnostics: Diagnostic[] = [];\n\tconst runtimeBlocks = new Map<string, { kind: \"mailbox\" }>();\n\tconst { diagnosticsCalls, cancelCalls } = rewriteChains(\n\t\trewrite,\n\t\tfiles,\n\t\tdiagnostics,\n\t);\n\tfor (const { node, owner } of cancelCalls) {\n\t\tcancelScope(rewrite, node, owner, diagnostics);\n\t}\n\tconst owner = rewrite.diagnosticsOwner;\n\tif (owner) {\n\t\tconst source = owner.getSourceFile();\n\t\trewrite.ensureImports(source, owner);\n\t\trewrite.append(\n\t\t\tsource,\n\t\t\towner,\n\t\t\t`export class TsplcPromiseDiagnostics extends FunctionBlock<{}>{private count:UDINT=0;private lastError:UDINT=0;public report(code:UDINT,count:UDINT):BOOL{this.count=${asyncWrapAdd}<UDINT>(this.count,count);this.lastError=code;return true;}public snapshot():{valid:BOOL;count:UDINT;lastError:UDINT}{return {valid:true,count:this.count,lastError:this.lastError};}protected execute(input:{}):void{}}\nexport const ${diagnosticsInstance}=new TsplcPromiseDiagnostics();`,\n\t\t);\n\t\truntimeBlocks.set(loweringKey(source.fileName, \"TsplcPromiseDiagnostics\"), {\n\t\t\tkind: \"mailbox\",\n\t\t});\n\t\tfor (const file of new Set([\n\t\t\t...rewrite.extendedFiles(),\n\t\t\t...diagnosticsCalls.map((node) => node.getSourceFile()),\n\t\t])) {\n\t\t\tif (file !== source) {\n\t\t\t\trewrite.append(\n\t\t\t\t\tfile,\n\t\t\t\t\tfile,\n\t\t\t\t\t`import {${diagnosticsInstance}} from ${importSpecifier(file.fileName, source.fileName)};`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tfor (const call of diagnosticsCalls) {\n\t\t\trewrite.edit(call, `${diagnosticsInstance}.snapshot()`);\n\t\t}\n\t}\n\treturn { sources: rewrite.sources(files), diagnostics, runtimeBlocks };\n};\n\n/**\n * Replaces each promise chain in a routine: a detached statement becomes a cooperative site,\n * and a chain used as a value becomes a call to its last helper. Collects the\n * `asyncDiagnostics()` and `cancelAsync()` calls it passes.\n */\nfunction rewriteChains(\n\trewrite: PromiseRewrite,\n\tfiles: readonly ts.SourceFile[],\n\tdiagnostics: Diagnostic[],\n) {\n\tconst diagnosticsCalls: ts.CallExpression[] = [];\n\tconst cancelCalls: { node: ts.CallExpression; owner: Callable }[] = [];\n\tconst lower = (\n\t\tnode: ts.Node,\n\t\texpression: ts.Expression,\n\t\tchain: Chain,\n\t\towner: Callable,\n\t\t{ detached }: { detached: boolean },\n\t) => {\n\t\ttry {\n\t\t\trewrite.edit(\n\t\t\t\tnode,\n\t\t\t\tlowerChain(rewrite, expression, chain, owner, { detached }),\n\t\t\t);\n\t\t} catch (cause) {\n\t\t\tif (!(cause instanceof SemanticError)) {\n\t\t\t\tthrow cause;\n\t\t\t}\n\t\t\tdiagnostics.push(cause.diagnostic);\n\t\t}\n\t};\n\tfor (const source of files) {\n\t\tconst visit = (node: ts.Node, owner?: Callable): void => {\n\t\t\tif (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node)) {\n\t\t\t\tif (node.body) {\n\t\t\t\t\tts.forEachChild(node.body, (child) => visit(child, node));\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!owner) {\n\t\t\t\tts.forEachChild(node, (child) => visit(child));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tts.isCallExpression(node) &&\n\t\t\t\trewrite.namesSdk(node.expression, \"asyncDiagnostics\")\n\t\t\t) {\n\t\t\t\trewrite.useDiagnostics(node);\n\t\t\t\tdiagnosticsCalls.push(node);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tts.isCallExpression(node) &&\n\t\t\t\trewrite.namesSdk(node.expression, \"cancelAsync\")\n\t\t\t) {\n\t\t\t\tcancelCalls.push({ node, owner });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (ts.isExpressionStatement(node)) {\n\t\t\t\tconst expression = ts.isVoidExpression(node.expression)\n\t\t\t\t\t? node.expression.expression\n\t\t\t\t\t: node.expression;\n\t\t\t\tconst chain = chainOf(rewrite, expression);\n\t\t\t\tif (chain) {\n\t\t\t\t\tif (hasModifier(owner, ts.SyntaxKind.AsyncKeyword)) {\n\t\t\t\t\t\tdiagnostics.push(\n\t\t\t\t\t\t\trewrite.diagnostic(\n\t\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\t\"Await async work inside an async routine; detached calls belong in synchronous controllers.\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlower(node, expression, chain, owner, { detached: true });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ts.isCallExpression(node)) {\n\t\t\t\tconst chain = chainOf(rewrite, node);\n\t\t\t\tif (chain?.links.length) {\n\t\t\t\t\tlower(node, node, chain, owner, { detached: false });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tts.forEachChild(node, (child) => visit(child, owner));\n\t\t};\n\t\tvisit(source);\n\t}\n\treturn { diagnosticsCalls, cancelCalls };\n}\n\n/**\n * `cancelAsync()` cancels every detached chain of the module, `cancelAsync(this)` of the block, and\n * `cancelAsync(run, ...)` in a module each of the module's chains that starts with one of those\n * routines, which is how a plain program cancels one object's calls.\n */\nfunction cancelScope(\n\trewrite: PromiseRewrite,\n\tnode: ts.CallExpression,\n\towner: Callable,\n\tdiagnostics: Diagnostic[],\n): void {\n\tconst scope =\n\t\tts.isMethodDeclaration(owner) && ts.isClassDeclaration(owner.parent)\n\t\t\t? owner.parent\n\t\t\t: owner.getSourceFile();\n\tconst member = ts.isClassDeclaration(scope);\n\tconst [argument, ...rest] = node.arguments;\n\tconst roots = member\n\t\t? undefined\n\t\t: node.arguments.map((routine) =>\n\t\t\t\tts.isIdentifier(routine) ? rewrite.symbol(routine) : undefined,\n\t\t\t);\n\tconst byRoutine =\n\t\troots !== undefined &&\n\t\troots.length > 0 &&\n\t\troots.every((root) => root !== undefined && rewrite.routines.has(root));\n\tif (\n\t\targument &&\n\t\t!byRoutine &&\n\t\t(rest.length || argument.kind !== ts.SyntaxKind.ThisKeyword)\n\t) {\n\t\tdiagnostics.push(\n\t\t\trewrite.diagnostic(\n\t\t\t\tnode,\n\t\t\t\t\"cancelAsync takes this in a controller, or no argument in a module.\",\n\t\t\t),\n\t\t);\n\t}\n\tconst name = rewrite.names.name(\"tsplcCancelScope\", node);\n\tconst body = (rewrite.sites.get(scope) ?? [])\n\t\t.filter(\n\t\t\t(site) =>\n\t\t\t\t!byRoutine || (site.root !== undefined && roots.includes(site.root)),\n\t\t)\n\t\t.map((site) => `${member ? \"this.\" : \"\"}${site.name}.cancel();`)\n\t\t.join(\"\");\n\trewrite.append(\n\t\tscope,\n\t\tnode,\n\t\tmember\n\t\t\t? `private ${name}():void{${body}}`\n\t\t\t: `function ${name}():void{${body}}`,\n\t);\n\trewrite.edit(node, `${member ? \"this.\" : \"\"}${name}()`);\n}\n\n/** The edits and generated code promise lowering makes across the program. */\nclass PromiseRewrite implements PromiseContext {\n\treadonly routines: ReadonlyMap<ts.Symbol, Callable>;\n\treadonly sites = new Map<ts.SourceFile | ts.ClassDeclaration, ChainSite[]>();\n\t/** The first node that needs the shared diagnostics block, which its module declares. */\n\tdiagnosticsOwner: ts.Node | undefined;\n\t/** Generated code by the module it ends or the class it joins. */\n\tprivate readonly additions = new Map<\n\t\tts.SourceFile | ts.ClassDeclaration,\n\t\tMapped[]\n\t>();\n\tprivate readonly edits = new Map<ts.SourceFile, Edit[]>();\n\tprivate readonly aliases = new Map<ts.Node, string>();\n\tprivate readonly typeImports = new Map<ts.SourceFile, Set<string>>();\n\tprivate readonly imported = new Set<ts.SourceFile>();\n\tconstructor(\n\t\treadonly checker: ts.TypeChecker,\n\t\tprivate readonly sdk: string,\n\t\tprivate readonly positions: Positions,\n\t\tfiles: readonly ts.SourceFile[],\n\t\treadonly names: GeneratedNames,\n\t) {\n\t\tthis.routines = namedRoutines(files, checker);\n\t}\n\n\tsymbol(node: ts.Node): ts.Symbol | undefined {\n\t\treturn symbolAt(this.checker, node);\n\t}\n\n\tnamesSdk(node: ts.Node, name: string): boolean {\n\t\treturn namesSdk(this.checker, this.sdk, node, name);\n\t}\n\n\tdiagnostic(node: ts.Node, message: string): Diagnostic {\n\t\treturn error(\"PLC1012\", message, this.positions.node(node));\n\t}\n\n\tfail(node: ts.Node, message: string): never {\n\t\tthrow new SemanticError(this.diagnostic(node, message));\n\t}\n\n\tappend(\n\t\tscope: ts.SourceFile | ts.ClassDeclaration,\n\t\torigin: ts.Node,\n\t\ttext: string,\n\t): void {\n\t\tthis.additions.set(scope, [\n\t\t\t...(this.additions.get(scope) ?? []),\n\t\t\tfrom(origin, text),\n\t\t]);\n\t}\n\n\tedit(node: ts.Node, text: string): void {\n\t\tconst source = node.getSourceFile();\n\t\tthis.edits.set(source, [\n\t\t\t...(this.edits.get(source) ?? []),\n\t\t\t{ start: node.getStart(source), end: node.end, text },\n\t\t]);\n\t}\n\n\t/** The modules generated code has been added to so far. */\n\textendedFiles(): ts.SourceFile[] {\n\t\treturn [...this.additions.keys()].filter(ts.isSourceFile);\n\t}\n\n\ttypeText(node: ts.TypeNode, source: ts.SourceFile): string {\n\t\tif (node.kind === ts.SyntaxKind.VoidKeyword) {\n\t\t\treturn \"void\";\n\t\t}\n\t\tif (node.getSourceFile() === source) {\n\t\t\treturn node.getText(source);\n\t\t}\n\t\tconst alias = this.aliases.get(node) ?? this.declareAlias(node);\n\t\tconst importedAliases = this.typeImports.get(source) ?? new Set<string>();\n\t\tif (importedAliases.has(alias)) {\n\t\t\treturn alias;\n\t\t}\n\t\timportedAliases.add(alias);\n\t\tthis.typeImports.set(source, importedAliases);\n\t\tthis.append(\n\t\t\tsource,\n\t\t\tnode,\n\t\t\t`import type {${alias}} from ${importSpecifier(source.fileName, node.getSourceFile().fileName)};`,\n\t\t);\n\t\treturn alias;\n\t}\n\n\t/** Exports a type from the module that declares it, so other modules can name it. */\n\tprivate declareAlias(node: ts.TypeNode): string {\n\t\tconst alias = this.names.name(\"TsplcPromiseType\", node);\n\t\tthis.aliases.set(node, alias);\n\t\tthis.append(\n\t\t\tnode.getSourceFile(),\n\t\t\tnode,\n\t\t\t`export type ${alias}=${node.getText(node.getSourceFile())};`,\n\t\t);\n\t\treturn alias;\n\t}\n\n\tensureImports(source: ts.SourceFile, origin: ts.Node): void {\n\t\tif (this.imported.has(source)) {\n\t\t\treturn;\n\t\t}\n\t\tthis.imported.add(source);\n\t\tthis.append(\n\t\t\tsource,\n\t\t\torigin,\n\t\t\t`import {cooperativeTasks as ${cooperativeTasksAlias},errorCode as ${errorCodeAlias}} from \"${sdkModules.async}\";import {wrapAdd as ${asyncWrapAdd}} from \"${sdkModules.types}\";`,\n\t\t);\n\t}\n\n\tuseDiagnostics(node: ts.Node): void {\n\t\tthis.diagnosticsOwner ??= node;\n\t}\n\n\t/** Each changed module's text: its edits, class members appended in place, then its additions. */\n\tsources(files: readonly ts.SourceFile[]): Map<string, Mapped> {\n\t\tfor (const [owner, texts] of this.additions) {\n\t\t\tif (!ts.isClassDeclaration(owner)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst source = owner.getSourceFile();\n\t\t\tthis.edits.set(source, [\n\t\t\t\t...(this.edits.get(source) ?? []),\n\t\t\t\t{\n\t\t\t\t\tstart: owner.end - 1,\n\t\t\t\t\tend: owner.end - 1,\n\t\t\t\t\ttext: mapped`\\n${joined(texts, \"\\n\")}`,\n\t\t\t\t},\n\t\t\t]);\n\t\t}\n\t\tconst sources = new Map<string, Mapped>();\n\t\tfor (const source of files) {\n\t\t\tconst changes = this.edits.get(source) ?? [];\n\t\t\tconst extra = this.additions.get(source) ?? [];\n\t\t\tif (!changes.length && !extra.length) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tsources.set(\n\t\t\t\tsource.fileName,\n\t\t\t\tmapped`${edited(source, changes)}\\n${joined(extra, \"\\n\")}`,\n\t\t\t);\n\t\t}\n\t\treturn sources;\n\t}\n}\n",
56
+ "import { dirname, join } from \"node:path\";\nimport { type Diagnostic, error } from \"@tsplc/compiler/ir\";\nimport type { ServerConfig } from \"@tsplc/config\";\nimport {\n\tisIntegerType,\n\tplcProcedureKind,\n\ttype ServiceContract,\n\tserviceContract,\n\ttype WireField,\n\ttype WireScalar,\n\twireLayout,\n\twireRecord,\n} from \"@tsplc/server/contract\";\nimport { servicePath } from \"@tsplc/server/wire\";\nimport ts from \"typescript\";\nimport { importSpecifier, plcSources, runtimeImport } from \"./module-graph\";\nimport {\n\ttype Edit,\n\tedited,\n\tfrom,\n\ttype Mapped,\n\tmapped,\n\ttype Positions,\n} from \"./positions\";\nimport { namesSdk, sdkModules, symbolAt } from \"./sdk\";\nimport type { ServiceRecord } from \"./types\";\n\n/** The server section's transport; each client's type argument names its router. */\nexport type ServiceOptions = Pick<ServerConfig, \"transport\" | \"baseUrlEnv\">;\n\n/** Why a procedure's input or output cannot cross the wire to the PLC; the message names the field. */\nclass WireLayoutError extends Error {}\n\n/** A server contract check, whose every Error describes a schema the PLC cannot exchange. */\nconst contractCheck = <T>(check: () => T): T => {\n\ttry {\n\t\treturn check();\n\t} catch (cause) {\n\t\tthrow cause instanceof Error ? new WireLayoutError(cause.message) : cause;\n\t}\n};\n\n/** What `read` returns, or the WireLayoutError it rejected the schema with. */\nconst wireLayoutOf = <T>(read: () => T): T | WireLayoutError => {\n\ttry {\n\t\treturn read();\n\t} catch (cause) {\n\t\tif (cause instanceof WireLayoutError) {\n\t\t\treturn cause;\n\t\t}\n\t\tthrow cause;\n\t}\n};\n\n/** The longest server base URL the PLC holds. */\nconst baseUrlCapacity = 512;\n\n/** A procedure record read from its type, with the PLC enum each enum field names. */\ninterface RecordLayout {\n\tfields: Record<string, WireField>;\n\tenums: Record<string, ts.EnumDeclaration>;\n}\n\nconst property = (checker: ts.TypeChecker, type: ts.Type, name: string) => {\n\tconst symbol = type.getProperty(name);\n\treturn symbol && checker.getTypeOfSymbol(symbol);\n};\n\n/** An `iec.*` schema's layout, which its type carries as an optional phantom property. */\nconst layoutNumber = (\n\tchecker: ts.TypeChecker,\n\ttype: ts.Type,\n\tname: string,\n\tlabel: string,\n) => {\n\tconst brand = property(checker, type, wireLayout);\n\tconst value =\n\t\tbrand && property(checker, checker.getNonNullableType(brand), name);\n\tif (!value) {\n\t\treturn undefined;\n\t}\n\tif (!value.isNumberLiteral()) {\n\t\tthrow new WireLayoutError(`${label}: ${name} must be a literal number.`);\n\t}\n\treturn value.value;\n};\n\nconst scalarLayout = (\n\tchecker: ts.TypeChecker,\n\ttype: ts.Type,\n\tlabel: string,\n): { field: WireScalar; enumeration?: ts.EnumDeclaration } => {\n\tif (type.flags & ts.TypeFlags.Boolean) {\n\t\treturn { field: { kind: \"boolean\" } };\n\t}\n\t// An enum type is the union of its member literals.\n\tconst first = type.isUnion() ? type.types[0] : type;\n\tconst member = first?.symbol?.valueDeclaration;\n\tif (\n\t\tfirst &&\n\t\tfirst.flags & ts.TypeFlags.EnumLiteral &&\n\t\tmember &&\n\t\tts.isEnumMember(member)\n\t) {\n\t\tconst members: Record<string, number> = {};\n\t\tfor (const item of member.parent.members) {\n\t\t\tconst value = checker.getConstantValue(item);\n\t\t\tif (typeof value !== \"number\") {\n\t\t\t\tthrow new WireLayoutError(\n\t\t\t\t\t`${label}: PLC enums require numeric members.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tmembers[item.name.getText()] = value;\n\t\t}\n\t\treturn { field: { kind: \"enum\", members }, enumeration: member.parent };\n\t}\n\tconst capacity = layoutNumber(checker, type, \"capacity\", label);\n\tif (capacity !== undefined) {\n\t\treturn { field: { kind: \"string\", capacity } };\n\t}\n\tconst brand = property(checker, type, wireLayout);\n\tconst iec =\n\t\tbrand && property(checker, checker.getNonNullableType(brand), \"iec\");\n\tif (iec?.isStringLiteral() && isIntegerType(iec.value)) {\n\t\tconst minimum = layoutNumber(checker, type, \"minimum\", label);\n\t\tconst maximum = layoutNumber(checker, type, \"maximum\", label);\n\t\tif (minimum !== undefined && maximum !== undefined) {\n\t\t\treturn { field: { kind: \"integer\", iec: iec.value, minimum, maximum } };\n\t\t}\n\t}\n\tthrow new WireLayoutError(\n\t\t`${label}: use z.boolean(), z.enum() of a numeric enum, iec.STRING(), or an integer such as iec.INT().`,\n\t);\n};\n\nconst recordLayout = (\n\tchecker: ts.TypeChecker,\n\ttype: ts.Type,\n\tlabel: string,\n\toutput: boolean,\n): RecordLayout => {\n\tconst fields: Record<string, WireField> = {};\n\tconst enums: Record<string, ts.EnumDeclaration> = {};\n\t// A procedure without `.input()` takes `void`.\n\tif (!(type.flags & ts.TypeFlags.Void)) {\n\t\tif (\n\t\t\t!(type.flags & ts.TypeFlags.Object) ||\n\t\t\ttype.getStringIndexType() ||\n\t\t\ttype.getNumberIndexType() ||\n\t\t\ttype.getCallSignatures().length\n\t\t) {\n\t\t\tthrow new WireLayoutError(\n\t\t\t\t`${label}: PLC procedures exchange one closed z.strictObject() record.`,\n\t\t\t);\n\t\t}\n\t\tfor (const field of type.getProperties()) {\n\t\t\tconst key = `${label}.${field.name}`;\n\t\t\tif (field.flags & ts.SymbolFlags.Optional) {\n\t\t\t\tthrow new WireLayoutError(\n\t\t\t\t\t`${key}: optional wire fields are unsupported.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst value = checker.getTypeOfSymbol(field);\n\t\t\tconst length = layoutNumber(checker, value, \"length\", key);\n\t\t\tconst element =\n\t\t\t\tlength === undefined ? undefined : value.getNumberIndexType();\n\t\t\tconst scalar = scalarLayout(checker, element ?? value, key);\n\t\t\tfields[field.name] =\n\t\t\t\tlength === undefined\n\t\t\t\t\t? scalar.field\n\t\t\t\t\t: { kind: \"array\", length, element: scalar.field };\n\t\t\tif (scalar.enumeration) {\n\t\t\t\tenums[field.name] = scalar.enumeration;\n\t\t\t}\n\t\t}\n\t}\n\treturn {\n\t\tfields: contractCheck(() => wireRecord(fields, label, output)).fields,\n\t\tenums,\n\t};\n};\n\n/** Identifies a record by layout, so every name for it lowers to one PLC struct. */\nconst recordKey = (layout: RecordLayout) =>\n\tJSON.stringify([\n\t\tlayout.fields,\n\t\tObject.entries(layout.enums)\n\t\t\t.map(([field, value]) => [\n\t\t\t\tfield,\n\t\t\t\tvalue.getSourceFile().fileName,\n\t\t\t\tvalue.name.text,\n\t\t\t])\n\t\t\t.sort(),\n\t]);\n\nconst procedureAt = (\n\tchecker: ts.TypeChecker,\n\trouter: ts.Type,\n\tpath: readonly string[],\n) => {\n\tconst type = [\"_def\", \"record\", ...path].reduce<ts.Type | undefined>(\n\t\t(parent, name) => parent && property(checker, parent, name),\n\t\trouter,\n\t);\n\tconst definition = type && property(checker, type, \"_def\");\n\tif (!definition || !property(checker, definition, \"procedure\")) {\n\t\treturn undefined;\n\t}\n\tconst kind = property(checker, definition, \"type\");\n\tconst types = property(checker, definition, \"$types\");\n\tconst input = types && property(checker, types, \"input\");\n\tconst output = types && property(checker, types, \"output\");\n\tif (!kind?.isStringLiteral() || !input || !output) {\n\t\treturn undefined;\n\t}\n\treturn { kind: kind.value, input, output };\n};\n\n// Unlike the backend's pascalCase, this keeps underscores: `line_state.get` names `Line_stateGet`.\nconst pascalServicePath = (path: string) =>\n\tpath\n\t\t.split(\".\")\n\t\t.map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))\n\t\t.join(\"\");\n\n/** The export of the generated service module that calls the procedure at `path`. */\nconst serviceExportName = (path: string) =>\n\t`tsplcService_${path.replaceAll(\".\", \"_\")}`;\n\ninterface ServiceCall {\n\tcontract: ServiceContract;\n\tinput: string;\n\toutput: string;\n}\n\n/** A called procedure's contract with the record names it exchanges, or why the PLC cannot call it. */\nconst serviceCall = (\n\tchecker: ts.TypeChecker,\n\tpath: string,\n\tprocedure: NonNullable<ReturnType<typeof procedureAt>>,\n\trecord: (layout: RecordLayout, name: string) => string,\n): ServiceCall | WireLayoutError =>\n\twireLayoutOf(() => {\n\t\tconst kind = contractCheck(() => plcProcedureKind(path, procedure.kind));\n\t\tconst input = recordLayout(\n\t\t\tchecker,\n\t\t\tprocedure.input,\n\t\t\t`${path}.input`,\n\t\t\tfalse,\n\t\t);\n\t\tconst output = recordLayout(\n\t\t\tchecker,\n\t\t\tprocedure.output,\n\t\t\t`${path}.output`,\n\t\t\ttrue,\n\t\t);\n\t\tconst contract = contractCheck(() =>\n\t\t\tserviceContract(\n\t\t\t\tpath,\n\t\t\t\tkind,\n\t\t\t\t{ fields: input.fields },\n\t\t\t\t{ fields: output.fields },\n\t\t\t),\n\t\t);\n\t\treturn {\n\t\t\tcontract,\n\t\t\tinput: record(input, `${pascalServicePath(path)}Input`),\n\t\t\toutput: record(output, `${pascalServicePath(path)}Output`),\n\t\t};\n\t});\n\n/**\n * Replaces each `createServiceClient<Router>()` call with an in-memory module of the called\n * procedures, read from the router's type: the server never runs and no file is written.\n */\nexport const lowerServices = (\n\tprogram: ts.Program,\n\tsdk: string,\n\tpositions: Positions,\n\toptions: ServiceOptions | undefined,\n) => {\n\tconst sources = new Map<string, Mapped>();\n\tconst diagnostics: Diagnostic[] = [];\n\tconst records = new Map<string, { name: string; layout: RecordLayout }>();\n\tconst calls = new Map<string, ServiceCall>();\n\tconst checker = program.getTypeChecker();\n\tconst fail = (node: ts.Node, code: string, message: string) =>\n\t\tdiagnostics.push(error(code, message, positions.node(node)));\n\tconst record = (layout: RecordLayout, name: string) => {\n\t\tconst key = recordKey(layout);\n\t\tconst existing = records.get(key);\n\t\tif (existing) {\n\t\t\treturn existing.name;\n\t\t}\n\t\trecords.set(key, { name, layout });\n\t\treturn name;\n\t};\n\n\tconst clients = new Map<ts.Symbol, ts.Type>();\n\t/** The generated service module, and the first client's creation it stands for. */\n\tlet module: { file: string; client: ts.CallExpression } | undefined;\n\tconst sourceFiles = plcSources(program);\n\tfor (const source of sourceFiles) {\n\t\tfor (const statement of source.statements) {\n\t\t\tif (!ts.isVariableStatement(statement)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const declaration of statement.declarationList.declarations) {\n\t\t\t\tconst call = declaration.initializer;\n\t\t\t\tif (\n\t\t\t\t\t!call ||\n\t\t\t\t\t!ts.isCallExpression(call) ||\n\t\t\t\t\t!namesSdk(checker, sdk, call.expression, \"createServiceClient\")\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst router = call.typeArguments?.[0];\n\t\t\t\tconst client = symbolAt(checker, declaration.name);\n\t\t\t\tif (\n\t\t\t\t\t!router ||\n\t\t\t\t\t!client ||\n\t\t\t\t\t!(statement.declarationList.flags & ts.NodeFlags.Const)\n\t\t\t\t) {\n\t\t\t\t\tfail(\n\t\t\t\t\t\tdeclaration,\n\t\t\t\t\t\t\"PLC1013\",\n\t\t\t\t\t\t\"Create a service client as a module constant: const services = createServiceClient<AppRouter>().\",\n\t\t\t\t\t);\n\t\t\t\t} else if (!options) {\n\t\t\t\t\tfail(\n\t\t\t\t\t\tcall,\n\t\t\t\t\t\t\"PLC1013\",\n\t\t\t\t\t\t\"Configure server in tsplc.config.ts to call the server.\",\n\t\t\t\t\t);\n\t\t\t\t} else if (options.transport === \"http\" && !options.baseUrlEnv) {\n\t\t\t\t\tfail(\n\t\t\t\t\t\tcall,\n\t\t\t\t\t\t\"PLC1013\",\n\t\t\t\t\t\t\"HTTP service transport requires server.baseUrlEnv.\",\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tclients.set(client, checker.getTypeFromTypeNode(router));\n\t\t\t\t\tmodule ??= {\n\t\t\t\t\t\tfile: join(dirname(source.fileName), \".tsplc-services.ts\"),\n\t\t\t\t\t\tclient: call,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (const source of sourceFiles) {\n\t\tconst edits: Edit[] = [];\n\t\tconst imports = new Map<string, string>();\n\t\tconst visit = (node: ts.Node): void => {\n\t\t\tif (\n\t\t\t\tts.isImportDeclaration(node) &&\n\t\t\t\tts.isStringLiteral(node.moduleSpecifier)\n\t\t\t) {\n\t\t\t\tconst clause = node.importClause;\n\t\t\t\tconst bindings = clause?.namedBindings;\n\t\t\t\tconst runtime = runtimeImport(node, checker);\n\t\t\t\tif (runtime && clause && bindings && ts.isNamedImports(bindings)) {\n\t\t\t\t\tconst elements = bindings.elements.filter((element) => {\n\t\t\t\t\t\tconst imported = symbolAt(checker, element.name);\n\t\t\t\t\t\treturn !imported || !clients.has(imported);\n\t\t\t\t\t});\n\t\t\t\t\tif (elements.length !== bindings.elements.length) {\n\t\t\t\t\t\tedits.push({\n\t\t\t\t\t\t\tstart: node.getStart(source),\n\t\t\t\t\t\t\tend: node.end,\n\t\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\t\telements.length || clause.name\n\t\t\t\t\t\t\t\t\t? ts\n\t\t\t\t\t\t\t\t\t\t\t.createPrinter()\n\t\t\t\t\t\t\t\t\t\t\t.printNode(\n\t\t\t\t\t\t\t\t\t\t\t\tts.EmitHint.Unspecified,\n\t\t\t\t\t\t\t\t\t\t\t\tts.factory.updateImportDeclaration(\n\t\t\t\t\t\t\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\t\t\t\t\t\tnode.modifiers,\n\t\t\t\t\t\t\t\t\t\t\t\t\tts.factory.updateImportClause(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tclause,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tclause.isTypeOnly,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tclause.name,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tts.factory.updateNamedImports(bindings, elements),\n\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\tnode.moduleSpecifier,\n\t\t\t\t\t\t\t\t\t\t\t\t\tnode.attributes,\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\tsource,\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t: \"\",\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\truntime &&\n\t\t\t\t\t(node.moduleSpecifier.text.startsWith(\"node:\") ||\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"@tsplc/server\",\n\t\t\t\t\t\t\t\"@trpc/server\",\n\t\t\t\t\t\t\t\"zod\",\n\t\t\t\t\t\t\t\"fs\",\n\t\t\t\t\t\t\t\"http\",\n\t\t\t\t\t\t\t\"https\",\n\t\t\t\t\t\t\t\"net\",\n\t\t\t\t\t\t\t\"tls\",\n\t\t\t\t\t\t].includes(node.moduleSpecifier.text))\n\t\t\t\t) {\n\t\t\t\t\tfail(\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\"PLC1013\",\n\t\t\t\t\t\t`Server runtime import ${node.moduleSpecifier.text} cannot execute in PLC code. Expose a PLC procedure on the server router and call it through createServiceClient instead.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ts.isVariableStatement(node)) {\n\t\t\t\tconst clientStatement = node.declarationList.declarations.some(\n\t\t\t\t\t(declaration) => {\n\t\t\t\t\t\tconst declared = symbolAt(checker, declaration.name);\n\t\t\t\t\t\treturn declared && clients.has(declared);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tif (clientStatement) {\n\t\t\t\t\tedits.push({ start: node.getStart(source), end: node.end, text: \"\" });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// The client's binding is removed, so a type of it, as `typeof services`, has nothing to name.\n\t\t\tif (clients.size && ts.isTypeQueryNode(node)) {\n\t\t\t\tconst named = ts.isQualifiedName(node.exprName)\n\t\t\t\t\t? undefined\n\t\t\t\t\t: symbolAt(checker, node.exprName);\n\t\t\t\tif (named && clients.has(named)) {\n\t\t\t\t\tedits.push({\n\t\t\t\t\t\tstart: node.getStart(source),\n\t\t\t\t\t\tend: node.end,\n\t\t\t\t\t\ttext: \"unknown\",\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (clients.size && ts.isPropertyAccessExpression(node)) {\n\t\t\t\tconst parts: string[] = [];\n\t\t\t\tlet root: ts.Expression = node;\n\t\t\t\twhile (ts.isPropertyAccessExpression(root)) {\n\t\t\t\t\tparts.unshift(root.name.text);\n\t\t\t\t\troot = root.expression;\n\t\t\t\t}\n\t\t\t\tconst client = symbolAt(checker, root);\n\t\t\t\tconst router = client && clients.get(client);\n\t\t\t\tconst procedure = router && procedureAt(checker, router, parts);\n\t\t\t\tif (router) {\n\t\t\t\t\tconst path = parts.join(\".\");\n\t\t\t\t\tif (!procedure) {\n\t\t\t\t\t\tfail(\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\"PLC1013\",\n\t\t\t\t\t\t\t`${path} is not a procedure of the client's router.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst call =\n\t\t\t\t\t\tcalls.get(path) ?? serviceCall(checker, path, procedure, record);\n\t\t\t\t\tif (call instanceof WireLayoutError) {\n\t\t\t\t\t\tfail(node, \"PLC2001\", call.message);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcalls.set(path, call);\n\t\t\t\t\tconst name = serviceExportName(path);\n\t\t\t\t\tconst local = imports.get(name) ?? `tsplcRemote${imports.size}`;\n\t\t\t\t\timports.set(name, local);\n\t\t\t\t\tedits.push({\n\t\t\t\t\t\tstart: node.getStart(source),\n\t\t\t\t\t\tend: node.end,\n\t\t\t\t\t\ttext: local,\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tts.forEachChild(node, visit);\n\t\t};\n\t\tvisit(source);\n\t\tif (!edits.length) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst text = edited(source, edits);\n\t\tsources.set(\n\t\t\tsource.fileName,\n\t\t\timports.size && module\n\t\t\t\t? mapped`${text}\\nimport {${[...imports].map(([name, local]) => `${name} as ${local}`).join(\",\")}} from ${importSpecifier(source.fileName, module.file)};\\n`\n\t\t\t\t: text,\n\t\t);\n\t}\n\tif (module && options) {\n\t\tsources.set(\n\t\t\tmodule.file,\n\t\t\tfrom(module.client, serviceModule(records, calls, options)),\n\t\t);\n\t}\n\treturn {\n\t\tsources,\n\t\tdiagnostics,\n\t\tfile: module?.file,\n\t\trecords: new Map([...records].map(([key, { name }]) => [key, name])),\n\t};\n};\n\nconst serviceModule = (\n\trecords: ReadonlyMap<string, { name: string; layout: RecordLayout }>,\n\tcalls: ReadonlyMap<string, ServiceCall>,\n\toptions: ServiceOptions,\n) => {\n\tconst enums = new Map<ts.EnumDeclaration, string>();\n\tconst enumName = (declaration: ts.EnumDeclaration) => {\n\t\tconst name = enums.get(declaration) ?? `tsplcEnum${enums.size}`;\n\t\tenums.set(declaration, name);\n\t\treturn name;\n\t};\n\tconst scalar = (\n\t\tfield: WireScalar,\n\t\tenumeration: ts.EnumDeclaration | undefined,\n\t) => {\n\t\tswitch (field.kind) {\n\t\t\tcase \"boolean\":\n\t\t\t\treturn \"BOOL\";\n\t\t\tcase \"integer\":\n\t\t\t\treturn field.iec;\n\t\t\tcase \"string\":\n\t\t\t\treturn `STRING<${field.capacity}>`;\n\t\t\tcase \"enum\":\n\t\t\t\tif (!enumeration) {\n\t\t\t\t\tthrow new Error(\"An enum wire field has no PLC enum declaration.\");\n\t\t\t\t}\n\t\t\t\treturn enumName(enumeration);\n\t\t}\n\t};\n\tconst interfaces = [...records.values()].map(({ name, layout }) => {\n\t\tconst fields = Object.entries(layout.fields).map(([key, field]) => {\n\t\t\tconst enumeration = layout.enums[key];\n\t\t\tconst type =\n\t\t\t\tfield.kind === \"array\"\n\t\t\t\t\t? `FixedArray<${scalar(field.element, enumeration)},${field.length}>`\n\t\t\t\t\t: scalar(field, enumeration);\n\t\t\treturn `${key}:${type}`;\n\t\t});\n\t\treturn `export interface ${name}{${fields.join(\";\")}}`;\n\t});\n\tconst functions = [...calls.values()]\n\t\t.sort((left, right) =>\n\t\t\tleft.contract.path.localeCompare(right.contract.path),\n\t\t)\n\t\t.map(({ contract, input, output }) => {\n\t\t\tconst hasInput = Object.keys(contract.input.fields).length > 0;\n\t\t\tconst request = hasInput ? \"input\" : `defaultValue<${input}>()`;\n\t\t\tconst operation =\n\t\t\t\toptions.transport === \"http\"\n\t\t\t\t\t? `tsplcServiceFetch<${output}>(\\`\\${tsplcServiceBaseUrl}${servicePath(contract)}\\`,{method:\"POST\",json:${request}})`\n\t\t\t\t\t: `tsplcServiceCall<${output},${input}>(${JSON.stringify(servicePath(contract))},${request})`;\n\t\t\treturn `export const ${serviceExportName(contract.path)}=async(${hasInput ? `input:${input}` : \"\"}):Promise<${output}>=>{return await ${operation};};`;\n\t\t});\n\tconst transport =\n\t\toptions.transport === \"http\"\n\t\t\t? `import {fetch as tsplcServiceFetch} from \"${sdkModules.async}\";\\nimport {env as tsplcServiceEnv} from \"${sdkModules.config}\";`\n\t\t\t: `import {opcuaCall as tsplcServiceCall} from \"${sdkModules.async}\";`;\n\tconst enumImports = [...enums].map(\n\t\t([declaration, name]) =>\n\t\t\t`import type {${declaration.name.text} as ${name}} from ${JSON.stringify(declaration.getSourceFile().fileName)};`,\n\t);\n\tconst baseUrl =\n\t\toptions.transport === \"http\"\n\t\t\t? `const tsplcServiceBaseUrl:STRING<${baseUrlCapacity}>=tsplcServiceEnv<STRING<${baseUrlCapacity}>>(${JSON.stringify(options.baseUrlEnv)});`\n\t\t\t: \"\";\n\treturn `${[\n\t\ttransport,\n\t\t...enumImports,\n\t\tbaseUrl,\n\t\t...interfaces,\n\t\t...functions,\n\t].join(\"\\n\")}\\n`;\n};\n\n/** Lowers a type that names a called procedure's record, such as `inferRouterOutputs<AppRouter>[\"a\"][\"b\"]`. */\nexport const serviceRecords = (\n\tprogram: ts.Program,\n\tlowering: { file: string | undefined; records: ReadonlyMap<string, string> },\n): ServiceRecord | null => {\n\tconst source = lowering.file && program.getSourceFile(lowering.file);\n\tif (!source) {\n\t\treturn null;\n\t}\n\tconst checker = program.getTypeChecker();\n\tconst declarations = new Map(\n\t\tsource.statements\n\t\t\t.filter(ts.isInterfaceDeclaration)\n\t\t\t.map((value) => [value.name.text, value]),\n\t);\n\treturn (type) => {\n\t\tconst layout = wireLayoutOf(() =>\n\t\t\trecordLayout(checker, type, \"record\", false),\n\t\t);\n\t\tif (layout instanceof WireLayoutError) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst name = lowering.records.get(recordKey(layout));\n\t\tconst declaration = name === undefined ? undefined : declarations.get(name);\n\t\treturn declaration && checker.getSymbolAtLocation(declaration.name);\n\t};\n};\n"
57
+ ],
58
+ "mappings": ";AAAA,qCAAoB;AACpB,0BAAS;AACT,oBAAS,kBAAS,mBAAM,sBAAU;AAClC;AAEA,+BAAS;AACT;;;ACNA,oBAAS;AACT;AAAA,eACC;AAAA,WAEA;AAAA;AAMD;;;ACVA;AAAA;AAAA,oBAG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