@scriptc/compiler 0.1.1 → 0.1.2

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 (209) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +45 -17
  2. package/ambient/scriptc.d.ts +2 -1
  3. package/dist/backend/build-cache.js.map +1 -1
  4. package/dist/backend/c/async.js +24 -2
  5. package/dist/backend/c/async.js.map +1 -1
  6. package/dist/backend/c/c-emitter.d.ts +22 -10
  7. package/dist/backend/c/c-emitter.js +60 -15
  8. package/dist/backend/c/c-emitter.js.map +1 -1
  9. package/dist/backend/c/exprs.js +220 -10
  10. package/dist/backend/c/exprs.js.map +1 -1
  11. package/dist/backend/c/island.js.map +1 -1
  12. package/dist/backend/c/may-throw.js.map +1 -1
  13. package/dist/backend/c/stmts.d.ts +3 -5
  14. package/dist/backend/c/stmts.js +58 -17
  15. package/dist/backend/c/stmts.js.map +1 -1
  16. package/dist/backend/c/types.js.map +1 -1
  17. package/dist/backend/c/walkers.js +31 -5
  18. package/dist/backend/c/walkers.js.map +1 -1
  19. package/dist/backend/external-c.js.map +1 -1
  20. package/dist/backend/linker.js.map +1 -1
  21. package/dist/backend/llvm/blocks.js.map +1 -1
  22. package/dist/backend/llvm/dyn.js +56 -3
  23. package/dist/backend/llvm/dyn.js.map +1 -1
  24. package/dist/backend/llvm/emitter.js +98 -19
  25. package/dist/backend/llvm/emitter.js.map +1 -1
  26. package/dist/backend/llvm/expr-async.js +85 -3
  27. package/dist/backend/llvm/expr-async.js.map +1 -1
  28. package/dist/backend/llvm/expr-bytes.js.map +1 -1
  29. package/dist/backend/llvm/expr-calls.js.map +1 -1
  30. package/dist/backend/llvm/expr-containers.js.map +1 -1
  31. package/dist/backend/llvm/expr-context.d.ts +1 -0
  32. package/dist/backend/llvm/expr-control.js.map +1 -1
  33. package/dist/backend/llvm/expr-dispatch.js.map +1 -1
  34. package/dist/backend/llvm/expr-dynamic.js +6 -3
  35. package/dist/backend/llvm/expr-dynamic.js.map +1 -1
  36. package/dist/backend/llvm/expr-island.js.map +1 -1
  37. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  38. package/dist/backend/llvm/expr-records.js.map +1 -1
  39. package/dist/backend/llvm/expr-stream-bridges.js +220 -9
  40. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  41. package/dist/backend/llvm/lib-dispatch.js +2 -0
  42. package/dist/backend/llvm/lib-dispatch.js.map +1 -1
  43. package/dist/backend/llvm/lib-shared.js +18 -0
  44. package/dist/backend/llvm/lib-shared.js.map +1 -1
  45. package/dist/backend/llvm/lib-stream.js +6 -3
  46. package/dist/backend/llvm/lib-stream.js.map +1 -1
  47. package/dist/backend/llvm/split.js.map +1 -1
  48. package/dist/backend/llvm/unsupported.js.map +1 -1
  49. package/dist/backend/llvm/walkers.js.map +1 -1
  50. package/dist/backend/native-codegen.js.map +1 -1
  51. package/dist/backend/native-codegen.test.js +2 -0
  52. package/dist/backend/native-codegen.test.js.map +1 -1
  53. package/dist/backend/native-toolchain.js.map +1 -1
  54. package/dist/backend/native-toolchain.test.js.map +1 -1
  55. package/dist/backend/runtime-pack.js.map +1 -1
  56. package/dist/backend/targets.js.map +1 -1
  57. package/dist/backend/vendor-archives.js.map +1 -1
  58. package/dist/compat/fetch-profile.js +4 -2
  59. package/dist/compat/fetch-profile.js.map +1 -1
  60. package/dist/coverage/report.js.map +1 -1
  61. package/dist/coverage/surface-manifest.js +12 -0
  62. package/dist/coverage/surface-manifest.js.map +1 -1
  63. package/dist/diagnostics/diagnostic.d.ts +6 -5
  64. package/dist/diagnostics/diagnostic.js +7 -6
  65. package/dist/diagnostics/diagnostic.js.map +1 -1
  66. package/dist/diagnostics/render.js.map +1 -1
  67. package/dist/ffi/ffi-manifest.js.map +1 -1
  68. package/dist/frontend/cjs-lexer.js.map +1 -1
  69. package/dist/frontend/dts-paths.js.map +1 -1
  70. package/dist/frontend/input-tracker.d.ts +10 -0
  71. package/dist/frontend/input-tracker.js +26 -3
  72. package/dist/frontend/input-tracker.js.map +1 -1
  73. package/dist/frontend/input-tracker.test.js +8 -1
  74. package/dist/frontend/input-tracker.test.js.map +1 -1
  75. package/dist/frontend/lib-contract.js.map +1 -1
  76. package/dist/frontend/lowering/array-values.d.ts +4 -0
  77. package/dist/frontend/lowering/array-values.js +18 -2
  78. package/dist/frontend/lowering/array-values.js.map +1 -1
  79. package/dist/frontend/lowering/callback-arg.js.map +1 -1
  80. package/dist/frontend/lowering/containers/bytes.d.ts +35 -0
  81. package/dist/frontend/lowering/containers/bytes.js +1021 -0
  82. package/dist/frontend/lowering/containers/bytes.js.map +1 -0
  83. package/dist/frontend/lowering/containers/string-and-regexp.d.ts +17 -0
  84. package/dist/frontend/lowering/containers/string-and-regexp.js +345 -0
  85. package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -0
  86. package/dist/frontend/lowering/expressions/evaluation-safety.d.ts +13 -0
  87. package/dist/frontend/lowering/expressions/evaluation-safety.js +76 -0
  88. package/dist/frontend/lowering/expressions/evaluation-safety.js.map +1 -0
  89. package/dist/frontend/lowering/expressions/object-literals.d.ts +44 -0
  90. package/dist/frontend/lowering/expressions/object-literals.js +1815 -0
  91. package/dist/frontend/lowering/expressions/object-literals.js.map +1 -0
  92. package/dist/frontend/lowering/expressions/optional-chains.d.ts +31 -0
  93. package/dist/frontend/lowering/expressions/optional-chains.js +382 -0
  94. package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -0
  95. package/dist/frontend/lowering/expressions/try-lower-expression.d.ts +7 -0
  96. package/dist/frontend/lowering/expressions/try-lower-expression.js +26 -0
  97. package/dist/frontend/lowering/expressions/try-lower-expression.js.map +1 -0
  98. package/dist/frontend/lowering/lib-boundary.js +7 -2
  99. package/dist/frontend/lowering/lib-boundary.js.map +1 -1
  100. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  101. package/dist/frontend/lowering/lower-async-iteration.d.ts +7 -0
  102. package/dist/frontend/lowering/lower-async-iteration.js +657 -0
  103. package/dist/frontend/lowering/lower-async-iteration.js.map +1 -0
  104. package/dist/frontend/lowering/lower-builtins.d.ts +18 -0
  105. package/dist/frontend/lowering/lower-builtins.js +219 -48
  106. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  107. package/dist/frontend/lowering/lower-calls.d.ts +13 -4
  108. package/dist/frontend/lowering/lower-calls.js +407 -64
  109. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  110. package/dist/frontend/lowering/lower-classes.d.ts +7 -13
  111. package/dist/frontend/lowering/lower-classes.js +128 -35
  112. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  113. package/dist/frontend/lowering/lower-comptime.js.map +1 -1
  114. package/dist/frontend/lowering/lower-containers.d.ts +1 -47
  115. package/dist/frontend/lowering/lower-containers.js +135 -1467
  116. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  117. package/dist/frontend/lowering/lower-event-emitter.js +51 -5
  118. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
  119. package/dist/frontend/lowering/lower-exprs.d.ts +0 -78
  120. package/dist/frontend/lowering/lower-exprs.js +402 -2351
  121. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  122. package/dist/frontend/lowering/lower-generators.d.ts +18 -3
  123. package/dist/frontend/lowering/lower-generators.js +145 -9
  124. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  125. package/dist/frontend/lowering/lower-inspect.js +3 -3
  126. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  127. package/dist/frontend/lowering/lower-island.d.ts +6 -0
  128. package/dist/frontend/lowering/lower-island.js +37 -5
  129. package/dist/frontend/lowering/lower-island.js.map +1 -1
  130. package/dist/frontend/lowering/lower-modules.js +52 -15
  131. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  132. package/dist/frontend/lowering/lower-node-module.d.ts +18 -0
  133. package/dist/frontend/lowering/lower-node-module.js +302 -0
  134. package/dist/frontend/lowering/lower-node-module.js.map +1 -0
  135. package/dist/frontend/lowering/lower-server.js +1 -1
  136. package/dist/frontend/lowering/lower-server.js.map +1 -1
  137. package/dist/frontend/lowering/lower-stmts.d.ts +5 -24
  138. package/dist/frontend/lowering/lower-stmts.js +519 -253
  139. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  140. package/dist/frontend/lowering/lower-stream.js +4 -4
  141. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  142. package/dist/frontend/lowering/lowerer.d.ts +37 -34
  143. package/dist/frontend/lowering/lowerer.js +143 -57
  144. package/dist/frontend/lowering/lowerer.js.map +1 -1
  145. package/dist/frontend/lowering/optional-arguments.d.ts +9 -0
  146. package/dist/frontend/lowering/optional-arguments.js +57 -0
  147. package/dist/frontend/lowering/optional-arguments.js.map +1 -0
  148. package/dist/frontend/npm-static-declarations.d.ts +35 -0
  149. package/dist/frontend/npm-static-declarations.js +506 -0
  150. package/dist/frontend/npm-static-declarations.js.map +1 -0
  151. package/dist/frontend/npm-static-declarations.test.d.ts +1 -0
  152. package/dist/frontend/npm-static-declarations.test.js +122 -0
  153. package/dist/frontend/npm-static-declarations.test.js.map +1 -0
  154. package/dist/frontend/npm-static.d.ts +2 -0
  155. package/dist/frontend/npm-static.js +26 -10
  156. package/dist/frontend/npm-static.js.map +1 -1
  157. package/dist/frontend/npm.d.ts +60 -0
  158. package/dist/frontend/npm.js +38 -4
  159. package/dist/frontend/npm.js.map +1 -1
  160. package/dist/frontend/npm.test.d.ts +1 -0
  161. package/dist/frontend/npm.test.js +50 -0
  162. package/dist/frontend/npm.test.js.map +1 -0
  163. package/dist/frontend/program.d.ts +3 -2
  164. package/dist/frontend/program.js +495 -68
  165. package/dist/frontend/program.js.map +1 -1
  166. package/dist/frontend/resolve.d.ts +10 -2
  167. package/dist/frontend/resolve.js +90 -14
  168. package/dist/frontend/resolve.js.map +1 -1
  169. package/dist/frontend/resolve.test.js +4 -1
  170. package/dist/frontend/resolve.test.js.map +1 -1
  171. package/dist/frontend/runtime-resolve.d.ts +22 -0
  172. package/dist/frontend/runtime-resolve.js +101 -0
  173. package/dist/frontend/runtime-resolve.js.map +1 -0
  174. package/dist/frontend/runtime-resolve.test.d.ts +1 -0
  175. package/dist/frontend/runtime-resolve.test.js +18 -0
  176. package/dist/frontend/runtime-resolve.test.js.map +1 -0
  177. package/dist/frontend/ts7/adapter.js +12 -13
  178. package/dist/frontend/ts7/adapter.js.map +1 -1
  179. package/dist/frontend/ts7/ast.js.map +1 -1
  180. package/dist/frontend/ts7/census-check.js +3 -3
  181. package/dist/frontend/ts7/census-check.js.map +1 -1
  182. package/dist/frontend/ts7/checker.d.ts +3 -0
  183. package/dist/frontend/ts7/checker.js +12 -3
  184. package/dist/frontend/ts7/checker.js.map +1 -1
  185. package/dist/frontend/ts7/enums.js.map +1 -1
  186. package/dist/frontend/ts7/program-adapter.js +42 -3
  187. package/dist/frontend/ts7/program-adapter.js.map +1 -1
  188. package/dist/frontend/type-mapper.js +120 -7
  189. package/dist/frontend/type-mapper.js.map +1 -1
  190. package/dist/index.js +5 -5
  191. package/dist/index.js.map +1 -1
  192. package/dist/ir/analysis.js.map +1 -1
  193. package/dist/ir/ir.d.ts +60 -30
  194. package/dist/ir/ir.js +57 -6
  195. package/dist/ir/ir.js.map +1 -1
  196. package/dist/ir/validate.js +44 -59
  197. package/dist/ir/validate.js.map +1 -1
  198. package/dist/library/cache-primitives.js.map +1 -1
  199. package/dist/library/cache-reset.test.js.map +1 -1
  200. package/dist/library/compiler-self-identity.js.map +1 -1
  201. package/dist/library/int-infer.js.map +1 -1
  202. package/dist/library/int-infer.test.js.map +1 -1
  203. package/dist/library/library-profile.js.map +1 -1
  204. package/dist/library/sidecar-validate.js.map +1 -1
  205. package/dist/library/sidecar.js.map +1 -1
  206. package/dist/startup-cache.js.map +1 -1
  207. package/dist/wasi-paths.js.map +1 -1
  208. package/package.json +18 -18
  209. package/surface-manifest.json +60 -4
