@scriptc/compiler 0.4.2 → 0.4.3

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 (636) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +397 -37
  2. package/dist/backend/cycle-analysis.d.ts +4 -1
  3. package/dist/backend/cycle-analysis.js +6 -4
  4. package/dist/backend/cycle-analysis.js.map +1 -1
  5. package/dist/backend/cycle-analysis.test.js +55 -0
  6. package/dist/backend/cycle-analysis.test.js.map +1 -1
  7. package/dist/backend/cycle-mutability.d.ts +7 -0
  8. package/dist/backend/cycle-mutability.js +19 -1
  9. package/dist/backend/cycle-mutability.js.map +1 -1
  10. package/dist/backend/executable-features.js +2 -0
  11. package/dist/backend/executable-features.js.map +1 -1
  12. package/dist/backend/immutability.d.ts +6 -3
  13. package/dist/backend/immutability.js +33 -29
  14. package/dist/backend/immutability.js.map +1 -1
  15. package/dist/backend/library-pack.js +1 -0
  16. package/dist/backend/library-pack.js.map +1 -1
  17. package/dist/backend/llvm/alloc.d.ts +16 -1
  18. package/dist/backend/llvm/alloc.js +54 -4
  19. package/dist/backend/llvm/alloc.js.map +1 -1
  20. package/dist/backend/llvm/appended-array-literals.d.ts +2 -1
  21. package/dist/backend/llvm/appended-array-literals.js +44 -36
  22. package/dist/backend/llvm/appended-array-literals.js.map +1 -1
  23. package/dist/backend/llvm/appended-array-literals.test.js +4 -3
  24. package/dist/backend/llvm/appended-array-literals.test.js.map +1 -1
  25. package/dist/backend/llvm/array-search.d.ts +4 -3
  26. package/dist/backend/llvm/array-search.js +21 -9
  27. package/dist/backend/llvm/array-search.js.map +1 -1
  28. package/dist/backend/llvm/blocks.d.ts +1 -1
  29. package/dist/backend/llvm/blocks.js +2 -2
  30. package/dist/backend/llvm/blocks.js.map +1 -1
  31. package/dist/backend/llvm/byte-windows.js +2 -0
  32. package/dist/backend/llvm/byte-windows.js.map +1 -1
  33. package/dist/backend/llvm/bytes-alias.d.ts +6 -1
  34. package/dist/backend/llvm/bytes-alias.js +8 -2
  35. package/dist/backend/llvm/bytes-alias.js.map +1 -1
  36. package/dist/backend/llvm/bytes-loop-versions.d.ts +47 -5
  37. package/dist/backend/llvm/bytes-loop-versions.js +473 -32
  38. package/dist/backend/llvm/bytes-loop-versions.js.map +1 -1
  39. package/dist/backend/llvm/bytes-loop-versions.test.js +258 -2
  40. package/dist/backend/llvm/bytes-loop-versions.test.js.map +1 -1
  41. package/dist/backend/llvm/checked-value-lifetimes.js +2 -0
  42. package/dist/backend/llvm/checked-value-lifetimes.js.map +1 -1
  43. package/dist/backend/llvm/classes.d.ts +7 -5
  44. package/dist/backend/llvm/classes.js +44 -20
  45. package/dist/backend/llvm/classes.js.map +1 -1
  46. package/dist/backend/llvm/classes.test.js +167 -7
  47. package/dist/backend/llvm/classes.test.js.map +1 -1
  48. package/dist/backend/llvm/common.d.ts +9 -3
  49. package/dist/backend/llvm/common.js +9 -3
  50. package/dist/backend/llvm/common.js.map +1 -1
  51. package/dist/backend/llvm/constant-callbacks.d.ts +2 -1
  52. package/dist/backend/llvm/constant-callbacks.js +83 -52
  53. package/dist/backend/llvm/constant-callbacks.js.map +1 -1
  54. package/dist/backend/llvm/counted-loops.d.ts +7 -0
  55. package/dist/backend/llvm/counted-loops.js +18 -0
  56. package/dist/backend/llvm/counted-loops.js.map +1 -1
  57. package/dist/backend/llvm/dense-array-access.d.ts +39 -8
  58. package/dist/backend/llvm/dense-array-access.js +222 -52
  59. package/dist/backend/llvm/dense-array-access.js.map +1 -1
  60. package/dist/backend/llvm/dense-array-access.test.js +36 -0
  61. package/dist/backend/llvm/dense-array-access.test.js.map +1 -1
  62. package/dist/backend/llvm/dense-array-loops.d.ts +17 -1
  63. package/dist/backend/llvm/dense-array-loops.js +194 -5
  64. package/dist/backend/llvm/dense-array-loops.js.map +1 -1
  65. package/dist/backend/llvm/dense-array-loops.test.js +90 -1
  66. package/dist/backend/llvm/dense-array-loops.test.js.map +1 -1
  67. package/dist/backend/llvm/dyn-handle-tags.test.js +6 -1
  68. package/dist/backend/llvm/dyn-handle-tags.test.js.map +1 -1
  69. package/dist/backend/llvm/dyn.d.ts +26 -0
  70. package/dist/backend/llvm/dyn.js +352 -61
  71. package/dist/backend/llvm/dyn.js.map +1 -1
  72. package/dist/backend/llvm/emit-function.js +11 -20
  73. package/dist/backend/llvm/emit-function.js.map +1 -1
  74. package/dist/backend/llvm/emit-journal.d.ts +93 -0
  75. package/dist/backend/llvm/emit-journal.js +170 -0
  76. package/dist/backend/llvm/emit-journal.js.map +1 -0
  77. package/dist/backend/llvm/emit-module.js +195 -27
  78. package/dist/backend/llvm/emit-module.js.map +1 -1
  79. package/dist/backend/llvm/emit-statements.d.ts +0 -4
  80. package/dist/backend/llvm/emit-statements.js +268 -84
  81. package/dist/backend/llvm/emit-statements.js.map +1 -1
  82. package/dist/backend/llvm/emitter-state.d.ts +7 -0
  83. package/dist/backend/llvm/emitter-state.js +14 -0
  84. package/dist/backend/llvm/emitter-state.js.map +1 -0
  85. package/dist/backend/llvm/emitter.d.ts +176 -37
  86. package/dist/backend/llvm/emitter.js +724 -85
  87. package/dist/backend/llvm/emitter.js.map +1 -1
  88. package/dist/backend/llvm/emitter.test.js +54 -5
  89. package/dist/backend/llvm/emitter.test.js.map +1 -1
  90. package/dist/backend/llvm/expr-bytes.js +34 -12
  91. package/dist/backend/llvm/expr-bytes.js.map +1 -1
  92. package/dist/backend/llvm/expr-callbacks.js +47 -0
  93. package/dist/backend/llvm/expr-callbacks.js.map +1 -1
  94. package/dist/backend/llvm/expr-calls.js +28 -14
  95. package/dist/backend/llvm/expr-calls.js.map +1 -1
  96. package/dist/backend/llvm/expr-containers.d.ts +14 -2
  97. package/dist/backend/llvm/expr-containers.js +129 -37
  98. package/dist/backend/llvm/expr-containers.js.map +1 -1
  99. package/dist/backend/llvm/expr-context.d.ts +14 -0
  100. package/dist/backend/llvm/expr-dynamic.js +18 -11
  101. package/dist/backend/llvm/expr-dynamic.js.map +1 -1
  102. package/dist/backend/llvm/expr-primitives.js +100 -28
  103. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  104. package/dist/backend/llvm/expr-primitives.test.js +11 -6
  105. package/dist/backend/llvm/expr-primitives.test.js.map +1 -1
  106. package/dist/backend/llvm/expr-records.d.ts +12 -0
  107. package/dist/backend/llvm/expr-records.js +106 -0
  108. package/dist/backend/llvm/expr-records.js.map +1 -1
  109. package/dist/backend/llvm/expr-stream-bridges.d.ts +2 -2
  110. package/dist/backend/llvm/expr-stream-bridges.js +194 -65
  111. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  112. package/dist/backend/llvm/expr-stream-bridges.test.js +1 -1
  113. package/dist/backend/llvm/expr-stream-bridges.test.js.map +1 -1
  114. package/dist/backend/llvm/expr-stream-callbacks.d.ts +2 -2
  115. package/dist/backend/llvm/expr-stream-callbacks.js +74 -20
  116. package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
  117. package/dist/backend/llvm/int32-kind-loops.d.ts +39 -0
  118. package/dist/backend/llvm/int32-kind-loops.js +106 -0
  119. package/dist/backend/llvm/int32-kind-loops.js.map +1 -0
  120. package/dist/backend/llvm/integer-or-nan-indexes.test.d.ts +1 -0
  121. package/dist/backend/llvm/integer-or-nan-indexes.test.js +118 -0
  122. package/dist/backend/llvm/integer-or-nan-indexes.test.js.map +1 -0
  123. package/dist/backend/llvm/integer-values.d.ts +20 -1
  124. package/dist/backend/llvm/integer-values.js +71 -0
  125. package/dist/backend/llvm/integer-values.js.map +1 -1
  126. package/dist/backend/llvm/js-ic.d.ts +1 -1
  127. package/dist/backend/llvm/js-ic.js +1 -1
  128. package/dist/backend/llvm/js-ic.js.map +1 -1
  129. package/dist/backend/llvm/key-orders.d.ts +7 -0
  130. package/dist/backend/llvm/key-orders.js +33 -0
  131. package/dist/backend/llvm/key-orders.js.map +1 -0
  132. package/dist/backend/llvm/lib-connect.js +4 -0
  133. package/dist/backend/llvm/lib-connect.js.map +1 -1
  134. package/dist/backend/llvm/lib-datagram.js +11 -0
  135. package/dist/backend/llvm/lib-datagram.js.map +1 -1
  136. package/dist/backend/llvm/lib-dispatch.js +80 -2
  137. package/dist/backend/llvm/lib-dispatch.js.map +1 -1
  138. package/dist/backend/llvm/lib-filesystem.js +4 -4
  139. package/dist/backend/llvm/lib-filesystem.js.map +1 -1
  140. package/dist/backend/llvm/lib-http2.js +4 -0
  141. package/dist/backend/llvm/lib-http2.js.map +1 -1
  142. package/dist/backend/llvm/lib-lookup.js +16 -6
  143. package/dist/backend/llvm/lib-lookup.js.map +1 -1
  144. package/dist/backend/llvm/lib-shared.js +73 -2
  145. package/dist/backend/llvm/lib-shared.js.map +1 -1
  146. package/dist/backend/llvm/lib-stream.js +35 -5
  147. package/dist/backend/llvm/lib-stream.js.map +1 -1
  148. package/dist/backend/llvm/local-array-reads.js +115 -19
  149. package/dist/backend/llvm/local-array-reads.js.map +1 -1
  150. package/dist/backend/llvm/local-array-reads.test.js +14 -0
  151. package/dist/backend/llvm/local-array-reads.test.js.map +1 -1
  152. package/dist/backend/llvm/loop-state.d.ts +33 -0
  153. package/dist/backend/llvm/loop-state.js +42 -0
  154. package/dist/backend/llvm/loop-state.js.map +1 -0
  155. package/dist/backend/llvm/map-number-lookup.d.ts +26 -8
  156. package/dist/backend/llvm/map-number-lookup.js +91 -31
  157. package/dist/backend/llvm/map-number-lookup.js.map +1 -1
  158. package/dist/backend/llvm/map-number-lookup.test.js +55 -0
  159. package/dist/backend/llvm/map-number-lookup.test.js.map +1 -1
  160. package/dist/backend/llvm/map-read-lifetimes.js +4 -2
  161. package/dist/backend/llvm/map-read-lifetimes.js.map +1 -1
  162. package/dist/backend/llvm/nullable-unions.d.ts +2 -1
  163. package/dist/backend/llvm/nullable-unions.js +15 -3
  164. package/dist/backend/llvm/nullable-unions.js.map +1 -1
  165. package/dist/backend/llvm/publish.d.ts +10 -0
  166. package/dist/backend/llvm/publish.js +12 -0
  167. package/dist/backend/llvm/publish.js.map +1 -1
  168. package/dist/backend/llvm/receivers.js +6 -1
  169. package/dist/backend/llvm/receivers.js.map +1 -1
  170. package/dist/backend/llvm/record-results.d.ts +1 -9
  171. package/dist/backend/llvm/record-results.js +2 -11
  172. package/dist/backend/llvm/record-results.js.map +1 -1
  173. package/dist/backend/llvm/reference-writes.d.ts +7 -2
  174. package/dist/backend/llvm/reference-writes.js +89 -72
  175. package/dist/backend/llvm/reference-writes.js.map +1 -1
  176. package/dist/backend/llvm/running-extrema.d.ts +11 -0
  177. package/dist/backend/llvm/running-extrema.js +115 -0
  178. package/dist/backend/llvm/running-extrema.js.map +1 -0
  179. package/dist/backend/llvm/running-extrema.test.d.ts +1 -0
  180. package/dist/backend/llvm/running-extrema.test.js +89 -0
  181. package/dist/backend/llvm/running-extrema.test.js.map +1 -0
  182. package/dist/backend/llvm/shapes.d.ts +71 -15
  183. package/dist/backend/llvm/shapes.js +222 -33
  184. package/dist/backend/llvm/shapes.js.map +1 -1
  185. package/dist/backend/llvm/shapes.test.js +53 -7
  186. package/dist/backend/llvm/shapes.test.js.map +1 -1
  187. package/dist/backend/llvm/speculative-integers.d.ts +6 -0
  188. package/dist/backend/llvm/speculative-integers.js +2 -2
  189. package/dist/backend/llvm/speculative-integers.js.map +1 -1
  190. package/dist/backend/llvm/stack-objects.d.ts +3 -2
  191. package/dist/backend/llvm/stack-objects.js +5 -2
  192. package/dist/backend/llvm/stack-objects.js.map +1 -1
  193. package/dist/backend/llvm/string-reads.d.ts +12 -0
  194. package/dist/backend/llvm/string-reads.js +44 -0
  195. package/dist/backend/llvm/string-reads.js.map +1 -1
  196. package/dist/backend/llvm/walk-borrows.d.ts +3 -0
  197. package/dist/backend/llvm/walk-borrows.js +46 -41
  198. package/dist/backend/llvm/walk-borrows.js.map +1 -1
  199. package/dist/backend/llvm/walkers.d.ts +3 -0
  200. package/dist/backend/llvm/walkers.js +88 -65
  201. package/dist/backend/llvm/walkers.js.map +1 -1
  202. package/dist/backend/llvm/wrapping-sums.d.ts +16 -1
  203. package/dist/backend/llvm/wrapping-sums.js +126 -0
  204. package/dist/backend/llvm/wrapping-sums.js.map +1 -1
  205. package/dist/backend/may-throw.d.ts +8 -10
  206. package/dist/backend/may-throw.js +14 -10
  207. package/dist/backend/may-throw.js.map +1 -1
  208. package/dist/backend/native/contracts.d.ts +5 -0
  209. package/dist/backend/native/executable.js +7 -0
  210. package/dist/backend/native/executable.js.map +1 -1
  211. package/dist/backend/native/runtime-inputs.d.ts +1 -1
  212. package/dist/backend/native/runtime-inputs.js +1 -0
  213. package/dist/backend/native/runtime-inputs.js.map +1 -1
  214. package/dist/backend/native-link-info-core.d.ts +4 -0
  215. package/dist/backend/native-link-info-core.js.map +1 -1
  216. package/dist/backend/publication.d.ts +12 -1
  217. package/dist/backend/publication.js +37 -14
  218. package/dist/backend/publication.js.map +1 -1
  219. package/dist/backend/publication.test.js +30 -0
  220. package/dist/backend/publication.test.js.map +1 -1
  221. package/dist/backend/result-slots.d.ts +16 -0
  222. package/dist/backend/result-slots.js +23 -0
  223. package/dist/backend/result-slots.js.map +1 -0
  224. package/dist/backend/runtime-abi.d.ts +2 -2
  225. package/dist/backend/runtime-abi.js +2 -2
  226. package/dist/backend/runtime-pack-core.d.ts +1 -0
  227. package/dist/backend/runtime-pack-core.js +1 -0
  228. package/dist/backend/runtime-pack-core.js.map +1 -1
  229. package/dist/backend/runtime-pack-targets.test.js +2 -1
  230. package/dist/backend/runtime-pack-targets.test.js.map +1 -1
  231. package/dist/backend/runtime-pack.test.js +2 -1
  232. package/dist/backend/runtime-pack.test.js.map +1 -1
  233. package/dist/backend/stack-observations.d.ts +2 -1
  234. package/dist/backend/stack-observations.js +67 -42
  235. package/dist/backend/stack-observations.js.map +1 -1
  236. package/dist/backend/target-diagnostics.js +5 -3
  237. package/dist/backend/target-diagnostics.js.map +1 -1
  238. package/dist/backend/warm-cache.js +1 -0
  239. package/dist/backend/warm-cache.js.map +1 -1
  240. package/dist/cli/usage.d.ts +1 -1
  241. package/dist/cli/usage.js +3 -3
  242. package/dist/compat/fetch-profile.js +1 -1
  243. package/dist/compat/fetch-profile.js.map +1 -1
  244. package/dist/contracts/check.js +4 -3
  245. package/dist/contracts/check.js.map +1 -1
  246. package/dist/contracts/int32-elements.js +10 -2
  247. package/dist/contracts/int32-elements.js.map +1 -1
  248. package/dist/coverage/report.js +12 -3
  249. package/dist/coverage/report.js.map +1 -1
  250. package/dist/diagnostics/diagnostic.d.ts +4 -0
  251. package/dist/diagnostics/diagnostic.js.map +1 -1
  252. package/dist/diagnostics/envelope.d.ts +3 -0
  253. package/dist/diagnostics/envelope.js +1 -0
  254. package/dist/diagnostics/envelope.js.map +1 -1
  255. package/dist/executable/executable-cache.d.ts +2 -0
  256. package/dist/executable/executable-cache.js +1 -0
  257. package/dist/executable/executable-cache.js.map +1 -1
  258. package/dist/executable/executable-cache.test.js +1 -0
  259. package/dist/executable/executable-cache.test.js.map +1 -1
  260. package/dist/frontend/decl-projection.d.ts +41 -0
  261. package/dist/frontend/decl-projection.js +854 -0
  262. package/dist/frontend/decl-projection.js.map +1 -0
  263. package/dist/frontend/decl-projection.test.d.ts +1 -0
  264. package/dist/frontend/decl-projection.test.js +30 -0
  265. package/dist/frontend/decl-projection.test.js.map +1 -0
  266. package/dist/frontend/dts-paths.d.ts +15 -0
  267. package/dist/frontend/dts-paths.js +25 -0
  268. package/dist/frontend/dts-paths.js.map +1 -1
  269. package/dist/frontend/input-tracker.d.ts +6 -0
  270. package/dist/frontend/input-tracker.js +51 -28
  271. package/dist/frontend/input-tracker.js.map +1 -1
  272. package/dist/frontend/input-tracker.test.js +19 -0
  273. package/dist/frontend/input-tracker.test.js.map +1 -1
  274. package/dist/frontend/lowering/array-values.js +100 -2
  275. package/dist/frontend/lowering/array-values.js.map +1 -1
  276. package/dist/frontend/lowering/builtins/child-process-methods.js +46 -15
  277. package/dist/frontend/lowering/builtins/child-process-methods.js.map +1 -1
  278. package/dist/frontend/lowering/builtins/child-process.js +13 -2
  279. package/dist/frontend/lowering/builtins/child-process.js.map +1 -1
  280. package/dist/frontend/lowering/builtins/crypto.js +84 -9
  281. package/dist/frontend/lowering/builtins/crypto.js.map +1 -1
  282. package/dist/frontend/lowering/builtins/global-namespace-keys.d.ts +3 -0
  283. package/dist/frontend/lowering/builtins/global-namespace-keys.js +122 -0
  284. package/dist/frontend/lowering/builtins/global-namespace-keys.js.map +1 -0
  285. package/dist/frontend/lowering/builtins/numbers.js +9 -1
  286. package/dist/frontend/lowering/builtins/numbers.js.map +1 -1
  287. package/dist/frontend/lowering/builtins/promises.d.ts +6 -0
  288. package/dist/frontend/lowering/builtins/promises.js +88 -2
  289. package/dist/frontend/lowering/builtins/promises.js.map +1 -1
  290. package/dist/frontend/lowering/builtins/readline.d.ts +5 -1
  291. package/dist/frontend/lowering/builtins/readline.js +35 -3
  292. package/dist/frontend/lowering/builtins/readline.js.map +1 -1
  293. package/dist/frontend/lowering/builtins/url.js +24 -1
  294. package/dist/frontend/lowering/builtins/url.js.map +1 -1
  295. package/dist/frontend/lowering/builtins/webassembly.js +6 -3
  296. package/dist/frontend/lowering/builtins/webassembly.js.map +1 -1
  297. package/dist/frontend/lowering/class-callbacks.d.ts +5 -2
  298. package/dist/frontend/lowering/class-callbacks.js +82 -12
  299. package/dist/frontend/lowering/class-callbacks.js.map +1 -1
  300. package/dist/frontend/lowering/class-construction.d.ts +4 -1
  301. package/dist/frontend/lowering/class-construction.js +17 -3
  302. package/dist/frontend/lowering/class-construction.js.map +1 -1
  303. package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +39 -2
  304. package/dist/frontend/lowering/class-dynamic-dispatch.js +766 -108
  305. package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
  306. package/dist/frontend/lowering/class-dynamic-dispatch.test.js +47 -0
  307. package/dist/frontend/lowering/class-dynamic-dispatch.test.js.map +1 -1
  308. package/dist/frontend/lowering/class-iterables.d.ts +2 -1
  309. package/dist/frontend/lowering/class-iterables.js +9 -1
  310. package/dist/frontend/lowering/class-iterables.js.map +1 -1
  311. package/dist/frontend/lowering/class-method-mutations.js +32 -9
  312. package/dist/frontend/lowering/class-method-mutations.js.map +1 -1
  313. package/dist/frontend/lowering/class-prototypes.js +31 -2
  314. package/dist/frontend/lowering/class-prototypes.js.map +1 -1
  315. package/dist/frontend/lowering/class-runtime-statics.d.ts +9 -3
  316. package/dist/frontend/lowering/class-runtime-statics.js +29 -4
  317. package/dist/frontend/lowering/class-runtime-statics.js.map +1 -1
  318. package/dist/frontend/lowering/coercions/structural-plans.js +48 -1
  319. package/dist/frontend/lowering/coercions/structural-plans.js.map +1 -1
  320. package/dist/frontend/lowering/coercions/structural.js +91 -1
  321. package/dist/frontend/lowering/coercions/structural.js.map +1 -1
  322. package/dist/frontend/lowering/containers/array-callback-call.js +2 -2
  323. package/dist/frontend/lowering/containers/array-callback-call.js.map +1 -1
  324. package/dist/frontend/lowering/containers/array-callbacks.js +338 -18
  325. package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
  326. package/dist/frontend/lowering/containers/array-concat.js +10 -0
  327. package/dist/frontend/lowering/containers/array-concat.js.map +1 -1
  328. package/dist/frontend/lowering/containers/array-methods.js +15 -0
  329. package/dist/frontend/lowering/containers/array-methods.js.map +1 -1
  330. package/dist/frontend/lowering/containers/array-pipelines.js +19 -8
  331. package/dist/frontend/lowering/containers/array-pipelines.js.map +1 -1
  332. package/dist/frontend/lowering/containers/bytes.js +2 -1
  333. package/dist/frontend/lowering/containers/bytes.js.map +1 -1
  334. package/dist/frontend/lowering/containers/callback-arguments.js +3 -0
  335. package/dist/frontend/lowering/containers/callback-arguments.js.map +1 -1
  336. package/dist/frontend/lowering/containers/collection-methods.js +7 -2
  337. package/dist/frontend/lowering/containers/collection-methods.js.map +1 -1
  338. package/dist/frontend/lowering/containers/filter-predicates.d.ts +6 -0
  339. package/dist/frontend/lowering/containers/filter-predicates.js +205 -0
  340. package/dist/frontend/lowering/containers/filter-predicates.js.map +1 -0
  341. package/dist/frontend/lowering/containers/indexed-objects.d.ts +0 -12
  342. package/dist/frontend/lowering/containers/indexed-objects.js +46 -7
  343. package/dist/frontend/lowering/containers/indexed-objects.js.map +1 -1
  344. package/dist/frontend/lowering/containers/string-and-regexp.js +55 -9
  345. package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
  346. package/dist/frontend/lowering/containers/string-replacement.js +43 -19
  347. package/dist/frontend/lowering/containers/string-replacement.js.map +1 -1
  348. package/dist/frontend/lowering/dispatch-sites.js +15 -1
  349. package/dist/frontend/lowering/dispatch-sites.js.map +1 -1
  350. package/dist/frontend/lowering/divergences.js +9 -1
  351. package/dist/frontend/lowering/divergences.js.map +1 -1
  352. package/dist/frontend/lowering/error-methods.js +47 -2
  353. package/dist/frontend/lowering/error-methods.js.map +1 -1
  354. package/dist/frontend/lowering/expressions/array-literals.js +47 -0
  355. package/dist/frontend/lowering/expressions/array-literals.js.map +1 -1
  356. package/dist/frontend/lowering/expressions/binary.js +36 -2
  357. package/dist/frontend/lowering/expressions/binary.js.map +1 -1
  358. package/dist/frontend/lowering/expressions/element-access.js +90 -13
  359. package/dist/frontend/lowering/expressions/element-access.js.map +1 -1
  360. package/dist/frontend/lowering/expressions/identifiers.js +33 -4
  361. package/dist/frontend/lowering/expressions/identifiers.js.map +1 -1
  362. package/dist/frontend/lowering/expressions/narrowing.js +95 -1
  363. package/dist/frontend/lowering/expressions/narrowing.js.map +1 -1
  364. package/dist/frontend/lowering/expressions/nullish-assignment.js +3 -1
  365. package/dist/frontend/lowering/expressions/nullish-assignment.js.map +1 -1
  366. package/dist/frontend/lowering/expressions/object-literals.d.ts +10 -0
  367. package/dist/frontend/lowering/expressions/object-literals.js +138 -51
  368. package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
  369. package/dist/frontend/lowering/expressions/optional-chains.js +12 -0
  370. package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
  371. package/dist/frontend/lowering/expressions/property-access.js +113 -11
  372. package/dist/frontend/lowering/expressions/property-access.js.map +1 -1
  373. package/dist/frontend/lowering/expressions/relational.js +212 -33
  374. package/dist/frontend/lowering/expressions/relational.js.map +1 -1
  375. package/dist/frontend/lowering/expressions/union-fields.js +4 -0
  376. package/dist/frontend/lowering/expressions/union-fields.js.map +1 -1
  377. package/dist/frontend/lowering/expressions/updates.js +22 -3
  378. package/dist/frontend/lowering/expressions/updates.js.map +1 -1
  379. package/dist/frontend/lowering/frozen-records.d.ts +28 -0
  380. package/dist/frontend/lowering/frozen-records.js +322 -0
  381. package/dist/frontend/lowering/frozen-records.js.map +1 -0
  382. package/dist/frontend/lowering/function-returns.js +49 -0
  383. package/dist/frontend/lowering/function-returns.js.map +1 -1
  384. package/dist/frontend/lowering/generic-functions.js +7 -2
  385. package/dist/frontend/lowering/generic-functions.js.map +1 -1
  386. package/dist/frontend/lowering/iterable-values.d.ts +49 -0
  387. package/dist/frontend/lowering/iterable-values.js +297 -0
  388. package/dist/frontend/lowering/iterable-values.js.map +1 -0
  389. package/dist/frontend/lowering/iterator-adapters.js +186 -1
  390. package/dist/frontend/lowering/iterator-adapters.js.map +1 -1
  391. package/dist/frontend/lowering/js-class-fields.d.ts +8 -0
  392. package/dist/frontend/lowering/js-class-fields.js +45 -10
  393. package/dist/frontend/lowering/js-class-fields.js.map +1 -1
  394. package/dist/frontend/lowering/key-order-witness.d.ts +18 -3
  395. package/dist/frontend/lowering/key-order-witness.js +770 -22
  396. package/dist/frontend/lowering/key-order-witness.js.map +1 -1
  397. package/dist/frontend/lowering/key-order-witness.test.js +428 -8
  398. package/dist/frontend/lowering/key-order-witness.test.js.map +1 -1
  399. package/dist/frontend/lowering/lower-async-iteration.js +4 -1
  400. package/dist/frontend/lowering/lower-async-iteration.js.map +1 -1
  401. package/dist/frontend/lowering/lower-calls.d.ts +7 -0
  402. package/dist/frontend/lowering/lower-calls.js +443 -41
  403. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  404. package/dist/frontend/lowering/lower-classes.d.ts +11 -2
  405. package/dist/frontend/lowering/lower-classes.js +302 -22
  406. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  407. package/dist/frontend/lowering/lower-dgram.js +3 -1
  408. package/dist/frontend/lowering/lower-dgram.js.map +1 -1
  409. package/dist/frontend/lowering/lower-exprs.js +10 -2
  410. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  411. package/dist/frontend/lowering/lower-functions.d.ts +11 -0
  412. package/dist/frontend/lowering/lower-functions.js +83 -0
  413. package/dist/frontend/lowering/lower-functions.js.map +1 -1
  414. package/dist/frontend/lowering/lower-generators.js +41 -31
  415. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  416. package/dist/frontend/lowering/lower-global-value.js +6 -3
  417. package/dist/frontend/lowering/lower-global-value.js.map +1 -1
  418. package/dist/frontend/lowering/lower-inspect.js +18 -6
  419. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  420. package/dist/frontend/lowering/lower-modules.js +32 -0
  421. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  422. package/dist/frontend/lowering/lower-namespaces.js +5 -1
  423. package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
  424. package/dist/frontend/lowering/lower-server.js +2 -2
  425. package/dist/frontend/lowering/lower-server.js.map +1 -1
  426. package/dist/frontend/lowering/lower-stdlib.d.ts +5 -0
  427. package/dist/frontend/lowering/lower-stdlib.js +30 -0
  428. package/dist/frontend/lowering/lower-stdlib.js.map +1 -1
  429. package/dist/frontend/lowering/lower-stmts.d.ts +23 -0
  430. package/dist/frontend/lowering/lower-stmts.js +454 -48
  431. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  432. package/dist/frontend/lowering/lower-stream.d.ts +20 -2
  433. package/dist/frontend/lowering/lower-stream.js +1483 -156
  434. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  435. package/dist/frontend/lowering/lowerer.d.ts +77 -6
  436. package/dist/frontend/lowering/lowerer.js +313 -29
  437. package/dist/frontend/lowering/lowerer.js.map +1 -1
  438. package/dist/frontend/lowering/module-namespace-elements.d.ts +11 -1
  439. package/dist/frontend/lowering/module-namespace-elements.js +82 -5
  440. package/dist/frontend/lowering/module-namespace-elements.js.map +1 -1
  441. package/dist/frontend/lowering/new-target.d.ts +12 -0
  442. package/dist/frontend/lowering/new-target.js +280 -0
  443. package/dist/frontend/lowering/new-target.js.map +1 -0
  444. package/dist/frontend/lowering/surfaces.d.ts +3 -0
  445. package/dist/frontend/lowering/surfaces.js +18 -6
  446. package/dist/frontend/lowering/surfaces.js.map +1 -1
  447. package/dist/frontend/lowering/undefined-index.d.ts +27 -0
  448. package/dist/frontend/lowering/undefined-index.js +82 -0
  449. package/dist/frontend/lowering/undefined-index.js.map +1 -0
  450. package/dist/frontend/lowering/var-hoisting.js +29 -13
  451. package/dist/frontend/lowering/var-hoisting.js.map +1 -1
  452. package/dist/frontend/lowering/width-lift.d.ts +18 -0
  453. package/dist/frontend/npm-static-bundled-chunks.js +9 -11
  454. package/dist/frontend/npm-static-bundled-chunks.js.map +1 -1
  455. package/dist/frontend/npm-static-bundled-chunks.test.js +6 -5
  456. package/dist/frontend/npm-static-bundled-chunks.test.js.map +1 -1
  457. package/dist/frontend/npm-static-rewrite-syntax.js +9 -1
  458. package/dist/frontend/npm-static-rewrite-syntax.js.map +1 -1
  459. package/dist/frontend/npm-static.js +4 -20
  460. package/dist/frontend/npm-static.js.map +1 -1
  461. package/dist/frontend/package-shims.d.ts +3 -0
  462. package/dist/frontend/package-shims.js +71 -8
  463. package/dist/frontend/package-shims.js.map +1 -1
  464. package/dist/frontend/pipeline.js +18 -10
  465. package/dist/frontend/pipeline.js.map +1 -1
  466. package/dist/frontend/process-fork.d.ts +25 -0
  467. package/dist/frontend/process-fork.js +2 -0
  468. package/dist/frontend/process-fork.js.map +1 -0
  469. package/dist/frontend/program.d.ts +8 -1
  470. package/dist/frontend/program.js +484 -69
  471. package/dist/frontend/program.js.map +1 -1
  472. package/dist/frontend/program.test.js +43 -3
  473. package/dist/frontend/program.test.js.map +1 -1
  474. package/dist/frontend/token-equivalence.d.ts +3 -0
  475. package/dist/frontend/token-equivalence.js +409 -0
  476. package/dist/frontend/token-equivalence.js.map +1 -0
  477. package/dist/frontend/token-equivalence.test.d.ts +1 -0
  478. package/dist/frontend/token-equivalence.test.js +67 -0
  479. package/dist/frontend/token-equivalence.test.js.map +1 -0
  480. package/dist/frontend/ts7/ast-node.d.ts +22 -0
  481. package/dist/frontend/ts7/ast-node.js +1048 -103
  482. package/dist/frontend/ts7/ast-node.js.map +1 -1
  483. package/dist/frontend/ts7/ast-node.test.js +24 -0
  484. package/dist/frontend/ts7/ast-node.test.js.map +1 -1
  485. package/dist/frontend/ts7/ast-wire.d.ts +4 -3
  486. package/dist/frontend/ts7/ast-wire.js +34 -24
  487. package/dist/frontend/ts7/ast-wire.js.map +1 -1
  488. package/dist/frontend/ts7/ast-wire.test.js +23 -0
  489. package/dist/frontend/ts7/ast-wire.test.js.map +1 -1
  490. package/dist/frontend/ts7/checker-backend.d.ts +3 -4
  491. package/dist/frontend/ts7/checker-backend.js +2 -2
  492. package/dist/frontend/ts7/checker-backend.js.map +1 -1
  493. package/dist/frontend/ts7/checker-backend.test.js +5 -9
  494. package/dist/frontend/ts7/checker-backend.test.js.map +1 -1
  495. package/dist/frontend/ts7/checker.d.ts +4 -0
  496. package/dist/frontend/ts7/checker.js +7 -0
  497. package/dist/frontend/ts7/checker.js.map +1 -1
  498. package/dist/frontend/ts7/lib-diagnostics.d.ts +24 -0
  499. package/dist/frontend/ts7/lib-diagnostics.js +307 -0
  500. package/dist/frontend/ts7/lib-diagnostics.js.map +1 -0
  501. package/dist/frontend/ts7/lib-diagnostics.test.d.ts +1 -0
  502. package/dist/frontend/ts7/lib-diagnostics.test.js +199 -0
  503. package/dist/frontend/ts7/lib-diagnostics.test.js.map +1 -0
  504. package/dist/frontend/ts7/program-host.d.ts +7 -0
  505. package/dist/frontend/ts7/program-host.js +25 -2
  506. package/dist/frontend/ts7/program-host.js.map +1 -1
  507. package/dist/frontend/ts7/session.d.ts +14 -1
  508. package/dist/frontend/ts7/session.js +22 -0
  509. package/dist/frontend/ts7/session.js.map +1 -1
  510. package/dist/frontend/type-mapper.d.ts +13 -1
  511. package/dist/frontend/type-mapper.js +191 -11
  512. package/dist/frontend/type-mapper.js.map +1 -1
  513. package/dist/index.d.ts +0 -5
  514. package/dist/index.js +34 -4
  515. package/dist/index.js.map +1 -1
  516. package/dist/ir/analysis.js +5 -3
  517. package/dist/ir/analysis.js.map +1 -1
  518. package/dist/ir/array-length-stability.d.ts +4 -0
  519. package/dist/ir/array-length-stability.js +19 -6
  520. package/dist/ir/array-length-stability.js.map +1 -1
  521. package/dist/ir/array-length-stability.test.js +24 -0
  522. package/dist/ir/array-length-stability.test.js.map +1 -1
  523. package/dist/ir/builtin-effects.d.ts +7 -0
  524. package/dist/ir/builtin-effects.js +52 -0
  525. package/dist/ir/builtin-effects.js.map +1 -1
  526. package/dist/ir/builtin-signatures.d.ts +6 -4
  527. package/dist/ir/builtin-signatures.js +166 -13
  528. package/dist/ir/builtin-signatures.js.map +1 -1
  529. package/dist/ir/callback-specialization.d.ts +2 -1
  530. package/dist/ir/callback-specialization.js +23 -18
  531. package/dist/ir/callback-specialization.js.map +1 -1
  532. package/dist/ir/char-unit-locals.d.ts +19 -0
  533. package/dist/ir/char-unit-locals.js +185 -0
  534. package/dist/ir/char-unit-locals.js.map +1 -0
  535. package/dist/ir/char-unit-locals.test.d.ts +1 -0
  536. package/dist/ir/char-unit-locals.test.js +94 -0
  537. package/dist/ir/char-unit-locals.test.js.map +1 -0
  538. package/dist/ir/final-fields.d.ts +2 -1
  539. package/dist/ir/final-fields.js +14 -16
  540. package/dist/ir/final-fields.js.map +1 -1
  541. package/dist/ir/function-references.d.ts +2 -0
  542. package/dist/ir/function-references.js +2 -0
  543. package/dist/ir/function-references.js.map +1 -1
  544. package/dist/ir/function-references.test.js +3 -0
  545. package/dist/ir/function-references.test.js.map +1 -1
  546. package/dist/ir/initializer-bindings.d.ts +2 -1
  547. package/dist/ir/initializer-bindings.js +27 -20
  548. package/dist/ir/initializer-bindings.js.map +1 -1
  549. package/dist/ir/int32-arrays.d.ts +108 -0
  550. package/dist/ir/int32-arrays.js +831 -0
  551. package/dist/ir/int32-arrays.js.map +1 -0
  552. package/dist/ir/int32-slots.d.ts +24 -2
  553. package/dist/ir/int32-slots.js +259 -57
  554. package/dist/ir/int32-slots.js.map +1 -1
  555. package/dist/ir/integer-loops.d.ts +3 -3
  556. package/dist/ir/integer-loops.js +14 -6
  557. package/dist/ir/integer-loops.js.map +1 -1
  558. package/dist/ir/integer-loops.test.js +10 -0
  559. package/dist/ir/integer-loops.test.js.map +1 -1
  560. package/dist/ir/integer-ranges.d.ts +5 -0
  561. package/dist/ir/integer-ranges.js +125 -12
  562. package/dist/ir/integer-ranges.js.map +1 -1
  563. package/dist/ir/integer-ranges.test.js +30 -0
  564. package/dist/ir/integer-ranges.test.js.map +1 -1
  565. package/dist/ir/ir.d.ts +70 -7
  566. package/dist/ir/ir.js +58 -1
  567. package/dist/ir/ir.js.map +1 -1
  568. package/dist/ir/ir.test.js +21 -1
  569. package/dist/ir/ir.test.js.map +1 -1
  570. package/dist/ir/js-ic.d.ts +19 -2
  571. package/dist/ir/js-ic.js +95 -11
  572. package/dist/ir/js-ic.js.map +1 -1
  573. package/dist/ir/js-ic.test.js +188 -0
  574. package/dist/ir/js-ic.test.js.map +1 -1
  575. package/dist/ir/node-index.d.ts +57 -0
  576. package/dist/ir/node-index.js +215 -0
  577. package/dist/ir/node-index.js.map +1 -0
  578. package/dist/ir/paired-while-loops.d.ts +25 -0
  579. package/dist/ir/paired-while-loops.js +335 -0
  580. package/dist/ir/paired-while-loops.js.map +1 -0
  581. package/dist/ir/paired-while-loops.test.d.ts +1 -0
  582. package/dist/ir/paired-while-loops.test.js +163 -0
  583. package/dist/ir/paired-while-loops.test.js.map +1 -0
  584. package/dist/ir/parameter-versions.d.ts +25 -0
  585. package/dist/ir/parameter-versions.js +300 -0
  586. package/dist/ir/parameter-versions.js.map +1 -0
  587. package/dist/ir/runtime-features.d.ts +34 -13
  588. package/dist/ir/runtime-features.js +152 -38
  589. package/dist/ir/runtime-features.js.map +1 -1
  590. package/dist/ir/serialize.d.ts +12 -2
  591. package/dist/ir/serialize.js +16 -3
  592. package/dist/ir/serialize.js.map +1 -1
  593. package/dist/ir/serialize.test.js +17 -0
  594. package/dist/ir/serialize.test.js.map +1 -1
  595. package/dist/ir/traverse.js +18 -6
  596. package/dist/ir/traverse.js.map +1 -1
  597. package/dist/ir/validate.js +122 -36
  598. package/dist/ir/validate.js.map +1 -1
  599. package/dist/library/ir-policy.js +2 -0
  600. package/dist/library/ir-policy.js.map +1 -1
  601. package/dist/native/cache.d.ts +6 -1
  602. package/dist/native/cache.js +28 -5
  603. package/dist/native/cache.js.map +1 -1
  604. package/dist/native/cache.test.js +16 -2
  605. package/dist/native/cache.test.js.map +1 -1
  606. package/dist/native/cli.js +21 -1
  607. package/dist/native/cli.js.map +1 -1
  608. package/dist/native/compiler.js +8 -6
  609. package/dist/native/compiler.js.map +1 -1
  610. package/dist/native/executable-cache.d.ts +1 -1
  611. package/dist/native/executable-cache.js +2 -2
  612. package/dist/native/executable-cache.js.map +1 -1
  613. package/dist/native/prepare.d.ts +3 -1
  614. package/dist/native/prepare.js +119 -31
  615. package/dist/native/prepare.js.map +1 -1
  616. package/dist/native/prepare.test.js +78 -18
  617. package/dist/native/prepare.test.js.map +1 -1
  618. package/dist/native/sanitizer.test.js +2 -0
  619. package/dist/native/sanitizer.test.js.map +1 -1
  620. package/dist/native/text-file.d.ts +13 -3
  621. package/dist/native/text-file.js +63 -9
  622. package/dist/native/text-file.js.map +1 -1
  623. package/dist/native/text-file.test.d.ts +1 -0
  624. package/dist/native/text-file.test.js +49 -0
  625. package/dist/native/text-file.test.js.map +1 -0
  626. package/dist/native/toolchain.js +4 -4
  627. package/dist/native/toolchain.js.map +1 -1
  628. package/dist/native/toolchain.test.js +3 -3
  629. package/dist/native/toolchain.test.js.map +1 -1
  630. package/package.json +21 -21
  631. package/shims/chalk/v5.ts +688 -0
  632. package/shims/hono-node-server/v2.ts +645 -0
  633. package/shims/hot-shots/client.ts +1126 -0
  634. package/shims/hot-shots/v8-unix-dgram.ts +8 -0
  635. package/shims/hot-shots/v8.ts +8 -0
  636. package/surface-manifest.json +26 -4
