@scriptc/compiler 0.0.34 → 0.0.36

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 (424) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +7 -6
  2. package/dist/backend/build-cache.d.ts +44 -0
  3. package/dist/backend/build-cache.js +241 -0
  4. package/dist/backend/build-cache.js.map +1 -0
  5. package/dist/backend/{emission/emit-async.d.ts → c/async.d.ts} +21 -30
  6. package/dist/backend/{emission/emit-async.js → c/async.js} +270 -286
  7. package/dist/backend/c/async.js.map +1 -0
  8. package/dist/backend/{emission/emitter.d.ts → c/c-emitter.d.ts} +6 -23
  9. package/dist/backend/{emission/emitter.js → c/c-emitter.js} +53 -107
  10. package/dist/backend/c/c-emitter.js.map +1 -0
  11. package/dist/backend/c/exprs.d.ts +8 -0
  12. package/dist/backend/c/exprs.js +7913 -0
  13. package/dist/backend/c/exprs.js.map +1 -0
  14. package/dist/backend/{emission/emit-island.d.ts → c/island.d.ts} +5 -5
  15. package/dist/backend/{emission/emit-island.js → c/island.js} +24 -22
  16. package/dist/backend/c/island.js.map +1 -0
  17. package/dist/backend/{emission → c}/may-throw.d.ts +1 -1
  18. package/dist/backend/{emission → c}/may-throw.js +1 -1
  19. package/dist/backend/c/may-throw.js.map +1 -0
  20. package/dist/backend/{emission/emit-shapes.d.ts → c/shapes.d.ts} +19 -19
  21. package/dist/backend/{emission/emit-shapes.js → c/shapes.js} +78 -87
  22. package/dist/backend/c/shapes.js.map +1 -0
  23. package/dist/backend/{emission/emit-stmts.d.ts → c/stmts.d.ts} +12 -12
  24. package/dist/backend/{emission/emit-stmts.js → c/stmts.js} +377 -343
  25. package/dist/backend/c/stmts.js.map +1 -0
  26. package/dist/backend/{emission/emit-types.d.ts → c/types.d.ts} +1 -1
  27. package/dist/backend/{emission/emit-types.js → c/types.js} +42 -286
  28. package/dist/backend/c/types.js.map +1 -0
  29. package/dist/backend/c/types.test.js +25 -0
  30. package/dist/backend/c/types.test.js.map +1 -0
  31. package/dist/backend/{emission/emit-walkers.d.ts → c/walkers.d.ts} +19 -41
  32. package/dist/backend/{emission/emit-walkers.js → c/walkers.js} +238 -298
  33. package/dist/backend/c/walkers.js.map +1 -0
  34. package/dist/backend/ffi-callbacks.d.ts +1 -1
  35. package/dist/backend/ffi-callbacks.js +4 -3
  36. package/dist/backend/ffi-callbacks.js.map +1 -1
  37. package/dist/backend/{library-identity.d.ts → library-identity-markers.d.ts} +0 -4
  38. package/dist/backend/{library-identity.js → library-identity-markers.js} +10 -9
  39. package/dist/backend/library-identity-markers.js.map +1 -0
  40. package/dist/backend/llvm/blocks.d.ts +4 -0
  41. package/dist/backend/llvm/blocks.js +29 -0
  42. package/dist/backend/llvm/blocks.js.map +1 -1
  43. package/dist/backend/llvm/classes.d.ts +2 -19
  44. package/dist/backend/llvm/classes.js +20 -52
  45. package/dist/backend/llvm/classes.js.map +1 -1
  46. package/dist/backend/llvm/common.d.ts +4 -0
  47. package/dist/backend/llvm/common.js +27 -0
  48. package/dist/backend/llvm/common.js.map +1 -0
  49. package/dist/backend/llvm/dyn.d.ts +3 -8
  50. package/dist/backend/llvm/dyn.js +152 -224
  51. package/dist/backend/llvm/dyn.js.map +1 -1
  52. package/dist/backend/llvm/emitter.d.ts +4 -1
  53. package/dist/backend/llvm/emitter.js +514 -9981
  54. package/dist/backend/llvm/emitter.js.map +1 -1
  55. package/dist/backend/llvm/expr-async.d.ts +4 -0
  56. package/dist/backend/llvm/expr-async.js +726 -0
  57. package/dist/backend/llvm/expr-async.js.map +1 -0
  58. package/dist/backend/llvm/expr-bytes.d.ts +13 -0
  59. package/dist/backend/llvm/expr-bytes.js +456 -0
  60. package/dist/backend/llvm/expr-bytes.js.map +1 -0
  61. package/dist/backend/llvm/expr-callbacks.d.ts +22 -0
  62. package/dist/backend/llvm/expr-callbacks.js +520 -0
  63. package/dist/backend/llvm/expr-callbacks.js.map +1 -0
  64. package/dist/backend/llvm/expr-calls.d.ts +2 -0
  65. package/dist/backend/llvm/expr-calls.js +618 -0
  66. package/dist/backend/llvm/expr-calls.js.map +1 -0
  67. package/dist/backend/llvm/expr-containers.d.ts +25 -0
  68. package/dist/backend/llvm/expr-containers.js +623 -0
  69. package/dist/backend/llvm/expr-containers.js.map +1 -0
  70. package/dist/backend/llvm/expr-context.d.ts +255 -0
  71. package/dist/backend/llvm/expr-context.js +2 -0
  72. package/dist/backend/llvm/expr-context.js.map +1 -0
  73. package/dist/backend/llvm/expr-control.d.ts +2 -0
  74. package/dist/backend/llvm/expr-control.js +473 -0
  75. package/dist/backend/llvm/expr-control.js.map +1 -0
  76. package/dist/backend/llvm/expr-dispatch.d.ts +4 -0
  77. package/dist/backend/llvm/expr-dispatch.js +151 -0
  78. package/dist/backend/llvm/expr-dispatch.js.map +1 -0
  79. package/dist/backend/llvm/expr-dynamic.d.ts +2 -0
  80. package/dist/backend/llvm/expr-dynamic.js +810 -0
  81. package/dist/backend/llvm/expr-dynamic.js.map +1 -0
  82. package/dist/backend/llvm/expr-island.d.ts +15 -0
  83. package/dist/backend/llvm/expr-island.js +690 -0
  84. package/dist/backend/llvm/expr-island.js.map +1 -0
  85. package/dist/backend/llvm/expr-primitives.d.ts +6 -0
  86. package/dist/backend/llvm/expr-primitives.js +622 -0
  87. package/dist/backend/llvm/expr-primitives.js.map +1 -0
  88. package/dist/backend/llvm/expr-records.d.ts +9 -0
  89. package/dist/backend/llvm/expr-records.js +299 -0
  90. package/dist/backend/llvm/expr-records.js.map +1 -0
  91. package/dist/backend/llvm/expr-stream-bridges.d.ts +13 -0
  92. package/dist/backend/llvm/expr-stream-bridges.js +396 -0
  93. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -0
  94. package/dist/backend/llvm/expr-stream-callbacks.d.ts +12 -0
  95. package/dist/backend/llvm/expr-stream-callbacks.js +360 -0
  96. package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -0
  97. package/dist/backend/llvm/lib-dispatch.d.ts +5 -0
  98. package/dist/backend/llvm/lib-dispatch.js +267 -0
  99. package/dist/backend/llvm/lib-dispatch.js.map +1 -0
  100. package/dist/backend/llvm/lib-filesystem.d.ts +6 -0
  101. package/dist/backend/llvm/lib-filesystem.js +594 -0
  102. package/dist/backend/llvm/lib-filesystem.js.map +1 -0
  103. package/dist/backend/llvm/lib-network.d.ts +2 -0
  104. package/dist/backend/llvm/lib-network.js +429 -0
  105. package/dist/backend/llvm/lib-network.js.map +1 -0
  106. package/dist/backend/llvm/lib-process.d.ts +5 -0
  107. package/dist/backend/llvm/lib-process.js +585 -0
  108. package/dist/backend/llvm/lib-process.js.map +1 -0
  109. package/dist/backend/llvm/lib-shared.d.ts +6 -0
  110. package/dist/backend/llvm/lib-shared.js +687 -0
  111. package/dist/backend/llvm/lib-shared.js.map +1 -0
  112. package/dist/backend/llvm/lib-stream.d.ts +2 -0
  113. package/dist/backend/llvm/lib-stream.js +470 -0
  114. package/dist/backend/llvm/lib-stream.js.map +1 -0
  115. package/dist/backend/llvm/shapes.d.ts +12 -2
  116. package/dist/backend/llvm/shapes.js +66 -307
  117. package/dist/backend/llvm/shapes.js.map +1 -1
  118. package/dist/backend/llvm/shapes.test.js +52 -0
  119. package/dist/backend/llvm/shapes.test.js.map +1 -0
  120. package/dist/backend/llvm/split.d.ts +43 -0
  121. package/dist/backend/llvm/split.js +227 -0
  122. package/dist/backend/llvm/split.js.map +1 -0
  123. package/dist/backend/llvm/split.test.d.ts +1 -0
  124. package/dist/backend/llvm/split.test.js +102 -0
  125. package/dist/backend/llvm/split.test.js.map +1 -0
  126. package/dist/backend/llvm/unsupported.d.ts +1 -1
  127. package/dist/backend/llvm/walkers.d.ts +2 -3
  128. package/dist/backend/llvm/walkers.js +164 -218
  129. package/dist/backend/llvm/walkers.js.map +1 -1
  130. package/dist/backend/native-codegen.d.ts +38 -0
  131. package/dist/backend/native-codegen.js +261 -0
  132. package/dist/backend/native-codegen.js.map +1 -0
  133. package/dist/backend/native-codegen.test.d.ts +1 -0
  134. package/dist/backend/native-codegen.test.js +188 -0
  135. package/dist/backend/native-codegen.test.js.map +1 -0
  136. package/dist/backend/native-link-info.d.ts +96 -0
  137. package/dist/backend/native-link-info.js +219 -0
  138. package/dist/backend/native-link-info.js.map +1 -0
  139. package/dist/backend/native-link-info.test.d.ts +1 -0
  140. package/dist/backend/native-link-info.test.js +134 -0
  141. package/dist/backend/native-link-info.test.js.map +1 -0
  142. package/dist/backend/{cc.d.ts → native-toolchain.d.ts} +139 -47
  143. package/dist/backend/{cc.js → native-toolchain.js} +1008 -910
  144. package/dist/backend/native-toolchain.js.map +1 -0
  145. package/dist/backend/native-toolchain.test.d.ts +1 -0
  146. package/dist/backend/{cc-cache.test.js → native-toolchain.test.js} +1297 -127
  147. package/dist/backend/native-toolchain.test.js.map +1 -0
  148. package/dist/backend/object-localize.js +1 -1
  149. package/dist/backend/object-localize.test.js +20 -0
  150. package/dist/backend/object-localize.test.js.map +1 -1
  151. package/dist/backend/runtime-abi.d.ts +10 -0
  152. package/dist/backend/runtime-abi.js +11 -0
  153. package/dist/backend/runtime-abi.js.map +1 -0
  154. package/dist/backend/runtime-pack.d.ts +137 -0
  155. package/dist/backend/runtime-pack.js +400 -0
  156. package/dist/backend/runtime-pack.js.map +1 -0
  157. package/dist/backend/runtime-pack.test.d.ts +1 -0
  158. package/dist/backend/runtime-pack.test.js +438 -0
  159. package/dist/backend/runtime-pack.test.js.map +1 -0
  160. package/dist/backend/targets.d.ts +30 -0
  161. package/dist/backend/targets.js +46 -0
  162. package/dist/backend/targets.js.map +1 -0
  163. package/dist/backend/targets.test.d.ts +1 -0
  164. package/dist/backend/targets.test.js +19 -0
  165. package/dist/backend/targets.test.js.map +1 -0
  166. package/dist/backend/vendor-archives.d.ts +41 -0
  167. package/dist/backend/vendor-archives.js +462 -0
  168. package/dist/backend/vendor-archives.js.map +1 -0
  169. package/dist/compat/fetch-profile.d.ts +0 -1
  170. package/dist/compat/fetch-profile.js +0 -1
  171. package/dist/compat/fetch-profile.js.map +1 -1
  172. package/dist/coverage/report.js +3 -3
  173. package/dist/coverage/report.js.map +1 -1
  174. package/dist/coverage/surface-manifest.js +25 -32
  175. package/dist/coverage/surface-manifest.js.map +1 -1
  176. package/dist/diagnostics/diagnostic.d.ts +11 -12
  177. package/dist/diagnostics/diagnostic.js +19 -17
  178. package/dist/diagnostics/diagnostic.js.map +1 -1
  179. package/dist/diagnostics/render.d.ts +1 -1
  180. package/dist/diagnostics/render.js +1 -1
  181. package/dist/diagnostics/render.js.map +1 -1
  182. package/dist/errors.d.ts +5 -0
  183. package/dist/errors.js +9 -0
  184. package/dist/errors.js.map +1 -0
  185. package/dist/executable/executable-cache.d.ts +86 -0
  186. package/dist/executable/executable-cache.js +398 -0
  187. package/dist/executable/executable-cache.js.map +1 -0
  188. package/dist/executable/executable-cache.test.d.ts +1 -0
  189. package/dist/executable/executable-cache.test.js +300 -0
  190. package/dist/executable/executable-cache.test.js.map +1 -0
  191. package/dist/ffi/{profile.d.ts → ffi-manifest.d.ts} +7 -2
  192. package/dist/ffi/{profile.js → ffi-manifest.js} +2 -1
  193. package/dist/ffi/ffi-manifest.js.map +1 -0
  194. package/dist/frontend/builtin-modules.d.ts +21 -0
  195. package/dist/frontend/builtin-modules.js +82 -0
  196. package/dist/frontend/builtin-modules.js.map +1 -0
  197. package/dist/frontend/cjs-lexer.d.ts +7 -0
  198. package/dist/frontend/cjs-lexer.js +15 -17
  199. package/dist/frontend/cjs-lexer.js.map +1 -1
  200. package/dist/frontend/dts-paths.d.ts +26 -0
  201. package/dist/frontend/dts-paths.js +41 -0
  202. package/dist/frontend/dts-paths.js.map +1 -0
  203. package/dist/frontend/input-tracker.d.ts +0 -2
  204. package/dist/frontend/input-tracker.js +1 -4
  205. package/dist/frontend/input-tracker.js.map +1 -1
  206. package/dist/frontend/lib-contract.d.ts +1 -5
  207. package/dist/frontend/lib-contract.js +1 -1
  208. package/dist/frontend/lib-contract.js.map +1 -1
  209. package/dist/frontend/lib-exports.d.ts +1 -1
  210. package/dist/frontend/lowering/call-position.d.ts +4 -0
  211. package/dist/frontend/lowering/call-position.js +7 -0
  212. package/dist/frontend/lowering/call-position.js.map +1 -0
  213. package/dist/frontend/lowering/callback-arg.d.ts +20 -0
  214. package/dist/frontend/lowering/callback-arg.js +44 -0
  215. package/dist/frontend/lowering/callback-arg.js.map +1 -0
  216. package/dist/frontend/lowering/lib-boundary.d.ts +1 -1
  217. package/dist/frontend/lowering/lib-boundary.js +34 -34
  218. package/dist/frontend/lowering/lib-boundary.js.map +1 -1
  219. package/dist/frontend/lowering/lower-assert.d.ts +3 -3
  220. package/dist/frontend/lowering/lower-assert.js +214 -241
  221. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  222. package/dist/frontend/lowering/lower-builtins.d.ts +74 -146
  223. package/dist/frontend/lowering/lower-builtins.js +1126 -1234
  224. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  225. package/dist/frontend/lowering/lower-calls.d.ts +56 -188
  226. package/dist/frontend/lowering/lower-calls.js +1409 -1494
  227. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  228. package/dist/frontend/lowering/lower-classes.d.ts +62 -125
  229. package/dist/frontend/lowering/lower-classes.js +832 -866
  230. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  231. package/dist/frontend/lowering/lower-comptime.d.ts +5 -12
  232. package/dist/frontend/lowering/lower-comptime.js +32 -31
  233. package/dist/frontend/lowering/lower-comptime.js.map +1 -1
  234. package/dist/frontend/lowering/lower-containers.d.ts +35 -135
  235. package/dist/frontend/lowering/lower-containers.js +1394 -1715
  236. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  237. package/dist/frontend/lowering/lower-dgram.d.ts +3 -7
  238. package/dist/frontend/lowering/lower-dgram.js +97 -111
  239. package/dist/frontend/lowering/lower-dgram.js.map +1 -1
  240. package/dist/frontend/lowering/lower-enums.d.ts +4 -4
  241. package/dist/frontend/lowering/lower-enums.js +30 -30
  242. package/dist/frontend/lowering/lower-enums.js.map +1 -1
  243. package/dist/frontend/lowering/{lower-emitter.d.ts → lower-event-emitter.d.ts} +7 -18
  244. package/dist/frontend/lowering/{lower-emitter.js → lower-event-emitter.js} +172 -174
  245. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -0
  246. package/dist/frontend/lowering/lower-expando.d.ts +5 -5
  247. package/dist/frontend/lowering/lower-expando.js +40 -40
  248. package/dist/frontend/lowering/lower-expando.js.map +1 -1
  249. package/dist/frontend/lowering/lower-exprs.d.ts +56 -264
  250. package/dist/frontend/lowering/lower-exprs.js +1644 -1704
  251. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  252. package/dist/frontend/lowering/lower-generators.d.ts +6 -6
  253. package/dist/frontend/lowering/lower-generators.js +73 -72
  254. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  255. package/dist/frontend/lowering/lower-inspect.d.ts +5 -17
  256. package/dist/frontend/lowering/lower-inspect.js +236 -238
  257. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  258. package/dist/frontend/lowering/lower-island.d.ts +34 -45
  259. package/dist/frontend/lowering/lower-island.js +440 -511
  260. package/dist/frontend/lowering/lower-island.js.map +1 -1
  261. package/dist/frontend/lowering/lower-mixins.d.ts +7 -10
  262. package/dist/frontend/lowering/lower-mixins.js +86 -86
  263. package/dist/frontend/lowering/lower-mixins.js.map +1 -1
  264. package/dist/frontend/lowering/lower-modules.d.ts +12 -18
  265. package/dist/frontend/lowering/lower-modules.js +284 -283
  266. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  267. package/dist/frontend/lowering/lower-namespaces.d.ts +23 -49
  268. package/dist/frontend/lowering/lower-namespaces.js +123 -115
  269. package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
  270. package/dist/frontend/lowering/lower-server.d.ts +18 -25
  271. package/dist/frontend/lowering/lower-server.js +899 -899
  272. package/dist/frontend/lowering/lower-server.js.map +1 -1
  273. package/dist/frontend/lowering/lower-stmts.d.ts +30 -149
  274. package/dist/frontend/lowering/lower-stmts.js +1176 -1229
  275. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  276. package/dist/frontend/lowering/lower-stream.d.ts +12 -12
  277. package/dist/frontend/lowering/lower-stream.js +300 -301
  278. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  279. package/dist/frontend/lowering/lower-test.d.ts +5 -5
  280. package/dist/frontend/lowering/lower-test.js +82 -82
  281. package/dist/frontend/lowering/lower-test.js.map +1 -1
  282. package/dist/frontend/lowering/lowerer.d.ts +66 -20
  283. package/dist/frontend/lowering/lowerer.js +421 -198
  284. package/dist/frontend/lowering/lowerer.js.map +1 -1
  285. package/dist/frontend/lowering/pairs-snapshot.d.ts +11 -0
  286. package/dist/frontend/lowering/pairs-snapshot.js +85 -0
  287. package/dist/frontend/lowering/pairs-snapshot.js.map +1 -0
  288. package/dist/frontend/lowering/static-this.d.ts +6 -0
  289. package/dist/frontend/lowering/static-this.js +24 -0
  290. package/dist/frontend/lowering/static-this.js.map +1 -0
  291. package/dist/frontend/lowering/surfaces.d.ts +14 -33
  292. package/dist/frontend/lowering/surfaces.js +64 -64
  293. package/dist/frontend/lowering/surfaces.js.map +1 -1
  294. package/dist/frontend/npm-static-rewrite.js +6 -28
  295. package/dist/frontend/npm-static-rewrite.js.map +1 -1
  296. package/dist/frontend/npm-static.d.ts +0 -10
  297. package/dist/frontend/npm-static.js +4 -7
  298. package/dist/frontend/npm-static.js.map +1 -1
  299. package/dist/frontend/npm.d.ts +0 -24
  300. package/dist/frontend/npm.js +11 -85
  301. package/dist/frontend/npm.js.map +1 -1
  302. package/dist/frontend/program.d.ts +3 -1
  303. package/dist/frontend/program.js +51 -17
  304. package/dist/frontend/program.js.map +1 -1
  305. package/dist/frontend/provenance-registry.d.ts +0 -2
  306. package/dist/frontend/provenance-registry.js +0 -10
  307. package/dist/frontend/provenance-registry.js.map +1 -1
  308. package/dist/frontend/provenance.js +4 -7
  309. package/dist/frontend/provenance.js.map +1 -1
  310. package/dist/frontend/resolve.d.ts +7 -2
  311. package/dist/frontend/resolve.js +12 -17
  312. package/dist/frontend/resolve.js.map +1 -1
  313. package/dist/frontend/resolve.test.d.ts +1 -0
  314. package/dist/frontend/resolve.test.js +29 -0
  315. package/dist/frontend/resolve.test.js.map +1 -0
  316. package/dist/frontend/ts7/adapter.d.ts +2 -2
  317. package/dist/frontend/ts7/adapter.js +1 -1
  318. package/dist/frontend/ts7/adapter.js.map +1 -1
  319. package/dist/frontend/ts7/checker.d.ts +40 -2
  320. package/dist/frontend/ts7/checker.js +182 -54
  321. package/dist/frontend/ts7/checker.js.map +1 -1
  322. package/dist/frontend/ts7/enums.js +2 -1
  323. package/dist/frontend/ts7/enums.js.map +1 -1
  324. package/dist/frontend/ts7/{program.js → program-adapter.js} +7 -6
  325. package/dist/frontend/ts7/program-adapter.js.map +1 -0
  326. package/dist/frontend/ts7/world-check.d.ts +1 -3
  327. package/dist/frontend/ts7/world-check.js +3 -1
  328. package/dist/frontend/ts7/world-check.js.map +1 -1
  329. package/dist/frontend/tsc-codes.d.ts +8 -0
  330. package/dist/frontend/tsc-codes.js +109 -0
  331. package/dist/frontend/tsc-codes.js.map +1 -0
  332. package/dist/frontend/{types.d.ts → type-mapper.d.ts} +2 -25
  333. package/dist/frontend/{types.js → type-mapper.js} +31 -52
  334. package/dist/frontend/type-mapper.js.map +1 -0
  335. package/dist/frontend/workspace-registry.d.ts +26 -0
  336. package/dist/frontend/workspace-registry.js +71 -0
  337. package/dist/frontend/workspace-registry.js.map +1 -0
  338. package/dist/index.d.ts +115 -30
  339. package/dist/index.js +650 -146
  340. package/dist/index.js.map +1 -1
  341. package/dist/ir/analysis.d.ts +37 -0
  342. package/dist/ir/analysis.js +118 -0
  343. package/dist/ir/analysis.js.map +1 -0
  344. package/dist/ir/analysis.test.d.ts +1 -0
  345. package/dist/ir/analysis.test.js +21 -0
  346. package/dist/ir/analysis.test.js.map +1 -0
  347. package/dist/ir/build.d.ts +9 -0
  348. package/dist/ir/build.js +33 -0
  349. package/dist/ir/build.js.map +1 -0
  350. package/dist/ir/integer-loops.d.ts +1 -1
  351. package/dist/ir/{nodes.d.ts → ir.d.ts} +60 -26
  352. package/dist/ir/{nodes.js → ir.js} +173 -141
  353. package/dist/ir/ir.js.map +1 -0
  354. package/dist/ir/ir.test.d.ts +1 -0
  355. package/dist/ir/ir.test.js +17 -0
  356. package/dist/ir/ir.test.js.map +1 -0
  357. package/dist/ir/serialize.d.ts +1 -1
  358. package/dist/ir/serialize.js +2 -1
  359. package/dist/ir/serialize.js.map +1 -1
  360. package/dist/ir/validate.d.ts +1 -1
  361. package/dist/ir/validate.js +16 -5
  362. package/dist/ir/validate.js.map +1 -1
  363. package/dist/library/cache-primitives.d.ts +24 -0
  364. package/dist/library/cache-primitives.js +83 -0
  365. package/dist/library/cache-primitives.js.map +1 -0
  366. package/dist/library/cache-reset.test.d.ts +1 -0
  367. package/dist/library/cache-reset.test.js +47 -0
  368. package/dist/library/cache-reset.test.js.map +1 -0
  369. package/dist/library/compiler-self-identity.d.ts +23 -0
  370. package/dist/library/compiler-self-identity.js +84 -0
  371. package/dist/library/compiler-self-identity.js.map +1 -0
  372. package/dist/library/fence-eval.d.ts +3 -1
  373. package/dist/library/fence-eval.js +5 -1
  374. package/dist/library/fence-eval.js.map +1 -1
  375. package/dist/library/int-infer.d.ts +1 -36
  376. package/dist/library/int-infer.js +17 -17
  377. package/dist/library/int-infer.js.map +1 -1
  378. package/dist/library/{early-cache.d.ts → library-cache.d.ts} +1 -1
  379. package/dist/library/{early-cache.js → library-cache.js} +37 -111
  380. package/dist/library/library-cache.js.map +1 -0
  381. package/dist/library/library-cache.test.d.ts +1 -0
  382. package/dist/library/{early-cache.test.js → library-cache.test.js} +2 -2
  383. package/dist/library/library-cache.test.js.map +1 -0
  384. package/dist/library/{profile.d.ts → library-profile.d.ts} +4 -7
  385. package/dist/library/{profile.js → library-profile.js} +18 -11
  386. package/dist/library/library-profile.js.map +1 -0
  387. package/dist/library/semantic-source.js +2 -1
  388. package/dist/library/semantic-source.js.map +1 -1
  389. package/dist/library/sidecar.d.ts +5 -2
  390. package/dist/library/sidecar.js +11 -5
  391. package/dist/library/sidecar.js.map +1 -1
  392. package/dist/startup-cache.d.ts +6 -0
  393. package/dist/startup-cache.js +6 -0
  394. package/dist/startup-cache.js.map +1 -0
  395. package/package.json +7 -2
  396. package/surface-manifest.json +1 -1
  397. package/dist/backend/cc-cache.test.js.map +0 -1
  398. package/dist/backend/cc.js.map +0 -1
  399. package/dist/backend/emission/emit-async.js.map +0 -1
  400. package/dist/backend/emission/emit-exprs.d.ts +0 -13
  401. package/dist/backend/emission/emit-exprs.js +0 -7407
  402. package/dist/backend/emission/emit-exprs.js.map +0 -1
  403. package/dist/backend/emission/emit-island.js.map +0 -1
  404. package/dist/backend/emission/emit-shapes.js.map +0 -1
  405. package/dist/backend/emission/emit-stmts.js.map +0 -1
  406. package/dist/backend/emission/emit-types.js.map +0 -1
  407. package/dist/backend/emission/emit-walkers.js.map +0 -1
  408. package/dist/backend/emission/emitter.js.map +0 -1
  409. package/dist/backend/emission/may-throw.js.map +0 -1
  410. package/dist/backend/library-identity.js.map +0 -1
  411. package/dist/ffi/profile.js.map +0 -1
  412. package/dist/frontend/lowering/lower-emitter.js.map +0 -1
  413. package/dist/frontend/shared.d.ts +0 -82
  414. package/dist/frontend/shared.js +0 -308
  415. package/dist/frontend/shared.js.map +0 -1
  416. package/dist/frontend/ts7/program.js.map +0 -1
  417. package/dist/frontend/types.js.map +0 -1
  418. package/dist/ir/nodes.js.map +0 -1
  419. package/dist/library/early-cache.js.map +0 -1
  420. package/dist/library/early-cache.test.js.map +0 -1
  421. package/dist/library/profile.js.map +0 -1
  422. /package/dist/backend/{cc-cache.test.d.ts → c/types.test.d.ts} +0 -0
  423. /package/dist/{library/early-cache.test.d.ts → backend/llvm/shapes.test.d.ts} +0 -0
  424. /package/dist/frontend/ts7/{program.d.ts → program-adapter.d.ts} +0 -0