package/dist/ir/ir.d.ts CHANGED
@@ -359,6 +359,7 @@ export type IrType = {
359
359
  * array elements, and JSON. */
360
360
  | {
361
361
  kind: "generator";
362
+ async?: true;
362
363
  yieldT: IrType;
363
364
  retT: IrType;
364
365
  nextT: IrType;
@@ -389,11 +390,11 @@ interface IrKindSet<K extends IrType["kind"]> extends ReadonlySet<IrType["kind"]
389
390
  * every other handle has pointer representation. */
390
391
  declare const HANDLE_KIND_LIST: readonly ["stats", "fileHandle", "spawnRes", "child", "netServer", "netSocket", "http2Session", "http2Stream", "dgramSocket", "testCtx", "httpReq", "httpRes", "httpClientReq", "secureCtx", "fsWatcher", "childStream", "procStream"];
391
392
  export type HandleKind = typeof HANDLE_KIND_LIST[number];
392
- export declare const HANDLE_KINDS: IrKindSet<"fileHandle" | "stats" | "spawnRes" | "child" | "netServer" | "netSocket" | "http2Session" | "http2Stream" | "dgramSocket" | "testCtx" | "httpReq" | "httpRes" | "httpClientReq" | "childStream" | "procStream" | "fsWatcher" | "secureCtx">;
393
+ export declare const HANDLE_KINDS: IrKindSet<"child" | "childStream" | "dgramSocket" | "fileHandle" | "fsWatcher" | "http2Session" | "http2Stream" | "httpClientReq" | "httpReq" | "httpRes" | "netServer" | "netSocket" | "procStream" | "secureCtx" | "spawnRes" | "stats" | "testCtx">;
393
394
  /** The IR kinds represented as pointers in both native backends. */
394
395
  declare const POINTER_KIND_LIST: readonly ["string", "array", "map", "set", "regex", "bytes", "url", "searchParams", "symbol", "stats", "fileHandle", "spawnRes", "child", "netServer", "netSocket", "http2Session", "http2Stream", "dgramSocket", "testCtx", "httpReq", "httpRes", "httpClientReq", "secureCtx", "fsWatcher", "childStream", "func", "object", "classval", "record", "union", "dyn", "jsval", "caught", "promise", "generator"];
395
396
  export type PointerKind = typeof POINTER_KIND_LIST[number];
396
- export declare const POINTER_KINDS: IrKindSet<"string" | "symbol" | "object" | "map" | "bytes" | "regex" | "fileHandle" | "searchParams" | "array" | "set" | "url" | "stats" | "spawnRes" | "child" | "netServer" | "netSocket" | "http2Session" | "http2Stream" | "dgramSocket" | "testCtx" | "httpReq" | "httpRes" | "httpClientReq" | "childStream" | "fsWatcher" | "secureCtx" | "func" | "jsval" | "classval" | "record" | "union" | "dyn" | "caught" | "promise" | "generator">;
397
+ export declare const POINTER_KINDS: IrKindSet<"array" | "bytes" | "caught" | "child" | "childStream" | "classval" | "dgramSocket" | "dyn" | "fileHandle" | "fsWatcher" | "func" | "generator" | "http2Session" | "http2Stream" | "httpClientReq" | "httpReq" | "httpRes" | "jsval" | "map" | "netServer" | "netSocket" | "object" | "promise" | "record" | "regex" | "searchParams" | "secureCtx" | "set" | "spawnRes" | "stats" | "string" | "symbol" | "testCtx" | "union" | "url">;
397
398
  /** Runtime RC symbol stem for each IR type kind. An empty stem means the
398
399
  * kind is scalar/unit or uses an emitted per-shape helper (object/record).
399
400
  * Keeping this exhaustive makes a new runtime handle kind a compile error
@@ -945,7 +946,9 @@ export interface IrFunction {
945
946
  * Each is also listed in `locals` (with boxed: true); it is NOT a param. */
946
947
  captures?: IrParam[];
947
948
  /** Async: the body runs on a fiber; `returnType` is the INNER type T (a
948
- * `return v` fulfills with v) while call sites receive Promise<T>. */
949
+ * `return v` fulfills with v) while ordinary call sites receive
950
+ * Promise<T>. With `generator` present, call sites receive the lazy
951
+ * async-generator object instead. */
949
952
  async?: true;
950
953
  /** Async module initializers only: a module-global Promise<T> slot where
951
954
  * the spawn wrapper caches its first evaluation promise. Every later
@@ -958,17 +961,21 @@ export interface IrFunction {
958
961
  * becomes the runtime cycle root. Dynamic imports wait on this shared
959
962
  * completion verdict instead of a build-time-selected member. */
960
963
  asyncCycleCacheGlobal?: string;
961
- /** Generator (`function*`): the body runs on a fiber created SUSPENDED
964
+ /** Generator (`function*` / `async function*`): the body runs on a fiber created SUSPENDED
962
965
  * (nothing runs until the first `.next()`); `returnType` is the
963
966
  * generator's TReturn (VOID when it carries no value — `return;`
964
967
  * completes with the undefined arm) while call sites receive the
965
- * generator type `{ yieldT, retT: returnType, nextT }` from an emitted
968
+ * generator type `{ async?, yieldT, retT: returnType, nextT }` from an emitted
966
969
  * spawn wrapper that only allocates. `yieldT` is what `yield e` sends
967
970
  * out, `nextT` what `.next(v)` sends in (the yield expression's result
968
- * type). Mutually exclusive with `async` (async generators are fenced). */
971
+ * type). `async` alongside this field marks an async generator: its
972
+ * resume methods queue requests and return promises. */
969
973
  generator?: {
970
974
  yieldT: IrType;
971
975
  nextT: IrType;
976
+ resultType: IrType & {
977
+ kind: "record";
978
+ };
972
979
  };
