@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
@@ -3,7 +3,7 @@
3
3
  * methods with Node-exact forEach desugaring, and the string and regex
4
4
  * method surfaces. */
5
5
  import * as ts from "../ts7/adapter.js";
6
- import { BOOL, BYTES_U8, CAUGHT, DYN, F64, JSVAL, STRING, UNDEFINED_T, VOID, arrayOf, bytesOf, funcOf, isRefCounted, isSupportedIndexValue, isUnitType, typeEquals } from "../../ir/nodes.js";
6
+ import { BOOL, BYTES_U8, CAUGHT, DYN, F64, JSVAL, STRING, UNDEFINED_T, VOID, arrayOf, bytesOf, funcOf, isRefCounted, isSupportedArrayElem, isSupportedIndexValue, isUnitType, typeEquals } from "../../ir/nodes.js";
7
7
  import { ARRAY_METHODS, MAP_METHODS, SET_COMBINE_METHODS, SET_METHODS, STR_METHODS } from "./surfaces.js";
8
8
  import { droppableStatic, isRequireMainFilename, lowerDynObjectLiteral, probeLower, pureReemittable } from "./lower-exprs.js";
9
9
  import { forOfVarTarget, lowerDestructuringAssign } from "./lower-stmts.js";
@@ -91,6 +91,18 @@ function lowerSplitLimitArg(L, node, loc) {
91
91
  const defaultValue = { kind: "numLit", value: 4294967295, type: F64, loc };
92
92
  return node ? lowerOptionalDefaultArg(L, node, F64, defaultValue) : defaultValue;
93
93
  }
