@geastack/compiler 1.0.20 → 1.0.21

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 (534) hide show
  1. package/dist/cli-emit.js +11 -1
  2. package/dist/cli-package-source.d.ts +0 -4
  3. package/dist/cli-package-source.js +8 -112
  4. package/dist/cli-refusal-location.d.ts +6 -0
  5. package/dist/cli-refusal-location.js +5 -0
  6. package/dist/cli.js +2 -1
  7. package/dist/compiler.d.ts +4 -0
  8. package/dist/compiler.js +118 -28
  9. package/dist/conversion/algebra.d.ts +16 -1
  10. package/dist/conversion/algebra.js +2 -0
  11. package/dist/conversion/build.js +16 -6
  12. package/dist/conversion/constructor-identity-family.d.ts +49 -0
  13. package/dist/conversion/constructor-identity-family.js +67 -0
  14. package/dist/conversion/derive.js +39 -6
  15. package/dist/conversion/iterable-object-view.d.ts +44 -0
  16. package/dist/conversion/iterable-object-view.js +55 -0
  17. package/dist/conversion/iterator-object-view.d.ts +77 -0
  18. package/dist/conversion/iterator-object-view.js +112 -0
  19. package/dist/conversion/nodes.d.ts +93 -0
  20. package/dist/conversion/nodes.js +262 -5
  21. package/dist/conversion/operand-view.js +41 -0
  22. package/dist/conversion/protocol-iterator.d.ts +84 -0
  23. package/dist/conversion/protocol-iterator.js +88 -0
  24. package/dist/conversion/record-view.d.ts +152 -8
  25. package/dist/conversion/record-view.js +518 -37
  26. package/dist/conversion/registry.d.ts +32 -0
  27. package/dist/ir/borrowed-call-arguments.d.ts +22 -1
  28. package/dist/ir/borrowed-call-arguments.js +102 -1
  29. package/dist/ir/borrowed-callable-uses.d.ts +62 -0
  30. package/dist/ir/borrowed-callable-uses.js +135 -0
  31. package/dist/ir/boxed-bind-assumptions.d.ts +24 -0
  32. package/dist/ir/boxed-bind-assumptions.js +93 -0
  33. package/dist/ir/build.d.ts +18 -7
  34. package/dist/ir/build.js +71 -13
  35. package/dist/ir/call-dispatch.js +474 -10
  36. package/dist/ir/call-entry.d.ts +24 -1
  37. package/dist/ir/call-entry.js +106 -1
  38. package/dist/ir/callable-class-flow.js +15 -5
  39. package/dist/ir/callable-identity-demand.d.ts +20 -1
  40. package/dist/ir/callable-identity-demand.js +157 -18
  41. package/dist/ir/callable-member-candidates.d.ts +11 -1
  42. package/dist/ir/callable-member-candidates.js +82 -3
  43. package/dist/ir/callable-records.js +2 -2
  44. package/dist/ir/callable-site-escape.d.ts +4 -0
  45. package/dist/ir/callable-site-escape.js +228 -0
  46. package/dist/ir/captures.d.ts +10 -1
  47. package/dist/ir/captures.js +219 -4
  48. package/dist/ir/certify/carrier-keys.d.ts +58 -1
  49. package/dist/ir/certify/carrier-keys.js +158 -6
  50. package/dist/ir/certify/property-access-keys.d.ts +17 -0
  51. package/dist/ir/certify/property-access-keys.js +36 -0
  52. package/dist/ir/certify/property-access.js +49 -4
  53. package/dist/ir/certify/runtime-helper.d.ts +4 -0
  54. package/dist/ir/certify/runtime-helper.js +17 -5
  55. package/dist/ir/certify.js +132 -79
  56. package/dist/ir/class-static-fields.d.ts +11 -0
  57. package/dist/ir/class-static-fields.js +28 -0
  58. package/dist/ir/construct-entry.d.ts +2 -1
  59. package/dist/ir/construct-entry.js +3 -2
  60. package/dist/ir/construction-only-fields.d.ts +73 -0
  61. package/dist/ir/construction-only-fields.js +211 -0
  62. package/dist/ir/dominance.d.ts +14 -0
  63. package/dist/ir/dominance.js +18 -4
  64. package/dist/ir/emission-representations.js +4 -1
  65. package/dist/ir/exception-edges.d.ts +17 -0
  66. package/dist/ir/exception-edges.js +75 -0
  67. package/dist/ir/facts.d.ts +54 -3
  68. package/dist/ir/facts.js +182 -5
  69. package/dist/ir/generator-split.js +2 -2
  70. package/dist/ir/instance-reparenting.d.ts +83 -0
  71. package/dist/ir/instance-reparenting.js +167 -0
  72. package/dist/ir/integer-storage.d.ts +29 -0
  73. package/dist/ir/integer-storage.js +188 -79
  74. package/dist/ir/integers.d.ts +16 -0
  75. package/dist/ir/integers.js +327 -8
  76. package/dist/ir/integrity-restrictions.d.ts +42 -9
  77. package/dist/ir/integrity-restrictions.js +335 -42
  78. package/dist/ir/key-order-observation.d.ts +38 -0
  79. package/dist/ir/key-order-observation.js +173 -0
  80. package/dist/ir/literal-set-membership.d.ts +30 -0
  81. package/dist/ir/literal-set-membership.js +277 -0
  82. package/dist/ir/lower-allocation.js +68 -8
  83. package/dist/ir/lower-completion.d.ts +0 -9
  84. package/dist/ir/lower-completion.js +14 -5
  85. package/dist/ir/lower-destructuring.js +24 -2
  86. package/dist/ir/lower-exceptions.js +4 -4
  87. package/dist/ir/lower-flow.d.ts +21 -0
  88. package/dist/ir/lower-flow.js +37 -3
  89. package/dist/ir/lower-graph.d.ts +19 -1
  90. package/dist/ir/lower-graph.js +91 -67
  91. package/dist/ir/lower-invocation.d.ts +16 -0
  92. package/dist/ir/lower-invocation.js +182 -28
  93. package/dist/ir/lower-narrow.d.ts +0 -46
  94. package/dist/ir/lower-narrow.js +63 -1
  95. package/dist/ir/lower-operands.d.ts +52 -2
  96. package/dist/ir/lower-operands.js +491 -8
  97. package/dist/ir/lower-property.d.ts +2 -1
  98. package/dist/ir/lower-property.js +140 -31
  99. package/dist/ir/lower-protocol.js +16 -4
  100. package/dist/ir/lower-proxy.d.ts +65 -0
  101. package/dist/ir/lower-proxy.js +181 -0
  102. package/dist/ir/lower.js +112 -17
  103. package/dist/ir/model.d.ts +228 -18
  104. package/dist/ir/native-class-accessor.d.ts +9 -2
  105. package/dist/ir/native-class-accessor.js +12 -3
  106. package/dist/ir/native-class-construction.d.ts +1 -1
  107. package/dist/ir/native-class-construction.js +2 -1
  108. package/dist/ir/native-class-initialization.js +2 -2
  109. package/dist/ir/object-value-conversions.js +20 -5
  110. package/dist/ir/operation-index.d.ts +16 -0
  111. package/dist/ir/operation-index.js +17 -0
  112. package/dist/ir/pcm-loops.d.ts +11 -0
  113. package/dist/ir/pcm-loops.js +284 -0
  114. package/dist/ir/presence-proof.js +5 -0
  115. package/dist/ir/program-facts.d.ts +10 -20
  116. package/dist/ir/program-facts.js +80 -6
  117. package/dist/ir/proven-branches.d.ts +2 -2
  118. package/dist/ir/proven-branches.js +196 -3
  119. package/dist/ir/queries.js +35 -1
  120. package/dist/ir/reflection-demand.d.ts +9 -4
  121. package/dist/ir/reflection-demand.js +400 -28
  122. package/dist/ir/refusal.d.ts +1 -0
  123. package/dist/ir/refusal.js +2 -1
  124. package/dist/ir/shake.d.ts +94 -1
  125. package/dist/ir/shake.js +209 -12
  126. package/dist/ir/shared-empty-records.d.ts +12 -0
  127. package/dist/ir/shared-empty-records.js +301 -0
  128. package/dist/ir/spread-copy-elision.d.ts +59 -0
  129. package/dist/ir/spread-copy-elision.js +431 -0
  130. package/dist/ir/stable-cell-reads.d.ts +40 -0
  131. package/dist/ir/stable-cell-reads.js +123 -0
  132. package/dist/ir/static-callables.js +50 -0
  133. package/dist/ir/string-layout-reuse.d.ts +16 -1
  134. package/dist/ir/string-layout-reuse.js +66 -0
  135. package/dist/ir/transfer.d.ts +72 -3
  136. package/dist/ir/transfer.js +511 -19
  137. package/dist/ir/typed-property-access.d.ts +18 -2
  138. package/dist/ir/typed-property-access.js +109 -12
  139. package/dist/ir/verify.js +2 -1
  140. package/dist/plugins/apple/plugin.js +3 -2
  141. package/dist/plugins/gea/host.d.ts +7 -0
  142. package/dist/plugins/gea/host.js +30 -1
  143. package/dist/plugins/gea/lower.js +6 -1
  144. package/dist/plugins/gea/plugin.js +7 -4
  145. package/dist/plugins/gea/render-bridge.d.ts +4 -2
  146. package/dist/plugins/gea/render-bridge.js +23 -7
  147. package/dist/plugins/model.d.ts +2 -0
  148. package/dist/project-preparation.d.ts +5 -1
  149. package/dist/project-preparation.js +164 -7
  150. package/dist/projection/bindings.d.ts +5 -2
  151. package/dist/projection/bindings.js +40 -1
  152. package/dist/projection/callee.d.ts +16 -0
  153. package/dist/projection/callee.js +35 -6
  154. package/dist/projection/class-prototype.js +5 -1
  155. package/dist/projection/classes.d.ts +65 -2
  156. package/dist/projection/classes.js +159 -2
  157. package/dist/projection/dispatch.d.ts +69 -18
  158. package/dist/projection/dispatch.js +391 -19
  159. package/dist/projection/fields.d.ts +4 -3
  160. package/dist/projection/fields.js +89 -21
  161. package/dist/projection/instance-test.d.ts +12 -0
  162. package/dist/projection/instance-test.js +40 -10
  163. package/dist/projection/method-value-escapes.d.ts +43 -0
  164. package/dist/projection/method-value-escapes.js +113 -0
  165. package/dist/projection/slots.d.ts +34 -1
  166. package/dist/projection/slots.js +82 -5
  167. package/dist/representation/any-null-record-members.d.ts +41 -0
  168. package/dist/representation/any-null-record-members.js +115 -0
  169. package/dist/representation/collections.d.ts +3 -1
  170. package/dist/representation/collections.js +5 -2
  171. package/dist/representation/derive.d.ts +9 -1
  172. package/dist/representation/derive.js +366 -25
  173. package/dist/representation/difference.js +14 -0
  174. package/dist/representation/embedded-carriers.js +1 -0
  175. package/dist/representation/host-abi.d.ts +15 -0
  176. package/dist/representation/host-abi.js +28 -0
  177. package/dist/representation/host-templates.d.ts +1 -1
  178. package/dist/representation/host-templates.js +7 -3
  179. package/dist/representation/intersection.js +22 -0
  180. package/dist/representation/json-nullable.d.ts +18 -0
  181. package/dist/representation/json-nullable.js +22 -0
  182. package/dist/representation/model.d.ts +141 -0
  183. package/dist/representation/model.js +47 -3
  184. package/dist/representation/object-shape.d.ts +5 -1
  185. package/dist/representation/object-shape.js +5 -2
  186. package/dist/representation/policies.d.ts +66 -1
  187. package/dist/representation/proxy-carriers.d.ts +71 -0
  188. package/dist/representation/proxy-carriers.js +330 -0
  189. package/dist/representation/publish.d.ts +9 -1
  190. package/dist/representation/publish.js +186 -18
  191. package/dist/representation/record-fields.d.ts +5 -0
  192. package/dist/representation/record-fields.js +7 -1
  193. package/dist/representation/static-field-cells.d.ts +61 -0
  194. package/dist/representation/static-field-cells.js +80 -0
  195. package/dist/representation/unassigned-binding-cells.d.ts +32 -0
  196. package/dist/representation/unassigned-binding-cells.js +44 -0
  197. package/dist/representation/union.js +17 -1
  198. package/dist/representation/unwritten-record-members.d.ts +54 -0
  199. package/dist/representation/unwritten-record-members.js +167 -0
  200. package/dist/representation/value-records.js +153 -11
  201. package/dist/semantics/ambient.d.ts +102 -0
  202. package/dist/semantics/ambient.js +183 -0
  203. package/dist/semantics/any-null-member-declarations.d.ts +32 -0
  204. package/dist/semantics/any-null-member-declarations.js +90 -0
  205. package/dist/semantics/borrowed-builtin-call-bind-source-transform.js +14 -0
  206. package/dist/semantics/borrowed-method-receiver-copy-source-transform.d.ts +51 -0
  207. package/dist/semantics/borrowed-method-receiver-copy-source-transform.js +367 -0
  208. package/dist/semantics/call-invalidated-narrowing.d.ts +3 -0
  209. package/dist/semantics/call-invalidated-narrowing.js +715 -0
  210. package/dist/semantics/callable-origins.d.ts +39 -0
  211. package/dist/semantics/callable-origins.js +73 -2
  212. package/dist/semantics/class-alias.d.ts +21 -0
  213. package/dist/semantics/class-alias.js +45 -14
  214. package/dist/semantics/class-heritage.d.ts +64 -0
  215. package/dist/semantics/class-heritage.js +278 -2
  216. package/dist/semantics/commonjs-wrapper.d.ts +1 -1
  217. package/dist/semantics/commonjs-wrapper.js +24 -7
  218. package/dist/semantics/constructor-function-class-source-transform.d.ts +4 -0
  219. package/dist/semantics/constructor-function-class-source-transform.js +327 -0
  220. package/dist/semantics/constructor-slot-subclasses.js +163 -4
  221. package/dist/semantics/declaration-overlay-transform.js +197 -3
  222. package/dist/semantics/frontend.d.ts +31 -0
  223. package/dist/semantics/frontend.js +177 -19
  224. package/dist/semantics/host-methods.d.ts +27 -2
  225. package/dist/semantics/host-methods.js +57 -4
  226. package/dist/semantics/host-protocols.d.ts +19 -8
  227. package/dist/semantics/host-protocols.js +145 -31
  228. package/dist/semantics/interface-families.d.ts +51 -2
  229. package/dist/semantics/interface-families.js +609 -23
  230. package/dist/semantics/interface-implementors.d.ts +20 -0
  231. package/dist/semantics/interface-implementors.js +130 -6
  232. package/dist/semantics/known-caller-predicate-parameters.d.ts +2 -0
  233. package/dist/semantics/known-caller-predicate-parameters.js +161 -0
  234. package/dist/semantics/model/intrinsic-accessor-getters.d.ts +10 -0
  235. package/dist/semantics/model/intrinsic-accessor-getters.js +4 -0
  236. package/dist/semantics/model/operands.d.ts +10 -0
  237. package/dist/semantics/model/operations.d.ts +107 -0
  238. package/dist/semantics/model/selected-signature.d.ts +33 -0
  239. package/dist/semantics/model/structural-type-table.d.ts +15 -0
  240. package/dist/semantics/model/structural-type-table.js +19 -1
  241. package/dist/semantics/model/structural-types.d.ts +99 -0
  242. package/dist/semantics/model/structural-types.js +31 -2
  243. package/dist/semantics/normalize/absent-globals.d.ts +1 -1
  244. package/dist/semantics/normalize/absent-globals.js +3 -3
  245. package/dist/semantics/normalize/bivariant-slot-parameter.d.ts +46 -0
  246. package/dist/semantics/normalize/bivariant-slot-parameter.js +357 -0
  247. package/dist/semantics/normalize/callback-parameter-contracts.d.ts +2 -0
  248. package/dist/semantics/normalize/callback-parameter-contracts.js +21 -0
  249. package/dist/semantics/normalize/census.d.ts +2 -1
  250. package/dist/semantics/normalize/census.js +25 -2
  251. package/dist/semantics/normalize/class-instance-record-statement.d.ts +37 -0
  252. package/dist/semantics/normalize/class-instance-record-statement.js +74 -0
  253. package/dist/semantics/normalize/collection-bindings.js +242 -5
  254. package/dist/semantics/normalize/commonjs-require.d.ts +26 -0
  255. package/dist/semantics/normalize/commonjs-require.js +355 -121
  256. package/dist/semantics/normalize/dead-event-emissions.d.ts +6 -0
  257. package/dist/semantics/normalize/dead-event-emissions.js +866 -0
  258. package/dist/semantics/normalize/dead-method-copies.d.ts +56 -0
  259. package/dist/semantics/normalize/dead-method-copies.js +239 -0
  260. package/dist/semantics/normalize/derived-expression-type.d.ts +149 -2
  261. package/dist/semantics/normalize/derived-expression-type.js +418 -14
  262. package/dist/semantics/normalize/field-bindings.js +139 -4
  263. package/dist/semantics/normalize/flow/callable-reach.js +162 -9
  264. package/dist/semantics/normalize/flow/member-call-forwarding.js +6 -0
  265. package/dist/semantics/normalize/flow/owned-class-receivers.js +40 -2
  266. package/dist/semantics/normalize/flow/source-class-data.d.ts +7 -1
  267. package/dist/semantics/normalize/flow/source-class-data.js +28 -9
  268. package/dist/semantics/normalize/flow/source-value-session.js +32 -13
  269. package/dist/semantics/normalize/flow/targets.d.ts +32 -0
  270. package/dist/semantics/normalize/flow/targets.js +65 -6
  271. package/dist/semantics/normalize/flow/value-flow.d.ts +7 -0
  272. package/dist/semantics/normalize/flow/value-flow.js +30 -2
  273. package/dist/semantics/normalize/fresh-array-result.d.ts +32 -0
  274. package/dist/semantics/normalize/fresh-array-result.js +125 -0
  275. package/dist/semantics/normalize/gating.js +2 -0
  276. package/dist/semantics/normalize/global-host-mutations.d.ts +11 -1
  277. package/dist/semantics/normalize/global-host-mutations.js +691 -27
  278. package/dist/semantics/normalize/host-effect-contracts.d.ts +43 -1
  279. package/dist/semantics/normalize/host-effect-contracts.js +60 -3
  280. package/dist/semantics/normalize/identities.js +49 -3
  281. package/dist/semantics/normalize/intrinsic-accessor-getter.d.ts +59 -0
  282. package/dist/semantics/normalize/intrinsic-accessor-getter.js +129 -0
  283. package/dist/semantics/normalize/local-bindings.js +117 -21
  284. package/dist/semantics/normalize/merged-declaration.d.ts +41 -0
  285. package/dist/semantics/normalize/merged-declaration.js +81 -0
  286. package/dist/semantics/normalize/never-override-result.d.ts +21 -0
  287. package/dist/semantics/normalize/never-override-result.js +64 -0
  288. package/dist/semantics/normalize/null-blind-parameter.d.ts +21 -0
  289. package/dist/semantics/normalize/null-blind-parameter.js +77 -0
  290. package/dist/semantics/normalize/object-bag-bindings.js +10 -0
  291. package/dist/semantics/normalize/override-field-arms.d.ts +33 -0
  292. package/dist/semantics/normalize/override-field-arms.js +362 -0
  293. package/dist/semantics/normalize/parameter-bindings.d.ts +64 -1
  294. package/dist/semantics/normalize/parameter-bindings.js +801 -81
  295. package/dist/semantics/normalize/parameter-slot.d.ts +1 -0
  296. package/dist/semantics/normalize/parameter-slot.js +69 -0
  297. package/dist/semantics/normalize/physical-overload-result.d.ts +45 -0
  298. package/dist/semantics/normalize/physical-overload-result.js +132 -0
  299. package/dist/semantics/normalize/producer-context.d.ts +23 -0
  300. package/dist/semantics/normalize/producers/allocations.d.ts +13 -0
  301. package/dist/semantics/normalize/producers/allocations.js +8 -15
  302. package/dist/semantics/normalize/producers/binding-kind.d.ts +11 -0
  303. package/dist/semantics/normalize/producers/binding-kind.js +31 -0
  304. package/dist/semantics/normalize/producers/bindings.js +16 -1
  305. package/dist/semantics/normalize/producers/boundary.js +21 -1
  306. package/dist/semantics/normalize/producers/class-lifecycle.js +23 -14
  307. package/dist/semantics/normalize/producers/computations.js +8 -67
  308. package/dist/semantics/normalize/producers/control-loops.d.ts +1 -1
  309. package/dist/semantics/normalize/producers/control-loops.js +25 -1
  310. package/dist/semantics/normalize/producers/control.js +87 -60
  311. package/dist/semantics/normalize/producers/declaration-lifecycle.js +5 -0
  312. package/dist/semantics/normalize/producers/enums.d.ts +10 -0
  313. package/dist/semantics/normalize/producers/enums.js +169 -0
  314. package/dist/semantics/normalize/producers/erasure.d.ts +10 -0
  315. package/dist/semantics/normalize/producers/erasure.js +23 -0
  316. package/dist/semantics/normalize/producers/intrinsic-accessor-getter.d.ts +15 -0
  317. package/dist/semantics/normalize/producers/intrinsic-accessor-getter.js +33 -0
  318. package/dist/semantics/normalize/producers/invocations.js +255 -18
  319. package/dist/semantics/normalize/producers/iteration-yield.js +6 -1
  320. package/dist/semantics/normalize/producers/logical-merge-type.d.ts +36 -0
  321. package/dist/semantics/normalize/producers/logical-merge-type.js +163 -0
  322. package/dist/semantics/normalize/producers/properties.js +207 -18
  323. package/dist/semantics/normalize/producers/protocol.d.ts +4 -0
  324. package/dist/semantics/normalize/producers/protocol.js +147 -12
  325. package/dist/semantics/normalize/producers/references.js +50 -9
  326. package/dist/semantics/normalize/producers/shared.d.ts +120 -0
  327. package/dist/semantics/normalize/producers/shared.js +359 -10
  328. package/dist/semantics/normalize/producers/spread-arguments.js +85 -4
  329. package/dist/semantics/normalize/producers/tuple-spread.d.ts +1 -0
  330. package/dist/semantics/normalize/producers/tuple-spread.js +1 -1
  331. package/dist/semantics/normalize/property-key-domain.js +6 -0
  332. package/dist/semantics/normalize/reachability.d.ts +7 -0
  333. package/dist/semantics/normalize/reachability.js +166 -9
  334. package/dist/semantics/normalize/record-home-arms.d.ts +25 -0
  335. package/dist/semantics/normalize/record-home-arms.js +87 -0
  336. package/dist/semantics/normalize/record-link-families.d.ts +74 -0
  337. package/dist/semantics/normalize/record-link-families.js +327 -0
  338. package/dist/semantics/normalize/record-stand-in-arms.d.ts +56 -0
  339. package/dist/semantics/normalize/record-stand-in-arms.js +484 -0
  340. package/dist/semantics/normalize/return-bindings.d.ts +6 -2
  341. package/dist/semantics/normalize/return-bindings.js +60 -7
  342. package/dist/semantics/normalize/script-global-redefinition.js +5 -0
  343. package/dist/semantics/normalize/shared-array-storage.d.ts +42 -0
  344. package/dist/semantics/normalize/shared-array-storage.js +373 -0
  345. package/dist/semantics/normalize/sloppy-absence.d.ts +41 -0
  346. package/dist/semantics/normalize/sloppy-absence.js +199 -0
  347. package/dist/semantics/normalize/specialization.d.ts +40 -0
  348. package/dist/semantics/normalize/specialization.js +770 -36
  349. package/dist/semantics/normalize/structural-array-element.js +196 -6
  350. package/dist/semantics/normalize/structural-array-read.js +12 -0
  351. package/dist/semantics/normalize/structural-creation-order.d.ts +15 -0
  352. package/dist/semantics/normalize/structural-creation-order.js +51 -48
  353. package/dist/semantics/normalize/structural-declarations.d.ts +16 -0
  354. package/dist/semantics/normalize/structural-declarations.js +43 -0
  355. package/dist/semantics/normalize/structural-generics.d.ts +13 -0
  356. package/dist/semantics/normalize/structural-generics.js +22 -0
  357. package/dist/semantics/normalize/structural-indexed-access.js +16 -0
  358. package/dist/semantics/normalize/structural-instantiated-member.js +68 -2
  359. package/dist/semantics/normalize/structural-joins.js +2 -0
  360. package/dist/semantics/normalize/structural-layout-relevance.d.ts +30 -0
  361. package/dist/semantics/normalize/structural-layout-relevance.js +164 -0
  362. package/dist/semantics/normalize/structural-layout-type.js +270 -14
  363. package/dist/semantics/normalize/structural-leaves.d.ts +1 -1
  364. package/dist/semantics/normalize/structural-leaves.js +17 -3
  365. package/dist/semantics/normalize/structural-mutable-method.js +5 -1
  366. package/dist/semantics/normalize/structural-parts.d.ts +18 -5
  367. package/dist/semantics/normalize/structural-parts.js +68 -19
  368. package/dist/semantics/normalize/structural-receiver.d.ts +1 -1
  369. package/dist/semantics/normalize/structural-receiver.js +23 -1
  370. package/dist/semantics/normalize/structural-self-reference.d.ts +1 -1
  371. package/dist/semantics/normalize/structural-self-reference.js +23 -2
  372. package/dist/semantics/normalize/structural.d.ts +12 -1
  373. package/dist/semantics/normalize/structural.js +1420 -53
  374. package/dist/semantics/normalize/suppressed-write-arms.d.ts +47 -0
  375. package/dist/semantics/normalize/suppressed-write-arms.js +393 -0
  376. package/dist/semantics/normalize/unresolvable-names.d.ts +15 -2
  377. package/dist/semantics/normalize/unresolvable-names.js +30 -6
  378. package/dist/semantics/normalize/unshared-array-result.d.ts +32 -0
  379. package/dist/semantics/normalize/unshared-array-result.js +125 -0
  380. package/dist/semantics/package-sources.d.ts +1 -1
  381. package/dist/semantics/package-sources.js +120 -8
  382. package/dist/semantics/program.d.ts +20 -0
  383. package/dist/semantics/program.js +145 -14
  384. package/dist/semantics/stable-checker.d.ts +1 -1
  385. package/dist/semantics/stable-checker.js +7 -2
  386. package/dist/semantics/unchecked-guard-argument-copies.d.ts +67 -0
  387. package/dist/semantics/unchecked-guard-argument-copies.js +163 -0
  388. package/dist/semantics/unchecked-write-member-declarations.d.ts +46 -0
  389. package/dist/semantics/unchecked-write-member-declarations.js +331 -0
  390. package/dist/targets/cpp/balanced-units.d.ts +31 -0
  391. package/dist/targets/cpp/balanced-units.js +57 -0
  392. package/dist/targets/cpp/borrowed-arm-projections.d.ts +31 -0
  393. package/dist/targets/cpp/borrowed-arm-projections.js +106 -0
  394. package/dist/targets/cpp/borrowed-call-entry.d.ts +1 -1
  395. package/dist/targets/cpp/borrowed-call-entry.js +24 -20
  396. package/dist/targets/cpp/captures.js +314 -8
  397. package/dist/targets/cpp/char-code-buffers.d.ts +36 -0
  398. package/dist/targets/cpp/char-code-buffers.js +214 -0
  399. package/dist/targets/cpp/class-layout.d.ts +7 -1
  400. package/dist/targets/cpp/class-layout.js +42 -17
  401. package/dist/targets/cpp/class-properties/computed-method-value.d.ts +17 -2
  402. package/dist/targets/cpp/class-properties/computed-method-value.js +50 -4
  403. package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +31 -1
  404. package/dist/targets/cpp/class-properties/emit-class-properties.js +174 -17
  405. package/dist/targets/cpp/class-ref-transport.d.ts +32 -0
  406. package/dist/targets/cpp/class-ref-transport.js +56 -1
  407. package/dist/targets/cpp/conversions.js +1827 -1502
  408. package/dist/targets/cpp/coroutine-bodies.d.ts +97 -0
  409. package/dist/targets/cpp/coroutine-bodies.js +187 -0
  410. package/dist/targets/cpp/document.js +11 -1
  411. package/dist/targets/cpp/emit-allocation.js +535 -21
  412. package/dist/targets/cpp/emit-arrays.d.ts +10 -0
  413. package/dist/targets/cpp/emit-arrays.js +147 -16
  414. package/dist/targets/cpp/emit-binding-reference.d.ts +26 -2
  415. package/dist/targets/cpp/emit-binding-reference.js +97 -5
  416. package/dist/targets/cpp/emit-bindings.d.ts +9 -1
  417. package/dist/targets/cpp/emit-bindings.js +108 -8
  418. package/dist/targets/cpp/emit-buffers.d.ts +2 -16
  419. package/dist/targets/cpp/emit-buffers.js +124 -25
  420. package/dist/targets/cpp/emit-callable.d.ts +35 -72
  421. package/dist/targets/cpp/emit-callable.js +647 -82
  422. package/dist/targets/cpp/emit-carrier-members.d.ts +13 -2
  423. package/dist/targets/cpp/emit-carrier-members.js +50 -9
  424. package/dist/targets/cpp/emit-constructor-identity-family.d.ts +20 -0
  425. package/dist/targets/cpp/emit-constructor-identity-family.js +45 -0
  426. package/dist/targets/cpp/emit-context.d.ts +329 -15
  427. package/dist/targets/cpp/emit-context.js +104 -13
  428. package/dist/targets/cpp/emit-dynamic-properties.d.ts +44 -0
  429. package/dist/targets/cpp/emit-dynamic-properties.js +256 -37
  430. package/dist/targets/cpp/emit-equality.js +117 -2
  431. package/dist/targets/cpp/emit-error-constructor.d.ts +19 -0
  432. package/dist/targets/cpp/emit-error-constructor.js +73 -0
  433. package/dist/targets/cpp/emit-exceptions.d.ts +25 -3
  434. package/dist/targets/cpp/emit-exceptions.js +215 -26
  435. package/dist/targets/cpp/emit-in.js +52 -5
  436. package/dist/targets/cpp/emit-instanceof.js +59 -11
  437. package/dist/targets/cpp/emit-integers.d.ts +6 -0
  438. package/dist/targets/cpp/emit-integers.js +10 -0
  439. package/dist/targets/cpp/emit-iterable-object-view.d.ts +15 -0
  440. package/dist/targets/cpp/emit-iterable-object-view.js +51 -0
  441. package/dist/targets/cpp/emit-iterator-object-view.d.ts +15 -0
  442. package/dist/targets/cpp/emit-iterator-object-view.js +125 -0
  443. package/dist/targets/cpp/emit-iterator.d.ts +7 -10
  444. package/dist/targets/cpp/emit-iterator.js +361 -24
  445. package/dist/targets/cpp/emit-json.d.ts +7 -1
  446. package/dist/targets/cpp/emit-json.js +595 -55
  447. package/dist/targets/cpp/emit-jsx.d.ts +0 -37
  448. package/dist/targets/cpp/emit-jsx.js +70 -8
  449. package/dist/targets/cpp/emit-narrowing.d.ts +192 -28
  450. package/dist/targets/cpp/emit-narrowing.js +1595 -120
  451. package/dist/targets/cpp/emit-native-selection.js +8 -2
  452. package/dist/targets/cpp/emit-presence.js +13 -0
  453. package/dist/targets/cpp/emit-properties.d.ts +3 -1
  454. package/dist/targets/cpp/emit-properties.js +303 -54
  455. package/dist/targets/cpp/emit-protocol-iterator.d.ts +14 -0
  456. package/dist/targets/cpp/emit-protocol-iterator.js +203 -0
  457. package/dist/targets/cpp/emit-proxy.d.ts +17 -0
  458. package/dist/targets/cpp/emit-proxy.js +35 -0
  459. package/dist/targets/cpp/emit-record-view.d.ts +12 -1
  460. package/dist/targets/cpp/emit-record-view.js +429 -18
  461. package/dist/targets/cpp/emit-return.d.ts +38 -0
  462. package/dist/targets/cpp/emit-return.js +143 -21
  463. package/dist/targets/cpp/emit-scopes.d.ts +78 -0
  464. package/dist/targets/cpp/emit-scopes.js +196 -0
  465. package/dist/targets/cpp/emit-sum-widening.js +6 -3
  466. package/dist/targets/cpp/emit-tonumber.d.ts +40 -1
  467. package/dist/targets/cpp/emit-tonumber.js +75 -4
  468. package/dist/targets/cpp/emit-tostring.d.ts +28 -2
  469. package/dist/targets/cpp/emit-tostring.js +115 -12
  470. package/dist/targets/cpp/emit-typeof.js +2 -2
  471. package/dist/targets/cpp/emit-union-properties.d.ts +9 -0
  472. package/dist/targets/cpp/emit-union-properties.js +375 -46
  473. package/dist/targets/cpp/emit.d.ts +3 -1
  474. package/dist/targets/cpp/emit.js +725 -90
  475. package/dist/targets/cpp/evaluated-once.d.ts +51 -0
  476. package/dist/targets/cpp/evaluated-once.js +140 -0
  477. package/dist/targets/cpp/host/core-globals.d.ts +0 -21
  478. package/dist/targets/cpp/host/core-globals.js +10 -2
  479. package/dist/targets/cpp/host/emit-host-invoke.d.ts +0 -10
  480. package/dist/targets/cpp/host/emit-host-invoke.js +454 -36
  481. package/dist/targets/cpp/host/emit-host-object.js +733 -88
  482. package/dist/targets/cpp/host/emit-host-properties.js +26 -2
  483. package/dist/targets/cpp/host/emit-host-reflect.d.ts +1 -0
  484. package/dist/targets/cpp/host/emit-host-reflect.js +26 -7
  485. package/dist/targets/cpp/host/emit-host-value.d.ts +13 -0
  486. package/dist/targets/cpp/host/emit-host-value.js +47 -3
  487. package/dist/targets/cpp/host/host-members.d.ts +11 -0
  488. package/dist/targets/cpp/host/host-members.js +50 -4
  489. package/dist/targets/cpp/host/native-protocols.js +3 -0
  490. package/dist/targets/cpp/host/object-protocol.d.ts +8 -0
  491. package/dist/targets/cpp/host/object-protocol.js +55 -13
  492. package/dist/targets/cpp/key-order-tracking.d.ts +11 -0
  493. package/dist/targets/cpp/key-order-tracking.js +18 -0
  494. package/dist/targets/cpp/manifest/capabilities.js +107 -8
  495. package/dist/targets/cpp/manifest.js +14 -0
  496. package/dist/targets/cpp/native-collection-base.d.ts +27 -0
  497. package/dist/targets/cpp/native-collection-base.js +202 -0
  498. package/dist/targets/cpp/native-error-base.d.ts +14 -0
  499. package/dist/targets/cpp/native-error-base.js +19 -4
  500. package/dist/targets/cpp/native-promise-base.d.ts +23 -0
  501. package/dist/targets/cpp/native-promise-base.js +30 -0
  502. package/dist/targets/cpp/native-symbol-keys.js +1 -1
  503. package/dist/targets/cpp/prototype/emit-prototype-array.js +258 -20
  504. package/dist/targets/cpp/prototype/emit-prototype-date.js +5 -4
  505. package/dist/targets/cpp/prototype/emit-prototype-invoke.d.ts +9 -1
  506. package/dist/targets/cpp/prototype/emit-prototype-invoke.js +232 -26
  507. package/dist/targets/cpp/prototype/emit-prototype-iterator.d.ts +1 -1
  508. package/dist/targets/cpp/prototype/emit-prototype-iterator.js +111 -13
  509. package/dist/targets/cpp/prototype/emit-prototype-promise.d.ts +33 -4
  510. package/dist/targets/cpp/prototype/emit-prototype-promise.js +218 -10
  511. package/dist/targets/cpp/prototype/emit-prototype-regexp.js +8 -5
  512. package/dist/targets/cpp/prototype/emit-prototype-string.js +24 -7
  513. package/dist/targets/cpp/prototype/prototype-method-reads.js +18 -3
  514. package/dist/targets/cpp/reactive-dependencies.d.ts +2 -0
  515. package/dist/targets/cpp/reactive-dependencies.js +94 -3
  516. package/dist/targets/cpp/realm-storage.d.ts +5 -0
  517. package/dist/targets/cpp/realm-storage.js +12 -0
  518. package/dist/targets/cpp/records.d.ts +151 -1
  519. package/dist/targets/cpp/records.js +1321 -122
  520. package/dist/targets/cpp/recursive-containers.d.ts +4 -1
  521. package/dist/targets/cpp/recursive-containers.js +28 -9
  522. package/dist/targets/cpp/translation-unit.d.ts +10 -0
  523. package/dist/targets/cpp/translation-unit.js +686 -140
  524. package/dist/targets/cpp/types.d.ts +56 -6
  525. package/dist/targets/cpp/types.js +218 -12
  526. package/dist/targets/cpp/virtual-methods.d.ts +3 -3
  527. package/dist/targets/cpp/virtual-methods.js +174 -17
  528. package/package.json +6 -5
  529. package/src/targets/cpp/runtime/gea_dynamic_proxy.h +155 -25
  530. package/src/targets/cpp/runtime/gea_eval.h +3 -0
  531. package/src/targets/cpp/runtime/gea_pcm.h +116 -0
  532. package/src/targets/cpp/runtime/gea_runtime.h +18096 -4876
  533. package/src/targets/cpp/runtime/gea_runtime_builtins.cpp +7 -45
  534. package/src/targets/cpp/runtime/gea_runtime_rtc.h +247 -0
