@scriptc/compiler 0.0.35 → 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 (418) 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/unsupported.d.ts +1 -1
  121. package/dist/backend/llvm/walkers.d.ts +2 -3
  122. package/dist/backend/llvm/walkers.js +164 -218
  123. package/dist/backend/llvm/walkers.js.map +1 -1
  124. package/dist/backend/native-codegen.d.ts +38 -0
  125. package/dist/backend/native-codegen.js +261 -0
  126. package/dist/backend/native-codegen.js.map +1 -0
  127. package/dist/backend/native-codegen.test.js +188 -0
  128. package/dist/backend/native-codegen.test.js.map +1 -0
  129. package/dist/backend/native-link-info.d.ts +96 -0
  130. package/dist/backend/native-link-info.js +219 -0
  131. package/dist/backend/native-link-info.js.map +1 -0
  132. package/dist/backend/native-link-info.test.d.ts +1 -0
  133. package/dist/backend/native-link-info.test.js +134 -0
  134. package/dist/backend/native-link-info.test.js.map +1 -0
  135. package/dist/backend/{cc.d.ts → native-toolchain.d.ts} +54 -34
  136. package/dist/backend/{cc.js → native-toolchain.js} +231 -810
  137. package/dist/backend/native-toolchain.js.map +1 -0
  138. package/dist/backend/native-toolchain.test.d.ts +1 -0
  139. package/dist/backend/{cc-cache.test.js → native-toolchain.test.js} +214 -6
  140. package/dist/backend/native-toolchain.test.js.map +1 -0
  141. package/dist/backend/object-localize.js +1 -1
  142. package/dist/backend/runtime-abi.d.ts +10 -0
  143. package/dist/backend/runtime-abi.js +11 -0
  144. package/dist/backend/runtime-abi.js.map +1 -0
  145. package/dist/backend/runtime-pack.d.ts +137 -0
  146. package/dist/backend/runtime-pack.js +400 -0
  147. package/dist/backend/runtime-pack.js.map +1 -0
  148. package/dist/backend/runtime-pack.test.d.ts +1 -0
  149. package/dist/backend/runtime-pack.test.js +438 -0
  150. package/dist/backend/runtime-pack.test.js.map +1 -0
  151. package/dist/backend/targets.d.ts +30 -0
  152. package/dist/backend/targets.js +46 -0
  153. package/dist/backend/targets.js.map +1 -0
  154. package/dist/backend/targets.test.d.ts +1 -0
  155. package/dist/backend/targets.test.js +19 -0
  156. package/dist/backend/targets.test.js.map +1 -0
  157. package/dist/backend/vendor-archives.d.ts +41 -0
  158. package/dist/backend/vendor-archives.js +462 -0
  159. package/dist/backend/vendor-archives.js.map +1 -0
  160. package/dist/compat/fetch-profile.d.ts +0 -1
  161. package/dist/compat/fetch-profile.js +0 -1
  162. package/dist/compat/fetch-profile.js.map +1 -1
  163. package/dist/coverage/report.js +3 -3
  164. package/dist/coverage/report.js.map +1 -1
  165. package/dist/coverage/surface-manifest.js +25 -32
  166. package/dist/coverage/surface-manifest.js.map +1 -1
  167. package/dist/diagnostics/diagnostic.d.ts +11 -12
  168. package/dist/diagnostics/diagnostic.js +19 -17
  169. package/dist/diagnostics/diagnostic.js.map +1 -1
  170. package/dist/diagnostics/render.d.ts +1 -1
  171. package/dist/diagnostics/render.js +1 -1
  172. package/dist/diagnostics/render.js.map +1 -1
  173. package/dist/errors.d.ts +5 -0
  174. package/dist/errors.js +9 -0
  175. package/dist/errors.js.map +1 -0
  176. package/dist/executable/{early-cache.d.ts → executable-cache.d.ts} +2 -2
  177. package/dist/executable/{early-cache.js → executable-cache.js} +36 -98
  178. package/dist/executable/executable-cache.js.map +1 -0
  179. package/dist/executable/executable-cache.test.d.ts +1 -0
  180. package/dist/executable/{early-cache.test.js → executable-cache.test.js} +3 -3
  181. package/dist/executable/executable-cache.test.js.map +1 -0
  182. package/dist/ffi/{profile.js → ffi-manifest.js} +1 -1
  183. package/dist/ffi/ffi-manifest.js.map +1 -0
  184. package/dist/frontend/builtin-modules.d.ts +21 -0
  185. package/dist/frontend/builtin-modules.js +82 -0
  186. package/dist/frontend/builtin-modules.js.map +1 -0
  187. package/dist/frontend/cjs-lexer.d.ts +7 -0
  188. package/dist/frontend/cjs-lexer.js +15 -17
  189. package/dist/frontend/cjs-lexer.js.map +1 -1
  190. package/dist/frontend/dts-paths.d.ts +26 -0
  191. package/dist/frontend/dts-paths.js +41 -0
  192. package/dist/frontend/dts-paths.js.map +1 -0
  193. package/dist/frontend/input-tracker.d.ts +0 -2
  194. package/dist/frontend/input-tracker.js +1 -4
  195. package/dist/frontend/input-tracker.js.map +1 -1
  196. package/dist/frontend/lib-contract.d.ts +1 -5
  197. package/dist/frontend/lib-contract.js +1 -1
  198. package/dist/frontend/lib-contract.js.map +1 -1
  199. package/dist/frontend/lib-exports.d.ts +1 -1
  200. package/dist/frontend/lowering/call-position.d.ts +4 -0
  201. package/dist/frontend/lowering/call-position.js +7 -0
  202. package/dist/frontend/lowering/call-position.js.map +1 -0
  203. package/dist/frontend/lowering/callback-arg.d.ts +20 -0
  204. package/dist/frontend/lowering/callback-arg.js +44 -0
  205. package/dist/frontend/lowering/callback-arg.js.map +1 -0
  206. package/dist/frontend/lowering/lib-boundary.d.ts +1 -1
  207. package/dist/frontend/lowering/lib-boundary.js +34 -34
  208. package/dist/frontend/lowering/lib-boundary.js.map +1 -1
  209. package/dist/frontend/lowering/lower-assert.d.ts +3 -3
  210. package/dist/frontend/lowering/lower-assert.js +214 -241
  211. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  212. package/dist/frontend/lowering/lower-builtins.d.ts +74 -146
  213. package/dist/frontend/lowering/lower-builtins.js +1124 -1232
  214. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  215. package/dist/frontend/lowering/lower-calls.d.ts +56 -188
  216. package/dist/frontend/lowering/lower-calls.js +1397 -1492
  217. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  218. package/dist/frontend/lowering/lower-classes.d.ts +62 -125
  219. package/dist/frontend/lowering/lower-classes.js +832 -866
  220. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  221. package/dist/frontend/lowering/lower-comptime.d.ts +5 -12
  222. package/dist/frontend/lowering/lower-comptime.js +32 -31
  223. package/dist/frontend/lowering/lower-comptime.js.map +1 -1
  224. package/dist/frontend/lowering/lower-containers.d.ts +35 -135
  225. package/dist/frontend/lowering/lower-containers.js +1384 -1700
  226. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  227. package/dist/frontend/lowering/lower-dgram.d.ts +3 -7
  228. package/dist/frontend/lowering/lower-dgram.js +97 -111
  229. package/dist/frontend/lowering/lower-dgram.js.map +1 -1
  230. package/dist/frontend/lowering/lower-enums.d.ts +4 -4
  231. package/dist/frontend/lowering/lower-enums.js +30 -30
  232. package/dist/frontend/lowering/lower-enums.js.map +1 -1
  233. package/dist/frontend/lowering/{lower-emitter.d.ts → lower-event-emitter.d.ts} +7 -18
  234. package/dist/frontend/lowering/{lower-emitter.js → lower-event-emitter.js} +172 -174
  235. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -0
  236. package/dist/frontend/lowering/lower-expando.d.ts +5 -5
  237. package/dist/frontend/lowering/lower-expando.js +40 -40
  238. package/dist/frontend/lowering/lower-expando.js.map +1 -1
  239. package/dist/frontend/lowering/lower-exprs.d.ts +56 -264
  240. package/dist/frontend/lowering/lower-exprs.js +1624 -1696
  241. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  242. package/dist/frontend/lowering/lower-generators.d.ts +6 -6
  243. package/dist/frontend/lowering/lower-generators.js +73 -72
  244. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  245. package/dist/frontend/lowering/lower-inspect.d.ts +5 -17
  246. package/dist/frontend/lowering/lower-inspect.js +236 -238
  247. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  248. package/dist/frontend/lowering/lower-island.d.ts +34 -45
  249. package/dist/frontend/lowering/lower-island.js +437 -508
  250. package/dist/frontend/lowering/lower-island.js.map +1 -1
  251. package/dist/frontend/lowering/lower-mixins.d.ts +7 -10
  252. package/dist/frontend/lowering/lower-mixins.js +85 -85
  253. package/dist/frontend/lowering/lower-mixins.js.map +1 -1
  254. package/dist/frontend/lowering/lower-modules.d.ts +12 -18
  255. package/dist/frontend/lowering/lower-modules.js +284 -283
  256. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  257. package/dist/frontend/lowering/lower-namespaces.d.ts +23 -49
  258. package/dist/frontend/lowering/lower-namespaces.js +123 -115
  259. package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
  260. package/dist/frontend/lowering/lower-server.d.ts +18 -25
  261. package/dist/frontend/lowering/lower-server.js +899 -899
  262. package/dist/frontend/lowering/lower-server.js.map +1 -1
  263. package/dist/frontend/lowering/lower-stmts.d.ts +30 -149
  264. package/dist/frontend/lowering/lower-stmts.js +1175 -1228
  265. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  266. package/dist/frontend/lowering/lower-stream.d.ts +12 -12
  267. package/dist/frontend/lowering/lower-stream.js +300 -301
  268. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  269. package/dist/frontend/lowering/lower-test.d.ts +5 -5
  270. package/dist/frontend/lowering/lower-test.js +82 -82
  271. package/dist/frontend/lowering/lower-test.js.map +1 -1
  272. package/dist/frontend/lowering/lowerer.d.ts +60 -20
  273. package/dist/frontend/lowering/lowerer.js +191 -117
  274. package/dist/frontend/lowering/lowerer.js.map +1 -1
  275. package/dist/frontend/lowering/pairs-snapshot.d.ts +11 -0
  276. package/dist/frontend/lowering/pairs-snapshot.js +85 -0
  277. package/dist/frontend/lowering/pairs-snapshot.js.map +1 -0
  278. package/dist/frontend/lowering/static-this.d.ts +6 -0
  279. package/dist/frontend/lowering/static-this.js +24 -0
  280. package/dist/frontend/lowering/static-this.js.map +1 -0
  281. package/dist/frontend/lowering/surfaces.d.ts +14 -33
  282. package/dist/frontend/lowering/surfaces.js +63 -63
  283. package/dist/frontend/lowering/surfaces.js.map +1 -1
  284. package/dist/frontend/npm-static-rewrite.js +6 -28
  285. package/dist/frontend/npm-static-rewrite.js.map +1 -1
  286. package/dist/frontend/npm-static.d.ts +0 -10
  287. package/dist/frontend/npm-static.js +4 -7
  288. package/dist/frontend/npm-static.js.map +1 -1
  289. package/dist/frontend/npm.d.ts +0 -24
  290. package/dist/frontend/npm.js +11 -85
  291. package/dist/frontend/npm.js.map +1 -1
  292. package/dist/frontend/program.d.ts +3 -1
  293. package/dist/frontend/program.js +9 -4
  294. package/dist/frontend/program.js.map +1 -1
  295. package/dist/frontend/provenance-registry.d.ts +0 -2
  296. package/dist/frontend/provenance-registry.js +0 -10
  297. package/dist/frontend/provenance-registry.js.map +1 -1
  298. package/dist/frontend/provenance.js +4 -7
  299. package/dist/frontend/provenance.js.map +1 -1
  300. package/dist/frontend/resolve.d.ts +7 -2
  301. package/dist/frontend/resolve.js +12 -17
  302. package/dist/frontend/resolve.js.map +1 -1
  303. package/dist/frontend/resolve.test.d.ts +1 -0
  304. package/dist/frontend/resolve.test.js +29 -0
  305. package/dist/frontend/resolve.test.js.map +1 -0
  306. package/dist/frontend/ts7/adapter.d.ts +2 -2
  307. package/dist/frontend/ts7/adapter.js +1 -1
  308. package/dist/frontend/ts7/adapter.js.map +1 -1
  309. package/dist/frontend/ts7/checker.js +2 -36
  310. package/dist/frontend/ts7/checker.js.map +1 -1
  311. package/dist/frontend/ts7/enums.js +2 -1
  312. package/dist/frontend/ts7/enums.js.map +1 -1
  313. package/dist/frontend/ts7/{program.js → program-adapter.js} +7 -6
  314. package/dist/frontend/ts7/program-adapter.js.map +1 -0
  315. package/dist/frontend/ts7/world-check.d.ts +1 -3
  316. package/dist/frontend/ts7/world-check.js +3 -1
  317. package/dist/frontend/ts7/world-check.js.map +1 -1
  318. package/dist/frontend/tsc-codes.d.ts +8 -0
  319. package/dist/frontend/tsc-codes.js +109 -0
  320. package/dist/frontend/tsc-codes.js.map +1 -0
  321. package/dist/frontend/{types.d.ts → type-mapper.d.ts} +2 -25
  322. package/dist/frontend/{types.js → type-mapper.js} +12 -11
  323. package/dist/frontend/type-mapper.js.map +1 -0
  324. package/dist/frontend/workspace-registry.d.ts +26 -0
  325. package/dist/frontend/workspace-registry.js +71 -0
  326. package/dist/frontend/workspace-registry.js.map +1 -0
  327. package/dist/index.d.ts +112 -30
  328. package/dist/index.js +512 -126
  329. package/dist/index.js.map +1 -1
  330. package/dist/ir/analysis.d.ts +37 -0
  331. package/dist/ir/analysis.js +118 -0
  332. package/dist/ir/analysis.js.map +1 -0
  333. package/dist/ir/analysis.test.d.ts +1 -0
  334. package/dist/ir/analysis.test.js +21 -0
  335. package/dist/ir/analysis.test.js.map +1 -0
  336. package/dist/ir/build.d.ts +9 -0
  337. package/dist/ir/build.js +33 -0
  338. package/dist/ir/build.js.map +1 -0
  339. package/dist/ir/integer-loops.d.ts +1 -1
  340. package/dist/ir/{nodes.d.ts → ir.d.ts} +54 -26
  341. package/dist/ir/{nodes.js → ir.js} +145 -141
  342. package/dist/ir/ir.js.map +1 -0
  343. package/dist/ir/ir.test.d.ts +1 -0
  344. package/dist/ir/ir.test.js +17 -0
  345. package/dist/ir/ir.test.js.map +1 -0
  346. package/dist/ir/serialize.d.ts +1 -1
  347. package/dist/ir/serialize.js +2 -1
  348. package/dist/ir/serialize.js.map +1 -1
  349. package/dist/ir/validate.d.ts +1 -1
  350. package/dist/ir/validate.js +10 -5
  351. package/dist/ir/validate.js.map +1 -1
  352. package/dist/library/cache-primitives.d.ts +24 -0
  353. package/dist/library/cache-primitives.js +83 -0
  354. package/dist/library/cache-primitives.js.map +1 -0
  355. package/dist/library/cache-reset.test.d.ts +1 -0
  356. package/dist/library/cache-reset.test.js +47 -0
  357. package/dist/library/cache-reset.test.js.map +1 -0
  358. package/dist/library/{implementation-identity.js → compiler-self-identity.js} +1 -1
  359. package/dist/library/compiler-self-identity.js.map +1 -0
  360. package/dist/library/fence-eval.d.ts +3 -1
  361. package/dist/library/fence-eval.js +5 -1
  362. package/dist/library/fence-eval.js.map +1 -1
  363. package/dist/library/int-infer.d.ts +1 -36
  364. package/dist/library/int-infer.js +17 -17
  365. package/dist/library/int-infer.js.map +1 -1
  366. package/dist/library/{early-cache.d.ts → library-cache.d.ts} +1 -1
  367. package/dist/library/{early-cache.js → library-cache.js} +34 -89
  368. package/dist/library/library-cache.js.map +1 -0
  369. package/dist/library/library-cache.test.d.ts +1 -0
  370. package/dist/library/{early-cache.test.js → library-cache.test.js} +2 -2
  371. package/dist/library/library-cache.test.js.map +1 -0
  372. package/dist/library/{profile.d.ts → library-profile.d.ts} +4 -7
  373. package/dist/library/{profile.js → library-profile.js} +18 -11
  374. package/dist/library/library-profile.js.map +1 -0
  375. package/dist/library/semantic-source.js +2 -1
  376. package/dist/library/semantic-source.js.map +1 -1
  377. package/dist/library/sidecar.d.ts +5 -2
  378. package/dist/library/sidecar.js +11 -5
  379. package/dist/library/sidecar.js.map +1 -1
  380. package/dist/startup-cache.d.ts +3 -3
  381. package/dist/startup-cache.js +2 -2
  382. package/dist/startup-cache.js.map +1 -1
  383. package/package.json +6 -2
  384. package/surface-manifest.json +1 -1
  385. package/dist/backend/cc-cache.test.js.map +0 -1
  386. package/dist/backend/cc.js.map +0 -1
  387. package/dist/backend/emission/emit-async.js.map +0 -1
  388. package/dist/backend/emission/emit-exprs.d.ts +0 -13
  389. package/dist/backend/emission/emit-exprs.js +0 -7407
  390. package/dist/backend/emission/emit-exprs.js.map +0 -1
  391. package/dist/backend/emission/emit-island.js.map +0 -1
  392. package/dist/backend/emission/emit-shapes.js.map +0 -1
  393. package/dist/backend/emission/emit-stmts.js.map +0 -1
  394. package/dist/backend/emission/emit-types.js.map +0 -1
  395. package/dist/backend/emission/emit-walkers.js.map +0 -1
  396. package/dist/backend/emission/emitter.js.map +0 -1
  397. package/dist/backend/emission/may-throw.js.map +0 -1
  398. package/dist/backend/library-identity.js.map +0 -1
  399. package/dist/executable/early-cache.js.map +0 -1
  400. package/dist/executable/early-cache.test.js.map +0 -1
  401. package/dist/ffi/profile.js.map +0 -1
  402. package/dist/frontend/lowering/lower-emitter.js.map +0 -1
  403. package/dist/frontend/shared.d.ts +0 -82
  404. package/dist/frontend/shared.js +0 -308
  405. package/dist/frontend/shared.js.map +0 -1
  406. package/dist/frontend/ts7/program.js.map +0 -1
  407. package/dist/frontend/types.js.map +0 -1
  408. package/dist/ir/nodes.js.map +0 -1
  409. package/dist/library/early-cache.js.map +0 -1
  410. package/dist/library/early-cache.test.js.map +0 -1
  411. package/dist/library/implementation-identity.js.map +0 -1
  412. package/dist/library/profile.js.map +0 -1
  413. /package/dist/backend/{cc-cache.test.d.ts → c/types.test.d.ts} +0 -0
  414. /package/dist/{executable/early-cache.test.d.ts → backend/llvm/shapes.test.d.ts} +0 -0
  415. /package/dist/{library/early-cache.test.d.ts → backend/native-codegen.test.d.ts} +0 -0
  416. /package/dist/ffi/{profile.d.ts → ffi-manifest.d.ts} +0 -0
  417. /package/dist/frontend/ts7/{program.d.ts → program-adapter.d.ts} +0 -0
  418. /package/dist/library/{implementation-identity.d.ts → compiler-self-identity.d.ts} +0 -0
