@scriptc/compiler 0.4.6 → 0.4.7

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 (652) hide show
  1. package/ambient/node-fallback/events.d.ts +6 -1
  2. package/ambient/node-fallback/fs-promises.d.ts +1 -1
  3. package/ambient/node-fallback/fs.d.ts +54 -10
  4. package/ambient/node-fallback/http.d.ts +3 -1
  5. package/ambient/node-fallback/net.d.ts +19 -0
  6. package/ambient/node-fallback/querystring.d.ts +3 -3
  7. package/ambient/scriptc-node-fallback.d.ts +58 -13
  8. package/dist/backend/executable-features.js +13 -0
  9. package/dist/backend/executable-features.js.map +1 -1
  10. package/dist/backend/immutability.d.ts +12 -1
  11. package/dist/backend/immutability.js +50 -4
  12. package/dist/backend/immutability.js.map +1 -1
  13. package/dist/backend/immutability.test.js +95 -1
  14. package/dist/backend/immutability.test.js.map +1 -1
  15. package/dist/backend/library-pack.js +2 -0
  16. package/dist/backend/library-pack.js.map +1 -1
  17. package/dist/backend/linker.d.ts +11 -0
  18. package/dist/backend/linker.js +31 -3
  19. package/dist/backend/linker.js.map +1 -1
  20. package/dist/backend/lld.d.ts +7 -2
  21. package/dist/backend/lld.js +5 -3
  22. package/dist/backend/lld.js.map +1 -1
  23. package/dist/backend/lld.test.js +10 -4
  24. package/dist/backend/lld.test.js.map +1 -1
  25. package/dist/backend/llvm/constant-callbacks.test.js +50 -1
  26. package/dist/backend/llvm/constant-callbacks.test.js.map +1 -1
  27. package/dist/backend/llvm/cpu-dispatch.js +6 -5
  28. package/dist/backend/llvm/cpu-dispatch.js.map +1 -1
  29. package/dist/backend/llvm/dyn.d.ts +53 -1
  30. package/dist/backend/llvm/dyn.js +221 -9
  31. package/dist/backend/llvm/dyn.js.map +1 -1
  32. package/dist/backend/llvm/emit-function.js +1 -1
  33. package/dist/backend/llvm/emit-function.js.map +1 -1
  34. package/dist/backend/llvm/emit-module.js +148 -50
  35. package/dist/backend/llvm/emit-module.js.map +1 -1
  36. package/dist/backend/llvm/emit-statements.js +39 -19
  37. package/dist/backend/llvm/emit-statements.js.map +1 -1
  38. package/dist/backend/llvm/emitter.d.ts +29 -2
  39. package/dist/backend/llvm/emitter.js +86 -7
  40. package/dist/backend/llvm/emitter.js.map +1 -1
  41. package/dist/backend/llvm/expr-calls.d.ts +4 -1
  42. package/dist/backend/llvm/expr-calls.js +20 -4
  43. package/dist/backend/llvm/expr-calls.js.map +1 -1
  44. package/dist/backend/llvm/expr-dynamic.js +209 -16
  45. package/dist/backend/llvm/expr-dynamic.js.map +1 -1
  46. package/dist/backend/llvm/expr-primitives.js +94 -11
  47. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  48. package/dist/backend/llvm/expr-stream-bridges.d.ts +8 -0
  49. package/dist/backend/llvm/expr-stream-bridges.js +42 -2
  50. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  51. package/dist/backend/llvm/expr-stream-callbacks.d.ts +16 -0
  52. package/dist/backend/llvm/expr-stream-callbacks.js +206 -20
  53. package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
  54. package/dist/backend/llvm/integer-values.d.ts +2 -0
  55. package/dist/backend/llvm/integer-values.js +6 -0
  56. package/dist/backend/llvm/integer-values.js.map +1 -1
  57. package/dist/backend/llvm/js-ic.d.ts +38 -0
  58. package/dist/backend/llvm/js-ic.js +295 -1
  59. package/dist/backend/llvm/js-ic.js.map +1 -1
  60. package/dist/backend/llvm/lib-dispatch.js +20 -0
  61. package/dist/backend/llvm/lib-dispatch.js.map +1 -1
  62. package/dist/backend/llvm/lib-filesystem.js +116 -11
  63. package/dist/backend/llvm/lib-filesystem.js.map +1 -1
  64. package/dist/backend/llvm/lib-process.js +136 -24
  65. package/dist/backend/llvm/lib-process.js.map +1 -1
  66. package/dist/backend/llvm/lib-shared.js +70 -0
  67. package/dist/backend/llvm/lib-shared.js.map +1 -1
  68. package/dist/backend/llvm/lib-stream.js +67 -0
  69. package/dist/backend/llvm/lib-stream.js.map +1 -1
  70. package/dist/backend/llvm/loop-entry-versions.d.ts +2 -2
  71. package/dist/backend/llvm/loop-entry-versions.js +43 -21
  72. package/dist/backend/llvm/loop-entry-versions.js.map +1 -1
  73. package/dist/backend/llvm/loop-state.d.ts +7 -1
  74. package/dist/backend/llvm/loop-state.js +20 -2
  75. package/dist/backend/llvm/loop-state.js.map +1 -1
  76. package/dist/backend/llvm/map-number-lookup.d.ts +3 -1
  77. package/dist/backend/llvm/map-number-lookup.js +7 -3
  78. package/dist/backend/llvm/map-number-lookup.js.map +1 -1
  79. package/dist/backend/llvm/map-number-lookup.test.js +52 -11
  80. package/dist/backend/llvm/map-number-lookup.test.js.map +1 -1
  81. package/dist/backend/llvm/receiver-brackets.test.d.ts +1 -0
  82. package/dist/backend/llvm/receiver-brackets.test.js +68 -0
  83. package/dist/backend/llvm/receiver-brackets.test.js.map +1 -0
  84. package/dist/backend/llvm/record-views.d.ts +22 -2
  85. package/dist/backend/llvm/record-views.js +139 -10
  86. package/dist/backend/llvm/record-views.js.map +1 -1
  87. package/dist/backend/llvm/record-views.test.js +76 -0
  88. package/dist/backend/llvm/record-views.test.js.map +1 -1
  89. package/dist/backend/llvm/reference-writes.js +1 -0
  90. package/dist/backend/llvm/reference-writes.js.map +1 -1
  91. package/dist/backend/llvm/shapes.d.ts +3 -0
  92. package/dist/backend/llvm/shapes.js +18 -3
  93. package/dist/backend/llvm/shapes.js.map +1 -1
  94. package/dist/backend/llvm/shapes.test.js +4 -0
  95. package/dist/backend/llvm/shapes.test.js.map +1 -1
  96. package/dist/backend/llvm/speculative-integers.d.ts +10 -1
  97. package/dist/backend/llvm/speculative-integers.js +59 -8
  98. package/dist/backend/llvm/speculative-integers.js.map +1 -1
  99. package/dist/backend/llvm/unwind-abi.d.ts +3 -3
  100. package/dist/backend/llvm/unwind-abi.js +8 -3
  101. package/dist/backend/llvm/unwind-abi.js.map +1 -1
  102. package/dist/backend/llvm/walkers.js +1 -1
  103. package/dist/backend/llvm/walkers.js.map +1 -1
  104. package/dist/backend/native/contracts.d.ts +54 -0
  105. package/dist/backend/native/executable.js +87 -5
  106. package/dist/backend/native/executable.js.map +1 -1
  107. package/dist/backend/native/library.js +1 -1
  108. package/dist/backend/native/library.js.map +1 -1
  109. package/dist/backend/native/runtime-inputs.js +5 -1
  110. package/dist/backend/native/runtime-inputs.js.map +1 -1
  111. package/dist/backend/native/vendor.d.ts +1 -1
  112. package/dist/backend/native/vendor.js +1 -1
  113. package/dist/backend/native/vendor.js.map +1 -1
  114. package/dist/backend/native-codegen.js +3 -0
  115. package/dist/backend/native-codegen.js.map +1 -1
  116. package/dist/backend/native-link-info-core.d.ts +43 -0
  117. package/dist/backend/native-link-info-core.js.map +1 -1
  118. package/dist/backend/native-link-info.js +1 -0
  119. package/dist/backend/native-link-info.js.map +1 -1
  120. package/dist/backend/native-profile.d.ts +4 -1
  121. package/dist/backend/native-profile.js +12 -1
  122. package/dist/backend/native-profile.js.map +1 -1
  123. package/dist/backend/native-profile.test.js +10 -0
  124. package/dist/backend/native-profile.test.js.map +1 -1
  125. package/dist/backend/publication.d.ts +4 -1
  126. package/dist/backend/publication.js +4 -2
  127. package/dist/backend/publication.js.map +1 -1
  128. package/dist/backend/runtime-abi.d.ts +2 -2
  129. package/dist/backend/runtime-abi.js +2 -2
  130. package/dist/backend/runtime-pack-core.d.ts +31 -7
  131. package/dist/backend/runtime-pack-core.js +21 -1
  132. package/dist/backend/runtime-pack-core.js.map +1 -1
  133. package/dist/backend/runtime-pack-native.d.ts +18 -1
  134. package/dist/backend/runtime-pack-native.js +138 -29
  135. package/dist/backend/runtime-pack-native.js.map +1 -1
  136. package/dist/backend/runtime-pack-native.test.js +166 -4
  137. package/dist/backend/runtime-pack-native.test.js.map +1 -1
  138. package/dist/backend/runtime-pack-targets.test.js +3 -1
  139. package/dist/backend/runtime-pack-targets.test.js.map +1 -1
  140. package/dist/backend/runtime-pack.d.ts +7 -0
  141. package/dist/backend/runtime-pack.js +25 -3
  142. package/dist/backend/runtime-pack.js.map +1 -1
  143. package/dist/backend/runtime-pack.test.js +3 -11
  144. package/dist/backend/runtime-pack.test.js.map +1 -1
  145. package/dist/backend/vendor-archives.d.ts +4 -1
  146. package/dist/backend/vendor-archives.js +264 -3
  147. package/dist/backend/vendor-archives.js.map +1 -1
  148. package/dist/backend/vendor-inputs.d.ts +36 -0
  149. package/dist/backend/vendor-inputs.js +42 -0
  150. package/dist/backend/vendor-inputs.js.map +1 -1
  151. package/dist/backend/vendor-inputs.test.js +28 -1
  152. package/dist/backend/vendor-inputs.test.js.map +1 -1
  153. package/dist/backend/warm-cache.js +2 -0
  154. package/dist/backend/warm-cache.js.map +1 -1
  155. package/dist/compat/fetch-profile.d.ts +7 -1
  156. package/dist/compat/fetch-profile.js +23 -10
  157. package/dist/compat/fetch-profile.js.map +1 -1
  158. package/dist/compile-types.d.ts +7 -0
  159. package/dist/contracts/check.d.ts +3 -0
  160. package/dist/contracts/check.js +18 -5
  161. package/dist/contracts/check.js.map +1 -1
  162. package/dist/coverage/surface-manifest.js +1 -1
  163. package/dist/coverage/surface-manifest.js.map +1 -1
  164. package/dist/diagnostics/codes.d.ts +6 -0
  165. package/dist/diagnostics/codes.js +6 -0
  166. package/dist/diagnostics/codes.js.map +1 -1
  167. package/dist/diagnostics/diagnostic.d.ts +50 -0
  168. package/dist/diagnostics/diagnostic.js +142 -3
  169. package/dist/diagnostics/diagnostic.js.map +1 -1
  170. package/dist/diagnostics/dynamic-tier.js +3 -1
  171. package/dist/diagnostics/dynamic-tier.js.map +1 -1
  172. package/dist/executable/executable-cache.d.ts +29 -0
  173. package/dist/executable/executable-cache.js +18 -0
  174. package/dist/executable/executable-cache.js.map +1 -1
  175. package/dist/executable/executable-cache.test.js +5 -1
  176. package/dist/executable/executable-cache.test.js.map +1 -1
  177. package/dist/executable/prepare.d.ts +13 -3
  178. package/dist/executable/prepare.js +271 -18
  179. package/dist/executable/prepare.js.map +1 -1
  180. package/dist/frontend/early-errors.d.ts +14 -0
  181. package/dist/frontend/early-errors.js +305 -0
  182. package/dist/frontend/early-errors.js.map +1 -0
  183. package/dist/frontend/early-errors.test.d.ts +1 -0
  184. package/dist/frontend/early-errors.test.js +42 -0
  185. package/dist/frontend/early-errors.test.js.map +1 -0
  186. package/dist/frontend/inferred-js-diagnostics.test.js +23 -0
  187. package/dist/frontend/inferred-js-diagnostics.test.js.map +1 -1
  188. package/dist/frontend/input-tracker.d.ts +47 -0
  189. package/dist/frontend/input-tracker.js +173 -36
  190. package/dist/frontend/input-tracker.js.map +1 -1
  191. package/dist/frontend/input-tracker.test.js +86 -2
  192. package/dist/frontend/input-tracker.test.js.map +1 -1
  193. package/dist/frontend/js-inference.d.ts +2 -0
  194. package/dist/frontend/js-inference.js +18 -0
  195. package/dist/frontend/js-inference.js.map +1 -0
  196. package/dist/frontend/lowering/binding-analysis.d.ts +2 -1
  197. package/dist/frontend/lowering/binding-analysis.js +65 -1
  198. package/dist/frontend/lowering/binding-analysis.js.map +1 -1
  199. package/dist/frontend/lowering/builtin-calls.js +9 -0
  200. package/dist/frontend/lowering/builtin-calls.js.map +1 -1
  201. package/dist/frontend/lowering/builtin-namespaces.d.ts +1 -1
  202. package/dist/frontend/lowering/builtin-namespaces.js +19 -2
  203. package/dist/frontend/lowering/builtin-namespaces.js.map +1 -1
  204. package/dist/frontend/lowering/builtins/child-process-methods.d.ts +7 -0
  205. package/dist/frontend/lowering/builtins/child-process-methods.js +50 -10
  206. package/dist/frontend/lowering/builtins/child-process-methods.js.map +1 -1
  207. package/dist/frontend/lowering/builtins/child-process.js +5 -1
  208. package/dist/frontend/lowering/builtins/child-process.js.map +1 -1
  209. package/dist/frontend/lowering/builtins/dates.d.ts +1 -1
  210. package/dist/frontend/lowering/builtins/dates.js +23 -1
  211. package/dist/frontend/lowering/builtins/dates.js.map +1 -1
  212. package/dist/frontend/lowering/builtins/environment.d.ts +55 -0
  213. package/dist/frontend/lowering/builtins/environment.js +213 -2
  214. package/dist/frontend/lowering/builtins/environment.js.map +1 -1
  215. package/dist/frontend/lowering/builtins/filesystem-calls.js +47 -16
  216. package/dist/frontend/lowering/builtins/filesystem-calls.js.map +1 -1
  217. package/dist/frontend/lowering/builtins/filesystem.d.ts +25 -7
  218. package/dist/frontend/lowering/builtins/filesystem.js +185 -16
  219. package/dist/frontend/lowering/builtins/filesystem.js.map +1 -1
  220. package/dist/frontend/lowering/builtins/module-calls.js +39 -2
  221. package/dist/frontend/lowering/builtins/module-calls.js.map +1 -1
  222. package/dist/frontend/lowering/builtins/module-resolution.d.ts +8 -0
  223. package/dist/frontend/lowering/builtins/module-resolution.js +31 -5
  224. package/dist/frontend/lowering/builtins/module-resolution.js.map +1 -1
  225. package/dist/frontend/lowering/builtins/operating-system.d.ts +3 -2
  226. package/dist/frontend/lowering/builtins/operating-system.js +5 -4
  227. package/dist/frontend/lowering/builtins/operating-system.js.map +1 -1
  228. package/dist/frontend/lowering/builtins/process.d.ts +17 -1
  229. package/dist/frontend/lowering/builtins/process.js +285 -19
  230. package/dist/frontend/lowering/builtins/process.js.map +1 -1
  231. package/dist/frontend/lowering/builtins/querystring.d.ts +8 -0
  232. package/dist/frontend/lowering/builtins/querystring.js +202 -18
  233. package/dist/frontend/lowering/builtins/querystring.js.map +1 -1
  234. package/dist/frontend/lowering/builtins/readline.js +21 -3
  235. package/dist/frontend/lowering/builtins/readline.js.map +1 -1
  236. package/dist/frontend/lowering/builtins/reflection.js +60 -1
  237. package/dist/frontend/lowering/builtins/reflection.js.map +1 -1
  238. package/dist/frontend/lowering/builtins/text-codecs.js +208 -59
  239. package/dist/frontend/lowering/builtins/text-codecs.js.map +1 -1
  240. package/dist/frontend/lowering/builtins/url.js +20 -1
  241. package/dist/frontend/lowering/builtins/url.js.map +1 -1
  242. package/dist/frontend/lowering/builtins/v8.d.ts +5 -5
  243. package/dist/frontend/lowering/builtins/v8.js +7 -5
  244. package/dist/frontend/lowering/builtins/v8.js.map +1 -1
  245. package/dist/frontend/lowering/builtins/web-streams-dyn.d.ts +17 -2
  246. package/dist/frontend/lowering/builtins/web-streams-dyn.js +97 -9
  247. package/dist/frontend/lowering/builtins/web-streams-dyn.js.map +1 -1
  248. package/dist/frontend/lowering/call-signatures.js +77 -0
  249. package/dist/frontend/lowering/call-signatures.js.map +1 -1
  250. package/dist/frontend/lowering/cjs-exports-object.d.ts +3 -0
  251. package/dist/frontend/lowering/cjs-exports-object.js +1 -1
  252. package/dist/frontend/lowering/cjs-exports-object.js.map +1 -1
  253. package/dist/frontend/lowering/cjs-inline-require.js +5 -0
  254. package/dist/frontend/lowering/cjs-inline-require.js.map +1 -1
  255. package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +5 -0
  256. package/dist/frontend/lowering/class-dynamic-dispatch.js +114 -0
  257. package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
  258. package/dist/frontend/lowering/class-protocols.js +59 -10
  259. package/dist/frontend/lowering/class-protocols.js.map +1 -1
  260. package/dist/frontend/lowering/class-runtime-statics.js +15 -0
  261. package/dist/frontend/lowering/class-runtime-statics.js.map +1 -1
  262. package/dist/frontend/lowering/class-views.d.ts +13 -0
  263. package/dist/frontend/lowering/class-views.js +51 -0
  264. package/dist/frontend/lowering/class-views.js.map +1 -0
  265. package/dist/frontend/lowering/coercions/function-adapters.d.ts +15 -1
  266. package/dist/frontend/lowering/coercions/function-adapters.js +54 -10
  267. package/dist/frontend/lowering/coercions/function-adapters.js.map +1 -1
  268. package/dist/frontend/lowering/coercions/state.d.ts +7 -0
  269. package/dist/frontend/lowering/coercions/state.js +7 -0
  270. package/dist/frontend/lowering/coercions/state.js.map +1 -1
  271. package/dist/frontend/lowering/coercions/structural-plans.js +60 -3
  272. package/dist/frontend/lowering/coercions/structural-plans.js.map +1 -1
  273. package/dist/frontend/lowering/coercions/structural.js +29 -1
  274. package/dist/frontend/lowering/coercions/structural.js.map +1 -1
  275. package/dist/frontend/lowering/containers/array-callbacks.d.ts +8 -1
  276. package/dist/frontend/lowering/containers/array-callbacks.js +132 -28
  277. package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
  278. package/dist/frontend/lowering/containers/array-construction.js +16 -5
  279. package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
  280. package/dist/frontend/lowering/containers/array-methods.js +16 -0
  281. package/dist/frontend/lowering/containers/array-methods.js.map +1 -1
  282. package/dist/frontend/lowering/containers/bytes.js +4 -0
  283. package/dist/frontend/lowering/containers/bytes.js.map +1 -1
  284. package/dist/frontend/lowering/containers/callback-arguments.d.ts +11 -0
  285. package/dist/frontend/lowering/containers/callback-arguments.js +53 -0
  286. package/dist/frontend/lowering/containers/callback-arguments.js.map +1 -1
  287. package/dist/frontend/lowering/containers/filter-predicates.d.ts +10 -0
  288. package/dist/frontend/lowering/containers/filter-predicates.js +69 -3
  289. package/dist/frontend/lowering/containers/filter-predicates.js.map +1 -1
  290. package/dist/frontend/lowering/containers/indexed-objects.js +46 -2
  291. package/dist/frontend/lowering/containers/indexed-objects.js.map +1 -1
  292. package/dist/frontend/lowering/expressions/array-literals.d.ts +14 -0
  293. package/dist/frontend/lowering/expressions/array-literals.js +26 -10
  294. package/dist/frontend/lowering/expressions/array-literals.js.map +1 -1
  295. package/dist/frontend/lowering/expressions/binary.js +104 -12
  296. package/dist/frontend/lowering/expressions/binary.js.map +1 -1
  297. package/dist/frontend/lowering/expressions/element-access.js +121 -4
  298. package/dist/frontend/lowering/expressions/element-access.js.map +1 -1
  299. package/dist/frontend/lowering/expressions/identifiers.js +143 -3
  300. package/dist/frontend/lowering/expressions/identifiers.js.map +1 -1
  301. package/dist/frontend/lowering/expressions/keyed-field-targets.d.ts +11 -1
  302. package/dist/frontend/lowering/expressions/keyed-field-targets.js +22 -1
  303. package/dist/frontend/lowering/expressions/keyed-field-targets.js.map +1 -1
  304. package/dist/frontend/lowering/expressions/narrowing.js +25 -1
  305. package/dist/frontend/lowering/expressions/narrowing.js.map +1 -1
  306. package/dist/frontend/lowering/expressions/object-literals.d.ts +5 -1
  307. package/dist/frontend/lowering/expressions/object-literals.js +778 -229
  308. package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
  309. package/dist/frontend/lowering/expressions/optional-chains.js +66 -20
  310. package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
  311. package/dist/frontend/lowering/expressions/property-access.d.ts +31 -0
  312. package/dist/frontend/lowering/expressions/property-access.js +796 -12
  313. package/dist/frontend/lowering/expressions/property-access.js.map +1 -1
  314. package/dist/frontend/lowering/expressions/relational.js +29 -1
  315. package/dist/frontend/lowering/expressions/relational.js.map +1 -1
  316. package/dist/frontend/lowering/expressions/typeof.js +17 -0
  317. package/dist/frontend/lowering/expressions/typeof.js.map +1 -1
  318. package/dist/frontend/lowering/expressions/updates.js +132 -17
  319. package/dist/frontend/lowering/expressions/updates.js.map +1 -1
  320. package/dist/frontend/lowering/frozen-records.d.ts +6 -0
  321. package/dist/frontend/lowering/frozen-records.js +10 -4
  322. package/dist/frontend/lowering/frozen-records.js.map +1 -1
  323. package/dist/frontend/lowering/frozen-records.test.d.ts +1 -0
  324. package/dist/frontend/lowering/frozen-records.test.js +44 -0
  325. package/dist/frontend/lowering/frozen-records.test.js.map +1 -0
  326. package/dist/frontend/lowering/function-names.d.ts +9 -0
  327. package/dist/frontend/lowering/function-names.js +95 -0
  328. package/dist/frontend/lowering/function-names.js.map +1 -0
  329. package/dist/frontend/lowering/function-returns.js +5 -3
  330. package/dist/frontend/lowering/function-returns.js.map +1 -1
  331. package/dist/frontend/lowering/generic-functions.d.ts +49 -0
  332. package/dist/frontend/lowering/generic-functions.js +365 -7
  333. package/dist/frontend/lowering/generic-functions.js.map +1 -1
  334. package/dist/frontend/lowering/global-values.d.ts +9 -0
  335. package/dist/frontend/lowering/global-values.js +44 -0
  336. package/dist/frontend/lowering/global-values.js.map +1 -1
  337. package/dist/frontend/lowering/handle-properties.js +34 -1
  338. package/dist/frontend/lowering/handle-properties.js.map +1 -1
  339. package/dist/frontend/lowering/key-order-witness.d.ts +54 -0
  340. package/dist/frontend/lowering/key-order-witness.js +546 -5
  341. package/dist/frontend/lowering/key-order-witness.js.map +1 -1
  342. package/dist/frontend/lowering/lib-boundary.js +14 -0
  343. package/dist/frontend/lowering/lib-boundary.js.map +1 -1
  344. package/dist/frontend/lowering/lower-assert.js +110 -1
  345. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  346. package/dist/frontend/lowering/lower-builtin-values.d.ts +36 -6
  347. package/dist/frontend/lowering/lower-builtin-values.js +332 -58
  348. package/dist/frontend/lowering/lower-builtin-values.js.map +1 -1
  349. package/dist/frontend/lowering/lower-calls.d.ts +22 -1
  350. package/dist/frontend/lowering/lower-calls.js +427 -48
  351. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  352. package/dist/frontend/lowering/lower-calls.test.d.ts +1 -0
  353. package/dist/frontend/lowering/lower-calls.test.js +78 -0
  354. package/dist/frontend/lowering/lower-calls.test.js.map +1 -0
  355. package/dist/frontend/lowering/lower-classes.d.ts +16 -5
  356. package/dist/frontend/lowering/lower-classes.js +168 -51
  357. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  358. package/dist/frontend/lowering/lower-event-emitter.d.ts +9 -0
  359. package/dist/frontend/lowering/lower-event-emitter.js +383 -41
  360. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
  361. package/dist/frontend/lowering/lower-exprs.d.ts +14 -0
  362. package/dist/frontend/lowering/lower-exprs.js +25 -0
  363. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  364. package/dist/frontend/lowering/lower-functions.js +2 -0
  365. package/dist/frontend/lowering/lower-functions.js.map +1 -1
  366. package/dist/frontend/lowering/lower-inspect.js +80 -33
  367. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  368. package/dist/frontend/lowering/lower-modules.js +87 -25
  369. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  370. package/dist/frontend/lowering/lower-node-island.d.ts +35 -4
  371. package/dist/frontend/lowering/lower-node-island.js +456 -61
  372. package/dist/frontend/lowering/lower-node-island.js.map +1 -1
  373. package/dist/frontend/lowering/lower-server.js +160 -9
  374. package/dist/frontend/lowering/lower-server.js.map +1 -1
  375. package/dist/frontend/lowering/lower-shared-modules.js +13 -1
  376. package/dist/frontend/lowering/lower-shared-modules.js.map +1 -1
  377. package/dist/frontend/lowering/lower-stdlib.d.ts +3 -2
  378. package/dist/frontend/lowering/lower-stdlib.js +32 -18
  379. package/dist/frontend/lowering/lower-stdlib.js.map +1 -1
  380. package/dist/frontend/lowering/lower-stmts.d.ts +21 -4
  381. package/dist/frontend/lowering/lower-stmts.js +580 -103
  382. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  383. package/dist/frontend/lowering/lower-stream.js +126 -8
  384. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  385. package/dist/frontend/lowering/lower-timers.js +133 -21
  386. package/dist/frontend/lowering/lower-timers.js.map +1 -1
  387. package/dist/frontend/lowering/lowerer.d.ts +139 -3
  388. package/dist/frontend/lowering/lowerer.js +579 -43
  389. package/dist/frontend/lowering/lowerer.js.map +1 -1
  390. package/dist/frontend/lowering/lowerer.test.js +1 -1
  391. package/dist/frontend/lowering/lowerer.test.js.map +1 -1
  392. package/dist/frontend/lowering/module-namespace-elements.js +15 -0
  393. package/dist/frontend/lowering/module-namespace-elements.js.map +1 -1
  394. package/dist/frontend/lowering/new-target.js +2 -2
  395. package/dist/frontend/lowering/nullish-empty-pattern.d.ts +17 -0
  396. package/dist/frontend/lowering/nullish-empty-pattern.js +118 -0
  397. package/dist/frontend/lowering/nullish-empty-pattern.js.map +1 -0
  398. package/dist/frontend/lowering/partial-assertions.d.ts +39 -0
  399. package/dist/frontend/lowering/partial-assertions.js +195 -0
  400. package/dist/frontend/lowering/partial-assertions.js.map +1 -0
  401. package/dist/frontend/lowering/primitive-wrappers.d.ts +34 -0
  402. package/dist/frontend/lowering/primitive-wrappers.js +220 -0
  403. package/dist/frontend/lowering/primitive-wrappers.js.map +1 -0
  404. package/dist/frontend/lowering/private-statics.d.ts +46 -0
  405. package/dist/frontend/lowering/private-statics.js +322 -0
  406. package/dist/frontend/lowering/private-statics.js.map +1 -0
  407. package/dist/frontend/lowering/record-sources.d.ts +12 -1
  408. package/dist/frontend/lowering/record-sources.js +60 -0
  409. package/dist/frontend/lowering/record-sources.js.map +1 -1
  410. package/dist/frontend/lowering/strict-equality.d.ts +4 -0
  411. package/dist/frontend/lowering/strict-equality.js +14 -0
  412. package/dist/frontend/lowering/strict-equality.js.map +1 -1
  413. package/dist/frontend/lowering/surfaces.d.ts +27 -0
  414. package/dist/frontend/lowering/surfaces.js +135 -62
  415. package/dist/frontend/lowering/surfaces.js.map +1 -1
  416. package/dist/frontend/lowering/unit-journal.d.ts +128 -17
  417. package/dist/frontend/lowering/unit-journal.js +310 -53
  418. package/dist/frontend/lowering/unit-journal.js.map +1 -1
  419. package/dist/frontend/lowering/unit-journal.test.js +91 -3
  420. package/dist/frontend/lowering/unit-journal.test.js.map +1 -1
  421. package/dist/frontend/lowering/unit-reuse.d.ts +92 -0
  422. package/dist/frontend/lowering/unit-reuse.js +1008 -0
  423. package/dist/frontend/lowering/unit-reuse.js.map +1 -0
  424. package/dist/frontend/lowering/width-lift.d.ts +12 -0
  425. package/dist/frontend/npm-file-import.test.d.ts +1 -0
  426. package/dist/frontend/npm-file-import.test.js +76 -0
  427. package/dist/frontend/npm-file-import.test.js.map +1 -0
  428. package/dist/frontend/npm-static.js +17 -2
  429. package/dist/frontend/npm-static.js.map +1 -1
  430. package/dist/frontend/npm.d.ts +9 -0
  431. package/dist/frontend/npm.js +82 -0
  432. package/dist/frontend/npm.js.map +1 -1
  433. package/dist/frontend/pipeline-native.js +2 -1
  434. package/dist/frontend/pipeline-native.js.map +1 -1
  435. package/dist/frontend/pipeline.d.ts +4 -0
  436. package/dist/frontend/pipeline.js +68 -7
  437. package/dist/frontend/pipeline.js.map +1 -1
  438. package/dist/frontend/program-node.d.ts +3 -0
  439. package/dist/frontend/program-node.js +13 -6
  440. package/dist/frontend/program-node.js.map +1 -1
  441. package/dist/frontend/program.d.ts +9 -0
  442. package/dist/frontend/program.js +159 -7
  443. package/dist/frontend/program.js.map +1 -1
  444. package/dist/frontend/provenance-core.js +4 -0
  445. package/dist/frontend/provenance-core.js.map +1 -1
  446. package/dist/frontend/services.d.ts +14 -0
  447. package/dist/frontend/services.js +52 -2
  448. package/dist/frontend/services.js.map +1 -1
  449. package/dist/frontend/services.test.js +61 -1
  450. package/dist/frontend/services.test.js.map +1 -1
  451. package/dist/frontend/shape-inference/analyze.d.ts +5 -0
  452. package/dist/frontend/shape-inference/analyze.js +104 -4
  453. package/dist/frontend/shape-inference/analyze.js.map +1 -1
  454. package/dist/frontend/shape-inference/domain.js +0 -1
  455. package/dist/frontend/shape-inference/domain.js.map +1 -1
  456. package/dist/frontend/shape-inference/index.js +5 -1
  457. package/dist/frontend/shape-inference/index.js.map +1 -1
  458. package/dist/frontend/shape-inference/memo.d.ts +2 -1
  459. package/dist/frontend/shape-inference/memo.js +6 -2
  460. package/dist/frontend/shape-inference/memo.js.map +1 -1
  461. package/dist/frontend/shape-inference/overlay.d.ts +1 -1
  462. package/dist/frontend/shape-inference/overlay.js +116 -2
  463. package/dist/frontend/shape-inference/overlay.js.map +1 -1
  464. package/dist/frontend/shape-inference/static-objects.js +11 -6
  465. package/dist/frontend/shape-inference/static-objects.js.map +1 -1
  466. package/dist/frontend/source-phase-imports.test.d.ts +1 -0
  467. package/dist/frontend/source-phase-imports.test.js +37 -0
  468. package/dist/frontend/source-phase-imports.test.js.map +1 -0
  469. package/dist/frontend/ts7/ast-node.d.ts +6 -1
  470. package/dist/frontend/ts7/ast-node.js +12 -0
  471. package/dist/frontend/ts7/ast-node.js.map +1 -1
  472. package/dist/frontend/ts7/ast-wire-protocols.test.js +11 -3
  473. package/dist/frontend/ts7/ast-wire-protocols.test.js.map +1 -1
  474. package/dist/frontend/ts7/ast-wire.js +3 -5
  475. package/dist/frontend/ts7/ast-wire.js.map +1 -1
  476. package/dist/frontend/ts7/checker-backend.d.ts +13 -0
  477. package/dist/frontend/ts7/checker-backend.js +84 -2
  478. package/dist/frontend/ts7/checker-backend.js.map +1 -1
  479. package/dist/frontend/ts7/checker-backend.test.js +126 -2
  480. package/dist/frontend/ts7/checker-backend.test.js.map +1 -1
  481. package/dist/frontend/ts7/program-host.d.ts +22 -1
  482. package/dist/frontend/ts7/program-host.js +49 -4
  483. package/dist/frontend/ts7/program-host.js.map +1 -1
  484. package/dist/frontend/ts7/program-host.test.js +83 -0
  485. package/dist/frontend/ts7/program-host.test.js.map +1 -1
  486. package/dist/frontend/ts7/rpc-process.d.ts +16 -1
  487. package/dist/frontend/ts7/rpc-process.js +170 -92
  488. package/dist/frontend/ts7/rpc-process.js.map +1 -1
  489. package/dist/frontend/ts7/rpc-process.test.js +49 -21
  490. package/dist/frontend/ts7/rpc-process.test.js.map +1 -1
  491. package/dist/frontend/tsc-codes.js +70 -0
  492. package/dist/frontend/tsc-codes.js.map +1 -1
  493. package/dist/frontend/type-mapper.d.ts +7 -2
  494. package/dist/frontend/type-mapper.js +148 -1
  495. package/dist/frontend/type-mapper.js.map +1 -1
  496. package/dist/index.d.ts +1 -1
  497. package/dist/index.js +152 -8
  498. package/dist/index.js.map +1 -1
  499. package/dist/ir/api.d.ts +1 -1
  500. package/dist/ir/api.js +1 -1
  501. package/dist/ir/api.js.map +1 -1
  502. package/dist/ir/build.d.ts +3 -2
  503. package/dist/ir/build.js +4 -2
  504. package/dist/ir/build.js.map +1 -1
  505. package/dist/ir/builtin-effects.js +53 -0
  506. package/dist/ir/builtin-effects.js.map +1 -1
  507. package/dist/ir/builtin-signatures.d.ts +1 -1
  508. package/dist/ir/builtin-signatures.js +211 -10
  509. package/dist/ir/builtin-signatures.js.map +1 -1
  510. package/dist/ir/codec.d.ts +82 -0
  511. package/dist/ir/codec.generated.d.ts +13 -0
  512. package/dist/ir/codec.generated.js +5274 -0
  513. package/dist/ir/codec.generated.js.map +1 -0
  514. package/dist/ir/codec.js +325 -0
  515. package/dist/ir/codec.js.map +1 -0
  516. package/dist/ir/codec.test.d.ts +1 -0
  517. package/dist/ir/codec.test.js +225 -0
  518. package/dist/ir/codec.test.js.map +1 -0
  519. package/dist/ir/fields.generated.d.ts +20 -10
  520. package/dist/ir/fields.generated.js +1031 -11
  521. package/dist/ir/fields.generated.js.map +1 -1
  522. package/dist/ir/fields.test.js +46 -2
  523. package/dist/ir/fields.test.js.map +1 -1
  524. package/dist/ir/function-references.d.ts +5 -4
  525. package/dist/ir/function-references.js +8 -4
  526. package/dist/ir/function-references.js.map +1 -1
  527. package/dist/ir/function-references.test.js +7 -0
  528. package/dist/ir/function-references.test.js.map +1 -1
  529. package/dist/ir/inline-array-sources.js +4 -1
  530. package/dist/ir/inline-array-sources.js.map +1 -1
  531. package/dist/ir/inline-array-views.d.ts +13 -0
  532. package/dist/ir/inline-array-views.js +944 -0
  533. package/dist/ir/inline-array-views.js.map +1 -0
  534. package/dist/ir/inline-arrays.d.ts +7 -0
  535. package/dist/ir/inline-arrays.js +190 -55
  536. package/dist/ir/inline-arrays.js.map +1 -1
  537. package/dist/ir/inline-arrays.test.js +140 -2
  538. package/dist/ir/inline-arrays.test.js.map +1 -1
  539. package/dist/ir/integer-ranges.js +16 -6
  540. package/dist/ir/integer-ranges.js.map +1 -1
  541. package/dist/ir/ir.d.ts +75 -44
  542. package/dist/ir/ir.js.map +1 -1
  543. package/dist/ir/js-ic.d.ts +10 -9
  544. package/dist/ir/js-ic.js +28 -20
  545. package/dist/ir/js-ic.js.map +1 -1
  546. package/dist/ir/js-ic.test.js +10 -2
  547. package/dist/ir/js-ic.test.js.map +1 -1
  548. package/dist/ir/jsval.js +374 -63
  549. package/dist/ir/jsval.js.map +1 -1
  550. package/dist/ir/jsval.test.js +96 -2
  551. package/dist/ir/jsval.test.js.map +1 -1
  552. package/dist/ir/loop-entry-ranges.js +112 -9
  553. package/dist/ir/loop-entry-ranges.js.map +1 -1
  554. package/dist/ir/loop-entry-ranges.test.js +40 -0
  555. package/dist/ir/loop-entry-ranges.test.js.map +1 -1
  556. package/dist/ir/parameter-versions.d.ts +2 -1
  557. package/dist/ir/parameter-versions.js +3 -1
  558. package/dist/ir/parameter-versions.js.map +1 -1
  559. package/dist/ir/receiver-readers.js +58 -2
  560. package/dist/ir/receiver-readers.js.map +1 -1
  561. package/dist/ir/runtime-features.d.ts +60 -1
  562. package/dist/ir/runtime-features.js +277 -2
  563. package/dist/ir/runtime-features.js.map +1 -1
  564. package/dist/ir/runtime-features.test.js +165 -1
  565. package/dist/ir/runtime-features.test.js.map +1 -1
  566. package/dist/ir/saturating-loop-jams.d.ts +8 -1
  567. package/dist/ir/saturating-loop-jams.js +46 -7
  568. package/dist/ir/saturating-loop-jams.js.map +1 -1
  569. package/dist/ir/saturating-loop-jams.test.js +39 -1
  570. package/dist/ir/saturating-loop-jams.test.js.map +1 -1
  571. package/dist/ir/self-captures.js +8 -1
  572. package/dist/ir/self-captures.js.map +1 -1
  573. package/dist/ir/self-captures.test.js +15 -0
  574. package/dist/ir/self-captures.test.js.map +1 -1
  575. package/dist/ir/serialize.d.ts +3 -2
  576. package/dist/ir/serialize.js +6 -2
  577. package/dist/ir/serialize.js.map +1 -1
  578. package/dist/ir/validate.js +82 -4
  579. package/dist/ir/validate.js.map +1 -1
  580. package/dist/ir/validate.test.js +46 -0
  581. package/dist/ir/validate.test.js.map +1 -1
  582. package/dist/library/ir-policy.js +3 -0
  583. package/dist/library/ir-policy.js.map +1 -1
  584. package/dist/native/cache.js +2 -0
  585. package/dist/native/cache.js.map +1 -1
  586. package/dist/native/cli.js +2 -0
  587. package/dist/native/cli.js.map +1 -1
  588. package/dist/native/compiler.js +8 -2
  589. package/dist/native/compiler.js.map +1 -1
  590. package/dist/native/prepare.js +32 -3
  591. package/dist/native/prepare.js.map +1 -1
  592. package/dist/native/sanitizer.js +53 -3
  593. package/dist/native/sanitizer.js.map +1 -1
  594. package/dist/native/sanitizer.test.js +88 -2
  595. package/dist/native/sanitizer.test.js.map +1 -1
  596. package/dist/native/toolchain.js +9 -2
  597. package/dist/native/toolchain.js.map +1 -1
  598. package/dist/node-islands/boundary.d.ts +25 -1
  599. package/dist/node-islands/boundary.js +28 -2
  600. package/dist/node-islands/boundary.js.map +1 -1
  601. package/dist/node-islands/detect.d.ts +18 -1
  602. package/dist/node-islands/detect.js +365 -40
  603. package/dist/node-islands/detect.js.map +1 -1
  604. package/dist/node-islands/detect.test.js +151 -4
  605. package/dist/node-islands/detect.test.js.map +1 -1
  606. package/dist/node-islands/effect-gate.js +30 -20
  607. package/dist/node-islands/effect-gate.js.map +1 -1
  608. package/dist/node-islands/effect-gate.test.js +4 -1
  609. package/dist/node-islands/effect-gate.test.js.map +1 -1
  610. package/dist/node-islands/libnode.d.ts +1 -1
  611. package/dist/node-islands/libnode.js +1 -1
  612. package/dist/node-islands/libnode.js.map +1 -1
  613. package/dist/node-islands/modules.d.ts +28 -0
  614. package/dist/node-islands/modules.js +156 -0
  615. package/dist/node-islands/modules.js.map +1 -1
  616. package/dist/node-islands/modules.test.js +105 -1
  617. package/dist/node-islands/modules.test.js.map +1 -1
  618. package/dist/node-islands/policy.js +2 -3
  619. package/dist/node-islands/policy.js.map +1 -1
  620. package/dist/node-islands/probe-recorder.d.ts +1 -0
  621. package/dist/node-islands/probe-recorder.js +596 -0
  622. package/dist/node-islands/probe-recorder.js.map +1 -0
  623. package/dist/node-islands/probe-recorder.test.d.ts +1 -0
  624. package/dist/node-islands/probe-recorder.test.js +80 -0
  625. package/dist/node-islands/probe-recorder.test.js.map +1 -0
  626. package/dist/node-islands/report.test.js +2 -0
  627. package/dist/node-islands/report.test.js.map +1 -1
  628. package/dist/node-islands/rules.js +4 -0
  629. package/dist/node-islands/rules.js.map +1 -1
  630. package/dist/node-islands/scan.d.ts +7 -1
  631. package/dist/node-islands/scan.js +51 -2
  632. package/dist/node-islands/scan.js.map +1 -1
  633. package/dist/node-islands/snapshot.d.ts +38 -1
  634. package/dist/node-islands/snapshot.js +165 -161
  635. package/dist/node-islands/snapshot.js.map +1 -1
  636. package/dist/node-islands/snapshot.test.js +63 -2
  637. package/dist/node-islands/snapshot.test.js.map +1 -1
  638. package/dist/node-islands/summary.js +8 -0
  639. package/dist/node-islands/summary.js.map +1 -1
  640. package/dist/node-islands/type-strip.d.ts +11 -0
  641. package/dist/node-islands/type-strip.js +157 -0
  642. package/dist/node-islands/type-strip.js.map +1 -0
  643. package/dist/node-islands/type-strip.test.d.ts +1 -0
  644. package/dist/node-islands/type-strip.test.js +31 -0
  645. package/dist/node-islands/type-strip.test.js.map +1 -0
  646. package/dist/project-config.d.ts +4 -0
  647. package/dist/project-config.js +19 -0
  648. package/dist/project-config.js.map +1 -1
  649. package/dist/project-config.test.js +10 -0
  650. package/dist/project-config.test.js.map +1 -1
  651. package/package.json +20 -20
  652. package/surface-manifest.json +43 -11
