@scriptc/compiler 0.0.32 → 0.0.34

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 (120) hide show
  1. package/dist/backend/cc-cache.test.js +430 -1
  2. package/dist/backend/cc-cache.test.js.map +1 -1
  3. package/dist/backend/cc.d.ts +25 -0
  4. package/dist/backend/cc.js +818 -88
  5. package/dist/backend/cc.js.map +1 -1
  6. package/dist/backend/emission/emit-exprs.js +79 -3
  7. package/dist/backend/emission/emit-exprs.js.map +1 -1
  8. package/dist/backend/emission/emit-shapes.js +37 -4
  9. package/dist/backend/emission/emit-shapes.js.map +1 -1
  10. package/dist/backend/emission/emitter.d.ts +23 -7
  11. package/dist/backend/emission/emitter.js +171 -27
  12. package/dist/backend/emission/emitter.js.map +1 -1
  13. package/dist/backend/emission/may-throw.js +7 -4
  14. package/dist/backend/emission/may-throw.js.map +1 -1
  15. package/dist/backend/ffi-callbacks.d.ts +38 -1
  16. package/dist/backend/ffi-callbacks.js +76 -3
  17. package/dist/backend/ffi-callbacks.js.map +1 -1
  18. package/dist/backend/library-identity.d.ts +22 -0
  19. package/dist/backend/library-identity.js +103 -0
  20. package/dist/backend/library-identity.js.map +1 -0
  21. package/dist/backend/llvm/emitter.d.ts +3 -0
  22. package/dist/backend/llvm/emitter.js +278 -17
  23. package/dist/backend/llvm/emitter.js.map +1 -1
  24. package/dist/backend/llvm/shapes.d.ts +1 -0
  25. package/dist/backend/llvm/shapes.js +25 -1
  26. package/dist/backend/llvm/shapes.js.map +1 -1
  27. package/dist/backend/mangle.d.ts +1 -0
  28. package/dist/backend/mangle.js +3 -0
  29. package/dist/backend/mangle.js.map +1 -1
  30. package/dist/backend/object-localize.d.ts +5 -5
  31. package/dist/backend/object-localize.js +19 -16
  32. package/dist/backend/object-localize.js.map +1 -1
  33. package/dist/backend/object-localize.test.js +37 -13
  34. package/dist/backend/object-localize.test.js.map +1 -1
  35. package/dist/diagnostics/diagnostic.js +2 -0
  36. package/dist/diagnostics/diagnostic.js.map +1 -1
  37. package/dist/ffi/profile.d.ts +17 -5
  38. package/dist/ffi/profile.js +169 -22
  39. package/dist/ffi/profile.js.map +1 -1
  40. package/dist/frontend/input-tracker.d.ts +82 -0
  41. package/dist/frontend/input-tracker.js +380 -0
  42. package/dist/frontend/input-tracker.js.map +1 -0
  43. package/dist/frontend/input-tracker.test.d.ts +1 -0
  44. package/dist/frontend/input-tracker.test.js +137 -0
  45. package/dist/frontend/input-tracker.test.js.map +1 -0
  46. package/dist/frontend/lowering/lower-builtins.js +2 -8
  47. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  48. package/dist/frontend/lowering/lower-calls.d.ts +1 -0
  49. package/dist/frontend/lowering/lower-calls.js +244 -163
  50. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  51. package/dist/frontend/lowering/lower-classes.js +3 -0
  52. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  53. package/dist/frontend/lowering/lower-containers.js +113 -28
  54. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  55. package/dist/frontend/lowering/lower-exprs.js +67 -1
  56. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  57. package/dist/frontend/lowering/lower-inspect.js +45 -26
  58. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  59. package/dist/frontend/lowering/lower-modules.js +1 -1
  60. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  61. package/dist/frontend/lowering/lower-stmts.js +48 -3
  62. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  63. package/dist/frontend/lowering/lowerer.d.ts +79 -29
  64. package/dist/frontend/lowering/lowerer.js +429 -87
  65. package/dist/frontend/lowering/lowerer.js.map +1 -1
  66. package/dist/frontend/npm-static-rewrite.js +25 -26
  67. package/dist/frontend/npm-static-rewrite.js.map +1 -1
  68. package/dist/frontend/npm-static.js +29 -30
  69. package/dist/frontend/npm-static.js.map +1 -1
  70. package/dist/frontend/npm-static.test.d.ts +1 -0
  71. package/dist/frontend/npm-static.test.js +15 -0
  72. package/dist/frontend/npm-static.test.js.map +1 -0
  73. package/dist/frontend/npm.js +5 -17
  74. package/dist/frontend/npm.js.map +1 -1
  75. package/dist/frontend/program.js +2 -6
  76. package/dist/frontend/program.js.map +1 -1
  77. package/dist/frontend/resolve.js +8 -29
  78. package/dist/frontend/resolve.js.map +1 -1
  79. package/dist/frontend/ts7/checker.d.ts +2 -0
  80. package/dist/frontend/ts7/checker.js +20 -3
  81. package/dist/frontend/ts7/checker.js.map +1 -1
  82. package/dist/frontend/ts7/program.js +17 -18
  83. package/dist/frontend/ts7/program.js.map +1 -1
  84. package/dist/frontend/types.d.ts +41 -0
  85. package/dist/frontend/types.js +147 -8
  86. package/dist/frontend/types.js.map +1 -1
  87. package/dist/index.d.ts +1 -1
  88. package/dist/index.js +275 -41
  89. package/dist/index.js.map +1 -1
  90. package/dist/ir/nodes.d.ts +42 -12
  91. package/dist/ir/nodes.js +7 -1
  92. package/dist/ir/nodes.js.map +1 -1
  93. package/dist/ir/serialize.d.ts +1 -1
  94. package/dist/ir/serialize.js +1 -1
  95. package/dist/ir/validate.js +104 -1
  96. package/dist/ir/validate.js.map +1 -1
  97. package/dist/library/early-cache.d.ts +65 -0
  98. package/dist/library/early-cache.js +380 -0
  99. package/dist/library/early-cache.js.map +1 -0
  100. package/dist/library/early-cache.test.d.ts +1 -0
  101. package/dist/library/early-cache.test.js +528 -0
  102. package/dist/library/early-cache.test.js.map +1 -0
  103. package/dist/library/int-infer.js +14 -0
  104. package/dist/library/int-infer.js.map +1 -1
  105. package/dist/library/int-infer.test.js +21 -4
  106. package/dist/library/int-infer.test.js.map +1 -1
  107. package/dist/library/profile.d.ts +3 -0
  108. package/dist/library/profile.js +9 -1
  109. package/dist/library/profile.js.map +1 -1
  110. package/dist/library/semantic-source.d.ts +13 -0
  111. package/dist/library/semantic-source.js +257 -0
  112. package/dist/library/semantic-source.js.map +1 -0
  113. package/dist/library/semantic-source.test.d.ts +1 -0
  114. package/dist/library/semantic-source.test.js +113 -0
  115. package/dist/library/semantic-source.test.js.map +1 -0
  116. package/dist/library/sidecar.d.ts +6 -0
  117. package/dist/library/sidecar.js +11 -0
  118. package/dist/library/sidecar.js.map +1 -1
  119. package/package.json +2 -2
  120. package/surface-manifest.json +1 -1