package/dist/index.js CHANGED
@@ -1,47 +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, executableNativeEnvironmentFingerprint, 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";
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";
6
13
  import { splitLlvmLibraryProgram, splitLlvmProgram } from "./backend/llvm/split.js";
7
- import { rebaseLibrarySourceComments, replaceLibraryIdentity, stripLibraryIdentity, stripLibrarySourceComments } from "./backend/library-identity.js";
8
- 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";
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";
9
16
  import { checkLibraryIntegerSlots, classSeed, hasIntSlots, numberCarrierKind } from "./library/int-infer.js";
10
- import { loadLibraryProfile, profileRemediation, profileTeaching } from "./library/profile.js";
11
- 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";
12
19
  import { assembleTrapTeaching } from "./library/trap-teaching.js";
13
- import { buildSidecar, canonicalModuleGraph, canonicalPath, compilerReleaseVersion, libraryIdentityHashes, updateSidecarIdentity, } from "./library/sidecar.js";
20
+ import { buildSidecar, canonicalModuleGraph, canonicalPath, clearSidecarCaches, compilerReleaseVersion, libraryIdentityHashes, updateSidecarIdentity, } from "./library/sidecar.js";
14
21
  import { validateSidecar } from "./library/sidecar-validate.js";
15
22
  import { entryFunctionExports } from "./frontend/lib-exports.js";
