@scriptc/compiler 0.4.1 → 0.4.2

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 (680) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +582 -78
  2. package/dist/backend/cycle-analysis.d.ts +2 -1
  3. package/dist/backend/cycle-analysis.js +4 -4
  4. package/dist/backend/cycle-analysis.js.map +1 -1
  5. package/dist/backend/cycle-mutability.d.ts +2 -1
  6. package/dist/backend/cycle-mutability.js +2 -2
  7. package/dist/backend/cycle-mutability.js.map +1 -1
  8. package/dist/backend/executable-features.js +4 -1
  9. package/dist/backend/executable-features.js.map +1 -1
  10. package/dist/backend/immutability.d.ts +2 -1
  11. package/dist/backend/immutability.js +2 -2
  12. package/dist/backend/immutability.js.map +1 -1
  13. package/dist/backend/library-pack.js +4 -0
  14. package/dist/backend/library-pack.js.map +1 -1
  15. package/dist/backend/llvm/alloc.d.ts +7 -3
  16. package/dist/backend/llvm/alloc.js +7 -4
  17. package/dist/backend/llvm/alloc.js.map +1 -1
  18. package/dist/backend/llvm/array-search.js +2 -1
  19. package/dist/backend/llvm/array-search.js.map +1 -1
  20. package/dist/backend/llvm/bytes-loop-versions.d.ts +23 -2
  21. package/dist/backend/llvm/bytes-loop-versions.js +115 -19
  22. package/dist/backend/llvm/bytes-loop-versions.js.map +1 -1
  23. package/dist/backend/llvm/bytes-loop-versions.test.js +131 -0
  24. package/dist/backend/llvm/bytes-loop-versions.test.js.map +1 -1
  25. package/dist/backend/llvm/classes.d.ts +72 -1
  26. package/dist/backend/llvm/classes.js +331 -45
  27. package/dist/backend/llvm/classes.js.map +1 -1
  28. package/dist/backend/llvm/classes.test.js +223 -16
  29. package/dist/backend/llvm/classes.test.js.map +1 -1
  30. package/dist/backend/llvm/common.d.ts +1 -3
  31. package/dist/backend/llvm/common.js +1 -3
  32. package/dist/backend/llvm/common.js.map +1 -1
  33. package/dist/backend/llvm/constant-callbacks.js +8 -4
  34. package/dist/backend/llvm/constant-callbacks.js.map +1 -1
  35. package/dist/backend/llvm/constant-callbacks.test.js +4 -4
  36. package/dist/backend/llvm/constant-callbacks.test.js.map +1 -1
  37. package/dist/backend/llvm/counted-loops.d.ts +4 -1
  38. package/dist/backend/llvm/counted-loops.js +62 -23
  39. package/dist/backend/llvm/counted-loops.js.map +1 -1
  40. package/dist/backend/llvm/dense-array-loops.d.ts +19 -16
  41. package/dist/backend/llvm/dense-array-loops.js +46 -10
  42. package/dist/backend/llvm/dense-array-loops.js.map +1 -1
  43. package/dist/backend/llvm/dense-array-loops.test.js +50 -14
  44. package/dist/backend/llvm/dense-array-loops.test.js.map +1 -1
  45. package/dist/backend/llvm/dyn.d.ts +25 -1
  46. package/dist/backend/llvm/dyn.js +331 -8
  47. package/dist/backend/llvm/dyn.js.map +1 -1
  48. package/dist/backend/llvm/emit-function.js +22 -6
  49. package/dist/backend/llvm/emit-function.js.map +1 -1
  50. package/dist/backend/llvm/emit-module.js +17 -11
  51. package/dist/backend/llvm/emit-module.js.map +1 -1
  52. package/dist/backend/llvm/emit-statements.d.ts +0 -23
  53. package/dist/backend/llvm/emit-statements.js +325 -25
  54. package/dist/backend/llvm/emit-statements.js.map +1 -1
  55. package/dist/backend/llvm/emitter.d.ts +141 -15
  56. package/dist/backend/llvm/emitter.js +537 -64
  57. package/dist/backend/llvm/emitter.js.map +1 -1
  58. package/dist/backend/llvm/expr-async.js +19 -0
  59. package/dist/backend/llvm/expr-async.js.map +1 -1
  60. package/dist/backend/llvm/expr-bytes.d.ts +5 -2
  61. package/dist/backend/llvm/expr-bytes.js +110 -40
  62. package/dist/backend/llvm/expr-bytes.js.map +1 -1
  63. package/dist/backend/llvm/expr-calls.d.ts +1 -1
  64. package/dist/backend/llvm/expr-calls.js +34 -22
  65. package/dist/backend/llvm/expr-calls.js.map +1 -1
  66. package/dist/backend/llvm/expr-containers.js +21 -5
  67. package/dist/backend/llvm/expr-containers.js.map +1 -1
  68. package/dist/backend/llvm/expr-control.js +2 -3
  69. package/dist/backend/llvm/expr-control.js.map +1 -1
  70. package/dist/backend/llvm/expr-dynamic.js +54 -6
  71. package/dist/backend/llvm/expr-dynamic.js.map +1 -1
  72. package/dist/backend/llvm/expr-primitives.js +26 -8
  73. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  74. package/dist/backend/llvm/expr-stream-bridges.js +38 -6
  75. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  76. package/dist/backend/llvm/expr-stream-callbacks.js +131 -35
  77. package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
  78. package/dist/backend/llvm/lib-dispatch.js +10 -0
  79. package/dist/backend/llvm/lib-dispatch.js.map +1 -1
  80. package/dist/backend/llvm/lib-filesystem.js +61 -0
  81. package/dist/backend/llvm/lib-filesystem.js.map +1 -1
  82. package/dist/backend/llvm/lib-http2.d.ts +4 -0
  83. package/dist/backend/llvm/lib-http2.js +20 -17
  84. package/dist/backend/llvm/lib-http2.js.map +1 -1
  85. package/dist/backend/llvm/lib-process.js +65 -14
  86. package/dist/backend/llvm/lib-process.js.map +1 -1
  87. package/dist/backend/llvm/lib-shared.js +53 -1
  88. package/dist/backend/llvm/lib-shared.js.map +1 -1
  89. package/dist/backend/llvm/lib-stream.js +65 -28
  90. package/dist/backend/llvm/lib-stream.js.map +1 -1
  91. package/dist/backend/llvm/lib-tls.js +23 -0
  92. package/dist/backend/llvm/lib-tls.js.map +1 -1
  93. package/dist/backend/llvm/local-array-reads.js +66 -45
  94. package/dist/backend/llvm/local-array-reads.js.map +1 -1
  95. package/dist/backend/llvm/local-array-reads.test.js +14 -0
  96. package/dist/backend/llvm/local-array-reads.test.js.map +1 -1
  97. package/dist/backend/llvm/publish.d.ts +8 -1
  98. package/dist/backend/llvm/publish.js +64 -25
  99. package/dist/backend/llvm/publish.js.map +1 -1
  100. package/dist/backend/llvm/publish.test.js +3 -0
  101. package/dist/backend/llvm/publish.test.js.map +1 -1
  102. package/dist/backend/llvm/receivers.js +1 -1
  103. package/dist/backend/llvm/receivers.js.map +1 -1
  104. package/dist/backend/llvm/reference-writes.js +2 -0
  105. package/dist/backend/llvm/reference-writes.js.map +1 -1
  106. package/dist/backend/llvm/regex-matchers.js +161 -14
  107. package/dist/backend/llvm/regex-matchers.js.map +1 -1
  108. package/dist/backend/llvm/regex-matchers.test.js +18 -0
  109. package/dist/backend/llvm/regex-matchers.test.js.map +1 -1
  110. package/dist/backend/llvm/shapes.d.ts +9 -7
  111. package/dist/backend/llvm/shapes.js +12 -10
  112. package/dist/backend/llvm/shapes.js.map +1 -1
  113. package/dist/backend/llvm/string-lifetimes.test.js +2 -1
  114. package/dist/backend/llvm/string-lifetimes.test.js.map +1 -1
  115. package/dist/backend/llvm/string-reads.d.ts +3 -0
  116. package/dist/backend/llvm/string-reads.js +84 -0
  117. package/dist/backend/llvm/string-reads.js.map +1 -1
  118. package/dist/backend/llvm/wasm-modules.d.ts +6 -5
  119. package/dist/backend/llvm/wasm-modules.js +32 -9
  120. package/dist/backend/llvm/wasm-modules.js.map +1 -1
  121. package/dist/backend/mangle.d.ts +3 -0
  122. package/dist/backend/mangle.js +5 -0
  123. package/dist/backend/mangle.js.map +1 -1
  124. package/dist/backend/native/contracts.d.ts +22 -4
  125. package/dist/backend/native/executable.js +24 -8
  126. package/dist/backend/native/executable.js.map +1 -1
  127. package/dist/backend/native/library.js +1 -0
  128. package/dist/backend/native/library.js.map +1 -1
  129. package/dist/backend/native-codegen.d.ts +11 -6
  130. package/dist/backend/native-codegen.js +36 -9
  131. package/dist/backend/native-codegen.js.map +1 -1
  132. package/dist/backend/native-codegen.test.js +0 -23
  133. package/dist/backend/native-codegen.test.js.map +1 -1
  134. package/dist/backend/native-link-info-core.d.ts +14 -4
  135. package/dist/backend/native-link-info-core.js.map +1 -1
  136. package/dist/backend/optimization.d.ts +2 -2
  137. package/dist/backend/runtime-abi.d.ts +2 -2
  138. package/dist/backend/runtime-abi.js +2 -2
  139. package/dist/backend/runtime-pack-core.d.ts +1 -1
  140. package/dist/backend/runtime-pack-core.js +1 -1
  141. package/dist/backend/runtime-pack-core.js.map +1 -1
  142. package/dist/backend/runtime-pack-targets.test.js +4 -1
  143. package/dist/backend/runtime-pack-targets.test.js.map +1 -1
  144. package/dist/backend/runtime-pack.d.ts +0 -21
  145. package/dist/backend/runtime-pack.js +0 -29
  146. package/dist/backend/runtime-pack.js.map +1 -1
  147. package/dist/backend/runtime-pack.test.js +9 -69
  148. package/dist/backend/runtime-pack.test.js.map +1 -1
  149. package/dist/backend/target-diagnostics.js +31 -1
  150. package/dist/backend/target-diagnostics.js.map +1 -1
  151. package/dist/backend/warm-cache.js +3 -0
  152. package/dist/backend/warm-cache.js.map +1 -1
  153. package/dist/cli/command.js +26 -6
  154. package/dist/cli/command.js.map +1 -1
  155. package/dist/cli/usage.d.ts +5 -1
  156. package/dist/cli/usage.js +7 -2
  157. package/dist/cli/usage.js.map +1 -1
  158. package/dist/contracts/check.js +1 -1
  159. package/dist/contracts/check.js.map +1 -1
  160. package/dist/coverage/report.d.ts +7 -2
  161. package/dist/coverage/report.js +18 -0
  162. package/dist/coverage/report.js.map +1 -1
  163. package/dist/coverage/verdict-cache.d.ts +1 -0
  164. package/dist/coverage/verdict-cache.js +4 -0
  165. package/dist/coverage/verdict-cache.js.map +1 -1
  166. package/dist/coverage/verdict-semantic.js +4 -0
  167. package/dist/coverage/verdict-semantic.js.map +1 -1
  168. package/dist/diagnostics/diagnostic.js.map +1 -1
  169. package/dist/diagnostics/dynamic-tier.d.ts +40 -0
  170. package/dist/diagnostics/dynamic-tier.js +57 -0
  171. package/dist/diagnostics/dynamic-tier.js.map +1 -0
  172. package/dist/diagnostics/envelope.d.ts +2 -1
  173. package/dist/diagnostics/envelope.js +5 -2
  174. package/dist/diagnostics/envelope.js.map +1 -1
  175. package/dist/executable/executable-cache.d.ts +23 -1
  176. package/dist/executable/executable-cache.js +59 -7
  177. package/dist/executable/executable-cache.js.map +1 -1
  178. package/dist/executable/executable-cache.test.js +45 -3
  179. package/dist/executable/executable-cache.test.js.map +1 -1
  180. package/dist/executable/prepare.js +3 -1
  181. package/dist/executable/prepare.js.map +1 -1
  182. package/dist/frontend/analysis.js +1 -0
  183. package/dist/frontend/analysis.js.map +1 -1
  184. package/dist/frontend/dispose-hook.d.ts +2 -0
  185. package/dist/frontend/dispose-hook.js +14 -0
  186. package/dist/frontend/dispose-hook.js.map +1 -0
  187. package/dist/frontend/jsx-entities.d.ts +4 -0
  188. package/dist/frontend/jsx-entities.js +259 -0
  189. package/dist/frontend/jsx-entities.js.map +1 -0
  190. package/dist/frontend/jsx-source.d.ts +71 -0
  191. package/dist/frontend/jsx-source.js +781 -0
  192. package/dist/frontend/jsx-source.js.map +1 -0
  193. package/dist/frontend/jsx-source.test.d.ts +1 -0
  194. package/dist/frontend/jsx-source.test.js +200 -0
  195. package/dist/frontend/jsx-source.test.js.map +1 -0
  196. package/dist/frontend/literal-values.test.js +8 -9
  197. package/dist/frontend/literal-values.test.js.map +1 -1
  198. package/dist/frontend/lowering/array-indexed-mutation.js +2 -1
  199. package/dist/frontend/lowering/array-indexed-mutation.js.map +1 -1
  200. package/dist/frontend/lowering/array-values.js +3 -2
  201. package/dist/frontend/lowering/array-values.js.map +1 -1
  202. package/dist/frontend/lowering/binding-analysis.d.ts +1 -1
  203. package/dist/frontend/lowering/binding-analysis.js +2 -2
  204. package/dist/frontend/lowering/binding-analysis.js.map +1 -1
  205. package/dist/frontend/lowering/builtins/arguments.d.ts +3 -0
  206. package/dist/frontend/lowering/builtins/arguments.js +30 -15
  207. package/dist/frontend/lowering/builtins/arguments.js.map +1 -1
  208. package/dist/frontend/lowering/builtins/atomics.js +10 -6
  209. package/dist/frontend/lowering/builtins/atomics.js.map +1 -1
  210. package/dist/frontend/lowering/builtins/child-process-async.js +2 -1
  211. package/dist/frontend/lowering/builtins/child-process-async.js.map +1 -1
  212. package/dist/frontend/lowering/builtins/child-process-sync.js +2 -1
  213. package/dist/frontend/lowering/builtins/child-process-sync.js.map +1 -1
  214. package/dist/frontend/lowering/builtins/crypto.d.ts +4 -2
  215. package/dist/frontend/lowering/builtins/crypto.js +59 -3
  216. package/dist/frontend/lowering/builtins/crypto.js.map +1 -1
  217. package/dist/frontend/lowering/builtins/date-classes.d.ts +46 -0
  218. package/dist/frontend/lowering/builtins/date-classes.js +477 -0
  219. package/dist/frontend/lowering/builtins/date-classes.js.map +1 -0
  220. package/dist/frontend/lowering/builtins/dates.d.ts +11 -1
  221. package/dist/frontend/lowering/builtins/dates.js +55 -26
  222. package/dist/frontend/lowering/builtins/dates.js.map +1 -1
  223. package/dist/frontend/lowering/builtins/dh.d.ts +15 -0
  224. package/dist/frontend/lowering/builtins/dh.js +151 -0
  225. package/dist/frontend/lowering/builtins/dh.js.map +1 -0
  226. package/dist/frontend/lowering/builtins/disposable-stack.js +2 -1
  227. package/dist/frontend/lowering/builtins/disposable-stack.js.map +1 -1
  228. package/dist/frontend/lowering/builtins/ecdh.d.ts +12 -1
  229. package/dist/frontend/lowering/builtins/ecdh.js +7 -7
  230. package/dist/frontend/lowering/builtins/ecdh.js.map +1 -1
  231. package/dist/frontend/lowering/builtins/errors.d.ts +15 -0
  232. package/dist/frontend/lowering/builtins/errors.js +110 -0
  233. package/dist/frontend/lowering/builtins/errors.js.map +1 -1
  234. package/dist/frontend/lowering/builtins/filesystem-calls.d.ts +1 -1
  235. package/dist/frontend/lowering/builtins/filesystem-calls.js +23 -17
  236. package/dist/frontend/lowering/builtins/filesystem-calls.js.map +1 -1
  237. package/dist/frontend/lowering/builtins/filesystem.js +6 -4
  238. package/dist/frontend/lowering/builtins/filesystem.js.map +1 -1
  239. package/dist/frontend/lowering/builtins/fs-paths.d.ts +15 -0
  240. package/dist/frontend/lowering/builtins/fs-paths.js +209 -0
  241. package/dist/frontend/lowering/builtins/fs-paths.js.map +1 -0
  242. package/dist/frontend/lowering/builtins/hash-stream.d.ts +16 -4
  243. package/dist/frontend/lowering/builtins/hash-stream.js +86 -23
  244. package/dist/frontend/lowering/builtins/hash-stream.js.map +1 -1
  245. package/dist/frontend/lowering/builtins/json.js +2 -1
  246. package/dist/frontend/lowering/builtins/json.js.map +1 -1
  247. package/dist/frontend/lowering/builtins/key-object.d.ts +2 -1
  248. package/dist/frontend/lowering/builtins/key-object.js +20 -7
  249. package/dist/frontend/lowering/builtins/key-object.js.map +1 -1
  250. package/dist/frontend/lowering/builtins/module-calls.js +11 -4
  251. package/dist/frontend/lowering/builtins/module-calls.js.map +1 -1
  252. package/dist/frontend/lowering/builtins/numbers.js +9 -5
  253. package/dist/frontend/lowering/builtins/numbers.js.map +1 -1
  254. package/dist/frontend/lowering/builtins/operating-system.js +4 -3
  255. package/dist/frontend/lowering/builtins/operating-system.js.map +1 -1
  256. package/dist/frontend/lowering/builtins/performance.js +3 -2
  257. package/dist/frontend/lowering/builtins/performance.js.map +1 -1
  258. package/dist/frontend/lowering/builtins/process.js +3 -2
  259. package/dist/frontend/lowering/builtins/process.js.map +1 -1
  260. package/dist/frontend/lowering/builtins/promises.js +3 -2
  261. package/dist/frontend/lowering/builtins/promises.js.map +1 -1
  262. package/dist/frontend/lowering/builtins/promisify-callback.js +2 -1
  263. package/dist/frontend/lowering/builtins/promisify-callback.js.map +1 -1
  264. package/dist/frontend/lowering/builtins/readline.d.ts +2 -1
  265. package/dist/frontend/lowering/builtins/readline.js +23 -6
  266. package/dist/frontend/lowering/builtins/readline.js.map +1 -1
  267. package/dist/frontend/lowering/builtins/strings.js +13 -5
  268. package/dist/frontend/lowering/builtins/strings.js.map +1 -1
  269. package/dist/frontend/lowering/builtins/text-codecs.js +2 -1
  270. package/dist/frontend/lowering/builtins/text-codecs.js.map +1 -1
  271. package/dist/frontend/lowering/builtins/timers.js +1 -1
  272. package/dist/frontend/lowering/builtins/timers.js.map +1 -1
  273. package/dist/frontend/lowering/builtins/url.js +4 -3
  274. package/dist/frontend/lowering/builtins/url.js.map +1 -1
  275. package/dist/frontend/lowering/builtins/v8.js +2 -1
  276. package/dist/frontend/lowering/builtins/v8.js.map +1 -1
  277. package/dist/frontend/lowering/builtins/webcrypto.js +39 -20
  278. package/dist/frontend/lowering/builtins/webcrypto.js.map +1 -1
  279. package/dist/frontend/lowering/call-arguments.js +2 -1
  280. package/dist/frontend/lowering/call-arguments.js.map +1 -1
  281. package/dist/frontend/lowering/call-signatures.js +13 -6
  282. package/dist/frontend/lowering/call-signatures.js.map +1 -1
  283. package/dist/frontend/lowering/caught-value-dispatch.d.ts +18 -1
  284. package/dist/frontend/lowering/caught-value-dispatch.js +201 -32
  285. package/dist/frontend/lowering/caught-value-dispatch.js.map +1 -1
  286. package/dist/frontend/lowering/class-assertions.js +3 -2
  287. package/dist/frontend/lowering/class-assertions.js.map +1 -1
  288. package/dist/frontend/lowering/class-construction.d.ts +2 -1
  289. package/dist/frontend/lowering/class-construction.js +8 -13
  290. package/dist/frontend/lowering/class-construction.js.map +1 -1
  291. package/dist/frontend/lowering/class-descriptors.js +1 -1
  292. package/dist/frontend/lowering/class-descriptors.js.map +1 -1
  293. package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +34 -0
  294. package/dist/frontend/lowering/class-dynamic-dispatch.js +568 -151
  295. package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
  296. package/dist/frontend/lowering/class-dynamic-dispatch.test.js +77 -0
  297. package/dist/frontend/lowering/class-dynamic-dispatch.test.js.map +1 -1
  298. package/dist/frontend/lowering/class-method-mutations.js +3 -0
  299. package/dist/frontend/lowering/class-method-mutations.js.map +1 -1
  300. package/dist/frontend/lowering/class-method-values.js +1 -1
  301. package/dist/frontend/lowering/class-method-values.js.map +1 -1
  302. package/dist/frontend/lowering/class-protocols.d.ts +7 -0
  303. package/dist/frontend/lowering/class-protocols.js +64 -4
  304. package/dist/frontend/lowering/class-protocols.js.map +1 -1
  305. package/dist/frontend/lowering/class-prototypes.d.ts +5 -0
  306. package/dist/frontend/lowering/class-prototypes.js +36 -3
  307. package/dist/frontend/lowering/class-prototypes.js.map +1 -1
  308. package/dist/frontend/lowering/class-to-primitive.js +25 -5
  309. package/dist/frontend/lowering/class-to-primitive.js.map +1 -1
  310. package/dist/frontend/lowering/class-unions.js +2 -1
  311. package/dist/frontend/lowering/class-unions.js.map +1 -1
  312. package/dist/frontend/lowering/coercions/function-adapters.js +6 -5
  313. package/dist/frontend/lowering/coercions/function-adapters.js.map +1 -1
  314. package/dist/frontend/lowering/coercions/structural.js +8 -7
  315. package/dist/frontend/lowering/coercions/structural.js.map +1 -1
  316. package/dist/frontend/lowering/coercions/unions.js +8 -7
  317. package/dist/frontend/lowering/coercions/unions.js.map +1 -1
  318. package/dist/frontend/lowering/collection-ingestion.js +2 -1
  319. package/dist/frontend/lowering/collection-ingestion.js.map +1 -1
  320. package/dist/frontend/lowering/containers/array-callbacks.d.ts +7 -0
  321. package/dist/frontend/lowering/containers/array-callbacks.js +14 -13
  322. package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
  323. package/dist/frontend/lowering/containers/array-concat.js +2 -1
  324. package/dist/frontend/lowering/containers/array-concat.js.map +1 -1
  325. package/dist/frontend/lowering/containers/array-construction.js +25 -4
  326. package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
  327. package/dist/frontend/lowering/containers/array-methods.js +6 -5
  328. package/dist/frontend/lowering/containers/array-methods.js.map +1 -1
  329. package/dist/frontend/lowering/containers/array-pipelines.js +2 -1
  330. package/dist/frontend/lowering/containers/array-pipelines.js.map +1 -1
  331. package/dist/frontend/lowering/containers/bytes.d.ts +1 -1
  332. package/dist/frontend/lowering/containers/bytes.js +129 -28
  333. package/dist/frontend/lowering/containers/bytes.js.map +1 -1
  334. package/dist/frontend/lowering/containers/callback-arguments.js +52 -2
  335. package/dist/frontend/lowering/containers/callback-arguments.js.map +1 -1
  336. package/dist/frontend/lowering/containers/collection-grouping.js +3 -2
  337. package/dist/frontend/lowering/containers/collection-grouping.js.map +1 -1
  338. package/dist/frontend/lowering/containers/collection-methods.js +8 -7
  339. package/dist/frontend/lowering/containers/collection-methods.js.map +1 -1
  340. package/dist/frontend/lowering/containers/indexed-objects.js +8 -7
  341. package/dist/frontend/lowering/containers/indexed-objects.js.map +1 -1
  342. package/dist/frontend/lowering/containers/iterator-helpers.d.ts +32 -1
  343. package/dist/frontend/lowering/containers/iterator-helpers.js +6 -5
  344. package/dist/frontend/lowering/containers/iterator-helpers.js.map +1 -1
  345. package/dist/frontend/lowering/containers/string-and-regexp.js +36 -9
  346. package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
  347. package/dist/frontend/lowering/containers/string-replacement.js +2 -1
  348. package/dist/frontend/lowering/containers/string-replacement.js.map +1 -1
  349. package/dist/frontend/lowering/cycle-initialization.js +25 -4
  350. package/dist/frontend/lowering/cycle-initialization.js.map +1 -1
  351. package/dist/frontend/lowering/deferred-module-initializers.d.ts +18 -1
  352. package/dist/frontend/lowering/deferred-module-initializers.js +226 -115
  353. package/dist/frontend/lowering/deferred-module-initializers.js.map +1 -1
  354. package/dist/frontend/lowering/deferred-module-initializers.test.js +28 -0
  355. package/dist/frontend/lowering/deferred-module-initializers.test.js.map +1 -1
  356. package/dist/frontend/lowering/dispatch-sites.d.ts +59 -0
  357. package/dist/frontend/lowering/dispatch-sites.js +204 -0
  358. package/dist/frontend/lowering/dispatch-sites.js.map +1 -0
  359. package/dist/frontend/lowering/dispatch-sites.test.d.ts +1 -0
  360. package/dist/frontend/lowering/dispatch-sites.test.js +59 -0
  361. package/dist/frontend/lowering/dispatch-sites.test.js.map +1 -0
  362. package/dist/frontend/lowering/dyn-streams.d.ts +3 -0
  363. package/dist/frontend/lowering/dyn-streams.js +1 -1
  364. package/dist/frontend/lowering/dyn-streams.js.map +1 -1
  365. package/dist/frontend/lowering/dynamic-tier.d.ts +25 -0
  366. package/dist/frontend/lowering/dynamic-tier.js +327 -0
  367. package/dist/frontend/lowering/dynamic-tier.js.map +1 -0
  368. package/dist/frontend/lowering/error-methods.js +4 -0
  369. package/dist/frontend/lowering/error-methods.js.map +1 -1
  370. package/dist/frontend/lowering/expressions/array-literals.js +15 -0
  371. package/dist/frontend/lowering/expressions/array-literals.js.map +1 -1
  372. package/dist/frontend/lowering/expressions/binary.js +45 -3
  373. package/dist/frontend/lowering/expressions/binary.js.map +1 -1
  374. package/dist/frontend/lowering/expressions/element-access.js +17 -1
  375. package/dist/frontend/lowering/expressions/element-access.js.map +1 -1
  376. package/dist/frontend/lowering/expressions/identifiers.js +46 -7
  377. package/dist/frontend/lowering/expressions/identifiers.js.map +1 -1
  378. package/dist/frontend/lowering/expressions/narrowing.js +35 -5
  379. package/dist/frontend/lowering/expressions/narrowing.js.map +1 -1
  380. package/dist/frontend/lowering/expressions/object-literals.d.ts +0 -3
  381. package/dist/frontend/lowering/expressions/object-literals.js +27 -6
  382. package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
  383. package/dist/frontend/lowering/expressions/optional-chains.js +5 -5
  384. package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
  385. package/dist/frontend/lowering/expressions/property-access.d.ts +0 -4
  386. package/dist/frontend/lowering/expressions/property-access.js +99 -7
  387. package/dist/frontend/lowering/expressions/property-access.js.map +1 -1
  388. package/dist/frontend/lowering/expressions/relational.js +63 -5
  389. package/dist/frontend/lowering/expressions/relational.js.map +1 -1
  390. package/dist/frontend/lowering/expressions/updates.js +63 -9
  391. package/dist/frontend/lowering/expressions/updates.js.map +1 -1
  392. package/dist/frontend/lowering/generator-dynamic-dispatch.d.ts +6 -1
  393. package/dist/frontend/lowering/generator-dynamic-dispatch.js +20 -30
  394. package/dist/frontend/lowering/generator-dynamic-dispatch.js.map +1 -1
  395. package/dist/frontend/lowering/generic-functions.d.ts +42 -1
  396. package/dist/frontend/lowering/generic-functions.js +448 -18
  397. package/dist/frontend/lowering/generic-functions.js.map +1 -1
  398. package/dist/frontend/lowering/intern-tables.js +2 -1
  399. package/dist/frontend/lowering/intern-tables.js.map +1 -1
  400. package/dist/frontend/lowering/iterator-adapters.js +9 -8
  401. package/dist/frontend/lowering/iterator-adapters.js.map +1 -1
  402. package/dist/frontend/lowering/js-dynamic-objects.js +3 -2
  403. package/dist/frontend/lowering/js-dynamic-objects.js.map +1 -1
  404. package/dist/frontend/lowering/json-require.js +2 -1
  405. package/dist/frontend/lowering/json-require.js.map +1 -1
  406. package/dist/frontend/lowering/key-order-witness.d.ts +7 -2
  407. package/dist/frontend/lowering/key-order-witness.js +21 -4
  408. package/dist/frontend/lowering/key-order-witness.js.map +1 -1
  409. package/dist/frontend/lowering/key-order-witness.test.js +38 -2
  410. package/dist/frontend/lowering/key-order-witness.test.js.map +1 -1
  411. package/dist/frontend/lowering/lifetime-regions.js +2 -1
  412. package/dist/frontend/lowering/lifetime-regions.js.map +1 -1
  413. package/dist/frontend/lowering/lower-assert.js +6 -5
  414. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  415. package/dist/frontend/lowering/lower-async-iteration.js +3 -1
  416. package/dist/frontend/lowering/lower-async-iteration.js.map +1 -1
  417. package/dist/frontend/lowering/lower-calls.d.ts +4 -0
  418. package/dist/frontend/lowering/lower-calls.js +339 -91
  419. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  420. package/dist/frontend/lowering/lower-classes.d.ts +18 -0
  421. package/dist/frontend/lowering/lower-classes.js +280 -25
  422. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  423. package/dist/frontend/lowering/lower-dgram.js +3 -2
  424. package/dist/frontend/lowering/lower-dgram.js.map +1 -1
  425. package/dist/frontend/lowering/lower-event-emitter.d.ts +14 -0
  426. package/dist/frontend/lowering/lower-event-emitter.js +267 -20
  427. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
  428. package/dist/frontend/lowering/lower-exprs.d.ts +19 -2
  429. package/dist/frontend/lowering/lower-exprs.js +116 -11
  430. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  431. package/dist/frontend/lowering/lower-functions.js +304 -72
  432. package/dist/frontend/lowering/lower-functions.js.map +1 -1
  433. package/dist/frontend/lowering/lower-inspect.js +10 -6
  434. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  435. package/dist/frontend/lowering/lower-mixins.js +2 -1
  436. package/dist/frontend/lowering/lower-mixins.js.map +1 -1
  437. package/dist/frontend/lowering/lower-mock.js +2 -1
  438. package/dist/frontend/lowering/lower-mock.js.map +1 -1
  439. package/dist/frontend/lowering/lower-modules.js +15 -5
  440. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  441. package/dist/frontend/lowering/lower-modules.test.js +2 -2
  442. package/dist/frontend/lowering/lower-modules.test.js.map +1 -1
  443. package/dist/frontend/lowering/lower-namespaces.d.ts +2 -1
  444. package/dist/frontend/lowering/lower-namespaces.js +4 -3
  445. package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
  446. package/dist/frontend/lowering/lower-server.d.ts +10 -0
  447. package/dist/frontend/lowering/lower-server.js +237 -59
  448. package/dist/frontend/lowering/lower-server.js.map +1 -1
  449. package/dist/frontend/lowering/lower-stdlib.js +12 -10
  450. package/dist/frontend/lowering/lower-stdlib.js.map +1 -1
  451. package/dist/frontend/lowering/lower-stmts.js +168 -20
  452. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  453. package/dist/frontend/lowering/lower-stmts.test.js +1 -1
  454. package/dist/frontend/lowering/lower-stmts.test.js.map +1 -1
  455. package/dist/frontend/lowering/lower-stream.js +575 -165
  456. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  457. package/dist/frontend/lowering/lower-timers.js +4 -3
  458. package/dist/frontend/lowering/lower-timers.js.map +1 -1
  459. package/dist/frontend/lowering/lowerer.d.ts +125 -28
  460. package/dist/frontend/lowering/lowerer.js +557 -63
  461. package/dist/frontend/lowering/lowerer.js.map +1 -1
  462. package/dist/frontend/lowering/lowerer.test.js +21 -9
  463. package/dist/frontend/lowering/lowerer.test.js.map +1 -1
  464. package/dist/frontend/lowering/narrowing-stability.js +5 -0
  465. package/dist/frontend/lowering/narrowing-stability.js.map +1 -1
  466. package/dist/frontend/lowering/native-ffi.js +1 -1
  467. package/dist/frontend/lowering/native-ffi.js.map +1 -1
  468. package/dist/frontend/lowering/object-enumeration-receiver.js +2 -1
  469. package/dist/frontend/lowering/object-enumeration-receiver.js.map +1 -1
  470. package/dist/frontend/lowering/pairs-snapshot.js +2 -1
  471. package/dist/frontend/lowering/pairs-snapshot.js.map +1 -1
  472. package/dist/frontend/lowering/private-brands.d.ts +9 -0
  473. package/dist/frontend/lowering/private-brands.js +66 -15
  474. package/dist/frontend/lowering/private-brands.js.map +1 -1
  475. package/dist/frontend/lowering/promise-executor-adapter.js +2 -1
  476. package/dist/frontend/lowering/promise-executor-adapter.js.map +1 -1
  477. package/dist/frontend/lowering/require-initialization.js +2 -1
  478. package/dist/frontend/lowering/require-initialization.js.map +1 -1
  479. package/dist/frontend/lowering/runtime-optional-elements.d.ts +5 -0
  480. package/dist/frontend/lowering/runtime-optional-elements.js +17 -1
  481. package/dist/frontend/lowering/runtime-optional-elements.js.map +1 -1
  482. package/dist/frontend/lowering/runtime-optional-records.d.ts +2 -0
  483. package/dist/frontend/lowering/runtime-optional-records.js +18 -5
  484. package/dist/frontend/lowering/runtime-optional-records.js.map +1 -1
  485. package/dist/frontend/lowering/site-dependencies.d.ts +35 -0
  486. package/dist/frontend/lowering/site-dependencies.js +84 -0
  487. package/dist/frontend/lowering/site-dependencies.js.map +1 -0
  488. package/dist/frontend/lowering/site-dependencies.test.d.ts +1 -0
  489. package/dist/frontend/lowering/site-dependencies.test.js +53 -0
  490. package/dist/frontend/lowering/site-dependencies.test.js.map +1 -0
  491. package/dist/frontend/lowering/stable-names.d.ts +11 -0
  492. package/dist/frontend/lowering/stable-names.js +35 -0
  493. package/dist/frontend/lowering/stable-names.js.map +1 -0
  494. package/dist/frontend/lowering/static-typeof.d.ts +2 -2
  495. package/dist/frontend/lowering/static-typeof.js +42 -3
  496. package/dist/frontend/lowering/static-typeof.js.map +1 -1
  497. package/dist/frontend/lowering/strict-equality.js +2 -1
  498. package/dist/frontend/lowering/strict-equality.js.map +1 -1
  499. package/dist/frontend/lowering/structural-positions.d.ts +32 -0
  500. package/dist/frontend/lowering/structural-positions.js +108 -0
  501. package/dist/frontend/lowering/structural-positions.js.map +1 -0
  502. package/dist/frontend/lowering/surfaces.js +42 -26
  503. package/dist/frontend/lowering/surfaces.js.map +1 -1
  504. package/dist/frontend/lowering/var-hoisting.js +37 -3
  505. package/dist/frontend/lowering/var-hoisting.js.map +1 -1
  506. package/dist/frontend/npm-static-tsc-helpers.d.ts +5 -0
  507. package/dist/frontend/npm-static-tsc-helpers.js +106 -0
  508. package/dist/frontend/npm-static-tsc-helpers.js.map +1 -0
  509. package/dist/frontend/npm-static-tsc-helpers.test.d.ts +1 -0
  510. package/dist/frontend/npm-static-tsc-helpers.test.js +58 -0
  511. package/dist/frontend/npm-static-tsc-helpers.test.js.map +1 -0
  512. package/dist/frontend/npm-static-type-exports-host.d.ts +8 -0
  513. package/dist/frontend/npm-static-type-exports-host.js +214 -0
  514. package/dist/frontend/npm-static-type-exports-host.js.map +1 -0
  515. package/dist/frontend/npm-static-type-exports-host.test.d.ts +1 -0
  516. package/dist/frontend/npm-static-type-exports-host.test.js +53 -0
  517. package/dist/frontend/npm-static-type-exports-host.test.js.map +1 -0
  518. package/dist/frontend/npm-static-type-exports.d.ts +52 -0
  519. package/dist/frontend/npm-static-type-exports.js +261 -0
  520. package/dist/frontend/npm-static-type-exports.js.map +1 -0
  521. package/dist/frontend/npm-static-type-exports.test.d.ts +1 -0
  522. package/dist/frontend/npm-static-type-exports.test.js +103 -0
  523. package/dist/frontend/npm-static-type-exports.test.js.map +1 -0
  524. package/dist/frontend/npm-static-umd.d.ts +6 -0
  525. package/dist/frontend/npm-static-umd.js +203 -0
  526. package/dist/frontend/npm-static-umd.js.map +1 -0
  527. package/dist/frontend/npm-static-umd.test.d.ts +1 -0
  528. package/dist/frontend/npm-static-umd.test.js +105 -0
  529. package/dist/frontend/npm-static-umd.test.js.map +1 -0
  530. package/dist/frontend/npm-static.d.ts +8 -0
  531. package/dist/frontend/npm-static.js +47 -2
  532. package/dist/frontend/npm-static.js.map +1 -1
  533. package/dist/frontend/program.d.ts +13 -0
  534. package/dist/frontend/program.js +103 -6
  535. package/dist/frontend/program.js.map +1 -1
  536. package/dist/frontend/program.test.js +1 -1
  537. package/dist/frontend/program.test.js.map +1 -1
  538. package/dist/frontend/services.d.ts +6 -0
  539. package/dist/frontend/services.js +18 -0
  540. package/dist/frontend/services.js.map +1 -1
  541. package/dist/frontend/ts7/ast-node.d.ts +21 -7
  542. package/dist/frontend/ts7/ast-node.js +131 -29
  543. package/dist/frontend/ts7/ast-node.js.map +1 -1
  544. package/dist/frontend/ts7/ast-node.test.js +60 -0
  545. package/dist/frontend/ts7/ast-node.test.js.map +1 -1
  546. package/dist/frontend/ts7/ast-wire.d.ts +27 -2
  547. package/dist/frontend/ts7/ast-wire.js +124 -21
  548. package/dist/frontend/ts7/ast-wire.js.map +1 -1
  549. package/dist/frontend/ts7/ast.d.ts +23 -2
  550. package/dist/frontend/ts7/ast.js +143 -2
  551. package/dist/frontend/ts7/ast.js.map +1 -1
  552. package/dist/frontend/ts7/checker.d.ts +13 -1
  553. package/dist/frontend/ts7/checker.js +75 -1
  554. package/dist/frontend/ts7/checker.js.map +1 -1
  555. package/dist/frontend/ts7/checker.test.js +9 -6
  556. package/dist/frontend/ts7/checker.test.js.map +1 -1
  557. package/dist/frontend/ts7/enums.d.ts +3 -3
  558. package/dist/frontend/ts7/enums.generated.d.ts +10 -0
  559. package/dist/frontend/ts7/enums.generated.js +21 -0
  560. package/dist/frontend/ts7/enums.generated.js.map +1 -1
  561. package/dist/frontend/ts7/enums.js +19 -0
  562. package/dist/frontend/ts7/enums.js.map +1 -1
  563. package/dist/frontend/ts7/program-host.js +5 -2
  564. package/dist/frontend/ts7/program-host.js.map +1 -1
  565. package/dist/frontend/ts7/semantic-checker.d.ts +10 -0
  566. package/dist/frontend/ts7/semantic-checker.js +25 -20
  567. package/dist/frontend/ts7/semantic-checker.js.map +1 -1
  568. package/dist/frontend/ts7/semantic-json.d.ts +13 -0
  569. package/dist/frontend/ts7/semantic-json.js +146 -0
  570. package/dist/frontend/ts7/semantic-json.js.map +1 -1
  571. package/dist/frontend/ts7/semantic-json.test.js +57 -1
  572. package/dist/frontend/ts7/semantic-json.test.js.map +1 -1
  573. package/dist/frontend/ts7/semantic-model.d.ts +15 -0
  574. package/dist/frontend/ts7/semantic-model.js +67 -19
  575. package/dist/frontend/ts7/semantic-model.js.map +1 -1
  576. package/dist/frontend/ts7/semantic-model.test.js +3 -2
  577. package/dist/frontend/ts7/semantic-model.test.js.map +1 -1
  578. package/dist/frontend/ts7/session.js +1 -1
  579. package/dist/frontend/ts7/session.js.map +1 -1
  580. package/dist/frontend/tsc-codes.d.ts +1 -1
  581. package/dist/frontend/tsc-codes.js +7 -0
  582. package/dist/frontend/tsc-codes.js.map +1 -1
  583. package/dist/frontend/type-mapper.d.ts +38 -6
  584. package/dist/frontend/type-mapper.js +265 -32
  585. package/dist/frontend/type-mapper.js.map +1 -1
  586. package/dist/frontend/type-mapper.test.js +1 -1
  587. package/dist/frontend/type-mapper.test.js.map +1 -1
  588. package/dist/frontend-process-args.d.ts +4 -0
  589. package/dist/frontend-process-args.js +52 -0
  590. package/dist/frontend-process-args.js.map +1 -0
  591. package/dist/frontend-process-args.test.d.ts +1 -0
  592. package/dist/frontend-process-args.test.js +47 -0
  593. package/dist/frontend-process-args.test.js.map +1 -0
  594. package/dist/frontend-process.d.ts +1 -0
  595. package/dist/frontend-process.js +23 -0
  596. package/dist/frontend-process.js.map +1 -0
  597. package/dist/heap-collection.d.ts +16 -0
  598. package/dist/heap-collection.js +42 -0
  599. package/dist/heap-collection.js.map +1 -0
  600. package/dist/heap-collection.test.d.ts +1 -0
  601. package/dist/heap-collection.test.js +59 -0
  602. package/dist/heap-collection.test.js.map +1 -0
  603. package/dist/heap-pressure.d.ts +2 -0
  604. package/dist/heap-pressure.js +12 -0
  605. package/dist/heap-pressure.js.map +1 -0
  606. package/dist/index.d.ts +7 -0
  607. package/dist/index.js +402 -86
  608. package/dist/index.js.map +1 -1
  609. package/dist/ir/array-length-stability.js +7 -0
  610. package/dist/ir/array-length-stability.js.map +1 -1
  611. package/dist/ir/array-length-stability.test.js +25 -0
  612. package/dist/ir/array-length-stability.test.js.map +1 -1
  613. package/dist/ir/builtin-effects.js +28 -0
  614. package/dist/ir/builtin-effects.js.map +1 -1
  615. package/dist/ir/builtin-signatures.d.ts +5 -1
  616. package/dist/ir/builtin-signatures.js +141 -12
  617. package/dist/ir/builtin-signatures.js.map +1 -1
  618. package/dist/ir/final-fields.d.ts +2 -1
  619. package/dist/ir/final-fields.js +2 -2
  620. package/dist/ir/final-fields.js.map +1 -1
  621. package/dist/ir/function-references.test.js +2 -0
  622. package/dist/ir/function-references.test.js.map +1 -1
  623. package/dist/ir/int32-slots.d.ts +13 -5
  624. package/dist/ir/int32-slots.js +112 -115
  625. package/dist/ir/int32-slots.js.map +1 -1
  626. package/dist/ir/int32-slots.test.js +3 -1
  627. package/dist/ir/int32-slots.test.js.map +1 -1
  628. package/dist/ir/integer-loop-facts.d.ts +9 -4
  629. package/dist/ir/integer-loop-facts.js +93 -18
  630. package/dist/ir/integer-loop-facts.js.map +1 -1
  631. package/dist/ir/integer-loops.d.ts +49 -0
  632. package/dist/ir/integer-loops.js +193 -39
  633. package/dist/ir/integer-loops.js.map +1 -1
  634. package/dist/ir/integer-loops.test.js +201 -1
  635. package/dist/ir/integer-loops.test.js.map +1 -1
  636. package/dist/ir/integer-ranges.test.js +64 -0
  637. package/dist/ir/integer-ranges.test.js.map +1 -1
  638. package/dist/ir/ir.d.ts +17 -2
  639. package/dist/ir/ir.js +3 -1
  640. package/dist/ir/ir.js.map +1 -1
  641. package/dist/ir/runtime-features.d.ts +31 -7
  642. package/dist/ir/runtime-features.js +138 -11
  643. package/dist/ir/runtime-features.js.map +1 -1
  644. package/dist/ir/tiers.js +1 -0
  645. package/dist/ir/tiers.js.map +1 -1
  646. package/dist/ir/traverse.d.ts +2 -0
  647. package/dist/ir/traverse.js +14 -2
  648. package/dist/ir/traverse.js.map +1 -1
  649. package/dist/ir/validate.js +56 -16
  650. package/dist/ir/validate.js.map +1 -1
  651. package/dist/library/ir-policy.js +10 -0
  652. package/dist/library/ir-policy.js.map +1 -1
  653. package/dist/library/library-cache.d.ts +2 -0
  654. package/dist/library/library-cache.js.map +1 -1
  655. package/dist/library/prepare.js +2 -0
  656. package/dist/library/prepare.js.map +1 -1
  657. package/dist/native/cli.js +5 -0
  658. package/dist/native/cli.js.map +1 -1
  659. package/dist/native/prepare.js +5 -1
  660. package/dist/native/prepare.js.map +1 -1
  661. package/dist/native/sanitizer.test.js +4 -1
  662. package/dist/native/sanitizer.test.js.map +1 -1
  663. package/dist/startup-cache.d.ts +1 -0
  664. package/dist/startup-cache.js +1 -0
  665. package/dist/startup-cache.js.map +1 -1
  666. package/dist/text-parts.d.ts +7 -0
  667. package/dist/text-parts.js +44 -0
  668. package/dist/text-parts.js.map +1 -1
  669. package/dist/text-parts.test.d.ts +1 -0
  670. package/dist/text-parts.test.js +46 -0
  671. package/dist/text-parts.test.js.map +1 -0
  672. package/dist/timing.d.ts +9 -2
  673. package/dist/timing.js +7 -4
  674. package/dist/timing.js.map +1 -1
  675. package/dist/wasm/translate.d.ts +4 -0
  676. package/dist/wasm/translate.js +2 -2
  677. package/dist/wasm/translate.js.map +1 -1
  678. package/package.json +21 -21
  679. package/shims/undici/core/client.ts +4 -4
  680. package/surface-manifest.json +19 -49