@@ -232,13 +232,13 @@ export interface LowerOptions {
232
232
  }
233
233
  /** The Lowerer's pass configuration (see lowerToIr). */
234
234
  export interface LowererMode {
235
- /** Names of bodies the discovery pass reached; null lowers everything. */
235
+ /** Names of bodies a prior reachability pass reached; null lowers everything. */
236
236
  reachable?: ReadonlySet<string> | null;
237
237
  /** Coverage remainder: lower ONLY bodies outside `reachable`, skip the
238
238
  * always-reachable init bodies and module building, and report deferred
239
239
  * collection diagnostics nothing flushed. */
240
240
  remainder?: boolean;
241
- /** Symbols whose deferred diagnostics the emit pass already flushed —
241
+ /** Symbols whose deferred diagnostics reachable emit already flushed —
242
242
  * the remainder must not report them a second time. */
243
243
  alreadyFlushed?: ReadonlySet<ts.Symbol>;
244
244
  /** The build's target platform (LowerOptions.targetPlatform — lowerToIr
@@ -261,24 +261,22 @@ export interface LowererMode {
261
261
  /** LowerOptions.externalTypeSpecifiersByFile, shared by every pass. */
262
262
  externalTypeSpecifiersByFile?: ReadonlyMap<string, readonly string[]>;
263
263
  }