@@ -15,18 +15,21 @@ import { loopTestsEveryIteration } from "../loop-polls.js";
15
15
  import { isDynTypedRefType, isRefCounted, isUnitType, POINTER_KINDS, RUNTIME_EMITTER_CLASS, RUNTIME_EVENT_CLASS, RUNTIME_EVENT_TARGET_CLASS, RUNTIME_ERROR_CLASSES, RUNTIME_STREAM_CLASSES, typeEquals, typeKey, VOID, classJsName, } from "../../ir/ir.js";
16
16
  import { moduleRuntimeFeatures } from "../../ir/runtime-features.js";
17
17
  import { captureFreeFunctions, observesStacks } from "../stack-observations.js";
18
- import {} from "./dense-array-loops.js";
19
18
  import { findInitializedByteLoopBindings } from "./byte-windows.js";
20
19
  import { matchBytesLoopVersion } from "./bytes-loop-versions.js";
21
20
  import { globalSlotAlias } from "./bytes-alias.js";
22
21
  import { materializeSplitPiece, } from "./split-loops.js";
23
22
  import { scalarizeNumericRecords } from "../../ir/scalar-records.js";
24
- import { addRecordResultEntries } from "./record-results.js";
23
+ import { addRecordResultEntries, resultEntryName } from "./record-results.js";
25
24
  import { specializeCallbackCalls } from "../../ir/callback-specialization.js";
