@scriptc/compiler 0.0.33 → 0.0.35

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 (133) hide show
  1. package/dist/backend/cc-cache.test.js +1091 -7
  2. package/dist/backend/cc-cache.test.js.map +1 -1
  3. package/dist/backend/cc.d.ts +109 -18
  4. package/dist/backend/cc.js +1057 -289
  5. package/dist/backend/cc.js.map +1 -1
  6. package/dist/backend/emission/emit-exprs.js +26 -1
  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 +11 -2
  11. package/dist/backend/emission/emitter.js +11 -5
  12. package/dist/backend/emission/emitter.js.map +1 -1
  13. package/dist/backend/library-identity.d.ts +22 -0
  14. package/dist/backend/library-identity.js +103 -0
  15. package/dist/backend/library-identity.js.map +1 -0
  16. package/dist/backend/llvm/emitter.d.ts +3 -0
  17. package/dist/backend/llvm/emitter.js +35 -5
  18. package/dist/backend/llvm/emitter.js.map +1 -1
  19. package/dist/backend/llvm/shapes.d.ts +1 -0
  20. package/dist/backend/llvm/shapes.js +25 -1
  21. package/dist/backend/llvm/shapes.js.map +1 -1
  22. package/dist/backend/llvm/split.d.ts +43 -0
  23. package/dist/backend/llvm/split.js +227 -0
  24. package/dist/backend/llvm/split.js.map +1 -0
  25. package/dist/backend/llvm/split.test.d.ts +1 -0
  26. package/dist/backend/llvm/split.test.js +102 -0
  27. package/dist/backend/llvm/split.test.js.map +1 -0
  28. package/dist/backend/mangle.d.ts +1 -0
  29. package/dist/backend/mangle.js +3 -0
  30. package/dist/backend/mangle.js.map +1 -1
  31. package/dist/backend/object-localize.d.ts +5 -5
  32. package/dist/backend/object-localize.js +19 -16
  33. package/dist/backend/object-localize.js.map +1 -1
  34. package/dist/backend/object-localize.test.js +57 -13
  35. package/dist/backend/object-localize.test.js.map +1 -1
  36. package/dist/executable/early-cache.d.ts +86 -0
  37. package/dist/executable/early-cache.js +460 -0
  38. package/dist/executable/early-cache.js.map +1 -0
  39. package/dist/executable/early-cache.test.d.ts +1 -0
  40. package/dist/executable/early-cache.test.js +300 -0
  41. package/dist/executable/early-cache.test.js.map +1 -0
  42. package/dist/ffi/profile.d.ts +7 -2
  43. package/dist/ffi/profile.js +1 -0
  44. package/dist/ffi/profile.js.map +1 -1
  45. package/dist/frontend/input-tracker.d.ts +82 -0
  46. package/dist/frontend/input-tracker.js +380 -0
  47. package/dist/frontend/input-tracker.js.map +1 -0
  48. package/dist/frontend/input-tracker.test.d.ts +1 -0
  49. package/dist/frontend/input-tracker.test.js +137 -0
  50. package/dist/frontend/input-tracker.test.js.map +1 -0
  51. package/dist/frontend/lowering/lower-builtins.js +4 -10
  52. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  53. package/dist/frontend/lowering/lower-calls.js +169 -144
  54. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  55. package/dist/frontend/lowering/lower-classes.js +3 -0
  56. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  57. package/dist/frontend/lowering/lower-containers.js +66 -32
  58. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  59. package/dist/frontend/lowering/lower-exprs.js +89 -11
  60. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  61. package/dist/frontend/lowering/lower-inspect.js +45 -26
  62. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  63. package/dist/frontend/lowering/lower-island.js +3 -3
  64. package/dist/frontend/lowering/lower-island.js.map +1 -1
  65. package/dist/frontend/lowering/lower-mixins.js +1 -1
  66. package/dist/frontend/lowering/lower-mixins.js.map +1 -1
  67. package/dist/frontend/lowering/lower-modules.js +1 -1
  68. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  69. package/dist/frontend/lowering/lower-stmts.js +49 -4
  70. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  71. package/dist/frontend/lowering/lowerer.d.ts +73 -29
  72. package/dist/frontend/lowering/lowerer.js +588 -116
  73. package/dist/frontend/lowering/lowerer.js.map +1 -1
  74. package/dist/frontend/lowering/surfaces.js +1 -1
  75. package/dist/frontend/lowering/surfaces.js.map +1 -1
  76. package/dist/frontend/npm-static-rewrite.js +25 -26
  77. package/dist/frontend/npm-static-rewrite.js.map +1 -1
  78. package/dist/frontend/npm-static.js +29 -30
  79. package/dist/frontend/npm-static.js.map +1 -1
  80. package/dist/frontend/npm-static.test.d.ts +1 -0
  81. package/dist/frontend/npm-static.test.js +15 -0
  82. package/dist/frontend/npm-static.test.js.map +1 -0
  83. package/dist/frontend/npm.js +5 -17
  84. package/dist/frontend/npm.js.map +1 -1
  85. package/dist/frontend/program.js +44 -19
  86. package/dist/frontend/program.js.map +1 -1
  87. package/dist/frontend/resolve.js +8 -29
  88. package/dist/frontend/resolve.js.map +1 -1
  89. package/dist/frontend/ts7/checker.d.ts +40 -2
  90. package/dist/frontend/ts7/checker.js +194 -32
  91. package/dist/frontend/ts7/checker.js.map +1 -1
  92. package/dist/frontend/ts7/program.js +17 -18
  93. package/dist/frontend/ts7/program.js.map +1 -1
  94. package/dist/frontend/types.d.ts +33 -0
  95. package/dist/frontend/types.js +134 -45
  96. package/dist/frontend/types.js.map +1 -1
  97. package/dist/index.d.ts +5 -2
  98. package/dist/index.js +458 -141
  99. package/dist/index.js.map +1 -1
  100. package/dist/ir/nodes.d.ts +27 -4
  101. package/dist/ir/nodes.js +28 -0
  102. package/dist/ir/nodes.js.map +1 -1
  103. package/dist/ir/serialize.d.ts +1 -1
  104. package/dist/ir/serialize.js +1 -1
  105. package/dist/ir/validate.js +37 -1
  106. package/dist/ir/validate.js.map +1 -1
  107. package/dist/library/early-cache.d.ts +65 -0
  108. package/dist/library/early-cache.js +361 -0
  109. package/dist/library/early-cache.js.map +1 -0
  110. package/dist/library/early-cache.test.d.ts +1 -0
  111. package/dist/library/early-cache.test.js +528 -0
  112. package/dist/library/early-cache.test.js.map +1 -0
  113. package/dist/library/implementation-identity.d.ts +23 -0
  114. package/dist/library/implementation-identity.js +84 -0
  115. package/dist/library/implementation-identity.js.map +1 -0
  116. package/dist/library/int-infer.js +14 -0
  117. package/dist/library/int-infer.js.map +1 -1
  118. package/dist/library/int-infer.test.js +21 -4
  119. package/dist/library/int-infer.test.js.map +1 -1
  120. package/dist/library/semantic-source.d.ts +13 -0
  121. package/dist/library/semantic-source.js +257 -0
  122. package/dist/library/semantic-source.js.map +1 -0
  123. package/dist/library/semantic-source.test.d.ts +1 -0
  124. package/dist/library/semantic-source.test.js +113 -0
  125. package/dist/library/semantic-source.test.js.map +1 -0
  126. package/dist/library/sidecar.d.ts +6 -0
  127. package/dist/library/sidecar.js +11 -0
  128. package/dist/library/sidecar.js.map +1 -1
  129. package/dist/startup-cache.d.ts +6 -0
  130. package/dist/startup-cache.js +6 -0
  131. package/dist/startup-cache.js.map +1 -0
  132. package/package.json +3 -2
  133. 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
