@tsplc/compiler 0.2.21 → 0.4.0
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 +1 -1
- package/dist/cli.js +280 -223
- package/dist/cli.js.map +12 -12
- package/dist/codesys.js +452 -330
- package/dist/codesys.js.map +24 -24
- package/dist/elaborate-capture.js +112 -7
- package/dist/elaborate-capture.js.map +5 -4
- package/dist/index.js +5682 -5407
- package/dist/index.js.map +39 -37
- package/dist/ir.js +1154 -327
- package/dist/ir.js.map +23 -20
- package/dist/project.js +68 -29
- package/dist/project.js.map +4 -4
- package/dist/retain.js +8 -0
- package/dist/retain.js.map +10 -0
- package/dist/server-check.js +59 -0
- package/dist/server-check.js.map +11 -0
- package/dist/telemetry.js +19 -10
- package/dist/telemetry.js.map +3 -3
- package/package.json +33 -12
- package/src/codesys/config.ts +1 -1
- package/src/codesys/debug.ts +7 -21
- package/src/codesys/engineering.ts +8 -12
- package/src/codesys/global-lists.ts +19 -17
- package/src/codesys/global-names.ts +3 -3
- package/src/codesys/http.ts +37 -34
- package/src/codesys/index.ts +5 -22
- package/src/codesys/instrumentation.ts +3 -1
- package/src/codesys/io-paths.ts +2 -1
- package/src/codesys/manifest.ts +35 -18
- package/src/codesys/numeric.ts +2 -4
- package/src/codesys/plan.ts +94 -26
- package/src/codesys/publication.ts +4 -3
- package/src/codesys/routines.ts +2 -2
- package/src/codesys/sources.ts +1 -0
- package/src/codesys/st-files.ts +86 -50
- package/src/codesys/storage.ts +44 -9
- package/src/codesys/task-access.ts +32 -10
- package/src/codesys/telemetry.ts +93 -46
- package/src/codesys/types.ts +81 -3
- package/src/codesys/vendor.ts +1 -1
- package/src/frontend/analyzer.ts +15 -14
- package/src/frontend/async.ts +23 -21
- package/src/frontend/blocks.ts +7 -6
- package/src/frontend/configuration.ts +8 -6
- package/src/frontend/const-functions.ts +5 -5
- package/src/frontend/cooperative.ts +2 -1
- package/src/frontend/coroutines.ts +24 -21
- package/src/frontend/elaborate/calls.ts +12 -7
- package/src/frontend/elaborate/capture-protocol.ts +103 -0
- package/src/frontend/elaborate/capture.ts +48 -19
- package/src/frontend/elaborate/dialect.ts +2 -2
- package/src/frontend/elaborate/expressions.ts +9 -6
- package/src/frontend/elaborate/frame.ts +1 -1
- package/src/frontend/elaborate/graph.ts +27 -43
- package/src/frontend/elaborate/index.ts +52 -17
- package/src/frontend/elaborate/initializers.ts +3 -2
- package/src/frontend/elaborate/layouts.ts +2 -2
- package/src/frontend/elaborate/model.ts +34 -21
- package/src/frontend/elaborate/retention.ts +206 -0
- package/src/frontend/elaborate/specialize.ts +7 -6
- package/src/frontend/elaborate/statements.ts +47 -38
- package/src/frontend/elaborate/storage.ts +26 -6
- package/src/frontend/exposure.ts +6 -6
- package/src/frontend/expressions.ts +26 -25
- package/src/frontend/intrinsics.ts +3 -3
- package/src/frontend/module-graph.ts +1 -1
- package/src/frontend/positions.ts +2 -1
- package/src/frontend/promise-chains.ts +1 -0
- package/src/frontend/promises.ts +8 -7
- package/src/frontend/routines.ts +3 -2
- package/src/frontend/sdk.ts +2 -2
- package/src/frontend/services.ts +23 -20
- package/src/frontend/statements.ts +8 -6
- package/src/frontend/tasks.ts +11 -6
- package/src/frontend/telemetry.ts +1 -1
- package/src/frontend/types.ts +11 -9
- package/src/frontend/typescript.ts +92 -42
- package/src/index.ts +2 -1
- package/src/ir/aggregates.ts +4 -3
- package/src/ir/allocation.ts +2 -1
- package/src/ir/core-model.ts +38 -8
- package/src/ir/declarations.ts +12 -12
- package/src/ir/domains.ts +8 -8
- package/src/ir/fold.ts +2 -2
- package/src/ir/index.ts +53 -40
- package/src/ir/job-errors.ts +22 -11
- package/src/ir/layouts.ts +3 -2
- package/src/ir/link.ts +6 -24
- package/src/ir/model.ts +3 -2
- package/src/ir/normalization-error.ts +1 -1
- package/src/ir/normalize.ts +19 -12
- package/src/ir/numeric.ts +1 -0
- package/src/{codesys → ir}/operands.ts +2 -6
- package/src/ir/ranges.ts +2 -2
- package/src/ir/routine.ts +35 -20
- package/src/ir/scalars.ts +3 -3
- package/src/ir/share.ts +862 -0
- package/src/ir/temporaries.ts +236 -0
- package/src/ir/types.ts +1 -1
- package/src/project/artifacts.ts +12 -2
- package/src/project/cli.ts +42 -44
- package/src/project/debugger.ts +15 -9
- package/src/project/index.ts +1 -1
- package/src/project/plant.ts +34 -23
- package/src/project/project-commands.ts +92 -73
- package/src/project/project.ts +91 -42
- package/src/project/release.ts +50 -57
- package/src/project/server-check.ts +54 -0
- package/src/project/server.ts +60 -41
- package/src/project/terminal.ts +3 -1
- package/stdlib/retain.ts +2 -0
- package/types/globals.d.ts +1 -0
- package/types/retain.d.ts +6 -0
- package/types/telemetry.d.ts +2 -2
package/src/ir/share.ts
ADDED
|
@@ -0,0 +1,862 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CoreExpression,
|
|
3
|
+
type CoreFunction,
|
|
4
|
+
type CoreFunctionBlock,
|
|
5
|
+
type CorePath,
|
|
6
|
+
type CoreStatement,
|
|
7
|
+
nestedBodies,
|
|
8
|
+
type VerifiedCoreModule,
|
|
9
|
+
} from "./core-model.ts";
|
|
10
|
+
import type { Variable } from "./model.ts";
|
|
11
|
+
import { admitCore } from "./normalize.ts";
|
|
12
|
+
import type { PlcType } from "./types.ts";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Routines that are the same code over different storage, such as one method elaborated once per
|
|
16
|
+
* instance, merged into one routine that borrows that storage. `routines` maps every routine that
|
|
17
|
+
* was merged away to the one that runs in its place.
|
|
18
|
+
*/
|
|
19
|
+
export interface SharedRoutines {
|
|
20
|
+
core: VerifiedCoreModule;
|
|
21
|
+
routines: ReadonlyMap<string, string>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Merges free routines whose bodies differ only in the persistent storage they reach. Each place a
|
|
26
|
+
* routine reaches through a fixed path into module storage starts at an anchor: the place without
|
|
27
|
+
* its last field, or the whole place when it ends in a constant index or reaches the first index
|
|
28
|
+
* that is computed at run time. Routines with the same anchored body, declaration and partition
|
|
29
|
+
* share one routine that takes each anchor that differs between them as an `InOut` parameter;
|
|
30
|
+
* each call site borrows its routine's anchors. A borrowed place is the caller's storage, read and
|
|
31
|
+
* written where the original routine read and wrote it, so evaluation order and aliasing are
|
|
32
|
+
* unchanged. Callees merge before their callers, whose calls then differ only in what they borrow.
|
|
33
|
+
*
|
|
34
|
+
* `partition` keeps routines apart that must stay apart, such as those of different tasks; a
|
|
35
|
+
* routine it gives no partition is left as it is.
|
|
36
|
+
*/
|
|
37
|
+
export function shareRoutines(
|
|
38
|
+
core: VerifiedCoreModule,
|
|
39
|
+
partition: (routine: CoreFunction) => string | undefined,
|
|
40
|
+
): SharedRoutines {
|
|
41
|
+
const types = new Map(core.types.map((type) => [type.id, type]));
|
|
42
|
+
const globals = new Map(core.variables.map((item) => [item.id, item]));
|
|
43
|
+
const entries = new Set(core.programs.map((program) => program.entry));
|
|
44
|
+
const bodies = new Map<string, readonly CoreStatement[]>(
|
|
45
|
+
[...core.functions, ...core.blocks].map((routine) => [
|
|
46
|
+
routine.id,
|
|
47
|
+
routine.body,
|
|
48
|
+
]),
|
|
49
|
+
);
|
|
50
|
+
const merged = new Map<string, string>();
|
|
51
|
+
const shared = new Map<string, CoreFunction>();
|
|
52
|
+
|
|
53
|
+
// A reference can only bind to plain data: a block instance or a stored reference stays where it is.
|
|
54
|
+
const plainData = (id: string, seen = new Set<string>()): boolean => {
|
|
55
|
+
const type = types.get(id);
|
|
56
|
+
if (!type || seen.has(id)) {
|
|
57
|
+
return type !== undefined;
|
|
58
|
+
}
|
|
59
|
+
seen.add(id);
|
|
60
|
+
if (type.kind === "block") {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
if (type.kind === "array") {
|
|
64
|
+
return plainData(type.element, seen);
|
|
65
|
+
}
|
|
66
|
+
if (type.kind === "record") {
|
|
67
|
+
return type.fields.every(
|
|
68
|
+
(field) => field.mode !== "inOut" && plainData(field.type, seen),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
};
|
|
73
|
+
const roots: Roots = {
|
|
74
|
+
anchorable: (root) => {
|
|
75
|
+
const variable = globals.get(root);
|
|
76
|
+
return variable !== undefined && variable.storage !== "constant";
|
|
77
|
+
},
|
|
78
|
+
type: (root) => globals.get(root)?.type,
|
|
79
|
+
name: (root) => globals.get(root)?.name ?? "anchor",
|
|
80
|
+
plainData: (type) => plainData(type),
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const candidates = core.functions.filter(
|
|
84
|
+
(fn) => !fn.owner && !entries.has(fn.id),
|
|
85
|
+
);
|
|
86
|
+
for (const level of callLevels(candidates, bodies)) {
|
|
87
|
+
const groups = new Map<string, Anchored[]>();
|
|
88
|
+
for (const fn of level) {
|
|
89
|
+
const group = partition(fn);
|
|
90
|
+
if (group === undefined) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const anchored = anchor(
|
|
94
|
+
{ ...fn, body: bodies.get(fn.id) ?? fn.body },
|
|
95
|
+
types,
|
|
96
|
+
roots,
|
|
97
|
+
);
|
|
98
|
+
if (!anchored) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const key = `${group}\n${anchored.key}`;
|
|
102
|
+
groups.set(key, [...(groups.get(key) ?? []), anchored]);
|
|
103
|
+
}
|
|
104
|
+
const calls = new Map<string, MergedCall>();
|
|
105
|
+
for (const members of groups.values()) {
|
|
106
|
+
const [first] = members;
|
|
107
|
+
if (!first || members.length < 2) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const varying: Varying = {
|
|
111
|
+
anchors: first.anchors.map((slot, index) =>
|
|
112
|
+
members.some((member) => member.anchors[index]?.key !== slot.key),
|
|
113
|
+
),
|
|
114
|
+
constants: first.constants.map((constant, index) =>
|
|
115
|
+
members.some(
|
|
116
|
+
(member) =>
|
|
117
|
+
JSON.stringify(member.constants[index]?.value) !==
|
|
118
|
+
JSON.stringify(constant.value),
|
|
119
|
+
),
|
|
120
|
+
),
|
|
121
|
+
};
|
|
122
|
+
shared.set(first.fn.id, mergedRoutine(first, varying, roots, types));
|
|
123
|
+
for (const [index, member] of members.entries()) {
|
|
124
|
+
if (index) {
|
|
125
|
+
merged.set(member.fn.id, first.fn.id);
|
|
126
|
+
}
|
|
127
|
+
calls.set(member.fn.id, {
|
|
128
|
+
target: first.fn.id,
|
|
129
|
+
borrows: member.anchors.filter((_, slot) => varying.anchors[slot]),
|
|
130
|
+
values: member.constants.filter((_, slot) => varying.constants[slot]),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!calls.size) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
for (const [id, body] of bodies) {
|
|
138
|
+
bodies.set(id, rewriteCalls(body, calls));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (!merged.size) {
|
|
142
|
+
return { core, routines: merged };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const functions = core.functions.flatMap((fn): CoreFunction[] => {
|
|
146
|
+
if (merged.has(fn.id)) {
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
const routine = shared.get(fn.id);
|
|
150
|
+
if (routine) {
|
|
151
|
+
return [routine];
|
|
152
|
+
}
|
|
153
|
+
return [{ ...fn, body: bodies.get(fn.id) ?? fn.body }];
|
|
154
|
+
});
|
|
155
|
+
const blocks = core.blocks.map(
|
|
156
|
+
(block): CoreFunctionBlock => ({
|
|
157
|
+
...block,
|
|
158
|
+
body: bodies.get(block.id) ?? block.body,
|
|
159
|
+
}),
|
|
160
|
+
);
|
|
161
|
+
return {
|
|
162
|
+
core: admitCore({ ...core, functions, blocks }),
|
|
163
|
+
routines: merged,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
interface Roots {
|
|
168
|
+
/** Whether a root is module storage, whose places a routine can borrow. */
|
|
169
|
+
anchorable: (root: string) => boolean;
|
|
170
|
+
type: (root: string) => string | undefined;
|
|
171
|
+
name: (root: string) => string;
|
|
172
|
+
/** Whether a type holds only data, which a reference can bind to. */
|
|
173
|
+
plainData: (type: string) => boolean;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** A place a routine reaches in module storage, from the routine's own anchor. */
|
|
177
|
+
interface Borrow {
|
|
178
|
+
root: string;
|
|
179
|
+
path: CorePath;
|
|
180
|
+
type: string;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** A routine's body with its anchors numbered in the order it first reaches them. */
|
|
184
|
+
interface Anchored {
|
|
185
|
+
fn: CoreFunction;
|
|
186
|
+
key: string;
|
|
187
|
+
anchors: readonly (Borrow & { key: string })[];
|
|
188
|
+
/** Each scalar constant the body evaluates, in order. */
|
|
189
|
+
constants: readonly Extract<CoreExpression, { kind: "constant" }>[];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Candidate routines, callees before their callers. A routine's level is one more than its deepest callee's. */
|
|
193
|
+
function callLevels(
|
|
194
|
+
candidates: readonly CoreFunction[],
|
|
195
|
+
bodies: ReadonlyMap<string, readonly CoreStatement[]>,
|
|
196
|
+
): CoreFunction[][] {
|
|
197
|
+
const levels = new Map<string, number>();
|
|
198
|
+
const callees = (items: readonly CoreStatement[], found: Set<string>) => {
|
|
199
|
+
for (const item of items) {
|
|
200
|
+
if (item.kind === "invoke") {
|
|
201
|
+
found.add(item.function);
|
|
202
|
+
}
|
|
203
|
+
for (const body of nestedBodies(item)) {
|
|
204
|
+
callees(body, found);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return found;
|
|
208
|
+
};
|
|
209
|
+
const level = (id: string, path: Set<string>): number => {
|
|
210
|
+
const known = levels.get(id);
|
|
211
|
+
if (known !== undefined) {
|
|
212
|
+
return known;
|
|
213
|
+
}
|
|
214
|
+
// Verified routines do not recurse; a cycle would only stop merging, never recurse here.
|
|
215
|
+
if (path.has(id)) {
|
|
216
|
+
return 0;
|
|
217
|
+
}
|
|
218
|
+
path.add(id);
|
|
219
|
+
const deepest = [...callees(bodies.get(id) ?? [], new Set())].reduce(
|
|
220
|
+
(depth, callee) => Math.max(depth, level(callee, path) + 1),
|
|
221
|
+
0,
|
|
222
|
+
);
|
|
223
|
+
path.delete(id);
|
|
224
|
+
levels.set(id, deepest);
|
|
225
|
+
return deepest;
|
|
226
|
+
};
|
|
227
|
+
const ordered: CoreFunction[][] = [];
|
|
228
|
+
for (const fn of candidates) {
|
|
229
|
+
const depth = level(fn.id, new Set());
|
|
230
|
+
ordered[depth] = [...(ordered[depth] ?? []), fn];
|
|
231
|
+
}
|
|
232
|
+
return ordered.filter((items) => items !== undefined);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const staticIndex = (segment: CorePath[number]) =>
|
|
236
|
+
segment.kind === "index" &&
|
|
237
|
+
segment.value.kind === "constant" &&
|
|
238
|
+
segment.value.value.kind === "integer";
|
|
239
|
+
|
|
240
|
+
/** The fixed part of a place that an anchor holds, by the rule `shareRoutines` describes. */
|
|
241
|
+
function anchorLength(path: CorePath): number {
|
|
242
|
+
const dynamic = path.findIndex(
|
|
243
|
+
(segment) => segment.kind === "index" && !staticIndex(segment),
|
|
244
|
+
);
|
|
245
|
+
if (dynamic >= 0) {
|
|
246
|
+
return dynamic;
|
|
247
|
+
}
|
|
248
|
+
return path.at(-1)?.kind === "field" ? path.length - 1 : path.length;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const pathType = (
|
|
252
|
+
root: string,
|
|
253
|
+
path: CorePath,
|
|
254
|
+
types: ReadonlyMap<string, PlcType>,
|
|
255
|
+
): string | undefined =>
|
|
256
|
+
path.reduce<string | undefined>((id, segment) => {
|
|
257
|
+
const type = id === undefined ? undefined : types.get(id);
|
|
258
|
+
if (segment.kind === "field" && type?.kind === "record") {
|
|
259
|
+
return type.fields.find((field) => field.name === segment.name)?.type;
|
|
260
|
+
}
|
|
261
|
+
if (segment.kind === "index" && type?.kind === "array") {
|
|
262
|
+
return type.element;
|
|
263
|
+
}
|
|
264
|
+
return undefined;
|
|
265
|
+
}, root);
|
|
266
|
+
|
|
267
|
+
const constantText = (segment: CorePath[number]) =>
|
|
268
|
+
segment.kind === "field"
|
|
269
|
+
? `.${segment.name}`
|
|
270
|
+
: `[${segment.value.kind === "constant" ? JSON.stringify(segment.value.value) : "?"}]`;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Numbers a routine's anchors and writes its body with each anchored place as its anchor's number
|
|
274
|
+
* and the rest of its path, and its own variables by position. Two routines with the same key run
|
|
275
|
+
* the same statements over their own anchors. Undefined when a place cannot be anchored the same
|
|
276
|
+
* way in every routine, such as a loop counter in module storage.
|
|
277
|
+
*/
|
|
278
|
+
function anchor(
|
|
279
|
+
fn: CoreFunction,
|
|
280
|
+
types: ReadonlyMap<string, PlcType>,
|
|
281
|
+
roots: Roots,
|
|
282
|
+
): Anchored | undefined {
|
|
283
|
+
const own = new Map(
|
|
284
|
+
[...fn.parameters, ...fn.locals].map((variable, index) => [
|
|
285
|
+
variable.id,
|
|
286
|
+
`#${index}`,
|
|
287
|
+
]),
|
|
288
|
+
);
|
|
289
|
+
const anchors: (Borrow & { key: string })[] = [];
|
|
290
|
+
const constants: Extract<CoreExpression, { kind: "constant" }>[] = [];
|
|
291
|
+
const numbers = new Map<string, number>();
|
|
292
|
+
const rewrite: PlaceRewrite = {
|
|
293
|
+
constant: (value) => {
|
|
294
|
+
if (!scalarConstant(value, types)) {
|
|
295
|
+
return value;
|
|
296
|
+
}
|
|
297
|
+
constants.push(value);
|
|
298
|
+
return {
|
|
299
|
+
kind: "load",
|
|
300
|
+
type: value.type,
|
|
301
|
+
span: value.span,
|
|
302
|
+
root: `$${constants.length - 1}`,
|
|
303
|
+
};
|
|
304
|
+
},
|
|
305
|
+
place: (root, path) => {
|
|
306
|
+
if (!roots.anchorable(root)) {
|
|
307
|
+
return { root: own.get(root) ?? root, path: mapPath(path) };
|
|
308
|
+
}
|
|
309
|
+
const { fixed, key } = anchorOf(root, path);
|
|
310
|
+
const rest = mapPath(path.slice(fixed.length));
|
|
311
|
+
const known = numbers.get(key);
|
|
312
|
+
if (known !== undefined) {
|
|
313
|
+
return { root: `@${known}`, path: rest };
|
|
314
|
+
}
|
|
315
|
+
const rootType = roots.type(root);
|
|
316
|
+
const type =
|
|
317
|
+
rootType === undefined ? undefined : pathType(rootType, fixed, types);
|
|
318
|
+
if (type === undefined) {
|
|
319
|
+
throw new Unanchored();
|
|
320
|
+
}
|
|
321
|
+
// A block instance is not borrowed: its place stays as written, the same in every routine or none.
|
|
322
|
+
if (!roots.plainData(type)) {
|
|
323
|
+
return { root, path: [...fixed, ...rest] };
|
|
324
|
+
}
|
|
325
|
+
numbers.set(key, anchors.length);
|
|
326
|
+
anchors.push({ root, path: fixed, type, key });
|
|
327
|
+
return { root: `@${anchors.length - 1}`, path: rest };
|
|
328
|
+
},
|
|
329
|
+
identity: (root) => {
|
|
330
|
+
if (roots.anchorable(root)) {
|
|
331
|
+
throw new Unanchored();
|
|
332
|
+
}
|
|
333
|
+
return own.get(root) ?? root;
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
const mapPath = (path: CorePath): CorePath =>
|
|
337
|
+
path.map((segment) =>
|
|
338
|
+
segment.kind === "field"
|
|
339
|
+
? segment
|
|
340
|
+
: { kind: "index", value: rewriteExpression(segment.value, rewrite) },
|
|
341
|
+
);
|
|
342
|
+
try {
|
|
343
|
+
const body = rewriteStatements(fn.body, rewrite);
|
|
344
|
+
// Not the name: the elaborator numbers each instance's copy of a routine. The declaration
|
|
345
|
+
// and the body say what it does.
|
|
346
|
+
const signature = {
|
|
347
|
+
span: fn.span,
|
|
348
|
+
result: fn.result,
|
|
349
|
+
parameters: fn.parameters.map(({ id, ...rest }) => rest),
|
|
350
|
+
locals: fn.locals.map(({ id, ...rest }) => rest),
|
|
351
|
+
anchors: anchors.map((item) => item.type),
|
|
352
|
+
};
|
|
353
|
+
return { fn, key: JSON.stringify([signature, body]), anchors, constants };
|
|
354
|
+
} catch (cause) {
|
|
355
|
+
if (cause instanceof Unanchored) {
|
|
356
|
+
return undefined;
|
|
357
|
+
}
|
|
358
|
+
throw cause;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** A place's anchor, and the key that identifies it. */
|
|
363
|
+
const anchorOf = (root: string, path: CorePath) => {
|
|
364
|
+
const fixed = path.slice(0, anchorLength(path));
|
|
365
|
+
return { fixed, key: `${root}${fixed.map(constantText).join("")}` };
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* The first routine of a group, taking each anchor that differs between the routines as an
|
|
370
|
+
* `InOut` parameter after its own parameters, then each constant that differs as a value
|
|
371
|
+
* parameter. Anchors and constants all of them share stay in place.
|
|
372
|
+
*/
|
|
373
|
+
function mergedRoutine(
|
|
374
|
+
{ fn, anchors, constants }: Anchored,
|
|
375
|
+
varying: Varying,
|
|
376
|
+
roots: Roots,
|
|
377
|
+
types: ReadonlyMap<string, PlcType>,
|
|
378
|
+
): CoreFunction {
|
|
379
|
+
const borrowed = new Map<number, Variable>();
|
|
380
|
+
for (const [index, slot] of anchors.entries()) {
|
|
381
|
+
if (!varying.anchors[index]) {
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
const field = [...slot.path]
|
|
385
|
+
.reverse()
|
|
386
|
+
.find((segment) => segment.kind === "field");
|
|
387
|
+
borrowed.set(index, {
|
|
388
|
+
id: `${fn.id}:anchor${index}`,
|
|
389
|
+
name: field?.kind === "field" ? field.name : roots.name(slot.root),
|
|
390
|
+
type: slot.type,
|
|
391
|
+
storage: "parameter",
|
|
392
|
+
mutable: true,
|
|
393
|
+
retain: false,
|
|
394
|
+
mode: "inOut",
|
|
395
|
+
span: fn.span,
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
const values = new Map<number, Variable>();
|
|
399
|
+
for (const [index, constant] of constants.entries()) {
|
|
400
|
+
if (varying.constants[index]) {
|
|
401
|
+
values.set(index, {
|
|
402
|
+
id: `${fn.id}:value${index}`,
|
|
403
|
+
name: "value",
|
|
404
|
+
type: constant.type,
|
|
405
|
+
storage: "parameter",
|
|
406
|
+
mutable: false,
|
|
407
|
+
retain: false,
|
|
408
|
+
span: fn.span,
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
const slots = new Map(anchors.map((slot, index) => [slot.key, index]));
|
|
413
|
+
// Scalar constants come in the order `anchor` numbered them in.
|
|
414
|
+
const order = constants.keys();
|
|
415
|
+
const rewrite: PlaceRewrite = {
|
|
416
|
+
constant: (value) => {
|
|
417
|
+
if (!scalarConstant(value, types)) {
|
|
418
|
+
return value;
|
|
419
|
+
}
|
|
420
|
+
const parameter = values.get(order.next().value ?? -1);
|
|
421
|
+
return parameter
|
|
422
|
+
? {
|
|
423
|
+
kind: "load",
|
|
424
|
+
type: value.type,
|
|
425
|
+
span: value.span,
|
|
426
|
+
root: parameter.id,
|
|
427
|
+
}
|
|
428
|
+
: value;
|
|
429
|
+
},
|
|
430
|
+
place: (root, path) => {
|
|
431
|
+
if (!roots.anchorable(root)) {
|
|
432
|
+
return { root, path: mapPath(path) };
|
|
433
|
+
}
|
|
434
|
+
const { fixed, key } = anchorOf(root, path);
|
|
435
|
+
const rest = mapPath(path.slice(fixed.length));
|
|
436
|
+
const parameter = borrowed.get(slots.get(key) ?? -1);
|
|
437
|
+
return parameter
|
|
438
|
+
? { root: parameter.id, path: rest }
|
|
439
|
+
: { root, path: [...fixed, ...rest] };
|
|
440
|
+
},
|
|
441
|
+
identity: (root) => root,
|
|
442
|
+
};
|
|
443
|
+
const mapPath = (path: CorePath): CorePath =>
|
|
444
|
+
path.map((segment) =>
|
|
445
|
+
segment.kind === "field"
|
|
446
|
+
? segment
|
|
447
|
+
: { kind: "index", value: rewriteExpression(segment.value, rewrite) },
|
|
448
|
+
);
|
|
449
|
+
return {
|
|
450
|
+
...fn,
|
|
451
|
+
parameters: [...fn.parameters, ...borrowed.values(), ...values.values()],
|
|
452
|
+
body: rewriteStatements(fn.body, rewrite),
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** Which anchors and constants differ between the routines of a group, by number. */
|
|
457
|
+
interface Varying {
|
|
458
|
+
anchors: readonly boolean[];
|
|
459
|
+
constants: readonly boolean[];
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** What a call to a merged routine adds after its own arguments. */
|
|
463
|
+
interface MergedCall {
|
|
464
|
+
target: string;
|
|
465
|
+
borrows: readonly Borrow[];
|
|
466
|
+
values: readonly CoreExpression[];
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/** Calls to merged routines go to the routine that runs in their place, borrowing their anchors. */
|
|
470
|
+
function rewriteCalls(
|
|
471
|
+
items: readonly CoreStatement[],
|
|
472
|
+
calls: ReadonlyMap<string, MergedCall>,
|
|
473
|
+
): CoreStatement[] {
|
|
474
|
+
return items.map((item): CoreStatement => {
|
|
475
|
+
if (item.kind === "invoke") {
|
|
476
|
+
const call = calls.get(item.function);
|
|
477
|
+
if (!call) {
|
|
478
|
+
return item;
|
|
479
|
+
}
|
|
480
|
+
return {
|
|
481
|
+
...item,
|
|
482
|
+
function: call.target,
|
|
483
|
+
arguments: [
|
|
484
|
+
...item.arguments,
|
|
485
|
+
...call.borrows.map(
|
|
486
|
+
(borrow): CoreExpression => ({
|
|
487
|
+
kind: "borrow",
|
|
488
|
+
type: borrow.type,
|
|
489
|
+
span: item.span,
|
|
490
|
+
place: { root: borrow.root, path: borrow.path },
|
|
491
|
+
}),
|
|
492
|
+
),
|
|
493
|
+
...call.values,
|
|
494
|
+
],
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
switch (item.kind) {
|
|
498
|
+
case "if":
|
|
499
|
+
return {
|
|
500
|
+
...item,
|
|
501
|
+
// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.
|
|
502
|
+
then: rewriteCalls(item.then, calls),
|
|
503
|
+
else: rewriteCalls(item.else, calls),
|
|
504
|
+
};
|
|
505
|
+
case "switch":
|
|
506
|
+
return {
|
|
507
|
+
...item,
|
|
508
|
+
cases: item.cases.map((branch) => ({
|
|
509
|
+
...branch,
|
|
510
|
+
body: rewriteCalls(branch.body, calls),
|
|
511
|
+
})),
|
|
512
|
+
fallback: rewriteCalls(item.fallback, calls),
|
|
513
|
+
};
|
|
514
|
+
case "for":
|
|
515
|
+
return { ...item, body: rewriteCalls(item.body, calls) };
|
|
516
|
+
default:
|
|
517
|
+
return item;
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
class Unanchored extends Error {}
|
|
523
|
+
|
|
524
|
+
interface PlaceRewrite {
|
|
525
|
+
place: (root: string, path: CorePath) => { root: string; path: CorePath };
|
|
526
|
+
/** A root a statement names without a path: a loop counter, call destination or block instance. */
|
|
527
|
+
identity: (root: string) => string;
|
|
528
|
+
/** A scalar constant the body evaluates; case labels and loop bounds are not expressions. */
|
|
529
|
+
constant: (
|
|
530
|
+
value: Extract<CoreExpression, { kind: "constant" }>,
|
|
531
|
+
) => CoreExpression;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** Constants a routine can take as a value parameter instead: scalars of an elementary or enum type. */
|
|
535
|
+
const scalarConstant = (
|
|
536
|
+
value: Extract<CoreExpression, { kind: "constant" }>,
|
|
537
|
+
types: ReadonlyMap<string, PlcType>,
|
|
538
|
+
) =>
|
|
539
|
+
["bool", "integer", "float", "duration", "calendar"].includes(
|
|
540
|
+
value.value.kind,
|
|
541
|
+
) && types.get(value.type)?.kind !== "string";
|
|
542
|
+
|
|
543
|
+
function rewriteExpression(
|
|
544
|
+
value: CoreExpression,
|
|
545
|
+
rewrite: PlaceRewrite,
|
|
546
|
+
): CoreExpression {
|
|
547
|
+
switch (value.kind) {
|
|
548
|
+
case "constant":
|
|
549
|
+
return rewrite.constant(value);
|
|
550
|
+
case "load": {
|
|
551
|
+
const place = rewrite.place(value.root, value.path ?? []);
|
|
552
|
+
return {
|
|
553
|
+
...value,
|
|
554
|
+
root: place.root,
|
|
555
|
+
...(value.path || place.path.length ? { path: place.path } : {}),
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
case "borrow":
|
|
559
|
+
return {
|
|
560
|
+
...value,
|
|
561
|
+
place: rewrite.place(value.place.root, value.place.path),
|
|
562
|
+
};
|
|
563
|
+
case "unary":
|
|
564
|
+
case "convert":
|
|
565
|
+
return { ...value, operand: rewriteExpression(value.operand, rewrite) };
|
|
566
|
+
case "binary":
|
|
567
|
+
return {
|
|
568
|
+
...value,
|
|
569
|
+
left: rewriteExpression(value.left, rewrite),
|
|
570
|
+
right: rewriteExpression(value.right, rewrite),
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function rewriteStatements(
|
|
576
|
+
items: readonly CoreStatement[],
|
|
577
|
+
rewrite: PlaceRewrite,
|
|
578
|
+
): CoreStatement[] {
|
|
579
|
+
const expression = (value: CoreExpression) =>
|
|
580
|
+
rewriteExpression(value, rewrite);
|
|
581
|
+
const statements = (body: readonly CoreStatement[]) =>
|
|
582
|
+
rewriteStatements(body, rewrite);
|
|
583
|
+
return items.map((item) =>
|
|
584
|
+
rewriteStatement(item, rewrite, expression, statements),
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function rewriteStatement(
|
|
589
|
+
item: CoreStatement,
|
|
590
|
+
rewrite: PlaceRewrite,
|
|
591
|
+
expression: (value: CoreExpression) => CoreExpression,
|
|
592
|
+
statements: (body: readonly CoreStatement[]) => CoreStatement[],
|
|
593
|
+
): CoreStatement {
|
|
594
|
+
switch (item.kind) {
|
|
595
|
+
case "assign": {
|
|
596
|
+
const place = rewrite.place(item.root, item.path ?? []);
|
|
597
|
+
return {
|
|
598
|
+
...item,
|
|
599
|
+
root: place.root,
|
|
600
|
+
...(item.path || place.path.length ? { path: place.path } : {}),
|
|
601
|
+
value: expression(item.value),
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
case "if":
|
|
605
|
+
return {
|
|
606
|
+
...item,
|
|
607
|
+
condition: expression(item.condition),
|
|
608
|
+
// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.
|
|
609
|
+
then: statements(item.then),
|
|
610
|
+
else: statements(item.else),
|
|
611
|
+
};
|
|
612
|
+
case "switch":
|
|
613
|
+
return {
|
|
614
|
+
...item,
|
|
615
|
+
value: expression(item.value),
|
|
616
|
+
cases: item.cases.map((branch) => ({
|
|
617
|
+
...branch,
|
|
618
|
+
body: statements(branch.body),
|
|
619
|
+
})),
|
|
620
|
+
fallback: statements(item.fallback),
|
|
621
|
+
};
|
|
622
|
+
case "for":
|
|
623
|
+
return {
|
|
624
|
+
...item,
|
|
625
|
+
counter: rewrite.identity(item.counter),
|
|
626
|
+
...(item.dynamic && {
|
|
627
|
+
dynamic: {
|
|
628
|
+
...item.dynamic,
|
|
629
|
+
start: expression(item.dynamic.start),
|
|
630
|
+
limit: expression(item.dynamic.limit),
|
|
631
|
+
},
|
|
632
|
+
}),
|
|
633
|
+
body: statements(item.body),
|
|
634
|
+
};
|
|
635
|
+
case "invoke":
|
|
636
|
+
return {
|
|
637
|
+
...item,
|
|
638
|
+
...(item.instance !== undefined && {
|
|
639
|
+
instance: rewrite.identity(item.instance),
|
|
640
|
+
}),
|
|
641
|
+
...(item.index && { index: expression(item.index) }),
|
|
642
|
+
arguments: item.arguments.map(expression),
|
|
643
|
+
...(item.destination !== undefined && {
|
|
644
|
+
destination: rewrite.identity(item.destination),
|
|
645
|
+
}),
|
|
646
|
+
};
|
|
647
|
+
case "blockUpdate":
|
|
648
|
+
return {
|
|
649
|
+
...item,
|
|
650
|
+
instance: rewrite.identity(item.instance),
|
|
651
|
+
...(item.index && { index: expression(item.index) }),
|
|
652
|
+
inputs: Object.fromEntries(
|
|
653
|
+
Object.entries(item.inputs).map(([name, input]) => [
|
|
654
|
+
name,
|
|
655
|
+
expression(input),
|
|
656
|
+
]),
|
|
657
|
+
),
|
|
658
|
+
};
|
|
659
|
+
case "return":
|
|
660
|
+
return item.value ? { ...item, value: expression(item.value) } : item;
|
|
661
|
+
case "telemetry":
|
|
662
|
+
return {
|
|
663
|
+
...item,
|
|
664
|
+
properties: item.properties.map((property) => ({
|
|
665
|
+
...property,
|
|
666
|
+
value: expression(property.value),
|
|
667
|
+
...(property.length && { length: expression(property.length) }),
|
|
668
|
+
})),
|
|
669
|
+
...(item.record.kind === "exception" && {
|
|
670
|
+
record: { ...item.record, code: expression(item.record.code) },
|
|
671
|
+
}),
|
|
672
|
+
};
|
|
673
|
+
case "break":
|
|
674
|
+
case "continue":
|
|
675
|
+
return item;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
const returns = (items: readonly CoreStatement[]): boolean =>
|
|
680
|
+
items.some(
|
|
681
|
+
(item) => item.kind === "return" || nestedBodies(item).some(returns),
|
|
682
|
+
);
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Joins each group of programs into its first: one entry that runs the entries' bodies in the
|
|
686
|
+
* group's order, which is the order a task runs them in. An entry that can return early would
|
|
687
|
+
* skip the ones after it, so it stays a program of its own. `routines` maps each entry joined
|
|
688
|
+
* away to the entry that now runs it.
|
|
689
|
+
*/
|
|
690
|
+
export function joinPrograms(
|
|
691
|
+
core: VerifiedCoreModule,
|
|
692
|
+
groups: readonly (readonly string[])[],
|
|
693
|
+
): SharedRoutines {
|
|
694
|
+
const functions = new Map(core.functions.map((fn) => [fn.id, fn]));
|
|
695
|
+
const programs = new Map(core.programs.map((item) => [item.name, item]));
|
|
696
|
+
const joined = new Map<string, CoreFunction>();
|
|
697
|
+
const routines = new Map<string, string>();
|
|
698
|
+
const removed = new Set<string>();
|
|
699
|
+
for (const group of groups) {
|
|
700
|
+
const members = group.flatMap((name) => {
|
|
701
|
+
const program = programs.get(name);
|
|
702
|
+
const entry = program && functions.get(program.entry);
|
|
703
|
+
return program && entry && !returns(entry.body)
|
|
704
|
+
? [{ program, entry }]
|
|
705
|
+
: [];
|
|
706
|
+
});
|
|
707
|
+
const [first, ...rest] = members;
|
|
708
|
+
if (!first || !rest.length) {
|
|
709
|
+
continue;
|
|
710
|
+
}
|
|
711
|
+
joined.set(first.entry.id, {
|
|
712
|
+
...first.entry,
|
|
713
|
+
locals: members.flatMap(({ entry }) => entry.locals),
|
|
714
|
+
body: members.flatMap(({ entry }) => entry.body),
|
|
715
|
+
});
|
|
716
|
+
for (const { program, entry } of rest) {
|
|
717
|
+
removed.add(program.name);
|
|
718
|
+
routines.set(entry.id, first.entry.id);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
if (!routines.size) {
|
|
722
|
+
return { core, routines };
|
|
723
|
+
}
|
|
724
|
+
return {
|
|
725
|
+
core: admitCore({
|
|
726
|
+
...core,
|
|
727
|
+
functions: core.functions.flatMap((fn) =>
|
|
728
|
+
routines.has(fn.id) ? [] : [joined.get(fn.id) ?? fn],
|
|
729
|
+
),
|
|
730
|
+
programs: core.programs.filter((item) => !removed.has(item.name)),
|
|
731
|
+
}),
|
|
732
|
+
routines,
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/** A routine that only returns a constant, or does nothing: what each of its calls amounts to. */
|
|
737
|
+
function constantResult(
|
|
738
|
+
fn: CoreFunction,
|
|
739
|
+
): { value?: CoreExpression } | undefined {
|
|
740
|
+
const [only, ...rest] = fn.body;
|
|
741
|
+
if (rest.length || fn.owner) {
|
|
742
|
+
return undefined;
|
|
743
|
+
}
|
|
744
|
+
if (!only) {
|
|
745
|
+
return fn.result ? undefined : {};
|
|
746
|
+
}
|
|
747
|
+
if (only.kind !== "return") {
|
|
748
|
+
return undefined;
|
|
749
|
+
}
|
|
750
|
+
if (!only.value) {
|
|
751
|
+
return fn.result ? undefined : {};
|
|
752
|
+
}
|
|
753
|
+
return only.value.kind === "constant" ? { value: only.value } : undefined;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
/** The path a load or borrow reads through. */
|
|
757
|
+
const placePath = (value: CoreExpression): CorePath | undefined => {
|
|
758
|
+
if (value.kind === "load") {
|
|
759
|
+
return value.path ?? [];
|
|
760
|
+
}
|
|
761
|
+
return value.kind === "borrow" ? value.place.path : undefined;
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
/** Arguments that reading cannot fault: loads, borrows and constants, without arithmetic in their indexes. */
|
|
765
|
+
const plainArgument = (value: CoreExpression): boolean => {
|
|
766
|
+
if (value.kind === "constant") {
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
return (
|
|
770
|
+
placePath(value)?.every(
|
|
771
|
+
(segment) => segment.kind === "field" || plainArgument(segment.value),
|
|
772
|
+
) ?? false
|
|
773
|
+
);
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Replaces each call of a routine that only returns a constant with an assignment of that
|
|
778
|
+
* constant, and drops each call of one that does nothing. A call whose arguments compute
|
|
779
|
+
* something stays, so evaluating them can still fault as it would have. Routines no call
|
|
780
|
+
* reaches any more, other than program entries, are dropped.
|
|
781
|
+
*/
|
|
782
|
+
export function foldConstantRoutines(core: VerifiedCoreModule): {
|
|
783
|
+
core: VerifiedCoreModule;
|
|
784
|
+
routines: ReadonlySet<string>;
|
|
785
|
+
} {
|
|
786
|
+
const entries = new Set(core.programs.map((program) => program.entry));
|
|
787
|
+
const constants = new Map(
|
|
788
|
+
core.functions.flatMap((fn) => {
|
|
789
|
+
const result = entries.has(fn.id) ? undefined : constantResult(fn);
|
|
790
|
+
return result ? [[fn.id, result] as const] : [];
|
|
791
|
+
}),
|
|
792
|
+
);
|
|
793
|
+
if (!constants.size) {
|
|
794
|
+
return { core, routines: new Set() };
|
|
795
|
+
}
|
|
796
|
+
const called = new Set<string>();
|
|
797
|
+
const fold = (items: readonly CoreStatement[]): CoreStatement[] =>
|
|
798
|
+
items.flatMap((item): CoreStatement[] => {
|
|
799
|
+
if (item.kind === "invoke") {
|
|
800
|
+
const result = constants.get(item.function);
|
|
801
|
+
if (!result || !item.arguments.every(plainArgument)) {
|
|
802
|
+
called.add(item.function);
|
|
803
|
+
return [item];
|
|
804
|
+
}
|
|
805
|
+
if (item.destination === undefined || !result.value) {
|
|
806
|
+
return [];
|
|
807
|
+
}
|
|
808
|
+
return [
|
|
809
|
+
{
|
|
810
|
+
kind: "assign",
|
|
811
|
+
span: item.span,
|
|
812
|
+
root: item.destination,
|
|
813
|
+
value: { ...result.value, span: item.span },
|
|
814
|
+
},
|
|
815
|
+
];
|
|
816
|
+
}
|
|
817
|
+
switch (item.kind) {
|
|
818
|
+
case "if":
|
|
819
|
+
return [
|
|
820
|
+
{
|
|
821
|
+
...item,
|
|
822
|
+
// biome-ignore lint/suspicious/noThenProperty: PLC branch data is an array, not a thenable callback.
|
|
823
|
+
then: fold(item.then),
|
|
824
|
+
else: fold(item.else),
|
|
825
|
+
},
|
|
826
|
+
];
|
|
827
|
+
case "switch":
|
|
828
|
+
return [
|
|
829
|
+
{
|
|
830
|
+
...item,
|
|
831
|
+
cases: item.cases.map((branch) => ({
|
|
832
|
+
...branch,
|
|
833
|
+
body: fold(branch.body),
|
|
834
|
+
})),
|
|
835
|
+
fallback: fold(item.fallback),
|
|
836
|
+
},
|
|
837
|
+
];
|
|
838
|
+
case "for":
|
|
839
|
+
return [{ ...item, body: fold(item.body) }];
|
|
840
|
+
default:
|
|
841
|
+
return [item];
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
const functions = core.functions.map((fn) => ({
|
|
845
|
+
...fn,
|
|
846
|
+
body: fold(fn.body),
|
|
847
|
+
}));
|
|
848
|
+
const blocks = core.blocks.map(
|
|
849
|
+
(block): CoreFunctionBlock => ({ ...block, body: fold(block.body) }),
|
|
850
|
+
);
|
|
851
|
+
const routines = new Set(
|
|
852
|
+
[...constants.keys()].filter((id) => !called.has(id)),
|
|
853
|
+
);
|
|
854
|
+
return {
|
|
855
|
+
core: admitCore({
|
|
856
|
+
...core,
|
|
857
|
+
functions: functions.filter((fn) => !routines.has(fn.id)),
|
|
858
|
+
blocks,
|
|
859
|
+
}),
|
|
860
|
+
routines,
|
|
861
|
+
};
|
|
862
|
+
}
|