@scriptc/compiler 0.4.7 → 0.4.8

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 (776) hide show
  1. package/ambient/node-fallback/child_process.d.ts +71 -22
  2. package/ambient/node-fallback/crypto.d.ts +15 -7
  3. package/ambient/node-fallback/events.d.ts +23 -5
  4. package/ambient/node-fallback/fs.d.ts +3 -2
  5. package/ambient/node-fallback/http.d.ts +23 -17
  6. package/ambient/node-fallback/https.d.ts +5 -2
  7. package/ambient/node-fallback/net.d.ts +6 -0
  8. package/ambient/node-fallback/os.d.ts +11 -1
  9. package/ambient/node-fallback/path-posix.d.ts +6 -0
  10. package/ambient/node-fallback/path-win32.d.ts +5 -0
  11. package/ambient/node-fallback/path.d.ts +2 -0
  12. package/ambient/node-fallback/zlib.d.ts +31 -2
  13. package/ambient/scriptc-node-fallback.d.ts +37 -7
  14. package/ambient/scriptc.d.ts +7 -2
  15. package/dist/backend/executable-features.js +11 -3
  16. package/dist/backend/executable-features.js.map +1 -1
  17. package/dist/backend/library-pack.d.ts +6 -0
  18. package/dist/backend/library-pack.js +17 -6
  19. package/dist/backend/library-pack.js.map +1 -1
  20. package/dist/backend/library-pack.test.d.ts +1 -0
  21. package/dist/backend/library-pack.test.js +28 -0
  22. package/dist/backend/library-pack.test.js.map +1 -0
  23. package/dist/backend/linker.d.ts +9 -2
  24. package/dist/backend/linker.js +190 -32
  25. package/dist/backend/linker.js.map +1 -1
  26. package/dist/backend/lld.d.ts +8 -4
  27. package/dist/backend/lld.js +19 -13
  28. package/dist/backend/lld.js.map +1 -1
  29. package/dist/backend/lld.test.js +3 -1
  30. package/dist/backend/lld.test.js.map +1 -1
  31. package/dist/backend/llvm/alloc.d.ts +15 -2
  32. package/dist/backend/llvm/alloc.js +172 -36
  33. package/dist/backend/llvm/alloc.js.map +1 -1
  34. package/dist/backend/llvm/alloc.test.js +69 -1
  35. package/dist/backend/llvm/alloc.test.js.map +1 -1
  36. package/dist/backend/llvm/arenas.d.ts +17 -4
  37. package/dist/backend/llvm/arenas.js +105 -10
  38. package/dist/backend/llvm/arenas.js.map +1 -1
  39. package/dist/backend/llvm/arenas.test.js +229 -0
  40. package/dist/backend/llvm/arenas.test.js.map +1 -1
  41. package/dist/backend/llvm/bytes-alias.js +10 -1
  42. package/dist/backend/llvm/bytes-alias.js.map +1 -1
  43. package/dist/backend/llvm/bytes-headers.js +6 -0
  44. package/dist/backend/llvm/bytes-headers.js.map +1 -1
  45. package/dist/backend/llvm/bytes-loop-versions.test.js +25 -0
  46. package/dist/backend/llvm/bytes-loop-versions.test.js.map +1 -1
  47. package/dist/backend/llvm/call-lifetimes.js +10 -0
  48. package/dist/backend/llvm/call-lifetimes.js.map +1 -1
  49. package/dist/backend/llvm/classes.d.ts +16 -9
  50. package/dist/backend/llvm/classes.js +142 -37
  51. package/dist/backend/llvm/classes.js.map +1 -1
  52. package/dist/backend/llvm/classes.test.js +42 -0
  53. package/dist/backend/llvm/classes.test.js.map +1 -1
  54. package/dist/backend/llvm/cpu-dispatch.d.ts +15 -5
  55. package/dist/backend/llvm/cpu-dispatch.js +31 -7
  56. package/dist/backend/llvm/cpu-dispatch.js.map +1 -1
  57. package/dist/backend/llvm/dyn.d.ts +12 -3
  58. package/dist/backend/llvm/dyn.js +31 -7
  59. package/dist/backend/llvm/dyn.js.map +1 -1
  60. package/dist/backend/llvm/emit-function.js +67 -4
  61. package/dist/backend/llvm/emit-function.js.map +1 -1
  62. package/dist/backend/llvm/emit-module.js +90 -39
  63. package/dist/backend/llvm/emit-module.js.map +1 -1
  64. package/dist/backend/llvm/emit-module.test.d.ts +1 -0
  65. package/dist/backend/llvm/emit-module.test.js +52 -0
  66. package/dist/backend/llvm/emit-module.test.js.map +1 -0
  67. package/dist/backend/llvm/emit-statements.js +99 -15
  68. package/dist/backend/llvm/emit-statements.js.map +1 -1
  69. package/dist/backend/llvm/emitter.d.ts +113 -8
  70. package/dist/backend/llvm/emitter.js +438 -67
  71. package/dist/backend/llvm/emitter.js.map +1 -1
  72. package/dist/backend/llvm/emitter.test.js +31 -3
  73. package/dist/backend/llvm/emitter.test.js.map +1 -1
  74. package/dist/backend/llvm/expr-async.js +19 -1
  75. package/dist/backend/llvm/expr-async.js.map +1 -1
  76. package/dist/backend/llvm/expr-bytes.js +16 -1
  77. package/dist/backend/llvm/expr-bytes.js.map +1 -1
  78. package/dist/backend/llvm/expr-calls.js +18 -2
  79. package/dist/backend/llvm/expr-calls.js.map +1 -1
  80. package/dist/backend/llvm/expr-dynamic.js +31 -10
  81. package/dist/backend/llvm/expr-dynamic.js.map +1 -1
  82. package/dist/backend/llvm/expr-primitives.js +31 -3
  83. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  84. package/dist/backend/llvm/expr-records.d.ts +1 -1
  85. package/dist/backend/llvm/expr-records.js +124 -56
  86. package/dist/backend/llvm/expr-records.js.map +1 -1
  87. package/dist/backend/llvm/expr-stream-bridges.js +17 -0
  88. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  89. package/dist/backend/llvm/js-groups.d.ts +21 -0
  90. package/dist/backend/llvm/js-groups.js +277 -0
  91. package/dist/backend/llvm/js-groups.js.map +1 -0
  92. package/dist/backend/llvm/js-ic.d.ts +19 -1
  93. package/dist/backend/llvm/js-ic.js +96 -23
  94. package/dist/backend/llvm/js-ic.js.map +1 -1
  95. package/dist/backend/llvm/lib-dispatch.js +132 -1
  96. package/dist/backend/llvm/lib-dispatch.js.map +1 -1
  97. package/dist/backend/llvm/lib-network.js +33 -6
  98. package/dist/backend/llvm/lib-network.js.map +1 -1
  99. package/dist/backend/llvm/lib-process.js +44 -3
  100. package/dist/backend/llvm/lib-process.js.map +1 -1
  101. package/dist/backend/llvm/lib-shared.js +69 -2
  102. package/dist/backend/llvm/lib-shared.js.map +1 -1
  103. package/dist/backend/llvm/local-union-storage.test.js +32 -0
  104. package/dist/backend/llvm/local-union-storage.test.js.map +1 -1
  105. package/dist/backend/llvm/loop-state.js +7 -2
  106. package/dist/backend/llvm/loop-state.js.map +1 -1
  107. package/dist/backend/llvm/map-entry-fusion.d.ts +8 -0
  108. package/dist/backend/llvm/map-entry-fusion.js +3 -3
  109. package/dist/backend/llvm/map-entry-fusion.js.map +1 -1
  110. package/dist/backend/llvm/map-number-lookup.test.js +6 -6
  111. package/dist/backend/llvm/map-number-lookup.test.js.map +1 -1
  112. package/dist/backend/llvm/nullable-unions.js +7 -6
  113. package/dist/backend/llvm/nullable-unions.js.map +1 -1
  114. package/dist/backend/llvm/nullable-unions.test.js +4 -1
  115. package/dist/backend/llvm/nullable-unions.test.js.map +1 -1
  116. package/dist/backend/llvm/receivers.js +3 -0
  117. package/dist/backend/llvm/receivers.js.map +1 -1
  118. package/dist/backend/llvm/record-entry-fusion.d.ts +32 -0
  119. package/dist/backend/llvm/record-entry-fusion.js +217 -0
  120. package/dist/backend/llvm/record-entry-fusion.js.map +1 -0
  121. package/dist/backend/llvm/record-results.d.ts +5 -2
  122. package/dist/backend/llvm/record-results.js +13 -12
  123. package/dist/backend/llvm/record-results.js.map +1 -1
  124. package/dist/backend/llvm/record-views.js +12 -6
  125. package/dist/backend/llvm/record-views.js.map +1 -1
  126. package/dist/backend/llvm/reference-effects.js +1 -0
  127. package/dist/backend/llvm/reference-effects.js.map +1 -1
  128. package/dist/backend/llvm/reference-writes.js +3 -0
  129. package/dist/backend/llvm/reference-writes.js.map +1 -1
  130. package/dist/backend/llvm/region-ir.js +1 -0
  131. package/dist/backend/llvm/region-ir.js.map +1 -1
  132. package/dist/backend/llvm/region-sites.d.ts +18 -0
  133. package/dist/backend/llvm/region-sites.js +79 -1
  134. package/dist/backend/llvm/region-sites.js.map +1 -1
  135. package/dist/backend/llvm/runtime-registries.test.js +53 -6
  136. package/dist/backend/llvm/runtime-registries.test.js.map +1 -1
  137. package/dist/backend/llvm/serialized-ir-emission.test.js +3 -1
  138. package/dist/backend/llvm/serialized-ir-emission.test.js.map +1 -1
  139. package/dist/backend/llvm/shapes.d.ts +33 -3
  140. package/dist/backend/llvm/shapes.js +183 -13
  141. package/dist/backend/llvm/shapes.js.map +1 -1
  142. package/dist/backend/llvm/stack-objects.d.ts +1 -2
  143. package/dist/backend/llvm/stack-objects.js +8 -5
  144. package/dist/backend/llvm/stack-objects.js.map +1 -1
  145. package/dist/backend/llvm/walkers.d.ts +12 -0
  146. package/dist/backend/llvm/walkers.js +46 -2
  147. package/dist/backend/llvm/walkers.js.map +1 -1
  148. package/dist/backend/may-throw.js +12 -2
  149. package/dist/backend/may-throw.js.map +1 -1
  150. package/dist/backend/may-throw.test.js +13 -0
  151. package/dist/backend/may-throw.test.js.map +1 -1
  152. package/dist/backend/native/contracts.d.ts +48 -8
  153. package/dist/backend/native/executable.js +55 -13
  154. package/dist/backend/native/executable.js.map +1 -1
  155. package/dist/backend/native/helper-identity-record.d.ts +11 -0
  156. package/dist/backend/native/helper-identity-record.js +76 -0
  157. package/dist/backend/native/helper-identity-record.js.map +1 -0
  158. package/dist/backend/native/helper-identity-record.test.d.ts +1 -0
  159. package/dist/backend/native/helper-identity-record.test.js +101 -0
  160. package/dist/backend/native/helper-identity-record.test.js.map +1 -0
  161. package/dist/backend/native/library.js +9 -1
  162. package/dist/backend/native/library.js.map +1 -1
  163. package/dist/backend/native/runtime-inputs.js +4 -1
  164. package/dist/backend/native/runtime-inputs.js.map +1 -1
  165. package/dist/backend/native/vendor.d.ts +1 -1
  166. package/dist/backend/native/vendor.js +1 -1
  167. package/dist/backend/native/vendor.js.map +1 -1
  168. package/dist/backend/native-codegen-core.d.ts +13 -10
  169. package/dist/backend/native-codegen-core.js +26 -13
  170. package/dist/backend/native-codegen-core.js.map +1 -1
  171. package/dist/backend/native-codegen.js +27 -8
  172. package/dist/backend/native-codegen.js.map +1 -1
  173. package/dist/backend/native-codegen.test.js +110 -14
  174. package/dist/backend/native-codegen.test.js.map +1 -1
  175. package/dist/backend/native-link-info-core.d.ts +37 -8
  176. package/dist/backend/native-link-info-core.js.map +1 -1
  177. package/dist/backend/runtime-pack-core.d.ts +17 -2
  178. package/dist/backend/runtime-pack-core.js +18 -3
  179. package/dist/backend/runtime-pack-core.js.map +1 -1
  180. package/dist/backend/runtime-pack-targets.test.js +1 -1
  181. package/dist/backend/runtime-pack-targets.test.js.map +1 -1
  182. package/dist/backend/runtime-pack.test.js +211 -2
  183. package/dist/backend/runtime-pack.test.js.map +1 -1
  184. package/dist/backend/tree-classes.d.ts +42 -0
  185. package/dist/backend/tree-classes.js +723 -0
  186. package/dist/backend/tree-classes.js.map +1 -0
  187. package/dist/backend/tree-classes.test.d.ts +1 -0
  188. package/dist/backend/tree-classes.test.js +338 -0
  189. package/dist/backend/tree-classes.test.js.map +1 -0
  190. package/dist/backend/vendor-archives.d.ts +5 -1
  191. package/dist/backend/vendor-archives.js +51 -7
  192. package/dist/backend/vendor-archives.js.map +1 -1
  193. package/dist/backend/vendor-inputs.d.ts +25 -4
  194. package/dist/backend/vendor-inputs.js +68 -4
  195. package/dist/backend/vendor-inputs.js.map +1 -1
  196. package/dist/backend/vendor-inputs.test.js +35 -1
  197. package/dist/backend/vendor-inputs.test.js.map +1 -1
  198. package/dist/backend/warm-cache.js +1 -1
  199. package/dist/backend/warm-cache.js.map +1 -1
  200. package/dist/compat/fetch-profile.js +2 -2
  201. package/dist/coverage/report.js +47 -0
  202. package/dist/coverage/report.js.map +1 -1
  203. package/dist/coverage/surface-manifest.js +1 -1
  204. package/dist/diagnostics/codes.d.ts +8 -0
  205. package/dist/diagnostics/codes.js +8 -0
  206. package/dist/diagnostics/codes.js.map +1 -1
  207. package/dist/diagnostics/diagnostic.d.ts +27 -9
  208. package/dist/diagnostics/diagnostic.js +60 -19
  209. package/dist/diagnostics/diagnostic.js.map +1 -1
  210. package/dist/diagnostics/envelope.d.ts +18 -0
  211. package/dist/diagnostics/envelope.js.map +1 -1
  212. package/dist/executable/executable-cache.d.ts +21 -2
  213. package/dist/executable/executable-cache.js +21 -1
  214. package/dist/executable/executable-cache.js.map +1 -1
  215. package/dist/executable/executable-cache.test.js +123 -1
  216. package/dist/executable/executable-cache.test.js.map +1 -1
  217. package/dist/executable/prepare.js +199 -248
  218. package/dist/executable/prepare.js.map +1 -1
  219. package/dist/frontend/analysis.js +200 -18
  220. package/dist/frontend/analysis.js.map +1 -1
  221. package/dist/frontend/builtin-modules.d.ts +4 -0
  222. package/dist/frontend/builtin-modules.js +10 -0
  223. package/dist/frontend/builtin-modules.js.map +1 -1
  224. package/dist/frontend/early-errors.d.ts +12 -2
  225. package/dist/frontend/early-errors.js +535 -4
  226. package/dist/frontend/early-errors.js.map +1 -1
  227. package/dist/frontend/early-errors.test.js +165 -0
  228. package/dist/frontend/early-errors.test.js.map +1 -1
  229. package/dist/frontend/inferred-js-diagnostics.test.js +65 -0
  230. package/dist/frontend/inferred-js-diagnostics.test.js.map +1 -1
  231. package/dist/frontend/jsx-opinion-sites.test.d.ts +1 -0
  232. package/dist/frontend/jsx-opinion-sites.test.js +86 -0
  233. package/dist/frontend/jsx-opinion-sites.test.js.map +1 -0
  234. package/dist/frontend/lib-exports.d.ts +23 -4
  235. package/dist/frontend/lib-exports.js +98 -26
  236. package/dist/frontend/lib-exports.js.map +1 -1
  237. package/dist/frontend/lowering/binding-analysis.js +21 -3
  238. package/dist/frontend/lowering/binding-analysis.js.map +1 -1
  239. package/dist/frontend/lowering/buffers.d.ts +8 -0
  240. package/dist/frontend/lowering/buffers.js +43 -0
  241. package/dist/frontend/lowering/buffers.js.map +1 -0
  242. package/dist/frontend/lowering/builtin-calls.js +4 -0
  243. package/dist/frontend/lowering/builtin-calls.js.map +1 -1
  244. package/dist/frontend/lowering/builtin-namespaces.d.ts +3 -2
  245. package/dist/frontend/lowering/builtin-namespaces.js +24 -3
  246. package/dist/frontend/lowering/builtin-namespaces.js.map +1 -1
  247. package/dist/frontend/lowering/builtin-statics.d.ts +24 -0
  248. package/dist/frontend/lowering/builtin-statics.js +407 -0
  249. package/dist/frontend/lowering/builtin-statics.js.map +1 -0
  250. package/dist/frontend/lowering/builtins/arguments.d.ts +4 -0
  251. package/dist/frontend/lowering/builtins/arguments.js +12 -0
  252. package/dist/frontend/lowering/builtins/arguments.js.map +1 -1
  253. package/dist/frontend/lowering/builtins/atomics.d.ts +6 -1
  254. package/dist/frontend/lowering/builtins/atomics.js +87 -1
  255. package/dist/frontend/lowering/builtins/atomics.js.map +1 -1
  256. package/dist/frontend/lowering/builtins/child-process-methods.js +2 -2
  257. package/dist/frontend/lowering/builtins/child-process-methods.js.map +1 -1
  258. package/dist/frontend/lowering/builtins/child-process-sync.d.ts +13 -0
  259. package/dist/frontend/lowering/builtins/child-process-sync.js +1 -13
  260. package/dist/frontend/lowering/builtins/child-process-sync.js.map +1 -1
  261. package/dist/frontend/lowering/builtins/child-process.d.ts +10 -4
  262. package/dist/frontend/lowering/builtins/child-process.js +560 -27
  263. package/dist/frontend/lowering/builtins/child-process.js.map +1 -1
  264. package/dist/frontend/lowering/builtins/compression.d.ts +2 -2
  265. package/dist/frontend/lowering/builtins/compression.js +41 -21
  266. package/dist/frontend/lowering/builtins/compression.js.map +1 -1
  267. package/dist/frontend/lowering/builtins/constants.js +7 -2
  268. package/dist/frontend/lowering/builtins/constants.js.map +1 -1
  269. package/dist/frontend/lowering/builtins/filesystem-calls.d.ts +1 -0
  270. package/dist/frontend/lowering/builtins/filesystem-calls.js +28 -2
  271. package/dist/frontend/lowering/builtins/filesystem-calls.js.map +1 -1
  272. package/dist/frontend/lowering/builtins/json.js +4 -0
  273. package/dist/frontend/lowering/builtins/json.js.map +1 -1
  274. package/dist/frontend/lowering/builtins/module-calls.js +3 -1
  275. package/dist/frontend/lowering/builtins/module-calls.js.map +1 -1
  276. package/dist/frontend/lowering/builtins/numbers.d.ts +4 -1
  277. package/dist/frontend/lowering/builtins/numbers.js +10 -2
  278. package/dist/frontend/lowering/builtins/numbers.js.map +1 -1
  279. package/dist/frontend/lowering/builtins/operating-system.d.ts +6 -3
  280. package/dist/frontend/lowering/builtins/operating-system.js +96 -16
  281. package/dist/frontend/lowering/builtins/operating-system.js.map +1 -1
  282. package/dist/frontend/lowering/builtins/process.d.ts +2 -2
  283. package/dist/frontend/lowering/builtins/process.js +103 -8
  284. package/dist/frontend/lowering/builtins/process.js.map +1 -1
  285. package/dist/frontend/lowering/builtins/promises.js +169 -8
  286. package/dist/frontend/lowering/builtins/promises.js.map +1 -1
  287. package/dist/frontend/lowering/builtins/properties.js +6 -2
  288. package/dist/frontend/lowering/builtins/properties.js.map +1 -1
  289. package/dist/frontend/lowering/builtins/readline.d.ts +6 -4
  290. package/dist/frontend/lowering/builtins/readline.js +180 -36
  291. package/dist/frontend/lowering/builtins/readline.js.map +1 -1
  292. package/dist/frontend/lowering/builtins/url.js +35 -12
  293. package/dist/frontend/lowering/builtins/url.js.map +1 -1
  294. package/dist/frontend/lowering/builtins/webassembly.js +2 -0
  295. package/dist/frontend/lowering/builtins/webassembly.js.map +1 -1
  296. package/dist/frontend/lowering/call-arguments.d.ts +10 -0
  297. package/dist/frontend/lowering/call-arguments.js +37 -2
  298. package/dist/frontend/lowering/call-arguments.js.map +1 -1
  299. package/dist/frontend/lowering/call-signatures.d.ts +10 -0
  300. package/dist/frontend/lowering/call-signatures.js +103 -0
  301. package/dist/frontend/lowering/call-signatures.js.map +1 -1
  302. package/dist/frontend/lowering/class-construction.d.ts +14 -2
  303. package/dist/frontend/lowering/class-construction.js +99 -5
  304. package/dist/frontend/lowering/class-construction.js.map +1 -1
  305. package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +9 -0
  306. package/dist/frontend/lowering/class-dynamic-dispatch.js +1283 -1030
  307. package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
  308. package/dist/frontend/lowering/class-dynamic-dispatch.test.js +158 -0
  309. package/dist/frontend/lowering/class-dynamic-dispatch.test.js.map +1 -1
  310. package/dist/frontend/lowering/class-prototypes.js +20 -15
  311. package/dist/frontend/lowering/class-prototypes.js.map +1 -1
  312. package/dist/frontend/lowering/class-runtime-statics.d.ts +8 -0
  313. package/dist/frontend/lowering/class-runtime-statics.js +20 -1
  314. package/dist/frontend/lowering/class-runtime-statics.js.map +1 -1
  315. package/dist/frontend/lowering/class-unions.js +21 -4
  316. package/dist/frontend/lowering/class-unions.js.map +1 -1
  317. package/dist/frontend/lowering/coercions/function-adapters.js +9 -0
  318. package/dist/frontend/lowering/coercions/function-adapters.js.map +1 -1
  319. package/dist/frontend/lowering/coercions/state.d.ts +8 -0
  320. package/dist/frontend/lowering/coercions/state.js +17 -0
  321. package/dist/frontend/lowering/coercions/state.js.map +1 -1
  322. package/dist/frontend/lowering/coercions/structural-plans.js +20 -5
  323. package/dist/frontend/lowering/coercions/structural-plans.js.map +1 -1
  324. package/dist/frontend/lowering/coercions/structural.js +10 -1
  325. package/dist/frontend/lowering/coercions/structural.js.map +1 -1
  326. package/dist/frontend/lowering/coercions/unions.d.ts +2 -1
  327. package/dist/frontend/lowering/coercions/unions.js +54 -10
  328. package/dist/frontend/lowering/coercions/unions.js.map +1 -1
  329. package/dist/frontend/lowering/constructor-returns.d.ts +23 -2
  330. package/dist/frontend/lowering/constructor-returns.js +284 -58
  331. package/dist/frontend/lowering/constructor-returns.js.map +1 -1
  332. package/dist/frontend/lowering/containers/array-callbacks.js +156 -62
  333. package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
  334. package/dist/frontend/lowering/containers/array-construction.js +21 -3
  335. package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
  336. package/dist/frontend/lowering/containers/array-from-async.js +139 -3
  337. package/dist/frontend/lowering/containers/array-from-async.js.map +1 -1
  338. package/dist/frontend/lowering/containers/array-iteration.d.ts +14 -4
  339. package/dist/frontend/lowering/containers/array-iteration.js +24 -7
  340. package/dist/frontend/lowering/containers/array-iteration.js.map +1 -1
  341. package/dist/frontend/lowering/containers/array-methods.js +14 -11
  342. package/dist/frontend/lowering/containers/array-methods.js.map +1 -1
  343. package/dist/frontend/lowering/containers/bytes.d.ts +6 -0
  344. package/dist/frontend/lowering/containers/bytes.js +446 -86
  345. package/dist/frontend/lowering/containers/bytes.js.map +1 -1
  346. package/dist/frontend/lowering/containers/callback-arguments.d.ts +5 -0
  347. package/dist/frontend/lowering/containers/callback-arguments.js +21 -12
  348. package/dist/frontend/lowering/containers/callback-arguments.js.map +1 -1
  349. package/dist/frontend/lowering/containers/collection-grouping.js +421 -2
  350. package/dist/frontend/lowering/containers/collection-grouping.js.map +1 -1
  351. package/dist/frontend/lowering/containers/collection-methods.js +52 -17
  352. package/dist/frontend/lowering/containers/collection-methods.js.map +1 -1
  353. package/dist/frontend/lowering/containers/iterator-helpers.d.ts +23 -0
  354. package/dist/frontend/lowering/containers/iterator-helpers.js +176 -10
  355. package/dist/frontend/lowering/containers/iterator-helpers.js.map +1 -1
  356. package/dist/frontend/lowering/containers/string-and-regexp.d.ts +5 -2
  357. package/dist/frontend/lowering/containers/string-and-regexp.js +45 -11
  358. package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
  359. package/dist/frontend/lowering/crypto-tables.d.ts +3 -3
  360. package/dist/frontend/lowering/crypto-tables.js +5 -5
  361. package/dist/frontend/lowering/dispatch-sites.js +3 -0
  362. package/dist/frontend/lowering/dispatch-sites.js.map +1 -1
  363. package/dist/frontend/lowering/divergences.d.ts +40 -0
  364. package/dist/frontend/lowering/divergences.js +239 -20
  365. package/dist/frontend/lowering/divergences.js.map +1 -1
  366. package/dist/frontend/lowering/effect-free.d.ts +12 -0
  367. package/dist/frontend/lowering/effect-free.js +44 -0
  368. package/dist/frontend/lowering/effect-free.js.map +1 -0
  369. package/dist/frontend/lowering/expressions/array-literals.d.ts +10 -0
  370. package/dist/frontend/lowering/expressions/array-literals.js +62 -0
  371. package/dist/frontend/lowering/expressions/array-literals.js.map +1 -1
  372. package/dist/frontend/lowering/expressions/binary.js +115 -5
  373. package/dist/frontend/lowering/expressions/binary.js.map +1 -1
  374. package/dist/frontend/lowering/expressions/element-access.js +151 -7
  375. package/dist/frontend/lowering/expressions/element-access.js.map +1 -1
  376. package/dist/frontend/lowering/expressions/hosted-narrowing.d.ts +15 -0
  377. package/dist/frontend/lowering/expressions/hosted-narrowing.js +54 -1
  378. package/dist/frontend/lowering/expressions/hosted-narrowing.js.map +1 -1
  379. package/dist/frontend/lowering/expressions/identifiers.js +31 -2
  380. package/dist/frontend/lowering/expressions/identifiers.js.map +1 -1
  381. package/dist/frontend/lowering/expressions/narrowing.d.ts +3 -0
  382. package/dist/frontend/lowering/expressions/narrowing.js +175 -22
  383. package/dist/frontend/lowering/expressions/narrowing.js.map +1 -1
  384. package/dist/frontend/lowering/expressions/object-literals.js +173 -11
  385. package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
  386. package/dist/frontend/lowering/expressions/optional-chains.js +5 -1
  387. package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
  388. package/dist/frontend/lowering/expressions/property-access.d.ts +8 -0
  389. package/dist/frontend/lowering/expressions/property-access.js +379 -109
  390. package/dist/frontend/lowering/expressions/property-access.js.map +1 -1
  391. package/dist/frontend/lowering/expressions/relational.js +237 -7
  392. package/dist/frontend/lowering/expressions/relational.js.map +1 -1
  393. package/dist/frontend/lowering/expressions/typeof.js +8 -0
  394. package/dist/frontend/lowering/expressions/typeof.js.map +1 -1
  395. package/dist/frontend/lowering/expressions/union-fields.d.ts +20 -1
  396. package/dist/frontend/lowering/expressions/union-fields.js +103 -13
  397. package/dist/frontend/lowering/expressions/union-fields.js.map +1 -1
  398. package/dist/frontend/lowering/expressions/updates.js +74 -55
  399. package/dist/frontend/lowering/expressions/updates.js.map +1 -1
  400. package/dist/frontend/lowering/function-returns.js +37 -10
  401. package/dist/frontend/lowering/function-returns.js.map +1 -1
  402. package/dist/frontend/lowering/general-streams.js +5 -0
  403. package/dist/frontend/lowering/general-streams.js.map +1 -1
  404. package/dist/frontend/lowering/generator-delegation.d.ts +15 -7
  405. package/dist/frontend/lowering/generator-delegation.js +301 -118
  406. package/dist/frontend/lowering/generator-delegation.js.map +1 -1
  407. package/dist/frontend/lowering/generic-functions.d.ts +27 -1
  408. package/dist/frontend/lowering/generic-functions.js +432 -18
  409. package/dist/frontend/lowering/generic-functions.js.map +1 -1
  410. package/dist/frontend/lowering/global-function-values.d.ts +25 -0
  411. package/dist/frontend/lowering/global-function-values.js +193 -0
  412. package/dist/frontend/lowering/global-function-values.js.map +1 -0
  413. package/dist/frontend/lowering/global-values.d.ts +6 -4
  414. package/dist/frontend/lowering/global-values.js +24 -10
  415. package/dist/frontend/lowering/global-values.js.map +1 -1
  416. package/dist/frontend/lowering/host-global-values.d.ts +31 -0
  417. package/dist/frontend/lowering/host-global-values.js +121 -0
  418. package/dist/frontend/lowering/host-global-values.js.map +1 -0
  419. package/dist/frontend/lowering/host-globals.d.ts +74 -0
  420. package/dist/frontend/lowering/host-globals.js +344 -0
  421. package/dist/frontend/lowering/host-globals.js.map +1 -0
  422. package/dist/frontend/lowering/http2-constants.js +1 -1
  423. package/dist/frontend/lowering/iterator-adapters.js +46 -17
  424. package/dist/frontend/lowering/iterator-adapters.js.map +1 -1
  425. package/dist/frontend/lowering/iterator-prototype.d.ts +30 -0
  426. package/dist/frontend/lowering/iterator-prototype.js +160 -0
  427. package/dist/frontend/lowering/iterator-prototype.js.map +1 -0
  428. package/dist/frontend/lowering/key-order-witness.js +43 -22
  429. package/dist/frontend/lowering/key-order-witness.js.map +1 -1
  430. package/dist/frontend/lowering/key-order-witness.test.js +1 -0
  431. package/dist/frontend/lowering/key-order-witness.test.js.map +1 -1
  432. package/dist/frontend/lowering/lib-boundary.js +11 -3
  433. package/dist/frontend/lowering/lib-boundary.js.map +1 -1
  434. package/dist/frontend/lowering/lower-assert.js +30 -15
  435. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  436. package/dist/frontend/lowering/lower-async-iteration.d.ts +11 -0
  437. package/dist/frontend/lowering/lower-async-iteration.js +15 -0
  438. package/dist/frontend/lowering/lower-async-iteration.js.map +1 -1
  439. package/dist/frontend/lowering/lower-builtin-values.js +11 -1
  440. package/dist/frontend/lowering/lower-builtin-values.js.map +1 -1
  441. package/dist/frontend/lowering/lower-calls.d.ts +25 -0
  442. package/dist/frontend/lowering/lower-calls.js +929 -227
  443. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  444. package/dist/frontend/lowering/lower-calls.test.js +59 -16
  445. package/dist/frontend/lowering/lower-calls.test.js.map +1 -1
  446. package/dist/frontend/lowering/lower-classes.d.ts +20 -0
  447. package/dist/frontend/lowering/lower-classes.js +468 -44
  448. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  449. package/dist/frontend/lowering/lower-event-emitter.d.ts +6 -2
  450. package/dist/frontend/lowering/lower-event-emitter.js +253 -83
  451. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
  452. package/dist/frontend/lowering/lower-exprs.d.ts +1 -1
  453. package/dist/frontend/lowering/lower-exprs.js +71 -20
  454. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  455. package/dist/frontend/lowering/lower-functions.js +25 -6
  456. package/dist/frontend/lowering/lower-functions.js.map +1 -1
  457. package/dist/frontend/lowering/lower-generators.js +57 -10
  458. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  459. package/dist/frontend/lowering/lower-global-value.d.ts +6 -0
  460. package/dist/frontend/lowering/lower-global-value.js +14 -5
  461. package/dist/frontend/lowering/lower-global-value.js.map +1 -1
  462. package/dist/frontend/lowering/lower-inspect.d.ts +4 -0
  463. package/dist/frontend/lowering/lower-inspect.js +638 -64
  464. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  465. package/dist/frontend/lowering/lower-modules.js +48 -2
  466. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  467. package/dist/frontend/lowering/lower-namespaces.js +18 -0
  468. package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
  469. package/dist/frontend/lowering/lower-node-island.js +16 -6
  470. package/dist/frontend/lowering/lower-node-island.js.map +1 -1
  471. package/dist/frontend/lowering/lower-server.js +303 -87
  472. package/dist/frontend/lowering/lower-server.js.map +1 -1
  473. package/dist/frontend/lowering/lower-stdlib.js +45 -0
  474. package/dist/frontend/lowering/lower-stdlib.js.map +1 -1
  475. package/dist/frontend/lowering/lower-stmts.d.ts +14 -11
  476. package/dist/frontend/lowering/lower-stmts.js +270 -52
  477. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  478. package/dist/frontend/lowering/lower-timers.js +110 -27
  479. package/dist/frontend/lowering/lower-timers.js.map +1 -1
  480. package/dist/frontend/lowering/lower-url.js +6 -3
  481. package/dist/frontend/lowering/lower-url.js.map +1 -1
  482. package/dist/frontend/lowering/lowerer.d.ts +227 -21
  483. package/dist/frontend/lowering/lowerer.js +651 -92
  484. package/dist/frontend/lowering/lowerer.js.map +1 -1
  485. package/dist/frontend/lowering/lowerer.test.js +18 -0
  486. package/dist/frontend/lowering/lowerer.test.js.map +1 -1
  487. package/dist/frontend/lowering/lowering-facts.d.ts +110 -0
  488. package/dist/frontend/lowering/lowering-facts.js +323 -0
  489. package/dist/frontend/lowering/lowering-facts.js.map +1 -0
  490. package/dist/frontend/lowering/lowering-facts.test.d.ts +1 -0
  491. package/dist/frontend/lowering/lowering-facts.test.js +100 -0
  492. package/dist/frontend/lowering/lowering-facts.test.js.map +1 -0
  493. package/dist/frontend/lowering/nan-coded-reads.d.ts +27 -4
  494. package/dist/frontend/lowering/nan-coded-reads.js +112 -9
  495. package/dist/frontend/lowering/nan-coded-reads.js.map +1 -1
  496. package/dist/frontend/lowering/optional-arguments.d.ts +4 -0
  497. package/dist/frontend/lowering/optional-arguments.js +26 -2
  498. package/dist/frontend/lowering/optional-arguments.js.map +1 -1
  499. package/dist/frontend/lowering/partial-assertions.d.ts +0 -3
  500. package/dist/frontend/lowering/partial-assertions.js +9 -15
  501. package/dist/frontend/lowering/partial-assertions.js.map +1 -1
  502. package/dist/frontend/lowering/primitive-throws.d.ts +100 -0
  503. package/dist/frontend/lowering/primitive-throws.js +241 -0
  504. package/dist/frontend/lowering/primitive-throws.js.map +1 -0
  505. package/dist/frontend/lowering/primitive-wrappers.js +1 -0
  506. package/dist/frontend/lowering/primitive-wrappers.js.map +1 -1
  507. package/dist/frontend/lowering/record-inherited.d.ts +17 -1
  508. package/dist/frontend/lowering/record-inherited.js +16 -2
  509. package/dist/frontend/lowering/record-inherited.js.map +1 -1
  510. package/dist/frontend/lowering/record-links.d.ts +73 -0
  511. package/dist/frontend/lowering/record-links.js +797 -0
  512. package/dist/frontend/lowering/record-links.js.map +1 -0
  513. package/dist/frontend/lowering/runtime-optional-provenance.d.ts +27 -7
  514. package/dist/frontend/lowering/runtime-optional-provenance.js +25 -11
  515. package/dist/frontend/lowering/runtime-optional-provenance.js.map +1 -1
  516. package/dist/frontend/lowering/runtime-optional-report.d.ts +40 -0
  517. package/dist/frontend/lowering/runtime-optional-report.js +300 -0
  518. package/dist/frontend/lowering/runtime-optional-report.js.map +1 -0
  519. package/dist/frontend/lowering/scoped-type-memo.test.d.ts +1 -0
  520. package/dist/frontend/lowering/scoped-type-memo.test.js +86 -0
  521. package/dist/frontend/lowering/scoped-type-memo.test.js.map +1 -0
  522. package/dist/frontend/lowering/static-typeof.d.ts +3 -1
  523. package/dist/frontend/lowering/static-typeof.js +6 -1
  524. package/dist/frontend/lowering/static-typeof.js.map +1 -1
  525. package/dist/frontend/lowering/strict-mode.d.ts +1 -5
  526. package/dist/frontend/lowering/strict-mode.js +4 -30
  527. package/dist/frontend/lowering/strict-mode.js.map +1 -1
  528. package/dist/frontend/lowering/structural-instances.d.ts +7 -0
  529. package/dist/frontend/lowering/structural-instances.js +23 -0
  530. package/dist/frontend/lowering/structural-instances.js.map +1 -1
  531. package/dist/frontend/lowering/surfaces.d.ts +15 -1
  532. package/dist/frontend/lowering/surfaces.js +78 -10
  533. package/dist/frontend/lowering/surfaces.js.map +1 -1
  534. package/dist/frontend/lowering/union-retag.d.ts +13 -1
  535. package/dist/frontend/lowering/union-retag.js +55 -1
  536. package/dist/frontend/lowering/union-retag.js.map +1 -1
  537. package/dist/frontend/lowering/union-retag.test.js +51 -0
  538. package/dist/frontend/lowering/union-retag.test.js.map +1 -1
  539. package/dist/frontend/lowering/unit-journal.d.ts +8 -0
  540. package/dist/frontend/lowering/unit-journal.js +14 -0
  541. package/dist/frontend/lowering/unit-journal.js.map +1 -1
  542. package/dist/frontend/lowering/unit-journal.test.js +36 -1
  543. package/dist/frontend/lowering/unit-journal.test.js.map +1 -1
  544. package/dist/frontend/lowering/zlib-constants.js +3 -2
  545. package/dist/frontend/lowering/zlib-constants.js.map +1 -1
  546. package/dist/frontend/npm-static.js +78 -9
  547. package/dist/frontend/npm-static.js.map +1 -1
  548. package/dist/frontend/npm-static.test.js +95 -2
  549. package/dist/frontend/npm-static.test.js.map +1 -1
  550. package/dist/frontend/pipeline.d.ts +5 -4
  551. package/dist/frontend/pipeline.js +94 -31
  552. package/dist/frontend/pipeline.js.map +1 -1
  553. package/dist/frontend/pipeline.test.js +68 -11
  554. package/dist/frontend/pipeline.test.js.map +1 -1
  555. package/dist/frontend/program.d.ts +62 -2
  556. package/dist/frontend/program.js +695 -422
  557. package/dist/frontend/program.js.map +1 -1
  558. package/dist/frontend/program.test.js +37 -1
  559. package/dist/frontend/program.test.js.map +1 -1
  560. package/dist/frontend/services-node.d.ts +7 -0
  561. package/dist/frontend/services-node.js +32 -1
  562. package/dist/frontend/services-node.js.map +1 -1
  563. package/dist/frontend/services-node.test.js +51 -0
  564. package/dist/frontend/services-node.test.js.map +1 -1
  565. package/dist/frontend/shape-inference/overlay.js +68 -2
  566. package/dist/frontend/shape-inference/overlay.js.map +1 -1
  567. package/dist/frontend/tier-analysis.d.ts +9 -0
  568. package/dist/frontend/tier-analysis.js +1 -0
  569. package/dist/frontend/tier-analysis.js.map +1 -1
  570. package/dist/frontend/tsc-codes.d.ts +57 -3
  571. package/dist/frontend/tsc-codes.js +935 -150
  572. package/dist/frontend/tsc-codes.js.map +1 -1
  573. package/dist/frontend/tsc-codes.test.js +221 -12
  574. package/dist/frontend/tsc-codes.test.js.map +1 -1
  575. package/dist/frontend/type-mapper.d.ts +91 -9
  576. package/dist/frontend/type-mapper.js +622 -181
  577. package/dist/frontend/type-mapper.js.map +1 -1
  578. package/dist/index.d.ts +1 -1
  579. package/dist/index.js +80 -15
  580. package/dist/index.js.map +1 -1
  581. package/dist/index.test.d.ts +1 -0
  582. package/dist/index.test.js +60 -0
  583. package/dist/index.test.js.map +1 -0
  584. package/dist/ir/builtin-effects.js +43 -0
  585. package/dist/ir/builtin-effects.js.map +1 -1
  586. package/dist/ir/builtin-signatures.d.ts +1 -1
  587. package/dist/ir/builtin-signatures.js +242 -16
  588. package/dist/ir/builtin-signatures.js.map +1 -1
  589. package/dist/ir/callback-specialization.d.ts +3 -2
  590. package/dist/ir/callback-specialization.js +35 -25
  591. package/dist/ir/callback-specialization.js.map +1 -1
  592. package/dist/ir/capture-values.d.ts +8 -4
  593. package/dist/ir/capture-values.js +9 -6
  594. package/dist/ir/capture-values.js.map +1 -1
  595. package/dist/ir/char-unit-locals.d.ts +6 -2
  596. package/dist/ir/char-unit-locals.js +11 -2
  597. package/dist/ir/char-unit-locals.js.map +1 -1
  598. package/dist/ir/class-key-index.d.ts +18 -0
  599. package/dist/ir/class-key-index.js +29 -0
  600. package/dist/ir/class-key-index.js.map +1 -0
  601. package/dist/ir/class-key-index.test.d.ts +1 -0
  602. package/dist/ir/class-key-index.test.js +25 -0
  603. package/dist/ir/class-key-index.test.js.map +1 -0
  604. package/dist/ir/codec.generated.d.ts +1 -1
  605. package/dist/ir/codec.generated.js +724 -648
  606. package/dist/ir/codec.generated.js.map +1 -1
  607. package/dist/ir/constant-globals.d.ts +5 -2
  608. package/dist/ir/constant-globals.js +25 -27
  609. package/dist/ir/constant-globals.js.map +1 -1
  610. package/dist/ir/expression-inlining.d.ts +4 -2
  611. package/dist/ir/expression-inlining.js +8 -2
  612. package/dist/ir/expression-inlining.js.map +1 -1
  613. package/dist/ir/field-values.d.ts +5 -2
  614. package/dist/ir/field-values.js +32 -21
  615. package/dist/ir/field-values.js.map +1 -1
  616. package/dist/ir/fields.generated.d.ts +11 -2
  617. package/dist/ir/fields.generated.js +8 -0
  618. package/dist/ir/fields.generated.js.map +1 -1
  619. package/dist/ir/final-fields.js +1 -1
  620. package/dist/ir/final-fields.js.map +1 -1
  621. package/dist/ir/function-references.d.ts +5 -4
  622. package/dist/ir/function-references.js +7 -4
  623. package/dist/ir/function-references.js.map +1 -1
  624. package/dist/ir/function-references.test.js +7 -0
  625. package/dist/ir/function-references.test.js.map +1 -1
  626. package/dist/ir/init-only-globals.d.ts +4 -2
  627. package/dist/ir/init-only-globals.js +17 -18
  628. package/dist/ir/init-only-globals.js.map +1 -1
  629. package/dist/ir/inline-array-views.js +1 -0
  630. package/dist/ir/inline-array-views.js.map +1 -1
  631. package/dist/ir/int32-slots.js +7 -0
  632. package/dist/ir/int32-slots.js.map +1 -1
  633. package/dist/ir/ir.d.ts +59 -4
  634. package/dist/ir/ir.js +7 -0
  635. package/dist/ir/ir.js.map +1 -1
  636. package/dist/ir/js-groups.d.ts +51 -0
  637. package/dist/ir/js-groups.js +394 -0
  638. package/dist/ir/js-groups.js.map +1 -0
  639. package/dist/ir/js-groups.test.d.ts +1 -0
  640. package/dist/ir/js-groups.test.js +555 -0
  641. package/dist/ir/js-groups.test.js.map +1 -0
  642. package/dist/ir/js-ic.js +30 -5
  643. package/dist/ir/js-ic.js.map +1 -1
  644. package/dist/ir/js-ic.test.js +27 -1
  645. package/dist/ir/js-ic.test.js.map +1 -1
  646. package/dist/ir/node-index.d.ts +23 -6
  647. package/dist/ir/node-index.js +126 -49
  648. package/dist/ir/node-index.js.map +1 -1
  649. package/dist/ir/numeric-call-specialization.d.ts +4 -2
  650. package/dist/ir/numeric-call-specialization.js +40 -26
  651. package/dist/ir/numeric-call-specialization.js.map +1 -1
  652. package/dist/ir/paired-while-loops.d.ts +4 -2
  653. package/dist/ir/paired-while-loops.js +8 -2
  654. package/dist/ir/paired-while-loops.js.map +1 -1
  655. package/dist/ir/parameter-versions.d.ts +13 -4
  656. package/dist/ir/parameter-versions.js +63 -42
  657. package/dist/ir/parameter-versions.js.map +1 -1
  658. package/dist/ir/property-bags.d.ts +4 -2
  659. package/dist/ir/property-bags.js +22 -17
  660. package/dist/ir/property-bags.js.map +1 -1
  661. package/dist/ir/row-pairs.d.ts +4 -2
  662. package/dist/ir/row-pairs.js +12 -11
  663. package/dist/ir/row-pairs.js.map +1 -1
  664. package/dist/ir/runtime-features.d.ts +87 -12
  665. package/dist/ir/runtime-features.js +263 -160
  666. package/dist/ir/runtime-features.js.map +1 -1
  667. package/dist/ir/runtime-features.test.js +109 -139
  668. package/dist/ir/runtime-features.test.js.map +1 -1
  669. package/dist/ir/runtime-jam-loops.d.ts +35 -0
  670. package/dist/ir/runtime-jam-loops.js +604 -0
  671. package/dist/ir/runtime-jam-loops.js.map +1 -0
  672. package/dist/ir/runtime-jam-loops.test.d.ts +1 -0
  673. package/dist/ir/runtime-jam-loops.test.js +565 -0
  674. package/dist/ir/runtime-jam-loops.test.js.map +1 -0
  675. package/dist/ir/saturating-loop-jams.d.ts +4 -2
  676. package/dist/ir/saturating-loop-jams.js +11 -10
  677. package/dist/ir/saturating-loop-jams.js.map +1 -1
  678. package/dist/ir/scalar-records.d.ts +5 -2
  679. package/dist/ir/scalar-records.js +12 -2
  680. package/dist/ir/scalar-records.js.map +1 -1
  681. package/dist/ir/self-captures.d.ts +4 -2
  682. package/dist/ir/self-captures.js +32 -27
  683. package/dist/ir/self-captures.js.map +1 -1
  684. package/dist/ir/serialize.d.ts +6 -1
  685. package/dist/ir/serialize.js +87 -23
  686. package/dist/ir/serialize.js.map +1 -1
  687. package/dist/ir/serialize.test.js +26 -0
  688. package/dist/ir/serialize.test.js.map +1 -1
  689. package/dist/ir/tiers.js +1 -0
  690. package/dist/ir/tiers.js.map +1 -1
  691. package/dist/ir/traverse.js +4 -0
  692. package/dist/ir/traverse.js.map +1 -1
  693. package/dist/ir/typed-argument-clones.d.ts +30 -0
  694. package/dist/ir/typed-argument-clones.js +789 -0
  695. package/dist/ir/typed-argument-clones.js.map +1 -0
  696. package/dist/ir/union-arm-loops.d.ts +3 -0
  697. package/dist/ir/union-arm-loops.js +373 -0
  698. package/dist/ir/union-arm-loops.js.map +1 -0
  699. package/dist/ir/union-arm-loops.test.d.ts +1 -0
  700. package/dist/ir/union-arm-loops.test.js +230 -0
  701. package/dist/ir/union-arm-loops.test.js.map +1 -0
  702. package/dist/ir/validate.js +88 -18
  703. package/dist/ir/validate.js.map +1 -1
  704. package/dist/library/compiler-self-identity.d.ts +8 -2
  705. package/dist/library/compiler-self-identity.js +92 -18
  706. package/dist/library/compiler-self-identity.js.map +1 -1
  707. package/dist/library/compiler-self-identity.test.js +150 -3
  708. package/dist/library/compiler-self-identity.test.js.map +1 -1
  709. package/dist/library/int-infer.d.ts +5 -0
  710. package/dist/library/int-infer.js +15 -3
  711. package/dist/library/int-infer.js.map +1 -1
  712. package/dist/library/ir-policy.js +1 -0
  713. package/dist/library/ir-policy.js.map +1 -1
  714. package/dist/library/library-cache.d.ts +4 -0
  715. package/dist/library/library-cache.js +2 -0
  716. package/dist/library/library-cache.js.map +1 -1
  717. package/dist/library/library-cache.test.js +26 -0
  718. package/dist/library/library-cache.test.js.map +1 -1
  719. package/dist/library/prepare.js +99 -31
  720. package/dist/library/prepare.js.map +1 -1
  721. package/dist/native/cache.d.ts +7 -0
  722. package/dist/native/cache.js +47 -0
  723. package/dist/native/cache.js.map +1 -1
  724. package/dist/native/cache.test.js +13 -1
  725. package/dist/native/cache.test.js.map +1 -1
  726. package/dist/native/cli.js +1 -1
  727. package/dist/native/cli.js.map +1 -1
  728. package/dist/native/compiler.js +18 -3
  729. package/dist/native/compiler.js.map +1 -1
  730. package/dist/native/executable-cache-open.test.js +31 -5
  731. package/dist/native/executable-cache-open.test.js.map +1 -1
  732. package/dist/native/executable-cache.d.ts +6 -1
  733. package/dist/native/executable-cache.js +7 -1
  734. package/dist/native/executable-cache.js.map +1 -1
  735. package/dist/native/prepare.d.ts +3 -0
  736. package/dist/native/prepare.js +43 -26
  737. package/dist/native/prepare.js.map +1 -1
  738. package/dist/native/prepare.test.js +25 -3
  739. package/dist/native/prepare.test.js.map +1 -1
  740. package/dist/native/sanitizer.js +10 -1
  741. package/dist/native/sanitizer.js.map +1 -1
  742. package/dist/native/sanitizer.test.js +7 -2
  743. package/dist/native/sanitizer.test.js.map +1 -1
  744. package/dist/node-islands/boundary.d.ts +12 -0
  745. package/dist/node-islands/boundary.js +38 -6
  746. package/dist/node-islands/boundary.js.map +1 -1
  747. package/dist/node-islands/boundary.test.d.ts +1 -0
  748. package/dist/node-islands/boundary.test.js +76 -0
  749. package/dist/node-islands/boundary.test.js.map +1 -0
  750. package/dist/node-islands/detect.d.ts +9 -0
  751. package/dist/node-islands/detect.js +110 -0
  752. package/dist/node-islands/detect.js.map +1 -1
  753. package/dist/node-islands/detect.test.js +24 -0
  754. package/dist/node-islands/detect.test.js.map +1 -1
  755. package/dist/node-islands/graph-islands.d.ts +40 -0
  756. package/dist/node-islands/graph-islands.js +128 -0
  757. package/dist/node-islands/graph-islands.js.map +1 -0
  758. package/dist/node-islands/growth.d.ts +57 -0
  759. package/dist/node-islands/growth.js +205 -0
  760. package/dist/node-islands/growth.js.map +1 -0
  761. package/dist/node-islands/report.d.ts +12 -0
  762. package/dist/node-islands/report.js +28 -0
  763. package/dist/node-islands/report.js.map +1 -1
  764. package/dist/node-islands/report.test.js +2 -0
  765. package/dist/node-islands/report.test.js.map +1 -1
  766. package/dist/node-islands/rules.js +5 -0
  767. package/dist/node-islands/rules.js.map +1 -1
  768. package/dist/node-islands/scan.d.ts +11 -2
  769. package/dist/node-islands/scan.js +61 -9
  770. package/dist/node-islands/scan.js.map +1 -1
  771. package/dist/wasm/translate.js +11 -5
  772. package/dist/wasm/translate.js.map +1 -1
  773. package/dist/wasm/translate.test.js +35 -0
  774. package/dist/wasm/translate.test.js.map +1 -1
  775. package/package.json +20 -20
  776. package/surface-manifest.json +184 -117