@@ -1,19 +1,19 @@
1
1
  import { callableCompletionSummaryOf } from './flow/callable-completions.js';
2
2
  import ts from 'typescript';
3
- import { isAmbientDeclaration } from '../ambient.js';
3
+ import { globalSymbolBehindModuleAmbientConst, isAmbientDeclaration, moduleAmbientGlobalSatisfiesDeclaration } from '../ambient.js';
4
4
  import { unwrapErasedExpression } from './producers/erasure.js';
5
5
  import { scriptGlobalValueRedefinitionOf } from './script-global-redefinition.js';
6
- import { sourceClassDataMemberPlanOf } from './flow/source-class-data.js';
6
+ import { reflectiveDefinitionMayInstallGetterOf, sourceClassDataMemberPlanOf } from './flow/source-class-data.js';
7
7
  import { sourceRecordSlotValuesOf } from './flow/source-record-data.js';
8
8
  import { isRealCallableDeclaration, runtimeParametersOf } from './flow/targets.js';
9
- import { seededOriginSolver } from './flow/seeded-origins.js';
10
- import { closedCallableAuthorityOf } from './flow/callable-reach.js';
9
+ import { isVacuousOrigin, seededOriginSolver } from './flow/seeded-origins.js';
10
+ import { closedCallableAuthorityOf, closedValueOriginAuthorityOf } from './flow/callable-reach.js';
11
11
  import { sourceConstructorSelectionsOf, sourceConstructorReturnValuesOf } from './flow/member-call-forwarding.js';