@@ -1,3 +1,4 @@
1
+ import { programCreatesWrappers, routeWrapperConsumers } from "./primitive-wrappers.js";
1
2
  import { markInferredFactChecks, shapeOverlayFileNames } from "../shape-inference/index.js";
2
3
  import { npmStaticPackageOfPath } from "../npm-static.js";
3
4
  import { globalMemberValue } from "./global-values.js";
@@ -8,7 +9,8 @@ import { Normalizer } from "../canon.js";
8
9
  import { compactDeclOrigins, inPackageFile, recordOrigin, slotOrigin, } from "./decl-origin.js";
9
10
  import { isDeclBoundaryFile } from "../decl-projection.js";
10
11
  import { relieveHeapPressure } from "../../heap-pressure.js";
11
- import { checkedTable, countTable, fixedScalar, flagScalar, functionTable, irDataTable, journalDump, journalMode, lowerWaveRecorded, mapTable, setTable, waveStats, writeRecords, } from "./unit-journal.js";
12
+ import { checkedTable, countTable, fixedScalar, flagScalar, functionTable, irDataTable, journalDump, journalMode, HeldTables, lowerWaveRecorded, mapTable, setTable, waveStats, writeRecords, } from "./unit-journal.js";
13
+ import { UnitReuse, unitReuseVerify, verifyStoredUnit } from "./unit-reuse.js";
12
14
  import { moduleNamespaceDynValue, moduleNamespaceObject, moduleNamespaceValue, } from "./module-namespace-elements.js";