16
23
  import { entryContractFacts } from "./frontend/lib-contract.js";
17
- 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";
18
25
  import { serializeModule } from "./ir/serialize.js";
19
26
  import { validateModule } from "./ir/validate.js";
20
27
  import { canonicalBuiltinModule, checkPreflight, isNodeTypesPath, loadProgram, locOf, requiresOf, resolveNpmImport } from "./frontend/program.js";
21
28
  import { npmStaticIneligibleReason, npmStaticOffenders, npmStaticPackageOfPath } from "./frontend/npm-static.js";
22
29
  import { provenanceSources } from "./frontend/provenance-registry.js";
23
30
  import { clearResolveCaches, resolveBareModule } from "./frontend/resolve.js";
24
- import { isJsSourceFileName, isRelativeSpecifier } from "./frontend/shared.js";
31
+ import { isJsSourceFileName } from "./frontend/tsc-codes.js";
32
+ import { isRelativeSpecifier, packageNameOfSpecifier } from "./frontend/workspace-registry.js";
25
33
  import { lowerToIr } from "./frontend/lowering/lowerer.js";
26
- import { loadFfiProfile } from "./ffi/profile.js";
34
+ import { loadFfiProfile } from "./ffi/ffi-manifest.js";
27
35
  import { hasForeignFfiCallback } from "./backend/ffi-callbacks.js";