25
+ import { EmitJournal, registerReplay, renameChunk, replayJournal, } from "./emit-journal.js";
26
26
  import { specializeNumericCalls } from "../../ir/numeric-call-specialization.js";
27
+ import { versionLoopBoundParameters } from "../../ir/parameter-versions.js";
28
+ import { allocatedLiteral, fillAllocationLength, int32ArrayKey, selectInt32Arrays, } from "../../ir/int32-arrays.js";
27
29
  import { everyExpr, everyExprChild, everyStmtChild, everyStmtList } from "../../ir/traverse.js";
28
- import { INT32_RANGE } from "../../ir/integer-ranges.js";
30
+ import { INT32_RANGE, withinInt32, } from "../../ir/integer-ranges.js";
29
31
  import { unshareNodes } from "../../ir/unshare.js";
32
+ import { runPairedWhileLoopsAsFor } from "../../ir/paired-while-loops.js";
30
33
  import { copyStableCaptures } from "../../ir/capture-values.js";
31
34
  import { resolveSelfCaptures } from "../../ir/self-captures.js";
32
35
  import { analyzeInt32Slots, dynamicFieldStores } from "../../ir/int32-slots.js";
@@ -35,10 +38,11 @@ import { foldConstantGlobals } from "../../ir/constant-globals.js";
35
38
  import { dropUnwrittenPropertyBags } from "../../ir/property-bags.js";
