@tsplc/compiler 0.5.7 → 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.
Files changed (59) hide show
  1. package/dist/bun-runtime.js +8 -2
  2. package/dist/bun-runtime.js.map +3 -3
  3. package/dist/cli.js +17 -5
  4. package/dist/cli.js.map +5 -5
  5. package/dist/codesys.js +2933 -1724
  6. package/dist/codesys.js.map +20 -19
  7. package/dist/index.js +870 -685
  8. package/dist/index.js.map +20 -19
  9. package/dist/ir.js +1654 -1364
  10. package/dist/ir.js.map +16 -14
  11. package/dist/project.js +5 -2
  12. package/dist/project.js.map +3 -3
  13. package/dist/telemetry.js +8 -2
  14. package/dist/telemetry.js.map +3 -3
  15. package/package.json +9 -9
  16. package/src/codesys/debug.ts +17 -2
  17. package/src/codesys/emit.ts +34 -11
  18. package/src/codesys/engineering.ts +27 -12
  19. package/src/codesys/explain.ts +1465 -0
  20. package/src/codesys/global-lists.ts +21 -9
  21. package/src/codesys/http.ts +12 -0
  22. package/src/codesys/instrumentation.ts +131 -3
  23. package/src/codesys/manifest.ts +29 -12
  24. package/src/codesys/numeric.ts +5 -3
  25. package/src/codesys/plan.ts +31 -28
  26. package/src/codesys/programs.ts +63 -1
  27. package/src/codesys/types.ts +34 -12
  28. package/src/frontend/async.ts +14 -8
  29. package/src/frontend/coroutines.ts +55 -16
  30. package/src/frontend/elaborate/expressions.ts +10 -2
  31. package/src/frontend/elaborate/filtered-arrays.ts +5 -5
  32. package/src/frontend/elaborate/index.ts +42 -4
  33. package/src/frontend/elaborate/model.ts +48 -1
  34. package/src/frontend/elaborate/references.ts +6 -6
  35. package/src/frontend/elaborate/specialize.ts +18 -4
  36. package/src/frontend/elaborate/storage.ts +58 -2
  37. package/src/frontend/expressions.ts +2 -2
  38. package/src/frontend/generated-names.ts +95 -0
  39. package/src/frontend/intrinsics.ts +1 -2
  40. package/src/frontend/promise-chains.ts +22 -8
  41. package/src/frontend/promises.ts +8 -10
  42. package/src/frontend/statements.ts +3 -2
  43. package/src/frontend/tasks.ts +8 -8
  44. package/src/frontend/typescript.ts +5 -2
  45. package/src/ir/conditions.ts +895 -0
  46. package/src/ir/core-model.ts +2 -2
  47. package/src/ir/fold.ts +15 -107
  48. package/src/ir/identity.ts +9 -0
  49. package/src/ir/index.ts +18 -13
  50. package/src/ir/job-errors.ts +14 -0
  51. package/src/ir/link.ts +1 -0
  52. package/src/ir/model.ts +16 -79
  53. package/src/ir/numeric.ts +5 -41
  54. package/src/ir/ranges.ts +8 -14
  55. package/src/ir/scalars.ts +6 -4
  56. package/src/ir/share.ts +0 -52
  57. package/src/project/debugger.ts +9 -0
  58. package/src/project/project.ts +6 -0
  59. package/src/project/release.ts +7 -4
@@ -1,4 +1,5 @@
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
+ import { basename } from "node:path";
2
3
  import ts from "typescript";
3
4
  import type { CapturedPrimitive, CapturedValue } from "./capture-protocol";
4
5
  import type { EntryImports } from "./imports";
@@ -12,7 +13,7 @@ import {
12
13
  type Step,
13
14
  tsPath,
14
15
  } from "./model";
15
- import { referenceLayout, referenceType } from "./references";
16
+ import { referable, referenceLayout, referenceType } from "./references";
16
17
  import { constant, type Value } from "./values";
17
18
  import { ScanWrites } from "./writes";
18
19
 
@@ -110,9 +111,64 @@ export class Storage {
110
111
  const found =
111
112
  type !== undefined && referenceType(type) && this.written(holder, name);
112
113
  this.referenceFields.set(key, found);
114
+ if (found) {
115
+ this.references.push({ holder, name });
116
+ }
113
117
  return found;
114
118
  }
115
119
 