28
36
  import { FrontendInputTracker, trackedReadFile } from "./frontend/input-tracker.js";
29
- import { libraryFrontendImplementationFingerprint, publishEarlyLibraryCache, readEarlyLibraryCache, readSemanticLibraryCache } from "./library/early-cache.js";
37
+ import { libraryFrontendImplementationFingerprint, publishEarlyLibraryCache, readEarlyLibraryCache, readSemanticLibraryCache } from "./library/library-cache.js";
30
38
  import { createSourceLineRebaser } from "./library/semantic-source.js";
31
- import { publishEarlyExecutableCache, publishEarlyExecutableRoute, readEarlyExecutableCache } from "./executable/early-cache.js";
32
- import { compilerImplementationIdentity } from "./library/implementation-identity.js";
39
+ import { publishEarlyExecutableCache, publishEarlyExecutableRoute, readEarlyExecutableCache } from "./executable/executable-cache.js";
40
+ import { compilerImplementationIdentity } from "./library/compiler-self-identity.js";
33
41
  export const VERSION = "0.0.1";
34
- export { compileC, runtimeSrcDir, warmNativeCaches, } from "./backend/cc.js";
35
- export { ANDROID_MIN_API, IPHONEOS_MIN_VERSION, isAndroidTarget, isIosTarget, isMobileTarget, mobileLibraryTarget, mobileTargetRefusal } from "./backend/cc.js";
36
- export { emitModule } from "./backend/emission/emitter.js";
37
- 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";
38
48
  export { renderCoverage } from "./coverage/report.js";
39
49
  export { generateSurfaceManifest, renderSurfaceManifest, MANIFEST_SCHEMA_VERSION, } from "./coverage/surface-manifest.js";
40
50
  export { NODE24_FETCH_COMPAT_PROFILE, } from "./compat/fetch-profile.js";
41
51
  export { LIB_FN_SIGS, validateModule } from "./ir/validate.js";
52
+ export { deserializeModule, IR_VERSION, serializeModule } from "./ir/serialize.js";
42
53
  export { resolveLibraryFences } from "./library/fence-eval.js";
