@scriptc/compiler 0.0.8 → 0.0.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 (90) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +13 -0
  2. package/dist/backend/cc.js +14 -0
  3. package/dist/backend/cc.js.map +1 -1
  4. package/dist/backend/emission/emit-exprs.js +244 -17
  5. package/dist/backend/emission/emit-exprs.js.map +1 -1
  6. package/dist/backend/emission/emit-types.d.ts +3 -0
  7. package/dist/backend/emission/emit-types.js +12 -0
  8. package/dist/backend/emission/emit-types.js.map +1 -1
  9. package/dist/backend/emission/emit-walkers.d.ts +7 -5
  10. package/dist/backend/emission/emit-walkers.js +52 -12
  11. package/dist/backend/emission/emit-walkers.js.map +1 -1
  12. package/dist/backend/emission/emitter.d.ts +1 -1
  13. package/dist/backend/emission/emitter.js +30 -9
  14. package/dist/backend/emission/emitter.js.map +1 -1
  15. package/dist/backend/llvm/dyn.d.ts +1 -0
  16. package/dist/backend/llvm/dyn.js +83 -1
  17. package/dist/backend/llvm/dyn.js.map +1 -1
  18. package/dist/backend/llvm/emitter.js +357 -20
  19. package/dist/backend/llvm/emitter.js.map +1 -1
  20. package/dist/diagnostics/diagnostic.d.ts +73 -14
  21. package/dist/diagnostics/diagnostic.js +112 -31
  22. package/dist/diagnostics/diagnostic.js.map +1 -1
  23. package/dist/diagnostics/render.js +8 -0
  24. package/dist/diagnostics/render.js.map +1 -1
  25. package/dist/frontend/lowering/lib-boundary.js +11 -1
  26. package/dist/frontend/lowering/lib-boundary.js.map +1 -1
  27. package/dist/frontend/lowering/lower-assert.js +16 -0
  28. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  29. package/dist/frontend/lowering/lower-builtins.d.ts +24 -0
  30. package/dist/frontend/lowering/lower-builtins.js +256 -3
  31. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  32. package/dist/frontend/lowering/lower-calls.d.ts +71 -11
  33. package/dist/frontend/lowering/lower-calls.js +942 -18
  34. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  35. package/dist/frontend/lowering/lower-classes.js +27 -1
  36. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  37. package/dist/frontend/lowering/lower-containers.d.ts +21 -2
  38. package/dist/frontend/lowering/lower-containers.js +386 -53
  39. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  40. package/dist/frontend/lowering/lower-dgram.js +92 -17
  41. package/dist/frontend/lowering/lower-dgram.js.map +1 -1
  42. package/dist/frontend/lowering/lower-emitter.js +54 -0
  43. package/dist/frontend/lowering/lower-emitter.js.map +1 -1
  44. package/dist/frontend/lowering/lower-exprs.js +231 -17
  45. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  46. package/dist/frontend/lowering/lower-modules.js +33 -2
  47. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  48. package/dist/frontend/lowering/lower-namespaces.d.ts +25 -11
  49. package/dist/frontend/lowering/lower-namespaces.js +50 -15
  50. package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
  51. package/dist/frontend/lowering/lower-server.js +211 -4
  52. package/dist/frontend/lowering/lower-server.js.map +1 -1
  53. package/dist/frontend/lowering/lower-stmts.d.ts +1 -5
  54. package/dist/frontend/lowering/lower-stmts.js +660 -19
  55. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  56. package/dist/frontend/lowering/lower-stream.js +92 -5
  57. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  58. package/dist/frontend/lowering/lowerer.d.ts +102 -15
  59. package/dist/frontend/lowering/lowerer.js +378 -30
  60. package/dist/frontend/lowering/lowerer.js.map +1 -1
  61. package/dist/frontend/lowering/surfaces.js +20 -3
  62. package/dist/frontend/lowering/surfaces.js.map +1 -1
  63. package/dist/frontend/npm-static-rewrite.d.ts +7 -2
  64. package/dist/frontend/npm-static-rewrite.js +566 -138
  65. package/dist/frontend/npm-static-rewrite.js.map +1 -1
  66. package/dist/frontend/npm-static.js +11 -2
  67. package/dist/frontend/npm-static.js.map +1 -1
  68. package/dist/frontend/program.js +5 -5
  69. package/dist/frontend/program.js.map +1 -1
  70. package/dist/frontend/shared.d.ts +6 -1
  71. package/dist/frontend/shared.js +46 -1
  72. package/dist/frontend/shared.js.map +1 -1
  73. package/dist/frontend/types.d.ts +13 -0
  74. package/dist/frontend/types.js +88 -9
  75. package/dist/frontend/types.js.map +1 -1
  76. package/dist/index.js +169 -32
  77. package/dist/index.js.map +1 -1
  78. package/dist/ir/nodes.d.ts +230 -12
  79. package/dist/ir/nodes.js +85 -6
  80. package/dist/ir/nodes.js.map +1 -1
  81. package/dist/ir/validate.js +109 -9
  82. package/dist/ir/validate.js.map +1 -1
  83. package/dist/library/fence-eval.d.ts +77 -0
  84. package/dist/library/fence-eval.js +385 -0
  85. package/dist/library/fence-eval.js.map +1 -0
  86. package/dist/library/profile.d.ts +11 -1
  87. package/dist/library/profile.js +102 -18
  88. package/dist/library/profile.js.map +1 -1
  89. package/package.json +2 -2
  90. package/surface-manifest.json +10 -3