120
+ /** The fields that store a reference, found while laying out instances. */
121
+ private readonly references: { holder: ModelNode; name: string }[] = [];
122
+
123
+ /**
124
+ * Where each referable object is, in the storage spelling the debugger names module storage
125
+ * with, and the storage paths of fields that store a reference: the debugger shows a reference's
126
+ * id as the object it is. Empty when no field stores a reference.
127
+ */
128
+ referenceTable(): {
129
+ references: { id: number; path: string }[];
130
+ referenceFields: string[];
131
+ } {
132
+ if (!this.references.length) {
133
+ return { references: [], referenceFields: [] };
134
+ }
135
+ return {
136
+ references: this.model.nodes.flatMap((node) => {
137
+ const path = referable(node) ? this.storagePlace(node) : undefined;
138
+ return path === undefined ? [] : [{ id: node.reference, path }];
139
+ }),
140
+ referenceFields: this.references.flatMap(({ holder, name }) => {
141
+ const path = this.storagePlace(holder);
142
+ return path === undefined ? [] : [`${path}.${name}`];
143
+ }),
144
+ };
145
+ }
146
+
147
+ /** A node's place as module storage: its root's module, the root unless flattened, then fields and indexes. */
148
+ private storagePlace(node: ModelNode): string | undefined {
149
+ const owner = node.owner;
150
+ if (!owner) {
151
+ return undefined;
152
+ }
153
+ const root = this.flattened(owner.root)
154
+ ? owner.root.name
155
+ : `${owner.root.name}.${owner.root.name}`;
156
+ return (
157
+ root +
158
+ owner.steps
159
+ .map((step, index) => {
160
+ const holder = this.model.at(owner.root, owner.steps.slice(0, index));
161
+ if (step.kind === "index") {
162
+ return holder && this.mixedStates(holder)
163
+ ? `.${mixedItem(step.index)}`
164
+ : `[${step.index}]`;
165
+ }
166
+ return /^\d+$/.test(step.name) ? `[${step.name}]` : `.${step.name}`;
167
+ })
168
+ .join("")
169
+ );
170
+ }
171
+
116
172
  /** Asked of every field each time an instance's layout is, so answered once. */
117
173
  private readonly referenceFields = new Map<string, boolean>();
118
174
 
@@ -189,7 +245,7 @@ export class Storage {
189
245
  }
190
246
 
