@scriptc/compiler 0.2.9 → 0.2.10

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 (147) hide show
  1. package/dist/backend/cycle-analysis.d.ts +56 -0
  2. package/dist/backend/cycle-analysis.js +175 -14
  3. package/dist/backend/cycle-analysis.js.map +1 -1
  4. package/dist/backend/cycle-analysis.test.js +94 -1
  5. package/dist/backend/cycle-analysis.test.js.map +1 -1
  6. package/dist/backend/cycle-mutability.d.ts +2 -6
  7. package/dist/backend/cycle-mutability.js +3 -12
  8. package/dist/backend/cycle-mutability.js.map +1 -1
  9. package/dist/backend/immutability.d.ts +57 -0
  10. package/dist/backend/immutability.js +178 -0
  11. package/dist/backend/immutability.js.map +1 -0
  12. package/dist/backend/immutability.test.d.ts +1 -0
  13. package/dist/backend/immutability.test.js +131 -0
  14. package/dist/backend/immutability.test.js.map +1 -0
  15. package/dist/backend/llvm/borrowed-inputs.d.ts +9 -2
  16. package/dist/backend/llvm/borrowed-inputs.js +31 -3
  17. package/dist/backend/llvm/borrowed-inputs.js.map +1 -1
  18. package/dist/backend/llvm/classes.d.ts +28 -0
  19. package/dist/backend/llvm/classes.js +45 -5
  20. package/dist/backend/llvm/classes.js.map +1 -1
  21. package/dist/backend/llvm/classes.test.js +129 -1
  22. package/dist/backend/llvm/classes.test.js.map +1 -1
  23. package/dist/backend/llvm/common.d.ts +13 -0
  24. package/dist/backend/llvm/common.js +13 -0
  25. package/dist/backend/llvm/common.js.map +1 -1
  26. package/dist/backend/llvm/dense-array-access.js +5 -4
  27. package/dist/backend/llvm/dense-array-access.js.map +1 -1
  28. package/dist/backend/llvm/dense-array-access.test.js +9 -1
  29. package/dist/backend/llvm/dense-array-access.test.js.map +1 -1
  30. package/dist/backend/llvm/dyn.d.ts +2 -0
  31. package/dist/backend/llvm/dyn.js +3 -3
  32. package/dist/backend/llvm/dyn.js.map +1 -1
  33. package/dist/backend/llvm/emitter.d.ts +64 -2
  34. package/dist/backend/llvm/emitter.js +390 -45
  35. package/dist/backend/llvm/emitter.js.map +1 -1
  36. package/dist/backend/llvm/emitter.test.js +18 -0
  37. package/dist/backend/llvm/emitter.test.js.map +1 -1
  38. package/dist/backend/llvm/expr-calls.js +14 -6
  39. package/dist/backend/llvm/expr-calls.js.map +1 -1
  40. package/dist/backend/llvm/expr-containers.js +30 -7
  41. package/dist/backend/llvm/expr-containers.js.map +1 -1
  42. package/dist/backend/llvm/expr-primitives.js +30 -3
  43. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  44. package/dist/backend/llvm/expr-primitives.test.js +53 -0
  45. package/dist/backend/llvm/expr-primitives.test.js.map +1 -1
  46. package/dist/backend/llvm/expr-stream-bridges.js +4 -4
  47. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  48. package/dist/backend/llvm/local-array-reads.js +3 -3
  49. package/dist/backend/llvm/local-array-reads.js.map +1 -1
  50. package/dist/backend/llvm/loop-array-borrows.d.ts +5 -2
  51. package/dist/backend/llvm/loop-array-borrows.js +27 -8
  52. package/dist/backend/llvm/loop-array-borrows.js.map +1 -1
  53. package/dist/backend/llvm/map-number-lookup.d.ts +7 -0
  54. package/dist/backend/llvm/map-number-lookup.js +18 -1
  55. package/dist/backend/llvm/map-number-lookup.js.map +1 -1
  56. package/dist/backend/llvm/map-read-lifetimes.d.ts +5 -0
  57. package/dist/backend/llvm/map-read-lifetimes.js +14 -4
  58. package/dist/backend/llvm/map-read-lifetimes.js.map +1 -1
  59. package/dist/backend/llvm/map-read-lifetimes.test.js +5 -0
  60. package/dist/backend/llvm/map-read-lifetimes.test.js.map +1 -1
  61. package/dist/backend/llvm/reference-writes.d.ts +124 -0
  62. package/dist/backend/llvm/reference-writes.js +1090 -0
  63. package/dist/backend/llvm/reference-writes.js.map +1 -0
  64. package/dist/backend/llvm/shapes.d.ts +8 -5
  65. package/dist/backend/llvm/shapes.js +36 -11
  66. package/dist/backend/llvm/shapes.js.map +1 -1
  67. package/dist/backend/llvm/string-lifetimes.test.js +39 -10
  68. package/dist/backend/llvm/string-lifetimes.test.js.map +1 -1
  69. package/dist/backend/llvm/string-reads.d.ts +3 -0
  70. package/dist/backend/llvm/string-reads.js +31 -0
  71. package/dist/backend/llvm/string-reads.js.map +1 -1
  72. package/dist/backend/llvm/switch-dispatch.d.ts +2 -2
  73. package/dist/backend/llvm/switch-dispatch.js +35 -22
  74. package/dist/backend/llvm/switch-dispatch.js.map +1 -1
  75. package/dist/backend/llvm/switch-dispatch.test.js +28 -10
  76. package/dist/backend/llvm/switch-dispatch.test.js.map +1 -1
  77. package/dist/backend/llvm/walk-borrows.d.ts +8 -1
  78. package/dist/backend/llvm/walk-borrows.js +15 -4
  79. package/dist/backend/llvm/walk-borrows.js.map +1 -1
  80. package/dist/backend/may-throw.d.ts +36 -2
  81. package/dist/backend/may-throw.js +308 -12
  82. package/dist/backend/may-throw.js.map +1 -1
  83. package/dist/backend/may-throw.test.js +146 -1
  84. package/dist/backend/may-throw.test.js.map +1 -1
  85. package/dist/backend/publication.d.ts +5 -0
  86. package/dist/backend/publication.js +10 -0
  87. package/dist/backend/publication.js.map +1 -1
  88. package/dist/backend/runtime-abi.d.ts +2 -2
  89. package/dist/backend/runtime-abi.js +2 -2
  90. package/dist/backend/runtime-pack-targets.test.js +1 -1
  91. package/dist/backend/runtime-pack.test.js +1 -1
  92. package/dist/contracts/check.d.ts +8 -0
  93. package/dist/contracts/check.js +1577 -0
  94. package/dist/contracts/check.js.map +1 -0
  95. package/dist/executable/prepare.js +9 -0
  96. package/dist/executable/prepare.js.map +1 -1
  97. package/dist/frontend/contract-types.d.ts +50 -0
  98. package/dist/frontend/contract-types.js +232 -0
  99. package/dist/frontend/contract-types.js.map +1 -0
  100. package/dist/frontend/lowering/coercions/unions.d.ts +12 -0
  101. package/dist/frontend/lowering/coercions/unions.js +63 -0
  102. package/dist/frontend/lowering/coercions/unions.js.map +1 -1
  103. package/dist/frontend/lowering/expressions/optional-chains.js +4 -1
  104. package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
  105. package/dist/frontend/lowering/lower-calls.js +9 -2
  106. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  107. package/dist/frontend/lowering/lower-exprs.js +83 -1
  108. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  109. package/dist/frontend/lowering/lowerer.d.ts +9 -0
  110. package/dist/frontend/lowering/lowerer.js +47 -0
  111. package/dist/frontend/lowering/lowerer.js.map +1 -1
  112. package/dist/frontend/lowering/narrowing-stability.d.ts +100 -0
  113. package/dist/frontend/lowering/narrowing-stability.js +1174 -0
  114. package/dist/frontend/lowering/narrowing-stability.js.map +1 -0
  115. package/dist/frontend/lowering/narrowing-stability.test.d.ts +1 -0
  116. package/dist/frontend/lowering/narrowing-stability.test.js +150 -0
  117. package/dist/frontend/lowering/narrowing-stability.test.js.map +1 -0
  118. package/dist/frontend/program.js +1 -1
  119. package/dist/frontend/type-mapper.js +43 -0
  120. package/dist/frontend/type-mapper.js.map +1 -1
  121. package/dist/ir/int32-slots.d.ts +26 -0
  122. package/dist/ir/int32-slots.js +147 -47
  123. package/dist/ir/int32-slots.js.map +1 -1
  124. package/dist/ir/integer-loops.js +3 -0
  125. package/dist/ir/integer-loops.js.map +1 -1
  126. package/dist/ir/integer-loops.test.js +26 -1
  127. package/dist/ir/integer-loops.test.js.map +1 -1
  128. package/dist/ir/integer-ranges.d.ts +20 -0
  129. package/dist/ir/integer-ranges.js +178 -21
  130. package/dist/ir/integer-ranges.js.map +1 -1
  131. package/dist/ir/integer-ranges.test.js +148 -3
  132. package/dist/ir/integer-ranges.test.js.map +1 -1
  133. package/dist/ir/ir.d.ts +32 -0
  134. package/dist/ir/ir.js.map +1 -1
  135. package/dist/ir/serialize.d.ts +5 -1
  136. package/dist/ir/serialize.js +8 -0
  137. package/dist/ir/serialize.js.map +1 -1
  138. package/dist/ir/unshare.d.ts +14 -0
  139. package/dist/ir/unshare.js +60 -0
  140. package/dist/ir/unshare.js.map +1 -0
  141. package/dist/ir/unshare.test.d.ts +1 -0
  142. package/dist/ir/unshare.test.js +115 -0
  143. package/dist/ir/unshare.test.js.map +1 -0
  144. package/dist/library/prepare.js +9 -0
  145. package/dist/library/prepare.js.map +1 -1
  146. package/package.json +20 -20
  147. package/surface-manifest.json +1 -1
