@geastack/compiler 1.0.33 → 1.0.35

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 (215) hide show
  1. package/README.md +1 -1
  2. package/dist/cli-coverage.js +2 -4
  3. package/dist/cli-emit.js +1 -1
  4. package/dist/cli-module-graph.js +1 -1
  5. package/dist/cli.js +2 -1
  6. package/dist/compiler.js +14 -6
  7. package/dist/conversion/array-view.js +9 -0
  8. package/dist/conversion/build.js +15 -8
  9. package/dist/conversion/dictionary-view.js +2 -2
  10. package/dist/conversion/nodes.d.ts +7 -0
  11. package/dist/conversion/nodes.js +58 -11
  12. package/dist/identity/ids.d.ts +4 -0
  13. package/dist/identity/ids.js +4 -0
  14. package/dist/ir/build.d.ts +4 -3
  15. package/dist/ir/build.js +14 -5
  16. package/dist/ir/call-dispatch.js +67 -7
  17. package/dist/ir/call-entry.js +1 -1
  18. package/dist/ir/callable-class-flow.d.ts +4 -0
  19. package/dist/ir/callable-class-flow.js +123 -1
  20. package/dist/ir/certify/parallel-region.js +698 -20
  21. package/dist/ir/certify.d.ts +3 -0
  22. package/dist/ir/certify.js +44 -9
  23. package/dist/ir/class-allocation-domain.js +2 -2
  24. package/dist/ir/class-construction-status.d.ts +10 -0
  25. package/dist/ir/class-construction-status.js +36 -0
  26. package/dist/ir/convert-carriers.d.ts +10 -1
  27. package/dist/ir/convert-carriers.js +18 -1
  28. package/dist/ir/dynamic-constructor-conversions.js +4 -2
  29. package/dist/ir/finite-iterator-close.d.ts +14 -0
  30. package/dist/ir/finite-iterator-close.js +50 -0
  31. package/dist/ir/host-template-conversions.js +9 -0
  32. package/dist/ir/lower-allocation.js +1 -1
  33. package/dist/ir/lower-flow.js +24 -3
  34. package/dist/ir/lower-operands.js +88 -7
  35. package/dist/ir/lower-protocol.js +1 -1
  36. package/dist/ir/lower.js +9 -4
  37. package/dist/ir/model.d.ts +39 -1
  38. package/dist/ir/native-accessor-definition.d.ts +3 -2
  39. package/dist/ir/native-accessor-definition.js +29 -10
  40. package/dist/ir/native-array-transport.js +2 -2
  41. package/dist/ir/native-field-view-domains.d.ts +23 -0
  42. package/dist/ir/native-field-view-domains.js +115 -9
  43. package/dist/ir/native-field-view-facts.d.ts +46 -2
  44. package/dist/ir/native-field-view-facts.js +159 -4
  45. package/dist/ir/native-iterable.d.ts +17 -0
  46. package/dist/ir/native-iterable.js +72 -0
  47. package/dist/ir/native-key-query.js +1 -1
  48. package/dist/ir/operation-conversions.js +15 -3
  49. package/dist/ir/program-conversions.js +2 -2
  50. package/dist/ir/publish-native-field-view-facts.js +9 -4
  51. package/dist/ir/pure-conversion-reuse.d.ts +58 -0
  52. package/dist/ir/pure-conversion-reuse.js +263 -0
  53. package/dist/ir/queries.js +1 -0
  54. package/dist/ir/reflection-demand.js +70 -18
  55. package/dist/ir/shake.js +2 -2
  56. package/dist/ir/unobserved-callable-inputs.d.ts +37 -0
  57. package/dist/ir/unobserved-callable-inputs.js +111 -0
  58. package/dist/native-signatures.d.ts +1 -1
  59. package/dist/native-signatures.js +27 -2
  60. package/dist/plugins/gea/component-classes.d.ts +2 -1
  61. package/dist/plugins/gea/component-classes.js +3 -3
  62. package/dist/plugins/gea/contract.d.ts +26 -3
  63. package/dist/plugins/gea/contract.js +42 -43
  64. package/dist/plugins/gea/host.d.ts +9 -0
  65. package/dist/plugins/gea/host.js +25 -4
  66. package/dist/plugins/gea/plugin.js +12 -6
  67. package/dist/plugins/gea/producer.d.ts +2 -2
  68. package/dist/plugins/gea/producer.js +2 -2
  69. package/dist/plugins/load.js +18 -1
  70. package/dist/plugins/model.d.ts +5 -0
  71. package/dist/plugins/native-iterable-providers.d.ts +18 -0
  72. package/dist/plugins/native-iterable-providers.js +51 -0
  73. package/dist/project-preparation.d.ts +8 -0
  74. package/dist/project-preparation.js +49 -7
  75. package/dist/projection/bindings.d.ts +13 -0
  76. package/dist/projection/bindings.js +20 -1
  77. package/dist/projection/classes.d.ts +4 -2
  78. package/dist/projection/classes.js +12 -5
  79. package/dist/representation/collections.js +2 -0
  80. package/dist/representation/derive.js +1 -0
  81. package/dist/representation/model.d.ts +2 -0
  82. package/dist/representation/model.js +1 -0
  83. package/dist/representation/policies.d.ts +2 -0
  84. package/dist/representation/primitive-domain.d.ts +1 -1
  85. package/dist/representation/primitive-domain.js +1 -1
  86. package/dist/representation/unassigned-binding-cells.js +6 -1
  87. package/dist/representation/union.js +6 -6
  88. package/dist/semantics/frontend.d.ts +2 -0
  89. package/dist/semantics/frontend.js +34 -5
  90. package/dist/semantics/host-methods.js +4 -1
  91. package/dist/semantics/jsx-runtime-provider.d.ts +5 -0
  92. package/dist/semantics/jsx-runtime-provider.js +16 -0
  93. package/dist/semantics/model/native-iterable.d.ts +14 -0
  94. package/dist/semantics/model/native-iterable.js +7 -0
  95. package/dist/semantics/model/operands.d.ts +30 -0
  96. package/dist/semantics/model/operations.d.ts +15 -0
  97. package/dist/semantics/model/primitive-domain.d.ts +15 -0
  98. package/dist/semantics/model/primitive-domain.js +27 -4
  99. package/dist/semantics/module-resolution.js +13 -2
  100. package/dist/semantics/normalize/any-cast-member-call.d.ts +1 -1
  101. package/dist/semantics/normalize/callback-parameter-contracts.d.ts +32 -4
  102. package/dist/semantics/normalize/callback-parameter-contracts.js +66 -6
  103. package/dist/semantics/normalize/census.d.ts +3 -0
  104. package/dist/semantics/normalize/census.js +17 -12
  105. package/dist/semantics/normalize/deferred-intrinsic-protocols.d.ts +4 -1
  106. package/dist/semantics/normalize/deferred-intrinsic-protocols.js +29 -9
  107. package/dist/semantics/normalize/flow/callable-reach.js +94 -3
  108. package/dist/semantics/normalize/flow/component-solver.js +144 -55
  109. package/dist/semantics/normalize/flow/member-call-forwarding.d.ts +9 -0
  110. package/dist/semantics/normalize/flow/member-call-forwarding.js +30 -4
  111. package/dist/semantics/normalize/flow/proof-hypotheses.d.ts +2 -0
  112. package/dist/semantics/normalize/flow/proof-hypotheses.js +27 -0
  113. package/dist/semantics/normalize/flow/source-callable-own-data.js +87 -14
  114. package/dist/semantics/normalize/flow/source-commonjs-exports.d.ts +2 -0
  115. package/dist/semantics/normalize/flow/source-commonjs-exports.js +2 -0
  116. package/dist/semantics/normalize/flow/source-native-iterable-integrity.d.ts +17 -0
  117. package/dist/semantics/normalize/flow/source-native-iterable-integrity.js +125 -0
  118. package/dist/semantics/normalize/flow/source-native-origin.d.ts +6 -0
  119. package/dist/semantics/normalize/flow/source-native-origin.js +38 -0
  120. package/dist/semantics/normalize/flow/source-proxy-operation.d.ts +37 -0
  121. package/dist/semantics/normalize/flow/source-proxy-operation.js +201 -0
  122. package/dist/semantics/normalize/flow/source-raw-constructor-entry.d.ts +20 -0
  123. package/dist/semantics/normalize/flow/source-raw-constructor-entry.js +73 -0
  124. package/dist/semantics/normalize/flow/source-value-session.d.ts +50 -1
  125. package/dist/semantics/normalize/flow/source-value-session.js +596 -57
  126. package/dist/semantics/normalize/flow/value-flow.d.ts +17 -0
  127. package/dist/semantics/normalize/flow/value-flow.js +84 -0
  128. package/dist/semantics/normalize/fresh-dictionary-storage.js +2 -2
  129. package/dist/semantics/normalize/fresh-table-last-use.d.ts +52 -0
  130. package/dist/semantics/normalize/fresh-table-last-use.js +129 -0
  131. package/dist/semantics/normalize/gating.js +5 -1
  132. package/dist/semantics/normalize/global-host-mutations.js +190 -13
  133. package/dist/semantics/normalize/identities.js +20 -1
  134. package/dist/semantics/normalize/local-bindings.js +2 -2
  135. package/dist/semantics/normalize/parameter-bindings.js +10 -1
  136. package/dist/semantics/normalize/producer-context.d.ts +5 -0
  137. package/dist/semantics/normalize/producers/binding-kind.js +2 -0
  138. package/dist/semantics/normalize/producers/cited-value-type.d.ts +2 -2
  139. package/dist/semantics/normalize/producers/cited-value-type.js +2 -2
  140. package/dist/semantics/normalize/producers/class-lifecycle.js +39 -9
  141. package/dist/semantics/normalize/producers/computations.js +36 -5
  142. package/dist/semantics/normalize/producers/conditional-guard.d.ts +6 -0
  143. package/dist/semantics/normalize/producers/conditional-guard.js +5 -0
  144. package/dist/semantics/normalize/producers/control.js +7 -1
  145. package/dist/semantics/normalize/producers/destructuring.js +8 -9
  146. package/dist/semantics/normalize/producers/invocations.js +55 -2
  147. package/dist/semantics/normalize/producers/properties.d.ts +13 -0
  148. package/dist/semantics/normalize/producers/properties.js +21 -3
  149. package/dist/semantics/normalize/producers/references.js +8 -4
  150. package/dist/semantics/normalize/reachability.d.ts +15 -3
  151. package/dist/semantics/normalize/reachability.js +128 -20
  152. package/dist/semantics/normalize/return-bindings.js +3 -3
  153. package/dist/semantics/normalize/source-native-iterable.d.ts +19 -0
  154. package/dist/semantics/normalize/source-native-iterable.js +74 -0
  155. package/dist/semantics/normalize/structural-any-binding-consumer.d.ts +1 -1
  156. package/dist/semantics/normalize/structural-declarations.js +1 -1
  157. package/dist/semantics/normalize/structural-indexed-access.js +9 -0
  158. package/dist/semantics/normalize/structural.js +11 -0
  159. package/dist/semantics/normalize/unshared-array-result.d.ts +42 -0
  160. package/dist/semantics/normalize/unshared-array-result.js +269 -0
  161. package/dist/semantics/package-sources.js +3 -2
  162. package/dist/semantics/program.d.ts +8 -0
  163. package/dist/semantics/program.js +55 -0
  164. package/dist/semantics/source-transform-exports.d.ts +8 -0
  165. package/dist/semantics/source-transform-exports.js +145 -0
  166. package/dist/semantics/source-transform-protocol.d.ts +22 -0
  167. package/dist/semantics/this-constructor-source-transform.js +19 -1
  168. package/dist/targets/cpp/class-layout.d.ts +2 -0
  169. package/dist/targets/cpp/class-layout.js +35 -1
  170. package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +11 -1
  171. package/dist/targets/cpp/class-properties/emit-class-properties.js +33 -4
  172. package/dist/targets/cpp/conversions.js +6 -3
  173. package/dist/targets/cpp/emit-callable.js +73 -7
  174. package/dist/targets/cpp/emit-context.d.ts +23 -9
  175. package/dist/targets/cpp/emit-context.js +19 -8
  176. package/dist/targets/cpp/emit-equality.js +41 -1
  177. package/dist/targets/cpp/emit-exceptions.js +29 -11
  178. package/dist/targets/cpp/emit-iterator-object-view.js +2 -2
  179. package/dist/targets/cpp/emit-iterator.js +33 -9
  180. package/dist/targets/cpp/emit-live-field-view.js +6 -1
  181. package/dist/targets/cpp/emit-narrowing.d.ts +11 -3
  182. package/dist/targets/cpp/emit-narrowing.js +58 -18
  183. package/dist/targets/cpp/emit-native-field-view.d.ts +3 -1
  184. package/dist/targets/cpp/emit-native-field-view.js +84 -8
  185. package/dist/targets/cpp/emit-properties.d.ts +1 -0
  186. package/dist/targets/cpp/emit-properties.js +26 -7
  187. package/dist/targets/cpp/emit-protocol-iterator.js +5 -2
  188. package/dist/targets/cpp/emit-record-view.js +14 -2
  189. package/dist/targets/cpp/emit-tostring.js +23 -1
  190. package/dist/targets/cpp/emit-union-properties.js +1 -1
  191. package/dist/targets/cpp/emit.d.ts +1 -1
  192. package/dist/targets/cpp/emit.js +99 -13
  193. package/dist/targets/cpp/host/emit-host-invoke.js +2 -2
  194. package/dist/targets/cpp/host/emit-host-object.js +28 -2
  195. package/dist/targets/cpp/host/emit-host-properties.js +9 -1
  196. package/dist/targets/cpp/host/emit-host-value.d.ts +1 -1
  197. package/dist/targets/cpp/host/emit-host-value.js +8 -6
  198. package/dist/targets/cpp/host/host-members.js +2 -1
  199. package/dist/targets/cpp/prototype/emit-prototype-array.js +69 -5
  200. package/dist/targets/cpp/prototype/emit-prototype-invoke.js +9 -9
  201. package/dist/targets/cpp/prototype/emit-prototype-iterator.js +2 -2
  202. package/dist/targets/cpp/prototype/emit-prototype-promise.js +7 -7
  203. package/dist/targets/cpp/records.d.ts +1 -0
  204. package/dist/targets/cpp/records.js +83 -22
  205. package/dist/targets/cpp/translation-unit.js +30 -16
  206. package/package.json +8 -7
  207. package/src/targets/cpp/runtime/gea_dynamic_proxy.h +42 -3
  208. package/src/targets/cpp/runtime/gea_eval.h +3 -0
  209. package/src/targets/cpp/runtime/gea_runtime.h +2399 -676
  210. package/dist/representation/any-null-record-members.d.ts +0 -41
  211. package/dist/representation/any-null-record-members.js +0 -115
  212. package/dist/semantics/any-null-member-declarations.d.ts +0 -32
  213. package/dist/semantics/any-null-member-declarations.js +0 -90
  214. package/dist/semantics/normalize/fresh-array-result.d.ts +0 -32
  215. package/dist/semantics/normalize/fresh-array-result.js +0 -125
