@tsplc/compiler 0.5.8 → 0.5.9

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/src/ir/index.ts CHANGED
@@ -42,7 +42,14 @@ export {
42
42
  nanosecondsPerMillisecond,
43
43
  } from "./domains";
44
44
  export { fold } from "./fold";
45
- export { errorName, httpErrors, jobError, jobErrors } from "./job-errors";
45
+ export { identityDigest } from "./identity";
46
+ export {
47
+ errorName,
48
+ httpErrors,
49
+ jobError,
50
+ jobErrors,
51
+ reservedErrors,
52
+ } from "./job-errors";
46
53
  export { layoutIssue, maxNestingDepth, maxScalarElements } from "./layouts";
47
54
  export {
48
55
  type Artifact,
@@ -91,7 +98,6 @@ export {
91
98
  export { scalarIssue } from "./scalars";
92
99
  export {
93
100
  foldConstantRoutines,
94
- joinPrograms,
95
101
  type SharedRoutines,
96
102
  shareRoutines,
97
103
  } from "./share";
@@ -7,11 +7,20 @@ export const jobError = {
7
7
  network: 5,
8
8
  tls: 6,
9
9
  noRequestSlot: 7,
10
+ /**
11
+ * An online change replaced the code of a job that was running: its step and stored state
12
+ * were made for the old code, so it stops instead of resuming in the new. Like `cancelled`,
13
+ * it skips `catch`, so a retry can't send a request twice.
14
+ */
15
+ codeChanged: 11001,
10
16
  } as const;
11
17
 
12
18
  /** An HTTP response fails a job with `base` + its status, up to `last`. */
13
19
  export const httpErrors = { base: 10000, last: 10999 };
14
20
 
21
+ /** Codes tsPLC itself reports from 11000 on, which a program's own `throw` may not use. */
22
+ export const reservedErrors = { first: 11000, last: 11099 };
23
+
15
24
  /** Job error codes, as every generated async block and service call reports them. */
16
25
  export const jobErrors: Record<string, string> = {
17
26
  [jobError.cancelled]: "cancelled",
@@ -21,6 +30,8 @@ export const jobErrors: Record<string, string> = {
21
30
  [jobError.network]: "network error or server restarted",
22
31
  [jobError.tls]: "TLS error",
23
32
  [jobError.noRequestSlot]: "no free request slot",
33
+ [jobError.codeChanged]:
34
+ "an online change replaced the job's code while it ran",
24
35
  [httpErrors.base]: "HTTP status: 10000 + status code",
25
36
  };
26
37
 
@@ -29,5 +40,8 @@ export const errorName = (code: number): string | undefined => {
29
40
  if (code > httpErrors.base && code <= httpErrors.last) {
30
41
  return `HTTP ${code - httpErrors.base}`;
31
42
  }
43
+ if (code >= reservedErrors.first && code <= reservedErrors.last) {
44
+ return jobErrors[code];
45
+ }
32
46
  return code < httpErrors.base ? jobErrors[code] : undefined;
33
47
  };
package/src/ir/share.ts CHANGED
@@ -681,58 +681,6 @@ const returns = (items: readonly CoreStatement[]): boolean =>
681
681
  (item) => item.kind === "return" || nestedBodies(item).some(returns),
682
682
  );
683
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
684
  /** A routine that only returns a constant, or does nothing: what each of its calls amounts to. */
737
685
  function constantResult(
738
686
  fn: CoreFunction,