@@ -1,3 +1,4 @@
1
+ import { InternalCompilerError } from "../../errors.js";
1
2
  /* AST + checker → IR.
2
3
  *
3
4
  * Invariants:
@@ -13,21 +14,22 @@
13
14
  * ("x.0", "x.1" for shadowing); the IR is scope-flat.
14
15
  */
15
16
  import { resolve } from "node:path";
16
- import { isRelativeSpecifier, tsgoPath } from "../shared.js";
17
+ import { tsgoPath } from "../dts-paths.js";
18
+ import { isRelativeSpecifier } from "../workspace-registry.js";
17
19
  import * as ts from "../ts7/adapter.js";
18
20
  import { anyOpRequiresDynamicDiag, blockedBindingUseDiag, checkerPanicDiag, componentTypeDiag, isCheckerPanic, genericSignatureTypeDiag, indexSignatureTypeDiag, intersectionTypeDiag, noLoweringDiag, overloadedSignatureTypeDiag, recordShapeMismatchDiag, requiresDynamicApiDiag, requiresDynamicPackageDiag, requiresDynamicTypeDiag, unionMismatchDiag, unsupportedDiag, unsupportedTypeDiag, } from "../../diagnostics/diagnostic.js";
19
- import { arrayOf, BOOL, canAdaptDynFuncTo, canConvertToDyn, canCrossIslandBoundary, canExitIslandToType, canMarshalTypedFuncIntoIsland, DYN, F64, isJsonSafeType, isUndefinedArmedUnion, isUnitType, JSVAL, RUNTIME_ERROR_CLASSES, STRING, typeEquals, UNDEFINED_T, VOID } from "../../ir/nodes.js";
21
+ import { arrayOf, BOOL, canAdaptDynFuncTo, canConvertToDyn, canCrossIslandBoundary, canExitIslandToType, canMarshalTypedFuncIntoIsland, DYN, F64, isJsonSafeType, isUndefinedArmedUnion, isUnitType, JSVAL, RUNTIME_ERROR_CLASSES, STRING, typeEquals, UNDEFINED_T, VOID } from "../../ir/ir.js";
20
22
  import { provenanceActive } from "../provenance-registry.js";