@@ -8,6 +8,23 @@ import { type ProgramReachability } from '../reachability.js';
8
8
  * its arguments land in the implementation's parameters by position.
9
9
  */
10
10
  export declare const implementationOfOverload: (checker: ts.TypeChecker, declaration: ts.Node) => ts.FunctionDeclaration | ts.MethodDeclaration | null;
11
+ /**
12
+ * Whether two indices `indexValueFlow` built over the same checker, files and
13
+ * reachability state the same index: every write and every call site equal,
14
+ * field by field, by node and symbol identity, in the same order.
15
+ *
16
+ * Those two lists are the only part of an index the census inputs can move.
17
+ * Every census-dependent decision `indexValueFlow` makes -- the effective type
18
+ * of an `any` receiver, a call's inferred declaration and extra targets, its
19
+ * `.call`/`.apply` operands -- lands in a write it records or in a field of a
20
+ * call site it records. Everything else (property accesses, references,
21
+ * receiver owners, indexed bodies, class declarations) comes from the same
22
+ * syntax walk over the same reachable statements and the same checker, and
23
+ * every lookup table is built from those lists in list order. Two indices
24
+ * equal here therefore answer every question identically; the remaining
25
+ * length checks are a cheap guard on that argument, not part of it.
26
+ */
27
+ export declare const sameValueFlowContent: (a: ValueFlowIndex, b: ValueFlowIndex) => boolean;
11
28
  /**
12
29
  * Index every write edge in the program.
13
30
  *
@@ -181,6 +181,90 @@ const push = (table, key, value) => {
181
181
  else
182
182
  table.set(key, [value]);
183
183
  };
184
+ const sameNodes = (a, b) => {
185
+ if (a.length !== b.length)
186
+ return false;
187
+ for (let index = 0; index < a.length; index++)
188
+ if (a[index] !== b[index])
189
+ return false;
190
+ return true;
191
+ };
192
+ const sameDispatch = (a, b) => {
193
+ switch (a.kind) {
194
+ case 'direct':
195
+ return b.kind === 'direct';
196
+ case 'member':
197
+ return b.kind === 'member' && a.lookup === b.lookup && a.key === b.key;
198
+ case 'lexical-super':
199
+ return b.kind === 'lexical-super' && a.home === b.home && a.static === b.static && a.key === b.key;
200
+ case 'super-constructor':
201
+ return b.kind === 'super-constructor' && a.home === b.home;
202
+ }
203
+ };
204
+ const sameOperands = (a, b) => a.kind === b.kind &&
205
+ a.explicitThis === b.explicitThis &&
206
+ a.callee === b.callee &&
207
+ a.receiver === b.receiver &&
208
+ sameNodes(a.args, b.args) &&
209
+ sameDispatch(a.dispatch, b.dispatch);
210
+ const sameIterationOrigin = (a, b) => a === b || (a !== undefined && b !== undefined && a.source === b.source && a.mode === b.mode && a.asynchronous === b.asynchronous);
211
+ const sameWrite = (a, b) => a.edge === b.edge &&
212
+ a.slot === b.slot &&
213
+ a.member === b.member &&
214
+ a.value === b.value &&
215
+ a.site === b.site &&
216
+ a.naming === b.naming &&
217
+ a.propertyAccess === b.propertyAccess &&
218
+ a.target.symbol === b.target.symbol &&
219
+ a.target.nameSymbol === b.target.nameSymbol &&
220
+ a.target.declaration === b.target.declaration &&
221
+ 'iterationOrigin' in a === 'iterationOrigin' in b &&
222
+ sameIterationOrigin(a.iterationOrigin, b.iterationOrigin);
223
+ const sameExplicitThis = (a, b) => a === b || (a !== null && b !== null && a.callee === b.callee && a.receiver === b.receiver && sameNodes(a.args, b.args));
224
+ const sameCall = (a, b) => a.call === b.call &&
225
+ a.checkerDeclaration === b.checkerDeclaration &&
226
+ 'inferredDeclaration' in a === 'inferredDeclaration' in b &&
227
+ a.inferredDeclaration === b.inferredDeclaration &&
228
+ sameNodes(a.targets, b.targets) &&
229
+ sameOperands(a.operands, b.operands) &&
230
+ sameExplicitThis(a.explicitThis, b.explicitThis);
231
+ /**
232
+ * Whether two indices `indexValueFlow` built over the same checker, files and
233
+ * reachability state the same index: every write and every call site equal,
234
+ * field by field, by node and symbol identity, in the same order.
235
+ *
236
+ * Those two lists are the only part of an index the census inputs can move.
237
+ * Every census-dependent decision `indexValueFlow` makes -- the effective type
238
+ * of an `any` receiver, a call's inferred declaration and extra targets, its
239
+ * `.call`/`.apply` operands -- lands in a write it records or in a field of a
240
+ * call site it records. Everything else (property accesses, references,
241
+ * receiver owners, indexed bodies, class declarations) comes from the same
242
+ * syntax walk over the same reachable statements and the same checker, and
243
+ * every lookup table is built from those lists in list order. Two indices
244
+ * equal here therefore answer every question identically; the remaining
245
+ * length checks are a cheap guard on that argument, not part of it.
246
+ */
247
+ export const sameValueFlowContent = (a, b) => {
248
+ if (a === b)
249
+ return true;
250
+ if (a.buildIsStrict !== b.buildIsStrict ||
251
+ a.allWrites.length !== b.allWrites.length ||
252
+ a.calls.length !== b.calls.length ||
253
+ a.propertyAccesses.length !== b.propertyAccesses.length ||
254
+ a.bindingPatternReads.length !== b.bindingPatternReads.length ||
255
+ a.arrayLiterals.length !== b.arrayLiterals.length ||
256
+ a.classDeclarations.length !== b.classDeclarations.length ||
257
+ a.accessorNames.size !== b.accessorNames.size ||
258
+ a.hasComputedAccessorName !== b.hasComputedAccessorName)
259
+ return false;
260
+ for (let index = 0; index < a.allWrites.length; index++)
261
+ if (!sameWrite(a.allWrites[index], b.allWrites[index]))
262
+ return false;
263
+ for (let index = 0; index < a.calls.length; index++)
264
+ if (!sameCall(a.calls[index], b.calls[index]))
265
+ return false;
266
+ return true;
267
+ };
184
268
  /**
185
269
  * Index every write edge in the program.
186
270
  *
@@ -200,7 +200,7 @@ export const censusFreshDictionaryStorage = (checker, flow, parameters) => {
200
200
  if (ts.isObjectLiteralExpression(source))
201
201
  return [makeOrigin(source, targetKey)];
202
202
  // `Object.create(null)` is an empty table with no prototype to read
203
- // through, exactly the storage a closed component lays out. Hono's
203
+ // through, exactly the storage a closed component lays out. An HTTP framework's
204
204
  // `_getQueryParam` starts its results this way; typed `any`, it was an
205
205
  // unknown input that refused the whole component.
206
206
  if (isNullPrototypeCreate(checker, source))
@@ -589,7 +589,7 @@ export const isNullPrototypeCreate = (checker, node) => {
589
589
  * Blocked nodes the table only flows INTO, each stating one table view.
590
590
  *
591
591
  * A component reaching a public method is the ordinary case, not the
592
- * exception: hono's `HonoRequest.query()` returns the query parser's table to
592
+ * exception: an HTTP framework's request `query()` returns the query parser's table to
593
593
  * whatever the application does with it -- `JSON.stringify`, a field, a
594
594
  * callback -- and no closed proof covers that. Blocking such a consumer
595
595
  * refused the whole component, and the parser's one null-prototype object
@@ -0,0 +1,52 @@
1
+ import ts from 'typescript';
2
+ /**
3
+ * Whether a value expression hands over an object NO OTHER REFERENCE can ever
4
+ * observe again -- either a FRESH expression (an allocation written right
5
+ * there) or a `const` local initialized with one, whose every other reference
6
+ * is an admitted non-escaping use that runs before this one, so this use is
7
+ * its last.
8
+ *
9
+ * This is the one fact that makes converting a mutable object between two
10
+ * carriers sound. Such a conversion must allocate, and a second object loses
11
+ * every write made through the other alias; a value with no other alias can
12
+ * be copied once at the consumer and the copy is indistinguishable from the
13
+ * program having built it at the consumer's carrier in the first place.
14
+ *
15
+ * The proof is deliberately syntactic and small, like
16
+ * `unshared-array-result.ts`, and is parameterized by the object kind
17
+ * (`FreshValueKind`): what counts as a fresh allocation, and which uses of
18
+ * the local are non-escaping. Each refusal only keeps the conversion refused:
19
+ * - any reference after the use, or the use inside a loop the declaration is
20
+ * outside of (a later iteration would read the object the copy left
21
+ * behind);
22
+ * - any reference from another function (a closure could run later);
23
+ * - any reference the kind does not admit (passing it, storing it elsewhere,
24
+ * aliasing it, ...);
25
+ * - a declaration that is not a single-name `const` with a fresh initializer.
26
+ */
27
+ export interface FreshValueKind {
28
+ /** The initializer (or the value itself) is an allocation nothing else holds. */
29
+ readonly isFresh: (expression: ts.Expression) => boolean;
30
+ /** A reference to the local that hands no reference to it anywhere. */
31
+ readonly admitsUse: (use: ts.Identifier) => boolean;
32
+ }
33
+ /**
34
+ * `value` is fresh, or names a `const` local whose last use it is. The caller
35
+ * states that `value` itself is consumed only by the conversion being proved
36
+ * (its own context check, e.g. `isUnsharedFreshTableStore`'s).
37
+ */
38
+ export declare const isFreshOrLastUseOfFreshLocal: (checker: ts.TypeChecker, value: ts.Expression, kind: FreshValueKind) => boolean;
39
+ /** An open table: a plain object literal (no spreads, accessors, methods or computed keys), used only as a keyed receiver. */
40
+ export declare const freshTableKind: FreshValueKind;
41
+ /**
42
+ * Whether `value` -- the right-hand side of the plain store `receiver.key =
43
+ * value` -- hands over a fresh open table as its last use
44
+ * (`SemanticOperand.unsharedFreshTable`). Three's OutputPass builds `const
45
+ * defines: { [name: string]: string } = {}`, fills it, and stores it into
46
+ * `material.defines`, a table three itself reads and writes as `any` values.
47
+ * The store's own value must not be consumed (`x = (o.k = defines)` would be
48
+ * a second alias), so only an expression-statement `=` qualifies.
49
+ */
50
+ export declare const isUnsharedFreshTableStore: (checker: ts.TypeChecker, value: ts.Expression) => boolean;
51
+ /** `t.k`, `t[k]`, as a read, a store target, or a `delete` operand -- never a callee. */
52
+ export declare const keyedReceiverUse: (use: ts.Identifier) => boolean;
@@ -0,0 +1,129 @@
1
+ import ts from 'typescript';
2
+ /**
3
+ * `value` is fresh, or names a `const` local whose last use it is. The caller
4
+ * states that `value` itself is consumed only by the conversion being proved
5
+ * (its own context check, e.g. `isUnsharedFreshTableStore`'s).
6
+ */
7
+ export const isFreshOrLastUseOfFreshLocal = (checker, value, kind) => {
8
+ const expression = skipParentheses(value);
9
+ if (kind.isFresh(expression))
10
+ return true;
11
+ if (!ts.isIdentifier(expression))
12
+ return false;
13
+ const symbol = checker.getSymbolAtLocation(expression);
14
+ const declaration = symbol?.declarations?.length === 1 ? symbol.declarations[0] : undefined;
15
+ if (!symbol || !declaration || !ts.isVariableDeclaration(declaration) || !ts.isIdentifier(declaration.name))
16
+ return false;
17
+ const list = declaration.parent;
18
+ if (!ts.isVariableDeclarationList(list) || (list.flags & ts.NodeFlags.Const) === 0)
19
+ return false;
20
+ const initializer = declaration.initializer && skipParentheses(declaration.initializer);
21
+ if (!initializer || !kind.isFresh(initializer))
22
+ return false;
23
+ const body = enclosingFunctionOrFile(declaration);
24
+ if (enclosingFunctionOrFile(expression) !== body)
25
+ return false;
26
+ // A top-level binding other code can name after the "last" use: an exported
27
+ // one (another module imports it), or any in a classic script (its global
28
+ // lexical scope is shared with every later script).
29
+ if (ts.isSourceFile(body) && !moduleLocal(body, list, symbol, checker))
30
+ return false;
31
+ if (crossesLoop(expression, declaration))
32
+ return false;
33
+ let admitted = true;
34
+ const visit = (node) => {
35
+ if (!admitted)
36
+ return;
37
+ if (ts.isIdentifier(node) && node !== declaration.name && node !== expression && checker.getSymbolAtLocation(node) === symbol) {
38
+ admitted = enclosingFunctionOrFile(node) === body && node.getEnd() <= expression.getStart() && kind.admitsUse(node);
39
+ return;
40
+ }
41
+ ts.forEachChild(node, visit);
42
+ };
43
+ visit(body);
44
+ return admitted;
45
+ };
46
+ /** An open table: a plain object literal (no spreads, accessors, methods or computed keys), used only as a keyed receiver. */
47
+ export const freshTableKind = {
48
+ isFresh: (expression) => ts.isObjectLiteralExpression(expression) &&
49
+ expression.properties.every((property) => (ts.isPropertyAssignment(property) &&
50
+ (ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name) || ts.isNumericLiteral(property.name)) &&
51
+ property.name.text !== '__proto__') ||
52
+ (ts.isShorthandPropertyAssignment(property) && !property.objectAssignmentInitializer)),
53
+ admitsUse: (use) => keyedReceiverUse(use)
54
+ };
55
+ /**
56
+ * Whether `value` -- the right-hand side of the plain store `receiver.key =
57
+ * value` -- hands over a fresh open table as its last use
58
+ * (`SemanticOperand.unsharedFreshTable`). Three's OutputPass builds `const
59
+ * defines: { [name: string]: string } = {}`, fills it, and stores it into
60
+ * `material.defines`, a table three itself reads and writes as `any` values.
61
+ * The store's own value must not be consumed (`x = (o.k = defines)` would be
62
+ * a second alias), so only an expression-statement `=` qualifies.
63
+ */
64
+ export const isUnsharedFreshTableStore = (checker, value) => {
65
+ const assignment = value.parent;
66
+ if (!ts.isBinaryExpression(assignment) || assignment.right !== value)
67
+ return false;
68
+ if (assignment.operatorToken.kind !== ts.SyntaxKind.EqualsToken)
69
+ return false;
70
+ if (!ts.isPropertyAccessExpression(assignment.left) && !ts.isElementAccessExpression(assignment.left))
71
+ return false;
72
+ if (!ts.isExpressionStatement(assignment.parent))
73
+ return false;
74
+ // Only the local form: a literal stored directly already takes the slot's
75
+ // carrier from its own allocation.
76
+ return ts.isIdentifier(value) && isFreshOrLastUseOfFreshLocal(checker, value, freshTableKind);
77
+ };
78
+ /** `t.k`, `t[k]`, as a read, a store target, or a `delete` operand -- never a callee. */
79
+ export const keyedReceiverUse = (use) => {
80
+ const parent = use.parent;
81
+ const access = (ts.isPropertyAccessExpression(parent) && parent.expression === use && !ts.isPrivateIdentifier(parent.name)) ||
82
+ (ts.isElementAccessExpression(parent) && parent.expression === use);
83
+ if (!access || parent.questionDotToken !== undefined)
84
+ return false;
85
+ const outer = parent.parent;
86
+ return !(ts.isCallExpression(outer) && outer.expression === parent) && !(ts.isTaggedTemplateExpression(outer) && outer.tag === parent);
87
+ };
88
+ /** A module-scope binding no other module or script can reach: the file is a module, and nothing exports the binding. */
89
+ const moduleLocal = (file, list, symbol, checker) => {
90
+ if (!ts.isExternalModule(file))
91
+ return false;
92
+ const statement = list.parent;
93
+ if (ts.isVariableStatement(statement) && statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword))
94
+ return false;
95
+ const exported = (node) => {
96
+ if (ts.isExportSpecifier(node)) {
97
+ const local = node.propertyName ?? node.name;
98
+ const target = ts.isIdentifier(local) ? checker.getExportSpecifierLocalTargetSymbol(node) : undefined;
99
+ return target === symbol || (ts.isIdentifier(local) && local.text === symbol.name && node.parent.parent.moduleSpecifier === undefined);
100
+ }
101
+ if (ts.isExportAssignment(node)) {
102
+ const value = skipParentheses(node.expression);
103
+ return !ts.isIdentifier(value) || checker.getSymbolAtLocation(value) === symbol;
104
+ }
105
+ return ts.forEachChild(node, exported) === true;
106
+ };
107
+ return !file.statements.some((statement) => (ts.isExportDeclaration(statement) || ts.isExportAssignment(statement)) && exported(statement));
108
+ };
109
+ /** A loop between the use and the declaration repeats the use over the one object. */
110
+ const crossesLoop = (use, declaration) => {
111
+ for (let current = use.parent; current; current = current.parent) {
112
+ // The innermost node enclosing both: any loop above it holds the
113
+ // declaration too, so each iteration declares a fresh object.
114
+ if (current.pos <= declaration.pos && declaration.end <= current.end)
115
+ return false;
116
+ if (ts.isIterationStatement(current, false) || ts.isFunctionLike(current))
117
+ return true;
118
+ }
119
+ return true;
120
+ };
121
+ const enclosingFunctionOrFile = (node) => {
122
+ let current = node.parent;
123
+ while (current && !ts.isFunctionLike(current) && !ts.isSourceFile(current) && !ts.isClassStaticBlockDeclaration(current))
124
+ current = current.parent;
125
+ return current ?? node.getSourceFile();
126
+ };
127
+ const skipParentheses = (node) => ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isNonNullExpression(node) || ts.isSatisfiesExpression(node)
128
+ ? skipParentheses(node.expression)
129
+ : node;
@@ -6,6 +6,7 @@ import { rootSpecialization } from './identities.js';
6
6
  import { parameterValueResultOf } from './producers/bindings.js';
