@geastack/compiler 1.0.20 → 1.0.22

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 (543) 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 +120 -29
  9. package/dist/conversion/algebra.d.ts +16 -1
  10. package/dist/conversion/algebra.js +2 -0
  11. package/dist/conversion/build.d.ts +12 -0
  12. package/dist/conversion/build.js +31 -6
  13. package/dist/conversion/constructor-identity-family.d.ts +49 -0
  14. package/dist/conversion/constructor-identity-family.js +67 -0
  15. package/dist/conversion/derive.js +39 -6
  16. package/dist/conversion/iterable-object-view.d.ts +44 -0
  17. package/dist/conversion/iterable-object-view.js +55 -0
  18. package/dist/conversion/iterator-object-view.d.ts +77 -0
  19. package/dist/conversion/iterator-object-view.js +112 -0
  20. package/dist/conversion/nodes.d.ts +93 -0
  21. package/dist/conversion/nodes.js +262 -5
  22. package/dist/conversion/operand-view.js +41 -0
  23. package/dist/conversion/protocol-iterator.d.ts +84 -0
  24. package/dist/conversion/protocol-iterator.js +88 -0
  25. package/dist/conversion/record-view.d.ts +152 -8
  26. package/dist/conversion/record-view.js +518 -37
  27. package/dist/conversion/registry.d.ts +32 -0
  28. package/dist/ir/borrowed-call-arguments.d.ts +22 -1
  29. package/dist/ir/borrowed-call-arguments.js +102 -1
  30. package/dist/ir/borrowed-callable-uses.d.ts +62 -0
  31. package/dist/ir/borrowed-callable-uses.js +135 -0
  32. package/dist/ir/boxed-bind-assumptions.d.ts +24 -0
  33. package/dist/ir/boxed-bind-assumptions.js +93 -0
  34. package/dist/ir/build.d.ts +18 -7
  35. package/dist/ir/build.js +71 -13
  36. package/dist/ir/call-dispatch.js +474 -10
  37. package/dist/ir/call-entry.d.ts +24 -1
  38. package/dist/ir/call-entry.js +106 -1
  39. package/dist/ir/callable-class-flow.d.ts +3 -1
  40. package/dist/ir/callable-class-flow.js +42 -6
  41. package/dist/ir/callable-identity-demand.d.ts +20 -1
  42. package/dist/ir/callable-identity-demand.js +157 -18
  43. package/dist/ir/callable-member-candidates.d.ts +11 -1
  44. package/dist/ir/callable-member-candidates.js +82 -3
  45. package/dist/ir/callable-records.js +2 -2
  46. package/dist/ir/callable-site-escape.d.ts +4 -0
  47. package/dist/ir/callable-site-escape.js +228 -0
  48. package/dist/ir/captures.d.ts +10 -1
  49. package/dist/ir/captures.js +219 -4
  50. package/dist/ir/certificate.js +87 -16
  51. package/dist/ir/certify/carrier-keys.d.ts +58 -1
  52. package/dist/ir/certify/carrier-keys.js +160 -6
  53. package/dist/ir/certify/property-access-keys.d.ts +17 -0
  54. package/dist/ir/certify/property-access-keys.js +36 -0
  55. package/dist/ir/certify/property-access.js +49 -4
  56. package/dist/ir/certify/runtime-helper.d.ts +4 -0
  57. package/dist/ir/certify/runtime-helper.js +17 -5
  58. package/dist/ir/certify.js +132 -79
  59. package/dist/ir/class-static-fields.d.ts +11 -0
  60. package/dist/ir/class-static-fields.js +28 -0
  61. package/dist/ir/construct-entry.d.ts +2 -1
  62. package/dist/ir/construct-entry.js +3 -2
  63. package/dist/ir/construction-only-fields.d.ts +73 -0
  64. package/dist/ir/construction-only-fields.js +211 -0
  65. package/dist/ir/dominance.d.ts +14 -0
  66. package/dist/ir/dominance.js +18 -4
  67. package/dist/ir/emission-representations.js +4 -1
  68. package/dist/ir/exception-edges.d.ts +17 -0
  69. package/dist/ir/exception-edges.js +75 -0
  70. package/dist/ir/facts.d.ts +54 -3
  71. package/dist/ir/facts.js +182 -5
  72. package/dist/ir/generator-split.js +2 -2
  73. package/dist/ir/instance-reparenting.d.ts +83 -0
  74. package/dist/ir/instance-reparenting.js +167 -0
  75. package/dist/ir/integer-storage.d.ts +29 -0
  76. package/dist/ir/integer-storage.js +188 -79
  77. package/dist/ir/integers.d.ts +16 -0
  78. package/dist/ir/integers.js +327 -8
  79. package/dist/ir/integrity-restrictions.d.ts +42 -9
  80. package/dist/ir/integrity-restrictions.js +335 -42
  81. package/dist/ir/key-order-observation.d.ts +38 -0
  82. package/dist/ir/key-order-observation.js +173 -0
  83. package/dist/ir/literal-set-membership.d.ts +30 -0
  84. package/dist/ir/literal-set-membership.js +277 -0
  85. package/dist/ir/lower-allocation.js +68 -8
  86. package/dist/ir/lower-completion.d.ts +0 -9
  87. package/dist/ir/lower-completion.js +14 -5
  88. package/dist/ir/lower-destructuring.js +24 -2
  89. package/dist/ir/lower-exceptions.js +4 -4
  90. package/dist/ir/lower-flow.d.ts +21 -0
  91. package/dist/ir/lower-flow.js +37 -3
  92. package/dist/ir/lower-graph.d.ts +19 -1
  93. package/dist/ir/lower-graph.js +91 -67
  94. package/dist/ir/lower-invocation.d.ts +16 -0
  95. package/dist/ir/lower-invocation.js +189 -29
  96. package/dist/ir/lower-narrow.d.ts +0 -46
  97. package/dist/ir/lower-narrow.js +63 -1
  98. package/dist/ir/lower-operands.d.ts +52 -2
  99. package/dist/ir/lower-operands.js +491 -8
  100. package/dist/ir/lower-property.d.ts +2 -1
  101. package/dist/ir/lower-property.js +140 -31
  102. package/dist/ir/lower-protocol.js +16 -4
  103. package/dist/ir/lower-proxy.d.ts +65 -0
  104. package/dist/ir/lower-proxy.js +181 -0
  105. package/dist/ir/lower.js +112 -17
  106. package/dist/ir/model.d.ts +228 -18
  107. package/dist/ir/native-class-accessor.d.ts +9 -2
  108. package/dist/ir/native-class-accessor.js +12 -3
  109. package/dist/ir/native-class-construction.d.ts +1 -1
  110. package/dist/ir/native-class-construction.js +2 -1
  111. package/dist/ir/native-class-initialization.js +2 -2
  112. package/dist/ir/object-value-conversions.js +20 -5
  113. package/dist/ir/operation-index.d.ts +16 -0
  114. package/dist/ir/operation-index.js +17 -0
  115. package/dist/ir/pcm-loops.d.ts +11 -0
  116. package/dist/ir/pcm-loops.js +284 -0
  117. package/dist/ir/presence-proof.js +5 -0
  118. package/dist/ir/program-facts.d.ts +10 -20
  119. package/dist/ir/program-facts.js +80 -6
  120. package/dist/ir/proven-branches.d.ts +2 -2
  121. package/dist/ir/proven-branches.js +198 -3
  122. package/dist/ir/queries.js +35 -1
  123. package/dist/ir/reflection-demand.d.ts +9 -4
  124. package/dist/ir/reflection-demand.js +410 -28
  125. package/dist/ir/refusal.d.ts +1 -0
  126. package/dist/ir/refusal.js +2 -1
  127. package/dist/ir/shake.d.ts +94 -1
  128. package/dist/ir/shake.js +209 -12
  129. package/dist/ir/shared-empty-records.d.ts +12 -0
  130. package/dist/ir/shared-empty-records.js +301 -0
  131. package/dist/ir/spread-copy-elision.d.ts +59 -0
  132. package/dist/ir/spread-copy-elision.js +431 -0
  133. package/dist/ir/stable-cell-reads.d.ts +40 -0
  134. package/dist/ir/stable-cell-reads.js +123 -0
  135. package/dist/ir/static-callables.js +50 -0
  136. package/dist/ir/string-layout-reuse.d.ts +16 -1
  137. package/dist/ir/string-layout-reuse.js +66 -0
  138. package/dist/ir/transfer.d.ts +72 -3
  139. package/dist/ir/transfer.js +511 -19
  140. package/dist/ir/typed-property-access.d.ts +18 -2
  141. package/dist/ir/typed-property-access.js +109 -12
  142. package/dist/ir/verify.js +2 -1
  143. package/dist/plugins/apple/plugin.js +3 -2
  144. package/dist/plugins/gea/host.d.ts +7 -0
  145. package/dist/plugins/gea/host.js +30 -1
  146. package/dist/plugins/gea/lower.js +6 -1
  147. package/dist/plugins/gea/plugin.js +7 -4
  148. package/dist/plugins/gea/render-bridge.d.ts +4 -2
  149. package/dist/plugins/gea/render-bridge.js +23 -7
  150. package/dist/plugins/model.d.ts +2 -0
  151. package/dist/project-preparation.d.ts +5 -1
  152. package/dist/project-preparation.js +184 -7
  153. package/dist/projection/bindings.d.ts +5 -2
  154. package/dist/projection/bindings.js +40 -1
  155. package/dist/projection/callee.d.ts +16 -0
  156. package/dist/projection/callee.js +35 -6
  157. package/dist/projection/class-prototype.js +5 -1
  158. package/dist/projection/classes.d.ts +65 -2
  159. package/dist/projection/classes.js +159 -2
  160. package/dist/projection/dispatch.d.ts +69 -18
  161. package/dist/projection/dispatch.js +391 -19
  162. package/dist/projection/fields.d.ts +4 -3
  163. package/dist/projection/fields.js +89 -21
  164. package/dist/projection/instance-test.d.ts +12 -0
  165. package/dist/projection/instance-test.js +40 -10
  166. package/dist/projection/method-value-escapes.d.ts +43 -0
  167. package/dist/projection/method-value-escapes.js +113 -0
  168. package/dist/projection/slots.d.ts +34 -1
  169. package/dist/projection/slots.js +82 -5
  170. package/dist/representation/any-null-record-members.d.ts +41 -0
  171. package/dist/representation/any-null-record-members.js +115 -0
  172. package/dist/representation/collections.d.ts +3 -1
  173. package/dist/representation/collections.js +5 -2
  174. package/dist/representation/derive.d.ts +9 -1
  175. package/dist/representation/derive.js +366 -25
  176. package/dist/representation/difference.js +14 -0
  177. package/dist/representation/embedded-carriers.js +1 -0
  178. package/dist/representation/host-abi.d.ts +15 -0
  179. package/dist/representation/host-abi.js +28 -0
  180. package/dist/representation/host-templates.d.ts +1 -1
  181. package/dist/representation/host-templates.js +7 -3
  182. package/dist/representation/intersection.js +22 -0
  183. package/dist/representation/json-nullable.d.ts +18 -0
  184. package/dist/representation/json-nullable.js +22 -0
  185. package/dist/representation/model.d.ts +141 -0
  186. package/dist/representation/model.js +47 -3
  187. package/dist/representation/object-shape.d.ts +5 -1
  188. package/dist/representation/object-shape.js +5 -2
  189. package/dist/representation/policies.d.ts +66 -1
  190. package/dist/representation/proxy-carriers.d.ts +71 -0
  191. package/dist/representation/proxy-carriers.js +330 -0
  192. package/dist/representation/publish.d.ts +9 -1
  193. package/dist/representation/publish.js +186 -18
  194. package/dist/representation/record-fields.d.ts +5 -0
  195. package/dist/representation/record-fields.js +7 -1
  196. package/dist/representation/static-field-cells.d.ts +61 -0
  197. package/dist/representation/static-field-cells.js +80 -0
  198. package/dist/representation/unassigned-binding-cells.d.ts +32 -0
  199. package/dist/representation/unassigned-binding-cells.js +44 -0
  200. package/dist/representation/union.js +17 -1
  201. package/dist/representation/unwritten-record-members.d.ts +54 -0
  202. package/dist/representation/unwritten-record-members.js +167 -0
  203. package/dist/representation/value-records.js +153 -11
  204. package/dist/semantics/ambient.d.ts +102 -0
  205. package/dist/semantics/ambient.js +183 -0
  206. package/dist/semantics/any-null-member-declarations.d.ts +32 -0
  207. package/dist/semantics/any-null-member-declarations.js +90 -0
  208. package/dist/semantics/borrowed-builtin-call-bind-source-transform.js +14 -0
  209. package/dist/semantics/borrowed-method-receiver-copy-source-transform.d.ts +51 -0
  210. package/dist/semantics/borrowed-method-receiver-copy-source-transform.js +367 -0
  211. package/dist/semantics/call-invalidated-narrowing.d.ts +3 -0
  212. package/dist/semantics/call-invalidated-narrowing.js +715 -0
  213. package/dist/semantics/callable-origins.d.ts +39 -0
  214. package/dist/semantics/callable-origins.js +73 -2
  215. package/dist/semantics/class-alias.d.ts +36 -0
  216. package/dist/semantics/class-alias.js +64 -14
  217. package/dist/semantics/class-heritage.d.ts +64 -0
  218. package/dist/semantics/class-heritage.js +278 -2
  219. package/dist/semantics/commonjs-wrapper.d.ts +1 -1
  220. package/dist/semantics/commonjs-wrapper.js +24 -7
  221. package/dist/semantics/constructor-function-class-source-transform.d.ts +4 -0
  222. package/dist/semantics/constructor-function-class-source-transform.js +327 -0
  223. package/dist/semantics/constructor-slot-subclasses.js +163 -4
  224. package/dist/semantics/declaration-overlay-transform.js +197 -3
  225. package/dist/semantics/frontend.d.ts +31 -0
  226. package/dist/semantics/frontend.js +212 -26
  227. package/dist/semantics/host-methods.d.ts +27 -2
  228. package/dist/semantics/host-methods.js +57 -4
  229. package/dist/semantics/host-protocols.d.ts +19 -8
  230. package/dist/semantics/host-protocols.js +145 -31
  231. package/dist/semantics/interface-families.d.ts +51 -2
  232. package/dist/semantics/interface-families.js +609 -23
  233. package/dist/semantics/interface-implementors.d.ts +20 -0
  234. package/dist/semantics/interface-implementors.js +130 -6
  235. package/dist/semantics/known-caller-predicate-parameters.d.ts +2 -0
  236. package/dist/semantics/known-caller-predicate-parameters.js +161 -0
  237. package/dist/semantics/model/intrinsic-accessor-getters.d.ts +10 -0
  238. package/dist/semantics/model/intrinsic-accessor-getters.js +4 -0
  239. package/dist/semantics/model/operands.d.ts +10 -0
  240. package/dist/semantics/model/operations.d.ts +107 -0
  241. package/dist/semantics/model/selected-signature.d.ts +33 -0
  242. package/dist/semantics/model/structural-type-table.d.ts +15 -0
  243. package/dist/semantics/model/structural-type-table.js +19 -1
  244. package/dist/semantics/model/structural-types.d.ts +99 -0
  245. package/dist/semantics/model/structural-types.js +31 -2
  246. package/dist/semantics/normalize/absent-globals.d.ts +1 -1
  247. package/dist/semantics/normalize/absent-globals.js +3 -3
  248. package/dist/semantics/normalize/bivariant-slot-parameter.d.ts +46 -0
  249. package/dist/semantics/normalize/bivariant-slot-parameter.js +372 -0
  250. package/dist/semantics/normalize/callback-parameter-contracts.d.ts +2 -0
  251. package/dist/semantics/normalize/callback-parameter-contracts.js +21 -0
  252. package/dist/semantics/normalize/census.d.ts +2 -1
  253. package/dist/semantics/normalize/census.js +25 -2
  254. package/dist/semantics/normalize/class-instance-record-statement.d.ts +37 -0
  255. package/dist/semantics/normalize/class-instance-record-statement.js +74 -0
  256. package/dist/semantics/normalize/collection-bindings.js +242 -5
  257. package/dist/semantics/normalize/commonjs-require.d.ts +35 -5
  258. package/dist/semantics/normalize/commonjs-require.js +464 -147
  259. package/dist/semantics/normalize/dead-event-emissions.d.ts +6 -0
  260. package/dist/semantics/normalize/dead-event-emissions.js +866 -0
  261. package/dist/semantics/normalize/dead-method-copies.d.ts +56 -0
  262. package/dist/semantics/normalize/dead-method-copies.js +239 -0
  263. package/dist/semantics/normalize/derived-expression-type.d.ts +149 -2
  264. package/dist/semantics/normalize/derived-expression-type.js +418 -14
  265. package/dist/semantics/normalize/field-bindings.js +139 -4
  266. package/dist/semantics/normalize/flow/callable-reach.js +162 -9
  267. package/dist/semantics/normalize/flow/member-call-forwarding.js +6 -0
  268. package/dist/semantics/normalize/flow/owned-class-receivers.js +40 -2
  269. package/dist/semantics/normalize/flow/source-class-data.d.ts +7 -1
  270. package/dist/semantics/normalize/flow/source-class-data.js +28 -9
  271. package/dist/semantics/normalize/flow/source-value-session.js +32 -13
  272. package/dist/semantics/normalize/flow/targets.d.ts +32 -0
  273. package/dist/semantics/normalize/flow/targets.js +65 -6
  274. package/dist/semantics/normalize/flow/value-flow.d.ts +7 -0
  275. package/dist/semantics/normalize/flow/value-flow.js +30 -2
  276. package/dist/semantics/normalize/fresh-array-result.d.ts +32 -0
  277. package/dist/semantics/normalize/fresh-array-result.js +125 -0
  278. package/dist/semantics/normalize/gating.js +2 -0
  279. package/dist/semantics/normalize/global-host-mutations.d.ts +11 -1
  280. package/dist/semantics/normalize/global-host-mutations.js +691 -27
  281. package/dist/semantics/normalize/host-effect-contracts.d.ts +43 -1
  282. package/dist/semantics/normalize/host-effect-contracts.js +60 -3
  283. package/dist/semantics/normalize/host-mutation-key-reader.js +35 -10
  284. package/dist/semantics/normalize/identities.js +64 -3
  285. package/dist/semantics/normalize/intrinsic-accessor-getter.d.ts +59 -0
  286. package/dist/semantics/normalize/intrinsic-accessor-getter.js +129 -0
  287. package/dist/semantics/normalize/local-bindings.js +117 -21
  288. package/dist/semantics/normalize/merged-declaration.d.ts +41 -0
  289. package/dist/semantics/normalize/merged-declaration.js +81 -0
  290. package/dist/semantics/normalize/never-override-result.d.ts +21 -0
  291. package/dist/semantics/normalize/never-override-result.js +64 -0
  292. package/dist/semantics/normalize/null-blind-parameter.d.ts +21 -0
  293. package/dist/semantics/normalize/null-blind-parameter.js +77 -0
  294. package/dist/semantics/normalize/object-bag-bindings.js +26 -2
  295. package/dist/semantics/normalize/omitted-stated-parameter.d.ts +1 -1
  296. package/dist/semantics/normalize/omitted-stated-parameter.js +34 -4
  297. package/dist/semantics/normalize/override-field-arms.d.ts +33 -0
  298. package/dist/semantics/normalize/override-field-arms.js +362 -0
  299. package/dist/semantics/normalize/parameter-bindings.d.ts +64 -1
  300. package/dist/semantics/normalize/parameter-bindings.js +827 -81
  301. package/dist/semantics/normalize/parameter-slot.d.ts +1 -0
  302. package/dist/semantics/normalize/parameter-slot.js +69 -0
  303. package/dist/semantics/normalize/physical-overload-result.d.ts +45 -0
  304. package/dist/semantics/normalize/physical-overload-result.js +132 -0
  305. package/dist/semantics/normalize/producer-context.d.ts +23 -0
  306. package/dist/semantics/normalize/producers/allocations.d.ts +13 -0
  307. package/dist/semantics/normalize/producers/allocations.js +8 -15
  308. package/dist/semantics/normalize/producers/binding-kind.d.ts +11 -0
  309. package/dist/semantics/normalize/producers/binding-kind.js +31 -0
  310. package/dist/semantics/normalize/producers/bindings.js +16 -1
  311. package/dist/semantics/normalize/producers/boundary.js +21 -1
  312. package/dist/semantics/normalize/producers/class-lifecycle.js +23 -14
  313. package/dist/semantics/normalize/producers/computations.js +8 -67
  314. package/dist/semantics/normalize/producers/control-loops.d.ts +1 -1
  315. package/dist/semantics/normalize/producers/control-loops.js +25 -1
  316. package/dist/semantics/normalize/producers/control.js +87 -60
  317. package/dist/semantics/normalize/producers/declaration-lifecycle.js +5 -0
  318. package/dist/semantics/normalize/producers/enums.d.ts +10 -0
  319. package/dist/semantics/normalize/producers/enums.js +169 -0
  320. package/dist/semantics/normalize/producers/erasure.d.ts +10 -0
  321. package/dist/semantics/normalize/producers/erasure.js +23 -0
  322. package/dist/semantics/normalize/producers/intrinsic-accessor-getter.d.ts +15 -0
  323. package/dist/semantics/normalize/producers/intrinsic-accessor-getter.js +33 -0
  324. package/dist/semantics/normalize/producers/invocations.js +255 -18
  325. package/dist/semantics/normalize/producers/iteration-yield.js +6 -1
  326. package/dist/semantics/normalize/producers/logical-merge-type.d.ts +36 -0
  327. package/dist/semantics/normalize/producers/logical-merge-type.js +163 -0
  328. package/dist/semantics/normalize/producers/properties.js +207 -18
  329. package/dist/semantics/normalize/producers/protocol.d.ts +4 -0
  330. package/dist/semantics/normalize/producers/protocol.js +147 -12
  331. package/dist/semantics/normalize/producers/references.js +50 -9
  332. package/dist/semantics/normalize/producers/shared.d.ts +120 -0
  333. package/dist/semantics/normalize/producers/shared.js +359 -10
  334. package/dist/semantics/normalize/producers/spread-arguments.js +85 -4
  335. package/dist/semantics/normalize/producers/tuple-spread.d.ts +1 -0
  336. package/dist/semantics/normalize/producers/tuple-spread.js +1 -1
  337. package/dist/semantics/normalize/property-key-domain.js +6 -0
  338. package/dist/semantics/normalize/reachability.d.ts +7 -0
  339. package/dist/semantics/normalize/reachability.js +166 -9
  340. package/dist/semantics/normalize/record-home-arms.d.ts +25 -0
  341. package/dist/semantics/normalize/record-home-arms.js +87 -0
  342. package/dist/semantics/normalize/record-link-families.d.ts +74 -0
  343. package/dist/semantics/normalize/record-link-families.js +327 -0
  344. package/dist/semantics/normalize/record-stand-in-arms.d.ts +56 -0
  345. package/dist/semantics/normalize/record-stand-in-arms.js +484 -0
  346. package/dist/semantics/normalize/return-bindings.d.ts +6 -2
  347. package/dist/semantics/normalize/return-bindings.js +60 -7
  348. package/dist/semantics/normalize/script-global-redefinition.js +5 -0
  349. package/dist/semantics/normalize/shared-array-storage.d.ts +42 -0
  350. package/dist/semantics/normalize/shared-array-storage.js +373 -0
  351. package/dist/semantics/normalize/sloppy-absence.d.ts +41 -0
  352. package/dist/semantics/normalize/sloppy-absence.js +199 -0
  353. package/dist/semantics/normalize/specialization.d.ts +40 -0
  354. package/dist/semantics/normalize/specialization.js +770 -36
  355. package/dist/semantics/normalize/structural-array-element.js +196 -6
  356. package/dist/semantics/normalize/structural-array-read.js +12 -0
  357. package/dist/semantics/normalize/structural-creation-order.d.ts +15 -0
  358. package/dist/semantics/normalize/structural-creation-order.js +51 -48
  359. package/dist/semantics/normalize/structural-declarations.d.ts +16 -0
  360. package/dist/semantics/normalize/structural-declarations.js +43 -0
  361. package/dist/semantics/normalize/structural-generics.d.ts +13 -0
  362. package/dist/semantics/normalize/structural-generics.js +22 -0
  363. package/dist/semantics/normalize/structural-indexed-access.js +16 -0
  364. package/dist/semantics/normalize/structural-instantiated-member.js +68 -2
  365. package/dist/semantics/normalize/structural-joins.js +2 -0
  366. package/dist/semantics/normalize/structural-layout-relevance.d.ts +30 -0
  367. package/dist/semantics/normalize/structural-layout-relevance.js +164 -0
  368. package/dist/semantics/normalize/structural-layout-type.js +270 -14
  369. package/dist/semantics/normalize/structural-leaves.d.ts +1 -1
  370. package/dist/semantics/normalize/structural-leaves.js +17 -3
  371. package/dist/semantics/normalize/structural-mutable-method.js +5 -1
  372. package/dist/semantics/normalize/structural-parts.d.ts +18 -5
  373. package/dist/semantics/normalize/structural-parts.js +68 -19
  374. package/dist/semantics/normalize/structural-receiver.d.ts +1 -1
  375. package/dist/semantics/normalize/structural-receiver.js +23 -1
  376. package/dist/semantics/normalize/structural-self-reference.d.ts +1 -1
  377. package/dist/semantics/normalize/structural-self-reference.js +23 -2
  378. package/dist/semantics/normalize/structural.d.ts +12 -1
  379. package/dist/semantics/normalize/structural.js +1437 -53
  380. package/dist/semantics/normalize/suppressed-write-arms.d.ts +47 -0
  381. package/dist/semantics/normalize/suppressed-write-arms.js +393 -0
  382. package/dist/semantics/normalize/unresolvable-names.d.ts +15 -2
  383. package/dist/semantics/normalize/unresolvable-names.js +30 -6
  384. package/dist/semantics/normalize/unshared-array-result.d.ts +32 -0
  385. package/dist/semantics/normalize/unshared-array-result.js +125 -0
  386. package/dist/semantics/package-sources.d.ts +1 -1
  387. package/dist/semantics/package-sources.js +120 -8
  388. package/dist/semantics/program.d.ts +20 -0
  389. package/dist/semantics/program.js +179 -26
  390. package/dist/semantics/shared-declaration-files.d.ts +44 -0
  391. package/dist/semantics/shared-declaration-files.js +42 -0
  392. package/dist/semantics/stable-checker.d.ts +1 -1
  393. package/dist/semantics/stable-checker.js +7 -2
  394. package/dist/semantics/subclass-member-overlay-transform.js +95 -53
  395. package/dist/semantics/unchecked-guard-argument-copies.d.ts +67 -0
  396. package/dist/semantics/unchecked-guard-argument-copies.js +163 -0
  397. package/dist/semantics/unchecked-write-member-declarations.d.ts +46 -0
  398. package/dist/semantics/unchecked-write-member-declarations.js +331 -0
  399. package/dist/targets/cpp/balanced-units.d.ts +31 -0
  400. package/dist/targets/cpp/balanced-units.js +57 -0
  401. package/dist/targets/cpp/borrowed-arm-projections.d.ts +31 -0
  402. package/dist/targets/cpp/borrowed-arm-projections.js +106 -0
  403. package/dist/targets/cpp/borrowed-call-entry.d.ts +1 -1
  404. package/dist/targets/cpp/borrowed-call-entry.js +24 -20
  405. package/dist/targets/cpp/captures.js +314 -8
  406. package/dist/targets/cpp/char-code-buffers.d.ts +36 -0
  407. package/dist/targets/cpp/char-code-buffers.js +214 -0
  408. package/dist/targets/cpp/class-layout.d.ts +7 -1
  409. package/dist/targets/cpp/class-layout.js +42 -17
  410. package/dist/targets/cpp/class-properties/computed-method-value.d.ts +17 -2
  411. package/dist/targets/cpp/class-properties/computed-method-value.js +50 -4
  412. package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +31 -1
  413. package/dist/targets/cpp/class-properties/emit-class-properties.js +174 -17
  414. package/dist/targets/cpp/class-ref-transport.d.ts +32 -0
  415. package/dist/targets/cpp/class-ref-transport.js +56 -1
  416. package/dist/targets/cpp/conversions.js +1827 -1502
  417. package/dist/targets/cpp/coroutine-bodies.d.ts +97 -0
  418. package/dist/targets/cpp/coroutine-bodies.js +187 -0
  419. package/dist/targets/cpp/document.js +11 -1
  420. package/dist/targets/cpp/emit-allocation.js +568 -21
  421. package/dist/targets/cpp/emit-arrays.d.ts +10 -0
  422. package/dist/targets/cpp/emit-arrays.js +147 -16
  423. package/dist/targets/cpp/emit-binding-reference.d.ts +26 -2
  424. package/dist/targets/cpp/emit-binding-reference.js +97 -5
  425. package/dist/targets/cpp/emit-bindings.d.ts +9 -1
  426. package/dist/targets/cpp/emit-bindings.js +108 -8
  427. package/dist/targets/cpp/emit-buffers.d.ts +2 -16
  428. package/dist/targets/cpp/emit-buffers.js +124 -25
  429. package/dist/targets/cpp/emit-callable.d.ts +35 -72
  430. package/dist/targets/cpp/emit-callable.js +647 -82
  431. package/dist/targets/cpp/emit-carrier-members.d.ts +13 -2
  432. package/dist/targets/cpp/emit-carrier-members.js +50 -9
  433. package/dist/targets/cpp/emit-constructor-identity-family.d.ts +20 -0
  434. package/dist/targets/cpp/emit-constructor-identity-family.js +45 -0
  435. package/dist/targets/cpp/emit-context.d.ts +329 -15
  436. package/dist/targets/cpp/emit-context.js +104 -13
  437. package/dist/targets/cpp/emit-dynamic-properties.d.ts +44 -0
  438. package/dist/targets/cpp/emit-dynamic-properties.js +256 -37
  439. package/dist/targets/cpp/emit-equality.js +117 -2
  440. package/dist/targets/cpp/emit-error-constructor.d.ts +19 -0
  441. package/dist/targets/cpp/emit-error-constructor.js +73 -0
  442. package/dist/targets/cpp/emit-exceptions.d.ts +25 -3
  443. package/dist/targets/cpp/emit-exceptions.js +215 -26
  444. package/dist/targets/cpp/emit-in.js +52 -5
  445. package/dist/targets/cpp/emit-instanceof.js +59 -11
  446. package/dist/targets/cpp/emit-integers.d.ts +6 -0
  447. package/dist/targets/cpp/emit-integers.js +10 -0
  448. package/dist/targets/cpp/emit-iterable-object-view.d.ts +15 -0
  449. package/dist/targets/cpp/emit-iterable-object-view.js +51 -0
  450. package/dist/targets/cpp/emit-iterator-object-view.d.ts +15 -0
  451. package/dist/targets/cpp/emit-iterator-object-view.js +125 -0
  452. package/dist/targets/cpp/emit-iterator.d.ts +7 -10
  453. package/dist/targets/cpp/emit-iterator.js +361 -24
  454. package/dist/targets/cpp/emit-json.d.ts +7 -1
  455. package/dist/targets/cpp/emit-json.js +595 -55
  456. package/dist/targets/cpp/emit-jsx.d.ts +0 -37
  457. package/dist/targets/cpp/emit-jsx.js +70 -8
  458. package/dist/targets/cpp/emit-narrowing.d.ts +192 -28
  459. package/dist/targets/cpp/emit-narrowing.js +1595 -120
  460. package/dist/targets/cpp/emit-native-selection.js +8 -2
  461. package/dist/targets/cpp/emit-presence.js +13 -0
  462. package/dist/targets/cpp/emit-properties.d.ts +3 -1
  463. package/dist/targets/cpp/emit-properties.js +303 -54
  464. package/dist/targets/cpp/emit-protocol-iterator.d.ts +14 -0
  465. package/dist/targets/cpp/emit-protocol-iterator.js +203 -0
  466. package/dist/targets/cpp/emit-proxy.d.ts +17 -0
  467. package/dist/targets/cpp/emit-proxy.js +35 -0
  468. package/dist/targets/cpp/emit-record-view.d.ts +12 -1
  469. package/dist/targets/cpp/emit-record-view.js +429 -18
  470. package/dist/targets/cpp/emit-return.d.ts +38 -0
  471. package/dist/targets/cpp/emit-return.js +143 -21
  472. package/dist/targets/cpp/emit-scopes.d.ts +78 -0
  473. package/dist/targets/cpp/emit-scopes.js +196 -0
  474. package/dist/targets/cpp/emit-sum-widening.js +6 -3
  475. package/dist/targets/cpp/emit-tonumber.d.ts +40 -1
  476. package/dist/targets/cpp/emit-tonumber.js +75 -4
  477. package/dist/targets/cpp/emit-tostring.d.ts +28 -2
  478. package/dist/targets/cpp/emit-tostring.js +115 -12
  479. package/dist/targets/cpp/emit-typeof.js +2 -2
  480. package/dist/targets/cpp/emit-union-properties.d.ts +9 -0
  481. package/dist/targets/cpp/emit-union-properties.js +391 -49
  482. package/dist/targets/cpp/emit.d.ts +3 -1
  483. package/dist/targets/cpp/emit.js +725 -90
  484. package/dist/targets/cpp/evaluated-once.d.ts +51 -0
  485. package/dist/targets/cpp/evaluated-once.js +140 -0
  486. package/dist/targets/cpp/host/core-globals.d.ts +0 -21
  487. package/dist/targets/cpp/host/core-globals.js +10 -2
  488. package/dist/targets/cpp/host/emit-host-invoke.d.ts +0 -10
  489. package/dist/targets/cpp/host/emit-host-invoke.js +454 -36
  490. package/dist/targets/cpp/host/emit-host-object.js +733 -88
  491. package/dist/targets/cpp/host/emit-host-properties.js +26 -2
  492. package/dist/targets/cpp/host/emit-host-reflect.d.ts +1 -0
  493. package/dist/targets/cpp/host/emit-host-reflect.js +26 -7
  494. package/dist/targets/cpp/host/emit-host-value.d.ts +13 -0
  495. package/dist/targets/cpp/host/emit-host-value.js +47 -3
  496. package/dist/targets/cpp/host/host-members.d.ts +11 -0
  497. package/dist/targets/cpp/host/host-members.js +50 -4
  498. package/dist/targets/cpp/host/native-protocols.js +3 -0
  499. package/dist/targets/cpp/host/object-protocol.d.ts +8 -0
  500. package/dist/targets/cpp/host/object-protocol.js +55 -13
  501. package/dist/targets/cpp/key-order-tracking.d.ts +11 -0
  502. package/dist/targets/cpp/key-order-tracking.js +18 -0
  503. package/dist/targets/cpp/manifest/capabilities.js +117 -9
  504. package/dist/targets/cpp/manifest.js +14 -0
  505. package/dist/targets/cpp/native-collection-base.d.ts +27 -0
  506. package/dist/targets/cpp/native-collection-base.js +202 -0
  507. package/dist/targets/cpp/native-error-base.d.ts +14 -0
  508. package/dist/targets/cpp/native-error-base.js +19 -4
  509. package/dist/targets/cpp/native-promise-base.d.ts +23 -0
  510. package/dist/targets/cpp/native-promise-base.js +30 -0
  511. package/dist/targets/cpp/native-symbol-keys.js +1 -1
  512. package/dist/targets/cpp/prototype/emit-prototype-array.js +258 -20
  513. package/dist/targets/cpp/prototype/emit-prototype-date.js +5 -4
  514. package/dist/targets/cpp/prototype/emit-prototype-invoke.d.ts +9 -1
  515. package/dist/targets/cpp/prototype/emit-prototype-invoke.js +232 -26
  516. package/dist/targets/cpp/prototype/emit-prototype-iterator.d.ts +1 -1
  517. package/dist/targets/cpp/prototype/emit-prototype-iterator.js +111 -13
  518. package/dist/targets/cpp/prototype/emit-prototype-promise.d.ts +33 -4
  519. package/dist/targets/cpp/prototype/emit-prototype-promise.js +218 -10
  520. package/dist/targets/cpp/prototype/emit-prototype-regexp.js +8 -5
  521. package/dist/targets/cpp/prototype/emit-prototype-string.js +24 -7
  522. package/dist/targets/cpp/prototype/prototype-method-reads.js +18 -3
  523. package/dist/targets/cpp/reactive-dependencies.d.ts +2 -0
  524. package/dist/targets/cpp/reactive-dependencies.js +94 -3
  525. package/dist/targets/cpp/realm-storage.d.ts +5 -0
  526. package/dist/targets/cpp/realm-storage.js +12 -0
  527. package/dist/targets/cpp/records.d.ts +151 -1
  528. package/dist/targets/cpp/records.js +1328 -122
  529. package/dist/targets/cpp/recursive-containers.d.ts +4 -1
  530. package/dist/targets/cpp/recursive-containers.js +28 -9
  531. package/dist/targets/cpp/translation-unit.d.ts +10 -0
  532. package/dist/targets/cpp/translation-unit.js +686 -140
  533. package/dist/targets/cpp/types.d.ts +56 -6
  534. package/dist/targets/cpp/types.js +218 -12
  535. package/dist/targets/cpp/virtual-methods.d.ts +3 -3
  536. package/dist/targets/cpp/virtual-methods.js +174 -17
  537. package/package.json +14 -13
  538. package/src/targets/cpp/runtime/gea_dynamic_proxy.h +155 -25
  539. package/src/targets/cpp/runtime/gea_eval.h +3 -0
  540. package/src/targets/cpp/runtime/gea_pcm.h +116 -0
  541. package/src/targets/cpp/runtime/gea_runtime.h +18159 -4887
  542. package/src/targets/cpp/runtime/gea_runtime_builtins.cpp +7 -45
  543. package/src/targets/cpp/runtime/gea_runtime_rtc.h +247 -0