@@ -6,19 +6,19 @@ import { unionNarrowFailureMessage } from "./union-narrow.js";
6
6
  import { arrayClassFieldsFn, arrayClassSpeciesFn, arrayOfClassInstance, arrayRootOf, lowerWithArraySpecies, } from "./builtins/array-classes.js";
7
7
  import { canonShadowHook, mapCanonical } from "../canon-map.js";
8
8
  import { Normalizer } from "../canon.js";
9
- import { compactDeclOrigins, inPackageFile, recordOrigin, slotOrigin, } from "./decl-origin.js";
10
- import { isDeclBoundaryFile } from "../decl-projection.js";
9
+ import { resolveEntryExportSymbol } from "../lib-exports.js";
10
+ import { compactDeclOrigins, recordOrigin, slotOrigin } from "./decl-origin.js";
11
11
  import { relieveHeapPressure } from "../../heap-pressure.js";
12
12
  import { checkedTable, countTable, fixedScalar, flagScalar, functionTable, irDataTable, journalDump, journalMode, HeldTables, lowerWaveRecorded, mapTable, setTable, waveStats, writeRecords, } from "./unit-journal.js";
13
13
  import { UnitReuse, unitReuseVerify, verifyStoredUnit } from "./unit-reuse.js";
14
14
  import { moduleNamespaceDynValue, moduleNamespaceObject, moduleNamespaceValue, } from "./module-namespace-elements.js";