7
7
  import { citeSwitchCaseTest, citeSwitchGroupTest, clauseTerminates } from './producers/control.js';
8
8
  import { citeExpressionResult } from './producers/references.js';
9
+ import { constantConditionalGuardResult } from './producers/conditional-guard.js';
9
10
  import { optionalChainGuardOf, optionalCallGuardOf } from './producers/optional-chain.js';
10
11
  import { citeExtractedElementValue } from './producers/destructuring.js';
11
12
  /**
@@ -390,7 +391,10 @@ export const gatingEdges = (input) => {
390
391
  }
391
392
  if (ts.isConditionalExpression(node)) {
392
393
  visit(node.condition, gates);
393
- const guard = guardOf(node.condition, facts);
394
+ const cited = citeExpressionResult(node.condition, facts);
395
+ const guard = cited.kind === 'source' && cited.source.kind === 'constant'
396
+ ? constantConditionalGuardResult(node.condition, facts)
397
+ : guardOf(node.condition, facts);
394
398
  visit(node.whenTrue, guard === null ? gates : [...gates, { kind: 'guard', guard, takenWhen: 'truthy' }]);
395
399
  visit(node.whenFalse, guard === null ? gates : [...gates, { kind: 'guard', guard, takenWhen: 'falsy' }]);
396
400
  return;
@@ -730,6 +730,40 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
730
730
  * have reached that cell through `any`; its ordinary value-flow edges remain
731
731
  * authoritative and an opaque source still fails closed.
732
732
  */
