@geastack/compiler 1.0.48 → 1.0.62

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 (127) hide show
  1. package/README.md +57 -19
  2. package/dist/cli.js +2 -1
  3. package/dist/compiler.d.ts +1 -1
  4. package/dist/compiler.js +13 -6
  5. package/dist/conversion/derive.js +5 -0
  6. package/dist/conversion/native-field-view.d.ts +7 -0
  7. package/dist/conversion/native-field-view.js +50 -0
  8. package/dist/conversion/native-record-products.js +1 -0
  9. package/dist/conversion/native-view-origins.d.ts +1 -1
  10. package/dist/conversion/native-view-origins.js +5 -4
  11. package/dist/conversion/nodes.d.ts +9 -0
  12. package/dist/conversion/nodes.js +18 -0
  13. package/dist/conversion/record-view.d.ts +25 -1
  14. package/dist/conversion/record-view.js +61 -2
  15. package/dist/conversion/structural-plan.js +7 -6
  16. package/dist/ir/borrowed-field-reads.d.ts +30 -0
  17. package/dist/ir/borrowed-field-reads.js +218 -0
  18. package/dist/ir/borrowed-window-cells.d.ts +35 -0
  19. package/dist/ir/borrowed-window-cells.js +117 -0
  20. package/dist/ir/call-dispatch.js +21 -4
  21. package/dist/ir/callable-class-flow.js +269 -43
  22. package/dist/ir/captures.js +18 -1
  23. package/dist/ir/certify.js +14 -1
  24. package/dist/ir/construction-only-fields.d.ts +15 -1
  25. package/dist/ir/construction-only-fields.js +71 -3
  26. package/dist/ir/dead-logical-merge.d.ts +4 -0
  27. package/dist/ir/dead-logical-merge.js +89 -18
  28. package/dist/ir/dense-loops.d.ts +38 -4
  29. package/dist/ir/dense-loops.js +112 -17
  30. package/dist/ir/dense-read-windows.d.ts +42 -0
  31. package/dist/ir/dense-read-windows.js +137 -0
  32. package/dist/ir/facts.d.ts +12 -0
  33. package/dist/ir/facts.js +18 -2
  34. package/dist/ir/field-read-reuse.d.ts +71 -0
  35. package/dist/ir/field-read-reuse.js +430 -0
  36. package/dist/ir/hoist.d.ts +19 -2
  37. package/dist/ir/hoist.js +143 -24
  38. package/dist/ir/lower-narrow.js +19 -1
  39. package/dist/ir/model.d.ts +19 -0
  40. package/dist/ir/native-field-view-domains.d.ts +12 -2
  41. package/dist/ir/native-field-view-domains.js +51 -15
  42. package/dist/ir/native-field-view-facts.js +5 -2
  43. package/dist/ir/native-method-frames.js +15 -2
  44. package/dist/ir/plain-field-read.d.ts +31 -0
  45. package/dist/ir/plain-field-read.js +51 -0
  46. package/dist/ir/program-facts.d.ts +14 -0
  47. package/dist/ir/program-facts.js +85 -2
  48. package/dist/ir/proven-branches.js +8 -1
  49. package/dist/ir/publish-conversion-recipes.js +5 -1
  50. package/dist/ir/short-circuit-threading.d.ts +12 -4
  51. package/dist/ir/short-circuit-threading.js +124 -12
  52. package/dist/ir/stable-cell-reads.d.ts +24 -1
  53. package/dist/ir/stable-cell-reads.js +65 -42
  54. package/dist/ir/write-effects.d.ts +42 -0
  55. package/dist/ir/write-effects.js +208 -0
  56. package/dist/plugins/gea/contract.d.ts +3 -2
  57. package/dist/plugins/gea/contract.js +3 -1
  58. package/dist/plugins/gea/host.d.ts +7 -2
  59. package/dist/plugins/gea/host.js +25 -5
  60. package/dist/project-preparation.d.ts +11 -0
  61. package/dist/project-preparation.js +44 -0
  62. package/dist/projection/classes.d.ts +8 -0
  63. package/dist/projection/classes.js +112 -12
  64. package/dist/projection/dispatch.d.ts +24 -4
  65. package/dist/projection/dispatch.js +71 -2
  66. package/dist/projection/fields.js +2 -2
  67. package/dist/representation/model.d.ts +3 -0
  68. package/dist/representation/model.js +3 -0
  69. package/dist/representation/value-records.js +22 -0
  70. package/dist/semantics/frontend-timing.d.ts +9 -0
  71. package/dist/semantics/frontend-timing.js +43 -2
  72. package/dist/semantics/frontend.js +103 -7
  73. package/dist/semantics/model/operations.d.ts +7 -0
  74. package/dist/semantics/normalize/binding-fixpoint.js +7 -2
  75. package/dist/semantics/normalize/callable-data-write.js +6 -2
  76. package/dist/semantics/normalize/field-bindings.js +151 -111
  77. package/dist/semantics/normalize/flow/callable-reach.js +27 -0
  78. package/dist/semantics/normalize/flow/component-solver.js +23 -5
  79. package/dist/semantics/normalize/flow/source-record-data.js +6 -2
  80. package/dist/semantics/normalize/flow/source-value-session.d.ts +13 -0
  81. package/dist/semantics/normalize/flow/source-value-session.js +207 -65
  82. package/dist/semantics/normalize/global-host-mutations.js +162 -1
  83. package/dist/semantics/normalize/parameter-bindings.js +16 -1
  84. package/dist/semantics/normalize/producers/class-lifecycle.js +2 -1
  85. package/dist/semantics/normalize/producers/erasure.js +13 -8
  86. package/dist/semantics/subclass-member-overlay-transform.d.ts +3 -2
  87. package/dist/semantics/subclass-member-overlay-transform.js +416 -316
  88. package/dist/semantics/typescript-tsgo.d.ts +20 -0
  89. package/dist/semantics/typescript-tsgo.js +832 -0
  90. package/dist/semantics/typescript.d.ts +0 -9
  91. package/dist/semantics/typescript.js +4 -1
  92. package/dist/targets/cpp/borrowed-call-entry.d.ts +9 -0
  93. package/dist/targets/cpp/borrowed-call-entry.js +12 -2
  94. package/dist/targets/cpp/captures.js +4 -0
  95. package/dist/targets/cpp/class-properties/computed-method-value.d.ts +1 -1
  96. package/dist/targets/cpp/class-properties/computed-method-value.js +17 -7
  97. package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +8 -0
  98. package/dist/targets/cpp/class-properties/emit-class-properties.js +62 -2
  99. package/dist/targets/cpp/class-properties/native-method-read.js +12 -1
  100. package/dist/targets/cpp/conversions.js +1 -0
  101. package/dist/targets/cpp/emit-arrays.d.ts +5 -0
  102. package/dist/targets/cpp/emit-arrays.js +60 -10
  103. package/dist/targets/cpp/emit-binding-reference.d.ts +19 -6
  104. package/dist/targets/cpp/emit-binding-reference.js +26 -8
  105. package/dist/targets/cpp/emit-bindings.js +22 -0
  106. package/dist/targets/cpp/emit-callable.js +133 -16
  107. package/dist/targets/cpp/emit-carrier-members.d.ts +6 -0
  108. package/dist/targets/cpp/emit-carrier-members.js +24 -2
  109. package/dist/targets/cpp/emit-context.d.ts +97 -1
  110. package/dist/targets/cpp/emit-context.js +52 -0
  111. package/dist/targets/cpp/emit-equality.js +3 -0
  112. package/dist/targets/cpp/emit-narrowing.js +9 -0
  113. package/dist/targets/cpp/emit-native-field-view.d.ts +24 -0
  114. package/dist/targets/cpp/emit-native-field-view.js +87 -8
  115. package/dist/targets/cpp/emit-properties.js +139 -16
  116. package/dist/targets/cpp/emit-record-view.js +49 -22
  117. package/dist/targets/cpp/emit-return.js +5 -1
  118. package/dist/targets/cpp/emit-tonumber.js +4 -1
  119. package/dist/targets/cpp/emit-union-properties.js +1 -1
  120. package/dist/targets/cpp/emit.d.ts +4 -1
  121. package/dist/targets/cpp/emit.js +148 -6
  122. package/dist/targets/cpp/reactive-dependencies.js +100 -28
  123. package/dist/targets/cpp/translation-unit.js +71 -17
  124. package/dist/targets/cpp/virtual-methods.d.ts +2 -2
  125. package/dist/targets/cpp/virtual-methods.js +11 -3
  126. package/package.json +1 -1
  127. package/src/targets/cpp/runtime/gea_runtime.h +400 -21