973
980
  body: IrStmt[];
974
981
  loc: SrcLoc;
@@ -1283,23 +1290,19 @@ export type IrStmt =
1283
1290
  * completion AND on the exception path (after catch, or with the
1284
1291
  * exception still pending when there is no catch — it keeps propagating
1285
1292
  * after the finally completes; a throw inside the finally replaces it).
1286
- * A `return` inside tryBody/catchBody additionally runs the finally on
1287
- * its way out (the backend's PENDING-RETURN path: the value is computed
1288
- * and snapshotted FIRST, every crossed finally runs inner-to-outer, then
1289
- * the function returns — finally mutations of returned locals are
1290
- * invisible, Node-exact; a throw inside such a finally replaces the
1291
- * pending return, releasing the snapshot). The frontend still rejects
1292
- * break/continue crossing a try-with-finally and ANY jump out of a
1293
- * finally body, so normal, exception, and pending-return are the only
1294
- * completions a finally sees; plain try/catch has no such restriction
1295
- * (jumps out release the try scopes like any other jump). Each body is
1296
- * its own lexical scope. */
1293
+ * Every abrupt completion crossing the region runs the finally
1294
+ * inner-to-outer. Return values are snapshotted first; break/continue
1295
+ * retain their resolved targets; and a completion raised inside the
1296
+ * finally replaces the pending one. Each body is its own lexical scope. */
1297
1297
  | {
1298
1298
  kind: "tryCatch";
1299
1299
  tryBody: IrStmt[];
1300
1300
  catchBody: IrStmt[] | null;
1301
1301
  catchLocalId: string | null;
1302
1302
  finallyBody: IrStmt[] | null;
1303
+ /** Resource-management cleanup: if the guarded body and cleanup both
1304
+ * throw, raise a SuppressedError instead of replacing the first error. */
1305
+ suppressFinallyErrors?: true;
1303
1306
  loc: SrcLoc;
1304
1307
  };