733
+ /**
734
+ * The argument positions of a call into a bodiless ambient function -- a
735
+ * host native -- whose declared parameter type is primitive, with that type.
736
+ *
737
+ * Such a native receives its arguments across the host boundary as the
738
+ * declared types: a `number` parameter is a scalar there, whatever cell the
739
+ * argument was read out of, because the call converts it (or refuses) on
740
+ * the way in. What the native can reach through that argument is what a
741
+ * primitive of that type reaches -- its own wrapper's prototype chain, which
742
+ * `prototypeNamesOf` already models -- not the alias component of the cell
743
+ * it was read from. Charging the component instead stamped `every` onto each
744
+ * intrinsic prototype the component had been merged with, `Map.prototype`
745
+ * among them, for every `x` and `width` handed to a `readPixels`-style
746
+ * native, and refused obligations no native could touch.
747
+ */
748
+ const NO_SCALAR_POSITIONS = new Map();
749
+ const hostNativeScalarParametersOf = (call) => {
750
+ if (call.arguments.some(ts.isSpreadElement))
751
+ return NO_SCALAR_POSITIONS;
752
+ const signature = checker.getResolvedSignature(call);
753
+ const declaration = signature?.declaration;
754
+ if (!signature || !declaration || !isBodilessAmbientFunction(declaration))
755
+ return NO_SCALAR_POSITIONS;
756
+ const positions = new Map();
757
+ signature.parameters.forEach((parameter, position) => {
758
+ const declared = parameter.valueDeclaration;
759
+ if (!declared || !ts.isParameter(declared) || declared.dotDotDotToken)
760
+ return;
761
+ const type = checker.getTypeOfSymbolAtLocation(parameter, call);
762
+ if (primitiveResult(type))
763
+ positions.set(position, type);
764
+ });
765
+ return positions;
766
+ };
733
767
  const primitiveResult = (type) => {
734
768
  if (type.isUnion())
735
769
  return type.types.every(primitiveResult);
@@ -1484,6 +1518,110 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
1484
1518
  }