@@ -6,15 +6,21 @@ import { implicitArgumentsReadTypeAt, inferImplicitArgumentsTuple } from './impl
6
6
  import { censusArgumentsObjects } from './arguments-objects.js';
7
7
  import { censusRefusal } from './census-refusal.js';
8
8
  import { classFamilyMemberReadTypeOf } from './flow/class-family-member-read.js';
9
+ import { sourceValueSessionOf } from './flow/source-value-session.js';
10
+ import { interfaceFlowImplementorsOf } from '../interface-implementors.js';
9
11
  import { omissionStatedTypeOf, statedParameterWithOmission } from './omitted-stated-parameter.js';
10
- import { indexValueFlow } from './flow/value-flow.js';
12
+ import { implementationOfOverload, indexValueFlow } from './flow/value-flow.js';
11
13
  import { closedArrayCalleeAuthorityOf, hasClosedMemberCallableUses } from './flow/callable-reach.js';
12
14
  import { deferredIntrinsicProtocolLedgerOf } from './deferred-intrinsic-protocols.js';
13
- import { callbackContractParameterType, callbackParameterContractsFor } from './callback-parameter-contracts.js';
15
+ import { callbackContractParameterType, inlineJsxCallbackParameterType, callbackParameterContractsFor } from './callback-parameter-contracts.js';
14
16
  import { declaredClosedTupleRestElementsOf, impliedPatternElementOfArms, impliedPatternPositionPresentEverywhere } from './parameter-slot.js';
