@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
|
@@ -1,33 +1,48 @@
|
|
|
1
|
-
import { runtimeSources } from "./module-graph.ts";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
import { createRequire } from "node:module";
|
|
4
1
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
5
3
|
import { dirname, join, relative, resolve } from "node:path";
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
|
|
4
|
+
import { type Diagnostic, hasErrors, type PlcModule } from "@tsplc/compiler/ir";
|
|
5
|
+
import ts from "typescript";
|
|
9
6
|
import { Analyzer, suppressionDiagnostics } from "./analyzer.ts";
|
|
7
|
+
import { type AsyncLowering, lowerAsync } from "./async.ts";
|
|
8
|
+
import { lowerEnvironment } from "./configuration.ts";
|
|
9
|
+
import { lowerConstFunctions } from "./const-functions.ts";
|
|
10
|
+
import { lowerElaboration } from "./elaborate/index.ts";
|
|
10
11
|
import { lowerExposure } from "./exposure.ts";
|
|
12
|
+
import { runtimeSources } from "./module-graph.ts";
|
|
13
|
+
import { type Mapped, Positions, sourceSpan } from "./positions.ts";
|
|
14
|
+
import { lowerPromises } from "./promises.ts";
|
|
15
|
+
import { inSdk, sdkFor } from "./sdk.ts";
|
|
11
16
|
import {
|
|
12
17
|
lowerServices,
|
|
13
|
-
serviceRecords,
|
|
14
18
|
type ServiceOptions,
|
|
19
|
+
serviceRecords,
|
|
15
20
|
} from "./services.ts";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
|
|
22
|
+
/** The host environment a compilation reads, as `env()` values and endpoint settings. */
|
|
23
|
+
export type CompileEnvironment = Readonly<Record<string, string | undefined>>;
|
|
24
|
+
|
|
25
|
+
/** What a compilation writes or adds to help debug the compiler itself. */
|
|
26
|
+
export interface CompileDebug {
|
|
27
|
+
/** Writes every module the compiler generates or rewrites here, as the next step reads it. */
|
|
28
|
+
lowered: string | null;
|
|
29
|
+
/** Adds stack traces to elaboration errors. */
|
|
30
|
+
stackTraces: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The documented switches: `TSPLC_LOWERED=<directory>` and `TSPLC_DEBUG=1`. */
|
|
34
|
+
const compileDebug = (environment: CompileEnvironment): CompileDebug => ({
|
|
35
|
+
lowered: environment.TSPLC_LOWERED || null,
|
|
36
|
+
stackTraces: Boolean(environment.TSPLC_DEBUG),
|
|
37
|
+
});
|
|
23
38
|
|
|
24
39
|
export interface FrontendOptions {
|
|
25
40
|
sourceScope?: "project" | "entry";
|
|
26
41
|
services?: ServiceOptions;
|
|
27
|
-
/** What the program's `env()` calls read; `process.env` when omitted. The CLI passes its target's. */
|
|
28
|
-
env?: Environment;
|
|
29
42
|
tsconfig: string;
|
|
30
43
|
programs: Readonly<Record<string, { module: string; export: string }>>;
|
|
44
|
+
/** What `env()` reads, and the debug switches; this process's environment by default. */
|
|
45
|
+
environment?: CompileEnvironment;
|
|
31
46
|
}
|
|
32
47
|
|
|
33
48
|
export interface FrontendResult {
|
|
@@ -72,6 +87,8 @@ export const typeCheckOnly: ts.CompilerOptions = {
|
|
|
72
87
|
};
|
|
73
88
|
|
|
74
89
|
export function analyze(options: FrontendOptions): FrontendResult {
|
|
90
|
+
const environment = options.environment ?? { ...process.env };
|
|
91
|
+
const debug = compileDebug(environment);
|
|
75
92
|
const filename = resolve(options.tsconfig);
|
|
76
93
|
const config = ts.readConfigFile(filename, ts.sys.readFile);
|
|
77
94
|
if (config.error) {
|
|
@@ -123,7 +140,10 @@ export function analyze(options: FrontendOptions): FrontendResult {
|
|
|
123
140
|
delete compilerOptions.outDir;
|
|
124
141
|
const sdk = sdkFor(filename, compilerOptions);
|
|
125
142
|
const rootNames = [...new Set([...projectFiles, ...programFiles, sdk])];
|
|
126
|
-
|
|
143
|
+
const virtualSources = new Map<string, string>();
|
|
144
|
+
// Lowering also adds modules, such as the service client, that exist only here.
|
|
145
|
+
const host = loweringHost(compilerOptions, virtualSources);
|
|
146
|
+
let program = ts.createProgram(rootNames, compilerOptions, host);
|
|
127
147
|
const plcFiles = (program: ts.Program) => {
|
|
128
148
|
const files = new Set(runtimeSources(program));
|
|
129
149
|
for (const source of program.getSourceFiles()) {
|
|
@@ -153,9 +173,6 @@ export function analyze(options: FrontendOptions): FrontendResult {
|
|
|
153
173
|
) {
|
|
154
174
|
return { diagnostics };
|
|
155
175
|
}
|
|
156
|
-
const virtualSources = new Map<string, string>();
|
|
157
|
-
// Lowering also adds modules, such as the service client, that exist only here.
|
|
158
|
-
let host: ts.CompilerHost = ts.createCompilerHost(compilerOptions);
|
|
159
176
|
const apply = (lowering: {
|
|
160
177
|
sources: Map<string, Mapped>;
|
|
161
178
|
diagnostics: Diagnostic[];
|
|
@@ -177,28 +194,19 @@ export function analyze(options: FrontendOptions): FrontendResult {
|
|
|
177
194
|
for (const [path, text] of lowering.sources) {
|
|
178
195
|
virtualSources.set(path, text.text);
|
|
179
196
|
}
|
|
180
|
-
|
|
181
|
-
const dump = process.env.TSPLC_LOWERED;
|
|
182
|
-
if (dump) {
|
|
197
|
+
if (debug.lowered) {
|
|
183
198
|
for (const [path, text] of lowering.sources) {
|
|
184
|
-
const target = join(
|
|
199
|
+
const target = join(debug.lowered, relative(dirname(filename), path));
|
|
185
200
|
mkdirSync(dirname(target), { recursive: true });
|
|
186
201
|
writeFileSync(target, text.text);
|
|
187
202
|
}
|
|
188
203
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
// Generated modules can live in a directory that only exists in memory.
|
|
196
|
-
host.directoryExists = (path) =>
|
|
197
|
-
[...virtualSources.keys()].some((file) =>
|
|
198
|
-
file.startsWith(`${path.replace(/\/$/, "")}/`),
|
|
199
|
-
) ||
|
|
200
|
-
(directoryExists?.(path) ?? true);
|
|
201
|
-
program = ts.createProgram(rootNames, compilerOptions, host);
|
|
204
|
+
program = ts.createProgram({
|
|
205
|
+
rootNames,
|
|
206
|
+
options: compilerOptions,
|
|
207
|
+
host,
|
|
208
|
+
oldProgram: program,
|
|
209
|
+
});
|
|
202
210
|
diagnostics.push(...sourceDiagnostics(program));
|
|
203
211
|
}
|
|
204
212
|
return true;
|
|
@@ -209,6 +217,7 @@ export function analyze(options: FrontendOptions): FrontendResult {
|
|
|
209
217
|
options.programs,
|
|
210
218
|
dirname(filename),
|
|
211
219
|
positions,
|
|
220
|
+
debug,
|
|
212
221
|
);
|
|
213
222
|
if (!apply(elaboration)) {
|
|
214
223
|
return { diagnostics };
|
|
@@ -221,11 +230,7 @@ export function analyze(options: FrontendOptions): FrontendResult {
|
|
|
221
230
|
if (!apply(exposure)) {
|
|
222
231
|
return { diagnostics };
|
|
223
232
|
}
|
|
224
|
-
if (
|
|
225
|
-
!apply(
|
|
226
|
-
lowerEnvironment(program, sdk, positions, options.env ?? process.env),
|
|
227
|
-
)
|
|
228
|
-
) {
|
|
233
|
+
if (!apply(lowerEnvironment(program, sdk, positions, environment))) {
|
|
229
234
|
return { diagnostics };
|
|
230
235
|
}
|
|
231
236
|
if (!apply(lowerConstFunctions(program, positions))) {
|
|
@@ -260,6 +265,51 @@ export function analyze(options: FrontendOptions): FrontendResult {
|
|
|
260
265
|
return hasErrors(diagnostics) ? { diagnostics } : { module, diagnostics };
|
|
261
266
|
}
|
|
262
267
|
|
|
268
|
+
/**
|
|
269
|
+
* The compiler host of every lowering pass: lowered and generated modules are read from
|
|
270
|
+
* `virtualSources`, and everything else from disk. Each pass builds a new program, so the host
|
|
271
|
+
* parses a file again only when its text changed, and the program reuses its predecessor's module
|
|
272
|
+
* structure; a pass then costs its type check rather than reparsing thousands of declarations.
|
|
273
|
+
*/
|
|
274
|
+
function loweringHost(
|
|
275
|
+
options: ts.CompilerOptions,
|
|
276
|
+
virtualSources: ReadonlyMap<string, string>,
|
|
277
|
+
): ts.CompilerHost {
|
|
278
|
+
const host = ts.createCompilerHost(options);
|
|
279
|
+
const read = host.readFile;
|
|
280
|
+
const exists = host.fileExists;
|
|
281
|
+
const directoryExists = host.directoryExists?.bind(host);
|
|
282
|
+
const parse = host.getSourceFile;
|
|
283
|
+
host.readFile = (path) => virtualSources.get(path) ?? read(path);
|
|
284
|
+
host.fileExists = (path) => virtualSources.has(path) || exists(path);
|
|
285
|
+
// Generated modules can live in a directory that only exists in memory.
|
|
286
|
+
host.directoryExists = (path) =>
|
|
287
|
+
[...virtualSources.keys()].some((file) =>
|
|
288
|
+
file.startsWith(`${path.replace(/\/$/, "")}/`),
|
|
289
|
+
) ||
|
|
290
|
+
(directoryExists?.(path) ?? true);
|
|
291
|
+
const parsed = new Map<string, ts.SourceFile>();
|
|
292
|
+
host.getSourceFile = (fileName, version, onError, createNew) => {
|
|
293
|
+
const key = `${fileName}\0${typeof version === "object" ? `${version.languageVersion}:${version.impliedNodeFormat}` : version}`;
|
|
294
|
+
const known = parsed.get(key);
|
|
295
|
+
const lowered = virtualSources.get(fileName);
|
|
296
|
+
// A rewritten module never returns to its file on disk, so a file without lowered text is unchanged.
|
|
297
|
+
if (
|
|
298
|
+
known &&
|
|
299
|
+
!createNew &&
|
|
300
|
+
(lowered === undefined || known.text === lowered)
|
|
301
|
+
) {
|
|
302
|
+
return known;
|
|
303
|
+
}
|
|
304
|
+
const file = parse(fileName, version, onError, createNew);
|
|
305
|
+
if (file) {
|
|
306
|
+
parsed.set(key, file);
|
|
307
|
+
}
|
|
308
|
+
return file;
|
|
309
|
+
};
|
|
310
|
+
return host;
|
|
311
|
+
}
|
|
312
|
+
|
|
263
313
|
/**
|
|
264
314
|
* The lowerings record what they generated by `<file>:<name>`. The analyzed model's
|
|
265
315
|
* spans point at the user's files, but its ids still start with the lowered module
|
package/src/index.ts
CHANGED
package/src/ir/aggregates.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
2
|
+
import { calendarZero, domainConstantFits, domainIssue } from "./domains.ts";
|
|
1
3
|
import {
|
|
2
|
-
comparisonOperators,
|
|
3
4
|
type Constant,
|
|
5
|
+
comparisonOperators,
|
|
4
6
|
type Expression,
|
|
5
|
-
type Variable,
|
|
6
7
|
type Place,
|
|
8
|
+
type Variable,
|
|
7
9
|
} from "./model.ts";
|
|
8
10
|
import { constantFits, type IntegerInterval } from "./numeric.ts";
|
|
9
11
|
import { interval } from "./ranges.ts";
|
|
10
12
|
import { scalarIssue } from "./scalars.ts";
|
|
11
|
-
import { calendarZero, domainConstantFits, domainIssue } from "./domains.ts";
|
|
12
13
|
import type { PlcType } from "./types.ts";
|
|
13
14
|
|
|
14
15
|
export function aggregate(type: PlcType | undefined): boolean {
|
package/src/ir/allocation.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
2
2
|
import type { ModuleDeclarations } from "./declarations.ts";
|
|
3
3
|
import { maxNestingDepth, maxScalarElements } from "./layouts.ts";
|
|
4
|
+
import type { PlcModule } from "./model.ts";
|
|
4
5
|
import { reject } from "./normalization-error.ts";
|
|
5
6
|
import { instancedBlock } from "./types.ts";
|
|
6
7
|
|
package/src/ir/core-model.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { SourceSpan } from "./diagnostics.ts";
|
|
2
2
|
import type {
|
|
3
|
-
Variable,
|
|
4
|
-
Constant,
|
|
5
3
|
BinaryOperator,
|
|
4
|
+
Constant,
|
|
6
5
|
FunctionBlock,
|
|
7
|
-
|
|
6
|
+
MethodOwner,
|
|
8
7
|
PlcFunction,
|
|
9
8
|
PlcModule,
|
|
10
|
-
|
|
9
|
+
PlcProgram,
|
|
11
10
|
TelemetryCall,
|
|
11
|
+
Variable,
|
|
12
12
|
} from "./model.ts";
|
|
13
13
|
import type { PlcType } from "./types.ts";
|
|
14
14
|
|
|
@@ -32,7 +32,11 @@ export type CoreExpression = {
|
|
|
32
32
|
| {
|
|
33
33
|
readonly kind: "unary";
|
|
34
34
|
readonly operator:
|
|
35
|
-
|
|
35
|
+
| "not"
|
|
36
|
+
| "negate"
|
|
37
|
+
| "bitNot"
|
|
38
|
+
| "timeToMilliseconds"
|
|
39
|
+
| "clock";
|
|
36
40
|
readonly operand: CoreExpression;
|
|
37
41
|
}
|
|
38
42
|
| {
|
|
@@ -118,6 +122,33 @@ export const nestedBodies = (
|
|
|
118
122
|
}
|
|
119
123
|
return [];
|
|
120
124
|
};
|
|
125
|
+
/**
|
|
126
|
+
* The storage roots a statement writes itself, in statement order: an assignment's target, a
|
|
127
|
+
* loop's counter, a call's destination and every place it borrows. Nested bodies and the
|
|
128
|
+
* routines a call runs are the caller's to follow.
|
|
129
|
+
*/
|
|
130
|
+
export const directWrites = (item: CoreStatement): readonly string[] => {
|
|
131
|
+
if (item.kind === "assign") {
|
|
132
|
+
return [item.root];
|
|
133
|
+
}
|
|
134
|
+
if (item.kind === "for") {
|
|
135
|
+
return [item.counter];
|
|
136
|
+
}
|
|
137
|
+
if (item.kind === "invoke") {
|
|
138
|
+
return [
|
|
139
|
+
...(item.destination ? [item.destination] : []),
|
|
140
|
+
...item.arguments.flatMap((argument) =>
|
|
141
|
+
argument.kind === "borrow" ? [argument.place.root] : [],
|
|
142
|
+
),
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
if (item.kind === "blockUpdate") {
|
|
146
|
+
return Object.values(item.inputs).flatMap((input) =>
|
|
147
|
+
input.kind === "borrow" ? [input.place.root] : [],
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
return [];
|
|
151
|
+
};
|
|
121
152
|
export interface CoreFunction {
|
|
122
153
|
readonly owner?: MethodOwner;
|
|
123
154
|
readonly origin?: PlcFunction["origin"];
|
|
@@ -129,9 +160,8 @@ export interface CoreFunction {
|
|
|
129
160
|
readonly body: readonly CoreStatement[];
|
|
130
161
|
readonly span: SourceSpan;
|
|
131
162
|
}
|
|
132
|
-
export interface CoreFunctionBlock
|
|
133
|
-
Omit<FunctionBlock, "body"
|
|
134
|
-
> {
|
|
163
|
+
export interface CoreFunctionBlock
|
|
164
|
+
extends Readonly<Omit<FunctionBlock, "body">> {
|
|
135
165
|
readonly body: readonly CoreStatement[];
|
|
136
166
|
}
|
|
137
167
|
export const verified: unique symbol = Symbol("verified core");
|
package/src/ir/declarations.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import { valueFits } from "./aggregates.ts";
|
|
1
2
|
import type { SourceSpan } from "./diagnostics.ts";
|
|
3
|
+
import { admitLayouts } from "./layouts.ts";
|
|
2
4
|
import {
|
|
3
|
-
standardBlocks,
|
|
4
|
-
type PlcModule,
|
|
5
|
-
type Variable,
|
|
6
5
|
type FunctionBlock,
|
|
7
6
|
type PlcFunction,
|
|
7
|
+
type PlcModule,
|
|
8
8
|
type StandardBlock,
|
|
9
|
+
standardBlocks,
|
|
10
|
+
type Variable,
|
|
9
11
|
} from "./model.ts";
|
|
10
|
-
import { instancedBlock, type PlcType } from "./types.ts";
|
|
11
|
-
import { valueFits } from "./aggregates.ts";
|
|
12
|
-
import { admitLayouts } from "./layouts.ts";
|
|
13
12
|
import { reject } from "./normalization-error.ts";
|
|
13
|
+
import { instancedBlock, type PlcType } from "./types.ts";
|
|
14
14
|
|
|
15
15
|
const matchesPorts = (
|
|
16
16
|
variables: readonly Variable[],
|
|
@@ -204,12 +204,12 @@ export class ModuleDeclarations {
|
|
|
204
204
|
const type = this.types.get(id);
|
|
205
205
|
return Boolean(
|
|
206
206
|
type &&
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
207
|
+
type.kind !== "block" &&
|
|
208
|
+
(type.kind !== "record" ||
|
|
209
|
+
type.fields.every(
|
|
210
|
+
(field) => !field.mode && this.isValueType(field.type, seen),
|
|
211
|
+
)) &&
|
|
212
|
+
(type.kind !== "array" || this.isValueType(type.element, seen)),
|
|
213
213
|
);
|
|
214
214
|
}
|
|
215
215
|
|
package/src/ir/domains.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { elementaryType, integerRange } from "@tsplc/iec";
|
|
2
2
|
import {
|
|
3
|
-
comparisonOperators,
|
|
4
3
|
type Constant,
|
|
4
|
+
comparisonOperators,
|
|
5
5
|
type Expression,
|
|
6
6
|
} from "./model.ts";
|
|
7
7
|
import { canonicalInteger, exactDecimal } from "./numeric.ts";
|
|
@@ -68,10 +68,10 @@ function validDate(text: string): boolean {
|
|
|
68
68
|
];
|
|
69
69
|
return Boolean(
|
|
70
70
|
length &&
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
day >= 1 &&
|
|
72
|
+
day <= length &&
|
|
73
|
+
text >= calendarZero.date &&
|
|
74
|
+
text <= latestDate,
|
|
75
75
|
);
|
|
76
76
|
}
|
|
77
77
|
function validClock(text: string, milliseconds: boolean): boolean {
|
|
@@ -82,9 +82,9 @@ function validClock(text: string, milliseconds: boolean): boolean {
|
|
|
82
82
|
).exec(text);
|
|
83
83
|
return Boolean(
|
|
84
84
|
match &&
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
Number(match[1]) < 24 &&
|
|
86
|
+
Number(match[2]) < 60 &&
|
|
87
|
+
Number(match[3]) < 60,
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
90
|
export function calendarLiteral(
|
package/src/ir/fold.ts
CHANGED
package/src/ir/index.ts
CHANGED
|
@@ -1,24 +1,44 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
aggregate,
|
|
3
|
+
aggregateIssue,
|
|
4
|
+
defaultValue,
|
|
5
|
+
expressionIssue,
|
|
6
|
+
placeType,
|
|
7
|
+
valueFits,
|
|
8
|
+
} from "./aggregates.ts";
|
|
9
|
+
export {
|
|
10
|
+
type CheckedPlace,
|
|
11
|
+
type CoreExpression,
|
|
12
|
+
type CoreFunction,
|
|
13
|
+
type CoreFunctionBlock,
|
|
14
|
+
type CorePath,
|
|
15
|
+
type CoreStatement,
|
|
16
|
+
directWrites,
|
|
17
|
+
nestedBodies,
|
|
18
|
+
type VerifiedCoreModule,
|
|
19
|
+
} from "./core-model.ts";
|
|
2
20
|
export {
|
|
3
21
|
type Diagnostic,
|
|
4
|
-
type SourceSpan,
|
|
5
22
|
error,
|
|
6
23
|
formatDiagnostic,
|
|
7
24
|
hasErrors,
|
|
25
|
+
type SourceSpan,
|
|
8
26
|
} from "./diagnostics.ts";
|
|
9
27
|
export {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from "./
|
|
28
|
+
calendarLiteral,
|
|
29
|
+
domainConstantFits,
|
|
30
|
+
domainIssue,
|
|
31
|
+
durationLiteral,
|
|
32
|
+
nanosecondsPerMillisecond,
|
|
33
|
+
} from "./domains.ts";
|
|
34
|
+
export { fold } from "./fold.ts";
|
|
35
|
+
export { errorName, httpErrors, jobError, jobErrors } from "./job-errors.ts";
|
|
36
|
+
export { layoutIssue, maxNestingDepth, maxScalarElements } from "./layouts.ts";
|
|
18
37
|
export {
|
|
19
38
|
type Artifact,
|
|
20
39
|
type BinaryOperator,
|
|
21
40
|
type Constant,
|
|
41
|
+
comparisonOperators,
|
|
22
42
|
type Deployment,
|
|
23
43
|
type EmitResult,
|
|
24
44
|
type Expression,
|
|
@@ -32,36 +52,30 @@ export {
|
|
|
32
52
|
type PlcProgram,
|
|
33
53
|
type StandardBlock,
|
|
34
54
|
type Statement,
|
|
55
|
+
standardBlocks,
|
|
35
56
|
type Task,
|
|
36
57
|
type TelemetryCall,
|
|
37
|
-
type Variable,
|
|
38
|
-
comparisonOperators,
|
|
39
|
-
standardBlocks,
|
|
40
58
|
telemetryOperands,
|
|
59
|
+
type Variable,
|
|
41
60
|
} from "./model.ts";
|
|
61
|
+
export { isVerifiedCore, normalizeModule } from "./normalize.ts";
|
|
42
62
|
export {
|
|
43
|
-
type CheckedPlace,
|
|
44
|
-
type CoreExpression,
|
|
45
|
-
type CoreFunction,
|
|
46
|
-
type CoreFunctionBlock,
|
|
47
|
-
type CorePath,
|
|
48
|
-
type CoreStatement,
|
|
49
|
-
type VerifiedCoreModule,
|
|
50
|
-
nestedBodies,
|
|
51
|
-
} from "./core-model.ts";
|
|
52
|
-
export {
|
|
53
|
-
type IntegerInterval,
|
|
54
63
|
applyIntegerPolicy,
|
|
55
64
|
canAssign,
|
|
56
65
|
constantFits,
|
|
57
66
|
floatMaximum,
|
|
67
|
+
type IntegerInterval,
|
|
58
68
|
integerType,
|
|
59
69
|
parseInteger,
|
|
60
70
|
roundFloat,
|
|
61
71
|
saturateFloat,
|
|
62
72
|
wrapsNatively,
|
|
63
73
|
} from "./numeric.ts";
|
|
64
|
-
export {
|
|
74
|
+
export {
|
|
75
|
+
pathIndexes,
|
|
76
|
+
statementExpressions,
|
|
77
|
+
subexpressions,
|
|
78
|
+
} from "./operands.ts";
|
|
65
79
|
export {
|
|
66
80
|
interval,
|
|
67
81
|
loopBounds,
|
|
@@ -72,19 +86,18 @@ export {
|
|
|
72
86
|
} from "./ranges.ts";
|
|
73
87
|
export { scalarIssue } from "./scalars.ts";
|
|
74
88
|
export {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
} from "./aggregates.ts";
|
|
82
|
-
export { layoutIssue, maxNestingDepth, maxScalarElements } from "./layouts.ts";
|
|
89
|
+
foldConstantRoutines,
|
|
90
|
+
joinPrograms,
|
|
91
|
+
type SharedRoutines,
|
|
92
|
+
shareRoutines,
|
|
93
|
+
} from "./share.ts";
|
|
94
|
+
export { forwardTemporaries } from "./temporaries.ts";
|
|
83
95
|
export {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
type Field,
|
|
97
|
+
instancedBlock,
|
|
98
|
+
integerRange,
|
|
99
|
+
type PlcType,
|
|
100
|
+
primitiveTypes,
|
|
101
|
+
type SymbolId,
|
|
102
|
+
type TypeId,
|
|
103
|
+
} from "./types.ts";
|
package/src/ir/job-errors.ts
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
|
-
/** Job error codes, as
|
|
2
|
-
export const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
1
|
+
/** Job error codes by meaning, as generated async blocks and service calls set them. */
|
|
2
|
+
export const jobError = {
|
|
3
|
+
cancelled: 1,
|
|
4
|
+
timeout: 2,
|
|
5
|
+
tooLarge: 3,
|
|
6
|
+
malformedResponse: 4,
|
|
7
|
+
network: 5,
|
|
8
|
+
tls: 6,
|
|
9
|
+
noRequestSlot: 7,
|
|
10
|
+
} as const;
|
|
12
11
|
|
|
13
12
|
/** An HTTP response fails a job with `base` + its status, up to `last`. */
|
|
14
13
|
export const httpErrors = { base: 10000, last: 10999 };
|
|
15
14
|
|
|
15
|
+
/** Job error codes, as every generated async block and service call reports them. */
|
|
16
|
+
export const jobErrors: Record<string, string> = {
|
|
17
|
+
[jobError.cancelled]: "cancelled",
|
|
18
|
+
[jobError.timeout]: "timeout",
|
|
19
|
+
[jobError.tooLarge]: "request or response too large to encode",
|
|
20
|
+
[jobError.malformedResponse]: "malformed response",
|
|
21
|
+
[jobError.network]: "network error or server restarted",
|
|
22
|
+
[jobError.tls]: "TLS error",
|
|
23
|
+
[jobError.noRequestSlot]: "no free request slot",
|
|
24
|
+
[httpErrors.base]: "HTTP status: 10000 + status code",
|
|
25
|
+
};
|
|
26
|
+
|
|
16
27
|
/** What a telemetry exception record calls an error code: its meaning when it is a job error. */
|
|
17
28
|
export const errorName = (code: number): string | undefined => {
|
|
18
29
|
if (code > httpErrors.base && code <= httpErrors.last) {
|
package/src/ir/layouts.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
1
2
|
import { elementaryType, integerRange } from "@tsplc/iec";
|
|
2
|
-
import { constantFits } from "./numeric.ts";
|
|
3
3
|
import { InvalidCore, reject } from "./normalization-error.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { constantFits } from "./numeric.ts";
|
|
5
|
+
import { type PlcType, primitiveTypes } from "./types.ts";
|
|
5
6
|
|
|
6
7
|
/** The finite storage budget: scalar elements in one layout or allocation, and nesting depth. */
|
|
7
8
|
export const maxScalarElements = 1_000_000;
|
package/src/ir/link.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
2
2
|
import {
|
|
3
|
-
nestedBodies,
|
|
4
3
|
type CoreFunction,
|
|
5
4
|
type CoreFunctionBlock,
|
|
6
5
|
type CoreStatement,
|
|
6
|
+
directWrites,
|
|
7
|
+
nestedBodies,
|
|
7
8
|
} from "./core-model.ts";
|
|
8
9
|
import type { ModuleDeclarations } from "./declarations.ts";
|
|
10
|
+
import { type PlcModule, telemetryOperands } from "./model.ts";
|
|
9
11
|
import { reject } from "./normalization-error.ts";
|
|
10
12
|
import { instancedBlock, type PlcType } from "./types.ts";
|
|
11
13
|
|
|
@@ -158,28 +160,8 @@ const checkLoopCounterWrites = (
|
|
|
158
160
|
const result = new Set<string>();
|
|
159
161
|
const inspect = (body: readonly CoreStatement[]) => {
|
|
160
162
|
for (const item of body) {
|
|
161
|
-
|
|
162
|
-
result.add(
|
|
163
|
-
}
|
|
164
|
-
if (item.kind === "for") {
|
|
165
|
-
result.add(item.counter);
|
|
166
|
-
}
|
|
167
|
-
if (item.kind === "invoke") {
|
|
168
|
-
if (item.destination) {
|
|
169
|
-
result.add(item.destination);
|
|
170
|
-
}
|
|
171
|
-
for (const argument of item.arguments) {
|
|
172
|
-
if (argument.kind === "borrow") {
|
|
173
|
-
result.add(argument.place.root);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (item.kind === "blockUpdate") {
|
|
178
|
-
for (const input of Object.values(item.inputs)) {
|
|
179
|
-
if (input.kind === "borrow") {
|
|
180
|
-
result.add(input.place.root);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
163
|
+
for (const root of directWrites(item)) {
|
|
164
|
+
result.add(root);
|
|
183
165
|
}
|
|
184
166
|
for (const nested of nestedBodies(item)) {
|
|
185
167
|
inspect(nested);
|
package/src/ir/model.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Diagnostic, SourceSpan } from "./diagnostics.ts";
|
|
2
2
|
import type { PlcType, SymbolId, TypeId } from "./types.ts";
|
|
3
3
|
|
|
4
4
|
export type Constant =
|
|
@@ -37,7 +37,8 @@ export interface Variable {
|
|
|
37
37
|
export interface Place {
|
|
38
38
|
root: SymbolId;
|
|
39
39
|
path: readonly (
|
|
40
|
-
{ kind: "field"; name: string }
|
|
40
|
+
| { kind: "field"; name: string }
|
|
41
|
+
| { kind: "index"; value: Expression }
|
|
41
42
|
)[];
|
|
42
43
|
}
|
|
43
44
|
|