43
- export { loadLibraryProfile, profileTeaching, profileRemediation, LIB_PARAM_CLASSES, LIB_RETURN_CLASSES, } from "./library/profile.js";
44
- 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";
45
56
  export { assembleTrapTeaching, TRAP_TEACHING_MARKER, TRAP_TEACHING_SEP, } from "./library/trap-teaching.js";
46
57
  export { abiExportSuffixes, buildSidecar, canonicalModuleGraph, canonicalPath, compilerReleaseVersion, libraryIdentityHashes, SIDECAR_FORMAT, } from "./library/sidecar.js";
47
58
  export { validateSidecar } from "./library/sidecar-validate.js";
@@ -51,7 +62,7 @@ export { ambientDtsPath, isExactExternalTypeSpecifier, overridesDtsPath } from "
51
62
  export { resolveProvenanceSources } from "./frontend/provenance.js";
52
63
  export { wasiGuestPath } from "./wasi-paths.js";
53
64
  export { setProvenanceSources, } from "./frontend/provenance-registry.js";
54
- export * as ir from "./ir/nodes.js";
65
+ export * as ir from "./ir/ir.js";
55
66
  /** The LLVM backend's tier refusal as a diagnostic. SC3xxx = backend
56
67
  * coverage (the program is fine — this backend doesn't compile it yet);
57
68
  * the parenthesized kind tag is machine-readable for the differential
@@ -200,6 +211,12 @@ export function buildTargetPlatform(env = process.env) {
200
211
  return process.platform;
201
212
  }
202
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
+ }
203
220
  /** --npm-static=auto (and library mode's mandatory twin): one throwaway
204
221
  * load finds every bare npm import the program's own modules make, then
205
222
  * the eligibility heuristics (npm-static.ts) pick the packages whose
@@ -297,8 +314,7 @@ function packagesNamedByDiag(message, optedIn) {
297
314
  const hits = new Set();
298
315
  for (const m of message.matchAll(/Module '"([^"]+)"'/g)) {
299
316
  const spec = m[1];
300
- const parts = spec.split("/");
301
- const prefix = spec.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
317
+ const prefix = packageNameOfSpecifier(spec);
302
318
  if (optedIn.has(prefix))
303
319
  hits.add(prefix);
304
320
  }
@@ -309,13 +325,6 @@ function packagesNamedByDiag(message, optedIn) {
309
325
  }
310
326
  return hits;
311
327
  }
312
- /** The package-wide --npm-static name containing an exact bare specifier.
313
- * External mappings are exact (subpaths included), while npm-static owns a
314
- * whole package, so any mapped subpath conflicts with that package opt-in. */
315
- function packageNameOfBareSpecifier(specifier) {
316
- const parts = specifier.split("/");
317
- return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
318
- }
319
328
  /** The one frontend, three npm postures: `undefined`/explicit package
320
329
  * lists and `"auto"` are the executable lane's (--npm-static; fallback =
321
330
  * island). `"lib"` is library mode's mandatory auto twin — the same
@@ -370,7 +379,7 @@ function runFrontend(entryPath, npmStatic, externalTypes) {
370
379
  if (requested.length > 0 && externalTypes !== undefined) {
371
380
  const externalSpecifiersByPackage = new Map();
372
381
  for (const specifier of Object.keys(externalTypes)) {
373
- const pkg = packageNameOfBareSpecifier(specifier);
382
+ const pkg = packageNameOfSpecifier(specifier);
374
383
  const specs = externalSpecifiersByPackage.get(pkg) ?? [];
375
384
  specs.push(specifier);
376
385
  externalSpecifiersByPackage.set(pkg, specs);
@@ -631,10 +640,35 @@ export function analyze(entryPath, opts = {}) {
631
640
  }
632
641
  }
633
642
  /** The whole pipeline: load → preflight → lower → validate → emit C → clang. */
643
+ function clearCompileSessionCaches() {
644
+ clearResolveCaches();
645
+ clearCcCaches();
646
+ clearSidecarCaches();
647
+ clearFenceEvalCaches();
648
+ }
634
649
  export async function compile(entryPath, opts) {
650
+ clearCompileSessionCaches();
635
651
  const frontendInputs = new FrontendInputTracker();
636
652
  return frontendInputs.run(() => compileTracked(entryPath, opts, frontendInputs));
637
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;
638
672
  function executableNativeFeatures(mod, backend, dynamic, optimization, llvmRefusal) {
639
673
  return {
640
674
  backend,
@@ -674,60 +708,158 @@ function executableNativeFeatures(mod, backend, dynamic, optimization, llvmRefus
674
708
  tlsCa: moduleUsesTlsCa(mod),
675
709
  };
676
710
  }
677
- async function compileExecutableNative(features, cPath, outPath, sanitize, ffi, programSplit = null, onArtifactReady) {
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
+ }
678
739
  const effectiveProgramSplit = programSplit ??
679
- (features.optimization === "dev" && features.backend === "llvm" && !sanitize
740
+ (!programIsObject && features.optimization === "dev" && features.backend === "llvm" && !sanitize
680
741
  ? splitLlvmProgram(await readFile(cPath, "utf8"))
681
742
  : null);
682
- await compileC({
683
- cPath,
684
- outPath,
685
- cacheIdentity: "scriptc-generated-v1",
686
- ...(features.optimization === "dev" ? { optimization: "dev" } : {}),
687
- ...(effectiveProgramSplit === null
688
- ? {}
689
- : {
690
- programShards: effectiveProgramSplit.shards,
691
- programPublicSymbols: effectiveProgramSplit.publicSymbols,
692
- }),
693
- sanitize,
694
- dynamic: features.dynamic,
695
- regex: features.regex,
696
- copying: features.copying,
697
- textDecoderLegacy: features.textDecoderLegacy,
698
- fileHandle: features.fileHandle,
699
- fetch: features.fetch,
700
- netIsland: features.netIsland,
701
- zlib: features.zlib,
702
- assert: features.assert,
703
- inspect: features.inspect,
704
- dynInvoke: features.dynInvoke,
705
- dc: features.dc,
706
- dynAsync: features.dynAsync,
707
- events: features.events,
708
- emitter: features.emitter,
709
- symbol: features.symbol,
710
- searchParams: features.searchParams,
711
- qs: features.qs,
712
- parseArgs: features.parseArgs,
713
- stream: features.stream,
714
- net: features.net,
715
- http: features.http,
716
- http2: features.http2,
717
- dgram: features.dgram,
718
- watch: features.watch,
719
- foreignFfi: features.foreignFfi,
720
- nodeTest: features.nodeTest,
721
- tls: features.tls,
722
- tlsCa: features.tlsCa,
723
- ...(onArtifactReady === undefined ? {} : { onArtifactReady }),
724
- ...(ffi === null
725
- ? {}
726
- : { linkInputs: ffi.libraries, systemLibraries: ffi.systemLibraries }),
727
- });
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);
728
844
  }
729
845
  async function compileTracked(entryPath, opts, frontendInputs) {
730
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
+ }
731
863
  let ffi = null;
732
864
  let ffiProfileBytes = null;
733
865
  if (opts.ffiProfilePath !== undefined) {
@@ -739,12 +871,48 @@ async function compileTracked(entryPath, opts, frontendInputs) {
739
871
  ffi = loaded.profile;
740
872
  ffiProfileBytes = loaded.profileBytes;
741
873
  }
742
- const buildPlatform = buildTargetPlatform();
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
+ }
910
+ }
743
911
  // Mobile triples are library-mode targets: the archive an embedding app