21
23
  import { ambientDtsPath, canonicalBuiltinModule, cjsExportAssignmentOf, cjsExportDiscardReason, fallbackDtsPath, isCjsExportTableLiteral, isJsSourceFile, isNodeEsmFile, isNodeTypesPath, locOf, orderedImportsOf, overridesDtsPath, npmStaticDepSf7, requireSpecOf, resolveImport, workspacePackageOfPath, } from "../program.js";
22
- import { containsRecord, containsUnion, describeComponentBlocker, describeRecordMemberBlocker, formatIrType, ISLAND_AMBIENT_TYPES, isUnitOnlyTsType, mapType, ShapeRegistry, typeKey, UnionRegistry, withUndefinedArm as withUndefinedArmCanonical, } from "../types.js";
24
+ import { containsRecord, containsUnion, describeComponentBlocker, describeRecordMemberBlocker, formatIrType, ISLAND_AMBIENT_TYPES, isUnitOnlyTsType, mapType, ShapeRegistry, typeKey, UnionRegistry, withUndefinedArm as withUndefinedArmCanonical, } from "../type-mapper.js";
23
25
  import { boundaryIntoIslandMsg, boundaryOutOfIslandMsg, builtinConstLit, builtinModuleConstOf, builtinModulesArrayLit, builtinFenceHintOf, builtinModuleFnOf, stdlibMemberFence, isStdlibMember, isStdlibSymbol, isStdlibGlobal, stdlibGlobalMember, nodeTypesOnlySymbol } from "./surfaces.js";
24
26
  import { splitFiles, collectProgram, collectNpmImports, collectJsonImports, moduleArtifacts, collectGlobals, declSymbolOf, defaultExportSymbolOf, lowerFileInit, lowerDefaultExport, buildMain, appendDynamicImportModules } from "./lower-modules.js";
25
27
  import { registerBuiltinErrorClasses, registerBuiltinEmitterClass, registerBuiltinStreamClasses, builtinErrorInfoOf, builtinEmitterInfoOf, builtinStreamInfoOf, analyzeClassDecoration, classIteratorDrainCall, classIteratorNextCall, classIteratorOf, classIteratorOpenCall, classIteratorRestDrainCall, classMemberNameOf, classValueRef, collectClassShape, exactClassOfReceiver, collectClassShapeInner, ctorAbiEquals, findMethodOn, findStaticOn, findGenericMethodOn, findGenericStaticOn, 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, errorMessageArg, lowerNew, accessorCall } from "./lower-classes.js";
26
28
  import { mixinCallClassInfoOf, mixinIntersectionInstanceType } from "./lower-mixins.js";
27
- import { bindingNeverReassigned, bodyReadsArguments, isThisParameter, paramShape, paramShapes, checkDefaultParamBodyType, completeArgs, wrappedUndefined, undefinedArgFor, requireExactArityValue, bodyReturnType, declaredReturnType, collectSignature, collectSignatureInner, collectGenericSignature, genericFnOf, lowerGenericCall, lowerGenericFnValue, inferTypeParamBindings, lowerGenericInstance, lowerCall, lowerFfiCall, lowerTimersMemberCall, lowerPromiseMethodCall, lowerFilterNarrowCall, isTopLevelFnSymbol, lowerNestedFunctionDecl, lambdaSignature, lowerLambda, lowerFunction, validateFfiImports } from "./lower-calls.js";
29
+ import { bindingNeverReassigned, bodyReadsArguments, implicitMonoFile, isThisParameter, paramShape, paramShapes, checkDefaultParamBodyType, completeArgs, wrappedUndefined, undefinedArgFor, requireExactArityValue, bodyReturnType, declaredReturnType, collectSignature, collectSignatureInner, collectGenericSignature, genericFnOf, lowerGenericCall, lowerGenericFnValue, inferTypeParamBindings, lowerGenericInstance, lowerCall, lowerFfiCall, lowerTimersMemberCall, lowerPromiseMethodCall, lowerFilterNarrowCall, isTopLevelFnSymbol, lowerNestedFunctionDecl, lambdaSignature, lowerLambda, lowerFunction, validateFfiImports } from "./lower-calls.js";
28
30
  import { lowerArrayMethodCall, lowerBufferStaticCall, lowerBytesMethodCall, lowerBytesNew, lowerMapMethodCall, lowerMapForEachCall, buildMapForEachFn, lowerRecordOvfCaptureHelper, lowerEnvToPairsHelper, lowerSetMethodCall, lowerSetForEachCall, buildSetForEachFn, lowerRegexMethodCall, lowerStringMethodCall } from "./lower-containers.js";
29
31
  import { lowerStreamModuleCall } from "./lower-stream.js";
30
- import { lowerEmitOverrideSpec } from "./lower-emitter.js";
32
+ import { lowerEmitOverrideSpec } from "./lower-event-emitter.js";
31
33
  import { builtinImportOf, createRequireBindingDecl, createRequireNamespaceDecl, createRequireSpecOf, stripTypeCasts, lowerBuiltinModuleCall, lowerFsToUnixTimestampCall, lowerFsLadderCall, lowerChildArgsArg, lowerSpawnSyncCall, lowerSpawnCall, lowerExecSyncCall, recordToEnvPairs, lowerJsonMethodCall, fencedBuiltinImportOf, lowerCryptoComposedCall, lowerUrlMethodCall, lowerSearchParamsMethodCall, lowerStatsMethodCall, lowerChildMethodCall, lowerAtomicsCall, lowerBuiltinExtraProperty, promisifiedExecFileDecl, lowerExecFileAsyncCall, execFileAsyncHelper, lowerStringDecoderMethodCall, strdecHelper, lowerReadlineMethodCall, lowerDcChannelMethodCall, lowerDcChannelProperty, lowerAlsMethodCall, lowerDcTracingChannelMethodCall, lowerDcTracingChannelProperty, lowerJsonProperty, lowerErrorCodeProperty, lowerProcessProperty, isProcessEnv, envValueType, lowerProcessEnvGet, lowerProcessMethodCall, lowerProcessOptionalMethodCall, lowerTimeoutMethodCall, envSnapshotHelper, isConsoleLog, consoleCallMember, lowerNumberStaticCall, lowerNumberStaticProperty, lowerDateCall, lowerTextCodecCall, lowerCryptoModuleCall, lowerFsConstantsProperty, lowerBuiltinConstantsProperty, builtinConstantBindingOf, builtinConstantsDestructureDecl, lowerProcessStreamProperty, lowerStringStaticCall, lowerStringLastIndexOfCall, lowerPromiseStaticCall, textCodecBindingClassOf } from "./lower-builtins.js";
32
34
  import { fenceFetchObjectAssignment, fenceFetchObjectBinding, fenceStaticAbortControllerMemberRead, fenceStaticHeadersIteration, fenceStaticHeadersMember, fenceStaticReadableStreamMember, fenceStaticResponseMember, fenceUnsupportedFetchConstructorMember, isIslandExpr, islandFuncValueFence, islandRegexpOf, jsvalIn, requireDynamicApi, islandGlobalFnOf, lowerAbortControllerNew, lowerDynamicHeadersIteratorCall, lowerDynamicHeadersSpread, lowerDynamicImportCall, lowerFetchCall, lowerFetchElementMethodCall, lowerResponseNew, lowerStaticFetchCompanionCall, lowerStaticAbortControllerCall, lowerStaticAbortSignalListenerCall, lowerStaticReadableStreamCancelCall, lowerStaticReadableStreamControllerCall, lowerStaticReadableStreamNew, lowerStaticReadableStreamReaderCall, lowerStaticResponseCall, lowerIslandMethodCall, lowerMathProperty, npmPackageOf, npmMemberFence, npmPackageOfSymbol } from "./lower-island.js";
33
35
  import { lowerHttpHeadersElement, lowerNetModuleCall, lowerServerMethodCall, lowerServerProperty, lowerTlsRootCertificates } from "./lower-server.js";