@@ -1,4 +1,7 @@
1
- import { onlyForwarded } from "./typed-arguments.js";
1
+ import { relieveHeapPressure } from "../../heap-pressure.js";
2
+ import { keyedHelperName } from "./stable-names.js";
3
+ import { positionTag, StructuralPositions } from "./structural-positions.js";
4
+ import { onlyForwarded, stripTypeWrappers } from "./typed-arguments.js";
2
5
  import { needsGeneralNodeStreams, noteUntypedStreamFlow, stdioIntoGeneralStream, } from "./general-streams.js";
3
6
  import { extendAssertedRecordMembers } from "./assertion-members.js";
4
7
  import { jsDynamicDeclarations } from "./js-dynamic-objects.js";
@@ -14,6 +17,8 @@ import { checkRequireBindingAccesses, } from "./require-initialization.js";
14
17
  import { identityPreservingWidening } from "./coercions/identity.js";
15
18
  import { scanDivergences } from "./divergences.js";
16
19
  import { applyKeyOrderWitnesses, KeyOrderNotes } from "./key-order-witness.js";
20
+ import { exprFunctionReference } from "../../ir/function-references.js";
21
+ import { everyStmtList, observeRecordLiteralRebuilds } from "../../ir/traverse.js";
17
22
  import { checkedClassAssertion } from "./class-assertions.js";