1485
1519
  return { target, reads };
1486
1520
  };
1521
+ /**
1522
+ * The values a program proxy trap's `target` and `receiver` parameters can
1523
+ * hold, or `null` when this cannot be stated (another parameter, or a
1524
+ * program that can hand the proxy a receiver this census does not see).
1525
+ *
1526
+ * Only the proxy invokes its traps, with `target` = the proxy's target and
1527
+ * `receiver` = the object `[[Get]]`/`[[Set]]` started on: the proxy, an
1528
+ * object inheriting from it, or an explicit `Reflect.get`/`Reflect.set`
1529
+ * receiver. Putting a surface on the chain is a prototype replacement the
1530
+ * census already turns into a wildcard, a fresh inheriting object is the
1531
+ * program's own allocation, and the explicit receivers are enumerated here
1532
+ * -- so `receiver` is the proxy plus those arguments, provided nothing can
1533
+ * reach `Reflect.get`/`Reflect.set` other than as a direct call, and no
1534
+ * `super` access or `__proto__` key can start a lookup on an unseen object.
1535
+ * Sealing a trap's `receiver` opaque instead made `Reflect.set(target,
1536
+ * name, value, receiver)` -- the forwarding every set trap writes -- a
1537
+ * possible write to `globalThis` under every key, refusing every host
1538
+ * global in the program.
1539
+ */
1540
+ const reflectSymbol = (() => {
1541
+ const anchor = files[0];
1542
+ const symbol = anchor ? checker.resolveName('Reflect', anchor, ts.SymbolFlags.Value, false) : undefined;
1543
+ return symbol && hasStandardLibraryDeclaration(symbol) ? symbol : null;
1544
+ })();
1545
+ let explicitTrapReceivers;
1546
+ const explicitTrapReceiversOf = () => {
1547
+ if (explicitTrapReceivers !== undefined)
1548
+ return explicitTrapReceivers;
1549
+ const get = [];
1550
+ const set = [];
1551
+ const closed = (() => {
1552
+ if (reflectSymbol === null || intrinsicSymbolIsOverwritten(reflectSymbol))
1553
+ return false;
1554
+ for (const node of nodes) {
1555
+ if ((ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) &&
1556
+ node.expression.kind === ts.SyntaxKind.SuperKeyword)
1557
+ return false;
1558
+ if ((ts.isIdentifier(node) || ts.isStringLiteralLike(node) || ts.isPrivateIdentifier(node)) && node.text === '__proto__')
1559
+ return false;
1560
+ if (!ts.isIdentifier(node) || actualSymbol(checker.getSymbolAtLocation(node)) !== reflectSymbol)
1561
+ continue;
1562
+ const access = outermostErasureOf(node).parent;
1563
+ // `Reflect` as a value (passed, stored, indexed) can reach `get`/`set` unseen.
1564
+ if (!access || !ts.isPropertyAccessExpression(access) || unwrapErasedExpression(access.expression) !== node)
1565
+ return false;
1566
+ const member = access.name.text;
1567
+ if (member !== 'get' && member !== 'set')
1568
+ continue;
1569
+ const call = outermostErasureOf(access).parent;
1570
+ if (!call || !ts.isCallExpression(call) || unwrapErasedExpression(call.expression) !== access)
1571
+ return false;
1572
+ if (call.arguments.some(ts.isSpreadElement))
1573
+ return false;
1574
+ const receiver = call.arguments[member === 'get' ? 2 : 3];
1575
+ if (receiver)
1576
+ (member === 'get' ? get : set).push(receiver);
1577
+ }
1578
+ return true;
1579
+ })();
1580
+ explicitTrapReceivers = closed ? { get, set } : null;
1581
+ return explicitTrapReceivers;
1582
+ };
1583
+ const handlerMentionsThis = (literal) => {
1584
+ const visit = (node) => node.kind === ts.SyntaxKind.ThisKeyword || (ts.forEachChild(node, visit) ?? false);
1585
+ return visit(literal);
1586
+ };
1587
+ const proxyTrapParameterValuesOf = (parameter) => {
1588
+ if (parameter.dotDotDotToken || parameter.initializer)
1589
+ return null;
1590
+ const trap = parameter.parent;
1591
+ const property = ts.isMethodDeclaration(trap)
1592
+ ? trap
1593
+ : ts.isPropertyAssignment(outermostErasureOf(trap).parent)
1594
+ ? outermostErasureOf(trap).parent
1595
+ : null;
1596
+ if (!property || (!ts.isMethodDeclaration(property) && !ts.isPropertyAssignment(property)))
1597
+ return null;
1598
+ const literal = property.parent;
1599
+ if (!ts.isObjectLiteralExpression(literal))
1600
+ return null;
1601
+ const construct = outermostErasureOf(literal).parent;
1602
+ if (!construct || !ts.isNewExpression(construct) || construct.arguments?.[1] === undefined)
1603
+ return null;
1604
+ if (unwrapErasedExpression(construct.arguments[1]) !== literal)
1605
+ return null;
1606
+ const proxy = programProxyOf(construct);
1607
+ if (proxy === null)
1608
+ return null;
1609
+ // Traps run with `this` = the handler, so `this.set(...)` calls a trap with
1610
+ // arguments of the program's choosing; so does a named trap calling itself.
1611
+ if ((ts.isFunctionExpression(trap) && trap.name) || handlerMentionsThis(literal))
1612
+ return null;
1613
+ const name = staticPropertyName(property.name);
1614
+ const index = trap.parameters.indexOf(parameter);
1615
+ if (index === 0)
1616
+ return [proxy.target];
1617
+ const receiverIndex = name === 'get' ? 2 : name === 'set' ? 3 : -1;
1618
+ if (index !== receiverIndex)
1619
+ return null;
1620
+ const explicit = explicitTrapReceiversOf();
1621
+ if (explicit === null)
1622
+ return null;
1623
+ return [construct, ...(name === 'get' ? explicit.get : explicit.set)];
1624
+ };
1487
1625
  const publishedTypeRepresentation = (type, location) => primitiveResult(type) ? 'primitive' : nativeResult(type, location) ? 'native' : representedObjectResult(type) ? 'object' : null;