13
15
  import { keyedHelperName, moduleTagNumber, portableRelativePath } from "./stable-names.js";
14
16
  import { positionTag, StructuralPositions } from "./structural-positions.js";
@@ -30,11 +32,12 @@ import { checkRequireBindingAccesses, } from "./require-initialization.js";
30
32
  import { identityPreservingWidening } from "./coercions/identity.js";
31
33
  import { scanDivergences } from "./divergences.js";
32
34
  import { applyKeyOrderWitnesses, KeyOrderNotes } from "./key-order-witness.js";
35
+ import { functionKeepsRecordSources } from "./record-sources.js";
33
36
  import { exprFunctionReference } from "../../ir/function-references.js";
34
37
  import { everyStmtList, observeRecordLiteralRebuilds } from "../../ir/traverse.js";
35
38
  import { checkedClassAssertion } from "./class-assertions.js";
36
39
  import { narrowStoredClassValue, narrowGenericClassValue } from "./class-unions.js";
37
- import { isOptionalProcessStreamProperty, isOptionalProcessVersionsRead, } from "./builtins/process.js";
40
+ import { isOptionalProcessStreamProperty, isOptionalProcessVersionsRead, programPatchesStdio, } from "./builtins/process.js";
38
41
  import { isSettledIteratorValueRead } from "./lower-generators.js";