1305
1308
  /** The complete array method/property surface (mirrors ambient/scriptc.d.ts).
@@ -1578,7 +1581,11 @@ export type IrLibFn =
1578
1581
  * (bytes decode per the literal encoding — utf8 default; strings,
1579
1582
  * numbers, booleans, arrays, objects answer JS-exactly; undefined and
1580
1583
  * null throw the catchable TypeError). */
1581
- | "dyn.toString" | "fs.readFileSync"
1584
+ | "dyn.toString"
1585
+ /** Engine-free CommonJS module graph. Module values are scalar f64
1586
+ * handles; generated startup defines the registry, init wrappers update
1587
+ * loading/cache state, and the read surface answers Node's live metadata. */
1588
+ | "module.registryInit" | "module.define" | "module.enter" | "module.link" | "module.finish" | "module.fail" | "module.filename" | "module.id" | "module.path" | "module.paths" | "module.children" | "module.parent" | "module.loaded" | "module.cacheGet" | "module.cacheHas" | "module.cacheKeys" | "fs.readFileSync"
1582
1589
  /** readFileSync(path) — the Buffer read (+1 bytes); throws catchably
1583
1590
  * like the utf8 form. */
1584
1591
  | "fs.readFileSyncBuf"
@@ -2855,7 +2862,11 @@ export type IrLibFn =
2855
2862
  * error. The Dyn twin boxes chunks by runtime tag (the JS lane).