15
17
  import { iteratorYieldTypesOf } from './producers/iteration-yield.js';
16
- import { annotationStatesNothing, exactEmptyObjectLiteralType, isNullishType, containsUnstatedPosition, derivedExpressionType, indexAliasEvidence, indexedTypeOf, explicitThisCallReturnType, overloadInvariantReturnTypeAt, indexNamedCallables, isStandardInterfaceType, isBindingOnlyReference, isCalleeOf, isTrackedCallable, isUnusableEvidence as statesNoStorage, carriesNoEvidence, disjointUnionMembersOf, disjointUnionTypeOf, joinOfWrites, jsDocTypeStatesNothing, literalMemberNameOf, narrowsOnlyUnstatedPositions, withoutUndefinedMember, memberTypeOf, objectAssignTargetType, nameOfCallable, synthesizedUnionArmsAt, widestOf, impliedPatternElementRootOf, impliedPatternParameterOf } from './derived-expression-type.js';
18
+ import { annotationStatesNothing, exactEmptyObjectLiteralType, isNullishType, containsUnstatedPosition, derivedExpressionType, indexAliasEvidence, indexedTypeOf, explicitThisCallReturnType, overloadInvariantReturnTypeAt, arrayFromCopyTypeAt, indexNamedCallables, isStandardInterfaceType, isBindingOnlyReference, isCalleeOf, isTrackedCallable, isUnusableEvidence as statesNoStorage, carriesNoEvidence, disjointUnionMembersOf, disjointUnionTypeOf, joinOfWrites, jsDocTypeStatesNothing, literalMemberNameOf, narrowsOnlyUnstatedPositions, isStructuralConstructorType, narrowsStructuralConstructorToClasses, narrowsArrayBufferViewToViews, statesAnArrayBufferView, isLibArrayBufferViewType, withoutUndefinedMember, memberTypeOf, objectAssignTargetType, nameOfCallable, synthesizedUnionArmsAt, widestOf, impliedPatternElementRootOf, impliedPatternParameterOf } from './derived-expression-type.js';
17
19
  import { isUnreducedTypeForm } from './unreduced-type-form.js';
20
+ import { noHostProvidedNames, valueSymbolAt } from './unresolvable-names.js';
21
+ import { isHomelessRecordArm, recordArmUnionStatementOf, recordHomeArmsAtRead } from './record-home-arms.js';
22
+ import { classInstanceArmsPassed, plainRecordStatementOf } from './class-instance-record-statement.js';
23
+ import { overrideFieldArmsOf, overrideRecordStatementOf } from './override-field-arms.js';
18
24
  import { forEachReachableStatement } from './reachability.js';
19
25
  /** A census that binds nothing, for callers that state no program. */