744
912
  // links is the artifact, and only the library-admissible runtime surface
745
913
  // is verified on those device classes. The executable lane refuses before
746
914
  // any frontend work — a pure env check, so the refusal needs no toolchain.
747
- {
915
+ if (outputKind === "exe") {
748
916
  const entryLoc = { file: entryPath, start: 0, end: 0 };
749
917
  const mobileTarget = mobileLibraryTarget();
750
918
  if (mobileTarget !== null) {
@@ -766,40 +934,68 @@ async function compileTracked(entryPath, opts, frontendInputs) {
766
934
  };
767
935
  }
768
936
  }
769
- const cacheRoot = provenanceSources() === null
937
+ const cacheRoot = outputKind === "exe" && provenanceSources() === null
770
938
  ? await prepareBuildCacheRoot(buildCacheRoot())
771
939
  : null;
772
- const implementation = await compilerImplementationIdentity();
773
- const earlyCacheOptions = {
774
- entryPath,
775
- outDir: opts.outDir,
776
- outPath: opts.outPath,
777
- emitIr: opts.emitIr ?? false,
778
- sanitize: opts.sanitize ?? false,
779
- dynamic: opts.dynamic ?? false,
780
- backend: opts.backend ?? "auto",
781
- ...(opts.optimization === "dev" ? { optimization: "dev" } : {}),
782
- npmStatic: opts.npmStatic ?? null,
783
- ffiProfile: opts.ffiProfilePath === undefined || ffiProfileBytes === null
784
- ? null
785
- : { path: opts.ffiProfilePath, bytes: ffiProfileBytes },
786
- target: `${process.env["SCRIPTC_TARGET"] ?? "native"}:${buildPlatform}:${process.arch}`,
787
- compiler: [process.env["SCRIPTC_CC"] ?? "clang"],
788
- nativeEnvironment: await executableNativeEnvironmentFingerprint(),
789
- nodeVersion: process.version,
790
- implementation: implementation.digest,
791
- implementationDependencies: implementation.dependencies,
792
- };
793
- const earlyHit = await readEarlyExecutableCache(cacheRoot, earlyCacheOptions);
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);
794
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
+ }
795
982
  // Route/proof metadata is independently evictable. A full-compiler
796
983
  // fallback that still finds the validated payload repairs that lightweight
797
984
  // index so the next identical CLI invocation can avoid this module graph.
798
- await publishEarlyExecutableRoute(cacheRoot, earlyCacheOptions).catch(() => undefined);
985
+ await publishEarlyExecutableRoute(cacheRoot, executableCacheOptions).catch(() => undefined);
799
986
  if (earlyHit.executableRestored) {
800
987
  await pruneBuildCache(cacheRoot);
801
988
  return {
802
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
+ },
803
999
  binaryPath: opts.outPath,
804
1000
  cPath: earlyHit.cPath,
805
1001
  backend: earlyHit.native.backend,
@@ -809,17 +1005,45 @@ async function compileTracked(entryPath, opts, frontendInputs) {
809
1005
  : { llvmRefusal: earlyHit.native.llvmRefusal }),
810
1006
  };