@@ -40,6 +42,7 @@ import { lowerStmts, noteBlockedBindings, isBlockedBinding, lowerScopedBlock, pr
40
42
  import { lowerDynObjectLiteral, lowerExpr, maybeNarrow, lowerUnitComparison, lowerNullishCoalesce, lowerOptionalChain, finishOptionalChain, lowerCondition, ensureBool, requireTruthyUnion, eqComparableUnion, lowerIntrinsicProperty, lowerArrayLiteral, lowerObjectLiteral, lowerShorthandValue, rejectThisInObjectMethod, lowerElementAccess, lowerElementWrite, lowerRecordKeyRead, ensureString, lowerTemplate, lowerAsExpression, lowerPrefixUnary, lowerBinary, lowerCaughtTypeofTest, caughtRead, caughtLocalOf, caughtToString, lowerInstanceOf, lowerRegexLiteral, lowerFieldRead, lowerUnionProperty, fieldTarget, fieldGetExpr, fieldSetStmt, lowerFieldCompound, uniqueSymbolKeyOf, foldedStringKeyOf } from "./lower-exprs.js";
41
43
  import { lowerRecordFieldCall, lowerObjectMethodCall } from "./lower-calls.js";
42
44
  import { fenceCrossBlockNsRef, nsPathPrefix } from "./lower-namespaces.js";
45
+ import { numLit, varRef } from "../../ir/build.js";
43
46
  /** Entry function name. '%' cannot appear in a TS identifier, so a user
44
47
  * function can never collide with it (mangling is injective per prefix). */
45
48
  export const ENTRY_NAME = "%main";
@@ -56,7 +59,7 @@ export function own(table, key) {
56
59
  /** Sentinel binding key for `this` (which has no ts.Symbol): a stable
57
60
  * object identity used in the same scope/capture maps as real symbols, so
58
61
  * arrows capturing `this` ride the ordinary capture machinery. */
59
- export const THIS_BINDING = { escapedName: "%this" };
62
+ const THIS_BINDING = { escapedName: "%this" };
60
63
  export function newFnCtx(lifted, selfSymbol, selfType, returnType) {
61
64
  return {
62
65
  locals: [],
@@ -76,7 +79,7 @@ export function newFnCtx(lifted, selfSymbol, selfType, returnType) {
76
79
  * visit; descending would attribute a nested island statement to every
77
80
  * enclosing construct too). The top-level statement object itself is
78
81
  * always visited. */
79
- export const IR_STMT_KINDS = new Set([
82
+ const IR_STMT_KINDS = new Set([
80
83
  "varDecl", "assign", "exprStmt", "if", "while", "doWhile", "switch",
81
84
  "arraySet", "forOf", "return", "fieldSet", "recordSet", "break",
82
85
  "continue", "block", "tryCatch", "throw", "rethrow", "runtimeFence",
@@ -308,8 +311,8 @@ export function importCallHandleType(expr) {
308
311
  * Ambient (.d.ts) declarations never reach this: they have no compiled
309
312
  * implementation, so their calls lower through the island/builtin paths
310
313
  * whose validated exits keep the checker-trust trap. */
311
- export function uncheckedOverloadHandleCall(L, expr) {
312
- if (!L.dynamic || !expr)
314
+ export function uncheckedOverloadHandleCall(lowerer, expr) {
315
+ if (!lowerer.dynamic || !expr)
313
316
  return false;
314
317
  let e = expr;
315
318
  while (ts.isParenthesizedExpression(e))
@@ -319,25 +322,25 @@ export function uncheckedOverloadHandleCall(L, expr) {
319
322
  // overload of an any-returning implementation stores the handle.
320
323
  if (!ts.isCallExpression(e) && !ts.isTaggedTemplateExpression(e))
321
324
  return false;
322
- const rsig = L.checker.getResolvedSignature(e);
323
- const rdecl = rsig ? L.checker.signatureDeclaration(rsig) : undefined;
325
+ const rsig = lowerer.checker.getResolvedSignature(e);
326
+ const rdecl = rsig ? lowerer.checker.signatureDeclaration(rsig) : undefined;
324
327
  if (!rsig || !rdecl)
325
328
  return false;
326
329
  if (!(ts.isFunctionDeclaration(rdecl) || ts.isMethodDeclaration(rdecl)) || rdecl.body)
327
330
  return false;
328
331
  const name = rdecl.name;
329
- const symbol = name ? L.checker.getSymbolAtLocation(name) : undefined;
332
+ const symbol = name ? lowerer.checker.getSymbolAtLocation(name) : undefined;
330
333
  if (!symbol)
331
334
  return false;
332
- const impl = L.checker
335
+ const impl = lowerer.checker
333
336
  .declarationsOf(symbol)
334
337
  .find((d) => (ts.isFunctionDeclaration(d) || ts.isMethodDeclaration(d)) && d.body !== undefined);
335
338
  if (!impl)
336
339
  return false;
337
- const implSig = L.checker.getSignatureFromDeclaration(impl);
340
+ const implSig = lowerer.checker.getSignatureFromDeclaration(impl);
338
341
  if (!implSig)
339
342
  return false;
340
- return L.mapTypeOf(L.checker.getReturnTypeOfSignature(implSig))?.kind === "jsval";
343
+ return lowerer.mapTypeOf(lowerer.checker.getReturnTypeOfSignature(implSig))?.kind === "jsval";
341
344
  }
342
345
  /** The JavaScript declaration fallback for unmappable binding types (see
343
346
  * irTypeOf): `any` and every other inference residue is the checked-
@@ -356,16 +359,16 @@ export function uncheckedOverloadHandleCall(L, expr) {
356
359
  * checked-dynamic fallbacks apply, the pre-never-mapping behavior. Bare
357
360
  * `never` at the ROOT stays out (`for (const v of [])`'s loop var — the
358
361
  * dead read the f64 mapping is FOR). */
359
- export function neverTaintedJsType(L, node, t) {
362
+ export function neverTaintedJsType(lowerer, node, t) {
360
363
  if (!isJsSourceFile(node.getSourceFile()))
361
364
  return false;
362
365
  const walk = (x, depth) => {
363
366
  if (depth === 0)
364
367
  return false;
365
368
  if (x.isUnionType())
366
- return x.getTypes().some((a) => walk(a, depth - 1));
367
- if (L.checker.isArrayType(x) || L.checker.isTupleType(x)) {
368
- return L.checker
369
+ return ts.constituentTypes(x).some((a) => walk(a, depth - 1));
370
+ if (lowerer.checker.isArrayType(x) || lowerer.checker.isTupleType(x)) {
371
+ return lowerer.checker
369
372
  .getTypeArguments(x)
370
373
  .some((a) => (a.flags & ts.TypeFlags.Never) !== 0 || walk(a, depth - 1));
371
374
  }
@@ -414,10 +417,10 @@ export function nodeThrowExpr(kind, code, message, type, loc) {
414
417
  * (scr_throw_lowering_fence). The diagnostic joins the runtime-fence
415
418
  * ledger exactly like a deferred statement fence — nothing silently
416
419
  * drops off the coverage report. */
417
- export function ladderFenceExpr(L, surface, node, hint) {
420
+ export function ladderFenceExpr(lowerer, surface, node, hint) {
418
421
  const loc = locOf(node);
419
422
  const d = noLoweringDiag(surface, loc, hint);
420
- L.runtimeFences.push(d);
423
+ lowerer.runtimeFences.push(d);
421
424
  const sf = node.getSourceFile();
422
425
  const pos = ts.getLineAndCharacterOfPosition(sf, loc.start);
423
426
  return {
@@ -450,7 +453,7 @@ export function ladderFenceExpr(L, surface, node, hint) {
450
453
  * this fallback for `any` (mapType answers jsval first).
451
454
  *
452
455
  * Null for void (no value exists to represent). */
453
- export function dynFallbackType(L, node, t) {
456
+ export function dynFallbackType(lowerer, node, t) {
454
457
  if (t.flags & ts.TypeFlags.Void)
455
458
  return null;
456
459
  if (!isJsSourceFile(node.getSourceFile())) {
@@ -459,13 +462,13 @@ export function dynFallbackType(L, node, t) {
459
462
  // TS single-call-signature function types: per-piece fallback, but
460
463
  // ONLY `any` pieces fall to dyn — any other unmappable piece keeps
461
464
  // the whole type's own fence.
462
- return anyPiecedFuncType(L, node, t);
465
+ return anyPiecedFuncType(lowerer, node, t);
463
466
  }
464
- if (L.checker.isArrayType(t)) {
465
- const elem = L.checker.getTypeArguments(t)[0];
467
+ if (lowerer.checker.isArrayType(t)) {
468
+ const elem = lowerer.checker.getTypeArguments(t)[0];
466
469
  const elemTainted = elem !== undefined &&
467
- ((elem.flags & ts.TypeFlags.Never) !== 0 || neverTaintedJsType(L, node, elem));
468
- const mappedElem = elem !== undefined && !elemTainted ? L.mapTypeOf(elem) : null;
470
+ ((elem.flags & ts.TypeFlags.Never) !== 0 || neverTaintedJsType(lowerer, node, elem));
471
+ const mappedElem = elem !== undefined && !elemTainted ? lowerer.mapTypeOf(elem) : null;
469
472
  // A mappable element keeps the static array; an unmappable one makes
470
473
  // the WHOLE value dyn (the checked-dynamic tree has real arrays — length/index/push
471
474
  // read through the keyed-dyn paths; dyn-element STATIC arrays have no
@@ -482,14 +485,14 @@ export function dynFallbackType(L, node, t) {
482
485
  // construct signatures, overloads, and function-with-properties shapes
483
486
  // stay out (the whole value falls to dyn below, where every reached
484
487
  // use meets its own fence or boxes as-is).
485
- const sig = pureSingleCallSignatureOf(L, t);
488
+ const sig = pureSingleCallSignatureOf(lowerer, t);
486
489
  if (sig) {
487
490
  const params = sig.getParameters().map((p) => {
488
- const pt = L.checker.getTypeOfSymbolAtLocation(p, node);
489
- return L.mapTypeOf(pt) ?? DYN;
491
+ const pt = lowerer.checker.getTypeOfSymbolAtLocation(p, node);
492
+ return lowerer.mapTypeOf(pt) ?? DYN;
490
493
  });
491
- const retT = L.checker.getReturnTypeOfSignature(sig);
492
- const ret = retT.flags & ts.TypeFlags.Void ? VOID : L.mapTypeOf(retT) ?? DYN;
494
+ const retT = lowerer.checker.getReturnTypeOfSignature(sig);
495
+ const ret = retT.flags & ts.TypeFlags.Void ? VOID : lowerer.mapTypeOf(retT) ?? DYN;
493
496
  return { kind: "func", params, ret };
494
497
  }
495
498
  return DYN;
@@ -498,23 +501,23 @@ export function dynFallbackType(L, node, t) {
498
501
  * properties, no construct signatures, no type parameters, no rest params
499
502
  * (declared or synthesized from an `arguments` read). Null for every
500
503
  * other shape. The structural gate both dynFallbackType arms share. */
501
- function pureSingleCallSignatureOf(L, t) {
504
+ function pureSingleCallSignatureOf(lowerer, t) {
502
505
  if (!(t.flags & ts.TypeFlags.Object))
503
506
  return null;
504
- const sigs = L.checker.getCallSignatures(t);
507
+ const sigs = lowerer.checker.getCallSignatures(t);
505
508
  if (sigs.length === 1 &&
506
- L.checker.getPropertiesOfType(t).length === 0 &&
507
- L.checker.getConstructSignatures(t).length === 0 &&
509
+ lowerer.checker.getPropertiesOfType(t).length === 0 &&
510
+ lowerer.checker.getConstructSignatures(t).length === 0 &&
508
511
  sigs[0].getTypeParameters().length === 0 &&
509
512
  sigs[0].getParameters().every((p) => {
510
- const pDecl = L.checker.valueDeclarationOf(p);
513
+ const pDecl = lowerer.checker.valueDeclarationOf(p);
511
514
  return !pDecl || !ts.isParameter(pDecl) || pDecl.dotDotDotToken === undefined;
512
515
  }) &&
513
516
  // A SYNTHESIZED rest param (tsc's `arguments` inference — no
514
517
  // valueDeclaration to carry the dotDotDot): param-count mismatch
515
518
  // against the signature's declaration; the whole value stays dyn.
516
519
  (() => {
517
- const sigDecl = L.checker.signatureDeclaration(sigs[0]);
520
+ const sigDecl = lowerer.checker.signatureDeclaration(sigs[0]);
518
521
  const declParams = sigDecl !== undefined && ts.isFunctionLike(sigDecl) ? sigDecl.parameters : undefined;
519
522
  if (declParams !== undefined && declParams.length !== sigs[0].getParameters().length)
520
523
  return false;
@@ -534,21 +537,21 @@ function pureSingleCallSignatureOf(L, t) {
534
537
  * irTypeOf fallback, so the binding type and the closure type agree).
535
538
  * A piece that fails to map for any other reason answers null — the
536
539
  * whole type keeps its own diagnostic. */
537
- function anyPiecedFuncType(L, node, t) {
538
- const sig = pureSingleCallSignatureOf(L, t);
540
+ function anyPiecedFuncType(lowerer, node, t) {
541
+ const sig = pureSingleCallSignatureOf(lowerer, t);
539
542
  if (!sig)
540
543
  return null;
541
544
  const params = [];
542
545
  for (const p of sig.getParameters()) {
543
- const pt = L.checker.getTypeOfSymbolAtLocation(p, node);
544
- const mapped = L.mapTypeOf(pt) ?? (pt.flags & ts.TypeFlags.Any ? DYN : null);
546
+ const pt = lowerer.checker.getTypeOfSymbolAtLocation(p, node);
547
+ const mapped = lowerer.mapTypeOf(pt) ?? (pt.flags & ts.TypeFlags.Any ? DYN : null);
545
548
  if (!mapped || mapped.kind === "void")
546
549
  return null;
547
550
  params.push(mapped);
548
551
  }
549
- const retT = L.checker.getReturnTypeOfSignature(sig);
552
+ const retT = lowerer.checker.getReturnTypeOfSignature(sig);
550
553
  const ret = retT.flags & (ts.TypeFlags.Void | ts.TypeFlags.Never) ? VOID
551
- : L.mapTypeOf(retT) ?? (retT.flags & ts.TypeFlags.Any ? DYN : null);
554
+ : lowerer.mapTypeOf(retT) ?? (retT.flags & ts.TypeFlags.Any ? DYN : null);
552
555
  if (!ret)
553
556
  return null;
554
557
  return { kind: "func", params, ret };
@@ -863,7 +866,7 @@ export class Lowerer {
863
866
  * Reachability lowers inits before the declarations they discover, so
864
867
  * these rebuild after the worklist restores historical shape metadata. */
865
868
  shapeOrderHelperFinalizers = [];
866
- /** Emit-override specializations (`%C.emit:<event>` — lower-emitter.ts's
869
+ /** Emit-override specializations (`%C.emit:<event>` — lower-event-emitter.ts's
867
870
  * emit-overrides block): interned names, the drive-loop queue, and the
868
871
  * currently-lowering specialization's context (the super-forward
869
872
  * interception reads it). */
@@ -1130,7 +1133,7 @@ export class Lowerer {
1130
1133
  get ctx() {
1131
1134
  const top = this.fnStack[this.fnStack.length - 1];
1132
1135
  if (!top)
1133
- throw new Error("lowerer bug: no active function context");
1136
+ throw new InternalCompilerError("lowerer bug: no active function context");
1134
1137
  return top;
1135
1138
  }
1136
1139
  get scopes() {
@@ -1377,6 +1380,31 @@ export class Lowerer {
1377
1380
  this.flushDeferred(symbol);
1378
1381
  return symbol;
1379
1382
  }
1383
+ /** Whether this exact direct call belongs to a manifest-validated native
1384
+ * binding. Declaration classification uses this as a probe before normal
1385
+ * expression lowering: resolving must not flush deferred diagnostics or
1386
+ * trigger the merged-namespace fence just because it is asking ownership.
1387
+ * Call lowering remains the authority for every ABI and call-shape
1388
+ * diagnostic once this answers true. */
1389
+ ownsFfiCall(expr) {
1390
+ if (!ts.isIdentifier(expr.expression))
1391
+ return false;
1392
+ const binding = this.ffiImportsByName.get(expr.expression.text);
1393
+ if (binding === undefined || this.ffiBindingSymbols === null)
1394
+ return false;
1395
+ const validSymbols = this.ffiBindingSymbols.get(binding.name);
1396
+ if (validSymbols === undefined)
1397
+ return false;
1398
+ const wasCollecting = this.collecting;
1399
+ this.collecting = true;
1400
+ try {
1401
+ const symbol = this.resolveValueSymbol(expr.expression);
1402
+ return symbol !== null && validSymbols.has(symbol);
1403
+ }
1404
+ finally {
1405
+ this.collecting = wasCollecting;
1406
+ }
1407
+ }
1380
1408
  /** The configured external host module owning an expression's runtime
1381
1409
  * value, or null. Alias chains are followed to their declaration file so
1382
1410
  * direct imports and local re-export facades classify identically. Type
@@ -1985,6 +2013,16 @@ export class Lowerer {
1985
2013
  }
1986
2014
  run() {
1987
2015
  const parts = this.splitFiles();
2016
+ // The coverage remainder deliberately visits every body that reachable
2017
+ // emit skipped. Those files are already phase-managed, so an ordinary
2018
+ // checker miss would stay a one-node IPC query instead of falling back
2019
+ // to the facade's whole-file batch. Coverage has no dead-body boundary
2020
+ // to preserve: prime each complete file now, reusing the answers the
2021
+ // reachable pass already memoized and batching only the cold remainder.
2022
+ if (this.remainder) {
2023
+ for (const fp of parts)
2024
+ this.checker.prefetchSourceFile(fp.sf);
2025
+ }
1988
2026
  this.collectProgram(parts);
1989
2027
  // Decorated classes analyze AFTER the whole collection pass: a
1990
2028
  // decorator's return type may name a subclass declared below the
@@ -2339,6 +2377,23 @@ export class Lowerer {
2339
2377
  * themselves. */
2340
2378
  emitReachable(extraRoots) {
2341
2379
  const parts = this.splitFiles();
2380
+ // Direct lowering callers do not necessarily run program preflight.
2381
+ // Establish the same managed header/top-level batch here before
2382
+ // collection, while the production path simply finds warm memos.
2383
+ this.checker.prefetchSourceFileStructures(parts.map((fp) => fp.sf));
2384
+ // Signature collection may read the initializer type of a default whose
2385
+ // body type still admits undefined (for example `value =
2386
+ // process.env.VALUE`). The expression executes only when reached, but
2387
+ // that type query is mandatory now; batch hot defaults across ordinary
2388
+ // declarations before collectProgram visits their signatures.
2389
+ this.checker.prefetchCollectionTypes(parts.flatMap((fp) => fp.fnDecls
2390
+ .filter((decl) => decl.body !== undefined && decl.typeParameters === undefined)
2391
+ .flatMap((decl) => decl.parameters.flatMap((param) => param.initializer ? [param.initializer] : []))));
2392
+ // JavaScript class shapes are partly declared by constructor-body
2393
+ // assignments. Batch those collection-time queries across declarations
2394
+ // before collectProgram visits them one by one; reached body lowering
2395
+ // will reuse the same answers later.
2396
+ this.prefetchClassCollection(parts.flatMap((fp) => fp.classDecls));
2342
2397
  this.collectProgram(parts);
2343
2398
  // Decorated classes analyze post-collection here too: the %init seeds
2344
2399
  // lower the decoration calls, whose edges (decorator bodies, construct
@@ -2350,6 +2405,14 @@ export class Lowerer {
2350
2405
  // retained-function keys and are deterministic by construction
2351
2406
  // (qualified declaration names).
2352
2407
  const units = new Map();
2408
+ const bodyRoots = (...roots) => roots.filter((root) => root !== undefined && root !== null);
2409
+ const functionRoots = (decl) => bodyRoots(...decl.parameters.map((param) => param.initializer), decl.body);
2410
+ const classCtorRoots = (info) => bodyRoots(...(info.ctor?.parameters ?? []).map((param) => param.initializer), info.ctor?.body, ...info.fieldOrder.map((field) => field.initializer));
2411
+ const classMemberRoots = (info) => [
2412
+ ...classCtorRoots(info),
2413
+ ...[...this.classMethodMembers(info)].flatMap(({ member }) => functionRoots(member)),
2414
+ ...[...(info.staticMethods?.values() ?? [])].flatMap(({ member }) => functionRoots(member)),
2415
+ ];
2353
2416
  let unitOrder = 0;
2354
2417
  for (const fp of parts) {
2355
2418
  for (const decl of fp.fnDecls) {
@@ -2362,8 +2425,13 @@ export class Lowerer {
2362
2425
  if (!declSymbol || this.genericFnsBySymbol.has(declSymbol))
2363
2426
  continue;
2364
2427
  const sig = this.fnSigsBySymbol.get(declSymbol);
2365
- if (sig)
2366
- units.set(sig.name, { order: unitOrder++, lower: () => this.lowerFunction(decl) });
2428
+ if (sig) {
2429
+ units.set(sig.name, {
2430
+ order: unitOrder++,
2431
+ roots: functionRoots(decl),
2432
+ lower: () => this.lowerFunction(decl),
2433
+ });
2434
+ }
2367
2435
  }
2368
2436
  }
2369
2437
  for (const info of this.classes.values()) {
@@ -2378,16 +2446,32 @@ export class Lowerer {
2378
2446
  // A FAMILY has no constructor function and no instance members —
2379
2447
  // only its statics are units.
2380
2448
  if (!info.generic) {
2381
- units.set(`%${cName}.constructor`, { order: unitOrder++, lower: () => this.lowerClassCtor(info) });
2449
+ units.set(`%${cName}.constructor`, {
2450
+ order: unitOrder++,
2451
+ roots: classCtorRoots(info),
2452
+ lower: () => this.lowerClassCtor(info),
2453
+ });
2382
2454
  for (const { mName, member } of this.classMethodMembers(info)) {
2383
- units.set(`%${cName}.${mName}`, { order: unitOrder++, lower: () => this.lowerClassMethodMember(info, member) });
2455
+ units.set(`%${cName}.${mName}`, {
2456
+ order: unitOrder++,
2457
+ roots: functionRoots(member),
2458
+ lower: () => this.lowerClassMethodMember(info, member),
2459
+ });
2384
2460
  }
2385
2461
  for (const prop of info.throwingSetters) {
2386
- units.set(`%${cName}.set:${prop}`, { order: unitOrder++, lower: () => this.throwingSetterFn(info, prop) });
2462
+ units.set(`%${cName}.set:${prop}`, {
2463
+ order: unitOrder++,
2464
+ roots: [],
2465
+ lower: () => this.throwingSetterFn(info, prop),
2466
+ });
2387
2467
  }
2388
2468
  }
2389
- for (const name of info.staticMethods?.keys() ?? []) {
2390
- units.set(`%${cName}.static:${name}`, { order: unitOrder++, lower: () => lowerStaticMethod(this, info, name) });
2469
+ for (const [name, entry] of info.staticMethods ?? []) {
2470
+ units.set(`%${cName}.static:${name}`, {
2471
+ order: unitOrder++,
2472
+ roots: functionRoots(entry.member),
2473
+ lower: () => lowerStaticMethod(this, info, name),
2474
+ });
2391
2475
  }
2392
2476
  }
2393
2477
  // The old emit pass visited each file's functions and then its classes,
@@ -2461,19 +2545,19 @@ export class Lowerer {
2461
2545
  // edge to them can fire (references require the collected class).
2462
2546
  this.onExprClassCollected = (info) => {
2463
2547
  const cName = info.def.name;
2464
- const register = (name, lower) => {
2465
- units.set(name, { order: unitOrder++, lower });
2548
+ const register = (name, roots, lower) => {
2549
+ units.set(name, { order: unitOrder++, roots, lower });
2466
2550
  metadataPriority.set(name, [3, expressionMetadataOrder++]);
2467
2551
  };
2468
- register(`%${cName}.constructor`, () => this.lowerClassCtor(info));
2552
+ register(`%${cName}.constructor`, classCtorRoots(info), () => this.lowerClassCtor(info));
2469
2553
  for (const { mName, member } of this.classMethodMembers(info)) {
2470
- register(`%${cName}.${mName}`, () => this.lowerClassMethodMember(info, member));
2554
+ register(`%${cName}.${mName}`, functionRoots(member), () => this.lowerClassMethodMember(info, member));
2471
2555
  }
2472
- for (const name of info.staticMethods?.keys() ?? []) {
2473
- register(`%${cName}.static:${name}`, () => lowerStaticMethod(this, info, name));
2556
+ for (const [name, entry] of info.staticMethods ?? []) {
2557
+ register(`%${cName}.static:${name}`, functionRoots(entry.member), () => lowerStaticMethod(this, info, name));
2474
2558
  }
2475
2559
  for (const prop of info.throwingSetters) {
2476
- register(`%${cName}.set:${prop}`, () => this.throwingSetterFn(info, prop));
2560
+ register(`%${cName}.set:${prop}`, [], () => this.throwingSetterFn(info, prop));
2477
2561
  }
2478
2562
  };
2479
2563
  // Generic instances queued by the bodies above lower here (an instance
@@ -2488,45 +2572,73 @@ export class Lowerer {
2488
2572
  clsInstLowered < this.genericClassInstances.length ||
2489
2573
  specLowered < this.emitSpecQueue.length) {
2490
2574
  while (clsInstLowered < this.genericClassInstances.length) {
2491
- const info = this.genericClassInstances[clsInstLowered++];
2492
- const owner = demandOwner();
2493
- this.genericClassDemandOwner.set(info, owner);
2494
- const ref = this.genericClassDemandPriority.get(info) ?? { rank: [4, instanceMetadataOrder++] };
2495
- this.genericClassDemandPriority.set(info, ref);
2496
- instanceFunctions.push(...this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(ref, () => this.lowerClassMembers(info))));
2575
+ const waveEnd = this.genericClassInstances.length;
2576
+ this.checker.prefetchRoots(this.genericClassInstances.slice(clsInstLowered, waveEnd).flatMap(classMemberRoots));
2577
+ while (clsInstLowered < waveEnd) {
2578
+ const info = this.genericClassInstances[clsInstLowered++];
2579
+ const owner = demandOwner();
2580
+ this.genericClassDemandOwner.set(info, owner);
2581
+ const ref = this.genericClassDemandPriority.get(info) ?? { rank: [4, instanceMetadataOrder++] };
2582
+ this.genericClassDemandPriority.set(info, ref);
2583
+ instanceFunctions.push(...this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(ref, () => this.lowerClassMembers(info))));
2584
+ }
2497
2585
  }
2498
2586
  while (instLowered < this.instantiationQueue.length) {
2499
- const { info, inst } = this.instantiationQueue[instLowered++];
2500
- const owner = demandOwner();
2501
- this.genericFunctionDemandOwner.set(inst, owner);
2502
- const ref = this.genericDemandPriority.get(inst) ?? { rank: [4, instanceMetadataOrder++] };
2503
- this.genericDemandPriority.set(inst, ref);
2504
- // Body-level poisons skip the instance after retaining the
2505
- // diagnostic and every edge fired before poisoning.
2506
- try {
2507
- instanceFunctions.push(this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(ref, () => this.lowerGenericInstance(info, inst))));
2508
- }
2509
- catch (e) {
2510
- if (!(e instanceof PoisonError))
2511
- throw e;
2587
+ const waveEnd = this.instantiationQueue.length;
2588
+ this.checker.prefetchRoots(this.instantiationQueue
2589
+ .slice(instLowered, waveEnd)
2590
+ .flatMap(({ info }) => functionRoots(info.decl)));
2591
+ while (instLowered < waveEnd) {
2592
+ const { info, inst } = this.instantiationQueue[instLowered++];
2593
+ const owner = demandOwner();
2594
+ this.genericFunctionDemandOwner.set(inst, owner);
2595
+ const ref = this.genericDemandPriority.get(inst) ?? { rank: [4, instanceMetadataOrder++] };
2596
+ this.genericDemandPriority.set(inst, ref);
2597
+ // Body-level poisons skip the instance after retaining the
2598
+ // diagnostic and every edge fired before poisoning.
2599
+ try {
2600
+ instanceFunctions.push(this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(ref, () => this.lowerGenericInstance(info, inst))));
2601
+ }
2602
+ catch (e) {
2603
+ if (!(e instanceof PoisonError))
2604
+ throw e;
2605
+ }
2512
2606
  }
2513
2607
  }
2514
2608
  // Emit-override specialization bodies fire edges of their own
2515
2609
  // (the super-forward chain, closures, generic calls) — lower them
2516
2610
  // exactly like generic instances.
2517
2611
  while (specLowered < this.emitSpecQueue.length) {
2518
- try {
2519
- const fn = this.shapes.withDeclaredOrderPriority([4, instanceMetadataOrder++], () => lowerEmitOverrideSpec(this, this.emitSpecQueue[specLowered++]));
2520
- if (fn)
2521
- instanceFunctions.push(fn);
2522
- }
2523
- catch (e) {
2524
- if (!(e instanceof PoisonError))
2525
- throw e;
2612
+ const waveEnd = this.emitSpecQueue.length;
2613
+ this.checker.prefetchRoots(this.emitSpecQueue
2614
+ .slice(specLowered, waveEnd)
2615
+ .flatMap(({ info }) => info.emitOverride ? functionRoots(info.emitOverride.decl) : []));
2616
+ while (specLowered < waveEnd) {
2617
+ try {
2618
+ const fn = this.shapes.withDeclaredOrderPriority([4, instanceMetadataOrder++], () => lowerEmitOverrideSpec(this, this.emitSpecQueue[specLowered++]));
2619
+ if (fn)
2620
+ instanceFunctions.push(fn);
2621
+ }
2622
+ catch (e) {
2623
+ if (!(e instanceof PoisonError))
2624
+ throw e;
2625
+ }
2526
2626
  }
2527
2627
  }
2528
2628
  }
2529
2629
  };
2630
+ // Module inits are the unconditional root wave. Structure prefetch
2631
+ // already covered ordinary top-level expressions, but this full-root
2632
+ // pass also picks up nested/lifted function bodies and the class
2633
+ // declaration-time code that splitFiles hoists out of topStmts.
2634
+ this.checker.prefetchRoots([
2635
+ ...parts.flatMap((fp) => fp.topStmts),
2636
+ ...[...this.classes.values()].flatMap((info) => [
2637
+ ...info.staticFields.map((field) => field.initializer),
2638
+ ...(info.staticBlocks ?? []),
2639
+ ...(info.classDecorators?.nodes ?? []),
2640
+ ]),
2641
+ ]);
2530
2642
  parts.forEach((fp, index) => {
2531
2643
  const priority = [2, index];
2532
2644
  const owner = demandOwner(priority);
@@ -2538,25 +2650,31 @@ export class Lowerer {
2538
2650
  // (the export-map resolution reports them as SC4002 later).
2539
2651
  for (const root of extraRoots ?? [])
2540
2652
  this.onEdge?.(root);
2541
- while (queue.length > 0) {
2542
- // A body-level poison outside the per-statement catches (a fenced
2543
- // constructor/method parameter default lowered by declareParams):
2544
- // every edge fired before poisoning remains retained; the diagnostic
2545
- // stays recorded and the member stays omitted.
2546
- try {
2547
- const name = queue.shift();
2548
- const unit = units.get(name);
2549
- const priority = metadataPriority.get(name) ?? [3, expressionMetadataOrder++];
2550
- const owner = demandOwner(priority);
2551
- const fn = this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(priority, unit.lower));
2552
- if (fn)
2553
- loweredUnits.set(name, fn);
2554
- }
2555
- catch (e) {
2556
- if (!(e instanceof PoisonError))
2557
- throw e;
2653
+ const drainUnits = () => {
2654
+ while (queue.length > 0) {
2655
+ const wave = queue.splice(0);
2656
+ this.checker.prefetchRoots(wave.flatMap((name) => units.get(name).roots));
2657
+ for (const name of wave) {
2658
+ // A body-level poison outside the per-statement catches (a fenced
2659
+ // constructor/method parameter default lowered by declareParams):
2660
+ // every edge fired before poisoning remains retained; the diagnostic
2661
+ // stays recorded and the member stays omitted.
2662
+ try {
2663
+ const unit = units.get(name);
2664
+ const priority = metadataPriority.get(name) ?? [3, expressionMetadataOrder++];
2665
+ const owner = demandOwner(priority);
2666
+ const fn = this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(priority, unit.lower));
2667
+ if (fn)
2668
+ loweredUnits.set(name, fn);
2669
+ }
2670
+ catch (e) {
2671
+ if (!(e instanceof PoisonError))
2672
+ throw e;
2673
+ }
2674
+ }
2558
2675
  }
2559
- }
2676
+ };
2677
+ drainUnits();
2560
2678
  this.restoreGenericInstanceOrder();
2561
2679
  this.restoreGenericClassInstanceOrder();
2562
2680
  // Generic bodies can reach ordinary declarations, whose bodies can in
@@ -2567,21 +2685,7 @@ export class Lowerer {
2567
2685
  drainInstances();
2568
2686
  if (queue.length === 0)
2569
2687
  break;
2570
- while (queue.length > 0) {
2571
- try {
2572
- const name = queue.shift();
2573
- const unit = units.get(name);
2574
- const priority = metadataPriority.get(name) ?? [3, expressionMetadataOrder++];
2575
- const owner = demandOwner(priority);
2576
- const fn = this.withGenericDemandOwner(owner, () => this.shapes.withDeclaredOrderPriority(priority, unit.lower));
2577
- if (fn)
2578
- loweredUnits.set(name, fn);
2579
- }
2580
- catch (e) {
2581
- if (!(e instanceof PoisonError))
2582
- throw e;
2583
- }
2584
- }
2688
+ drainUnits();
2585
2689
  this.restoreGenericInstanceOrder(instLowered);
2586
2690
  this.restoreGenericClassInstanceOrder(clsInstLowered);
2587
2691
  }
@@ -2634,7 +2738,61 @@ export class Lowerer {
2634
2738
  moduleArtifacts(functions) {
2635
2739
  return moduleArtifacts(this, functions);
2636
2740
  }
2637
- /* ── diagnostics plumbing ─────────────────────────────────────────── */
2741
+ deferToRuntimeFence(diagsBefore, node, target) {
2742
+ if ((this.diagSink !== null && target.allowDiagSink !== true) ||
2743
+ (this.diags.length <= diagsBefore && target.fallback === undefined)) {
2744
+ return null;
2745
+ }
2746
+ const captured = this.diags.splice(diagsBefore);
2747
+ if (captured.some((d) => d.code === "SC9001")) {
2748
+ this.diags.push(...captured);
2749
+ return null;
2750
+ }
2751
+ this.runtimeFences.push(...captured);
2752
+ const first = captured[0];
2753
+ const loc = locOf(node);
2754
+ const code = first?.code ?? target.fallback.code;
2755
+ const baseMessage = first?.message ?? target.fallback.message;
2756
+ const messageLoc = first?.loc ?? loc;
2757
+ const source = first
2758
+ ? this.program.getSourceFile(messageLoc.file) ?? node.getSourceFile()
2759
+ : node.getSourceFile();
2760
+ const pos = ts.getLineAndCharacterOfPosition(source, messageLoc.start);
2761
+ const fence = {
2762
+ kind: "runtimeFence",
2763
+ code,
2764
+ message: target.bareMessage
2765
+ ? baseMessage
2766
+ : `${baseMessage} [${code} at ${messageLoc.file}:${pos.line + 1}]`,
2767
+ loc,
2768
+ };
2769
+ if (target.kind === "statement")
2770
+ return fence;
2771
+ const params = target.params ?? [];
2772
+ const name = typeof target.name === "function" ? target.name() : target.name;
2773
+ const fn = {
2774
+ name,
2775
+ params,
2776
+ returnType: target.returnType,
2777
+ locals: params.map((p) => ({
2778
+ id: p.localId,
2779
+ name: p.name,
2780
+ type: p.type,
2781
+ mutable: target.paramsMutable ?? false,
2782
+ })),
2783
+ body: [fence],
2784
+ loc,
2785
+ };
2786
+ if (target.async)
2787
+ fn.async = true;
2788
+ if (target.generator)
2789
+ fn.generator = target.generator;
2790
+ if (target.kind === "function")
2791
+ return fn;
2792
+ fn.captures = [];
2793
+ this.liftedFns.push(fn);
2794
+ return { kind: "closure", fnName: fn.name, captures: [], type: target.type, loc };
2795
+ }
2638
2796
  /** All diagnostics land here; while a generic instance body is lowering,
2639
2797
  * the instantiation context is appended so the user knows which concrete
2640
2798
  * types made the (source-anchored) construct fail. */
@@ -2781,7 +2939,7 @@ export class Lowerer {
2781
2939
  // story through its callable arm. After the package check: a
2782
2940
  // package-declared generic signature stays the package's story.
2783
2941
  {
2784
- const parts = widened.isUnionType() ? widened.getTypes() : [widened];
2942
+ const parts = widened.isUnionType() ? ts.constituentTypes(widened) : [widened];
2785
2943
  if (parts.some((p) => this.checker.getCallSignatures(p).some((s) => (s.typeParameters?.length ?? 0) > 0))) {
2786
2944
  this.pushDiag(genericSignatureTypeDiag(this.checker.typeToString(type), locOf(node)));
2787
2945
  throw new PoisonError();
@@ -3094,10 +3252,10 @@ export class Lowerer {
3094
3252
  // when one constituent is; a union is array-proven only when EVERY
3095
3253
  // arm is, so an ordinary `any[] | string` never qualifies.
3096
3254
  if ((part.flags & ts.TypeFlags.Intersection) !== 0) {
3097
- return part.getTypes().some(visit);
3255
+ return ts.constituentTypes(part).some(visit);
3098
3256
  }
3099
3257
  if (part.isUnionType())
3100
- return part.getTypes().every(visit);
3258
+ return ts.constituentTypes(part).every(visit);
3101
3259
  return false;
3102
3260
  };
3103
3261
  return visit(t);
@@ -3240,7 +3398,7 @@ export class Lowerer {
3240
3398
  /** Unwraps a HYBRID (function-with-properties) record to its callable:
3241
3399
  * a record whose shape carries the reserved `%call` func field reads
3242
3400
  * that field; anything else returns unchanged. The consumer half of
3243
- * types.ts's chalk-shape mapping — call paths and func-slot coercions
3401
+ * type-mapper.ts's chalk-shape mapping — call paths and func-slot coercions
3244
3402
  * share it. */
3245
3403
  hybridCallUnwrap(expr) {
3246
3404
  if (expr.type.kind !== "record")
@@ -3423,7 +3581,7 @@ export class Lowerer {
3423
3581
  }
3424
3582
  // A HYBRID (function-with-properties) record flowing into a plain
3425
3583
  // func slot extracts its reserved %call field — the chalk shape's
3426
- // "the value IS callable" half (types.ts's hybrid mapping).
3584
+ // "the value IS callable" half (type-mapper.ts's hybrid mapping).
3427
3585
  if (expected.kind === "func" && expr.type.kind === "record") {
3428
3586
  const un = this.hybridCallUnwrap(expr);
3429
3587
  if (un !== expr && typeEquals(un.type, expected))
@@ -3878,102 +4036,102 @@ export class Lowerer {
3878
4036
  return value;
3879
4037
  case "wrap": {
3880
4038
  if (dst.kind !== "union")
3881
- throw new Error("lowerer bug: wrap lift against a non-union");
4039
+ throw new InternalCompilerError("lowerer bug: wrap lift against a non-union");
3882
4040
  return { kind: "unionWrap", unionId: dst.unionId, tag: lift.tag, value, type: dst, loc };
3883
4041
  }
3884
4042
  case "retag": {
3885
4043
  if (dst.kind !== "union" || value.type.kind !== "union")
3886
- throw new Error("lowerer bug: retag lift shape");
4044
+ throw new InternalCompilerError("lowerer bug: retag lift shape");
3887
4045
  const retag = this.unionRetagHelper(value.type.unionId, dst.unionId, loc);
3888
4046
  if (!retag)
3889
- throw new Error("lowerer bug: planned retag lift failed to intern");
4047
+ throw new InternalCompilerError("lowerer bug: planned retag lift failed to intern");
3890
4048
  return { kind: "call", callee: retag, args: [value], type: dst, loc };
3891
4049
  }
3892
4050
  case "liftWrap": {
3893
4051
  if (dst.kind !== "union")
3894
- throw new Error("lowerer bug: liftWrap lift against a non-union");
4052
+ throw new InternalCompilerError("lowerer bug: liftWrap lift against a non-union");
3895
4053
  const inner = this.widthLiftPlan(value.type, lift.arm);
3896
4054
  if (!inner)
3897
- throw new Error("lowerer bug: planned liftWrap arm stopped lifting");
4055
+ throw new InternalCompilerError("lowerer bug: planned liftWrap arm stopped lifting");
3898
4056
  const lifted = this.applyWidthLift(inner, value, lift.arm, loc);
3899
4057
  return { kind: "unionWrap", unionId: dst.unionId, tag: lift.tag, value: lifted, type: dst, loc };
3900
4058
  }
3901
4059
  case "width": {
3902
4060
  if (dst.kind !== "record" || value.type.kind !== "record")
3903
- throw new Error("lowerer bug: width lift shape");
4061
+ throw new InternalCompilerError("lowerer bug: width lift shape");
3904
4062
  const helper = this.recordWidthHelper(value.type.shapeId, dst.shapeId, loc);
3905
4063
  if (!helper)
3906
- throw new Error("lowerer bug: planned width lift failed to intern");
4064
+ throw new InternalCompilerError("lowerer bug: planned width lift failed to intern");
3907
4065
  return { kind: "call", callee: helper, args: [value], type: dst, loc };
3908
4066
  }
3909
4067
  case "arr": {
3910
4068
  if (dst.kind !== "array" || value.type.kind !== "array")
3911
- throw new Error("lowerer bug: arr lift shape");
4069
+ throw new InternalCompilerError("lowerer bug: arr lift shape");
3912
4070
  const helper = this.arrayWidthHelper(value.type, dst, loc);
3913
4071
  if (!helper)
3914
- throw new Error("lowerer bug: planned arr lift failed to intern");
4072
+ throw new InternalCompilerError("lowerer bug: planned arr lift failed to intern");
3915
4073
  return { kind: "call", callee: helper, args: [value], type: dst, loc };
3916
4074
  }
3917
4075
  case "tupleArr": {
3918
4076
  if (dst.kind !== "array" || value.type.kind !== "record")
3919
- throw new Error("lowerer bug: tupleArr lift shape");
4077
+ throw new InternalCompilerError("lowerer bug: tupleArr lift shape");
3920
4078
  const helper = this.tupleArrayWidthHelper(value.type.shapeId, dst, loc);
3921
4079
  if (!helper)
3922
- throw new Error("lowerer bug: planned tupleArr lift failed to intern");
4080
+ throw new InternalCompilerError("lowerer bug: planned tupleArr lift failed to intern");
3923
4081
  return { kind: "call", callee: helper, args: [value], type: dst, loc };
3924
4082
  }
3925
4083
  case "emptyArr": {
3926
4084
  if (dst.kind !== "array" || value.type.kind !== "array")
3927
- throw new Error("lowerer bug: emptyArr lift shape");
4085
+ throw new InternalCompilerError("lowerer bug: emptyArr lift shape");
3928
4086
  const helper = this.emptyArrayLiftHelper(value.type, dst, loc);
3929
4087
  return { kind: "call", callee: helper, args: [value], type: dst, loc };
3930
4088
  }
3931
4089
  case "objWidth": {
3932
4090
  if (dst.kind !== "record" || value.type.kind !== "object")
3933
- throw new Error("lowerer bug: objWidth lift shape");
4091
+ throw new InternalCompilerError("lowerer bug: objWidth lift shape");
3934
4092
  const helper = this.objRecordWidthHelper(value.type.className, dst.shapeId, loc);
3935
4093
  if (!helper)
3936
- throw new Error("lowerer bug: planned objWidth lift failed to intern");
4094
+ throw new InternalCompilerError("lowerer bug: planned objWidth lift failed to intern");
3937
4095
  return { kind: "call", callee: helper, args: [value], type: dst, loc };
3938
4096
  }
3939
4097
  case "clsWidth": {
3940
4098
  if (dst.kind !== "object" || value.type.kind !== "record")
3941
- throw new Error("lowerer bug: clsWidth lift shape");
4099
+ throw new InternalCompilerError("lowerer bug: clsWidth lift shape");
3942
4100
  const helper = this.recordClassWidthHelper(value.type.shapeId, dst.className, loc);
3943
4101
  if (!helper)
3944
- throw new Error("lowerer bug: planned clsWidth lift failed to intern");
4102
+ throw new InternalCompilerError("lowerer bug: planned clsWidth lift failed to intern");
3945
4103
  return { kind: "call", callee: helper, args: [value], type: dst, loc };
3946
4104
  }
3947
4105
  case "narrow": {
3948
4106
  if (value.type.kind !== "union")
3949
- throw new Error("lowerer bug: narrow lift on a non-union");
4107
+ throw new InternalCompilerError("lowerer bug: narrow lift on a non-union");
3950
4108
  const helper = this.narrowedArmHelper(value.type.unionId, dst, loc);
3951
4109
  if (!helper)
3952
- throw new Error("lowerer bug: planned narrow lift failed to intern");
4110
+ throw new InternalCompilerError("lowerer bug: planned narrow lift failed to intern");
3953
4111
  return { kind: "call", callee: helper, args: [value], type: dst, loc };
3954
4112
  }
3955
4113
  case "dynIn": {
3956
4114
  if (dst.kind !== "dyn")
3957
- throw new Error("lowerer bug: dynIn lift against a non-dyn slot");
4115
+ throw new InternalCompilerError("lowerer bug: dynIn lift against a non-dyn slot");
3958
4116
  return { kind: "dynFrom", value, type: DYN, loc };
3959
4117
  }
3960
4118
  case "upcast": {
3961
4119
  if (dst.kind !== "object" || value.type.kind !== "object")
3962
- throw new Error("lowerer bug: upcast lift shape");
4120
+ throw new InternalCompilerError("lowerer bug: upcast lift shape");
3963
4121
  return this.upcastTo(value, dst.className);
3964
4122
  }
3965
4123
  case "funcAdapt": {
3966
4124
  if (dst.kind !== "func" || value.type.kind !== "func")
3967
- throw new Error("lowerer bug: funcAdapt lift shape");
4125
+ throw new InternalCompilerError("lowerer bug: funcAdapt lift shape");
3968
4126
  const adapter = this.funcCoerceAdapter(value.type, dst, loc);
3969
4127
  if (!adapter)
3970
- throw new Error("lowerer bug: planned funcAdapt lift failed to intern");
4128
+ throw new InternalCompilerError("lowerer bug: planned funcAdapt lift failed to intern");
3971
4129
  return { kind: "call", callee: adapter, args: [value], type: dst, loc };
3972
4130
  }
3973
4131
  default: {
3974
4132
  const _exhaustive = lift;
3975
4133
  void _exhaustive;
3976
- throw new Error("unreachable");
4134
+ throw new InternalCompilerError("unreachable");
3977
4135
  }
3978
4136
  }
3979
4137
  }
@@ -4188,7 +4346,7 @@ export class Lowerer {
4188
4346
  }
4189
4347
  if ("absent" in lift) {
4190
4348
  if (f.type.kind !== "union")
4191
- throw new Error("lowerer bug: absent lift against a non-union field");
4349
+ throw new InternalCompilerError("lowerer bug: absent lift against a non-union field");
4192
4350
  // The unset optional field: build the undefined arm.
4193
4351
  return {
4194
4352
  name: f.name,
@@ -4330,8 +4488,6 @@ export class Lowerer {
4330
4488
  this.widthHelpers.set(key, name);
4331
4489
  const arrT = { kind: "array", elem: fromElem };
4332
4490
  const outT = { kind: "array", elem: toElem };
4333
- const ref = (localId, type) => ({ kind: "varRef", localId, type, loc });
4334
- const num = (value) => ({ kind: "numLit", value, type: { kind: "f64" }, loc });
4335
4491
  const f64 = { kind: "f64" };
4336
4492
  this.liftedFns.push({
4337
4493
  name,
@@ -4348,17 +4504,17 @@ export class Lowerer {
4348
4504
  {
4349
4505
  kind: "varDecl",
4350
4506
  localId: "n.0",
4351
- init: { kind: "arrIntrinsic", method: "length", receiver: ref("a.0", arrT), args: [], type: f64, loc },
4507
+ init: { kind: "arrIntrinsic", method: "length", receiver: varRef("a.0", arrT, loc), args: [], type: f64, loc },
4352
4508
  loc,
4353
4509
  },
4354
4510
  {
4355
4511
  kind: "for",
4356
- init: { kind: "varDecl", localId: "i.0", init: num(0), loc },
4357
- cond: { kind: "bin", op: "<", left: ref("i.0", f64), right: ref("n.0", f64), type: BOOL, loc },
4512
+ init: { kind: "varDecl", localId: "i.0", init: numLit(0, loc), loc },
4513
+ cond: { kind: "bin", op: "<", left: varRef("i.0", f64, loc), right: varRef("n.0", f64, loc), type: BOOL, loc },
4358
4514
  update: {
4359
4515
  kind: "assign",
4360
4516
  localId: "i.0",
4361
- value: { kind: "bin", op: "+", left: ref("i.0", f64), right: num(1), type: f64, loc },
4517
+ value: { kind: "bin", op: "+", left: varRef("i.0", f64, loc), right: numLit(1, loc), type: f64, loc },
4362
4518
  loc,
4363
4519
  },
4364
4520
  body: [
@@ -4367,9 +4523,9 @@ export class Lowerer {
4367
4523
  expr: {
4368
4524
  kind: "arrIntrinsic",
4369
4525
  method: "push",
4370
- receiver: ref("out.0", outT),
4526
+ receiver: varRef("out.0", outT, loc),
4371
4527
  args: [
4372
- this.applyWidthLift(elemLift, { kind: "arrayGet", arr: ref("a.0", arrT), index: ref("i.0", f64), type: fromElem, loc }, toElem, loc),
4528
+ this.applyWidthLift(elemLift, { kind: "arrayGet", arr: varRef("a.0", arrT, loc), index: varRef("i.0", f64, loc), type: fromElem, loc }, toElem, loc),
4373
4529
  ],
4374
4530
  type: f64,
4375
4531
  loc,
@@ -4379,7 +4535,7 @@ export class Lowerer {
4379
4535
  ],
4380
4536
  loc,
4381
4537
  },
4382
- { kind: "return", value: ref("out.0", outT), loc },
4538
+ { kind: "return", value: varRef("out.0", outT, loc), loc },
4383
4539
  ],
4384
4540
  loc,
4385
4541
  });
@@ -4478,7 +4634,7 @@ export class Lowerer {
4478
4634
  const lift = plan.get(f.name);
4479
4635
  if ("absent" in lift) {
4480
4636
  if (f.type.kind !== "union")
4481
- throw new Error("lowerer bug: absent lift against a non-union field");
4637
+ throw new InternalCompilerError("lowerer bug: absent lift against a non-union field");
4482
4638
  return {
4483
4639
  name: f.name,
4484
4640
  value: {
@@ -4607,7 +4763,7 @@ export class Lowerer {
4607
4763
  if ("absent" in entry) {
4608
4764
  const u = this.wrappedUndefined(shape.type, loc);
4609
4765
  if (!u)
4610
- throw new Error("lowerer bug: planned absent ctor arg has no undefined arm");
4766
+ throw new InternalCompilerError("lowerer bug: planned absent ctor arg has no undefined arm");
4611
4767
  return u;
4612
4768
  }
4613
4769
  const get = { kind: "recordGet", obj: r, shapeId: fromId, field: entry.field, type: entry.src, loc };
@@ -4910,7 +5066,7 @@ export class Lowerer {
4910
5066
  const aRef = { kind: "varRef", localId: `a.${i}`, type: toT.params[i], loc };
4911
5067
  const converted = this.coerceToExpected(aRef, pt);
4912
5068
  if (!typeEquals(converted.type, pt))
4913
- throw new Error("lowerer bug: probed fn-adapter param stopped coercing");
5069
+ throw new InternalCompilerError("lowerer bug: probed fn-adapter param stopped coercing");
4914
5070
  return converted;
4915
5071
  });
4916
5072
  const call = {
@@ -4953,7 +5109,7 @@ export class Lowerer {
4953
5109
  else {
4954
5110
  const result = this.coerceToExpected(call, toT.ret);
4955
5111
  if (!typeEquals(result.type, toT.ret))
4956
- throw new Error("lowerer bug: probed fn-adapter return stopped coercing");
5112
+ throw new InternalCompilerError("lowerer bug: probed fn-adapter return stopped coercing");
4957
5113
  body = [{ kind: "return", value: result, loc }];
4958
5114
  }
4959
5115
  }
@@ -5644,7 +5800,7 @@ export class Lowerer {
5644
5800
  if (e.type.kind === "dyn" || e.type.kind === "func") {
5645
5801
  return { kind: "jsMarshal", value: e, type: JSVAL, loc };
5646
5802
  }
5647
- throw new Error(`lowerer bug: jsvalLiftExpr of unliftable ${e.type.kind}`);
5803
+ throw new InternalCompilerError(`lowerer bug: jsvalLiftExpr of unliftable ${e.type.kind}`);
5648
5804
  }
5649
5805
  /** Interned `%jsin.union.<n>(u)` — the runtime tag switch marshaling a
5650
5806
  * union value INTO the island: unit arms become the engine's own
@@ -5661,7 +5817,7 @@ export class Lowerer {
5661
5817
  return existing;
5662
5818
  const def = this.unions.get(unionId);
5663
5819
  if (!def)
5664
- throw new Error(`lowerer bug: jsval lift of unknown union ${unionId}`);
5820
+ throw new InternalCompilerError(`lowerer bug: jsval lift of unknown union ${unionId}`);
5665
5821
  const name = `%jsin.union.${this.jsinHelpers.size}`;
5666
5822
  this.jsinHelpers.set(key, name);
5667
5823
  const fromT = { kind: "union", unionId };
@@ -5703,7 +5859,7 @@ export class Lowerer {
5703
5859
  return existing;
5704
5860
  const shape = this.shapes.get(shapeId);
5705
5861
  if (!shape)
5706
- throw new Error(`lowerer bug: jsval lift of unknown shape ${shapeId}`);
5862
+ throw new InternalCompilerError(`lowerer bug: jsval lift of unknown shape ${shapeId}`);
5707
5863
  const name = `%jsin.rec.${this.jsinHelpers.size}`;
5708
5864
  this.jsinHelpers.set(key, name);
5709
5865
  const recT = { kind: "record", shapeId };
@@ -5736,9 +5892,7 @@ export class Lowerer {
5736
5892
  const iv = shape.indexValue;
5737
5893
  const f64 = { kind: "f64" };
5738
5894
  const ksT = arrayOf(STRING);
5739
- const ref = (localId, type) => ({ kind: "varRef", localId, type, loc });
5740
- const num = (value) => ({ kind: "numLit", value, type: f64, loc });
5741
- const kRef = ref("k.0", STRING);
5895
+ const kRef = varRef("k.0", STRING, loc);
5742
5896
  this.liftedFns.push({
5743
5897
  name,
5744
5898
  params: [{ localId: "r.0", name: "r", type: recT }],
@@ -5755,25 +5909,25 @@ export class Lowerer {
5755
5909
  { kind: "varDecl", localId: "ks.0", init: { kind: "recordOvfKeys", obj: r, shapeId, type: ksT, loc }, loc },
5756
5910
  {
5757
5911
  kind: "for",
5758
- init: { kind: "varDecl", localId: "i.0", init: num(0), loc },
5912
+ init: { kind: "varDecl", localId: "i.0", init: numLit(0, loc), loc },
5759
5913
  cond: {
5760
5914
  kind: "bin",
5761
5915
  op: "<",
5762
- left: ref("i.0", f64),
5763
- right: { kind: "arrIntrinsic", method: "length", receiver: ref("ks.0", ksT), args: [], type: f64, loc },
5916
+ left: varRef("i.0", f64, loc),
5917
+ right: { kind: "arrIntrinsic", method: "length", receiver: varRef("ks.0", ksT, loc), args: [], type: f64, loc },
5764
5918
  type: BOOL,
5765
5919
  loc,
5766
5920
  },
5767
- update: { kind: "assign", localId: "i.0", value: { kind: "bin", op: "+", left: ref("i.0", f64), right: num(1), type: f64, loc }, loc },
5921
+ update: { kind: "assign", localId: "i.0", value: { kind: "bin", op: "+", left: varRef("i.0", f64, loc), right: numLit(1, loc), type: f64, loc }, loc },
5768
5922
  body: [
5769
- { kind: "varDecl", localId: "k.0", init: { kind: "arrayGet", arr: ref("ks.0", ksT), index: ref("i.0", f64), type: STRING, loc }, loc },
5923
+ { kind: "varDecl", localId: "k.0", init: { kind: "arrayGet", arr: varRef("ks.0", ksT, loc), index: varRef("i.0", f64, loc), type: STRING, loc }, loc },
5770
5924
  {
5771
5925
  kind: "exprStmt",
5772
5926
  expr: {
5773
5927
  kind: "jsOp",
5774
5928
  op: "setIdx",
5775
5929
  args: [
5776
- ref("out.0", JSVAL),
5930
+ varRef("out.0", JSVAL, loc),
5777
5931
  { kind: "jsMarshal", value: kRef, type: JSVAL, loc },
5778
5932
  this.jsvalLiftExpr({ kind: "recordKeyGet", obj: r, shapeId, key: kRef, overflowOnly: true, type: iv, loc }, loc),
5779
5933
  ],
@@ -5785,7 +5939,7 @@ export class Lowerer {
5785
5939
  ],
5786
5940
  loc,
5787
5941
  },
5788
- { kind: "return", value: ref("out.0", JSVAL), loc },
5942
+ { kind: "return", value: varRef("out.0", JSVAL, loc), loc },
5789
5943
  ],
5790
5944
  loc,
5791
5945
  });
@@ -5804,8 +5958,6 @@ export class Lowerer {
5804
5958
  this.jsinHelpers.set(key, name);
5805
5959
  const arrT = { kind: "array", elem };
5806
5960
  const f64 = { kind: "f64" };
5807
- const ref = (localId, type) => ({ kind: "varRef", localId, type, loc });
5808
- const num = (value) => ({ kind: "numLit", value, type: f64, loc });
5809
5961
  this.liftedFns.push({
5810
5962
  name,
5811
5963
  params: [{ localId: "a.0", name: "a", type: arrT }],
@@ -5821,17 +5973,17 @@ export class Lowerer {
5821
5973
  {
5822
5974
  kind: "varDecl",
5823
5975
  localId: "n.0",
5824
- init: { kind: "arrIntrinsic", method: "length", receiver: ref("a.0", arrT), args: [], type: f64, loc },
5976
+ init: { kind: "arrIntrinsic", method: "length", receiver: varRef("a.0", arrT, loc), args: [], type: f64, loc },
5825
5977
  loc,
5826
5978
  },
5827
5979
  {
5828
5980
  kind: "for",
5829
- init: { kind: "varDecl", localId: "i.0", init: num(0), loc },
5830
- cond: { kind: "bin", op: "<", left: ref("i.0", f64), right: ref("n.0", f64), type: BOOL, loc },
5981
+ init: { kind: "varDecl", localId: "i.0", init: numLit(0, loc), loc },
5982
+ cond: { kind: "bin", op: "<", left: varRef("i.0", f64, loc), right: varRef("n.0", f64, loc), type: BOOL, loc },
5831
5983
  update: {
5832
5984
  kind: "assign",
5833
5985
  localId: "i.0",
5834
- value: { kind: "bin", op: "+", left: ref("i.0", f64), right: num(1), type: f64, loc },
5986
+ value: { kind: "bin", op: "+", left: varRef("i.0", f64, loc), right: numLit(1, loc), type: f64, loc },
5835
5987
  loc,
5836
5988
  },
5837
5989
  body: [
@@ -5841,9 +5993,9 @@ export class Lowerer {
5841
5993
  kind: "jsOp",
5842
5994
  op: "setIdx",
5843
5995
  args: [
5844
- ref("out.0", JSVAL),
5845
- { kind: "jsMarshal", value: ref("i.0", f64), type: JSVAL, loc },
5846
- this.jsvalLiftExpr({ kind: "arrayGet", arr: ref("a.0", arrT), index: ref("i.0", f64), type: elem, loc }, loc),
5996
+ varRef("out.0", JSVAL, loc),
5997
+ { kind: "jsMarshal", value: varRef("i.0", f64, loc), type: JSVAL, loc },
5998
+ this.jsvalLiftExpr({ kind: "arrayGet", arr: varRef("a.0", arrT, loc), index: varRef("i.0", f64, loc), type: elem, loc }, loc),
5847
5999
  ],
5848
6000
  type: { kind: "void" },
5849
6001
  loc,
@@ -5853,7 +6005,7 @@ export class Lowerer {
5853
6005
  ],
5854
6006
  loc,
5855
6007
  },
5856
- { kind: "return", value: ref("out.0", JSVAL), loc },
6008
+ { kind: "return", value: varRef("out.0", JSVAL, loc), loc },
5857
6009
  ],
5858
6010
  loc,
5859
6011
  });
@@ -5875,8 +6027,6 @@ export class Lowerer {
5875
6027
  const arrT = { kind: "array", elem: fromElem };
5876
6028
  const outT = { kind: "array", elem: JSVAL };
5877
6029
  const f64 = { kind: "f64" };
5878
- const ref = (localId, type) => ({ kind: "varRef", localId, type, loc });
5879
- const num = (value) => ({ kind: "numLit", value, type: f64, loc });
5880
6030
  this.liftedFns.push({
5881
6031
  name,
5882
6032
  params: [{ localId: "a.0", name: "a", type: arrT }],
@@ -5892,17 +6042,17 @@ export class Lowerer {
5892
6042
  {
5893
6043
  kind: "varDecl",
5894
6044
  localId: "n.0",
5895
- init: { kind: "arrIntrinsic", method: "length", receiver: ref("a.0", arrT), args: [], type: f64, loc },
6045
+ init: { kind: "arrIntrinsic", method: "length", receiver: varRef("a.0", arrT, loc), args: [], type: f64, loc },
5896
6046
  loc,
5897
6047
  },
5898
6048
  {
5899
6049
  kind: "for",
5900
- init: { kind: "varDecl", localId: "i.0", init: num(0), loc },
5901
- cond: { kind: "bin", op: "<", left: ref("i.0", f64), right: ref("n.0", f64), type: BOOL, loc },
6050
+ init: { kind: "varDecl", localId: "i.0", init: numLit(0, loc), loc },
6051
+ cond: { kind: "bin", op: "<", left: varRef("i.0", f64, loc), right: varRef("n.0", f64, loc), type: BOOL, loc },
5902
6052
  update: {
5903
6053
  kind: "assign",
5904
6054
  localId: "i.0",
5905
- value: { kind: "bin", op: "+", left: ref("i.0", f64), right: num(1), type: f64, loc },
6055
+ value: { kind: "bin", op: "+", left: varRef("i.0", f64, loc), right: numLit(1, loc), type: f64, loc },
5906
6056
  loc,
5907
6057
  },
5908
6058
  body: [
@@ -5911,9 +6061,9 @@ export class Lowerer {
5911
6061
  expr: {
5912
6062
  kind: "arrIntrinsic",
5913
6063
  method: "push",
5914
- receiver: ref("out.0", outT),
6064
+ receiver: varRef("out.0", outT, loc),
5915
6065
  args: [
5916
- this.jsvalLiftExpr({ kind: "arrayGet", arr: ref("a.0", arrT), index: ref("i.0", f64), type: fromElem, loc }, loc),
6066
+ this.jsvalLiftExpr({ kind: "arrayGet", arr: varRef("a.0", arrT, loc), index: varRef("i.0", f64, loc), type: fromElem, loc }, loc),
5917
6067
  ],
5918
6068
  type: f64,
5919
6069
  loc,
@@ -5923,7 +6073,7 @@ export class Lowerer {
5923
6073
  ],
5924
6074
  loc,
5925
6075
  },
5926
- { kind: "return", value: ref("out.0", outT), loc },
6076
+ { kind: "return", value: varRef("out.0", outT, loc), loc },
5927
6077
  ],
5928
6078
  loc,
5929
6079
  });
@@ -6050,7 +6200,7 @@ export class Lowerer {
6050
6200
  const t = this.typeOf(d.initializer);
6051
6201
  if (!isUnitOnlyTsType(t))
6052
6202
  return null;
6053
- for (const p of t.isUnionType() ? t.getTypes() : [t]) {
6203
+ for (const p of t.isUnionType() ? ts.constituentTypes(t) : [t]) {
6054
6204
  units.add((p.flags & ts.TypeFlags.Null) !== 0 ? "null" : "undefined");
6055
6205
  }
6056
6206
  }
@@ -6414,10 +6564,83 @@ export class Lowerer {
6414
6564
  return lowerGenericInstance(this, info, inst);
6415
6565
  }
6416
6566
  /* ── classes ──────────────────────────────────────────────────────── */
6567
+ /** Checker work class SHAPE collection performs inside otherwise
6568
+ * deferred JavaScript bodies. Constructor assignments declare fields,
6569
+ * so collection asks for each `this.x` symbol and RHS type even when the
6570
+ * constructor is unreachable. Keep that mandatory work batched without
6571
+ * sweeping unrelated dead method bodies. */
6572
+ prefetchClassCollection(decls) {
6573
+ const defaultTypeNodes = [];
6574
+ const typeNodes = [];
6575
+ const symbolRoots = [];
6576
+ for (const decl of decls) {
6577
+ for (const member of decl.members) {
6578
+ if ((ts.isConstructorDeclaration(member) ||
6579
+ ts.isMethodDeclaration(member) ||
6580
+ ts.isGetAccessor(member) ||
6581
+ ts.isSetAccessor(member)) &&
6582
+ (!ts.isMethodDeclaration(member) || member.typeParameters === undefined)) {
6583
+ for (const param of member.parameters) {
6584
+ if (param.initializer)
6585
+ defaultTypeNodes.push(param.initializer);
6586
+ }
6587
+ }
6588
+ }
6589
+ if (!isJsSourceFile(decl.getSourceFile()))
6590
+ continue;
6591
+ for (const member of decl.members) {
6592
+ if (ts.isConstructorDeclaration(member)) {
6593
+ for (const param of member.parameters) {
6594
+ if (param.initializer)
6595
+ typeNodes.push(param.initializer);
6596
+ }
6597
+ for (const stmt of member.body?.statements ?? []) {
6598
+ if (!ts.isExpressionStatement(stmt) || !ts.isBinaryExpression(stmt.expression))
6599
+ continue;
6600
+ if (stmt.expression.operatorToken.kind !== ts.SyntaxKind.EqualsToken)
6601
+ continue;
6602
+ const lhs = stmt.expression.left;
6603
+ if ((ts.isPropertyAccessExpression(lhs) || ts.isElementAccessExpression(lhs)) &&
6604
+ lhs.expression.kind === ts.SyntaxKind.ThisKeyword) {
6605
+ symbolRoots.push(lhs);
6606
+ // Field inference normally uses the symbol's type, but its
6607
+ // panic/undefined fallback asks for the assignment node too.
6608
+ typeNodes.push(lhs, stmt.expression.right);
6609
+ }
6610
+ }
6611
+ continue;
6612
+ }
6613
+ if (ts.isMethodDeclaration(member) ||
6614
+ ts.isGetAccessor(member) ||
6615
+ ts.isSetAccessor(member)) {
6616
+ for (const param of member.parameters) {
6617
+ if (param.initializer)
6618
+ typeNodes.push(param.initializer);
6619
+ }
6620
+ // npm-static implicit-any classification resolves body parameter
6621
+ // references while collecting the method's shape.
6622
+ if (implicitMonoFile(decl.getSourceFile()) && member.body) {
6623
+ symbolRoots.push(member.body);
6624
+ }
6625
+ }
6626
+ }
6627
+ }
6628
+ if (defaultTypeNodes.length > 0) {
6629
+ this.checker.prefetchCollectionTypes(defaultTypeNodes);
6630
+ }
6631
+ if (typeNodes.length > 0 || symbolRoots.length > 0) {
6632
+ this.checker.prefetchClassCollection(typeNodes, symbolRoots);
6633
+ }
6634
+ }
6417
6635
  collectClassShape(decl) {
6418
6636
  return collectClassShape(this, decl);
6419
6637
  }
6420
6638
  collectClassShapeInner(decl, jsNameOverride, inst, mixin) {
6639
+ // Late class expressions and mixin/generic instances do not participate
6640
+ // in emitReachable's initial declaration wave. Prime their mandatory
6641
+ // shape queries at the collection boundary; initial declarations are
6642
+ // already warm and this is memo-free.
6643
+ this.prefetchClassCollection([decl]);
6421
6644
  return collectClassShapeInner(this, decl, jsNameOverride, inst, mixin);
6422
6645
  }
6423
6646
  lowerClassExpressionInfo(expr) {
@@ -7069,7 +7292,7 @@ export class Lowerer {
7069
7292
  }
7070
7293
  if (d && ts.isVariableDeclaration(d) && d.initializer === undefined) {
7071
7294
  const t = this.checker.getTypeOfSymbol(symbol);
7072
- const parts = t.isUnionType() ? t.getTypes() : [t];
7295
+ const parts = t.isUnionType() ? ts.constituentTypes(t) : [t];
7073
7296
  if (parts.some((p) => this.checker.getCallSignatures(p).some((s) => (s.typeParameters?.length ?? 0) > 0))) {
7074
7297
  this.unsupported("SC1030", node, `the generic-signature binding '${name}' (its type keeps type parameters and the declaration has no initializer — no function body exists to monomorphize, so nothing can pin a concrete signature)`);
7075
7298
  }
@@ -7364,7 +7587,7 @@ export class Lowerer {
7364
7587
  * node_modules but NOT the standard library (typescript's own lib files
7365
7588
  * live under node_modules too), or inside a registered workspace-linked
7366
7589
  * package (a node_modules symlink whose realpath'd files carry no
7367
- * node_modules segment — shared.ts). The provenance half of the npm
7590
+ * node_modules segment — workspace-registry.ts). The provenance half of the npm
7368
7591
  * typing rule (package types are island handles) and of the per-package
7369
7592
  * requires-dynamic attribution. */
7370
7593
  isNpmFile = (sf) => sf.isDeclarationFile &&