1488
1626
  // An object-shaped result type is evidence only at an authenticated call
1489
1627
  // boundary. It is never value provenance by itself: an annotation or cast
@@ -3305,6 +3443,23 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
3305
3443
  }
3306
3444
  return terms;
3307
3445
  };
3446
+ /** The intrinsic prototypes (and their constructors) a value of primitive `type` reaches. */
3447
+ const primitivePrototypeReachOf = (type, at) => {
3448
+ const reach = new Set();
3449
+ for (const name of prototypeNamesOf(type)) {
3450
+ const constructor = checker.resolveName(name, undefined, ts.SymbolFlags.Value, false);
3451
+ if (!constructor || !hasStandardLibraryDeclaration(constructor))
3452
+ continue;
3453
+ const prototype = checker.getPropertyOfType(checker.getTypeOfSymbolAtLocation(constructor, at), 'prototype');
3454
+ const declaration = prototype && hasStandardLibraryDeclaration(prototype) ? identities.symbolDeclarationId(prototype) : null;
3455
+ if (declaration !== null)
3456
+ reach.add(declaration);
3457
+ const constructorId = identities.symbolValueDeclarationId(constructor, at);
3458
+ if (constructorId !== null)
3459
+ reach.add(constructorId);
3460
+ }
3461
+ return reach;
3462
+ };
3308
3463
  const prototypeTerms = new Map();
