@scriptc/compiler 0.2.5 → 0.2.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 (520) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +62 -48
  2. package/dist/backend/cycle-analysis.d.ts +21 -9
  3. package/dist/backend/cycle-analysis.js +139 -67
  4. package/dist/backend/cycle-analysis.js.map +1 -1
  5. package/dist/backend/cycle-analysis.test.js +283 -3
  6. package/dist/backend/cycle-analysis.test.js.map +1 -1
  7. package/dist/backend/cycle-mutability.d.ts +39 -0
  8. package/dist/backend/cycle-mutability.js +205 -0
  9. package/dist/backend/cycle-mutability.js.map +1 -0
  10. package/dist/backend/executable-features.js +1 -0
  11. package/dist/backend/executable-features.js.map +1 -1
  12. package/dist/backend/link-plan-core.d.ts +4 -1
  13. package/dist/backend/link-plan-core.js +16 -3
  14. package/dist/backend/link-plan-core.js.map +1 -1
  15. package/dist/backend/link-plan.d.ts +3 -1
  16. package/dist/backend/link-plan.js +3 -0
  17. package/dist/backend/link-plan.js.map +1 -1
  18. package/dist/backend/llvm/alloc.d.ts +40 -0
  19. package/dist/backend/llvm/alloc.js +205 -0
  20. package/dist/backend/llvm/alloc.js.map +1 -0
  21. package/dist/backend/llvm/alloc.test.d.ts +1 -0
  22. package/dist/backend/llvm/alloc.test.js +102 -0
  23. package/dist/backend/llvm/alloc.test.js.map +1 -0
  24. package/dist/backend/llvm/byte-numbers.js +32 -4
  25. package/dist/backend/llvm/byte-numbers.js.map +1 -1
  26. package/dist/backend/llvm/byte-windows.d.ts +31 -0
  27. package/dist/backend/llvm/byte-windows.js +334 -0
  28. package/dist/backend/llvm/byte-windows.js.map +1 -0
  29. package/dist/backend/llvm/byte-windows.test.d.ts +1 -0
  30. package/dist/backend/llvm/byte-windows.test.js +244 -0
  31. package/dist/backend/llvm/byte-windows.test.js.map +1 -0
  32. package/dist/backend/llvm/call-lifetimes.d.ts +17 -5
  33. package/dist/backend/llvm/call-lifetimes.js +58 -24
  34. package/dist/backend/llvm/call-lifetimes.js.map +1 -1
  35. package/dist/backend/llvm/call-lifetimes.test.js +170 -0
  36. package/dist/backend/llvm/call-lifetimes.test.js.map +1 -1
  37. package/dist/backend/llvm/classes.d.ts +18 -2
  38. package/dist/backend/llvm/classes.js +115 -41
  39. package/dist/backend/llvm/classes.js.map +1 -1
  40. package/dist/backend/llvm/classes.test.d.ts +1 -0
  41. package/dist/backend/llvm/classes.test.js +132 -0
  42. package/dist/backend/llvm/classes.test.js.map +1 -0
  43. package/dist/backend/llvm/common.d.ts +13 -0
  44. package/dist/backend/llvm/common.js +30 -0
  45. package/dist/backend/llvm/common.js.map +1 -1
  46. package/dist/backend/llvm/constant-callbacks.d.ts +27 -0
  47. package/dist/backend/llvm/constant-callbacks.js +450 -0
  48. package/dist/backend/llvm/constant-callbacks.js.map +1 -0
  49. package/dist/backend/llvm/constant-callbacks.test.d.ts +1 -0
  50. package/dist/backend/llvm/constant-callbacks.test.js +261 -0
  51. package/dist/backend/llvm/constant-callbacks.test.js.map +1 -0
  52. package/dist/backend/llvm/dense-array-access.d.ts +29 -0
  53. package/dist/backend/llvm/dense-array-access.js +335 -0
  54. package/dist/backend/llvm/dense-array-access.js.map +1 -0
  55. package/dist/backend/llvm/dense-array-access.test.d.ts +1 -0
  56. package/dist/backend/llvm/dense-array-access.test.js +149 -0
  57. package/dist/backend/llvm/dense-array-access.test.js.map +1 -0
  58. package/dist/backend/llvm/dyn.d.ts +35 -1
  59. package/dist/backend/llvm/dyn.js +196 -35
  60. package/dist/backend/llvm/dyn.js.map +1 -1
  61. package/dist/backend/llvm/emitter.d.ts +143 -4
  62. package/dist/backend/llvm/emitter.js +882 -136
  63. package/dist/backend/llvm/emitter.js.map +1 -1
  64. package/dist/backend/llvm/emitter.test.js +82 -14
  65. package/dist/backend/llvm/emitter.test.js.map +1 -1
  66. package/dist/backend/llvm/expr-async.js +58 -4
  67. package/dist/backend/llvm/expr-async.js.map +1 -1
  68. package/dist/backend/llvm/expr-async.test.d.ts +1 -0
  69. package/dist/backend/llvm/expr-async.test.js +62 -0
  70. package/dist/backend/llvm/expr-async.test.js.map +1 -0
  71. package/dist/backend/llvm/expr-bytes.js +11 -0
  72. package/dist/backend/llvm/expr-bytes.js.map +1 -1
  73. package/dist/backend/llvm/expr-calls.js +151 -25
  74. package/dist/backend/llvm/expr-calls.js.map +1 -1
  75. package/dist/backend/llvm/expr-containers.js +37 -14
  76. package/dist/backend/llvm/expr-containers.js.map +1 -1
  77. package/dist/backend/llvm/expr-control.js +92 -2
  78. package/dist/backend/llvm/expr-control.js.map +1 -1
  79. package/dist/backend/llvm/expr-dispatch.js +2 -0
  80. package/dist/backend/llvm/expr-dispatch.js.map +1 -1
  81. package/dist/backend/llvm/expr-dynamic.js +210 -28
  82. package/dist/backend/llvm/expr-dynamic.js.map +1 -1
  83. package/dist/backend/llvm/expr-primitives.d.ts +1 -1
  84. package/dist/backend/llvm/expr-primitives.js +58 -23
  85. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  86. package/dist/backend/llvm/expr-primitives.test.js +1 -1
  87. package/dist/backend/llvm/expr-records.js +3 -3
  88. package/dist/backend/llvm/expr-records.js.map +1 -1
  89. package/dist/backend/llvm/expr-stream-bridges.js +59 -2
  90. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  91. package/dist/backend/llvm/expr-stream-bridges.test.js +1 -1
  92. package/dist/backend/llvm/integer-remainder.d.ts +18 -0
  93. package/dist/backend/llvm/integer-remainder.js +117 -0
  94. package/dist/backend/llvm/integer-remainder.js.map +1 -0
  95. package/dist/backend/llvm/layouts.d.ts +2 -1
  96. package/dist/backend/llvm/layouts.js +4 -3
  97. package/dist/backend/llvm/layouts.js.map +1 -1
  98. package/dist/backend/llvm/lazy-captures.d.ts +16 -0
  99. package/dist/backend/llvm/lazy-captures.js +96 -0
  100. package/dist/backend/llvm/lazy-captures.js.map +1 -0
  101. package/dist/backend/llvm/lazy-captures.test.d.ts +1 -0
  102. package/dist/backend/llvm/lazy-captures.test.js +78 -0
  103. package/dist/backend/llvm/lazy-captures.test.js.map +1 -0
  104. package/dist/backend/llvm/lib-abi.js +7 -0
  105. package/dist/backend/llvm/lib-abi.js.map +1 -1
  106. package/dist/backend/llvm/lib-dispatch.js +7 -22
  107. package/dist/backend/llvm/lib-dispatch.js.map +1 -1
  108. package/dist/backend/llvm/lib-filesystem.js +3 -4
  109. package/dist/backend/llvm/lib-filesystem.js.map +1 -1
  110. package/dist/backend/llvm/lib-shared.js +15 -0
  111. package/dist/backend/llvm/lib-shared.js.map +1 -1
  112. package/dist/backend/llvm/local-array-reads.d.ts +13 -3
  113. package/dist/backend/llvm/local-array-reads.js +159 -77
  114. package/dist/backend/llvm/local-array-reads.js.map +1 -1
  115. package/dist/backend/llvm/local-array-reads.test.js +105 -4
  116. package/dist/backend/llvm/local-array-reads.test.js.map +1 -1
  117. package/dist/backend/llvm/local-union-storage.d.ts +5 -1
  118. package/dist/backend/llvm/local-union-storage.js +48 -6
  119. package/dist/backend/llvm/local-union-storage.js.map +1 -1
  120. package/dist/backend/llvm/local-union-storage.test.js +91 -4
  121. package/dist/backend/llvm/local-union-storage.test.js.map +1 -1
  122. package/dist/backend/llvm/loop-array-borrows.d.ts +11 -0
  123. package/dist/backend/llvm/loop-array-borrows.js +70 -0
  124. package/dist/backend/llvm/loop-array-borrows.js.map +1 -0
  125. package/dist/backend/llvm/loop-array-borrows.test.d.ts +1 -0
  126. package/dist/backend/llvm/loop-array-borrows.test.js +145 -0
  127. package/dist/backend/llvm/loop-array-borrows.test.js.map +1 -0
  128. package/dist/backend/llvm/map-read-lifetimes.d.ts +5 -0
  129. package/dist/backend/llvm/map-read-lifetimes.js +20 -5
  130. package/dist/backend/llvm/map-read-lifetimes.js.map +1 -1
  131. package/dist/backend/llvm/map-read-lifetimes.test.js +1 -1
  132. package/dist/backend/llvm/nullable-fields.d.ts +28 -0
  133. package/dist/backend/llvm/nullable-fields.js +45 -0
  134. package/dist/backend/llvm/nullable-fields.js.map +1 -0
  135. package/dist/backend/llvm/nullable-fields.test.d.ts +1 -0
  136. package/dist/backend/llvm/nullable-fields.test.js +48 -0
  137. package/dist/backend/llvm/nullable-fields.test.js.map +1 -0
  138. package/dist/backend/llvm/reference-effects.d.ts +2 -1
  139. package/dist/backend/llvm/reference-effects.js +7 -0
  140. package/dist/backend/llvm/reference-effects.js.map +1 -1
  141. package/dist/backend/llvm/serialized-ir-emission.test.d.ts +1 -0
  142. package/dist/backend/llvm/serialized-ir-emission.test.js +52 -0
  143. package/dist/backend/llvm/serialized-ir-emission.test.js.map +1 -0
  144. package/dist/backend/llvm/shapes.d.ts +73 -3
  145. package/dist/backend/llvm/shapes.js +281 -34
  146. package/dist/backend/llvm/shapes.js.map +1 -1
  147. package/dist/backend/llvm/shapes.test.js +114 -5
  148. package/dist/backend/llvm/shapes.test.js.map +1 -1
  149. package/dist/backend/llvm/split-loops.d.ts +48 -0
  150. package/dist/backend/llvm/split-loops.js +183 -0
  151. package/dist/backend/llvm/split-loops.js.map +1 -0
  152. package/dist/backend/llvm/split.js +0 -7
  153. package/dist/backend/llvm/split.js.map +1 -1
  154. package/dist/backend/llvm/split.test.js +66 -2
  155. package/dist/backend/llvm/split.test.js.map +1 -1
  156. package/dist/backend/llvm/stack-callbacks.d.ts +14 -0
  157. package/dist/backend/llvm/stack-callbacks.js +72 -0
  158. package/dist/backend/llvm/stack-callbacks.js.map +1 -0
  159. package/dist/backend/llvm/stack-captures.d.ts +27 -0
  160. package/dist/backend/llvm/stack-captures.js +152 -0
  161. package/dist/backend/llvm/stack-captures.js.map +1 -0
  162. package/dist/backend/llvm/stack-unions.test.js +38 -1
  163. package/dist/backend/llvm/stack-unions.test.js.map +1 -1
  164. package/dist/backend/llvm/string-construction.test.js +1 -1
  165. package/dist/backend/llvm/string-key-hash.d.ts +8 -0
  166. package/dist/backend/llvm/string-key-hash.js +59 -0
  167. package/dist/backend/llvm/string-key-hash.js.map +1 -0
  168. package/dist/backend/llvm/string-key-hash.test.d.ts +1 -0
  169. package/dist/backend/llvm/string-key-hash.test.js +34 -0
  170. package/dist/backend/llvm/string-key-hash.test.js.map +1 -0
  171. package/dist/backend/llvm/string-lifetimes.test.js +48 -7
  172. package/dist/backend/llvm/string-lifetimes.test.js.map +1 -1
  173. package/dist/backend/llvm/string-slices.d.ts +20 -0
  174. package/dist/backend/llvm/string-slices.js +87 -0
  175. package/dist/backend/llvm/string-slices.js.map +1 -0
  176. package/dist/backend/llvm/string-slices.test.d.ts +1 -0
  177. package/dist/backend/llvm/string-slices.test.js +98 -0
  178. package/dist/backend/llvm/string-slices.test.js.map +1 -0
  179. package/dist/backend/llvm/switch-dispatch.js +1 -1
  180. package/dist/backend/llvm/switch-dispatch.js.map +1 -1
  181. package/dist/backend/llvm/switch-dispatch.test.js +2 -2
  182. package/dist/backend/llvm/switch-dispatch.test.js.map +1 -1
  183. package/dist/backend/llvm/walkers.d.ts +4 -14
  184. package/dist/backend/llvm/walkers.js +53 -311
  185. package/dist/backend/llvm/walkers.js.map +1 -1
  186. package/dist/backend/may-throw.js +4 -1
  187. package/dist/backend/may-throw.js.map +1 -1
  188. package/dist/backend/may-throw.test.js +1 -1
  189. package/dist/backend/native/cache-warm.d.ts +2 -1
  190. package/dist/backend/native/cache-warm.js.map +1 -1
  191. package/dist/backend/native/contracts.d.ts +5 -2
  192. package/dist/backend/native/contracts.js.map +1 -1
  193. package/dist/backend/native/executable.js +12 -4
  194. package/dist/backend/native/executable.js.map +1 -1
  195. package/dist/backend/native/runtime-inputs.d.ts +1 -1
  196. package/dist/backend/native/runtime-inputs.js +3 -0
  197. package/dist/backend/native/runtime-inputs.js.map +1 -1
  198. package/dist/backend/native-codegen-core.d.ts +7 -0
  199. package/dist/backend/native-codegen-core.js +21 -0
  200. package/dist/backend/native-codegen-core.js.map +1 -1
  201. package/dist/backend/native-codegen.d.ts +9 -0
  202. package/dist/backend/native-codegen.js +38 -18
  203. package/dist/backend/native-codegen.js.map +1 -1
  204. package/dist/backend/native-codegen.test.js +70 -2
  205. package/dist/backend/native-codegen.test.js.map +1 -1
  206. package/dist/backend/native-link-info-core.d.ts +4 -2
  207. package/dist/backend/native-link-info-core.js.map +1 -1
  208. package/dist/backend/native-link-info.d.ts +2 -1
  209. package/dist/backend/native-link-info.js.map +1 -1
  210. package/dist/backend/native-link-info.test.js +2 -2
  211. package/dist/backend/native-link-info.test.js.map +1 -1
  212. package/dist/backend/native-tools.d.ts +6 -2
  213. package/dist/backend/native-tools.js +6 -5
  214. package/dist/backend/native-tools.js.map +1 -1
  215. package/dist/backend/optimization.d.ts +25 -0
  216. package/dist/backend/optimization.js +21 -0
  217. package/dist/backend/optimization.js.map +1 -0
  218. package/dist/backend/optimization.test.d.ts +1 -0
  219. package/dist/backend/optimization.test.js +24 -0
  220. package/dist/backend/optimization.test.js.map +1 -0
  221. package/dist/backend/runtime-abi.d.ts +2 -2
  222. package/dist/backend/runtime-abi.js +2 -2
  223. package/dist/backend/runtime-pack-core.d.ts +16 -4
  224. package/dist/backend/runtime-pack-core.js +31 -13
  225. package/dist/backend/runtime-pack-core.js.map +1 -1
  226. package/dist/backend/runtime-pack-native.d.ts +7 -3
  227. package/dist/backend/runtime-pack-native.js +0 -3
  228. package/dist/backend/runtime-pack-native.js.map +1 -1
  229. package/dist/backend/runtime-pack-targets.test.js +41 -4
  230. package/dist/backend/runtime-pack-targets.test.js.map +1 -1
  231. package/dist/backend/runtime-pack.d.ts +20 -2
  232. package/dist/backend/runtime-pack.js +23 -0
  233. package/dist/backend/runtime-pack.js.map +1 -1
  234. package/dist/backend/runtime-pack.test.js +125 -2
  235. package/dist/backend/runtime-pack.test.js.map +1 -1
  236. package/dist/backend/target-diagnostics.test.js +1 -1
  237. package/dist/backend/targets.d.ts +2 -1
  238. package/dist/backend/targets.js +1 -1
  239. package/dist/backend/targets.js.map +1 -1
  240. package/dist/cli/command.js +5 -4
  241. package/dist/cli/command.js.map +1 -1
  242. package/dist/cli/host.d.ts +2 -1
  243. package/dist/cli/usage.d.ts +1 -1
  244. package/dist/cli/usage.js +5 -2
  245. package/dist/cli/usage.js.map +1 -1
  246. package/dist/compile-types.d.ts +5 -2
  247. package/dist/diagnostics/diagnostic.js +10 -8
  248. package/dist/diagnostics/diagnostic.js.map +1 -1
  249. package/dist/executable/executable-cache.d.ts +3 -2
  250. package/dist/executable/executable-cache.js +8 -4
  251. package/dist/executable/executable-cache.js.map +1 -1
  252. package/dist/executable/executable-cache.test.js +35 -0
  253. package/dist/executable/executable-cache.test.js.map +1 -1
  254. package/dist/frontend/fork-target.d.ts +5 -0
  255. package/dist/frontend/fork-target.js +40 -8
  256. package/dist/frontend/fork-target.js.map +1 -1
  257. package/dist/frontend/fork-target.test.d.ts +1 -0
  258. package/dist/frontend/fork-target.test.js +59 -0
  259. package/dist/frontend/fork-target.test.js.map +1 -0
  260. package/dist/frontend/lowering/abstract-equality.js +5 -49
  261. package/dist/frontend/lowering/abstract-equality.js.map +1 -1
  262. package/dist/frontend/lowering/array-values.d.ts +23 -0
  263. package/dist/frontend/lowering/array-values.js +129 -0
  264. package/dist/frontend/lowering/array-values.js.map +1 -1
  265. package/dist/frontend/lowering/binding-analysis.js +2 -2
  266. package/dist/frontend/lowering/binding-analysis.js.map +1 -1
  267. package/dist/frontend/lowering/builtins/atomics.d.ts +2 -11
  268. package/dist/frontend/lowering/builtins/atomics.js +64 -28
  269. package/dist/frontend/lowering/builtins/atomics.js.map +1 -1
  270. package/dist/frontend/lowering/builtins/errors.js +17 -2
  271. package/dist/frontend/lowering/builtins/errors.js.map +1 -1
  272. package/dist/frontend/lowering/builtins/filesystem-calls.d.ts +3 -0
  273. package/dist/frontend/lowering/builtins/filesystem-calls.js +51 -4
  274. package/dist/frontend/lowering/builtins/filesystem-calls.js.map +1 -1
  275. package/dist/frontend/lowering/builtins/module-calls.js +6 -1
  276. package/dist/frontend/lowering/builtins/module-calls.js.map +1 -1
  277. package/dist/frontend/lowering/builtins/process.d.ts +6 -17
  278. package/dist/frontend/lowering/builtins/process.js +56 -29
  279. package/dist/frontend/lowering/builtins/process.js.map +1 -1
  280. package/dist/frontend/lowering/builtins/workers.d.ts +5 -0
  281. package/dist/frontend/lowering/builtins/workers.js +65 -0
  282. package/dist/frontend/lowering/builtins/workers.js.map +1 -0
  283. package/dist/frontend/lowering/caught-value-dispatch.d.ts +11 -0
  284. package/dist/frontend/lowering/caught-value-dispatch.js +87 -0
  285. package/dist/frontend/lowering/caught-value-dispatch.js.map +1 -0
  286. package/dist/frontend/lowering/class-assertions.d.ts +11 -0
  287. package/dist/frontend/lowering/class-assertions.js +104 -0
  288. package/dist/frontend/lowering/class-assertions.js.map +1 -0
  289. package/dist/frontend/lowering/class-callbacks.d.ts +3 -3
  290. package/dist/frontend/lowering/class-callbacks.js +18 -5
  291. package/dist/frontend/lowering/class-callbacks.js.map +1 -1
  292. package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +1 -0
  293. package/dist/frontend/lowering/class-dynamic-dispatch.js +4 -1
  294. package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
  295. package/dist/frontend/lowering/class-method-mutations.d.ts +5 -0
  296. package/dist/frontend/lowering/class-method-mutations.js +472 -0
  297. package/dist/frontend/lowering/class-method-mutations.js.map +1 -0
  298. package/dist/frontend/lowering/class-method-values.js +25 -5
  299. package/dist/frontend/lowering/class-method-values.js.map +1 -1
  300. package/dist/frontend/lowering/class-protocols.d.ts +17 -0
  301. package/dist/frontend/lowering/class-protocols.js +126 -0
  302. package/dist/frontend/lowering/class-protocols.js.map +1 -0
  303. package/dist/frontend/lowering/class-prototypes.js +8 -2
  304. package/dist/frontend/lowering/class-prototypes.js.map +1 -1
  305. package/dist/frontend/lowering/class-unions.d.ts +16 -0
  306. package/dist/frontend/lowering/class-unions.js +127 -0
  307. package/dist/frontend/lowering/class-unions.js.map +1 -0
  308. package/dist/frontend/lowering/coercions/builders.js +8 -1
  309. package/dist/frontend/lowering/coercions/builders.js.map +1 -1
  310. package/dist/frontend/lowering/coercions/function-adapters.js +2 -0
  311. package/dist/frontend/lowering/coercions/function-adapters.js.map +1 -1
  312. package/dist/frontend/lowering/coercions/identity.d.ts +7 -0
  313. package/dist/frontend/lowering/coercions/identity.js +26 -0
  314. package/dist/frontend/lowering/coercions/identity.js.map +1 -0
  315. package/dist/frontend/lowering/coercions/structural.js +9 -6
  316. package/dist/frontend/lowering/coercions/structural.js.map +1 -1
  317. package/dist/frontend/lowering/collection-narrowing.d.ts +6 -0
  318. package/dist/frontend/lowering/collection-narrowing.js +31 -0
  319. package/dist/frontend/lowering/collection-narrowing.js.map +1 -0
  320. package/dist/frontend/lowering/containers/array-callback-call.d.ts +7 -0
  321. package/dist/frontend/lowering/containers/array-callback-call.js +52 -0
  322. package/dist/frontend/lowering/containers/array-callback-call.js.map +1 -0
  323. package/dist/frontend/lowering/containers/array-callbacks.d.ts +8 -12
  324. package/dist/frontend/lowering/containers/array-callbacks.js +415 -136
  325. package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
  326. package/dist/frontend/lowering/containers/array-concat.d.ts +7 -0
  327. package/dist/frontend/lowering/containers/array-concat.js +130 -0
  328. package/dist/frontend/lowering/containers/array-concat.js.map +1 -0
  329. package/dist/frontend/lowering/containers/array-construction.d.ts +2 -0
  330. package/dist/frontend/lowering/containers/array-construction.js +95 -3
  331. package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
  332. package/dist/frontend/lowering/containers/array-methods.d.ts +1 -11
  333. package/dist/frontend/lowering/containers/array-methods.js +43 -132
  334. package/dist/frontend/lowering/containers/array-methods.js.map +1 -1
  335. package/dist/frontend/lowering/containers/bytes.js +12 -34
  336. package/dist/frontend/lowering/containers/bytes.js.map +1 -1
  337. package/dist/frontend/lowering/containers/collection-methods.js +10 -1
  338. package/dist/frontend/lowering/containers/collection-methods.js.map +1 -1
  339. package/dist/frontend/lowering/containers/indexed-objects.js +56 -70
  340. package/dist/frontend/lowering/containers/indexed-objects.js.map +1 -1
  341. package/dist/frontend/lowering/containers/string-and-regexp.js +22 -3
  342. package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
  343. package/dist/frontend/lowering/cycle-initialization.d.ts +41 -0
  344. package/dist/frontend/lowering/cycle-initialization.js +277 -0
  345. package/dist/frontend/lowering/cycle-initialization.js.map +1 -0
  346. package/dist/frontend/lowering/expressions/evaluation-safety.js +4 -0
  347. package/dist/frontend/lowering/expressions/evaluation-safety.js.map +1 -1
  348. package/dist/frontend/lowering/expressions/object-literals.js +140 -38
  349. package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
  350. package/dist/frontend/lowering/expressions/union-field-write.d.ts +4 -4
  351. package/dist/frontend/lowering/expressions/union-field-write.js +54 -44
  352. package/dist/frontend/lowering/expressions/union-field-write.js.map +1 -1
  353. package/dist/frontend/lowering/generic-functions.d.ts +2 -5
  354. package/dist/frontend/lowering/generic-functions.js +13 -10
  355. package/dist/frontend/lowering/generic-functions.js.map +1 -1
  356. package/dist/frontend/lowering/instantiation-path.d.ts +8 -0
  357. package/dist/frontend/lowering/instantiation-path.js +10 -0
  358. package/dist/frontend/lowering/instantiation-path.js.map +1 -0
  359. package/dist/frontend/lowering/instantiation-path.test.d.ts +1 -0
  360. package/dist/frontend/lowering/instantiation-path.test.js +23 -0
  361. package/dist/frontend/lowering/instantiation-path.test.js.map +1 -0
  362. package/dist/frontend/lowering/iterator-adapters.d.ts +20 -0
  363. package/dist/frontend/lowering/iterator-adapters.js +605 -0
  364. package/dist/frontend/lowering/iterator-adapters.js.map +1 -0
  365. package/dist/frontend/lowering/lower-array-sort.d.ts +1 -1
  366. package/dist/frontend/lowering/lower-array-sort.js +44 -5
  367. package/dist/frontend/lowering/lower-array-sort.js.map +1 -1
  368. package/dist/frontend/lowering/lower-array-sort.test.d.ts +1 -0
  369. package/dist/frontend/lowering/lower-array-sort.test.js +31 -0
  370. package/dist/frontend/lowering/lower-array-sort.test.js.map +1 -0
  371. package/dist/frontend/lowering/lower-assert.js +7 -0
  372. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  373. package/dist/frontend/lowering/lower-builtin-values.js +12 -7
  374. package/dist/frontend/lowering/lower-builtin-values.js.map +1 -1
  375. package/dist/frontend/lowering/lower-calls.d.ts +3 -3
  376. package/dist/frontend/lowering/lower-calls.js +198 -124
  377. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  378. package/dist/frontend/lowering/lower-classes.d.ts +7 -0
  379. package/dist/frontend/lowering/lower-classes.js +166 -96
  380. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  381. package/dist/frontend/lowering/lower-event-emitter.js +1 -1
  382. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
  383. package/dist/frontend/lowering/lower-exprs.d.ts +9 -2
  384. package/dist/frontend/lowering/lower-exprs.js +421 -167
  385. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  386. package/dist/frontend/lowering/lower-functions.d.ts +1 -1
  387. package/dist/frontend/lowering/lower-functions.js +33 -20
  388. package/dist/frontend/lowering/lower-functions.js.map +1 -1
  389. package/dist/frontend/lowering/lower-inspect.js +26 -2
  390. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  391. package/dist/frontend/lowering/lower-island.js +1 -1
  392. package/dist/frontend/lowering/lower-island.js.map +1 -1
  393. package/dist/frontend/lowering/lower-modules.d.ts +1 -0
  394. package/dist/frontend/lowering/lower-modules.js +54 -11
  395. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  396. package/dist/frontend/lowering/lower-stmts.js +59 -69
  397. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  398. package/dist/frontend/lowering/lower-stream.js +1 -1
  399. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  400. package/dist/frontend/lowering/lowerer.d.ts +50 -1
  401. package/dist/frontend/lowering/lowerer.js +333 -26
  402. package/dist/frontend/lowering/lowerer.js.map +1 -1
  403. package/dist/frontend/lowering/native-ffi.js +3 -1
  404. package/dist/frontend/lowering/native-ffi.js.map +1 -1
  405. package/dist/frontend/lowering/runtime-optional-provenance.d.ts +15 -0
  406. package/dist/frontend/lowering/runtime-optional-provenance.js +40 -0
  407. package/dist/frontend/lowering/runtime-optional-provenance.js.map +1 -0
  408. package/dist/frontend/lowering/sanitize-class-types.test.js +2 -2
  409. package/dist/frontend/lowering/split-consumers.d.ts +7 -0
  410. package/dist/frontend/lowering/split-consumers.js +64 -0
  411. package/dist/frontend/lowering/split-consumers.js.map +1 -0
  412. package/dist/frontend/lowering/strict-equality.d.ts +9 -0
  413. package/dist/frontend/lowering/strict-equality.js +116 -0
  414. package/dist/frontend/lowering/strict-equality.js.map +1 -0
  415. package/dist/frontend/lowering/surfaces.d.ts +3 -4
  416. package/dist/frontend/lowering/surfaces.js +38 -7
  417. package/dist/frontend/lowering/surfaces.js.map +1 -1
  418. package/dist/frontend/lowering/union-comparison.d.ts +5 -0
  419. package/dist/frontend/lowering/union-comparison.js +47 -0
  420. package/dist/frontend/lowering/union-comparison.js.map +1 -0
  421. package/dist/frontend/module-source-candidates.d.ts +10 -0
  422. package/dist/frontend/module-source-candidates.js +40 -0
  423. package/dist/frontend/module-source-candidates.js.map +1 -0
  424. package/dist/frontend/module-source-candidates.test.d.ts +1 -0
  425. package/dist/frontend/module-source-candidates.test.js +53 -0
  426. package/dist/frontend/module-source-candidates.test.js.map +1 -0
  427. package/dist/frontend/pipeline.js +2 -2
  428. package/dist/frontend/pipeline.js.map +1 -1
  429. package/dist/frontend/program-analysis.d.ts +2 -0
  430. package/dist/frontend/program-analysis.js +2 -0
  431. package/dist/frontend/program-analysis.js.map +1 -1
  432. package/dist/frontend/program.d.ts +38 -2
  433. package/dist/frontend/program.js +457 -88
  434. package/dist/frontend/program.js.map +1 -1
  435. package/dist/frontend/program.test.js +59 -6
  436. package/dist/frontend/program.test.js.map +1 -1
  437. package/dist/frontend/ts7/ast-node.js +6 -8
  438. package/dist/frontend/ts7/ast-node.js.map +1 -1
  439. package/dist/frontend/ts7/ast-node.test.js +42 -1
  440. package/dist/frontend/ts7/ast-node.test.js.map +1 -1
  441. package/dist/frontend/ts7/ast-wire.d.ts +4 -0
  442. package/dist/frontend/ts7/ast-wire.js +28 -0
  443. package/dist/frontend/ts7/ast-wire.js.map +1 -1
  444. package/dist/frontend/ts7/ast.d.ts +2 -1
  445. package/dist/frontend/ts7/ast.js +8 -4
  446. package/dist/frontend/ts7/ast.js.map +1 -1
  447. package/dist/frontend/ts7/checker.d.ts +8 -2
  448. package/dist/frontend/ts7/checker.js +41 -5
  449. package/dist/frontend/ts7/checker.js.map +1 -1
  450. package/dist/frontend/ts7/checker.test.js +42 -0
  451. package/dist/frontend/ts7/checker.test.js.map +1 -1
  452. package/dist/frontend/ts7/program-host.d.ts +7 -0
  453. package/dist/frontend/ts7/program-host.js +26 -2
  454. package/dist/frontend/ts7/program-host.js.map +1 -1
  455. package/dist/frontend/ts7/program-host.test.js +29 -0
  456. package/dist/frontend/ts7/program-host.test.js.map +1 -1
  457. package/dist/frontend/type-mapper.d.ts +4 -1
  458. package/dist/frontend/type-mapper.js +133 -16
  459. package/dist/frontend/type-mapper.js.map +1 -1
  460. package/dist/frontend/type-mapper.test.js +15 -3
  461. package/dist/frontend/type-mapper.test.js.map +1 -1
  462. package/dist/frontend/worker-target.d.ts +6 -0
  463. package/dist/frontend/worker-target.js +108 -0
  464. package/dist/frontend/worker-target.js.map +1 -0
  465. package/dist/frontend/worker-target.test.d.ts +1 -0
  466. package/dist/frontend/worker-target.test.js +71 -0
  467. package/dist/frontend/worker-target.test.js.map +1 -0
  468. package/dist/index.js +47 -14
  469. package/dist/index.js.map +1 -1
  470. package/dist/ir/analysis.d.ts +3 -1
  471. package/dist/ir/analysis.js +4 -0
  472. package/dist/ir/analysis.js.map +1 -1
  473. package/dist/ir/builtin-effects.js +12 -0
  474. package/dist/ir/builtin-effects.js.map +1 -1
  475. package/dist/ir/builtin-signatures.d.ts +1 -1
  476. package/dist/ir/builtin-signatures.js +15 -15
  477. package/dist/ir/builtin-signatures.js.map +1 -1
  478. package/dist/ir/constant-tables.test.js +1 -1
  479. package/dist/ir/initializer-bindings.test.js +1 -1
  480. package/dist/ir/ir.d.ts +85 -23
  481. package/dist/ir/ir.js +20 -6
  482. package/dist/ir/ir.js.map +1 -1
  483. package/dist/ir/numeric-call-specialization.d.ts +8 -0
  484. package/dist/ir/numeric-call-specialization.js +198 -0
  485. package/dist/ir/numeric-call-specialization.js.map +1 -0
  486. package/dist/ir/runtime-features.js +4 -3
  487. package/dist/ir/runtime-features.js.map +1 -1
  488. package/dist/ir/scalar-records.test.js +1 -1
  489. package/dist/ir/serialize.d.ts +1 -1
  490. package/dist/ir/serialize.js +3 -3
  491. package/dist/ir/serialize.js.map +1 -1
  492. package/dist/ir/traverse.js +8 -0
  493. package/dist/ir/traverse.js.map +1 -1
  494. package/dist/ir/validate.js +207 -43
  495. package/dist/ir/validate.js.map +1 -1
  496. package/dist/ir/validate.test.js +356 -8
  497. package/dist/ir/validate.test.js.map +1 -1
  498. package/dist/library/fence-eval.test.js +1 -1
  499. package/dist/library/int-infer.test.js +4 -4
  500. package/dist/library/ir-policy.js +2 -0
  501. package/dist/library/ir-policy.js.map +1 -1
  502. package/dist/library/library-cache.test.js +5 -5
  503. package/dist/library/library-profile.d.ts +2 -1
  504. package/dist/library/library-profile.js +4 -3
  505. package/dist/library/library-profile.js.map +1 -1
  506. package/dist/native/compiler.js +24 -11
  507. package/dist/native/compiler.js.map +1 -1
  508. package/dist/native/compiler.test.js +7 -3
  509. package/dist/native/compiler.test.js.map +1 -1
  510. package/dist/native/library.d.ts +2 -1
  511. package/dist/native/library.js.map +1 -1
  512. package/dist/native/prepare.js +29 -3
  513. package/dist/native/prepare.js.map +1 -1
  514. package/dist/native/sanitizer.d.ts +3 -2
  515. package/dist/native/sanitizer.js +3 -13
  516. package/dist/native/sanitizer.js.map +1 -1
  517. package/dist/native/sanitizer.test.js +1 -0
  518. package/dist/native/sanitizer.test.js.map +1 -1
  519. package/package.json +20 -20
  520. package/surface-manifest.json +37 -3
