@tsplc/compiler 0.5.13 → 0.5.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -8
- package/dist/cli.js +794 -621
- package/dist/cli.js.map +19 -16
- package/dist/clock.js +5 -2
- package/dist/clock.js.map +5 -4
- package/dist/codesys.js +4162 -4157
- package/dist/codesys.js.map +43 -29
- package/dist/index.js +7852 -6549
- package/dist/index.js.map +53 -50
- package/dist/ir.js +2482 -2277
- package/dist/ir.js.map +28 -25
- package/dist/retain.js +3 -1
- package/dist/retain.js.map +3 -3
- package/dist/signals.js +115 -0
- package/dist/signals.js.map +10 -0
- package/dist/telemetry.js +25 -20
- package/dist/telemetry.js.map +6 -6
- package/package.json +19 -39
- package/src/codesys/config.ts +3 -3
- package/src/codesys/debug.ts +92 -108
- package/src/codesys/emit.ts +100 -88
- package/src/codesys/endpoints.ts +111 -0
- package/src/codesys/engineering.ts +30 -54
- package/src/codesys/explain/expressions.ts +445 -0
- package/src/codesys/explain/flags.ts +134 -0
- package/src/codesys/explain/parameters.ts +53 -0
- package/src/codesys/explain/rows.ts +182 -0
- package/src/codesys/explain/tables.ts +79 -0
- package/src/codesys/explain/tasks.ts +68 -0
- package/src/codesys/explain/writes.ts +497 -0
- package/src/codesys/explain.ts +85 -1401
- package/src/codesys/expressions.ts +41 -33
- package/src/codesys/global-lists.ts +114 -94
- package/src/codesys/global-names.ts +12 -14
- package/src/codesys/http.ts +428 -388
- package/src/codesys/instrumentation.ts +142 -148
- package/src/codesys/io-paths.ts +31 -23
- package/src/codesys/loops.ts +101 -0
- package/src/codesys/manifest.ts +269 -269
- package/src/codesys/names.ts +10 -33
- package/src/codesys/numeric.ts +89 -42
- package/src/codesys/plan.ts +202 -190
- package/src/codesys/programs.ts +23 -16
- package/src/codesys/publication.ts +13 -86
- package/src/codesys/required.ts +8 -0
- package/src/codesys/routines.ts +103 -489
- package/src/codesys/scheduling.ts +96 -0
- package/src/codesys/service-channels.ts +23 -0
- package/src/codesys/sources.ts +34 -28
- package/src/codesys/st-files.ts +112 -105
- package/src/codesys/statements.ts +409 -0
- package/src/codesys/storage.ts +41 -23
- package/src/codesys/symbols.ts +130 -119
- package/src/codesys/task-access.ts +65 -221
- package/src/codesys/telemetry-settings.ts +19 -0
- package/src/codesys/telemetry.ts +185 -148
- package/src/codesys/types.ts +69 -109
- package/src/codesys/vendor.ts +13 -50
- package/src/frontend/analyzer.ts +66 -111
- package/src/frontend/async.ts +316 -128
- package/src/frontend/blocks.ts +178 -154
- package/src/frontend/configuration.ts +49 -153
- package/src/frontend/const-functions.ts +50 -40
- package/src/frontend/control-flow.ts +164 -129
- package/src/frontend/cooperative.ts +17 -9
- package/src/frontend/coroutines.ts +539 -441
- package/src/frontend/dialect-names.ts +104 -0
- package/src/frontend/elaborate/array-searches.ts +77 -69
- package/src/frontend/elaborate/assignments.ts +68 -77
- package/src/frontend/elaborate/calls.ts +878 -512
- package/src/frontend/elaborate/capture-protocol.ts +118 -21
- package/src/frontend/elaborate/capture.ts +196 -109
- package/src/frontend/elaborate/declarations.ts +124 -0
- package/src/frontend/elaborate/dialect.ts +119 -46
- package/src/frontend/elaborate/expressions.ts +763 -442
- package/src/frontend/elaborate/filtered-arrays.ts +127 -91
- package/src/frontend/elaborate/frame.ts +50 -2
- package/src/frontend/elaborate/generics.ts +20 -34
- package/src/frontend/elaborate/graph.ts +13 -87
- package/src/frontend/elaborate/imports.ts +0 -5
- package/src/frontend/elaborate/index.ts +416 -169
- package/src/frontend/elaborate/initializers.ts +64 -42
- package/src/frontend/elaborate/iterators.ts +228 -364
- package/src/frontend/elaborate/layouts.ts +477 -116
- package/src/frontend/elaborate/model.ts +113 -55
- package/src/frontend/elaborate/references.ts +116 -138
- package/src/frontend/elaborate/retention.ts +137 -59
- package/src/frontend/elaborate/specialize.ts +617 -308
- package/src/frontend/elaborate/statements.ts +436 -247
- package/src/frontend/elaborate/storage.ts +280 -213
- package/src/frontend/elaborate/time-constructors.ts +34 -0
- package/src/frontend/elaborate/values.ts +77 -7
- package/src/frontend/elaborate/writes.ts +98 -84
- package/src/frontend/expressions.ts +149 -151
- package/src/frontend/generated-names.ts +3 -3
- package/src/frontend/intrinsics.ts +31 -17
- package/src/frontend/lowering-key.ts +23 -0
- package/src/frontend/module-graph.ts +105 -43
- package/src/frontend/positions.ts +43 -35
- package/src/frontend/promise-chains.ts +226 -266
- package/src/frontend/promises.ts +88 -67
- package/src/frontend/routines.ts +122 -65
- package/src/frontend/sdk.ts +104 -5
- package/src/frontend/services.ts +149 -102
- package/src/frontend/statements.ts +60 -64
- package/src/frontend/tasks.ts +151 -96
- package/src/frontend/telemetry.ts +1 -1
- package/src/frontend/types.ts +366 -181
- package/src/frontend/typescript.ts +239 -112
- package/src/index.ts +2 -1
- package/src/ir/aggregates.ts +90 -75
- package/src/ir/allocation.ts +29 -18
- package/src/ir/conditions.ts +38 -78
- package/src/ir/core-model.ts +128 -11
- package/src/ir/declarations.ts +18 -32
- package/src/ir/diagnostics.ts +25 -18
- package/src/ir/domains.ts +26 -23
- package/src/ir/fold.ts +55 -50
- package/src/ir/identity.ts +10 -0
- package/src/ir/index.ts +31 -7
- package/src/ir/job-errors.ts +30 -8
- package/src/ir/layouts.ts +63 -34
- package/src/ir/link.ts +11 -46
- package/src/ir/model.ts +25 -6
- package/src/ir/normalize.ts +3 -28
- package/src/ir/numeric.ts +45 -18
- package/src/ir/operands.ts +102 -0
- package/src/ir/ranges.ts +242 -67
- package/src/ir/routine.ts +126 -183
- package/src/ir/scalars.ts +29 -25
- package/src/ir/share.ts +323 -343
- package/src/ir/short-circuit.ts +140 -0
- package/src/ir/tables.ts +111 -0
- package/src/ir/temporaries.ts +15 -113
- package/src/ir/types.ts +32 -8
- package/src/project/artifacts.ts +143 -71
- package/src/project/cli.ts +104 -87
- package/src/project/debugger.ts +48 -34
- package/src/project/deployments.ts +12 -68
- package/src/project/flags.ts +14 -0
- package/src/project/plant.ts +293 -225
- package/src/project/project-commands.ts +254 -192
- package/src/project/project.ts +184 -141
- package/src/project/release.ts +22 -28
- package/src/project/server.ts +22 -26
- package/src/project/terminal.ts +13 -2
- package/src/runtime/async.ts +17 -13
- package/src/runtime/launch.ts +5 -2
- package/src/runtime/main.ts +8 -3
- package/src/runtime/missing-file.ts +3 -0
- package/src/runtime/process.ts +24 -19
- package/src/runtime/program.ts +20 -53
- package/src/runtime/retain.ts +18 -10
- package/src/runtime/runtime.ts +47 -60
- package/src/runtime/settings.ts +27 -0
- package/src/runtime/storage.ts +49 -74
- package/src/runtime/symbols.ts +19 -75
- package/src/runtime/telemetry.ts +37 -14
- package/src/runtime/transport.ts +26 -30
- package/stdlib/clock.ts +4 -2
- package/stdlib/plc-time.ts +2 -0
- package/stdlib/retain.ts +2 -0
- package/stdlib/signals.ts +142 -0
- package/stdlib/telemetry.ts +5 -12
- package/types/dialect.d.ts +49 -0
- package/types/globals.d.ts +2 -42
- package/types/index.d.ts +3 -1
- package/types/retain.d.ts +8 -2
- package/types/telemetry.d.ts +3 -0
- package/dist/bun-runtime.js +0 -1472
- package/dist/bun-runtime.js.map +0 -26
- package/dist/elaborate-capture.js +0 -304
- package/dist/elaborate-capture.js.map +0 -11
- package/dist/math.js +0 -24
- package/dist/math.js.map +0 -10
- package/dist/project.js +0 -626
- package/dist/project.js.map +0 -12
- package/dist/server-check.js +0 -59
- package/dist/server-check.js.map +0 -11
- package/src/frontend/exposure.ts +0 -181
- package/src/project/index.ts +0 -6
- package/src/runtime/.runtime-65O4JH/server/router.ts +0 -17
- package/src/runtime/.runtime-65O4JH/src/cell.ts +0 -45
- package/src/runtime/.runtime-65O4JH/src/controller.ts +0 -58
- package/src/runtime/.runtime-65O4JH/src/lane.ts +0 -6
- package/src/runtime/.runtime-65O4JH/src/main.ts +0 -11
- package/src/runtime/.runtime-65O4JH/src/services.ts +0 -8
- package/src/runtime/.runtime-65O4JH/tsconfig.json +0 -13
- package/src/runtime/.runtime-65O4JH/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-Brw2kO/server/router.ts +0 -17
- package/src/runtime/.runtime-Brw2kO/src/cell.ts +0 -45
- package/src/runtime/.runtime-Brw2kO/src/controller.ts +0 -58
- package/src/runtime/.runtime-Brw2kO/src/lane.ts +0 -6
- package/src/runtime/.runtime-Brw2kO/src/main.ts +0 -11
- package/src/runtime/.runtime-Brw2kO/src/services.ts +0 -8
- package/src/runtime/.runtime-Brw2kO/tsconfig.json +0 -13
- package/src/runtime/.runtime-Brw2kO/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-NHfu1D/server/router.ts +0 -17
- package/src/runtime/.runtime-NHfu1D/src/cell.ts +0 -45
- package/src/runtime/.runtime-NHfu1D/src/controller.ts +0 -58
- package/src/runtime/.runtime-NHfu1D/src/lane.ts +0 -6
- package/src/runtime/.runtime-NHfu1D/src/main.ts +0 -11
- package/src/runtime/.runtime-NHfu1D/src/services.ts +0 -8
- package/src/runtime/.runtime-NHfu1D/tsconfig.json +0 -13
- package/src/runtime/.runtime-NHfu1D/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-VaUSOu/server/router.ts +0 -17
- package/src/runtime/.runtime-VaUSOu/src/cell.ts +0 -45
- package/src/runtime/.runtime-VaUSOu/src/controller.ts +0 -58
- package/src/runtime/.runtime-VaUSOu/src/lane.ts +0 -6
- package/src/runtime/.runtime-VaUSOu/src/main.ts +0 -11
- package/src/runtime/.runtime-VaUSOu/src/services.ts +0 -8
- package/src/runtime/.runtime-VaUSOu/tsconfig.json +0 -13
- package/src/runtime/.runtime-VaUSOu/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-WbtNvR/server/router.ts +0 -17
- package/src/runtime/.runtime-WbtNvR/src/cell.ts +0 -45
- package/src/runtime/.runtime-WbtNvR/src/controller.ts +0 -58
- package/src/runtime/.runtime-WbtNvR/src/lane.ts +0 -6
- package/src/runtime/.runtime-WbtNvR/src/main.ts +0 -11
- package/src/runtime/.runtime-WbtNvR/src/services.ts +0 -8
- package/src/runtime/.runtime-WbtNvR/tsconfig.json +0 -13
- package/src/runtime/.runtime-WbtNvR/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-GMPUt8/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-GMPUt8/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-GMPUt8/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-GMPUt8/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-GMPUt8/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-GMPUt8/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-GMPUt8/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-GMPUt8/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-UwafxO/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-UwafxO/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-UwafxO/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-UwafxO/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-UwafxO/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-UwafxO/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-UwafxO/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-UwafxO/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-ecaSee/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-ecaSee/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-ecaSee/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-ecaSee/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-ecaSee/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-ecaSee/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-ecaSee/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-ecaSee/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-y91UCm/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-y91UCm/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-y91UCm/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-y91UCm/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-y91UCm/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-y91UCm/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-y91UCm/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-y91UCm/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-ybIxYh/server/router.ts +0 -17
- package/src/runtime/.runtime-ybIxYh/src/cell.ts +0 -45
- package/src/runtime/.runtime-ybIxYh/src/controller.ts +0 -58
- package/src/runtime/.runtime-ybIxYh/src/lane.ts +0 -6
- package/src/runtime/.runtime-ybIxYh/src/main.ts +0 -11
- package/src/runtime/.runtime-ybIxYh/src/services.ts +0 -8
- package/src/runtime/.runtime-ybIxYh/tsconfig.json +0 -13
- package/src/runtime/.runtime-ybIxYh/tsplc.config.ts +0 -31
- package/stdlib/math.ts +0 -23
- package/types/plc.d.ts +0 -4
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
2
1
|
import type {
|
|
3
2
|
CoreExpression,
|
|
4
3
|
CoreFunction,
|
|
@@ -6,37 +5,15 @@ import type {
|
|
|
6
5
|
CoreStatement,
|
|
7
6
|
Deployment,
|
|
8
7
|
PlcProgram,
|
|
9
|
-
SourceSpan,
|
|
10
|
-
Task,
|
|
11
|
-
Variable,
|
|
12
8
|
VerifiedCoreModule,
|
|
13
9
|
} from "@tsplc/compiler/ir";
|
|
14
10
|
import {
|
|
15
|
-
|
|
16
|
-
nanosecondsPerMillisecond,
|
|
11
|
+
coreTables,
|
|
17
12
|
nestedBodies,
|
|
18
13
|
statementExpressions,
|
|
19
14
|
subexpressions,
|
|
20
15
|
} from "@tsplc/compiler/ir";
|
|
21
|
-
|
|
22
|
-
type Report = (message: string, span?: SourceSpan) => void;
|
|
23
|
-
|
|
24
|
-
/** Every variable of a module by id: its storage, and each routine's parameters, locals and members. */
|
|
25
|
-
export const variablesById = (
|
|
26
|
-
core: VerifiedCoreModule,
|
|
27
|
-
): Map<string, Variable> =>
|
|
28
|
-
new Map(
|
|
29
|
-
[
|
|
30
|
-
...core.variables,
|
|
31
|
-
...core.functions.flatMap((fn) => [...fn.parameters, ...fn.locals]),
|
|
32
|
-
...core.blocks.flatMap((block) => [
|
|
33
|
-
...block.inputs,
|
|
34
|
-
...block.outputs,
|
|
35
|
-
...block.state,
|
|
36
|
-
...block.locals,
|
|
37
|
-
]),
|
|
38
|
-
].map((variable) => [variable.id, variable]),
|
|
39
|
-
);
|
|
16
|
+
import type { Report } from "./plan";
|
|
40
17
|
|
|
41
18
|
/** The task that runs each function and block; undefined for one more than one task runs. */
|
|
42
19
|
export function routineTasks(
|
|
@@ -44,80 +21,46 @@ export function routineTasks(
|
|
|
44
21
|
deployment: Deployment,
|
|
45
22
|
): Map<string, string | undefined> {
|
|
46
23
|
const tasks = new Map<string, string | undefined>();
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
[...core.functions, ...core.blocks].map((routine) => [routine.id, routine]),
|
|
50
|
-
);
|
|
51
|
-
const variables = variablesById(core);
|
|
52
|
-
const programs = new Map(
|
|
53
|
-
core.programs.map((program) => [program.name, program]),
|
|
54
|
-
);
|
|
24
|
+
const { functionOf, calledRoutineOf } = coreTables(core);
|
|
25
|
+
const programs = new Map(core.programs.map((item) => [item.name, item]));
|
|
55
26
|
for (const task of deployment.tasks) {
|
|
56
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
|
+
}
|
|
57
33
|
const seen = new Set<string>();
|
|
58
|
-
const visit = (
|
|
59
|
-
if (seen.has(id)) {
|
|
34
|
+
const visit = (routine: CoreFunction | CoreFunctionBlock): void => {
|
|
35
|
+
if (seen.has(routine.id)) {
|
|
60
36
|
return;
|
|
61
37
|
}
|
|
62
|
-
seen.add(id);
|
|
38
|
+
seen.add(routine.id);
|
|
63
39
|
tasks.set(
|
|
64
|
-
id,
|
|
65
|
-
tasks.has(id) && tasks.get(id) !== task.name
|
|
40
|
+
routine.id,
|
|
41
|
+
tasks.has(routine.id) && tasks.get(routine.id) !== task.name
|
|
42
|
+
? undefined
|
|
43
|
+
: task.name,
|
|
66
44
|
);
|
|
67
45
|
const inspect = (items: readonly CoreStatement[]): void => {
|
|
68
46
|
for (const item of items) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (item.kind === "blockUpdate") {
|
|
73
|
-
const block = instancedBlock(
|
|
74
|
-
variables.get(item.instance)!.type,
|
|
75
|
-
types,
|
|
76
|
-
);
|
|
77
|
-
if (block) {
|
|
78
|
-
visit(block.block);
|
|
79
|
-
}
|
|
47
|
+
const called = calledRoutineOf(item);
|
|
48
|
+
if (called) {
|
|
49
|
+
visit(called);
|
|
80
50
|
}
|
|
81
51
|
for (const body of nestedBodies(item)) {
|
|
82
52
|
inspect(body);
|
|
83
53
|
}
|
|
84
54
|
}
|
|
85
55
|
};
|
|
86
|
-
inspect(
|
|
56
|
+
inspect(routine.body);
|
|
87
57
|
};
|
|
88
|
-
visit(
|
|
58
|
+
visit(functionOf(program.entry));
|
|
89
59
|
}
|
|
90
60
|
}
|
|
91
61
|
return tasks;
|
|
92
62
|
}
|
|
93
63
|
|
|
94
|
-
export function schedulePrograms(
|
|
95
|
-
core: VerifiedCoreModule,
|
|
96
|
-
tasks: readonly Task[],
|
|
97
|
-
report: Report,
|
|
98
|
-
): readonly Task[] {
|
|
99
|
-
const background = new Map<string, Task & { programs: string[] }>();
|
|
100
|
-
for (const program of core.programs) {
|
|
101
|
-
if (!program.background) {
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
const { priority, intervalNanoseconds } = program.background;
|
|
105
|
-
const name = `TsplcBackground_${priority}_${BigInt(intervalNanoseconds) / nanosecondsPerMillisecond}`;
|
|
106
|
-
const existing = background.get(name);
|
|
107
|
-
if (existing) {
|
|
108
|
-
existing.programs.push(program.name);
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
background.set(name, {
|
|
112
|
-
name,
|
|
113
|
-
priority,
|
|
114
|
-
intervalNanoseconds,
|
|
115
|
-
programs: [program.name],
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
return appendContinuations(core, [...tasks, ...background.values()], report);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
64
|
/** The generated worker may enter its host, and only mailbox roots are shared between tasks. */
|
|
122
65
|
export function taskStorageOwnership(
|
|
123
66
|
core: VerifiedCoreModule,
|
|
@@ -125,45 +68,37 @@ export function taskStorageOwnership(
|
|
|
125
68
|
): (task: string, program: PlcProgram) => void {
|
|
126
69
|
const owners = new Map<string, string>();
|
|
127
70
|
const globals = new Map(core.variables.map((item) => [item.id, item]));
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
),
|
|
136
|
-
);
|
|
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
|
+
};
|
|
137
78
|
|
|
138
79
|
return (task, program) => {
|
|
139
|
-
const fn =
|
|
140
|
-
if (!fn) {
|
|
141
|
-
throw new Error("Verified core has a missing entry.");
|
|
142
|
-
}
|
|
80
|
+
const fn = functionOf(program.entry);
|
|
143
81
|
const worker = program.background?.worker;
|
|
144
|
-
const host =
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
for (const id of
|
|
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)) {
|
|
153
91
|
const item = globals.get(id);
|
|
154
92
|
if (
|
|
155
93
|
!item ||
|
|
156
94
|
item.storage === "constant" ||
|
|
157
|
-
|
|
95
|
+
runtimeOf(item.type) === "mailbox"
|
|
158
96
|
) {
|
|
159
97
|
continue;
|
|
160
98
|
}
|
|
161
99
|
const ownsWorker =
|
|
162
100
|
worker === item.name && item.span.file === fn.span.file;
|
|
163
|
-
if (
|
|
164
|
-
program.background &&
|
|
165
|
-
(!ownsWorker || (host && item.id === host.id))
|
|
166
|
-
) {
|
|
101
|
+
if (program.background && (!ownsWorker || item.id === host?.id)) {
|
|
167
102
|
report(
|
|
168
103
|
`Background task ${program.name} accesses scan-owned storage ${item.name}; pass value snapshots through the mailbox.`,
|
|
169
104
|
item.span,
|
|
@@ -181,44 +116,32 @@ export function taskStorageOwnership(
|
|
|
181
116
|
};
|
|
182
117
|
}
|
|
183
118
|
|
|
184
|
-
const buildModuleTables = (core: VerifiedCoreModule) => ({
|
|
185
|
-
functions: new Map(core.functions.map((item) => [item.id, item])),
|
|
186
|
-
blocks: new Map(core.blocks.map((item) => [item.id, item])),
|
|
187
|
-
types: new Map(core.types.map((item) => [item.id, item])),
|
|
188
|
-
variables: variablesById(core),
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
const builtTables = new WeakMap<
|
|
192
|
-
VerifiedCoreModule,
|
|
193
|
-
ReturnType<typeof buildModuleTables>
|
|
194
|
-
>();
|
|
195
|
-
|
|
196
|
-
/** A module's routines, types and variables by id, built once: planning and emission ask for every routine's storage. */
|
|
197
|
-
const moduleTables = (core: VerifiedCoreModule) => {
|
|
198
|
-
const known = builtTables.get(core);
|
|
199
|
-
if (known) {
|
|
200
|
-
return known;
|
|
201
|
-
}
|
|
202
|
-
const tables = buildModuleTables(core);
|
|
203
|
-
builtTables.set(core, tables);
|
|
204
|
-
return tables;
|
|
205
|
-
};
|
|
206
|
-
|
|
207
119
|
// Follow both helper calls and instance updates. Borrow addresses count as storage
|
|
208
120
|
// access, so scheduling cannot accidentally give one mutable record two owners.
|
|
209
|
-
export
|
|
121
|
+
export const accessedStorage = (
|
|
210
122
|
fn: CoreFunction,
|
|
211
123
|
core: VerifiedCoreModule,
|
|
212
|
-
|
|
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,
|
|
213
135
|
): Set<string> {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
136
|
+
const scheduledCall =
|
|
137
|
+
scheduledHost === null
|
|
138
|
+
? undefined
|
|
139
|
+
: fn.body.find(
|
|
140
|
+
(item) => item.kind === "invoke" && item.instance === scheduledHost,
|
|
141
|
+
);
|
|
219
142
|
const result = new Set<string>();
|
|
220
143
|
const seen = new Set<string>();
|
|
221
|
-
const {
|
|
144
|
+
const { calledRoutineOf } = coreTables(core);
|
|
222
145
|
|
|
223
146
|
const expression = (value: CoreExpression): void => {
|
|
224
147
|
if (value.kind === "load") {
|
|
@@ -245,27 +168,13 @@ export function accessedStorage(
|
|
|
245
168
|
if (item.kind === "for") {
|
|
246
169
|
result.add(item.counter);
|
|
247
170
|
}
|
|
248
|
-
if (item.kind === "invoke") {
|
|
249
|
-
|
|
250
|
-
result.add(item.destination);
|
|
251
|
-
}
|
|
252
|
-
const called = functions.get(item.function);
|
|
253
|
-
if (called && !seen.has(called.id)) {
|
|
254
|
-
seen.add(called.id);
|
|
255
|
-
body(called.body);
|
|
256
|
-
}
|
|
171
|
+
if (item.kind === "invoke" && item.destination) {
|
|
172
|
+
result.add(item.destination);
|
|
257
173
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
const type = instancedBlock(variable.type, types);
|
|
264
|
-
const block = type && blocks.get(type.block);
|
|
265
|
-
if (block && !seen.has(block.id)) {
|
|
266
|
-
seen.add(block.id);
|
|
267
|
-
body(block.body);
|
|
268
|
-
}
|
|
174
|
+
const called = calledRoutineOf(item);
|
|
175
|
+
if (called && !seen.has(called.id)) {
|
|
176
|
+
seen.add(called.id);
|
|
177
|
+
body(called.body);
|
|
269
178
|
}
|
|
270
179
|
nestedBodies(item).forEach(body);
|
|
271
180
|
}
|
|
@@ -275,68 +184,3 @@ export function accessedStorage(
|
|
|
275
184
|
body(fn.body);
|
|
276
185
|
return result;
|
|
277
186
|
}
|
|
278
|
-
|
|
279
|
-
/** Detached continuations run after their caller programs in the same cyclic task. */
|
|
280
|
-
function appendContinuations(
|
|
281
|
-
core: VerifiedCoreModule,
|
|
282
|
-
tasks: readonly Task[],
|
|
283
|
-
report: Report,
|
|
284
|
-
): readonly Task[] {
|
|
285
|
-
const continuations = core.programs.flatMap((program) =>
|
|
286
|
-
program.continuation
|
|
287
|
-
? [{ name: program.name, scope: program.continuation }]
|
|
288
|
-
: [],
|
|
289
|
-
);
|
|
290
|
-
if (!continuations.length) {
|
|
291
|
-
return tasks;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const programs = new Map(
|
|
295
|
-
core.programs.map((program) => [program.name, program]),
|
|
296
|
-
);
|
|
297
|
-
const functions = new Map(
|
|
298
|
-
core.functions.map((routine) => [routine.id, routine]),
|
|
299
|
-
);
|
|
300
|
-
const placements = tasks.map(
|
|
301
|
-
(task): { task: Task; roots: Set<string>; additions: string[] } => {
|
|
302
|
-
const roots = new Set<string>();
|
|
303
|
-
for (const name of task.programs) {
|
|
304
|
-
const program = programs.get(name);
|
|
305
|
-
if (!program || program.background) {
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
const entry = functions.get(program.entry);
|
|
309
|
-
if (entry) {
|
|
310
|
-
for (const id of accessedStorage(entry, core)) {
|
|
311
|
-
roots.add(id);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return { task, roots, additions: [] };
|
|
316
|
-
},
|
|
317
|
-
);
|
|
318
|
-
for (const { name, scope } of continuations) {
|
|
319
|
-
const root = core.variables.find(
|
|
320
|
-
(variable) =>
|
|
321
|
-
variable.name === scope.instance && variable.span.file === scope.file,
|
|
322
|
-
);
|
|
323
|
-
if (!root) {
|
|
324
|
-
report(`Missing continuation owner ${scope.instance}.`);
|
|
325
|
-
continue;
|
|
326
|
-
}
|
|
327
|
-
const owners = placements.filter(({ roots }) => roots.has(root.id));
|
|
328
|
-
const [owner] = owners;
|
|
329
|
-
if (!owner || owners.length !== 1) {
|
|
330
|
-
report(
|
|
331
|
-
`Continuation owner ${scope.instance} must belong to exactly one caller task.`,
|
|
332
|
-
root.span,
|
|
333
|
-
);
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
owner.additions.push(name);
|
|
337
|
-
}
|
|
338
|
-
return placements.map(({ task, additions }) => ({
|
|
339
|
-
...task,
|
|
340
|
-
programs: task.programs.concat(additions),
|
|
341
|
-
}));
|
|
342
|
-
}
|
|
@@ -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
|
+
};
|