15
15
  import { keyedHelperName, moduleTagNumber, portableRelativePath } from "./stable-names.js";
16
16
  import { positionTag, StructuralPositions } from "./structural-positions.js";
17
- import { activeNodeIslands, isForeignType, setActiveNodeIslands, } from "../../node-islands/boundary.js";
17
+ import { activeNodeIslands, setActiveNodeIslands, } from "../../node-islands/boundary.js";
18
18
  import { bindingSymbolOfRead, onlyForwarded, stripTypeWrappers } from "./typed-arguments.js";
19
19
  import { needsGeneralNodeStreams, noteUntypedStreamFlow, stdioIntoGeneralStream, } from "./general-streams.js";
20
20
  import { extendAssertedRecordMembers } from "./assertion-members.js";
21
- import { jsDynamicDeclarations } from "./js-dynamic-objects.js";
21
+ import { LoweringFacts } from "./lowering-facts.js";
22
22
  import { isJsSourceFileName } from "../tsc-codes.js";
23
23
  import { builtinClassKind, builtinClassValue, builtinMemberClassKind, } from "./builtins/builtin-class-dyn.js";
24
24
  import { lifetimeRegionType, lowerLifetimeRegionCall, lowerLifetimeRegionNew, } from "./lifetime-regions.js";
@@ -32,6 +32,7 @@ import { checkRequireBindingAccesses, } from "./require-initialization.js";
32
32
  import { identityPreservingWidening } from "./coercions/identity.js";
