@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
package/dist/index.js CHANGED
@@ -1,44 +1,58 @@
1
- import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
1
+ import { InternalCompilerError } from "./errors.js";
2
+ import { mkdir, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
2
4
  import { basename, dirname, join, resolve } from "node:path";
3
- import { buildCacheRoot, CcCompileError, compileC, compileLibArchive, mobileLibraryTarget, mobileTargetRefusal, prepareBuildCacheRoot, pruneBuildCache, resolveCc, targetPlatform } from "./backend/cc.js";
4
- import { emitModule } from "./backend/emission/emitter.js";
5
+ import { buildCacheRoot, CcCompileError, clearCcCaches, compileC, compileLibArchive, compilerDriverSupportsPersistentCache, configuredTargetPlatform, executableNativeEnvironmentFingerprint, mobileLibraryTarget, mobileTargetRefusal, prepareBuildCacheRoot, pruneBuildCache, resolveCc, targetPlatform, toolchainEnvironmentCachePolicy, toolchainEnvironmentFingerprint } from "./backend/native-toolchain.js";
6
+ import { emitCModule } from "./backend/c/c-emitter.js";
5
7
  import { emitLlvmModule, LlvmUnsupportedError } from "./backend/llvm/emitter.js";
6
- import { rebaseLibrarySourceComments, replaceLibraryIdentity, stripLibraryIdentity, stripLibrarySourceComments } from "./backend/library-identity.js";
7
- import { checkerPanicDiag, ffiNativeBuildDiag, libAsyncExportDiag, libAsyncSurfaceDiag, libExportUnresolvedDiag, libGenericExportDiag, libIntBoundaryDiag, libNpmIneligibleDiag, libSidecarDiag, libUnmappableSignatureDiag, iceDiag, isCheckerPanic, LIB_INBOUND_BYTES_TRAP_CODE, LIB_RUNTIME_TRAP_CODES } from "./diagnostics/diagnostic.js";
8
+ import { emitNativeArtifact, NativeCodegenError } from "./backend/native-codegen.js";
9
+ import { privateSiblingPath } from "./backend/build-cache.js";
10
+ import { nativeCodegenTarget, nativeCodegenTargetRefusal } from "./backend/targets.js";
11
+ import { createNativeLinkInfo } from "./backend/native-link-info.js";
12
+ import { createRuntimeLinkPlan, linkRuntimePackExecutable, RuntimePackError } from "./backend/runtime-pack.js";
13
+ import { splitLlvmLibraryProgram, splitLlvmProgram } from "./backend/llvm/split.js";
14
+ import { rebaseLibrarySourceComments, replaceLibraryIdentity, stripLibraryIdentity, stripLibrarySourceComments } from "./backend/library-identity-markers.js";
15
+ import { checkerPanicDiag, ffiNativeBuildDiag, libAsyncExportDiag, libAsyncSurfaceDiag, libExportUnresolvedDiag, libGenericExportDiag, libIntBoundaryDiag, libNpmIneligibleDiag, libSidecarDiag, libUnmappableSignatureDiag, iceDiag, isCheckerPanic, LIB_INBOUND_BYTES_TRAP_CODE, LIB_RUNTIME_TRAP_CODES, nativeCodegenDiag } from "./diagnostics/diagnostic.js";
8
16
  import { checkLibraryIntegerSlots, classSeed, hasIntSlots, numberCarrierKind } from "./library/int-infer.js";
9
- import { loadLibraryProfile, profileRemediation, profileTeaching } from "./library/profile.js";
10
- import { decorateLibraryRefusals, evaluateLibraryFences } from "./library/fence-eval.js";
17
+ import { loadLibraryProfile, profileRemediation, profileTeaching } from "./library/library-profile.js";
18
+ import { clearFenceEvalCaches, decorateLibraryRefusals, evaluateLibraryFences } from "./library/fence-eval.js";
11
19
  import { assembleTrapTeaching } from "./library/trap-teaching.js";
12
- import { buildSidecar, canonicalModuleGraph, canonicalPath, compilerReleaseVersion, libraryIdentityHashes, updateSidecarIdentity, } from "./library/sidecar.js";
20
+ import { buildSidecar, canonicalModuleGraph, canonicalPath, clearSidecarCaches, compilerReleaseVersion, libraryIdentityHashes, updateSidecarIdentity, } from "./library/sidecar.js";
13
21
  import { validateSidecar } from "./library/sidecar-validate.js";
14
22
  import { entryFunctionExports } from "./frontend/lib-exports.js";
15
23
  import { entryContractFacts } from "./frontend/lib-contract.js";
16
- import { moduleLibAsyncSurface, moduleLibNondeterministicSurface, moduleEmbedsBuiltin, moduleEmbedsCompressedNpm, moduleUsesAssert, moduleUsesCopying, moduleUsesDc, moduleUsesDgram, moduleUsesDynAsync, moduleUsesDynInvoke, moduleUsesEmitter, moduleUsesFetch, moduleUsesFileHandle, moduleUsesFsWatch, moduleUsesHttp2, moduleUsesHttpServer, moduleUsesInspect, moduleUsesLegacyTextDecoder, moduleUsesNet, moduleUsesNodeTest, moduleUsesParseArgs, moduleUsesProcessEvents, moduleUsesQs, moduleUsesRegex, moduleUsesSearchParams, moduleUsesStream, moduleUsesSymbol, moduleUsesTls, moduleUsesTlsCa, moduleUsesZlib } from "./ir/nodes.js";
24
+ import { moduleLibAsyncSurface, moduleLibNondeterministicSurface, moduleEmbedsBuiltin, moduleEmbedsCompressedNpm, moduleUsesAssert, moduleUsesCopying, moduleUsesDc, moduleUsesDgram, moduleUsesDynAsync, moduleUsesDynInvoke, moduleUsesEmitter, moduleUsesFetch, moduleUsesFileHandle, moduleUsesFsWatch, moduleUsesHttp2, moduleUsesHttpServer, moduleUsesInspect, moduleUsesLegacyTextDecoder, moduleUsesNet, moduleUsesNodeTest, moduleUsesParseArgs, moduleUsesProcessEvents, moduleUsesQs, moduleUsesRegex, moduleUsesSearchParams, moduleUsesStream, moduleUsesSymbol, moduleUsesTls, moduleUsesTlsCa, moduleUsesZlib } from "./ir/ir.js";
17
25
  import { serializeModule } from "./ir/serialize.js";
18
26
  import { validateModule } from "./ir/validate.js";
19
27
  import { canonicalBuiltinModule, checkPreflight, isNodeTypesPath, loadProgram, locOf, requiresOf, resolveNpmImport } from "./frontend/program.js";
20
28
  import { npmStaticIneligibleReason, npmStaticOffenders, npmStaticPackageOfPath } from "./frontend/npm-static.js";
21
29
  import { provenanceSources } from "./frontend/provenance-registry.js";
22
30
  import { clearResolveCaches, resolveBareModule } from "./frontend/resolve.js";
23
- import { isJsSourceFileName, isRelativeSpecifier } from "./frontend/shared.js";
31
+ import { isJsSourceFileName } from "./frontend/tsc-codes.js";
32
+ import { isRelativeSpecifier, packageNameOfSpecifier } from "./frontend/workspace-registry.js";
24
33
  import { lowerToIr } from "./frontend/lowering/lowerer.js";
25
- import { loadFfiProfile } from "./ffi/profile.js";
34
+ import { loadFfiProfile } from "./ffi/ffi-manifest.js";
26
35
  import { hasForeignFfiCallback } from "./backend/ffi-callbacks.js";
27
36
  import { FrontendInputTracker, trackedReadFile } from "./frontend/input-tracker.js";
28
- import { libraryFrontendImplementationFingerprint, publishEarlyLibraryCache, readEarlyLibraryCache, readSemanticLibraryCache } from "./library/early-cache.js";
37
+ import { libraryFrontendImplementationFingerprint, publishEarlyLibraryCache, readEarlyLibraryCache, readSemanticLibraryCache } from "./library/library-cache.js";
29
38
  import { createSourceLineRebaser } from "./library/semantic-source.js";
39
+ import { publishEarlyExecutableCache, publishEarlyExecutableRoute, readEarlyExecutableCache } from "./executable/executable-cache.js";
40
+ import { compilerImplementationIdentity } from "./library/compiler-self-identity.js";
30
41
  export const VERSION = "0.0.1";
31
- export { compileC, runtimeSrcDir } from "./backend/cc.js";
32
- export { ANDROID_MIN_API, IPHONEOS_MIN_VERSION, isAndroidTarget, isIosTarget, isMobileTarget, mobileLibraryTarget, mobileTargetRefusal } from "./backend/cc.js";
33
- export { emitModule } from "./backend/emission/emitter.js";
34
- export { renderAll, renderDiagnostic } from "./diagnostics/render.js";
42
+ export { EXTERNAL_OBJECT_ABI_STABILITY, RUNTIME_ABI_MARKER, RUNTIME_ABI_VERSION, } from "./backend/runtime-abi.js";
43
+ export { InternalCompilerError } from "./errors.js";
44
+ export { compileC, runtimeSrcDir, warmNativeCaches, } from "./backend/native-toolchain.js";
45
+ export { ANDROID_MIN_API, IPHONEOS_MIN_VERSION, isAndroidTarget, isIosTarget, isMobileTarget, mobileLibraryTarget, mobileTargetRefusal } from "./backend/native-toolchain.js";
46
+ export { emitCModule, emitCModule as emitModule, } from "./backend/c/c-emitter.js";
47
+ export { renderDiagnostics, renderDiagnostics as renderAll, renderDiagnostic, } from "./diagnostics/render.js";
35
48
  export { renderCoverage } from "./coverage/report.js";
36
49
  export { generateSurfaceManifest, renderSurfaceManifest, MANIFEST_SCHEMA_VERSION, } from "./coverage/surface-manifest.js";
37
50
  export { NODE24_FETCH_COMPAT_PROFILE, } from "./compat/fetch-profile.js";
38
51
  export { LIB_FN_SIGS, validateModule } from "./ir/validate.js";
52
+ export { deserializeModule, IR_VERSION, serializeModule } from "./ir/serialize.js";
39
53
  export { resolveLibraryFences } from "./library/fence-eval.js";
40
- export { loadLibraryProfile, profileTeaching, profileRemediation, LIB_PARAM_CLASSES, LIB_RETURN_CLASSES, } from "./library/profile.js";
41
- export { loadFfiProfile, FFI_CALLBACK_PARAM_CLASSES, FFI_PARAM_CLASSES, FFI_RETURN_CLASSES, } from "./ffi/profile.js";
54
+ export { loadLibraryProfile, profileTeaching, profileRemediation, LIB_PARAM_CLASSES, LIB_RETURN_CLASSES, } from "./library/library-profile.js";
55
+ export { loadFfiProfile, FFI_CALLBACK_PARAM_CLASSES, FFI_PARAM_CLASSES, FFI_RETURN_CLASSES, } from "./ffi/ffi-manifest.js";
42
56
  export { assembleTrapTeaching, TRAP_TEACHING_MARKER, TRAP_TEACHING_SEP, } from "./library/trap-teaching.js";
43
57
  export { abiExportSuffixes, buildSidecar, canonicalModuleGraph, canonicalPath, compilerReleaseVersion, libraryIdentityHashes, SIDECAR_FORMAT, } from "./library/sidecar.js";
44
58
  export { validateSidecar } from "./library/sidecar-validate.js";
@@ -48,7 +62,7 @@ export { ambientDtsPath, isExactExternalTypeSpecifier, overridesDtsPath } from "
48
62
  export { resolveProvenanceSources } from "./frontend/provenance.js";
49
63
  export { wasiGuestPath } from "./wasi-paths.js";
50
64
  export { setProvenanceSources, } from "./frontend/provenance-registry.js";
51
- export * as ir from "./ir/nodes.js";
65
+ export * as ir from "./ir/ir.js";
52
66
  /** The LLVM backend's tier refusal as a diagnostic. SC3xxx = backend
53
67
  * coverage (the program is fine — this backend doesn't compile it yet);
54
68
  * the parenthesized kind tag is machine-readable for the differential
@@ -197,6 +211,12 @@ export function buildTargetPlatform(env = process.env) {
197
211
  return process.platform;
198
212
  }
199
213
  }
214
+ /** Target-platform classification without compiler or SDK discovery. Source
215
+ * artifacts need target semantics for lowering, but do not need a native
216
+ * toolchain merely to decide whether that target is Windows, WASI, etc. */
217
+ export function sourceTargetPlatform(env = process.env) {
218
+ return configuredTargetPlatform(env);
219
+ }
200
220
  /** --npm-static=auto (and library mode's mandatory twin): one throwaway
201
221
  * load finds every bare npm import the program's own modules make, then
202
222
  * the eligibility heuristics (npm-static.ts) pick the packages whose
@@ -294,8 +314,7 @@ function packagesNamedByDiag(message, optedIn) {
294
314
  const hits = new Set();
295
315
  for (const m of message.matchAll(/Module '"([^"]+)"'/g)) {
296
316
  const spec = m[1];
297
- const parts = spec.split("/");
298
- const prefix = spec.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
317
+ const prefix = packageNameOfSpecifier(spec);
299
318
  if (optedIn.has(prefix))
300
319
  hits.add(prefix);
301
320
  }
@@ -306,13 +325,6 @@ function packagesNamedByDiag(message, optedIn) {
306
325
  }
307
326
  return hits;
308
327
  }
309
- /** The package-wide --npm-static name containing an exact bare specifier.
310
- * External mappings are exact (subpaths included), while npm-static owns a
311
- * whole package, so any mapped subpath conflicts with that package opt-in. */
312
- function packageNameOfBareSpecifier(specifier) {
313
- const parts = specifier.split("/");
314
- return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
315
- }
316
328
  /** The one frontend, three npm postures: `undefined`/explicit package
317
329
  * lists and `"auto"` are the executable lane's (--npm-static; fallback =
318
330
  * island). `"lib"` is library mode's mandatory auto twin — the same
@@ -367,7 +379,7 @@ function runFrontend(entryPath, npmStatic, externalTypes) {
367
379
  if (requested.length > 0 && externalTypes !== undefined) {
368
380
  const externalSpecifiersByPackage = new Map();
369
381
  for (const specifier of Object.keys(externalTypes)) {
370
- const pkg = packageNameOfBareSpecifier(specifier);
382
+ const pkg = packageNameOfSpecifier(specifier);
371
383
  const specs = externalSpecifiersByPackage.get(pkg) ?? [];
372
384
  specs.push(specifier);
373
385
  externalSpecifiersByPackage.set(pkg, specs);
@@ -628,21 +640,279 @@ export function analyze(entryPath, opts = {}) {
628
640
  }
629
641
  }
630
642
  /** The whole pipeline: load → preflight → lower → validate → emit C → clang. */
643
+ function clearCompileSessionCaches() {
644
+ clearResolveCaches();
645
+ clearCcCaches();
646
+ clearSidecarCaches();
647
+ clearFenceEvalCaches();
648
+ }
631
649
  export async function compile(entryPath, opts) {
650
+ clearCompileSessionCaches();
651
+ const frontendInputs = new FrontendInputTracker();
652
+ return frontendInputs.run(() => compileTracked(entryPath, opts, frontendInputs));
653
+ }
654
+ /** Build-time API compatibility fence: a caller's existing CompileOptions
655
+ * variable must retain the executable result aliases without narrowing. */
656
+ async function assertCompileOptionsCompatibility(entryPath, opts) {
657
+ const result = await compile(entryPath, opts);
658
+ if (result.ok) {
659
+ const binaryPath = result.binaryPath;
660
+ void binaryPath;
661
+ }
662
+ }
663
+ void assertCompileOptionsCompatibility;
664
+ /** The historical exported CompileResult itself remains executable-shaped. */
665
+ function assertCompileResultCompatibility(result) {
666
+ if (result.ok) {
667
+ const binaryPath = result.binaryPath;
668
+ void binaryPath;
669
+ }
670
+ }
671
+ void assertCompileResultCompatibility;
672
+ function executableNativeFeatures(mod, backend, dynamic, optimization, llvmRefusal) {
673
+ return {
674
+ backend,
675
+ ...(optimization === "dev" ? { optimization: "dev" } : {}),
676
+ ...(llvmRefusal === undefined ? {} : { llvmRefusal }),
677
+ dynamic,
678
+ regex: moduleUsesRegex(mod),
679
+ copying: moduleUsesCopying(mod),
680
+ textDecoderLegacy: moduleUsesLegacyTextDecoder(mod),
681
+ fileHandle: moduleUsesFileHandle(mod),
682
+ fetch: moduleUsesFetch(mod),
683
+ netIsland: moduleEmbedsBuiltin(mod, "node:http") ||
684
+ moduleEmbedsBuiltin(mod, "node:https") ||
685
+ moduleEmbedsBuiltin(mod, "node:net") ||
686
+ moduleEmbedsBuiltin(mod, "node:tls"),
687
+ zlib: moduleUsesZlib(mod) || moduleEmbedsCompressedNpm(mod),
688
+ assert: moduleUsesAssert(mod),
689
+ inspect: moduleUsesInspect(mod),
690
+ dynInvoke: moduleUsesDynInvoke(mod),
691
+ dc: moduleUsesDc(mod),
692
+ dynAsync: moduleUsesDynAsync(mod),
693
+ events: moduleUsesProcessEvents(mod),
694
+ emitter: moduleUsesEmitter(mod),
695
+ symbol: moduleUsesSymbol(mod),
696
+ searchParams: moduleUsesSearchParams(mod),
697
+ qs: moduleUsesQs(mod),
698
+ parseArgs: moduleUsesParseArgs(mod),
699
+ stream: moduleUsesStream(mod),
700
+ net: moduleUsesNet(mod),
701
+ http: moduleUsesHttpServer(mod),
702
+ http2: moduleUsesHttp2(mod),
703
+ dgram: moduleUsesDgram(mod),
704
+ watch: moduleUsesFsWatch(mod),
705
+ foreignFfi: hasForeignFfiCallback(mod.ffiImports ?? []),
706
+ nodeTest: moduleUsesNodeTest(mod),
707
+ tls: moduleUsesTls(mod),
708
+ tlsCa: moduleUsesTlsCa(mod),
709
+ };
710
+ }
711
+ async function compileExecutableNative(features, cPath, outPath, sanitize, ffi, programSplit = null, programObjectDependencies = [], onArtifactReady) {
712
+ const programIsObject = /\.(?:o|obj)$/.test(cPath);
713
+ const runtimePackTarget = programIsObject && !sanitize && process.env["SCRIPTC_RUNTIME_PACK"] !== "0"
714
+ ? nativeCodegenTarget()
715
+ : null;
716
+ if (runtimePackTarget !== null) {
717
+ const plan = await createRuntimeLinkPlan({
718
+ target: runtimePackTarget,
719
+ programObject: cPath,
720
+ outPath,
721
+ features,
722
+ ffi,
723
+ optimization: features.optimization ?? "release",
724
+ programObjectDependencies,
725
+ });
726
+ const cacheableLinker = onArtifactReady !== undefined && process.env["SCRIPTC_LINKER"] === undefined && ffi === null &&
727
+ toolchainEnvironmentCachePolicy().completeArtifacts &&
728
+ await compilerDriverSupportsPersistentCache(resolveCc(), toolchainEnvironmentFingerprint());
729
+ await linkRuntimePackExecutable(plan, {
730
+ // A caller-selected linker can be a mutable wrapper with hidden inputs,
731
+ // and a PATH-selected `clang` can be one too. FFI profiles and mutable
732
+ // linker search environments likewise name transitive files that the
733
+ // top-level dependency snapshot cannot prove. Only a direct driver in a
734
+ // stable link environment may publish a reusable final executable.
735
+ ...(cacheableLinker ? { onArtifactReady } : {}),
736
+ });
737
+ return;
738
+ }
739
+ const effectiveProgramSplit = programSplit ??
740
+ (!programIsObject && features.optimization === "dev" && features.backend === "llvm" && !sanitize
741
+ ? splitLlvmProgram(await readFile(cPath, "utf8"))
742
+ : null);
743
+ const objectLinkDir = programIsObject
744
+ ? await mkdtemp(join(tmpdir(), "scriptc-object-link-"))
745
+ : null;
746
+ const linkDriverSource = objectLinkDir === null
747
+ ? cPath
748
+ : join(objectLinkDir, "driver.c");
749
+ if (objectLinkDir !== null)
750
+ await writeFile(linkDriverSource, "/* scriptc object link driver */\n");
751
+ try {
752
+ await compileC({
753
+ cPath: linkDriverSource,
754
+ outPath,
755
+ cacheIdentity: "scriptc-generated-v1",
756
+ ...(features.optimization === "dev" ? { optimization: "dev" } : {}),
757
+ ...(effectiveProgramSplit === null
758
+ ? {}
759
+ : {
760
+ programShards: effectiveProgramSplit.shards,
761
+ programPublicSymbols: effectiveProgramSplit.publicSymbols,
762
+ }),
763
+ sanitize,
764
+ dynamic: features.dynamic,
765
+ regex: features.regex,
766
+ copying: features.copying,
767
+ textDecoderLegacy: features.textDecoderLegacy,
768
+ fileHandle: features.fileHandle,
769
+ fetch: features.fetch,
770
+ netIsland: features.netIsland,
771
+ zlib: features.zlib,
772
+ assert: features.assert,
773
+ inspect: features.inspect,
774
+ dynInvoke: features.dynInvoke,
775
+ dc: features.dc,
776
+ dynAsync: features.dynAsync,
777
+ events: features.events,
778
+ emitter: features.emitter,
779
+ symbol: features.symbol,
780
+ searchParams: features.searchParams,
781
+ qs: features.qs,
782
+ parseArgs: features.parseArgs,
783
+ stream: features.stream,
784
+ net: features.net,
785
+ http: features.http,
786
+ http2: features.http2,
787
+ dgram: features.dgram,
788
+ watch: features.watch,
789
+ foreignFfi: features.foreignFfi,
790
+ nodeTest: features.nodeTest,
791
+ tls: features.tls,
792
+ tlsCa: features.tlsCa,
793
+ ...(onArtifactReady === undefined ? {} : { onArtifactReady }),
794
+ ...(ffi === null && !programIsObject
795
+ ? {}
796
+ : {
797
+ linkInputs: [
798
+ ...(programIsObject ? [cPath] : []),
799
+ ...(ffi?.libraries ?? []),
800
+ ],
801
+ ...(ffi === null ? {} : { systemLibraries: ffi.systemLibraries }),
802
+ }),
803
+ });
804
+ }
805
+ finally {
806
+ if (objectLinkDir !== null) {
807
+ await rm(objectLinkDir, { recursive: true, force: true }).catch(() => undefined);
808
+ }
809
+ }
810
+ }
811
+ async function emitNativeProgramObject(entryPath, opts, llvm) {
812
+ const stem = basename(entryPath).replace(/\.(ts|mts|cts|js|mjs|cjs)$/, "");
813
+ const artifactPath = join(opts.outDir, `${stem}.helper.o`);
814
+ // compileExecutableNative recognizes object inputs by suffix. The random
815
+ // private name isolates concurrent builds; retain .o so the driver links
816
+ // it rather than attempting to compile it as source.
817
+ const linkPath = `${privateSiblingPath(artifactPath, "native-program-object")}.o`;
818
+ try {
819
+ const artifact = await emitNativeArtifact({
820
+ outputPath: linkPath,
821
+ llvm,
822
+ outputKind: "obj",
823
+ sourcePath: entryPath,
824
+ optimization: opts.optimization === "dev" ? "0" : "2",
825
+ ...(opts.sanitize === undefined ? {} : { sanitize: opts.sanitize }),
826
+ });
827
+ return { linkPath, artifactPath, dependencies: artifact.dependencies };
828
+ }
829
+ catch (error) {
830
+ await rm(linkPath, { force: true }).catch(() => undefined);
831
+ throw error;
832
+ }
833
+ }
834
+ function usesPrecompiledRuntimePack(opts, backend) {
835
+ if (backend !== "llvm" || opts.sanitize === true ||
836
+ process.env["SCRIPTC_RUNTIME_PACK"] === "0" ||
837
+ process.env["SCRIPTC_FETCH_CURL"] === "1")
838
+ return false;
839
+ const cc = process.env["SCRIPTC_CC"] ?? "";
840
+ return (cc === "" || cc === "clang") && nativeCodegenTarget() !== null;
841
+ }
842
+ function runtimePackDiagnostic(error, entryPath) {
843
+ return nativeCodegenDiag(error.code === "unsupported" ? "SC3002" : "SC3003", error.message, entryPath);
844
+ }
845
+ async function compileTracked(entryPath, opts, frontendInputs) {
846
+ entryPath = resolve(entryPath);
847
+ const outputKind = opts.outputKind ?? "exe";
848
+ if (opts.nativeLinkInfo === true && outputKind !== "obj") {
849
+ return {
850
+ ok: false,
851
+ diagnostics: [nativeCodegenDiag("SC3002", "native link info is available only for object output", entryPath)],
852
+ sourceTexts: new Map(),
853
+ };
854
+ }
855
+ if (opts.nativeProgramObject === true &&
856
+ (outputKind !== "exe" || opts.backend !== "llvm")) {
857
+ return {
858
+ ok: false,
859
+ diagnostics: [nativeCodegenDiag("SC3002", "native program-object validation requires an executable build with backend explicitly set to llvm", entryPath)],
860
+ sourceTexts: new Map(),
861
+ };
862
+ }
632
863
  let ffi = null;
864
+ let ffiProfileBytes = null;
633
865
  if (opts.ffiProfilePath !== undefined) {
634
- const loaded = loadFfiProfile(opts.ffiProfilePath);
866
+ const ffiProfilePath = resolve(opts.ffiProfilePath);
867
+ const loaded = loadFfiProfile(ffiProfilePath);
635
868
  if (!loaded.ok) {
636
869
  return { ok: false, diagnostics: loaded.diagnostics, sourceTexts: new Map() };
637
870
  }
638
871
  ffi = loaded.profile;
872
+ ffiProfileBytes = loaded.profileBytes;
873
+ }
874
+ let buildPlatform;
875
+ if (outputKind === "exe") {
876
+ buildPlatform = buildTargetPlatform();
877
+ }
878
+ else {
879
+ try {
880
+ buildPlatform = sourceTargetPlatform();
881
+ }
882
+ catch (err) {
883
+ return {
884
+ ok: false,
885
+ diagnostics: [{
886
+ code: "SC3002",
887
+ message: err instanceof Error ? err.message : String(err),
888
+ loc: { file: entryPath, start: 0, end: 0 },
889
+ }],
890
+ sourceTexts: new Map(),
891
+ };
892
+ }
893
+ if (outputKind === "asm" || outputKind === "obj") {
894
+ const refusal = nativeCodegenTargetRefusal();
895
+ if (refusal !== null) {
896
+ return {
897
+ ok: false,
898
+ diagnostics: [nativeCodegenDiag("SC3002", refusal, entryPath)],
899
+ sourceTexts: new Map(),
900
+ };
901
+ }
902
+ if (opts.sanitize === true) {
903
+ return {
904
+ ok: false,
905
+ diagnostics: [nativeCodegenDiag("SC3002", `--sanitize is not supported with --emit=${outputKind}; AddressSanitizer instrumentation parity is not available in the LLVM native helper yet`, entryPath)],
906
+ sourceTexts: new Map(),
907
+ };
908
+ }
909
+ }
639
910
  }
640
- const buildPlatform = buildTargetPlatform();
641
911
  // Mobile triples are library-mode targets: the archive an embedding app
642
912
  // links is the artifact, and only the library-admissible runtime surface
643
913
  // is verified on those device classes. The executable lane refuses before
644
914
  // any frontend work — a pure env check, so the refusal needs no toolchain.
645
- {
915
+ if (outputKind === "exe") {
646
916
  const entryLoc = { file: entryPath, start: 0, end: 0 };
647
917
  const mobileTarget = mobileLibraryTarget();
648
918
  if (mobileTarget !== null) {
@@ -664,6 +934,151 @@ export async function compile(entryPath, opts) {
664
934
  };
665
935
  }
666
936
  }
937
+ const cacheRoot = outputKind === "exe" && provenanceSources() === null
938
+ ? await prepareBuildCacheRoot(buildCacheRoot())
939
+ : null;
940
+ let earlyCacheOptions = null;
941
+ if (outputKind === "exe") {
942
+ const implementation = await compilerImplementationIdentity();
943
+ earlyCacheOptions = {
944
+ entryPath,
945
+ outDir: opts.outDir,
946
+ outPath: opts.outPath,
947
+ emitIr: opts.emitIr ?? false,
948
+ sanitize: opts.sanitize ?? false,
949
+ dynamic: opts.dynamic ?? false,
950
+ backend: opts.backend ?? "auto",
951
+ ...(opts.optimization === "dev" ? { optimization: "dev" } : {}),
952
+ npmStatic: opts.npmStatic ?? null,
953
+ ffiProfile: opts.ffiProfilePath === undefined || ffiProfileBytes === null
954
+ ? null
955
+ : { path: opts.ffiProfilePath, bytes: ffiProfileBytes },
956
+ target: `${process.env["SCRIPTC_TARGET"] ?? "native"}:${buildPlatform}:${process.arch}:${opts.nativeProgramObject === true
957
+ ? "helper-object"
958
+ : (opts.backend !== "c" && opts.sanitize !== true &&
959
+ process.env["SCRIPTC_RUNTIME_PACK"] !== "0" &&
960
+ process.env["SCRIPTC_FETCH_CURL"] !== "1" &&
961
+ ((process.env["SCRIPTC_CC"] ?? "") === "" || process.env["SCRIPTC_CC"] === "clang") &&
962
+ nativeCodegenTarget() !== null) ? "runtime-pack" : "driver-tu"}`,
963
+ compiler: [process.env["SCRIPTC_LINKER"] ?? process.env["SCRIPTC_CC"] ?? "clang"],
964
+ nativeEnvironment: await executableNativeEnvironmentFingerprint(),
965
+ nodeVersion: process.version,
966
+ implementation: implementation.digest,
967
+ implementationDependencies: implementation.dependencies,
968
+ };
969
+ }
970
+ const earlyHit = earlyCacheOptions === null
971
+ ? null
972
+ : await readEarlyExecutableCache(cacheRoot, earlyCacheOptions);
973
+ if (earlyHit !== null) {
974
+ if (earlyCacheOptions === null) {
975
+ throw new InternalCompilerError("executable cache hit without executable cache options");
976
+ }
977
+ const executableCacheOptions = earlyCacheOptions;
978
+ if (!opts.emitIr) {
979
+ const stem = basename(entryPath).replace(/\.(ts|mts|cts|js|mjs|cjs)$/, "");
980
+ await rm(join(opts.outDir, `${stem}.ir.json`), { force: true });
981
+ }
982
+ // Route/proof metadata is independently evictable. A full-compiler
983
+ // fallback that still finds the validated payload repairs that lightweight
984
+ // index so the next identical CLI invocation can avoid this module graph.
985
+ await publishEarlyExecutableRoute(cacheRoot, executableCacheOptions).catch(() => undefined);
986
+ if (earlyHit.executableRestored) {
987
+ await pruneBuildCache(cacheRoot);
988
+ return {
989
+ ok: true,
990
+ artifact: {
991
+ kind: "exe",
992
+ path: opts.outPath,
993
+ translationUnitPath: earlyHit.cPath,
994
+ backend: earlyHit.native.backend,
995
+ ...(earlyHit.native.llvmRefusal === undefined
996
+ ? {}
997
+ : { llvmRefusal: earlyHit.native.llvmRefusal }),
998
+ },
999
+ binaryPath: opts.outPath,
1000
+ cPath: earlyHit.cPath,
1001
+ backend: earlyHit.native.backend,
1002
+ ...(earlyHit.irPath === undefined ? {} : { irPath: earlyHit.irPath }),
1003
+ ...(earlyHit.native.llvmRefusal === undefined
1004
+ ? {}
1005
+ : { llvmRefusal: earlyHit.native.llvmRefusal }),
1006
+ };
1007
+ }
1008
+ let nativeInputPath = earlyHit.cPath;
1009
+ let nativeProgramObject = null;
1010
+ const useRuntimePack = opts.nativeProgramObject === true ||
1011
+ usesPrecompiledRuntimePack(opts, earlyHit.native.backend);
1012
+ if (useRuntimePack) {
1013
+ if (earlyHit.native.backend !== "llvm") {
1014
+ throw new InternalCompilerError("native program-object cache hit restored a non-LLVM translation unit");
1015
+ }
1016
+ try {
1017
+ nativeProgramObject = await emitNativeProgramObject(entryPath, opts, await readFile(earlyHit.cPath, "utf8"));
1018
+ nativeInputPath = nativeProgramObject.linkPath;
1019
+ }
1020
+ catch (err) {
1021
+ if (!(err instanceof NativeCodegenError))
1022
+ throw err;
1023
+ return {
1024
+ ok: false,
1025
+ diagnostics: [nativeCodegenDiag(err.diagnosticCode, err.message, entryPath)],
1026
+ sourceTexts: new Map(),
1027
+ };
1028
+ }
1029
+ }
1030
+ try {
1031
+ await compileExecutableNative(earlyHit.native, nativeInputPath, opts.outPath, opts.sanitize ?? false, ffi, null, nativeProgramObject?.dependencies, opts.nativeProgramObject === true ? undefined : async ({ dependencies }) => {
1032
+ await publishEarlyExecutableCache(cacheRoot, executableCacheOptions, {
1033
+ ...earlyHit,
1034
+ executableRestored: true,
1035
+ nativeDependencies: dependencies,
1036
+ frontend: earlyHit.frontend,
1037
+ });
1038
+ });
1039
+ if (nativeProgramObject !== null && opts.nativeProgramObject === true) {
1040
+ await rename(nativeProgramObject.linkPath, nativeProgramObject.artifactPath);
1041
+ }
1042
+ }
1043
+ catch (err) {
1044
+ if (err instanceof RuntimePackError) {
1045
+ return { ok: false, diagnostics: [runtimePackDiagnostic(err, entryPath)], sourceTexts: new Map() };
1046
+ }
1047
+ if (ffi !== null && err instanceof CcCompileError) {
1048
+ return {
1049
+ ok: false,
1050
+ diagnostics: [ffiNativeBuildDiag(ffiNativeBuildDetail(err), opts.ffiProfilePath ?? entryPath)],
1051
+ sourceTexts: new Map(),
1052
+ };
1053
+ }
1054
+ throw err;
1055
+ }
1056
+ finally {
1057
+ if (nativeProgramObject !== null) {
1058
+ await rm(nativeProgramObject.linkPath, { force: true }).catch(() => undefined);
1059
+ }
1060
+ }
1061
+ await pruneBuildCache(cacheRoot);
1062
+ return {
1063
+ ok: true,
1064
+ artifact: {
1065
+ kind: "exe",
1066
+ path: opts.outPath,
1067
+ translationUnitPath: earlyHit.cPath,
1068
+ backend: earlyHit.native.backend,
1069
+ ...(earlyHit.native.llvmRefusal === undefined
1070
+ ? {}
1071
+ : { llvmRefusal: earlyHit.native.llvmRefusal }),
1072
+ },
1073
+ binaryPath: opts.outPath,
1074
+ cPath: earlyHit.cPath,
1075
+ backend: earlyHit.native.backend,
1076
+ ...(earlyHit.irPath === undefined ? {} : { irPath: earlyHit.irPath }),
1077
+ ...(earlyHit.native.llvmRefusal === undefined
1078
+ ? {}
1079
+ : { llvmRefusal: earlyHit.native.llvmRefusal }),
1080
+ };
1081
+ }
667
1082
  const fe = runFrontend(entryPath, opts.npmStatic);
668
1083
  let lowered;
669
1084
  let entryText;
@@ -713,7 +1128,7 @@ export async function compile(entryPath, opts) {
713
1128
  if (unavailable !== null) {
714
1129
  return fail([targetRefusalDiag("wasm32-wasi", unavailable.surface, unavailable.loc)]);
715
1130
  }
716
- if (opts.backend === "c") {
1131
+ if (opts.backend === "c" || outputKind === "c") {
717
1132
  const asyncSurface = moduleLibAsyncSurface(lowered.module);
718
1133
  if (asyncSurface !== null) {
719
1134
  return fail([
@@ -728,24 +1143,128 @@ export async function compile(entryPath, opts) {
728
1143
  finally {
729
1144
  fe.dispose();
730
1145
  }
1146
+ const stem = basename(entryPath).replace(/\.(ts|mts|cts|js|mjs|cjs)$/, "");
1147
+ const defaultSourcePaths = {
1148
+ ir: join(opts.outDir, `${stem}.ir.json`),
1149
+ c: join(opts.outDir, `${stem}.c`),
1150
+ llvm: join(opts.outDir, `${stem}.ll`),
1151
+ asm: join(opts.outDir, `${stem}.s`),
1152
+ obj: join(opts.outDir, `${stem}.o`),
1153
+ };
1154
+ const defaultExecutablePaths = [
1155
+ join(opts.outDir, stem),
1156
+ join(opts.outDir, `${stem}.exe`),
1157
+ join(opts.outDir, `${stem}.wasm`),
1158
+ ];
1159
+ const removeStaleSourceArtifacts = async (keep) => {
1160
+ const kept = new Set(keep.map((path) => resolve(path)));
1161
+ const candidates = outputKind === "exe"
1162
+ // Executable builds can generate only these compatibility/translation
1163
+ // unit siblings. Assembly and object outputs are independent primary
1164
+ // artifacts, so an executable build must never claim or delete them.
1165
+ ? [defaultSourcePaths.ir, defaultSourcePaths.c, defaultSourcePaths.llvm]
1166
+ : opts.defaultOutputPath === true
1167
+ ? [...Object.values(defaultSourcePaths), ...defaultExecutablePaths]
1168
+ : [];
1169
+ await Promise.all(candidates
1170
+ .filter((path) => !kept.has(resolve(path)))
1171
+ .map((path) => rm(path, { force: true })));
1172
+ };
1173
+ if (outputKind === "ir") {
1174
+ await mkdir(dirname(opts.outPath), { recursive: true });
1175
+ await writeFile(opts.outPath, serializeModule(lowered.module));
1176
+ await removeStaleSourceArtifacts([opts.outPath]);
1177
+ return { ok: true, artifact: { kind: "ir", path: opts.outPath } };
1178
+ }
1179
+ if (outputKind === "c") {
1180
+ await mkdir(dirname(opts.outPath), { recursive: true });
1181
+ await writeFile(opts.outPath, emitCModule(lowered.module, entryText));
1182
+ await removeStaleSourceArtifacts([opts.outPath]);
1183
+ return { ok: true, artifact: { kind: "c", path: opts.outPath } };
1184
+ }
1185
+ if (outputKind === "llvm" || outputKind === "asm" || outputKind === "obj") {
1186
+ let llvm;
1187
+ try {
1188
+ llvm = emitLlvmModule(lowered.module, {
1189
+ pointerBits: buildPlatform === "wasi" ? 32 : 64,
1190
+ wasi: buildPlatform === "wasi",
1191
+ runtimeAbiMarker: outputKind === "obj",
1192
+ });
1193
+ }
1194
+ catch (err) {
1195
+ if (!(err instanceof LlvmUnsupportedError))
1196
+ throw err;
1197
+ return { ok: false, diagnostics: [llvmRefusalDiag(err, entryPath)], sourceTexts };
1198
+ }
1199
+ if (outputKind === "llvm") {
1200
+ await mkdir(dirname(opts.outPath), { recursive: true });
1201
+ await writeFile(opts.outPath, llvm);
1202
+ }
1203
+ else {
1204
+ try {
1205
+ await emitNativeArtifact({
1206
+ outputPath: opts.outPath,
1207
+ llvm,
1208
+ outputKind,
1209
+ sourcePath: entryPath,
1210
+ optimization: opts.optimization === "dev" ? "0" : "2",
1211
+ ...(opts.sanitize === undefined ? {} : { sanitize: opts.sanitize }),
1212
+ });
1213
+ }
1214
+ catch (err) {
1215
+ if (!(err instanceof NativeCodegenError))
1216
+ throw err;
1217
+ return {
1218
+ ok: false,
1219
+ diagnostics: [nativeCodegenDiag(err.diagnosticCode, err.message, entryPath)],
1220
+ sourceTexts,
1221
+ };
1222
+ }
1223
+ }
1224
+ await removeStaleSourceArtifacts([opts.outPath]);
1225
+ if (outputKind === "obj" && opts.nativeLinkInfo === true) {
1226
+ const target = nativeCodegenTarget();
1227
+ if (target === null) {
1228
+ throw new InternalCompilerError("native object emitted without a native target");
1229
+ }
1230
+ return {
1231
+ ok: true,
1232
+ artifact: {
1233
+ kind: "obj",
1234
+ path: opts.outPath,
1235
+ nativeLinkInfo: await createNativeLinkInfo({
1236
+ programObject: opts.outPath,
1237
+ target,
1238
+ features: executableNativeFeatures(lowered.module, "llvm", opts.dynamic ?? false, opts.optimization ?? "release"),
1239
+ ffi,
1240
+ optimization: opts.optimization ?? "release",
1241
+ }),
1242
+ },
1243
+ };
1244
+ }
1245
+ return { ok: true, artifact: { kind: outputKind, path: opts.outPath } };
1246
+ }
731
1247
  await mkdir(opts.outDir, { recursive: true });
732
- const stem = basename(entryPath).replace(/\.(ts|js|mjs|cjs)$/, "");
733
1248
  // Both backends hang off the same in-memory IrModule (never the JSON
734
1249
  // dump); the LLVM backend's .ll takes the .c's seat on the exact clang
735
1250
  // command line below — compileC accepts either. The default lane tries
736
1251
  // LLVM first; a tier refusal retries ONLY the emit with the C backend
737
1252
  // (the frontend ran once, the IR is backend-agnostic — nothing recompiles).
738
- let cPath = join(opts.outDir, `${stem}.c`);
1253
+ let cPath = defaultSourcePaths.c;
739
1254
  let backend = "c";
1255
+ let llvmSource = null;
740
1256
  let llvmRefusal;
741
1257
  if (opts.backend !== "c") {
742
1258
  try {
743
1259
  const ll = emitLlvmModule(lowered.module, {
744
1260
  pointerBits: buildPlatform === "wasi" ? 32 : 64,
745
1261
  wasi: buildPlatform === "wasi",
1262
+ runtimeAbiMarker: opts.nativeProgramObject === true ||
1263
+ usesPrecompiledRuntimePack(opts, "llvm"),
746
1264
  });
747
- cPath = join(opts.outDir, `${stem}.ll`);
1265
+ cPath = defaultSourcePaths.llvm;
748
1266
  await writeFile(cPath, ll);
1267
+ llvmSource = ll;
749
1268
  backend = "llvm";
750
1269
  }
751
1270
  catch (err) {
@@ -760,120 +1279,72 @@ export async function compile(entryPath, opts) {
760
1279
  }
761
1280
  }
762
1281
  if (backend === "c") {
763
- await writeFile(cPath, emitModule(lowered.module, entryText));
1282
+ await writeFile(cPath, emitCModule(lowered.module, entryText));
764
1283
  }
765
1284
  // Kept-TU honesty: outDir persists across builds (the CLI's .scriptc/),
766
1285
  // so a lane change would leave the PREVIOUS lane's TU beside the fresh
767
1286
  // one — remove the loser so the surviving TU is always the one the
768
1287
  // binary below was linked from.
769
- await rm(join(opts.outDir, `${stem}${backend === "llvm" ? ".c" : ".ll"}`), { force: true });
770
1288
  let irPath;
771
1289
  if (opts.emitIr) {
772
- irPath = join(opts.outDir, `${stem}.ir.json`);
1290
+ irPath = defaultSourcePaths.ir;
773
1291
  await writeFile(irPath, serializeModule(lowered.module));
774
1292
  }
1293
+ await removeStaleSourceArtifacts([
1294
+ cPath,
1295
+ ...(irPath === undefined ? [] : [irPath]),
1296
+ ]);
1297
+ const nativeFeatures = executableNativeFeatures(lowered.module, backend, opts.dynamic ?? false, opts.optimization ?? "release", llvmRefusal);
1298
+ const programSplit = backend === "llvm" && (opts.optimization ?? "release") === "dev" &&
1299
+ !(opts.sanitize ?? false) && llvmSource !== null
1300
+ ? splitLlvmProgram(llvmSource)
1301
+ : null;
775
1302
  await mkdir(dirname(opts.outPath), { recursive: true });
1303
+ if (earlyCacheOptions === null) {
1304
+ throw new InternalCompilerError("executable emission without executable cache options");
1305
+ }
1306
+ const executableCacheOptions = earlyCacheOptions;
1307
+ let publishedExecutable = false;
1308
+ let nativeProgramObject = null;
776
1309
  try {
777
- await compileC({
778
- cPath,
779
- outPath: opts.outPath,
780
- // The emitted TU's non-system dependencies are the runtime/vendor tree,
781
- // which cc.ts fingerprints separately. Low-level arbitrary C omits this
782
- // opt-in so same-path header edits can never hit a stale artifact.
783
- cacheIdentity: "scriptc-generated-v1",
784
- sanitize: opts.sanitize ?? false,
785
- dynamic: opts.dynamic ?? false,
786
- // The link switch for scr_regex.c + libregexp: detected on the IR, so
787
- // regex-free programs keep the historical (pinned) command line.
788
- regex: moduleUsesRegex(lowered.module),
789
- // Array copying methods and the typed-array bridges live in one
790
- // optional TU, linked only when one of their IR intrinsics survives.
791
- copying: moduleUsesCopying(lowered.module),
792
- textDecoderLegacy: moduleUsesLegacyTextDecoder(lowered.module),
793
- // FileHandle owns a native descriptor and its settled-promise adapters;
794
- // keep that optional TU out of programs that never call fsp.open.
795
- fileHandle: moduleUsesFileHandle(lowered.module),
796
- // The link switch for scr_fetch.c (the native bridge over scr_net +
797
- // scr_tls + scr_http's client parser + zlib — cc.ts implies those
798
- // units into the link): embedded npm code that references fetch gets
799
- // the bridge; everything else keeps its exact link line.
800
- fetch: moduleUsesFetch(lowered.module),
801
- // The island's node:http/https client bridge: embedded graphs that
802
- // import those builtins pull scr_net_island.c + the socket units.
803
- netIsland: moduleEmbedsBuiltin(lowered.module, "node:http") ||
804
- moduleEmbedsBuiltin(lowered.module, "node:https") ||
805
- moduleEmbedsBuiltin(lowered.module, "node:net") ||
806
- moduleEmbedsBuiltin(lowered.module, "node:tls"),
807
- // The link switch for scr_zlib.c + libz: zlib.* libCalls on the IR,
808
- // node:zlib in the embedded graph, or COMPRESSED embedded module text
809
- // (emit-island.ts stores big npm sources as raw DEFLATE; the emitted
810
- // main installs scr_zlib_inflate_exact on the same predicate).
811
- zlib: moduleUsesZlib(lowered.module) || moduleEmbedsCompressedNpm(lowered.module),
812
- // The link switch for scr_assert.c: assert.* libCalls on the IR (the
813
- // regex switch also pulls it — scr_regex.c calls the assert helpers).
814
- assert: moduleUsesAssert(lowered.module),
815
- // The link switch for scr_inspect.c: insp.* libCalls on the IR.
816
- inspect: moduleUsesInspect(lowered.module),
817
- // The link switch for scr_dyn_invoke.c: dynInvoke nodes or
818
- // dyn.defineProps libCalls on the IR.
819
- dynInvoke: moduleUsesDynInvoke(lowered.module),
820
- // The link switch for scr_dc.c: dc.* libCalls on the IR (the
821
- // diagnostics_channel registry and pub/sub).
822
- dc: moduleUsesDc(lowered.module),
823
- // The link switch for scr_async_dyn.c: the checked-dynamic async
824
- // surfaces (cc.ts also pulls it under the dynInvoke/dc gates).
825
- dynAsync: moduleUsesDynAsync(lowered.module),
826
- // The link switch for scr_events.c: process signal/exit listeners and
827
- // the stdin event surface on the IR.
828
- events: moduleUsesProcessEvents(lowered.module),
829
- // The link switch for scr_events_emitter.c: the node:events
830
- // EventEmitter surface on the IR (emitter.* libCalls or the
831
- // %EventEmitter class def).
832
- emitter: moduleUsesEmitter(lowered.module),
833
- // The link switch for scr_symbol.c: sym.* libCalls or a symbol-kind
834
- // type anywhere on the IR.
835
- symbol: moduleUsesSymbol(lowered.module),
836
- // The link switch for scr_url_params.c: sp.* libCalls, the
837
- // url.searchParams getter, or a searchParams-kind type on the IR.
838
- searchParams: moduleUsesSearchParams(lowered.module),
839
- // The link switch for scr_qs.c: the qs.* libCalls that live there
840
- // (parse/stringify/unescape; escape rides the always-linked encoder).
841
- qs: moduleUsesQs(lowered.module),
842
- // The static node:util parseArgs implementation (scr_util.c).
843
- parseArgs: moduleUsesParseArgs(lowered.module),
844
- // The link switch for scr_stream.c: the node:stream class surface on
845
- // the IR (stream libCalls or the %Readable-family class defs).
846
- stream: moduleUsesStream(lowered.module),
847
- // The link switch for scr_net.c: net.* (or http.* — http rides on
848
- // net) libCalls on the IR.
849
- net: moduleUsesNet(lowered.module),
850
- // The link switch for scr_http.c: http.* libCalls on the IR.
851
- http: moduleUsesHttpServer(lowered.module),
852
- http2: moduleUsesHttp2(lowered.module),
853
- // The link switch for scr_dgram.c: dgram.* or dns.* libCalls on the IR.
854
- dgram: moduleUsesDgram(lowered.module),
855
- // The link switch for scr_watch.c: fs.watch/watcher.* libCalls on the IR.
856
- watch: moduleUsesFsWatch(lowered.module),
857
- foreignFfi: hasForeignFfiCallback(lowered.module.ffiImports ?? []),
858
- // The link switch for scr_test.c: test.* libCalls on the IR.
859
- nodeTest: moduleUsesNodeTest(lowered.module),
860
- // The link switch for scr_tls.c + the vendored mbedTLS archive:
861
- // tls.* or https.* libCalls on the IR.
862
- tls: moduleUsesTls(lowered.module),
863
- // The link switch for scr_tls_ca.c (the CA-store introspection unit
864
- // — plain PEM bookkeeping, no mbedTLS): tlsca.* libCalls on the IR.
865
- // cc.ts also compiles it under the tls gate (scr_tls.c consults the
866
- // unit's default-set override for its trust anchors).
867
- tlsCa: moduleUsesTlsCa(lowered.module),
868
- ...(ffi !== null
869
- ? {
870
- linkInputs: ffi.libraries,
871
- systemLibraries: ffi.systemLibraries,
872
- }
873
- : {}),
1310
+ const useRuntimePack = opts.nativeProgramObject === true ||
1311
+ usesPrecompiledRuntimePack(opts, backend);
1312
+ if (useRuntimePack) {
1313
+ if (backend !== "llvm" || llvmSource === null) {
1314
+ throw new InternalCompilerError("native program-object validation requires the LLVM backend");
1315
+ }
1316
+ try {
1317
+ nativeProgramObject = await emitNativeProgramObject(entryPath, opts, llvmSource);
1318
+ }
1319
+ catch (err) {
1320
+ if (!(err instanceof NativeCodegenError))
1321
+ throw err;
1322
+ return {
1323
+ ok: false,
1324
+ diagnostics: [nativeCodegenDiag(err.diagnosticCode, err.message, entryPath)],
1325
+ sourceTexts,
1326
+ };
1327
+ }
1328
+ }
1329
+ await compileExecutableNative(nativeFeatures, nativeProgramObject?.linkPath ?? cPath, opts.outPath, opts.sanitize ?? false, ffi, programSplit, nativeProgramObject?.dependencies, opts.nativeProgramObject === true ? undefined : async ({ dependencies }) => {
1330
+ await publishEarlyExecutableCache(cacheRoot, executableCacheOptions, {
1331
+ cPath,
1332
+ native: nativeFeatures,
1333
+ executableRestored: true,
1334
+ nativeDependencies: dependencies,
1335
+ frontend: frontendInputs.snapshot(),
1336
+ ...(irPath === undefined ? {} : { irPath }),
1337
+ });
1338
+ publishedExecutable = true;
874
1339
  });
1340
+ if (nativeProgramObject !== null && opts.nativeProgramObject === true) {
1341
+ await rename(nativeProgramObject.linkPath, nativeProgramObject.artifactPath);
1342
+ }
875
1343
  }
876
1344
  catch (err) {
1345
+ if (err instanceof RuntimePackError) {
1346
+ return { ok: false, diagnostics: [runtimePackDiagnostic(err, entryPath)], sourceTexts };
1347
+ }
877
1348
  if (ffi !== null && err instanceof CcCompileError) {
878
1349
  return {
879
1350
  ok: false,
@@ -885,8 +1356,30 @@ export async function compile(entryPath, opts) {
885
1356
  }
886
1357
  throw err;
887
1358
  }
1359
+ finally {
1360
+ if (nativeProgramObject !== null) {
1361
+ await rm(nativeProgramObject.linkPath, { force: true }).catch(() => undefined);
1362
+ }
1363
+ }
1364
+ if (!publishedExecutable) {
1365
+ await publishEarlyExecutableCache(cacheRoot, executableCacheOptions, {
1366
+ cPath,
1367
+ native: nativeFeatures,
1368
+ executableRestored: false,
1369
+ frontend: frontendInputs.snapshot(),
1370
+ ...(irPath === undefined ? {} : { irPath }),
1371
+ }).catch(() => undefined);
1372
+ }
1373
+ await pruneBuildCache(cacheRoot);
888
1374
  return {
889
1375
  ok: true,
1376
+ artifact: {
1377
+ kind: "exe",
1378
+ path: opts.outPath,
1379
+ translationUnitPath: cPath,
1380
+ backend,
1381
+ ...(llvmRefusal !== undefined ? { llvmRefusal } : {}),
1382
+ },
890
1383
  binaryPath: opts.outPath,
891
1384
  cPath,
892
1385
  backend,
@@ -1245,16 +1738,17 @@ async function compileLibraryNative(profile, cPath, archivePath, sanitize, featu
1245
1738
  const localizeSymbols = libraryLocalizeSymbols(profile);
1246
1739
  let identityCSource;
1247
1740
  let programSource;
1248
- if (profile.sidecar !== null || profile.emission === "c") {
1741
+ if (profile.sidecar !== null || profile.emission === "c" ||
1742
+ (profile.emission === "llvm" && profile.optimization === "dev" && !sanitize)) {
1249
1743
  const publicSource = await readFile(cPath, "utf8");
1250
1744
  programSource = publicSource;
1251
1745
  }
1252
1746
  if (profile.sidecar !== null) {
1253
1747
  if (features.buildId === undefined)
1254
- throw new Error("library identity TU has no build id");
1748
+ throw new InternalCompilerError("library identity TU has no build id");
1255
1749
  const withoutIdentity = stripLibraryIdentity(programSource, profile.emission);
1256
1750
  if (withoutIdentity === programSource) {
1257
- throw new Error("generated public library TU has no identity region");
1751
+ throw new InternalCompilerError("generated public library TU has no identity region");
1258
1752
  }
1259
1753
  programSource = withoutIdentity;
1260
1754
  identityCSource = [
@@ -1268,10 +1762,19 @@ async function compileLibraryNative(profile, cPath, archivePath, sanitize, featu
1268
1762
  if (profile.emission === "c") {
1269
1763
  programSource = stripLibrarySourceComments(programSource, profile.entry);
1270
1764
  }
1765
+ const llvmSplit = profile.emission === "llvm" && profile.optimization === "dev" && !sanitize && programSource !== undefined
1766
+ ? splitLlvmLibraryProgram(programSource)
1767
+ : null;
1271
1768
  await compileLibArchive({
1272
1769
  cPath,
1273
1770
  ...(programSource !== undefined ? { programSource } : {}),
1274
1771
  ...(identityCSource !== undefined ? { identityCSource } : {}),
1772
+ ...(llvmSplit !== null
1773
+ ? {
1774
+ programShards: llvmSplit.shards,
1775
+ programPublicSymbols: llvmSplit.publicSymbols,
1776
+ }
1777
+ : {}),
1275
1778
  outPath: archivePath,
1276
1779
  cacheIdentity: "scriptc-generated-library-v1",
1277
1780
  sanitize,
@@ -1295,7 +1798,7 @@ async function emitSemanticLibraryHit(hit, profile, opts, archivePath, cacheRoot
1295
1798
  let sidecarJson = hit.sidecarJson;
1296
1799
  if (profile.sidecar !== null) {
1297
1800
  if (mod.lib?.identity === undefined || sidecarJson === null) {
1298
- throw new Error("semantic library cache lost sidecar identity metadata");
1801
+ throw new InternalCompilerError("semantic library cache lost sidecar identity metadata");
1299
1802
  }
1300
1803
  const modules = canonicalModuleGraph(rootDir, hit.sourceTexts);
1301
1804
  const { buildId, sourceHash } = libraryIdentityHashes(compilerReleaseVersion(), profile.profileBytes, modules);
@@ -1312,7 +1815,7 @@ async function emitSemanticLibraryHit(hit, profile, opts, archivePath, cacheRoot
1312
1815
  };
1313
1816
  }
1314
1817
  await mkdir(opts.outDir, { recursive: true });
1315
- const stem = basename(profile.entry).replace(/\.(ts|js|mjs|cjs)$/, "");
1818
+ const stem = basename(profile.entry).replace(/\.(ts|mts|cts|js|mjs|cjs)$/, "");
1316
1819
  const cPath = join(opts.outDir, `${stem}.lib.${profile.emission === "llvm" ? "ll" : "c"}`);
1317
1820
  let translationUnit = hit.translationUnit;
1318
1821
  if (profile.sidecar !== null) {
@@ -1325,7 +1828,7 @@ async function emitSemanticLibraryHit(hit, profile, opts, archivePath, cacheRoot
1325
1828
  const previous = hit.previousSources.get(mod.sourceFile);
1326
1829
  const current = hit.sourceTexts.get(mod.sourceFile);
1327
1830
  if (previous === undefined || current === undefined) {
1328
- throw new Error("semantic library cache lost the entry source text");
1831
+ throw new InternalCompilerError("semantic library cache lost the entry source text");
1329
1832
  }
1330
1833
  translationUnit = rebaseLibrarySourceComments(translationUnit, mod.sourceFile, createSourceLineRebaser(mod.sourceFile, previous, current));
1331
1834
  await writeFile(cPath, translationUnit);
@@ -1367,6 +1870,7 @@ async function emitSemanticLibraryHit(hit, profile, opts, archivePath, cacheRoot
1367
1870
  };
1368
1871
  }
1369
1872
  export async function compileLibrary(opts) {
1873
+ clearCompileSessionCaches();
1370
1874
  const frontendInputs = new FrontendInputTracker();
1371
1875
  return frontendInputs.run(() => compileLibraryTracked(opts, frontendInputs));
1372
1876
  }
@@ -1409,7 +1913,7 @@ async function compileLibraryTracked(opts, frontendInputs) {
1409
1913
  if (directory === profileDir || dirname(directory) === directory)
1410
1914
  break;
1411
1915
  }
1412
- const archivePath = opts.outPath ?? join(opts.outDir, `${basename(entryPath).replace(/\.(ts|js|mjs|cjs)$/, "")}.lib.a`);
1916
+ const archivePath = opts.outPath ?? join(opts.outDir, `${basename(entryPath).replace(/\.(ts|mts|cts|js|mjs|cjs)$/, "")}.lib.a`);
1413
1917
  // Mobile-target admission first — a pure env/host check, so a refused
1414
1918
  // pairing never reaches toolchain discovery. iOS targets (device and
1415
1919
  // simulator) build on darwin hosts only: the Apple SDK sysroot and the
@@ -1429,7 +1933,7 @@ async function compileLibraryTracked(opts, frontendInputs) {
1429
1933
  // Multi-instance library mode (abi.localize_runtime) localizes per
1430
1934
  // OBJECT FORMAT: ELF and COFF archives localize from any host (cross
1431
1935
  // ELF merges through the cross driver's own lld; COFF merges and
1432
- // demotes in process — see cc.ts's localizeLibraryObjects), and Mach-O
1936
+ // demotes in process — see native-toolchain.ts's localizeLibraryObjects), and Mach-O
1433
1937
  // localization runs the macOS host linker, so macos and ios targets
1434
1938
  // admit darwin hosts only (the mobile admission above already refused
1435
1939
  // an ios triple off darwin). Everything else refuses before frontend/
@@ -1726,7 +2230,7 @@ async function compileLibraryTracked(opts, frontendInputs) {
1726
2230
  return fail(validation.map((v) => iceDiag(v.message, v.loc)));
1727
2231
  timing("ir-validate");
1728
2232
  await mkdir(opts.outDir, { recursive: true });
1729
- const stem = basename(entryPath).replace(/\.(ts|js|mjs|cjs)$/, "");
2233
+ const stem = basename(entryPath).replace(/\.(ts|mts|cts|js|mjs|cjs)$/, "");
1730
2234
  let cPath;
1731
2235
  if (profile.emission === "llvm") {
1732
2236
  try {
@@ -1745,7 +2249,7 @@ async function compileLibraryTracked(opts, frontendInputs) {
1745
2249
  }
1746
2250
  else {
1747
2251
  cPath = join(opts.outDir, `${stem}.lib.c`);
1748
- await writeFile(cPath, emitModule(mod, entryText));
2252
+ await writeFile(cPath, emitCModule(mod, entryText));
1749
2253
  }
1750
2254
  await rm(join(opts.outDir, `${stem}.lib.${profile.emission === "llvm" ? "c" : "ll"}`), { force: true });
1751
2255
  let irPath;