@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
@@ -1,5 +1,5 @@
1
1
  import * as ts from "./ts7/adapter.js";
2
- import { arrayOf, BOOL, bytesOf, CHILD_T, DYN, F64, funcOf, isSupportedIndexValue, isSupportedMapKey, isSupportedMapValue, isSupportedSetElem, isUnitType, JSVAL, mapOf, NULL_T, PROCSTREAM_T, RUNTIME_EMITTER_CLASS, RUNTIME_ERROR_CLASSES, RUNTIME_STREAM_CLASSES, setOf, STRING, SYMBOL_T, typeEquals, typeKey, UNDEFINED_T, VOID } from "../ir/nodes.js";
2
+ import { arrayOf, BOOL, bytesOf, canConvertToDyn, CHILD_T, DYN, F64, funcOf, isSupportedIndexValue, isSupportedMapKey, isSupportedMapValue, isSupportedSetElem, isUnitType, JSVAL, mapOf, NULL_T, PROCSTREAM_T, RUNTIME_EMITTER_CLASS, RUNTIME_ERROR_CLASSES, RUNTIME_STREAM_CLASSES, setOf, STRING, SYMBOL_T, typeEquals, typeKey, UNDEFINED_T, VOID } from "../ir/nodes.js";
3
3
  import { isJsSourceFile, isNodeTypesPath } from "./program.js";
4
4
  import { accessorSlotProp } from "../ir/nodes.js";
5
5
  // typeKey moved to ir/nodes.ts (the backend needs it too, for per-type
@@ -813,10 +813,19 @@ function mapTypeInner(type, ctx) {
813
813
  elem.kind === "fsWatcher" ||
814
814
  elem.kind === "childStream" ||
815
815
  elem.kind === "procStream" ||
816
- elem.kind === "generator" ||
817
- elem.kind === "dyn") {
818
- return null; // ScrArr has no closure/map/regex/url/dyn element kinds yet
819
- }
816
+ elem.kind === "generator") {
817
+ return null; // ScrArr has no closure/map/regex/url element kinds yet
818
+ }
819
+ // A dyn ELEMENT makes the WHOLE array the checked-dynamic value:
820
+ // `unknown[]`, `object[]`, and the collapsed `(string | object)[]`
821
+ // (the plugins-slot shape) — the DOM has real arrays, so length/
822
+ // index/push/iteration ride the keyed-DOM paths, while a dyn-element
823
+ // STATIC array has no backend representation (ScrArr has no dyn
824
+ // element kind). This is dynFallbackType's JS stance promoted into
825
+ // the mapping itself; construction sites build dynArrLit (the DOM
826
+ // array literal) and typed sources convert per element at the slot.
827
+ if (elem.kind === "dyn")
828
+ return DYN;
820
829
  // ChildProcess[] (the running-apps list) and Server[] (the [...set]
821
830
  // drain of the auxiliary-server registries): handles are ordinary
822
831
  // refcounted REF elements (their `_v` adapters, no trace — both drop
@@ -2049,6 +2058,31 @@ function mapTypeInner(type, ctx) {
2049
2058
  return null;
2050
2059
  return arms[0];
2051
2060
  }