33
33
  import { scanDivergences } from "./divergences.js";
34
34
  import { applyKeyOrderWitnesses, KeyOrderNotes } from "./key-order-witness.js";
35
+ import { installBuiltinStatics } from "./builtin-statics.js";
35
36
  import { functionKeepsRecordSources } from "./record-sources.js";
36
37
  import { exprFunctionReference } from "../../ir/function-references.js";
37
38
  import { everyStmtList, observeRecordLiteralRebuilds } from "../../ir/traverse.js";
@@ -70,6 +71,7 @@ import { boxBuiltinValuesChecked, lowerUtilTypeValue, checkedNativeCallableValue
70
71
  import { devirtualizeVirtualCalls } from "./devirtualize.js";
71
72
  import { foldRegexSpanReads } from "./regex-span-reads.js";
72
73
  import { RuntimeOptionalProvenance } from "./runtime-optional-provenance.js";
74
+ import { runtimeOptionalNarrowings, } from "./runtime-optional-report.js";
73
75
  import { presentAtUse, reassignedBindings } from "./runtime-optional-guards.js";
74
76
  import { NarrowingStability, widenedReceiver } from "./narrowing-stability.js";
75
77
  import { ArrayElementStates } from "./runtime-optional-elements.js";
@@ -94,6 +96,7 @@ import { sloppyDynamicWrites } from "./frozen-records.js";
94
96
  import { guardFrozenWrites, markSloppyRecordWrites } from "./frozen-records.js";
95
97
  import { applyHandleProperties } from "./handle-properties.js";
96
98
  import { installBufferValue } from "./containers/bytes.js";
99
+ import { installMutableBuffersArm } from "./buffers.js";
97
100
  import { ClassProtocols } from "./class-protocols.js";
98
101
  import { earlyReadVarSymbols } from "./var-hoisting.js";
99
102
  import { recordTextCodecClass } from "../../ir/ir.js";
@@ -104,6 +107,7 @@ import { returnDispatchReceivers } from "./receiver-returns.js";
104
107
  import { analyzeTiers, dynamicStatementCount, } from "../tier-analysis.js";
105
108
  import { DeferredModuleInitializers } from "./deferred-module-initializers.js";
106
109
  import { finalizeClassMethodValues } from "./class-method-values.js";
110
+ import { finalizeRecordLinks } from "./record-links.js";
107
111
  import { finalizePrivateBrands } from "./private-brands.js";
108
112
  import { finalizeFunctionNames } from "./function-names.js";
109
113
  import { INSPECT_CUSTOM_MEMBER, tableKeyFieldType } from "./symbol-fields.js";
@@ -132,11 +136,11 @@ import { literalValues } from "../literal-values.js";
132
136
  import { discriminantOwners, literalUnionArm } from "../union-discriminants.js";
133
137
  import { declarationGroupKey, typeFailureOf } from "./type-failure.js";
134
138
  import { dynamicSlotDiag } from "../../diagnostics/dynamic-slots.js";
135
- import { unsupportedAnyOperationDiag, blockedBindingUseDiag, checkerPanicDiag, componentTypeDiag, isCheckerPanic, genericSignatureTypeDiag, indexSignatureTypeDiag, intersectionTypeDiag, noLoweringDiag, overloadedSignatureTypeDiag, recordShapeMismatchDiag, stdlibSnapshotValueUseDiag, unsupportedNativeApiDiag, unsupportedPackageValueDiag, unionMismatchDiag, UNSUPPORTED, unsupportedDiag, unsupportedTypeDiag, } from "../../diagnostics/diagnostic.js";
139
+ import { unsupportedAnyOperationDiag, blockedBindingUseDiag, checkerPanicDiag, componentTypeDiag, isCheckerPanic, genericSignatureTypeDiag, hostGlobalDiag, indexSignatureTypeDiag, intersectionTypeDiag, noLoweringDiag, overloadedSignatureTypeDiag, recordShapeMismatchDiag, stdlibSnapshotValueUseDiag, unsupportedNativeApiDiag, unsupportedPackageValueDiag, unionMismatchDiag, UNSUPPORTED, unsupportedDiag, unsupportedTypeDiag, } from "../../diagnostics/diagnostic.js";
136
140
  import { arrayOf, BOOL, canAdaptDynFuncTo, canBoxFuncIntoDyn, canDynCheckTo, canConvertToDyn, DYN, DYN_HANDLE_KINDS, F64, isDynTypedRefType, isJsonSafeType, isJsonStringifySafeType, isPrimitiveCollectionKey, isSupportedMapKey, isSupportedMapValue, isUndefinedArmedUnion, isUnitType, NULL_T, RUNTIME_ERROR_CLASSES, STRING, typeEquals, UNDEFINED_T, VOID, } from "../../ir/ir.js";
137
141
  import { provenanceActive } from "../provenance-registry.js";
138
- import { ambientDtsPath, canonicalBuiltinModule, cjsExportAssignmentOf, cjsExportDiscardReason, cjsExportsAssignedInFunctions, cjsReexportedModules, cjsNamespaceExportNames, isCheckedJsSourceFile, isCjsExportTableLiteral, isCjsJsFile, isJsSourceFile, isNodeEsmFile, isFallbackDtsPath, isNodeTypesPath, locOf, orderedImportsOf, overridesDtsPath, npmStaticDepSf7, requireSpecOf, isJsWriteTarget7, resolveImport, workspacePackageOfPath, } from "../program.js";
139
- import { containsRecord, containsUnion, describeComponentBlocker, describeRecordMemberBlocker, erasedOverloadMemberType, formatIrType, FETCH_AMBIENT_TYPES, isOsConstantsSymbol, isOverloadedCallableMemberType, isUnitOnlyTsType, isWorkerHandleType, isFetchHandleType, jsOpenObjectType, mapType, ShapeRegistry, typeKey, UnionRegistry, withUndefinedArm as withUndefinedArmCanonical, } from "../type-mapper.js";
142
+ import { canonicalBuiltinModule, cjsExportAssignmentOf, cjsExportDiscardReason, cjsExportsAssignedInFunctions, cjsReexportedModules, cjsNamespaceExportNames, isCheckedJsSourceFile, isCjsExportTableLiteral, isCjsJsFile, isJsSourceFile, isNodeEsmFile, locOf, orderedImportsOf, npmStaticDepSf7, requireSpecOf, isJsWriteTarget7, isStrictCode, resolveImport, workspacePackageOfPath, } from "../program.js";
143
+ import { containsRecord, containsUnion, describeComponentBlocker, describeRecordMemberBlocker, erasedOverloadMemberType, formatIrType, FETCH_AMBIENT_TYPES, isOsConstantsSymbol, isOverloadedCallableMemberType, isUnitOnlyTsType, isWorkerHandleType, isFetchHandleType, jsOpenObjectType, mapType, computeSymbolProvenance, declaresLegacyUrl, declaresWebAssemblyNamespace, ShapeRegistry, noteScopeSensitiveMapping, typeKey, UnionRegistry, withUndefinedArm as withUndefinedArmCanonical, } from "../type-mapper.js";
140
144
  import { builtinConstLit, builtinModuleConstOf, builtinModulesArrayLit, builtinFenceHintOf, builtinModuleFnOf, stdlibMemberFence, isStdlibMember, isStdlibSymbol, isStdlibGlobal, stdlibGlobalNameOf, stdlibGlobalMember, nodeTypesOnlySymbol, } from "./surfaces.js";
141
145
  import { builtinClassAliasOf, runtimeClassValueOfType, } from "./builtins/class-values.js";
142
146
  import { splitFiles, collectProgram, collectNpmImports, collectJsonImports, moduleArtifacts, collectGlobals, declSymbolOf, defaultExportSymbolOf, lowerFileInit, lowerDefaultExport, buildMain, appendDynamicImportModules, appendForkModules, appendWorkerModules, } from "./lower-modules.js";
@@ -219,6 +223,8 @@ import { NodeIslandModuleCollector } from "../../node-islands/modules.js";
219
223
  /** Entry function name. '%' cannot appear in a TS identifier, so a user
220
224
  * function can never collide with it (mangling is injective per prefix). */
221
225
  export const ENTRY_NAME = "%main";
226
+ /** Stands for a null binding map in Lowerer.scopedTypeMemos. */
227
+ const NO_BINDINGS = {};
222
228
  /** Localized failure: rounds of the declaration flush retry. */
223
229
  const MAX_DECLARATION_RETRIES = 16;
224
230
  /** The slot kinds the declaration flush retry degrades (stage L2). */
@@ -470,7 +476,16 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
470
476
  const externalTypes = options.externalTypes ?? new Map();
471
477
  const externalTypeSpecifiersByFile = options.externalTypeSpecifiersByFile ?? directExternalTypeSpecifiersByFile(externalTypes);
472
478
  const tierMode = options.tierMode ?? "auto";
479
+ const runtimeOptionalReport = options.tierReport !== undefined;
480
+ // One island round lowers the same program through several passes:
481
+ // validation, reachable emit, the whole-slot comparison, the stream
482
+ // relowers, historical order and the coverage remainder. They differ only
483
+ // in their mode flags, so every fact they derive from the program alone is
484
+ // computed once here and shared (lowering-facts.ts); per-pass state stays
485
+ // private to the pass.
486
+ const facts = new LoweringFacts(program, moduleOrder, externalTypeSpecifiersByFile);
473
487
  const validation = new Lowerer(program, entry, moduleOrder, {
488
+ facts,
474
489
  frontendServices: options.frontendServices,
475
490
  projectCheckJs: options.projectCheckJs ?? false,
476
491
  targetPlatform,
@@ -484,6 +499,7 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
484
499
  externalTypes,
485
500
  externalTypeSpecifiersByFile,
486
501
  tierMode,
502
+ runtimeOptionalReport,
487
503
  });
488
504
  const ffiValidation = validateFfiImports(validation);
489
505
  timing("ffi-validate");
@@ -495,10 +511,12 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
495
511
  const reachableEmit = ffiImports.length === 0
496
512
  ? validation
497
513
  : new Lowerer(program, entry, moduleOrder, {
514
+ facts,
498
515
  frontendServices: options.frontendServices,
499
516
  projectCheckJs: options.projectCheckJs ?? false,
500
517
  targetPlatform,
501
518
  startupCrash,
519
+ admittedOpinions: options.admittedOpinions,
502
520
  inlineRequireCycleCalls,
503
521
  dynamicImportRejections: options.dynamicImportRejections,
504
522
  ffiImports,
@@ -508,6 +526,7 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
508
526
  externalTypes,
509
527
  externalTypeSpecifiersByFile,
510
528
  tierMode,
529
+ runtimeOptionalReport,
511
530
  ffiBindingSymbols: ffiValidation.symbolsByName,
512
531
  });
513
532
  for (const d of extraModuleCycleDiags)
@@ -527,10 +546,12 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
527
546
  // keep push-down). A program that compiles never takes this path.
528
547
  if (result.diagnostics.length > 0 && reachableEmit.hasPartialDegradedTypes()) {
529
548
  const whole = new Lowerer(program, entry, moduleOrder, {
549
+ facts,
530
550
  frontendServices: options.frontendServices,
531
551
  projectCheckJs: options.projectCheckJs ?? false,
532
552
  targetPlatform,
533
553
  startupCrash,
554
+ admittedOpinions: options.admittedOpinions,
534
555
  inlineRequireCycleCalls,
535
556
  ffiImports,
536
557
  libraryCallbacks,
@@ -539,6 +560,7 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
539
560
  externalTypes,
540
561
  externalTypeSpecifiersByFile,
541
562
  tierMode,
563
+ runtimeOptionalReport,
542
564
  ffiBindingSymbols: ffiValidation.symbolsByName,
543
565
  wholeSlotDegradation: true,
544
566
  });
@@ -565,10 +587,12 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
565
587
  let dynNodeStreams = reachableEmit.requiresDynNodeStreams;
566
588
  const streamPass = (dyn) => {
567
589
  const general = new Lowerer(program, entry, moduleOrder, {
590
+ facts,
568
591
  frontendServices: options.frontendServices,
569
592
  projectCheckJs: options.projectCheckJs ?? false,
570
593
  targetPlatform,
571
594
  startupCrash,
595
+ admittedOpinions: options.admittedOpinions,
572
596
  inlineRequireCycleCalls,
573
597
  dynamicImportRejections: options.dynamicImportRejections,
574
598
  ffiImports,
@@ -578,6 +602,7 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
578
602
  externalTypes,
579
603
  externalTypeSpecifiersByFile,
580
604
  tierMode,
605
+ runtimeOptionalReport,
581
606
  ffiBindingSymbols: ffiValidation.symbolsByName,
582
607
  generalNodeStreams: true,
583
608
  ...(dyn ? { dynNodeStreams: true } : {}),
@@ -610,6 +635,7 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
610
635
  // without such a settled fence retain checker-backed IR exactly once.
611
636
  if (resultLowerer.requiresHistoricalOrderRelower) {
612
637
  const emit = new Lowerer(program, entry, moduleOrder, {
638
+ facts,
613
639
  frontendServices: options.frontendServices,
614
640
  projectCheckJs: options.projectCheckJs ?? false,
615
641
  ...(generalNodeStreams ? { generalNodeStreams: true } : {}),
@@ -617,6 +643,7 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
617
643
  reachable,
618
644
  targetPlatform,
619
645
  startupCrash,
646
+ admittedOpinions: options.admittedOpinions,
620
647
  inlineRequireCycleCalls,
621
648
  dynamicImportRejections: options.dynamicImportRejections,
622
649
  ffiImports,
@@ -627,6 +654,7 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
627
654
  externalTypes,
628
655
  externalTypeSpecifiersByFile,
629
656
  tierMode,
657
+ runtimeOptionalReport,
630
658
  ...(resultLowerer.wholeSlotDegradation ? { wholeSlotDegradation: true } : {}),
631
659
  });
632
660
  for (const d of extraModuleCycleDiags)
@@ -637,6 +665,20 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
637
665
  resultLowerer = emit;
638
666
  timing("historical-order-relower");
639
667
  }
668
+ // LIBRARY mode: the profile's export names resolved to the units that
669
+ // supply them — the entry's own unit for a direct export, the declaring
670
+ // module's tagged unit for a re-exported one. The export-map resolution
671
+ // reads this to land each profile entry on the compiled function without
672
+ // assuming the entry file declared it.
673
+ if (options.libRoots !== undefined && options.libRoots.length > 0) {
674
+ const libExportUnits = new Map();
675
+ for (const name of options.libRoots) {
676
+ const unit = resultLowerer.libExportUnit(name);
677
+ if (unit !== null)
678
+ libExportUnits.set(name, unit);
679
+ }
680
+ result = { ...result, libExportUnits };
681
+ }
640
682
  // Divergence warnings over the program's own modules: computed once,
641
683
  // after lowering, from the same checker (never part of a failure).
642
684
  const divergences = [
@@ -747,6 +789,7 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
747
789
  if (options.coverage !== true)
748
790
  return result;
749
791
  const remainderPass = (general, dyn = dynNodeStreams) => new Lowerer(program, entry, moduleOrder, {
792
+ facts,
750
793
  frontendServices: options.frontendServices,
751
794
  projectCheckJs: options.projectCheckJs ?? false,
752
795
  ...(general ? { generalNodeStreams: true } : {}),
@@ -756,6 +799,7 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
756
799
  alreadyFlushed: resultLowerer.flushedSymbols,
757
800
  degradedTypes: resultLowerer.degradedTypes,
758
801
  retriedSymbols: resultLowerer.retriedSymbols,
802
+ admittedOpinions: options.admittedOpinions,
759
803
  inlineRequireCycleCalls,
760
804
  dynamicImportRejections: options.dynamicImportRejections,
761
805
  targetPlatform,
@@ -767,6 +811,7 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
767
811
  externalTypes,
768
812
  externalTypeSpecifiersByFile,
769
813
  tierMode,
814
+ runtimeOptionalReport,
770
815
  });
771
816
  let remainder = remainderPass(generalNodeStreams);
772
817
  let rem = remainder.run();
@@ -793,6 +838,7 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
793
838
  reached: [...options.tierReport.preflight, ...result.diagnostics],
794
839
  deferred: result.runtimeFences,
795
840
  unreached: [...rem.diagnostics, ...rem.runtimeFences],
841
+ runtimeOptional: resultLowerer.runtimeOptionalNarrowings,
796
842
  });
797
843
  // A dynamic function's own statements can include ones that failed.
798
844
  const statementsDynamic = Math.min(tiers?.statementsDynamic ?? dynamicStatementCount(program, dynamicFunctions), result.stats.statementsTotal - result.stats.statementsFailed);
@@ -855,7 +901,7 @@ export function staticImportNamespaceType(lowerer, expr) {
855
901
  !source.fileName.endsWith(".cts") &&
856
902
  !isCjsJsFile(source, lowerer.program) &&
857
903
  lowerer.moduleOrder.includes(source)) {
858
- moduleId = `file:${tsgoPath(resolve(source.fileName))}`;
904
+ moduleId = `file:${lowerer.pathOf(source)}`;
859
905
  }
860
906
  }
861
907
  if (moduleId === null)
@@ -1283,6 +1329,10 @@ function isAnonymousCallableDefinition(node) {
1283
1329
  * property reads (`process.cwd`), or the binding an anonymous definition
1284
1330
  * initializes. Null when the source does not determine it. */
1285
1331
  export function jsFuncNameOf(node, lowerer) {
1332
+ // Typed source cannot read a function's `name` (SC2020), so the names below
1333
+ // are unobservable there; keeping them JavaScript-only leaves every typed
1334
+ // program's output byte-identical.
1335
+ const js = isJsSourceFile(ts.getSourceFileOfNode(node));
1286
1336
  let n = node;
1287
1337
  while (ts.isParenthesizedExpression(n))
1288
1338
  n = n.expression;
@@ -1297,6 +1347,23 @@ export function jsFuncNameOf(node, lowerer) {
1297
1347
  n = declaration;
1298
1348
  break;
1299
1349
  }
1350
+ // A binding element or a parameter holds the default's value only when the
1351
+ // destructured value or the argument was undefined; otherwise it holds the
1352
+ // source's value. Which one ran is a runtime fact, so a default never
1353
+ // answers for the binding: when it runs, the definition it created was
1354
+ // already named after the binding, and a named definition it references
1355
+ // keeps the name it spells. A default the source overrides must not lend
1356
+ // its name to the supplied value (`const [x = function unused() {}] =
1357
+ // [function supplied() {}]` is "supplied"), so this answers null and the
1358
+ // name read takes the runtime value's own name.
1359
+ // Without a default the spelling is wrong for every value the binding can
1360
+ // hold, but that shape has no pattern-default signature and is a separate
1361
+ // change; it keeps the previous answer here.
1362
+ if (js && declaration && (ts.isBindingElement(declaration) || ts.isParameter(declaration))) {
1363
+ if (!declaration.initializer)
1364
+ break;
1365
+ return null;
1366
+ }
1300
1367
  if (!declaration || !ts.isVariableDeclaration(declaration) || !declaration.initializer)
1301
1368
  break;
1302
1369
  let value = declaration.initializer;
@@ -1344,6 +1411,32 @@ export function jsFuncNameOf(node, lowerer) {
1344
1411
  if (p && ts.isPropertyAssignment(p) && p.initializer === outer && ts.isIdentifier(p.name)) {
1345
1412
  return p.name.text;
1346
1413
  }
1414
+ // A default parameter names it (`function f(a = function () {})`), as
1415
+ // does an object-assignment shorthand (`({ a = function () {} } = o)`)
1416
+ // and a plain identifier assignment (`a = function () {}`). A member
1417
+ // target never names one: only an identifier reference does.
1418
+ if (js && p && ts.isParameter(p) && p.initializer === outer && ts.isIdentifier(p.name)) {
1419
+ return p.name.text;
1420
+ }
1421
+ if (js &&
1422
+ p &&
1423
+ ts.isShorthandPropertyAssignment(p) &&
1424
+ p.objectAssignmentInitializer === outer &&
1425
+ ts.isIdentifier(p.name)) {
1426
+ return p.name.text;
1427
+ }
1428
+ if (js &&
1429
+ p &&
1430
+ ts.isBinaryExpression(p) &&
1431
+ p.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
1432
+ p.right === outer &&
1433
+ ts.isIdentifier(p.left) &&
1434
+ // The native parser folds a parenthesized target into the target itself
1435
+ // (`(a) = f`), leaving the source's `(` as a gap in front of it. A
1436
+ // parenthesized target is not an IdentifierReference and names nothing.
1437
+ p.getStart() === p.left.getStart()) {
1438
+ return p.left.text;
1439
+ }
1347
1440
  }
1348
1441
  return null;
1349
1442
  }
@@ -1400,6 +1493,9 @@ export class Lowerer {
1400
1493
  /** Per file: whether it assigns `exports` and `module.exports`
1401
1494
  * (cjs-exports-object.ts). */
1402
1495
  cjsExportsAssignments = new Map();
1496
+ /** JavaScript checker diagnostics preflight admitted under an opinion row
1497
+ * (LoadResult.admittedOpinions): the sites opinionAt answers for. */
1498
+ admittedOpinions;
1403
1499
  /** Inline require() calls whose module edge closes a require cycle
1404
1500
  * (LoadResult.inlineRequireCycleCalls). */
1405
1501
  inlineRequireCycleCalls;
@@ -1410,6 +1506,11 @@ export class Lowerer {
1410
1506
  * exact binding discipline as globals/functions. */
1411
1507
  staticCallables = new Map();
1412
1508
  genericFnsBySymbol = new Map();
1509
+ /** Temporal-dead-zone flags of module-scope generic ALIASES (`const h =
1510
+ * id`) that code can read before the declaration runs: the alias has no
1511
+ * binding storage of its own, so a read that can come first checks a
1512
+ * flag instead (bindingGenericFnAliasInfoOf). */
1513
+ genericAliasPresence = new Map();
1413
1514
  /** Typed declarations' instances for arguments that keep their own
1414
1515
  * record or array layout (structural-instances.ts). */
1415
1516
  structuralFnInfos = new Map();
@@ -1689,6 +1790,15 @@ export class Lowerer {
1689
1790
  * lowering and resolved by checkGenericIdentityPins only when some
1690
1791
  * generic declaration is held at more than one signature. */
1691
1792
  dynIdentityComparisons = [];
1793
+ /** The value instance each pinned binding holds (`const f: Fn = ident`),
1794
+ * keyed by the binding's declaration: two pins of one generic
1795
+ * declaration at different signatures are separate compiled closures, so
1796
+ * checkGenericIdentityPins refuses to compare them. */
1797
+ pinnedValueInstances = new Map();
1798
+ /** Function-vs-function identity comparisons recorded while lowering,
1799
+ * with the closure name each operand lowered to when it is a closure
1800
+ * (an inline instantiation expression names its instance directly). */
1801
+ pinnedIdentityComparisons = [];
1692
1802
  /** The identity comparison check reports once, after all lowering. */
1693
1803
  genericIdentityCheckDone = false;
1694
1804
  /** Function expressions lowered against a fixed target signature with a
@@ -1791,7 +1901,7 @@ export class Lowerer {
1791
1901
  * (programPatchesStdio in builtins/process.ts). */
1792
1902
  patchesStdio = null;
1793
1903
  /** The write-replacement site programPatchesStdio found: the executable
1794
- * planner refuses it beside Node islands (SC8020). */
1904
+ * planner refuses it beside Node islands (SC8006). */
1795
1905
  stdioPatchSites = [];
1796
1906
  requestInitPropMutatedSyms = null;
1797
1907
  emitterEventTable = null;
@@ -1851,6 +1961,15 @@ export class Lowerer {
1851
1961
  * prepass. This includes explicit annotations: unchecked TS annotations do
1852
1962
  * not prove that an array property read produced a value. */
1853
1963
  runtimeOptionalBindingTypes = new Map();
1964
+ /** The indexed-read analysis's storage decisions: kept for the coverage
1965
+ * report when --explain-dynamic asks, and written to stderr under
1966
+ * SCRIPTC_DEBUG_RUNTIME_OPTIONAL=1. */
1967
+ runtimeOptionalProvenance;
1968
+ /** Coverage (--explain-dynamic): the widened slots whose storage holds
1969
+ * an absence the checker's type does not admit, with the reads that
1970
+ * narrow them below it (runtime-optional-report.ts). Empty unless the
1971
+ * report was asked for. */
1972
+ runtimeOptionalNarrowings = [];
1854
1973
  /** JavaScript bindings assigned values outside their declared type
1855
1974
  * (analyzeJsWidenedBindings): checked-dynamic storage, and reads keep the
1856
1975
  * stored value instead of narrowing it to the checker's type. */
@@ -2585,6 +2704,10 @@ export class Lowerer {
2585
2704
  builtinCallableValueFns = new Map();
2586
2705
  /** Each builtin function-value adapter's Node name, for boxed values. */
2587
2706
  builtinCallableValueNames = new Map();
2707
+ /** Adapters whose name holds on the main thread only
2708
+ * (BuiltinModuleFn.valueNameMainThreadOnly): a Worker boxes them
2709
+ * unnamed, as Node's unwrapped function is. */
2710
+ builtinCallableValueMainThreadNames = new Set();
2588
2711
  /** Builtin function values whose `length` differs from their adapter's
2589
2712
  * parameter count (BuiltinModuleFn.valueLength), by adapter name. */
2590
2713
  builtinCallableValueLengths = new Map();
@@ -2813,6 +2936,25 @@ export class Lowerer {
2813
2936
  threadSlotFamilies = new Map();
2814
2937
  /** Classes used as ThreadSlots keys: their hierarchies carry a slot word. */
2815
2938
  threadSlotKeys = new Set();
2939
+ /** The narrowing conversions that link copies to their sources, by
2940
+ * `${from}:${to}` (record-links.ts). */
2941
+ recordLinks = new Map();
2942
+ /** Where each of recordLinks' pairs was first converted, by compose
2943
+ * helper name. */
2944
+ recordLinkLocs = new Map();
2945
+ /** The conversion each %rec.string and %rec.primitive helper's calls
2946
+ * replace, by helper name (record-links.ts recordStringCall). */
2947
+ recordStringFallbacks = new Map();
2948
+ /** The conversion helpers that build copies of recordLinks' pairs. */
2949
+ recordLinkSites = [];
2950
+ /** Object.prototype methods other than toString called by name on
2951
+ * record types (finalizeRecordLinks checks them against link sources). */
2952
+ recordMethodCalls = [];
2953
+ /** Completions of "custom" linked helpers (record-links.ts), which
2954
+ * finalizeRecordLinks runs once the links are known. */
2955
+ linkedHelperFinalizers = [];
2956
+ /** Helpers over record types that finalizeRecordLinks completes. */
2957
+ linkedHelpers = [];
2816
2958
  /** The JavaScript names of object literals' methods, by lifted function
2817
2959
  * (function-names.ts). */
2818
2960
  objectMethodNames = new Map();
@@ -2879,12 +3021,63 @@ export class Lowerer {
2879
3021
  unions = new UnionRegistry();
2880
3022
  /** Context-free successful type mappings. See TypeMapperCtx.typeMemo. */
2881
3023
  typeMemo = new Map();
2882
- ambient = ambientDtsPath();
2883
- overridesAmbient = overridesDtsPath();
3024
+ /** Successful mappings that read no generic-instantiation scope state
3025
+ * (TypeMapperCtx.typeMemoShared): the same answer in every binding scope
3026
+ * and at the top level. A generic instance's unscoped types land here, so
3027
+ * the next instance — and the top level — answers them without mapping
3028
+ * again. */
3029
+ sharedTypeMemo = new Map();
3030
+ /** Successful mappings per generic binding context (TypeMapperCtx.typeMemoFor):
3031
+ * by the installed typeParamBindings map, then the typeParamTsBindings map
3032
+ * (NO_BINDINGS stands for null). Binding maps are filled before they are
3033
+ * installed and never change while installed, so their identity is the
3034
+ * context. The lowerer owns the memos: they live as long as it does. */
3035
+ scopedTypeMemos = new Map();
3036
+ /** The program facts this Lowerer shares with the other passes of its
3037
+ * island round (lowering-facts.ts). Every field that is a fact lives
3038
+ * there, so a pass that re-derives it cannot disagree with its siblings.
3039
+ * A Lowerer built without LowererMode.facts gets a private copy (tests,
3040
+ * one-off lowerings). */
3041
+ facts;
3042
+ /** SCRIPTC_LOWERING_FACTS_VERIFY: the shared provenance memo's hit check,
3043
+ * public so contexts built from this Lowerer (webassembly.ts's hand-made
3044
+ * ctx, property-access.ts passing the Lowerer itself) verify too. */
3045
+ verifySymbolProvenance;
2884
3046
  /** The one mapType context: registries + hooks, assembled in the
2885
3047
  * constructor (typeParamResolver reads the CURRENT instantiation bindings
2886
3048
  * through `this`, so the same ctx serves generic bodies too). */
2887
3049
  typeCtx;
3050
+ /** The context lastContextMemo answered for. Every mapType call asks for the
3051
+ * current binding context, and a lowering pass stays in one context for
3052
+ * thousands of calls, so the pair of identity checks below is the whole
3053
+ * cost on that path: the two-level lookup only runs when the context
3054
+ * actually changes. */
3055
+ lastMemoOuter = null;
3056
+ lastMemoInner = null;
3057
+ lastMemo = null;
3058
+ /** The memo for the current binding context (scopedTypeMemos). */
3059
+ currentTypeMemo() {
3060
+ if (this.typeParamBindings === null && this.typeParamTsBindings === null)
3061
+ return this.typeMemo;
3062
+ const outer = this.typeParamBindings ?? NO_BINDINGS;
3063
+ const inner = this.typeParamTsBindings ?? NO_BINDINGS;
3064
+ if (outer === this.lastMemoOuter && inner === this.lastMemoInner)
3065
+ return this.lastMemo;
3066
+ let byTs = this.scopedTypeMemos.get(outer);
3067
+ if (byTs === undefined) {
3068
+ byTs = new Map();
3069
+ this.scopedTypeMemos.set(outer, byTs);
3070
+ }
3071
+ let memo = byTs.get(inner);
3072
+ if (memo === undefined) {
3073
+ memo = new Map();
3074
+ byTs.set(inner, memo);
3075
+ }
3076
+ this.lastMemoOuter = outer;
3077
+ this.lastMemoInner = inner;
3078
+ this.lastMemo = memo;
3079
+ return memo;
3080
+ }
2888
3081
  stats = {
2889
3082
  statementsTotal: 0,
2890
3083
  statementsFailed: 0,
@@ -2907,6 +3100,11 @@ export class Lowerer {
2907
3100
  /** Whether the program freezes, seals or prevents extensions of untyped
2908
3101
  * values other than fresh literals (noteUntypedIntegrity). */
2909
3102
  untypedIntegrity = false;
3103
+ /** A JavaScript source constructs an ArrayBuffer with a maxByteLength,
3104
+ * or reads a member that resizes, grows or detaches a buffer
3105
+ * (buffers.ts, t262-dc §2.4). Sets IrModule.bytesHeadersMutable and arms
3106
+ * the scr_js_buffers views registry in %main. */
3107
+ buffersMutable = false;
2910
3108
  liftedFns = [];
2911
3109
  /** `for … of` and `for await` loops over untyped iterables, by their
2912
3110
  * generator-kind local (generator-dynamic-dispatch.ts steps the program's
@@ -3260,6 +3458,7 @@ export class Lowerer {
3260
3458
  mapTable("primitiveCtorFns", this.primitiveCtorFns),
3261
3459
  mapTable("builtinCallableValueFns", this.builtinCallableValueFns),
3262
3460
  mapTable("builtinCallableValueNames", this.builtinCallableValueNames),
3461
+ setTable("builtinCallableValueMainThreadNames", this.builtinCallableValueMainThreadNames),
3263
3462
  countTable("builtinCallableValueLengths", this.builtinCallableValueLengths),
3264
3463
  irDataTable("builtinCheckedValues", this.builtinCheckedValues),
3265
3464
  mapTable("regionRunHelpers", this.regionRunHelpers),
@@ -3297,6 +3496,7 @@ export class Lowerer {
3297
3496
  checkedTable("genericFnsBySymbol", () => this.genericFnsBySymbol.size),
3298
3497
  checkedTable("objLitGenericFns", () => this.objLitGenericFns.size),
3299
3498
  checkedTable("bindingGenericFns", () => this.bindingGenericFns.size),
3499
+ checkedTable("genericAliasPresence", () => this.genericAliasPresence.size),
3300
3500
  checkedTable("bindingIdentifiers", () => this.bindingIdentifiers.size),
3301
3501
  checkedTable("ownToStringTargets", () => this.ownToStringTargets.size),
3302
3502
  checkedTable("neverReassignedCache", () => this.neverReassignedCache.size),
@@ -3310,6 +3510,11 @@ export class Lowerer {
3310
3510
  checkedTable("erasingLambdas", () => this.erasingLambdas.size),
3311
3511
  checkedTable("genericIdentityPins", () => this.genericIdentityPins.length),
3312
3512
  checkedTable("dynIdentityComparisons", () => this.dynIdentityComparisons.length),
3513
+ // Pinned binding instances and function-vs-function identity
3514
+ // comparisons feed the same end-of-lowering check; a unit that records
3515
+ // one lowers again rather than replaying a record without it.
3516
+ checkedTable("pinnedValueInstances", () => this.pinnedValueInstances.size),
3517
+ checkedTable("pinnedIdentityComparisons", () => this.pinnedIdentityComparisons.length),
3313
3518
  checkedTable("typedArgumentsLambdas", () => this.typedArgumentsLambdas.size),
3314
3519
  checkedTable("tupleAliasSymbols", () => this.tupleAliasSymbols.size),
3315
3520
  checkedTable("nullishFuncResults", () => this.nullishFuncResults.size),
@@ -3405,6 +3610,13 @@ export class Lowerer {
3405
3610
  checkedTable("threadSlotNames", () => this.threadSlotNames.size),
3406
3611
  checkedTable("threadSlotFamilies", () => this.threadSlotFamilies.size),
3407
3612
  checkedTable("threadSlotKeys", () => this.threadSlotKeys.size),
3613
+ checkedTable("recordLinks", () => this.recordLinks.size),
3614
+ checkedTable("recordLinkLocs", () => this.recordLinkLocs.size),
3615
+ checkedTable("recordLinkSites", () => this.recordLinkSites.length),
3616
+ checkedTable("recordStringFallbacks", () => this.recordStringFallbacks.size),
3617
+ checkedTable("linkedHelpers", () => this.linkedHelpers.length),
3618
+ checkedTable("linkedHelperFinalizers", () => this.linkedHelperFinalizers.length),
3619
+ checkedTable("recordMethodCalls", () => this.recordMethodCalls.length),
3408
3620
  checkedTable("objectMethodNames", () => this.objectMethodNames.size),
3409
3621
  checkedTable("forkTargetIdByPath", () => this.forkTargetIdByPath.size),
3410
3622
  checkedTable("nsBlocks", () => this.nsBlocks.size),
@@ -3501,10 +3713,9 @@ export class Lowerer {
3501
3713
  // settings
3502
3714
  "frontendServices",
3503
3715
  "nodeIslands",
3504
- "ambient",
3505
- "overridesAmbient",
3506
3716
  "remainder",
3507
3717
  "tierMode",
3718
+ "runtimeOptionalReport",
3508
3719
  "generalNodeStreams",
3509
3720
  "dynNodeStreams",
3510
3721
  "targetPlatform",
@@ -3531,10 +3742,29 @@ export class Lowerer {
3531
3742
  "patchesStdio",
3532
3743
  "stdioPatchSites",
3533
3744
  "requestInitPropMutatedSyms",
3534
- "classProtocols",
3745
+ // Program facts the round's passes share (lowering-facts.ts): file
3746
+ // paths, stdlib/external/package classification, a symbol's declared
3747
+ // provenance, the island-handle answers, the admitted-opinion index,
3748
+ // the JavaScript dynamic-declaration set and the class protocol index.
3749
+ // They are pure functions of (program, island set, external surface),
3750
+ // so no pass's mode can change them, and each is verified against a
3751
+ // fresh computation under SCRIPTC_LOWERING_FACTS_VERIFY.
3752
+ "facts",
3753
+ // SCRIPTC_LOWERING_FACTS_VERIFY only: this pass's own class protocol
3754
+ // index and provenance hit check, the comparisons the shared answers
3755
+ // are checked against.
3756
+ "ownClassProtocols",
3757
+ "verifySymbolProvenance",
3535
3758
  // The whole-program prepass analyzeJsWidenedBindings computes this set
3536
3759
  // before lowering begins: a pure function of the program's modules.
3537
3760
  "jsWidenedBindings",
3761
+ // Preflight's admitted opinions are a program fact computed before any
3762
+ // unit lowers.
3763
+ "admittedOpinions",
3764
+ // Coverage's --explain-dynamic report: the indexed-read analysis's
3765
+ // storage decisions and the narrowed reads they explain.
3766
+ "runtimeOptionalProvenance",
3767
+ "runtimeOptionalNarrowings",
3538
3768
  "cjsSplitRequireBindings",
3539
3769
  "cjsWholeExportSymbols",
3540
3770
  "cjsLiveMemberExports",
@@ -3551,7 +3781,10 @@ export class Lowerer {
3551
3781
  "dynamicOverloadAnswers",
3552
3782
  "argumentCountSlots",
3553
3783
  "coercions.widenedReturnTypes",
3554
- "packageFileMemo",
3784
+ // LIBRARY mode: the unit each root export name seeds is a pure function
3785
+ // of the entry's export table and the signatures collected before any
3786
+ // body lowers, so a pass that asks again computes the same answer.
3787
+ "libExportUnits",
3555
3788
  // NI-5: whether a symbol names an island handle binding depends only on
3556
3789
  // its declaration, so the answer is a memo keyed by symbol.
3557
3790
  "islandHandleBindings",
@@ -3569,7 +3802,6 @@ export class Lowerer {
3569
3802
  "slotOriginMemo",
3570
3803
  "recordOriginMemo",
3571
3804
  "boundaryCastOrder",
3572
- "declBoundaryMemo",
3573
3805
  "structuredCloneReadCounts",
3574
3806
  // state of the unit being lowered
3575
3807
  "assertedValues",
@@ -3626,6 +3858,11 @@ export class Lowerer {
3626
3858
  "spreadArmOverrides",
3627
3859
  "splitIdentifierUses",
3628
3860
  "typeMemo",
3861
+ "sharedTypeMemo",
3862
+ "scopedTypeMemos",
3863
+ "lastMemoOuter",
3864
+ "lastMemoInner",
3865
+ "lastMemo",
3629
3866
  "fnStack",
3630
3867
  "positions.nodesByKey",
3631
3868
  "positions.paths",
@@ -3654,6 +3891,7 @@ export class Lowerer {
3654
3891
  flag("cjsModuleGraphEnabled", () => this.cjsModuleGraphEnabled, () => (this.cjsModuleGraphEnabled = true)),
3655
3892
  flag("globalThisComputedWrite", () => this.globalThisComputedWrite, () => (this.globalThisComputedWrite = true)),
3656
3893
  flag("untypedIntegrity", () => this.untypedIntegrity, () => (this.untypedIntegrity = true)),
3894
+ flag("buffersMutable", () => this.buffersMutable, () => (this.buffersMutable = true)),
3657
3895
  flag("partialDegradedTypesMapped", () => this.partialDegradedTypesMapped, () => (this.partialDegradedTypesMapped = true)),
3658
3896
  fixed("errorAccessorReflection", () => this.errorAccessorReflection),
3659
3897
  fixed("subclassLinks", () => this.subclassLinks),
@@ -3711,6 +3949,8 @@ export class Lowerer {
3711
3949
  * refuse and fence exactly as before. Stage S6 demotes the units of
3712
3950
  * committed refusals in "auto" and keeps them refusals in "static-only". */
3713
3951
  tierMode;
3952
+ /** LowererMode.runtimeOptionalReport. */
3953
+ runtimeOptionalReport;
3714
3954
  generalNodeStreams;
3715
3955
  dynNodeStreams;
3716
3956
  /** Functions finishModule placed in the dynamic tier (ir/tiers.ts). */
@@ -3888,7 +4128,6 @@ export class Lowerer {
3888
4128
  * (decl-origin.ts), by IrModule.declOrigins index. */
3889
4129
  declOrigins = [];
3890
4130
  declOriginIds = new Map();
3891
- packageFileMemo = new Map();
3892
4131
  slotOriginMemo = new Map();
3893
4132
  /** The value whose slot coercion is being lowered, while that value is
3894
4133
  * in a package file: union extractions built for it carry the slot's
@@ -3944,18 +4183,10 @@ export class Lowerer {
3944
4183
  return origin;
3945
4184
  }
3946
4185
  inPackageFileOf(node) {
3947
- const sf = ts.getSourceFileOfNode(node);
3948
- let inside = this.packageFileMemo.get(sf);
3949
- if (inside === undefined) {
3950
- inside = inPackageFile(node);
3951
- this.packageFileMemo.set(sf, inside);
3952
- }
3953
- return inside;
4186
+ return this.facts.inPackageFile(node);
3954
4187
  }
3955
- declBoundaryMemo = null;
3956
4188
  get declBoundary() {
3957
- this.declBoundaryMemo ??= this.program.getSourceFileNames().some(isDeclBoundaryFile);
3958
- return this.declBoundaryMemo;
4189
+ return this.facts.declBoundary;
3959
4190
  }
3960
4191
  /** Tracked classes' bag initializers over a typed `this`
3961
4192
  * (class-dynamic-dispatch.ts recordBagInitializers). */
@@ -3981,6 +4212,7 @@ export class Lowerer {
3981
4212
  this.ffiImports = mode.ffiImports ?? [];
3982
4213
  this.forkTargets = mode.forkTargets ?? [];
3983
4214
  this.frontendServices = mode.frontendServices;
4215
+ this.admittedOpinions = mode.admittedOpinions ?? [];
3984
4216
  this.inlineRequireCycleCalls = mode.inlineRequireCycleCalls ?? new Set();
3985
4217
  this.dynamicImportRejections = mode.dynamicImportRejections ?? new Map();
3986
4218
  this.libraryCallbacks = mode.libraryCallbacks ?? false;
@@ -3990,6 +4222,10 @@ export class Lowerer {
3990
4222
  this.startupCrash = mode.startupCrash ?? null;
3991
4223
  this.targetPlatform = mode.targetPlatform ?? process.platform;
3992
4224
  this.tierMode = mode.tierMode ?? "auto";
4225
+ this.runtimeOptionalReport = mode.runtimeOptionalReport === true;
4226
+ this.runtimeOptionalProvenance = this.runtimeOptionalReport
4227
+ ? RuntimeOptionalProvenance.forReport()
4228
+ : RuntimeOptionalProvenance.fromEnvironment();
3993
4229
  this.generalNodeStreams = mode.generalNodeStreams ?? false;
3994
4230
  this.dynNodeStreams = this.generalNodeStreams && (mode.dynNodeStreams ?? false);
3995
4231
  this.workerTargets = mode.workerTargets ?? [];
@@ -4002,13 +4238,20 @@ export class Lowerer {
4002
4238
  this.ffiImportsByName = new Map(this.ffiImports.map((entry) => [entry.name, entry]));
4003
4239
  this.externalTypeSpecifiersByFile =
4004
4240
  mode.externalTypeSpecifiersByFile ?? directExternalTypeSpecifiersByFile(this.externalTypes);
4241
+ this.facts =
4242
+ mode.facts ?? new LoweringFacts(program, moduleOrder, this.externalTypeSpecifiersByFile);
4243
+ // A shared fact would be a silent miscompile if it described another
4244
+ // program: the round hands every pass its own program and moduleOrder.
4245
+ if (this.facts.program !== program || this.facts.moduleOrder !== moduleOrder)
4246
+ throw new InternalCompilerError("lowerer bug: LowererMode.facts belongs to a different program or moduleOrder");
4247
+ this.verifySymbolProvenance = this.facts.verify
4248
+ ? (sym, answer) => this.verifySymbolProvenanceAnswer(sym, answer)
4249
+ : undefined;
4005
4250
  this.checker = program.getTypeChecker();
4006
4251
  const islands = this.nodeIslands;
4007
4252
  const shadow = canonShadowHook(this.checker);
4008
4253
  this.typeCtx = {
4009
- ...(islands !== null
4010
- ? { foreignType: (t) => isForeignType(islands, t, this.checker) }
4011
- : {}),
4254
+ ...(islands !== null ? { foreignType: (t) => this.foreignType(t) } : {}),
4012
4255
  checker: this.checker,
4013
4256
  positionOf: (node) => this.positions.of(node),
4014
4257
  shapes: this.shapes,
@@ -4044,7 +4287,7 @@ export class Lowerer {
4044
4287
  genericClassInstance: (decl, ref, mapArgument) => this.genericClassInstanceType(decl, ref, mapArgument),
4045
4288
  runtimeClassValue: (type) => runtimeClassValueOfType(this, type),
4046
4289
  localClassValue: (type) => this.instanceResultClass !== null && this.instanceResultClass.declared === type.id
4047
- ? this.instanceResultClass.value
4290
+ ? (noteScopeSensitiveMapping(), this.instanceResultClass.value)
4048
4291
  : (this.localClassValueTypes.get(type.id) ?? null),
4049
4292
  mixinClassInstance: (decl) => this.mixinTypeContext && this.mixinTypeContext.classNode === decl
4050
4293
  ? { kind: "object", className: this.mixinTypeContext.className }
@@ -4055,6 +4298,11 @@ export class Lowerer {
4055
4298
  const instanceClass = instanceType && this.localClassInstanceTypes.get(instanceType.id);
4056
4299
  if (instanceClass)
4057
4300
  return { kind: "object", className: instanceClass };
4301
+ // The instantiation-stack check below (and classNamer) answers
4302
+ // differently inside a generic instance, so this mapping stays in
4303
+ // its scope.
4304
+ if (this.classInsideFunction(decl))
4305
+ noteScopeSensitiveMapping();
4058
4306
  // Computed heritage can close over parameters of its factory.
4059
4307
  // A speculative checker query outside that factory must not lower
4060
4308
  // the extends expression in the caller's lexical scope.
@@ -4107,14 +4355,23 @@ export class Lowerer {
4107
4355
  isExperimentalFile: (sf) => isExperimentalDeclarationFile(sf, this.experimentalFiles),
4108
4356
  // The declaration-typed boundary's generated types (decl-projection.ts)
4109
4357
  // describe data, like an explicitly mapped external type surface.
4110
- isExternalTypeFile: (sf) => this.externalTypeSpecifiersByFile.has(tsgoPath(resolve(sf.fileName))) ||
4111
- isDeclBoundaryFile(sf.fileName),
4358
+ isExternalTypeFile: this.isExternalTypeFile,
4359
+ symbolProvenance: this.symbolProvenance,
4360
+ ...(this.verifySymbolProvenance
4361
+ ? { verifySymbolProvenance: this.verifySymbolProvenance }
4362
+ : {}),
4112
4363
  typeMemo: this.typeMemo,
4364
+ // A hook: the ctx is spread in several places, and a copy made inside a
4365
+ // binding scope must follow the lowerer's CURRENT scope, not the one
4366
+ // that was installed at spread time.
4367
+ typeMemoFor: () => this.currentTypeMemo(),
4368
+ typeMemoShared: this.sharedTypeMemo,
4113
4369
  ...(this.generalNodeStreams ? { generalNodeStreams: true } : {}),
4114
4370
  ...(this.dynNodeStreams ? { dynNodeStreams: true } : {}),
4115
- canMemoizeType: () => this.typeParamBindings === null &&
4116
- this.typeParamTsBindings === null &&
4117
- this.mixinTypeContext === null,
4371
+ // Memoization is scoped by the binding maps (typeMemoFor); only a mixin
4372
+ // context opts out, because mixinClassInstance answers by class node and
4373
+ // the bindings do not identify it.
4374
+ canMemoizeType: () => this.mixinTypeContext === null,
4118
4375
  // fileTag is filled just below; the hook is only ever CALLED during
4119
4376
  // lowering, long after the constructor completes.
4120
4377
  isProgramFile: (sf) => this.fileTag.has(sf),
@@ -4149,7 +4406,7 @@ export class Lowerer {
4149
4406
  }
4150
4407
  if (this.moduleOrder.length === 0)
4151
4408
  this.fileTag.set(entry, "");
4152
- const jsDynamic = jsDynamicDeclarations(this.moduleOrder, this.checker);
4409
+ const jsDynamic = this.facts.jsDynamicDeclarations();
4153
4410
  if (jsDynamic.size > 0)
4154
4411
  this.typeCtx.jsDynamicDeclaration = (decl) => jsDynamic.has(decl);
4155
4412
  this.registerBuiltinErrorClasses();
@@ -4157,6 +4414,27 @@ export class Lowerer {
4157
4414
  registerBuiltinStreamClasses(this);
4158
4415
  registerBuiltinEventTargetClasses(this);
4159
4416
  }
4417
+ /** Whether preflight admitted the checker diagnostic `code` at `node`: a
4418
+ * site in `admittedOpinions` (tsc-codes.ts, JS_OPINIONS) whose span the
4419
+ * node contains. A `widen`/`throw`/`island` row's lowering path is reached
4420
+ * only through this query, so a program that admitted no such site keeps
4421
+ * the IR it has today. */
4422
+ opinionAt(node, code) {
4423
+ if (this.admittedOpinions.length === 0)
4424
+ return false;
4425
+ const file = ts.getSourceFileOfNode(node).fileName;
4426
+ const start = ts.tokenStartOfNode(node);
4427
+ const hit = this.admittedOpinionSites();
4428
+ const list = hit.get(`${file}\0${code}`);
4429
+ if (list === undefined)
4430
+ return false;
4431
+ return list.some((site) => start <= site.pos && site.end <= node.end);
4432
+ }
4433
+ /** opinionAt's index: admitted sites by file and code (one index per
4434
+ * admitted-opinions list, shared by the round). */
4435
+ admittedOpinionSites() {
4436
+ return this.facts.opinionIndex(this.admittedOpinions);
4437
+ }
4160
4438
  /** A JavaScript file TypeScript type-checks (`// @ts-check`, or the
4161
4439
  * project's `checkJs`). Its JSDoc types are enforced like TypeScript
4162
4440
  * annotations, so its classes use them as a TypeScript file would. */
@@ -4171,17 +4449,32 @@ export class Lowerer {
4171
4449
  registerBuiltinErrorClasses() {
4172
4450
  return registerBuiltinErrorClasses(this);
4173
4451
  }
4174
- classProtocols = null;
4175
4452
  classImplementedProtocol(type) {
4176
- this.classProtocols ??= new ClassProtocols(this.checker, this.moduleOrder);
4177
- return this.classProtocols.usesCheckedIdentity(type);
4453
+ return this.verifyProtocol("usesCheckedIdentity", type, (protocols) => protocols.usesCheckedIdentity(type));
4178
4454
  }
4179
4455
  /** A record view a Map or Set answers: it keeps protocol identity but
4180
4456
  * calls the collection's own methods, never a stored member. */
4181
4457
  classCollectionView(type) {
4182
- this.classProtocols ??= new ClassProtocols(this.checker, this.moduleOrder);
4183
- return this.classProtocols.collectionView(type);
4184
- }
4458
+ return this.verifyProtocol("collectionView", type, (protocols) => protocols.collectionView(type));
4459
+ }
4460
+ /** The round's shared class protocol index (lowering-facts.ts): a pure
4461
+ * analysis of (checker, moduleOrder). With SCRIPTC_LOWERING_FACTS_VERIFY
4462
+ * this Lowerer builds its own index and every answer is compared. */
4463
+ verifyProtocol(query, type, ask) {
4464
+ const answer = ask(this.facts.classProtocols());
4465
+ if (!this.facts.verify)
4466
+ return answer;
4467
+ if (this.ownClassProtocols === null) {
4468
+ this.ownClassProtocols = new ClassProtocols(this.checker, this.moduleOrder);
4469
+ }
4470
+ const fresh = ask(this.ownClassProtocols);
4471
+ this.facts.noteVerified("classProtocols");
4472
+ if (answer === fresh)
4473
+ return answer;
4474
+ throw new InternalCompilerError(`shared class protocol index answered ${String(answer)} for ${query} where a fresh ` +
4475
+ `index over the same program answered ${String(fresh)}`);
4476
+ }
4477
+ ownClassProtocols = null;
4185
4478
  /** Declared class fields may store a DYN value only when its static type
4186
4479
  * is `unknown` or `object` (also with `null` or `undefined`, or an array
4187
4480
  * of those), names checked protocol identity, is an owned runtime
@@ -4269,7 +4562,7 @@ export class Lowerer {
4269
4562
  !decl.fileName.endsWith(".cts") &&
4270
4563
  !isCjsJsFile(decl, this.program) &&
4271
4564
  this.moduleOrder.includes(decl)) {
4272
- return `file:${tsgoPath(resolve(decl.fileName))}`;
4565
+ return `file:${this.pathOf(decl)}`;
4273
4566
  }
4274
4567
  if (ts.isModuleDeclaration(decl) && ts.isStringLiteral(decl.name)) {
4275
4568
  const builtin = canonicalBuiltinModule(decl.name.text);
@@ -4415,6 +4708,11 @@ export class Lowerer {
4415
4708
  * program-unique through the file qualifier, and collision-free with
4416
4709
  * user identifiers ('%'). */
4417
4710
  classNamer = (decl) => {
4711
+ // A class declared inside a function takes the instantiated owner's name
4712
+ // (`%<instance>`, below), so its type's answer is per instance — and a
4713
+ // mapping that reads it may not be shared between scopes.
4714
+ if (this.classInsideFunction(decl))
4715
+ noteScopeSensitiveMapping();
4418
4716
  const name = ts.isClassExpression(decl) ||
4419
4717
  (() => {
4420
4718
  for (let parent = decl.parent; parent && !ts.isSourceFile(parent); parent = parent.parent) {
@@ -4434,6 +4732,16 @@ export class Lowerer {
4434
4732
  }
4435
4733
  return name;
4436
4734
  };
4735
+ /** True for a class declaration lexically inside a function: only such a
4736
+ * class can take an instantiated owner's name (classNamer), and only there
4737
+ * can localClassInstance's instantiation-stack check answer. */
4738
+ classInsideFunction(decl) {
4739
+ for (let parent = decl.parent; parent !== undefined && !ts.isSourceFile(parent); parent = parent.parent) {
4740
+ if (ts.isFunctionLike(parent))
4741
+ return true;
4742
+ }
4743
+ return false;
4744
+ }
4437
4745
  /** Follows import aliases to the original declaration's symbol. Every
4438
4746
  * value reference resolves through here, so it doubles as the flush
4439
4747
  * point for deferred collection diagnostics: resolving a reference to a
@@ -5551,12 +5859,32 @@ export class Lowerer {
5551
5859
  * TypeScript types the binding from its initializer and reports the
5552
5860
  * assignment (TS2322), which JavaScript files relax, so the binding takes
5553
5861
  * checked-dynamic storage and holds whatever the program stores. JSDoc
5554
- * type annotations keep their declared storage. */
5862
+ * type annotations keep their declared storage.
5863
+ *
5864
+ * A set accessor's unannotated parameter joins them: a JavaScript setter's
5865
+ * parameter is whatever the caller passes, and `paramShape` gives the slot
5866
+ * checked-dynamic storage. The checker types it from the twin getter's
5867
+ * return when one exists (`set value(next) { this.stored = next; }` beside
5868
+ * `get value() { return this.stored; }` types `next` as the getter's type),
5869
+ * and otherwise reports TS7032; reading the parameter at the inferred type
5870
+ * would check the caller's value back into it and throw where Node stores
5871
+ * it as is. A JSDoc `@param` type keeps its declared storage, exactly like
5872
+ * a variable's `@type`. */
5555
5873
  analyzeJsWidenedBindings(parts) {
5556
5874
  for (const { sf } of parts) {
5557
5875
  if (!isJsSourceFileName(sf.fileName) || sf.isDeclarationFile)
5558
5876
  continue;
5559
5877
  ts.walkPreorder(sf, (node) => {
5878
+ if (ts.isParameter(node) &&
5879
+ ts.isSetAccessorDeclaration(node.parent) &&
5880
+ !node.type &&
5881
+ ts.isIdentifier(node.name) &&
5882
+ !hasJsSetterParamAnnotation(node)) {
5883
+ const setterParam = this.resolveValueSymbol(node.name);
5884
+ if (setterParam)
5885
+ this.jsWidenedBindings.add(setterParam);
5886
+ return undefined;
5887
+ }
5560
5888
  if (!ts.isBinaryExpression(node) ||
5561
5889
  node.operatorToken.kind !== ts.SyntaxKind.EqualsToken ||
5562
5890
  !ts.isIdentifier(node.left))
@@ -5590,7 +5918,7 @@ export class Lowerer {
5590
5918
  }
5591
5919
  }
5592
5920
  analyzeRuntimeOptionalArrayReads(parts) {
5593
- const provenance = RuntimeOptionalProvenance.fromEnvironment();
5921
+ const provenance = this.runtimeOptionalProvenance;
5594
5922
  // The site whose value the current promotion follows (debug only).
5595
5923
  let provenanceSite;
5596
5924
  const optionalSymbols = new Set();
@@ -5903,19 +6231,31 @@ export class Lowerer {
5903
6231
  };
5904
6232
  /** `r.name` where the name resolves to the receiver's index signature. */
5905
6233
  const isRecordIndexPropertyRead = (e) => {
5906
- // A name that resolves to a declared member is not an index read, and
5907
- // only a receiver with an index signature maps to an indexed record.
5908
- if (symbolOf(e.name))
6234
+ // A name that resolves to a declared member is a member read, and only
6235
+ // a receiver with an index signature maps to an indexed record. The
6236
+ // name's own symbol separates the two spellings: a mapped
6237
+ // `Record<string, V>` answers no declaration at all, while a named
6238
+ // object type answers the index signature's symbol, whose declaration
6239
+ // is that signature. Reading the receiver's type instead would ask the
6240
+ // checker about a node inside a body lowered only for coverage, which
6241
+ // the batch prefetch covers and an extra individual query does not.
6242
+ const nameSymbol = symbolOf(e.name);
6243
+ const answersIndexSignature = nameSymbol === null ||
6244
+ (nameSymbol.declarations ?? []).some((decl) => ts.isIndexSignatureDeclaration(decl));
6245
+ if (!answersIndexSignature)
5909
6246
  return false;
5910
- const receiverType = this.typeOf(e.expression);
5911
- if (this.checker.getIndexInfosOfType(receiverType).length === 0)
5912
- return false;
5913
- const receiver = this.mapTypeOf(receiverType);
6247
+ const receiver = this.mapTypeOf(this.typeOf(e.expression));
5914
6248
  if (receiver?.kind !== "record")
5915
6249
  return false;
5916
6250
  const shape = this.shapes.get(receiver.shapeId);
5917
6251
  if (!shape || shape.tuple || !shape.indexValue || shape.indexValue.kind === "dyn")
5918
6252
  return false;
6253
+ // A slot whose value type already admits undefined tells the checker
6254
+ // itself that a key can be missing (`{ [name: string]: string |
6255
+ // undefined }` in the http-header shape), so the read hides nothing.
6256
+ if (shape.indexValue.kind === "union" &&
6257
+ this.armTag(shape.indexValue.unionId, UNDEFINED_T) >= 0)
6258
+ return false;
5919
6259
  if (shape.fields.some((field) => field.name === e.name.text))
5920
6260
  return false;
5921
6261
  const read = this.mapTypeOf(this.typeOf(e));
@@ -8477,6 +8817,11 @@ export class Lowerer {
8477
8817
  }
8478
8818
  }
8479
8819
  provenance?.flush();
8820
+ // Coverage (--explain-dynamic): the slots the analysis widened past the
8821
+ // checker's type, with the reads that narrow them back and the
8822
+ // decisions that widened them. Report-only; lowering does not read it.
8823
+ if (this.runtimeOptionalReport)
8824
+ this.runtimeOptionalNarrowings = runtimeOptionalNarrowings(this, sourceFiles);
8480
8825
  }
8481
8826
  run() {
8482
8827
  const parts = this.splitFiles();
@@ -8687,12 +9032,18 @@ export class Lowerer {
8687
9032
  return this.finishModule(functions);
8688
9033
  }
8689
9034
  /** Final retention, pruning, and module assembly shared by ordinary emit
8690
- * and the retained reachability worklist. */
8691
- finishModule(functions) {
9035
+ * and the retained reachability worklist. `library` is true for a native
9036
+ * library's emit, whose runtime has no builtin-statics unit. */
9037
+ finishModule(functions, library = false) {
8692
9038
  // Every instance of every generic value is known now (the
8693
9039
  // monomorphization worklists drained): an identity comparison against
8694
9040
  // one is exact only if the declaration is held at a single signature.
8695
9041
  checkGenericIdentityPins(this);
9042
+ finalizeRecordLinks(this, functions);
9043
+ // The statics lookup installs before value boxing, so the function
9044
+ // values it adds to the entry module are boxed with the rest.
9045
+ if (!library)
9046
+ installBuiltinStatics(this, functions);
8696
9047
  boxBuiltinValuesChecked(this, functions);
8697
9048
  finalizeFunctionNames(this, functions);
8698
9049
  if (this.diags.length === 0)
@@ -8707,6 +9058,9 @@ export class Lowerer {
8707
9058
  guardFrozenWrites(this, functions);
8708
9059
  applyHandleProperties(this, functions);
8709
9060
  installBufferValue(functions);
9061
+ // A mutable-buffers program arms the views registry before any buffer
9062
+ // exists, so every buffer in it is detachable from the start.
9063
+ const buffersMutable = this.buffersMutable && installMutableBuffersArm(functions);
8710
9064
  installFetchBodyWebStreams(this, functions);
8711
9065
  returnDispatchReceivers(this, functions);
8712
9066
  // Globals typed by a class that never REGISTERED (a JS class whose
@@ -8829,10 +9183,12 @@ export class Lowerer {
8829
9183
  ...(this.threadSlotKeys.size > 0
8830
9184
  ? { threadSlotKeys: [...this.threadSlotKeys].sort() }
8831
9185
  : {}),
9186
+ ...(this.recordLinks.size > 0 ? { recordLinks: [...this.recordLinks.values()] } : {}),
8832
9187
  ...(this.freezableArrays.size > 0
8833
9188
  ? { freezableArrays: [...this.freezableArrays].sort() }
8834
9189
  : {}),
8835
9190
  ...(this.untypedIntegrity ? { untypedIntegrity: true } : {}),
9191
+ ...(buffersMutable ? { bytesHeadersMutable: true } : {}),
8836
9192
  ...(sloppyDynWrites.length > 0 ? { sloppyDynWrites } : {}),
8837
9193
  ...(isNodeEsmFile(this.entry, this.program) ? {} : { commonJsEntry: true }),
8838
9194
  ...(this.ffiImports.length > 0 ? { ffiImports: [...this.ffiImports] } : {}),
@@ -8857,7 +9213,7 @@ export class Lowerer {
8857
9213
  if (module && this.dynamicFunctions.length > 0)
8858
9214
  promoteJsvals(module);
8859
9215
  // A program that replaces a process output stream's write method beside
8860
- // Node islands is refused by the executable planner (SC8020): an
9216
+ // Node islands is refused by the executable planner (SC8006): an
8861
9217
  // island's process.stdout is its own object. Only island builds pay for
8862
9218
  // the whole-program scan.
8863
9219
  const stdioPatches = this.nodeIslands !== null && programPatchesStdio(this)
@@ -8988,6 +9344,42 @@ export class Lowerer {
8988
9344
  return this.reachable === null || this.remainder;
8989
9345
  }
8990
9346
  /* ── reachability ─────────────────────────────────────────────────── */
9347
+ /** LIBRARY mode: the unit the root name `name` seeds, resolved through
9348
+ * the entry module's export table. A direct `export function f` and every
9349
+ * facade that names it (`export { f }`, `export { f as g }`,
9350
+ * `export { f } from "./m"`, `export * from "./m"`) reach the same
9351
+ * declaration, and the unit is whatever the declaration's own module
9352
+ * qualified it as — the entry's bare name or another module's `%mN.` tag.
9353
+ * Memoized: the four emit passes and the result's export map read one
9354
+ * answer. Null when the name is not an export of a compiled function
9355
+ * (SC4002/SC4004/SC4007 report it). */
9356
+ libExportUnit(name) {
9357
+ const memo = this.libExportUnits;
9358
+ if (memo.has(name))
9359
+ return memo.get(name);
9360
+ const symbol = resolveEntryExportSymbol(this.checker, this.entry, name);
9361
+ let unit = null;
9362
+ if (symbol !== null) {
9363
+ unit = this.fnSigsBySymbol.get(symbol)?.name ?? null;
9364
+ if (unit === null) {
9365
+ // The export table's symbol can be a copy of the declaration's; the
9366
+ // declaration's own symbol is the one signatures are keyed by.
9367
+ for (const declaration of symbol.declarations) {
9368
+ if (!ts.isFunctionDeclaration(declaration))
9369
+ continue;
9370
+ const declared = declSymbolOf(this, declaration);
9371
+ unit = declared === undefined ? null : (this.fnSigsBySymbol.get(declared)?.name ?? null);
9372
+ if (unit !== null)
9373
+ break;
9374
+ }
9375
+ }
9376
+ }
9377
+ memo.set(name, unit);
9378
+ return unit;
9379
+ }
9380
+ /** One answer per root name: a pass builds its own Lowerer, and the
9381
+ * signatures this reads are collected before any body is lowered. */
9382
+ libExportUnits = new Map();
8991
9383
  /** Reachable emit: computes the set of body names the program's entry
8992
9384
  * reaches and retains each body IR as it lowers. Seeds are the per-file
8993
9385
  * init bodies (top-level statements always run); edges fire from
@@ -9031,21 +9423,42 @@ export class Lowerer {
9031
9423
  collectionEdges.add(name);
9032
9424
  };
9033
9425
  this.prefetchProgramSymbols(parts);
9034
- this.collectProgram(parts);
9035
- this.speculativeTypeQueries(() => {
9036
- extendAssertedRecordMembers(this, parts.map((fp) => fp.sf));
9037
- this.analyzeRuntimeOptionalArrayReads(parts);
9038
- this.analyzeDateJsonResults(parts);
9039
- this.analyzeGuardedRecordReadGlobals(parts);
9040
- this.analyzeJsWidenedBindings(parts);
9041
- });
9042
- // Decorated classes analyze post-collection here too: the %init seeds
9043
- // lower the decoration calls, whose edges (decorator bodies, construct
9044
- // thunks) reachable emit must see.
9045
- for (const info of this.classes.values())
9046
- analyzeClassDecoration(this, info);
9047
- this.prepareModuleInits(parts);
9048
- prepareCjsModuleGraph(this, parts);
9426
+ // Collection poisons the pass the way statement lowering does: a Node
9427
+ // island module the build cannot ship pushes its diagnostic (SC8006)
9428
+ // and aborts (nodeIslandModules.addLoaded, lower-node-island.ts). The
9429
+ // diagnostic is the report, and emission must not run on a program
9430
+ // collected halfway, so the pass ends here with it. A poison nothing
9431
+ // reported is still a bug and stays a crash.
9432
+ try {
9433
+ this.collectProgram(parts);
9434
+ this.speculativeTypeQueries(() => {
9435
+ extendAssertedRecordMembers(this, parts.map((fp) => fp.sf));
9436
+ this.analyzeRuntimeOptionalArrayReads(parts);
9437
+ this.analyzeDateJsonResults(parts);
9438
+ this.analyzeGuardedRecordReadGlobals(parts);
9439
+ this.analyzeJsWidenedBindings(parts);
9440
+ });
9441
+ // Decorated classes analyze post-collection here too: the %init seeds
9442
+ // lower the decoration calls, whose edges (decorator bodies, construct
9443
+ // thunks) reachable emit must see.
9444
+ for (const info of this.classes.values())
9445
+ analyzeClassDecoration(this, info);
9446
+ this.prepareModuleInits(parts);
9447
+ prepareCjsModuleGraph(this, parts);
9448
+ }
9449
+ catch (e) {
9450
+ if (!(e instanceof PoisonError) || this.diags.length === 0)
9451
+ throw e;
9452
+ return {
9453
+ reachable: collectionEdges,
9454
+ result: {
9455
+ module: null,
9456
+ diagnostics: this.diags,
9457
+ runtimeFences: this.runtimeFences,
9458
+ stats: this.stats,
9459
+ },
9460
+ };
9461
+ }
9049
9462
  // Every lowerable body, by emitted-function name. The names double as
9050
9463
  // retained-function keys and are deterministic by construction
9051
9464
  // (qualified declaration names).
@@ -9444,11 +9857,16 @@ export class Lowerer {
9444
9857
  });
9445
9858
  // LIBRARY mode's extra reachability roots (LowerOptions.libRoots): the
9446
9859
  // profile-mapped exports are called from outside the graph, so they
9447
- // seed the worklist beside the init bodies. Unknown names are inert
9448
- // (the export-map resolution reports them as SC4002 later).
9860
+ // seed the worklist beside the init bodies. Each name resolves through
9861
+ // the entry module's export table to the unit that supplies it, so a
9862
+ // re-exported function seeds its own module's unit. Unknown names are
9863
+ // inert (the export-map resolution reports them as SC4002 later).
9449
9864
  const rootEdge = this.onEdge;
9450
- for (const root of extraRoots ?? [])
9451
- rootEdge?.(root);
9865
+ for (const root of extraRoots ?? []) {
9866
+ const unit = this.libExportUnit(root);
9867
+ if (unit !== null)
9868
+ rootEdge?.(unit);
9869
+ }
9452
9870
  const shuffle = lowerShuffle();
9453
9871
  const lowerUnitBody = (name) => {
9454
9872
  const unit = units.get(name);
@@ -9658,7 +10076,7 @@ export class Lowerer {
9658
10076
  files: parts.map((fp) => fp.sf),
9659
10077
  });
9660
10078
  this.reachableForArtifacts = reachable;
9661
- return { reachable, result: this.finishModule(functions) };
10079
+ return { reachable, result: this.finishModule(functions, extraRoots !== undefined) };
9662
10080
  }
9663
10081
  /** What the steps before the worklist settled for a top-level
9664
10082
  * declaration, as text without source positions (unit-reuse.ts): a
@@ -10421,7 +10839,14 @@ export class Lowerer {
10421
10839
  }
10422
10840
  this.typeFail(node, type, "index-signature", indexSignatureTypeDiag(this.checker.typeToString(type), locOf(node)));
10423
10841
  }
10424
- // Attribute an unsupported package type to its package.
10842
+ // Attribute an unsupported package type to its package. A PACKAGE DATA
10843
+ // SHAPE (an interface or type alias declared only by a package the
10844
+ // module graph never loads) never reaches this: it describes data the
10845
+ // program itself builds, so mapTypeEntry already widened it to the
10846
+ // checked-dynamic value exactly as it does for the same shape declared
10847
+ // locally. What arrives here is a package's VALUE shape — a class or a
10848
+ // merged value declaration, which only that package's implementation
10849
+ // could produce.
10425
10850
  {
10426
10851
  const pkg = this.npmPackageOf(widened);
10427
10852
  if (pkg) {
@@ -10522,6 +10947,13 @@ export class Lowerer {
10522
10947
  this.pushDiag(diag);
10523
10948
  throw new PoisonError();
10524
10949
  }
10950
+ /** A read of a Node 24 global the native runtime does not implement
10951
+ * (host-globals.ts): refusing is the honest answer, and the reason id
10952
+ * lets a Node island run the module instead. */
10953
+ hostGlobalFence(name, node) {
10954
+ this.pushDiag(hostGlobalDiag(name, locOf(node)));
10955
+ throw new PoisonError();
10956
+ }
10525
10957
  /** The declaration-side refusal of a stdlib-global snapshot read as a
10526
10958
  * VALUE (stdlibGlobalAliasDecl): report once, at the declaration's name,
10527
10959
  * naming the type the program asked the compiler to hold when it has a
@@ -10872,7 +11304,12 @@ export class Lowerer {
10872
11304
  * (`T`, `T[]`, `{ v: T }`, `(x: T) => T` all resolve). Inert outside
10873
11305
  * generic instantiation. */
10874
11306
  typeParamResolver = (t) => {
10875
- if (!this.typeParamBindings || !(t.flags & ts.TypeFlags.TypeParameter))
11307
+ if (!(t.flags & ts.TypeFlags.TypeParameter))
11308
+ return null;
11309
+ // The answer is the current bindings' (an unbound parameter maps by the
11310
+ // symbolic rules), so the mapping may not leave its scope.
11311
+ noteScopeSensitiveMapping();
11312
+ if (!this.typeParamBindings)
10876
11313
  return null;
10877
11314
  const sym = t.getSymbol();
10878
11315
  return (sym && this.typeParamBindings.get(sym)) ?? null;
@@ -10884,7 +11321,10 @@ export class Lowerer {
10884
11321
  * over literal arguments). Inert outside generic function and class
10885
11322
  * instantiation. */
10886
11323
  typeParamTsResolver = (t) => {
10887
- if (!this.typeParamTsBindings || !(t.flags & ts.TypeFlags.TypeParameter))
11324
+ if (!(t.flags & ts.TypeFlags.TypeParameter))
11325
+ return null;
11326
+ noteScopeSensitiveMapping();
11327
+ if (!this.typeParamTsBindings)
10888
11328
  return null;
10889
11329
  const sym = t.getSymbol();
10890
11330
  return (sym && this.typeParamTsBindings.get(sym)) ?? null;
@@ -10894,7 +11334,13 @@ export class Lowerer {
10894
11334
  * (boundAliasInstances), or null when its signature never instantiated
10895
11335
  * that reference. Inert outside generic function instantiation. */
10896
11336
  boundAliasTsResolver = (t) => {
10897
- if (!this.typeParamTsBindings || t.getAliasTypeArguments().length === 0)
11337
+ const aliasArguments = t.getAliasTypeArguments().length;
11338
+ if (aliasArguments === 0)
11339
+ return null;
11340
+ // boundAliasInstances is keyed by the installed ts bindings, so this
11341
+ // answer belongs to the instantiation that asks.
11342
+ noteScopeSensitiveMapping();
11343
+ if (!this.typeParamTsBindings)
10898
11344
  return null;
10899
11345
  const tsBindings = this.typeParamTsBindings;
10900
11346
  return (this.boundAliasInstances.get(t)?.find((entry) => entry.tsBindings === tsBindings)?.instance ??
@@ -11687,6 +12133,14 @@ export class Lowerer {
11687
12133
  if (helper) {
11688
12134
  return { kind: "call", callee: helper, args: [expr], type: expected, loc: expr.loc };
11689
12135
  }
12136
+ // Inside a type assertion's operand the program claimed the value's
12137
+ // shape: an arm the asserted target excludes traps (divergence 38's
12138
+ // lying-assertion stance) instead of refusing the whole conversion.
12139
+ if (this.coercions.assertedOperand > 0) {
12140
+ const checked = this.widthLiftPlan(expr.type, expected);
12141
+ if (checked?.how === "checkedRetag")
12142
+ return this.applyWidthLift(checked, expr, expected, expr.loc);
12143
+ }
11690
12144
  return assertedConversion(this, expr, expected) ?? expr;
11691
12145
  }
11692
12146
  if (expr.type.kind === "void") {
@@ -11939,8 +12393,8 @@ export class Lowerer {
11939
12393
  recordUnionRouteHelper(source, toId, loc) {
11940
12394
  return recordUnionRouteHelper(this, source, toId, loc);
11941
12395
  }
11942
- unionRetagHelper(fromId, toId, loc, trappable) {
11943
- return unionRetagHelper(this, fromId, toId, loc, trappable);
12396
+ unionRetagHelper(fromId, toId, loc, trappable, classRoutes) {
12397
+ return unionRetagHelper(this, fromId, toId, loc, trappable, classRoutes);
11944
12398
  }
11945
12399
  narrowedArmHelper(fromId, target, loc, message) {
11946
12400
  return narrowedArmHelper(this, fromId, target, loc, message);
@@ -12580,6 +13034,12 @@ export class Lowerer {
12580
13034
  return true;
12581
13035
  if (to.inner.kind === "void")
12582
13036
  return from.inner.kind !== "void";
13037
+ // A module namespace widens into a checked-dynamic payload: both settle
13038
+ // the module's namespace object (coerceToExpected routes the value
13039
+ // through moduleNamespacePromiseDynValue). The joint payload of several
13040
+ // namespace-valued promise arms is exactly this dyn (mergePromiseArms).
13041
+ if (from.inner.kind === "moduleNs" && to.inner.kind === "dyn")
13042
+ return true;
12583
13043
  return (this.dynConvertible(from) &&
12584
13044
  canDynCheckTo(to, (id) => this.shapes.get(id), (id) => this.unions.get(id)));
12585
13045
  }
@@ -12648,6 +13108,36 @@ export class Lowerer {
12648
13108
  if (expected.kind !== "record")
12649
13109
  return false;
12650
13110
  let e = node;
13111
+ while (ts.isParenthesizedExpression(e))
13112
+ e = e.expression;
13113
+ // A conditional of fresh object literals (`return valid ? { entries, … }
13114
+ // : { entries: [], … }`) is the same fresh construction per arm: the
13115
+ // checker's join can carry an EMPTY arm's uninhabited element
13116
+ // representation, which the populated arm then cannot lift into. Build
13117
+ // both arms at the declared result, exactly as a synchronous return
13118
+ // does. Neither arm can be a thenable (an object literal that declares
13119
+ // `then` is awaited instead), so no promise adoption is bypassed. A
13120
+ // conditional whose join every arm already lifts into takes the same
13121
+ // path for the same layout: each arm is constructed at the result
13122
+ // instead of the join being constructed and width-copied into it (the
13123
+ // zero-cost gate lists the programs whose code that changes).
13124
+ if (ts.isConditionalExpression(e))
13125
+ return this.isFreshRecordLiteral(e.whenTrue) && this.isFreshRecordLiteral(e.whenFalse);
13126
+ return this.freshRecordLiteralInto(e, expected);
13127
+ }
13128
+ /** A parenthesized fresh object literal that does not declare `then`. */
13129
+ isFreshRecordLiteral(node) {
13130
+ let e = node;
13131
+ while (ts.isParenthesizedExpression(e))
13132
+ e = e.expression;
13133
+ return (ts.isObjectLiteralExpression(e) &&
13134
+ this.checker.getPropertyOfType(this.typeOf(e), "then") === undefined);
13135
+ }
13136
+ /** One arm of a returned conditional: a fresh object literal whose
13137
+ * ordinary construction cannot reach the declared result (see
13138
+ * returnsFreshRecord). */
13139
+ freshRecordLiteralInto(node, expected) {
13140
+ let e = node;
12651
13141
  while (ts.isParenthesizedExpression(e))
12652
13142
  e = e.expression;
12653
13143
  if (!ts.isObjectLiteralExpression(e))
@@ -13651,7 +14141,7 @@ export class Lowerer {
13651
14141
  * call runs for its effects (it throws or exits), and the expression ends
13652
14142
  * in an unreachable trap instead of producing a value. The result reads an
13653
14143
  * uninitialized hidden local that control never reaches. */
13654
- divergentValue(call, expected) {
14144
+ divergentValue(call, expected, message = "unreachable: a 'never' call returned — please report this") {
13655
14145
  const loc = call.loc;
13656
14146
  const slot = this.declareHiddenLocal("%never", expected);
13657
14147
  slot.mutable = true;
@@ -13663,7 +14153,7 @@ export class Lowerer {
13663
14153
  {
13664
14154
  kind: "runtimeFence",
13665
14155
  code: "SC9002",
13666
- message: "unreachable: a 'never' call returned — please report this",
14156
+ message,
13667
14157
  loc,
13668
14158
  },
13669
14159
  ],
@@ -14257,7 +14747,7 @@ export class Lowerer {
14257
14747
  // (plan D-5). Until the write is routed there it is refused by name
14258
14748
  // rather than by the generic no-lowering text.
14259
14749
  if (symbol === null && isJsWriteTarget7(node) && isJsSourceFile(ts.getSourceFileOfNode(node))) {
14260
- this.unsupported("SC1091", node, `writing the undeclared name '${name}' in a JavaScript source`);
14750
+ this.unsupported("SC1091", node, `writing the undeclared name '${name}' in a JavaScript source`, undefined, isStrictCode(node) ? undefined : "implicit-global-write");
14261
14751
  }
14262
14752
  if (this.isBlockedBinding(symbol)) {
14263
14753
  this.pushDiag(blockedBindingUseDiag(name, locOf(node)));
@@ -14449,11 +14939,58 @@ export class Lowerer {
14449
14939
  * members by name + this provenance, and everything else those files
14450
14940
  * declare hits the SC2020-family fence). The file half of every
14451
14941
  * supported-surface provenance check. */
14452
- isStdlibFile = (sf) => sf.fileName === this.ambient ||
14453
- sf.fileName === this.overridesAmbient ||
14454
- isFallbackDtsPath(sf.fileName) ||
14455
- this.program.isSourceFileDefaultLibrary(sf) ||
14456
- (sf.isDeclarationFile && isNodeTypesPath(sf.fileName));
14942
+ isStdlibFile = (sf) => this.facts.isStdlibFile(sf);
14943
+ /** provenanceOf's answers (type-mapper.ts's SymbolProvenance), keyed by
14944
+ * symbol. A symbol's declarations are fixed for one loaded program, and
14945
+ * the mapper asks on every object type it maps, so the round shares one
14946
+ * map (lowering-facts.ts). */
14947
+ get symbolProvenance() {
14948
+ return this.facts.symbolProvenance;
14949
+ }
14950
+ /** SCRIPTC_LOWERING_FACTS_VERIFY: the shared provenance memo answered, so
14951
+ * recompute it and fail on a disagreement (lowering-facts.ts). */
14952
+ verifySymbolProvenanceAnswer(sym, answer) {
14953
+ const fresh = computeSymbolProvenance(sym, this.isStdlibFile);
14954
+ // The two lazily filled answers (`??=` on a hit) are declaration-only
14955
+ // too, so recompute the ones an answer carries. The pass that filled one
14956
+ // stored the value it computed, and this comparison catches a later pass
14957
+ // that would have filled a different one.
14958
+ const freshWebAssembly = answer.webAssembly === undefined
14959
+ ? undefined
14960
+ : declaresWebAssemblyNamespace(sym.declarations, this.isStdlibFile);
14961
+ const freshLegacyUrl = answer.legacyUrl === undefined
14962
+ ? undefined
14963
+ : declaresLegacyUrl(sym.declarations, { isStdlibFile: this.isStdlibFile });
14964
+ const same = fresh.stdlibInterface === answer.stdlibInterface &&
14965
+ fresh.stdlibClass === answer.stdlibClass &&
14966
+ fresh.libInterface === answer.libInterface &&
14967
+ freshWebAssembly === answer.webAssembly &&
14968
+ freshLegacyUrl === answer.legacyUrl;
14969
+ this.facts.noteVerified("symbolProvenance");
14970
+ if (same)
14971
+ return;
14972
+ if (freshWebAssembly !== undefined)
14973
+ fresh.webAssembly = freshWebAssembly;
14974
+ if (freshLegacyUrl !== undefined)
14975
+ fresh.legacyUrl = freshLegacyUrl;
14976
+ throw new InternalCompilerError(`shared symbol provenance for ${ts.symbolName(sym)} does not match a fresh ` +
14977
+ `computation: shared ${JSON.stringify(answer)}, recomputed ${JSON.stringify(fresh)}`);
14978
+ }
14979
+ /** Whether the file holds declarations of an explicitly mapped external
14980
+ * type surface (coverage's --external-types) or of the declaration-typed
14981
+ * boundary's generated types. Both are fixed for the program, and the
14982
+ * mapper asks per type (lowering-facts.ts keeps the answer). */
14983
+ isExternalTypeFile = (sf) => this.facts.isExternalTypeFile(sf, this.externalTypeSpecifiersByFile);
14984
+ /** tsgoPath(resolve(sf.fileName)): the path spelling the module tables
14985
+ * key by. A source file's path cannot change while the program lowers. */
14986
+ pathOf = (sf) => this.facts.pathOf(sf);
14987
+ /** Whether values of `type` are island handles (boundary.ts's
14988
+ * isForeignType; the answers and their invalidation live in
14989
+ * lowering-facts.ts). The type mapper asks this on every mapType call,
14990
+ * memo hits included. */
14991
+ foreignType(type) {
14992
+ return this.facts.foreignType(type, this.nodeIslands, this.checker);
14993
+ }
14457
14994
  nodeTypesOnlySymbol(sym) {
14458
14995
  return nodeTypesOnlySymbol(this, sym);
14459
14996
  }
@@ -15394,6 +15931,8 @@ export class Lowerer {
15394
15931
  fnName = keyedHelperName(this, `%builtin.value.${fn.valueFn ?? fn.fn}`, key);
15395
15932
  this.builtinCallableValueFns.set(key, fnName);
15396
15933
  this.builtinCallableValueNames.set(fnName, fn.valueName ?? display.slice(display.lastIndexOf(".") + 1));
15934
+ if (fn.valueNameMainThreadOnly)
15935
+ this.builtinCallableValueMainThreadNames.add(fnName);
15397
15936
  if (fn.valueLength !== undefined)
15398
15937
  this.builtinCallableValueLengths.set(fnName, fn.valueLength);
15399
15938
  const params = funcType.params.map((type, index) => ({
@@ -15475,6 +16014,13 @@ export class Lowerer {
15475
16014
  });
15476
16015
  }
15477
16016
  if (valueParams.some((param) => param.name !== undefined)) {
16017
+ // Every materialization writes this entry at ITS location, so a second
16018
+ // one overwrites the first in place. A table only grows by addition, so
16019
+ // that change is no part of this unit's function: name it (unit-journal.ts
16020
+ // UnitEvents.touch), and the change is counted here instead of being
16021
+ // found by HeldTables.check as an unnamed write.
16022
+ if (this.builtinCheckedValues.has(fnName))
16023
+ this.unitEvents?.touch(fnName);
15478
16024
  this.builtinCheckedValues.set(fnName, { fn, display, loc });
15479
16025
  }
15480
16026
  return { kind: "closure", fnName, captures: [], type: funcType, loc };
@@ -15490,16 +16036,19 @@ export class Lowerer {
15490
16036
  : expr;
15491
16037
  }
15492
16038
  /** The name and length a builtin function's adapter boxes under: the ones
15493
- * Node's function carries (`[Function: randomUUID]`). Empty for any other
15494
- * value. */
16039
+ * Node's function carries (`[Function: randomUUID]`), with the main-thread
16040
+ * qualifier of a name a Worker does not carry (`process.cwd`). Empty for
16041
+ * any other value. */
15495
16042
  builtinFunctionIdentity(expr) {
15496
16043
  if (expr.kind !== "closure")
15497
16044
  return {};
15498
16045
  const name = this.builtinCallableValueNames.get(expr.fnName);
15499
16046
  const length = this.builtinCallableValueLengths.get(expr.fnName);
16047
+ const mainThreadOnly = this.builtinCallableValueMainThreadNames.has(expr.fnName);
15500
16048
  return {
15501
16049
  ...(name !== undefined ? { fnName: name } : {}),
15502
16050
  ...(length !== undefined ? { fnLength: length } : {}),
16051
+ ...(mainThreadOnly ? { fnNameMainThreadOnly: true } : {}),
15503
16052
  };
15504
16053
  }
15505
16054
  isBuiltinCallableValue(expr) {
@@ -15914,6 +16463,16 @@ function droppedMembers(lowerer, from, to, seen) {
15914
16463
  }
15915
16464
  return out;
15916
16465
  }
16466
+ /** A JSDoc `@param` type on a set accessor's parameter is an annotation like
16467
+ * a variable's `@type` (hasJsTypeAnnotation, lower-stmts.ts): the setter
16468
+ * keeps its declared storage. Setters take exactly one parameter, so any
16469
+ * `@param` before it belongs to it. */
16470
+ function hasJsSetterParamAnnotation(param) {
16471
+ const accessor = param.parent;
16472
+ if (!accessor)
16473
+ return false;
16474
+ return /@param\b/.test(ts.getSourceFileOfNode(accessor).text.slice(accessor.pos, ts.tokenStartOfNode(param)));
16475
+ }
15917
16476
  /** fs.realpathSync and its .native as function values (fs.realpath stores
15918
16477
  * `var origRealpathSync = fs.realpathSync`): path and options pass through
15919
16478
  * unchecked to the runtime, which applies Node's argument handling. */