36
39
  import { freezeInitOnlyGlobals } from "../../ir/init-only-globals.js";
37
40
  import { hoistFinalFieldReads } from "../../ir/field-values.js";
41
+ import { holdCharLocalsAsUnits } from "../../ir/char-unit-locals.js";
38
42
  import { findInt32Abis, INT32_ABI_SUFFIX, SCALAR_UNION_DUMMY, SCALAR_UNION_RESULT, } from "./int32-abi.js";
39
43
  import {} from "./int32-locals.js";
40
44
  import { findIntegerClones, NO_INTEGER_CLONES } from "./integer-clones.js";
41
- import { exactInteger, narrowInteger } from "./integer-values.js";
45
+ import { exactInteger, narrowInteger, widenInteger } from "./integer-values.js";
42
46
  import { findInitializerBindings } from "../../ir/initializer-bindings.js";
43
47
  import { findConstantNumericTables } from "../../ir/constant-tables.js";
44
48
  import { allocateFfiCallbackAdapters, hasForeignFfiCallback, hasRetainedFfiCallback, } from "../ffi-callbacks.js";
@@ -52,12 +56,13 @@ import { NullableRefFields } from "./nullable-fields.js";
52
56
  import { InlineUnionFields, loadInlineUnion, presentBits, stackUnionBox, storeInlineUnion, unionBoxBits, } from "./inline-unions.js";
53
57
  import { OptionalArrayReads } from "./local-array-reads.js";
54
58
  import { CheckedNarrows } from "./checked-narrows.js";
55
- import { emitDenseArraySet, emitDenseSlotUnlink } from "./dense-array-access.js";
59
+ import { emitDenseArraySet, emitDenseSlotUnlink, SCR_ELEM_I32, } from "./dense-array-access.js";
56
60
  import { matchMapRead } from "./map-read-lifetimes.js";
57
61
  import {} from "./map-entry-fusion.js";
58
62
  import { emitBorrowedFieldSequence, guardedValue } from "./borrowed-receivers.js";
59
63
  import { emitBorrowedInputs } from "./borrowed-inputs.js";
60
64
  import { findWalkBorrows } from "./walk-borrows.js";
65
+ import { IrNodeIndex } from "../../ir/node-index.js";
61
66
  import { lastUseRead } from "./local-extents.js";
62
67
  import { findReboundParameters } from "./rebound-parameters.js";
63
68
  import { ReferenceEffects } from "./reference-effects.js";
@@ -69,7 +74,7 @@ import { AmbientReceiverReaders, findConstantCallbacks } from "./constant-callba
69
74
  import { findLentStringParameters, } from "./string-slices.js";
70
75
  import { LazyCaptures } from "./lazy-captures.js";
71
76
  import { StackCaptures } from "./stack-captures.js";
72
- import { emitFieldAbsentTest, f64Lit } from "./common.js";
77
+ import { emitFieldAbsentTest, f64Lit, SCR_ARR_FIELD, SCR_ARR_FROZEN } from "./common.js";
73
78
  import { ffiExtendsNarrowIntegers } from "../targets.js";
74
79
  import { emitLiteralExpr, emitOperatorExpr, emitStringExpr, emitContainerExpr, emitRecordExpr, } from "./expr-primitives.js";
75
80
  import { emitControlExpr } from "./expr-control.js";
@@ -78,8 +83,10 @@ import { emitDynamicExpr } from "./expr-dynamic.js";
78
83
  import { emitIntrinsicExpr, emitSerializationExpr, emitAsyncExpr } from "./expr-async.js";
79
84
  import { PublishWalkers } from "./publish.js";
80
85
  import { computeImmutableFields, stableGlobals } from "../immutability.js";
86
+ import { computeCycleMutability, hierarchyUnitOfClass } from "../cycle-mutability.js";
81
87
  import { computePublishedTypes } from "../publication.js";
82
88
  import { emitExpr } from "./expr-dispatch.js";
89
+ import { LOOPS } from "./loop-state.js";
83
90
  import { dynKind, raceAdapterFor, genResultThunkFor, childExitThunkFor, childExitSignalThunkFor, childDataDynThunkFor, childDataThunkFor, execFileThunkFor, ipcMessageThunkFor, ipcSendThunkFor, emitterFixedAdapter, emitterOnceAdapter, wrapEmitterListener, unwrapNullableClosure, closeBindThunkFor, closeOverrideWrapFor, } from "./expr-callbacks.js";
84
91
  import { streamDataAdapter, streamDoneFnFor, cryptoBytesThunkFor, cryptoIntThunkFor, fsRenameThunkFor, streamCbThunkFor, zlibBytesThunkFor, } from "./expr-stream-callbacks.js";
85
92
  import { emitStableReceiver, resolveThunkFor, tagInSet, arrPush, emitArrayCopyLoop, emitStrIntrinsic, emitArrIntrinsic, wrapNullable, emitMapNew, mapSet, emitMapLikeIntrinsic, emitSetNew, } from "./expr-containers.js";