811
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
+ }
812
1030
  try {
813
- await compileExecutableNative(earlyHit.native, earlyHit.cPath, opts.outPath, opts.sanitize ?? false, ffi, null, async ({ dependencies }) => {
814
- await publishEarlyExecutableCache(cacheRoot, earlyCacheOptions, {
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, {
815
1033
  ...earlyHit,
816
1034
  executableRestored: true,
817
1035
  nativeDependencies: dependencies,
818
1036
  frontend: earlyHit.frontend,
819
1037
  });
820
1038
  });
1039
+ if (nativeProgramObject !== null && opts.nativeProgramObject === true) {
1040
+ await rename(nativeProgramObject.linkPath, nativeProgramObject.artifactPath);
1041
+ }
821
1042
  }
822
1043
  catch (err) {
1044
+ if (err instanceof RuntimePackError) {
1045
+ return { ok: false, diagnostics: [runtimePackDiagnostic(err, entryPath)], sourceTexts: new Map() };
1046
+ }
823
1047
  if (ffi !== null && err instanceof CcCompileError) {
824
1048
  return {
825
1049
  ok: false,
@@ -829,9 +1053,23 @@ async function compileTracked(entryPath, opts, frontendInputs) {
829
1053
  }
830
1054
  throw err;
831
1055
  }
1056
+ finally {
1057
+ if (nativeProgramObject !== null) {
1058
+ await rm(nativeProgramObject.linkPath, { force: true }).catch(() => undefined);
1059
+ }
1060
+ }
832
1061
  await pruneBuildCache(cacheRoot);
833
1062
  return {
834
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
+ },
835
1073
  binaryPath: opts.outPath,
836
1074
  cPath: earlyHit.cPath,
837
1075
  backend: earlyHit.native.backend,
@@ -890,7 +1128,7 @@ async function compileTracked(entryPath, opts, frontendInputs) {
890
1128
  if (unavailable !== null) {
891
1129
  return fail([targetRefusalDiag("wasm32-wasi", unavailable.surface, unavailable.loc)]);
892
1130
  }
893
- if (opts.backend === "c") {
1131
+ if (opts.backend === "c" || outputKind === "c") {
894
1132
  const asyncSurface = moduleLibAsyncSurface(lowered.module);
895
1133
  if (asyncSurface !== null) {
896
1134
  return fail([
@@ -905,14 +1143,114 @@ async function compileTracked(entryPath, opts, frontendInputs) {
905
1143
  finally {
906
1144
  fe.dispose();
907
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
+ }
908
1247
  await mkdir(opts.outDir, { recursive: true });
909
- const stem = basename(entryPath).replace(/\.(ts|js|mjs|cjs)$/, "");
910
1248
  // Both backends hang off the same in-memory IrModule (never the JSON
911
1249
  // dump); the LLVM backend's .ll takes the .c's seat on the exact clang
912
1250
  // command line below — compileC accepts either. The default lane tries
913
1251
  // LLVM first; a tier refusal retries ONLY the emit with the C backend
914
1252
  // (the frontend ran once, the IR is backend-agnostic — nothing recompiles).
915
- let cPath = join(opts.outDir, `${stem}.c`);
1253
+ let cPath = defaultSourcePaths.c;
916
1254
  let backend = "c";
917
1255
  let llvmSource = null;
918
1256
  let llvmRefusal;
@@ -921,8 +1259,10 @@ async function compileTracked(entryPath, opts, frontendInputs) {
921
1259
  const ll = emitLlvmModule(lowered.module, {
922
1260
  pointerBits: buildPlatform === "wasi" ? 32 : 64,
923
1261
  wasi: buildPlatform === "wasi",
1262
+ runtimeAbiMarker: opts.nativeProgramObject === true ||
1263
+ usesPrecompiledRuntimePack(opts, "llvm"),
924
1264
  });
925
- cPath = join(opts.outDir, `${stem}.ll`);
1265
+ cPath = defaultSourcePaths.llvm;
926
1266
  await writeFile(cPath, ll);
927
1267
  llvmSource = ll;
928
1268
  backend = "llvm";
@@ -939,28 +1279,55 @@ async function compileTracked(entryPath, opts, frontendInputs) {
939
1279
  }
940
1280
  }
941
1281
  if (backend === "c") {
942
- await writeFile(cPath, emitModule(lowered.module, entryText));
1282
+ await writeFile(cPath, emitCModule(lowered.module, entryText));
943
1283
  }
944
1284
  // Kept-TU honesty: outDir persists across builds (the CLI's .scriptc/),
945
1285
  // so a lane change would leave the PREVIOUS lane's TU beside the fresh
946
1286
  // one — remove the loser so the surviving TU is always the one the
947
1287
  // binary below was linked from.
948
- await rm(join(opts.outDir, `${stem}${backend === "llvm" ? ".c" : ".ll"}`), { force: true });
949
1288
  let irPath;
950
1289
  if (opts.emitIr) {
951
- irPath = join(opts.outDir, `${stem}.ir.json`);
1290
+ irPath = defaultSourcePaths.ir;
952
1291
  await writeFile(irPath, serializeModule(lowered.module));
953
1292
  }
1293
+ await removeStaleSourceArtifacts([
1294
+ cPath,
1295
+ ...(irPath === undefined ? [] : [irPath]),
1296
+ ]);
954
1297
  const nativeFeatures = executableNativeFeatures(lowered.module, backend, opts.dynamic ?? false, opts.optimization ?? "release", llvmRefusal);
955
1298
  const programSplit = backend === "llvm" && (opts.optimization ?? "release") === "dev" &&
956
1299
  !(opts.sanitize ?? false) && llvmSource !== null
957
1300
  ? splitLlvmProgram(llvmSource)
958
1301
  : null;
959
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;
960
1307
  let publishedExecutable = false;
1308
+ let nativeProgramObject = null;
961
1309
  try {
962
- await compileExecutableNative(nativeFeatures, cPath, opts.outPath, opts.sanitize ?? false, ffi, programSplit, async ({ dependencies }) => {
963
- await publishEarlyExecutableCache(cacheRoot, earlyCacheOptions, {
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, {
964
1331
  cPath,
965
1332
  native: nativeFeatures,
966
1333
  executableRestored: true,
@@ -970,8 +1337,14 @@ async function compileTracked(entryPath, opts, frontendInputs) {
970
1337
  });
971
1338
  publishedExecutable = true;
972
1339
  });
1340
+ if (nativeProgramObject !== null && opts.nativeProgramObject === true) {
1341
+ await rename(nativeProgramObject.linkPath, nativeProgramObject.artifactPath);
1342
+ }
973
1343
  }
974
1344
  catch (err) {
1345
+ if (err instanceof RuntimePackError) {
1346
+ return { ok: false, diagnostics: [runtimePackDiagnostic(err, entryPath)], sourceTexts };
1347
+ }
975
1348
  if (ffi !== null && err instanceof CcCompileError) {
976
1349
  return {
977
1350
  ok: false,
@@ -983,8 +1356,13 @@ async function compileTracked(entryPath, opts, frontendInputs) {
983
1356
  }
984
1357
  throw err;
985
1358
  }
1359
+ finally {
1360
+ if (nativeProgramObject !== null) {
1361
+ await rm(nativeProgramObject.linkPath, { force: true }).catch(() => undefined);
1362
+ }
1363
+ }
986
1364
  if (!publishedExecutable) {
987
- await publishEarlyExecutableCache(cacheRoot, earlyCacheOptions, {
1365
+ await publishEarlyExecutableCache(cacheRoot, executableCacheOptions, {
988
1366
  cPath,
989
1367
  native: nativeFeatures,
990
1368
  executableRestored: false,
@@ -995,6 +1373,13 @@ async function compileTracked(entryPath, opts, frontendInputs) {
995
1373
  await pruneBuildCache(cacheRoot);
996
1374
  return {
997
1375
  ok: true,
1376
+ artifact: {
1377
+ kind: "exe",
1378
+ path: opts.outPath,
1379
+ translationUnitPath: cPath,
1380
+ backend,
1381
+ ...(llvmRefusal !== undefined ? { llvmRefusal } : {}),
1382
+ },
998
1383
  binaryPath: opts.outPath,
999
1384
  cPath,
1000
1385
  backend,
@@ -1360,10 +1745,10 @@ async function compileLibraryNative(profile, cPath, archivePath, sanitize, featu
1360
1745
  }
1361
1746
  if (profile.sidecar !== null) {
1362
1747
  if (features.buildId === undefined)
1363
- throw new Error("library identity TU has no build id");
1748
+ throw new InternalCompilerError("library identity TU has no build id");
1364
1749
  const withoutIdentity = stripLibraryIdentity(programSource, profile.emission);
1365
1750
  if (withoutIdentity === programSource) {
1366
- throw new Error("generated public library TU has no identity region");
1751
+ throw new InternalCompilerError("generated public library TU has no identity region");
1367
1752
  }
1368
1753
  programSource = withoutIdentity;
1369
1754
  identityCSource = [
@@ -1413,7 +1798,7 @@ async function emitSemanticLibraryHit(hit, profile, opts, archivePath, cacheRoot
1413
1798
  let sidecarJson = hit.sidecarJson;
1414
1799
  if (profile.sidecar !== null) {
1415
1800
  if (mod.lib?.identity === undefined || sidecarJson === null) {
1416
- throw new Error("semantic library cache lost sidecar identity metadata");
1801
+ throw new InternalCompilerError("semantic library cache lost sidecar identity metadata");
1417
1802
  }
1418
1803
  const modules = canonicalModuleGraph(rootDir, hit.sourceTexts);
1419
1804
  const { buildId, sourceHash } = libraryIdentityHashes(compilerReleaseVersion(), profile.profileBytes, modules);
@@ -1430,7 +1815,7 @@ async function emitSemanticLibraryHit(hit, profile, opts, archivePath, cacheRoot
1430
1815
  };
1431
1816
  }
1432
1817
  await mkdir(opts.outDir, { recursive: true });
1433
- const stem = basename(profile.entry).replace(/\.(ts|js|mjs|cjs)$/, "");
1818
+ const stem = basename(profile.entry).replace(/\.(ts|mts|cts|js|mjs|cjs)$/, "");
1434
1819
  const cPath = join(opts.outDir, `${stem}.lib.${profile.emission === "llvm" ? "ll" : "c"}`);
1435
1820
  let translationUnit = hit.translationUnit;
1436
1821
  if (profile.sidecar !== null) {
@@ -1443,7 +1828,7 @@ async function emitSemanticLibraryHit(hit, profile, opts, archivePath, cacheRoot
1443
1828
  const previous = hit.previousSources.get(mod.sourceFile);
1444
1829
  const current = hit.sourceTexts.get(mod.sourceFile);
1445
1830
  if (previous === undefined || current === undefined) {
1446
- throw new Error("semantic library cache lost the entry source text");
1831
+ throw new InternalCompilerError("semantic library cache lost the entry source text");
1447
1832
  }
1448
1833
  translationUnit = rebaseLibrarySourceComments(translationUnit, mod.sourceFile, createSourceLineRebaser(mod.sourceFile, previous, current));
1449
1834
  await writeFile(cPath, translationUnit);
@@ -1485,6 +1870,7 @@ async function emitSemanticLibraryHit(hit, profile, opts, archivePath, cacheRoot
1485
1870
  };
1486
1871
  }
1487
1872
  export async function compileLibrary(opts) {
1873
+ clearCompileSessionCaches();
1488
1874
  const frontendInputs = new FrontendInputTracker();
1489
1875
  return frontendInputs.run(() => compileLibraryTracked(opts, frontendInputs));
1490
1876
  }
@@ -1527,7 +1913,7 @@ async function compileLibraryTracked(opts, frontendInputs) {
1527
1913
  if (directory === profileDir || dirname(directory) === directory)
1528
1914
  break;
1529
1915
  }
1530
- 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`);
1531
1917
  // Mobile-target admission first — a pure env/host check, so a refused
1532
1918
  // pairing never reaches toolchain discovery. iOS targets (device and
1533
1919
  // simulator) build on darwin hosts only: the Apple SDK sysroot and the
@@ -1547,7 +1933,7 @@ async function compileLibraryTracked(opts, frontendInputs) {
1547
1933
  // Multi-instance library mode (abi.localize_runtime) localizes per
1548
1934
  // OBJECT FORMAT: ELF and COFF archives localize from any host (cross
1549
1935
  // ELF merges through the cross driver's own lld; COFF merges and
1550
- // demotes in process — see cc.ts's localizeLibraryObjects), and Mach-O
1936
+ // demotes in process — see native-toolchain.ts's localizeLibraryObjects), and Mach-O
1551
1937
  // localization runs the macOS host linker, so macos and ios targets
1552
1938
  // admit darwin hosts only (the mobile admission above already refused
1553
1939
  // an ios triple off darwin). Everything else refuses before frontend/
@@ -1844,7 +2230,7 @@ async function compileLibraryTracked(opts, frontendInputs) {
1844
2230
  return fail(validation.map((v) => iceDiag(v.message, v.loc)));
1845
2231
  timing("ir-validate");
1846
2232
  await mkdir(opts.outDir, { recursive: true });
1847
- const stem = basename(entryPath).replace(/\.(ts|js|mjs|cjs)$/, "");
2233
+ const stem = basename(entryPath).replace(/\.(ts|mts|cts|js|mjs|cjs)$/, "");
1848
2234
  let cPath;
1849
2235
  if (profile.emission === "llvm") {
1850
2236
  try {
@@ -1863,7 +2249,7 @@ async function compileLibraryTracked(opts, frontendInputs) {
1863
2249
  }
1864
2250
  else {
1865
2251
  cPath = join(opts.outDir, `${stem}.lib.c`);
1866
- await writeFile(cPath, emitModule(mod, entryText));
2252
+ await writeFile(cPath, emitCModule(mod, entryText));
1867
2253
  }
1868
2254
  await rm(join(opts.outDir, `${stem}.lib.${profile.emission === "llvm" ? "c" : "ll"}`), { force: true });
1869
2255
  let irPath;