@@ -0,0 +1,208 @@
1
+ import { borrowSafeOperationsOf } from './borrow-effects.js';
2
+ import { stringConstantsOf } from './dead-values.js';
3
+ import { arrayAllocationDrainsDynamicIterator } from './queries.js';
4
+ const none = { kind: 'none' };
5
+ const all = { kind: 'all' };
6
+ const primitiveKinds = new Set(['scalar', 'string', 'null', 'undefined', 'symbol', 'record-literal']);
7
+ export const primitive = (value) => {
8
+ if (value.kind === 'optional')
9
+ return primitive(value.payload);
10
+ if (value.kind === 'tagged-union')
11
+ return value.arms.every((arm) => primitive(arm.value));
12
+ return primitiveKinds.has(value.kind);
13
+ };
14
+ /** Carriers whose property reads load native data: no getter of the program's can run. */
15
+ const nativeDataKinds = new Set([
16
+ 'string',
17
+ 'typed-array',
18
+ 'array-buffer',
19
+ 'shared-array-buffer',
20
+ 'data-view',
21
+ 'array-object',
22
+ 'dense-buffer',
23
+ 'native-sequence',
24
+ 'native-handle'
25
+ ]);
26
+ export const nativeData = (value) => value.kind === 'optional' ? nativeData(value.payload) : nativeDataKinds.has(value.kind);
27
+ /**
28
+ * An argument a host function can only read as data: a host method handed one
29
+ * can neither call it back nor coerce it through a method of the program's
30
+ * (`join` on an array of class instances calls their `toString`).
31
+ */
32
+ export const inertArgument = (value) => {
33
+ if (value.kind === 'optional')
34
+ return inertArgument(value.payload);
35
+ if (value.kind === 'tagged-union')
36
+ return value.arms.every((arm) => inertArgument(arm.value));
37
+ if (primitive(value))
38
+ return true;
39
+ return (value.kind === 'typed-array' ||
40
+ value.kind === 'array-buffer' ||
41
+ value.kind === 'shared-array-buffer' ||
42
+ value.kind === 'data-view' ||
43
+ (value.kind === 'native-handle' && value.native !== null) ||
44
+ ((value.kind === 'array-object' || value.kind === 'dense-buffer' || value.kind === 'native-sequence') &&
45
+ 'element' in value &&
46
+ primitive(value.element)));
47
+ };
48
+ const localEffectsOf = (body, plainFieldRead, codeFreeRead) => {
49
+ const keys = stringConstantsOf(body);
50
+ const producers = new Map();
51
+ for (const block of body.blocks.values())
52
+ for (const operation of block.operations) {
53
+ const result = 'result' in operation ? operation.result : null;
54
+ if (result !== null && typeof result === 'object' && 'id' in result)
55
+ producers.set(result.id, operation);
56
+ }
57
+ const safe = borrowSafeOperationsOf(body, new Set(), plainFieldRead);
58
+ const unwrap = (value) => (value.kind === 'optional' ? value.payload : value);
59
+ const effects = new Map();
60
+ const classify = (operation) => {
61
+ switch (operation.kind) {
62
+ case 'constant':
63
+ case 'binding-read':
64
+ case 'binding-write':
65
+ case 'binding-renew':
66
+ case 'parameter':
67
+ case 'receiver':
68
+ case 'phi':
69
+ case 'global-this':
70
+ case 'allocate-ordinary-object':
71
+ case 'allocate-record':
72
+ case 'allocate-callable':
73
+ case 'test':
74
+ return none;
75
+ case 'allocate-array-object':
76
+ return arrayAllocationDrainsDynamicIterator(operation) ? all : none;
77
+ case 'compute':
78
+ // A nullish check throws or passes; it reads no property and calls nothing.
79
+ return safe.has(operation) || operation.form === 'require-object-coercible' ? none : all;
80
+ case 'convert':
81
+ // An unwrap, a widening or a re-carry runs nothing; only a coercion of
82
+ // an object into a primitive can call one of the program's methods.
83
+ return primitive(operation.source.representation) || !primitive(operation.result.representation) ? none : all;
84
+ case 'get': {
85
+ if (safe.has(operation))
86
+ return none;
87
+ if (operation.hostMethod !== undefined || nativeData(operation.receiver.representation))
88
+ return none;
89
+ const key = keys.get(operation.key.value);
90
+ return key !== undefined && codeFreeRead(unwrap(operation.receiver.representation), key) ? none : all;
91
+ }
92
+ case 'set': {
93
+ if (safe.has(operation))
94
+ return none;
95
+ const key = keys.get(operation.key.value);
96
+ const receiver = unwrap(operation.receiver.representation);
97
+ if (receiver.kind === 'array-object' && operation.key.representation.kind === 'scalar')
98
+ return none;
99
+ if (key === undefined)
100
+ return all;
101
+ return plainFieldRead(receiver, key) || receiver.kind === 'native-handle' ? { kind: 'key', key } : all;
102
+ }
103
+ case 'call': {
104
+ if (safe.has(operation))
105
+ return none;
106
+ const closed = operation.closedCallee;
107
+ if (closed !== undefined)
108
+ return { kind: 'calls', functionIds: closed.kind === 'exact' ? [closed.functionId] : closed.functionIds };
109
+ const callee = producers.get(operation.callee.value);
110
+ // The receiver counts as an argument: `sort()` and `join()` on an array
111
+ // of class instances call each element's `toString`.
112
+ const receiver = callee?.kind === 'get' ? unwrap(callee.receiver.representation) : null;
113
+ const host = callee?.kind === 'get' &&
114
+ receiver !== null &&
115
+ (callee.hostMethod !== undefined || nativeData(receiver)) &&
116
+ (receiver.kind === 'native-handle' || inertArgument(receiver));
117
+ return host && operation.arguments.every((argument) => inertArgument(argument.representation)) ? none : all;
118
+ }
119
+ default:
120
+ return all;
121
+ }
122
+ };
123
+ for (const block of body.blocks.values())
124
+ for (const operation of block.operations)
125
+ effects.set(operation, classify(operation));
126
+ return effects;
127
+ };
128
+ /**
129
+ * `codeFreeRead` answers whether reading `key` off a carrier runs none of the
130
+ * program's code: a data field, or a method a class installs (no accessor).
131
+ */
132
+ export const writeEffectsOf = (bodies, plainFieldRead, codeFreeRead) => {
133
+ const locals = new Map();
134
+ const bodiesOf = new Map();
135
+ for (const body of bodies) {
136
+ locals.set(body, localEffectsOf(body, plainFieldRead, codeFreeRead));
137
+ const owner = String(body.sourceOwner);
138
+ const list = bodiesOf.get(owner) ?? [];
139
+ list.push(body);
140
+ bodiesOf.set(owner, list);
141
+ }
142
+ // Owners' summaries grow from nothing: a recursive component stores only
143
+ // what some member's own operations store, by induction on call depth.
144
+ const summaries = new Map();
145
+ for (const owner of bodiesOf.keys())
146
+ summaries.set(owner, { all: false, keys: new Set() });
147
+ const absorb = (into, owner) => {
148
+ const callee = summaries.get(owner);
149
+ if (callee === undefined || callee.all)
150
+ return false;
151
+ for (const key of callee.keys)
152
+ into.add(key);
153
+ return true;
154
+ };
155
+ let changed = true;
156
+ while (changed) {
157
+ changed = false;
158
+ for (const [owner, ownerBodies] of bodiesOf) {
159
+ const current = summaries.get(owner);
160
+ if (current === undefined || current.all)
161
+ continue;
162
+ const keys = new Set(current.keys);
163
+ let everything = false;
164
+ for (const body of ownerBodies) {
165
+ for (const local of locals.get(body)?.values() ?? []) {
166
+ if (local.kind === 'all')
167
+ everything = true;
168
+ else if (local.kind === 'key')
169
+ keys.add(local.key);
170
+ else if (local.kind === 'calls')
171
+ for (const functionId of local.functionIds)
172
+ if (!absorb(keys, String(functionId)))
173
+ everything = true;
174
+ if (everything)
175
+ break;
176
+ }
177
+ if (everything)
178
+ break;
179
+ }
180
+ if (everything) {
181
+ summaries.set(owner, { all: true });
182
+ changed = true;
183
+ }
184
+ else if (keys.size !== current.keys.size) {
185
+ summaries.set(owner, { all: false, keys });
186
+ changed = true;
187
+ }
188
+ }
189
+ }
190
+ return {
191
+ plainField: plainFieldRead,
192
+ mayStore: (body, operation, key) => {
193
+ const local = locals.get(body)?.get(operation);
194
+ if (local === undefined || local.kind === 'all')
195
+ return true;
196
+ if (local.kind === 'none')
197
+ return false;
198
+ if (local.kind === 'key')
199
+ return local.key === key;
200
+ return local.functionIds.some((functionId) => {
201
+ const summary = summaries.get(String(functionId));
202
+ return summary === undefined || summary.all || summary.keys.has(key);
203
+ });
204
+ }
205
+ };
206
+ };
207
+ /** No window is clean: the answer for a context built without the census. */
208
+ export const everyStoreEffects = { mayStore: () => true, plainField: () => false };
@@ -143,14 +143,15 @@ export interface GeaElementFacts {
143
143
  * @semanticCategory framework-protocol
144
144
  */
145
145
  export interface GeaProviderAuthority {
146
- readonly nativeDeclarationFileName: string;
146
+ /** `null` when `@geastack/core` is not installed: then no declaration file is the native provider. */
147
+ readonly nativeDeclarationFileName: string | null;
147
148
  readonly modulesOf: (containingFile: string) => readonly ts.SourceFile[];
148
149
  }
149
150
  /** The frontend, not package spelling or a class name, selects the Gea provider.
150
151
  * This is the Gea class protocol witness, not generic source identity admission.
151
152
  * @semanticCategory framework-protocol
152
153
  */
153
- export declare const createGeaProviderAuthority: (context: Pick<ProducerContext, "runtimeModuleTargetOf" | "sourceFileOf" | "jsxRuntimeModuleOf">, nativeDeclarationFileName: string) => GeaProviderAuthority;
154
+ export declare const createGeaProviderAuthority: (context: Pick<ProducerContext, "runtimeModuleTargetOf" | "sourceFileOf" | "jsxRuntimeModuleOf">, nativeDeclarationFileName: string | null) => GeaProviderAuthority;
154
155
  /** Whether this class is one of gea's components -- `derivesFromGeaBase` asked about gea's component base. */
155
156
  export declare const derivesFromGeaComponent: (checker: ts.TypeChecker, instance: ts.Type, authority?: GeaProviderAuthority) => boolean;
156
157
  /**
@@ -146,7 +146,9 @@ const derivesFromGeaBase = (checker, instance, baseName, authority) => {
146
146
  providers.add(provider);
147
147
  // A native-only module has no executable runtime target. Its installed
148
148
  // host declaration remains an exact owned witness, never ambient names.
149
- if (file.isDeclarationFile && resolve(file.fileName) === resolve(authority.nativeDeclarationFileName))
149
+ if (file.isDeclarationFile &&
150
+ authority.nativeDeclarationFileName !== null &&
151
+ resolve(file.fileName) === resolve(authority.nativeDeclarationFileName))
150
152
  providers.add(file);
151
153
  }
152
154
  }
@@ -314,8 +314,13 @@ export declare const geaHostNamespaceProperties: () => ReadonlyMap<string, strin
314
314
  export declare const geaHostNamespacePropertySetters: () => ReadonlyMap<string, string>;
315
315
  /** The host's free functions, by the name the program writes. */
316
316
  export declare const geaHostFunctions: () => ReadonlyMap<string, string>;
317
- /** The declaration authority already selected for this host's native signatures. */
318
- export declare const geaCoreDeclarationFileName: (options?: PluginOptions) => string;
317
+ /**
318
+ * The declaration authority already selected for this host's native signatures.
319
+ * `null` when nothing names one and `@geastack/core` is not installed: a
320
+ * program compiled without gea (a Node server, a library's test fixture) has no
321
+ * gea provider to recognize, and must not fail to start for lack of one.
322
+ */
323
+ export declare const geaCoreDeclarationFileName: (options?: PluginOptions) => string | null;
319
324
  export declare const geaNativeFunctionDeclarations: (options: PluginOptions) => readonly NativeHostFunctionDeclaration[];
320
325
  /**
321
326
  * `new <AmbientConstructor>(...)` spellings, transposed from the package's own
@@ -338,15 +338,35 @@ export const geaHostNamespaceProperties = () => {
338
338
  export const geaHostNamespacePropertySetters = () => nestedTable(geaShims()?.hostNamespacePropertySetters);
339
339
  /** The host's free functions, by the name the program writes. */
340
340
  export const geaHostFunctions = () => flatTable(geaShims()?.embeddedHostFunctions);
341
- /** The declaration authority already selected for this host's native signatures. */
342
- export const geaCoreDeclarationFileName = (options) => resolve(options?.get('gea.native-signature-core-root') ??
343
- process.env.GEA_CORE_DIR ??
344
- dirname(packageLoader.resolve('@geastack/core/package.json')), 'index.d.ts');
341
+ /** `@geastack/core`'s installed root; `null` when it is not installed, which is a configuration, as with the shims above. */
342
+ const installedGeaCoreRoot = () => {
343
+ try {
344
+ return dirname(packageLoader.resolve('@geastack/core/package.json'));
345
+ }
346
+ catch (error) {
347
+ if (error.code === 'MODULE_NOT_FOUND')
348
+ return null;
349
+ throw error;
350
+ }
351
+ };
352
+ /**
353
+ * The declaration authority already selected for this host's native signatures.
354
+ * `null` when nothing names one and `@geastack/core` is not installed: a
355
+ * program compiled without gea (a Node server, a library's test fixture) has no
356
+ * gea provider to recognize, and must not fail to start for lack of one.
357
+ */
358
+ export const geaCoreDeclarationFileName = (options) => {
359
+ const root = options?.get('gea.native-signature-core-root') ?? process.env.GEA_CORE_DIR ?? installedGeaCoreRoot();
360
+ return root === null ? null : resolve(root, 'index.d.ts');
361
+ };
345
362
  export const geaNativeFunctionDeclarations = (options) => {
346
363
  const sources = geaShims()?.nativeFunctionSignatureSources ?? {};
347
364
  if (Object.keys(sources).length === 0)
348
365
  return [];
349
- const coreRoot = dirname(geaCoreDeclarationFileName(options));
366
+ const coreDeclarationFileName = geaCoreDeclarationFileName(options);
367
+ if (coreDeclarationFileName === null)
368
+ throw new Error('gea host shims state native function signatures, but @geastack/core is not installed');
369
+ const coreRoot = dirname(coreDeclarationFileName);
350
370
  const functions = geaHostFunctions();
351
371
  return Object.entries(sources).map(([name, source]) => {
352
372
  const cppFunction = functions.get(name);
@@ -41,5 +41,16 @@ export declare const checkout: (identity: SourceIdentity, destination: string) =
41
41
  * else is no manifest (`{}`), which the version check below refuses.
42
42
  */
43
43
  export declare const registryManifest: (json: string) => Manifest;
44
+ /**
45
+ * The project file (`tsconfig.json`) of every package whose TypeScript this
46
+ * program compiles: each acquired checkout in `sources`, and each installed
47
+ * package that already maps its runtime output back to its own `.ts`
48
+ * (`installedSourceMapped`). A library's sources are written against its own
49
+ * checker settings -- a driver built with `useUnknownInCatchVariables: false`
50
+ * reads `error.message` off an untyped catch variable -- so a build that checks
51
+ * them must know those settings; the application's own project cannot state
52
+ * them. Packages without a project file contribute nothing.
53
+ */
54
+ export declare const packageSourceProjects: (root: string, sources: readonly PackageSource[], files?: SourceFileSystem) => readonly string[];
44
55
  /** Acquire missing typed sources at the installed version; plain JS remains usable. */
45
56
  export declare const preparePackageSources: (root: string, options?: PreparationOptions) => Promise<readonly PackageSource[]>;
@@ -432,6 +432,50 @@ export const registryManifest = (json) => {
432
432
  const parsed = JSON.parse(json);
433
433
  return object(Array.isArray(parsed) && parsed.length === 1 ? parsed[0] : parsed);
434
434
  };
435
+ /**
436
+ * The project file (`tsconfig.json`) of every package whose TypeScript this
437
+ * program compiles: each acquired checkout in `sources`, and each installed
438
+ * package that already maps its runtime output back to its own `.ts`
439
+ * (`installedSourceMapped`). A library's sources are written against its own
440
+ * checker settings -- a driver built with `useUnknownInCatchVariables: false`
441
+ * reads `error.message` off an untyped catch variable -- so a build that checks
442
+ * them must know those settings; the application's own project cannot state
443
+ * them. Packages without a project file contribute nothing.
444
+ */
445
+ export const packageSourceProjects = (root, sources, files = disk) => {
446
+ const projects = new Set();
447
+ const add = (directory) => {
448
+ const project = join(directory, 'tsconfig.json');
449
+ if (files.exists(project))
450
+ projects.add(project);
451
+ };
452
+ for (const source of sources)
453
+ add(source.root);
454
+ const visited = new Set();
455
+ const compiler = ownPackageName();
456
+ const pending = [resolve(root)];
457
+ while (pending.length > 0) {
458
+ const directory = pending.shift();
459
+ if (visited.has(directory) || !files.exists(join(directory, 'package.json')))
460
+ continue;
461
+ visited.add(directory);
462
+ const manifest = manifestAt(directory, files);
463
+ if (compiler !== undefined && manifest.name === compiler)
464
+ continue;
465
+ for (const name of Object.keys({
466
+ ...object(manifest.dependencies),
467
+ ...object(manifest.optionalDependencies),
468
+ ...object(manifest.peerDependencies)
469
+ })) {
470
+ const installed = installedPackage(name, directory, files);
471
+ if (installed)
472
+ pending.push(installed);
473
+ }
474
+ if (directory !== resolve(root) && installedSourceMapped(directory, manifest, files))
475
+ add(directory);
476
+ }
477
+ return [...projects];
478
+ };
435
479
  /** Acquire missing typed sources at the installed version; plain JS remains usable. */
436
480
  export const preparePackageSources = async (root, options = {}) => {
437
481
  const files = options.files ?? disk;
@@ -54,6 +54,8 @@ export interface ClassFieldOwnership {
54
54
  export interface ClassMethod {
55
55
  readonly key: string;
56
56
  readonly callable: FunctionId | null;
57
+ /** Declared `abstract`: the key is stated for subclasses and nothing is installed (`callable` is null). */
58
+ readonly abstract?: true;
57
59
  /**
58
60
  * The census copy of a generic class whose evaluation installed this body
59
61
  * (`decl|f0|36@2`), absent for a class that was never copied. A generic
@@ -101,6 +103,12 @@ export interface ClassLayout {
101
103
  readonly nativeStorage?: NativeClassStorage;
102
104
  /** Typed own-property shadows, initially absent; prototype methods remain methods. */
103
105
  readonly methodOverrides?: readonly RecordField[];
106
+ /**
107
+ * Methods only a write through a dynamic receiver can shadow. They get no
108
+ * slot: such a write lands in the instance's native expando table, and a
109
+ * call checks the instance's expando bit before dispatching normally.
110
+ */
111
+ readonly dynamicMethodShadows?: readonly string[];
104
112
  /** Methods replaced on this prototype, rather than on ordinary instances. */
105
113
  readonly prototypeMethodMutations?: readonly string[];
106
114
  /** Uses outside the currently supported typed method-only prototype protocol. */
@@ -683,6 +683,7 @@ export const projectClasses = (input) => {
683
683
  bucket.push({
684
684
  key: key.source.text,
685
685
  callable: method?.source.kind === 'result' ? allocatedCallableOf(allocatedCallables, method.source.result) : null,
686
+ ...(operation.abstractMember ? { abstract: true } : {}),
686
687
  ...(operation.placement !== 'static' && genericRootOf(operation.classDeclaration) !== operation.classDeclaration
687
688
  ? { publishedBy: operation.classDeclaration }
688
689
  : {}),
@@ -838,6 +839,7 @@ export const keyExcludesSymbols = (carrier) => {
838
839
  /** A write creates an own callable property without replacing its prototype declaration. */
839
840
  export const publishClassMethodOverrides = (layouts, input) => {
840
841
  const overrides = new Map();
842
+ const dynamicShadows = new Map();
841
843
  const prototypeMutations = new Map();
842
844
  const prototypes = new Map();
843
845
  const prototypeBindings = new Map();
@@ -959,14 +961,86 @@ export const publishClassMethodOverrides = (layouts, input) => {
959
961
  }
960
962
  }
961
963
  }
962
- const mark = (receiver, key, prototype = null, symbolKeys = true) => {
964
+ // A write through a dynamic receiver (`target[key] = value` with `target:
965
+ // any`) lands on whatever object was boxed into it, so it shadows a method
966
+ // of every class whose instance enters a dynamic slot. Which values are
967
+ // boxed is settled only by lowering (`ir/boxed-bind-assumptions.ts`), after
968
+ // this layout is fixed; the declared slot each operand enters
969
+ // (`conversionRoles`: an `any` parameter, an `any[]` element, an `any`
970
+ // field) is the semantic layer's own statement of that boundary.
971
+ let boxed;
972
+ const boxedInstances = () => {
973
+ if (boxed)
974
+ return boxed;
975
+ boxed = new Map();
976
+ const holdsDynamic = (slot) => slot.kind === 'dynamic' ||
977
+ (slot.kind === 'optional' && holdsDynamic(slot.payload)) ||
978
+ (slot.kind === 'tagged-union' && slot.arms.some((arm) => holdsDynamic(arm.value)));
979
+ const collect = (carrier) => {
980
+ if (carrier.kind === 'optional')
981
+ return collect(carrier.payload);
982
+ if (carrier.kind === 'borrowed-ref')
983
+ return collect(carrier.referent);
984
+ if (carrier.kind === 'tagged-union')
985
+ return carrier.arms.forEach((arm) => collect(arm.value));
986
+ if (carrier.kind === 'class-ref')
987
+ boxed?.set(genericRootOf(carrier.declaration), carrier);
988
+ };
989
+ // An array of instances entering an `any[]` slot boxes each element, not
990
+ // the array: `installAll([element], key)` hands the callee the instance.
991
+ const enter = (carrier, slot) => {
992
+ if (holdsDynamic(slot))
993
+ return collect(carrier);
994
+ if (slot.kind === 'optional')
995
+ return enter(carrier, slot.payload);
996
+ if (carrier.kind === 'optional')
997
+ return enter(carrier.payload, slot);
998
+ if (carrier.kind === 'borrowed-ref')
999
+ return enter(carrier.referent, slot);
1000
+ if (carrier.kind === 'array-object' && slot.kind === 'array-object')
1001
+ enter(carrier.element, slot.element);
1002
+ };
1003
+ const carrierOfResult = (operand) => operand?.source.kind === 'result' ? input.plan.selected.get(operand.source.result) : undefined;
1004
+ // A binding's cell holds the carrier its introducing operation published
1005
+ // (`projectBindingPlacements`): `for (const target of targets)` over an
1006
+ // `any[]` boxes each instance into `target`'s cell, not into a slot.
1007
+ const cells = new Map();
1008
+ for (const operation of input.graph.operations.values()) {
1009
+ if (operation.family !== 'binding' || (operation.action !== 'initialize' && operation.action !== 'declare'))
1010
+ continue;
1011
+ const published = resultOf(operation, 'value');
1012
+ const cell = published ? input.plan.selected.get(published.id) : undefined;
1013
+ if (cell && !cells.has(operation.declaration))
1014
+ cells.set(operation.declaration, cell);
1015
+ }
1016
+ for (const operation of input.graph.operations.values()) {
1017
+ for (const target of operation.conversionRoles ?? []) {
1018
+ const carrier = carrierOfResult(operation.operands.find((each) => each.role === target.role && each.ordinal === target.ordinal));
1019
+ if (carrier)
1020
+ enter(carrier, input.deriver.derive(target.type));
1021
+ }
1022
+ if (operation.family !== 'binding' || (operation.action !== 'initialize' && operation.action !== 'write'))
1023
+ continue;
1024
+ const cell = cells.get(operation.declaration);
1025
+ const carrier = carrierOfResult(operandOf(operation, operation.action === 'initialize' ? 'initializer' : 'value'));
1026
+ if (cell && carrier)
1027
+ enter(carrier, cell);
1028
+ }
1029
+ return boxed;
1030
+ };
1031
+ const mark = (receiver, key, prototype = null, symbolKeys = true, viaDynamic = false) => {
963
1032
  if (receiver.kind === 'optional')
964
- return mark(receiver.payload, key, prototype, symbolKeys);
1033
+ return mark(receiver.payload, key, prototype, symbolKeys, viaDynamic);
965
1034
  if (receiver.kind === 'borrowed-ref')
966
- return mark(receiver.referent, key, prototype, symbolKeys);
1035
+ return mark(receiver.referent, key, prototype, symbolKeys, viaDynamic);
967
1036
  if (receiver.kind === 'tagged-union') {
968
1037
  for (const arm of receiver.arms)
969
- mark(arm.value, key, prototype, symbolKeys);
1038
+ mark(arm.value, key, prototype, symbolKeys, viaDynamic);
1039
+ return;
1040
+ }
1041
+ if (receiver.kind === 'dynamic') {
1042
+ for (const instance of boxedInstances().values())
1043
+ mark(instance, key, prototype, symbolKeys, true);
970
1044
  return;
971
1045
  }
972
1046
  if (receiver.kind !== 'class-ref')
@@ -1011,6 +1085,21 @@ export const publishClassMethodOverrides = (layouts, input) => {
1011
1085
  const abi = abiOfCallee(representation);
1012
1086
  if (!abi)
1013
1087
  continue;
1088
+ // A write through a dynamic receiver may land on any boxed instance, so
1089
+ // it marks every method of every boxed class (three's `InterleavedBuffer.toJSON`
1090
+ // marked all of Vector3, Object3D and Matrix4), and a computed key no
1091
+ // proof bounds marks every method of its receiver's class (three's
1092
+ // `BoxGeometry` writes `vector[u]`). A slot per method made each instance
1093
+ // carry the whole method table. Both writes run the dynamic own-property
1094
+ // protocol, which keeps a key the layout has no slot for in the expando
1095
+ // table, so the rare shadow lives there instead
1096
+ // (`ClassLayout.dynamicMethodShadows`). A spelled key keeps its slot.
1097
+ if ((viaDynamic || key === null) && prototype === null) {
1098
+ const keys = dynamicShadows.get(owner.declaration) ?? new Set();
1099
+ keys.add(name);
1100
+ dynamicShadows.set(owner.declaration, keys);
1101
+ continue;
1102
+ }
1014
1103
  const fields = overrides.get(owner.declaration) ?? new Map();
1015
1104
  // An own method holds the Function object, independently of the object
1016
1105
  // used to read it. Its stored entry therefore accepts logical this;
@@ -1032,14 +1121,20 @@ export const publishClassMethodOverrides = (layouts, input) => {
1032
1121
  // Intrinsics without a key operand (`Object.assign`) copy whatever own
1033
1122
  // keys their source holds, symbols included, and keep `undefined` here.
1034
1123
  let runtimeKey;
1124
+ // The whole-program upper bound on a computed key (`provenKeyTexts`):
1125
+ // three's `BoxGeometry` writes `vector[u]` with `u` only ever 'x', 'y' or
1126
+ // 'z', and marking every Vector3 method for it guarded each of their calls.
1127
+ let proven;
1035
1128
  if (operation.family === 'property' &&
1036
1129
  (operation.internalMethod === 'set' || operation.internalMethod === 'delete' || operation.internalMethod === 'define-own-property')) {
1037
1130
  receiver = operandOf(operation, 'receiver');
1038
1131
  const named = operandOf(operation, 'key');
1039
1132
  if (named?.source.kind === 'constant')
1040
1133
  key = named.source.text;
1041
- else
1134
+ else {
1042
1135
  runtimeKey = named;
1136
+ proven = operation.provenKeyTexts;
1137
+ }
1043
1138
  }
1044
1139
  else if (operation.family === 'invocation' && operation.intrinsicMutation) {
1045
1140
  receiver = operation.operands.find((operand) => operand.role === 'argument' && operand.ordinal === 0);
@@ -1056,18 +1151,22 @@ export const publishClassMethodOverrides = (layouts, input) => {
1056
1151
  const symbolKeys = runtimeKey === undefined || !keyExcludesSymbols(carrierOf(runtimeKey));
1057
1152
  const selected = receiver.source.kind === 'result' ? input.plan.selected.get(receiver.source.result) : undefined;
1058
1153
  const prototypeOrigins = receiver.source.kind === 'result' ? prototypes.get(receiver.source.result) : undefined;
1059
- if (prototypeOrigins?.size) {
1060
- for (const declaration of prototypeOrigins) {
1061
- const instance = layouts.get(declaration)?.instance;
1062
- if (instance)
1063
- mark(instance, key, declaration, symbolKeys);
1154
+ const keys = key === null && proven !== undefined && proven.length > 0 ? proven : [key];
1155
+ for (const each of keys) {
1156
+ if (prototypeOrigins?.size) {
1157
+ for (const declaration of prototypeOrigins) {
1158
+ const instance = layouts.get(declaration)?.instance;
1159
+ if (instance)
1160
+ mark(instance, each, declaration, symbolKeys);
1161
+ }
1064
1162
  }
1163
+ else
1164
+ mark(selected ?? input.deriver.derive(receiver.type), each, null, symbolKeys);
1065
1165
  }
1066
- else
1067
- mark(selected ?? input.deriver.derive(receiver.type), key, null, symbolKeys);
1068
1166
  }
1069
1167
  return new Map([...layouts].map(([declaration, layout]) => {
1070
1168
  const fields = overrides.get(declaration);
1169
+ const shadows = [...(dynamicShadows.get(declaration) ?? [])].filter((key) => !fields?.has(key));
1071
1170
  const prototypeKeys = prototypeMutations.get(declaration);
1072
1171
  const unsupportedUses = unsupportedPrototypes.get(declaration);
1073
1172
  return [
@@ -1075,6 +1174,7 @@ export const publishClassMethodOverrides = (layouts, input) => {
1075
1174
  {
1076
1175
  ...layout,
1077
1176
  ...(fields ? { methodOverrides: [...fields.values()] } : {}),
1177
+ ...(shadows.length > 0 ? { dynamicMethodShadows: shadows } : {}),
1078
1178
  ...(prototypeKeys ? { prototypeMethodMutations: [...prototypeKeys] } : {}),
1079
1179
  ...(unsupportedUses ? { prototypeUnsupportedUses: [...unsupportedUses] } : {})
1080
1180
  }
@@ -2,10 +2,6 @@ import type { DeclarationId, FunctionId } from '../identity/ids.js';
2
2
  import type { ClassAccessor, ClassField, ClassLayout, ClassMethod } from './classes.js';
3
3
  import type { ConversionCensus } from '../conversion/nodes.js';
4
4
  import type { CallableAbi, Representation } from '../representation/model.js';
5
- /** Exact allocation identities and the method each prototype lookup selects.
6
- * Selection happens when the property is read, before a later call supplies
7
- * its receiver. A virtual call adapter would select at the wrong time.
8
- */
9
5
  export declare const classPrototypeMethodValueArmsOf: (classes: ReadonlyMap<DeclarationId, ClassLayout>, receiver: DeclarationId, key: string) => readonly {
10
6
  readonly allocation: DeclarationId;
11
7
  readonly method: (ClassMethod & {
@@ -45,12 +41,28 @@ export declare const classMethodValueArmsOf: (classes: ReadonlyMap<DeclarationId
45
41
  /** The class that declares `method`, whose struct holds its method state. */
46
42
  readonly owner: DeclarationId;
47
43
  }[] | null;
44
+ /** The method-bearing arms of a family whose every other allocation misses
45
+ * `key` on an abstract declaration (`classAbstractMemberMissesAt`). Those
46
+ * allocations read the empty callable, so only these arms publish a method
47
+ * frame; any other absence keeps the family incomplete (`null`).
48
+ */
49
+ export declare const classPresentMethodArmsOf: (classes: ReadonlyMap<DeclarationId, ClassLayout>, receiver: DeclarationId, key: string) => ReturnType<typeof classMethodValueArmsOf>;
48
50
  /** A declared method frame does not supply an executable body. A bodyless
49
51
  * method read needs the existing complete allocation/prototype selection,
50
52
  * including a callable on every normal allocation. One unused override does
51
53
  * not provide a method for an instance of its base.
52
54
  */
53
55
  export declare const classMethodFamilyHasNativeBody: (classes: ReadonlyMap<DeclarationId, ClassLayout>, receiver: DeclarationId, key: string) => boolean;
56
+ /** An allocation whose own class declares `key` abstract and inherits no
57
+ * body for it: its lookup misses, so the read is `undefined` and a call of it
58
+ * is JS's TypeError for calling `undefined` -- not an unproved family.
59
+ */
60
+ export declare const classAbstractMemberMissesAt: (classes: ReadonlyMap<DeclarationId, ClassLayout>, allocation: DeclarationId, key: string) => boolean;
61
+ /** Whether some allocation a read of `key` on `receiver` may meet misses it on
62
+ * an abstract declaration (`classAbstractMemberMissesAt`): the read is then
63
+ * `undefined` there, which only a carrier with an empty callable can hold.
64
+ */
65
+ export declare const classMethodReadMayMissAbstractly: (classes: ReadonlyMap<DeclarationId, ClassLayout>, receiver: DeclarationId, key: string) => boolean;
54
66
  /**
55
67
  * The class-hierarchy topology behind method dispatch: which key belongs to
56
68
  * which override family, and who redeclares what.
@@ -250,3 +262,11 @@ export interface VirtualDispatchVerdict {
250
262
  * method almost never is one.
251
263
  */
252
264
  export declare const virtualDispatchVerdictOf: (classes: ReadonlyMap<DeclarationId, ClassLayout>, abiOf: (callable: FunctionId) => CallableAbi | null, capturesNothing: (callable: FunctionId) => boolean, conversions: ConversionCensus) => VirtualDispatchVerdict;
265
+ /**
266
+ * Whether an instance carried as `declaration` may hold an own `key` that a
267
+ * write through a dynamic receiver installed over a method
268
+ * (`ClassLayout.dynamicMethodShadows`): on its own chain, or on a subclass it
269
+ * may really be. Such a shadow lives in the instance's native expando table,
270
+ * so a call checks that table before it dispatches.
271
+ */
272
+ export declare const classDynamicMethodShadowOf: (classes: ReadonlyMap<DeclarationId, ClassLayout>, declaration: DeclarationId, key: string) => boolean;