@@ -726,7 +754,7 @@ export declare class Lowerer {
726
754
  * through `this`, so the same ctx serves generic bodies too). */
727
755
  readonly typeCtx: TypeMapperCtx;
728
756
  readonly stats: LowerStats;
729
- /** Discovery-pass edge sink (null in the emit pass): every resolution of
757
+ /** Reachability edge sink: every resolution of
730
758
  * a reference to a lowerable body reports its name here — recorded even
731
759
  * when the enclosing statement later poisons. */
732
760
  onEdge: ((name: string) => void) | null;
@@ -767,9 +795,12 @@ export declare class Lowerer {
767
795
  readonly varGlobalEntryInits: Map<ts.SourceFile, IrGlobal[]>;
768
796
  get ctx(): FnCtx;
769
797
  get scopes(): Map<ts.Symbol, IrLocal>[];
770
- /** Names of bodies the discovery pass reached; null lowers everything
771
- * (the discovery pass itself). */
798
+ /** Names of bodies a prior reachability pass reached; null lowers everything. */
772
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;
773
804
  /** Coverage remainder mode: the reachability gate inverts (see wantBody)
774
805
  * and no module is built. */
775
806
  readonly remainder: boolean;
@@ -848,7 +879,7 @@ export declare class Lowerer {
848
879
  * namespace path (nsPathPrefix), so `namespace A { export class C }`
849
880
  * and a top-level `class C` never collide. Class EXPRESSIONS name by
850
881
  * SOURCE POSITION (`%cx<start>.<name>`): deterministic across the
851
- * discovery and emit passes (no counter can drift between them),
882
+ * builds (no counter can drift between invocations),
852
883
  * program-unique through the file qualifier, and collision-free with
853
884
  * user identifiers ('%'). */
854
885
  readonly classNamer: (decl: ts.ClassLikeDeclaration) => string;
@@ -939,13 +970,16 @@ export declare class Lowerer {
939
970
  * their external dependencies by name). Null for everything else
940
971
  * (builtins load nothing; the rest kept its preflight fence). */
941
972
  requireInitStmt(spec: string, node: ts.Node): IrStmt | null;
942
- /** True when this body should lower: everything with no reachable set
943
- * (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
944
975
  * UNMARKED bodies in the coverage remainder. */
945
976
  wantBody(name: string): boolean;
946
977
  collectNpmImports(parts: FileParts[]): void;
947
978
  collectJsonImports(parts: FileParts[]): void;
948
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;
949
983
  /** The unregistered-class type sweep (run()'s last step before the
950
984
  * module assembles): every `{kind:"object"}` TYPE naming a class with
951
985
  * no registered ClassInfo is rewritten IN PLACE to the f64 dummy.
@@ -962,12 +996,13 @@ export declare class Lowerer {
962
996
  typeNamesUnregisteredClass(t: IrType, seen?: Set<string>): boolean;
963
997
  /** Whether run() counts a signature-blocked declaration in
964
998
  * stats.functionsSkipped: whole-program passes and the coverage
965
- * remainder do; the reachability emit pass leaves the counting to the
999
+ * remainder do; an externally-gated emit pass leaves the counting to the
966
1000
  * remainder (the declaration was never reached). */
967
1001
  countsSkips(): boolean;
968
- /** The discovery pass: computes the set of body names the program's entry
969
- * reaches. Seeds are the per-file init bodies (top-level statements always
970
- * 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 /
971
1006
  * noteVirtualEdge) — direct calls, closure creation (a taken closure may
972
1007
  * be called indirectly), `new`, super calls, accessor invocations, and
973
1008
  * virtual dispatch. Recording at resolution time (not off the produced
@@ -977,9 +1012,12 @@ export declare class Lowerer {
977
1012
  * demand-driven) and lifted lambdas lower inline with their enclosing
978
1013
  * body; both fire edges through the same hooks and are not units
979
1014
  * themselves. */
980
- discover(extraRoots?: readonly string[]): Set<string>;
981
- /** Discovery hook (see discover): fires when lowering resolves a
982
- * 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. */
983
1021
  noteEdge(name: string): void;
984
1022
  /** Discovery hook for virtual dispatch: a virtualCall on `info`'s static
985
1023
  * class reaches the nearest declaration at/above it plus every override
@@ -1639,6 +1677,12 @@ export declare class Lowerer {
1639
1677
  lowerGenericFnValue(ref: ts.Expression, info: GenericFnInfo): IrExpr;
1640
1678
  inferTypeParamBindings(expr: ts.CallExpression, info: GenericFnInfo, rsig: ts.Signature, tsBindings?: Map<ts.Symbol, ts.Type>): Map<ts.Symbol, IrType>;
1641
1679
  lowerGenericInstance(info: GenericFnInfo, inst: GenericInstance): IrFunction;
1680
+ /** Checker work class SHAPE collection performs inside otherwise
1681
+ * deferred JavaScript bodies. Constructor assignments declare fields,
1682
+ * so collection asks for each `this.x` symbol and RHS type even when the
1683
+ * constructor is unreachable. Keep that mandatory work batched without
1684
+ * sweeping unrelated dead method bodies. */
1685
+ private prefetchClassCollection;
1642
1686
  collectClassShape(decl: ts.ClassDeclaration): void;
1643
1687
  collectClassShapeInner(decl: ts.ClassLikeDeclaration, jsNameOverride?: string, inst?: {
1644
1688
  family: ClassInfo;