18
23
  import { narrowStoredClassValue, narrowGenericClassValue } from "./class-unions.js";
19
24
  import { isOptionalProcessStreamProperty, isOptionalProcessVersionsRead, } from "./builtins/process.js";
@@ -28,8 +33,9 @@ import { encodeBase64 } from "../../wasm/base64.js";
28
33
  import { resolveRequireRuntime } from "../runtime-resolve.js";
29
34
  import { lowerKeyObjectCall } from "./builtins/key-object.js";
30
35
  import { isEcdhType, lowerEcdhCall } from "./builtins/ecdh.js";
36
+ import { isDiffieHellmanType, lowerDiffieHellmanCall } from "./builtins/dh.js";
31
37
  import { fenceWebCryptoMember, lowerWebCryptoCall } from "./builtins/webcrypto.js";
32
- import { hashStreamOf } from "./builtins/hash-stream.js";
38
+ import { valueStreamOf } from "./builtins/hash-stream.js";
33
39
  import { lowerNetAddressCall, lowerNetAddressNew } from "./builtins/net-address.js";
34
40
  import { dynUndefinedExpr, nodeThrowExpr, numLit, varRef } from "../../ir/build.js";
35
41
  import { iteratorSlotAdapter } from "./iterator-adapters.js";
@@ -49,6 +55,7 @@ import { ArrayElementStates } from "./runtime-optional-elements.js";
49
55
  import { indexReadInBounds } from "./runtime-optional-bounds.js";