12
12
  import { wholeProgram } from './reachability.js';
13
13
  import { createPropertyKeyDomains } from './property-key-domain.js';
14
14
  import { HostMutationTaint, everyKey, keySetTouches, namedKey, numericKeys } from './host-mutation-keys.js';
15
15
  import { attachDeferredIntrinsicProtocolLedger, createDeferredIntrinsicProtocolLedger, deferredIntrinsicProtocolLedgerOf, failedIntrinsicProtocolRequirements } from './deferred-intrinsic-protocols.js';
16
- import { symbolIsStandardLibraryMutator, symbolStatesHostInert, symbolWritesNoHostProperty } from './host-effect-contracts.js';
16
+ import { symbolIsStandardLibraryMutator, symbolStatesHostInert, symbolWritesNoIntrinsicProperty } from './host-effect-contracts.js';
17
17
  import { createMutationKeyReader, hostAccessorNamesOf, isProgramDeclaredSymbolKey, keyOfName } from './host-mutation-key-reader.js';
18
18
  const staticKeyOf = (node) => {
19
19
  if (ts.isPropertyAccessExpression(node))
@@ -102,7 +102,16 @@ declarationFiles = [],
102
102
  * census only ever narrows a write's key through this; `null` keeps the
103
103
  * key unknown.
104
104
  */
105
- computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
105
+ computedKeysOf = () => null,
106
+ /**
107
+ * The outcome kind when this call is a checker-authenticated static
108
+ * CommonJS `require` the invocation producer lowers to a `commonjs-require`
109
+ * module-record operation (`staticRequireOutcomeOf`), else `null`. Such a
110
+ * call runs only a compiled module body, or nothing at all when it throws
111
+ * `MODULE_NOT_FOUND` for a package absent from the build; see
112
+ * `unknownCalleeStampIsNarrowed` and the alias graph's call rule.
113
+ */
114
+ staticCommonJsRequireOutcomeOf = () => null, trustSeed = initialCensusSeed) => {
106
115
  const tainted = new HostMutationTaint();
107
116
  // Every intrinsic member name this run trusted, and every key its visit
108
117
  // wrote on a surface, a global binding or an intrinsic object: see
@@ -949,13 +958,20 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
949
958
  };