2856
2863
  * readable.fromArr is Readable.from(array): a fully-seeded object-
2857
2864
  * entry stream (one whole chunk per element; strings per the flag). */
2858
- | "readable.nextChunk" | "readable.nextChunkDyn" | "readable.fromArr" | "readable.isPaused" | "readable.pipe" | "readable.unpipe" | "readable.flowing" | "writable.write" | "writable.writeStr" | "writable.writeU" | "writable.writeDyn" | "writable.end" | "writable.cork" | "writable.uncork" | "stream.destroy" | "stream.destroyErr" | "stream.prop" | "stream.errored"
2865
+ | "readable.nextChunk" | "readable.nextChunkDyn" | "readable.fromArr" | "readable.isPaused" | "readable.pipe" | "readable.unpipe" | "readable.flowing" | "writable.write" | "writable.writeStr" | "writable.writeU" | "writable.writeDyn" | "writable.end" | "writable.cork" | "writable.uncork" | "stream.destroy" | "stream.destroyErr"
2866
+ /** AsyncIteratorClose for Readable[Symbol.asyncIterator](): destroy with
2867
+ * Node's AbortError/ABORT_ERR payload while the iterator's internal error
2868
+ * consumer prevents an unhandled-error crash. */
2869
+ | "stream.iteratorClose" | "stream.prop" | "stream.errored"
2859
2870
  /** The underscore-method assignment surface (`r._read = fn` after
2860
2871
  * construction — Node's own-property shadow of the prototype method):
2861
2872
  * args [stream receiver (borrowed), callback closure (+1 moves)]. The
@@ -3859,6 +3870,7 @@ export type IrExpr =
3859
3870
  | {
3860
3871
  kind: "yieldExpr";
3861
3872
  value: IrExpr | null;
3873
+ awaited?: true;
3862
3874
  type: IrType;
3863
3875
  loc: SrcLoc;
3864
3876
  }
@@ -3877,8 +3889,9 @@ export type IrExpr =
3877
3889
  * unless suspended (then the GENRET unwind runs finallys; a finally
3878
3890
  * yield answers done:false and parks the return value) / throw on a
3879
3891
  * non-suspended generator marks it done and re-throws at the call site.
3880
- * MAY-THROW SEED: a body exception (or the injected throw) propagates
3881
- * into the caller synchronously. */
3892
+ * Sync generators return that record directly and propagate body errors
3893
+ * synchronously. Async generators return Promise<record>; requests queue,
3894
+ * and body errors reject the corresponding promise. */
3882
3895
  | {
3883
3896
  kind: "genResume";
3884
3897
  mode: "next" | "return" | "throw";
@@ -4158,12 +4171,13 @@ export type IrExpr =
4158
4171
  * TypeError), the interned signature key (dynCheck's exact-unwrap fast
4159
4172
  * path), and `fnName` — the best-effort static spelling for inspect