264
- /** Build lowering runs in two passes over the same ts.Program:
264
+ /** Build lowering runs as a reachability worklist over the ts.Program:
265
265
  *
266
- * 1. DISCOVERY — a worklist computes the set of reachable bodies. Seeds are
266
+ * 1. REACHABLE EMIT — a worklist computes the set of reachable bodies.
267
+ * Seeds are
267
268
  * the per-file init bodies (module top-level statements always run, in
268
269
  * import order); lowering a body yields IR whose call/closure/new/
269
- * virtualCall nodes are the edges that enqueue further bodies. The
270
- * pass's IR, diagnostics, and stats are discarded — it exists only to
271
- * answer "which bodies does the entry reach?".
272
- * 2. EMIT — a fresh Lowerer lowers in the HISTORICAL order (per file:
273
- * function declarations, then class members; then file inits, %main,
274
- * generic instances, lifted lambdas), skipping bodies the discovery
275
- * pass did not mark. Keeping the emit order (and lambda/instance
276
- * numbering) identical to the pre-reachability compiler means a fully
277
- * reachable program emits byte-identical C.
270
+ * virtualCall nodes are the edges that enqueue further bodies. The pass
271
+ * retains that IR. Once the graph closes, those functions are assembled in
272
+ * deterministic declaration order beside the already-lowered init,
273
+ * generic-instance, and lifted bodies. Checker-backed IR construction
274
+ * therefore happens once instead of once for discovery and again for
275
+ * emission.
278
276
  *
279
- * `coverage: true` adds a third pass — the REMAINDER — that lowers only
280
- * the bodies discovery did NOT mark (plus deferred collection diagnostics
281
- * nothing flushed), reported separately: whole-program analysis without
277
+ * `coverage: true` adds a second pass — the REMAINDER — that lowers only
278
+ * the bodies reachable emit did NOT mark (plus deferred collection
279
+ * diagnostics nothing flushed), reported separately: whole-program analysis without
282
280
  * letting unreached code fail builds. */
283
281
  export declare function lowerToIr(program: ts.Program, entry: ts.SourceFile, moduleOrder: ts.SourceFile[], options?: LowerOptions): LowerResult;
284
282
  /** The island-handle type a `import(...)` initializer gives a binding
@@ -429,6 +427,26 @@ export declare class Lowerer {
429
427
  info: GenericFnInfo;
430
428
  inst: GenericInstance;
431
429
  }[];
430
+ /** Historical emit rank of the retained declaration/init body currently
431
+ * lowering, and the earliest such owner that demanded each generic
432
+ * instance. Reachability can encounter a later caller first; the minimum
433
+ * rank recovers the old emitter's source-order monomorphization queue. */
434
+ private genericDemandOwner;
435
+ private readonly genericDemandRoots;
436
+ private readonly genericFunctionDemandOwner;
437
+ private readonly genericClassDemandOwner;
438
+ private readonly genericDemandPriority;
439
+ private readonly genericClassDemandPriority;
440
+ private withGenericDemandOwner;
441
+ noteGenericInstanceDemand(inst: GenericInstance): void;
442
+ noteGenericClassInstanceDemand(info: ClassInfo): void;
443
+ /** The old emitter lowered all reachable declarations in source order,
444
+ * then every init, before draining generic instances FIFO. Reorder the
445
+ * retained queue from those recorded demands before any generic body
446
+ * lowers, so immediate support decisions see the same shape metadata too. */
447
+ private restoreGenericInstanceOrder;
448
+ private restoreGenericClassInstanceOrder;
449
+ private settleGenericDemandPriorities;
432
450
  /** Non-null while an instance body lowers: type-parameter symbol →
433
451
  * concrete IR type, consulted inside mapType's recursion. */
434
452
  typeParamBindings: Map<ts.Symbol, IrType> | null;