950
959
  });
951
960
  const hasFreshLiteralIdentity = (expression) => freshLiteralOrigin(expression) === 'allocated';
952
- const isIntrinsicSurface = (expression, seen = new Set()) => {
961
+ /**
962
+ * `byType` admits the structural fallback: a receiver whose static type a
963
+ * native receiver type is assignable to, or from, may be that native object
964
+ * (or its intrinsic prototype, which the standard library types as an
965
+ * instance). Without it the answer is identity only -- the global object, a
966
+ * standard-library binding, or a local cell some write fills with one.
967
+ */
968
+ const isIntrinsicSurface = (expression, seen = new Set(), byType = true) => {
953
969
  const current = unwrapErasedExpression(expression);
954
970
  if (hasFreshLiteralIdentity(current))
955
971
  return false;
956
972
  if (isProvenGlobalObject(current) ||
957
- nativeResult(checker.getTypeAtLocation(current), current) ||
958
- mayBeAuthenticatedNativeSurface(checker.getTypeAtLocation(current))) {
973
+ (byType &&
974
+ (nativeResult(checker.getTypeAtLocation(current), current) || mayBeAuthenticatedNativeSurface(checker.getTypeAtLocation(current))))) {
959
975
  return true;
960
976
  }
961
977
  if (ts.isIdentifier(current)) {
@@ -970,12 +986,12 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
970
986
  return flow
971
987
  .writesToDeclaration(declaration)
972
988
  .filter((write) => flowSiteIsReachable(write.site) && write.slot === 'whole' && write.value !== null)
973
- .some((write) => isIntrinsicSurface(write.value, next));
989
+ .some((write) => isIntrinsicSurface(write.value, next, byType));
974
990
  }
975
991
  if (!ts.isPropertyAccessExpression(current) && !ts.isElementAccessExpression(current))
976
992
  return false;
977
993
  if (staticKeyOf(current) === 'prototype')
978
- return isIntrinsicSurface(current.expression, seen);
994
+ return isIntrinsicSurface(current.expression, seen, byType);
979
995
  const symbol = memberSymbolOf(current);
980
996
  return isProvenGlobalObject(current.expression) && !!symbol && hasStandardLibraryDeclaration(symbol);
981
997
  };
@@ -1035,11 +1051,44 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
1035
1051
  for (const key of keys)
1036
1052
  tainted.taintObject(id, key);
1037
1053
  };
1038
- const markOverwrittenMember = (target, key) => {
1054
+ /**
1055
+ * A write of an unknown key through a receiver only the STRUCTURAL fallback
1056
+ * places on an intrinsic surface -- bson's `obj: Record<string, unknown> =
1057
+ * Object.create(null)`, the driver's `dest: Document` -- is decided after
1058
+ * the alias graph, not here. `Document`'s `[key: string]: any` accepts every
1059
+ * object type, so the type test says yes for every such receiver; only the
1060
+ * value's provenance can say no, and the provenance proof
1061
+ * (`isFreshProgramObject` below) needs the closed caller frames and source
1062
+ * invocation facts this pass runs before. Until then this run assumes the
1063
+ * write is harmless, and the census re-runs with every intrinsic distrusted
1064
+ * from the start if the proof does not close -- the same fixed point
1065
+ * `CensusSeed` already runs for every other assumption made here.
1066
+ *
1067
+ * A receiver that IS an intrinsic by identity (a standard global, the global
1068
+ * object, a cell holding one) is not deferred: nothing downstream could
1069
+ * clear it, and a re-run would only cost the time.
1070
+ */
1071
+ const deferredSurfaceWrites = [];
1072
+ const invalidateForSurfaceWrite = (receiver, site) => {
1073
+ if (allIntrinsicTrustInvalidated)
1074
+ return;
1075
+ if (isIntrinsicSurface(receiver, new Set(), false))
1076
+ invalidateAllIntrinsicTrust(site);
1077
+ else
1078
+ deferredSurfaceWrites.push(receiver);
1079
+ };
1080
+ /**
1081
+ * `Object.defineProperty(o, kDecorated, ...)` with a program-declared unique
1082
+ * symbol: the same argument `isDefinitelyProgramSymbolElementKey` makes for
1083
+ * `o[sym] = v`. The key names no string member and is not `__proto__`, so
1084
+ * whatever `o` is, it replaces no intrinsic member a static call resolves to.
1085
+ */
1086
+ const isProgramSymbolKeyExpression = (expression) => expression !== undefined && isProgramDeclaredSymbolKey(publishedTypeAt(unwrapErasedExpression(expression)));
1087
+ const markOverwrittenMember = (target, key, keyExpression) => {
1039
1088
  markIntrinsicPrototypeKeys(target, key === null ? [everyKey] : [key === '__proto__' ? everyKey : namedKey(key)]);
1040
1089
  if (key === null) {
1041
- if (isIntrinsicSurface(target))
1042
- invalidateAllIntrinsicTrust(target);
1090
+ if (!isProgramSymbolKeyExpression(keyExpression) && isIntrinsicSurface(target))
1091
+ invalidateForSurfaceWrite(target, target);
1043
1092
  return;
1044
1093
  }
1045
1094
  const symbol = actualSymbol(checker.getPropertyOfType(checker.getTypeAtLocation(target), key));
@@ -1089,7 +1138,7 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
1089
1138
  // A prototype replacement can affect every method, regardless of its
1090
1139
  // name. Other computed writes invalidate only the names they can reach.
1091
1140
  if (domain === null || propertyKeyDomains.mayName(domain, '__proto__') || propertyKeyDomains.mayName(domain, 'prototype'))
1092
- invalidateAllIntrinsicTrust(node);
1141
+ invalidateForSurfaceWrite(node.expression, node);
1093
1142
  else
1094
1143
  computedIntrinsicKeys.add(domain);
1095
1144
  }
@@ -1108,7 +1157,7 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
1108
1157
  mutator === 'Reflect.set' ||
1109
1158
  mutator === 'Reflect.deleteProperty') {
1110
1159
  const key = node.arguments[1] ? staticKeyExpression(node.arguments[1]) : null;
1111
- markOverwrittenMember(target, key);
1160
+ markOverwrittenMember(target, key, node.arguments[1]);
1112
1161
  }