39
42
  import { isRebindableFunctionSymbol } from "./rebindable-functions.js";
40
43
  import { concreteCollectionNarrow } from "./collection-narrowing.js";
@@ -63,7 +66,7 @@ import { widthCoerce, applyWidthLift, unionRecordWidthHelper, unionArrayWidthHel
63
66
  import { funcReturnWidthAdapter, coercibleValue, cleanFuncAdaptable, funcCoerceAdapter, spawnResFnAdapterPlan, spawnResFnAdapter, } from "./coercions/function-adapters.js";
64
67
  import { unionRetagMappable, narrowedRetagHelper, uninhabitedArmRetagHelper, strandedUnitTrap, strandedCoercionTrap, recordUnionRouteHelper, recordUnionWrapHelper, unionRetagHelper, narrowedArmHelper, checkedNarrowCall, checkedNarrowOperand, deferredReadHelper, widthNarrowHelper, } from "./coercions/unions.js";
65
68
  import { assertedConversion } from "./coercions/asserted.js";
66
- import { lowerUtilTypeValue, pathModuleValue, utilTypesModuleValue, } from "./lower-builtin-values.js";
69
+ import { boxBuiltinValuesChecked, lowerUtilTypeValue, checkedNativeCallableValue, pathModuleValue, utilTypesModuleValue, } from "./lower-builtin-values.js";
67
70
  import { devirtualizeVirtualCalls } from "./devirtualize.js";
68
71
  import { foldRegexSpanReads } from "./regex-span-reads.js";
69
72
  import { RuntimeOptionalProvenance } from "./runtime-optional-provenance.js";
@@ -102,6 +105,7 @@ import { analyzeTiers, dynamicStatementCount, } from "../tier-analysis.js";
102
105
  import { DeferredModuleInitializers } from "./deferred-module-initializers.js";
103
106
  import { finalizeClassMethodValues } from "./class-method-values.js";
104
107
  import { finalizePrivateBrands } from "./private-brands.js";
108
+ import { finalizeFunctionNames } from "./function-names.js";
105
109
  import { INSPECT_CUSTOM_MEMBER, tableKeyFieldType } from "./symbol-fields.js";
106
110
  export { newFnCtx } from "./function-context.js";
107
111
  /* AST + checker → IR.
@@ -131,7 +135,7 @@ import { dynamicSlotDiag } from "../../diagnostics/dynamic-slots.js";
131
135
  import { unsupportedAnyOperationDiag, blockedBindingUseDiag, checkerPanicDiag, componentTypeDiag, isCheckerPanic, genericSignatureTypeDiag, indexSignatureTypeDiag, intersectionTypeDiag, noLoweringDiag, overloadedSignatureTypeDiag, recordShapeMismatchDiag, stdlibSnapshotValueUseDiag, unsupportedNativeApiDiag, unsupportedPackageValueDiag, unionMismatchDiag, UNSUPPORTED, unsupportedDiag, unsupportedTypeDiag, } from "../../diagnostics/diagnostic.js";
132
136
  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";
133
137
  import { provenanceActive } from "../provenance-registry.js";
134
- import { ambientDtsPath, canonicalBuiltinModule, cjsExportAssignmentOf, cjsExportDiscardReason, cjsExportsAssignedInFunctions, cjsReexportedModules, cjsNamespaceExportNames, isCheckedJsSourceFile, isCjsExportTableLiteral, isCjsJsFile, isJsSourceFile, isNodeEsmFile, isFallbackDtsPath, isNodeTypesPath, locOf, orderedImportsOf, overridesDtsPath, npmStaticDepSf7, requireSpecOf, resolveImport, workspacePackageOfPath, } from "../program.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";
135
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";
136
140
  import { builtinConstLit, builtinModuleConstOf, builtinModulesArrayLit, builtinFenceHintOf, builtinModuleFnOf, stdlibMemberFence, isStdlibMember, isStdlibSymbol, isStdlibGlobal, stdlibGlobalNameOf, stdlibGlobalMember, nodeTypesOnlySymbol, } from "./surfaces.js";
137
141
  import { builtinClassAliasOf, runtimeClassValueOfType, } from "./builtins/class-values.js";
@@ -146,7 +150,7 @@ import { mixinCallClassInfoOf, mixinIntersectionInstanceType, } from "./lower-mi
146
150
  import { tryLowerExpression } from "./expressions/try-lower-expression.js";
147
151
  import { funcTypeFromParamShapes, isThisParameter, paramShape, paramShapes, checkDefaultParamBodyType, requireExactArityValue, collectSignature, collectSignatureInner, lambdaSignature, } from "./call-signatures.js";
148
152
  import { dynamicOverloadChoice, guessedOverloadIdentifier } from "./overload-choice.js";
149
- import { implicitAnyParamSymbolsOf, implicitLocalFnNodeOf, implicitMonoFile, collectGenericSignature, genericFnOf, lowerGenericCall, lowerGenericFnValue, inferTypeParamBindings, lowerGenericInstance, genericLocalClassBinding, } from "./generic-functions.js";
153
+ import { implicitAnyParamSymbolsOf, implicitLocalFnNodeOf, implicitMonoFile, collectGenericSignature, genericFnOf, lowerGenericCall, lowerGenericFnValue, inferTypeParamBindings, lowerGenericInstance, genericLocalClassBinding, checkGenericIdentityPins, } from "./generic-functions.js";
150
154
  import { bindingNeverReassigned } from "./binding-analysis.js";
151
155
  import { isMessageListenerCall } from "./expressions/message-listeners.js";
152
156
  import { bodyReadsArguments } from "../arguments-usage.js";
@@ -169,7 +173,7 @@ import { lowerTimersPromisesSetInterval, lowerTimeoutMethodCall } from "./builti
169
173
  import { lowerFsToUnixTimestampCall, lowerFsLadderCall, lowerStatsMethodCall, } from "./builtins/filesystem.js";
170
174
  import { lowerSpawnSyncCall, lowerSpawnCall, lowerExecFileCall } from "./builtins/child-process.js";
171
175
  import { lowerExecSyncCall } from "./builtins/child-process-sync.js";
172
- import { isProcessEnv, envValueType, lowerProcessEnvGet } from "./builtins/environment.js";
176
+ import { isProcessEnv, envValueType, lowerProcessEnvGet, refuseHeldEnvWrite, } from "./builtins/environment.js";
173
177
  import { lowerJsonMethodCall, lowerJsonProperty } from "./builtins/json.js";
174
178
  import { lowerCryptoComposedCall, lowerCryptoModuleCall } from "./builtins/crypto.js";
175
179
  import { lowerUrlMethodCall, lowerSearchParamsMethodCall } from "./builtins/url.js";
@@ -207,6 +211,8 @@ import { foldedStringKeyOf, lowerDynObjectLiteral, lowerObjectLiteral, lowerShor
207
211
  import { lowerRecordFieldCall, lowerObjectMethodCall } from "./lower-calls.js";
208
212
  import { fenceCrossBlockNsRef, nsPathPrefix } from "./lower-namespaces.js";
209
213
  import { isSafeToRepeat } from "./expressions/evaluation-safety.js";
214
+ import { partialAssertionFields } from "./partial-assertions.js";
215
+ import { emptyArrayLiteralArm } from "./expressions/array-literals.js";
210
216
  import { lowerTernary } from "./lower-exprs.js";
211
217
  import { maybePromiseReturnStmt, maybePromiseUnionOf, promiseArmedUnionOf, } from "./maybe-promise.js";
212
218
  import { NodeIslandModuleCollector } from "../../node-islands/modules.js";
@@ -508,7 +514,7 @@ function lowerToIrWithIslands(program, entry, moduleOrder, options) {
508
514
  reachableEmit.pushDiag(d);
509
515
  for (const d of ffiValidation.diagnostics)
510
516
  reachableEmit.pushDiag(d);
511
- const emitted = reachableEmit.emitReachable(options.libRoots);
517
+ const emitted = reachableEmit.emitReachable(options.libRoots, options.unitStore ?? null);
512
518
  let { reachable } = emitted;
513
519
  let result = emitted.result;
514
520
  let resultLowerer = reachableEmit;
@@ -1263,6 +1269,19 @@ function builtinMemberValueName(lowerer, receiver, member) {
1263
1269
  return null;
1264
1270
  return builtinModuleFnOf(lowerer, module, member)?.valueName ?? null;
1265
1271
  }
1272
+ /** Whether `node` is a function, arrow or class DEFINITION that carries no
1273
+ * name of its own, so the binding or property it initializes names it
1274
+ * (V8's SetFunctionName). Every other expression evaluates to a value that
1275
+ * already has whatever name it has. */
1276
+ function isAnonymousCallableDefinition(node) {
1277
+ if (ts.isArrowFunction(node))
1278
+ return true;
1279
+ return (ts.isFunctionExpression(node) || ts.isClassExpression(node)) && node.name === undefined;
1280
+ }
1281
+ /** The name V8 gives a function value read from this expression: its own
1282
+ * definition, through parenthesized, rebindable and const bindings and
1283
+ * property reads (`process.cwd`), or the binding an anonymous definition
1284
+ * initializes. Null when the source does not determine it. */
1266
1285
  export function jsFuncNameOf(node, lowerer) {
1267
1286
  let n = node;
1268
1287
  while (ts.isParenthesizedExpression(n))
@@ -1278,14 +1297,28 @@ export function jsFuncNameOf(node, lowerer) {
1278
1297
  n = declaration;
1279
1298
  break;
1280
1299
  }
1281
- if (!declaration ||
1282
- !ts.isVariableDeclaration(declaration) ||
1283
- !declaration.initializer ||
1284
- (ts.getCombinedNodeFlags(declaration) & ts.NodeFlags.Const) === 0)
1300
+ if (!declaration || !ts.isVariableDeclaration(declaration) || !declaration.initializer)
1285
1301
  break;
1286
- n = declaration.initializer;
1287
- while (ts.isParenthesizedExpression(n))
1288
- n = n.expression;
1302
+ let value = declaration.initializer;
1303
+ while (ts.isParenthesizedExpression(value))
1304
+ value = value.expression;
1305
+ // Name inference (V8's SetFunctionName) covers an ANONYMOUS function or
1306
+ // class definition and nothing else: the binding names it, so a
1307
+ // rebindable binding keeps the binding's spelling below. Any other
1308
+ // initializer is a value that carries its own name — a named
1309
+ // definition, a builtin function (`var a = String; a.name` is
1310
+ // "String") or another binding (`var a = b` keeps b's name) — and
1311
+ // resolution follows it.
1312
+ if (isAnonymousCallableDefinition(value)) {
1313
+ // The binding this definition initializes named it when it was
1314
+ // created, so answer that binding and not the alias the reference
1315
+ // reached it through: `import b from "./m"` keeps the "root" of
1316
+ // `const root = (text) => text;` in `m`.
1317
+ if (ts.isIdentifier(declaration.name))
1318
+ return declaration.name.text;
1319
+ break;
1320
+ }
1321
+ n = value;
1289
1322
  }
1290
1323
  if (ts.isIdentifier(n))
1291
1324
  return n.text;
@@ -1293,7 +1326,9 @@ export function jsFuncNameOf(node, lowerer) {
1293
1326
  return n.name.text;
1294
1327
  if ((ts.isFunctionExpression(n) || ts.isFunctionDeclaration(n)) && n.name)
1295
1328
  return n.name.text;
1296
- if (ts.isFunctionExpression(n) || ts.isArrowFunction(n)) {
1329
+ if (ts.isClassExpression(n) && n.name)
1330
+ return n.name.text;
1331
+ if (ts.isFunctionExpression(n) || ts.isArrowFunction(n) || ts.isClassExpression(n)) {
1297
1332
  // An anonymous function takes the name of the binding or property it
1298
1333
  // initializes, through parentheses (`const f = (function () {})`).
1299
1334
  let outer = n;
@@ -1645,6 +1680,17 @@ export class Lowerer {
1645
1680
  * type parameters are bound to `unknown`, so lambdaSignature admits
1646
1681
  * them. */
1647
1682
  erasingLambdas = new Set();
1683
+ /** Identity comparisons of a generic declaration met while lowering
1684
+ * (directly against the declaration, or through a dynamic value): exact
1685
+ * only while the program holds that declaration as one function object
1686
+ * (checkGenericIdentityPins). */
1687
+ genericIdentityPins = [];
1688
+ /** Identity comparisons whose operands are dynamic values, recorded while
1689
+ * lowering and resolved by checkGenericIdentityPins only when some
1690
+ * generic declaration is held at more than one signature. */
1691
+ dynIdentityComparisons = [];
1692
+ /** The identity comparison check reports once, after all lowering. */
1693
+ genericIdentityCheckDone = false;
1648
1694
  /** Function expressions lowered against a fixed target signature with a
1649
1695
  * tuple-typed `arguments` (typed-arguments.ts). */
1650
1696
  typedArgumentsLambdas = new Set();
@@ -1741,9 +1787,18 @@ export class Lowerer {
1741
1787
  streamPropMutatedSyms = null;
1742
1788
  /** Whether some source reads process.exitCode (processReadsExitCode). */
1743
1789
  readsExitCode = null;
1790
+ /** Whether some source replaces a process output stream's write method
1791
+ * (programPatchesStdio in builtins/process.ts). */
1792
+ patchesStdio = null;
1793
+ /** The write-replacement site programPatchesStdio found: the executable
1794
+ * planner refuses it beside Node islands (SC8020). */
1795
+ stdioPatchSites = [];
1744
1796
  requestInitPropMutatedSyms = null;
1745
1797
  emitterEventTable = null;
1746
1798
  emitterComputedPatterns = [];
1799
+ /** Some site registers a listener under an unrestricted computed name
1800
+ * (lower-event-emitter.ts emitterEvents). */
1801
+ emitterAnyNameListener = false;
1747
1802
  /** The EventTarget engine's handleEvent reader was lifted
1748
1803
  * (lower-event-target.ts noteEventListeners). */
1749
1804
  handleEventReader = false;
@@ -1796,6 +1851,10 @@ export class Lowerer {
1796
1851
  * prepass. This includes explicit annotations: unchecked TS annotations do
1797
1852
  * not prove that an array property read produced a value. */
1798
1853
  runtimeOptionalBindingTypes = new Map();
1854
+ /** JavaScript bindings assigned values outside their declared type
1855
+ * (analyzeJsWidenedBindings): checked-dynamic storage, and reads keep the
1856
+ * stored value instead of narrowing it to the checker's type. */
1857
+ jsWidenedBindings = new Set();
1799
1858
  /** A pipeline() function stage's `source` parameter: the IR type of what
1800
1859
  * the pipeline passes it (the previous stage as an async iterable), set
1801
1860
  * while the stage lowers. Parameter typing and `for await` heads read
@@ -2358,6 +2417,9 @@ export class Lowerer {
2358
2417
  /** The collection types that uses prove for untyped JavaScript bindings,
2359
2418
  * by every identifier naming one (js-collection-types.ts). */
2360
2419
  inferredCollectionTypes = undefined;
2420
+ /** Partial record assertions (`partial-assertions.ts`): per target shape,
2421
+ * the required fields some asserted literal leaves unwritten. */
2422
+ partialAssertions = undefined;
2361
2423
  /** overload-choice's answers per call, binding and function. */
2362
2424
  dynamicOverloadAnswers = new Map();
2363
2425
  /** Error parameters of an error-first callback with a known value in
@@ -2402,6 +2464,11 @@ export class Lowerer {
2402
2464
  * Reachability lowers inits before the declarations they discover, so
2403
2465
  * these rebuild after the worklist restores historical shape metadata. */
2404
2466
  shapeOrderHelperFinalizers = [];
2467
+ /** Whether any lowered function converts a checked-dynamic value into a
2468
+ * closed record, the only conversion that can leave a record holding
2469
+ * undeclared source keys (record-sources.ts). Settled once lowering ends,
2470
+ * before the shape helpers finalize their bodies. */
2471
+ recordSourcesPossible = false;
2405
2472
  /** Construction witnesses that choose each shape's enumeration order
2406
2473
  * once lowering settles (key-order-witness.ts). */
2407
2474
  keyOrder = new KeyOrderNotes();
@@ -2508,6 +2575,9 @@ export class Lowerer {
2508
2575
  * interned here so references under one source-world ABI are the SAME
2509
2576
  * zero-capture closure (see primitiveCtorClosure). */
2510
2577
  primitiveCtorFns = new Map();
2578
+ /** Whether a compiled source creates primitive wrapper objects
2579
+ * (programCreatesWrappers), computed on first use. */
2580
+ createsWrappers = undefined;
2511
2581
  /** Builtin-module FUNCTIONS admitted as values by their surface-table
2512
2582
  * entries. The resolved runtime function plus ABI is the identity key,
2513
2583
  * so named imports, namespace reads, CommonJS bindings, and alias chains
@@ -2518,6 +2588,9 @@ export class Lowerer {
2518
2588
  /** Builtin function values whose `length` differs from their adapter's
2519
2589
  * parameter count (BuiltinModuleFn.valueLength), by adapter name. */
2520
2590
  builtinCallableValueLengths = new Map();
2591
+ /** Typed builtin adapters with a checked twin (checkedBuiltinValue): the
2592
+ * builtin, its display name and the location the twin is lowered at. */
2593
+ builtinCheckedValues = new Map();
2521
2594
  /** Optional-chain lowering state. While a chain body lowers, the guarded
2522
2595
  * receiver NODE reads as a chainRecv (typed by the narrowed arm) instead
2523
2596
  * of re-lowering, its checker type reads non-nullish (typeOf), and the
@@ -2530,6 +2603,9 @@ export class Lowerer {
2530
2603
  neverValued = new Set();
2531
2604
  chainNarrowedType = new Map();
2532
2605
  chainHandled = new Set();
2606
+ /** One arm's narrowed value for a spread source while a distributed
2607
+ * union spread lowers that arm (lowerDistributedUnionSpread). */
2608
+ spreadArmOverrides = new Map();
2533
2609
  /** for-of-over-matchAll bindings whose `.index` reads the companion-index
2534
2610
  * array: binding SYMBOL → the hidden number[] of match start indices plus
2535
2611
  * the hidden cursor holding THIS iteration's position (registered while
@@ -2631,6 +2707,12 @@ export class Lowerer {
2631
2707
  globalsByDeclNode = new Map();
2632
2708
  globalsList = [];
2633
2709
  npmInitActions = new Map();
2710
+ /** Per-file %init statements of static island imports and re-exports,
2711
+ * by the import or export statement that loads the island module: the
2712
+ * importer's %init header runs them in that statement's place among its
2713
+ * dependencies' %init calls, so the island module evaluates in source
2714
+ * order with the native dependencies around it. */
2715
+ islandImportActions = new Map();
2634
2716
  /** Per-file %init PRELUDE statements for JSON imports: bakeable DATA
2635
2717
  * assignments with no observable evaluation order of their own —
2636
2718
  * prepended by lowerFileInit so the bindings are live before any
@@ -2707,6 +2789,9 @@ export class Lowerer {
2707
2789
  nodeIslandLoads = [];
2708
2790
  /** Island handle bindings by symbol (lower-node-island.ts). */
2709
2791
  islandHandleBindings = new Map();
2792
+ /** Names a native module re-exports from an island package, by the
2793
+ * symbol an alias chain reaches (lower-node-island.ts). */
2794
+ islandReexports = new Map();
2710
2795
  /** `instanceof` expressions the island lowering already handles. */
2711
2796
  islandInstanceofHandled = new Set();
2712
2797
  /** NI-6: the modules shared with Node islands (lower-shared-modules.ts),
@@ -2728,6 +2813,9 @@ export class Lowerer {
2728
2813
  threadSlotFamilies = new Map();
2729
2814
  /** Classes used as ThreadSlots keys: their hierarchies carry a slot word. */
2730
2815
  threadSlotKeys = new Set();
2816
+ /** The JavaScript names of object literals' methods, by lifted function
2817
+ * (function-names.ts). */
2818
+ objectMethodNames = new Map();
2731
2819
  forkTargetIdByPath = new Map();
2732
2820
  /** Namespace ModuleBlocks this program lowers, filled by splitFiles:
2733
2821
  * "flattened" — an instantiated namespace whose body joined the file's
@@ -2837,6 +2925,9 @@ export class Lowerer {
2837
2925
  /** web-streams-dyn.ts's answer: whether a JavaScript source names a web
2838
2926
  * stream class; undefined until asked. */
2839
2927
  namesWebStreamClass = undefined;
2928
+ /** web-streams-dyn.ts's answer: whether a TypeScript source uses a web
2929
+ * stream operation the native streams lack; undefined until asked. */
2930
+ typedWebStreams = undefined;
2840
2931
  /** The first lifted function of each name (liftedFnNamed), for the
2841
2932
  * liftedFns indexed so far. liftedFns only grows. */
2842
2933
  liftedFnsByName = new Map();
@@ -2919,6 +3010,10 @@ export class Lowerer {
2919
3010
  * function called above the declaration statement reads that, never a
2920
3011
  * NULL slot. Filled by collectGlobals. */
2921
3012
  varGlobalEntryInits = new Map();
3013
+ /** Initializer-less JavaScript lets holding a runtime handle or undefined
3014
+ * that a closure captures (inferredEvolvingLetType). Reads inside a nested
3015
+ * function lower as the checked-dynamic value. */
3016
+ closureDynLets = new Set();
2922
3017
  /** Import-cycle bindings with an initialization flag, by global id, and
2923
3018
  * the top-level statements declaring them (cycle-initialization.ts). */
2924
3019
  cycleInitFlags = new Map();
@@ -3166,6 +3261,7 @@ export class Lowerer {
3166
3261
  mapTable("builtinCallableValueFns", this.builtinCallableValueFns),
3167
3262
  mapTable("builtinCallableValueNames", this.builtinCallableValueNames),
3168
3263
  countTable("builtinCallableValueLengths", this.builtinCallableValueLengths),
3264
+ irDataTable("builtinCheckedValues", this.builtinCheckedValues),
3169
3265
  mapTable("regionRunHelpers", this.regionRunHelpers),
3170
3266
  mapTable("internTableHelpers", this.internTableHelpers),
3171
3267
  functionTable("liftedFns", this.liftedFns, (fn) => this.liftedFnNamed(fn) !== undefined, () => {
@@ -3212,6 +3308,8 @@ export class Lowerer {
3212
3308
  checkedTable("genericFunctionDemandOwner", () => this.genericFunctionDemandOwner.size),
3213
3309
  checkedTable("genericClassDemandOwner", () => this.genericClassDemandOwner.size),
3214
3310
  checkedTable("erasingLambdas", () => this.erasingLambdas.size),
3311
+ checkedTable("genericIdentityPins", () => this.genericIdentityPins.length),
3312
+ checkedTable("dynIdentityComparisons", () => this.dynIdentityComparisons.length),
3215
3313
  checkedTable("typedArgumentsLambdas", () => this.typedArgumentsLambdas.size),
3216
3314
  checkedTable("tupleAliasSymbols", () => this.tupleAliasSymbols.size),
3217
3315
  checkedTable("nullishFuncResults", () => this.nullishFuncResults.size),
@@ -3287,6 +3385,7 @@ export class Lowerer {
3287
3385
  checkedTable("globalsByDeclNode", () => this.globalsByDeclNode.size),
3288
3386
  checkedTable("globalsList", () => this.globalsList.length),
3289
3387
  checkedTable("npmInitActions", () => this.npmInitActions.size),
3388
+ checkedTable("islandImportActions", () => this.islandImportActions.size),
3290
3389
  checkedTable("jsonInitActions", () => this.jsonInitActions.size),
3291
3390
  checkedTable("jsonRequireModules", () => this.jsonRequireModules.size),
3292
3391
  checkedTable("jsonRequireCalls", () => this.jsonRequireCalls.size),
@@ -3306,6 +3405,7 @@ export class Lowerer {
3306
3405
  checkedTable("threadSlotNames", () => this.threadSlotNames.size),
3307
3406
  checkedTable("threadSlotFamilies", () => this.threadSlotFamilies.size),
3308
3407
  checkedTable("threadSlotKeys", () => this.threadSlotKeys.size),
3408
+ checkedTable("objectMethodNames", () => this.objectMethodNames.size),
3309
3409
  checkedTable("forkTargetIdByPath", () => this.forkTargetIdByPath.size),
3310
3410
  checkedTable("nsBlocks", () => this.nsBlocks.size),
3311
3411
  checkedTable("initNameOf", () => this.initNameOf.size),
@@ -3320,6 +3420,7 @@ export class Lowerer {
3320
3420
  checkedTable("preparedClassFactories", () => this.preparedClassFactories.size),
3321
3421
  checkedTable("preparingClassFactories", () => this.preparingClassFactories.size),
3322
3422
  checkedTable("varGlobalEntryInits", () => this.varGlobalEntryInits.size),
3423
+ checkedTable("closureDynLets", () => this.closureDynLets.size),
3323
3424
  checkedTable("cycleInitFlags", () => this.cycleInitFlags.size),
3324
3425
  checkedTable("classInitFlags", () => this.classInitFlags.size),
3325
3426
  checkedTable("cycleInitDeclarations", () => this.cycleInitDeclarations.size),
@@ -3414,10 +3515,12 @@ export class Lowerer {
3414
3515
  "priorRetriedSymbols",
3415
3516
  "wholeSlotDegradation",
3416
3517
  "inferredCollectionTypes",
3518
+ "partialAssertions",
3417
3519
  "foreignElementKeys",
3418
3520
  // caches made when first needed
3419
3521
  "nanCodedReads",
3420
3522
  "mentionsProcessVersions",
3523
+ "createsWrappers",
3421
3524
  "stringIndexBoundsCache",
3422
3525
  "functionLocalSubclasses",
3423
3526
  "socketEncodingReachable",
@@ -3425,8 +3528,13 @@ export class Lowerer {
3425
3528
  "unixListenReachable",
3426
3529
  "streamPropMutatedSyms",
3427
3530
  "readsExitCode",
3531
+ "patchesStdio",
3532
+ "stdioPatchSites",
3428
3533
  "requestInitPropMutatedSyms",
3429
3534
  "classProtocols",
3535
+ // The whole-program prepass analyzeJsWidenedBindings computes this set
3536
+ // before lowering begins: a pure function of the program's modules.
3537
+ "jsWidenedBindings",
3430
3538
  "cjsSplitRequireBindings",
3431
3539
  "cjsWholeExportSymbols",
3432
3540
  "cjsLiveMemberExports",
@@ -3437,6 +3545,7 @@ export class Lowerer {
3437
3545
  "sloppyThisGlobalReads",
3438
3546
  "globalLookupNames",
3439
3547
  "namesWebStreamClass",
3548
+ "typedWebStreams",
3440
3549
  "timeValueDateDecisions",
3441
3550
  "timeValueDateWrites",
3442
3551
  "dynamicOverloadAnswers",
@@ -3446,11 +3555,17 @@ export class Lowerer {
3446
3555
  // NI-5: whether a symbol names an island handle binding depends only on
3447
3556
  // its declaration, so the answer is a memo keyed by symbol.
3448
3557
  "islandHandleBindings",
3558
+ // The island names native modules re-export: a pure function of the
3559
+ // program's modules, collected before lowering begins.
3560
+ "islandReexports",
3449
3561
  // The modules shared with the islands (NI-6): a pure function of the
3450
3562
  // program's modules, computed once, and the TDZ flags its plan gives a
3451
3563
  // statement.
3452
3564
  "sharedModules",
3453
3565
  "sharedInitFlags",
3566
+ // Settled from every lowered function once lowering ends, before the
3567
+ // shape helpers finalize (record-sources.ts).
3568
+ "recordSourcesPossible",
3454
3569
  "slotOriginMemo",
3455
3570
  "recordOriginMemo",
3456
3571
  "boundaryCastOrder",
@@ -3508,6 +3623,7 @@ export class Lowerer {
3508
3623
  "neverValued",
3509
3624
  "chainNarrowedType",
3510
3625
  "chainHandled",
3626
+ "spreadArmOverrides",
3511
3627
  "splitIdentifierUses",
3512
3628
  "typeMemo",
3513
3629
  "fnStack",
@@ -3542,10 +3658,14 @@ export class Lowerer {
3542
3658
  fixed("errorAccessorReflection", () => this.errorAccessorReflection),
3543
3659
  fixed("subclassLinks", () => this.subclassLinks),
3544
3660
  fixed("errorPathCopies", () => this.errorPathCopies),
3661
+ // A latch of the end-of-lowering audit (checkGenericIdentityPins): a
3662
+ // unit never touches it.
3663
+ fixed("genericIdentityCheckDone", () => this.genericIdentityCheckDone),
3545
3664
  fixed("errorMethodDispatchRevision", () => this.errorMethodDispatchRevision),
3546
3665
  fixed("errorPropertyDispatchRevision", () => this.errorPropertyDispatchRevision),
3547
3666
  fixed("childAdditions", () => this.childAdditions),
3548
3667
  fixed("emitterEventTable", () => this.emitterEventTable),
3668
+ fixed("emitterAnyNameListener", () => this.emitterAnyNameListener),
3549
3669
  fixed("globalThisWrittenNames", () => this.globalThisWrittenNames),
3550
3670
  fixed("importRetryModules", () => this.importRetryModules),
3551
3671
  fixed("localSubclassIndex", () => this.localSubclassIndex),
@@ -3982,6 +4102,7 @@ export class Lowerer {
3982
4102
  mixinIntersectionInstance: (widened) => mixinIntersectionInstanceType(this, widened),
3983
4103
  classImplementedProtocol: (type) => this.classImplementedProtocol(type),
3984
4104
  isStdlibFile: (sf) => this.isStdlibFile(sf),
4105
+ primitiveWrappers: () => (this.createsWrappers ??= programCreatesWrappers(this)),
3985
4106
  isNpmFile: (sf) => this.isNpmFile(sf),
3986
4107
  isExperimentalFile: (sf) => isExperimentalDeclarationFile(sf, this.experimentalFiles),
3987
4108
  // The declaration-typed boundary's generated types (decl-projection.ts)
@@ -4077,15 +4198,40 @@ export class Lowerer {
4077
4198
  this.weakCollectionType(type) ||
4078
4199
  this.stdlibHandleType(type, (part) => isEcdhType(this, part) || isDiffieHellmanType(this, part)));
4079
4200
  }
4080
- /** A stdlib WeakMap or WeakSet, alone or with `null`/`undefined`. */
4201
+ /** A stdlib WeakMap or WeakSet, alone or in a union with `null`/`undefined`
4202
+ * (including the `WeakMap | WeakSet` pair). */
4081
4203
  weakCollectionType(type) {
4204
+ return this.weakCollectionNamesOf(type) !== null;
4205
+ }
4206
+ /** The stdlib collections a type denotes — `WeakMap`, `WeakSet`, or the
4207
+ * two in a union — alone or with `null`/`undefined`, which `nullable`
4208
+ * reports; null for everything else. The predicate behind
4209
+ * weak-collection lowering and the JavaScript value read of one of
4210
+ * their methods, whose receiver may hold either collection. */
4211
+ weakCollectionNamesOf(type) {
4212
+ const names = [];
4082
4213
  const weak = (part) => {
4083
4214
  const symbol = part.getSymbol();
4084
- return (((symbol !== undefined && ts.symbolName(symbol) === "WeakMap") ||
4085
- (symbol !== undefined && ts.symbolName(symbol) === "WeakSet")) &&
4086
- symbol.declarations.some((d) => ts.isInterfaceDeclaration(d) && this.isStdlibFile(ts.getSourceFileOfNode(d))));
4215
+ if (symbol === undefined)
4216
+ return false;
4217
+ const symbolName = ts.symbolName(symbol);
4218
+ if (symbolName !== "WeakMap" && symbolName !== "WeakSet")
4219
+ return false;
4220
+ if (!symbol.declarations.some((d) => ts.isInterfaceDeclaration(d) && this.isStdlibFile(ts.getSourceFileOfNode(d))))
4221
+ return false;
4222
+ if (!names.includes(symbolName))
4223
+ names.push(symbolName);
4224
+ return true;
4225
+ };
4226
+ if (!this.stdlibHandleType(type, weak))
4227
+ return null;
4228
+ return {
4229
+ names,
4230
+ nullable: type.isUnionType() &&
4231
+ ts
4232
+ .constituentTypes(type)
4233
+ .some((part) => (part.flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined)) !== 0),
4087
4234
  };
4088
- return this.stdlibHandleType(type, weak);
4089
4235
  }
4090
4236
  /** A type `handle` accepts, alone or with `null`/`undefined`. */
4091
4237
  stdlibHandleType(type, handle) {
@@ -5400,6 +5546,49 @@ export class Lowerer {
5400
5546
  }
5401
5547
  }
5402
5548
  }
5549
+ /** A JavaScript `let`/`var` binding assigned a value its declared type
5550
+ * does not admit (`let t = parseInt(s); if (isNaN(t)) t = undefined`):
5551
+ * TypeScript types the binding from its initializer and reports the
5552
+ * assignment (TS2322), which JavaScript files relax, so the binding takes
5553
+ * checked-dynamic storage and holds whatever the program stores. JSDoc
5554
+ * type annotations keep their declared storage. */
5555
+ analyzeJsWidenedBindings(parts) {
5556
+ for (const { sf } of parts) {
5557
+ if (!isJsSourceFileName(sf.fileName) || sf.isDeclarationFile)
5558
+ continue;
5559
+ ts.walkPreorder(sf, (node) => {
5560
+ if (!ts.isBinaryExpression(node) ||
5561
+ node.operatorToken.kind !== ts.SyntaxKind.EqualsToken ||
5562
+ !ts.isIdentifier(node.left))
5563
+ return undefined;
5564
+ const symbol = this.resolveValueSymbol(node.left);
5565
+ if (!symbol || this.runtimeOptionalBindingTypes.has(symbol))
5566
+ return undefined;
5567
+ const decl = symbol.valueDeclaration;
5568
+ if (decl === undefined ||
5569
+ !ts.isVariableDeclaration(decl) ||
5570
+ !ts.isIdentifier(decl.name) ||
5571
+ !isJsSourceFileName(ts.getSourceFileOfNode(decl).fileName) ||
5572
+ hasJsTypeAnnotation(decl) ||
5573
+ decl.parent === undefined ||
5574
+ !ts.isVariableDeclarationList(decl.parent) ||
5575
+ (decl.parent.flags & ts.NodeFlags.Const) !== 0)
5576
+ return undefined;
5577
+ const declared = this.checker.getTypeOfSymbol(symbol);
5578
+ if (declared.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown))
5579
+ return undefined;
5580
+ const assigned = this.checker.getTypeAtLocation(node.right);
5581
+ if (this.checker.isTypeAssignableTo(assigned, declared))
5582
+ return undefined;
5583
+ this.runtimeOptionalBindingTypes.set(symbol, DYN);
5584
+ this.jsWidenedBindings.add(symbol);
5585
+ const global = this.globalsBySymbol.get(symbol);
5586
+ if (global)
5587
+ global.type = DYN;
5588
+ return undefined;
5589
+ });
5590
+ }
5591
+ }
5403
5592
  analyzeRuntimeOptionalArrayReads(parts) {
5404
5593
  const provenance = RuntimeOptionalProvenance.fromEnvironment();
5405
5594
  // The site whose value the current promotion follows (debug only).
@@ -8309,6 +8498,7 @@ export class Lowerer {
8309
8498
  this.analyzeRuntimeOptionalArrayReads(parts);
8310
8499
  this.analyzeDateJsonResults(parts);
8311
8500
  this.analyzeGuardedRecordReadGlobals(parts);
8501
+ this.analyzeJsWidenedBindings(parts);
8312
8502
  });
8313
8503
  // Decorated classes analyze AFTER the whole collection pass: a
8314
8504
  // decorator's return type may name a subclass declared below the
@@ -8466,9 +8656,12 @@ export class Lowerer {
8466
8656
  // array-HOF loop functions, which ride the same list), and the
8467
8657
  // implicit-any instances lowered eagerly at their first call sites.
8468
8658
  this.settleSharedHelperLocations([...functions, ...this.liftedFns, ...this.implicitFns]);
8469
- functions.push(...this.liftedFns);
8470
- functions.push(...this.implicitFns);
8471
- functions.push(...runtimeClassConstructs(this, functions));
8659
+ for (const fn of this.liftedFns)
8660
+ functions.push(fn);
8661
+ for (const fn of this.implicitFns)
8662
+ functions.push(fn);
8663
+ for (const fn of runtimeClassConstructs(this, functions))
8664
+ functions.push(fn);
8472
8665
  if (this.remainder) {
8473
8666
  // Deferred collection diagnostics nothing flushed — declarations no
8474
8667
  // reference ever made relevant. They belong to the unreached group
@@ -8479,6 +8672,9 @@ export class Lowerer {
8479
8672
  for (const d of [...diags])
8480
8673
  this.pushDiag(d);
8481
8674
  }
8675
+ // Coverage visits more bodies; more value instances can only add
8676
+ // refusals to the identity comparison check.
8677
+ checkGenericIdentityPins(this);
8482
8678
  return {
8483
8679
  module: null,
8484
8680
  diagnostics: this.diags,
@@ -8493,10 +8689,17 @@ export class Lowerer {
8493
8689
  /** Final retention, pruning, and module assembly shared by ordinary emit
8494
8690
  * and the retained reachability worklist. */
8495
8691
  finishModule(functions) {
8692
+ // Every instance of every generic value is known now (the
8693
+ // monomorphization worklists drained): an identity comparison against
8694
+ // one is exact only if the declaration is held at a single signature.
8695
+ checkGenericIdentityPins(this);
8696
+ boxBuiltinValuesChecked(this, functions);
8697
+ finalizeFunctionNames(this, functions);
8496
8698
  if (this.diags.length === 0)
8497
8699
  fuseArrayPipelines(this, functions);
8498
8700
  finalizeClassMethodValues(this, functions);
8499
8701
  finalizePrivateBrands(this, functions);
8702
+ routeWrapperConsumers(this, functions);
8500
8703
  trackClassFieldCreation(this, functions);
8501
8704
  boxClassInstancesExactly(this, functions);
8502
8705
  addUntypedIntegrityWords(this);
@@ -8653,11 +8856,19 @@ export class Lowerer {
8653
8856
  // becomes its js twin), so coverage's dynamic statements are unchanged.
8654
8857
  if (module && this.dynamicFunctions.length > 0)
8655
8858
  promoteJsvals(module);
8859
+ // A program that replaces a process output stream's write method beside
8860
+ // Node islands is refused by the executable planner (SC8020): an
8861
+ // island's process.stdout is its own object. Only island builds pay for
8862
+ // the whole-program scan.
8863
+ const stdioPatches = this.nodeIslands !== null && programPatchesStdio(this)
8864
+ ? [...this.stdioPatchSites]
8865
+ : undefined;
8656
8866
  return {
8657
8867
  module,
8658
8868
  diagnostics: this.diags,
8659
8869
  runtimeFences: this.runtimeFences,
8660
8870
  stats: this.stats,
8871
+ ...(stdioPatches !== undefined && stdioPatches.length > 0 ? { stdioPatches } : {}),
8661
8872
  ...(this.dynamicFunctions.length > 0 ? { dynamicFunctions: this.dynamicFunctions } : {}),
8662
8873
  ...(this.statsByFile.size > 0 ? { statsByFile: this.statsByFile } : {}),
8663
8874
  ...(this.provenanceElided.length > 0 ? { provenanceElided: this.provenanceElided } : {}),
@@ -8760,11 +8971,14 @@ export class Lowerer {
8760
8971
  reportBlockedBody(decl) {
8761
8972
  const diags = blockedBodyDiagnostics(this, decl);
8762
8973
  const symbol = declSymbolOf(this, decl);
8763
- if (symbol && this.alreadyFlushed.has(symbol))
8764
- this.reachedBlockedBodyDiagnostics.push(...diags);
8765
- else
8974
+ if (symbol && this.alreadyFlushed.has(symbol)) {
8975
+ for (const d of diags)
8976
+ this.reachedBlockedBodyDiagnostics.push(d);
8977
+ }
8978
+ else {
8766
8979
  for (const d of diags)
8767
8980
  this.pushDiag(d);
8981
+ }
8768
8982
  }
8769
8983
  /** Whether run() counts a signature-blocked declaration in
8770
8984
  * stats.functionsSkipped: whole-program passes and the coverage
@@ -8787,7 +9001,7 @@ export class Lowerer {
8787
9001
  * demand-driven) and lifted lambdas lower inline with their enclosing
8788
9002
  * body; both fire edges through the same hooks and are not units
8789
9003
  * themselves. */
8790
- emitReachable(extraRoots) {
9004
+ emitReachable(extraRoots, unitStore = null) {
8791
9005
  // Frontend passes below rewrite function bodies through the IR mapper
8792
9006
  // (caught-value and class dispatch); key-order notes follow the record
8793
9007
  // literals they rebuild until the witness pass has read them.
@@ -8823,6 +9037,7 @@ export class Lowerer {
8823
9037
  this.analyzeRuntimeOptionalArrayReads(parts);
8824
9038
  this.analyzeDateJsonResults(parts);
8825
9039
  this.analyzeGuardedRecordReadGlobals(parts);
9040
+ this.analyzeJsWidenedBindings(parts);
8826
9041
  });
8827
9042
  // Decorated classes analyze post-collection here too: the %init seeds
8828
9043
  // lower the decoration calls, whose edges (decorator bodies, construct
@@ -8834,6 +9049,8 @@ export class Lowerer {
8834
9049
  // Every lowerable body, by emitted-function name. The names double as
8835
9050
  // retained-function keys and are deterministic by construction
8836
9051
  // (qualified declaration names).
9052
+ // `source` is the declaration whose text a unit lowers and `owners` the
9053
+ // declarations around it (unit-reuse.ts).
8837
9054
  const units = new Map();
8838
9055
  // Roots are collected with plain pushes: spread arguments into a rest
8839
9056
  // parameter pass the nodes as dynamic values.
@@ -8884,6 +9101,7 @@ export class Lowerer {
8884
9101
  order: unitOrder++,
8885
9102
  roots: functionRoots(decl),
8886
9103
  lower: () => this.lowerFunction(decl),
9104
+ source: decl,
8887
9105
  });
8888
9106
  }
8889
9107
  }
@@ -8906,6 +9124,7 @@ export class Lowerer {
8906
9124
  order: unitOrder++,
8907
9125
  roots: classCtorRoots(info),
8908
9126
  lower: () => info.localClass && !info.localClass.ready ? null : this.lowerClassCtor(info),
9127
+ source: info.decl ?? undefined,
8909
9128
  });
8910
9129
  // The descriptor helpers of a class that extends Array, reached
8911
9130
  // from its constructor.
@@ -8914,11 +9133,13 @@ export class Lowerer {
8914
9133
  order: unitOrder++,
8915
9134
  roots: [],
8916
9135
  lower: () => arrayClassFieldsFn(this, info),
9136
+ source: info.decl ?? undefined,
8917
9137
  });
8918
9138
  units.set(`%${cName}.species`, {
8919
9139
  order: unitOrder++,
8920
9140
  roots: [],
8921
9141
  lower: () => arrayClassSpeciesFn(this, info),
9142
+ source: info.decl ?? undefined,
8922
9143
  });
8923
9144
  }
8924
9145
  for (const { mName, member } of this.classMethodMembers(info)) {
@@ -8928,6 +9149,8 @@ export class Lowerer {
8928
9149
  lower: () => info.localClass && !info.localClass.ready
8929
9150
  ? null
8930
9151
  : this.lowerClassMethodMember(info, member),
9152
+ source: member,
9153
+ owners: info.decl ? [info.decl] : [],
8931
9154
  });
8932
9155
  }
8933
9156
  for (const prop of info.throwingSetters) {
@@ -8935,6 +9158,7 @@ export class Lowerer {
8935
9158
  order: unitOrder++,
8936
9159
  roots: [],
8937
9160
  lower: () => this.throwingSetterFn(info, prop),
9161
+ source: info.decl ?? undefined,
8938
9162
  });
8939
9163
  }
8940
9164
  }
@@ -8944,6 +9168,8 @@ export class Lowerer {
8944
9168
  order: unitOrder++,
8945
9169
  roots: functionRoots(entry.member),
8946
9170
  lower: () => lowerStaticMethod(this, info, name),
9171
+ source: entry.member,
9172
+ owners: info.decl ? [info.decl] : [],
8947
9173
  });
8948
9174
  }
8949
9175
  }
@@ -9230,17 +9456,77 @@ export class Lowerer {
9230
9456
  const owner = demandOwner(priority);
9231
9457
  return this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(priority, () => this.withClosureRoot(name, unit.lower)));
9232
9458
  };
9233
- const recorded = journalMode() === "serial" ? waveStats() : null;
9234
- const host = recorded === null ? null : this.waveHost(loweredUnits, lowerUnitBody);
9459
+ // With a unit store, every unit is recorded as in the serial mode, and
9460
+ // a unit applies the record an earlier build stored for it where that
9461
+ // record still holds (unit-reuse.ts).
9462
+ const reuse = unitStore === null
9463
+ ? null
9464
+ : UnitReuse.open(unitStore, this.program, parts.map((fp) => fp.sf), {
9465
+ facts: (declaration) => this.declarationFacts(declaration),
9466
+ exportsOf: (specifier) => {
9467
+ const symbol = this.checker.getSymbolAtLocation(specifier);
9468
+ if (!symbol)
9469
+ return null;
9470
+ return this.checker
9471
+ .getExportsOfModule(symbol)
9472
+ .map((exported) => ts.symbolName(exported))
9473
+ .sort()
9474
+ .join("\n");
9475
+ },
9476
+ isLocal: (identifier, container) => {
9477
+ const declarations = this.checker.getSymbolAtLocation(identifier)?.declarations;
9478
+ if (declarations === undefined || declarations.length === 0)
9479
+ return false;
9480
+ const sf = ts.getSourceFileOfNode(container);
9481
+ return declarations.every((declaration) => ts.getSourceFileOfNode(declaration) === sf &&
9482
+ declaration.pos >= container.pos &&
9483
+ declaration.end <= container.end);
9484
+ },
9485
+ });
9486
+ const recorded = journalMode() === "serial" || (reuse !== null && reuse.records) ? waveStats() : null;
9487
+ const host = recorded === null
9488
+ ? null
9489
+ : this.waveHost(loweredUnits, lowerUnitBody, (name) => {
9490
+ const priority = metadataPriority.get(name);
9491
+ return { owner: demandOwner(priority), priority };
9492
+ });
9235
9493
  const dump = recorded === null ? null : journalDump();
9494
+ const fileOfUnit = (name) => {
9495
+ const source = units.get(name)?.source;
9496
+ return source === undefined ? null : ts.getSourceFileOfNode(source).fileName;
9497
+ };
9498
+ const waveReuse = reuse === null || !reuse.records
9499
+ ? null
9500
+ : {
9501
+ verify: unitReuseVerify(),
9502
+ stored: (name) => {
9503
+ // A unit without a declared rank takes the next expression
9504
+ // rank when it lowers, which applying a record would not
9505
+ // advance.
9506
+ const unit = units.get(name);
9507
+ const file = fileOfUnit(name);
9508
+ if (unit === undefined || file === null || !metadataPriority.has(name))
9509
+ return null;
9510
+ return reuse.candidate(name, file, unit.source ?? null, unit.owners ?? []);
9511
+ },
9512
+ check: (name, stored, pending, unit) => verifyStoredUnit(name, stored, pending, unit.record, unit.reasons),
9513
+ note: (name, record, applied, files) => {
9514
+ const file = fileOfUnit(name);
9515
+ if (file !== null)
9516
+ reuse.note(name, file, record, applied, files);
9517
+ },
9518
+ };
9236
9519
  const recordLines = [];
9237
9520
  const drainUnits = () => {
9521
+ // The waves of one drain have only checker prefetches between them, so
9522
+ // they share the content their units start from (HeldTables).
9523
+ const held = host !== null && recorded !== null ? new HeldTables(host.tables, recorded) : null;
9238
9524
  while (queue.length > 0) {
9239
9525
  const wave = queue.splice(0);
9240
9526
  shuffle?.(wave);
9241
9527
  this.checker.prefetchRoots(wave.flatMap((name) => units.get(name).roots));
9242
9528
  if (host !== null && recorded !== null) {
9243
- lowerWaveRecorded(host, wave, recorded, dump === null ? null : recordLines);
9529
+ lowerWaveRecorded(host, wave, recorded, dump === null ? null : recordLines, waveReuse, held);
9244
9530
  continue;
9245
9531
  }
9246
9532
  for (const name of wave) {
@@ -9260,6 +9546,7 @@ export class Lowerer {
9260
9546
  }
9261
9547
  }
9262
9548
  }
9549
+ held?.check();
9263
9550
  };
9264
9551
  drainUnits();
9265
9552
  this.restoreGenericInstanceOrder();
@@ -9301,6 +9588,11 @@ export class Lowerer {
9301
9588
  classDispatch.finalize(this);
9302
9589
  if (dump !== null)
9303
9590
  writeRecords(dump, recordLines);
9591
+ if (reuse !== null) {
9592
+ reuse.finish();
9593
+ if (process.env["SCRIPTC_TIMING"] === "1")
9594
+ process.stderr.write(`scriptc lowering ${JSON.stringify({ phase: "unit-reuse", ...reuse.stats })}\n`);
9595
+ }
9304
9596
  if (recorded !== null && process.env["SCRIPTC_TIMING"] === "1")
9305
9597
  process.stderr.write(`scriptc lowering ${JSON.stringify({ phase: "unit-records", ...recorded })}\n`);
9306
9598
  const orderedUnits = unitsInOrder();
@@ -9308,13 +9600,30 @@ export class Lowerer {
9308
9600
  this.shapes.settleDeclaredOrderPriorities();
9309
9601
  for (const finalize of this.shapeOrderMetadataFinalizers)
9310
9602
  finalize();
9311
- applyKeyOrderWitnesses(this, [
9603
+ const keyOrderFunctions = [
9312
9604
  ...orderedUnits,
9313
9605
  ...initFunctions,
9314
9606
  ...instanceFunctions,
9315
9607
  ...this.liftedFns,
9316
9608
  ...this.implicitFns,
9317
- ]);
9609
+ ];
9610
+ // A program whose functions never convert a checked-dynamic value into a
9611
+ // closed record cannot keep a source view anywhere, so the captures that
9612
+ // consult one keep their static copy (record-sources.ts). Decided before
9613
+ // the key-order pass, which reads the fact (a same-shape copy of a kept
9614
+ // record keeps its keys; the `"k" in r` sites answer through the view).
9615
+ const sourceScan = { memo: new Map(), visiting: new Set() };
9616
+ for (const fn of keyOrderFunctions) {
9617
+ if (!functionKeepsRecordSources(this, fn, sourceScan))
9618
+ continue;
9619
+ this.recordSourcesPossible = true;
9620
+ break;
9621
+ }
9622
+ applyKeyOrderWitnesses(this, keyOrderFunctions);
9623
+ // A kept width spread builds a record that holds undeclared keys, so the
9624
+ // captures that consult a kept source must be active for it too.
9625
+ if (this.keyOrder.keptWidthSpreads > 0)
9626
+ this.recordSourcesPossible = true;
9318
9627
  observeRecordLiteralRebuilds(null);
9319
9628
  for (const finalize of this.shapeOrderHelperFinalizers)
9320
9629
  finalize();
@@ -9335,7 +9644,8 @@ export class Lowerer {
9335
9644
  ...byName(this.liftedFns),
9336
9645
  ...byName(this.implicitFns),
9337
9646
  ];
9338
- functions.push(...runtimeClassConstructs(this, functions));
9647
+ for (const fn of runtimeClassConstructs(this, functions))
9648
+ functions.push(fn);
9339
9649
  if (this.regexGroupResults)
9340
9650
  for (const fn of functions)
9341
9651
  foldRegexSpanReads(this, fn);
@@ -9350,9 +9660,50 @@ export class Lowerer {
9350
9660
  this.reachableForArtifacts = reachable;
9351
9661
  return { reachable, result: this.finishModule(functions) };
9352
9662
  }
9663
+ /** What the steps before the worklist settled for a top-level
9664
+ * declaration, as text without source positions (unit-reuse.ts): a
9665
+ * function's signature, a class's layout and the signatures of its
9666
+ * methods and statics, and the globals of a variable statement. */
9667
+ declarationFacts(declaration) {
9668
+ const positionFree = (key, value) => key === "loc" || key === "scope" ? undefined : value;
9669
+ if (ts.isFunctionDeclaration(declaration)) {
9670
+ const symbol = declSymbolOf(this, declaration);
9671
+ const sig = symbol ? this.fnSigsBySymbol.get(symbol) : undefined;
9672
+ return sig === undefined ? "" : JSON.stringify(sig, positionFree);
9673
+ }
9674
+ if (ts.isClassDeclaration(declaration)) {
9675
+ const info = this.classes.get(this.classNamer(declaration));
9676
+ if (info === undefined)
9677
+ return "";
9678
+ const staticMethods = [];
9679
+ if (info.staticMethods)
9680
+ for (const [name, method] of info.staticMethods)
9681
+ staticMethods.push({ name, params: method.params, ret: method.ret });
9682
+ return JSON.stringify({
9683
+ def: info.def,
9684
+ fields: [...info.fields],
9685
+ methods: [...info.methods],
9686
+ statics: info.staticFields.map((field) => ({
9687
+ name: field.name,
9688
+ type: field.type,
9689
+ runtimeOptional: field.runtimeOptional ?? false,
9690
+ globalId: field.globalId,
9691
+ readonly: field.readonly,
9692
+ })),
9693
+ staticMethods,
9694
+ }, positionFree);
9695
+ }
9696
+ if (ts.isVariableStatement(declaration)) {
9697
+ const globals = [];
9698
+ for (const decl of declaration.declarationList.declarations.nodes)
9699
+ globals.push(this.globalsByDeclNode.get(decl) ?? null);
9700
+ return JSON.stringify(globals, positionFree);
9701
+ }
9702
+ return "";
9703
+ }
9353
9704
  /** The lowerer's side of a recorded wave (unit-journal.ts).
9354
9705
  * `lowerUnitBody` lowers a unit as reachable emit does. */
9355
- waveHost(loweredUnits, lowerUnitBody) {
9706
+ waveHost(loweredUnits, lowerUnitBody, ownerOf) {
9356
9707
  const scalars = this.journalScalars();
9357
9708
  const flags = new Map(scalars.map((scalar) => [scalar.name, scalar]));
9358
9709
  let instances = new Map();
@@ -9384,6 +9735,35 @@ export class Lowerer {
9384
9735
  return undefined;
9385
9736
  }
9386
9737
  };
9738
+ // Makes a recorded call again (resolves has answered true for it).
9739
+ const replay = (event) => {
9740
+ switch (event.kind) {
9741
+ case "edge":
9742
+ this.noteEdge(event.name);
9743
+ break;
9744
+ case "superConstructorEdge":
9745
+ this.noteSuperConstructorEdge(event.name);
9746
+ break;
9747
+ case "virtualEdge":
9748
+ this.noteVirtualEdge(classNamed(event.name), event.detail);
9749
+ break;
9750
+ case "functionDemand":
9751
+ this.noteGenericInstanceDemand(instanceNamed(event.name));
9752
+ break;
9753
+ case "classDemand":
9754
+ this.noteGenericClassInstanceDemand(classNamed(event.name));
9755
+ break;
9756
+ case "statement":
9757
+ this.countStatement(statementNode(event), event.detail ?? undefined);
9758
+ break;
9759
+ case "failedStatement":
9760
+ this.countStatementFailed(statementNode(event), event.detail ?? undefined);
9761
+ break;
9762
+ case "flag":
9763
+ flags.get(event.name).set();
9764
+ break;
9765
+ }
9766
+ };
9387
9767
  return {
9388
9768
  tables: this.journalTables(),
9389
9769
  scalars,
@@ -9428,6 +9808,15 @@ export class Lowerer {
9428
9808
  return true;
9429
9809
  }
9430
9810
  },
9811
+ keep: (name, fn, events) => {
9812
+ if (fn)
9813
+ loweredUnits.set(name, fn);
9814
+ const { owner, priority } = ownerOf(name);
9815
+ this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(priority, () => {
9816
+ for (const event of events)
9817
+ replay(event);
9818
+ }));
9819
+ },
9431
9820
  };
9432
9821
  }
9433
9822
  /** Reachability hook (see emitReachable): fires when lowering resolves a
@@ -9512,10 +9901,12 @@ export class Lowerer {
9512
9901
  }
9513
9902
  const captured = this.diags.splice(diagsBefore);
9514
9903
  if (captured.some((d) => d.code === "SC9001")) {
9515
- this.diags.push(...captured);
9904
+ for (const d of captured)
9905
+ this.diags.push(d);
9516
9906
  return null;
9517
9907
  }
9518
- this.runtimeFences.push(...captured);
9908
+ for (const d of captured)
9909
+ this.runtimeFences.push(d);
9519
9910
  const fence = this.runtimeFenceStmt(captured[0], node, target.fallback, target.bareMessage);
9520
9911
  const loc = locOf(node);
9521
9912
  if (target.kind === "statement")
@@ -9785,7 +10176,8 @@ export class Lowerer {
9785
10176
  .slice(diagsBefore)
9786
10177
  .filter((d) => d.rejects !== undefined || this.loweredOnceDiags.has(d));
9787
10178
  this.diags.length = diagsBefore;
9788
- this.diags.push(...kept);
10179
+ for (const d of kept)
10180
+ this.diags.push(d);
9789
10181
  }
9790
10182
  /** A unit that still fails after its retries commits its first
9791
10183
  * attempt's own diagnostics (`first`, taken before the first
@@ -9796,7 +10188,11 @@ export class Lowerer {
9796
10188
  const carried = (d) => d.rejects !== undefined || this.loweredOnceDiags.has(d);
9797
10189
  const kept = this.diags.slice(diagsBefore).filter(carried);
9798
10190
  this.diags.length = diagsBefore;
9799
- this.diags.push(...first.filter((d) => !carried(d)), ...kept);
10191
+ for (const d of first)
10192
+ if (!carried(d))
10193
+ this.diags.push(d);
10194
+ for (const d of kept)
10195
+ this.diags.push(d);
9800
10196
  }
9801
10197
  /** Lowers one unit whose body-level poison skips it (a generic
9802
10198
  * instance), with localized failure's commit point: a degradable type
@@ -10083,9 +10479,11 @@ export class Lowerer {
10083
10479
  // story, naming the type — and for the families with a WHY, the same
10084
10480
  // pointed reason the identifier/constructor chokepoints teach.
10085
10481
  if (stdlibNominal) {
10086
- const intlHint = "Intl formatter values have no representation — the COMPOSED en-US forms lower: " +
10087
- 'new Intl.NumberFormat("en-US").format(x) and x.toLocaleString("en-US") with default options; ' +
10088
- "the rest is ICU locale data the binary does not carry";
10482
+ const intlHint = "Intl formatter values have no representation — the COMPOSED forms lower: " +
10483
+ 'new Intl.NumberFormat("en-US").format(x), x.toLocaleString("en-US") and ' +
10484
+ "x.toLocaleString() with default options, d.toLocaleString(), d.toLocaleTimeString(), " +
10485
+ "and Intl.Segmenter with grapheme or word granularity; the formatter objects " +
10486
+ "themselves (locale negotiation, resolvedOptions, options bags) remain unsupported";
10089
10487
  const typeHints = {
10090
10488
  ArrayBuffer: "fixed ArrayBuffer storage and typed-array views are supported; resizable and detached storage are not modeled",
10091
10489
  SharedArrayBuffer: "fixed SharedArrayBuffer storage is supported; growable shared storage is not modeled",
@@ -10570,8 +10968,26 @@ export class Lowerer {
10570
10968
  return dyn;
10571
10969
  this.badType(node, t);
10572
10970
  }
10971
+ // A JavaScript binding whose inferred type holds a union of functions
10972
+ // and arrays (a test table of `[fn, cases]` rows, or one row
10973
+ // destructured): the checked-dynamic kind dynFallbackType gives the
10974
+ // unmappable spellings of such tables, so the rows keep their functions'
10975
+ // names and the destructured items their values.
10976
+ if (isJsSourceFile(ts.getSourceFileOfNode(node)) && this.mixesFunctionsWithArrays(mapped))
10977
+ return DYN;
10573
10978
  return jsOpenObjectType(node, mapped, this.shapes, this.unions);
10574
10979
  }
10980
+ /** Whether `type`, or an array element type inside it, is a union with
10981
+ * both a function arm and an array arm. */
10982
+ mixesFunctionsWithArrays(type) {
10983
+ if (type.kind === "array")
10984
+ return this.mixesFunctionsWithArrays(type.elem);
10985
+ if (type.kind !== "union")
10986
+ return false;
10987
+ const arms = this.unions.get(type.unionId)?.arms ?? [];
10988
+ return ((arms.some((arm) => arm.kind === "func") && arms.some((arm) => arm.kind === "array")) ||
10989
+ arms.some((arm) => arm.kind === "array" && this.mixesFunctionsWithArrays(arm)));
10990
+ }
10575
10991
  /** Exact-shape enforcement (SC2002). Records are monomorphic structs, so
10576
10992
  * everywhere a value flows into a typed slot (call arg, initializer,
10577
10993
  * assignment, field, return) the shapes must MATCH — or width-coerce:
@@ -10929,6 +11345,28 @@ export class Lowerer {
10929
11345
  if (boxed)
10930
11346
  return boxed;
10931
11347
  }
11348
+ // A node:path family is its module object (pathModuleValue), the
11349
+ // bare module the target platform's family.
11350
+ if (expr.type.kind === "moduleNs" &&
11351
+ (expr.type.moduleId === "builtin:path" ||
11352
+ expr.type.moduleId === "builtin:path/posix" ||
11353
+ expr.type.moduleId === "builtin:path/win32")) {
11354
+ const family = expr.type.moduleId !== "builtin:path"
11355
+ ? expr.type.moduleId.slice("builtin:".length)
11356
+ : builtinModuleConstOf(this, "path", "sep") === "\\"
11357
+ ? "path/win32"
11358
+ : "path/posix";
11359
+ const value = pathModuleValue(this, family, expr.loc);
11360
+ if (expr.kind === "moduleNsRef")
11361
+ return value;
11362
+ return {
11363
+ kind: "seqExpr",
11364
+ stmts: [{ kind: "exprStmt", expr, loc: expr.loc }],
11365
+ result: value,
11366
+ type: DYN,
11367
+ loc: expr.loc,
11368
+ };
11369
+ }
10932
11370
  if (expr.type.kind === "moduleNs" &&
10933
11371
  expr.type.moduleId === "builtin:events" &&
10934
11372
  isJsSourceFileName(expr.loc.file)) {
@@ -10967,7 +11405,7 @@ export class Lowerer {
10967
11405
  (this.unions.get(expr.type.unionId)?.arms.some(liveReference) ?? false));
10968
11406
  return {
10969
11407
  kind: "dynFrom",
10970
- value: expr,
11408
+ value: this.checkedBuiltinValue(expr),
10971
11409
  type: DYN,
10972
11410
  loc: expr.loc,
10973
11411
  ...(liveRef ? { liveRef: true } : {}),
@@ -12040,6 +12478,11 @@ export class Lowerer {
12040
12478
  elements.every((element) => element !== null && this.widthLiftPlan(element.type, candidate.elem) !== null));
12041
12479
  }
12042
12480
  }
12481
+ // An EMPTY literal carries no element to select an arm by: it
12482
+ // builds as the union's first array arm (the emptyArrayLiteralArm
12483
+ // rule the contextual union and the `?? []` default share).
12484
+ if (!arm)
12485
+ arm = emptyArrayLiteralArm(x, arms) ?? undefined;
12043
12486
  if (arm) {
12044
12487
  const built = this.lowerArrayLiteral(x, arm);
12045
12488
  return this.coerceInto(node, built, expected);
@@ -12178,8 +12621,51 @@ export class Lowerer {
12178
12621
  return this.lowerExprExpecting(node, expected);
12179
12622
  if (this.returnsFreshCollection(node) && expected.kind !== "void")
12180
12623
  return this.lowerExprExpecting(node, expected);
12624
+ // A fresh object literal into a record result: the same
12625
+ // destination-directed construction. An unannotated method inside a
12626
+ // contextually typed literal is checked against the CONTEXTUAL
12627
+ // signature's result while its own return type stays the literal's
12628
+ // inferred (narrower) record — `ToolDefinition<Schema, Details>`
12629
+ // methods returning `{ content, details }`. Building at the
12630
+ // contextual type would then coerce that wider record into the
12631
+ // declared result and refuse; the result slot is the layout.
12632
+ if (this.returnsFreshRecord(node, expected))
12633
+ return this.lowerExprExpecting(node, expected);
12181
12634
  return this.asyncReturnValueOf(node, this.lowerExpr(node), expected);
12182
12635
  }
12636
+ /** A fresh object literal returned into a RECORD result whose ordinary
12637
+ * construction cannot reach that result: not a thenable, so it is built
12638
+ * at the result type like a synchronous return. An unannotated method
12639
+ * inside a contextually typed literal is checked against the CONTEXTUAL
12640
+ * signature's result while its own return type stays the literal's
12641
+ * inferred (narrower) record — `ToolDefinition<Schema, Details>` methods
12642
+ * returning `{ content, details }`. Building at the contextual type
12643
+ * would then coerce that wider record into the declared result and
12644
+ * refuse; the result slot is the layout. A literal that declares `then`
12645
+ * is awaited instead, and a literal whose contextual build does convert
12646
+ * keeps the ordinary lowering, so no convertible value changes. */
12647
+ returnsFreshRecord(node, expected) {
12648
+ if (expected.kind !== "record")
12649
+ return false;
12650
+ let e = node;
12651
+ while (ts.isParenthesizedExpression(e))
12652
+ e = e.expression;
12653
+ if (!ts.isObjectLiteralExpression(e))
12654
+ return false;
12655
+ if (this.checker.getPropertyOfType(this.typeOf(e), "then") !== undefined)
12656
+ return false;
12657
+ // The record the ordinary path builds: the literal's context, with an
12658
+ // async return's `T | PromiseLike<T>` stripped to the awaited record
12659
+ // (object-literals.ts does the same before mapping).
12660
+ let context = this.checker.getContextualType(e) ?? this.typeOf(e);
12661
+ if (context.isUnionType() &&
12662
+ ts.constituentTypes(context).some((t) => ts.symbolNameOf(t.getSymbol()) === "PromiseLike"))
12663
+ context = this.checker.getAwaitedType(context) ?? context;
12664
+ const built = this.mapTypeOf(context);
12665
+ if (!built || built.kind !== "record")
12666
+ return false;
12667
+ return this.widthLiftPlan(built, expected) === null;
12668
+ }
12183
12669
  /** An array literal or a `new Map(...)`, `new Set(...)` or `new
12184
12670
  * Array(...)` of the builtins: a fresh collection, never a thenable, so
12185
12671
  * an async return takes the declared result type as its construction
@@ -12207,6 +12693,20 @@ export class Lowerer {
12207
12693
  isJsSourceFile(ts.getSourceFileOfNode(node)) &&
12208
12694
  ts.isObjectLiteralExpression(literal));
12209
12695
  }
12696
+ /** Whether `node`'s TS type is a `Promise<never>` (the throw-only async
12697
+ * function's declared result): the promise can never settle, so the value
12698
+ * it would resolve to is unreachable. The IR keeps `Promise<never>` as a
12699
+ * promise with a void payload, exactly like `Promise<void>`, so the TS
12700
+ * payload type is what separates the two. */
12701
+ promisePayloadIsNever(node) {
12702
+ const t = this.typeOf(node);
12703
+ if ((t.flags & ts.TypeFlags.Object) === 0)
12704
+ return false;
12705
+ if ((t.objectFlags & ts.ObjectFlags.Reference) === 0)
12706
+ return false;
12707
+ const args = this.checker.getTypeArguments(t);
12708
+ return args.length === 1 && (args[0].flags & ts.TypeFlags.Never) !== 0;
12709
+ }
12210
12710
  /** The value of `return <e>` (already lowered untyped) in an async or
12211
12711
  * void context: a promise flattens through the returned-promise await,
12212
12712
  * everything else converts into the declared result. */
@@ -12215,6 +12715,13 @@ export class Lowerer {
12215
12715
  return null;
12216
12716
  if (this.ctx.isAsync && e.type.kind === "promise" && expected.kind !== "promise") {
12217
12717
  const awaited = this.returnedPromiseAwait(e);
12718
+ // A `Promise<never>` never settles, so the awaited value is
12719
+ // unreachable: it fills any result shape instead of failing the
12720
+ // void-to-record conversion.
12721
+ if (expected.kind !== "void" &&
12722
+ e.type.inner.kind === "void" &&
12723
+ this.promisePayloadIsNever(node))
12724
+ return this.divergentValue(awaited, expected);
12218
12725
  return this.coerceInto(node, awaited, expected);
12219
12726
  }
12220
12727
  return this.coerceInto(node, e, expected);
@@ -12324,7 +12831,8 @@ export class Lowerer {
12324
12831
  }
12325
12832
  if (this.adoptsReturnedPromise() &&
12326
12833
  !this.returnsLiteralIntoDyn(node, expected) &&
12327
- !this.returnsFreshCollection(node)) {
12834
+ !this.returnsFreshCollection(node) &&
12835
+ !this.returnsFreshRecord(node, expected)) {
12328
12836
  // The async return lowers its operand untyped first (a promise
12329
12837
  // adopts before its payload converts); a maybe-promise union needs
12330
12838
  // the statement form, which branches between adoption and fulfillment.
@@ -12436,6 +12944,10 @@ export class Lowerer {
12436
12944
  * undefined-armed union fields, which can be absent, and `true` for
12437
12945
  * every other declared field. */
12438
12946
  recordFieldPresent(obj, shapeId, field, loc) {
12947
+ // A partial record view (partial-assertions.ts) can lack a field its
12948
+ // asserted literal never wrote, whatever the field's required type.
12949
+ if (partialAssertionFields(this, shapeId).has(field))
12950
+ return { kind: "recordHas", obj, shapeId, field, type: BOOL, loc };
12439
12951
  const f = this.shapes.get(shapeId)?.fields.find((x) => x.name === field);
12440
12952
  if (f && f.type.kind === "union" && this.armTag(f.type.unionId, UNDEFINED_T) >= 0) {
12441
12953
  return { kind: "recordHas", obj, shapeId, field, type: BOOL, loc };
@@ -13739,6 +14251,14 @@ export class Lowerer {
13739
14251
  this.rejectUnresolvedSymbol(this.resolveValueSymbol(ident), ident.text, ident, fallback);
13740
14252
  }
13741
14253
  rejectUnresolvedSymbol(symbol, name, node, fallback) {
14254
+ // A `.js` WRITE to a name nothing declares. Sloppy mode resolves it by
14255
+ // creating a property on the global object — process-wide state a native
14256
+ // binary has no object for, so those programs run in a Node island
14257
+ // (plan D-5). Until the write is routed there it is refused by name
14258
+ // rather than by the generic no-lowering text.
14259
+ if (symbol === null && isJsWriteTarget7(node) && isJsSourceFile(ts.getSourceFileOfNode(node))) {
14260
+ this.unsupported("SC1091", node, `writing the undeclared name '${name}' in a JavaScript source`);
14261
+ }
13742
14262
  if (this.isBlockedBinding(symbol)) {
13743
14263
  this.pushDiag(blockedBindingUseDiag(name, locOf(node)));
13744
14264
  throw new PoisonError();
@@ -14355,6 +14875,7 @@ export class Lowerer {
14355
14875
  : null;
14356
14876
  }
14357
14877
  fieldSetStmt(target, value, loc, blame) {
14878
+ refuseHeldEnvWrite(this, blame);
14358
14879
  return markSloppyRecordWrites(this, fieldSetStmt(this, target, value, loc, blame), blame);
14359
14880
  }
14360
14881
  lowerFieldCompound(access, op, rhsNode, loc) {
@@ -14851,6 +15372,8 @@ export class Lowerer {
14851
15372
  const valueParams = fn.valueParams;
14852
15373
  if (!valueParams)
14853
15374
  return null;
15375
+ if (fn.checked?.only)
15376
+ return checkedNativeCallableValue(this, fn, display, loc);
14854
15377
  const shapes = valueParams.map((param) => {
14855
15378
  if (param.mode === "rest")
14856
15379
  return { mode: "rest", type: arrayOf(param.type) };
@@ -14951,8 +15474,21 @@ export class Lowerer {
14951
15474
  loc,
14952
15475
  });
14953
15476
  }
15477
+ if (valueParams.some((param) => param.name !== undefined)) {
15478
+ this.builtinCheckedValues.set(fnName, { fn, display, loc });
15479
+ }
14954
15480
  return { kind: "closure", fnName, captures: [], type: funcType, loc };
14955
15481
  }
15482
+ /** A builtin function value about to become untyped: its checked twin
15483
+ * when the builtin names its parameters (checkedNativeCallableValue), so
15484
+ * untyped callers meet Node's argument validation. Typed slots keep the
15485
+ * typed adapter. */
15486
+ checkedBuiltinValue(expr) {
15487
+ const checked = expr.kind === "closure" ? this.builtinCheckedValues.get(expr.fnName) : undefined;
15488
+ return checked
15489
+ ? checkedNativeCallableValue(this, checked.fn, checked.display, checked.loc)
15490
+ : expr;
15491
+ }
14956
15492
  /** The name and length a builtin function's adapter boxes under: the ones
14957
15493
  * Node's function carries (`[Function: randomUUID]`). Empty for any other
14958
15494
  * value. */