94
+ /** Callback-driven array producers bypass mapType's ordinary T[] mapping:
95
+ * the callback is lowered first, then the helper's result array is built
96
+ * directly from its IR return type. Fence element kinds ScrArr cannot hold
97
+ * before constructing that array type. */
98
+ function fenceProducedArrayElem(L, node, producer, elem) {
99
+ if (elem.kind === "dyn") {
100
+ L.unsupported("SC1090", node, `${producer} with a callback returning 'unknown'-typed values (the result array has no static element type — annotate the callback's return)`);
101
+ }
102
+ if (!isSupportedArrayElem(elem)) {
103
+ L.unsupported("SC1090", node, `${producer} with a callback returning '${L.fmt(elem)}' values (arrays of this element kind have no representation — store the values individually)`);
104
+ }
105
+ }
94
106
  /** Ambient array method calls. `push`/`unshift`/`pop`/`reverse`/
95
107
  * `indexOf`/`includes`/`join`
96
108
  * lower to arrIntrinsic; the HOF family — `map`/`filter`/`forEach`/
@@ -566,28 +578,8 @@ export function lowerArrayHofCall(L, call, access, method, elem) {
566
578
  // story yet).
567
579
  L.badType(call, L.typeOf(call));
568
580
  }
569
- if (method === "map" &&
570
- (fnRet.kind === "map" || fnRet.kind === "set" || fnRet.kind === "url" ||
571
- fnRet.kind === "searchParams" || fnRet.kind === "generator" || fnRet.kind === "caught" ||
572
- fnRet.kind === "stats" || fnRet.kind === "fileHandle" || fnRet.kind === "spawnRes" || fnRet.kind === "netSocket" ||
573
- fnRet.kind === "dgramSocket" || fnRet.kind === "testCtx" || fnRet.kind === "httpReq" ||
574
- fnRet.kind === "httpRes" || fnRet.kind === "httpClientReq" || fnRet.kind === "secureCtx" ||
575
- fnRet.kind === "fsWatcher" || fnRet.kind === "childStream" || fnRet.kind === "procStream" ||
576
- isUnitType(fnRet))) {
577
- // The result would be an array of an element kind ScrArr has no
578
- // home for (mapTypeOf's own array exclusions) — the callback return
579
- // type bypasses that gate, so it is enforced here: a named fence,
580
- // never a mistyped array into the backends.
581
- L.unsupported("SC1090", call, `'.map()' with a callback returning '${L.fmt(fnRet)}' values (arrays of this element kind have no representation — store the values individually)`);
582
- }
583
- if (method === "map" && fnRet.kind === "dyn") {
584
- // A checked-dynamic callback return would make the result a
585
- // dyn-element STATIC array, which has no backend representation
586
- // (dynFallbackType's rule: an unmappable element makes the WHOLE
587
- // value dyn — but map's fresh array is built here, not by a
588
- // declaration, so the honest answer is the fence).
589
- L.unsupported("SC1090", call, "'.map()' with a callback returning 'unknown'-typed values (the result array has no static element type — annotate the callback's return)");
590
- }
581
+ if (method === "map")
582
+ fenceProducedArrayElem(L, call, "'.map()'", fnRet);
591
583
  // JS applies ToBoolean to whatever the predicate answers, so a non-bool
592
584
  // result is not an error — the filter loop wraps the call in the same
593
585
  // toBool an `if` statement would apply. The island/dyn shapes, whose
@@ -753,6 +745,7 @@ export function lowerTupleReadMethodCall(L, call, access) {
753
745
  const fnRet = fnArg.type.ret;
754
746
  if (fnRet.kind === "void" || fnRet.kind === "func")
755
747
  L.badType(call, L.typeOf(call));
748
+ fenceProducedArrayElem(L, call, "'.map()'", fnRet);
756
749
  const helper = arrayHofHelper(L, "map", snapshotElem, fnRet, arity, loc);
757
750
  return { kind: "call", callee: helper, args: [snapshot, fnArg], type: arrayOf(fnRet), loc };
758
751
  }
@@ -1270,6 +1263,7 @@ export function lowerArrayFlatMapCall(L, call, access, elem) {
1270
1263
  // No flatten happens: exactly map's loop, map's helper.
1271
1264
  if (fnRet.kind === "void" || fnRet.kind === "func")
1272
1265
  L.badType(call, L.typeOf(call));
1266
+ fenceProducedArrayElem(L, call, "'.flatMap()'", fnRet);
1273
1267
  const helper = arrayHofHelper(L, "map", elem, fnRet, arity, loc);
1274
1268
  return { kind: "call", callee: helper, args: [receiver, fnArg], type: arrayOf(fnRet), loc };
1275
1269
  }
@@ -2356,6 +2350,7 @@ export function lowerArrayFromCall(L, call, access) {
2356
2350
  const fnRet = fnT.ret;
2357
2351
  if (fnRet.kind === "void" || fnRet.kind === "func")
2358
2352
  L.badType(call, L.typeOf(call));
2353
+ fenceProducedArrayElem(L, call, "'Array.from({ length }, mapper)'", fnRet);
2359
2354
  const arity = fnT.params.length;
2360
2355
  const key = `fromLen:${typeKey(fnRet)}:${arity}`;
2361
2356
  let helper = L.arrHofHelpers.get(key);
@@ -5854,6 +5849,7 @@ export function objectIterOverIndexShape(L, node, member, argIr, shape, receiver
5854
5849
  const body = [
5855
5850
  { kind: "varDecl", localId: "out.0", init: { kind: "arrayLit", elems: [], type: resultT, loc }, loc },
5856
5851
  ];
5852
+ const fieldStmts = new Map();
5857
5853
  // Declared fields, in declaration order. Undefined-valued fields
5858
5854
  // skip at runtime (the unset-optional convention); values surface
5859
5855
  // into the element type or the site fences with the field named.
@@ -5921,7 +5917,7 @@ export function objectIterOverIndexShape(L, node, member, argIr, shape, receiver
5921
5917
  loc,
5922
5918
  };
5923
5919
  }
5924
- body.push(utag >= 0 && f.type.kind === "union"
5920
+ const fieldStmt = utag >= 0 && f.type.kind === "union"
5925
5921
  ? {
5926
5922
  kind: "if",
5927
5923
  cond: { kind: "unionIsTag", unionId: f.type.unionId, tag: utag, negated: true, value: raw, type: BOOL, loc },
@@ -5929,7 +5925,9 @@ export function objectIterOverIndexShape(L, node, member, argIr, shape, receiver
5929
5925
  else_: null,
5930
5926
  loc,
5931
5927
  }
5932
- : push(pushed));
5928
+ : push(pushed);
5929
+ fieldStmts.set(f.name, fieldStmt);
5930
+ body.push(fieldStmt);
5933
5931
  }
5934
5932
  // The overflow walk: a fresh key snapshot in JS own-key order, each
5935
5933
  // value read back through the overflow-only keyed read (declared
@@ -5976,8 +5974,9 @@ export function objectIterOverIndexShape(L, node, member, argIr, shape, receiver
5976
5974
  ],
5977
5975
  loc,
5978
5976
  }, { kind: "return", value: outRef, loc });
5977
+ const suffix = body.slice(1 + fieldStmts.size);
5979
5978
  L.arrHofHelpers.set(key, helper);
5980
- L.liftedFns.push({
5979
+ const fn = {
5981
5980
  name: helper,
5982
5981
  params: [{ localId: "r.0", name: "r", type: argIr }],
5983
5982
  returnType: resultT,
@@ -5990,7 +5989,16 @@ export function objectIterOverIndexShape(L, node, member, argIr, shape, receiver
5990
5989
  ],
5991
5990
  body,
5992
5991
  loc,
5992
+ };
5993
+ L.shapeOrderHelperFinalizers.push(() => {
5994
+ const current = L.shapes.get(argIr.shapeId) ?? shape;
5995
+ const currentOrder = current.declaredOrder ?? current.fields.map((f) => f.name);
5996
+ fn.body = [body[0], ...currentOrder.flatMap((name) => {
5997
+ const stmt = fieldStmts.get(name);
5998
+ return stmt ? [stmt] : [];
5999
+ }), ...suffix];
5993
6000
  });
6001
+ L.liftedFns.push(fn);
5994
6002
  }
5995
6003
  return { kind: "call", callee: helper, args: [receiver], type: resultT, loc };
5996
6004
  }
@@ -6356,6 +6364,7 @@ export function lowerRecordOvfCaptureHelper(L, fromId, toId, loc) {
6356
6364
  loc,
6357
6365
  },
6358
6366
  ];
6367
+ const fieldStmts = new Map();
6359
6368
  // Source declared fields in declaration order, skipping unset
6360
6369
  // optionals (stance 37) and the direct-initialized (consumed) names.
6361
6370
  for (const ff of orderedFields) {
@@ -6374,7 +6383,7 @@ export function lowerRecordOvfCaptureHelper(L, fromId, toId, loc) {
6374
6383
  ...(to.fields.some((f) => f.name === ff.name) ? {} : { overflowOnly: true }),
6375
6384
  loc,
6376
6385
  };
6377
- body.push(utag >= 0 && ff.type.kind === "union"
6386
+ const fieldStmt = utag >= 0 && ff.type.kind === "union"
6378
6387
  ? {
6379
6388
  kind: "if",
6380
6389
  cond: { kind: "unionIsTag", unionId: ff.type.unionId, tag: utag, negated: true, value: raw, type: BOOL, loc },
@@ -6382,7 +6391,9 @@ export function lowerRecordOvfCaptureHelper(L, fromId, toId, loc) {
6382
6391
  else_: null,
6383
6392
  loc,
6384
6393
  }
6385
- : write);
6394
+ : write;
6395
+ fieldStmts.set(ff.name, fieldStmt);
6396
+ body.push(fieldStmt);
6386
6397
  }
6387
6398
  // The source overflow, in JS own-key order (only index-signature
6388
6399
  // sources carry one).
@@ -6421,7 +6432,8 @@ export function lowerRecordOvfCaptureHelper(L, fromId, toId, loc) {
6421
6432
  });
6422
6433
  }
6423
6434
  body.push({ kind: "return", value: outRef, loc });
6424
- L.liftedFns.push({
6435
+ const suffix = body.slice(1 + fieldStmts.size);
6436
+ const fn = {
6425
6437
  name,
6426
6438
  params: [{ localId: "s.0", name: "s", type: fromT }],
6427
6439
  returnType: toT,
@@ -6438,7 +6450,16 @@ export function lowerRecordOvfCaptureHelper(L, fromId, toId, loc) {
6438
6450
  ],
6439
6451
  body,
6440
6452
  loc,
6453
+ };
6454
+ L.shapeOrderHelperFinalizers.push(() => {
6455
+ const current = L.shapes.get(fromId) ?? from;
6456
+ const currentOrder = current.declaredOrder ?? current.fields.map((f) => f.name);
6457
+ fn.body = [body[0], ...currentOrder.flatMap((field) => {
6458
+ const stmt = fieldStmts.get(field);
6459
+ return stmt ? [stmt] : [];
6460
+ }), ...suffix];
6441
6461
  });
6462
+ L.liftedFns.push(fn);
6442
6463
  return name;
6443
6464
  }
6444
6465
  /** `Object.assign(target, ...sources)` into an INDEX-SIGNATURE record:
@@ -6531,6 +6552,7 @@ export function lowerObjectAssignIndexShape(L, call) {
6531
6552
  const sRef = ref("s.0", fromT);
6532
6553
  const intoSlot = (v, lift) => lift === "dyn" ? { kind: "dynFrom", value: v, type: DYN, loc } : L.applyWidthLift(lift, v, tIv, loc);
6533
6554
  const body = [];
6555
+ const fieldStmts = new Map();
6534
6556
  for (const ff of plan.fields) {
6535
6557
  const raw = { kind: "recordGet", obj: sRef, shapeId: plan.fromId, field: ff.name, type: ff.type, loc };
6536
6558
  const utag = ff.type.kind === "union" ? L.armTag(ff.type.unionId, UNDEFINED_T) : -1;
@@ -6542,7 +6564,7 @@ export function lowerObjectAssignIndexShape(L, call) {
6542
6564
  value: intoSlot(raw, ff.lift),
6543
6565
  loc,
6544
6566
  };
6545
- body.push(utag >= 0 && ff.type.kind === "union"
6567
+ const fieldStmt = utag >= 0 && ff.type.kind === "union"
6546
6568
  ? {
6547
6569
  kind: "if",
6548
6570
  cond: { kind: "unionIsTag", unionId: ff.type.unionId, tag: utag, negated: true, value: raw, type: BOOL, loc },
@@ -6550,7 +6572,9 @@ export function lowerObjectAssignIndexShape(L, call) {
6550
6572
  else_: null,
6551
6573
  loc,
6552
6574
  }
6553
- : write);
6575
+ : write;
6576
+ fieldStmts.set(ff.name, fieldStmt);
6577
+ body.push(fieldStmt);
6554
6578
  }
6555
6579
  const ksT = arrayOf(STRING);
6556
6580
  const fromShape = L.shapes.get(plan.fromId);
@@ -6588,7 +6612,8 @@ export function lowerObjectAssignIndexShape(L, call) {
6588
6612
  });
6589
6613
  }
6590
6614
  body.push({ kind: "return", value: tRef, loc });
6591
- L.liftedFns.push({
6615
+ const suffix = body.slice(fieldStmts.size);
6616
+ const fn = {
6592
6617
  name,
6593
6618
  params: [
6594
6619
  { localId: "t.0", name: "t", type: toT },
@@ -6608,7 +6633,16 @@ export function lowerObjectAssignIndexShape(L, call) {
6608
6633
  ],
6609
6634
  body,
6610
6635
  loc,
6636
+ };
6637
+ L.shapeOrderHelperFinalizers.push(() => {
6638
+ const current = L.shapes.get(plan.fromId) ?? fromShape;
6639
+ const currentOrder = current.declaredOrder ?? current.fields.map((f) => f.name);
6640
+ fn.body = [...currentOrder.flatMap((field) => {
6641
+ const stmt = fieldStmts.get(field);
6642
+ return stmt ? [stmt] : [];
6643
+ }), ...suffix];
6611
6644
  });
6645
+ L.liftedFns.push(fn);
6612
6646
  return name;
6613
6647
  };
6614
6648
  let acc = L.lowerExprExpecting(call.arguments[0], targetIr);