50
56
  import { ArrayOwnership } from "./runtime-optional-ownership.js";
51
57
  import { RecordFlowClasses } from "./runtime-optional-records.js";
58
+ import { SiteDependencies } from "./site-dependencies.js";
52
59
  import { StringIndexBounds } from "./string-index-bounds.js";
53
60
  import { NanCodedReads } from "./nan-coded-reads.js";
54
61
  import { RuntimeOptionalLocals } from "./runtime-optional-locals.js";
@@ -66,6 +73,7 @@ import { ClassProtocols } from "./class-protocols.js";
66
73
  import { earlyReadVarSymbols } from "./var-hoisting.js";
67
74
  import { recordTextCodecClass } from "../../ir/ir.js";
68
75
  import { assignLegacyTiers } from "../../ir/tiers.js";
76
+ import { dynamicTierWarning } from "./dynamic-tier.js";
69
77
  import { promoteJsvals } from "../../ir/jsval.js";
70
78
  import { analyzeTiers, dynamicStatementCount, } from "../tier-analysis.js";
71
79
  import { DeferredModuleInitializers } from "./deferred-module-initializers.js";
@@ -87,7 +95,7 @@ export { newFnCtx } from "./function-context.js";
87
95
  * - Lexical scoping is resolved here: locals get function-unique ids
88
96
  * ("x.0", "x.1" for shadowing); the IR is scope-flat.
89
97
  */
90
- import { resolve } from "node:path";
98
+ import { dirname, relative, resolve } from "node:path";
91
99
  import { bindingSource } from "../binding-source.js";
92
100
  import { tsgoPath } from "../dts-paths.js";
93
101
  import * as ts from "../ts7/adapter.js";
@@ -147,7 +155,8 @@ import { lowerStringDecoderMethodCall, lowerTextCodecCall } from "./builtins/tex
147
155
  import { lowerReadlineMethodCall } from "./builtins/readline.js";
148
156
  import { lowerDiagnosticsChannelMethodCall, lowerDiagnosticsChannelProperty, lowerAsyncLocalStorageMethodCall, lowerTracingChannelMethodCall, lowerTracingChannelProperty, } from "./builtins/async-context.js";
149
157
  import { lowerDisposableStackNew } from "./builtins/disposable-stack.js";
150
- import { lowerErrorCodeProperty } from "./builtins/errors.js";
158
+ import { lowerErrorCodeProperty, lowerErrorFunctionCall } from "./builtins/errors.js";
159
+ import { noteDateClassMethods } from "./builtins/date-classes.js";
151
160
  import { lowerProcessProperty, lowerProcessMethodCall, lowerProcessOptionalMethodCall, lowerProcessStreamProperty, } from "./builtins/process.js";
152
161
  import { consoleCallMember, consoleMethodMember, isConsoleLog, } from "./builtins/console.js";
153
162
  import { lowerConsoleNew } from "./lower-console.js";
@@ -247,6 +256,33 @@ function directExternalTypeSpecifiersByFile(externalTypes) {
247
256
  }
248
257
  return out;
249
258
  }
259
+ /** Debugging aid: SCRIPTC_LOWER_SHUFFLE_SEED=<n> lowers each wave of
260
+ * reachable bodies in an order drawn from that seed instead of discovery
261
+ * order. Output assembly is ordered independently of it, so any IR
262
+ * difference between seeds is state one body's lowering leaves for another
263
+ * (scripts/lowering-order.mjs). */
264
+ function lowerShuffle() {
265
+ const raw = process.env["SCRIPTC_LOWER_SHUFFLE_SEED"];
266
+ if (raw === undefined || raw === "")
267
+ return null;
268
+ // mulberry32
269
+ let state = Number.parseInt(raw, 10) >>> 0;
270
+ const next = () => {
271
+ state = (state + 0x6d2b79f5) >>> 0;
272
+ let t = state;
273
+ t = Math.imul(t ^ (t >>> 15), t | 1);
274
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
275
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
276
+ };
277
+ return (wave) => {
278
+ for (let index = wave.length - 1; index > 0; index--) {
279
+ const other = Math.floor(next() * (index + 1));
280
+ const swap = wave[index];
281
+ wave[index] = wave[other];
282
+ wave[other] = swap;
283
+ }
284
+ };
285
+ }
250
286
  /** Build lowering runs as a reachability worklist over the ts.Program:
251
287
  *
252
288
  * 1. REACHABLE EMIT — a worklist computes the set of reachable bodies.
@@ -264,6 +300,10 @@ function directExternalTypeSpecifiersByFile(externalTypes) {
264
300
  * the bodies reachable emit did NOT mark (plus deferred collection
265
301
  * diagnostics nothing flushed), reported separately: whole-program analysis without
266
302
  * letting unreached code fail builds. */