@@ -11,6 +11,7 @@ import { OptionalArrayReads, type LocalArrayRead } from "./local-array-reads.js"
11
11
  import { CheckedNarrows } from "./checked-narrows.js";
12
12
  import { type MapReadLifetimes } from "./map-read-lifetimes.js";
13
13
  import { ReferenceEffects } from "./reference-effects.js";
14
+ import { ReferenceWrites, type Writes } from "./reference-writes.js";
14
15
  import { StackCallbacks } from "./stack-callbacks.js";
15
16
  import { AmbientReceiverReaders } from "./constant-callbacks.js";
16
17
  import { type StringSliceSnapshot } from "./string-slices.js";
@@ -50,9 +51,9 @@ export interface LlvmTargetOptions {
50
51
  * Executables only; the runtime's weak default keeps it off. */
51
52
  detachedExit?: boolean;
52
53
  }
53
- export declare function emitLlvmModule(mod: IrModule, options?: LlvmTargetOptions): string;
54
+ export declare function emitLlvmModule(input: IrModule, options?: LlvmTargetOptions): string;
54
55
  /** Keep large translation units below the host's single-string limit. */
55
- export declare function emitLlvmModuleSource(mod: IrModule, options?: LlvmTargetOptions): string | readonly string[];
56
+ export declare function emitLlvmModuleSource(input: IrModule, options?: LlvmTargetOptions): string | readonly string[];
56
57
  export declare class LlEmitter {
57
58
  readonly mod: IrModule;
58
59
  localArrayReads: Map<string, LocalArrayRead>;
@@ -159,6 +160,12 @@ export declare class LlEmitter {
159
160
  * fiberless-async analysis scans it for suspension entry points. */
160
161
  private readonly fnDefText;
161
162
  readonly referenceEffects: ReferenceEffects;
163
+ /** Field-sensitive reference writes (null in debug builds). */
164
+ referenceWrites: ReferenceWrites | null;
165
+ private readonly borrowedReturnKeyCache;
166
+ /** The statement list being emitted and the current index, for blocks
167
+ * whose bindings end with the list (emitBlock and function bodies). */
168
+ private stmtCursor;
162
169
  readonly optionalArrayReads: OptionalArrayReads;
163
170
  readonly checkedNarrows: CheckedNarrows;
164
171
  callArrayReads: Map<IrExpr, LocalArrayRead>;
@@ -202,6 +209,9 @@ export declare class LlEmitter {
202
209
  readonly ffiHasRetainedCallback: boolean;
203
210
  private readonly ffiHasForeignCallback;
204
211
  private readonly globalTypes;
212
+ /** Module constants that keep one value once initialized
213
+ * (immutability.ts stableGlobals). */
214
+ private stableGlobals;
205
215
  private readonly tdzGlobals;
206
216
  readonly constantNumericTables: ReadonlyMap<string, ConstantNumericTable>;
207
217
  /** May-throw analysis (computeMayThrow): pending
@@ -217,6 +227,13 @@ export declare class LlEmitter {
217
227
  /** Static types whose values can be published (@scriptc/threads): their
218
228
  * stores carry the frozen-object guard. Null without publish calls. */
219
229
  readonly publishedTypes: PublishedTypes | null;
230
+ /** Construction-only class and record fields (immutability.ts); null
231
+ * where the facts are disabled. */
232
+ private readonly immutableFields;
233
+ /** Constructor function names: their bodies may still write their own
234
+ * `this`'s construction-only fields. */
235
+ private readonly constructorFunctions;
236
+ private inConstructor;
220
237
  /** Method names with at least one may-throw implementation — the
221
238
  * virtualCall pending check's key. */
222
239
  readonly mayThrowMethods: Set<string>;
@@ -292,6 +309,12 @@ export declare class LlEmitter {
292
309
  private readonly initializerBindings;
293
310
  /** Whole-program int32 storage and parameter/result facts. */
294
311
  readonly int32Slots: Int32Slots;
312
+ /** Immutable module constants (contract types) whose graphs become
313
+ * immortal once initialized: their reads need no reference counting. */
314
+ readonly immortalGlobals: ReadonlySet<string>;
315
+ /** ProgramLifetime hierarchy roots (contract types): their instances are
316
+ * immortal from construction (classes.ts programLifetimeClass). */
317
+ readonly programLifetime: ReadonlySet<string>;
295
318
  private numericLocals;
296
319
  private captureIds;
297
320
  /** Active induction bindings retain their width independently of size_t. */
@@ -706,6 +729,42 @@ export declare class LlEmitter {
706
729
  * rebound during a call; its independent payload owner keeps it alive.
707
730
  * Other writable bindings need an owned snapshot. */
708
731
  canBorrowCallArgument(value: IrExpr): boolean;
732
+ /** A plain-pointer read of a construction-only field outside any
733
+ * constructor (ImmutableFields). */
734
+ private immutableRead;
735
+ /** A projection read whose locations nothing writes while a borrowed
736
+ * read of it is in use (ReferenceWrites), given the writes of that
737
+ * extent. The root binding itself must stay alive across it too, which
738
+ * its own location (`l:`, `g:`, `bx`) covers. */
739
+ unwrittenRead(e: IrExpr, writes: Writes): boolean;
740
+ /** A stable binding initialized by a projection can borrow it when the
741
+ * rest of its block (its whole lifetime) writes none of the projection's
742
+ * locations: the source edge then keeps the value alive, and uses that
743
+ * escape still retain their own copies. */
744
+ private unwrittenAlias;
745
+ /** An optional element read into a projection-only local can borrow the
746
+ * element when the rest of the block writes no array element and none of
747
+ * the locations keeping the array alive (which must itself be read
748
+ * without a frame owner). */
749
+ private unwrittenLocalArrayRead;
750
+ /** An optional element read passed to a projection-only parameter can
751
+ * borrow the element when the callee and later arguments (`writes`)
752
+ * write no array element and nothing keeping the array alive. */
753
+ unwrittenCallArrayRead(read: LocalArrayRead, writes: Writes): boolean;
754
+ /** `return x` of a local whose slot is an owned scope entry of the same
755
+ * type: the return can take over the local's reference. */
756
+ private movableReturn;
757
+ /** A walk host for a body that may write the heap: each walk must read
758
+ * only locations the whole body (with its callees) never writes;
759
+ * rebinding the walk locals themselves releases nothing. */
760
+ private unwrittenWalkHost;
761
+ /** emitReadReceiver yields a plain pointer for `e` that no statement
762
+ * frame owns, so it can outlive the statement (walk-borrows' walks, from
763
+ * any unboxed plain-pointer binding, plus element reads). */
764
+ private unownedWalk;
765
+ /** Every location a borrowed-return callee's walks can read (its body's
766
+ * field, record and element reads, through nested borrowed returns). */
767
+ private borrowedReturnKeys;
709
768
  private emitStmts;
710
769
  /** Emits a block in its own lexical scope (refcounted locals released at
711
770
  * end). `setup` runs after the
@@ -808,6 +867,9 @@ export declare class LlEmitter {
808
867
  private publishedNamesSym;
809
868
  /** The class-name table the hierarchy field guards index by preorder. */
810
869
  private publishedClassNamesDefs;
870
+ /** The frozen-object guard of a class field store, unless the store
871
+ * provably targets a still-private `this` (PublishedTypes.privateStores). */
872
+ private emitStoreGuard;
811
873
  /** The frozen-object guard of a class field or record field store:
812
874
  * Node's "Cannot assign to read only property" TypeError when the target
813
875
  * is published. `className` null means a record (`#<Object>`). */