@scriptc/compiler 0.2.1 → 0.2.3

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 (315) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +158 -31
  2. package/dist/backend/cycle-analysis.js +63 -50
  3. package/dist/backend/cycle-analysis.js.map +1 -1
  4. package/dist/backend/cycle-analysis.test.js +51 -0
  5. package/dist/backend/cycle-analysis.test.js.map +1 -1
  6. package/dist/backend/llvm/borrowed-receivers.d.ts +9 -0
  7. package/dist/backend/llvm/borrowed-receivers.js +58 -0
  8. package/dist/backend/llvm/borrowed-receivers.js.map +1 -0
  9. package/dist/backend/llvm/call-lifetimes.d.ts +20 -0
  10. package/dist/backend/llvm/call-lifetimes.js +179 -0
  11. package/dist/backend/llvm/call-lifetimes.js.map +1 -0
  12. package/dist/backend/llvm/call-lifetimes.test.d.ts +1 -0
  13. package/dist/backend/llvm/call-lifetimes.test.js +205 -0
  14. package/dist/backend/llvm/call-lifetimes.test.js.map +1 -0
  15. package/dist/backend/llvm/dyn.d.ts +5 -2
  16. package/dist/backend/llvm/dyn.js +163 -47
  17. package/dist/backend/llvm/dyn.js.map +1 -1
  18. package/dist/backend/llvm/emitter.d.ts +37 -1
  19. package/dist/backend/llvm/emitter.js +209 -21
  20. package/dist/backend/llvm/emitter.js.map +1 -1
  21. package/dist/backend/llvm/emitter.test.js +29 -2
  22. package/dist/backend/llvm/emitter.test.js.map +1 -1
  23. package/dist/backend/llvm/expr-async.js +1 -1
  24. package/dist/backend/llvm/expr-async.js.map +1 -1
  25. package/dist/backend/llvm/expr-calls.js +42 -5
  26. package/dist/backend/llvm/expr-calls.js.map +1 -1
  27. package/dist/backend/llvm/expr-containers.js +75 -13
  28. package/dist/backend/llvm/expr-containers.js.map +1 -1
  29. package/dist/backend/llvm/expr-dynamic.js +31 -6
  30. package/dist/backend/llvm/expr-dynamic.js.map +1 -1
  31. package/dist/backend/llvm/expr-primitives.js +6 -5
  32. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  33. package/dist/backend/llvm/expr-records.js +1 -1
  34. package/dist/backend/llvm/expr-records.js.map +1 -1
  35. package/dist/backend/llvm/expr-stream-bridges.js +75 -19
  36. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  37. package/dist/backend/llvm/expr-stream-callbacks.d.ts +2 -2
  38. package/dist/backend/llvm/expr-stream-callbacks.js +7 -57
  39. package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
  40. package/dist/backend/llvm/lib-dispatch.js +41 -3
  41. package/dist/backend/llvm/lib-dispatch.js.map +1 -1
  42. package/dist/backend/llvm/lib-filesystem.js +12 -9
  43. package/dist/backend/llvm/lib-filesystem.js.map +1 -1
  44. package/dist/backend/llvm/lib-shared.js +70 -2
  45. package/dist/backend/llvm/lib-shared.js.map +1 -1
  46. package/dist/backend/llvm/local-array-reads.d.ts +44 -0
  47. package/dist/backend/llvm/local-array-reads.js +313 -0
  48. package/dist/backend/llvm/local-array-reads.js.map +1 -0
  49. package/dist/backend/llvm/local-array-reads.test.d.ts +1 -0
  50. package/dist/backend/llvm/local-array-reads.test.js +446 -0
  51. package/dist/backend/llvm/local-array-reads.test.js.map +1 -0
  52. package/dist/backend/llvm/map-read-lifetimes.d.ts +36 -0
  53. package/dist/backend/llvm/map-read-lifetimes.js +128 -0
  54. package/dist/backend/llvm/map-read-lifetimes.js.map +1 -0
  55. package/dist/backend/llvm/map-read-lifetimes.test.d.ts +1 -0
  56. package/dist/backend/llvm/map-read-lifetimes.test.js +123 -0
  57. package/dist/backend/llvm/map-read-lifetimes.test.js.map +1 -0
  58. package/dist/backend/llvm/shapes.js +1 -0
  59. package/dist/backend/llvm/shapes.js.map +1 -1
  60. package/dist/backend/llvm/split.js +15 -5
  61. package/dist/backend/llvm/split.js.map +1 -1
  62. package/dist/backend/llvm/split.test.js +17 -0
  63. package/dist/backend/llvm/split.test.js.map +1 -1
  64. package/dist/backend/llvm/stack-unions.d.ts +20 -0
  65. package/dist/backend/llvm/stack-unions.js +61 -0
  66. package/dist/backend/llvm/stack-unions.js.map +1 -0
  67. package/dist/backend/llvm/stack-unions.test.d.ts +1 -0
  68. package/dist/backend/llvm/stack-unions.test.js +241 -0
  69. package/dist/backend/llvm/stack-unions.test.js.map +1 -0
  70. package/dist/backend/llvm/string-lifetimes.d.ts +12 -0
  71. package/dist/backend/llvm/string-lifetimes.js +70 -0
  72. package/dist/backend/llvm/string-lifetimes.js.map +1 -0
  73. package/dist/backend/llvm/string-lifetimes.test.d.ts +1 -0
  74. package/dist/backend/llvm/string-lifetimes.test.js +230 -0
  75. package/dist/backend/llvm/string-lifetimes.test.js.map +1 -0
  76. package/dist/backend/mangle.d.ts +2 -0
  77. package/dist/backend/mangle.js +4 -0
  78. package/dist/backend/mangle.js.map +1 -1
  79. package/dist/backend/may-throw.js +71 -29
  80. package/dist/backend/may-throw.js.map +1 -1
  81. package/dist/backend/may-throw.test.js +104 -1
  82. package/dist/backend/may-throw.test.js.map +1 -1
  83. package/dist/backend/native-codegen.d.ts +1 -1
  84. package/dist/backend/native-codegen.js +4 -3
  85. package/dist/backend/native-codegen.js.map +1 -1
  86. package/dist/backend/native-codegen.test.js +11 -0
  87. package/dist/backend/native-codegen.test.js.map +1 -1
  88. package/dist/backend/native-toolchain.d.ts +2 -2
  89. package/dist/backend/native-toolchain.js +2 -0
  90. package/dist/backend/native-toolchain.js.map +1 -1
  91. package/dist/backend/target-diagnostics.d.ts +5 -0
  92. package/dist/backend/target-diagnostics.js +72 -1
  93. package/dist/backend/target-diagnostics.js.map +1 -1
  94. package/dist/backend/target-diagnostics.test.d.ts +1 -0
  95. package/dist/backend/target-diagnostics.test.js +68 -0
  96. package/dist/backend/target-diagnostics.test.js.map +1 -0
  97. package/dist/coverage/surface-manifest.js +5 -3
  98. package/dist/coverage/surface-manifest.js.map +1 -1
  99. package/dist/executable/executable-cache.d.ts +7 -3
  100. package/dist/executable/executable-cache.js +47 -11
  101. package/dist/executable/executable-cache.js.map +1 -1
  102. package/dist/executable/executable-cache.test.js +109 -2
  103. package/dist/executable/executable-cache.test.js.map +1 -1
  104. package/dist/executable/prepare.js +2 -1
  105. package/dist/executable/prepare.js.map +1 -1
  106. package/dist/frontend/builtin-modules.d.ts +1 -1
  107. package/dist/frontend/builtin-modules.js +1 -1
  108. package/dist/frontend/builtin-modules.js.map +1 -1
  109. package/dist/frontend/function-completion.d.ts +6 -0
  110. package/dist/frontend/function-completion.js +50 -0
  111. package/dist/frontend/function-completion.js.map +1 -0
  112. package/dist/frontend/input-tracker.js +3 -3
  113. package/dist/frontend/input-tracker.js.map +1 -1
  114. package/dist/frontend/input-tracker.test.js +38 -2
  115. package/dist/frontend/input-tracker.test.js.map +1 -1
  116. package/dist/frontend/lowering/abstract-equality.js +5 -1
  117. package/dist/frontend/lowering/abstract-equality.js.map +1 -1
  118. package/dist/frontend/lowering/checked-iterable-spread.d.ts +4 -0
  119. package/dist/frontend/lowering/checked-iterable-spread.js +30 -0
  120. package/dist/frontend/lowering/checked-iterable-spread.js.map +1 -0
  121. package/dist/frontend/lowering/checked-promise-all.d.ts +5 -0
  122. package/dist/frontend/lowering/checked-promise-all.js +31 -0
  123. package/dist/frontend/lowering/checked-promise-all.js.map +1 -0
  124. package/dist/frontend/lowering/class-callbacks.d.ts +1 -1
  125. package/dist/frontend/lowering/class-callbacks.js +7 -6
  126. package/dist/frontend/lowering/class-callbacks.js.map +1 -1
  127. package/dist/frontend/lowering/class-construction.d.ts +2 -0
  128. package/dist/frontend/lowering/class-construction.js +34 -5
  129. package/dist/frontend/lowering/class-construction.js.map +1 -1
  130. package/dist/frontend/lowering/class-descriptors.d.ts +1 -1
  131. package/dist/frontend/lowering/class-descriptors.js +12 -5
  132. package/dist/frontend/lowering/class-descriptors.js.map +1 -1
  133. package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +25 -0
  134. package/dist/frontend/lowering/class-dynamic-dispatch.js +597 -78
  135. package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
  136. package/dist/frontend/lowering/class-dynamic-dispatch.test.js +64 -2
  137. package/dist/frontend/lowering/class-dynamic-dispatch.test.js.map +1 -1
  138. package/dist/frontend/lowering/class-instance-constructor.d.ts +1 -1
  139. package/dist/frontend/lowering/class-instance-constructor.js +11 -41
  140. package/dist/frontend/lowering/class-instance-constructor.js.map +1 -1
  141. package/dist/frontend/lowering/class-method-values.d.ts +16 -0
  142. package/dist/frontend/lowering/class-method-values.js +60 -29
  143. package/dist/frontend/lowering/class-method-values.js.map +1 -1
  144. package/dist/frontend/lowering/class-prototypes.d.ts +5 -1
  145. package/dist/frontend/lowering/class-prototypes.js +69 -10
  146. package/dist/frontend/lowering/class-prototypes.js.map +1 -1
  147. package/dist/frontend/lowering/class-runtime-statics.d.ts +4 -4
  148. package/dist/frontend/lowering/class-runtime-statics.js +26 -8
  149. package/dist/frontend/lowering/class-runtime-statics.js.map +1 -1
  150. package/dist/frontend/lowering/class-static-data.d.ts +1 -0
  151. package/dist/frontend/lowering/class-static-data.js +4 -2
  152. package/dist/frontend/lowering/class-static-data.js.map +1 -1
  153. package/dist/frontend/lowering/collection-ingestion.d.ts +31 -0
  154. package/dist/frontend/lowering/collection-ingestion.js +215 -0
  155. package/dist/frontend/lowering/collection-ingestion.js.map +1 -0
  156. package/dist/frontend/lowering/containers/bytes.js +19 -4
  157. package/dist/frontend/lowering/containers/bytes.js.map +1 -1
  158. package/dist/frontend/lowering/containers/string-and-regexp.js +6 -1
  159. package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
  160. package/dist/frontend/lowering/deferred-module-initializers.d.ts +13 -0
  161. package/dist/frontend/lowering/deferred-module-initializers.js +410 -0
  162. package/dist/frontend/lowering/deferred-module-initializers.js.map +1 -0
  163. package/dist/frontend/lowering/deferred-module-initializers.test.d.ts +1 -0
  164. package/dist/frontend/lowering/deferred-module-initializers.test.js +92 -0
  165. package/dist/frontend/lowering/deferred-module-initializers.test.js.map +1 -0
  166. package/dist/frontend/lowering/expressions/object-literals.js +31 -1
  167. package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
  168. package/dist/frontend/lowering/expressions/optional-chains.js +3 -3
  169. package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
  170. package/dist/frontend/lowering/import-meta.d.ts +10 -0
  171. package/dist/frontend/lowering/import-meta.js +52 -0
  172. package/dist/frontend/lowering/import-meta.js.map +1 -0
  173. package/dist/frontend/lowering/lower-assert.js +105 -41
  174. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  175. package/dist/frontend/lowering/lower-builtin-values.d.ts +2 -0
  176. package/dist/frontend/lowering/lower-builtin-values.js +22 -1
  177. package/dist/frontend/lowering/lower-builtin-values.js.map +1 -1
  178. package/dist/frontend/lowering/lower-builtins.d.ts +7 -22
  179. package/dist/frontend/lowering/lower-builtins.js +439 -95
  180. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  181. package/dist/frontend/lowering/lower-calls.js +289 -76
  182. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  183. package/dist/frontend/lowering/lower-classes.d.ts +5 -0
  184. package/dist/frontend/lowering/lower-classes.js +443 -29
  185. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  186. package/dist/frontend/lowering/lower-containers.d.ts +6 -2
  187. package/dist/frontend/lowering/lower-containers.js +79 -20
  188. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  189. package/dist/frontend/lowering/lower-exprs.d.ts +10 -6
  190. package/dist/frontend/lowering/lower-exprs.js +329 -170
  191. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  192. package/dist/frontend/lowering/lower-generators.js +5 -1
  193. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  194. package/dist/frontend/lowering/lower-inspect.js +58 -1
  195. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  196. package/dist/frontend/lowering/lower-island.js +4 -0
  197. package/dist/frontend/lowering/lower-island.js.map +1 -1
  198. package/dist/frontend/lowering/lower-island.test.d.ts +1 -0
  199. package/dist/frontend/lowering/lower-island.test.js +51 -0
  200. package/dist/frontend/lowering/lower-island.test.js.map +1 -0
  201. package/dist/frontend/lowering/lower-modules.d.ts +1 -3
  202. package/dist/frontend/lowering/lower-modules.js +186 -82
  203. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  204. package/dist/frontend/lowering/lower-modules.test.js +69 -1
  205. package/dist/frontend/lowering/lower-modules.test.js.map +1 -1
  206. package/dist/frontend/lowering/lower-stmts.js +172 -103
  207. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  208. package/dist/frontend/lowering/lower-stmts.test.d.ts +1 -0
  209. package/dist/frontend/lowering/lower-stmts.test.js +77 -0
  210. package/dist/frontend/lowering/lower-stmts.test.js.map +1 -0
  211. package/dist/frontend/lowering/lower-stream.js +2 -0
  212. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  213. package/dist/frontend/lowering/lower-system-errors.d.ts +6 -0
  214. package/dist/frontend/lowering/lower-system-errors.js +29 -0
  215. package/dist/frontend/lowering/lower-system-errors.js.map +1 -0
  216. package/dist/frontend/lowering/lower-url.d.ts +2 -1
  217. package/dist/frontend/lowering/lower-url.js +32 -9
  218. package/dist/frontend/lowering/lower-url.js.map +1 -1
  219. package/dist/frontend/lowering/lowerer.d.ts +30 -12
  220. package/dist/frontend/lowering/lowerer.js +268 -49
  221. package/dist/frontend/lowering/lowerer.js.map +1 -1
  222. package/dist/frontend/lowering/lowerer.test.js +38 -0
  223. package/dist/frontend/lowering/lowerer.test.js.map +1 -1
  224. package/dist/frontend/lowering/module-namespace-elements.d.ts +7 -0
  225. package/dist/frontend/lowering/module-namespace-elements.js +54 -0
  226. package/dist/frontend/lowering/module-namespace-elements.js.map +1 -0
  227. package/dist/frontend/lowering/object-factory-new.d.ts +4 -3
  228. package/dist/frontend/lowering/object-factory-new.js +27 -14
  229. package/dist/frontend/lowering/object-factory-new.js.map +1 -1
  230. package/dist/frontend/lowering/surfaces.d.ts +3 -2
  231. package/dist/frontend/lowering/surfaces.js +93 -33
  232. package/dist/frontend/lowering/surfaces.js.map +1 -1
  233. package/dist/frontend/lowering/text-decoder-encoding.js +3 -0
  234. package/dist/frontend/lowering/text-decoder-encoding.js.map +1 -1
  235. package/dist/frontend/lowering/text-decoder-encoding.test.js +2 -1
  236. package/dist/frontend/lowering/text-decoder-encoding.test.js.map +1 -1
  237. package/dist/frontend/module-syntax.d.ts +1 -1
  238. package/dist/frontend/module-syntax.js +8 -1
  239. package/dist/frontend/module-syntax.js.map +1 -1
  240. package/dist/frontend/module-syntax.test.js +10 -0
  241. package/dist/frontend/module-syntax.test.js.map +1 -1
  242. package/dist/frontend/npm.d.ts +4 -0
  243. package/dist/frontend/npm.js +86 -33
  244. package/dist/frontend/npm.js.map +1 -1
  245. package/dist/frontend/npm.test.js +103 -0
  246. package/dist/frontend/npm.test.js.map +1 -1
  247. package/dist/frontend/pipeline-native.js +2 -1
  248. package/dist/frontend/pipeline-native.js.map +1 -1
  249. package/dist/frontend/program.js +4 -2
  250. package/dist/frontend/program.js.map +1 -1
  251. package/dist/frontend/services-node.js +3 -2
  252. package/dist/frontend/services-node.js.map +1 -1
  253. package/dist/frontend/services.d.ts +5 -1
  254. package/dist/frontend/services.js +9 -1
  255. package/dist/frontend/services.js.map +1 -1
  256. package/dist/frontend/services.test.js +21 -0
  257. package/dist/frontend/services.test.js.map +1 -1
  258. package/dist/frontend/ts7/ast-node.d.ts +2 -0
  259. package/dist/frontend/ts7/ast-node.js +30 -4
  260. package/dist/frontend/ts7/ast-node.js.map +1 -1
  261. package/dist/frontend/ts7/ast-node.test.js +60 -1
  262. package/dist/frontend/ts7/ast-node.test.js.map +1 -1
  263. package/dist/frontend/type-mapper.js +89 -14
  264. package/dist/frontend/type-mapper.js.map +1 -1
  265. package/dist/frontend/union-discriminants.js +22 -7
  266. package/dist/frontend/union-discriminants.js.map +1 -1
  267. package/dist/index.js +19 -12
  268. package/dist/index.js.map +1 -1
  269. package/dist/ir/analysis.js +1 -0
  270. package/dist/ir/analysis.js.map +1 -1
  271. package/dist/ir/integer-loops.d.ts +7 -0
  272. package/dist/ir/integer-loops.js +23 -0
  273. package/dist/ir/integer-loops.js.map +1 -1
  274. package/dist/ir/integer-loops.test.d.ts +1 -0
  275. package/dist/ir/integer-loops.test.js +41 -0
  276. package/dist/ir/integer-loops.test.js.map +1 -0
  277. package/dist/ir/ir.d.ts +44 -26
  278. package/dist/ir/ir.js +69 -11
  279. package/dist/ir/ir.js.map +1 -1
  280. package/dist/ir/ir.test.js +18 -0
  281. package/dist/ir/ir.test.js.map +1 -1
  282. package/dist/ir/serialize.js +21 -1
  283. package/dist/ir/serialize.js.map +1 -1
  284. package/dist/ir/serialize.test.js +21 -0
  285. package/dist/ir/serialize.test.js.map +1 -1
  286. package/dist/ir/traverse.d.ts +0 -3
  287. package/dist/ir/traverse.js +33 -20
  288. package/dist/ir/traverse.js.map +1 -1
  289. package/dist/ir/validate.js +216 -80
  290. package/dist/ir/validate.js.map +1 -1
  291. package/dist/ir/validate.test.js +244 -1
  292. package/dist/ir/validate.test.js.map +1 -1
  293. package/dist/library/compiler-self-identity.js +1 -1
  294. package/dist/library/compiler-self-identity.test.js +2 -2
  295. package/dist/library/compiler-self-identity.test.js.map +1 -1
  296. package/dist/library/fence-eval.js +9 -2
  297. package/dist/library/fence-eval.js.map +1 -1
  298. package/dist/library/fence-eval.test.d.ts +1 -0
  299. package/dist/library/fence-eval.test.js +21 -0
  300. package/dist/library/fence-eval.test.js.map +1 -0
  301. package/dist/library/int-infer.d.ts +2 -2
  302. package/dist/library/int-infer.js +10 -7
  303. package/dist/library/int-infer.js.map +1 -1
  304. package/dist/library/int-infer.test.js +44 -0
  305. package/dist/library/int-infer.test.js.map +1 -1
  306. package/dist/library/prepare.js +2 -1
  307. package/dist/library/prepare.js.map +1 -1
  308. package/dist/native/runtime-typescript.d.ts +4 -0
  309. package/dist/native/runtime-typescript.js +61 -0
  310. package/dist/native/runtime-typescript.js.map +1 -0
  311. package/dist/native/runtime-typescript.test.d.ts +1 -0
  312. package/dist/native/runtime-typescript.test.js +41 -0
  313. package/dist/native/runtime-typescript.test.js.map +1 -0
  314. package/package.json +20 -20
  315. package/surface-manifest.json +385 -29