@@ -1,4 +1,12 @@
1
+ import { checkCycleBindingAccesses, refuseUncheckedCycleReads, } from "./cycle-initialization.js";
2
+ import { identityPreservingWidening } from "./coercions/identity.js";
3
+ import { checkedClassAssertion } from "./class-assertions.js";
4
+ import { narrowStoredClassValue, narrowGenericClassValue } from "./class-unions.js";
5
+ import { isOptionalProcessStreamProperty } from "./builtins/process.js";
6
+ import { concreteCollectionNarrow } from "./collection-narrowing.js";
7
+ import { lowerWorkerMetadata } from "./builtins/workers.js";
1
8
  import { dynUndefinedExpr, nodeThrowExpr, numLit, varRef } from "../../ir/build.js";
9
+ import { iteratorSlotAdapter } from "./iterator-adapters.js";
2
10
  import { lowerBuiltinCall } from "./builtin-calls.js";
3
11
  import { CoercionState } from "./coercions/state.js";
4
12
  import { widthLiftPlan, unitOnlyElem, recordWidthPlan, describeRecordWidthBlocker, objToRecordPlan, recordToClassPlan, } from "./coercions/structural-plans.js";
@@ -8,6 +16,7 @@ import { unionRetagMappable, narrowedRetagHelper, strandedUnitTrap, strandedCoer
8
16
  import { jsvalLiftable, jsvalLiftExpr, unionToJsvalHelper, recordToJsvalHelper, arrayToJsvalHelper, arrayToJsvalArrayHelper, } from "./coercions/island.js";
9
17
  import { lowerUtilTypeValue, pathModuleValue, utilTypesModuleValue, } from "./lower-builtin-values.js";
10
18
  import { everyExprChild, everyStmtChild, transformStmtList } from "../../ir/traverse.js";
19
+ import { RuntimeOptionalProvenance } from "./runtime-optional-provenance.js";
11
20
  import { RuntimeOptionalLocals } from "./runtime-optional-locals.js";
12
21
  import { sanitizeUnregisteredClassTypes } from "./sanitize-class-types.js";
13
22
  import { UnregisteredClassTypes } from "./unregistered-class-types.js";
@@ -15,6 +24,7 @@ import { bindingInContext, captureContextBinding, declareContextLocal, declareCo
15
24
  import { InternalCompilerError } from "../../errors.js";
16
25
  import { defaultAfterUndefined, lowerStaticallyUndefinedArgument } from "./optional-arguments.js";
17
26
  import { ClassDynamicDispatch, trackClassFieldCreation } from "./class-dynamic-dispatch.js";
27
+ import { ClassProtocols } from "./class-protocols.js";
18
28
  import { DeferredModuleInitializers } from "./deferred-module-initializers.js";
19
29
  import { finalizeClassMethodValues } from "./class-method-values.js";
20
30
  export { newFnCtx } from "./function-context.js";
@@ -44,7 +54,7 @@ import { provenanceActive } from "../provenance-registry.js";
44
54
  import { ambientDtsPath, canonicalBuiltinModule, cjsExportAssignmentOf, cjsExportDiscardReason, fallbackDtsPath, isCjsExportTableLiteral, isCjsJsFile, isJsSourceFile, isNodeEsmFile, isNodeTypesPath, locOf, orderedImportsOf, overridesDtsPath, npmStaticDepSf7, requireSpecOf, resolveImport, workspacePackageOfPath, } from "../program.js";
45
55
  import { containsRecord, containsUnion, describeComponentBlocker, describeRecordMemberBlocker, formatIrType, ISLAND_AMBIENT_TYPES, isUnitOnlyTsType, jsOpenObjectType, mapType, ShapeRegistry, typeKey, UnionRegistry, withUndefinedArm as withUndefinedArmCanonical, } from "../type-mapper.js";
46
56
  import { boundaryIntoIslandMsg, boundaryOutOfIslandMsg, builtinConstLit, builtinModuleConstOf, builtinModulesArrayLit, builtinFenceHintOf, builtinModuleFnOf, stdlibMemberFence, isStdlibMember, isStdlibSymbol, isStdlibGlobal, stdlibGlobalNameOf, stdlibGlobalMember, nodeTypesOnlySymbol, } from "./surfaces.js";
47
- import { splitFiles, collectProgram, collectNpmImports, collectJsonImports, moduleArtifacts, collectGlobals, declSymbolOf, defaultExportSymbolOf, lowerFileInit, lowerDefaultExport, buildMain, appendDynamicImportModules, appendForkModules, } from "./lower-modules.js";
57
+ import { splitFiles, collectProgram, collectNpmImports, collectJsonImports, moduleArtifacts, collectGlobals, declSymbolOf, defaultExportSymbolOf, lowerFileInit, lowerDefaultExport, buildMain, appendDynamicImportModules, appendForkModules, appendWorkerModules, } from "./lower-modules.js";
48
58
  import { prepareCjsModuleGraph } from "./lower-node-module.js";
49
59
  import { registerBuiltinErrorClasses, registerBuiltinEmitterClass, registerBuiltinStreamClasses, builtinErrorInfoOf, builtinEmitterInfoOf, builtinStreamInfoOf, analyzeClassDecoration, classIteratorDrainCall, classIteratorNextCall, classIteratorOf, classIteratorOpenCall, classIteratorRestDrainCall, classMemberNameOf, classValueRef, collectClassShape, exactClassOfReceiver, collectClassShapeInner, ctorAbiEquals, findMethodOn, findStaticOn, genericClassInstanceType, isSubclassOf, inHierarchy, overrideBelow, staticShadowBelow, upcastTo, lowerClassMembers, lowerClassCtor, lowerClassExpression, lowerClassExpressionInfo, lowerClassMethodMember, lowerClassValueProperty, lowerStaticMethod, throwingSetterFn, fieldInitStmts, lowerStaticFieldInits, lowerStaticFieldRead, lowerDerivedCtorBody, superCallStmt, lowerSuperMethodCall, superThisRef, lowerSuperAccessorRead, lowerSuperAccessorWrite, inheritsBuiltinErrorCtor, inheritsBuiltinEmitterCtor, errorConstructorArgs, lowerNew, accessorCall, } from "./lower-classes.js";
50
60
  import { mixinCallClassInfoOf, mixinIntersectionInstanceType, } from "./lower-mixins.js";
@@ -247,6 +257,7 @@ export function lowerToIr(program, entry, moduleOrder, options = {}) {
247
257
  const extraModuleCycleDiags = [];
248
258
  const cycleKeys = new Set();
249
259
  const forkTargets = [];
260
+ const workerTargets = [];
250
261
  const onExtraCycle = (cycle, reason) => {
251
262
  const key = `${cycle}\0${reason}`;
252
263
  if (cycleKeys.has(key))
@@ -258,6 +269,7 @@ export function lowerToIr(program, entry, moduleOrder, options = {}) {
258
269
  const before = moduleOrder.length;
259
270
  appendDynamicImportModules(program, moduleOrder, onExtraCycle);
260
271
  appendForkModules(program, moduleOrder, forkTargets, onExtraCycle);
272
+ appendWorkerModules(program, moduleOrder, workerTargets, onExtraCycle);
261
273
  if (moduleOrder.length === before)
262
274
  break;
263
275
  if (pass === 31)
@@ -274,6 +286,7 @@ export function lowerToIr(program, entry, moduleOrder, options = {}) {
274
286
  ffiImports,
275
287
  libraryCallbacks,
276
288
  forkTargets,
289
+ workerTargets,
277
290
  externalTypes,
278
291
  externalTypeSpecifiersByFile,
279
292
  });
@@ -293,6 +306,7 @@ export function lowerToIr(program, entry, moduleOrder, options = {}) {
293
306
  ffiImports,
294
307
  libraryCallbacks,
295
308
  forkTargets,
309
+ workerTargets,
296
310
  externalTypes,
297
311
  externalTypeSpecifiersByFile,
298
312
  ffiBindingSymbols: ffiValidation.symbolsByName,
@@ -322,6 +336,7 @@ export function lowerToIr(program, entry, moduleOrder, options = {}) {
322
336
  ffiImports,
323
337
  libraryCallbacks,
324
338
  forkTargets,
339
+ workerTargets,
325
340
  ffiBindingSymbols: ffiValidation.symbolsByName,
326
341
  externalTypes,
327
342
  externalTypeSpecifiersByFile,
@@ -345,6 +360,7 @@ export function lowerToIr(program, entry, moduleOrder, options = {}) {
345
360
  ffiImports,
346
361
  libraryCallbacks,
347
362
  forkTargets,
363
+ workerTargets,
348
364
  ffiBindingSymbols: ffiValidation.symbolsByName,
349
365
  externalTypes,
350
366
  externalTypeSpecifiersByFile,
@@ -927,6 +943,7 @@ export class Lowerer {
927
943
  /** Monomorphization worklist: instances queued by call sites, drained in
928
944
  * run() (processing an instance body can queue more). */
929
945
  instantiationQueue = [];
946
+ genericInstantiationPath = null;
930
947
  /** Historical emit rank of the retained declaration/init body currently
931
948
  * lowering, and the earliest such owner that demanded each generic
932
949
  * instance. Reachability can encounter a later caller first; the minimum
@@ -1234,6 +1251,17 @@ export class Lowerer {
1234
1251
  while (ts.isParenthesizedExpression(origin))
1235
1252
  origin = origin.expression;
1236
1253
  let optionalOrigin = ts.isElementAccessExpression(origin) || ts.isPropertyAccessExpression(origin);
1254
+ if (ts.isCallExpression(origin)) {
1255
+ const name = ts.isPropertyAccessExpression(origin.expression)
1256
+ ? origin.expression.name
1257
+ : origin.expression;
1258
+ const symbol = ts.isIdentifier(name) ? this.resolveValueSymbol(name) : undefined;
1259
+ const signature = symbol ? this.fnSigsBySymbol.get(symbol) : undefined;
1260
+ optionalOrigin =
1261
+ this.runtimeOptionalFunctionReturns.has(origin) ||
1262
+ (signature?.returnType.kind === "union" &&
1263
+ this.armTag(signature.returnType.unionId, UNDEFINED_T) >= 0);
1264
+ }
1237
1265
  if (ts.isIdentifier(origin)) {
1238
1266
  const local = this.resolveLocal(origin);
1239
1267
  const root = local ? this.runtimeOptionalRootOf(local) : null;
@@ -1338,7 +1366,16 @@ export class Lowerer {
1338
1366
  runtimeOptionalWidening(actual, expected) {
1339
1367
  if (actual.kind !== "union" || this.armTag(actual.unionId, UNDEFINED_T) < 0)
1340
1368
  return null;
1341
- return typeEquals(this.stripUndefinedArm(actual), expected) ? actual : null;
1369
+ const present = this.stripUndefinedArm(actual);
1370
+ if (typeEquals(present, expected))
1371
+ return actual;
1372
+ // Only a bare expected arm gains runtime-optional storage. A slot that
1373
+ // already admits undefined keeps its own checked representation.
1374
+ if (expected.kind === "union" && this.armTag(expected.unionId, UNDEFINED_T) >= 0)
1375
+ return null;
1376
+ return identityPreservingWidening(this, present, expected)
1377
+ ? this.runtimeOptionalType(expected)
1378
+ : null;
1342
1379
  }
1343
1380
  runtimeOptionalType(t) {
1344
1381
  if (t.kind === "union")
@@ -1407,6 +1444,8 @@ export class Lowerer {
1407
1444
  /** True while re-lowering a base function's 2nd+ instance: the same source
1408
1445
  * statements were already counted for the first instance. */
1409
1446
  suppressStats = false;
1447
+ /** Comparisons interned by operand representations and equality semantics. */
1448
+ equalityHelpers = new Map();
1410
1449
  /** Synthetic array-HOF loop functions (map/filter/forEach desugar),
1411
1450
  * interned per method + element/callback-result type: key → fn name. */
1412
1451
  arrHofHelpers = new Map();
@@ -1498,6 +1537,10 @@ export class Lowerer {
1498
1537
  * node carrying the ?. token is marked handled so the receiver-typed
1499
1538
  * lowerings stop declining it (chainBlocked). */
1500
1539
  chainRecvByNode = new Map();
1540
+ /** Lowered void calls whose checked type is `never` (they throw or exit).
1541
+ * TypeScript lets such a call stand where any value is expected;
1542
+ * coerceToExpected turns them into diverging sequences. */
1543
+ neverValued = new Set();
1501
1544
  chainNarrowedType = new Map();
1502
1545
  chainHandled = new Set();
1503
1546
  /** for-of-over-matchAll bindings whose `.index` reads the companion-index
@@ -1513,6 +1556,7 @@ export class Lowerer {
1513
1556
  * (the ctx guard keeps hidden locals out of closures — a cross-function
1514
1557
  * walk falls back to the plain array walk and the fence). */
1515
1558
  matchAllDrainIndexes = new Map();
1559
+ splitIdentifierUses = new Map();
1516
1560
  /** STORED numeric value iterators: `const it = numbers.values()` (and
1517
1561
  * the equivalent `[Symbol.iterator]()` spelling) over number[] or a
1518
1562
  * represented typed array has no first-class IR value, so its statically
@@ -1528,6 +1572,8 @@ export class Lowerer {
1528
1572
  /** Named method slots observed before class collection need a callable
1529
1573
  * ABI and shared prototype descriptors instead of call-site specialization. */
1530
1574
  prototypeMethodAccesses = new Map();
1575
+ /** Field names whose complete source census stores only lexical arrows. */
1576
+ receiverFreeCallbackFields = new Set();
1531
1577
  /** Inferred JS methods participating in an override chain keep a vtable
1532
1578
  * ABI instead of call-site specialization. Filled before class collection. */
1533
1579
  virtualJsMethods = new Set();
@@ -1601,6 +1647,9 @@ export class Lowerer {
1601
1647
  fileTag = new Map();
1602
1648
  /** Embedded fork roots and their private startup ids. */
1603
1649
  forkTargets;
1650
+ workerTargets;
1651
+ workerTargetIdByPath = new Map();
1652
+ usesWorkers = false;
1604
1653
  forkTargetIdByPath = new Map();
1605
1654
  /** Namespace ModuleBlocks this program lowers, filled by splitFiles:
1606
1655
  * "flattened" — an instantiated namespace whose body joined the file's
@@ -1702,6 +1751,10 @@ export class Lowerer {
1702
1751
  * function called above the declaration statement reads that, never a
1703
1752
  * NULL slot. Filled by collectGlobals. */
1704
1753
  varGlobalEntryInits = new Map();
1754
+ /** Import-cycle bindings with an initialization flag, by global id, and
1755
+ * the top-level statements declaring them (cycle-initialization.ts). */
1756
+ cycleInitFlags = new Map();
1757
+ cycleInitDeclarations = new Map();
1705
1758
  get ctx() {
1706
1759
  const top = this.fnStack[this.fnStack.length - 1];
1707
1760
  if (!top)
@@ -1815,6 +1868,10 @@ export class Lowerer {
1815
1868
  this.startupCrash = mode.startupCrash ?? null;
1816
1869
  this.ffiImports = mode.ffiImports ?? [];
1817
1870
  this.libraryCallbacks = mode.libraryCallbacks ?? false;
1871
+ this.workerTargets = mode.workerTargets ?? [];
1872
+ this.workerTargets.forEach((sf, id) => {
1873
+ this.workerTargetIdByPath.set(tsgoPath(resolve(sf.fileName)), id);
1874
+ });
1818
1875
  this.forkTargets = mode.forkTargets ?? [];
1819
1876
  this.forkTargets.forEach((sf, id) => {
1820
1877
  this.forkTargetIdByPath.set(tsgoPath(resolve(sf.fileName)), id);
@@ -1881,6 +1938,7 @@ export class Lowerer {
1881
1938
  return { kind: "object", className };
1882
1939
  },
1883
1940
  mixinIntersectionInstance: (widened) => mixinIntersectionInstanceType(this, widened),
1941
+ classImplementedProtocol: (type) => this.classImplementedProtocol(type),
1884
1942
  isStdlibFile: this.isStdlibFile,
1885
1943
  isNpmFile: this.isNpmFile,
1886
1944
  isExternalTypeFile: (sf) => this.externalTypeSpecifiersByFile.has(tsgoPath(resolve(sf.fileName))),
@@ -1910,6 +1968,11 @@ export class Lowerer {
1910
1968
  registerBuiltinErrorClasses() {
1911
1969
  return registerBuiltinErrorClasses(this);
1912
1970
  }
1971
+ classProtocols = null;
1972
+ classImplementedProtocol(type) {
1973
+ this.classProtocols ??= new ClassProtocols(this.checker, this.moduleOrder);
1974
+ return this.classProtocols.usesCheckedIdentity(type);
1975
+ }
1913
1976
  /** The nominal identity of a checker module-namespace type. Program
1914
1977
  * modules use their normalized absolute source name; supported builtins
1915
1978
  * use the lowering tables' canonical bare name. */
@@ -2840,9 +2903,13 @@ export class Lowerer {
2840
2903
  * but it is not a runtime proof; promoting only the affected slots keeps
2841
2904
  * the rest of the dense ABI unchanged. */
2842
2905
  analyzeRuntimeOptionalArrayReads(parts) {
2906
+ const provenance = RuntimeOptionalProvenance.fromEnvironment();
2907
+ // The site whose value the current promotion follows (debug only).
2908
+ let provenanceSite;
2843
2909
  const optionalSymbols = new Set();
2844
2910
  const optionalReturns = new Set();
2845
2911
  const arithmeticReturns = new Map();
2912
+ const primitiveBindings = new Map();
2846
2913
  const optionalParams = new Map();
2847
2914
  const optionalFields = new Map();
2848
2915
  const dynamicObjectEntryRows = new Set();
@@ -2853,7 +2920,7 @@ export class Lowerer {
2853
2920
  // facade's panic fence, then keep lookup free of lowering side effects:
2854
2921
  // resolveValueSymbol also flushes deferred diagnostics and applies
2855
2922
  // merged-namespace fences, whose authority remains ordinary lowering.
2856
- this.checker.prefetchSymbolRoots(sourceFiles);
2923
+ this.checker.prefetchSymbolRoots(sourceFiles, true);
2857
2924
  const symbolOf = (node) => {
2858
2925
  const s = this.checker.getSymbolAtLocation(node);
2859
2926
  if (!s)
@@ -2869,6 +2936,17 @@ export class Lowerer {
2869
2936
  (projection?.kind === "declared-function" ? projection.signature : null));
2870
2937
  };
2871
2938
  const functionDeclBySymbol = new Map();
2939
+ const staticFieldsBySymbol = new Map();
2940
+ for (const info of this.classes.values()) {
2941
+ for (const field of info.staticFields) {
2942
+ const declaration = field.initializer.parent;
2943
+ if (!ts.isPropertyDeclaration(declaration))
2944
+ continue;
2945
+ const symbol = symbolOf(declaration.name);
2946
+ if (symbol)
2947
+ staticFieldsBySymbol.set(symbol, field);
2948
+ }
2949
+ }
2872
2950
  const signatureBySymbol = new Map();
2873
2951
  const methodFamilies = new Map();
2874
2952
  const familyBySymbol = new Map();
@@ -2965,11 +3043,12 @@ export class Lowerer {
2965
3043
  }
2966
3044
  return false;
2967
3045
  };
2968
- const isArrayRead = (node) => {
3046
+ const isIndexedRead = (node) => {
2969
3047
  const e = peel(node);
2970
3048
  if (!ts.isElementAccessExpression(e))
2971
3049
  return false;
2972
- return this.mapTypeOf(this.typeOf(e.expression))?.kind === "array";
3050
+ const kind = this.mapTypeOf(this.typeOf(e.expression))?.kind;
3051
+ return kind === "array" || kind === "string";
2973
3052
  };
2974
3053
  const isDynamicObjectEntryRead = (node) => {
2975
3054
  const read = peel(node);
@@ -3004,7 +3083,9 @@ export class Lowerer {
3004
3083
  if (explicitlyNonNull(node))
3005
3084
  return false;
3006
3085
  const e = peel(node);
3007
- if (isArrayRead(e))
3086
+ if (isIndexedRead(e))
3087
+ return true;
3088
+ if (ts.isPropertyAccessExpression(e) && isOptionalProcessStreamProperty(this, e))
3008
3089
  return true;
3009
3090
  if (ts.isCallExpression(e) && this.runtimeOptionalReduceTypes.has(e))
3010
3091
  return true;
@@ -3024,6 +3105,11 @@ export class Lowerer {
3024
3105
  const symbol = symbolOf(e);
3025
3106
  return symbol !== null && optionalSymbols.has(symbol);
3026
3107
  }
3108
+ if (ts.isPropertyAccessExpression(e)) {
3109
+ const symbol = symbolOf(e.name);
3110
+ if (symbol && optionalSymbols.has(symbol))
3111
+ return true;
3112
+ }
3027
3113
  if (ts.isCallExpression(e) && ts.isIdentifier(e.expression)) {
3028
3114
  const symbol = callableSymbolOf(e.expression);
3029
3115
  return symbol !== null && optionalReturns.has(symbol);
@@ -3051,11 +3137,31 @@ export class Lowerer {
3051
3137
  }
3052
3138
  return false;
3053
3139
  };
3054
- const optionalStringArithmeticType = (node) => {
3140
+ const optionalPrimitiveResultType = (node) => {
3055
3141
  const e = peel(node);
3056
- if (!ts.isBinaryExpression(e) || e.operatorToken.kind !== ts.SyntaxKind.PlusToken)
3142
+ if (ts.isIdentifier(e)) {
3143
+ const symbol = symbolOf(e);
3144
+ return symbol ? (primitiveBindings.get(symbol) ?? null) : null;
3145
+ }
3146
+ if (ts.isCallExpression(e)) {
3147
+ const symbol = callableSymbolOf(e.expression);
3148
+ return symbol ? (arithmeticReturns.get(symbol) ?? null) : null;
3149
+ }
3150
+ if (!ts.isBinaryExpression(e))
3057
3151
  return null;
3058
- const stringArrayRead = (part) => {
3152
+ if (e.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken && mayBeOptional(e.left)) {
3153
+ const left = this.mapTypeOf(this.typeOf(e.left));
3154
+ const right = this.mapTypeOf(this.typeOf(e.right));
3155
+ const primitive = (t) => t?.kind === "f64" || t?.kind === "string" || t?.kind === "bool";
3156
+ if (primitive(left) && primitive(right) && !typeEquals(left, right)) {
3157
+ const arms = [left, right].sort((a, b) => (typeKey(a) < typeKey(b) ? -1 : 1));
3158
+ return { kind: "union", unionId: this.unions.intern(arms) };
3159
+ }
3160
+ return null;
3161
+ }
3162
+ if (e.operatorToken.kind !== ts.SyntaxKind.PlusToken)
3163
+ return null;
3164
+ const stringRead = (part) => {
3059
3165
  const p = peel(part);
3060
3166
  if (!ts.isElementAccessExpression(p))
3061
3167
  return false;
@@ -3063,16 +3169,15 @@ export class Lowerer {
3063
3169
  if (t?.kind !== "string")
3064
3170
  return false;
3065
3171
  const recv = this.mapTypeOf(this.typeOf(p.expression));
3066
- return recv?.kind === "array" && recv.elem.kind === "string";
3172
+ return recv?.kind === "string" || (recv?.kind === "array" && recv.elem.kind === "string");
3067
3173
  };
3068
3174
  const primitive = (part) => {
3069
3175
  const t = this.mapTypeOf(this.typeOf(part));
3070
3176
  return t?.kind === "f64" || t?.kind === "string";
3071
3177
  };
3072
- if (!stringArrayRead(e.left) && !stringArrayRead(e.right))
3178
+ if (!stringRead(e.left) && !stringRead(e.right))
3073
3179
  return null;
3074
- if (!(primitive(e.left) || stringArrayRead(e.left)) ||
3075
- !(primitive(e.right) || stringArrayRead(e.right)))
3180
+ if (!primitive(e.left) || !primitive(e.right))
3076
3181
  return null;
3077
3182
  return { kind: "union", unionId: this.unions.intern([F64, STRING]) };
3078
3183
  };
@@ -3105,6 +3210,7 @@ export class Lowerer {
3105
3210
  const symbol = symbolOf(el.name);
3106
3211
  if (symbol && !el.initializer && !optionalSymbols.has(symbol)) {
3107
3212
  optionalSymbols.add(symbol);
3213
+ provenance?.note("pattern-binding", el.name, init);
3108
3214
  // Indexed flow facts can survive a mutating method call in the
3109
3215
  // checker. The array's element ABI describes every value a
3110
3216
  // position may hold after that call, so bind from that type.
@@ -3248,6 +3354,7 @@ export class Lowerer {
3248
3354
  const widened = this.runtimeOptionalType(current);
3249
3355
  const previous = this.runtimeOptionalBindingTypes.get(symbol);
3250
3356
  this.runtimeOptionalBindingTypes.set(symbol, widened);
3357
+ provenance?.note("callback-parameter", parameter.name, provenanceSite);
3251
3358
  if (!previous || !typeEquals(previous, widened))
3252
3359
  changed = true;
3253
3360
  if (!optionalSymbols.has(symbol)) {
@@ -3259,6 +3366,7 @@ export class Lowerer {
3259
3366
  const fnType = this.mapTypeOf(this.typeOf(fn));
3260
3367
  if (fnType?.kind === "func" && bodyReturnsOptional(fn)) {
3261
3368
  const widenedReturn = this.runtimeOptionalType(fnType.ret);
3369
+ provenance?.note("callback-return", fn, provenanceSite);
3262
3370
  const previousReturn = this.runtimeOptionalFunctionReturnType(fn, fnType.ret);
3263
3371
  this.runtimeOptionalFunctionReturns.set(fn, widenedReturn);
3264
3372
  if (!typeEquals(previousReturn, widenedReturn))
@@ -3391,6 +3499,16 @@ export class Lowerer {
3391
3499
  const scan = (node) => {
3392
3500
  if (ts.isVariableDeclaration(node)) {
3393
3501
  if (node.initializer) {
3502
+ const result = optionalPrimitiveResultType(node.initializer);
3503
+ const symbol = ts.isIdentifier(node.name) ? symbolOf(node.name) : null;
3504
+ if (result?.kind === "union" && symbol) {
3505
+ const before = primitiveBindings.get(symbol);
3506
+ if (!before || !typeEquals(before, result)) {
3507
+ primitiveBindings.set(symbol, result);
3508
+ this.runtimeOptionalBindingTypes.set(symbol, result);
3509
+ changed = true;
3510
+ }
3511
+ }
3394
3512
  if (ts.isIdentifier(node.name) && isDynamicObjectEntryRead(node.initializer)) {
3395
3513
  const symbol = symbolOf(node.name);
3396
3514
  if (symbol && !dynamicObjectEntryRows.has(symbol)) {
@@ -3402,6 +3520,7 @@ export class Lowerer {
3402
3520
  const symbol = symbolOf(node.name);
3403
3521
  if (symbol && !optionalSymbols.has(symbol)) {
3404
3522
  optionalSymbols.add(symbol);
3523
+ provenance?.note("binding", node.name, node.initializer);
3405
3524
  changed = true;
3406
3525
  }
3407
3526
  }
@@ -3422,6 +3541,8 @@ export class Lowerer {
3422
3541
  const aliasNew = !optionalReturns.has(symbol);
3423
3542
  if (aliasNew)
3424
3543
  optionalReturns.add(symbol);
3544
+ if (aliasNew)
3545
+ provenance?.note("function-alias", node.name, node.initializer);
3425
3546
  if (aliasNew)
3426
3547
  changed = true;
3427
3548
  const valueType = this.mapTypeOf(this.typeOf(node.name));
@@ -3457,8 +3578,10 @@ export class Lowerer {
3457
3578
  const value = ts.isPropertyAssignment(prop)
3458
3579
  ? prop.initializer
3459
3580
  : prop.name;
3460
- if (mayBeOptional(value) && noteField(node, name.text))
3581
+ if (mayBeOptional(value) && noteField(node, name.text)) {
3582
+ provenance?.note("literal-field", name, value);
3461
3583
  changed = true;
3584
+ }
3462
3585
  }
3463
3586
  }
3464
3587
  }
@@ -3473,14 +3596,24 @@ export class Lowerer {
3473
3596
  const symbol = symbolOf(node.left);
3474
3597
  if (symbol && !optionalSymbols.has(symbol)) {
3475
3598
  optionalSymbols.add(symbol);
3599
+ provenance?.note("assigned-binding", node.left, node.right);
3476
3600
  changed = true;
3477
3601
  }
3478
3602
  }
3479
- else if (ts.isPropertyAccessExpression(node.left) &&
3480
- ts.isIdentifier(node.left.expression)) {
3481
- const symbol = symbolOf(node.left.expression);
3482
- if (symbol && noteFieldSymbol(symbol, node.left.name.text))
3603
+ else if (ts.isPropertyAccessExpression(node.left)) {
3604
+ const field = symbolOf(node.left.name);
3605
+ if (field && staticFieldsBySymbol.has(field) && !optionalSymbols.has(field)) {
3606
+ optionalSymbols.add(field);
3607
+ provenance?.note("static-field", node.left, node.right);
3483
3608
  changed = true;
3609
+ }
3610
+ else if (ts.isIdentifier(node.left.expression)) {
3611
+ const symbol = symbolOf(node.left.expression);
3612
+ if (symbol && noteFieldSymbol(symbol, node.left.name.text)) {
3613
+ provenance?.note("assigned-field", node.left, node.right);
3614
+ changed = true;
3615
+ }
3616
+ }
3484
3617
  }
3485
3618
  }
3486
3619
  if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {
@@ -3521,6 +3654,7 @@ export class Lowerer {
3521
3654
  }
3522
3655
  }
3523
3656
  if (nativeArrayReceiver) {
3657
+ provenanceSite = node;
3524
3658
  if (promoteHofCallback(callback, callbackIndices))
3525
3659
  changed = true;
3526
3660
  const method = node.expression.name.text;
@@ -3571,6 +3705,7 @@ export class Lowerer {
3571
3705
  continue;
3572
3706
  shape.type = widened;
3573
3707
  const parameter = functionDeclBySymbol.get(target)?.parameters[i];
3708
+ provenance?.note("parameter", parameter, node, "(omitted or undefined argument)");
3574
3709
  if (parameter) {
3575
3710
  for (const bound of boundIdentifiersOf(parameter.name)) {
3576
3711
  const boundSymbol = symbolOf(bound);
@@ -3595,6 +3730,7 @@ export class Lowerer {
3595
3730
  const callbackSlot = shape?.type;
3596
3731
  if (callbackSlot?.kind === "func" && !ts.isSpreadElement(arg)) {
3597
3732
  const optionalCallbackParams = callbackSlot.params.flatMap((type, index) => type.kind === "union" && this.armTag(type.unionId, UNDEFINED_T) >= 0 ? [index] : []);
3733
+ provenanceSite = node;
3598
3734
  if (optionalCallbackParams.length > 0 &&
3599
3735
  promoteHofCallback(arg, optionalCallbackParams)) {
3600
3736
  changed = true;
@@ -3615,6 +3751,7 @@ export class Lowerer {
3615
3751
  continue;
3616
3752
  rest.type = widened;
3617
3753
  const parameter = functionDeclBySymbol.get(target)?.parameters[i];
3754
+ provenance?.note("rest-parameter", parameter, arg);
3618
3755
  if (parameter && ts.isIdentifier(parameter.name)) {
3619
3756
  const bound = symbolOf(parameter.name);
3620
3757
  if (bound)
@@ -3643,6 +3780,7 @@ export class Lowerer {
3643
3780
  if (set.size !== before) {
3644
3781
  changed = true;
3645
3782
  const parameter = functionDeclBySymbol.get(target)?.parameters[i];
3783
+ provenance?.note("parameter", parameter, arg, target === symbol ? "" : "(override)");
3646
3784
  if (parameter) {
3647
3785
  for (const bound of boundIdentifiersOf(parameter.name)) {
3648
3786
  const boundSymbol = symbolOf(bound);
@@ -3666,9 +3804,10 @@ export class Lowerer {
3666
3804
  for (const expression of returnsOf(decl)) {
3667
3805
  if (mayBeOptional(expression) && !optionalReturns.has(symbol)) {
3668
3806
  optionalReturns.add(symbol);
3807
+ provenance?.note("return", decl.name ?? decl, expression);
3669
3808
  changed = true;
3670
3809
  }
3671
- const arithmetic = optionalStringArithmeticType(expression);
3810
+ const arithmetic = optionalPrimitiveResultType(expression);
3672
3811
  if (arithmetic && !arithmeticReturns.has(symbol)) {
3673
3812
  arithmeticReturns.set(symbol, arithmetic);
3674
3813
  changed = true;
@@ -3679,6 +3818,13 @@ export class Lowerer {
3679
3818
  let changed = true;
3680
3819
  while (changed) {
3681
3820
  changed = false;
3821
+ for (const [symbol, field] of staticFieldsBySymbol) {
3822
+ if (!optionalSymbols.has(symbol) && mayBeOptional(field.initializer)) {
3823
+ optionalSymbols.add(symbol);
3824
+ provenance?.note("static-field", field.initializer.parent, field.initializer);
3825
+ changed = true;
3826
+ }
3827
+ }
3682
3828
  for (const sf of sourceFiles)
3683
3829
  if (scanFile(sf))
3684
3830
  changed = true;
@@ -3710,11 +3856,27 @@ export class Lowerer {
3710
3856
  for (const symbol of family) {
3711
3857
  if (!optionalReturns.has(symbol)) {
3712
3858
  optionalReturns.add(symbol);
3859
+ provenance?.note("return", functionDeclBySymbol.get(symbol), undefined, "(override family)");
3713
3860
  changed = true;
3714
3861
  }
3715
3862
  }
3716
3863
  }
3717
3864
  }
3865
+ const globalsById = new Map(this.globalsList.map((global) => [global.id, global]));
3866
+ for (const [symbol, field] of staticFieldsBySymbol) {
3867
+ if (!optionalSymbols.has(symbol))
3868
+ continue;
3869
+ const promoted = addUndefined(field.type);
3870
+ // An explicit optional annotation already has the right layout, but
3871
+ // an indexed assignment still invalidates the checker's presence fact.
3872
+ field.type = promoted;
3873
+ field.runtimeOptional = true;
3874
+ const global = globalsById.get(field.globalId);
3875
+ if (global) {
3876
+ global.type = promoted;
3877
+ this.runtimeOptionalGlobals.add(global);
3878
+ }
3879
+ }
3718
3880
  for (const [symbol, sig] of signatureBySymbol) {
3719
3881
  const params = optionalParams.get(symbol);
3720
3882
  if (params) {
@@ -3846,6 +4008,7 @@ export class Lowerer {
3846
4008
  }
3847
4009
  });
3848
4010
  }
4011
+ provenance?.flush();
3849
4012
  }
3850
4013
  run() {
3851
4014
  const parts = this.splitFiles();
@@ -3928,7 +4091,7 @@ export class Lowerer {
3928
4091
  // generic classes, generic methods calling generic functions) — the
3929
4092
  // index loops run to the joint fixpoint. Same-key recursion re-uses
3930
4093
  // its own entry; polymorphic recursion is cut off by
3931
- // MAX_GENERIC_INSTANCES.
4094
+ // the recursive instantiation demand path.
3932
4095
  {
3933
4096
  let ec = 0;
3934
4097
  let gc = 0;
@@ -4089,6 +4252,7 @@ export class Lowerer {
4089
4252
  // the emitted program references, flushing deferred class diagnostics
4090
4253
  // that a reached type makes relevant.
4091
4254
  const artifacts = this.moduleArtifacts(functions);
4255
+ refuseUncheckedCycleReads(this, artifacts.classes ?? []);
4092
4256
  // Types still naming a class that never REGISTERED after retention's
4093
4257
  // flush (JS graphs whose class fences deferred to runtime — the
4094
4258
  // sentence-walker's path params, printer tables whose func-typed
@@ -4103,7 +4267,7 @@ export class Lowerer {
4103
4267
  const module = this.diags.length > 0
4104
4268
  ? null
4105
4269
  : {
4106
- irVersion: 13,
4270
+ irVersion: 15,
4107
4271
  sourceFile: this.entry.fileName,
4108
4272
  functions,
4109
4273
  classes: artifacts.classes,
@@ -4112,10 +4276,13 @@ export class Lowerer {
4112
4276
  globals: this.globalsList,
4113
4277
  ...(this.npmEmbedded ? { embedded: this.npmEmbedded } : {}),
4114
4278
  entry: ENTRY_NAME,
4279
+ ...(this.usesWorkers ? { workers: true } : {}),
4115
4280
  ...(this.ffiImports.length > 0 ? { ffiImports: [...this.ffiImports] } : {}),
4116
4281
  };
4117
4282
  if (module)
4118
4283
  sanitizeUnregisteredClassTypes(module, (name) => this.classes.has(name));
4284
+ if (module)
4285
+ checkCycleBindingAccesses(this, module);
4119
4286
  return {
4120
4287
  module,
4121
4288
  diagnostics: this.diags,
@@ -4712,6 +4879,7 @@ export class Lowerer {
4712
4879
  // globals pre-register before their initializers lower) — an exact
4713
4880
  // duplicate (code + span + message) adds noise, not information.
4714
4881
  if (this.diags.some((p) => p.code === d.code &&
4882
+ p.loc.file === d.loc.file &&
4715
4883
  p.loc.start === d.loc.start &&
4716
4884
  p.loc.end === d.loc.end &&
4717
4885
  p.message === d.message)) {
@@ -4914,9 +5082,8 @@ export class Lowerer {
4914
5082
  'new Intl.NumberFormat("en-US").format(x) and x.toLocaleString("en-US") with default options; ' +
4915
5083
  "the rest is ICU locale data the binary does not carry";
4916
5084
  const typeHints = {
4917
- ArrayBuffer: "no free-standing ArrayBuffer value exists — typed arrays own their storage " +
4918
- "(new Uint8Array(n) allocates; new Uint8Array(new ArrayBuffer(n)) erases the buffer into the view)",
4919
- SharedArrayBuffer: "no shared-memory threads exist in a compiled program — Uint8Array is the byte storage",
5085
+ ArrayBuffer: "fixed ArrayBuffer storage and typed-array views are supported; resizable and detached storage are not modeled",
5086
+ SharedArrayBuffer: "fixed SharedArrayBuffer storage is supported; growable shared storage is not modeled",
4920
5087
  NumberFormat: intlHint,
4921
5088
  DateTimeFormat: intlHint,
4922
5089
  DurationFormat: intlHint,
@@ -5025,6 +5192,9 @@ export class Lowerer {
5025
5192
  if (arm !== undefined)
5026
5193
  return arm;
5027
5194
  }
5195
+ const collection = concreteCollectionNarrow(this, node, t);
5196
+ if (collection)
5197
+ return collection;
5028
5198
  // IMPLICIT-ANY instance bodies: an identifier reference to a BOUND
5029
5199
  // param answers the call site's concrete type wherever the checker
5030
5200
  // still says `any` (there is no `T` for mapType to substitute — the
@@ -5348,6 +5518,11 @@ export class Lowerer {
5348
5518
  this.pushDiag(recordShapeMismatchDiag(this.fmt(expected), this.fmt(actual), locOf(node), detail));
5349
5519
  throw new PoisonError();
5350
5520
  }
5521
+ // Iterator-typed slots hold generators and built-in collection
5522
+ // iterators; any other iterator object (a user class) stays fenced.
5523
+ if (expected.kind === "generator" && actual.kind !== "generator") {
5524
+ this.unsupported("SC1090", node, `'${this.fmt(actual)}' values in an iterator-typed slot (Iterator and IterableIterator slots hold generators and built-in collection iterators)`);
5525
+ }
5351
5526
  // Everything else — a plain-kind mismatch like a string flowing into a
5352
5527
  // class-instance slot — is tsc-rejected in the lowering world and only
5353
5528
  // reaches here through preflight's project-world second chance (e.g. a
@@ -5403,6 +5578,21 @@ export class Lowerer {
5403
5578
  }
5404
5579
  return literalUnionArm(def, values, (id) => this.shapes.get(id), cached.owners);
5405
5580
  }
5581
+ /** Widen only the result view; identical parameter ABIs preserve closure identity. */
5582
+ coerceCovariantFunction(expr, expected) {
5583
+ if (expr.type.kind === "func" &&
5584
+ expected.kind === "func" &&
5585
+ expr.type.rest === expected.rest &&
5586
+ expr.type.restAbi === expected.restAbi &&
5587
+ expr.type.argumentsAll === expected.argumentsAll &&
5588
+ expr.type.params.length === expected.params.length &&
5589
+ expr.type.params.every((type, i) => typeEquals(type, expected.params[i])) &&
5590
+ expr.type.ret.kind === "object" &&
5591
+ expected.ret.kind === "object" &&
5592
+ this.isSubclassOf(expr.type.ret.className, expected.ret.className))
5593
+ return { kind: "upcast", value: expr, type: expected, loc: expr.loc };
5594
+ return null;
5595
+ }
5406
5596
  /** Implicit union construction. Wherever a value flows into a typed slot
5407
5597
  * (initializer, assignment, call argument, return, field write, record
5408
5598
  * literal field, ternary arm) whose expected type is a union and the
@@ -5411,6 +5601,15 @@ export class Lowerer {
5411
5601
  * else (including a DIFFERENT union) is left for requireExactShape, which
5412
5602
  * rejects union mismatches with SC2003. */
5413
5603
  coerceToExpected(expr, expected) {
5604
+ if (expr.type.kind === "void" && expected.kind !== "void" && this.neverValued.has(expr))
5605
+ return this.divergentValue(expr, expected);
5606
+ // Iterator-typed slots: native iterators and differently typed
5607
+ // generators step through an adapter generator.
5608
+ if (expected.kind === "generator" && !typeEquals(expr.type, expected)) {
5609
+ const adapted = iteratorSlotAdapter(this, expr, expected);
5610
+ if (adapted)
5611
+ return adapted;
5612
+ }
5414
5613
  // Island boundary, both directions. IN: any static value flowing into
5415
5614
  // an any-typed slot marshals implicitly (tsc allows the assignment;
5416
5615
  // the marshal is where its semantics live). OUT: an 'any' value
@@ -5670,6 +5869,9 @@ export class Lowerer {
5670
5869
  return { kind: "call", callee: adapter, args: [expr], type: expected, loc: expr.loc };
5671
5870
  }
5672
5871
  }
5872
+ const covariant = this.coerceCovariantFunction(expr, expected);
5873
+ if (covariant)
5874
+ return covariant;
5673
5875
  // The GENERAL function-value adapter (funcCoerceAdapter): a function
5674
5876
  // whose signature differs from the slot's only by coercible pieces —
5675
5877
  // fewer parameters (JS ignores extras: `load(function () {})` into an
@@ -5693,6 +5895,31 @@ export class Lowerer {
5693
5895
  this.isSubclassOf(expr.type.className, expected.className)) {
5694
5896
  return { kind: "upcast", value: expr, type: expected, loc: expr.loc };
5695
5897
  }
5898
+ // Optional subclass storage still has the same object payload. Extract
5899
+ // it with a checked tag test, then widen the class view without copying.
5900
+ if (expected.kind === "object" && expr.type.kind === "union") {
5901
+ const arms = this.unions.get(expr.type.unionId)?.arms;
5902
+ const present = arms?.filter((arm) => !isUnitType(arm)) ?? [];
5903
+ if (present.length === 1 &&
5904
+ present[0].kind === "object" &&
5905
+ present[0].className !== expected.className &&
5906
+ this.isSubclassOf(present[0].className, expected.className)) {
5907
+ // One class arm: the ordinary checked narrow reports a missing value
5908
+ // exactly like same-class storage before the prefix view widens it.
5909
+ return {
5910
+ kind: "upcast",
5911
+ value: this.coerceToExpected(expr, present[0]),
5912
+ type: expected,
5913
+ loc: expr.loc,
5914
+ };
5915
+ }
5916
+ if (present.length > 1 &&
5917
+ present.every((arm) => identityPreservingWidening(this, arm, expected))) {
5918
+ const view = checkedClassAssertion(this, expr, expected, expr.loc);
5919
+ if (view)
5920
+ return view;
5921
+ }
5922
+ }
5696
5923
  // CLASS-VALUE widening (classval:D into a classval:C slot): the same
5697
5924
  // pointer with only the static type changing — legal exactly when D
5698
5925
  // strictly descends from C AND the two completed constructor ABIs
@@ -6075,6 +6302,17 @@ export class Lowerer {
6075
6302
  loc: expr.loc,
6076
6303
  }
6077
6304
  : this.coerceToExpected(expr, expected);
6305
+ // Keep storage intact when ordinary widening already accepts it. Only
6306
+ // a destination needing a more specific class layout uses the site's
6307
+ // refinement and checked extraction.
6308
+ if (!typeEquals(e.type, expected) &&
6309
+ (expected.kind === "object" || expected.kind === "union")) {
6310
+ const site = e.type.kind === "union" ? this.mapTypeOf(this.typeOf(node)) : null;
6311
+ const narrowed = (site && narrowStoredClassValue(this, e, site)) ??
6312
+ narrowGenericClassValue(this, e, expected);
6313
+ if (narrowed)
6314
+ e = this.coerceToExpected(narrowed, expected);
6315
+ }
6078
6316
  // Existing JavaScript arrays retain mutations and identity across checked
6079
6317
  // slots. Fresh literals have no prior identity and use checked storage
6080
6318
  // directly, so later writes can change their inferred element type.
@@ -6663,6 +6901,42 @@ export class Lowerer {
6663
6901
  wrappedUndefined(type, loc) {
6664
6902
  return wrappedUndefined(this, type, loc);
6665
6903
  }
6904
+ /** The value an OMITTED or deleted property leaves in a record field
6905
+ * slot of `type`: the ABSENT state for undefined-armed unions (the slot
6906
+ * reads as undefined but the property does not exist), the dyn
6907
+ * undefined for 'unknown' slots, and null when the slot cannot be
6908
+ * missing. Only legal as a direct field-slot write (IR fieldAbsent). */
6909
+ absentFieldValue(type, loc) {
6910
+ if (type.kind === "union" && this.armTag(type.unionId, UNDEFINED_T) >= 0) {
6911
+ return { kind: "fieldAbsent", unionId: type.unionId, type, loc };
6912
+ }
6913
+ return this.wrappedUndefined(type, loc);
6914
+ }
6915
+ /** A field copy that keeps absence: `value` (the converted read of
6916
+ * `field` from record `obj`, which must be repeatable) when the source
6917
+ * property exists, else the target slot's ABSENT state. Fields that are
6918
+ * always present, and targets that cannot be absent, copy `value`
6919
+ * as-is. Only legal as a direct field-slot write. */
6920
+ presenceKeepingCopy(obj, shapeId, field, value, loc) {
6921
+ const present = this.recordFieldPresent(obj, shapeId, field, loc);
6922
+ if (present.kind !== "recordHas")
6923
+ return value;
6924
+ const absent = this.absentFieldValue(value.type, loc);
6925
+ if (absent?.kind !== "fieldAbsent")
6926
+ return value;
6927
+ return { kind: "ternary", cond: present, then: value, else_: absent, type: value.type, loc };
6928
+ }
6929
+ /** Own-property presence of declared field `field` on record `obj`
6930
+ * (borrowed — callers pass a repeatable receiver): a runtime test for
6931
+ * undefined-armed union fields, which can be absent, and `true` for
6932
+ * every other declared field. */
6933
+ recordFieldPresent(obj, shapeId, field, loc) {
6934
+ const f = this.shapes.get(shapeId)?.fields.find((x) => x.name === field);
6935
+ if (f && f.type.kind === "union" && this.armTag(f.type.unionId, UNDEFINED_T) >= 0) {
6936
+ return { kind: "recordHas", obj, shapeId, field, type: BOOL, loc };
6937
+ }
6938
+ return { kind: "boolLit", value: true, type: BOOL, loc };
6939
+ }
6666
6940
  /** The entry value of a binding JS initializes to `undefined` (an
6667
6941
  * initializer-less declaration, a hoisted `var` before its statement):
6668
6942
  * undefined-armed unions hold the interned undefined arm, and 'any'
@@ -6957,6 +7231,8 @@ export class Lowerer {
6957
7231
  * instance table. Filled by collectClassShapeInner's family mode;
6958
7232
  * consulted by mapType's genericClassInstance hook. */
6959
7233
  genericClassByDecl = new Map();
7234
+ /** Forward generic references may demand a family before its declaration turn. */
7235
+ collectingClassDeclarations = new Set();
6960
7236
  /** Instantiations in demand order — the member-lowering worklist run()'s
6961
7237
  * monomorphization fixpoint drains (an instantiation's methods can
6962
7238
  * demand further instances of either kind). */
@@ -7065,6 +7341,32 @@ export class Lowerer {
7065
7341
  declareLocal(nameNode, name, type, mutable) {
7066
7342
  return declareContextLocal(this.ctx, name, type, mutable, this.checker.getSymbolAtLocation(nameNode), bindingSource(nameNode));
7067
7343
  }
7344
+ /** A never-returning call in a value position of type `expected`: the
7345
+ * call runs for its effects (it throws or exits), and the expression ends
7346
+ * in an unreachable trap instead of producing a value. The result reads an
7347
+ * uninitialized hidden local that control never reaches. */
7348
+ divergentValue(call, expected) {
7349
+ const loc = call.loc;
7350
+ const slot = this.declareHiddenLocal("%never", expected);
7351
+ slot.mutable = true;
7352
+ return {
7353
+ kind: "seqExpr",
7354
+ stmts: [
7355
+ { kind: "exprStmt", expr: call, loc },
7356
+ { kind: "varDecl", localId: slot.id, init: null, loc },
7357
+ {
7358
+ kind: "runtimeFence",
7359
+ code: "SC9002",
7360
+ message: "unreachable: a 'never' call returned — please report this",
7361
+ loc,
7362
+ },
7363
+ ],
7364
+ result: varRef(slot.id, expected, loc),
7365
+ diverges: true,
7366
+ type: expected,
7367
+ loc,
7368
+ };
7369
+ }
7068
7370
  /** A function-scope local bound to NO ts.Symbol — the hidden ABI slot of a
7069
7371
  * defaulted parameter (the parameter's symbol binds to the separately-
7070
7372
  * declared body local; nothing in the source can name this one). */
@@ -8167,8 +8469,8 @@ export class Lowerer {
8167
8469
  lambdaSignature(node) {
8168
8470
  return lambdaSignature(this, node);
8169
8471
  }
8170
- lowerLambda(node) {
8171
- return lowerLambda(this, node);
8472
+ lowerLambda(node, checkedReceiver = false) {
8473
+ return lowerLambda(this, node, checkedReceiver);
8172
8474
  }
8173
8475
  lowerArrayMethodCall(call, access) {
8174
8476
  return lowerArrayMethodCall(this, call, access);
@@ -8537,6 +8839,11 @@ export class Lowerer {
8537
8839
  if (bi.module === "events" && bi.member === "defaultMaxListeners") {
8538
8840
  return { kind: "libCall", fn: "emitter.getDefaultMax", args: [], type: F64, loc };
8539
8841
  }
8842
+ if (bi.module === "worker_threads") {
8843
+ const value = lowerWorkerMetadata(bi.member, loc);
8844
+ if (value)
8845
+ return value;
8846
+ }
8540
8847
  const c = builtinModuleConstOf(this, bi.module, bi.member);
8541
8848
  if (c !== undefined)
8542
8849
  return builtinConstLit(c, loc);