1113
1162
  else if (mutator === 'Object.assign' || mutator === 'Object.defineProperties') {
1114
1163
  const sources = mutator === 'Object.assign' ? node.arguments.slice(1) : node.arguments.slice(1, 2);
@@ -1223,6 +1272,60 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
1223
1272
  const summary = callableCompletionSummaryOf(flow, declaration);
1224
1273
  return summary === null ? [] : [...summary.values, ...summary.yields];
1225
1274
  };
1275
+ /**
1276
+ * `new Proxy( target, handler )` with the standard `Proxy`, a handler that
1277
+ * is an object literal of program traps, and only the traps whose effect
1278
+ * this census can state: `set`/`has`/`deleteProperty` run program code
1279
+ * (censused where it is written) and hand back only a boolean, and `get`
1280
+ * hands back its own return values. Every other operation forwards to the
1281
+ * target. So the proxy is exactly its target plus the `get` trap's results
1282
+ * -- never the global object, never a host object -- which is what the alias
1283
+ * graph records (`AliasTerm` `proxy`). Anything else keeps the ordinary
1284
+ * `new` rule: a library constructor with no body is opaque.
1285
+ *
1286
+ * mongodb's optional-dependency stub (`makeErrorModule` in `deps.ts`) is
1287
+ * one: a proxy over `{ kModuleError }` whose `get` trap throws.
1288
+ */
1289
+ const proxyConstructorSymbol = (() => {
1290
+ const anchor = files[0];
1291
+ const symbol = anchor ? checker.resolveName('Proxy', anchor, ts.SymbolFlags.Value, false) : undefined;
1292
+ return symbol && hasStandardLibraryDeclaration(symbol) ? symbol : null;
1293
+ })();
1294
+ const programProxyTraps = new Set(['get', 'set', 'has', 'deleteProperty']);
1295
+ const programProxyOf = (construct) => {
1296
+ const callee = unwrapErasedExpression(construct.expression);
1297
+ if (proxyConstructorSymbol === null || allIntrinsicTrustInvalidated || !ts.isIdentifier(callee))
1298
+ return null;
1299
+ if (actualSymbol(checker.getSymbolAtLocation(callee)) !== proxyConstructorSymbol ||
1300
+ intrinsicSymbolIsOverwritten(proxyConstructorSymbol))
1301
+ return null;
1302
+ const [target, handler] = construct.arguments ?? [];
1303
+ if (construct.arguments?.length !== 2 || !target || !handler || ts.isSpreadElement(target) || ts.isSpreadElement(handler))
1304
+ return null;
1305
+ const literal = unwrapErasedExpression(handler);
1306
+ if (!ts.isObjectLiteralExpression(literal))
1307
+ return null;
1308
+ const reads = [];
1309
+ for (const property of literal.properties) {
1310
+ const name = ts.isMethodDeclaration(property) || ts.isPropertyAssignment(property) ? staticPropertyName(property.name) : null;
1311
+ if (name === null || !programProxyTraps.has(name))
1312
+ return null;
1313
+ const initializer = ts.isPropertyAssignment(property) ? unwrapErasedExpression(property.initializer) : null;
1314
+ const trap = ts.isMethodDeclaration(property)
1315
+ ? property
1316
+ : initializer !== null && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer))
1317
+ ? initializer
1318
+ : null;
1319
+ if (trap === null || trap.asteriskToken !== undefined)
1320
+ return null;
1321
+ const summary = callableCompletionSummaryOf(flow, trap);
1322
+ if (summary === null || summary.execution !== 'sync')
1323
+ return null;
1324
+ if (name === 'get')
1325
+ reads.push(...summary.values);
1326
+ }
1327
+ return { target, reads };
1328
+ };
1226
1329
  const publishedTypeRepresentation = (type, location) => primitiveResult(type) ? 'primitive' : nativeResult(type, location) ? 'native' : representedObjectResult(type) ? 'object' : null;
1227
1330
  // An object-shaped result type is evidence only at an authenticated call
1228
1331
  // boundary. It is never value provenance by itself: an annotation or cast
@@ -1997,11 +2100,14 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
1997
2100
  const facts = declaration === null ? undefined : mutatorAliases.get(declaration);
1998
2101
  return facts !== undefined && (facts.size !== 1 || facts.has('UNKNOWN'));
1999
2102
  };