@@ -1,3 +1,4 @@
1
+ import { everyStmtList, everyTypeChild } from "../../ir/traverse.js";
1
2
  import { InternalCompilerError } from "../../errors.js";
2
3
  /* Module-graph lowering: splitting each source file into its parts, the
3
4
  * program-collection pass (signatures, classes, globals — reachability
@@ -17,7 +18,7 @@ import { ENTRY_NAME, PoisonError, boundIdentifiersOf, dynFallbackType, dynUndefi
17
18
  import { isNativeFfiRequire, builtinMemberRequireDecl, builtinNamespaceDestructureModuleOf, createRequireBindingDecl, createRequireNamespaceDecl, createRequireProgramModuleDecl, createRequireSpecOf, isPromisifyCall, registerBuiltinCallableAlias, stripTypeCasts } from "./lower-builtins.js";
18
19
  import { bindingContextualGenericFnNodeOf, bindingGenericFnAliasInfoOf, bindingGenericFnInfoOf, bindingGenericFnNodeOf, bindingNeverReassigned, deadUnmappableBinding, funcTypeFromParamShapes, implicitLocalFnInfoOf, implicitLocalFnNodeOf, nullishGenericBindingUnitOf, registerOverloadedCallableAlias } from "./lower-calls.js";
19
20
  import { jsBindingHasOpenWrites, hasJsTypeAnnotation, isVarDeclared, numericIteratorSourceOf, provenanceElidedConstDecl } from "./lower-stmts.js";
20
- import { objectFactorySignature } from "./object-factory-new.js";
21
+ import { objectFactoryGlobalType } from "./object-factory-new.js";
21
22
  import { streamClassAliasDecl } from "./lower-stream.js";
22
23
  import { stdlibGlobalAliasDecl, stdlibGlobalAliasNameOf, stdlibGlobalNameOf } from "./surfaces.js";
23
24
  import { isNativeBuiltinValueInitializer } from "./lower-builtin-values.js";
@@ -25,7 +26,7 @@ import { collectNamespaceStmt, nsMemberIdentOf, nsPathPrefix, trapDeclRootOf } f
25
26
  import { collectExpandoMembers } from "./lower-expando.js";
26
27
  import { recordTextCodecClass } from "../../ir/ir.js";
27
28
  import { isUnitOnlyTsType, unitOnlyUnion } from "../type-mapper.js";
28
- import { collectVirtualJsMethods, decoratorNodesOf, genericIfaceBindingKeepsClass, guaranteedDecorationThrow, storedClassValueType } from "./lower-classes.js";
29
+ import { collectInheritedJsFieldWrites, collectVirtualJsMethods, decoratorNodesOf, genericIfaceBindingKeepsClass, guaranteedDecorationThrow, storedClassValueType } from "./lower-classes.js";
29
30
  import { isMixinFnBinding, mixinResultBindingClassOf } from "./lower-mixins.js";
30
31
  import { cjsModuleRef, cjsModuleRegistryPrelude } from "./lower-node-module.js";
31
32
  import { forkTargetPaths } from "../fork-target.js";
@@ -259,6 +260,7 @@ export function collectProgram(lowerer, parts) {
259
260
  lowerer.collecting = true;
260
261
  try {
261
262
  collectVirtualJsMethods(lowerer, parts.map((part) => part.sf));
263
+ collectInheritedJsFieldWrites(lowerer, parts.map((part) => part.sf));
262
264
  for (const fp of parts)
263
265
  for (const decl of fp.classDecls)
264
266
  if (!computed.has(decl))
@@ -723,15 +725,14 @@ export function collectJsonImports(lowerer, parts) {
723
725
  /** The classes, records, and unions the emitted module carries: exactly
724
726
  * what the lowered functions and globals reference, closed transitively
725
727
  * over record fields, union arms, class field types, base chains, and
726
- * WHOLE hierarchies (hierarchy membership decides object layout:
727
- * dropping an unused subclass must not turn its base into a standalone
728
- * class at emit time). Registry entries interned while collecting
728
+ * constructible descendants and their base chains. Registry entries interned while collecting
729
729
  * signatures nothing reaches stay out — an unreached type leaves no
730
730
  * trace. A referenced class with no registration had its collection
731
731
  * deferred: the reference flushes those diagnostics. Methods whose
732
732
  * bodies were not lowered leave the def's method list, so vtable slots
733
733
  * exist exactly for emitted overrides. */