@@ -140,23 +147,58 @@ export function ffiCallbackDummyLl(callback) {
140
147
  export function lowRegionTarget(platform, sanitize) {
141
148
  return platform === "linux" && !sanitize;
142
149
  }
143
- export function emitLlvmModule(input, options = {}) {
150
+ /** Function versions on loop-bounding number parameters
151
+ * (ir/parameter-versions.ts). Library builds have no int32 entries, and a
152
+ * module that observes call stacks could see the version's frame. */
153
+ function versionParameters(mod) {
154
+ if (mod.lib !== undefined || observesStacks(mod))
155
+ return mod;
156
+ return versionLoopBoundParameters(mod, mangleFunction);
157
+ }
158
+ /** The int32 arrays the int32 slot analysis keeps in `mod` (proven and
159
+ * checked), under the inputs LlEmitter gives it (selectInt32Arrays). */
160
+ function provenInt32Arrays(mod) {
161
+ const slots = analyzeInt32Slots(mod, {
162
+ dynamicStores: dynamicFieldStores(mod),
163
+ initializerBindings: findInitializerBindings(mod),
164
+ });
165
+ return new Set([...slots.int32Arrays, ...slots.checkedInt32Arrays]);
166
+ }
167
+ /** The functions whose calls the backend may emit as calls of their
168
+ * result-slot entries (record-results.ts). */
169
+ function resultEntryTargets(mod) {
170
+ const names = new Set(mod.functions.map((fn) => fn.name));
171
+ const targets = new Set();
172
+ for (const name of names)
173
+ if (names.has(resultEntryName(name)))
174
+ targets.add(name);
175
+ return targets;
176
+ }
177
+ /** The emitter for `input` after the module passes every emission runs. */
178
+ function moduleEmitter(input, options) {
144
179
  // Facts are keyed by node identity: emit the same module whether it was
145
180
  // lowered in memory or read back from its serialized form.
146
181
  const mod = unshareNodes(input);
147
182
  // Keep source storage intact for debugger inspection in dev builds.
148
183
  return new LlEmitter(options.debugSources === undefined
149
- ? addRecordResultEntries(scalarizeNumericRecords(specializeCallbackCalls(specializeNumericCalls(foldConstantGlobals(copyStableCaptures(resolveSelfCaptures(hoistFinalFieldReads(freezeInitOnlyGlobals(dropUnwrittenPropertyBags(mod)))))), mangleFunction), mangleFunction)))
150
- : mod, options).emit();
184
+ ? selectInt32Arrays(versionParameters(addRecordResultEntries(scalarizeNumericRecords(specializeCallbackCalls(specializeNumericCalls(foldConstantGlobals(copyStableCaptures(resolveSelfCaptures(hoistFinalFieldReads(freezeInitOnlyGlobals(holdCharLocalsAsUnits(dropUnwrittenPropertyBags(runPairedWhileLoopsAsFor(mod)))))))), mangleFunction), mangleFunction)))), provenInt32Arrays, resultEntryTargets)
185
+ : mod, options);
186
+ }
187
+ export function emitLlvmModule(input, options = {}) {
188
+ return moduleEmitter(input, options).emit();
189
+ }
190
+ /** emitLlvmModule's text as parts that concatenate to it, without the copy
191
+ * that joining them makes: a large program's text is 150 MB. */
192
+ export function emitLlvmModuleParts(input, options = {}) {
193
+ return moduleEmitter(input, options)
194
+ .emitParts()
195
+ .flatMap((part, index) => (index === 0 ? [part] : ["\n", part]));
151
196
  }
152
197
  /** Keep large translation units below the host's single-string limit. */
153
198
  export function emitLlvmModuleSource(input, options = {}) {
154
199
  // IR validation, contracts and the frontend's disposal run after lowering without checks.
155
200
  relieveHeapPressure(true);
156
- const mod = unshareNodes(input);
157
- const parts = new LlEmitter(options.debugSources === undefined
158
- ? addRecordResultEntries(scalarizeNumericRecords(specializeCallbackCalls(specializeNumericCalls(foldConstantGlobals(copyStableCaptures(resolveSelfCaptures(hoistFinalFieldReads(freezeInitOnlyGlobals(dropUnwrittenPropertyBags(mod)))))), mangleFunction), mangleFunction)))
159
- : mod, options).emitParts();
201
+ const parts = moduleEmitter(input, options).emitParts();
160
202
  const length = parts.reduce((total, part) => total + part.length, Math.max(0, parts.length - 1));
161
203
  if (length <= 256 * 1024 * 1024)
162
204
  return parts.join("\n");
@@ -272,6 +314,8 @@ function countLocalMentions(body, id) {
272
314
  }
273
315
  export class LlEmitter {
274
316
  mod;
317
+ /** Per-feature state (emitter-state.ts), indexed by each key's slot. */
318
+ moduleStates = [];
275
319
  localArrayReads = new Map();
276
320
  loopArrayBorrows = new Set();
277
321
  scalarStringSlices = new Map();
@@ -297,9 +341,11 @@ export class LlEmitter {
297
341
  * 32-bit references to compact class instances (LlClassMeta.compressed):
298
342
  * loadField/loadRef decode them and storeField/storeRef encode them. */
299
343
  compressedFieldPtrs = new Set();
300
- /** Whether a class has compressed fields: main reserves the region before
301
- * compiled code runs (scr_plr_init). */
302
- usesCompactRefs = false;
344
+ /** Compact class instances live in the program-lifetime region below
345
+ * 32 GiB (LlvmTargetOptions.lowRegion, and the program has compact
346
+ * classes): main reserves it before compiled code runs (scr_plr_init), and
347
+ * fields and arrays of compactRefType hold 32-bit references. */
348
+ compactRegion = false;
303
349
  /** Native class fields with different property names cannot occupy the
304
350
  * same slot of one object. Inherited views of the same property share a
305
351
  * tag. Array storage has its own disjoint categories; untagged runtime
@@ -315,6 +361,7 @@ export class LlEmitter {
315
361
  tag = 2 + this.fieldAliasTags.size * 2;
316
362
  this.fieldAliasTags.set(field, tag);
317
363
  }
364
+ this.journal?.entry("tag", field, tag);
318
365
  this.fieldPointerTags.set(ptr, tag);
319
366
  }
320
367
  /** The alias tag of a runtime word that emitted code reads and writes
@@ -327,19 +374,225 @@ export class LlEmitter {
327
374
  tag = 2 + this.fieldAliasTags.size * 2;
328
375
  this.fieldAliasTags.set(category, tag);
329
376
  }
377
+ this.journal?.entry("tag", category, tag);
330
378
  return `, !tbaa !${tag}`;
331
379
  }
380
+ /** The current function's int32 array allocations: the array literals
381
+ * its int32 arrays are written with. They construct SCR_ELEM_I32 arrays. */
382
+ int32Allocations = new Set();
383
+ /** The fill temporaries (`new Array(n).fill(v)`) of those allocations:
384
+ * the same arrays, so int32 too. */
385
+ int32ArrayTemps = new Set();
386
+ /** The same for the current function's int32 arrays with checked stores,
387
+ * which are only allocated by fills (ir/int32-arrays.ts
388
+ * checkableInt32Allocations): their temporaries' literals, with the fill's
389
+ * length (a literal constructs SCR_ELEM_I32 storage when that length is at
390
+ * least CHECKED_INT32_MIN_LENGTH, SCR_ELEM_F64 otherwise), and their
391
+ * temporaries. */
392
+ checkedAllocations = new Map();
393
+ checkedArrayTemps = new Set();
394
+ /** The fill calls (`.fill(v)`) of those allocations: a value that is not
395
+ * an int32 widens the new array first. */
396
+ checkedFills = new Set();
397
+ /** Collect the int32 allocations of `fn`, about to be emitted. */
398
+ findInt32Allocations(fn) {
399
+ this.int32Allocations.clear();
400
+ this.int32ArrayTemps.clear();
401
+ this.checkedAllocations.clear();
402
+ this.checkedArrayTemps.clear();
403
+ this.checkedFills.clear();
404
+ const { int32Arrays, checkedInt32Arrays } = this.int32Slots;
405
+ if (int32Arrays.size === 0 && checkedInt32Arrays.size === 0)
406
+ return;
407
+ everyStmtList(fn.body, {
408
+ stmt: (s) => {
409
+ if (s.kind !== "varDecl" && s.kind !== "assign")
410
+ return true;
411
+ const key = int32ArrayKey(fn.name, s.localId);
412
+ const checked = checkedInt32Arrays.has(key);
413
+ if (!checked && !int32Arrays.has(key))
414
+ return true;
415
+ const value = s.kind === "varDecl" ? s.init : s.value;
416
+ const allocation = value && allocatedLiteral(value);
417
+ if (!allocation)
418
+ return true;
419
+ const length = checked ? fillAllocationLength(value) : null;
420
+ if (length !== null)
421
+ this.checkedAllocations.set(allocation.literal, length);
422
+ else if (!checked)
423
+ this.int32Allocations.add(allocation.literal);
424
+ if (allocation.temporary !== null)
425
+ (checked ? this.checkedArrayTemps : this.int32ArrayTemps).add(allocation.temporary);
426
+ if (checked && value !== allocation.literal)
427
+ this.checkedFills.add(value);
428
+ return true;
429
+ },
430
+ expr: () => true,
431
+ });
432
+ }
433
+ /** Whether `arr` reads one of the int32 arrays (ir/int32-arrays.ts, kept
434
+ * by the int32 slot analysis): a local or parameter of the current
435
+ * function, or a module global. */
436
+ int32Array(arr) {
437
+ if (arr.kind !== "varRef")
438
+ return false;
439
+ if (this.int32KindArray(arr))
440
+ return true;
441
+ if (this.int32Slots.int32Arrays.size === 0)
442
+ return false;
443
+ return (this.int32ArrayTemps.has(arr.localId) ||
444
+ this.int32Slots.int32Arrays.has(int32ArrayKey(this.currentFunctionName, arr.localId)));
445
+ }
446
+ /** Whether `arr` is one of the current function's int32 arrays with
447
+ * checked stores: int32 slots until a store widens it to doubles. Every
448
+ * access tests its kind (emitByElementKind), except in the fast copy of
449
+ * an int32 kind loop, which reads and writes it as an int32 array. */
450
+ checkedInt32Array(arr) {
451
+ if (arr.kind !== "varRef" || this.int32KindArray(arr))
452
+ return false;
453
+ if (this.int32Kinds?.wide.has(`${this.currentFunctionName}\0${arr.localId}`))
454
+ return false;
455
+ return this.checkedInt32Local(arr.localId);
456
+ }
457
+ /** Whether the local `localId` holds one of the current function's int32
458
+ * arrays with checked stores. */
459
+ checkedInt32Local(localId) {
460
+ if (this.int32Slots.checkedInt32Arrays.size === 0)
461
+ return false;
462
+ return (this.checkedArrayTemps.has(localId) ||
463
+ this.int32Slots.checkedInt32Arrays.has(`${this.currentFunctionName}\0${localId}`));
464
+ }
465
+ /** Whether `arr` is an int32 array with checked stores that the fast copy
466
+ * of the int32 kind loop being emitted holds as an int32 array. */
467
+ int32KindArray(arr) {
468
+ return (this.int32Kinds !== null &&
469
+ arr.kind === "varRef" &&
470
+ this.int32Kinds.int32.has(`${this.currentFunctionName}\0${arr.localId}`));
471
+ }
472
+ /** Before a store of `value` (of `expr`) into `arr`, in the fast copy of
473
+ * an int32 kind loop: continue when it is an int32 that is not -0, and
474
+ * otherwise leave for the statement's resume point, where it re-executes
475
+ * with kind tests. Returns the value as an i32 when it is at hand as an
476
+ * integer, or null when the store converts the double itself. */
477
+ emitInt32KindStoreCheck(arr, value, expr) {
478
+ if (!this.int32KindArray(arr) || withinInt32(this.integerRanges.get(expr)))
479
+ return null;
480
+ const integer = exactInteger(this, value, expr);
481
+ if (integer !== null && withinInt32(integer.range))
482
+ return narrowInteger(this, integer);
483
+ const resume = this.int32KindResume;
484
+ if (resume === null)
485
+ throw new InternalCompilerError("llvm emitter bug: an int32 kind store without a resume");
486
+ const B = this.B;
487
+ const ok = B.tmp(), int = B.tmp();
488
+ if (integer !== null) {
489
+ // An exact integer: a range test on its 64-bit form.
490
+ const wide = widenInteger(this, integer), low = B.tmp(), high = B.tmp();
491
+ B.line(`${low} = icmp sge i64 ${wide}, -2147483648`);
492
+ B.line(`${high} = icmp sle i64 ${wide}, 2147483647`);
493
+ B.line(`${ok} = and i1 ${low}, ${high}`);
494
+ const store = B.newLabel("arr.store.i32");
495
+ B.condBr(ok, store, resume);
496
+ B.startBlock(store);
497
+ B.line(`${int} = trunc i64 ${wide} to i32`);
498
+ return int;
499
+ }
500
+ this.declare("declare i32 @llvm.fptosi.sat.i32.f64(double)");
501
+ const back = B.tmp(), exact = B.tmp(), bits = B.tmp(), notNegativeZero = B.tmp();
502
+ B.line(`${int} = call i32 @llvm.fptosi.sat.i32.f64(double ${value.name})`);
503
+ B.line(`${back} = sitofp i32 ${int} to double`);
504
+ B.line(`${exact} = fcmp oeq double ${back}, ${value.name}`);
505
+ B.line(`${bits} = bitcast double ${value.name} to i64`);
506
+ B.line(`${notNegativeZero} = icmp ne i64 ${bits}, -9223372036854775808`);
507
+ B.line(`${ok} = and i1 ${exact}, ${notNegativeZero}`);
508
+ const store = B.newLabel("arr.store.i32");
509
+ B.condBr(ok, store, resume);
510
+ B.startBlock(store);
511
+ return int;
512
+ }
513
+ /** Emit an access to the checked int32 array `array` once per element
514
+ * kind: `arm("i32", widened)` while it holds int32 slots and
515
+ * `arm("f64", widened)` after it widened, joined after both. `widened` is
516
+ * the label of the double arm, where an int32 arm's store of a value that
517
+ * is not an int32 continues after widening the array. Returns the phi of
518
+ * the arms' results (of LLVM type `ty`), or null when `ty` is null. */
519
+ emitByElementKind(array, ty, arm) {
520
+ const B = this.B;
521
+ const narrow = B.newLabel("arr.kind.i32"), wide = B.newLabel("arr.kind.f64"), join = B.newLabel("arr.kind.join");
522
+ const kindPtr = B.tmp(), kind = B.tmp(), isInt32 = B.tmp();
523
+ B.line(`${kindPtr} = getelementptr inbounds %ScrArr, ptr ${array}, i32 0, i32 ${SCR_ARR_FIELD.elem}`);
524
+ this.markMemoryPointer(kindPtr, "array:header");
525
+ B.line(`${kind} = load i8, ptr ${kindPtr}${this.fieldAliasAttachment(kindPtr)}`);
526
+ B.line(`${isInt32} = icmp eq i8 ${kind}, ${SCR_ELEM_I32}`);
527
+ B.condBr(isInt32, narrow, wide);
528
+ B.startBlock(narrow);
529
+ const narrowValue = arm("i32", wide);
530
+ const narrowEnd = B.isTerminated() ? null : B.currentLabel();
531
+ if (narrowEnd !== null)
532
+ B.br(join);
533
+ B.startBlock(wide);
534
+ const wideValue = arm("f64", wide);
535
+ const wideEnd = B.isTerminated() ? null : B.currentLabel();
536
+ if (wideEnd !== null)
537
+ B.br(join);
538
+ B.startBlock(join);
539
+ // Arms that end in their own branches (a read's shared join) leave this
540
+ // join without predecessors.
541
+ if (narrowEnd === null && wideEnd === null)
542
+ B.terminate("unreachable");
543
+ if (ty === null)
544
+ return null;
545
+ const arms = [];
546
+ if (narrowEnd !== null)
547
+ arms.push(`[ ${narrowValue}, %${narrowEnd} ]`);
548
+ if (wideEnd !== null)
549
+ arms.push(`[ ${wideValue}, %${wideEnd} ]`);
550
+ const result = B.tmp();
551
+ B.line(`${result} = phi ${ty} ${arms.join(", ")}`);
552
+ return result;
553
+ }
554
+ /** Before storing the double `value` (of `expr`) into an int32 arm
555
+ * (emitByElementKind) of the checked int32 array `array`: continue in this
556
+ * arm when it is an int32 that is not -0, or widen the array and continue
557
+ * at `widened`. A value proven an int32 needs no test. */
558
+ emitCheckedInt32Store(array, value, expr, widened) {
559
+ if (withinInt32(this.integerRanges.get(expr)))
560
+ return;
561
+ const B = this.B;
562
+ this.declare("declare i32 @llvm.fptosi.sat.i32.f64(double)");
563
+ this.declare("declare void @scr_arr_widen_i32(ptr)");
564
+ const int = B.tmp(), back = B.tmp(), exact = B.tmp(), bits = B.tmp(), notNegativeZero = B.tmp(), ok = B.tmp();
565
+ B.line(`${int} = call i32 @llvm.fptosi.sat.i32.f64(double ${value})`);
566
+ B.line(`${back} = sitofp i32 ${int} to double`);
567
+ B.line(`${exact} = fcmp oeq double ${back}, ${value}`);
568
+ B.line(`${bits} = bitcast double ${value} to i64`);
569
+ B.line(`${notNegativeZero} = icmp ne i64 ${bits}, -9223372036854775808`);
570
+ B.line(`${ok} = and i1 ${exact}, ${notNegativeZero}`);
571
+ const store = B.newLabel("arr.store.i32"), widen = B.newLabel("arr.widen");
572
+ B.condBr(ok, store, widen);
573
+ B.startBlock(widen);
574
+ B.line(`call void @scr_arr_widen_i32(ptr ${array})`);
575
+ B.br(widened);
576
+ B.startBlock(store);
577
+ }
578
+ /** The access an element operation on `arr` (of element type `elem`)
579
+ * takes: int32 arrays read and write their 4-byte slots. */
580
+ arrayAccess(arr, elem) {
581
+ if (this.checkedInt32Array(arr))
582
+ throw new InternalCompilerError("llvm emitter bug: a checked int32 array without its kind test");
583
+ return this.int32Array(arr) ? "i32" : elemAccess(elem);
584
+ }
332
585
  /** Whether an element access at `index` of `arr` lies in the hole-free
333
- * prefix: the counter of a dense array loop's fast copy indexing one of
334
- * the arrays its entry test covered. */
586
+ * prefix: a counter of a dense array loop's fast copy indexing one of the
587
+ * arrays its entry test covered. */
335
588
  provenDenseIndex(arr, index) {
336
- const loop = this.denseLoop;
589
+ const loop = LOOPS.of(this).denseLoop;
337
590
  return (loop !== null &&
338
591
  arr.kind === "varRef" &&
339
592
  loop.arrays.has(arr.localId) &&
340
593
  index.kind === "varRef" &&
341
- index.localId === loop.counter &&
342
- this.integerLoopBindings.has(loop.counter));
594
+ (index.localId === loop.counter || index.localId === loop.pair?.high) &&
595
+ this.integerLoopBindings.has(index.localId));
343
596
  }
344
597
  fieldAliasAttachment(ptr) {
345
598
  const tag = this.fieldPointerTags.get(ptr);
@@ -430,6 +683,10 @@ export class LlEmitter {
430
683
  cstrs = new Map();
431
684
  /** Interned ScrMapOps descriptors (scr_map.h): initializer → symbol. */
432
685
  mapOpsConsts = new Map();
686
+ /** Method-id slots of checked-dynamic method calls
687
+ * (scr_dyn_invoke_prepared_id): method name → symbol of an i32 the
688
+ * runtime fills with the name's id on the first call. */
689
+ methodIdSlots = new Map();
433
690
  /** Type-directed walker functions (JSON serializers, the indent
434
691
  * rewriter, union ToString/join) — interned per typeKey/unionId, defs
435
692
  * flushed with the shape helpers. */
@@ -478,6 +735,9 @@ export class LlEmitter {
478
735
  callLifetimes;
479
736
  constantCallbacks;
480
737
  currentConstantCallbacks = new Map();
738
+ /** The current function's running maximum and minimum updates, whose
739
+ * branches are weighted as rarely taken (running-extrema.ts). */
740
+ runningExtrema = new Set();
481
741
  /** Callback bindings whose closures an enclosing callback loop version
482
742
  * proved to hold their known function: calls take the direct entry with
483
743
  * no fallback (emitCallbackVersionedLoop). */
@@ -526,6 +786,9 @@ export class LlEmitter {
526
786
  /** Module constants that keep one value once initialized
527
787
  * (immutability.ts stableGlobals). */
528
788
  stableGlobals = new Set();
789
+ /** Every function body's nodes in walk order (ir/node-index.ts), for the
790
+ * constructor's analyses. */
791
+ nodeIndex;
529
792
  tdzGlobals = new Map();
530
793
  constantNumericTables;
531
794
  /** Constant-key reads on checked-dynamic objects, each with its own
@@ -593,7 +856,7 @@ export class LlEmitter {
593
856
  /** The module's runtime features (moduleRuntimeFeatures), found with one
594
857
  * walk of the module the first time any of them is read. */
595
858
  get runtimeFeatures() {
596
- return (this.runtimeFeaturesValue ??= moduleRuntimeFeatures(this.mod));
859
+ return (this.runtimeFeaturesValue ??= moduleRuntimeFeatures(this.mod, this.nodeIndex));
597
860
  }
598
861
  /** Whether timer and tick scheduling goes through the *_als entry
599
862
  * points (RuntimeFeatures asyncContext). */
@@ -618,6 +881,11 @@ export class LlEmitter {
618
881
  get usesDynBuiltinStream() {
619
882
  return this.runtimeFeatures.dynBuiltinStream;
620
883
  }
884
+ /** A checked-dynamic for-await may hold a native stream: the program
885
+ * links the stream unit (and the dyn-async one the loop needs). */
886
+ get dynForAwaitStreams() {
887
+ return this.runtimeFeatures.stream && this.runtimeFeatures.dynAsync;
888
+ }
621
889
  /** Runtime-arm dispatchers for live union values. */
622
890
  liveDynUnionRefAdapters = new Map();
623
891
  dynPromiseAdapters = new Map();
@@ -706,14 +974,6 @@ export class LlEmitter {
706
974
  * immortal from construction (classes.ts programLifetimeClass). */
707
975
  programLifetime;
708
976
  numericLocals = new Map();
709
- /** Local arrays of the current function that no other binding can hold
710
- * (ir/array-length-stability.ts). */
711
- unaliasedArrays = new Set();
712
- /** Dense array loops (dense-array-loops.ts) run in this function. */
713
- denseLoopsEnabled = false;
714
- denseLoopEntries = new Map();
715
- /** The fast copy of a dense array loop being emitted. */
716
- denseLoop = null;
717
977
  captureIds = new Set();
718
978
  /** Active induction bindings retain their width independently of size_t. */
719
979
  integerLoopBindings = new Map();
@@ -725,7 +985,6 @@ export class LlEmitter {
725
985
  * async or generator body resumes with its locals in its frame, which
726
986
  * an entry alloca is not part of. */
727
987
  integerTempsEnabled = false;
728
- countedLoopsEnabled = false;
729
988
  /** Speculative integer loops (speculative-integers.ts) run in this function. */
730
989
  speculativeLoopsEnabled = false;
731
990
  /** The fast copy of a speculative integer loop being emitted: its
@@ -739,6 +998,14 @@ export class LlEmitter {
739
998
  * (`enterLoopHeader`): records the ordinary copy's header, or sends the
740
999
  * third copy's header there. */
741
1000
  speculationHeader = null;
1001
+ /** A copy of an int32 kind loop (int32-kind-loops.ts) being emitted: the
1002
+ * int32 arrays with checked stores it reads and writes as int32 arrays
1003
+ * (the fast copy) or as double arrays (an ordinary copy entered only
1004
+ * after they widened), as `function\0local` keys, and where each of the
1005
+ * fast copy's writes resumes in the third copy. */
1006
+ int32Kinds = null;
1007
+ /** The resume label of the fast-copy write being emitted. */
1008
+ int32KindResume = null;
742
1009
  /** The function being emitted, for speculative globals. */
743
1010
  speculativeFunction = "";
744
1011
  /** Every function that writes each number global (computed on demand). */
@@ -756,20 +1023,14 @@ export class LlEmitter {
756
1023
  int32Elements = null;
757
1024
  /** Sums whose result only feeds 32-bit conversions (wrapping-sums.ts). */
758
1025
  wrappingSums = new Set();
759
- byteWindowsEnabled = true;
760
- byteWindowEntries = new Map();
761
- /** Typed-array loop versioning (bytes-loop-versions.ts) for the current
762
- * function: off in debug and suspending functions and inside a copy. */
763
- bytesLoopVersionsEnabled = false;
764
- /** Loops being versioned around the statement being emitted: a loop is
765
- * never versioned inside its own copies, and versions nest boundedly. */
766
- bytesLoopVersioning = new Set();
767
- bytesLoopEntries = null;
768
- bytesLoopFunction = null;
769
- /** Counted loops whose integer-form safety test an enclosing version
770
- * guard already passed. */
771
- provenCountedGuards = new Set();
1026
+ /** Number locals of the current function that hold exact integers or NaN
1027
+ * (findIntegerOrNaNLocals in wrapping-sums.ts). */
1028
+ integerOrNaNLocals = new Map();
772
1029
  bytesBounds = new Set();
1030
+ /** The charCodeAt reads standing for charAt reads the emitter rewrote
1031
+ * (one-unit tests and switches, charAtUnitRead), with the charAt each
1032
+ * stands for: a loop version's proof for the charAt covers its read. */
1033
+ charAtUnitReads = new Map();
773
1034
  /** Worker programs: typed-array accesses whose views an enclosing version
774
1035
  * guard proved thread-owned. */
775
1036
  bytesOwned = new Set();
@@ -823,31 +1084,50 @@ export class LlEmitter {
823
1084
  chainSlots = new Map();
824
1085
  logArgSlots = 0;
825
1086
  stackTraces;
1087
+ /** The options this emitter was built with (chunk emitters reuse them). */
1088
+ targetOptions;
1089
+ /** Records the module-level effects of emitting a range of functions,
1090
+ * which the emitter that merges the range replays (emit-journal.ts). Null
1091
+ * when this emitter emits the whole module itself. */
1092
+ journal;
1093
+ /** The emitter's hosts forward to `journal` (journal set, or workers). */
1094
+ journaled;
826
1095
  /** Stack-trace mode: functions no capture can include (no frame push). */
827
1096
  unframedFunctions;
828
- constructor(mod, options) {
1097
+ constructor(mod, options, journal = null) {
829
1098
  this.mod = mod;
830
- this.stackTraces = observesStacks(mod);
831
- this.nullableUnions = new NullableUnions(mod, options.debugSources === undefined);
1099
+ this.targetOptions = options;
1100
+ this.journal = journal;
1101
+ this.journaled =
1102
+ journal !== null ||
1103
+ ((options.functionWorkers ?? 1) > 1 &&
1104
+ options.forkPrimitives !== undefined &&
1105
+ options.debugSources === undefined);
1106
+ // One walk of every body, which the analyses below read instead of
1107
+ // walking the bodies themselves.
1108
+ this.nodeIndex = new IrNodeIndex(mod);
1109
+ this.stackTraces = observesStacks(mod, this.nodeIndex);
1110
+ this.nullableUnions = new NullableUnions(mod, options.debugSources === undefined, this.nodeIndex);
832
1111
  this.mockTimers = this.runtimeFeatures.mockTimers;
833
1112
  this.debug =
834
1113
  options.debugSources === undefined
835
1114
  ? null
836
1115
  : new LlvmDebugInfo(mod.sourceFile, options.debugSources, options.pointerBits, mod.unions, this.nullableUnions.armTypes());
837
1116
  this.constantNumericTables = findConstantNumericTables(mod);
838
- this.initializerBindings = findInitializerBindings(mod);
1117
+ this.initializerBindings = findInitializerBindings(mod, this.nodeIndex);
839
1118
  // One walk finds the dynamic field stores every analysis below consults.
840
- const dynamicStores = dynamicFieldStores(mod);
1119
+ const dynamicStores = dynamicFieldStores(mod, undefined, undefined, this.nodeIndex);
841
1120
  this.int32Slots = analyzeInt32Slots(mod, {
842
1121
  dynamicStores,
843
1122
  initializerBindings: this.initializerBindings,
1123
+ nodes: this.nodeIndex,
844
1124
  });
845
1125
  this.liveViewsReadOnly =
846
1126
  mod.lib === undefined && !dynamicStores.all && dynamicStores.names.size === 0;
847
1127
  this.int32Abis = this.debug === null ? findInt32Abis(mod, this.int32Slots) : new Map();
848
1128
  this.immortalGlobals = new Set(mod.contracts?.immortalGlobals ?? []);
849
1129
  this.programLifetime = new Set(mod.contracts?.programLifetime ?? []);
850
- this.finalFields = analyzeFinalFields(mod, false, dynamicStores);
1130
+ this.finalFields = analyzeFinalFields(mod, false, dynamicStores, this.nodeIndex);
851
1131
  this.sizeType = options.pointerBits === 32 ? "i32" : "i64";
852
1132
  this.ffiExtendNarrowIntegers =
853
1133
  options.wasi === true || ffiExtendsNarrowIntegers(options.targetTriple);
@@ -896,7 +1176,7 @@ export class LlEmitter {
896
1176
  this.ffiHasForeignCallback = hasForeignFfiCallback(mod.ffiImports ?? []);
897
1177
  for (const fn of mod.functions)
898
1178
  this.fnByName.set(fn.name, fn);
899
- this.appendedArrayLiterals = findAppendedArrayLiterals(mod);
1179
+ this.appendedArrayLiterals = findAppendedArrayLiterals(mod, this.nodeIndex);
900
1180
  for (const entry of mod.ffiImports ?? []) {
901
1181
  this.ffiByName.set(entry.name, entry);
902
1182
  }
@@ -904,8 +1184,11 @@ export class LlEmitter {
904
1184
  // and per async fiber; WASI, Windows and library builds have none.
905
1185
  const triple = (options.targetTriple ?? "").toLowerCase();
906
1186
  const windows = triple === "" ? process.platform === "win32" : triple.includes("windows");
1187
+ this.publishedTypes = computePublishedTypes(mod, this.nodeIndex);
907
1188
  const mt = computeMayThrow(mod, {
908
1189
  stackChecks: !this.wasi && mod.lib === undefined && !windows,
1190
+ published: this.publishedTypes,
1191
+ nodes: this.nodeIndex,
909
1192
  });
910
1193
  this.mayThrow = mt.fns;
911
1194
  this.workerEntryPolls = mt.workerEntryPolls ?? null;
@@ -914,11 +1197,12 @@ export class LlEmitter {
914
1197
  // runtime moves deep prefix nests to a fresh stack using the guard,
915
1198
  // which Windows lacks.
916
1199
  this.stacklessAsyncAllowed = this.stacklessGenerators && mod.lib === undefined && !windows;
917
- this.publishedTypes = computePublishedTypes(mod);
918
1200
  this.unframedFunctions = this.stackTraces
919
1201
  ? captureFreeFunctions(mod, this.stackChecks, this.publishedTypes)
920
1202
  : new Set();
921
- this.immutableFields = computeImmutableFields(mod, dynamicStores);
1203
+ // One field-mutability answer serves immutable fields and traced shapes.
1204
+ const cycleMutability = computeCycleMutability(mod, hierarchyUnitOfClass(mod), dynamicStores);
1205
+ this.immutableFields = computeImmutableFields(mod, dynamicStores, cycleMutability);
922
1206
  this.constructorFunctions = new Set((mod.classes ?? []).map((c) => `%${c.name}.constructor`));
923
1207
  this.indirectMayThrow = mt.indirect || mod.workers === true;
924
1208
  for (const cls of mod.classes ?? []) {
@@ -951,12 +1235,13 @@ export class LlEmitter {
951
1235
  this.checkedNarrows = new CheckedNarrows(this.fnByName);
952
1236
  this.referenceEffects = new ReferenceEffects(this.fnByName, (call) => this.optionalArrayReads.get(call) !== null, mod.classes ?? []);
953
1237
  if (this.debug === null)
954
- this.referenceWrites = new ReferenceWrites(this.fnByName, mod.classes ?? [], (call) => this.optionalArrayReads.get(call) !== null, new Set((mod.globals ?? []).map((g) => g.id)), { unions: mod.unions, records: mod.records }, this.immutableFields);
1238
+ this.referenceWrites = new ReferenceWrites(this.fnByName, mod.classes ?? [], (call) => this.optionalArrayReads.get(call) !== null, new Set((mod.globals ?? []).map((g) => g.id)), { unions: mod.unions, records: mod.records }, this.immutableFields, this.nodeIndex);
955
1239
  const walkParameters = new Map();
956
1240
  if (this.debug === null) {
957
1241
  const host = {
958
1242
  pointerLocal: (local) => this.plainReference(local.type),
959
1243
  borrowsWithoutOwning: (e) => this.borrowsWithoutOwning(e),
1244
+ nodes: this.nodeIndex,
960
1245
  };
961
1246
  for (const fn of this.fnByName.values()) {
962
1247
  const preserving = this.referenceEffects.functions.has(fn.name);
@@ -1003,7 +1288,7 @@ export class LlEmitter {
1003
1288
  });
1004
1289
  this.lentStringParameters =
1005
1290
  this.debug === null ? findLentStringParameters(this.fnByName, this.callLifetimes) : new Map();
1006
- this.constantCallbacks = findConstantCallbacks(mod, this.callLifetimes);
1291
+ this.constantCallbacks = findConstantCallbacks(mod, this.callLifetimes, this.nodeIndex);
1007
1292
  // Integer clones signal a stack overflow through their result, which
1008
1293
  // needs the single-threaded guard; worker programs also poll for
1009
1294
  // termination, and debug builds and stack traces keep every frame.
@@ -1022,7 +1307,7 @@ export class LlEmitter {
1022
1307
  this.receiverReaders = new AmbientReceiverReaders(this.fnByName);
1023
1308
  this.stackCaptures = new StackCaptures(this.fnByName, this.callLifetimes, this.stackCallbacks);
1024
1309
  this.lazyCaptures = new LazyCaptures(this.fnByName);
1025
- const traced = computeTraced(mod, dynamicStores);
1310
+ const traced = computeTraced(mod, dynamicStores, cycleMutability);
1026
1311
  this.tracedShapes = traced.shapes;
1027
1312
  this.tracedUnions = traced.unions;
1028
1313
  // A shape union's value is whichever record it holds, and the collector
@@ -1046,6 +1331,22 @@ export class LlEmitter {
1046
1331
  }
1047
1332
  }
1048
1333
  this.shapeHost = {
1334
+ // Journal hooks only on emitters that can emit ranges (chunk
1335
+ // emitters, and emitters whose workers take a journal after the
1336
+ // fork), so the host's optional calls cost nothing otherwise.
1337
+ journalAllocated: !this.journaled
1338
+ ? undefined
1339
+ : (name, op, args) => this.journal?.allocated(name, op, args),
1340
+ journalBuilt: !this.journaled ? undefined : () => this.journal?.built(),
1341
+ journalOpened: !this.journaled ? undefined : (op) => this.journal?.opened(op),
1342
+ journalUsed: !this.journaled
1343
+ ? undefined
1344
+ : (name, op, args) => this.journal?.used(name, op, args),
1345
+ journalEntry: !this.journaled
1346
+ ? undefined
1347
+ : (table, key, value) => this.journal?.entry(table, key, value),
1348
+ compactArrayElem: (elem) => this.compactArrayElem(elem),
1349
+ compactRegion: () => this.compactRegion,
1049
1350
  sizeType: this.sizeType,
1050
1351
  cycleBufOffset: this.cycleBufOffset,
1051
1352
  tracedShapes: this.tracedShapes,
@@ -1084,9 +1385,16 @@ export class LlEmitter {
1084
1385
  liveDynRefAdapter: (type) => this.liveDynRefAdapter(type),
1085
1386
  usesDynBuiltinStream: () => this.usesDynBuiltinStream,
1086
1387
  liveDynUnionRefAdapter: (type) => this.liveDynUnionRefAdapter(type),
1388
+ declBoundary: () => this.mod.declBoundary === true,
1087
1389
  dynPromiseAdapter: (type) => this.dynPromiseAdapter(type),
1088
1390
  isErrorClass: (name) => this.classMeta.get(name)?.root.def.name === "%Error",
1089
1391
  classRootOf: (name) => this.classMeta.get(name)?.root.def.name,
1392
+ releasesNothing: (t) => {
1393
+ if (t.kind !== "object" || (this.shapeHost.regions ?? null) !== null)
1394
+ return false;
1395
+ const meta = this.classMeta.get(t.className);
1396
+ return meta !== undefined && programLifetimeClass(this.shapeHost, meta);
1397
+ },
1090
1398
  classSubtypes: (name) => {
1091
1399
  const target = this.classMetaOf(name);
1092
1400
  const intervals = classMembershipIntervals(this.classMeta, target.def.name);
@@ -1119,7 +1427,7 @@ export class LlEmitter {
1119
1427
  if (g.tdz)
1120
1428
  this.tdzGlobals.set(g.id, g.name);
1121
1429
  }
1122
- this.stableGlobals = stableGlobals(mod);
1430
+ this.stableGlobals = stableGlobals(mod, this.nodeIndex);
1123
1431
  // Runtime error, EventEmitter, stream, EventTarget and Event classes
1124
1432
  // have known layouts. Subclasses embed the runtime prefixes from
1125
1433
  // classes.ts.
@@ -1165,21 +1473,18 @@ export class LlEmitter {
1165
1473
  const f = cls.fields[i];
1166
1474
  if (this.inlineUnions.classField(cls.name, f.name))
1167
1475
  return false;
1168
- const t = f.type;
1169
- if (t.kind === "object")
1170
- return isCompact(t.className);
1171
- if (t.kind !== "union")
1172
- return false;
1173
- const single = this.nullableUnions.single(t.unionId);
1174
- if (single !== null)
1175
- return (single.nullTag < 0 &&
1176
- single.arm.kind === "object" &&
1177
- isCompact(single.arm.className));
1178
- const nullable = this.nullableFields.get(cls.name, f.name);
1476
+ if (this.compactRefType(f.type, isCompact))
1477
+ return true;
1478
+ const nullable = f.type.kind === "union" && this.nullableUnions.single(f.type.unionId) === null
1479
+ ? this.nullableFields.get(cls.name, f.name)
1480
+ : null;
1179
1481
  return nullable !== null && isCompact(nullable.arm.className);
1180
1482
  }
1181
1483
  : undefined);
1182
- this.usesCompactRefs = [...this.classMeta.values()].some((m) => m.compressed.some(Boolean));
1484
+ this.compactRegion =
1485
+ mod.lib === undefined &&
1486
+ options.lowRegion === true &&
1487
+ [...this.classMeta.values()].some((m) => m.compact);
1183
1488
  for (const [name, rec] of RUNTIME_ERROR_CLASSES) {
1184
1489
  const meta = this.classMeta.get(name);
1185
1490
  if (!meta)
@@ -1777,7 +2082,7 @@ export class LlEmitter {
1777
2082
  B.startBlock(clean);
1778
2083
  if (acc === "ref")
1779
2084
  this.toHeap(value);
1780
- this.arrPush(values, acc, value.name);
2085
+ this.arrPush(values, acc, value.name, elem);
1781
2086
  B.br(next);
1782
2087
  B.startBlock(rejected);
1783
2088
  const promise = B.tmp();
@@ -1891,6 +2196,7 @@ export class LlEmitter {
1891
2196
  };
1892
2197
  this.literals.set(text, lit);
1893
2198
  }
2199
+ this.journal?.entry("literal", text, lit);
1894
2200
  const name = `@${lit.sym}`;
1895
2201
  this.immortalValues.add(name);
1896
2202
  return name;
@@ -1900,6 +2206,7 @@ export class LlEmitter {
1900
2206
  literalEquals(text) {
1901
2207
  const literal = this.internLiteral(text);
1902
2208
  const name = `@sc_streq_${literal.slice("@sc_lit_".length)}`;
2209
+ this.journal?.entry("literalEquality", text, name);
1903
2210
  if (!this.literalEqualities.has(text)) {
1904
2211
  this.literalEqualities.set(text, name);
1905
2212
  if (Buffer.byteLength(text, "utf8") > INLINE_LITERAL_BYTES) {
@@ -1926,6 +2233,7 @@ export class LlEmitter {
1926
2233
  lit = { sym: this.contentSymbol("sc_bigint_", key), value };
1927
2234
  this.bigintLiterals.set(key, lit);
1928
2235
  }
2236
+ this.journal?.entry("bigint", key, { sym: lit.sym, value: lit.value.toString() });
1929
2237
  const name = `@${lit.sym}`;
1930
2238
  this.immortalValues.add(name);
1931
2239
  return name;
@@ -1938,8 +2246,19 @@ export class LlEmitter {
1938
2246
  c = { sym: this.contentSymbol("sc_cs_", text), len: Buffer.byteLength(text, "utf8") };
1939
2247
  this.cstrs.set(text, c);
1940
2248
  }
2249
+ this.journal?.entry("cstr", text, c);
1941
2250
  return `@${c.sym}`;
1942
2251
  }
2252
+ /** The method-id slot for a constant method name (methodIdSlots). */
2253
+ methodIdSlot(name) {
2254
+ let sym = this.methodIdSlots.get(name);
2255
+ if (!sym) {
2256
+ sym = this.contentSymbol("sc_mid_", name);
2257
+ this.methodIdSlots.set(name, sym);
2258
+ }
2259
+ this.journal?.entry("methodIdSlot", name, sym);
2260
+ return `@${sym}`;
2261
+ }
1943
2262
  needBadTag() {
1944
2263
  this.needsBadTag = true;
1945
2264
  }
@@ -1953,6 +2272,7 @@ export class LlEmitter {
1953
2272
  sym = this.contentSymbol("sc_map_ops_", body);
1954
2273
  this.mapOpsConsts.set(body, sym);
1955
2274
  }
2275
+ this.journal?.entry("mapOps", body, sym);
1956
2276
  return `@${sym}`;
1957
2277
  }
1958
2278
  /** The interned immortal instance for a UNIT arm of a union — asserts
@@ -1976,6 +2296,7 @@ export class LlEmitter {
1976
2296
  sym = `sc_unit_${this.unitInstances.size}`;
1977
2297
  this.unitInstances.set(key, sym);
1978
2298
  }
2299
+ this.journal?.entry("unit", key, sym);
1979
2300
  const name = `@${sym}`;
1980
2301
  this.immortalValues.add(name);
1981
2302
  return name;
@@ -1988,6 +2309,7 @@ export class LlEmitter {
1988
2309
  sym = `sc_retype_guard_${this.retypeGuards.size}`;
1989
2310
  this.retypeGuards.set(unionId, sym);
1990
2311
  }
2312
+ this.journal?.entry("retype", unionId, sym);
1991
2313
  return `@${sym}`;
1992
2314
  }
1993
2315
  /** The immortal ABSENT state of an undefined-armed record field slot
@@ -2006,6 +2328,7 @@ export class LlEmitter {
2006
2328
  sym = `sc_absent_${this.absentInstances.size}`;
2007
2329
  this.absentInstances.set(unionId, sym);
2008
2330
  }
2331
+ this.journal?.entry("absent", unionId, sym);
2009
2332
  const name = `@${sym}`;
2010
2333
  this.immortalValues.add(name);
2011
2334
  return name;
@@ -2046,6 +2369,7 @@ export class LlEmitter {
2046
2369
  return out;
2047
2370
  }
2048
2371
  declare(decl) {
2372
+ this.journal?.entry("decl", decl, null);
2049
2373
  this.decls.add(decl);
2050
2374
  }
2051
2375
  needOom() {
@@ -3056,6 +3380,24 @@ export class LlEmitter {
3056
3380
  this.compressedFieldPtrs.add(p);
3057
3381
  return { ptr: p, type, inline: this.inlineUnions.classField(className, field), compressed };
3058
3382
  }
3383
+ /** Whether values of `t` are NULL or a compact class instance: `C`,
3384
+ * `C | undefined` or `C | null` for a compact class `C`. `C | null |
3385
+ * undefined` is not: its null is a sentinel outside the region. */
3386
+ compactRefType(t, isCompact = (name) => this.classMeta.get(name)?.compact === true) {
3387
+ if (t.kind === "object")
3388
+ return isCompact(t.className);
3389
+ if (t.kind !== "union")
3390
+ return false;
3391
+ const single = this.nullableUnions.single(t.unionId);
3392
+ return (single !== null &&
3393
+ single.nullTag < 0 &&
3394
+ single.arm.kind === "object" &&
3395
+ isCompact(single.arm.className));
3396
+ }
3397
+ /** Whether arrays of `elem` hold 32-bit references (SCR_ELEM_CREF). */
3398
+ compactArrayElem(elem) {
3399
+ return this.compactRegion && this.compactRefType(elem);
3400
+ }
3059
3401
  /** Loads the reference a field pointer addresses: a pointer, or the
3060
3402
  * decoded 32-bit reference of a compressed field (compressedFieldPtrs).
3061
3403
  * `tagged`: the load carries the field's alias tags. */
@@ -3104,6 +3446,7 @@ export class LlEmitter {
3104
3446
  const meta = this.classMetaOf(className);
3105
3447
  this.classObjs.set(className, { nameSym: this.internLiteral(classJsName(meta.def)) });
3106
3448
  }
3449
+ this.journal?.entry("classObj", className, this.classObjs.get(className));
3107
3450
  return mangleClassObj(className);
3108
3451
  }
3109
3452
  // ── record plumbing ─────────────────────────────────────────────────────
@@ -3292,12 +3635,12 @@ export class LlEmitter {
3292
3635
  // ── bindings ────────────────────────────────────────────────────────────
3293
3636
  /** A binding's storage: a module global, a plain local slot, or a boxed
3294
3637
  * local (the slot holds the capture BOX; access goes through it). */
3295
- matchBytesLoopVersion(s, counted) {
3296
- const fn = this.bytesLoopFunction;
3638
+ matchBytesLoopVersion(s, counted, paired = null) {
3639
+ const fn = LOOPS.of(this).bytesLoopFunction;
3297
3640
  if (!fn)
3298
3641
  return null;
3299
- this.bytesLoopEntries ??= findInitializedByteLoopBindings(fn);
3300
- const initialized = this.bytesLoopEntries.get(s);
3642
+ LOOPS.of(this).bytesLoopEntries ??= findInitializedByteLoopBindings(fn);
3643
+ const initialized = LOOPS.of(this).bytesLoopEntries.get(s);
3301
3644
  if (!initialized)
3302
3645
  return null;
3303
3646
  const invariantGlobals = new Set(this.stableGlobals);
@@ -3312,7 +3655,8 @@ export class LlEmitter {
3312
3655
  proven: this.bytesBounds,
3313
3656
  workers: this.mod.workers === true,
3314
3657
  owned: this.bytesOwned,
3315
- });
3658
+ scalarStrings: new Set(this.stringSlices.keys()),
3659
+ }, paired);
3316
3660
  }
3317
3661
  /** The alias tag of a whole-slot load of a binding (module globals only). */
3318
3662
  slotAlias(id) {
@@ -3456,7 +3800,7 @@ export class LlEmitter {
3456
3800
  const acc = boxAccess(t);
3457
3801
  const cell = B.tmp();
3458
3802
  B.line(`${cell} = ${arrNewCall(this.shapeHost, t, "1")} ; TDZ cell`);
3459
- this.arrPush(cell, acc === "bool" ? "bool" : "f64", value);
3803
+ this.arrPush(cell, acc === "bool" ? "bool" : "f64", value, null);
3460
3804
  this.declare(`declare void @scr_box_set_ref(ptr, ptr)`);
3461
3805
  B.line(`call void @scr_box_set_ref(ptr ${box}, ptr ${cell})`);
3462
3806
  }
@@ -3746,6 +4090,171 @@ export class LlEmitter {
3746
4090
  emitFunction(fn) {
3747
4091
  return emitFunction(this, fn);
3748
4092
  }
4093
+ /** What this range emitter (chunkEmitter) hands the merging emitter, as
4094
+ * plain data a worker process can write: its journal and the sets and
4095
+ * flags its functions set. */
4096
+ chunkResult() {
4097
+ return {
4098
+ entries: this.journal.entries,
4099
+ flags: {
4100
+ usesCoroutines: this.usesCoroutines,
4101
+ usesTimers: this.usesTimers,
4102
+ usesGenSlots: this.usesGenSlots,
4103
+ needsUnionNone: this.needsUnionNone,
4104
+ needsNullableAbsent: this.needsNullableAbsent,
4105
+ needsOom: this.needsOom,
4106
+ needsBadTag: this.needsBadTag,
4107
+ needsBadKey: this.needsBadKey,
4108
+ needsRetainBox: this.needsRetainBox,
4109
+ },
4110
+ publishedNamesSym: this.publishedNamesSym,
4111
+ rcHelpers: this.rcHelpers === null ? [] : [...this.rcHelpers],
4112
+ immortalValues: [...this.immortalValues],
4113
+ fnValues: [...this.fnValues],
4114
+ arraySearchKinds: [...this.arraySearchKinds],
4115
+ recordCloneShapes: [...this.recordCloneShapes],
4116
+ awaitCallees: [...this.awaitCallees],
4117
+ adoptCallees: [...this.adoptCallees],
4118
+ directAwaitCallees: [...this.directAwaitCallees],
4119
+ inlineAwaitCallees: [...this.inlineAwaitCallees],
4120
+ };
4121
+ }
4122
+ /** Merges a range emitter's result (chunkResult) into this emitter, in
4123
+ * the range's order, and answers the rename of the range's text to this
4124
+ * emitter's numbered helpers. Ranges merge in function order. */
4125
+ mergeChunk(chunk) {
4126
+ const names = new Map();
4127
+ const tags = new Map();
4128
+ // The range's helpers and table entries first, in its order; then the
4129
+ // sets and flags, which replayed definitions must find as serial
4130
+ // emission left them (a helper set guards the declarations its first
4131
+ // request adds).
4132
+ replayJournal(this, chunk.entries, names, tags);
4133
+ const flags = chunk.flags;
4134
+ this.usesCoroutines ||= flags.usesCoroutines;
4135
+ this.usesTimers ||= flags.usesTimers;
4136
+ this.usesGenSlots ||= flags.usesGenSlots;
4137
+ this.needsUnionNone ||= flags.needsUnionNone;
4138
+ this.needsNullableAbsent ||= flags.needsNullableAbsent;
4139
+ this.needsOom ||= flags.needsOom;
4140
+ this.needsBadTag ||= flags.needsBadTag;
4141
+ this.needsBadKey ||= flags.needsBadKey;
4142
+ this.needsRetainBox ||= flags.needsRetainBox;
4143
+ this.publishedNamesSym ??= chunk.publishedNamesSym;
4144
+ if (this.rcHelpers !== null)
4145
+ for (const key of chunk.rcHelpers)
4146
+ this.rcHelpers.add(key);
4147
+ for (const name of chunk.immortalValues)
4148
+ this.immortalValues.add(name);
4149
+ for (const name of chunk.fnValues)
4150
+ this.fnValues.add(name);
4151
+ for (const kind of chunk.arraySearchKinds)
4152
+ this.arraySearchKinds.add(kind);
4153
+ for (const shapeId of chunk.recordCloneShapes)
4154
+ this.recordCloneShapes.add(shapeId);
4155
+ for (const name of chunk.awaitCallees)
4156
+ this.awaitCallees.add(name);
4157
+ for (const name of chunk.adoptCallees)
4158
+ this.adoptCallees.add(name);
4159
+ for (const name of chunk.directAwaitCallees)
4160
+ this.directAwaitCallees.add(name);
4161
+ for (const name of chunk.inlineAwaitCallees)
4162
+ this.inlineAwaitCallees.add(name);
4163
+ return renameChunk(names, tags);
4164
+ }
4165
+ /** Adds a content-named constant a chunk interned. Its symbol is this
4166
+ * emitter's own: a digest collision retries in first-use order, which a
4167
+ * chunk alone does not know. */
4168
+ addContentEntry(into, key, entry, prefix, names) {
4169
+ let own = into.get(key);
4170
+ if (own === undefined) {
4171
+ own = { ...entry, sym: this.contentSymbol(prefix, key) };
4172
+ into.set(key, own);
4173
+ }
4174
+ if (own.sym !== entry.sym)
4175
+ names.set(entry.sym, own.sym);
4176
+ }
4177
+ /** Applies a chunk's table entry (EmitJournal.entry) at its place in the
4178
+ * chunk's order: a key this emitter lacks is added, numbered after its
4179
+ * own entries where the table numbers them, and the chunk's name for it
4180
+ * is renamed to this emitter's. */
4181
+ applyJournalEntry(table, key, value, names, tags) {
4182
+ switch (table) {
4183
+ case "decl":
4184
+ this.decls.add(key);
4185
+ return;
4186
+ case "literal":
4187
+ this.addContentEntry(this.literals, key, value, "sc_lit_", names);
4188
+ return;
4189
+ case "literalEquality":
4190
+ addEntry(this.literalEqualities, key, value);
4191
+ return;
4192
+ case "bigint":
4193
+ {
4194
+ const entry = value;
4195
+ this.addContentEntry(this.bigintLiterals, key, { sym: entry.sym, value: BigInt(entry.value) }, "sc_bigint_", names);
4196
+ }
4197
+ return;
4198
+ case "cstr":
4199
+ this.addContentEntry(this.cstrs, key, value, "sc_cs_", names);
4200
+ return;
4201
+ case "mapOps": {
4202
+ let own = this.mapOpsConsts.get(key);
4203
+ if (own === undefined) {
4204
+ own = this.contentSymbol("sc_map_ops_", key);
4205
+ this.mapOpsConsts.set(key, own);
4206
+ }
4207
+ if (own !== value)
4208
+ names.set(value, own);
4209
+ return;
4210
+ }
4211
+ case "methodIdSlot": {
4212
+ let own = this.methodIdSlots.get(key);
4213
+ if (own === undefined) {
4214
+ own = this.contentSymbol("sc_mid_", key);
4215
+ this.methodIdSlots.set(key, own);
4216
+ }
4217
+ if (own !== value)
4218
+ names.set(value, own);
4219
+ return;
4220
+ }
4221
+ case "classObj":
4222
+ addEntry(this.classObjs, key, value);
4223
+ return;
4224
+ case "retainWrapper":
4225
+ addEntry(this.nullableUnions.retainWrappers, key, value);
4226
+ return;
4227
+ case "unit":
4228
+ return addNumbered(this.unitInstances, key, value, "sc_unit_", names);
4229
+ case "absent":
4230
+ return addNumbered(this.absentInstances, key, value, "sc_absent_", names);
4231
+ case "retype":
4232
+ return addNumbered(this.retypeGuards, key, value, "sc_retype_guard_", names);
4233
+ case "slots":
4234
+ return addNumbered(this.threadSlotsBlocks, key, value, "@sc_slots_", names);
4235
+ case "regex":
4236
+ return addNumberedSymbol(this.regexInstances, key, value, "sc_re_", names);
4237
+ case "templateStrings":
4238
+ return addNumberedSymbol(this.templateStringsInstances, key, value, "sc_tsa_", names);
4239
+ case "tag": {
4240
+ let own = this.fieldAliasTags.get(key);
4241
+ if (own === undefined) {
4242
+ own = 2 + this.fieldAliasTags.size * 2;
4243
+ this.fieldAliasTags.set(key, own);
4244
+ }
4245
+ if (own !== value)
4246
+ tags.set(value, own);
4247
+ return;
4248
+ }
4249
+ default:
4250
+ throw new InternalCompilerError(`llvm emitter bug: no journal table ${table}`);
4251
+ }
4252
+ }
4253
+ /** An emitter for a range of this module's functions: the same facts,
4254
+ * empty module-level tables, and a journal of what the range adds. */
4255
+ chunkEmitter() {
4256
+ return new LlEmitter(this.mod, { ...this.targetOptions, functionChunks: 1 }, new EmitJournal());
4257
+ }
3749
4258
  /** The double-ABI entry of a function with an i32 entry: every caller
3750
4259
  * that is not a direct call (closures, dispatch, adapters, the runtime)
3751
4260
  * enters here. A pending exception passes through to its caller. */
@@ -4341,11 +4850,15 @@ export class LlEmitter {
4341
4850
  const loop = s.kind === "while" || s.kind === "doWhile" || s.kind === "for" || s.kind === "forOf";
4342
4851
  if (loop)
4343
4852
  this.loopDepth++;
4853
+ // An int32 kind loop's fast-copy write leaves for its resume point.
4854
+ const kindResume = this.int32KindResume;
4855
+ this.int32KindResume = this.int32Kinds?.resume.get(s) ?? null;
4344
4856
  try {
4345
4857
  this.emitStmtBody(s);
4346
4858
  }
4347
4859
  finally {
4348
4860
  this.B.debugLocation = previous;
4861
+ this.int32KindResume = kindResume;
4349
4862
  if (loop)
4350
4863
  this.loopDepth--;
4351
4864
  }
@@ -4669,6 +5182,7 @@ export class LlEmitter {
4669
5182
  sym = `@sc_slots_${this.threadSlotsBlocks.size}`;
4670
5183
  this.threadSlotsBlocks.set(name, sym);
4671
5184
  }
5185
+ this.journal?.entry("slots", name, sym);
4672
5186
  return sym;
4673
5187
  }
4674
5188
  /** InternTable's runtime calls (scr_itable.c). Table and entry handles
@@ -4822,6 +5336,20 @@ export class LlEmitter {
4822
5336
  return this.publishWalkersCache;
4823
5337
  const byPre = [...this.classMeta.values()].sort((a, b) => a.pre - b.pre);
4824
5338
  this.publishWalkersCache = new PublishWalkers({
5339
+ // Journal hooks only on emitters that can emit ranges (chunk
5340
+ // emitters, and emitters whose workers take a journal after the
5341
+ // fork), so the host's optional calls cost nothing otherwise.
5342
+ journalAllocated: !this.journaled
5343
+ ? undefined
5344
+ : (name, op, args) => this.journal?.allocated(name, op, args),
5345
+ journalBuilt: !this.journaled ? undefined : () => this.journal?.built(),
5346
+ journalOpened: !this.journaled ? undefined : (op) => this.journal?.opened(op),
5347
+ journalUsed: !this.journaled
5348
+ ? undefined
5349
+ : (name, op, args) => this.journal?.used(name, op, args),
5350
+ journalEntry: !this.journaled
5351
+ ? undefined
5352
+ : (table, key, value) => this.journal?.entry(table, key, value),
4825
5353
  declare: (decl) => this.declare(decl),
4826
5354
  cstr: (text) => this.cstr(text),
4827
5355
  sizeType: this.sizeType,
@@ -4906,6 +5434,33 @@ export class LlEmitter {
4906
5434
  B.startBlock(cold);
4907
5435
  return ok;
4908
5436
  }
5437
+ /** Branches on "the array `arr` is frozen" (SCR_ARR_FROZEN in its storage
5438
+ * flags, scr_array.h), or published too when `published`; like
5439
+ * emitPublishedTest, leaves the builder in the cold block and answers the
5440
+ * continuation label. */
5441
+ emitFrozenArrayTest(arr, published) {
5442
+ const B = this.B;
5443
+ const sparep = B.tmp(), spare = B.tmp(), bit = B.tmp();
5444
+ let frozen = B.tmp();
5445
+ B.line(`${sparep} = getelementptr inbounds %ScrArr, ptr ${arr}, i32 0, i32 ${SCR_ARR_FIELD.spare}`);
5446
+ B.line(`${spare} = load i16, ptr ${sparep}`);
5447
+ B.line(`${bit} = and i16 ${spare}, ${SCR_ARR_FROZEN}`);
5448
+ B.line(`${frozen} = icmp ne i16 ${bit}, 0`);
5449
+ if (published) {
5450
+ const rc = B.tmp(), immortal = B.tmp(), either = B.tmp();
5451
+ B.line(`${rc} = load ${this.sizeType}, ptr ${arr}`);
5452
+ B.line(`${immortal} = icmp eq ${this.sizeType} ${rc}, -1`);
5453
+ B.line(`${either} = or i1 ${frozen}, ${immortal}`);
5454
+ frozen = either;
5455
+ }
5456
+ this.declare(`declare i1 @llvm.expect.i1(i1, i1)`);
5457
+ const expected = B.tmp();
5458
+ B.line(`${expected} = call i1 @llvm.expect.i1(i1 ${frozen}, i1 false)`);
5459
+ const cold = B.newLabel("arr.frozen"), ok = B.newLabel("arr.ok");
5460
+ B.condBr(expected, cold, ok);
5461
+ B.startBlock(cold);
5462
+ return ok;
5463
+ }
4909
5464
  publishedNamesSym = null;
4910
5465
  /** The class-name table the hierarchy field guards index by preorder. */
4911
5466
  publishedClassNamesDefs() {
@@ -4960,14 +5515,24 @@ export class LlEmitter {
4960
5515
  }
4961
5516
  /** The frozen-array guard (scr_throw_published_array's ops): `index` and
4962
5517
  * `count` are doubles (the written index, the argument count). */
4963
- emitPublishedArrayGuard(arr, arrType, op, index = f64Lit(0), count = f64Lit(0)) {
4964
- if (this.publishedTypes?.containerGuarded(arrType) !== true)
5518
+ emitPublishedArrayGuard(arr, arrType, op, index = f64Lit(0), count = f64Lit(0), third = null) {
5519
+ const published = this.publishedTypes;
5520
+ if (published?.containerGuarded(arrType) !== true)
4965
5521
  return;
4966
5522
  const B = this.B;
4967
- const ok = this.emitPublishedTest(arr);
4968
- this.declare(`declare zeroext i1 @scr_throw_published_array(i32, ptr, double, double)`);
5523
+ const guards = published.arrayGuards(arrType);
5524
+ const ok = guards.frozen
5525
+ ? this.emitFrozenArrayTest(arr, guards.published)
5526
+ : this.emitPublishedTest(arr);
4969
5527
  const threw = B.tmp();
4970
- B.line(`${threw} = call zeroext i1 @scr_throw_published_array(i32 ${op}, ptr ${arr}, double ${index}, double ${count})`);
5528
+ if (third === null) {
5529
+ this.declare(`declare zeroext i1 @scr_throw_published_array(i32, ptr, double, double)`);
5530
+ B.line(`${threw} = call zeroext i1 @scr_throw_published_array(i32 ${op}, ptr ${arr}, double ${index}, double ${count})`);
5531
+ }
5532
+ else {
5533
+ this.declare(`declare zeroext i1 @scr_throw_published_array_range(i32, ptr, double, double, double)`);
5534
+ B.line(`${threw} = call zeroext i1 @scr_throw_published_array_range(i32 ${op}, ptr ${arr}, double ${index}, double ${count}, double ${third})`);
5535
+ }
4971
5536
  const unwind = B.newLabel("pub.throw");
4972
5537
  B.condBr(threw, unwind, ok);
4973
5538
  B.startBlock(unwind);
@@ -5253,11 +5818,25 @@ export class LlEmitter {
5253
5818
  return (this.jsIcSitesMemo ??= new JsIcSites(this.mod));
5254
5819
  }
5255
5820
  jsIcSite() {
5256
- return `@sc_js_ic_${this.jsIcSiteCount++}`;
5821
+ const name = `@sc_js_ic_${this.jsIcSiteCount++}`;
5822
+ this.journal?.site(name, "jsIcSite");
5823
+ return name;
5257
5824
  }
5258
5825
  /** A fresh read-site cache for one constant-key dyn read. */
5259
5826
  dynReadIcSite() {
5260
- return `@sc_dyn_read_ic_${this.dynReadIcSites++}`;
5827
+ const name = `@sc_dyn_read_ic_${this.dynReadIcSites++}`;
5828
+ this.journal?.site(name, "dynReadIcSite");
5829
+ return name;
5830
+ }
5831
+ /** A fresh speculative loop site: the global that counts its bailing
5832
+ * entries in a row. */
5833
+ speculativeLoopSite() {
5834
+ const name = `@sc_spec_bails_${this.speculativeLoopSites++}`;
5835
+ this.journal?.site(name, "speculativeLoopSite");
5836
+ this.journal?.opened("speculativeLoopSite");
5837
+ this.declare(`${name} = internal global i8 0`);
5838
+ this.journal?.built();
5839
+ return name;
5261
5840
  }
5262
5841
  dynKind(d) {
5263
5842
  return dynKind(this, d);
@@ -5334,8 +5913,8 @@ export class LlEmitter {
5334
5913
  tagInSet(uName, unionId, tags) {
5335
5914
  return tagInSet(this, uName, unionId, tags);
5336
5915
  }
5337
- arrPush(arr, acc, value) {
5338
- return arrPush(this, arr, acc, value);
5916
+ arrPush(arr, acc, value, element) {
5917
+ return arrPush(this, arr, acc, value, element);
5339
5918
  }
5340
5919
  emitArrayCopyLoop(dst, src, acc) {
5341
5920
  return emitArrayCopyLoop(this, dst, src, acc);
@@ -5534,4 +6113,64 @@ export function adoptingAwaitOf(value) {
5534
6113
  });
5535
6114
  return found;
5536
6115
  }
6116
+ /** Adds `key` to `into` when it lacks it. */
6117
+ function addEntry(into, key, value) {
6118
+ if (!into.has(key))
6119
+ into.set(key, value);
6120
+ }
6121
+ /** Adds `key` to a numbered table when it lacks it, numbering it after the
6122
+ * table's own entries (`prefix` and its index), and records the rename of
6123
+ * the chunk's `name` for it. */
6124
+ function addNumbered(into, key, name, prefix, names) {
6125
+ let own = into.get(key);
6126
+ if (own === undefined) {
6127
+ own = `${prefix}${into.size}`;
6128
+ into.set(key, own);
6129
+ }
6130
+ if (own !== name)
6131
+ names.set(name.replace(/^@/, ""), own.replace(/^@/, ""));
6132
+ }
6133
+ /** addNumbered for entries that keep their numbered name in `sym`. */
6134
+ function addNumberedSymbol(into, key, entry, prefix, names) {
6135
+ let own = into.get(key);
6136
+ if (own === undefined) {
6137
+ own = { ...entry, sym: `${prefix}${into.size}` };
6138
+ into.set(key, own);
6139
+ }
6140
+ if (own.sym !== entry.sym)
6141
+ names.set(entry.sym, own.sym);
6142
+ }
6143
+ registerReplay("jsIcSite", (emitter) => emitter.jsIcSite());
6144
+ registerReplay("dynReadIcSite", (emitter) => emitter.dynReadIcSite());
6145
+ registerReplay("speculativeLoopSite", (emitter) => emitter.speculativeLoopSite());
6146
+ for (const op of [
6147
+ "dyn.collectionDynOps",
6148
+ "dyn.dynMatchHelper",
6149
+ "dyn.jsonSchema",
6150
+ "dyn.recordNameTable",
6151
+ "dyn.jsonParseHelper",
6152
+ "dyn.dynCheckHelper",
6153
+ "dyn.toDynHelper",
6154
+ "dyn.promiseDynAdapterHelper",
6155
+ "dyn.dynFuncThunkHelper",
6156
+ "dyn.dynFuncBoxHelper",
6157
+ "dyn.dynFuncAdapterHelper",
6158
+ "dyn.dynToStrHelper",
6159
+ "dyn.dynIterNHelper",
6160
+ "dyn.dynDestrCheckHelper",
6161
+ "dyn.dynKeyGetHelper",
6162
+ "dyn.dynComputedKeyGetHelper",
6163
+ "dyn.caughtToDynHelper",
6164
+ "dyn.messageListenerHelper",
6165
+ "dyn.messageReaderHelper",
6166
+ ])
6167
+ registerReplay(op, (emitter, args) => emitter.dyn.replayHelper(op, args));
6168
+ for (const op of [
6169
+ "walkers.jsonWriteHelper",
6170
+ "walkers.recordFieldWriter",
6171
+ "walkers.unionJoinHelper",
6172
+ ])
6173
+ registerReplay(op, (emitter, args) => emitter.walkers.replayHelper(op, args));
6174
+ for (const op of ["publish.walker", "publish.refusal"])
6175
+ registerReplay(op, (emitter, args) => emitter.publishWalkers.replayHelper(op, args));
5537
6176
  //# sourceMappingURL=emitter.js.map