2061
+ // The `string | object`-family COLLAPSE (world unification lane 3):
2062
+ // a union with an 'object'/'unknown'/`{}`-flavored arm (dyn) beside
2063
+ // arms the checked-dynamic representation FAITHFULLY holds maps to
2064
+ // DYN WHOLESALE — the DOM's scalar kinds ARE the scalar arms (===,
2065
+ // typeof, switch dispatch all exact), typeof/Array.isArray/unit
2066
+ // narrowing on dyn already dispatches natively (dynTest +
2067
+ // maybeNarrow's validated scalar extraction), and engine-valued
2068
+ // arms ride the island kind (SCR_DYN_JSVAL), so no per-arm runtime
2069
+ // tag is ever needed and the component fence retires at these
2070
+ // sites. The domain is dynSubsumableUnionArm's: scalars, units, dyn
2071
+ // itself, and records/arrays inside the dynFrom conversion domain
2072
+ // (those enter as DOM data — the deep-copy stance, so identity and
2073
+ // mutation coupling with the source value end at the slot;
2074
+ // SEMANTICS.md). Arms with real typed representations whose
2075
+ // semantics would DEGRADE under the collapse — class instances,
2076
+ // Maps/Sets, functions (closure identity, `x === String`
2077
+ // narrowing), promises, regexes, generators, handles — keep their
2078
+ // existing union homes and fences below. A pending recursive
2079
+ // placeholder cannot collapse (back-references already hold the
2080
+ // union id); the degenerate recursive spelling keeps its fence.
2081
+ if (arms.some((a) => a.kind === "dyn") &&
2082
+ arms.every((a) => dynSubsumableUnionArm(a, ctx)) &&
2083
+ !unions.recursivePending(widened)) {
2084
+ return DYN;
2085
+ }
2052
2086
  if (arms.some((a) => a.kind === "void" || a.kind === "union" ||
2053
2087
  // Map/Set arms stay out (like func against data arms: no
2054
2088
  // narrowing test — no discriminant fields on them). REGEX
@@ -2655,8 +2689,10 @@ function mapRecordTypeInner(widened, ctx) {
2655
2689
  // BOTH signatures at once (string + number) collapse into the one store
2656
2690
  // when their value types intern identically (tsc requires only
2657
2691
  // assignability; unequal slots would need a per-key answer the store
2658
- // cannot give). Value types outside the map-value world stay unmapped
2659
- // (isSupportedIndexValue).
2692
+ // cannot give). The value domain is the overflow store's
2693
+ // (isSupportedIndexValue): the map-value kinds plus 'unknown', functions
2694
+ // (the command-registry pattern), Maps/Sets, and nested index-signature
2695
+ // records; everything else stays unmapped.
2660
2696
  let indexValue;
2661
2697
  const indexInfos = checker.getIndexInfosOfType(widened);
2662
2698
  if (indexInfos.length > 0) {
@@ -2930,6 +2966,34 @@ const STDLIB_CONTAINERS = {
2930
2966
  Generator: { role: (i) => ["yield", "return", "next"][i] ?? "channel" },
2931
2967
  AsyncGenerator: { role: (i) => ["yield", "return", "next"][i] ?? "channel" },
2932
2968
  };
2969
+ /** The `string | object`-family collapse domain (mapTypeInner's union
2970
+ * rule): arms the checked-dynamic representation holds FAITHFULLY, so a
2971
+ * union carrying a dyn arm beside only these maps to DYN wholesale.
2972
+ * Scalars and units are the DOM's own kinds (value-exact ===/typeof);
2973
+ * records and arrays qualify exactly when the dynFrom conversion can
2974
+ * build them (canConvertToDyn — JSON-safe data plus bytes-bearing
2975
+ * composites), entering as DOM data under the documented deep-copy
2976
+ * stance. Everything else — class instances, Maps/Sets, functions
2977
+ * (closure identity and `x === String` narrowing live in the typed union
2978
+ * machinery), promises, regexes, generators, handles, nested unions —
2979
+ * would DEGRADE (identity, methods, dispatch) riding dyn, so those arms
2980
+ * keep their existing homes and fences. */
2981
+ export function dynSubsumableUnionArm(arm, ctx) {
2982
+ switch (arm.kind) {
2983
+ case "dyn":
2984
+ case "f64":
2985
+ case "string":
2986
+ case "bool":
2987
+ case "undefinedT":
2988
+ case "nullT":
2989
+ return true;
2990
+ case "record":
2991
+ case "array":
2992
+ return canConvertToDyn(arm, (id) => ctx.shapes.get(id), (id) => ctx.unions.get(id));
2993
+ default:
2994
+ return false;
2995
+ }
2996
+ }
2933
2997
  /** Arm kinds with no home in a compiled union (mapTypeInner's union rule):
2934
2998
  * no runtime narrowing test exists against sibling data arms. */
2935
2999
  function armHasUnionHome(arm, siblingCount) {
@@ -3025,8 +3089,23 @@ export function describeComponentBlocker(widened, ctx) {
3025
3089
  const parts = widened.getTypes();
3026
3090
  const UNIT = ts.TypeFlags.Undefined | ts.TypeFlags.Void | ts.TypeFlags.Null;
3027
3091
  const dataArms = parts.filter((p) => (p.flags & UNIT) === 0);
3028
- for (const part of dataArms) {
3029
- const mapped = mapType(part, ctx);
3092
+ // A union carrying an 'object'/'unknown'-flavored arm rides the
3093
+ // checked-dynamic representation WHOLESALE when every sibling is
3094
+ // dyn-subsumable (mapTypeInner's collapse) — so when such a union
3095
+ // still failed, the story is the sibling that CANNOT ride the
3096
+ // collapse, never the dyn arm itself.
3097
+ const mappedArms = dataArms.map((p) => ({ p, mapped: mapType(p, ctx) }));
3098
+ if (mappedArms.some(({ mapped }) => mapped?.kind === "dyn")) {
3099
+ const blocker = mappedArms.find(({ mapped }) => mapped !== null && !dynSubsumableUnionArm(mapped, ctx));
3100
+ if (blocker) {
3101
+ return `the union shape is supported, and unions in the 'string | object' family ride the checked-dynamic representation wholesale, but '${text(blocker.p)}' arms have a typed representation whose semantics (identity, methods, dispatch) do not survive that collapse`;
3102
+ }
3103
+ // Every sibling subsumable and the union STILL failed: the
3104
+ // recursive-placeholder fence (a degenerate spelling) — no per-arm
3105
+ // story is true, so the residual fence speaks.
3106
+ return null;
3107
+ }
3108
+ for (const { p: part, mapped } of mappedArms) {
3030
3109
  if (!mapped) {
3031
3110
  return `the union shape is supported, but its arm '${text(part)}' does not compile`;
3032
3111
  }