734
734
  export function moduleArtifacts(lowerer, functions) {
735
+ const valueInstanceOfRoots = new Set();
735
736
  const classNames = new Set();
736
737
  const shapeIds = new Set();
737
738
  const unionIds = new Set();
@@ -759,56 +760,137 @@ export function moduleArtifacts(lowerer, functions) {
759
760
  default: return false;
760
761
  }
761
762
  };
762
- const visit = (node) => {
763
- if (Array.isArray(node)) {
764
- // This walk only reads compiler-owned arrays. A callback traversal
765
- // reuses one checked view instead of refreshing it at each step.
766
- node.forEach(visit);
763
+ const visitClass = (name) => {
764
+ if (classNames.has(name))
767
765
  return;
768
- }
769
- if (node === null || typeof node !== "object")
766
+ classNames.add(name);
767
+ pendingClasses.push(name);
768
+ };
769
+ const visitShape = (id) => {
770
+ if (shapeIds.has(id))
770
771
  return;
771
- const rec = node;
772
- if (rec["kind"] === "dynFrom" && boxedChild(rec["value"].type)) {
773
- // A generic child can expose native stdio without importing stream.
774
- visit([{ className: "%Readable" }, { className: "%Writable" }]);
775
- }
776
- if (typeof rec["className"] === "string" && !classNames.has(rec["className"])) {
777
- classNames.add(rec["className"]);
778
- pendingClasses.push(rec["className"]);
779
- }
780
- if (typeof rec["shapeId"] === "string" && !shapeIds.has(rec["shapeId"])) {
781
- shapeIds.add(rec["shapeId"]);
782
- pendingShapes.push(rec["shapeId"]);
783
- }
784
- if (typeof rec["unionId"] === "string" && !unionIds.has(rec["unionId"])) {
785
- unionIds.add(rec["unionId"]);
786
- pendingUnions.push(rec["unionId"]);
787
- }
788
- for (const key of Object.keys(rec)) {
789
- if (key !== "loc")
790
- visit(rec[key]);
772
+ shapeIds.add(id);
773
+ pendingShapes.push(id);
774
+ };
775
+ const visitUnion = (id) => {
776
+ if (unionIds.has(id))
777
+ return;
778
+ unionIds.add(id);
779
+ pendingUnions.push(id);
780
+ };
781
+ const visitType = (type) => {
782
+ switch (type.kind) {
783
+ case "object":
784
+ case "classval":
785
+ visitClass(type.className);
786
+ break;
787
+ case "record":
788
+ visitShape(type.shapeId);
789
+ break;
790
+ case "union":
791
+ visitUnion(type.unionId);
792
+ break;
791
793
  }
794
+ return everyTypeChild(type, visitType);
795
+ };
796
+ const visitor = {
797
+ expr: (node) => {
798
+ visitType(node.type);
799
+ switch (node.kind) {
800
+ case "fieldIncDec":
801
+ case "new":
802
+ case "classRef":
803
+ case "instanceOf":
804
+ case "virtualCall":
805
+ case "fieldGet":
806
+ case "caughtCheck":
807
+ visitClass(node.className);
808
+ break;
809
+ case "caughtTest":
810
+ if (node.className !== undefined)
811
+ visitClass(node.className);
812
+ break;
813
+ case "recordGet":
814
+ case "recordKeyGet":
815
+ case "recordOvfKeys":
816
+ case "recordOvfHas":
817
+ visitShape(node.shapeId);
818
+ break;
819
+ case "unionWrap":
820
+ case "unionFuncEq":
821
+ case "unionNarrow":
822
+ case "unionDisc":
823
+ case "unionKeyGet":
824
+ case "unionIsTag":
825
+ case "unionEq":
826
+ visitUnion(node.unionId);
827
+ break;
828
+ case "yieldExpr":
829
+ if (node.captureCompletion !== undefined)
830
+ visitType(node.captureCompletion.returnType);
831
+ break;
832
+ case "instanceOfValue":
833
+ for (const type of [node.value.type, node.classValue.type]) {
834
+ if (type.kind !== "object" && type.kind !== "classval")
835
+ continue;
836
+ let root = lowerer.classes.get(type.className);
837
+ if (!root)
838
+ continue;
839
+ while (root.base)
840
+ root = root.base;
841
+ valueInstanceOfRoots.add(root.def.name);
842
+ }
843
+ break;
844
+ case "dynFrom":
845
+ if (boxedChild(node.value.type)) {
846
+ // A generic child can expose native stdio without importing stream.
847
+ visitClass("%Readable");
848
+ visitClass("%Writable");
849
+ }
850
+ break;
851
+ default:
852
+ // A new node with a named artifact reference must join this switch.
853
+ node;
854
+ }
855
+ return true;
856
+ },
857
+ stmt: (node) => {
858
+ switch (node.kind) {
859
+ case "fieldSet":
860
+ visitClass(node.className);
861
+ break;
862
+ case "recordSet":
863
+ case "recordKeySet":
864
+ case "recordKeyDelete":
865
+ visitShape(node.shapeId);
866
+ break;
867
+ default:
868
+ node;
869
+ }
870
+ return true;
871
+ },
792
872
  };
793
- // Keep function lists and their typed slots in native storage. Reflective
794
- // array iteration refreshes a complete view at each step; only executable
795
- // nodes and individual types need the general dependency walk.
873
+ // Visit compiler-owned typed storage and executable trees directly, without
874
+ // creating dynamic snapshots of every node's properties and metadata.
796
875
  for (const fn of functions) {
797
876
  for (const param of fn.params)
798
- visit(param.type);
799
- visit(fn.returnType);
877
+ visitType(param.type);
878
+ visitType(fn.returnType);
800
879
  for (const local of fn.locals)
801
- visit(local.type);
880
+ visitType(local.type);
802
881
  for (const capture of fn.captures ?? [])
803
- visit(capture.type);
882
+ visitType(capture.type);
804
883
  for (const capture of fn.classCaptures ?? [])
805
- visit(capture.type);
806
- visit(fn.generator);
807
- for (const stmt of fn.body)
808
- visit(stmt);
884
+ visitType(capture.type);
885
+ if (fn.generator !== undefined) {
886
+ visitType(fn.generator.yieldT);
887
+ visitType(fn.generator.nextT);
888
+ visitType(fn.generator.resultType);
889
+ }
890
+ everyStmtList(fn.body, visitor);
809
891
  }
810
892
  for (const global of lowerer.globalsList)
811
- visit(global.type);
893
+ visitType(global.type);
812
894
  // The builtin error classes ride EVERY module: the runtime's own throws
813
895
  // (JSON/dynCheck/regex failures) mint instances of them whether or not
814
896
  // user code mentions Error, and the uncaught printer tells Error
@@ -829,12 +911,19 @@ export function moduleArtifacts(lowerer, functions) {
829
911
  // overflow-valued shape (`{ [key: string]: {script?: string} }`)
830
912
  // references its value shape through indexValue alone.
831
913
  const shape = lowerer.shapes.get(pendingShapes.pop());
832
- visit(shape?.fields);
833
- if (shape?.indexValue)
834
- visit(shape.indexValue);
914
+ if (shape !== undefined) {
915
+ for (const field of shape.fields)
916
+ visitType(field.type);
917
+ if (shape.indexValue !== undefined)
918
+ visitType(shape.indexValue);
919
+ }
920
+ }
921
+ while (pendingUnions.length > 0) {
922
+ const union = lowerer.unions.get(pendingUnions.pop());
923
+ if (union !== undefined)
924
+ for (const arm of union.arms)
925
+ visitType(arm);
835
926
  }
836
- while (pendingUnions.length > 0)
837
- visit(lowerer.unions.get(pendingUnions.pop())?.arms);
838
927
  while (pendingClasses.length > 0) {
839
928
  const name = pendingClasses.pop();
840
929
  const info = lowerer.classes.get(name);
@@ -844,15 +933,17 @@ export function moduleArtifacts(lowerer, functions) {
844
933
  lowerer.flushDeferredClass(name);
845
934
  continue;
846
935
  }
847
- visit(info.def.fields);
936
+ for (const field of info.def.fields)
937
+ visitType(field.type);
848
938
  if (info.base)
849
- visit([{ className: info.base.def.name }]);
939
+ visitClass(info.base.def.name);
850
940
  if (lowerer.inHierarchy(info)) {
851
941
  let root = info;
852
942
  while (root.base)
853
943
  root = root.base;
854
944
  const wholeTree = (c) => {
855
- visit([{ className: c.def.name }]);
945
+ if (valueInstanceOfRoots.has(root.def.name) || lowerer.classCanBeConstructed(c))
946
+ visitClass(c.def.name);
856
947
  for (const s of c.subclasses)
857
948
  wholeTree(s);
858
949
  };
@@ -1121,6 +1212,10 @@ export function collectGlobals(lowerer, sf, topStmts) {
1121
1212
  let type = lowerer.mapTypeOf(tsType) ?? dynFallbackType(lowerer, stmt.expression, tsType);
1122
1213
  if (type === null)
1123
1214
  lowerer.badType(stmt.expression, tsType);
1215
+ // Inferred JavaScript factory exports keep their original value,
1216
+ // including callable objects decorated with Object.assign.
1217
+ if (isJsSourceFile(sf) && ts.isCallExpression(stmt.expression) && type.kind === "record" && lowerer.dynConvertible(type))
1218
+ type = DYN;
1124
1219
  // `export default undefined` — the unit-only union, like any
1125
1220
  // unit-only binding (`export default null` maps via mapType).
1126
1221
  if (type.kind === "void" && isUnitOnlyTsType(tsType)) {
@@ -1169,16 +1264,9 @@ export function collectGlobals(lowerer, sf, topStmts) {
1169
1264
  const t = lowerer.mapTypeOf(strict) ?? dynFallbackType(lowerer, nameNode, strict);
1170
1265
  if (!t || t.kind === "void")
1171
1266
  lowerer.badType(typeNode, strict);
1172
- // `module.exports.Strings = Strings` naming a dyn-HOLDING
1173
- // const (the JS file-scope object-literal identity story): the
1174
- // export ALIASES the const's own dyn global — one storage, one
1175
- // owner, identity by construction (a record-typed second slot
1176
- // would either copy or mismatch the dyn value — that mismatch
1177
- // was an ICE; a second same-named global double-released at
1178
- // teardown). The statement's assign degenerates to a harmless
1179
- // self-assign. Mutable (`let`) sources keep the registration
1180
- // below: Node copies the VALUE at this statement, and separate
1181
- // storage is exactly that copy.
1267
+ // An immutable export source shares its live storage and native
1268
+ // callable ABI. Mutable sources need a separate snapshot slot:
1269
+ // later writes to the binding do not change the exported value.
1182
1270
  {
1183
1271
  let rhs = typeNode;
1184
1272
  while (ts.isParenthesizedExpression(rhs))
@@ -1186,19 +1274,14 @@ export function collectGlobals(lowerer, sf, topStmts) {
1186
1274
  if (ts.isIdentifier(rhs)) {
1187
1275
  const vSym = lowerer.checker.getSymbolAtLocation(rhs);
1188
1276
  const vG = vSym && lowerer.globalsBySymbol.get(vSym);
1189
- if (vG?.type.kind === "dyn") {
1277
+ if (vG) {
1190
1278
  if (!vG.mutable) {
1191
1279
  lowerer.globalsBySymbol.set(symbol, vG);
1192
1280
  for (const d of lowerer.checker.declarationsOf(symbol))
1193
1281
  lowerer.globalsByDeclNode.set(d, vG);
1194
1282
  return;
1195
1283
  }
1196
- // A mutable (`let`) dyn source: separate DYN storage IS
1197
- // Node's copy-of-the-reference at this statement (later
1198
- // reassignments of the let stay invisible through the
1199
- // export). The id must not collide with the let's own
1200
- // `%g.<tag><name>` global.
1201
- const g = { id: `%g.${tag}%export.${name}`, name, type: DYN, mutable: false };
1284
+ const g = { id: `%g.${tag}%export.${name}`, name, type: vG.type, mutable: false };
1202
1285
  lowerer.globalsBySymbol.set(symbol, g);
1203
1286
  for (const d of lowerer.checker.declarationsOf(symbol))
1204
1287
  lowerer.globalsByDeclNode.set(d, g);
@@ -1207,7 +1290,7 @@ export function collectGlobals(lowerer, sf, topStmts) {
1207
1290
  }
1208
1291
  }
1209
1292
  }
1210
- const g = { id: `%g.${tag}${name}`, name, type: t, mutable: false };
1293
+ const g = { id: `%g.${tag}%export.${name}`, name, type: t, mutable: false };
1211
1294
  lowerer.globalsBySymbol.set(symbol, g);
1212
1295
  // Importer aliases resolve to a DISTINCT late-bound symbol with
1213
1296
  // the same declaration — key the node too (globalOf's fallback).
@@ -1849,9 +1932,7 @@ export function collectGlobals(lowerer, sf, topStmts) {
1849
1932
  // their own per-site runtime fences.
1850
1933
  const factoryType = !isLet && isJsSourceFile(sf) && !decl.type && !hasJsTypeAnnotation(decl) &&
1851
1934
  ts.isIdentifier(decl.name) && nameNode === decl.name && decl.initializer && ts.isNewExpression(decl.initializer)
1852
- ? objectFactorySignature(lowerer, decl.initializer)?.returnType : undefined;
1853
- if (!factoryType && isJsSourceFile(sf) && !lowerer.mapTypeOf(lowerer.typeOf(nameNode)))
1854
- continue;
1935
+ ? objectFactoryGlobalType(lowerer, decl.initializer) ?? undefined : undefined;
1855
1936
  // `var p1 = import("./m")` at file scope: the global holds the
1856
1937
  // island promise/handle — the import expression's only
1857
1938
  // production — whatever the checker's namespace type mapped to
@@ -1865,20 +1946,39 @@ export function collectGlobals(lowerer, sf, topStmts) {
1865
1946
  // exactly the local rule (uncheckedOverloadHandleCall).
1866
1947
  (uncheckedOverloadHandleCall(lowerer, decl.initializer) ? JSVAL : null) : null)
1867
1948
  : null;
1868
- // Unannotated results of JavaScript calls can carry callable
1869
- // objects or heterogeneous unions absent from the native type
1870
- // map. Their compiled initializer still validates every crossing.
1871
- const callSignature = !decl.type && !hasJsTypeAnnotation(decl) && decl.initializer && ts.isCallExpression(decl.initializer)
1949
+ // JavaScript factory results with unmappable annotations still
1950
+ // need shared storage. Unannotated callable unions also use a
1951
+ // checked slot; mappable authored annotations keep their layout.
1952
+ const unannotatedCall = !decl.type && !hasJsTypeAnnotation(decl);
1953
+ const callSignature = (isJsSourceFile(sf) || unannotatedCall) && decl.initializer && ts.isCallExpression(decl.initializer)
1872
1954
  ? lowerer.checker.getResolvedSignature(decl.initializer) : undefined;
1873
1955
  const callDeclaration = callSignature && lowerer.checker.signatureDeclaration(callSignature);
1956
+ const callType = callDeclaration && isJsSourceFile(callDeclaration.getSourceFile())
1957
+ ? lowerer.mapTypeOf(lowerer.typeOf(nameNode)) : null;
1874
1958
  const inferredJsCall = callDeclaration && isJsSourceFile(callDeclaration.getSourceFile()) &&
1875
- !lowerer.mapTypeOf(lowerer.typeOf(nameNode));
1959
+ (!callType || unannotatedCall && callType.kind === "union" && lowerer.unions.get(callType.unionId)?.arms.some((arm) => arm.kind === "func"));
1960
+ if (!factoryType && !inferredJsCall && isJsSourceFile(sf) && !lowerer.mapTypeOf(lowerer.typeOf(nameNode)))
1961
+ continue;
1876
1962
  let type = handleT ?? factoryType ?? (inferredJsCall ? DYN : lowerer.irTypeOf(nameNode));
1877
1963
  if (isJsSourceFile(sf) && !decl.type && !hasJsTypeAnnotation(decl) && decl.initializer &&
1878
1964
  (ts.isArrowFunction(decl.initializer) || ts.isFunctionExpression(decl.initializer)) &&
1879
1965
  !decl.initializer.typeParameters?.length) {
1880
1966
  type = lowerer.lambdaSignature(decl.initializer).funcType;
1881
1967
  }
1968
+ // Namespace aliases of inferred helpers carry the helper's
1969
+ // settled callable, whose return can differ from checker inference.
1970
+ // Keep a shared checked slot before any consumer specializes it.
1971
+ if (isJsSourceFile(sf) && !decl.type && !hasJsTypeAnnotation(decl) && type.kind === "func" &&
1972
+ decl.initializer && ts.isPropertyAccessExpression(decl.initializer)) {
1973
+ const member = nsMemberIdentOf(lowerer, decl.initializer);
1974
+ if (member && lowerer.genericFnOf(member)?.implicitParams)
1975
+ type = DYN;
1976
+ else if (member) {
1977
+ const source = lowerer.globalOf(member);
1978
+ if (source?.type.kind === "func")
1979
+ type = source.type;
1980
+ }
1981
+ }
1882
1982
  if (isJsSourceFile(sf) && !decl.type && !hasJsTypeAnnotation(decl) &&
1883
1983
  decl.initializer && ts.isCallExpression(decl.initializer) && type.kind === "union") {
1884
1984
  const arms = lowerer.unions.get(type.unionId)?.arms;
@@ -1892,8 +1992,7 @@ export function collectGlobals(lowerer, sf, topStmts) {
1892
1992
  // Calls through checked function values retain their object
1893
1993
  // identity, including symbol keys absent from inferred records.
1894
1994
  if (isJsSourceFile(sf) && !decl.type && !hasJsTypeAnnotation(decl) && type.kind === "record" &&
1895
- decl.initializer && ts.isCallExpression(decl.initializer) &&
1896
- ts.isIdentifier(decl.initializer.expression) && lowerer.globalOf(decl.initializer.expression)?.type.kind === "dyn") {
1995
+ decl.initializer && ts.isCallExpression(decl.initializer) && lowerer.dynConvertible(type)) {
1897
1996
  type = DYN;
1898
1997
  }
1899
1998
  if (isJsSourceFile(sf) && !decl.type && !hasJsTypeAnnotation(decl) && type.kind === "record" &&
@@ -1916,6 +2015,10 @@ export function collectGlobals(lowerer, sf, topStmts) {
1916
2015
  if (isJsSourceFile(sf) && !decl.type && !hasJsTypeAnnotation(decl) && type.kind === "array" &&
1917
2016
  decl.initializer && ts.isCallExpression(decl.initializer))
1918
2017
  type = DYN;
2018
+ if (!lowerer.dynamic && isJsSourceFile(sf) && !decl.type && !hasJsTypeAnnotation(decl) &&
2019
+ decl.initializer && ts.isNewExpression(decl.initializer) && lowerer.isStdlibGlobal(decl.initializer.expression, "Array") &&
2020
+ (type.kind !== "array" || type.elem.kind === "dyn"))
2021
+ type = DYN;
1919
2022
  // Unannotated JavaScript aliases retain an existing native
1920
2023
  // checked object instead of copying it into an inferred record.
1921
2024
  if (isJsSourceFile(sf) && !decl.type && !hasJsTypeAnnotation(decl) &&
@@ -2417,7 +2520,7 @@ export function lowerFileInit(lowerer, sf, stmts, name) {
2417
2520
  // SITE's position instead (below) — their inner class node may
2418
2521
  // even live in another file.
2419
2522
  c.decl && ts.isClassDeclaration(c.decl) && !c.mixinInstance && c.decl.getSourceFile() === sf &&
2420
- (c.callableBase !== undefined || c.def.baseValueGlobal !== undefined || c.staticFields.length > 0 || (c.staticBlocks?.length ?? 0) > 0 || c.classDecorators !== undefined))
2523
+ (c.callableBase !== undefined || c.def.baseValueGlobal !== undefined || c.runtimeStatics !== undefined || c.staticFields.length > 0 || (c.staticBlocks?.length ?? 0) > 0 || c.classDecorators !== undefined))
2421
2524
  .map((c) => ({ pos: c.decl.getStart(), info: c }));
2422
2525
  // Statics-bearing MIXIN instantiations whose call evaluates in THIS
2423
2526
  // file: their declaration-time code runs when the call does — the
@@ -2443,7 +2546,8 @@ export function lowerFileInit(lowerer, sf, stmts, name) {
2443
2546
  body.push(...lowerer.lowerStaticFieldInits(statics[at].info));
2444
2547
  at++;
2445
2548
  }
2446
- const stmtIr = lowerer.lowerStmts([stmt]);
2549
+ const deferred = lowerer.deferredModuleInitializers?.defer(lowerer, stmt);
2550
+ const stmtIr = deferred ? [deferred] : lowerer.lowerStmts([stmt]);
2447
2551
  // Class EXPRESSIONS inside this statement queued their static
2448
2552
  // inits while it lowered: they land immediately before it — JS's
2449
2553
  // order for the supported whole-initializer positions.