@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,240 @@
1
+ import {
2
+ type CoreFunction,
3
+ type CoreFunctionBlock,
4
+ coreTables,
5
+ type GeneratedObject,
6
+ instanceFields,
7
+ isBlockRoutine,
8
+ standardBlocks,
9
+ } from "@tsplc/compiler/ir";
10
+ import { planGlobalNames } from "./global-names";
11
+ import type { BlockInstrumentation, Instrumentation } from "./instrumentation";
12
+ import { Names } from "./names";
13
+ import { NumericLowering } from "./numeric";
14
+ import type { CodesysPlan } from "./plan";
15
+ import { required } from "./required";
16
+ import { planScanClock } from "./scan-clock";
17
+ import { accessedStorage } from "./task-access";
18
+
19
+ /** The names a routine's ST gives its parameters, locals and the block state it reaches. */
20
+ export interface RoutineScope {
21
+ names: Names;
22
+ references: ReadonlyMap<string, string>;
23
+ }
24
+
25
+ /** The names fixed before emission: objects of types, blocks, storage lists and routines that hold state. */
26
+ export type GlobalSymbols = ReturnType<typeof globalSymbols>;
27
+
28
+ /**
29
+ * The target names of a program: its objects, storage, routines and block fields. `emitCodesys`
30
+ * allocates them in emission order, each scope reserving the objects emitted before it, and they
31
+ * are complete before any routine body is written.
32
+ */
33
+ export type CodesysSymbols = GlobalSymbols & {
34
+ /** The global symbol of each module variable and logical IO. */
35
+ references: ReadonlyMap<string, string>;
36
+ functionNames: ReadonlyMap<string, string>;
37
+ programResults: ReadonlyMap<string, string>;
38
+ mailboxLocks: ReadonlyMap<string, string>;
39
+ blockFields: ReadonlyMap<string, ReadonlyMap<string, string>>;
40
+ routineScopes: ReadonlyMap<string, RoutineScope>;
41
+ };
42
+
43
+ /** A plan with the target names and instrumentation allocated for it: what each emitter reads. */
44
+ export interface EmissionContext {
45
+ plan: CodesysPlan;
46
+ symbols: CodesysSymbols;
47
+ instrumentation: Instrumentation;
48
+ }
49
+
50
+ export function globalSymbols(plan: CodesysPlan) {
51
+ const { core } = plan;
52
+ const persistent = new Set(
53
+ core.variables
54
+ .filter((item) => item.storage !== "constant")
55
+ .map((item) => item.id),
56
+ );
57
+ const programRoutines: ReadonlySet<string> = new Set(
58
+ core.functions
59
+ .filter(
60
+ (fn) =>
61
+ !fn.owner &&
62
+ [...accessedStorage(fn, core)].some((id) => persistent.has(id)),
63
+ )
64
+ .map((fn) => fn.id),
65
+ );
66
+ const globalNames = planGlobalNames(core, plan.programNames);
67
+ const scanClock = planScanClock(
68
+ core,
69
+ plan.deployment.tasks,
70
+ globalNames.names,
71
+ );
72
+ return {
73
+ ...globalNames,
74
+ blocks: coreTables(core).blocks,
75
+ scanClock,
76
+ numeric: new NumericLowering(
77
+ globalNames.typeMap,
78
+ (label) => globalNames.names.allocate(label),
79
+ scanClock?.now,
80
+ ),
81
+ programRoutines,
82
+ };
83
+ }
84
+
85
+ /** The object name of each function that is not a method. */
86
+ export function allocateFunctionNames(
87
+ { core }: CodesysPlan,
88
+ symbols: GlobalSymbols,
89
+ ): Map<string, string> {
90
+ const entries = new Set(core.programs.map((program) => program.entry));
91
+ return new Map(
92
+ core.functions
93
+ .filter((fn) => !fn.owner)
94
+ .map((fn) => {
95
+ const program = symbols.programRoutines.has(fn.id);
96
+ const label =
97
+ program && entries.has(fn.id) ? `${fn.name}_body` : fn.name;
98
+ return [
99
+ fn.id,
100
+ symbols.names.allocateObject(program ? "PRG" : "F", label),
101
+ ];
102
+ }),
103
+ );
104
+ }
105
+
106
+ /**
107
+ * The names a routine's or block's own scope must not shadow: the objects emitted so far, the
108
+ * debug global, and every routine and block named so far.
109
+ */
110
+ const scopeNames = (
111
+ symbols: Pick<CodesysSymbols, "functionNames" | "blockNames">,
112
+ objects: readonly GeneratedObject[],
113
+ global: string,
114
+ ): Names =>
115
+ new Names([
116
+ ...objects.map((object) => object.name),
117
+ global,
118
+ ...symbols.functionNames.values(),
119
+ ...symbols.blockNames.values(),
120
+ ]);
121
+
122
+ /**
123
+ * Each block's field names, its methods' names and its mailbox lock, and the instrumentation fields
124
+ * of the blocks that have any. A block's scope reserves the names of the functions that are not
125
+ * methods.
126
+ */
127
+ export function allocateBlockMembers(
128
+ plan: CodesysPlan,
129
+ symbols: GlobalSymbols & Pick<CodesysSymbols, "functionNames">,
130
+ instrumentation: Pick<Instrumentation, "global" | "analysis">,
131
+ objects: readonly GeneratedObject[],
132
+ ) {
133
+ const { core } = plan;
134
+ const fields = new Map<string, ReadonlyMap<string, string>>();
135
+ const methods = new Map<string, string>();
136
+ const mailboxLocks = new Map<string, string>();
137
+ const instrumented = new Map<string, BlockInstrumentation>();
138
+ for (const block of core.blocks) {
139
+ const names = scopeNames(symbols, objects, instrumentation.global);
140
+ for (const method of core.functions.filter(
141
+ (fn) => fn.owner?.block === block.id,
142
+ )) {
143
+ methods.set(method.id, names.allocate(method.name));
144
+ }
145
+ const native = block.standard && standardBlocks[block.standard];
146
+ fields.set(
147
+ block.id,
148
+ new Map(
149
+ instanceFields(block).map((item) => [
150
+ item.id,
151
+ native
152
+ ? required(
153
+ [...native.inputs, ...native.outputs].find(
154
+ ([name]) => name === item.name,
155
+ ),
156
+ )[1]
157
+ : names.allocate(item.name),
158
+ ]),
159
+ ),
160
+ );
161
+ if (block.runtime?.kind === "mailbox") {
162
+ mailboxLocks.set(block.id, names.allocate("plc_mailbox_lock"));
163
+ }
164
+
165
+ const settings = plan.project.debug;
166
+ // Trace sites and an unhandled failure need the step a job finished at.
167
+ const stepped =
168
+ instrumentation.analysis.jobSites.has(block.id) ||
169
+ plan.telemetry?.failures.has(block.id);
170
+ const tracked = Boolean(block.job && (settings?.jobs || stepped));
171
+ const carries =
172
+ settings?.jobs && instrumentation.analysis.carriers.has(block.id);
173
+ if (tracked || carries) {
174
+ instrumented.set(block.id, {
175
+ ...(tracked && {
176
+ busy: names.allocate("tsplcBusy"),
177
+ track: names.allocate("TsplcTrack"),
178
+ }),
179
+ ...(tracked &&
180
+ settings?.jobs && { startedAt: names.allocate("startedAt") }),
181
+ ...(stepped && { step: names.allocate("tsplcStep") }),
182
+ ...(carries && { job: names.allocate("requestJob") }),
183
+ ...(carries &&
184
+ block.runtime?.kind === "http" && {
185
+ sequence: names.allocate("sequence"),
186
+ }),
187
+ });
188
+ }
189
+ }
190
+ return { fields, methods, mailboxLocks, instrumented };
191
+ }
192
+
193
+ /** The names a routine's ST gives its parameters, locals and block state, and a stateful program's result. */
194
+ export function allocateRoutineScope(
195
+ symbols: GlobalSymbols &
196
+ Pick<CodesysSymbols, "functionNames" | "blockFields">,
197
+ objects: readonly GeneratedObject[],
198
+ global: string,
199
+ fn: CoreFunction | CoreFunctionBlock,
200
+ ): { scope: RoutineScope; result?: string } {
201
+ const block = isBlockRoutine(fn) ? fn : undefined;
202
+ const owner = owningBlock(symbols, fn);
203
+ const names = scopeNames(symbols, objects, global);
204
+ const references = new Map<string, string>();
205
+ const result =
206
+ !block && symbols.programRoutines.has(fn.id) && fn.result
207
+ ? names.allocate("plc_result")
208
+ : undefined;
209
+ if (owner) {
210
+ for (const item of [...owner.outputs, ...owner.state]) {
211
+ const name = required(
212
+ required(symbols.blockFields.get(owner.id)).get(item.id),
213
+ );
214
+ names.reserve(name);
215
+ references.set(item.id, name);
216
+ }
217
+ }
218
+ for (const item of isBlockRoutine(fn) ? fn.inputs : fn.parameters) {
219
+ const name = block
220
+ ? required(required(symbols.blockFields.get(block.id)).get(item.id))
221
+ : names.allocate(item.name);
222
+ names.reserve(name);
223
+ references.set(item.id, name);
224
+ }
225
+ for (const item of fn.locals) {
226
+ references.set(item.id, names.allocate(item.name));
227
+ }
228
+ return { scope: { names, references }, ...(result && { result }) };
229
+ }
230
+
231
+ /** The block whose state a routine reaches: the block itself, or a method's block. */
232
+ export const owningBlock = (
233
+ symbols: GlobalSymbols,
234
+ fn: CoreFunction | CoreFunctionBlock,
235
+ ): CoreFunctionBlock | undefined => {
236
+ if (isBlockRoutine(fn)) {
237
+ return fn;
238
+ }
239
+ return fn.owner && required(symbols.blocks.get(fn.owner.block));
240
+ };
@@ -0,0 +1,186 @@
1
+ import type {
2
+ CoreExpression,
3
+ CoreFunction,
4
+ CoreFunctionBlock,
5
+ CoreStatement,
6
+ Deployment,
7
+ PlcProgram,
8
+ VerifiedCoreModule,
9
+ } from "@tsplc/compiler/ir";
10
+ import {
11
+ coreTables,
12
+ nestedBodies,
13
+ statementExpressions,
14
+ subexpressions,
15
+ } from "@tsplc/compiler/ir";
16
+ import type { Report } from "./plan";
17
+
18
+ /** The task that runs each function and block; undefined for one more than one task runs. */
19
+ export function routineTasks(
20
+ core: VerifiedCoreModule,
21
+ deployment: Deployment,
22
+ ): Map<string, string | undefined> {
23
+ const tasks = new Map<string, string | undefined>();
24
+ const { functionOf, calledRoutineOf } = coreTables(core);
25
+ const programs = new Map(core.programs.map((item) => [item.name, item]));
26
+ for (const task of deployment.tasks) {
27
+ for (const name of task.programs) {
28
+ // `validateTasks` reports a program the module lacks.
29
+ const program = programs.get(name);
30
+ if (!program) {
31
+ continue;
32
+ }
33
+ const seen = new Set<string>();
34
+ const visit = (routine: CoreFunction | CoreFunctionBlock): void => {
35
+ if (seen.has(routine.id)) {
36
+ return;
37
+ }
38
+ seen.add(routine.id);
39
+ tasks.set(
40
+ routine.id,
41
+ tasks.has(routine.id) && tasks.get(routine.id) !== task.name
42
+ ? undefined
43
+ : task.name,
44
+ );
45
+ const inspect = (items: readonly CoreStatement[]): void => {
46
+ for (const item of items) {
47
+ const called = calledRoutineOf(item);
48
+ if (called) {
49
+ visit(called);
50
+ }
51
+ for (const body of nestedBodies(item)) {
52
+ inspect(body);
53
+ }
54
+ }
55
+ };
56
+ inspect(routine.body);
57
+ };
58
+ visit(functionOf(program.entry));
59
+ }
60
+ }
61
+ return tasks;
62
+ }
63
+
64
+ /** The generated worker may enter its host, and only mailbox roots are shared between tasks. */
65
+ export function taskStorageOwnership(
66
+ core: VerifiedCoreModule,
67
+ report: Report,
68
+ ): (task: string, program: PlcProgram) => void {
69
+ const owners = new Map<string, string>();
70
+ const globals = new Map(core.variables.map((item) => [item.id, item]));
71
+ const { types, functionOf, blockOf } = coreTables(core);
72
+ const runtimeOf = (type: string) => {
73
+ const block = types.get(type);
74
+ return block?.kind === "block"
75
+ ? blockOf(block.block).runtime?.kind
76
+ : undefined;
77
+ };
78
+
79
+ return (task, program) => {
80
+ const fn = functionOf(program.entry);
81
+ const worker = program.background?.worker;
82
+ const host = worker
83
+ ? core.variables.find(
84
+ (item) =>
85
+ item.name === worker &&
86
+ item.span.file === fn.span.file &&
87
+ runtimeOf(item.type) === "backgroundHost",
88
+ )
89
+ : undefined;
90
+ for (const id of storageAccess(fn, core, host?.id ?? null)) {
91
+ const item = globals.get(id);
92
+ if (
93
+ !item ||
94
+ item.storage === "constant" ||
95
+ runtimeOf(item.type) === "mailbox"
96
+ ) {
97
+ continue;
98
+ }
99
+ const ownsWorker =
100
+ worker === item.name && item.span.file === fn.span.file;
101
+ if (program.background && (!ownsWorker || item.id === host?.id)) {
102
+ report(
103
+ `Background task ${program.name} accesses scan-owned storage ${item.name}; pass value snapshots through the mailbox.`,
104
+ item.span,
105
+ );
106
+ }
107
+ const owner = owners.get(id);
108
+ if (owner && owner !== task) {
109
+ report(
110
+ `Storage ${item.name} is shared across cyclic tasks ${owner} and ${task}.`,
111
+ item.span,
112
+ );
113
+ }
114
+ owners.set(id, task);
115
+ }
116
+ };
117
+ }
118
+
119
+ // Follow both helper calls and instance updates. Borrow addresses count as storage
120
+ // access, so scheduling cannot accidentally give one mutable record two owners.
121
+ export const accessedStorage = (
122
+ fn: CoreFunction,
123
+ core: VerifiedCoreModule,
124
+ ): Set<string> => storageAccess(fn, core, null);
125
+
126
+ /**
127
+ * The storage a function reaches, where `scheduledHost` is the background host whose worker call
128
+ * the generated entry makes: only that call may borrow its host. Ordinary calls reached through
129
+ * the async body still count as access to scan-owned storage.
130
+ */
131
+ function storageAccess(
132
+ fn: CoreFunction,
133
+ core: VerifiedCoreModule,
134
+ scheduledHost: string | null,
135
+ ): Set<string> {
136
+ const scheduledCall =
137
+ scheduledHost === null
138
+ ? undefined
139
+ : fn.body.find(
140
+ (item) => item.kind === "invoke" && item.instance === scheduledHost,
141
+ );
142
+ const result = new Set<string>();
143
+ const seen = new Set<string>();
144
+ const { calledRoutineOf } = coreTables(core);
145
+
146
+ const expression = (value: CoreExpression): void => {
147
+ if (value.kind === "load") {
148
+ result.add(value.root);
149
+ }
150
+ if (value.kind === "borrow") {
151
+ result.add(value.place.root);
152
+ }
153
+ subexpressions(value).forEach(expression);
154
+ };
155
+
156
+ const body = (items: readonly CoreStatement[]): void => {
157
+ for (const item of items) {
158
+ if (item.kind === "assign") {
159
+ result.add(item.root);
160
+ }
161
+ if (item.kind === "invoke" && item.instance && item !== scheduledCall) {
162
+ result.add(item.instance);
163
+ }
164
+ if (item.kind === "blockUpdate") {
165
+ result.add(item.instance);
166
+ }
167
+ statementExpressions(item).forEach(expression);
168
+ if (item.kind === "for") {
169
+ result.add(item.counter);
170
+ }
171
+ if (item.kind === "invoke" && item.destination) {
172
+ result.add(item.destination);
173
+ }
174
+ const called = calledRoutineOf(item);
175
+ if (called && !seen.has(called.id)) {
176
+ seen.add(called.id);
177
+ body(called.body);
178
+ }
179
+ nestedBodies(item).forEach(body);
180
+ }
181
+ };
182
+
183
+ seen.add(fn.id);
184
+ body(fn.body);
185
+ return result;
186
+ }
@@ -0,0 +1,19 @@
1
+ import { type ResolvedTelemetryConfig, telemetrySchema } from "@tsplc/config";
2
+
3
+ /** How long a sender waits for a full batch before it sends what it has, and before it retries. */
4
+ export const telemetrySendIntervalMs = 200;
5
+
6
+ /**
7
+ * The configured telemetry settings or their defaults, with rings that also hold `debug.trace`'s
8
+ * records: each task has one ring for both.
9
+ */
10
+ export const ringSettings = (
11
+ telemetry: ResolvedTelemetryConfig | undefined,
12
+ trace: { capacity: number } | false | undefined,
13
+ ): ResolvedTelemetryConfig => {
14
+ const settings = telemetry ?? telemetrySchema.parse({});
15
+ return {
16
+ ...settings,
17
+ capacity: Math.max(settings.capacity, trace ? trace.capacity : 0),
18
+ };
19
+ };