4160
4173
  * ([Function: name]) and Node-shaped call errors. The operand is
4161
- * borrowed; the result is owned (+1). Never throws. `liveRef` is the
4162
- * narrow Web-platform exception for record/array/bytes values (including
4163
- * mutable arms selected at runtime from a union) whose API contract
4164
- * exposes the same reference again (stream chunks and abort reasons): it
4165
- * emits a typed capsule with a live materializer instead of the ordinary
4166
- * deep copy. */
4174
+ * borrowed; the result is owned (+1). Never throws. Program class
4175
+ * instances always use a typed capsule so an exact checked cast recovers
4176
+ * the original identity. `liveRef` requests the same capsule form for
4177
+ * record/array/bytes values (including mutable arms selected at runtime
4178
+ * from a union) whose Web API contract exposes the reference again, such
4179
+ * as stream chunks and abort reasons; ordinary JSON-shaped values retain
4180
+ * the documented deep-copy boundary. */
4167
4181
  | {
4168
4182
  kind: "dynFrom";
4169
4183
  value: IrExpr;
@@ -4935,10 +4949,22 @@ export declare const DYN_HANDLE_KINDS: ReadonlyMap<string, {
4935
4949
  tag: string;
4936
4950
  cls: string;
4937
4951
  }>;
4952
+ /** A class value that crosses an `unknown` slot as a compiler-owned typed
4953
+ * reference. %Error keeps its dedicated error encoding; every other class
4954
+ * preserves the original object identity and exposes a materialized own-field
4955
+ * view only when a checked-dynamic operation actually needs one. */
4956
+ export declare function isDynTypedRefType(t: IrType): t is Extract<IrType, {
4957
+ kind: "object";
4958
+ }>;
4959
+ /** Whether a class layout field is an ECMAScript own enumerable property.
4960
+ * `#private` slots and `%`-prefixed compiler storage exist only in the native
4961
+ * layout; TypeScript `private`/`protected` fields keep ordinary names and are
4962
+ * observable properties at runtime. */
4963
+ export declare function isClassOwnEnumerableFieldName(name: string): boolean;
4938
4964
  /** A static type that CONVERTS into a dyn value — the dynFrom domain:
4939
- * JSON-safe data, bytes<u8> (payload copied), undefined-armed unions of
4940
- * JSON-safe arms, boxable function types, and the runtime HANDLE kinds
4941
- * (boxed by reference — DYN_HANDLE_KINDS). */
4965
+ * JSON-safe data, bytes<u8> (payload copied), identity-preserving class
4966
+ * references, undefined-armed unions of those arms, boxable function types,
4967
+ * and the runtime HANDLE kinds (boxed by reference — DYN_HANDLE_KINDS). */
4942
4968
  export declare function canConvertToDyn(t: IrType, getRecord: (shapeId: string) => IrRecordShape | undefined, getUnion: (unionId: string) => IrUnionDef | undefined): boolean;
4943
4969
  /** A type a dyn value can be VALIDATED into — the dynCheck domain:
4944
4970
  * JSON-safe data, bytes<u8> (a fresh copy out), the %Error extraction,
@@ -5080,6 +5106,10 @@ export declare function moduleUsesDynInvoke(mod: IrModule): boolean;
5080
5106
  * walk shape as moduleUsesZlib. */
5081
5107
  export declare function moduleUsesDynAsync(mod: IrModule): boolean;
5082
5108
  export declare function moduleUsesInspect(mod: IrModule): boolean;
5109
+ /** True when the module reaches child_process or carries one of its runtime
5110
+ * handle/result types. Besides the existing link consequence, this gates the
5111
+ * checked-dynamic ChildProcess handle table installed from scr_child.c. */
5112
+ export declare function moduleUsesChildProcess(mod: IrModule): boolean;
5083
5113
  /** True when the module contains any net libCall — the link switch that
5084
5114
  * pulls scr_net.c into the binary and has the emitted main call
5085
5115
  * scr_net_install (native-toolchain.ts + emitter; the scr_events gating precedent).
package/dist/ir/ir.js CHANGED
@@ -366,7 +366,7 @@ export function typeKey(t) {
366
366
  case "promise":
367
367
  return `promise<${typeKey(t.inner)}>`;
368
368
  case "generator":
369
- return `generator<${typeKey(t.yieldT)},${typeKey(t.retT)},${typeKey(t.nextT)}>`;
369
+ return `${t.async ? "async-generator" : "generator"}<${typeKey(t.yieldT)},${typeKey(t.retT)},${typeKey(t.nextT)}>`;
370
370
  default: {
371
371
  const _exhaustive = t;
372
372
  void _exhaustive;
@@ -406,6 +406,7 @@ export function typeEquals(a, b) {
406
406
  return b.kind === "promise" && typeEquals(a.inner, b.inner);
407
407
  if (a.kind === "generator") {
408
408
  return (b.kind === "generator" &&
409
+ (a.async === true) === (b.async === true) &&
409
410
  typeEquals(a.yieldT, b.yieldT) &&
410
411
  typeEquals(a.retT, b.retT) &&
411
412
  typeEquals(a.nextT, b.nextT));
@@ -916,6 +917,7 @@ export function canMarshalTypedFuncIntoIsland(t, getRecord, getUnion) {
916
917
  * entry carries the runtime tag spelling and the class display name
917
918
  * (dynCheck's "expected IncomingMessage ..." texts). */
918
919
  export const DYN_HANDLE_KINDS = new Map([
920
+ ["child", { tag: "SCR_DYNH_CHILD", cls: "ChildProcess" }],
919
921
  ["httpReq", { tag: "SCR_DYNH_HTTP_REQ", cls: "IncomingMessage" }],
920
922
  ["httpRes", { tag: "SCR_DYNH_HTTP_RES", cls: "ServerResponse" }],
921
923
  ["netSocket", { tag: "SCR_DYNH_NET_SOCKET", cls: "Socket" }],
@@ -924,10 +926,24 @@ export const DYN_HANDLE_KINDS = new Map([
924
926
  ["http2Stream", { tag: "SCR_DYNH_H2_STREAM", cls: "Http2Stream" }],
925
927
  ["httpClientReq", { tag: "SCR_DYNH_HTTP_CLIENT", cls: "ClientRequest" }],
926
928
  ]);
929
+ /** A class value that crosses an `unknown` slot as a compiler-owned typed
930
+ * reference. %Error keeps its dedicated error encoding; every other class
931
+ * preserves the original object identity and exposes a materialized own-field
932
+ * view only when a checked-dynamic operation actually needs one. */
933
+ export function isDynTypedRefType(t) {
934
+ return t.kind === "object" && !RUNTIME_ERROR_CLASSES.has(t.className);
935
+ }
936
+ /** Whether a class layout field is an ECMAScript own enumerable property.
937
+ * `#private` slots and `%`-prefixed compiler storage exist only in the native
938
+ * layout; TypeScript `private`/`protected` fields keep ordinary names and are
939
+ * observable properties at runtime. */
940
+ export function isClassOwnEnumerableFieldName(name) {
941
+ return !name.startsWith("#") && !name.startsWith("%");
942
+ }
927
943
  /** A static type that CONVERTS into a dyn value — the dynFrom domain:
928
- * JSON-safe data, bytes<u8> (payload copied), undefined-armed unions of
929
- * JSON-safe arms, boxable function types, and the runtime HANDLE kinds
930
- * (boxed by reference — DYN_HANDLE_KINDS). */
944
+ * JSON-safe data, bytes<u8> (payload copied), identity-preserving class
945
+ * references, undefined-armed unions of those arms, boxable function types,
946
+ * and the runtime HANDLE kinds (boxed by reference — DYN_HANDLE_KINDS). */
931
947
  export function canConvertToDyn(t, getRecord, getUnion) {
932
948
  if (isJsonSafeType(t, getRecord, getUnion))
933
949
  return true;
@@ -945,6 +961,8 @@ export function canConvertToDyn(t, getRecord, getUnion) {
945
961
  // listener boundary (a mustCall-wrapped handler receiving the payload).
946
962
  if (t.kind === "object" && t.className === "%Error")
947
963
  return true;
964
+ if (isDynTypedRefType(t))
965
+ return true;
948
966
  if (t.kind === "func")
949
967
  return canBoxFuncIntoDyn(t, getRecord, getUnion);
950
968
  if (DYN_HANDLE_KINDS.has(t.kind))
@@ -962,12 +980,14 @@ export function canConvertToDyn(t, getRecord, getUnion) {
962
980
  }
963
981
  if (t.kind === "union") {
964
982
  const def = getUnion(t.unionId);
965
- // JSON-safe arms box as before; BOXABLE FUNCTION arms join them (the
983
+ // JSON-safe arms box as before; BOXABLE FUNCTION and PROMISE arms join them (the
966
984
  // invalid-input probes iterate `[1, null, () => {}, true]` — the
967
985
  // union's func arm crosses through the checked-dynamic function
968
986
  // boundary exactly like a bare func dynFrom).
969
987
  return !!def && def.arms.every((a) => a.kind === "undefinedT" || isJsonSafeType(a, getRecord, getUnion) ||
970
- (a.kind === "func" && canBoxFuncIntoDyn(a, getRecord, getUnion)));
988
+ isDynTypedRefType(a) || DYN_HANDLE_KINDS.has(a.kind) ||
989
+ (a.kind === "func" && canBoxFuncIntoDyn(a, getRecord, getUnion)) ||
990
+ (a.kind === "promise" && canConvertToDyn(a, getRecord, getUnion)));
971
991
  }
972
992
  return false;
973
993
  }
@@ -1594,6 +1614,36 @@ export function moduleUsesInspect(mod) {
1594
1614
  visit(mod);
1595
1615
  return found;
1596
1616
  }
1617
+ /** True when the module reaches child_process or carries one of its runtime
1618
+ * handle/result types. Besides the existing link consequence, this gates the
1619
+ * checked-dynamic ChildProcess handle table installed from scr_child.c. */
1620
+ export function moduleUsesChildProcess(mod) {
1621
+ let found = false;
1622
+ const visit = (v) => {
1623
+ if (found || v === null || typeof v !== "object")
1624
+ return;
1625
+ if (Array.isArray(v)) {
1626
+ for (const item of v)
1627
+ visit(item);
1628
+ return;
1629
+ }
1630
+ const node = v;
1631
+ if (node.kind === "libCall" &&
1632
+ typeof node.fn === "string" &&
1633
+ (node.fn.startsWith("cp.") || node.fn.startsWith("child.") || node.fn.startsWith("spawnRes."))) {
1634
+ found = true;
1635
+ return;
1636
+ }
1637
+ if (node.kind === "child" || node.kind === "childStream" || node.kind === "spawnRes") {
1638
+ found = true;
1639
+ return;
1640
+ }
1641
+ for (const key of Object.keys(v))
1642
+ visit(v[key]);
1643
+ };
1644
+ visit(mod);
1645
+ return found;
1646
+ }
1597
1647
  /** True when the module contains any net libCall — the link switch that
1598
1648
  * pulls scr_net.c into the binary and has the emitted main call
1599
1649
  * scr_net_install (native-toolchain.ts + emitter; the scr_events gating precedent).
@@ -2377,6 +2427,7 @@ export const MAY_THROW_LIB_FNS = new Set([
2377
2427
  "writable.uncork",
2378
2428
  "stream.destroy",
2379
2429
  "stream.destroyErr",
2430
+ "stream.iteratorClose",
2380
2431
  // setMaxListeners(n) throws Node's ERR_OUT_OF_RANGE RangeError for
2381
2432
  // negative/NaN arguments; the static form's default-max write validates
2382
2433
  // identically (Node's validateNumber(n, "setMaxListeners", 0)).