3309
3464
  const globalTerm = { kind: 'GLOBAL_TRUE' };
3310
3465
  const opaqueTerm = { kind: 'OPAQUE_UNKNOWN' };
@@ -3942,7 +4097,11 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
3942
4097
  if (declaration === null)
3943
4098
  return;
3944
4099
  const currentType = checker.getTypeAtLocation(current);
3945
- if ((currentType.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0 && writesOf(declaration).length === 0) {
4100
+ if ((currentType.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0 &&
4101
+ !writesOf(declaration).some((write) => write.slot === 'whole')) {
4102
+ // A mutation THROUGH an ambient cell (including Object.assign) does
4103
+ // not supply that cell's original identity. Only a whole binding write
4104
+ // can replace its externally supplied, otherwise unknown origin.
3946
4105
  // No body write is not "no evidence" for a PARAMETER: its value comes
3947
4106
  // from its callers, never from a write this function's own body makes.
3948
4107
  // `enumeratedParameterValuesOf` is the closed-caller proof for exactly
@@ -3953,9 +4112,12 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
3953
4112
  // the identifier-parameter case the census can actually enumerate.
3954
4113
  const isIdentifierParameter = ts.isParameter(declaration) && ts.isIdentifier(declaration.name);
3955
4114
  // TEMPORARY bisect switch, remove before landing.
3956
- const parameterValues = isIdentifierParameter && process.env['GEA_NO_ENUMERATED_PARAMETER_VALUES'] !== '1'
3957
- ? enumeratedParameterValuesOf(declaration)
3958
- : null;
4115
+ const parameterValues = !isIdentifierParameter
4116
+ ? null
4117
+ : (proxyTrapParameterValuesOf(declaration) ??
4118
+ (process.env['GEA_NO_ENUMERATED_PARAMETER_VALUES'] !== '1'
4119
+ ? enumeratedParameterValuesOf(declaration)
4120
+ : null));
3959
4121
  // An EMPTY closed set is not a proof of safety, it is the absence of
3960
4122
  // any runtime data point: a function with zero enumerated callers
3961
4123
  // (dead code, or a call graph this proof cannot yet see) never
@@ -4873,6 +5035,12 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
4873
5035
  return false;
4874
5036
  return globalObjectEscapesIntoData() && globalObjectMayInhabit(expression);
4875
5037
  };
5038
+ // A reflective writer can receive an intrinsic/global object from an
5039
+ // external producer even when this program never spelled that object as a
5040
+ // data value. An unplaced target therefore needs the existing per-key
5041
+ // surface stamp, not only the source-global escape test above. A published
5042
+ // carrier remains a per-expression proof that excludes this surface.
5043
+ const mayMutateReflectedSurface = (expression) => mayAliasGlobal(expression) || (aliasFacts(expression).opaque && publishedRepresentationOf(expression) === null);
4876
5044
  /**
4877
5045
  * Whether the global object can be REACHED from a value of this type --
4878
5046
  * `globalObjectMayInhabit`'s question asked transitively, because
@@ -5249,9 +5417,10 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
5249
5417
  // already refuse to trust `facts.opaque` alone for exactly that reason --
5250
5418
  // they ask `publishedRepresentationOf(expression)`, the per-EXPRESSION
5251
5419
  // proof that requires every write reaching this value to agree on one
5252
- // representation, not just this component's coarse term union. Every
5253
- // caller of this function already gates entry on `mayAliasGlobal`, but
5254
- // that gate is `facts.global || (facts.opaque && published === null)`:
5420
+ // representation, not just this component's coarse term union. Ordinary
5421
+ // writes enter through `mayAliasGlobal`; reflected writers additionally
5422
+ // admit an externally supplied opaque surface without a source-global
5423
+ // data escape. In either case a published nonalias proof must survive:
5255
5424
  // when `facts.global` is ALSO true for this component (a genuinely
5256
5425
  // separate, unrelated merge), the gate passes on that disjunct alone and
5257
5426
  // the surface taint below used to fire from `facts.opaque` unconditionally,
@@ -6423,8 +6592,8 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
6423
6592
  }
6424
6593
  if ((mutator === 'Object.setPrototypeOf' || mutator === 'Reflect.setPrototypeOf') &&
6425
6594
  node.arguments[0] &&
6426
- mayAliasGlobal(node.arguments[0])) {
6427
- markWildcard(node, 'global prototype replacement');
6595
+ mayMutateReflectedSurface(node.arguments[0])) {
6596
+ markWildcard(node, 'global or unproven reflected prototype replacement');
6428
6597
  }
6429
6598
  if (mutator === 'Object.defineProperty' ||
6430
6599
  mutator === 'Reflect.defineProperty' ||
@@ -6438,7 +6607,7 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
6438
6607
  // kind of writer and nothing to taint.
6439
6608
  const storesScriptVar = mutator === 'Object.defineProperty' && scriptGlobalValueRedefinitionOf(checker, names, node) !== null;
6440
6609
  for (const receiver of receivers) {
6441
- if (receiver && !storesScriptVar && mayAliasGlobal(receiver))
6610
+ if (receiver && !storesScriptVar && mayMutateReflectedSurface(receiver))
6442
6611
  taintMutationKeys(receiver, keyReader.keysOfKeyExpression(key));
6443
6612
  }
6444
6613
  }
@@ -6448,7 +6617,7 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
6448
6617
  // key set is unknown keys; on a target that may be the global object
6449
6618
  // or an intrinsic, that is the wildcard. (A target that cannot alias
6450
6619
  // one is not a surface: its keys are the alias graph's business.)
6451
- if (mayAliasGlobal(target)) {
6620
+ if (mayMutateReflectedSurface(target)) {
6452
6621
  const keys = mutatorTargetKeys(node, mutator);
6453
6622
  if (keys.some((key) => key.kind === 'every'))
6454
6623
  markWildcard(node, 'unknown bulk-mutator keys');
@@ -6460,10 +6629,18 @@ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
6460
6629
  // mutation. This is intentionally conservative: a missed write would
6461
6630
  // retain a native singleton after JavaScript replaced it.
6462
6631
  if (callAsksContainsGlobal(node)) {
6463
- for (const argument of node.arguments) {
6632
+ const scalarParameters = hostNativeScalarParametersOf(node);
6633
+ for (const [position, argument] of node.arguments.entries()) {
6464
6634
  const current = unwrapErasedExpression(argument);
6465
6635
  const target = containsRequests.get(current);
6466
- const facts = target ? factsByComponent.get(componentOf.get(target)) : undefined;
6636
+ const component = target ? factsByComponent.get(componentOf.get(target)) : undefined;
6637
+ // A scalar host parameter reaches what its primitive reaches, and
6638
+ // nothing else of the cell's component (`hostNativeScalarParametersOf`).
6639
+ const scalar = scalarParameters.get(position);
6640
+ const reach = scalar === undefined ? null : primitivePrototypeReachOf(scalar, current);
6641
+ const facts = component === undefined || reach === null
6642
+ ? component
6643
+ : { ...component, prototypes: new Set([...component.prototypes].filter((declaration) => reach.has(declaration))) };
6467
6644
  if (process.env['GEA_DEBUG_GLOBAL_MUTATION'] && facts && facts.prototypes.size > 0)
6468
6645
  debugSite(argument, `opaque argument exposes ${facts.prototypes.size} intrinsic objects [${[...facts.prototypes].join(' ')}]`);
6469
6646
  // A fully-settled argument (a known intrinsic like `Math`, a plain
@@ -1,3 +1,4 @@
1
+ import { sep } from 'node:path';
1
2
  import ts from 'typescript';
2
3
  import { declarationId, functionId, nodeId } from '../../identity/ids.js';
3
4
  import { isAmbientDeclaration } from '../ambient.js';
@@ -90,10 +91,28 @@ export const createIdentityTable = (program, checker, specializations = emptySpe
90
91
  // `Record` -- and a declaration the compiler can reach must have an identity
91
92
  // wherever it was declared. Excluding them makes `declarationIdOf` throw the
92
93
  // first time any real program mentions a library type.
94
+ //
95
+ // The order is the same on every host. TypeScript names the files it found
96
+ // `C:/x/a.ts` on Windows but keeps a root file as given -- `C:\x\a.ts` -- and
97
+ // a backslash sorts after every letter, so the root's index, and every
98
+ // identity minted in a later file, differed from a POSIX host's. The sort
99
+ // key spells every name with forward slashes and an upper-case drive letter;
100
+ // on POSIX hosts it is the name itself.
101
+ const sortKey = (file) => sep === '/'
102
+ ? file.fileName
103
+ : file.fileName
104
+ .split(sep)
105
+ .join('/')
106
+ .replace(/^[a-z](?=:\/)/, (drive) => drive.toUpperCase());
107
+ const keys = new Map(program.getSourceFiles().map((file) => [file, sortKey(file)]));
93
108
  const files = program
94
109
  .getSourceFiles()
95
110
  .slice()
96
- .sort((left, right) => (left.fileName < right.fileName ? -1 : left.fileName > right.fileName ? 1 : 0));
111
+ .sort((left, right) => {
112
+ const leftKey = keys.get(left) ?? left.fileName;
113
+ const rightKey = keys.get(right) ?? right.fileName;
114
+ return leftKey < rightKey ? -1 : leftKey > rightKey ? 1 : 0;
115
+ });
97
116
  const fileIndex = new Map();
98
117
  files.forEach((file, index) => fileIndex.set(file, `f${index}`));
99
118
  const ordinalsByFile = new Map();