303
+ /** The closure root of an emit-override specialization body. */
304
+ function emitSpecRoot(spec) {
305
+ return `%emit.${spec.info.def.name}.${spec.event}.${spec.ordinal}`;
306
+ }
267
307
  export function lowerToIr(program, entry, moduleOrder, options = {}) {
268
308
  const phaseTiming = process.env["SCRIPTC_TIMING"] === "1";
269
309
  const phaseStarted = performance.now();
@@ -453,6 +493,14 @@ export function lowerToIr(program, entry, moduleOrder, options = {}) {
453
493
  timing("divergence-scan", { found: divergences.length });
454
494
  if (divergences.length > 0)
455
495
  result = { ...result, divergences };
496
+ // The performance warning (SC6101): likely-hot functions of the program
497
+ // that compile to the dynamic tier because the source leaves them untyped.
498
+ if (result.module !== null && resultLowerer.dynamicFunctions.length > 0) {
499
+ const hotDynamic = dynamicTierWarning(resultLowerer, result.module, dirname(entry.fileName));
500
+ timing("dynamic-tier-scan", { found: hotDynamic === null ? 0 : 1 });
501
+ if (hotDynamic !== null)
502
+ result = { ...result, performance: [hotDynamic] };
503
+ }
456
504
  // Contract types (@scriptc/types): written annotations, checked against
457
505
  // the IR by the compile pipeline (contracts/check.ts).
458
506
  // Acyclic object types name the IR unit the program lowered them to; a
@@ -498,18 +546,28 @@ export function lowerToIr(program, entry, moduleOrder, options = {}) {
498
546
  });
499
547
  // A program that uses the WebAssembly API carries every module the build
500
548
  // can see and translate (wasm/translate.ts); the rest fail at run time
501
- // with the CompileError for untranslated bytes.
549
+ // with a CompileError, which names the reason for the modules the build
550
+ // saw but does not translate.
502
551
  if (result.module !== null && resultLowerer.usesWebAssembly) {
503
552
  const bytesByHash = new Map();
504
553
  const reports = discoverModules((sha256, bytes) => bytesByHash.set(sha256, bytes));
505
554
  const wasmModules = [];
555
+ const wasmUntranslated = [];
506
556
  for (const report of reports) {
507
557
  const bytes = bytesByHash.get(report.sha256);
508
- if (report.status !== "valid" || bytes === undefined)
558
+ if (bytes === undefined)
509
559
  continue;
510
- wasmModules.push({ sha256: report.sha256, bytes: encodeBase64(bytes) });
560
+ if (report.status === "valid") {
561
+ wasmModules.push({ sha256: report.sha256, bytes: encodeBase64(bytes) });
562
+ continue;
563
+ }
564
+ const reason = report.status === "unsupported"
565
+ ? `it uses ${report.unsupported.join(", ")}, outside the translated WebAssembly feature set`
566
+ : `it is not a valid module: ${report.error ?? report.status}`;
567
+ wasmUntranslated.push({ sha256: report.sha256, size: bytes.length, reason });
511
568
  }
512
569
  result.module.wasmModules = wasmModules;
570
+ result.module.wasmUntranslated = wasmUntranslated;
513
571
  if (resultLowerer.usesWasmCustomSections)
514
572
  result.module.wasmCustomSections = true;
515
573
  timing("wasm-discovery", { modules: wasmModules.length });
@@ -1061,6 +1119,10 @@ function monomorphizedImplicit(lowerer, fn) {
1061
1119
  return implicitLocalFnNodeOf(lowerer, binding) !== null;
1062
1120
  return true;
1063
1121
  }
1122
+ /** `fns` sorted by name; functions of one name keep their order. */
1123
+ function byName(fns) {
1124
+ return [...fns].sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
1125
+ }
1064
1126
  export class Lowerer {
1065
1127
  program;
1066
1128
  entry;
@@ -1091,6 +1153,9 @@ export class Lowerer {
1091
1153
  * pinned values resolve through genericFnOf exactly like top-level
1092
1154
  * generic function declarations (bindingGenericFnInfoOf). */
1093
1155
  bindingGenericFns = new Map();
1156
+ /** Identifiers by spelling, per file, for the generic bindings' use
1157
+ * ordering (runsAfterDeclaration). */
1158
+ bindingIdentifiers = new Map();
1094
1159
  /** Per-symbol result of the never-reassigned file scan
1095
1160
  * (bindingNeverReassigned — object-literal generic-method receivers). */
1096
1161
  neverReassignedCache = new Map();
@@ -1242,6 +1307,35 @@ export class Lowerer {
1242
1307
  });
1243
1308
  this.genericClassInstances.splice(from, tail.length, ...tail);
1244
1309
  }
1310
+ /** The classes in table order. Generic instances are added as bodies
1311
+ * demand them, so they keep the slots they hold and fill them in the
1312
+ * order of their settled demand ranks. */
1313
+ classesInTableOrder() {
1314
+ const all = [...this.classes.values()];
1315
+ const slots = all.flatMap((info, index) => this.genericClassDemandPriority.has(info) ? [index] : []);
1316
+ const ranked = slots
1317
+ .map((index) => all[index])
1318
+ .sort((left, right) => {
1319
+ const a = this.genericClassDemandPriority.get(left).rank;
1320
+ const b = this.genericClassDemandPriority.get(right).rank;
1321
+ return a[0] - b[0] || a[1] - b[1];
1322
+ });
1323
+ slots.forEach((slot, index) => (all[slot] = ranked[index]));
1324
+ return all;
1325
+ }
1326
+ /** The globals in table order. A class's prototype data globals are
1327
+ * added when a body first reads that prototype, so they keep the slots
1328
+ * they hold and fill them in id order. */
1329
+ globalsInTableOrder() {
1330
+ const all = [...this.globalsList];
1331
+ const prototypeData = (global) => global.id.startsWith("%g.%prototype.data.");
1332
+ const slots = all.flatMap((global, index) => (prototypeData(global) ? [index] : []));
1333
+ const sorted = slots
1334
+ .map((index) => all[index])
1335
+ .sort((left, right) => (left.id < right.id ? -1 : left.id > right.id ? 1 : 0));
1336
+ slots.forEach((slot, index) => (all[slot] = sorted[index]));
1337
+ return all;
1338
+ }
1245
1339
  settleGenericDemandPriorities() {
1246
1340
  const functionQueue = [];
1247
1341
  const classQueue = [];
@@ -1323,6 +1417,12 @@ export class Lowerer {
1323
1417
  /** Instance types (by checker type id) of the local classes generic
1324
1418
  * factory calls return, and the per-instance class each names. */
1325
1419
  localClassInstanceTypes = new Map();
1420
+ /** A generic factory's instantiated result type → the class value of the
1421
+ * local class it returns (TypeMapperCtx.localClassValue). */
1422
+ localClassValueTypes = new Map();
1423
+ /** While a generic factory instance lowers: its declared result type → the
1424
+ * class value of the local class it returns. */
1425
+ instanceResultClass = null;
1326
1426
  /** The ts-level twin of typeParamBindings, non-null while a CALL-keyed
1327
1427
  * instance body lowers: type-parameter symbol → the bound CHECKER type,
1328
1428
  * consulted where the mapped IrType has already widened away information
@@ -1857,6 +1957,19 @@ export class Lowerer {
1857
1957
  /** True while re-lowering a base function's 2nd+ instance: the same source
1858
1958
  * statements were already counted for the first instance. */
1859
1959
  suppressStats = false;
1960
+ /** Callback literals passed straight to an error-first zlib or crypto
1961
+ * function: only that function's callback adapter calls them
1962
+ * (lowerUndefinedResultBody). */
1963
+ errorFirstLiterals = new Set();
1964
+ /** Parameters read as `any` in the error-path copy of an error-first
1965
+ * callback. */
1966
+ anySymbols = new Set();
1967
+ /** Error parameters of an error-first callback with a known value in
1968
+ * the copy being lowered: true while it holds an Error, false while it
1969
+ * holds null (staticCondition folds conditions on them). */
1970
+ knownErrors = new Map();
1971
+ /** The number of error-path callback copies being lowered. */
1972
+ errorPathCopies = 0;
1860
1973
  /** Comparisons interned by operand representations and equality semantics. */
1861
1974
  equalityHelpers = new Map();
1862
1975
  /** Synthetic array-HOF loop functions (map/filter/forEach desugar),
@@ -1907,6 +2020,8 @@ export class Lowerer {
1907
2020
  /** Generated value helpers, keyed by operation and type. Callers own
1908
2021
  * their key prefixes; this includes more than structural conversions. */
1909
2022
  valueHelpers = new Map();
2023
+ /** Each name keyedHelperName made, with a second hash of its key. */
2024
+ keyedNameKeys = new Map();
1910
2025
  /** structuralNarrowing's assignable classes, keyed by static and
1911
2026
  * narrowed class name. */
1912
2027
  structuralClassPeers = new Map();
@@ -2021,13 +2136,16 @@ export class Lowerer {
2021
2136
  * `doneLocalId` is sticky: once next() observes the end, later source
2022
2137
  * changes do not revive the exhausted iterator, exactly like Node. */
2023
2138
  numericIterators = new Map();
2024
- chainCounter = 0;
2025
2139
  /** Keyed by program-wide qualified class name (what IR object types carry). */
2026
2140
  classes = new Map();
2027
2141
  classBySymbol = new Map();
2028
2142
  /** Named method slots observed before class collection need a callable
2029
2143
  * ABI and shared prototype descriptors instead of call-site specialization. */
2030
2144
  prototypeMethodAccesses = new Map();
2145
+ /** Whether the program reads `Error.prototype`, the checked-dynamic
2146
+ * object an ES5 constructor function can inherit from: only then can a
2147
+ * value that is not an Error instance be `instanceof Error`. */
2148
+ errorPrototypeValues = false;
2031
2149
  /** Well-known symbol methods (`sym:iterator`) the program may replace
2032
2150
  * through a symbol-keyed write: an instance or prototype property, or a
2033
2151
  * reflection call. */
@@ -2092,10 +2210,16 @@ export class Lowerer {
2092
2210
  /** Inline Promise.then parameters whose contextual type is a builtin
2093
2211
  * module namespace anonymous object. The settled native token is the
2094
2212
  * ABI truth even when the checker type has no stable module symbol. */
2095
- /** Receivers of a stream call on a Hash or Hmac (lowerHashStreamCall):
2096
- * for the duration of that call, the receiver lowers to the Transform of
2097
- * the value held in the named local. */
2098
- hashStreamReceivers = new Map();
2213
+ /** Receivers of a stream call on a Hash, Hmac, Cipheriv or Decipheriv
2214
+ * (lowerHashStreamCall): for the duration of that call, the receiver
2215
+ * lowers to the Transform of the value held in the named local. */
2216
+ valueStreamReceivers = new Map();
2217
+ /** fs call arguments evaluated ahead of a URL path's conversion
2218
+ * (builtins/fs-paths.ts): each lowers to the hidden local that holds its
2219
+ * value, which is null until the path's lowering has saved it. */
2220
+ stagedArguments = new Map();
2221
+ /** The staged arguments that follow each such URL path, in order. */
2222
+ stagedAfterPath = new Map();
2099
2223
  moduleNsParamOverrides = new Map();
2100
2224
  /** File → qualifier prefix: "" for the entry, "%mI." otherwise. */
2101
2225
  fileTag = new Map();
@@ -2210,6 +2334,10 @@ export class Lowerer {
2210
2334
  // top level, top = the innermost nested function currently lowering).
2211
2335
  fnStack = [];
2212
2336
  liftedFns = [];
2337
+ /** The first lifted function of each name (liftedFnNamed), for the
2338
+ * liftedFns indexed so far. liftedFns only grows. */
2339
+ liftedFnsByName = new Map();
2340
+ liftedFnsIndexed = 0;
2213
2341
  /** Runtime-provided classes used as values (defineClassValueConstruct),
2214
2342
  * by IR class name. */
2215
2343
  runtimeClassValues = new Map();
@@ -2217,7 +2345,49 @@ export class Lowerer {
2217
2345
  * dispatch revision needs no weak-key identity or process-global state. */
2218
2346
  errorMethodDispatchRevision = null;
2219
2347
  errorPropertyDispatchRevision = null;
2220
- lambdaCounter = 0;
2348
+ /** Structural source positions (structural-positions.ts) for names that
2349
+ * stay the same when unrelated code moves. */
2350
+ /** Files are named by their path relative to the entry's directory, so
2351
+ * names do not depend on where the program sits, and default library
2352
+ * files by their base name: two checkers install them in different
2353
+ * directories. */
2354
+ positions = new StructuralPositions((sf) => this.program.isSourceFileDefaultLibrary(sf)
2355
+ ? `lib:${sf.fileName.slice(sf.fileName.lastIndexOf("/") + 1)}`
2356
+ : relative(dirname(this.entry.fileName), sf.fileName));
2357
+ /** The outermost node whose token span is exactly `loc`, or null. */
2358
+ nodeAtLoc(loc) {
2359
+ const sf = this.program.getSourceFile(loc.file);
2360
+ return sf === undefined ? null : (ts.nodeAtSpan(sf, loc.start, loc.end) ?? null);
2361
+ }
2362
+ /** The lowering unit whose name scopes the closures it lifts. */
2363
+ closureRoot = "%pre";
2364
+ closureNameCounts = new Map();
2365
+ /** Runs `fn` with the closures it lifts named under `root`. */
2366
+ withClosureRoot(root, fn) {
2367
+ const previous = this.closureRoot;
2368
+ this.closureRoot = root;
2369
+ try {
2370
+ return fn();
2371
+ }
2372
+ finally {
2373
+ this.closureRoot = previous;
2374
+ }
2375
+ }
2376
+ /** The name of a closure (or wrapper) lifted for the source at `loc`:
2377
+ * `<prefix>.<hash>` of the current lowering unit, the location and
2378
+ * `suffix`, then `suffix`. A unit that lifts several functions for the same
2379
+ * location and suffix numbers them in the order it lifts them, so a
2380
+ * closure's name depends only on its unit, not on which units lowered
2381
+ * before it. */
2382
+ closureName(loc, suffix = "", prefix = "%fn") {
2383
+ const node = this.nodeAtLoc(loc);
2384
+ const where = node === null ? `${loc.file}:${loc.start}:${loc.end}` : this.positions.of(node);
2385
+ const key = `${prefix}|${this.closureRoot}|${where}|${suffix}`;
2386
+ const first = keyedHelperName(this, prefix, key);
2387
+ const seen = this.closureNameCounts.get(first) ?? 0;
2388
+ this.closureNameCounts.set(first, seen + 1);
2389
+ return (seen === 0 ? first : keyedHelperName(this, prefix, `${key}|${seen}`)) + suffix;
2390
+ }
2221
2391
  preparedClassFactories = new Map();
2222
2392
  preparingClassFactories = new Set();
2223
2393
  /** Statement lists currently mid-lowering, innermost last: the forward-
@@ -2269,6 +2439,10 @@ export class Lowerer {
2269
2439
  * can contain any retained descendant, but importing its declaration
2270
2440
  * alone does not make every descendant constructible. */
2271
2441
  constructedClasses = null;
2442
+ /** Classes added to some ClassInfo's subclasses (lower-classes.ts). With
2443
+ * the class and constructed-class counts, it tells caches over the class
2444
+ * graph when the graph changed. */
2445
+ subclassLinks = 0;
2272
2446
  /** Set while a subclass constructor's super() call notes its base
2273
2447
  * constructor edge: that edge does not instantiate the base exactly. */
2274
2448
  superConstructorEdge = false;
@@ -2282,6 +2456,136 @@ export class Lowerer {
2282
2456
  info.genericInstance !== undefined ||
2283
2457
  info.mixinInstance !== undefined);
2284
2458
  }
2459
+ /** How many classes classCanBeConstructed admits by name, or -1 while
2460
+ * it admits every class. The count only grows. */
2461
+ constructedClassCount() {
2462
+ return this.constructedClasses?.size ?? -1;
2463
+ }
2464
+ /** Helpers that every site asking for them shares (shareHelper). */
2465
+ sharedHelpers = new Set();
2466
+ sharedHelperNames = new Set();
2467
+ /** Marks a helper, or the lifted helpers of a name, as shared by every
2468
+ * site that asks for it. A shared helper is built for whichever site asks
2469
+ * first, so once lowering finishes its locations are replaced by one that
2470
+ * names no site. */
2471
+ shareHelper(helper) {
2472
+ if (typeof helper === "string")
2473
+ this.sharedHelperNames.add(helper);
2474
+ else
2475
+ this.sharedHelpers.add(helper);
2476
+ }
2477
+ /** Gives each shared helper (those marked by shareHelper, and those
2478
+ * interned by key in the helper tables) one location for all its nodes:
2479
+ * the earliest site in `functions` that uses it, by file and position, so
2480
+ * reports such as --explain-dynamic point at a use whatever order bodies
2481
+ * lowered in. A helper used only by other shared helpers takes their
2482
+ * location; one with no use takes the entry file's start. */
2483
+ settleSharedHelperLocations(functions) {
2484
+ const interned = new Set([...this.sharedHelperNames, ...this.classMethodValueHelpers]);
2485
+ for (const table of [
2486
+ this.equalityHelpers,
2487
+ this.arrHofHelpers,
2488
+ this.unionCallHelpers,
2489
+ this.valueHelpers,
2490
+ this.assertHelpers,
2491
+ this.inspectHelpers,
2492
+ this.iterDrainHelpers,
2493
+ this.mapHofHelpers,
2494
+ this.setHofHelpers,
2495
+ this.spHofHelpers,
2496
+ this.primitiveCtorFns,
2497
+ this.builtinCallableValueFns,
2498
+ this.regionRunHelpers,
2499
+ this.internTableHelpers,
2500
+ this.coercions.retags,
2501
+ this.coercions.narrows,
2502
+ ])
2503
+ for (const name of table.values())
2504
+ interned.add(name);
2505
+ for (const fn of [...this.liftedFns, ...this.implicitFns])
2506
+ if (interned.has(fn.name))
2507
+ this.sharedHelpers.add(fn);
2508
+ if (this.sharedHelpers.size === 0)
2509
+ return;
2510
+ const shared = new Map([...this.sharedHelpers].map((fn) => [fn.name, fn]));
2511
+ const earlier = (left, right) => left.file < right.file || (left.file === right.file && left.start < right.start);
2512
+ // The earliest use of each shared helper outside the shared helpers, and
2513
+ // which shared helpers each shared helper uses.
2514
+ const uses = new Map();
2515
+ const usedBy = new Map();
2516
+ for (const fn of functions) {
2517
+ const inShared = shared.has(fn.name) ? fn.name : undefined;
2518
+ everyStmtList(fn.body, {
2519
+ stmt: () => true,
2520
+ expr: (expr) => {
2521
+ const name = expr.kind === "call" ? expr.callee : exprFunctionReference(expr);
2522
+ if (name === undefined || name === inShared || !shared.has(name))
2523
+ return true;
2524
+ if (inShared !== undefined) {
2525
+ let users = usedBy.get(name);
2526
+ if (users === undefined)
2527
+ usedBy.set(name, (users = new Set()));
2528
+ users.add(inShared);
2529
+ }
2530
+ else {
2531
+ const current = uses.get(name);
2532
+ if (current === undefined || earlier(expr.loc, current))
2533
+ uses.set(name, expr.loc);
2534
+ }
2535
+ return true;
2536
+ },
2537
+ });
2538
+ }
2539
+ // Helpers reached only through other shared helpers take the earliest
2540
+ // location among those, to a fixed point.
2541
+ for (let changed = true; changed;) {
2542
+ changed = false;
2543
+ for (const [name, users] of usedBy) {
2544
+ for (const user of users) {
2545
+ const loc = uses.get(user);
2546
+ const current = uses.get(name);
2547
+ if (loc !== undefined && (current === undefined || earlier(loc, current))) {
2548
+ uses.set(name, loc);
2549
+ changed = true;
2550
+ }
2551
+ }
2552
+ }
2553
+ }
2554
+ const fallback = { file: this.entry.fileName, start: 0, end: 0 };
2555
+ for (const fn of this.sharedHelpers) {
2556
+ const use = uses.get(fn.name) ?? fallback;
2557
+ const loc = { file: use.file, start: use.start, end: use.end };
2558
+ const seen = new Set();
2559
+ const visit = (node) => {
2560
+ if (typeof node !== "object" || node === null || seen.has(node))
2561
+ return;
2562
+ seen.add(node);
2563
+ if (Array.isArray(node)) {
2564
+ for (const item of node)
2565
+ visit(item);
2566
+ return;
2567
+ }
2568
+ const record = node;
2569
+ for (const key of Object.keys(record)) {
2570
+ if (key === "loc")
2571
+ record[key] = loc;
2572
+ else if (key !== "type")
2573
+ visit(record[key]);
2574
+ }
2575
+ };
2576
+ visit(fn);
2577
+ }
2578
+ }
2579
+ /** The first lifted function named `name`, the one
2580
+ * `liftedFns.find((fn) => fn.name === name)` returns. */
2581
+ liftedFnNamed(name) {
2582
+ for (; this.liftedFnsIndexed < this.liftedFns.length; this.liftedFnsIndexed++) {
2583
+ const fn = this.liftedFns[this.liftedFnsIndexed];
2584
+ if (!this.liftedFnsByName.has(fn.name))
2585
+ this.liftedFnsByName.set(fn.name, fn);
2586
+ }
2587
+ return name === undefined ? undefined : this.liftedFnsByName.get(name);
2588
+ }
2285
2589
  /** Coverage remainder mode: the reachability gate inverts (see wantBody)
2286
2590
  * and no module is built. */
2287
2591
  remainder;
@@ -2435,6 +2739,7 @@ export class Lowerer {
2435
2739
  this.checker = program.getTypeChecker();
2436
2740
  this.typeCtx = {
2437
2741
  checker: this.checker,
2742
+ positionOf: (node) => this.positions.of(node),
2438
2743
  shapes: this.shapes,
2439
2744
  unions: this.unions,
2440
2745
  classNamer: this.classNamer,
@@ -2443,6 +2748,9 @@ export class Lowerer {
2443
2748
  isErasing: () => this.erasingDepth > 0,
2444
2749
  genericClassInstance: (decl, ref, mapArgument) => this.genericClassInstanceType(decl, ref, mapArgument),
2445
2750
  runtimeClassValue: (type) => runtimeClassValueOfType(this, type),
2751
+ localClassValue: (type) => this.instanceResultClass !== null && this.instanceResultClass.declared === type.id
2752
+ ? this.instanceResultClass.value
2753
+ : (this.localClassValueTypes.get(type.id) ?? null),
2446
2754
  mixinClassInstance: (decl) => this.mixinTypeContext && this.mixinTypeContext.classNode === decl
2447
2755
  ? { kind: "object", className: this.mixinTypeContext.className }
2448
2756
  : null,
@@ -2561,16 +2869,16 @@ export class Lowerer {
2561
2869
  * is `unknown` or `object` (also with `null` or `undefined`, or an array
2562
2870
  * of those), names checked protocol identity, is an owned runtime
2563
2871
  * handle (a Worker or MessagePort, a fetch Headers/Request/Response, or
2564
- * a node:crypto ECDH), or is a WeakMap/WeakSet (native weak collections
2565
- * live in checked-dynamic storage, as locals of those types do); `any`
2566
- * fields stay refused. */
2872
+ * a node:crypto ECDH, DiffieHellman or DiffieHellmanGroup), or is a
2873
+ * WeakMap/WeakSet (native weak collections live in checked-dynamic
2874
+ * storage, as locals of those types do); `any` fields stay refused. */
2567
2875
  classFieldStoresDyn(type) {
2568
2876
  return (this.opaqueValueType(type) ||
2569
2877
  this.classImplementedProtocol(type) ||
2570
2878
  isWorkerHandleType(type, this.typeCtx) ||
2571
2879
  isFetchHandleType(type, this.typeCtx) ||
2572
2880
  this.weakCollectionType(type) ||
2573
- this.stdlibHandleType(type, (part) => isEcdhType(this, part)));
2881
+ this.stdlibHandleType(type, (part) => isEcdhType(this, part) || isDiffieHellmanType(this, part)));
2574
2882
  }
2575
2883
  /** A stdlib WeakMap or WeakSet, alone or with `null`/`undefined`. */
2576
2884
  weakCollectionType(type) {
@@ -2670,8 +2978,8 @@ export class Lowerer {
2670
2978
  }
2671
2979
  return false;
2672
2980
  })()
2673
- ? this.qualify(ts.getSourceFileOfNode(decl), `%cx${ts.tokenStartOfNode(decl)}.${decl.name?.text ?? ""}`)
2674
- : this.qualify(ts.getSourceFileOfNode(decl), nsPathPrefix(decl) + (decl.name ? decl.name.text : "%anon"));
2981
+ ? this.qualify(ts.getSourceFileOfNode(decl), `%cx${positionTag(this, decl)}.${decl.name?.text ?? ""}`)
2982
+ : this.qualify(ts.getSourceFileOfNode(decl), nsPathPrefix(this, decl) + (decl.name ? decl.name.text : "%anon"));
2675
2983
  for (let index = this.localClassInstantiations.length - 1; index >= 0; index--) {
2676
2984
  const entry = this.localClassInstantiations[index];
2677
2985
  for (let parent = decl.parent; parent && !ts.isSourceFile(parent); parent = parent.parent) {
@@ -3760,11 +4068,16 @@ export class Lowerer {
3760
4068
  // resolveValueSymbol also flushes deferred diagnostics and applies
3761
4069
  // merged-namespace fences, whose authority remains ordinary lowering.
3762
4070
  this.checker.prefetchSymbolRoots(sourceFiles, true);
4071
+ // The facts each fixed-point site reads, by the symbols, nodes and
4072
+ // element keys they belong to (created with the site list below).
4073
+ let siteDependencies = null;
3763
4074
  const symbolOf = (node) => {
3764
4075
  const s = this.checker.getSymbolAtLocation(node);
3765
4076
  if (!s)
3766
4077
  return null;
3767
- return s.flags & ts.SymbolFlags.Alias ? this.checker.getAliasedSymbol(s) : s;
4078
+ const symbol = s.flags & ts.SymbolFlags.Alias ? this.checker.getAliasedSymbol(s) : s;
4079
+ siteDependencies?.read(symbol);
4080
+ return symbol;
3768
4081
  };
3769
4082
  const signatureOf = (node) => {
3770
4083
  const symbol = symbolOf(node);
@@ -3932,8 +4245,11 @@ export class Lowerer {
3932
4245
  const callableSymbols = new Map();
3933
4246
  const callableSymbolOf = (node) => {
3934
4247
  const cached = callableSymbols.get(node);
3935
- if (cached !== undefined)
4248
+ if (cached !== undefined) {
4249
+ if (cached !== null)
4250
+ siteDependencies?.read(cached);
3936
4251
  return cached;
4252
+ }
3937
4253
  let symbol = symbolOf(ts.isPropertyAccessExpression(node) ? node.name : node);
3938
4254
  if (symbol === null || signatureBySymbol.has(symbol)) {
3939
4255
  callableSymbols.set(node, symbol);
@@ -4241,8 +4557,11 @@ export class Lowerer {
4241
4557
  return true;
4242
4558
  if (ts.isPropertyAccessExpression(e) && isOsConstantsSymbol(symbolOf(e.expression), this))
4243
4559
  return true;
4244
- if (ts.isCallExpression(e) && this.runtimeOptionalReduceTypes.has(e))
4245
- return true;
4560
+ if (ts.isCallExpression(e)) {
4561
+ siteDependencies?.read(e);
4562
+ if (this.runtimeOptionalReduceTypes.has(e))
4563
+ return true;
4564
+ }
4246
4565
  if (ts.isCallExpression(e) &&
4247
4566
  e.arguments.nodes.length === 0 &&
4248
4567
  ts.isPropertyAccessExpression(e.expression) &&
@@ -4747,6 +5066,7 @@ export class Lowerer {
4747
5066
  if (fnType?.kind === "func" && bodyReturnsOptional(fn)) {
4748
5067
  const widenedReturn = this.runtimeOptionalType(fnType.ret);
4749
5068
  provenance?.note("callback-return", fn, provenanceSite);
5069
+ siteDependencies?.read(fn);
4750
5070
  const previousReturn = this.runtimeOptionalFunctionReturnType(fn, fnType.ret);
4751
5071
  this.runtimeOptionalFunctionReturns.set(fn, widenedReturn);
4752
5072
  if (!typeEquals(previousReturn, widenedReturn))
@@ -4989,8 +5309,11 @@ export class Lowerer {
4989
5309
  const key = typeKey(arm.elem);
4990
5310
  if (arm.elem.kind === "union"
4991
5311
  ? this.armTag(arm.elem.unionId, UNDEFINED_T) >= 0
4992
- : isUnitType(arm.elem) || arm.elem.kind === "void")
5312
+ : isUnitType(arm.elem) || arm.elem.kind === "void") {
5313
+ if (!optionalElementKeys.has(key))
5314
+ siteDependencies?.changed(key);
4993
5315
  optionalElementKeys.add(key);
5316
+ }
4994
5317
  keys.push(key);
4995
5318
  }
4996
5319
  return keys;
@@ -5102,7 +5425,10 @@ export class Lowerer {
5102
5425
  return keys;
5103
5426
  };
5104
5427
  const elementStates = new ArrayElementStates({
5105
- elementAdmitsUndefined: (key) => optionalElementKeys.has(key),
5428
+ elementAdmitsUndefined: (key) => {
5429
+ siteDependencies?.read(key);
5430
+ return optionalElementKeys.has(key);
5431
+ },
5106
5432
  ownerOf: (node) => ownership.ownerOf(node),
5107
5433
  allocationOwner: (node) => ownership.allocationOwner(node),
5108
5434
  arrayKeys: arrayKeysOf,
@@ -5177,6 +5503,8 @@ export class Lowerer {
5177
5503
  note: provenance
5178
5504
  ? (fact, key, site) => provenance.note(`element-${fact}`, site, site, key)
5179
5505
  : null,
5506
+ read: (fact) => siteDependencies?.read(fact),
5507
+ changed: (fact) => siteDependencies?.changed(fact),
5180
5508
  });
5181
5509
  // Each pass revisits every array callback site; the last visit holds
5182
5510
  // the decision at the fixed point.
@@ -5461,6 +5789,7 @@ export class Lowerer {
5461
5789
  if (promoteHofCallback(callback, [0, 1]))
5462
5790
  changed = true;
5463
5791
  const result = this.runtimeOptionalType(this.irTypeOf(node));
5792
+ siteDependencies?.read(node);
5464
5793
  const previous = this.runtimeOptionalReduceTypes.get(node);
5465
5794
  if (!previous || !typeEquals(previous, result)) {
5466
5795
  this.runtimeOptionalReduceTypes.set(node, result);
@@ -5518,6 +5847,7 @@ export class Lowerer {
5518
5847
  (this.typeOf(arg).flags & (ts.TypeFlags.Undefined | ts.TypeFlags.Void)) === 0)
5519
5848
  continue;
5520
5849
  for (const target of familyBySymbol.get(symbol) ?? [symbol]) {
5850
+ siteDependencies?.read(target);
5521
5851
  const shape = signatureBySymbol.get(target)?.params[i];
5522
5852
  if (!shape || shape.mode !== "required")
5523
5853
  continue;
@@ -5557,6 +5887,7 @@ export class Lowerer {
5557
5887
  if (!ts.isSpreadElement(arg) && shape && i !== restAt && fieldsOfValue(arg)) {
5558
5888
  const fields = fieldsOfValue(arg);
5559
5889
  for (const target of familyBySymbol.get(symbol) ?? [symbol]) {
5890
+ siteDependencies?.read(target);
5560
5891
  const parameterShape = signatureBySymbol.get(target)?.params[i];
5561
5892
  const parameter = functionDeclBySymbol.get(target)?.parameters?.nodes[i];
5562
5893
  if (!parameterShape || parameterShape.type.kind !== "record")
@@ -5608,6 +5939,7 @@ export class Lowerer {
5608
5939
  // argument can make its elements undefined, not the pack.
5609
5940
  // Keep every virtual implementation on the same array ABI.
5610
5941
  for (const target of familyBySymbol.get(symbol) ?? [symbol]) {
5942
+ siteDependencies?.read(target);
5611
5943
  const rest = signatureBySymbol.get(target)?.params[i];
5612
5944
  if (rest?.mode !== "rest" || rest.type.kind !== "array")
5613
5945
  continue;
@@ -5632,6 +5964,7 @@ export class Lowerer {
5632
5964
  // downstream calls and returns see the same optional value.
5633
5965
  const family = familyBySymbol.get(symbol);
5634
5966
  for (const target of family ?? [symbol]) {
5967
+ siteDependencies?.read(target);
5635
5968
  const parameterShape = signatureBySymbol.get(target)?.params[i];
5636
5969
  if (!parameterShape)
5637
5970
  continue;
@@ -5658,9 +5991,23 @@ export class Lowerer {
5658
5991
  });
5659
5992
  }
5660
5993
  };
5661
- for (const node of sitesOf(sf))
5662
- scan(node);
5663
- return changed;
5994
+ // A site whose facts are unchanged since its last visit would compute
5995
+ // that visit's result again, except in a full pass.
5996
+ const base = siteBase.get(sf);
5997
+ const dependencies = siteDependencies;
5998
+ const sites = sitesOf(sf);
5999
+ let fileChanged = false;
6000
+ for (let i = 0; i < sites.length; i++) {
6001
+ if (!fullPass && !dependencies.isStale(base + i))
6002
+ continue;
6003
+ changed = false;
6004
+ dependencies.begin(base + i);
6005
+ scan(sites[i]);
6006
+ dependencies.end(changed);
6007
+ if (changed)
6008
+ fileChanged = true;
6009
+ }
6010
+ return fileChanged;
5664
6011
  };
5665
6012
  const scanReturns = (symbol, decl) => {
5666
6013
  let changed = false;
@@ -5711,12 +6058,26 @@ export class Lowerer {
5711
6058
  optionalSymbols.add(symbol);
5712
6059
  this.earlyReadVars.add(symbol);
5713
6060
  }
5714
- let changed = true;
5715
- while (changed) {
6061
+ // Number the sites of every file. The first and the last pass visit
6062
+ // every site; the passes between visit only the sites whose facts
6063
+ // changed (SiteDependencies). When such a pass changes nothing, a full
6064
+ // pass confirms the fixed point, and the iteration resumes if it
6065
+ // changes a fact after all.
6066
+ const siteBase = new Map();
6067
+ let siteCount = 0;
6068
+ for (const sf of sourceFiles) {
6069
+ siteBase.set(sf, siteCount);
6070
+ siteCount += sitesOf(sf).length;
6071
+ }
6072
+ siteDependencies = new SiteDependencies(siteCount);
6073
+ let fullPass = true;
6074
+ for (let changed = true, first = true; changed || !fullPass; first = false) {
6075
+ fullPass = first || !changed;
5716
6076
  changed = false;
5717
6077
  for (const [symbol, field] of staticFieldsBySymbol) {
5718
6078
  if (!optionalSymbols.has(symbol) && mayBeOptional(field.initializer)) {
5719
6079
  optionalSymbols.add(symbol);
6080
+ siteDependencies.changed(symbol);
5720
6081
  provenance?.note("static-field", field.initializer.parent, field.initializer);
5721
6082
  changed = true;
5722
6083
  }
@@ -5724,15 +6085,19 @@ export class Lowerer {
5724
6085
  for (const sf of sourceFiles)
5725
6086
  if (scanFile(sf))
5726
6087
  changed = true;
5727
- for (const [symbol, decl] of functionDeclBySymbol)
5728
- if (scanReturns(symbol, decl))
5729
- changed = true;
6088
+ for (const [symbol, decl] of functionDeclBySymbol) {
6089
+ if (!scanReturns(symbol, decl))
6090
+ continue;
6091
+ siteDependencies.changed(symbol);
6092
+ changed = true;
6093
+ }
5730
6094
  const noteGenericReturn = (symbol, decl) => {
5731
6095
  if (optionalReturns.has(symbol) || isJsSourceFile(ts.getSourceFileOfNode(decl)))
5732
6096
  return;
5733
6097
  if (!returnsOf(decl).some(genericMayBeOptional))
5734
6098
  return;
5735
6099
  optionalReturns.add(symbol);
6100
+ siteDependencies.changed(symbol);
5736
6101
  this.runtimeOptionalGenericReturns.add(decl);
5737
6102
  provenance?.note("return", decl.name ?? decl, decl);
5738
6103
  changed = true;
@@ -5770,6 +6135,7 @@ export class Lowerer {
5770
6135
  : previous;
5771
6136
  if (!typeEquals(previous, next)) {
5772
6137
  this.runtimeOptionalFunctionReturns.set(fn, next);
6138
+ siteDependencies.changed(fn);
5773
6139
  provenance?.note("lambda-return", fn, fn.body);
5774
6140
  changed = true;
5775
6141
  }
@@ -5785,11 +6151,13 @@ export class Lowerer {
5785
6151
  if (symbol && next.kind === "union" && this.armTag(next.unionId, UNDEFINED_T) >= 0) {
5786
6152
  if (!optionalReturns.has(symbol)) {
5787
6153
  optionalReturns.add(symbol);
6154
+ siteDependencies.changed(symbol);
5788
6155
  changed = true;
5789
6156
  }
5790
6157
  }
5791
6158
  else if (symbol && !arithmeticReturns.has(symbol)) {
5792
6159
  arithmeticReturns.set(symbol, next);
6160
+ siteDependencies.changed(symbol);
5793
6161
  changed = true;
5794
6162
  }
5795
6163
  }
@@ -5808,6 +6176,7 @@ export class Lowerer {
5808
6176
  : this.runtimeOptionalType(previous);
5809
6177
  if (!typeEquals(previous, next)) {
5810
6178
  this.runtimeOptionalFunctionReturns.set(fn, next);
6179
+ siteDependencies.changed(fn);
5811
6180
  changed = true;
5812
6181
  }
5813
6182
  }
@@ -5822,6 +6191,7 @@ export class Lowerer {
5822
6191
  for (const symbol of optional ? family : []) {
5823
6192
  if (!optionalReturns.has(symbol)) {
5824
6193
  optionalReturns.add(symbol);
6194
+ siteDependencies.changed(symbol);
5825
6195
  provenance?.note("return", functionDeclBySymbol.get(symbol), undefined, "(override family)");
5826
6196
  changed = true;
5827
6197
  }
@@ -5838,10 +6208,14 @@ export class Lowerer {
5838
6208
  if (previous && typeEquals(previous, joined))
5839
6209
  continue;
5840
6210
  arithmeticReturns.set(symbol, joined);
6211
+ siteDependencies.changed(symbol);
5841
6212
  changed = true;
5842
6213
  }
5843
6214
  }
5844
6215
  }
6216
+ // The site facts serve only the fixed point; release them for the rest
6217
+ // of lowering.
6218
+ siteDependencies = null;
5845
6219
  // NaN-coded slots convert optional values on entry instead of holding
5846
6220
  // the union, so promotion never applies to them.
5847
6221
  for (const symbol of [...optionalSymbols])
@@ -6195,7 +6569,7 @@ export class Lowerer {
6195
6569
  for (const decl of fp.classDecls) {
6196
6570
  const info = this.classes.get(this.classNamer(decl));
6197
6571
  if (info)
6198
- functions.push(...this.lowerClassMembers(info));
6572
+ functions.push(...this.withClosureRoot(info.def.name, () => this.lowerClassMembers(info)));
6199
6573
  else if (this.countsSkips())
6200
6574
  this.countSkippedBody(decl);
6201
6575
  }
@@ -6208,7 +6582,8 @@ export class Lowerer {
6208
6582
  // are reachable by definition, already counted by reachable emit.
6209
6583
  if (!this.remainder) {
6210
6584
  for (const fp of parts) {
6211
- functions.push(this.lowerFileInit(fp.sf, fp.topStmts, this.initNameOf.get(fp.sf)));
6585
+ const initName = this.initNameOf.get(fp.sf);
6586
+ functions.push(this.withClosureRoot(initName, () => this.lowerFileInit(fp.sf, fp.topStmts, initName)));
6212
6587
  }
6213
6588
  functions.push(this.buildMain());
6214
6589
  }
@@ -6248,7 +6623,7 @@ export class Lowerer {
6248
6623
  // default): the diagnostic is recorded — the instance skips
6249
6624
  // like a signature-blocked function (lowerFunction's rule).
6250
6625
  try {
6251
- functions.push(this.lowerGenericInstance(info, inst));
6626
+ functions.push(this.withClosureRoot(inst.name, () => this.lowerGenericInstance(info, inst)));
6252
6627
  }
6253
6628
  catch (e) {
6254
6629
  if (!(e instanceof PoisonError))
@@ -6260,7 +6635,8 @@ export class Lowerer {
6260
6635
  // instances of its own; the joint fixpoint covers both).
6261
6636
  while (es < this.emitSpecQueue.length) {
6262
6637
  try {
6263
- const fn = lowerEmitOverrideSpec(this, this.emitSpecQueue[es++]);
6638
+ const spec = this.emitSpecQueue[es++];
6639
+ const fn = this.withClosureRoot(emitSpecRoot(spec), () => lowerEmitOverrideSpec(this, spec));
6264
6640
  if (fn)
6265
6641
  functions.push(fn);
6266
6642
  }
@@ -6278,6 +6654,7 @@ export class Lowerer {
6278
6654
  // Lambdas lifted while lowering any of the above (plus synthetic
6279
6655
  // array-HOF loop functions, which ride the same list), and the
6280
6656
  // implicit-any instances lowered eagerly at their first call sites.
6657
+ this.settleSharedHelperLocations([...functions, ...this.liftedFns, ...this.implicitFns]);
6281
6658
  functions.push(...this.liftedFns);
6282
6659
  functions.push(...this.implicitFns);
6283
6660
  functions.push(...runtimeClassConstructs(this, functions));
@@ -6409,7 +6786,7 @@ export class Lowerer {
6409
6786
  classes: artifacts.classes,
6410
6787
  records: artifacts.records,
6411
6788
  unions: artifacts.unions,
6412
- globals: this.globalsList,
6789
+ globals: this.globalsInTableOrder(),
6413
6790
  entry: ENTRY_NAME,
6414
6791
  ...(this.usesWorkers ? { workers: true } : {}),
6415
6792
  ...(this.usesLifetimeRegions ? { lifetimeRegions: true } : {}),
@@ -6538,6 +6915,10 @@ export class Lowerer {
6538
6915
  * body; both fire edges through the same hooks and are not units
6539
6916
  * themselves. */
6540
6917
  emitReachable(extraRoots) {
6918
+ // Frontend passes below rewrite function bodies through the IR mapper
6919
+ // (caught-value and class dispatch); key-order notes follow the record
6920
+ // literals they rebuild until the witness pass has read them.
6921
+ observeRecordLiteralRebuilds((from, to) => this.keyOrder.follow(from, to));
6541
6922
  this.deferredModuleInitializers = new DeferredModuleInitializers();
6542
6923
  const parts = this.splitFiles();
6543
6924
  this.narrowing.setFiles(parts.map((fp) => fp.sf));
@@ -6790,7 +7171,8 @@ export class Lowerer {
6790
7171
  rank: [4, instanceMetadataOrder++],
6791
7172
  };
6792
7173
  this.genericClassDemandPriority.set(info, ref);
6793
- instanceFunctions.push(...this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(ref, () => this.lowerClassMembers(info))));
7174
+ instanceFunctions.push(...this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(ref, () => this.withClosureRoot(info.def.name, () => this.lowerClassMembers(info)))));
7175
+ relieveHeapPressure();
6794
7176
  }
6795
7177
  }
6796
7178
  while (instLowered < this.instantiationQueue.length) {
@@ -6809,7 +7191,8 @@ export class Lowerer {
6809
7191
  // Body-level poisons skip the instance after retaining the
6810
7192
  // diagnostic and every edge fired before poisoning.
6811
7193
  try {
6812
- instanceFunctions.push(this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(ref, () => this.lowerGenericInstance(info, inst))));
7194
+ instanceFunctions.push(this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(ref, () => this.withClosureRoot(inst.name, () => this.lowerGenericInstance(info, inst)))));
7195
+ relieveHeapPressure();
6813
7196
  }
6814
7197
  catch (e) {
6815
7198
  if (!(e instanceof PoisonError))
@@ -6822,12 +7205,21 @@ export class Lowerer {
6822
7205
  // exactly like generic instances.
6823
7206
  while (specLowered < this.emitSpecQueue.length) {
6824
7207
  const waveEnd = this.emitSpecQueue.length;
7208
+ // A wave's specializations lower by class and event, not in the
7209
+ // order bodies asked for them.
7210
+ const wave = this.emitSpecQueue.slice(specLowered, waveEnd);
7211
+ const specKey = ({ info, event }) => `${info.def.name}\0${event}`;
7212
+ wave.sort((left, right) => specKey(left) < specKey(right) ? -1 : specKey(left) > specKey(right) ? 1 : 0);
7213
+ this.emitSpecQueue.splice(specLowered, wave.length, ...wave);
6825
7214
  this.checker.prefetchRoots(this.emitSpecQueue
6826
7215
  .slice(specLowered, waveEnd)
6827
7216
  .flatMap(({ info }) => info.emitOverride ? functionRoots(info.emitOverride.decl) : []));
6828
7217
  while (specLowered < waveEnd) {
6829
7218
  try {
6830
- const fn = this.shapes.withDeclaredOrderPriority([4, instanceMetadataOrder++], () => lowerEmitOverrideSpec(this, this.emitSpecQueue[specLowered++]));
7219
+ const fn = this.shapes.withDeclaredOrderPriority([4, instanceMetadataOrder++], () => {
7220
+ const spec = this.emitSpecQueue[specLowered++];
7221
+ return this.withClosureRoot(emitSpecRoot(spec), () => lowerEmitOverrideSpec(this, spec));
7222
+ });
6831
7223
  if (fn)
6832
7224
  instanceFunctions.push(fn);
6833
7225
  }
@@ -6854,7 +7246,7 @@ export class Lowerer {
6854
7246
  parts.forEach((fp, index) => {
6855
7247
  const priority = [2, index];
6856
7248
  const owner = demandOwner(priority);
6857
- initFunctions.push(this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(priority, () => this.lowerFileInit(fp.sf, fp.topStmts, this.initNameOf.get(fp.sf)))));
7249
+ initFunctions.push(this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(priority, () => this.withClosureRoot(this.initNameOf.get(fp.sf), () => this.lowerFileInit(fp.sf, fp.topStmts, this.initNameOf.get(fp.sf))))));
6858
7250
  });
6859
7251
  // LIBRARY mode's extra reachability roots (LowerOptions.libRoots): the
6860
7252
  // profile-mapped exports are called from outside the graph, so they
@@ -6862,9 +7254,11 @@ export class Lowerer {
6862
7254
  // (the export-map resolution reports them as SC4002 later).
6863
7255
  for (const root of extraRoots ?? [])
6864
7256
  this.onEdge?.(root);
7257
+ const shuffle = lowerShuffle();
6865
7258
  const drainUnits = () => {
6866
7259
  while (queue.length > 0) {
6867
7260
  const wave = queue.splice(0);
7261
+ shuffle?.(wave);
6868
7262
  this.checker.prefetchRoots(wave.flatMap((name) => units.get(name).roots));
6869
7263
  for (const name of wave) {
6870
7264
  // A body-level poison outside the per-statement catches (a fenced
@@ -6875,9 +7269,10 @@ export class Lowerer {
6875
7269
  const unit = units.get(name);
6876
7270
  const priority = metadataPriority.get(name) ?? [3, expressionMetadataOrder++];
6877
7271
  const owner = demandOwner(priority);
6878
- const fn = this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(priority, unit.lower));
7272
+ const fn = this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(priority, () => this.withClosureRoot(name, unit.lower)));
6879
7273
  if (fn)
6880
7274
  loweredUnits.set(name, fn);
7275
+ relieveHeapPressure();
6881
7276
  }
6882
7277
  catch (e) {
6883
7278
  if (!(e instanceof PoisonError))
@@ -6893,22 +7288,29 @@ export class Lowerer {
6893
7288
  // turn queue more instances. Continue to the joint fixpoint; the initial
6894
7289
  // queue above is the only portion whose discovery order differed from
6895
7290
  // historical emit order.
7291
+ noteDateClassMethods(this);
6896
7292
  const classDispatch = new ClassDynamicDispatch(extraRoots !== undefined);
7293
+ // Units in declaration order, so the passes below meet functions, and the
7294
+ // classes they collect, in an order that does not depend on lowering order.
7295
+ const unitsInOrder = () => [...loweredUnits]
7296
+ .sort(([left], [right]) => units.get(left).order - units.get(right).order)
7297
+ .map(([, fn]) => fn);
6897
7298
  for (;;) {
6898
7299
  drainInstances();
7300
+ const declared = unitsInOrder();
6899
7301
  const initializerChanged = this.deferredModuleInitializers.process(this, [
6900
- ...loweredUnits.values(),
7302
+ ...declared,
6901
7303
  ...initFunctions,
6902
7304
  ...instanceFunctions,
6903
- ...this.liftedFns,
6904
- ...this.implicitFns,
6905
- ]);
7305
+ ...byName(this.liftedFns),
7306
+ ...byName(this.implicitFns),
7307
+ ], (fn) => classDispatch.sites.forget(fn));
6906
7308
  const dispatchChanged = classDispatch.process(this, [
6907
- ...loweredUnits.values(),
7309
+ ...declared,
6908
7310
  ...initFunctions,
6909
7311
  ...instanceFunctions,
6910
- ...this.liftedFns,
6911
- ...this.implicitFns,
7312
+ ...byName(this.liftedFns),
7313
+ ...byName(this.implicitFns),
6912
7314
  ]);
6913
7315
  if (queue.length === 0 && !dispatchChanged && !initializerChanged)
6914
7316
  break;
@@ -6917,9 +7319,7 @@ export class Lowerer {
6917
7319
  this.restoreGenericClassInstanceOrder(clsInstLowered);
6918
7320
  }
6919
7321
  classDispatch.finalize(this);
6920
- const orderedUnits = [...loweredUnits]
6921
- .sort(([left], [right]) => units.get(left).order - units.get(right).order)
6922
- .map(([, fn]) => fn);
7322
+ const orderedUnits = unitsInOrder();
6923
7323
  this.settleGenericDemandPriorities();
6924
7324
  this.shapes.settleDeclaredOrderPriorities();
6925
7325
  for (const finalize of this.shapeOrderMetadataFinalizers)
@@ -6931,15 +7331,25 @@ export class Lowerer {
6931
7331
  ...this.liftedFns,
6932
7332
  ...this.implicitFns,
6933
7333
  ]);
7334
+ observeRecordLiteralRebuilds(null);
6934
7335
  for (const finalize of this.shapeOrderHelperFinalizers)
6935
7336
  finalize();
6936
- const functions = [
7337
+ this.settleSharedHelperLocations([
6937
7338
  ...orderedUnits,
6938
7339
  ...initFunctions,
6939
- this.buildMain(),
6940
7340
  ...instanceFunctions,
6941
7341
  ...this.liftedFns,
6942
7342
  ...this.implicitFns,
7343
+ ]);
7344
+ // Lifted and implicit functions are created in lowering order; they
7345
+ // are assembled by name.
7346
+ const functions = [
7347
+ ...orderedUnits,
7348
+ ...initFunctions,
7349
+ this.buildMain(),
7350
+ ...instanceFunctions,
7351
+ ...byName(this.liftedFns),
7352
+ ...byName(this.implicitFns),
6943
7353
  ];
6944
7354
  functions.push(...runtimeClassConstructs(this, functions));
6945
7355
  if (this.regexGroupResults)
@@ -7323,7 +7733,36 @@ export class Lowerer {
7323
7733
  fenceStaticReadableStreamMember(access, use) {
7324
7734
  return fenceStaticReadableStreamMember(this, access, use);
7325
7735
  }
7736
+ /** Whether `node` reads an anySymbols parameter, or a member, element or
7737
+ * call result of one: the error-path copy of a callback reads those as
7738
+ * `any`. */
7739
+ readsAnySymbol(node) {
7740
+ let base = node;
7741
+ for (;;) {
7742
+ if (ts.isPropertyAccessExpression(base) ||
7743
+ ts.isElementAccessExpression(base) ||
7744
+ ts.isNonNullExpression(base) ||
7745
+ ts.isParenthesizedExpression(base)) {
7746
+ base = base.expression;
7747
+ }
7748
+ else if (ts.isCallExpression(base) && ts.isPropertyAccessExpression(base.expression)) {
7749
+ base = base.expression.expression;
7750
+ }
7751
+ else {
7752
+ break;
7753
+ }
7754
+ }
7755
+ if (!ts.isIdentifier(base))
7756
+ return false;
7757
+ const parent = base.parent;
7758
+ const symbol = parent !== undefined && ts.isShorthandPropertyAssignment(parent) && parent.name === base
7759
+ ? this.checker.getShorthandAssignmentValueSymbol(parent)
7760
+ : this.checker.getSymbolAtLocation(base);
7761
+ return symbol !== undefined && this.anySymbols.has(symbol);
7762
+ }
7326
7763
  typeOf(node) {
7764
+ if (this.anySymbols.size > 0 && this.readsAnySymbol(node))
7765
+ return this.checker.getAnyType();
7327
7766
  if (ts.isPropertyAccessExpression(node) && isJsSourceFile(ts.getSourceFileOfNode(node))) {
7328
7767
  const receiver = node.expression.kind === ts.SyntaxKind.ThisKeyword && this.fnStack.length > 0
7329
7768
  ? this.resolveThis()?.type
@@ -7598,8 +8037,9 @@ export class Lowerer {
7598
8037
  /** The ts-level twin of typeParamResolver: the bound CHECKER type of a
7599
8038
  * type parameter in the current instantiation (typeParamTsBindings), for
7600
8039
  * the resolutions where mapType's widening already dropped what the body
7601
- * needs (indexed accesses over literal-bound keys). Inert outside
7602
- * call-keyed generic instantiation. */
8040
+ * needs (indexed accesses over literal-bound keys, conditional types
8041
+ * over literal arguments). Inert outside generic function and class
8042
+ * instantiation. */
7603
8043
  typeParamTsResolver = (t) => {
7604
8044
  if (!this.typeParamTsBindings || !(t.flags & ts.TypeFlags.TypeParameter))
7605
8045
  return null;
@@ -8453,6 +8893,19 @@ export class Lowerer {
8453
8893
  * directly when the expression was already lowered. */
8454
8894
  coerceInto(node, expr, expected) {
8455
8895
  refuseInferredCallbackDrops(this, node, expr.type, expected);
8896
+ // An assertion's scalar check whose value goes straight back into a
8897
+ // checked-dynamic slot (`process.loadEnvFile({} as unknown as string)`)
8898
+ // keeps the original value: JavaScript erases assertions, so the check
8899
+ // could only add a TypeError Node does not throw, and the slot holds
8900
+ // the value either way.
8901
+ if (expected.kind === "dyn" && expr.kind === "dynCheck" && expr.value.type.kind === "dyn") {
8902
+ let source = node;
8903
+ while (ts.isParenthesizedExpression(source))
8904
+ source = source.expression;
8905
+ if ((ts.isAsExpression(source) || ts.isTypeAssertion(source)) &&
8906
+ (expr.type.kind === "string" || expr.type.kind === "f64" || expr.type.kind === "bool"))
8907
+ return expr.value;
8908
+ }
8456
8909
  // A union destination can accept the binding's tagged storage directly.
8457
8910
  // The checker's single-arm flow type can be stale after a callback writes
8458
8911
  // the binding. Extracting that arm and wrapping it again would discard the
@@ -8725,6 +9178,9 @@ export class Lowerer {
8725
9178
  // retain their own checked conversion and must not be erased here.
8726
9179
  while (ts.isParenthesizedExpression(node) || ts.isSatisfiesExpression(node))
8727
9180
  node = node.expression;
9181
+ const staged = this.stagedArgument(node);
9182
+ if (staged)
9183
+ return expected ? this.coerceInto(node, staged, expected) : staged;
8728
9184
  if (expected) {
8729
9185
  if (ts.isConditionalExpression(node))
8730
9186
  return lowerTernary(this, node, expected);
@@ -10453,10 +10909,23 @@ export class Lowerer {
10453
10909
  }
10454
10910
  /* ── expressions ──────────────────────────────────────────────────── */
10455
10911
  lowerExpr(expr) {
10456
- const hash = this.hashStreamReceivers.get(expr);
10457
- if (hash)
10458
- return hashStreamOf(varRef(hash.localId, hash.type, locOf(expr)));
10459
- return lowerExpr(this, expr);
10912
+ const streamValue = this.valueStreamReceivers.get(expr);
10913
+ if (streamValue)
10914
+ return valueStreamOf(varRef(streamValue.localId, streamValue.type, locOf(expr)));
10915
+ return this.stagedArgument(expr) ?? lowerExpr(this, expr);
10916
+ }
10917
+ /** The saved value of a staged fs argument (stagedArguments, keyed
10918
+ * without type-only wrappers), or null for every other expression. */
10919
+ stagedArgument(node) {
10920
+ if (this.stagedArguments.size === 0)
10921
+ return null;
10922
+ node = stripTypeWrappers(node);
10923
+ if (!this.stagedArguments.has(node))
10924
+ return null;
10925
+ const slot = this.stagedArguments.get(node);
10926
+ if (!slot)
10927
+ throw new InternalCompilerError("an fs argument lowered before the URL path it follows");
10928
+ return varRef(slot.localId, slot.type, locOf(node));
10460
10929
  }
10461
10930
  lowerIntrinsicProperty(expr) {
10462
10931
  // The builtin-spoke property extensions (Stats.mtimeMs,
@@ -10715,6 +11184,25 @@ export class Lowerer {
10715
11184
  return lower();
10716
11185
  return this.withExpressionOverride(node, this.checkedNarrowCall(helper, optional.value, optional.present, locOf(node)), lower);
10717
11186
  }
11187
+ /** withExpressionOverride for several nodes at once. */
11188
+ withExpressionOverrides(overrides, lower) {
11189
+ const previous = overrides.map((override) => this.chainRecvByNode.get(override.node));
11190
+ for (const override of overrides)
11191
+ this.chainRecvByNode.set(override.node, override.value);
11192
+ try {
11193
+ return lower();
11194
+ }
11195
+ finally {
11196
+ for (let i = overrides.length - 1; i >= 0; i--) {
11197
+ const node = overrides[i].node;
11198
+ const value = previous[i];
11199
+ if (value)
11200
+ this.chainRecvByNode.set(node, value);
11201
+ else
11202
+ this.chainRecvByNode.delete(node);
11203
+ }
11204
+ }
11205
+ }
10718
11206
  withExpressionOverride(node, value, lower) {
10719
11207
  const previous = this.chainRecvByNode.get(node);
10720
11208
  this.chainRecvByNode.set(node, value);
@@ -10736,7 +11224,8 @@ export class Lowerer {
10736
11224
  if (webAssembly !== null)
10737
11225
  return webAssembly;
10738
11226
  refuseWebAssemblyUse(this, expr.expression);
10739
- return (lowerLifetimeRegionCall(this, expr) ??
11227
+ return (lowerErrorFunctionCall(this, expr) ??
11228
+ lowerLifetimeRegionCall(this, expr) ??
10740
11229
  lowerInternTableCall(this, expr) ??
10741
11230
  lowerThreadSlotsCall(this, expr) ??
10742
11231
  lowerFfiCall(this, expr) ??
@@ -10752,6 +11241,7 @@ export class Lowerer {
10752
11241
  lowerWebCryptoCall(this, expr) ??
10753
11242
  lowerKeyObjectCall(this, expr) ??
10754
11243
  lowerEcdhCall(this, expr) ??
11244
+ lowerDiffieHellmanCall(this, expr) ??
10755
11245
  lowerNetAddressCall(this, expr) ??
10756
11246
  lowerFetchElementMethodCall(this, expr) ??
10757
11247
  lowerDynamicImportCall(this, expr) ??
@@ -11259,6 +11749,10 @@ export class Lowerer {
11259
11749
  if (callable)
11260
11750
  return callable;
11261
11751
  }
11752
+ // node:crypto's webcrypto is the WebCrypto global's object.
11753
+ if (bi.module === "crypto" && bi.member === "webcrypto") {
11754
+ return { kind: "libCall", fn: "webcrypto.object", args: [], type: DYN, loc };
11755
+ }
11262
11756
  // node:stream/web's exports are the web stream globals themselves: in
11263
11757
  // JavaScript sources the same identity token as the global spelling
11264
11758
  // (`require("stream/web").ReadableStream === globalThis.ReadableStream`).
@@ -11328,7 +11822,7 @@ export class Lowerer {
11328
11822
  const key = `${fn.valueFn ?? fn.fn}:${typeKey(funcType)}:${adapterShape}`;
11329
11823
  let fnName = this.builtinCallableValueFns.get(key);
11330
11824
  if (!fnName) {
11331
- fnName = `%builtin.value.${fn.valueFn ?? fn.fn}.${this.builtinCallableValueFns.size}`;
11825
+ fnName = keyedHelperName(this, `%builtin.value.${fn.valueFn ?? fn.fn}`, key);
11332
11826
  this.builtinCallableValueFns.set(key, fnName);
11333
11827
  this.builtinCallableValueNames.set(fnName, display.slice(display.lastIndexOf(".") + 1));
11334
11828
  const params = funcType.params.map((type, index) => ({