191
247
  private namespace(root: Root): string {
192
- const pascal = pascalCase(root.name);
248
+ const pascal = pascalCase(basename(this.rootModule(root), ".ts"));
193
249
  const name = this.typeNames.has(pascal) ? `${pascal}Root` : pascal;
194
250
  this.imports.namespaces.set(name, this.rootModule(root));
195
251
  return name;
@@ -1,7 +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
3
  import {
3
4
  aggregate,
4
- type BinaryOperator,
5
5
  type Constant,
6
6
  canAssign,
7
7
  comparisonOperators,
@@ -19,12 +19,12 @@ import {
19
19
  type PlcType,
20
20
  parseInteger,
21
21
  placeType,
22
- roundFloat,
23
22
  type SourceSpan,
24
23
  type Statement,
25
24
  type Variable,
26
25
  valueRange,
27
26
  } from "@tsplc/compiler/ir";
27
+ import { type BinaryOperator, roundFloat } from "@tsplc/iec/arithmetic";
28
28
  import ts from "typescript";
29
29
  import type { BlockResolver, BlockSource } from "./blocks";
30
30
  import { intrinsicExpression } from "./intrinsics";
@@ -0,0 +1,95 @@
1
+ import { relative } from "node:path";
2
+ import { identityDigest } from "@tsplc/compiler/ir";
3
+ import ts from "typescript";
4
+
5
+ /**
6
+ * Names for what lowering generates, each a fixed function of the source node it stands for: its
7
+ * module, the declarations around it, and its ordinal among the nodes with the same key in the
8
+ * innermost one. An edit elsewhere then never renames it, so an online change finds its state
9
+ * where it left it; counting generated objects across the program renamed them all.
10
+ */
11
+ export class GeneratedNames {
12
+ constructor(private readonly root: string) {}
13
+
14
+ /** `base` followed by the digest of `node`'s identity. */
15
+ name(base: string, node: ts.Node): string {
16
+ return `${base}_${identityDigest(this.identity(node))}`;
17
+ }
18
+
19
+ identity(node: ts.Node): string {
20
+ const source = node.getSourceFile();
21
+ const module = relative(this.root, source.fileName).replace(/\\/g, "/");
22
+ const scopes = enclosingDeclarations(node);
23
+ const scope = scopes.at(-1)?.node ?? source;
24
+ const key = nodeKey(node, source);
25
+ const ordinal = sameKey(scope, key, source).indexOf(node);
26
+ return [
27
+ module,
28
+ ...scopes.map((declaration) => declaration.name),
29
+ `${key}#${ordinal}`,
30
+ ].join("\0");
31
+ }
32
+ }
33
+
34
+ /** A call is told apart by its callee, a declaration by its name, anything else by its syntax. */
35
+ const nodeKey = (node: ts.Node, source: ts.SourceFile): string => {
36
+ if (ts.isCallExpression(node)) {
37
+ return `call ${node.expression.getText(source)}`;
38
+ }
39
+ const name = declarationName(node);
40
+ return name === undefined
41
+ ? ts.SyntaxKind[node.kind]
42
+ : `${ts.SyntaxKind[node.kind]} ${name}`;
43
+ };
44
+
45
+ /** The nodes under `scope` with `key`, in source order. */
46
+ const sameKey = (
47
+ scope: ts.Node,
48
+ key: string,
49
+ source: ts.SourceFile,
50
+ ): ts.Node[] => {
51
+ const found: ts.Node[] = [];
52
+ const visit = (node: ts.Node) => {
53
+ if (nodeKey(node, source) === key) {
54
+ found.push(node);
55
+ }
56
+ ts.forEachChild(node, visit);
57
+ };
58
+ ts.forEachChild(scope, visit);
59
+ return found;
60
+ };
61
+
62
+ const declarationName = (node: ts.Node): string | undefined => {
63
+ if (
64
+ (ts.isClassDeclaration(node) ||
65
+ ts.isFunctionDeclaration(node) ||
66
+ ts.isMethodDeclaration(node) ||
67
+ ts.isPropertyDeclaration(node) ||
68
+ ts.isGetAccessorDeclaration(node) ||
69
+ ts.isSetAccessorDeclaration(node) ||
70
+ ts.isVariableDeclaration(node) ||
71
+ ts.isInterfaceDeclaration(node) ||
72
+ ts.isTypeAliasDeclaration(node)) &&
73
+ node.name &&
74
+ (ts.isIdentifier(node.name) || ts.isStringLiteral(node.name))
75
+ ) {
76
+ return node.name.text;
77
+ }
78
+ if (ts.isConstructorDeclaration(node)) {
79
+ return "constructor";
80
+ }
81
+ return undefined;
82
+ };
83
+
84
+ /** The named declarations around `node`, outermost first. */
85
+ const enclosingDeclarations = (
86
+ node: ts.Node,
87
+ ): { name: string; node: ts.Node }[] => {
88
+ const parent = node.parent;
89
+ if (!parent || ts.isSourceFile(parent)) {
90
+ return [];
91
+ }
92
+ const name = declarationName(parent);
93
+ const outer = enclosingDeclarations(parent);
94
+ return name === undefined ? outer : [...outer, { name, node: parent }];
95
+ };
@@ -4,10 +4,9 @@ import {
4
4
  defaultValue,
5
5
  durationLiteral,
6
6
  type Expression,
7
- elementaryFunctions,
8
7
  parseInteger,
9
- type UnaryOperator,
10
8
  } from "@tsplc/compiler/ir";
9
+ import { elementaryFunctions, type UnaryOperator } from "@tsplc/iec/arithmetic";
11
10
  import ts from "typescript";
12
11
  import type { ExpressionLowering } from "./expressions";
13
12
  import { numericLiteral } from "./types";
@@ -508,7 +508,7 @@ class PromiseChain {
508
508
  const links = this.chain.links;
509
509
  let lowered = {
510
510
  call: this.addHelper(
511
- `tsplcPromiseOperation${context.sequence()}`,
511
+ context.names.name("tsplcPromiseOperation", this.chain.root),
512
512
  helperFinish(this.rootInvocation, this.rootType),
513
513
  this.rootType,
514
514
  ),
@@ -522,13 +522,14 @@ class PromiseChain {
522
522
  for (const [index, link] of links.entries()) {
523
523
  lowered = this.link(link, lowered, {
524
524
  terminal: detached && index === links.length - 1,
525
+ index,
525
526
  });
526
527
  }
527
528
  const values = this.params.map((value) => value.expression).join(",");
528
529
  if (!detached) {
529
530
  return lowered.call.replace(`(${this.args})`, `(${values})`);
530
531
  }
531
- const site = `tsplcPromiseSite${context.sequence()}`;
532
+ const site = context.names.name("tsplcPromiseSite", this.chain.root);
532
533
  const callable = lowered.call.slice(0, lowered.call.indexOf("("));
533
534
  const scope = classOwner ?? source;
534
535
  context.append(
@@ -547,16 +548,22 @@ class PromiseChain {
547
548
  private link(
548
549
  link: ChainLink,
549
550
  previous: Callback,
550
- { terminal }: { terminal: boolean },
551
+ { terminal, index }: { terminal: boolean; index: number },
551
552
  ): Callback {
552
553
  const fulfilled =
553
554
  link.kind === "then"
554
- ? this.callback(link.handlers[0], previous.type, "promiseResult")
555
+ ? this.callback(
556
+ link.handlers[0],
557
+ previous.type,
558
+ "promiseResult",
559
+ `${index}Fulfilled`,
560
+ )
555
561
  : undefined;
556
562
  const rejected = this.callback(
557
563
  link.handlers[link.kind === "catch" ? 0 : 1],
558
564
  "UDINT",
559
565
  "tsplcErrorCode(promiseError)",
566
+ `${index}Rejected`,
560
567
  );
561
568
  if (!fulfilled && !rejected) {
562
569
  return previous;
@@ -570,7 +577,7 @@ class PromiseChain {
570
577
  }
571
578
  return {
572
579
  call: this.addHelper(
573
- `tsplcPromiseChain${this.context.sequence()}`,
580
+ this.context.names.name(`tsplcPromiseChain${index}`, this.chain.root),
574
581
  linkBody(previous, { fulfilled, rejected, terminal }),
575
582
  output,
576
583
  ),
@@ -582,10 +589,12 @@ class PromiseChain {
582
589
  }
583
590
 
584
591
  /** How the chain calls a callback, declaring a helper for it when it needs one. */
592
+ /** `slot` tells the callbacks of one chain apart: its link and whether it fulfils or rejects. */
585
593
  private callback(
586
594
  expression: ts.Expression | undefined,
587
595
  inputType: string,
588
596
  input: string,
597
+ slot: string,
589
598
  ): Callback | undefined {
590
599
  if (
591
600
  !expression ||
@@ -615,6 +624,7 @@ class PromiseChain {
615
624
  inputType,
616
625
  input,
617
626
  aggregate,
627
+ slot,
618
628
  });
619
629
  }
620
630
  const names = new Map(this.captureNames);
@@ -629,7 +639,10 @@ class PromiseChain {
629
639
  parameter,
630
640
  inputType,
631
641
  });
632
- const name = `tsplcPromiseHandler${context.sequence()}`;
642
+ const name = context.names.name(
643
+ `tsplcPromiseHandler${slot}`,
644
+ this.chain.root,
645
+ );
633
646
  const body = this.replaceNames(declaration.body, names);
634
647
  const takesInput = Boolean(parameter && inputType !== "void");
635
648
  const handlerParams = [
@@ -677,7 +690,8 @@ class PromiseChain {
677
690
  inputType,
678
691
  input,
679
692
  aggregate,
680
- }: { inputType: string; input: string; aggregate: boolean },
693
+ slot,
694
+ }: { inputType: string; input: string; aggregate: boolean; slot: string },
681
695
  ): Callback {
682
696
  const { context, source } = this;
683
697
  const result = declaration.type;
@@ -704,7 +718,7 @@ class PromiseChain {
704
718
  }
705
719
  return {
706
720
  call: this.addHelper(
707
- `tsplcPromiseNamed${context.sequence()}`,
721
+ context.names.name(`tsplcPromiseNamed${slot}`, this.chain.root),
708
722
  callbackType === "void"
709
723
  ? `${name}(${takesInput ? "promiseInput" : ""});return;`
710
724
  : `return ${name}(${takesInput ? "promiseInput" : ""});`,
@@ -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 Diagnostic, error } from "@tsplc/compiler/ir";
3
3
  import ts from "typescript";
4
+ import { GeneratedNames } from "./generated-names";
4
5
  import { importSpecifier, runtimeSources } from "./module-graph";
5
6
  import {
6
7
  type Edit,
@@ -34,8 +35,8 @@ export interface PromiseContext {
34
35
  /** Whether a node names the SDK declaration `name`. */
35
36
  namesSdk(node: ts.Node, name: string): boolean;
36
37
  fail(node: ts.Node, message: string): never;
37
- /** The next number for a generated name. */
38
- sequence(): number;
38
+ /** Names for generated declarations, from the source node each stands for. */
39
+ readonly names: GeneratedNames;
39
40
  /** Adds generated code to the end of a module, or to a class, mapped to the node it was made for. */
40
41
  append(
41
42
  scope: ts.SourceFile | ts.ClassDeclaration,
@@ -58,6 +59,7 @@ export const lowerPromises = (
58
59
  program: ts.Program,
59
60
  sdk: string,
60
61
  positions: Positions,
62
+ root: string,
61
63
  ): PromiseLowering => {
62
64
  const files = runtimeSources(program).filter(
63
65
  (source) => !source.isDeclarationFile,
@@ -67,6 +69,7 @@ export const lowerPromises = (
67
69
  sdk,
68
70
  positions,
69
71
  files,
72
+ new GeneratedNames(root),
70
73
  );
71
74
  const diagnostics: Diagnostic[] = [];
72
75
  const runtimeBlocks = new Map<string, { kind: "mailbox" }>();
@@ -216,7 +219,7 @@ function cancelScope(
216
219
  ),
217
220
  );
218
221
  }
219
- const name = `tsplcCancelScope${rewrite.sequence()}`;
222
+ const name = rewrite.names.name("tsplcCancelScope", node);
220
223
  const member = ts.isClassDeclaration(scope);
221
224
  const body = (rewrite.sites.get(scope) ?? [])
222
225
  .map((site) => `${member ? "this." : ""}${site}.cancel();`)
@@ -243,13 +246,12 @@ class PromiseRewrite implements PromiseContext {
243
246
  private readonly aliases = new Map<ts.Node, string>();
244
247
  private readonly typeImports = new Map<ts.SourceFile, Set<string>>();
245
248
  private readonly imported = new Set<ts.SourceFile>();
246
- private nextName = 0;
247
-
248
249
  constructor(
249
250
  readonly checker: ts.TypeChecker,
250
251
  private readonly sdk: string,
251
252
  private readonly positions: Positions,
252
253
  files: readonly ts.SourceFile[],
254
+ readonly names: GeneratedNames,
253
255
  ) {
254
256
  for (const source of files) {
255
257
  for (const statement of source.statements) {
@@ -285,10 +287,6 @@ class PromiseRewrite implements PromiseContext {
285
287
  throw new SemanticError(this.diagnostic(node, message));
286
288
  }
287
289
 
288
- sequence(): number {
289
- return this.nextName++;
290
- }
291
-
292
290
  append(
293
291
  scope: ts.SourceFile | ts.ClassDeclaration,
294
292
  origin: ts.Node,
@@ -344,7 +342,7 @@ class PromiseRewrite implements PromiseContext {
344
342
 
345
343
  /** Exports a type from the module that declares it, so other modules can name it. */
346
344
  private declareAlias(node: ts.TypeNode): string {
347
- const alias = `TsplcPromiseType${this.sequence()}`;
345
+ const alias = this.names.name("TsplcPromiseType", node);
348
346
  this.aliases.set(node, alias);
349
347
  this.append(
350
348
  node.getSourceFile(),
@@ -1,4 +1,5 @@
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
3
  import {
3
4
  aggregate,
4
5
  type Constant,
@@ -6,13 +7,13 @@ import {
6
7
  type IntegerInterval,
7
8
  integerRange,
8
9
  loopBounds,
9
- loopIterations,
10
10
  maxLoopIterations,
11
11
  type PlcFunction,
12
12
  type PlcType,
13
13
  type Statement,
14
14
  type Variable,
15
15
  } from "@tsplc/compiler/ir";
16
+ import { loopIterations } from "@tsplc/iec/arithmetic";
16
17
  import ts from "typescript";
17
18
  import type { AnalysisContext, ExpressionLowering } from "./expressions";
18
19
  import type { Positions } from "./positions";
@@ -483,7 +484,7 @@ export class StatementLowering {
483
484
  const direction = ascending ? 1n : -1n;
484
485
  const finish = BigInt(bound.value) - (exclusive ? direction : 0n);
485
486
  const first = BigInt(start.value);
486
- const count = loopIterations(first, finish, step);
487
+ const count = loopIterations(first, BigInt(bound.value), exclusive, step);
487
488
  this.checkIterations(node, count);
488
489
  if (existing) {
489
490
  this.checkFinalIncrement(node, plcType, first + count * step);
@@ -95,7 +95,7 @@ function taskDefinition(
95
95
  fn,
96
96
  declaration,
97
97
  );
98
- const worker = `tsplcTaskWorker${context.sequence()}`;
98
+ const worker = context.names.name("tsplcTaskWorker", declaration);
99
99
  const receiver = `this.${worker}`;
100
100
  const site = taskSite(
101
101
  declaration.name.text,
@@ -143,7 +143,7 @@ function cooperativeDefinition(
143
143
  }));
144
144
  // An async method runs as members of the owner itself; a helper runs in its own block.
145
145
  const method = context.methods.get(symbol);
146
- const worker = `tsplcCooperativeWorker${context.sequence()}`;
146
+ const worker = context.names.name("tsplcCooperativeWorker", declaration);
147
147
  const receiver = method ? "this" : `this.${worker}`;
148
148
  const site = cooperativeSite(
149
149
  declaration.name.text,
@@ -216,8 +216,8 @@ function placeSite(
216
216
  visit(owner);
217
217
  return;
218
218
  }
219
- const block = `${siteClass}${context.sequence()}`;
220
- const entry = `tsplcContinuation${context.sequence()}`;
219
+ const block = context.names.name(siteClass, declaration);
220
+ const entry = context.names.name("tsplcContinuation", declaration);
221
221
  extra.push(
222
222
  from(
223
223
  declaration,
@@ -275,9 +275,9 @@ function backgroundDefinition(
275
275
  fn,
276
276
  declaration,
277
277
  );
278
- const mailbox = `TsplcMailbox${context.sequence()}`;
279
- const worker = `tsplcWorker${context.sequence()}`;
280
- const entry = `tsplcBackground${context.sequence()}`;
278
+ const mailbox = context.names.name("TsplcMailbox", declaration);
279
+ const worker = context.names.name("tsplcWorker", declaration);
280
+ const entry = context.names.name("tsplcBackground", declaration);
281
281
  const requestType = `{ready:BOOL;${params.map((p) => `${p.field}:${p.type}`).join(";")}}`;
282
282
  const snapshotType = `{valid:BOOL;busy:BOOL;done:BOOL;cancelRequested:BOOL;error:UDINT;result:${valueType}}`;
283
283
  const emptySnapshot = `{valid:true,busy:this.pending || this.active,done:this.completed,cancelRequested:this.cancelRequested,error:this.failure,result:${copyValue("this.value", valueAggregate)}}`;
@@ -456,7 +456,7 @@ function workTypes(
456
456
  };
457
457
  }
458
458
  // Another module's types are named through the aliases its coroutine exports.
459
- const prefix = aliasPrefix(fn);
459
+ const prefix = aliasPrefix(context.names, fn);
460
460
  const params = fn.parameters.map((node, index) =>
461
461
  parameter(node, index, `${prefix}Argument${index}`),
462
462
  );
@@ -236,11 +236,11 @@ export function analyze(options: FrontendOptions): FrontendResult {
236
236
  if (!apply(lowerConstFunctions(program, positions))) {
237
237
  return { diagnostics };
238
238
  }
239
- const promises = lowerPromises(program, sdk, positions);
239
+ const promises = lowerPromises(program, sdk, positions, dirname(filename));
240
240
  if (!apply(promises)) {
241
241
  return { diagnostics };
242
242
  }
243
- const lowering = lowerAsync(program, sdk, positions);
243
+ const lowering = lowerAsync(program, sdk, positions, dirname(filename));
244
244
  for (const [key, value] of promises.runtimeBlocks) {
245
245
  lowering.blocks.set(key, value);
246
246
  }
@@ -375,6 +375,9 @@ function attachLowerings(
375
375
  if (elaboration.folded.length) {
376
376
  module.folded = elaboration.folded;
377
377
  }
378
+ if (elaboration.references?.fields.length) {
379
+ module.references = elaboration.references;
380
+ }
378
381
  for (const entry of module.programs) {
379
382
  const background = lowering.schedules.get(entry.name);
380
383
  if (background) {