@@ -43,6 +43,12 @@ export type WidthLift = {
43
43
  how: "clsWidth";
44
44
  } | {
45
45
  how: "narrow";
46
+ } | {
47
+ how: "dynIn";
48
+ } | {
49
+ how: "upcast";
50
+ } | {
51
+ how: "funcAdapt";
46
52
  };
47
53
  export declare class PoisonError extends Error {
48
54
  }
@@ -288,6 +294,21 @@ export declare function neverTaintedJsType(L: Lowerer, node: ts.Node, t: ts.Type
288
294
  * forward captures included), and the implicit-return completion
289
295
  * (lower-calls' own copy of this pattern predates the helper). */
290
296
  export declare function dynUndefinedExpr(loc: SrcLoc): IrExpr;
297
+ /** An always-throwing Node-parity error expression (the error.nodeThrow
298
+ * libCall — the lowered form of arms Node rejects unconditionally:
299
+ * ERR_INVALID_THIS receivers, ERR_MISSING_ARGS arity ladders, the
300
+ * symbol-to-string TypeError). kind 0 Error / 1 TypeError / 2 RangeError;
301
+ * an empty code means no code slot. `type` is the replaced expression's
302
+ * own (never materialized — the global.undefRead pattern). */
303
+ export declare function nodeThrowExpr(kind: 0 | 1 | 2, code: string, message: string, type: IrType, loc: SrcLoc): IrExpr;
304
+ /** The post-validation fence STRING a validation-ladder Chk libCall
305
+ * throws after its Node-order checks pass: the same SC2020 text the
306
+ * per-statement runtime fence would have thrown (message + "[code at
307
+ * file:line]"), rendered eagerly so the runtime can throw it verbatim
308
+ * (scr_throw_lowering_fence). The diagnostic joins the runtime-fence
309
+ * ledger exactly like a deferred statement fence — nothing silently
310
+ * drops off the coverage report. */
311
+ export declare function ladderFenceExpr(L: Lowerer, surface: string, node: ts.Node, hint?: string): IrExpr;
291
312
  /** The checked-dynamic declaration fallback for unmappable binding types
292
313
  * (see irTypeOf), two gates over one story:
293
314
  *
@@ -344,6 +365,29 @@ export declare class Lowerer {
344
365
  /** Per-symbol result of the never-reassigned file scan
345
366
  * (bindingNeverReassigned — object-literal generic-method receivers). */
346
367
  readonly neverReassignedCache: Map<ts.Symbol, boolean>;
368
+ /** TRAP bindings: declarations whose initializer provably throws before
369
+ * producing a value (its chain roots at an ambient-undefined name —
370
+ * ambientUndefVarRootOf). Module init unwinds at the declaration, so no
371
+ * reference to the binding can ever execute; the statement lowers to the
372
+ * root's throw, no storage exists, and references lower to the same
373
+ * trap shape (never reached — sound whatever the type). */
374
+ readonly trapBindings: Set<ts.Symbol>;
375
+ /** NULLISH bindings of unmappable (generic-signature) types: `const i:
376
+ * I<A & B> = null as any` — the binding provably holds null/undefined
377
+ * forever (every write's RHS is nullish too), so no storage exists and
378
+ * each READ knows the value. Member reads and method calls through one
379
+ * lower to Node's exact TypeError ("Cannot read properties of null
380
+ * (reading 'fn')"); nullish-to-nullish flows lower to nothing. The map
381
+ * answers which unit the binding holds (the TypeError names it). Null
382
+ * entries cache probed non-qualifiers. */
383
+ readonly nullishBindings: Map<ts.Symbol, "undefined" | "null" | null>;
384
+ /** DEAD bindings of unmappable types: never READ anywhere in the
385
+ * program, declared with no initializer or a value-only one (a function
386
+ * literal), every write's RHS side-effect-free. Node materializes the
387
+ * value and drops it — zero observable effect — so the declaration and
388
+ * its writes lower to nothing, and no type fence fires for a value the
389
+ * program never consumes. */
390
+ readonly deadBindings: Set<ts.Symbol>;
347
391
  /** IMPLICIT-ANY function-value bindings (npm-static JS — `const knownBy
348
392
  * = (cmd) => ...`), by their VariableDeclaration: the registered info,
349
393
  * or null for probed non-qualifiers (implicitLocalFnNodeOf). */
@@ -730,12 +774,14 @@ export declare class Lowerer {
730
774
  private cjsDefaultImportDepOf;
731
775
  /** True when `expr` is an identifier bound by a top-level
732
776
  * `const x = require("./local")` of a RELATIVE module — the CommonJS
733
- * namespace binding — or by a DEFAULT import of a CommonJS JS module
734
- * (`import d from "./lib.cjs"`: Node binds d to module.exports, the
735
- * same value require answers). Member accesses on it resolve through
736
- * the export table (property symbols → resolveValueSymbol); the bare
737
- * value keeps the namespace-object fence, like ESM namespace imports
738
- * of builtins. */
777
+ * namespace binding — or of a bare specifier naming an opted-in
778
+ * --npm-static package (its CJS entry is a program module, so the
779
+ * binding is the same namespace over the same export table), or by a
780
+ * DEFAULT import of a CommonJS JS module (`import d from "./lib.cjs"`:
781
+ * Node binds d to module.exports, the same value require answers).
782
+ * Member accesses on it resolve through the export table (property
783
+ * symbols → resolveValueSymbol); the bare value keeps the
784
+ * namespace-object fence, like ESM namespace imports of builtins. */
739
785
  cjsLocalModuleBindingOf(expr: ts.Expression): boolean;
740
786
  /** Assignment-target resolution: a function local (possibly captured) or
741
787
  * a module global. tsc has already rejected writes to consts. */
@@ -758,9 +804,11 @@ export declare class Lowerer {
758
804
  /** The lowering of a CommonJS `require("./local")` occurrence: a call of
759
805
  * the required module's run-once %init at exactly this statement's
760
806
  * position — Node's inline evaluation, with the guard supplying the
761
- * cache-hit behavior for every require after the first. Null when the
762
- * specifier is not a relative program module (builtins load nothing;
763
- * anything else kept its preflight fence). */
807
+ * cache-hit behavior for every require after the first. Bare specifiers
808
+ * naming an opted-in --npm-static package resolve to that package's
809
+ * program entry (the same edge preflight admitted — bundle dists require
810
+ * their external dependencies by name). Null for everything else
811
+ * (builtins load nothing; the rest kept its preflight fence). */
764
812
  requireInitStmt(spec: string, node: ts.Node): IrStmt | null;
765
813
  /** True when this body should lower: everything with no reachable set
766
814
  * (discovery), the marked bodies in the emit pass, and exactly the
@@ -897,8 +945,10 @@ export declare class Lowerer {
897
945
  irTypeOf(node: ts.Node): IrType;
898
946
  /** Exact-shape enforcement (SC2002). Records are monomorphic structs, so
899
947
  * everywhere a value flows into a typed slot (call arg, initializer,
900
- * assignment, field, return) the shapes must MATCH — TS's structural width
901
- * subtyping (`{a, b}` where `{a}` is expected) has no runtime coercion.
948
+ * assignment, field, return) the shapes must MATCH — or width-coerce:
949
+ * coerceToExpected already ran widthCoerce (the copy-reshape family),
950
+ * so what reaches here is the RESIDUE its rules decline, and the
951
+ * diagnostic names the first blocking rule (describeRecordWidthBlocker).
902
952
  * Non-record mismatches are not reachable through tsc-clean programs; the
903
953
  * validator ICEs on them as the usual backstop. */
904
954
  requireExactShape(node: ts.Node, actual: IrType, expected: IrType): void;
@@ -952,6 +1002,13 @@ export declare class Lowerer {
952
1002
  * recursively — NESTED width)
953
1003
  * arr — array into array whose element pair lifts (per-element
954
1004
  * copy loop, arrayWidthHelper)
1005
+ * dynIn — a typed value into an 'unknown' (dyn) slot — the same
1006
+ * static→DOM deep copy coerceToExpected applies top-level
1007
+ * upcast — a derived class instance into a base-typed slot (the
1008
+ * prefix-layout pointer reinterpret, no copy)
1009
+ * funcAdapt — a function into a slot whose signature differs only by
1010
+ * CLEAN mechanical conversions (cleanFuncAdaptable); the
1011
+ * stranded (trap-only) dispositions stay out of the plan
955
1012
  * Null when the pair isn't in the relation — callers keep their fences. */
956
1013
  widthLiftPlan(src: IrType, dst: IrType): WidthLift | null;
957
1014
  /** True for the unit-only element types (`(null | undefined)[]`, the
@@ -972,9 +1029,11 @@ export declare class Lowerer {
972
1029
  * optional-flavored field completes to its undefined arm (the
973
1030
  * literal-completion rule). TUPLES width-coerce too, arity-exact (TS
974
1031
  * permits no other tuple width): per-position lifts, never completion.
975
- * Index-signature shapes keep the exactness fences here (the overflow
976
- * CAPTURE helper owns their reshapes). Null when the shapes don't
977
- * relate that way. */
1032
+ * Index-signature SOURCES narrow here like any wider record — declared
1033
+ * fields copy, the overflow drops with the width (missing target
1034
+ * fields decline: the overflow could hold them). Index-signature
1035
+ * TARGETS keep the overflow CAPTURE helper (widthCoerce's other arm).
1036
+ * Null when the shapes don't relate that way. */
978
1037
  /** The pure planning half of recordWidthHelper — every target field's
979
1038
  * lift, or null when the pair isn't width-coercible. Callers that must
980
1039
  * validate a WHOLE plan before interning anything (the retag helper's
@@ -988,6 +1047,14 @@ export declare class Lowerer {
988
1047
  } | {
989
1048
  absentDyn: true;
990
1049
  }> | null;
1050
+ /** Post-hoc classifier for SC2002's record→record residue: WHY the
1051
+ * width family (recordWidthPlan and the overflow capture — widthCoerce's
1052
+ * two record arms) declined this pair — the FIRST blocking rule, named.
1053
+ * Pure description on the failure path (the site already carries the
1054
+ * rejection): mirrors the planners' gates, never changes what coerces,
1055
+ * and answers null when no pointed story applies (the generic message
1056
+ * stands). */
1057
+ describeRecordWidthBlocker(fromId: string, toId: string): string | null;
991
1058
  recordWidthHelper(fromId: string, toId: string, loc: SrcLoc): string | null;
992
1059
  /** Interned `%arr.width.<n>(a)` — the per-element copy loop over
993
1060
  * widthLiftPlan's element lift: out = []; n = a.length; for (...)
@@ -1098,6 +1165,18 @@ export declare class Lowerer {
1098
1165
  * Deliberately EXCLUDES the trap-only stranded conversions — an adapter
1099
1166
  * that could only ever throw is a fence, not a bridge. */
1100
1167
  coercibleValue(src: IrType, dst: IrType): boolean;
1168
+ /** True when a `src` function value enters a `dst` slot through
1169
+ * funcCoerceAdapter with NO stranded (trap-only) piece: no rest packs,
1170
+ * no surplus source params, every slot parameter converts into the
1171
+ * wrapped function's own type, and the result converts back (a void
1172
+ * slot drops it; a void result answers the exact JS undefined for
1173
+ * dyn/jsval slots). The width family's func gate — widthLiftPlan
1174
+ * bridges only signatures whose every call succeeds by construction. */
1175
+ cleanFuncAdaptable(src: IrType & {
1176
+ kind: "func";
1177
+ }, dst: IrType & {
1178
+ kind: "func";
1179
+ }): boolean;
1101
1180
  /** Interned `%fn.adapt.<n>(f)` — the GENERAL function-value adapter: a
1102
1181
  * `fromT` function value flowing into a `toT` slot whose pieces differ
1103
1182
  * only by coercibleValue conversions. The slot's callers pass toT's
@@ -1583,7 +1662,7 @@ export declare class Lowerer {
1583
1662
  stmts: IrStmt[];
1584
1663
  value: IrExpr;
1585
1664
  };
1586
- lowerBindingPattern(pattern: ts.ArrayBindingPattern | ts.ObjectBindingPattern, srcRef: () => IrExpr, srcType: IrType, isLet: boolean, out: IrStmt[]): void;
1665
+ lowerBindingPattern(pattern: ts.ArrayBindingPattern | ts.ObjectBindingPattern, srcRef: () => IrExpr, srcType: IrType, isLet: boolean, out: IrStmt[], dynSpell?: string): void;
1587
1666
  checkBindingElement(el: ts.BindingElement, allowDefault?: boolean): void;
1588
1667
  bindPatternTarget(name: ts.BindingName, value: IrExpr, isLet: boolean, out: IrStmt[]): void;
1589
1668
  lowerVarDeclList(list: ts.VariableDeclarationList): IrStmt | null;
@@ -1747,6 +1826,14 @@ export declare class Lowerer {
1747
1826
  module: string;
1748
1827
  member: string;
1749
1828
  }, fn: BuiltinModuleFn, loc: SrcLoc): IrExpr;
1829
+ lowerFsToUnixTimestampCall(expr: ts.CallExpression, bi: {
1830
+ module: string;
1831
+ member: string;
1832
+ }, loc: SrcLoc): IrExpr | null;
1833
+ lowerFsLadderCall(expr: ts.CallExpression, bi: {
1834
+ module: string;
1835
+ member: string;
1836
+ }, loc: SrcLoc): IrExpr | null;
1750
1837
  lowerChildArgsArg(node: ts.Expression | undefined, loc: SrcLoc): IrExpr;
1751
1838
  lowerSpawnSyncCall(expr: ts.CallExpression, loc: SrcLoc): IrExpr;
1752
1839
  lowerSpawnCall(expr: ts.CallExpression, loc: SrcLoc): IrExpr;