20
26
  export const emptyParameterBindingCensus = {
@@ -140,6 +146,22 @@ const isGenericCallableType = (type) => [...type.getCallSignatures(), ...type.ge
140
146
  * (`derived-expression-type.js`) for what is deliberately NOT in it --
141
147
  * `unknown`, a named empty type, an explicit `: any`.
142
148
  */
149
+ /**
150
+ * JavaScript does not check arity: a call that leaves a trailing formal out
151
+ * binds it to `undefined`, and the checker accepts it for a JS signature that
152
+ * states nothing (its untyped-JS-signature relaxation) without calling the
153
+ * formal optional. memory-pager's `Pager(pageSize, opts)`, reached only as
154
+ * `pager(pageSize)`, was refused `call-passes-no-argument`, so `opts` -- and
155
+ * through `this.deduplicate`, the `set` reassignment and `truncate` --
156
+ * `Page.buffer` were all boxed. A JSDoc `@param` or a type makes the
157
+ * signature typed, and then `isOptionalParameter` is the authority.
158
+ */
159
+ const omissionIsUntypedJavaScript = (parameter) => (parameter.getSourceFile().flags & ts.NodeFlags.JavaScriptFile) !== 0 &&
160
+ parameter.type === undefined &&
161
+ !parameter.dotDotDotToken &&
162
+ ts.isIdentifier(parameter.name) &&
163
+ ts.getJSDocParameterTags(parameter).length === 0 &&
164
+ ts.getJSDocType(parameter) === undefined;
143
165
  const isUnannotated = (checker, parameter) => {
144
166
  if (parameter.dotDotDotToken)
145
167
  return false;
@@ -172,7 +194,12 @@ const isUnannotated = (checker, parameter) => {
172
194
  }
173
195
  const jsDocParamTags = ts.getJSDocParameterTags(parameter);
174
196
  const jsDocType = ts.getJSDocType(parameter) ?? jsDocParamTags[0]?.typeExpression?.type;
175
- if (jsDocType || jsDocParamTags.length > 0) {
197
+ // A tag with no `{type}` -- `@param [opts]`, which `declarationOverlayTransform`
198
+ // writes for memory-pager's `opts` because `@types/memory-pager` declares
199
+ // only `pageSize` -- states optionality and a description, never a type, so
200
+ // the parameter is as unannotated as one with no tag and falls through to
201
+ // the site-type test below.
202
+ if (jsDocType) {
176
203
  // HELD, not landed: candidacy itself is sound (see the doc above), but
177
204
  // admitting it before `.call`/`.apply` attribution exists (see
178
205
  // `unwrapExplicitThisCall`) measurably regressed `EventDispatcher.
@@ -201,8 +228,7 @@ const isUnannotated = (checker, parameter) => {
201
228
  // `jsDocTypeIsUninformative`; the remaining 17-18% resolve to a real type
202
229
  // (`number | Vector3`, ...) and keep being excluded here, same as before
203
230
  // this change.
204
- if (!jsDocType ||
205
- !(jsDocTypeStatesNothing(checker, jsDocType) || annotationStatesNothing(checker, jsDocType, checker.getTypeFromTypeNode(jsDocType))))
231
+ if (!(jsDocTypeStatesNothing(checker, jsDocType) || annotationStatesNothing(checker, jsDocType, checker.getTypeFromTypeNode(jsDocType))))
206
232
  return false;
207
233
  // Admit it HERE, rather than falling through to the `isAnyType(checker.
208
234
  // getTypeAtLocation(parameter))` test below -- that test is written for
@@ -268,6 +294,39 @@ export const carriesUnsubstitutedGeneric = (checker, type, depth = 0) => {
268
294
  return false;
269
295
  return checker.getTypeArguments(reference).some((part) => carriesUnsubstitutedGeneric(checker, part, depth + 1));
270
296
  };
297
+ /** Whether every value of `type` is an object -- so ToBoolean answers `true` for it. */
298
+ const isAlwaysTruthyType = (type) => type.isUnion()
299
+ ? type.types.every(isAlwaysTruthyType)
300
+ : (type.flags & (ts.TypeFlags.Object | ts.TypeFlags.NonPrimitive)) !== 0 &&
301
+ (type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) === 0;
302
+ /**
303
+ * Whether `value` is the right-hand side of `p = value` written as the whole
304
+ * consequent of `if (!p)`, for the parameter `symbol` -- a write that runs only
305
+ * while the parameter holds a falsy value.
306
+ */
307
+ const isFalsyGuardedWriteOf = (checker, value, symbol) => {
308
+ const unwrap = (node) => (ts.isParenthesizedExpression(node) ? unwrap(node.expression) : node);
309
+ const namesParameter = (node) => {
310
+ const bare = unwrap(node);
311
+ return ts.isIdentifier(bare) && checker.getSymbolAtLocation(bare) === symbol;
312
+ };
313
+ let assignment = value;
314
+ while (ts.isParenthesizedExpression(assignment.parent))
315
+ assignment = assignment.parent;
316
+ const binary = assignment.parent;
317
+ if (!ts.isBinaryExpression(binary) || binary.operatorToken.kind !== ts.SyntaxKind.EqualsToken || binary.right !== assignment)
318
+ return false;
319
+ if (!namesParameter(binary.left) || !ts.isExpressionStatement(binary.parent))
320
+ return false;
321
+ let consequent = binary.parent;
322
+ if (ts.isBlock(consequent.parent) && consequent.parent.statements.length === 1)
323
+ consequent = consequent.parent;
324
+ const guard = consequent.parent;
325
+ if (!ts.isIfStatement(guard) || guard.thenStatement !== consequent)
326
+ return false;
327
+ const condition = unwrap(guard.expression);
328
+ return ts.isPrefixUnaryExpression(condition) && condition.operator === ts.SyntaxKind.ExclamationToken && namesParameter(condition.operand);
329
+ };
271
330
  /**
272
331
  * A parameter the program DID type, whose statement is still only an UPPER
273
332
  * BOUND -- one with an `any`/`unknown`/bare-`Function` position somewhere
@@ -299,7 +358,9 @@ const statedUpperBound = (checker, parameter) => {
299
358
  return null;
300
359
  if (isUnusableEvidence(declared))
301
360
  return null;
302
- if (!containsUnstatedPosition(checker, parameter.type, declared))
361
+ if (!containsUnstatedPosition(checker, parameter.type, declared) &&
362
+ !statesOnlyAConstructionConvention(declared) &&
363
+ !statesAnArrayBufferView(declared))
303
364
  return null;
304
365
  // A DEFAULTED or OPTIONAL parameter's statement is `T | undefined` to its
305
366
  // callers, whatever its annotation spells: the absence is what the default
@@ -315,6 +376,23 @@ const statedUpperBound = (checker, parameter) => {
315
376
  const absent = parameter.initializer !== undefined || parameter.questionToken !== undefined;
316
377
  return absent ? checker.getNullableType(declared, ts.TypeFlags.Undefined) : declared;
317
378
  };
379
+ /**
380
+ * A stated structural constructor type, alone or beside absence: the class it
381
+ * constructs is the one position it leaves open -- see
382
+ * `narrowsStructuralConstructorToClasses`.
383
+ */
384
+ const statesOnlyAConstructionConvention = (declared) => {
385
+ const present = (declared.isUnion() ? declared.types : [declared]).filter((part) => (part.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined)) === 0);
386
+ return present.length === 1 && present[0] !== undefined && isStructuralConstructorType(present[0]);
387
+ };
388
+ /**
389
+ * Whether `actual` differs from the statement only where it said nothing: the
390
+ * shared `narrowsOnlyUnstatedPositions` test, or a closed set of classes
391
+ * standing in for a structural constructor type's open class identity.
392
+ */
393
+ const narrowsStatement = (checker, anchor, stated, actual) => narrowsOnlyUnstatedPositions(checker, anchor, stated, actual) ||
394
+ narrowsStructuralConstructorToClasses(checker, stated, actual) ||
395
+ narrowsArrayBufferViewToViews(checker, stated, actual);
318
396
  /**
319
397
  * A pure open object dictionary whose values the program explicitly leaves
320
398
  * dynamic.
@@ -332,12 +410,45 @@ const openDynamicObjectUpperBound = (checker, parameter) => {
332
410
  if (!parameter.type || !ts.isIdentifier(parameter.name) || parameter.dotDotDotToken)
333
411
  return null;
334
412
  const declared = checker.getTypeFromTypeNode(parameter.type);
335
- if (checker.getPropertiesOfType(declared).length !== 0)
413
+ if (isOpenDynamicObject(checker, declared))
414
+ return declared;
415
+ // mongodb's `decorateDecryptionResult(decrypted: Document & {
416
+ // [kDecoratedKeys]?: Array<string> })`: the open document beside members
417
+ // keyed only by program symbols, all optional. No caller's string key can
418
+ // name one, so the document is exactly as open as it is alone -- and the
419
+ // function recurses with `decrypted[k]`, an `any` that is a string or a
420
+ // number as often as an object, which the body's own `typeof` guard is for.
421
+ if (declared.isIntersection()) {
422
+ const open = declared.types.filter((member) => isOpenDynamicObject(checker, member));
423
+ const symbolKeyedOnly = (member) => (member.flags & ts.TypeFlags.Object) !== 0 &&
424
+ member.getCallSignatures().length === 0 &&
425
+ member.getConstructSignatures().length === 0 &&
426
+ checker.getIndexInfosOfType(member).length === 0 &&
427
+ checker
428
+ .getPropertiesOfType(member)
429
+ .every((property) => (property.flags & ts.SymbolFlags.Optional) !== 0 && String(property.escapedName).startsWith('__@'));
430
+ return open.length === 1 && declared.types.every((member) => open.includes(member) || symbolKeyedOnly(member)) ? declared : null;
431
+ }
432
+ // mongodb's `ifItFitsItSits(key, value: Record<string, any> | string)`: the
433
+ // open dictionary is one arm of a union whose other arms are primitives.
434
+ // Those primitives state their whole carrier and have no container a
435
+ // caller's Map could be mistaken for, so the dictionary arm is exactly as
436
+ // open as it is alone and the union is the same upper bound.
437
+ if (!declared.isUnion())
336
438
  return null;
337
- const dynamicStringIndex = checker
439
+ const primitive = ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BooleanLike | ts.TypeFlags.Undefined | ts.TypeFlags.Null;
440
+ const open = declared.types.filter((member) => isOpenDynamicObject(checker, member));
441
+ const rest = declared.types.filter((member) => !open.includes(member));
442
+ return open.length === 1 && rest.every((member) => (member.flags & primitive) !== 0) ? declared : null;
443
+ };
444
+ const isOpenDynamicObject = (checker, declared) => {
445
+ if ((declared.flags & ts.TypeFlags.Object) === 0)
446
+ return false;
447
+ if (checker.getPropertiesOfType(declared).length !== 0)
448
+ return false;
449
+ return checker
338
450
  .getIndexInfosOfType(declared)
339
- .find((index) => (index.keyType.flags & ts.TypeFlags.String) !== 0 && (index.type.flags & ts.TypeFlags.Any) !== 0);
340
- return dynamicStringIndex ? declared : null;
451
+ .some((index) => (index.keyType.flags & ts.TypeFlags.String) !== 0 && (index.type.flags & ts.TypeFlags.Any) !== 0);
341
452
  };
342
453
  /**
343
454
  * A flow narrowing that changes the value's physical container identity.
@@ -349,6 +460,13 @@ const openDynamicObjectUpperBound = (checker, parameter) => {
349
460
  * names to dictionary properties; treating that view as a second allocation
350
461
  * kind loses negative narrowing when control leaves the predicate branch.
351
462
  */
463
+ /** `{ [key: string]: any }` -- mongodb's and bson's `Document`, the one object type that can view an Array or a Map. */
464
+ const isOpenDocumentBound = (checker, type) => {
465
+ if ((type.flags & ts.TypeFlags.Object) === 0 || checker.isArrayType(type) || checker.isTupleType(type))
466
+ return false;
467
+ const index = checker.getIndexInfoOfType(type, ts.IndexKind.String);
468
+ return index !== undefined && (index.type.flags & ts.TypeFlags.Any) !== 0 && type.getCallSignatures().length === 0;
469
+ };
352
470
  const isFlowContainerType = (checker, anchor, type) => checker.isArrayType(type) || ['Map', 'Set', 'WeakMap', 'WeakSet'].some((name) => isStandardInterfaceType(checker, anchor, name, type));
353
471
  export const indexParameterBindingProgram = (checker, files, reachable, valueFlow = indexValueFlow(checker, files, reachable), argumentsObjects = censusArgumentsObjects(checker, files)) => {
354
472
  // `GEA_INDEX_TIMING=1` prints what one build of this index costs. It is the
@@ -358,8 +476,12 @@ export const indexParameterBindingProgram = (checker, files, reachable, valueFlo
358
476
  // five without the hoist, one with it.
359
477
  const startedAt = process.env['GEA_INDEX_TIMING'] ? performance.now() : 0;
360
478
  const candidates = [];
479
+ const jsxCallbackParameters = new Map();
361
480
  const restParameterCandidates = [];
362
481
  const omissionSites = [];
482
+ const recordHomeSites = [];
483
+ const classInstanceSites = [];
484
+ const overrideRecordSites = [];
363
485
  const assigned = new Set();
364
486
  // An update, logical assignment, destructuring assignment, or loop binding
365
487
  // also replaces a parameter. Sharing the write inventory prevents the
@@ -417,8 +539,11 @@ export const indexParameterBindingProgram = (checker, files, reachable, valueFlo
417
539
  const visit = (node) => {
418
540
  if (reachable.memberIsPruned(node))
419
541
  return;
420
- if (isTrackedCallable(node)) {
542
+ if (isTrackedCallable(node) || ts.isMethodSignature(node)) {
421
543
  runtimeParametersOf(node).forEach((parameter, index) => {
544
+ const contextual = inlineJsxCallbackParameterType(checker, parameter);
545
+ if (contextual !== null)
546
+ jsxCallbackParameters.set(parameter, contextual);
422
547
  // An UNANNOTATED rest parameter is a candidate for its OWN
423
548
  // element-wise join (`restElementTypeAt`), never for the ordinary
424
549
  // fixed-position sweep below -- `isUnannotated` returns `false` for
@@ -447,6 +572,15 @@ export const indexParameterBindingProgram = (checker, files, reachable, valueFlo
447
572
  const omissionStated = omissionStatedTypeOf(checker, parameter);
448
573
  if (omissionStated)
449
574
  omissionSites.push({ declaration: node, parameter, index, stated: omissionStated });
575
+ const recordUnion = recordArmUnionStatementOf(checker, node, parameter);
576
+ if (recordUnion)
577
+ recordHomeSites.push({ declaration: node, parameter, index, stated: recordUnion });
578
+ const recordStatement = plainRecordStatementOf(checker, parameter);
579
+ if (recordStatement)
580
+ classInstanceSites.push({ declaration: node, parameter, index, stated: recordStatement });
581
+ const overrideStatement = overrideRecordStatementOf(checker, node, parameter);
582
+ if (overrideStatement)
583
+ overrideRecordSites.push({ declaration: node, parameter, index, stated: overrideStatement });
450
584
  }
451
585
  }
452
586
  });
@@ -625,6 +759,24 @@ export const indexParameterBindingProgram = (checker, files, reachable, valueFlo
625
759
  }
626
760
  return result;
627
761
  })();
762
+ const interfaceMemberBodies = new Map();
763
+ // The interface carrier census already proves that every store into these
764
+ // contracts holds one of these classes. Its physical methods must receive
765
+ // the contract's call-site evidence even when receiver escape analysis cannot
766
+ // independently close the whole object graph. This adds evidence only; the
767
+ // method's existing escape obligation still decides whether narrowing is safe.
768
+ for (const [contract, implementations] of interfaceFlowImplementorsOf(checker, files)) {
769
+ for (const member of contract.members) {
770
+ if (!ts.isMethodSignature(member))
771
+ continue;
772
+ const symbol = checker.getSymbolAtLocation(member.name);
773
+ if (!symbol)
774
+ continue;
775
+ const bodies = implementations.flatMap((implementation) => (checker.getPropertyOfType(checker.getTypeAtLocation(implementation), symbol.getName())?.declarations ?? []).filter((declaration) => ts.isMethodDeclaration(declaration) && declaration.body !== undefined));
776
+ if (bodies.length > 0)
777
+ interfaceMemberBodies.set(member, [...new Set(bodies)]);
778
+ }
779
+ }
628
780
  if (process.env['GEA_INDEX_TIMING']) {
629
781
  process.stderr.write(`[INDEX] parameter-binding program index built in ${(performance.now() - startedAt).toFixed(0)}ms\n`);
630
782
  }
@@ -632,10 +784,14 @@ export const indexParameterBindingProgram = (checker, files, reachable, valueFlo
632
784
  implicitArgumentsUses: argumentsObjects.usesByOwner,
633
785
  valueFlow,
634
786
  candidates,
787
+ jsxCallbackParameters,
635
788
  restParameterCandidates,
636
789
  notReassigned,
637
790
  reassigned,
638
791
  omissionSites,
792
+ recordHomeSites,
793
+ classInstanceSites,
794
+ overrideRecordSites,
639
795
  assigned,
640
796
  assignedEvidence,
641
797
  allCalls,
@@ -643,7 +799,8 @@ export const indexParameterBindingProgram = (checker, files, reachable, valueFlo
643
799
  invocationOperands,
644
800
  aliasEvidence,
645
801
  overridesOfBaseMethod,
646
- siblingMemberDeclarations
802
+ siblingMemberDeclarations,
803
+ interfaceMemberBodies
647
804
  });
648
805
  };
649
806
  /**
@@ -737,7 +894,15 @@ index = indexParameterBindingProgram(checker, files, reachable),
737
894
  * A one-shot census can use its index's flow; a composed census must receive
738
895
  * the same round snapshot as the field, local, return and collection censuses.
739
896
  */
740
- valueFlow = index.valueFlow) => {
897
+ valueFlow = index.valueFlow,
898
+ /**
899
+ * Which copy of a generic body each call reaches -- see `copyTypeAt`. Absent
900
+ * for a caller that states no generics, which then binds per declaration
901
+ * exactly as before.
902
+ */
903
+ specializations,
904
+ /** `UnresolvableNameCensus.hostProvidedNames`, so a name this census resolves resolves as the reference producer does. */
905
+ hostProvided = noHostProvidedNames) => {
741
906
  /** Every call this program makes, grouped by the declaration its signature resolved to. */
742
907
  const callsByDeclaration = new Map();
743
908
  const callTargets = new Map();
@@ -760,12 +925,17 @@ valueFlow = index.valueFlow) => {
760
925
  * see its doc. `callsByDeclaration` above is the one index that is NOT
761
926
  * shared: `attributeCalls` rewrites it as bindings improve.
762
927
  */
763
- const { allCalls, checkerAttribution, invocationOperands, aliasEvidence, overridesOfBaseMethod, siblingMemberDeclarations, assignedEvidence } = index;
928
+ const { allCalls, checkerAttribution, invocationOperands, aliasEvidence, overridesOfBaseMethod, siblingMemberDeclarations, interfaceMemberBodies, assignedEvidence } = index;
764
929
  const protocolLedger = deferredIntrinsicProtocolLedgerOf(valueFlow);
765
930
  const protocolRequirements = new Map();
766
931
  const upstreamProtocolRequirements = protocolLedger?.requirements() ?? [];
767
932
  /** What each bound parameter declaration now holds. */
768
933
  const bindings = new Map();
934
+ for (const [parameter, type] of index.jsxCallbackParameters) {
935
+ const symbol = checker.getSymbolAtLocation(parameter.name);
936
+ if (symbol && !index.assigned.has(symbol))
937
+ bindings.set(parameter, type);
938
+ }
769
939
  /** Synthesized union arms for a disjointly-disagreeing parameter -- see `agreedArgumentType`. */
770
940
  const unionArms = new Map();
771
941
  // A synthesized parameter union is also a value read by sibling parameter
@@ -784,11 +954,68 @@ valueFlow = index.valueFlow) => {
784
954
  unionTypes.set(parameter, disjointUnionTypeOf(checker, arms));
785
955
  return unionTypes.get(parameter) ?? null;
786
956
  };
957
+ /**
958
+ * The STATED parameters `statedUnionArmsRefusal` admitted a synthesized
959
+ * union for. Their cell holds different arms at different points of the
960
+ * body -- `isSuperset`'s `set` is the caller's `string[]` until
961
+ * `set = Array.isArray(set) ? new Set(set) : set` rebinds it -- and the
962
+ * checker's control flow says which one a read sees. A read the flow
963
+ * narrowed to exactly one arm is typed as that arm (`flowArmOf`), and its
964
+ * binding read projects the arm out of the cell with the runtime-checked
965
+ * exact-arm projection (`narrowedBindingRead`, the operand's `asserted`).
966
+ */
967
+ const statedUnionParameters = new Set();
968
+ const flowArmOf = (node, parameter) => {
969
+ if (flowCarrierArms.has(parameter)) {
970
+ const carried = flowCarrierArmsOf(node, parameter);
971
+ return carried?.length === 1 ? carried[0] : null;
972
+ }
973
+ if (!statedUnionParameters.has(parameter))
974
+ return null;
975
+ const arms = unionArms.get(parameter);
976
+ if (!arms)
977
+ return null;
978
+ const flow = checker.getTypeAtLocation(node);
979
+ const matching = arms.filter((arm) => arm === flow || (checker.isTypeAssignableTo(arm, flow) && checker.isTypeAssignableTo(flow, arm)));
980
+ return matching.length === 1 ? matching[0] : null;
981
+ };
787
982
  /** What each array-pattern element reads before its default -- see `patternReadTypeAt`. */
788
983
  const patternReadTypes = new Map();
789
984
  /** Physical object arms proven by flow narrowing of an open dynamic-object upper bound. */
790
985
  const flowCarrierArms = new Map();
791
986
  const flowCarrierBounds = new Map();
987
+ /** A stated record union's declared arms plus the callers' records it had no single home for -- see `record-home-arms.ts`. */
988
+ const recordHomeArms = new Map();
989
+ /**
990
+ * The one physical arm a read of an open-document cell holds where the
991
+ * checker's flow narrowed it to a container: bson's `makeFrame(sourceObject:
992
+ * Document)` reads `sourceObject` as `any[]` under `Array.isArray`. The cell
993
+ * is the arm union, and typing that read as the whole cell let the store
994
+ * into a `Document` slot select the dictionary arm out of an array --
995
+ * certified, and reading the array's bytes as a dictionary. A read at the
996
+ * upper bound itself is the whole cell (`null`, `unionArmsAt` answers it).
997
+ * `any[]` matches every array arm -- a caller's `number[]` beside the
998
+ * body's own `any[]` -- and `Array.isArray` is true of each, so such a read
999
+ * is the sub-union of those arms, never one picked from among them.
1000
+ */
1001
+ const flowCarrierArmsOf = (node, parameter) => {
1002
+ const arms = flowCarrierArms.get(parameter);
1003
+ const upper = flowCarrierBounds.get(parameter);
1004
+ if (!arms || !upper)
1005
+ return null;
1006
+ const flow = checker.getNonNullableType(checker.getTypeAtLocation(node));
1007
+ if (!isFlowContainerType(checker, node, flow))
1008
+ return null;
1009
+ // The open document itself stays an arm of an Array or Map read: it may
1010
+ // VIEW one (`gea::dictionary::aliasOf`) -- a caller's `Document` that
1011
+ // holds a Map passes `instanceof Map` exactly as the Map arm does.
1012
+ const viewable = checker.isArrayType(flow) || isStandardInterfaceType(checker, node, 'Map', flow);
1013
+ const bounds = upper.isUnion() ? upper.types : [upper];
1014
+ const matching = arms.filter((arm) => arm === flow ||
1015
+ (checker.isTypeAssignableTo(arm, flow) && checker.isTypeAssignableTo(flow, arm)) ||
1016
+ (viewable && bounds.includes(arm) && !isFlowContainerType(checker, node, arm) && isOpenDocumentBound(checker, arm)));
1017
+ return matching.length === 0 ? null : matching;
1018
+ };
792
1019
  /**
793
1020
  * Whether every reference to this function's name is a call this census
794
1021
  * counted. A function nothing holds as a value has exactly the callers this
@@ -1012,6 +1239,17 @@ valueFlow = index.valueFlow) => {
1012
1239
  };
1013
1240
  const escapeReason = (declaration, requireCountedReferences = false) => {
1014
1241
  memberOpenUses.delete(declaration);
1242
+ if (ts.isMethodSignature(declaration)) {
1243
+ // An interface has no executable body to escape. Its physical call
1244
+ // frame can follow the caller census only when the joint value graph
1245
+ // closes every receiver and implementation used through this signature.
1246
+ const calls = callsByDeclaration.get(declaration) ?? [];
1247
+ const sourceValues = sourceValueSessionOf(checker, valueFlow);
1248
+ return calls.length > 0 &&
1249
+ calls.every((call) => ts.isCallExpression(call) && sourceValues.ownsInvocation(call) && (sourceValues.invocationTargetsOf(call)?.length ?? 0) > 0)
1250
+ ? null
1251
+ : 'function-escapes:uncounted-member-reference';
1252
+ }
1015
1253
  const name = nameOfCallable(declaration);
1016
1254
  if (!name)
1017
1255
  return `function-escapes:unnamed:${declaration.parent ? ts.SyntaxKind[declaration.parent.kind] : 'root'}`;
@@ -1308,10 +1546,17 @@ valueFlow = index.valueFlow) => {
1308
1546
  if (declaration && ts.isBindingElement(declaration) && impliedPatternElementRootOf(checker, declaration) !== null)
1309
1547
  return null;
1310
1548
  }
1549
+ // The checker's `any[]` for an `Array.from` it instantiated over an
1550
+ // `any` source is not what the census knows the source holds: the
1551
+ // resolver's own answer (`arrayFromCopyTypeAt`) is.
1552
+ if (ts.isCallExpression(node) && arrayFromCopyTypeAt(checker, node, (operand) => known(operand) ?? resolve(operand)) !== null)
1553
+ return null;
1311
1554
  return type;
1312
1555
  };
1313
1556
  const declarationOf = (node) => {
1314
- const symbol = checker.getSymbolAtLocation(node);
1557
+ // `{ x }` reads the binding `x` exactly as `{ x: x }` does; the name's
1558
+ // own symbol is the literal's property, which holds no cell.
1559
+ const symbol = valueSymbolAt(checker, node, hostProvided);
1315
1560
  const declarations = symbol?.declarations;
1316
1561
  return declarations && declarations.length === 1 ? (declarations[0] ?? null) : null;
1317
1562
  };
@@ -1359,7 +1604,7 @@ valueFlow = index.valueFlow) => {
1359
1604
  * member initializer reads back through the same member.
1360
1605
  */
1361
1606
  const propertyTypeOf = (receiver, name, at) => {
1362
- const answer = memberTypeOf(checker, receiver, name, at, valueFlow);
1607
+ const answer = memberTypeOf(checker, receiver, name, at, valueFlow, upstream);
1363
1608
  if (answer !== null && !isUnusableEvidence(answer))
1364
1609
  return answer;
1365
1610
  // A member only some classes of the receiver's closed family declare:
@@ -1654,7 +1899,7 @@ valueFlow = index.valueFlow) => {
1654
1899
  if (!declaration)
1655
1900
  return null;
1656
1901
  if (ts.isParameter(declaration))
1657
- return parameterTypeOf(declaration);
1902
+ return flowArmOf(node, declaration) ?? parameterTypeOf(declaration);
1658
1903
  // A binding holds what is written into it, and EVERY write counts. Its
1659
1904
  // initializer is one; so is every later assignment -- `let _gl = context;
1660
1905
  // ... _gl = getContext( contextName, contextAttributes );` in
@@ -1992,7 +2237,7 @@ valueFlow = index.valueFlow) => {
1992
2237
  // discarded all their supplied configuration evidence. Absence is a
1993
2238
  // real incoming value, including when every caller omits the argument;
1994
2239
  // only a default replaces it before the body observes the binding.
1995
- if (!argument && checker.isOptionalParameter(parameter)) {
2240
+ if (!argument && (checker.isOptionalParameter(parameter) || omissionIsUntypedJavaScript(parameter))) {
1996
2241
  sawOmitted = true;
1997
2242
  if (parameter.initializer === undefined)
1998
2243
  passed.push(checker.getUndefinedType());
@@ -2063,9 +2308,75 @@ valueFlow = index.valueFlow) => {
2063
2308
  }
2064
2309
  return { passed, sawBackEdge, sawOmitted, sawSilentSite, deferredRecursiveArguments };
2065
2310
  };
2311
+ /**
2312
+ * The statement a GENERIC declaration makes at this parameter, as its
2313
+ * callers instantiate it.
2314
+ *
2315
+ * mongodb's `setDifference<T>(setA: Iterable<T>, setB: Iterable<T>)` states
2316
+ * `Iterable<T>`, and no concrete argument is assignable to an open `T` -- so
2317
+ * the upper-bound census refused a `Set<string>` and a `string[]` and the
2318
+ * parameters fell back to a record layout for the protocol view. What the
2319
+ * statement says to each caller is the signature the checker resolved there
2320
+ * (`Iterable<string>`); when every direct caller resolves the SAME closed
2321
+ * statement, that is the statement this parameter's storage answers to, and
2322
+ * holding the agreed argument to it is exactly the non-generic test. Callers
2323
+ * that disagree, a callback contract (no resolved call to read), or a
2324
+ * statement still open at a call site keep the refusal.
2325
+ */
2326
+ const instantiatedStatement = (declaration, parameter, parameterIndex, stated, calls = callsByDeclaration.get(declaration) ?? []) => {
2327
+ if (!carriesUnsubstitutedGeneric(checker, stated))
2328
+ return stated;
2329
+ if ((contractsFor(declaration)?.length ?? 0) > 0)
2330
+ return null;
2331
+ if (calls.length === 0)
2332
+ return null;
2333
+ let agreed = null;
2334
+ for (const call of calls) {
2335
+ const signature = checker.getResolvedSignature(call);
2336
+ const symbol = signature?.parameters[parameterIndex];
2337
+ if (!symbol)
2338
+ return null;
2339
+ const instantiated = checker.getTypeOfSymbol(symbol);
2340
+ if (carriesUnsubstitutedGeneric(checker, instantiated))
2341
+ return null;
2342
+ if (agreed !== null && agreed !== instantiated)
2343
+ return null;
2344
+ agreed = instantiated;
2345
+ }
2346
+ if (agreed === null)
2347
+ return null;
2348
+ const absent = parameter.initializer !== undefined || parameter.questionToken !== undefined;
2349
+ return absent ? checker.getNullableType(agreed, ts.TypeFlags.Undefined) : agreed;
2350
+ };
2351
+ /**
2352
+ * Whether a synthesized disjoint union of call-site types may stand for a
2353
+ * STATED parameter: held to the statement exactly as a single agreed type
2354
+ * is, with the arms read together as the one union they are. mongodb's
2355
+ * `isSuperset(set: Set<any> | any[], ...)` is passed a `string[]` and
2356
+ * rebinds itself to `new Set(set)`: the cell holds `string[] | Set<string>`,
2357
+ * each arm the statement's own member with only its `any` element refined.
2358
+ * `null` when admitted, otherwise the refusal to record.
2359
+ */
2360
+ const statedUnionArmsRefusal = (candidate, arms, recursive) => {
2361
+ if (candidate.stated === null)
2362
+ return 'stated-parameter-synthesized-union';
2363
+ if (recursive)
2364
+ return 'recursive-derived-argument-synthesized-union';
2365
+ if (arms.some((arm) => carriesUnsubstitutedGeneric(checker, arm)))
2366
+ return 'stated-parameter-open-generic';
2367
+ const stated = instantiatedStatement(candidate.declaration, candidate.parameter, candidate.index, candidate.stated);
2368
+ if (stated === null || !arms.every((arm) => checker.isTypeAssignableTo(arm, stated)))
2369
+ return 'stated-parameter-argument-not-assignable';
2370
+ const constructing = checker;
2371
+ const union = typeof constructing.getUnionType === 'function' ? constructing.getUnionType(arms) : null;
2372
+ if (union === null)
2373
+ return 'stated-parameter-synthesized-union';
2374
+ if (!narrowsStatement(checker, candidate.parameter, stated, union))
2375
+ return 'stated-parameter-narrows-a-stated-position';
2376
+ return null;
2377
+ };
2066
2378
  /** The type every call site passes at this position, or the reason there is no single one. */
2067
- const agreedArgumentType = (declaration, parameter, parameterIndex, skipSilentSites) => {
2068
- const calls = callsByDeclaration.get(declaration) ?? [];
2379
+ const agreedArgumentType = (declaration, parameter, parameterIndex, skipSilentSites, calls = callsByDeclaration.get(declaration) ?? []) => {
2069
2380
  const contracts = contractsFor(declaration) ?? [];
2070
2381
  const contractTypes = [];
2071
2382
  for (const contract of contracts) {
@@ -2144,10 +2455,24 @@ valueFlow = index.valueFlow) => {
2144
2455
  // the assignment expression itself, where the operator states the result;
2145
2456
  // every other write is resolved like any other value expression.
2146
2457
  const parameterSymbol = ts.isIdentifier(parameter.name) ? checker.getSymbolAtLocation(parameter.name) : undefined;
2147
- const writes = (parameterSymbol && assignedEvidence.get(parameterSymbol)) || [];
2148
- const writtenTypes = writes.map((write) => write.operatorTyped
2458
+ const allWrites = (parameterSymbol && assignedEvidence.get(parameterSymbol)) || [];
2459
+ const allWrittenTypes = allWrites.map((write) => write.operatorTyped
2149
2460
  ? checker.getTypeAtLocation(write.expression)
2150
2461
  : (propagating.known(write.expression) ?? propagating.resolve(write.expression)));
2462
+ // `if (!opts) opts = {}` runs only when the cell holds a falsy value. When
2463
+ // every value that can reach the guard -- each supplied argument and every
2464
+ // OTHER write -- is an object, the guard cannot pass and the write never
2465
+ // executes, so it is not evidence about the cell (sparse-bitfield's
2466
+ // `Bitfield(opts)`, called only as `bitfield({ buffer })`). An omitted or
2467
+ // unresolved argument may be `undefined`, so either keeps every write.
2468
+ const falsyGuarded = allWrites.map((write) => !write.operatorTyped && parameterSymbol !== undefined && isFalsyGuardedWriteOf(checker, write.expression, parameterSymbol));
2469
+ const guardedWritesAreDead = falsyGuarded.some(Boolean) &&
2470
+ !resolution.sawOmitted &&
2471
+ !resolution.sawSilentSite &&
2472
+ resolution.passed.length > 0 &&
2473
+ [...resolution.passed, ...contractTypes, ...allWrittenTypes.filter((_, position) => !falsyGuarded[position])].every((type) => type !== null && type !== undefined && isAlwaysTruthyType(type));
2474
+ const writes = guardedWritesAreDead ? allWrites.filter((_, position) => !falsyGuarded[position]) : allWrites;
2475
+ const writtenTypes = guardedWritesAreDead ? allWrittenTypes.filter((_, position) => !falsyGuarded[position]) : allWrittenTypes;
2151
2476
  // A complete numeric incoming frame can seed a numeric storage invariant.
2152
2477
  // Test EVERY write under that hypothesis before publishing it. In
2153
2478
  // particular, += is operand-sensitive: its checker answer stays any for an
@@ -2443,6 +2768,14 @@ valueFlow = index.valueFlow) => {
2443
2768
  pushCall(declaration, call);
2444
2769
  if (ts.isFunctionLike(declaration))
2445
2770
  resolvedCallDeclarations.set(call, declaration);
2771
+ // An overload signature is a compile-time view: the body that runs,
2772
+ // and whose parameters these arguments land in, is the one
2773
+ // implementation. mongodb's `Connection.command` is called only
2774
+ // through its three overloads, so its implementation saw no call
2775
+ // site at all and every parameter of it stayed the annotation.
2776
+ const implementation = implementationOfOverload(checker, declaration);
2777
+ if (implementation !== null)
2778
+ pushCall(implementation, call);
2446
2779
  }
2447
2780
  // ALIAS value flow: a call through a resolved member/selector-result
2448
2781
  // whose VALUE is a known function is a real call site of that
@@ -2452,6 +2785,17 @@ valueFlow = index.valueFlow) => {
2452
2785
  if (ts.isCallExpression(call)) {
2453
2786
  for (const aliased of aliasDeclarationsFor(call))
2454
2787
  pushCall(aliased, call);
2788
+ // A structural interface signature is not the body receiving the
2789
+ // arguments. Attribute its closed source targets too; otherwise one
2790
+ // direct call can narrow a method while its interface callers vanish.
2791
+ const sourceValues = sourceValueSessionOf(checker, valueFlow);
2792
+ if (sourceValues.ownsInvocation(call)) {
2793
+ const implementations = sourceValues.invocationTargetsOf(call);
2794
+ for (const implementation of implementations ?? [])
2795
+ pushCall(implementation, call);
2796
+ if (implementations?.length === 1)
2797
+ resolvedCallDeclarations.set(call, implementations[0]);
2798
+ }
2455
2799
  }
2456
2800
  }
2457
2801
  // Close the declaration relation with a worklist. A single pass depends on
@@ -2460,7 +2804,11 @@ valueFlow = index.valueFlow) => {
2460
2804
  const pending = [...callsByDeclaration].flatMap(([declaration, calls]) => calls.map((call) => ({ declaration, call })));
2461
2805
  for (let cursor = 0; cursor < pending.length; cursor++) {
2462
2806
  const { declaration, call } = pending[cursor];
2463
- const destinations = [...(overridesOfBaseMethod.get(declaration) ?? []), ...(siblingMemberDeclarations.get(declaration) ?? [])];
2807
+ const destinations = [
2808
+ ...(overridesOfBaseMethod.get(declaration) ?? []),
2809
+ ...(siblingMemberDeclarations.get(declaration) ?? []),
2810
+ ...(interfaceMemberBodies.get(declaration) ?? [])
2811
+ ];
2464
2812
  for (const destination of destinations) {
2465
2813
  if (callsByDeclaration.get(destination)?.includes(call))
2466
2814
  continue;
@@ -2507,6 +2855,11 @@ valueFlow = index.valueFlow) => {
2507
2855
  refuse('parameter-reassigned', describeParameter(candidate.parameter));
2508
2856
  /** The subset of `bindings` that came from a STATED annotation -- see `statedTypeAt`. */
2509
2857
  const statedBindings = new Map();
2858
+ for (const parameter of index.jsxCallbackParameters.keys()) {
2859
+ const bound = bindings.get(parameter);
2860
+ if (bound)
2861
+ statedBindings.set(parameter, bound);
2862
+ }
2510
2863
  let lastRefusal = new Map();
2511
2864
  /**
2512
2865
  * An optional parameter with no default binds `T | undefined` in its body, whatever
@@ -2615,19 +2968,30 @@ valueFlow = index.valueFlow) => {
2615
2968
  // census builds for `table.intern`, never a `ts.Type` the statement can
2616
2969
  // be tested against, so there is nothing to hold it to.
2617
2970
  if (candidate.stated) {
2971
+ if ('unionArms' in answer) {
2972
+ const refusal = statedUnionArmsRefusal(candidate, answer.unionArms, answer.deferredRecursiveArguments.length > 0);
2973
+ if (refusal !== null) {
2974
+ lastRefusal.set(candidate.parameter, refusal);
2975
+ return false;
2976
+ }
2977
+ unionArms.set(candidate.parameter, withDeclaredAbsenceArms(candidate.parameter, answer.unionArms));
2978
+ statedUnionParameters.add(candidate.parameter);
2979
+ return true;
2980
+ }
2618
2981
  if (!('type' in answer)) {
2619
- lastRefusal.set(candidate.parameter, 'unionArms' in answer ? 'stated-parameter-synthesized-union' : answer.refused);
2982
+ lastRefusal.set(candidate.parameter, answer.refused);
2620
2983
  return false;
2621
2984
  }
2622
2985
  if (carriesUnsubstitutedGeneric(checker, answer.type)) {
2623
2986
  lastRefusal.set(candidate.parameter, 'stated-parameter-open-generic');
2624
2987
  return false;
2625
2988
  }
2626
- if (!checker.isTypeAssignableTo(answer.type, candidate.stated)) {
2989
+ const stated = instantiatedStatement(candidate.declaration, candidate.parameter, candidate.index, candidate.stated);
2990
+ if (stated === null || !checker.isTypeAssignableTo(answer.type, stated)) {
2627
2991
  lastRefusal.set(candidate.parameter, 'stated-parameter-argument-not-assignable');
2628
2992
  return false;
2629
2993
  }
2630
- if (!narrowsOnlyUnstatedPositions(checker, candidate.parameter, candidate.stated, answer.type)) {
2994
+ if (!narrowsStatement(checker, candidate.parameter, stated, answer.type)) {
2631
2995
  lastRefusal.set(candidate.parameter, 'stated-parameter-narrows-a-stated-position');
2632
2996
  return false;
2633
2997
  }
@@ -2810,59 +3174,135 @@ valueFlow = index.valueFlow) => {
2810
3174
  // checker exposes under a pure `[string]: any` upper bound, alongside the
2811
3175
  // dictionary arm used by unnarrowed reads. Preserve the complete finite
2812
3176
  // member set, as the ordinary synthesized-union path does.
2813
- for (const candidate of notReassigned) {
2814
- const upper = candidate.flowCarrierUpperBound;
2815
- if (!upper || !ts.isIdentifier(candidate.parameter.name))
2816
- continue;
2817
- const symbol = checker.getSymbolAtLocation(candidate.parameter.name);
2818
- const references = symbol ? valueFlow.memberReferencesToSymbol(symbol) : [];
2819
- const narrowed = [];
2820
- for (const reference of references) {
2821
- const type = checker.getTypeAtLocation(reference);
2822
- if ((type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never)) !== 0)
2823
- continue;
2824
- if (!isFlowContainerType(checker, reference, type))
2825
- continue;
2826
- if (!checker.isTypeAssignableTo(type, upper))
2827
- continue;
2828
- if (checker.isTypeAssignableTo(upper, type))
3177
+ const publishFlowCarrierArms = () => {
3178
+ let grew = false;
3179
+ for (const candidate of notReassigned) {
3180
+ const upper = candidate.flowCarrierUpperBound;
3181
+ if (!upper || !ts.isIdentifier(candidate.parameter.name))
2829
3182
  continue;
2830
- if (narrowed.some((seen) => checker.isTypeAssignableTo(type, seen) && checker.isTypeAssignableTo(seen, type)))
3183
+ const symbol = checker.getSymbolAtLocation(candidate.parameter.name);
3184
+ const references = symbol ? valueFlow.memberReferencesToSymbol(symbol) : [];
3185
+ const narrowed = [];
3186
+ // The union form (`Record<string, any> | string`) is admitted for what
3187
+ // callers physically hand over, not for what a body guard could imagine:
3188
+ // mongodb's `normalizeHintField(hint?: string | Document)` tests
3189
+ // `Array.isArray(hint)` though no caller passes an array, and a speculative
3190
+ // array arm there only makes every later object read a three-way sum.
3191
+ for (const reference of upper.isUnion() ? [] : references) {
3192
+ const type = checker.getTypeAtLocation(reference);
3193
+ if ((type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never)) !== 0)
3194
+ continue;
3195
+ if (!isFlowContainerType(checker, reference, type))
3196
+ continue;
3197
+ if (!checker.isTypeAssignableTo(type, upper))
3198
+ continue;
3199
+ if (checker.isTypeAssignableTo(upper, type))
3200
+ continue;
3201
+ if (narrowed.some((seen) => checker.isTypeAssignableTo(type, seen) && checker.isTypeAssignableTo(seen, type)))
3202
+ continue;
3203
+ narrowed.push(type);
3204
+ }
3205
+ // A call that explicitly crosses this boundary from `any` contributes a
3206
+ // real dynamic arm. Plain runtime objects must remain the boxes they are;
3207
+ // rebuilding them as dictionaries would change identity and lose
3208
+ // prototype/accessor behavior. Concrete Document/Array/Map callers keep
3209
+ // their native arms beside it.
3210
+ let dynamicCallArm = null;
3211
+ for (const call of callsByDeclaration.get(candidate.declaration) ?? []) {
3212
+ const args = invocationOperands.get(call).args;
3213
+ const argument = args?.[candidate.index];
3214
+ if (!argument)
3215
+ continue;
3216
+ // Another open-document cell handed over whole hands over every arm it
3217
+ // holds: `describe(source: Document)` passing `source` on to
3218
+ // `keysOf(d: Document)` passes the array a caller put in `source`, and
3219
+ // a `d` that holds only the dictionary arm selected it out of the array.
3220
+ const forwarded = forwardedFlowCarrierArms(argument);
3221
+ if (forwarded !== null) {
3222
+ for (const arm of forwarded) {
3223
+ if ((arm.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0)
3224
+ dynamicCallArm ??= arm;
3225
+ else if (isFlowContainerType(checker, argument, arm) && checker.isTypeAssignableTo(arm, upper) && !narrowed.includes(arm))
3226
+ narrowed.push(arm);
3227
+ }
3228
+ continue;
3229
+ }
3230
+ const passed = checker.getTypeAtLocation(argument);
3231
+ if ((passed.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0) {
3232
+ dynamicCallArm ??= passed;
3233
+ continue;
3234
+ }
3235
+ // A caller handing over a Map, Set or Array hands over THAT object:
3236
+ // `makeClientMetadata` passes its `os` Map and keeps deleting from it
3237
+ // afterwards, so a dictionary rebuilt from it would be a copy the
3238
+ // caller's later writes never reach. Its container is a carrier arm of
3239
+ // this cell exactly as a body `instanceof Map` narrowing makes one.
3240
+ // A caller's own union hands over each of its members: mongodb's
3241
+ // `updateOne(filter, update: UpdateFilter<TSchema> | Document[])`
3242
+ // passes `update` on to `UpdateOneOperation(..., update: Document)`,
3243
+ // whose cell then holds the pipeline array as well as the document.
3244
+ for (const member of passed.isUnion() ? passed.types : [passed]) {
3245
+ if (!isFlowContainerType(checker, argument, member))
3246
+ continue;
3247
+ if (!checker.isTypeAssignableTo(member, upper))
3248
+ continue;
3249
+ // Identity, not mutual assignability: `Map<any, any>` and `Map<string,
3250
+ // string | Int32>` assign both ways, but they are two storages, and an
3251
+ // arm of one cannot hold the other without a copy.
3252
+ if (narrowed.includes(member))
3253
+ continue;
3254
+ narrowed.push(member);
3255
+ }
3256
+ }
3257
+ const arms = [...(upper.isUnion() ? upper.types : [upper]), ...narrowed, ...(dynamicCallArm ? [dynamicCallArm] : [])];
3258
+ if (arms.length === (upper.isUnion() ? upper.types.length : 1))
2831
3259
  continue;
2832
- narrowed.push(type);
2833
- }
2834
- // A call that explicitly crosses this boundary from `any` contributes a
2835
- // real dynamic arm. Plain runtime objects must remain the boxes they are;
2836
- // rebuilding them as dictionaries would change identity and lose
2837
- // prototype/accessor behavior. Concrete Document/Array/Map callers keep
2838
- // their native arms beside it.
2839
- let dynamicCallArm = null;
2840
- for (const call of callsByDeclaration.get(candidate.declaration) ?? []) {
2841
- const args = invocationOperands.get(call).args;
2842
- const argument = args?.[candidate.index];
2843
- if (!argument)
3260
+ const published = withDeclaredAbsenceArms(candidate.parameter, arms);
3261
+ const previous = flowCarrierArms.get(candidate.parameter);
3262
+ if (previous !== undefined && previous.length === published.length && previous.every((arm, index) => arm === published[index]))
2844
3263
  continue;
2845
- const passed = checker.getTypeAtLocation(argument);
2846
- if ((passed.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0) {
2847
- dynamicCallArm = passed;
2848
- break;
2849
- }
3264
+ grew = true;
3265
+ // This late flow-container publication is a second synthesized-arm entry
3266
+ // point. It must preserve the same declared absence as the ordinary
3267
+ // `unionArms` path above; otherwise an optional open-document parameter
3268
+ // (BSON's `DBRef(..., fields?: Document)`) binds a required body union
3269
+ // while its callable slot remains optional.
3270
+ flowCarrierArms.set(candidate.parameter, published);
3271
+ flowCarrierBounds.set(candidate.parameter, upper);
3272
+ // The union is the cell's placement. A same-annotation binding learned
3273
+ // from call sites would otherwise outrank it in `parameterOf`.
3274
+ bindings.delete(candidate.parameter);
3275
+ statedBindings.delete(candidate.parameter);
3276
+ lastRefusal.delete(candidate.parameter);
2850
3277
  }
2851
- const arms = [upper, ...narrowed, ...(dynamicCallArm ? [dynamicCallArm] : [])];
2852
- if (arms.length === 1)
2853
- continue;
2854
- // This late flow-container publication is a second synthesized-arm entry
2855
- // point. It must preserve the same declared absence as the ordinary
2856
- // `unionArms` path above; otherwise an optional open-document parameter
2857
- // (BSON's `DBRef(..., fields?: Document)`) binds a required body union
2858
- // while its callable slot remains optional.
2859
- flowCarrierArms.set(candidate.parameter, withDeclaredAbsenceArms(candidate.parameter, arms));
2860
- flowCarrierBounds.set(candidate.parameter, upper);
2861
- // The union is the cell's placement. A same-annotation binding learned
2862
- // from call sites would otherwise outrank it in `parameterOf`.
2863
- bindings.delete(candidate.parameter);
2864
- statedBindings.delete(candidate.parameter);
2865
- lastRefusal.delete(candidate.parameter);
3278
+ return grew;
3279
+ };
3280
+ /**
3281
+ * The arms an argument hands over when it is itself a read of an
3282
+ * open-document cell: the whole cell at its upper bound, the matching arms
3283
+ * where the caller's flow narrowed it, `null` for any other argument.
3284
+ */
3285
+ const forwardedFlowCarrierArms = (argument) => {
3286
+ let unwrapped = argument;
3287
+ while (ts.isParenthesizedExpression(unwrapped))
3288
+ unwrapped = unwrapped.expression;
3289
+ if (!ts.isIdentifier(unwrapped))
3290
+ return null;
3291
+ const parameter = valueSymbolAt(checker, unwrapped, hostProvided)?.declarations?.find(ts.isParameter);
3292
+ const arms = parameter ? flowCarrierArms.get(parameter) : undefined;
3293
+ const upper = parameter ? flowCarrierBounds.get(parameter) : undefined;
3294
+ if (!parameter || !arms || !upper)
3295
+ return null;
3296
+ const read = checker.getNonNullableType(checker.getTypeAtLocation(unwrapped));
3297
+ if (checker.isTypeAssignableTo(read, upper) && checker.isTypeAssignableTo(upper, read))
3298
+ return arms;
3299
+ return flowCarrierArmsOf(unwrapped, parameter);
3300
+ };
3301
+ // A cell's arms feed the cells it is passed on to, so the publication runs
3302
+ // until no cell gains an arm; arms only ever grow, and each is a type some
3303
+ // caller or guard already states, so the set is finite.
3304
+ for (let round = 0; round <= notReassigned.length && publishFlowCarrierArms(); round++) {
3305
+ // A cell that grew may forward its new arms to the cells it is passed to.
2866
3306
  }
2867
3307
  // A stated JS parameter the census does not infer can still be left out by
2868
3308
  // a caller: three's `colorBuffer.setClear( 0, 0, 0, 1 )` against the
@@ -2873,6 +3313,9 @@ valueFlow = index.valueFlow) => {
2873
3313
  // like any inference, and its obligations are kept with the binding.
2874
3314
  propagating.reset();
2875
3315
  // `GEA_STATED_OMISSION_OFF` keeps the arm without this rule runnable, the way `GEA_BAG_OFF` is.
3316
+ // The parameters this rule widened. The class-instance rule below still owns
3317
+ // their LAYOUT -- see its own comment -- and keeps this rule's absence arm.
3318
+ const omissionWidened = new Set();
2876
3319
  for (const site of process.env['GEA_STATED_OMISSION_OFF'] ? [] : index.omissionSites) {
2877
3320
  if (bindings.has(site.parameter) || unionArms.has(site.parameter))
2878
3321
  continue;
@@ -2898,9 +3341,187 @@ valueFlow = index.valueFlow) => {
2898
3341
  bindings.set(site.parameter, answer.type);
2899
3342
  statedBindings.set(site.parameter, answer.type);
2900
3343
  protocolRequirements.set(site.parameter, captured.requirements);
3344
+ omissionWidened.add(site.parameter);
2901
3345
  if (process.env['GEA_BINDING_DEBUG'])
2902
3346
  console.error(`[STATED-OMISSION] ${describeParameter(site.parameter)} :: ${checker.typeToString(answer.type)}`);
2903
3347
  }
3348
+ // A record a caller hands to a stated record union with no single home for
3349
+ // it -- see `record-home-arms.ts`. Asked of the settled attribution, like the
3350
+ // omission rule above; not gated on escape for the same reason: the declared
3351
+ // arms stay, so a caller the census cannot see is still held to them, and
3352
+ // the arm only adds the value a caller the census DOES see provably passes.
3353
+ for (const site of index.recordHomeSites) {
3354
+ if (!ts.isIdentifier(site.parameter.name) || !site.stated.isUnion())
3355
+ continue;
3356
+ const declaredArms = site.stated.types;
3357
+ const symbol = checker.getSymbolAtLocation(site.parameter.name);
3358
+ if (!symbol || index.assigned.has(symbol))
3359
+ continue;
3360
+ const added = [];
3361
+ for (const call of callsByDeclaration.get(site.declaration) ?? []) {
3362
+ const argument = invocationOperands.get(call)?.args?.[site.index];
3363
+ if (!argument)
3364
+ continue;
3365
+ const passed = checker.getTypeAtLocation(argument);
3366
+ for (const member of passed.isUnion() ? passed.types : [passed]) {
3367
+ if (added.includes(member) || carriesUnsubstitutedGeneric(checker, member))
3368
+ continue;
3369
+ if (isHomelessRecordArm(checker, site.stated, member))
3370
+ added.push(member);
3371
+ }
3372
+ }
3373
+ if (added.length === 0)
3374
+ continue;
3375
+ recordHomeArms.set(site.parameter, withDeclaredAbsenceArms(site.parameter, [...declaredArms, ...added]));
3376
+ if (process.env['GEA_BINDING_DEBUG'])
3377
+ console.error(`[RECORD-HOME] ${describeParameter(site.parameter)} :: ${added.map((arm) => checker.typeToString(arm)).join(' | ')}`);
3378
+ }
3379
+ // A class instance a caller hands to a stated data record -- see
3380
+ // `class-instance-record-statement.ts`. The class joins the statement as
3381
+ // one more arm of the cell, exactly as a homeless record joins its union
3382
+ // above, and for the same reason needs no proof that the census found every
3383
+ // caller: the statement's own arm stays, so a caller it cannot see still
3384
+ // converts into it, and the class arm only holds what a caller it CAN see
3385
+ // provably passes -- the object itself, never a copy of it.
3386
+ for (const site of index.classInstanceSites) {
3387
+ // A parameter the omission rule widened is still this rule's: widening
3388
+ // answers only "may it be absent", while this answers which object the
3389
+ // record statement holds. memory-pager's `updated(page)` receives a `Page`
3390
+ // instance the census types `Page | undefined`; bound as the bare widened
3391
+ // statement, the instance was viewed into the record's struct -- a copy --
3392
+ // and `pager.updates[0] === one` compared a record with a `Page`.
3393
+ const widened = omissionWidened.has(site.parameter);
3394
+ if ((bindings.has(site.parameter) && !widened) || unionArms.has(site.parameter) || recordHomeArms.has(site.parameter))
3395
+ continue;
3396
+ if (!ts.isIdentifier(site.parameter.name))
3397
+ continue;
3398
+ const symbol = checker.getSymbolAtLocation(site.parameter.name);
3399
+ if (!symbol || index.assigned.has(symbol))
3400
+ continue;
3401
+ const passed = [];
3402
+ for (const call of callsByDeclaration.get(site.declaration) ?? []) {
3403
+ const argument = invocationOperands.get(call)?.args?.[site.index];
3404
+ if (argument)
3405
+ passed.push(propagating.known(argument) ?? propagating.resolve(argument) ?? checker.getTypeAtLocation(argument));
3406
+ }
3407
+ const classes = classInstanceArmsPassed(checker, site.stated, passed).filter((arm) => !carriesUnsubstitutedGeneric(checker, arm));
3408
+ if (classes.length === 0)
3409
+ continue;
3410
+ const declaredArms = site.stated.isUnion() ? site.stated.types : [site.stated];
3411
+ const absence = widened ? [checker.getUndefinedType()] : [];
3412
+ recordHomeArms.set(site.parameter, withDeclaredAbsenceArms(site.parameter, [...declaredArms, ...classes, ...absence]));
3413
+ if (widened) {
3414
+ bindings.delete(site.parameter);
3415
+ statedBindings.delete(site.parameter);
3416
+ }
3417
+ if (process.env['GEA_BINDING_DEBUG'])
3418
+ console.error(`[CLASS-INSTANCE] ${describeParameter(site.parameter)} :: ${classes.map((arm) => checker.typeToString(arm)).join(' | ')}`);
3419
+ }
3420
+ // A record a subclass redeclared a field as, handed to its base's
3421
+ // constructor -- see `override-field-arms.ts`'s `overrideRecordStatementOf`.
3422
+ // The same one-more-arm rule as the class instance above, on the same terms.
3423
+ const overrideArms = overrideFieldArmsOf(checker, files);
3424
+ for (const site of overrideArms.chainClasses.size === 0 ? [] : index.overrideRecordSites) {
3425
+ if (bindings.has(site.parameter) || unionArms.has(site.parameter) || recordHomeArms.has(site.parameter))
3426
+ continue;
3427
+ if (!ts.isIdentifier(site.parameter.name))
3428
+ continue;
3429
+ const symbol = checker.getSymbolAtLocation(site.parameter.name);
3430
+ if (!symbol || index.assigned.has(symbol))
3431
+ continue;
3432
+ const records = (overrideArms.parameterArms.get(site.parameter) ?? []).filter((arm) => !carriesUnsubstitutedGeneric(checker, arm));
3433
+ if (records.length === 0)
3434
+ continue;
3435
+ const declaredArms = site.stated.isUnion() ? site.stated.types : [site.stated];
3436
+ recordHomeArms.set(site.parameter, withDeclaredAbsenceArms(site.parameter, [...declaredArms, ...records]));
3437
+ if (process.env['GEA_BINDING_DEBUG'])
3438
+ console.error(`[OVERRIDE-RECORD] ${describeParameter(site.parameter)} :: ${records.map((arm) => checker.typeToString(arm)).join(' | ')}`);
3439
+ }
3440
+ // ONE STATED PARAMETER PER COPY.
3441
+ //
3442
+ // Everything above answers per DECLARATION, and holds every caller to one
3443
+ // agreed type. A generic body is not one body: monomorphization gives it one
3444
+ // copy per instantiation (`specialization.ts`), each with its own frame, so
3445
+ // "what does this parameter receive" is a question about the callers of ONE
3446
+ // copy. mongodb's `shuffle<T>(sequence: Iterable<T>)` is called with a
3447
+ // `Set<string>`, a `HostAddress[]` and a `ServerDescription[]`: across the
3448
+ // declaration those disagree and no single carrier holds all three, but each
3449
+ // copy is called with exactly one of them. Refused per declaration, every
3450
+ // copy's slot stayed the `Iterable` protocol's record, which no concrete
3451
+ // collection converts into without a copy -- three certification refusals.
3452
+ //
3453
+ // Asked only where the declaration-wide answer refused, of the same evidence
3454
+ // under the same statement tests, restricted to the calls that reach each
3455
+ // copy. A copy whose own callers disagree keeps the refusal, exactly as the
3456
+ // declaration did. The partition has to be COMPLETE: a call the census cannot
3457
+ // place in a copy from the root scope -- one written inside another generic
3458
+ // body, whose copy depends on which copy of THAT body is asking -- could
3459
+ // reach any of them, so one such call withholds every copy of the parameter.
3460
+ const copyBindings = new Map();
3461
+ if (specializations) {
3462
+ propagating.reset();
3463
+ for (const candidate of notReassigned) {
3464
+ const { declaration, parameter } = candidate;
3465
+ if (!candidate.stated || bindings.has(parameter) || unionArms.has(parameter) || flowCarrierArms.has(parameter))
3466
+ continue;
3467
+ if (!specializations.isGeneric(declaration))
3468
+ continue;
3469
+ const copies = specializations.specializationsOf(declaration);
3470
+ if (copies.length < 2)
3471
+ continue;
3472
+ if (escapeReason(declaration) !== null || (contractsFor(declaration)?.length ?? 0) > 0)
3473
+ continue;
3474
+ const calls = callsByDeclaration.get(declaration) ?? [];
3475
+ const callsByCopy = new Map();
3476
+ let complete = calls.length > 0;
3477
+ for (const call of calls) {
3478
+ const site = specializations.specializationAt(call);
3479
+ if (!site || site.declaration !== declaration) {
3480
+ complete = false;
3481
+ break;
3482
+ }
3483
+ const group = callsByCopy.get(site.ordinal);
3484
+ if (group)
3485
+ group.push(call);
3486
+ else
3487
+ callsByCopy.set(site.ordinal, [call]);
3488
+ }
3489
+ if (!complete)
3490
+ continue;
3491
+ const perCopy = new Map();
3492
+ const requirements = [];
3493
+ for (const [ordinal, copyCalls] of callsByCopy) {
3494
+ const bindCopy = () => {
3495
+ const answer = agreedArgumentType(declaration, parameter, candidate.index, false, copyCalls);
3496
+ if (!('type' in answer) || answer.sawSilentSite || answer.deferredRecursiveArguments.length > 0)
3497
+ return null;
3498
+ if (carriesUnsubstitutedGeneric(checker, answer.type))
3499
+ return null;
3500
+ const stated = instantiatedStatement(declaration, parameter, candidate.index, candidate.stated, copyCalls);
3501
+ if (stated === null || !checker.isTypeAssignableTo(answer.type, stated))
3502
+ return null;
3503
+ if (!narrowsStatement(checker, parameter, stated, answer.type))
3504
+ return null;
3505
+ return withDeclaredAbsence(parameter, answer.type);
3506
+ };
3507
+ const captured = protocolLedger?.capture(bindCopy) ?? { value: bindCopy(), requirements: [] };
3508
+ if (captured.value === null)
3509
+ continue;
3510
+ perCopy.set(ordinal, captured.value);
3511
+ requirements.push(...captured.requirements);
3512
+ }
3513
+ if (perCopy.size === 0)
3514
+ continue;
3515
+ copyBindings.set(parameter, perCopy);
3516
+ protocolRequirements.set(parameter, requirements);
3517
+ // The declaration-wide refusal stands for any copy still unbound.
3518
+ if (perCopy.size === copies.length)
3519
+ lastRefusal.delete(parameter);
3520
+ if (process.env['GEA_BINDING_DEBUG'])
3521
+ for (const [ordinal, type] of perCopy)
3522
+ console.error(`[COPY-BINDING] ${describeParameter(parameter)} #${ordinal} :: ${checker.typeToString(type)}`);
3523
+ }
3524
+ }
2904
3525
  for (const [parameter, reason] of lastRefusal)
2905
3526
  refuse(reason, describeParameter(parameter));
2906
3527
  /**
@@ -2929,6 +3550,47 @@ valueFlow = index.valueFlow) => {
2929
3550
  return narrowed;
2930
3551
  return withoutUndefinedMember(checker, narrowed);
2931
3552
  };
3553
+ /**
3554
+ * A READ of a narrowed parameter keeps the absence the checker's own flow
3555
+ * analysis already removed there. `responseType ? new responseType(b) : u`
3556
+ * reads the cell inside a truthiness guard: the checker types that read
3557
+ * without `undefined`, and handing it the whole `typeof Reply | undefined`
3558
+ * binding instead made the construction's callee an `optional` with no
3559
+ * construct path. Only the absence members are taken from the checker --
3560
+ * everything else the read holds is still the census's answer.
3561
+ */
3562
+ const withReadAbsenceOf = (read, parameter, bound) => {
3563
+ if (!bound.isUnion())
3564
+ return bound;
3565
+ const checked = checker.getTypeAtLocation(read);
3566
+ if ((checked.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0)
3567
+ return bound;
3568
+ const flagsOf = (type) => (type.isUnion() ? type.types : [type]).reduce((flags, part) => flags | part.flags, 0);
3569
+ const present = flagsOf(checked);
3570
+ // The checker's read lacks an absence only as evidence that its flow ruled
3571
+ // it out when the parameter's own declaration admits it. A binding that
3572
+ // ADDS an absence the statement never spelled -- `omitted-stated-
3573
+ // parameter.ts`'s `@param {boolean} premultipliedAlpha` that
3574
+ // `colorBuffer.setClear( 0, 0, 0, 1 )` leaves out -- reads as `boolean` at
3575
+ // every mention, so stripping on that basis undid the widening at each
3576
+ // read: three's `premultipliedAlpha === true` converted the omitted
3577
+ // argument to a bare boolean and threw where the language answers false.
3578
+ const declared = flagsOf(checker.getTypeAtLocation(parameter));
3579
+ const dropped = (ts.TypeFlags.Undefined | ts.TypeFlags.Null) & ~present & declared;
3580
+ // A narrowed `BufferSource` read under `ArrayBuffer.isView(data)` is an
3581
+ // `ArrayBufferView` to the checker: the arms its flow ruled out are the
3582
+ // callers' arms not assignable to what it reads there.
3583
+ const viewRead = (checked.isUnion() ? checked.types : [checked]).some(isLibArrayBufferViewType);
3584
+ if (dropped === 0 && !viewRead)
3585
+ return bound;
3586
+ const kept = bound.types.filter((part) => (part.flags & dropped) === 0 && (!viewRead || (part.flags & ts.TypeFlags.Object) === 0 || checker.isTypeAssignableTo(part, checked)));
3587
+ if (kept.length === bound.types.length || kept.length === 0)
3588
+ return bound;
3589
+ if (kept.length === 1 && kept[0] !== undefined)
3590
+ return kept[0];
3591
+ const constructing = checker;
3592
+ return typeof constructing.getUnionType === 'function' ? constructing.getUnionType(kept) : bound;
3593
+ };
2932
3594
  // Publication reads a settled binding set, so its memo is built once, after
2933
3595
  // the fixpoint stops -- unlike the propagating one, which is thrown away
2934
3596
  // each round because the answers it caches are answers to a smaller view.
@@ -2985,11 +3647,58 @@ valueFlow = index.valueFlow) => {
2985
3647
  if (!ts.isParameter(declaration))
2986
3648
  continue;
2987
3649
  const narrowed = statedBindings.get(declaration);
2988
- if (narrowed)
2989
- return bodyBindingOf(declaration, narrowed);
3650
+ if (!narrowed)
3651
+ continue;
3652
+ if (guardNarrowsDynamicBinding(node, narrowed))
3653
+ return null;
3654
+ return withReadAbsenceOf(node, declaration, bodyBindingOf(declaration, narrowed));
2990
3655
  }
2991
3656
  return null;
2992
3657
  };
3658
+ /**
3659
+ * A read inside a guard over a cell whose callers all handed it a dynamic
3660
+ * value: `function touch(value: unknown)` called with `held[0]` binds
3661
+ * `unknown`, and `if (value instanceof Date) value.setUTCFullYear(...)` reads
3662
+ * the cell where the checker has proved it holds a Date. The binding states
3663
+ * nothing about that read -- `unknown` is the cell's storage, not a claim
3664
+ * about what a guard found in it -- so answering the binding there kept the
3665
+ * branch on the box and turned every member access into a dynamic `[[Get]]`
3666
+ * on it. The checker's narrowing is the read's type, exactly as for a
3667
+ * parameter DECLARED `any`, which this census never binds; the narrowed
3668
+ * read then converts out of the dynamic cell once, at the read. A dead
3669
+ * branch (`never`) and an unnarrowed read keep the binding.
3670
+ */
3671
+ const guardNarrowsDynamicBinding = (read, bound) => {
3672
+ if ((bound.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) === 0)
3673
+ return false;
3674
+ const flow = checker.getTypeAtLocation(read);
3675
+ return (flow.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never)) === 0;
3676
+ };
3677
+ /** The copy-bound parameter a node is, or reads -- memoized, since every node of every copy asks. */
3678
+ const copyParameters = new Map();
3679
+ const copyParameterOf = (node) => {
3680
+ if (ts.isParameter(node))
3681
+ return copyBindings.has(node) ? node : null;
3682
+ if (!ts.isIdentifier(node))
3683
+ return null;
3684
+ const remembered = copyParameters.get(node);
3685
+ if (remembered !== undefined)
3686
+ return remembered;
3687
+ const parameter = checker.getSymbolAtLocation(node)?.declarations?.find(ts.isParameter) ?? null;
3688
+ const answer = parameter && copyBindings.has(parameter) ? parameter : null;
3689
+ copyParameters.set(node, answer);
3690
+ return answer;
3691
+ };
3692
+ const copyTypeAt = (node, ordinalOf) => {
3693
+ const parameter = copyParameterOf(node);
3694
+ if (!parameter)
3695
+ return null;
3696
+ const ordinal = ordinalOf(parameter.parent);
3697
+ const narrowed = ordinal === null ? undefined : copyBindings.get(parameter)?.get(ordinal);
3698
+ if (!narrowed)
3699
+ return null;
3700
+ return node === parameter || !ts.isIdentifier(node) ? narrowed : withReadAbsenceOf(node, parameter, bodyBindingOf(parameter, narrowed));
3701
+ };
2993
3702
  // Implicit slots have an owning signature but no parameter declaration.
2994
3703
  // Reuse the settled call attribution and resolver; never start a second
2995
3704
  // call-site inventory or infer from only the successfully typed callers.
@@ -3260,6 +3969,7 @@ valueFlow = index.valueFlow) => {
3260
3969
  publishing.resolve(element);
3261
3970
  return patternReadTypes.get(element) ?? null;
3262
3971
  },
3972
+ ...(copyBindings.size === 0 ? {} : { copyTypeAt }),
3263
3973
  statedTypeAt: (node) => {
3264
3974
  // Memoized, and safe to memoize only HERE: this is the published view,
3265
3975
  // returned after the fixpoint has stopped, so `statedBindings` and
@@ -3286,7 +3996,7 @@ valueFlow = index.valueFlow) => {
3286
3996
  const declaration = ts.isParameter(node)
3287
3997
  ? node
3288
3998
  : ts.isIdentifier(node)
3289
- ? checker.getSymbolAtLocation(node)?.declarations?.find(ts.isParameter)
3999
+ ? valueSymbolAt(checker, node, hostProvided)?.declarations?.find(ts.isParameter)
3290
4000
  : undefined;
3291
4001
  if (declaration) {
3292
4002
  const arms = flowCarrierArms.get(declaration);
@@ -3304,12 +4014,22 @@ valueFlow = index.valueFlow) => {
3304
4014
  const present = checker.getNonNullableType(read);
3305
4015
  if (checker.isTypeAssignableTo(present, upper) && checker.isTypeAssignableTo(upper, present))
3306
4016
  return arms;
3307
- return null;
4017
+ return ts.isIdentifier(node) ? flowCarrierArmsOf(node, declaration) : null;
3308
4018
  }
3309
4019
  }
4020
+ const recordArms = declaration ? recordHomeArms.get(declaration) : undefined;
4021
+ if (recordArms)
4022
+ return ts.isParameter(node) ? recordArms : recordHomeArmsAtRead(checker, recordArms, checker.getTypeAtLocation(node));
4023
+ // A stated-union read the checker's flow narrowed to one arm is typed
4024
+ // as that arm (`flowArmOf`), not as the cell's whole union: a one-arm
4025
+ // list, which `structural.ts`'s `parameter-union-arms` rule publishes
4026
+ // as the arm itself.
4027
+ const flowArm = declaration && ts.isIdentifier(node) ? flowArmOf(node, declaration) : null;
4028
+ if (flowArm !== null)
4029
+ return [flowArm];
3310
4030
  return synthesizedUnionArmsAt(checker, node, unionArms);
3311
4031
  },
3312
- boundCount: bindings.size + unionArms.size + flowCarrierArms.size + implicitTuples.size,
4032
+ boundCount: bindings.size + unionArms.size + flowCarrierArms.size + recordHomeArms.size + implicitTuples.size,
3313
4033
  refusals,
3314
4034
  refusalOf: (parameter) => lastRefusal.get(parameter) ?? null,
3315
4035
  debugReport: () => {
@@ -3337,3 +4057,29 @@ valueFlow = index.valueFlow) => {
3337
4057
  }
3338
4058
  };
3339
4059
  };
4060
+ /**
4061
+ * The census as ONE COPY of a generic body sees it: `typeAt` and
4062
+ * `statedTypeAt` answer a copy-bound parameter (`copyTypeAt`) with what that
4063
+ * copy's own callers pass, and everything else exactly as the program-wide
4064
+ * census does. `path` is the copy chain the asking view is inside, innermost
4065
+ * last; the root scope, and a census that bound no copy, get the census back
4066
+ * unchanged.
4067
+ */
4068
+ export const parameterCensusForCopy = (census, path) => {
4069
+ const copyTypeAt = census.copyTypeAt;
4070
+ if (!copyTypeAt || path.length === 0)
4071
+ return census;
4072
+ const ordinalOf = (owner) => {
4073
+ for (let index = path.length - 1; index >= 0; index -= 1) {
4074
+ const step = path[index];
4075
+ if (step && step.owner === owner)
4076
+ return step.ordinal;
4077
+ }
4078
+ return null;
4079
+ };
4080
+ return {
4081
+ ...census,
4082
+ typeAt: (node) => (ts.isParameter(node) ? copyTypeAt(node, ordinalOf) : null) ?? census.typeAt(node),
4083
+ statedTypeAt: (node) => copyTypeAt(node, ordinalOf) ?? census.statedTypeAt(node)
4084
+ };
4085
+ };