2000
- const invalidateIntrinsicMember = (target, key) => {
2103
+ const invalidateIntrinsicMember = (target, key, keyExpression) => {
2001
2104
  if (!isIntrinsicSurface(target) && !standardGlobalValue(target))
2002
2105
  return;
2003
2106
  if (key === null) {
2004
- invalidateAllIntrinsicTrust(target);
2107
+ if (standardGlobalValue(target))
2108
+ invalidateAllIntrinsicTrust(target);
2109
+ else if (!isProgramSymbolKeyExpression(keyExpression))
2110
+ invalidateForSurfaceWrite(target, target);
2005
2111
  return;
2006
2112
  }
2007
2113
  markOverwrittenMember(target, key);
@@ -2030,7 +2136,7 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
2030
2136
  mutator === 'Reflect.defineProperty' ||
2031
2137
  mutator === 'Reflect.set' ||
2032
2138
  mutator === 'Reflect.deleteProperty') {
2033
- invalidateIntrinsicMember(target, node.arguments[1] ? staticKeyExpression(node.arguments[1]) : null);
2139
+ invalidateIntrinsicMember(target, node.arguments[1] ? staticKeyExpression(node.arguments[1]) : null, node.arguments[1]);
2034
2140
  }
2035
2141
  else if (mutator === 'Object.assign') {
2036
2142
  for (const source of node.arguments.slice(1))
@@ -3466,6 +3572,13 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
3466
3572
  node.seeds.add(opaqueTerm);
3467
3573
  return;
3468
3574
  }
3575
+ // `require( 'optional-peer' )` of a package absent from the build never
3576
+ // completes normally: the backend throws `MODULE_NOT_FOUND` in its place
3577
+ // (`gea::commonjs::absentPackage`). It hands its binding no value at all,
3578
+ // so it contributes no origin -- the `catch` arm's value is the only one
3579
+ // mongodb's `getGcpMetadata()` can return.
3580
+ if (staticCommonJsRequireOutcomeOf(current) === 'absent-package')
3581
+ return;
3469
3582
  const call = reachableCallOfNode.get(current);
3470
3583
  const declaration = executableDeclarationOf(callDeclarationAt(current));
3471
3584
  const body = declaration && ts.isFunctionLike(declaration) ? declaration.body : undefined;
@@ -3475,6 +3588,21 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
3475
3588
  // carrier. The result is not an identity copy of the property lookup:
3476
3589
  // receiver-sensitive calls were refused before this point unless the
3477
3590
  // receiver itself had non-global provenance.
3591
+ //
3592
+ // When the call's callee set is CLOSED -- every frame the shared
3593
+ // invocation proof admits returns only values it names -- those values
3594
+ // are the result's whole origin, so the result carries theirs and
3595
+ // nothing else: no represented-but-unplaced marker a consumer would have
3596
+ // to read as "possibly anything" (`unknownCalleeStampIsNarrowed`'s
3597
+ // receiver rule is one).
3598
+ const frames = representation === 'object' && sourceFrameOwnedCalls.has(current) ? sourceInvocationFacts.get(current)?.frames : undefined;
3599
+ if (frames && frames.length > 0 && frames.every((frame) => frame.completions.kind === 'values')) {
3600
+ for (const frame of frames)
3601
+ if (frame.completions.kind === 'values')
3602
+ for (const value of frame.completions.values)
3603
+ link(valueNodeOf(value), node);
3604
+ return;
3605
+ }
3478
3606
  node.seeds.add(representedNonGlobalTerm);
3479
3607
  if (representation === 'object' && declaration && !declaration.getSourceFile().isDeclarationFile && body) {
3480
3608
  for (const returned of observableCompletionValuesOf(declaration))
@@ -3502,6 +3630,12 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
3502
3630
  return;
3503
3631
  }
3504
3632
  if (ts.isNewExpression(current)) {
3633
+ const proxy = programProxyOf(current);
3634
+ if (proxy !== null) {
3635
+ link(valueNodeOf(proxy.target), node);
3636
+ node.seeds.add({ kind: 'proxy', reads: proxy.reads.map(valueNodeOf) });
3637
+ return;
3638
+ }
3505
3639
  const constructionReturns = sourceConstructionReturnsOf(current.expression);
3506
3640
  for (const value of constructionReturns ?? [])
3507
3641
  link(valueNodeOf(value), node);
@@ -4014,6 +4148,22 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
4014
4148
  addTerm(target, globalTerm);
4015
4149
  return;
4016
4150
  }
4151
+ if (term.kind === 'proxy') {
4152
+ // Every key read runs the `get` trap when there is one, so any read
4153
+ // (and anything reachable from one) may be a trap result. Without the
4154
+ // trap a read forwards to the target, whose terms this proxy's node
4155
+ // already carries.
4156
+ for (const value of term.reads) {
4157
+ const source = componentOf.get(value);
4158
+ if (!source)
4159
+ throw new Error('global-host mutation proxy read was not condensed');
4160
+ if (selector.key === null)
4161
+ addSelector(source, null, target, childModeOf(selector.mode));
4162
+ else
4163
+ addFlow(source, target);
4164
+ }
4165
+ return;
4166
+ }
4017
4167
  if (term.kind === 'source-containment') {
4018
4168
  if (selector.key === null) {
4019
4169
  for (const value of selector.mode === 'copied-reachable' ? term.ownValues : term.values) {
@@ -4759,7 +4909,7 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
4759
4909
  addExpression(write.source);
4760
4910
  continue;
4761
4911
  }
4762
- if (term.kind === 'rest') {
4912
+ if (term.kind === 'rest' || term.kind === 'proxy') {
4763
4913
  unknown = true;
4764
4914
  continue;
4765
4915
  }
@@ -5165,7 +5315,31 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
5165
5315
  // the intrinsics its arguments reach", so the narrower contract answers it
5166
5316
  // as completely as the full one. `authenticatedCalleeIdentity` still asks
5167
5317
  // for `@gea-host-inert`, because retention and re-entry matter there.
5168
- if (symbolWritesNoHostProperty(symbol))
5318
+ // The typed-array-element contract answers it too: a store into a typed
5319
+ // array's element storage puts no key on any intrinsic
5320
+ // (`host-effect-contracts.ts`).
5321
+ if (symbolWritesNoIntrinsicProperty(symbol))
5322
+ return null;
5323
+ // A module-scoped `declare const atob: ...` is not a host native of its
5324
+ // own: no module binding exists at run time, and its linkage name is the
5325
+ // global's (`globalSymbolBehindModuleAmbientConst`). Binding placement
5326
+ // resolves that name through the installed host's tables BEFORE the
5327
+ // standard-library fallback, and the fallback is gated on the
5328
+ // standard-library declaration, so the local declaration reaches either
5329
+ // the very host binding the global declaration reaches, or none (an
5330
+ // unresolved external, which does not link). So the global's stated
5331
+ // contract is exactly the one that covers it. A global stating no
5332
+ // contract keeps the refusal: the local is then as unknown as the global.
5333
+ //
5334
+ // Only when the global SATISFIES the module's declaration -- the one
5335
+ // condition under which the declaration is blanked and the name really is
5336
+ // the global (`withoutModuleAmbientGlobalRedeclarations`). A module's
5337
+ // `declare const external: (value: unknown) => void` is unrelated to
5338
+ // lib.dom's `declare var external: External` that merely shares the
5339
+ // spelling; borrowing that global's contract made a callable no source
5340
+ // file defines look inert.
5341
+ const global = globalSymbolBehindModuleAmbientConst(checker, symbol);
5342
+ if (global !== null && moduleAmbientGlobalSatisfiesDeclaration(checker, symbol, global) && symbolWritesNoIntrinsicProperty(global))
5169
5343
  return null;
5170
5344
  const ambient = declarations.filter((declaration) => isAmbientDeclaration(declaration) || declaration.getSourceFile().isDeclarationFile);
5171
5345
  if (ambient.length === 0 || ambient.length !== declarations.length)
@@ -5275,6 +5449,17 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
5275
5449
  return true;
5276
5450
  if (ts.isExpressionWithTypeArguments(parent) && ts.isHeritageClause(parent.parent))
5277
5451
  return true;
5452
+ // `encrypted.sort = sort`: a plain store to (or `delete` of) a member
5453
+ // never performs [[Get]] on it, so the library callable that member names
5454
+ // on the receiver's type is not read, let alone handed out. A compound or
5455
+ // logical assignment reads first, and stays a value position.
5456
+ if (ts.isPropertyAccessExpression(parent) && parent.name === node) {
5457
+ const outer = parent.parent;
5458
+ if (ts.isBinaryExpression(outer) && outer.left === parent && outer.operatorToken.kind === ts.SyntaxKind.EqualsToken)
5459
+ return true;
5460
+ if (ts.isDeleteExpression(outer) && outer.expression === parent)
5461
+ return true;
5462
+ }
5278
5463
  return false;
5279
5464
  };
5280
5465
  /**
@@ -5291,10 +5476,13 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
5291
5476
  * `toString`/`subarray`, whose implementation is the native carrier -- is
5292
5477
  * not, and keeps needing a stated contract.
5293
5478
  */
5294
- const ambientCallableIsProgramSupplied = (symbol) => {
5479
+ const ambientCallableIsProgramSupplied = (symbol, seen = new Set()) => {
5295
5480
  const declaration = symbol.declarations?.[0];
5296
5481
  if (!declaration)
5297
5482
  return false;
5483
+ const inherited = classChainMemberOfMergedSignature(symbol);
5484
+ if (inherited !== undefined)
5485
+ return inherited !== null && !seen.has(inherited) && ambientCallableIsProgramSupplied(inherited, new Set([...seen, symbol]));
5298
5486
  const signatures = checker.getSignaturesOfType(checker.getTypeOfSymbolAtLocation(symbol, declaration), ts.SignatureKind.Call);
5299
5487
  return (signatures.length > 0 &&
5300
5488
  signatures.every((signature) => {
@@ -5304,6 +5492,41 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
5304
5492
  supplied.body !== undefined);
5305
5493
  }));
5306
5494
  };
5495
+ /**
5496
+ * mongodb's `export declare interface TypedEventEmitter<E> extends
5497
+ * EventEmitter { listeners(...): E[K][] }` merged into `export class
5498
+ * TypedEventEmitter<E> extends EventEmitter {}`. A method signature on an
5499
+ * interface puts no value anywhere: at run time `emitter.listeners` is
5500
+ * whatever the class's prototype chain holds -- the class's own member of
5501
+ * that name, else its base class's. So the signature is answered for by
5502
+ * that member, and a base whose method has a body in this program is
5503
+ * program code like any other.
5504
+ *
5505
+ * `undefined`: not such a signature, answer for the symbol itself. `null`:
5506
+ * it is one, and nothing on the chain names the member -- it is supplied
5507
+ * some other way, so it is not program code.
5508
+ */
5509
+ const classChainMemberOfMergedSignature = (symbol) => {
5510
+ const declarations = symbol.declarations ?? [];
5511
+ if (declarations.length === 0 || !declarations.every((node) => ts.isMethodSignature(node) && ts.isInterfaceDeclaration(node.parent)))
5512
+ return undefined;
5513
+ const owners = new Set(declarations.map((node) => checker.getSymbolAtLocation(node.parent.name)));
5514
+ const [owner] = owners;
5515
+ if (owners.size !== 1 || !owner)
5516
+ return undefined;
5517
+ const classDeclarations = (owner.declarations ?? []).filter(ts.isClassDeclaration);
5518
+ const classDeclaration = classDeclarations[0];
5519
+ if (classDeclarations.length !== 1 || !classDeclaration || classDeclaration.getSourceFile().isDeclarationFile)
5520
+ return undefined;
5521
+ const name = symbol.getName();
5522
+ const own = classDeclaration.members.find((member) => member.name !== undefined && ts.isIdentifier(member.name) && member.name.text === name);
5523
+ if (own)
5524
+ return own.name ? (actualSymbol(checker.getSymbolAtLocation(own.name)) ?? null) : null;
5525
+ const base = classDeclaration.heritageClauses?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
5526
+ if (!base)
5527
+ return null;
5528
+ return actualSymbol(checker.getTypeAtLocation(base).getProperty(name)) ?? null;
5529
+ };
5307
5530
  const forwardingLibraryMember = (node, symbol) => FORWARDING_MEMBERS.has(node.text) && hasStandardLibraryDeclaration(symbol);
5308
5531
  const returnHandsBackCallable = (declaration) => {
5309
5532
  if (!ts.isFunctionLike(declaration))
@@ -5435,6 +5658,43 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
5435
5658
  return stampRefusal('eval-or-function-callee');
5436
5659
  if (untaggedHostCallableEscapesAsValue())
5437
5660
  return stampRefusal('host-callable-escapes-as-value');
5661
+ // A static CommonJS `require( 'x' )` is not a call of the ambient
5662
+ // `require` declaration at all. The producer lowers it to a
5663
+ // `commonjs-require` operation with NO operands -- the specifier is
5664
+ // resolved at compile time -- which the backend spells as a call of the
5665
+ // target module's own generated initializer. So nothing this call's
5666
+ // argument reaches is handed to any code (and a string literal carries no
5667
+ // object), and the only code it runs is a compiled module body, whose
5668
+ // writes this census reads in that module's own file, exactly as for any
5669
+ // other program body. What it returns is that module's exports record,
5670
+ // which the alias graph handles as the call's result, not here. A require
5671
+ // of a package absent from the build runs no code at all: it throws a
5672
+ // fresh `Error` carrying `code: 'MODULE_NOT_FOUND'` and nothing else. A require
5673
+ // the producer does NOT lower that way -- a possibly reassigned or
5674
+ // unauthenticated loader, a computed specifier, an unresolved one --
5675
+ // falls through and keeps the host-native refusal.
5676
+ if (staticCommonJsRequireOutcomeOf(call) !== null)
5677
+ return true;
5678
+ // A method read off a receiver that is no host object cannot BE an
5679
+ // untagged host native. The escape check above already proved no such
5680
+ // native is ever held as a value, so the only way to reach one is to read
5681
+ // it off a host object -- and every host object enters this graph opaque
5682
+ // (a bodiless call or construction, a declaration-file value, a class
5683
+ // chain that is not source-owned). A receiver whose provenance is only
5684
+ // program allocations reads program values or library members. mongodb's
5685
+ // `gcpMetadata.instance( ... )` is typed by the types-only `gcp-metadata`
5686
+ // declarations, but the value is `getGcpMetadata()`'s: the absent
5687
+ // package's `require` throws, and the `catch` hands back a program proxy.
5688
+ // Represented and intrinsic receivers keep the declaration's answer.
5689
+ const calleeRead = unwrapErasedExpression(call.expression);
5690
+ if (ts.isPropertyAccessExpression(calleeRead) || ts.isElementAccessExpression(calleeRead)) {
5691
+ const receiver = aliasFacts(calleeRead.expression);
5692
+ if (!receiver.opaque && !receiver.global && !receiver.represented && receiver.prototypes.size === 0)
5693
+ return true;
5694
+ if (process.env['GEA_DEBUG_GLOBAL_MUTATION'])
5695
+ debugSite(call, `callee receiver may be a host object: opaque=${receiver.opaque} global=${receiver.global} ` +
5696
+ `represented=${receiver.represented} intrinsics=${receiver.prototypes.size}`);
5697
+ }
5438
5698
  // Kept only as a fast path over the whole-program predicate: a callee
5439
5699
  // spelled as an untagged ambient bodiless declaration is a host native
5440
5700
  // outright, with no cell in between. It must not be the gate -- see
@@ -5475,7 +5735,14 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
5475
5735
  // An untagged HOST native keeps `every`: its writes are in no source file,
5476
5736
  // so `visitWrittenKeys` bounds nothing about it. That is the whole of the
5477
5737
  // per-declaration contract's job.
5478
- return library || supplied ? true : stampRefusal('callee-is-host-native');
5738
+ if (library || supplied)
5739
+ return true;
5740
+ // The site, not only the per-name count: `require` alone is ten calls of
5741
+ // two different kinds (static module records and dynamic loads), and
5742
+ // only the site says which one is still refusing.
5743
+ if (process.env['GEA_DEBUG_GLOBAL_MUTATION'])
5744
+ debugSite(call, `refused callee-is-host-native ${row}`);
5745
+ return stampRefusal('callee-is-host-native');
5479
5746
  };
5480
5747
  /**
5481
5748
  * Objects an unauthenticated call reached with a narrowed stamp, held until
@@ -5913,6 +6180,395 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
5913
6180
  }
5914
6181
  ts.forEachChild(node, visit);
5915
6182
  };
6183
+ /**
6184
+ * Can this receiver hold only ordinary objects THIS program allocated, or
6185
+ * no object at all? The proof a deferred surface write (see
6186
+ * `invalidateForSurfaceWrite`) needs.
6187
+ *
6188
+ * Soundness. An intrinsic object -- a constructor, a namespace, a
6189
+ * prototype, the global object -- and a native (host-carried) instance
6190
+ * enter a program only as values: a standard-library binding, a host call
6191
+ * result, a native allocation. None of those is a seed below, and every
6192
+ * other node must enumerate ALL of its values or refuse:
6193
+ *
6194
+ * - a literal, and `Object.create(p)`, allocate a fresh ordinary object;
6195
+ * `Object.assign(t, ...)` returns `t`. Both calls are trusted by name
6196
+ * through `intrinsicSymbolIsOverwritten`, so a program that replaces
6197
+ * either is re-run with that name distrusted.
6198
+ * - a local binding holds its complete reachable whole writes; `x += y`
6199
+ * always stores a primitive.
6200
+ * - a parameter holds its closed caller frame
6201
+ * (`enumeratedParameterValuesOf`, which fails closed for an escaping,
6202
+ * exported or `arguments`-reading callable, and whose intrinsic
6203
+ * requirements join the invocation ledger this census validates).
6204
+ * - a source call returns its closed frames' normal completions.
6205
+ * - a property read holds its slot's complete stored values
6206
+ * (`closedValueOriginAuthorityOf(...).fieldValuesOf`, the shared
6207
+ * closed-slot proof; its requirements join the same ledger).
6208
+ * - a primitive, `null`/`undefined`, or a never-reassigned identifier read
6209
+ * under its own `typeof x === '<primitive>'` guard is no object at all.
6210
+ *
6211
+ * A write through such a receiver creates or replaces an own property of a
6212
+ * program allocation. It cannot replace a member of any intrinsic, so no
6213
+ * static intrinsic callee selection depends on it. Everything else --
6214
+ * property reads, `this`, host results, casts from `any` -- refuses.
6215
+ */
6216
+ const objectConstructorSymbol = (() => {
6217
+ const anchor = files[0];
6218
+ const symbol = anchor ? checker.resolveName('Object', anchor, ts.SymbolFlags.Value, false) : undefined;
6219
+ return symbol && hasStandardLibraryDeclaration(symbol) ? symbol : null;
6220
+ })();
6221
+ const trustedObjectStatic = (callee, member) => {
6222
+ const current = unwrapErasedExpression(callee);
6223
+ if (!objectConstructorSymbol || !ts.isPropertyAccessExpression(current))
6224
+ return false;
6225
+ if (actualSymbol(checker.getSymbolAtLocation(unwrapErasedExpression(current.expression))) !== objectConstructorSymbol)
6226
+ return false;
6227
+ const expected = actualSymbol(checker.getTypeOfSymbol(objectConstructorSymbol).getProperty(member));
6228
+ const symbol = actualSymbol(checker.getSymbolAtLocation(current.name));
6229
+ return !!symbol && symbol === expected && !allIntrinsicTrustInvalidated && !intrinsicSymbolIsOverwritten(symbol);
6230
+ };
6231
+ const neverReassigned = (declaration) => writesOf(declaration).every((write) => write.slot !== 'whole' ||
6232
+ write.edge === 'declaration-initializer' ||
6233
+ write.edge === 'call-argument' ||
6234
+ write.edge === 'super-argument' ||
6235
+ write.edge === 'default-parameter');
6236
+ /**
6237
+ * Can a get/set of `key` on an object whose prototype chain holds only this
6238
+ * program's class prototypes and `Object.prototype` run an accessor?
6239
+ *
6240
+ * Class prototypes carry the accessors their class bodies declare (a getter,
6241
+ * a setter or an `accessor` field, by any name that can equal `key`), and
6242
+ * whatever a decorator or a reflective definition puts there -- which the
6243
+ * caller rules out separately with the class family's inventory, and which
6244
+ * any decorator anywhere refuses here. `Object.prototype` carries a library
6245
+ * accessor (`hostAccessorNames`) or a key this census found written on it.
6246
+ * A computed accessor name refuses unless it is a symbol: a well-known one
6247
+ * or a program-declared unique one, neither of which is a string key.
6248
+ */
6249
+ /**
6250
+ * The accessor names that can be on an object's prototype chain, as a
6251
+ * name set or `every`. `family` null: every accessor this program declares
6252
+ * anywhere. `family` a base class: only what can sit between an instance of
6253
+ * it and `Object.prototype` -- its own accessors and those of every class
6254
+ * that extends it, directly or through a chain -- plus every object-literal
6255
+ * accessor (a literal can be spliced into a chain reflectively, which the
6256
+ * class family's inventory, not this scan, is what refuses). A class whose
6257
+ * `extends` names no class declaration this scan can resolve might extend
6258
+ * the base, so it counts as family. A decorator anywhere can install
6259
+ * anything, so it is `every` for every family.
6260
+ */
6261
+ const accessorNamesOnChain = new Map();
6262
+ const classFamilyOf = (base) => {
6263
+ const family = new Set([base]);
6264
+ const classes = nodes.filter((node) => ts.isClassDeclaration(node) || ts.isClassExpression(node));
6265
+ for (let grew = true; grew;) {
6266
+ grew = false;
6267
+ for (const candidate of classes) {
6268
+ if (family.has(candidate))
6269
+ continue;
6270
+ const heritage = candidate.heritageClauses?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
6271
+ if (!heritage)
6272
+ continue;
6273
+ const symbol = actualSymbol(checker.getSymbolAtLocation(unwrapErasedExpression(heritage.expression)));
6274
+ // `extends Error`: a standard-library constructor nothing replaced is
6275
+ // that intrinsic, never a program class.
6276
+ if (symbol && hasStandardLibraryDeclaration(symbol) && !allIntrinsicTrustInvalidated && !intrinsicSymbolIsOverwritten(symbol))
6277
+ continue;
6278
+ const declaration = symbol?.valueDeclaration;
6279
+ const extended = declaration !== undefined && (ts.isClassDeclaration(declaration) || ts.isClassExpression(declaration)) ? declaration : null;
6280
+ if (extended === null || family.has(extended)) {
6281
+ family.add(candidate);
6282
+ grew = true;
6283
+ }
6284
+ }
6285
+ }
6286
+ return family;
6287
+ };
6288
+ const accessorNamesOnChainOf = (family) => {
6289
+ const known = accessorNamesOnChain.get(family);
6290
+ if (known !== undefined)
6291
+ return known;
6292
+ const members = family === null ? null : classFamilyOf(family);
6293
+ const names = new Set();
6294
+ let every = false;
6295
+ for (const node of nodes) {
6296
+ if (ts.isDecorator(node))
6297
+ every = true;
6298
+ const name = ts.isGetAccessorDeclaration(node) || ts.isSetAccessorDeclaration(node)
6299
+ ? node.name
6300
+ : ts.isPropertyDeclaration(node) && node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AccessorKeyword)
6301
+ ? node.name
6302
+ : null;
6303
+ if (!name || ts.isPrivateIdentifier(name))
6304
+ continue;
6305
+ if (members !== null && ts.isClassLike(node.parent) && !members.has(node.parent))
6306
+ continue;
6307
+ if (ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name))
6308
+ names.add(name.text);
6309
+ else if (ts.isComputedPropertyName(name)) {
6310
+ const expression = unwrapErasedExpression(name.expression);
6311
+ const owner = ts.isPropertyAccessExpression(expression)
6312
+ ? actualSymbol(checker.getSymbolAtLocation(unwrapErasedExpression(expression.expression)))
6313
+ : undefined;
6314
+ const wellKnown = owner != null &&
6315
+ hasStandardLibraryDeclaration(owner) &&
6316
+ (checker.getTypeAtLocation(expression).flags & ts.TypeFlags.UniqueESSymbol) !== 0;
6317
+ if (!wellKnown && !isProgramDeclaredSymbolKey(publishedTypeAt(expression)))
6318
+ every = true;
6319
+ }
6320
+ else
6321
+ every = true;
6322
+ }
6323
+ const answer = every ? 'every' : names;
6324
+ accessorNamesOnChain.set(family, answer);
6325
+ return answer;
6326
+ };
6327
+ /**
6328
+ * Can a get/set of `key` on an object whose prototype chain holds only this
6329
+ * program's class prototypes and `Object.prototype` run an accessor?
6330
+ *
6331
+ * Class prototypes carry the accessors their class bodies declare (a getter,
6332
+ * a setter or an `accessor` field, by any name that can equal `key`), and
6333
+ * whatever a decorator or a reflective definition puts there -- which the
6334
+ * caller rules out separately with the class family's inventory, and which
6335
+ * any decorator anywhere refuses here. `Object.prototype` carries a library
6336
+ * accessor (`hostAccessorNames`) or a key this census found written on it.
6337
+ * A computed accessor name refuses unless it is a symbol: a well-known one
6338
+ * or a program-declared unique one, neither of which is a string key.
6339
+ *
6340
+ * `family`, when given, is the base class the object was constructed by:
6341
+ * then only that class family's accessors are on the chain
6342
+ * (`accessorNamesOnChainOf`), not every class's in the program.
6343
+ */
6344
+ const accessorMayRunFor = (key, family = null) => {
6345
+ const names = accessorNamesOnChainOf(family);
6346
+ if (names === 'every' || names.has(key) || hostAccessorNames.has(key))
6347
+ return true;
6348
+ // `flow.accessorNames` is the same program-wide scan, kept as the
6349
+ // unfamilied answer only: a family answer has already filtered it.
6350
+ if (family === null && flow.accessorNames.has(key))
6351
+ return true;
6352
+ const inherited = objectPrototypeKeysOf(tainted);
6353
+ return inherited.every || inherited.names.has(key) || (inherited.numeric && String(Number(key)) === key);
6354
+ };
6355
+ /**
6356
+ * Does this base-class constructor keep `this` to itself? Every mention of
6357
+ * `this` in its parameters, its body and the class's instance field
6358
+ * initializers is a get or set of a named member no accessor can intercept
6359
+ * (`accessorMayRunFor`), never a method call, a computed member, a private
6360
+ * member or the bare value. Then no code but these member stores and loads
6361
+ * ever holds the object while the constructor runs, and nothing can have
6362
+ * made one of its own properties an accessor. A parameter property is a
6363
+ * store of its own name.
6364
+ */
6365
+ const constructorKeepsThisLocal = (constructor) => {
6366
+ for (const parameter of constructor.parameters)
6367
+ if (ts.canHaveModifiers(parameter) &&
6368
+ ts.getModifiers(parameter)?.length &&
6369
+ (!ts.isIdentifier(parameter.name) || accessorMayRunFor(parameter.name.text, constructor.parent)))
6370
+ return false;
6371
+ let local = true;
6372
+ const visit = (node) => {
6373
+ if (!local)
6374
+ return;
6375
+ if (node.kind === ts.SyntaxKind.ThisKeyword) {
6376
+ const access = node.parent;
6377
+ local =
6378
+ ts.isPropertyAccessExpression(access) &&
6379
+ access.expression === node &&
6380
+ ts.isIdentifier(access.name) &&
6381
+ !((ts.isCallExpression(access.parent) || ts.isNewExpression(access.parent)) && access.parent.expression === access) &&
6382
+ !ts.isTaggedTemplateExpression(access.parent) &&
6383
+ !accessorMayRunFor(access.name.text, constructor.parent);
6384
+ return;
6385
+ }
6386
+ if (ts.isFunctionLike(node) && !ts.isArrowFunction(node) && node !== constructor)
6387
+ return;
6388
+ if (ts.isClassLike(node))
6389
+ return;
6390
+ ts.forEachChild(node, visit);
6391
+ };
6392
+ ts.forEachChild(constructor, visit);
6393
+ for (const member of constructor.parent.members)
6394
+ if (ts.isPropertyDeclaration(member) && !ts.getModifiers(member)?.some((modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword)) {
6395
+ if (!ts.isIdentifier(member.name) || accessorMayRunFor(member.name.text, constructor.parent))
6396
+ return false;
6397
+ if (member.initializer)
6398
+ visit(member.initializer);
6399
+ }
6400
+ return local;
6401
+ };
6402
+ /**
6403
+ * `this.commandObj = {}; this.commandObj[commandName] = true` in a base
6404
+ * class constructor: the receiver of the second statement is the value the
6405
+ * first one stored, whatever else the slot holds elsewhere.
6406
+ *
6407
+ * Control reaches a statement only from the normal completion of the one
6408
+ * before it in the same list, and the write's receiver is the first thing
6409
+ * its statement evaluates, so no code runs between the [[Set]] and this
6410
+ * [[Get]]. In a base class constructor `this` is an ordinary object made by
6411
+ * [[Construct]] (never a proxy or exotic object) whose prototype chain is
6412
+ * its class family's prototypes and `Object.prototype` -- the family
6413
+ * inventory (`sourceClassDataMemberPlanOf`) refuses any reference to one of
6414
+ * those constructors or prototypes it cannot explain, which is every way a
6415
+ * foreign `newTarget` could reach them, and `reflectiveDefinitionMayInstallGetterOf`
6416
+ * refuses a reflective definition or prototype swap of the key on any
6417
+ * target not proven a fresh program allocation (which is never a prototype
6418
+ * of anything this program constructs). Both statements sit directly in
6419
+ * the constructor body, not in a nested function that could run after the
6420
+ * object escaped and something defined an own accessor on it. Class
6421
+ * code is strict, so a [[Set]] that cannot store throws instead of
6422
+ * completing. The [[Get]] then returns the stored value unless an accessor
6423
+ * for that key is on the object or its chain: `constructorKeepsThisLocal`
6424
+ * rules out an own one, `accessorMayRunFor` an inherited one.
6425
+ */
6426
+ const valueStoredJustBefore = (read) => {
6427
+ if (read.expression.kind !== ts.SyntaxKind.ThisKeyword || !ts.isIdentifier(read.name))
6428
+ return null;
6429
+ const access = read.parent;
6430
+ if (!(ts.isElementAccessExpression(access) || ts.isPropertyAccessExpression(access)) || access.expression !== read)
6431
+ return null;
6432
+ const operation = access.parent;
6433
+ const written = (ts.isBinaryExpression(operation) &&
6434
+ operation.left === access &&
6435
+ operation.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&
6436
+ operation.operatorToken.kind <= ts.SyntaxKind.LastAssignment) ||
6437
+ (ts.isDeleteExpression(operation) && operation.expression === access);
6438
+ if (!written || !ts.isExpressionStatement(operation.parent))
6439
+ return null;
6440
+ const statement = operation.parent;
6441
+ const list = statement.parent;
6442
+ if (!ts.isBlock(list) && !ts.isCaseClause(list) && !ts.isDefaultClause(list))
6443
+ return null;
6444
+ const index = list.statements.indexOf(statement);
6445
+ const previous = index > 0 ? list.statements[index - 1] : undefined;
6446
+ if (!previous || !ts.isExpressionStatement(previous))
6447
+ return null;
6448
+ const store = previous.expression;
6449
+ if (!ts.isBinaryExpression(store) || store.operatorToken.kind !== ts.SyntaxKind.EqualsToken)
6450
+ return null;
6451
+ const target = store.left;
6452
+ if (!ts.isPropertyAccessExpression(target) ||
6453
+ target.expression.kind !== ts.SyntaxKind.ThisKeyword ||
6454
+ !ts.isIdentifier(target.name) ||
6455
+ target.name.text !== read.name.text)
6456
+ return null;
6457
+ const owner = ts.findAncestor(list, (node) => ts.isFunctionLike(node) || ts.isClassStaticBlockDeclaration(node));
6458
+ if (!owner || !ts.isConstructorDeclaration(owner))
6459
+ return null;
6460
+ if (owner.parent.heritageClauses?.some((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword))
6461
+ return null;
6462
+ const key = read.name.text;
6463
+ if (key === '__proto__' || accessorMayRunFor(key, owner.parent) || !constructorKeepsThisLocal(owner))
6464
+ return null;
6465
+ if (sourceClassDataMemberPlanOf(checker, flow, { kind: 'declared', receiver: checker.getTypeAtLocation(read.expression) }, key) === null)
6466
+ return null;
6467
+ if (reflectiveDefinitionMayInstallGetterOf(checker, flow, key, (target) => freshDefinitionTarget(target) !== 'refused'))
6468
+ return null;
6469
+ return store.right;
6470
+ };
6471
+ // Two solvers over one rule: the reflective-definition question
6472
+ // `valueStoredJustBefore` asks about definition targets must not re-enter
6473
+ // the solver that is asking it, so the one answering it proves targets
6474
+ // without store-then-read reasoning -- strictly fewer origins, still sound.
6475
+ const originRuleOf = (storedReads) => (key) => {
6476
+ const refused = { seed: false, admitted: false, dependencies: [] };
6477
+ const through = (dependencies) => ({ seed: false, admitted: true, dependencies });
6478
+ if (ts.isParameter(key)) {
6479
+ if (key.dotDotDotToken)
6480
+ return refused;
6481
+ const values = enumeratedParameterValuesOf(key);
6482
+ return values === null ? refused : through(values);
6483
+ }
6484
+ if (ts.isVariableDeclaration(key)) {
6485
+ const values = [];
6486
+ const writes = writesOf(key).filter((write) => write.slot === 'whole');
6487
+ if (writes.length === 0)
6488
+ return refused;
6489
+ for (const write of writes) {
6490
+ if (write.edge === 'compound-assignment')
6491
+ continue;
6492
+ if (write.value === null ||
6493
+ (write.edge !== 'declaration-initializer' && write.edge !== 'identifier-assignment' && write.edge !== 'logical-assignment'))
6494
+ return refused;
6495
+ values.push(write.value);
6496
+ }
6497
+ return through(values);
6498
+ }
6499
+ if (!ts.isExpression(key))
6500
+ return refused;
6501
+ const current = unwrapErasedExpression(key);
6502
+ if (ts.isObjectLiteralExpression(current) || ts.isArrayLiteralExpression(current))
6503
+ return { seed: true, admitted: true, dependencies: [] };
6504
+ if (isVacuousOrigin(flow, current) ||
6505
+ ts.isStringLiteralLike(current) ||
6506
+ ts.isTemplateExpression(current) ||
6507
+ ts.isNumericLiteral(current) ||
6508
+ ts.isBigIntLiteral(current) ||
6509
+ ts.isTypeOfExpression(current) ||
6510
+ current.kind === ts.SyntaxKind.TrueKeyword ||
6511
+ current.kind === ts.SyntaxKind.FalseKeyword)
6512
+ return through([]);
6513
+ if (ts.isConditionalExpression(current))
6514
+ return through([current.whenTrue, current.whenFalse]);
6515
+ if (ts.isBinaryExpression(current)) {
6516
+ const operator = current.operatorToken.kind;
6517
+ if (operator === ts.SyntaxKind.QuestionQuestionToken ||
6518
+ operator === ts.SyntaxKind.BarBarToken ||
6519
+ operator === ts.SyntaxKind.AmpersandAmpersandToken)
6520
+ return through([current.left, current.right]);
6521
+ if (operator === ts.SyntaxKind.CommaToken || operator === ts.SyntaxKind.EqualsToken)
6522
+ return through([current.right]);
6523
+ return refused;
6524
+ }
6525
+ if (ts.isCallExpression(current)) {
6526
+ if (trustedObjectStatic(current.expression, 'create'))
6527
+ return { seed: true, admitted: true, dependencies: [] };
6528
+ const target = current.arguments[0];
6529
+ if (trustedObjectStatic(current.expression, 'assign') && target && !ts.isSpreadElement(target))
6530
+ return through([target]);
6531
+ const fact = sourceFrameOwnedCalls.has(current) ? sourceInvocationFacts.get(current) : undefined;
6532
+ if (!fact || fact.frames.length === 0)
6533
+ return refused;
6534
+ const values = [];
6535
+ for (const frame of fact.frames) {
6536
+ if (frame.completions.kind !== 'values')
6537
+ return refused;
6538
+ values.push(...frame.completions.values);
6539
+ }
6540
+ return through(values);
6541
+ }
6542
+ if (ts.isIdentifier(current)) {
6543
+ const declaration = bindingOf(current);
6544
+ if (!declaration || (!ts.isParameter(declaration) && !ts.isVariableDeclaration(declaration)))
6545
+ return refused;
6546
+ if (isRuntimePrimitiveGuarded(current) && neverReassigned(declaration))
6547
+ return through([]);
6548
+ return through([declaration]);
6549
+ }
6550
+ const stored = storedReads && ts.isPropertyAccessExpression(current) ? valueStoredJustBefore(current) : null;
6551
+ if (stored)
6552
+ return through([stored]);
6553
+ if ((ts.isPropertyAccessExpression(current) || ts.isElementAccessExpression(current)) &&
6554
+ !trustSeed.rejectedCallableProofs.has(current)) {
6555
+ try {
6556
+ const proof = invocationLedger.capture(() => closedValueOriginAuthorityOf(checker, flow, current).fieldValuesOf(current));
6557
+ if (proof.value === null)
6558
+ return refused;
6559
+ invocationRequirements.set(current, proof.requirements);
6560
+ return through(proof.value);
6561
+ }
6562
+ catch {
6563
+ // The same live proof `enumeratedParameterValuesOf` guards: a slot
6564
+ // this file cannot evaluate is a slot it cannot close.
6565
+ return refused;
6566
+ }
6567
+ }
6568
+ return refused;
6569
+ };
6570
+ const freshDefinitionTarget = seededOriginSolver(originRuleOf(false));
6571
+ const freshProgramObjectOrigin = seededOriginSolver(originRuleOf(true));
5916
6572
  finishCensus();
5917
6573
  for (const file of files) {
5918
6574
  if (file.isDeclarationFile)
@@ -5926,6 +6582,13 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
5926
6582
  // every key Object.prototype may carry; and a key set's intrinsic
5927
6583
  // assumptions hold against this very result. See `CensusSeed`.
5928
6584
  if (!tainted.has('*')) {
6585
+ // Evaluated before the ledger checks below: the parameter proofs it asks
6586
+ // file their intrinsic requirements with `invocationRequirements`.
6587
+ const unprovenSurfaceWrite = allIntrinsicTrustInvalidated
6588
+ ? undefined
6589
+ : deferredSurfaceWrites.find((receiver) => freshProgramObjectOrigin(receiver) === 'refused');
6590
+ if (unprovenSurfaceWrite && process.env['GEA_DEBUG_GLOBAL_MUTATION'])
6591
+ debugSite(unprovenSurfaceWrite, 'surface write receiver is not a fresh program object; invalidates all intrinsic trust');
5929
6592
  const written = visitWrittenKeys.surfaceKeys;
5930
6593
  const distrusted = [...trustedIntrinsicNames].filter((name) => !trustSeed.names.has(name) && keySetTouches(written, { names: [name] }));
5931
6594
  const objectPrototypeKeys = inheritedObjectPrototypeKeys ? objectPrototypeKeysOf(tainted) : trustSeed.objectPrototypeKeys;
@@ -5944,13 +6607,14 @@ computedKeysOf = () => null, trustSeed = initialCensusSeed) => {
5944
6607
  if (failedIntrinsicProtocolRequirements({ checker, identities, globalHostMutationTaint: tainted, isStandardLibraryDeclaration }, requirements).length > 0)
5945
6608
  rejectedCallableProofs.add(call);
5946
6609
  const invocationFailed = rejectedCallableProofs.size > trustSeed.rejectedCallableProofs.size;
5947
- if (distrusted.length > 0 || (written.every && !trustSeed.all) || inheritedGrew || assumptionFailed || invocationFailed) {
6610
+ const distrustAll = written.every || unprovenSurfaceWrite !== undefined;
6611
+ if (distrusted.length > 0 || (distrustAll && !trustSeed.all) || inheritedGrew || assumptionFailed || invocationFailed) {
5948
6612
  if (process.env['GEA_DEBUG_GLOBAL_MUTATION'])
5949
- process.stderr.write(`global host census re-run: distrusting ${written.every ? '<all>' : distrusted.join(', ') || '-'}` +
6613
+ process.stderr.write(`global host census re-run: distrusting ${distrustAll ? '<all>' : distrusted.join(', ') || '-'}` +
5950
6614
  `${inheritedGrew ? '; Object.prototype keys grew' : ''}${assumptionFailed ? '; computed-key assumption failed' : ''}\n`);
5951
- return censusGlobalHostMutations(checker, identities, files, names, hostBindings, flow, reachable, nativeReceiverDeclarations, nativeReceiverSymbols, nativeConstructorSymbols, publishedTypeAt, declarationFiles, computedKeysOf, {
6615
+ return censusGlobalHostMutations(checker, identities, files, names, hostBindings, flow, reachable, nativeReceiverDeclarations, nativeReceiverSymbols, nativeConstructorSymbols, publishedTypeAt, declarationFiles, computedKeysOf, staticCommonJsRequireOutcomeOf, {
5952
6616
  names: new Set([...trustSeed.names, ...distrusted]),
5953
- all: trustSeed.all || written.every,
6617
+ all: trustSeed.all || distrustAll,
5954
6618
  objectPrototypeKeys: {
5955
6619
  names: new Set([...trustSeed.objectPrototypeKeys.names, ...objectPrototypeKeys.names]),
5956
6620
  numeric: trustSeed.objectPrototypeKeys.numeric || objectPrototypeKeys.numeric,