@@ -482,6 +500,16 @@ export declare class Lowerer {
482
500
  /** Synthetic array-HOF loop functions (map/filter/forEach desugar),
483
501
  * interned per method + element/callback-result type: key → fn name. */
484
502
  readonly arrHofHelpers: Map<string, string>;
503
+ /** Derived shape metadata that depends on another shape's declaration
504
+ * order. These settle before helper bodies rebuild from that metadata. */
505
+ readonly shapeOrderMetadataFinalizers: (() => void)[];
506
+ /** Settled generic class-rest metadata requires the historical emit
507
+ * fallback so its fence can poison the original statement atomically. */
508
+ requiresHistoricalOrderRelower: boolean;
509
+ /** Helpers that snapshot shape declaration order into their bodies.
510
+ * Reachability lowers inits before the declarations they discover, so
511
+ * these rebuild after the worklist restores historical shape metadata. */
512
+ readonly shapeOrderHelperFinalizers: (() => void)[];
485
513
  /** Emit-override specializations (`%C.emit:<event>` — lower-emitter.ts's
486
514
  * emit-overrides block): interned names, the drive-loop queue, and the
487
515
  * currently-lowering specialization's context (the super-forward
@@ -511,6 +539,16 @@ export declare class Lowerer {
511
539
  /** Union re-tag helpers (%union.retag.N), interned per (from, to)
512
540
  * unionId pair — see unionRetagHelper. */
513
541
  readonly retagHelpers: Map<string, string>;
542
+ /** Callee names of every interned coercion helper whose CALL mints a
543
+ * FRESH closure per evaluation (%fn.width.*, %fn.adapt.*,
544
+ * %fnval.spawnres.*). Registered at the mint site — NOT recovered by
545
+ * name-prefix matching — because retained-FFI release identity is the
546
+ * runtime closure pointer: a coercion adapter allocates a different
547
+ * closure at the registration and release sites, so lowerFfiCall must
548
+ * refuse these forms at compile time (SC5003). Any new closure-minting
549
+ * adapter helper MUST add its name here, or the identity guard silently
550
+ * reopens and the mismatch surfaces as a runtime release trap instead. */
551
+ readonly freshClosureAdapters: Set<string>;
514
552
  /** Symbols bound by `const x = promisify(execFile)` — the one lowered
515
553
  * util.promisify shape. Declarations register here and emit nothing;
516
554
  * calls through the binding lower (lowerExecFileAsyncCall) and value
@@ -706,6 +744,8 @@ export declare class Lowerer {
706
744
  * IrModule.unions. An arm's index in the canonical list is its runtime
707
745
  * tag. */
708
746
  readonly unions: UnionRegistry;
747
+ /** Context-free successful type mappings. See TypeMapperCtx.typeMemo. */
748
+ readonly typeMemo: Map<string, IrType>;
709
749
  readonly ambient: string;
710
750
  readonly overridesAmbient: string;
711
751
  readonly fallbackAmbient: string;
@@ -714,7 +754,7 @@ export declare class Lowerer {
714
754
  * through `this`, so the same ctx serves generic bodies too). */
715
755
  readonly typeCtx: TypeMapperCtx;
716
756
  readonly stats: LowerStats;
717
- /** Discovery-pass edge sink (null in the emit pass): every resolution of
757
+ /** Reachability edge sink: every resolution of
718
758
  * a reference to a lowerable body reports its name here — recorded even
719
759
  * when the enclosing statement later poisons. */
720
760
  onEdge: ((name: string) => void) | null;
@@ -755,9 +795,12 @@ export declare class Lowerer {
755
795
  readonly varGlobalEntryInits: Map<ts.SourceFile, IrGlobal[]>;
756
796
  get ctx(): FnCtx;
757
797
  get scopes(): Map<ts.Symbol, IrLocal>[];
758
- /** Names of bodies the discovery pass reached; null lowers everything
759
- * (the discovery pass itself). */
798
+ /** Names of bodies a prior reachability pass reached; null lowers everything. */
760
799
  readonly reachable: ReadonlySet<string> | null;
800
+ /** Reachability computed by this same Lowerer when retained worklist IR
801
+ * is assembled directly. The configured reachable set remains null so
802
+ * demand-driven instance lowering keeps its existing gates. */
803
+ reachableForArtifacts: ReadonlySet<string> | null;
761
804
  /** Coverage remainder mode: the reachability gate inverts (see wantBody)
762
805
  * and no module is built. */
763
806
  readonly remainder: boolean;
@@ -836,7 +879,7 @@ export declare class Lowerer {
836
879
  * namespace path (nsPathPrefix), so `namespace A { export class C }`
837
880
  * and a top-level `class C` never collide. Class EXPRESSIONS name by
838
881
  * SOURCE POSITION (`%cx<start>.<name>`): deterministic across the
839
- * discovery and emit passes (no counter can drift between them),
882
+ * builds (no counter can drift between invocations),
840
883
  * program-unique through the file qualifier, and collision-free with
841
884
  * user identifiers ('%'). */
842
885
  readonly classNamer: (decl: ts.ClassLikeDeclaration) => string;
@@ -927,13 +970,16 @@ export declare class Lowerer {
927
970
  * their external dependencies by name). Null for everything else
928
971
  * (builtins load nothing; the rest kept its preflight fence). */
929
972
  requireInitStmt(spec: string, node: ts.Node): IrStmt | null;
930
- /** True when this body should lower: everything with no reachable set
931
- * (discovery), the marked bodies in the emit pass, and exactly the
973
+ /** True when this body should lower: everything with no reachable set,
974
+ * the marked bodies in an externally-gated pass, and exactly the
932
975
  * UNMARKED bodies in the coverage remainder. */
933
976
  wantBody(name: string): boolean;
934
977
  collectNpmImports(parts: FileParts[]): void;
935
978
  collectJsonImports(parts: FileParts[]): void;
936
979
  run(): LowerResult;
980
+ /** Final retention, pruning, and module assembly shared by ordinary emit
981
+ * and the retained reachability worklist. */
982
+ finishModule(functions: IrFunction[]): LowerResult;
937
983
  /** The unregistered-class type sweep (run()'s last step before the
938
984
  * module assembles): every `{kind:"object"}` TYPE naming a class with
939
985
  * no registered ClassInfo is rewritten IN PLACE to the f64 dummy.
@@ -950,12 +996,13 @@ export declare class Lowerer {
950
996
  typeNamesUnregisteredClass(t: IrType, seen?: Set<string>): boolean;
951
997
  /** Whether run() counts a signature-blocked declaration in
952
998
  * stats.functionsSkipped: whole-program passes and the coverage
953
- * remainder do; the reachability emit pass leaves the counting to the
999
+ * remainder do; an externally-gated emit pass leaves the counting to the
954
1000
  * remainder (the declaration was never reached). */
955
1001
  countsSkips(): boolean;
956
- /** The discovery pass: computes the set of body names the program's entry
957
- * reaches. Seeds are the per-file init bodies (top-level statements always
958
- * run); edges fire from RESOLUTION sites while a body lowers (noteEdge /
1002
+ /** Reachable emit: computes the set of body names the program's entry
1003
+ * reaches and retains each body IR as it lowers. Seeds are the per-file
1004
+ * init bodies (top-level statements always run); edges fire from
1005
+ * RESOLUTION sites while a body lowers (noteEdge /
959
1006
  * noteVirtualEdge) — direct calls, closure creation (a taken closure may
960
1007
  * be called indirectly), `new`, super calls, accessor invocations, and
961
1008
  * virtual dispatch. Recording at resolution time (not off the produced
@@ -965,9 +1012,12 @@ export declare class Lowerer {
965
1012
  * demand-driven) and lifted lambdas lower inline with their enclosing
966
1013
  * body; both fire edges through the same hooks and are not units
967
1014
  * themselves. */
968
- discover(extraRoots?: readonly string[]): Set<string>;
969
- /** Discovery hook (see discover): fires when lowering resolves a
970
- * reference to a lowerable body. Inert in the emit pass. */
1015
+ emitReachable(extraRoots?: readonly string[]): {
1016
+ reachable: Set<string>;
1017
+ result: LowerResult;
1018
+ };
1019
+ /** Reachability hook (see emitReachable): fires when lowering resolves a
1020
+ * reference to a lowerable body. */
971
1021
  noteEdge(name: string): void;
972
1022
  /** Discovery hook for virtual dispatch: a virtualCall on `info`'s static
973
1023
  * class reaches the nearest declaration at/above it plus every override